@@ -58,20 +58,9 @@ struct vport_addr {
5858 bool mc_promisc ;
5959};
6060
61- enum {
62- UC_ADDR_CHANGE = BIT (0 ),
63- MC_ADDR_CHANGE = BIT (1 ),
64- PROMISC_CHANGE = BIT (3 ),
65- };
66-
6761static void esw_destroy_legacy_fdb_table (struct mlx5_eswitch * esw );
6862static void esw_cleanup_vepa_rules (struct mlx5_eswitch * esw );
6963
70- /* Vport context events */
71- #define SRIOV_VPORT_EVENTS (UC_ADDR_CHANGE | \
72- MC_ADDR_CHANGE | \
73- PROMISC_CHANGE)
74-
7564struct mlx5_vport * __must_check
7665mlx5_eswitch_get_vport (struct mlx5_eswitch * esw , u16 vport_num )
7766{
@@ -108,13 +97,13 @@ static int arm_vport_context_events_cmd(struct mlx5_core_dev *dev, u16 vport,
10897
10998 MLX5_SET (nic_vport_context , nic_vport_ctx , arm_change_event , 1 );
11099
111- if (events_mask & UC_ADDR_CHANGE )
100+ if (events_mask & MLX5_VPORT_UC_ADDR_CHANGE )
112101 MLX5_SET (nic_vport_context , nic_vport_ctx ,
113102 event_on_uc_address_change , 1 );
114- if (events_mask & MC_ADDR_CHANGE )
103+ if (events_mask & MLX5_VPORT_MC_ADDR_CHANGE )
115104 MLX5_SET (nic_vport_context , nic_vport_ctx ,
116105 event_on_mc_address_change , 1 );
117- if (events_mask & PROMISC_CHANGE )
106+ if (events_mask & MLX5_VPORT_PROMISC_CHANGE )
118107 MLX5_SET (nic_vport_context , nic_vport_ctx ,
119108 event_on_promisc_change , 1 );
120109
@@ -901,21 +890,21 @@ static void esw_vport_change_handle_locked(struct mlx5_vport *vport)
901890 esw_debug (dev , "vport[%d] Context Changed: perm mac: %pM\n" ,
902891 vport -> vport , mac );
903892
904- if (vport -> enabled_events & UC_ADDR_CHANGE ) {
893+ if (vport -> enabled_events & MLX5_VPORT_UC_ADDR_CHANGE ) {
905894 esw_update_vport_addr_list (esw , vport , MLX5_NVPRT_LIST_TYPE_UC );
906895 esw_apply_vport_addr_list (esw , vport , MLX5_NVPRT_LIST_TYPE_UC );
907896 }
908897
909- if (vport -> enabled_events & MC_ADDR_CHANGE )
898+ if (vport -> enabled_events & MLX5_VPORT_MC_ADDR_CHANGE )
910899 esw_update_vport_addr_list (esw , vport , MLX5_NVPRT_LIST_TYPE_MC );
911900
912- if (vport -> enabled_events & PROMISC_CHANGE ) {
901+ if (vport -> enabled_events & MLX5_VPORT_PROMISC_CHANGE ) {
913902 esw_update_vport_rx_mode (esw , vport );
914903 if (!IS_ERR_OR_NULL (vport -> allmulti_rule ))
915904 esw_update_vport_mc_promisc (esw , vport );
916905 }
917906
918- if (vport -> enabled_events & (PROMISC_CHANGE | MC_ADDR_CHANGE ))
907+ if (vport -> enabled_events & (MLX5_VPORT_PROMISC_CHANGE | MLX5_VPORT_MC_ADDR_CHANGE ))
919908 esw_apply_vport_addr_list (esw , vport , MLX5_NVPRT_LIST_TYPE_MC );
920909
921910 esw_debug (esw -> dev , "vport[%d] Context Changed: Done\n" , vport -> vport );
@@ -1649,7 +1638,7 @@ static void esw_vport_destroy_drop_counters(struct mlx5_vport *vport)
16491638}
16501639
16511640static void esw_enable_vport (struct mlx5_eswitch * esw , struct mlx5_vport * vport ,
1652- int enable_events )
1641+ enum mlx5_eswitch_vport_event enabled_events )
16531642{
16541643 u16 vport_num = vport -> vport ;
16551644
@@ -1671,7 +1660,7 @@ static void esw_enable_vport(struct mlx5_eswitch *esw, struct mlx5_vport *vport,
16711660 esw_warn (esw -> dev , "Failed to attach vport %d to eswitch rate limiter" , vport_num );
16721661
16731662 /* Sync with current vport context */
1674- vport -> enabled_events = enable_events ;
1663+ vport -> enabled_events = enabled_events ;
16751664 vport -> enabled = true;
16761665
16771666 /* Esw manager is trusted by default. Host PF (vport 0) is trusted as well
@@ -1800,11 +1789,51 @@ static void mlx5_eswitch_event_handlers_unregister(struct mlx5_eswitch *esw)
18001789/* Public E-Switch API */
18011790#define ESW_ALLOWED (esw ) ((esw) && MLX5_ESWITCH_MANAGER((esw)->dev))
18021791
1803- int mlx5_eswitch_enable (struct mlx5_eswitch * esw , int mode )
1792+ /* mlx5_eswitch_enable_pf_vf_vports() enables vports of PF, ECPF and VFs
1793+ * whichever are present on the eswitch.
1794+ */
1795+ void
1796+ mlx5_eswitch_enable_pf_vf_vports (struct mlx5_eswitch * esw ,
1797+ enum mlx5_eswitch_vport_event enabled_events )
1798+ {
1799+ struct mlx5_vport * vport ;
1800+ int i ;
1801+
1802+ /* Enable PF vport */
1803+ vport = mlx5_eswitch_get_vport (esw , MLX5_VPORT_PF );
1804+ esw_enable_vport (esw , vport , enabled_events );
1805+
1806+ /* Enable ECPF vports */
1807+ if (mlx5_ecpf_vport_exists (esw -> dev )) {
1808+ vport = mlx5_eswitch_get_vport (esw , MLX5_VPORT_ECPF );
1809+ esw_enable_vport (esw , vport , enabled_events );
1810+ }
1811+
1812+ /* Enable VF vports */
1813+ mlx5_esw_for_each_vf_vport (esw , i , vport , esw -> esw_funcs .num_vfs )
1814+ esw_enable_vport (esw , vport , enabled_events );
1815+ }
1816+
1817+ /* mlx5_eswitch_disable_pf_vf_vports() disables vports of PF, ECPF and VFs
1818+ * whichever are previously enabled on the eswitch.
1819+ */
1820+ void mlx5_eswitch_disable_pf_vf_vports (struct mlx5_eswitch * esw )
18041821{
18051822 struct mlx5_vport * vport ;
1823+ int i ;
1824+
1825+ mlx5_esw_for_all_vports_reverse (esw , i , vport )
1826+ esw_disable_vport (esw , vport );
1827+ }
1828+
1829+ #define MLX5_LEGACY_SRIOV_VPORT_EVENTS (MLX5_VPORT_UC_ADDR_CHANGE | \
1830+ MLX5_VPORT_MC_ADDR_CHANGE | \
1831+ MLX5_VPORT_PROMISC_CHANGE)
1832+
1833+ int mlx5_eswitch_enable (struct mlx5_eswitch * esw , int mode )
1834+ {
1835+ int enabled_events ;
18061836 int err ;
1807- int i , enabled_events ;
18081837
18091838 if (!ESW_ALLOWED (esw ) ||
18101839 !MLX5_CAP_ESW_FLOWTABLE_FDB (esw -> dev , ft_support )) {
@@ -1837,22 +1866,10 @@ int mlx5_eswitch_enable(struct mlx5_eswitch *esw, int mode)
18371866 if (err )
18381867 goto abort ;
18391868
1840- enabled_events = (mode == MLX5_ESWITCH_LEGACY ) ? SRIOV_VPORT_EVENTS :
1841- UC_ADDR_CHANGE ;
1869+ enabled_events = (mode == MLX5_ESWITCH_LEGACY ) ? MLX5_LEGACY_SRIOV_VPORT_EVENTS :
1870+ MLX5_VPORT_UC_ADDR_CHANGE ;
18421871
1843- /* Enable PF vport */
1844- vport = mlx5_eswitch_get_vport (esw , MLX5_VPORT_PF );
1845- esw_enable_vport (esw , vport , enabled_events );
1846-
1847- /* Enable ECPF vports */
1848- if (mlx5_ecpf_vport_exists (esw -> dev )) {
1849- vport = mlx5_eswitch_get_vport (esw , MLX5_VPORT_ECPF );
1850- esw_enable_vport (esw , vport , enabled_events );
1851- }
1852-
1853- /* Enable VF vports */
1854- mlx5_esw_for_each_vf_vport (esw , i , vport , esw -> esw_funcs .num_vfs )
1855- esw_enable_vport (esw , vport , enabled_events );
1872+ mlx5_eswitch_enable_pf_vf_vports (esw , enabled_events );
18561873
18571874 mlx5_eswitch_event_handlers_register (esw );
18581875
@@ -1876,9 +1893,7 @@ int mlx5_eswitch_enable(struct mlx5_eswitch *esw, int mode)
18761893void mlx5_eswitch_disable (struct mlx5_eswitch * esw )
18771894{
18781895 struct esw_mc_addr * mc_promisc ;
1879- struct mlx5_vport * vport ;
18801896 int old_mode ;
1881- int i ;
18821897
18831898 if (!ESW_ALLOWED (esw ) || esw -> mode == MLX5_ESWITCH_NONE )
18841899 return ;
@@ -1890,8 +1905,7 @@ void mlx5_eswitch_disable(struct mlx5_eswitch *esw)
18901905 mc_promisc = & esw -> mc_promisc ;
18911906 mlx5_eswitch_event_handlers_unregister (esw );
18921907
1893- mlx5_esw_for_all_vports (esw , i , vport )
1894- esw_disable_vport (esw , vport );
1908+ mlx5_eswitch_disable_pf_vf_vports (esw );
18951909
18961910 if (mc_promisc && mc_promisc -> uplink_rule )
18971911 mlx5_del_flow_rules (mc_promisc -> uplink_rule );
0 commit comments