Skip to content
/ linux Public

Commit 6445eef

Browse files
Jiri Pirkodavem330
authored andcommitted
mlxsw: spectrum: Add port to linecard mapping
For each port get slot_index using PMLP register. For ports residing on a linecard, identify it with the linecard by setting mapping using devlink_port_linecard_set() helper. Use linecard slot index for PMTDB register queries. Signed-off-by: Jiri Pirko <jiri@nvidia.com> Signed-off-by: Ido Schimmel <idosch@nvidia.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 45bf3b7 commit 6445eef

File tree

8 files changed

+107
-33
lines changed

8 files changed

+107
-33
lines changed

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ struct mlxsw_core_port {
4848
struct devlink_port devlink_port;
4949
void *port_driver_priv;
5050
u16 local_port;
51+
struct mlxsw_linecard *linecard;
5152
};
5253

5354
void *mlxsw_core_port_driver_priv(struct mlxsw_core_port *mlxsw_core_port)
@@ -2975,7 +2976,7 @@ EXPORT_SYMBOL(mlxsw_core_res_get);
29752976

29762977
static int __mlxsw_core_port_init(struct mlxsw_core *mlxsw_core, u16 local_port,
29772978
enum devlink_port_flavour flavour,
2978-
u32 port_number, bool split,
2979+
u8 slot_index, u32 port_number, bool split,
29792980
u32 split_port_subnumber,
29802981
bool splittable, u32 lanes,
29812982
const unsigned char *switch_id,
@@ -2998,6 +2999,15 @@ static int __mlxsw_core_port_init(struct mlxsw_core *mlxsw_core, u16 local_port,
29982999
attrs.switch_id.id_len = switch_id_len;
29993000
mlxsw_core_port->local_port = local_port;
30003001
devlink_port_attrs_set(devlink_port, &attrs);
3002+
if (slot_index) {
3003+
struct mlxsw_linecard *linecard;
3004+
3005+
linecard = mlxsw_linecard_get(mlxsw_core->linecards,
3006+
slot_index);
3007+
mlxsw_core_port->linecard = linecard;
3008+
devlink_port_linecard_set(devlink_port,
3009+
linecard->devlink_linecard);
3010+
}
30013011
err = devl_port_register(devlink, devlink_port, local_port);
30023012
if (err)
30033013
memset(mlxsw_core_port, 0, sizeof(*mlxsw_core_port));
@@ -3015,7 +3025,7 @@ static void __mlxsw_core_port_fini(struct mlxsw_core *mlxsw_core, u16 local_port
30153025
}
30163026

30173027
int mlxsw_core_port_init(struct mlxsw_core *mlxsw_core, u16 local_port,
3018-
u32 port_number, bool split,
3028+
u8 slot_index, u32 port_number, bool split,
30193029
u32 split_port_subnumber,
30203030
bool splittable, u32 lanes,
30213031
const unsigned char *switch_id,
@@ -3024,7 +3034,7 @@ int mlxsw_core_port_init(struct mlxsw_core *mlxsw_core, u16 local_port,
30243034
int err;
30253035

30263036
err = __mlxsw_core_port_init(mlxsw_core, local_port,
3027-
DEVLINK_PORT_FLAVOUR_PHYSICAL,
3037+
DEVLINK_PORT_FLAVOUR_PHYSICAL, slot_index,
30283038
port_number, split, split_port_subnumber,
30293039
splittable, lanes,
30303040
switch_id, switch_id_len);
@@ -3055,7 +3065,7 @@ int mlxsw_core_cpu_port_init(struct mlxsw_core *mlxsw_core,
30553065

30563066
err = __mlxsw_core_port_init(mlxsw_core, MLXSW_PORT_CPU_PORT,
30573067
DEVLINK_PORT_FLAVOUR_CPU,
3058-
0, false, 0, false, 0,
3068+
0, 0, false, 0, false, 0,
30593069
switch_id, switch_id_len);
30603070
if (err)
30613071
return err;
@@ -3131,6 +3141,16 @@ mlxsw_core_port_devlink_port_get(struct mlxsw_core *mlxsw_core,
31313141
}
31323142
EXPORT_SYMBOL(mlxsw_core_port_devlink_port_get);
31333143

3144+
struct mlxsw_linecard *
3145+
mlxsw_core_port_linecard_get(struct mlxsw_core *mlxsw_core,
3146+
u16 local_port)
3147+
{
3148+
struct mlxsw_core_port *mlxsw_core_port =
3149+
&mlxsw_core->ports[local_port];
3150+
3151+
return mlxsw_core_port->linecard;
3152+
}
3153+
31343154
bool mlxsw_core_port_is_xm(const struct mlxsw_core *mlxsw_core, u16 local_port)
31353155
{
31363156
const struct mlxsw_bus_info *bus_info = mlxsw_core->bus_info;

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,8 @@ void mlxsw_core_lag_mapping_clear(struct mlxsw_core *mlxsw_core,
236236

237237
void *mlxsw_core_port_driver_priv(struct mlxsw_core_port *mlxsw_core_port);
238238
int mlxsw_core_port_init(struct mlxsw_core *mlxsw_core, u16 local_port,
239-
u32 port_number, bool split, u32 split_port_subnumber,
239+
u8 slot_index, u32 port_number, bool split,
240+
u32 split_port_subnumber,
240241
bool splittable, u32 lanes,
241242
const unsigned char *switch_id,
242243
unsigned char switch_id_len);
@@ -257,6 +258,9 @@ enum devlink_port_type mlxsw_core_port_type_get(struct mlxsw_core *mlxsw_core,
257258
struct devlink_port *
258259
mlxsw_core_port_devlink_port_get(struct mlxsw_core *mlxsw_core,
259260
u16 local_port);
261+
struct mlxsw_linecard *
262+
mlxsw_core_port_linecard_get(struct mlxsw_core *mlxsw_core,
263+
u16 local_port);
260264
bool mlxsw_core_port_is_xm(const struct mlxsw_core *mlxsw_core, u16 local_port);
261265
void mlxsw_core_ports_remove_selected(struct mlxsw_core *mlxsw_core,
262266
bool (*selector)(void *priv,

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,15 @@ mlxsw_linecard_ini_in_use_wait(struct mlxsw_core *mlxsw_core,
481481
return 0;
482482
}
483483

484+
static bool mlxsw_linecard_port_selector(void *priv, u16 local_port)
485+
{
486+
struct mlxsw_linecard *linecard = priv;
487+
struct mlxsw_core *mlxsw_core;
488+
489+
mlxsw_core = linecard->linecards->mlxsw_core;
490+
return linecard == mlxsw_core_port_linecard_get(mlxsw_core, local_port);
491+
}
492+
484493
static int mlxsw_linecard_provision(struct devlink_linecard *devlink_linecard,
485494
void *priv, const char *type,
486495
const void *type_priv,
@@ -531,6 +540,10 @@ static int mlxsw_linecard_unprovision(struct devlink_linecard *devlink_linecard,
531540

532541
mlxsw_core = linecard->linecards->mlxsw_core;
533542

543+
mlxsw_core_ports_remove_selected(mlxsw_core,
544+
mlxsw_linecard_port_selector,
545+
linecard);
546+
534547
err = mlxsw_linecard_ini_in_use_wait(mlxsw_core, linecard, extack);
535548
if (err)
536549
goto err_out;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ mlxsw_m_port_create(struct mlxsw_m *mlxsw_m, u16 local_port, u8 module)
223223
struct net_device *dev;
224224
int err;
225225

226-
err = mlxsw_core_port_init(mlxsw_m->core, local_port,
226+
err = mlxsw_core_port_init(mlxsw_m->core, local_port, 0,
227227
module + 1, false, 0, false,
228228
0, mlxsw_m->base_mac,
229229
sizeof(mlxsw_m->base_mac));

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4325,6 +4325,15 @@ MLXSW_ITEM32(reg, pmlp, width, 0x00, 0, 8);
43254325
*/
43264326
MLXSW_ITEM32_INDEXED(reg, pmlp, module, 0x04, 0, 8, 0x04, 0x00, false);
43274327

4328+
/* reg_pmlp_slot_index
4329+
* Module number.
4330+
* Slot_index
4331+
* Slot_index = 0 represent the onboard (motherboard).
4332+
* In case of non-modular system only slot_index = 0 is available.
4333+
* Access: RW
4334+
*/
4335+
MLXSW_ITEM32_INDEXED(reg, pmlp, slot_index, 0x04, 8, 4, 0x04, 0x00, false);
4336+
43284337
/* reg_pmlp_tx_lane
43294338
* Tx Lane. When rxtx field is cleared, this field is used for Rx as well.
43304339
* Access: RW

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

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -492,11 +492,13 @@ mlxsw_sp_port_module_info_parse(struct mlxsw_sp *mlxsw_sp,
492492
{
493493
bool separate_rxtx;
494494
u8 first_lane;
495+
u8 slot_index;
495496
u8 module;
496497
u8 width;
497498
int i;
498499

499500
module = mlxsw_reg_pmlp_module_get(pmlp_pl, 0);
501+
slot_index = mlxsw_reg_pmlp_slot_index_get(pmlp_pl, 0);
500502
width = mlxsw_reg_pmlp_width_get(pmlp_pl);
501503
separate_rxtx = mlxsw_reg_pmlp_rxtx_get(pmlp_pl);
502504
first_lane = mlxsw_reg_pmlp_tx_lane_get(pmlp_pl, 0);
@@ -513,6 +515,11 @@ mlxsw_sp_port_module_info_parse(struct mlxsw_sp *mlxsw_sp,
513515
local_port);
514516
return -EINVAL;
515517
}
518+
if (mlxsw_reg_pmlp_slot_index_get(pmlp_pl, i) != slot_index) {
519+
dev_err(mlxsw_sp->bus_info->dev, "Port %d: Unsupported module config: contains multiple slot indexes\n",
520+
local_port);
521+
return -EINVAL;
522+
}
516523
if (separate_rxtx &&
517524
mlxsw_reg_pmlp_tx_lane_get(pmlp_pl, i) !=
518525
mlxsw_reg_pmlp_rx_lane_get(pmlp_pl, i)) {
@@ -528,6 +535,7 @@ mlxsw_sp_port_module_info_parse(struct mlxsw_sp *mlxsw_sp,
528535
}
529536

530537
port_mapping->module = module;
538+
port_mapping->slot_index = slot_index;
531539
port_mapping->width = width;
532540
port_mapping->module_width = width;
533541
port_mapping->lane = mlxsw_reg_pmlp_tx_lane_get(pmlp_pl, 0);
@@ -556,11 +564,14 @@ mlxsw_sp_port_module_map(struct mlxsw_sp *mlxsw_sp, u16 local_port,
556564
char pmlp_pl[MLXSW_REG_PMLP_LEN];
557565
int i, err;
558566

559-
mlxsw_env_module_port_map(mlxsw_sp->core, 0, port_mapping->module);
567+
mlxsw_env_module_port_map(mlxsw_sp->core, port_mapping->slot_index,
568+
port_mapping->module);
560569

561570
mlxsw_reg_pmlp_pack(pmlp_pl, local_port);
562571
mlxsw_reg_pmlp_width_set(pmlp_pl, port_mapping->width);
563572
for (i = 0; i < port_mapping->width; i++) {
573+
mlxsw_reg_pmlp_slot_index_set(pmlp_pl, i,
574+
port_mapping->slot_index);
564575
mlxsw_reg_pmlp_module_set(pmlp_pl, i, port_mapping->module);
565576
mlxsw_reg_pmlp_tx_lane_set(pmlp_pl, i, port_mapping->lane + i); /* Rx & Tx */
566577
}
@@ -571,7 +582,8 @@ mlxsw_sp_port_module_map(struct mlxsw_sp *mlxsw_sp, u16 local_port,
571582
return 0;
572583

573584
err_pmlp_write:
574-
mlxsw_env_module_port_unmap(mlxsw_sp->core, 0, port_mapping->module);
585+
mlxsw_env_module_port_unmap(mlxsw_sp->core, port_mapping->slot_index,
586+
port_mapping->module);
575587
return err;
576588
}
577589

@@ -592,7 +604,8 @@ static int mlxsw_sp_port_open(struct net_device *dev)
592604
struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
593605
int err;
594606

595-
err = mlxsw_env_module_port_up(mlxsw_sp->core, 0,
607+
err = mlxsw_env_module_port_up(mlxsw_sp->core,
608+
mlxsw_sp_port->mapping.slot_index,
596609
mlxsw_sp_port->mapping.module);
597610
if (err)
598611
return err;
@@ -603,7 +616,8 @@ static int mlxsw_sp_port_open(struct net_device *dev)
603616
return 0;
604617

605618
err_port_admin_status_set:
606-
mlxsw_env_module_port_down(mlxsw_sp->core, 0,
619+
mlxsw_env_module_port_down(mlxsw_sp->core,
620+
mlxsw_sp_port->mapping.slot_index,
607621
mlxsw_sp_port->mapping.module);
608622
return err;
609623
}
@@ -615,7 +629,8 @@ static int mlxsw_sp_port_stop(struct net_device *dev)
615629

616630
netif_stop_queue(dev);
617631
mlxsw_sp_port_admin_status_set(mlxsw_sp_port, false);
618-
mlxsw_env_module_port_down(mlxsw_sp->core, 0,
632+
mlxsw_env_module_port_down(mlxsw_sp->core,
633+
mlxsw_sp_port->mapping.slot_index,
619634
mlxsw_sp_port->mapping.module);
620635
return 0;
621636
}
@@ -1462,12 +1477,13 @@ static int mlxsw_sp_port_tc_mc_mode_set(struct mlxsw_sp_port *mlxsw_sp_port,
14621477
static int mlxsw_sp_port_overheat_init_val_set(struct mlxsw_sp_port *mlxsw_sp_port)
14631478
{
14641479
struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
1480+
u8 slot_index = mlxsw_sp_port->mapping.slot_index;
14651481
u8 module = mlxsw_sp_port->mapping.module;
14661482
u64 overheat_counter;
14671483
int err;
14681484

1469-
err = mlxsw_env_module_overheat_counter_get(mlxsw_sp->core, 0, module,
1470-
&overheat_counter);
1485+
err = mlxsw_env_module_overheat_counter_get(mlxsw_sp->core, slot_index,
1486+
module, &overheat_counter);
14711487
if (err)
14721488
return err;
14731489

@@ -1542,7 +1558,7 @@ static int mlxsw_sp_port_create(struct mlxsw_sp *mlxsw_sp, u16 local_port,
15421558
}
15431559

15441560
splittable = lanes > 1 && !split;
1545-
err = mlxsw_core_port_init(mlxsw_sp->core, local_port,
1561+
err = mlxsw_core_port_init(mlxsw_sp->core, local_port, slot_index,
15461562
port_number, split, split_port_subnumber,
15471563
splittable, lanes, mlxsw_sp->base_mac,
15481564
sizeof(mlxsw_sp->base_mac));
@@ -1792,14 +1808,16 @@ static int mlxsw_sp_port_create(struct mlxsw_sp *mlxsw_sp, u16 local_port,
17921808
mlxsw_sp_port_swid_set(mlxsw_sp, local_port,
17931809
MLXSW_PORT_SWID_DISABLED_PORT);
17941810
err_port_swid_set:
1795-
mlxsw_sp_port_module_unmap(mlxsw_sp, local_port, 0,
1811+
mlxsw_sp_port_module_unmap(mlxsw_sp, local_port,
1812+
port_mapping->slot_index,
17961813
port_mapping->module);
17971814
return err;
17981815
}
17991816

18001817
static void mlxsw_sp_port_remove(struct mlxsw_sp *mlxsw_sp, u16 local_port)
18011818
{
18021819
struct mlxsw_sp_port *mlxsw_sp_port = mlxsw_sp->ports[local_port];
1820+
u8 slot_index = mlxsw_sp_port->mapping.slot_index;
18031821
u8 module = mlxsw_sp_port->mapping.module;
18041822

18051823
cancel_delayed_work_sync(&mlxsw_sp_port->periodic_hw_stats.update_dw);
@@ -1822,7 +1840,7 @@ static void mlxsw_sp_port_remove(struct mlxsw_sp *mlxsw_sp, u16 local_port)
18221840
mlxsw_core_port_fini(mlxsw_sp->core, local_port);
18231841
mlxsw_sp_port_swid_set(mlxsw_sp, local_port,
18241842
MLXSW_PORT_SWID_DISABLED_PORT);
1825-
mlxsw_sp_port_module_unmap(mlxsw_sp, local_port, 0, module);
1843+
mlxsw_sp_port_module_unmap(mlxsw_sp, local_port, slot_index, module);
18261844
}
18271845

18281846
static int mlxsw_sp_cpu_port_create(struct mlxsw_sp *mlxsw_sp)
@@ -2194,7 +2212,8 @@ static int mlxsw_sp_port_split(struct mlxsw_core *mlxsw_core, u16 local_port,
21942212
return -EINVAL;
21952213
}
21962214

2197-
mlxsw_reg_pmtdb_pack(pmtdb_pl, 0, mlxsw_sp_port->mapping.module,
2215+
mlxsw_reg_pmtdb_pack(pmtdb_pl, mlxsw_sp_port->mapping.slot_index,
2216+
mlxsw_sp_port->mapping.module,
21982217
mlxsw_sp_port->mapping.module_width / count,
21992218
count);
22002219
err = mlxsw_reg_query(mlxsw_core, MLXSW_REG(pmtdb), pmtdb_pl);
@@ -2259,7 +2278,8 @@ static int mlxsw_sp_port_unsplit(struct mlxsw_core *mlxsw_core, u16 local_port,
22592278
count = mlxsw_sp_port->mapping.module_width /
22602279
mlxsw_sp_port->mapping.width;
22612280

2262-
mlxsw_reg_pmtdb_pack(pmtdb_pl, 0, mlxsw_sp_port->mapping.module,
2281+
mlxsw_reg_pmtdb_pack(pmtdb_pl, mlxsw_sp_port->mapping.slot_index,
2282+
mlxsw_sp_port->mapping.module,
22632283
mlxsw_sp_port->mapping.module_width / count,
22642284
count);
22652285
err = mlxsw_reg_query(mlxsw_core, MLXSW_REG(pmtdb), pmtdb_pl);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ struct mlxsw_sp_mall_entry;
145145

146146
struct mlxsw_sp_port_mapping {
147147
u8 module;
148+
u8 slot_index;
148149
u8 width; /* Number of lanes used by the port */
149150
u8 module_width; /* Number of lanes in the module (static) */
150151
u8 lane;

0 commit comments

Comments
 (0)