Skip to content

Commit 1bac938

Browse files
committed
Merge branch 'mlxsw-cosmetics-plus-res-mgmt-rewrite'
Jiri Pirko says: ==================== mlxsw: Driver update Mostly cosmetics and small resource values management rewrite. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 67dc159 + c1a3831 commit 1bac938

File tree

12 files changed

+405
-586
lines changed

12 files changed

+405
-586
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,11 @@ static inline int mlxsw_cmd_unmap_fa(struct mlxsw_core *mlxsw_core)
513513
* are no more sources in the table, will return resource id 0xFFF to indicate
514514
* it.
515515
*/
516+
517+
#define MLXSW_CMD_QUERY_RESOURCES_TABLE_END_ID 0xffff
518+
#define MLXSW_CMD_QUERY_RESOURCES_MAX_QUERIES 100
519+
#define MLXSW_CMD_QUERY_RESOURCES_PER_QUERY 32
520+
516521
static inline int mlxsw_cmd_query_resources(struct mlxsw_core *mlxsw_core,
517522
char *out_mbox, int index)
518523
{

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

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
#include "trap.h"
6868
#include "emad.h"
6969
#include "reg.h"
70+
#include "resources.h"
7071

7172
static LIST_HEAD(mlxsw_core_driver_list);
7273
static DEFINE_SPINLOCK(mlxsw_core_driver_list_lock);
@@ -111,7 +112,7 @@ struct mlxsw_core {
111112
struct {
112113
u8 *mapping; /* lag_id+port_index to local_port mapping */
113114
} lag;
114-
struct mlxsw_resources resources;
115+
struct mlxsw_res res;
115116
struct mlxsw_hwmon *hwmon;
116117
unsigned long driver_priv[0];
117118
/* driver_priv has to be always the last item */
@@ -1101,14 +1102,15 @@ int mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info,
11011102
}
11021103

11031104
err = mlxsw_bus->init(bus_priv, mlxsw_core, mlxsw_driver->profile,
1104-
&mlxsw_core->resources);
1105+
&mlxsw_core->res);
11051106
if (err)
11061107
goto err_bus_init;
11071108

1108-
if (mlxsw_core->resources.max_lag_valid &&
1109-
mlxsw_core->resources.max_ports_in_lag_valid) {
1110-
alloc_size = sizeof(u8) * mlxsw_core->resources.max_lag *
1111-
mlxsw_core->resources.max_ports_in_lag;
1109+
if (MLXSW_CORE_RES_VALID(mlxsw_core, MAX_LAG) &&
1110+
MLXSW_CORE_RES_VALID(mlxsw_core, MAX_LAG_MEMBERS)) {
1111+
alloc_size = sizeof(u8) *
1112+
MLXSW_CORE_RES_GET(mlxsw_core, MAX_LAG) *
1113+
MLXSW_CORE_RES_GET(mlxsw_core, MAX_LAG_MEMBERS);
11121114
mlxsw_core->lag.mapping = kzalloc(alloc_size, GFP_KERNEL);
11131115
if (!mlxsw_core->lag.mapping) {
11141116
err = -ENOMEM;
@@ -1615,7 +1617,7 @@ EXPORT_SYMBOL(mlxsw_core_skb_receive);
16151617
static int mlxsw_core_lag_mapping_index(struct mlxsw_core *mlxsw_core,
16161618
u16 lag_id, u8 port_index)
16171619
{
1618-
return mlxsw_core->resources.max_ports_in_lag * lag_id +
1620+
return MLXSW_CORE_RES_GET(mlxsw_core, MAX_LAG_MEMBERS) * lag_id +
16191621
port_index;
16201622
}
16211623

@@ -1644,7 +1646,7 @@ void mlxsw_core_lag_mapping_clear(struct mlxsw_core *mlxsw_core,
16441646
{
16451647
int i;
16461648

1647-
for (i = 0; i < mlxsw_core->resources.max_ports_in_lag; i++) {
1649+
for (i = 0; i < MLXSW_CORE_RES_GET(mlxsw_core, MAX_LAG_MEMBERS); i++) {
16481650
int index = mlxsw_core_lag_mapping_index(mlxsw_core,
16491651
lag_id, i);
16501652

@@ -1654,11 +1656,19 @@ void mlxsw_core_lag_mapping_clear(struct mlxsw_core *mlxsw_core,
16541656
}
16551657
EXPORT_SYMBOL(mlxsw_core_lag_mapping_clear);
16561658

1657-
struct mlxsw_resources *mlxsw_core_resources_get(struct mlxsw_core *mlxsw_core)
1659+
bool mlxsw_core_res_valid(struct mlxsw_core *mlxsw_core,
1660+
enum mlxsw_res_id res_id)
16581661
{
1659-
return &mlxsw_core->resources;
1662+
return mlxsw_res_valid(&mlxsw_core->res, res_id);
16601663
}
1661-
EXPORT_SYMBOL(mlxsw_core_resources_get);
1664+
EXPORT_SYMBOL(mlxsw_core_res_valid);
1665+
1666+
u64 mlxsw_core_res_get(struct mlxsw_core *mlxsw_core,
1667+
enum mlxsw_res_id res_id)
1668+
{
1669+
return mlxsw_res_get(&mlxsw_core->res, res_id);
1670+
}
1671+
EXPORT_SYMBOL(mlxsw_core_res_get);
16621672

16631673
int mlxsw_core_port_init(struct mlxsw_core *mlxsw_core,
16641674
struct mlxsw_core_port *mlxsw_core_port, u8 local_port,

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

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@
4848

4949
#include "trap.h"
5050
#include "reg.h"
51-
5251
#include "cmd.h"
52+
#include "resources.h"
5353

5454
#define MLXSW_MODULE_ALIAS_PREFIX "mlxsw-driver-"
5555
#define MODULE_MLXSW_DRIVER_ALIAS(kind) \
@@ -266,45 +266,23 @@ struct mlxsw_driver {
266266
const struct mlxsw_config_profile *profile;
267267
};
268268

269-
struct mlxsw_resources {
270-
u32 max_span_valid:1,
271-
max_lag_valid:1,
272-
max_ports_in_lag_valid:1,
273-
kvd_size_valid:1,
274-
kvd_single_min_size_valid:1,
275-
kvd_double_min_size_valid:1,
276-
max_virtual_routers_valid:1,
277-
max_system_ports_valid:1,
278-
max_vlan_groups_valid:1,
279-
max_regions_valid:1,
280-
max_rif_valid:1;
281-
u8 max_span;
282-
u8 max_lag;
283-
u8 max_ports_in_lag;
284-
u32 kvd_size;
285-
u32 kvd_single_min_size;
286-
u32 kvd_double_min_size;
287-
u16 max_virtual_routers;
288-
u16 max_system_ports;
289-
u16 max_vlan_groups;
290-
u16 max_regions;
291-
u16 max_rif;
269+
bool mlxsw_core_res_valid(struct mlxsw_core *mlxsw_core,
270+
enum mlxsw_res_id res_id);
292271

293-
/* Internal resources.
294-
* Determined by the SW, not queried from the HW.
295-
*/
296-
u32 kvd_single_size;
297-
u32 kvd_double_size;
298-
u32 kvd_linear_size;
299-
};
272+
#define MLXSW_CORE_RES_VALID(res, short_res_id) \
273+
mlxsw_core_res_valid(res, MLXSW_RES_ID_##short_res_id)
274+
275+
u64 mlxsw_core_res_get(struct mlxsw_core *mlxsw_core,
276+
enum mlxsw_res_id res_id);
300277

301-
struct mlxsw_resources *mlxsw_core_resources_get(struct mlxsw_core *mlxsw_core);
278+
#define MLXSW_CORE_RES_GET(res, short_res_id) \
279+
mlxsw_core_res_get(res, MLXSW_RES_ID_##short_res_id)
302280

303281
struct mlxsw_bus {
304282
const char *kind;
305283
int (*init)(void *bus_priv, struct mlxsw_core *mlxsw_core,
306284
const struct mlxsw_config_profile *profile,
307-
struct mlxsw_resources *resources);
285+
struct mlxsw_res *res);
308286
void (*fini)(void *bus_priv);
309287
bool (*skb_transmit_busy)(void *bus_priv,
310288
const struct mlxsw_tx_info *tx_info);

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

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ struct mlxsw_item {
5555
};
5656

5757
static inline unsigned int
58-
__mlxsw_item_offset(struct mlxsw_item *item, unsigned short index,
58+
__mlxsw_item_offset(const struct mlxsw_item *item, unsigned short index,
5959
size_t typesize)
6060
{
6161
BUG_ON(index && !item->step);
@@ -72,7 +72,8 @@ __mlxsw_item_offset(struct mlxsw_item *item, unsigned short index,
7272
typesize);
7373
}
7474

75-
static inline u16 __mlxsw_item_get16(char *buf, struct mlxsw_item *item,
75+
static inline u16 __mlxsw_item_get16(const char *buf,
76+
const struct mlxsw_item *item,
7677
unsigned short index)
7778
{
7879
unsigned int offset = __mlxsw_item_offset(item, index, sizeof(u16));
@@ -87,7 +88,7 @@ static inline u16 __mlxsw_item_get16(char *buf, struct mlxsw_item *item,
8788
return tmp;
8889
}
8990

90-
static inline void __mlxsw_item_set16(char *buf, struct mlxsw_item *item,
91+
static inline void __mlxsw_item_set16(char *buf, const struct mlxsw_item *item,
9192
unsigned short index, u16 val)
9293
{
9394
unsigned int offset = __mlxsw_item_offset(item, index,
@@ -105,7 +106,8 @@ static inline void __mlxsw_item_set16(char *buf, struct mlxsw_item *item,
105106
b[offset] = cpu_to_be16(tmp);
106107
}
107108

108-
static inline u32 __mlxsw_item_get32(char *buf, struct mlxsw_item *item,
109+
static inline u32 __mlxsw_item_get32(const char *buf,
110+
const struct mlxsw_item *item,
109111
unsigned short index)
110112
{
111113
unsigned int offset = __mlxsw_item_offset(item, index, sizeof(u32));
@@ -120,7 +122,7 @@ static inline u32 __mlxsw_item_get32(char *buf, struct mlxsw_item *item,
120122
return tmp;
121123
}
122124

123-
static inline void __mlxsw_item_set32(char *buf, struct mlxsw_item *item,
125+
static inline void __mlxsw_item_set32(char *buf, const struct mlxsw_item *item,
124126
unsigned short index, u32 val)
125127
{
126128
unsigned int offset = __mlxsw_item_offset(item, index,
@@ -138,7 +140,8 @@ static inline void __mlxsw_item_set32(char *buf, struct mlxsw_item *item,
138140
b[offset] = cpu_to_be32(tmp);
139141
}
140142

141-
static inline u64 __mlxsw_item_get64(char *buf, struct mlxsw_item *item,
143+
static inline u64 __mlxsw_item_get64(const char *buf,
144+
const struct mlxsw_item *item,
142145
unsigned short index)
143146
{
144147
unsigned int offset = __mlxsw_item_offset(item, index, sizeof(u64));
@@ -153,7 +156,7 @@ static inline u64 __mlxsw_item_get64(char *buf, struct mlxsw_item *item,
153156
return tmp;
154157
}
155158

156-
static inline void __mlxsw_item_set64(char *buf, struct mlxsw_item *item,
159+
static inline void __mlxsw_item_set64(char *buf, const struct mlxsw_item *item,
157160
unsigned short index, u64 val)
158161
{
159162
unsigned int offset = __mlxsw_item_offset(item, index, sizeof(u64));
@@ -170,8 +173,8 @@ static inline void __mlxsw_item_set64(char *buf, struct mlxsw_item *item,
170173
b[offset] = cpu_to_be64(tmp);
171174
}
172175

173-
static inline void __mlxsw_item_memcpy_from(char *buf, char *dst,
174-
struct mlxsw_item *item,
176+
static inline void __mlxsw_item_memcpy_from(const char *buf, char *dst,
177+
const struct mlxsw_item *item,
175178
unsigned short index)
176179
{
177180
unsigned int offset = __mlxsw_item_offset(item, index, sizeof(char));
@@ -180,7 +183,7 @@ static inline void __mlxsw_item_memcpy_from(char *buf, char *dst,
180183
}
181184

182185
static inline void __mlxsw_item_memcpy_to(char *buf, const char *src,
183-
struct mlxsw_item *item,
186+
const struct mlxsw_item *item,
184187
unsigned short index)
185188
{
186189
unsigned int offset = __mlxsw_item_offset(item, index, sizeof(char));
@@ -189,7 +192,8 @@ static inline void __mlxsw_item_memcpy_to(char *buf, const char *src,
189192
}
190193

191194
static inline u16
192-
__mlxsw_item_bit_array_offset(struct mlxsw_item *item, u16 index, u8 *shift)
195+
__mlxsw_item_bit_array_offset(const struct mlxsw_item *item,
196+
u16 index, u8 *shift)
193197
{
194198
u16 max_index, be_index;
195199
u16 offset; /* byte offset inside the array */
@@ -212,7 +216,8 @@ __mlxsw_item_bit_array_offset(struct mlxsw_item *item, u16 index, u8 *shift)
212216
return item->offset + offset;
213217
}
214218

215-
static inline u8 __mlxsw_item_bit_array_get(char *buf, struct mlxsw_item *item,
219+
static inline u8 __mlxsw_item_bit_array_get(const char *buf,
220+
const struct mlxsw_item *item,
216221
u16 index)
217222
{
218223
u8 shift, tmp;
@@ -224,7 +229,8 @@ static inline u8 __mlxsw_item_bit_array_get(char *buf, struct mlxsw_item *item,
224229
return tmp;
225230
}
226231

227-
static inline void __mlxsw_item_bit_array_set(char *buf, struct mlxsw_item *item,
232+
static inline void __mlxsw_item_bit_array_set(char *buf,
233+
const struct mlxsw_item *item,
228234
u16 index, u8 val)
229235
{
230236
u8 shift, tmp;
@@ -254,7 +260,7 @@ static struct mlxsw_item __ITEM_NAME(_type, _cname, _iname) = { \
254260
.size = {.bits = _sizebits,}, \
255261
.name = #_type "_" #_cname "_" #_iname, \
256262
}; \
257-
static inline u16 mlxsw_##_type##_##_cname##_##_iname##_get(char *buf) \
263+
static inline u16 mlxsw_##_type##_##_cname##_##_iname##_get(const char *buf) \
258264
{ \
259265
return __mlxsw_item_get16(buf, &__ITEM_NAME(_type, _cname, _iname), 0); \
260266
} \
@@ -275,7 +281,7 @@ static struct mlxsw_item __ITEM_NAME(_type, _cname, _iname) = { \
275281
.name = #_type "_" #_cname "_" #_iname, \
276282
}; \
277283
static inline u16 \
278-
mlxsw_##_type##_##_cname##_##_iname##_get(char *buf, unsigned short index) \
284+
mlxsw_##_type##_##_cname##_##_iname##_get(const char *buf, unsigned short index)\
279285
{ \
280286
return __mlxsw_item_get16(buf, &__ITEM_NAME(_type, _cname, _iname), \
281287
index); \
@@ -295,7 +301,7 @@ static struct mlxsw_item __ITEM_NAME(_type, _cname, _iname) = { \
295301
.size = {.bits = _sizebits,}, \
296302
.name = #_type "_" #_cname "_" #_iname, \
297303
}; \
298-
static inline u32 mlxsw_##_type##_##_cname##_##_iname##_get(char *buf) \
304+
static inline u32 mlxsw_##_type##_##_cname##_##_iname##_get(const char *buf) \
299305
{ \
300306
return __mlxsw_item_get32(buf, &__ITEM_NAME(_type, _cname, _iname), 0); \
301307
} \
@@ -316,7 +322,7 @@ static struct mlxsw_item __ITEM_NAME(_type, _cname, _iname) = { \
316322
.name = #_type "_" #_cname "_" #_iname, \
317323
}; \
318324
static inline u32 \
319-
mlxsw_##_type##_##_cname##_##_iname##_get(char *buf, unsigned short index) \
325+
mlxsw_##_type##_##_cname##_##_iname##_get(const char *buf, unsigned short index)\
320326
{ \
321327
return __mlxsw_item_get32(buf, &__ITEM_NAME(_type, _cname, _iname), \
322328
index); \
@@ -336,7 +342,7 @@ static struct mlxsw_item __ITEM_NAME(_type, _cname, _iname) = { \
336342
.size = {.bits = _sizebits,}, \
337343
.name = #_type "_" #_cname "_" #_iname, \
338344
}; \
339-
static inline u64 mlxsw_##_type##_##_cname##_##_iname##_get(char *buf) \
345+
static inline u64 mlxsw_##_type##_##_cname##_##_iname##_get(const char *buf) \
340346
{ \
341347
return __mlxsw_item_get64(buf, &__ITEM_NAME(_type, _cname, _iname), 0); \
342348
} \
@@ -357,7 +363,7 @@ static struct mlxsw_item __ITEM_NAME(_type, _cname, _iname) = { \
357363
.name = #_type "_" #_cname "_" #_iname, \
358364
}; \
359365
static inline u64 \
360-
mlxsw_##_type##_##_cname##_##_iname##_get(char *buf, unsigned short index) \
366+
mlxsw_##_type##_##_cname##_##_iname##_get(const char *buf, unsigned short index)\
361367
{ \
362368
return __mlxsw_item_get64(buf, &__ITEM_NAME(_type, _cname, _iname), \
363369
index); \
@@ -377,7 +383,7 @@ static struct mlxsw_item __ITEM_NAME(_type, _cname, _iname) = { \
377383
.name = #_type "_" #_cname "_" #_iname, \
378384
}; \
379385
static inline void \
380-
mlxsw_##_type##_##_cname##_##_iname##_memcpy_from(char *buf, char *dst) \
386+
mlxsw_##_type##_##_cname##_##_iname##_memcpy_from(const char *buf, char *dst) \
381387
{ \
382388
__mlxsw_item_memcpy_from(buf, dst, \
383389
&__ITEM_NAME(_type, _cname, _iname), 0); \
@@ -399,7 +405,7 @@ static struct mlxsw_item __ITEM_NAME(_type, _cname, _iname) = { \
399405
.name = #_type "_" #_cname "_" #_iname, \
400406
}; \
401407
static inline void \
402-
mlxsw_##_type##_##_cname##_##_iname##_memcpy_from(char *buf, \
408+
mlxsw_##_type##_##_cname##_##_iname##_memcpy_from(const char *buf, \
403409
unsigned short index, \
404410
char *dst) \
405411
{ \
@@ -424,7 +430,7 @@ static struct mlxsw_item __ITEM_NAME(_type, _cname, _iname) = { \
424430
.name = #_type "_" #_cname "_" #_iname, \
425431
}; \
426432
static inline u8 \
427-
mlxsw_##_type##_##_cname##_##_iname##_get(char *buf, u16 index) \
433+
mlxsw_##_type##_##_cname##_##_iname##_get(const char *buf, u16 index) \
428434
{ \
429435
return __mlxsw_item_bit_array_get(buf, \
430436
&__ITEM_NAME(_type, _cname, _iname), \

0 commit comments

Comments
 (0)