52
52
#include "core.h"
53
53
#include "cmd.h"
54
54
#include "port.h"
55
+ #include "resources.h"
55
56
56
57
static const char mlxsw_pci_driver_name [] = "mlxsw_pci" ;
57
58
@@ -1155,73 +1156,8 @@ mlxsw_pci_config_profile_swid_config(struct mlxsw_pci *mlxsw_pci,
1155
1156
mlxsw_cmd_mbox_config_profile_swid_config_mask_set (mbox , index , mask );
1156
1157
}
1157
1158
1158
- #define MLXSW_MAX_SPAN_ID 0x2420
1159
- #define MLXSW_MAX_LAG_ID 0x2520
1160
- #define MLXSW_MAX_PORTS_IN_LAG_ID 0x2521
1161
- #define MLXSW_KVD_SIZE_ID 0x1001
1162
- #define MLXSW_KVD_SINGLE_MIN_SIZE_ID 0x1002
1163
- #define MLXSW_KVD_DOUBLE_MIN_SIZE_ID 0x1003
1164
- #define MLXSW_MAX_VIRTUAL_ROUTERS_ID 0x2C01
1165
- #define MLXSW_MAX_SYSTEM_PORT_ID 0x2502
1166
- #define MLXSW_MAX_VLAN_GROUPS_ID 0x2906
1167
- #define MLXSW_MAX_REGIONS_ID 0x2901
1168
- #define MLXSW_MAX_RIF_ID 0x2C02
1169
-
1170
- static void mlxsw_pci_resources_query_parse (int id , u64 val ,
1171
- struct mlxsw_resources * resources )
1172
- {
1173
- switch (id ) {
1174
- case MLXSW_MAX_SPAN_ID :
1175
- resources -> max_span = val ;
1176
- resources -> max_span_valid = 1 ;
1177
- break ;
1178
- case MLXSW_MAX_LAG_ID :
1179
- resources -> max_lag = val ;
1180
- resources -> max_lag_valid = 1 ;
1181
- break ;
1182
- case MLXSW_MAX_PORTS_IN_LAG_ID :
1183
- resources -> max_ports_in_lag = val ;
1184
- resources -> max_ports_in_lag_valid = 1 ;
1185
- break ;
1186
- case MLXSW_KVD_SIZE_ID :
1187
- resources -> kvd_size = val ;
1188
- resources -> kvd_size_valid = 1 ;
1189
- break ;
1190
- case MLXSW_KVD_SINGLE_MIN_SIZE_ID :
1191
- resources -> kvd_single_min_size = val ;
1192
- resources -> kvd_single_min_size_valid = 1 ;
1193
- break ;
1194
- case MLXSW_KVD_DOUBLE_MIN_SIZE_ID :
1195
- resources -> kvd_double_min_size = val ;
1196
- resources -> kvd_double_min_size_valid = 1 ;
1197
- break ;
1198
- case MLXSW_MAX_VIRTUAL_ROUTERS_ID :
1199
- resources -> max_virtual_routers = val ;
1200
- resources -> max_virtual_routers_valid = 1 ;
1201
- break ;
1202
- case MLXSW_MAX_SYSTEM_PORT_ID :
1203
- resources -> max_system_ports = val ;
1204
- resources -> max_system_ports_valid = 1 ;
1205
- break ;
1206
- case MLXSW_MAX_VLAN_GROUPS_ID :
1207
- resources -> max_vlan_groups = val ;
1208
- resources -> max_vlan_groups_valid = 1 ;
1209
- break ;
1210
- case MLXSW_MAX_REGIONS_ID :
1211
- resources -> max_regions = val ;
1212
- resources -> max_regions_valid = 1 ;
1213
- break ;
1214
- case MLXSW_MAX_RIF_ID :
1215
- resources -> max_rif = val ;
1216
- resources -> max_rif_valid = 1 ;
1217
- break ;
1218
- default :
1219
- break ;
1220
- }
1221
- }
1222
-
1223
1159
static int mlxsw_pci_resources_query (struct mlxsw_pci * mlxsw_pci , char * mbox ,
1224
- struct mlxsw_resources * resources ,
1160
+ struct mlxsw_res * res ,
1225
1161
u8 query_enabled )
1226
1162
{
1227
1163
int index , i ;
@@ -1248,7 +1184,7 @@ static int mlxsw_pci_resources_query(struct mlxsw_pci *mlxsw_pci, char *mbox,
1248
1184
if (id == MLXSW_CMD_QUERY_RESOURCES_TABLE_END_ID )
1249
1185
return 0 ;
1250
1186
1251
- mlxsw_pci_resources_query_parse ( id , data , resources );
1187
+ mlxsw_res_parse ( res , id , data );
1252
1188
}
1253
1189
}
1254
1190
@@ -1258,13 +1194,14 @@ static int mlxsw_pci_resources_query(struct mlxsw_pci *mlxsw_pci, char *mbox,
1258
1194
return - EIO ;
1259
1195
}
1260
1196
1261
- static int mlxsw_pci_profile_get_kvd_sizes (const struct mlxsw_config_profile * profile ,
1262
- struct mlxsw_resources * resources )
1197
+ static int
1198
+ mlxsw_pci_profile_get_kvd_sizes (const struct mlxsw_config_profile * profile ,
1199
+ struct mlxsw_res * res )
1263
1200
{
1264
- u32 singles_size , doubles_size , linear_size ;
1201
+ u32 single_size , double_size , linear_size ;
1265
1202
1266
- if (!resources -> kvd_single_min_size_valid ||
1267
- !resources -> kvd_double_min_size_valid ||
1203
+ if (!MLXSW_RES_VALID ( res , KVD_SINGLE_MIN_SIZE ) ||
1204
+ !MLXSW_RES_VALID ( res , KVD_DOUBLE_MIN_SIZE ) ||
1268
1205
!profile -> used_kvd_split_data )
1269
1206
return - EIO ;
1270
1207
@@ -1276,31 +1213,31 @@ static int mlxsw_pci_profile_get_kvd_sizes(const struct mlxsw_config_profile *pr
1276
1213
* Both sizes must be a multiplications of the
1277
1214
* granularity from the profile.
1278
1215
*/
1279
- doubles_size = ( resources -> kvd_size - linear_size ) ;
1280
- doubles_size *= profile -> kvd_hash_double_parts ;
1281
- doubles_size /= ( profile -> kvd_hash_double_parts +
1282
- profile -> kvd_hash_single_parts ) ;
1283
- doubles_size /= profile -> kvd_hash_granularity ;
1284
- doubles_size *= profile -> kvd_hash_granularity ;
1285
- singles_size = resources -> kvd_size - doubles_size -
1286
- linear_size ;
1216
+ double_size = MLXSW_RES_GET ( res , KVD_SIZE ) - linear_size ;
1217
+ double_size *= profile -> kvd_hash_double_parts ;
1218
+ double_size /= profile -> kvd_hash_double_parts +
1219
+ profile -> kvd_hash_single_parts ;
1220
+ double_size /= profile -> kvd_hash_granularity ;
1221
+ double_size *= profile -> kvd_hash_granularity ;
1222
+ single_size = MLXSW_RES_GET ( res , KVD_SIZE ) - double_size -
1223
+ linear_size ;
1287
1224
1288
1225
/* Check results are legal. */
1289
- if (singles_size < resources -> kvd_single_min_size ||
1290
- doubles_size < resources -> kvd_double_min_size ||
1291
- resources -> kvd_size < linear_size )
1226
+ if (single_size < MLXSW_RES_GET ( res , KVD_SINGLE_MIN_SIZE ) ||
1227
+ double_size < MLXSW_RES_GET ( res , KVD_DOUBLE_MIN_SIZE ) ||
1228
+ MLXSW_RES_GET ( res , KVD_SIZE ) < linear_size )
1292
1229
return - EIO ;
1293
1230
1294
- resources -> kvd_single_size = singles_size ;
1295
- resources -> kvd_double_size = doubles_size ;
1296
- resources -> kvd_linear_size = linear_size ;
1231
+ MLXSW_RES_SET ( res , KVD_SINGLE_SIZE , single_size ) ;
1232
+ MLXSW_RES_SET ( res , KVD_DOUBLE_SIZE , double_size ) ;
1233
+ MLXSW_RES_SET ( res , KVD_LINEAR_SIZE , linear_size ) ;
1297
1234
1298
1235
return 0 ;
1299
1236
}
1300
1237
1301
1238
static int mlxsw_pci_config_profile (struct mlxsw_pci * mlxsw_pci , char * mbox ,
1302
1239
const struct mlxsw_config_profile * profile ,
1303
- struct mlxsw_resources * resources )
1240
+ struct mlxsw_res * res )
1304
1241
{
1305
1242
int i ;
1306
1243
int err ;
@@ -1389,22 +1326,22 @@ static int mlxsw_pci_config_profile(struct mlxsw_pci *mlxsw_pci, char *mbox,
1389
1326
mlxsw_cmd_mbox_config_profile_adaptive_routing_group_cap_set (
1390
1327
mbox , profile -> adaptive_routing_group_cap );
1391
1328
}
1392
- if (resources -> kvd_size_valid ) {
1393
- err = mlxsw_pci_profile_get_kvd_sizes (profile , resources );
1329
+ if (MLXSW_RES_VALID ( res , KVD_SIZE ) ) {
1330
+ err = mlxsw_pci_profile_get_kvd_sizes (profile , res );
1394
1331
if (err )
1395
1332
return err ;
1396
1333
1397
1334
mlxsw_cmd_mbox_config_profile_set_kvd_linear_size_set (mbox , 1 );
1398
1335
mlxsw_cmd_mbox_config_profile_kvd_linear_size_set (mbox ,
1399
- resources -> kvd_linear_size );
1336
+ MLXSW_RES_GET ( res , KVD_LINEAR_SIZE ) );
1400
1337
mlxsw_cmd_mbox_config_profile_set_kvd_hash_single_size_set (mbox ,
1401
1338
1 );
1402
1339
mlxsw_cmd_mbox_config_profile_kvd_hash_single_size_set (mbox ,
1403
- resources -> kvd_single_size );
1340
+ MLXSW_RES_GET ( res , KVD_SINGLE_SIZE ) );
1404
1341
mlxsw_cmd_mbox_config_profile_set_kvd_hash_double_size_set (
1405
1342
mbox , 1 );
1406
1343
mlxsw_cmd_mbox_config_profile_kvd_hash_double_size_set (mbox ,
1407
- resources -> kvd_double_size );
1344
+ MLXSW_RES_GET ( res , KVD_DOUBLE_SIZE ) );
1408
1345
}
1409
1346
1410
1347
for (i = 0 ; i < MLXSW_CONFIG_PROFILE_SWID_COUNT ; i ++ )
@@ -1542,7 +1479,7 @@ static void mlxsw_pci_mbox_free(struct mlxsw_pci *mlxsw_pci,
1542
1479
1543
1480
static int mlxsw_pci_init (void * bus_priv , struct mlxsw_core * mlxsw_core ,
1544
1481
const struct mlxsw_config_profile * profile ,
1545
- struct mlxsw_resources * resources )
1482
+ struct mlxsw_res * res )
1546
1483
{
1547
1484
struct mlxsw_pci * mlxsw_pci = bus_priv ;
1548
1485
struct pci_dev * pdev = mlxsw_pci -> pdev ;
@@ -1601,12 +1538,12 @@ static int mlxsw_pci_init(void *bus_priv, struct mlxsw_core *mlxsw_core,
1601
1538
if (err )
1602
1539
goto err_boardinfo ;
1603
1540
1604
- err = mlxsw_pci_resources_query (mlxsw_pci , mbox , resources ,
1541
+ err = mlxsw_pci_resources_query (mlxsw_pci , mbox , res ,
1605
1542
profile -> resource_query_enable );
1606
1543
if (err )
1607
1544
goto err_query_resources ;
1608
1545
1609
- err = mlxsw_pci_config_profile (mlxsw_pci , mbox , profile , resources );
1546
+ err = mlxsw_pci_config_profile (mlxsw_pci , mbox , profile , res );
1610
1547
if (err )
1611
1548
goto err_config_profile ;
1612
1549
0 commit comments