Line data Source code
1 : #include "configure.h" 2 : #include "fd_ethtool_ioctl.h" 3 : #include "../../../../disco/net/mlx5/fd_mlx5.h" 4 : 5 : #include <linux/capability.h> 6 : 7 : static int 8 0 : enabled( config_t const * config ) { 9 0 : return !strcmp( config->net.provider, "mlx5" ); 10 0 : } 11 : 12 : static void 13 : init_perm( fd_cap_chk_t * chk, 14 0 : config_t const * config FD_PARAM_UNUSED ) { 15 0 : fd_cap_chk_root( chk, "mlx5", "configure mlx5 network devices and load the ib_uverbs kernel module" ); 16 0 : if( !fd_mlx5_uverbs_avail() ) { 17 0 : fd_cap_chk_cap( chk, "mlx5", CAP_SYS_MODULE, "run modprobe to load the ib_uverbs kernel module" ); 18 0 : } 19 0 : } 20 : 21 : static void 22 : fini_perm( fd_cap_chk_t * chk, 23 0 : config_t const * config FD_PARAM_UNUSED ) { 24 0 : fd_cap_chk_root( chk, "mlx5", "modify network device configuration with ethtool" ); 25 0 : } 26 : 27 : static void 28 0 : init( config_t const * config FD_PARAM_UNUSED ) { 29 0 : if( !fd_mlx5_uverbs_avail() ) { 30 0 : FD_LOG_NOTICE(( "%sRUN: `modprobe ib_uverbs`%s", fd_log_style_dim(), fd_log_style_normal() )); 31 0 : if( FD_UNLIKELY( fd_mlx5_uverbs_modprobe( 0 ) ) ) { 32 0 : FD_LOG_ERR(( "failed to load ib_uverbs kernel module. " 33 0 : "Run `sudo modprobe ib_uverbs` and retry" )); 34 0 : } 35 0 : if( FD_UNLIKELY( !fd_mlx5_uverbs_avail() ) ) { 36 0 : FD_LOG_ERR(( "failed to run mlx5 tile: uverbs interface still unavailable after trying to load ib_uverbs kernel module. " 37 0 : "Please set [net.provider] to `xdp`" )); 38 0 : } 39 0 : } 40 0 : } 41 : 42 : static int 43 : fini( config_t const * config, 44 0 : int pre_init FD_PARAM_UNUSED ) { 45 0 : return fd_ethtool_ioctl_reset( config->net.interface ); 46 0 : } 47 : 48 : static configure_result_t 49 : check( config_t const * config, 50 0 : int check_type ) { 51 0 : int is_modified = fd_ethtool_ioctl_is_modified( config->net.interface ); 52 0 : if( FD_UNLIKELY( is_modified ) ) { 53 0 : PARTIALLY_CONFIGURED( "device `%s` has ethtool configuration left by the xdp provider", config->net.interface ); 54 0 : } 55 : 56 0 : if( check_type==FD_CONFIGURE_CHECK_TYPE_FINI_PERM || 57 0 : check_type==FD_CONFIGURE_CHECK_TYPE_PRE_FINI || 58 0 : check_type==FD_CONFIGURE_CHECK_TYPE_POST_FINI ) { 59 0 : NOT_CONFIGURED( "device `%s` has no ethtool configuration to clear", config->net.interface ); 60 0 : } 61 : 62 0 : if( !fd_mlx5_uverbs_avail() ) NOT_CONFIGURED( "uverbs interface unavailable" ); 63 0 : CONFIGURE_OK(); 64 0 : } 65 : 66 : configure_stage_t fd_cfg_stage_mlx5 = { 67 : .name = "mlx5", 68 : .enabled = enabled, 69 : .init_perm = init_perm, 70 : .fini_perm = fini_perm, 71 : .init = init, 72 : .fini = fini, 73 : .check = check, 74 : };