@@ -1864,18 +1864,6 @@ esw_check_vport_match_metadata_supported(const struct mlx5_eswitch *esw)
18641864 return true;
18651865}
18661866
1867- static bool
1868- esw_check_vport_match_metadata_mandatory (const struct mlx5_eswitch * esw )
1869- {
1870- return mlx5_core_mp_enabled (esw -> dev );
1871- }
1872-
1873- static bool esw_use_vport_metadata (const struct mlx5_eswitch * esw )
1874- {
1875- return esw_check_vport_match_metadata_mandatory (esw ) &&
1876- esw_check_vport_match_metadata_supported (esw );
1877- }
1878-
18791867u32 mlx5_esw_match_metadata_alloc (struct mlx5_eswitch * esw )
18801868{
18811869 u32 num_vports = GENMASK (ESW_VPORT_BITS - 1 , 0 ) - 1 ;
@@ -1908,9 +1896,6 @@ void mlx5_esw_match_metadata_free(struct mlx5_eswitch *esw, u32 metadata)
19081896static int esw_offloads_vport_metadata_setup (struct mlx5_eswitch * esw ,
19091897 struct mlx5_vport * vport )
19101898{
1911- if (vport -> vport == MLX5_VPORT_UPLINK )
1912- return 0 ;
1913-
19141899 vport -> default_metadata = mlx5_esw_match_metadata_alloc (esw );
19151900 vport -> metadata = vport -> default_metadata ;
19161901 return vport -> metadata ? 0 : - ENOSPC ;
@@ -1919,26 +1904,56 @@ static int esw_offloads_vport_metadata_setup(struct mlx5_eswitch *esw,
19191904static void esw_offloads_vport_metadata_cleanup (struct mlx5_eswitch * esw ,
19201905 struct mlx5_vport * vport )
19211906{
1922- if (vport -> vport == MLX5_VPORT_UPLINK || !vport -> default_metadata )
1907+ if (!vport -> default_metadata )
19231908 return ;
19241909
19251910 WARN_ON (vport -> metadata != vport -> default_metadata );
19261911 mlx5_esw_match_metadata_free (esw , vport -> default_metadata );
19271912}
19281913
1914+ static void esw_offloads_metadata_uninit (struct mlx5_eswitch * esw )
1915+ {
1916+ struct mlx5_vport * vport ;
1917+ int i ;
1918+
1919+ if (!mlx5_eswitch_vport_match_metadata_enabled (esw ))
1920+ return ;
1921+
1922+ mlx5_esw_for_all_vports_reverse (esw , i , vport )
1923+ esw_offloads_vport_metadata_cleanup (esw , vport );
1924+ }
1925+
1926+ static int esw_offloads_metadata_init (struct mlx5_eswitch * esw )
1927+ {
1928+ struct mlx5_vport * vport ;
1929+ int err ;
1930+ int i ;
1931+
1932+ if (!mlx5_eswitch_vport_match_metadata_enabled (esw ))
1933+ return 0 ;
1934+
1935+ mlx5_esw_for_all_vports (esw , i , vport ) {
1936+ err = esw_offloads_vport_metadata_setup (esw , vport );
1937+ if (err )
1938+ goto metadata_err ;
1939+ }
1940+
1941+ return 0 ;
1942+
1943+ metadata_err :
1944+ esw_offloads_metadata_uninit (esw );
1945+ return err ;
1946+ }
1947+
19291948int
19301949esw_vport_create_offloads_acl_tables (struct mlx5_eswitch * esw ,
19311950 struct mlx5_vport * vport )
19321951{
19331952 int err ;
19341953
1935- err = esw_offloads_vport_metadata_setup (esw , vport );
1936- if (err )
1937- goto metadata_err ;
1938-
19391954 err = esw_acl_ingress_ofld_setup (esw , vport );
19401955 if (err )
1941- goto ingress_err ;
1956+ return err ;
19421957
19431958 if (mlx5_eswitch_is_vf_vport (esw , vport -> vport )) {
19441959 err = esw_acl_egress_ofld_setup (esw , vport );
@@ -1950,9 +1965,6 @@ esw_vport_create_offloads_acl_tables(struct mlx5_eswitch *esw,
19501965
19511966egress_err :
19521967 esw_acl_ingress_ofld_cleanup (esw , vport );
1953- ingress_err :
1954- esw_offloads_vport_metadata_cleanup (esw , vport );
1955- metadata_err :
19561968 return err ;
19571969}
19581970
@@ -1962,22 +1974,14 @@ esw_vport_destroy_offloads_acl_tables(struct mlx5_eswitch *esw,
19621974{
19631975 esw_acl_egress_ofld_cleanup (vport );
19641976 esw_acl_ingress_ofld_cleanup (esw , vport );
1965- esw_offloads_vport_metadata_cleanup (esw , vport );
19661977}
19671978
19681979static int esw_create_uplink_offloads_acl_tables (struct mlx5_eswitch * esw )
19691980{
19701981 struct mlx5_vport * vport ;
1971- int err ;
1972-
1973- if (esw_use_vport_metadata (esw ))
1974- esw -> flags |= MLX5_ESWITCH_VPORT_MATCH_METADATA ;
19751982
19761983 vport = mlx5_eswitch_get_vport (esw , MLX5_VPORT_UPLINK );
1977- err = esw_vport_create_offloads_acl_tables (esw , vport );
1978- if (err )
1979- esw -> flags &= ~MLX5_ESWITCH_VPORT_MATCH_METADATA ;
1980- return err ;
1984+ return esw_vport_create_offloads_acl_tables (esw , vport );
19811985}
19821986
19831987static void esw_destroy_uplink_offloads_acl_tables (struct mlx5_eswitch * esw )
@@ -1986,7 +1990,6 @@ static void esw_destroy_uplink_offloads_acl_tables(struct mlx5_eswitch *esw)
19861990
19871991 vport = mlx5_eswitch_get_vport (esw , MLX5_VPORT_UPLINK );
19881992 esw_vport_destroy_offloads_acl_tables (esw , vport );
1989- esw -> flags &= ~MLX5_ESWITCH_VPORT_MATCH_METADATA ;
19901993}
19911994
19921995static int esw_offloads_steering_init (struct mlx5_eswitch * esw )
@@ -2144,7 +2147,14 @@ int esw_offloads_enable(struct mlx5_eswitch *esw)
21442147
21452148 err = mlx5_esw_host_number_init (esw );
21462149 if (err )
2147- goto err_vport_metadata ;
2150+ goto err_metadata ;
2151+
2152+ if (esw_check_vport_match_metadata_supported (esw ))
2153+ esw -> flags |= MLX5_ESWITCH_VPORT_MATCH_METADATA ;
2154+
2155+ err = esw_offloads_metadata_init (esw );
2156+ if (err )
2157+ goto err_metadata ;
21482158
21492159 err = esw_set_passing_vport_metadata (esw , true);
21502160 if (err )
@@ -2178,6 +2188,9 @@ int esw_offloads_enable(struct mlx5_eswitch *esw)
21782188err_steering_init :
21792189 esw_set_passing_vport_metadata (esw , false);
21802190err_vport_metadata :
2191+ esw_offloads_metadata_uninit (esw );
2192+ err_metadata :
2193+ esw -> flags &= ~MLX5_ESWITCH_VPORT_MATCH_METADATA ;
21812194 mlx5_rdma_disable_roce (esw -> dev );
21822195 mutex_destroy (& esw -> offloads .termtbl_mutex );
21832196 return err ;
@@ -2211,6 +2224,8 @@ void esw_offloads_disable(struct mlx5_eswitch *esw)
22112224 esw_offloads_unload_rep (esw , MLX5_VPORT_UPLINK );
22122225 esw_set_passing_vport_metadata (esw , false);
22132226 esw_offloads_steering_cleanup (esw );
2227+ esw_offloads_metadata_uninit (esw );
2228+ esw -> flags &= ~MLX5_ESWITCH_VPORT_MATCH_METADATA ;
22142229 mlx5_rdma_disable_roce (esw -> dev );
22152230 mutex_destroy (& esw -> offloads .termtbl_mutex );
22162231 esw -> offloads .encap = DEVLINK_ESWITCH_ENCAP_MODE_NONE ;
0 commit comments