Skip to content

Commit 01de00f

Browse files
pmachatakuba-moo
authored andcommitted
mlxsw: spectrum_fid: Privatize FID families
Currently, mlxsw always uses a "controlled" flood mode on all Nvidia Spectrum generations. The following patches will however introduce a possibility to run a "CFF" (for Compressed FID Flooding) mode on newer machines, if the FW supports it. Several operations will differ between how they need to be done in controlled mode vs. CFF mode. Thus the per-FID-family ops will differ between controlled and CFF, thus the FID family array as such will differ depending on whether the mode negotiated with FW is controlled or CFF. The simple approach of having several globally visible arrays for spectrum.c to statically choose from no longer works. Instead privatize all FID initialization and finalization logic, and expose it as ops instead. Signed-off-by: Petr Machata <petrm@nvidia.com> Reviewed-by: Ido Schimmel <idosch@nvidia.com> Link: https://lore.kernel.org/r/d3fa390d97cf3dbd2f7a28741be69b311e2059e4.1701183891.git.petrm@nvidia.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 7edce37 commit 01de00f

File tree

3 files changed

+44
-20
lines changed

3 files changed

+44
-20
lines changed

drivers/net/ethernet/mellanox/mlxsw/spectrum.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3190,10 +3190,10 @@ static int mlxsw_sp_init(struct mlxsw_core *mlxsw_core,
31903190
goto err_lag_init;
31913191
}
31923192

3193-
err = mlxsw_sp_fids_init(mlxsw_sp);
3193+
err = mlxsw_sp->fid_core_ops->init(mlxsw_sp);
31943194
if (err) {
31953195
dev_err(mlxsw_sp->bus_info->dev, "Failed to initialize FIDs\n");
3196-
goto err_fids_init;
3196+
goto err_fid_core_init;
31973197
}
31983198

31993199
err = mlxsw_sp_policers_init(mlxsw_sp);
@@ -3379,8 +3379,8 @@ static int mlxsw_sp_init(struct mlxsw_core *mlxsw_core,
33793379
err_traps_init:
33803380
mlxsw_sp_policers_fini(mlxsw_sp);
33813381
err_policers_init:
3382-
mlxsw_sp_fids_fini(mlxsw_sp);
3383-
err_fids_init:
3382+
mlxsw_sp->fid_core_ops->fini(mlxsw_sp);
3383+
err_fid_core_init:
33843384
mlxsw_sp_lag_fini(mlxsw_sp);
33853385
err_lag_init:
33863386
mlxsw_sp_pgt_fini(mlxsw_sp);
@@ -3416,7 +3416,7 @@ static int mlxsw_sp1_init(struct mlxsw_core *mlxsw_core,
34163416
mlxsw_sp->router_ops = &mlxsw_sp1_router_ops;
34173417
mlxsw_sp->listeners = mlxsw_sp1_listener;
34183418
mlxsw_sp->listeners_count = ARRAY_SIZE(mlxsw_sp1_listener);
3419-
mlxsw_sp->fid_family_arr = mlxsw_sp1_fid_family_arr;
3419+
mlxsw_sp->fid_core_ops = &mlxsw_sp1_fid_core_ops;
34203420
mlxsw_sp->lowest_shaper_bs = MLXSW_REG_QEEC_LOWEST_SHAPER_BS_SP1;
34213421
mlxsw_sp->pgt_smpe_index_valid = true;
34223422

@@ -3450,7 +3450,7 @@ static int mlxsw_sp2_init(struct mlxsw_core *mlxsw_core,
34503450
mlxsw_sp->router_ops = &mlxsw_sp2_router_ops;
34513451
mlxsw_sp->listeners = mlxsw_sp2_listener;
34523452
mlxsw_sp->listeners_count = ARRAY_SIZE(mlxsw_sp2_listener);
3453-
mlxsw_sp->fid_family_arr = mlxsw_sp2_fid_family_arr;
3453+
mlxsw_sp->fid_core_ops = &mlxsw_sp2_fid_core_ops;
34543454
mlxsw_sp->lowest_shaper_bs = MLXSW_REG_QEEC_LOWEST_SHAPER_BS_SP2;
34553455
mlxsw_sp->pgt_smpe_index_valid = false;
34563456

@@ -3484,7 +3484,7 @@ static int mlxsw_sp3_init(struct mlxsw_core *mlxsw_core,
34843484
mlxsw_sp->router_ops = &mlxsw_sp2_router_ops;
34853485
mlxsw_sp->listeners = mlxsw_sp2_listener;
34863486
mlxsw_sp->listeners_count = ARRAY_SIZE(mlxsw_sp2_listener);
3487-
mlxsw_sp->fid_family_arr = mlxsw_sp2_fid_family_arr;
3487+
mlxsw_sp->fid_core_ops = &mlxsw_sp2_fid_core_ops;
34883488
mlxsw_sp->lowest_shaper_bs = MLXSW_REG_QEEC_LOWEST_SHAPER_BS_SP3;
34893489
mlxsw_sp->pgt_smpe_index_valid = false;
34903490

@@ -3518,7 +3518,7 @@ static int mlxsw_sp4_init(struct mlxsw_core *mlxsw_core,
35183518
mlxsw_sp->router_ops = &mlxsw_sp2_router_ops;
35193519
mlxsw_sp->listeners = mlxsw_sp2_listener;
35203520
mlxsw_sp->listeners_count = ARRAY_SIZE(mlxsw_sp2_listener);
3521-
mlxsw_sp->fid_family_arr = mlxsw_sp2_fid_family_arr;
3521+
mlxsw_sp->fid_core_ops = &mlxsw_sp2_fid_core_ops;
35223522
mlxsw_sp->lowest_shaper_bs = MLXSW_REG_QEEC_LOWEST_SHAPER_BS_SP4;
35233523
mlxsw_sp->pgt_smpe_index_valid = false;
35243524

@@ -3552,7 +3552,7 @@ static void mlxsw_sp_fini(struct mlxsw_core *mlxsw_core)
35523552
mlxsw_sp_devlink_traps_fini(mlxsw_sp);
35533553
mlxsw_sp_traps_fini(mlxsw_sp);
35543554
mlxsw_sp_policers_fini(mlxsw_sp);
3555-
mlxsw_sp_fids_fini(mlxsw_sp);
3555+
mlxsw_sp->fid_core_ops->fini(mlxsw_sp);
35563556
mlxsw_sp_lag_fini(mlxsw_sp);
35573557
mlxsw_sp_pgt_fini(mlxsw_sp);
35583558
mlxsw_sp_kvdl_fini(mlxsw_sp);

drivers/net/ethernet/mellanox/mlxsw/spectrum.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ struct mlxsw_sp {
205205
const struct mlxsw_sp_mall_ops *mall_ops;
206206
const struct mlxsw_sp_router_ops *router_ops;
207207
const struct mlxsw_listener *listeners;
208-
const struct mlxsw_sp_fid_family **fid_family_arr;
208+
const struct mlxsw_sp_fid_core_ops *fid_core_ops;
209209
size_t listeners_count;
210210
u32 lowest_shaper_bs;
211211
struct rhashtable ipv6_addr_ht;
@@ -252,6 +252,11 @@ struct mlxsw_sp_ptp_ops {
252252
const struct mlxsw_tx_info *tx_info);
253253
};
254254

255+
struct mlxsw_sp_fid_core_ops {
256+
int (*init)(struct mlxsw_sp *mlxsw_sp);
257+
void (*fini)(struct mlxsw_sp *mlxsw_sp);
258+
};
259+
255260
static inline struct mlxsw_sp_upper *
256261
mlxsw_sp_lag_get(struct mlxsw_sp *mlxsw_sp, u16 lag_id)
257262
{
@@ -1321,11 +1326,9 @@ struct mlxsw_sp_fid *mlxsw_sp_fid_dummy_get(struct mlxsw_sp *mlxsw_sp);
13211326
void mlxsw_sp_fid_put(struct mlxsw_sp_fid *fid);
13221327
int mlxsw_sp_port_fids_init(struct mlxsw_sp_port *mlxsw_sp_port);
13231328
void mlxsw_sp_port_fids_fini(struct mlxsw_sp_port *mlxsw_sp_port);
1324-
int mlxsw_sp_fids_init(struct mlxsw_sp *mlxsw_sp);
1325-
void mlxsw_sp_fids_fini(struct mlxsw_sp *mlxsw_sp);
13261329

1327-
extern const struct mlxsw_sp_fid_family *mlxsw_sp1_fid_family_arr[];
1328-
extern const struct mlxsw_sp_fid_family *mlxsw_sp2_fid_family_arr[];
1330+
extern const struct mlxsw_sp_fid_core_ops mlxsw_sp1_fid_core_ops;
1331+
extern const struct mlxsw_sp_fid_core_ops mlxsw_sp2_fid_core_ops;
13291332

13301333
/* spectrum_mr.c */
13311334
enum mlxsw_sp_mr_route_prio {

drivers/net/ethernet/mellanox/mlxsw/spectrum_fid.c

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,7 +1486,7 @@ static const struct mlxsw_sp_fid_family mlxsw_sp_fid_rfid_family = {
14861486
.smpe_index_valid = false,
14871487
};
14881488

1489-
const struct mlxsw_sp_fid_family *mlxsw_sp1_fid_family_arr[] = {
1489+
static const struct mlxsw_sp_fid_family *mlxsw_sp1_fid_family_arr[] = {
14901490
[MLXSW_SP_FID_TYPE_8021Q] = &mlxsw_sp1_fid_8021q_family,
14911491
[MLXSW_SP_FID_TYPE_8021D] = &mlxsw_sp1_fid_8021d_family,
14921492
[MLXSW_SP_FID_TYPE_DUMMY] = &mlxsw_sp1_fid_dummy_family,
@@ -1529,7 +1529,7 @@ static const struct mlxsw_sp_fid_family mlxsw_sp2_fid_dummy_family = {
15291529
.smpe_index_valid = false,
15301530
};
15311531

1532-
const struct mlxsw_sp_fid_family *mlxsw_sp2_fid_family_arr[] = {
1532+
static const struct mlxsw_sp_fid_family *mlxsw_sp2_fid_family_arr[] = {
15331533
[MLXSW_SP_FID_TYPE_8021Q] = &mlxsw_sp2_fid_8021q_family,
15341534
[MLXSW_SP_FID_TYPE_8021D] = &mlxsw_sp2_fid_8021d_family,
15351535
[MLXSW_SP_FID_TYPE_DUMMY] = &mlxsw_sp2_fid_dummy_family,
@@ -1799,7 +1799,9 @@ void mlxsw_sp_port_fids_fini(struct mlxsw_sp_port *mlxsw_sp_port)
17991799
mlxsw_sp->fid_core->port_fid_mappings[mlxsw_sp_port->local_port] = 0;
18001800
}
18011801

1802-
int mlxsw_sp_fids_init(struct mlxsw_sp *mlxsw_sp)
1802+
static int
1803+
mlxsw_sp_fids_init(struct mlxsw_sp *mlxsw_sp,
1804+
const struct mlxsw_sp_fid_family *fid_family_arr[])
18031805
{
18041806
unsigned int max_ports = mlxsw_core_max_ports(mlxsw_sp->core);
18051807
struct mlxsw_sp_fid_core *fid_core;
@@ -1826,8 +1828,7 @@ int mlxsw_sp_fids_init(struct mlxsw_sp *mlxsw_sp)
18261828
}
18271829

18281830
for (i = 0; i < MLXSW_SP_FID_TYPE_MAX; i++) {
1829-
err = mlxsw_sp_fid_family_register(mlxsw_sp,
1830-
mlxsw_sp->fid_family_arr[i]);
1831+
err = mlxsw_sp_fid_family_register(mlxsw_sp, fid_family_arr[i]);
18311832

18321833
if (err)
18331834
goto err_fid_ops_register;
@@ -1852,7 +1853,7 @@ int mlxsw_sp_fids_init(struct mlxsw_sp *mlxsw_sp)
18521853
return err;
18531854
}
18541855

1855-
void mlxsw_sp_fids_fini(struct mlxsw_sp *mlxsw_sp)
1856+
static void mlxsw_sp_fids_fini(struct mlxsw_sp *mlxsw_sp)
18561857
{
18571858
struct mlxsw_sp_fid_core *fid_core = mlxsw_sp->fid_core;
18581859
int i;
@@ -1865,3 +1866,23 @@ void mlxsw_sp_fids_fini(struct mlxsw_sp *mlxsw_sp)
18651866
rhashtable_destroy(&fid_core->fid_ht);
18661867
kfree(fid_core);
18671868
}
1869+
1870+
static int mlxsw_sp1_fids_init(struct mlxsw_sp *mlxsw_sp)
1871+
{
1872+
return mlxsw_sp_fids_init(mlxsw_sp, mlxsw_sp1_fid_family_arr);
1873+
}
1874+
1875+
const struct mlxsw_sp_fid_core_ops mlxsw_sp1_fid_core_ops = {
1876+
.init = mlxsw_sp1_fids_init,
1877+
.fini = mlxsw_sp_fids_fini,
1878+
};
1879+
1880+
static int mlxsw_sp2_fids_init(struct mlxsw_sp *mlxsw_sp)
1881+
{
1882+
return mlxsw_sp_fids_init(mlxsw_sp, mlxsw_sp2_fid_family_arr);
1883+
}
1884+
1885+
const struct mlxsw_sp_fid_core_ops mlxsw_sp2_fid_core_ops = {
1886+
.init = mlxsw_sp2_fids_init,
1887+
.fini = mlxsw_sp_fids_fini,
1888+
};

0 commit comments

Comments
 (0)