Skip to content

Commit 57d316b

Browse files
Nogah Frankeldavem330
authored andcommitted
mlxsw: pci: Add resources query implementation.
Add resources query implementation. If exists, query the HW for its builtin resources instead of having them as consts in the code. Signed-off-by: Nogah Frankel <[email protected]> Reviewed-by: Ido Schimmel <[email protected]> Signed-off-by: Jiri Pirko <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent bfe9b9d commit 57d316b

File tree

6 files changed

+109
-3
lines changed

6 files changed

+109
-3
lines changed

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ enum mlxsw_cmd_opcode {
105105
MLXSW_CMD_OPCODE_SW2HW_EQ = 0x013,
106106
MLXSW_CMD_OPCODE_HW2SW_EQ = 0x014,
107107
MLXSW_CMD_OPCODE_QUERY_EQ = 0x015,
108+
MLXSW_CMD_OPCODE_QUERY_RESOURCES = 0x101,
108109
};
109110

110111
static inline const char *mlxsw_cmd_opcode_str(u16 opcode)
@@ -144,6 +145,8 @@ static inline const char *mlxsw_cmd_opcode_str(u16 opcode)
144145
return "HW2SW_EQ";
145146
case MLXSW_CMD_OPCODE_QUERY_EQ:
146147
return "QUERY_EQ";
148+
case MLXSW_CMD_OPCODE_QUERY_RESOURCES:
149+
return "QUERY_RESOURCES";
147150
default:
148151
return "*UNKNOWN*";
149152
}
@@ -500,6 +503,35 @@ static inline int mlxsw_cmd_unmap_fa(struct mlxsw_core *mlxsw_core)
500503
return mlxsw_cmd_exec_none(mlxsw_core, MLXSW_CMD_OPCODE_UNMAP_FA, 0, 0);
501504
}
502505

506+
/* QUERY_RESOURCES - Query chip resources
507+
* --------------------------------------
508+
* OpMod == 0 (N/A) , INMmod is index
509+
* ----------------------------------
510+
* The QUERY_RESOURCES command retrieves information related to chip resources
511+
* by resource ID. Every command returns 32 entries. INmod is being use as base.
512+
* for example, index 1 will return entries 32-63. When the tables end and there
513+
* are no more sources in the table, will return resource id 0xFFF to indicate
514+
* it.
515+
*/
516+
static inline int mlxsw_cmd_query_resources(struct mlxsw_core *mlxsw_core,
517+
char *out_mbox, int index)
518+
{
519+
return mlxsw_cmd_exec_out(mlxsw_core, MLXSW_CMD_OPCODE_QUERY_RESOURCES,
520+
0, index, false, out_mbox,
521+
MLXSW_CMD_MBOX_SIZE);
522+
}
523+
524+
/* cmd_mbox_query_resource_id
525+
* The resource id. 0xFFFF indicates table's end.
526+
*/
527+
MLXSW_ITEM32_INDEXED(cmd_mbox, query_resource, id, 0x00, 16, 16, 0x8, 0, false);
528+
529+
/* cmd_mbox_query_resource_data
530+
* The resource
531+
*/
532+
MLXSW_ITEM64_INDEXED(cmd_mbox, query_resource, data,
533+
0x00, 0, 40, 0x8, 0, false);
534+
503535
/* CONFIG_PROFILE (Set) - Configure Switch Profile
504536
* ------------------------------
505537
* OpMod == 1 (Set), INMmod == 0 (N/A)

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ struct mlxsw_core {
111111
struct {
112112
u8 *mapping; /* lag_id+port_index to local_port mapping */
113113
} lag;
114+
struct mlxsw_resources resources;
114115
struct mlxsw_hwmon *hwmon;
115116
unsigned long driver_priv[0];
116117
/* driver_priv has to be always the last item */
@@ -1110,7 +1111,8 @@ int mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info,
11101111
}
11111112
}
11121113

1113-
err = mlxsw_bus->init(bus_priv, mlxsw_core, mlxsw_driver->profile);
1114+
err = mlxsw_bus->init(bus_priv, mlxsw_core, mlxsw_driver->profile,
1115+
&mlxsw_core->resources);
11141116
if (err)
11151117
goto err_bus_init;
11161118

@@ -1652,6 +1654,12 @@ void mlxsw_core_lag_mapping_clear(struct mlxsw_core *mlxsw_core,
16521654
}
16531655
EXPORT_SYMBOL(mlxsw_core_lag_mapping_clear);
16541656

1657+
struct mlxsw_resources *mlxsw_core_resources_get(struct mlxsw_core *mlxsw_core)
1658+
{
1659+
return &mlxsw_core->resources;
1660+
}
1661+
EXPORT_SYMBOL(mlxsw_core_resources_get);
1662+
16551663
int mlxsw_core_port_init(struct mlxsw_core *mlxsw_core,
16561664
struct mlxsw_core_port *mlxsw_core_port, u8 local_port,
16571665
struct net_device *dev, bool split, u32 split_group)

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ struct mlxsw_config_profile {
215215
u32 kvd_linear_size;
216216
u32 kvd_hash_single_size;
217217
u32 kvd_hash_double_size;
218+
u8 resource_query_enable;
218219
struct mlxsw_swid_config swid_config[MLXSW_CONFIG_PROFILE_SWID_COUNT];
219220
};
220221

@@ -266,10 +267,16 @@ struct mlxsw_driver {
266267
const struct mlxsw_config_profile *profile;
267268
};
268269

270+
struct mlxsw_resources {
271+
};
272+
273+
struct mlxsw_resources *mlxsw_core_resources_get(struct mlxsw_core *mlxsw_core);
274+
269275
struct mlxsw_bus {
270276
const char *kind;
271277
int (*init)(void *bus_priv, struct mlxsw_core *mlxsw_core,
272-
const struct mlxsw_config_profile *profile);
278+
const struct mlxsw_config_profile *profile,
279+
struct mlxsw_resources *resources);
273280
void (*fini)(void *bus_priv);
274281
bool (*skb_transmit_busy)(void *bus_priv,
275282
const struct mlxsw_tx_info *tx_info);

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

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,56 @@ mlxsw_pci_config_profile_swid_config(struct mlxsw_pci *mlxsw_pci,
11541154
mlxsw_cmd_mbox_config_profile_swid_config_mask_set(mbox, index, mask);
11551155
}
11561156

1157+
#define MLXSW_RESOURCES_TABLE_END_ID 0xffff
1158+
#define MLXSW_RESOURCES_QUERY_MAX_QUERIES 100
1159+
#define MLXSW_RESOURCES_PER_QUERY 32
1160+
1161+
static void mlxsw_pci_resources_query_parse(int id, u64 val,
1162+
struct mlxsw_resources *resources)
1163+
{
1164+
switch (id) {
1165+
default:
1166+
break;
1167+
}
1168+
}
1169+
1170+
static int mlxsw_pci_resources_query(struct mlxsw_pci *mlxsw_pci, char *mbox,
1171+
struct mlxsw_resources *resources,
1172+
u8 query_enabled)
1173+
{
1174+
int index, i;
1175+
u64 data;
1176+
u16 id;
1177+
int err;
1178+
1179+
/* Not all the versions support resources query */
1180+
if (!query_enabled)
1181+
return 0;
1182+
1183+
mlxsw_cmd_mbox_zero(mbox);
1184+
1185+
for (index = 0; index < MLXSW_RESOURCES_QUERY_MAX_QUERIES; index++) {
1186+
err = mlxsw_cmd_query_resources(mlxsw_pci->core, mbox, index);
1187+
if (err)
1188+
return err;
1189+
1190+
for (i = 0; i < MLXSW_RESOURCES_PER_QUERY; i++) {
1191+
id = mlxsw_cmd_mbox_query_resource_id_get(mbox, i);
1192+
data = mlxsw_cmd_mbox_query_resource_data_get(mbox, i);
1193+
1194+
if (id == MLXSW_RESOURCES_TABLE_END_ID)
1195+
return 0;
1196+
1197+
mlxsw_pci_resources_query_parse(id, data, resources);
1198+
}
1199+
}
1200+
1201+
/* If after MLXSW_RESOURCES_QUERY_MAX_QUERIES we still didn't get
1202+
* MLXSW_RESOURCES_TABLE_END_ID, something went bad in the FW.
1203+
*/
1204+
return -EIO;
1205+
}
1206+
11571207
static int mlxsw_pci_config_profile(struct mlxsw_pci *mlxsw_pci, char *mbox,
11581208
const struct mlxsw_config_profile *profile)
11591209
{
@@ -1404,7 +1454,8 @@ static void mlxsw_pci_mbox_free(struct mlxsw_pci *mlxsw_pci,
14041454
}
14051455

14061456
static int mlxsw_pci_init(void *bus_priv, struct mlxsw_core *mlxsw_core,
1407-
const struct mlxsw_config_profile *profile)
1457+
const struct mlxsw_config_profile *profile,
1458+
struct mlxsw_resources *resources)
14081459
{
14091460
struct mlxsw_pci *mlxsw_pci = bus_priv;
14101461
struct pci_dev *pdev = mlxsw_pci->pdev;
@@ -1463,6 +1514,11 @@ static int mlxsw_pci_init(void *bus_priv, struct mlxsw_core *mlxsw_core,
14631514
if (err)
14641515
goto err_boardinfo;
14651516

1517+
err = mlxsw_pci_resources_query(mlxsw_pci, mbox, resources,
1518+
profile->resource_query_enable);
1519+
if (err)
1520+
goto err_query_resources;
1521+
14661522
err = mlxsw_pci_config_profile(mlxsw_pci, mbox, profile);
14671523
if (err)
14681524
goto err_config_profile;
@@ -1485,6 +1541,7 @@ static int mlxsw_pci_init(void *bus_priv, struct mlxsw_core *mlxsw_core,
14851541
mlxsw_pci_aqs_fini(mlxsw_pci);
14861542
err_aqs_init:
14871543
err_config_profile:
1544+
err_query_resources:
14881545
err_boardinfo:
14891546
mlxsw_pci_fw_area_fini(mlxsw_pci);
14901547
err_fw_area_init:

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2488,6 +2488,7 @@ static struct mlxsw_config_profile mlxsw_sp_config_profile = {
24882488
.type = MLXSW_PORT_SWID_TYPE_ETH,
24892489
}
24902490
},
2491+
.resource_query_enable = 1,
24912492
};
24922493

24932494
static struct mlxsw_driver mlxsw_sp_driver = {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,6 +1541,7 @@ static struct mlxsw_config_profile mlxsw_sx_config_profile = {
15411541
.type = MLXSW_PORT_SWID_TYPE_ETH,
15421542
}
15431543
},
1544+
.resource_query_enable = 0,
15441545
};
15451546

15461547
static struct mlxsw_driver mlxsw_sx_driver = {

0 commit comments

Comments
 (0)