diff options
author | David S. Miller <davem@davemloft.net> | 2018-04-01 10:56:44 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2018-04-01 10:56:44 -0400 |
commit | 2919ee2d41084aef216331d960b9e338ceff77a6 (patch) | |
tree | 230ba7148718abcfaf4586c4a3eb8ed51e598867 | |
parent | 06b19fe9a6df7aaa423cd8404ebe5ac9ec4b2960 (diff) | |
parent | 59441fef2b10c651261be08aec558e90fbd594f8 (diff) |
Merge branch 'mlxsw-cleanups'
Ido Schimmel says:
====================
mlxsw: Various cleanups
The first nine patches from Jiri perform small and unrelated cleanups.
The largest being the conversion of the KVD linear partitions from a
list to an array, which simplifies the code.
The last patch from Petr is a bug fix for a recent net-next commit that
prevented the "kvd" resource from being marked as the parent of its
various child resources (e.g., "/kvd/linear").
v2: Dropped devlink patch following David's comment. Will be sent
separately.
====================
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | drivers/net/ethernet/mellanox/mlxsw/core.c | 5 | ||||
-rw-r--r-- | drivers/net/ethernet/mellanox/mlxsw/core.h | 14 | ||||
-rw-r--r-- | drivers/net/ethernet/mellanox/mlxsw/pci.c | 11 | ||||
-rw-r--r-- | drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 16 | ||||
-rw-r--r-- | drivers/net/ethernet/mellanox/mlxsw/spectrum.h | 4 | ||||
-rw-r--r-- | drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_flex_actions.h | 4 | ||||
-rw-r--r-- | drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c | 284 | ||||
-rw-r--r-- | drivers/net/ethernet/mellanox/mlxsw/switchib.c | 1 | ||||
-rw-r--r-- | drivers/net/ethernet/mellanox/mlxsw/switchx2.c | 1 |
9 files changed, 131 insertions, 209 deletions
diff --git a/drivers/net/ethernet/mellanox/mlxsw/core.c b/drivers/net/ethernet/mellanox/mlxsw/core.c index 3529b545675d..93ea56620a24 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core.c | |||
@@ -1008,6 +1008,7 @@ int mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info, | |||
1008 | const char *device_kind = mlxsw_bus_info->device_kind; | 1008 | const char *device_kind = mlxsw_bus_info->device_kind; |
1009 | struct mlxsw_core *mlxsw_core; | 1009 | struct mlxsw_core *mlxsw_core; |
1010 | struct mlxsw_driver *mlxsw_driver; | 1010 | struct mlxsw_driver *mlxsw_driver; |
1011 | struct mlxsw_res *res; | ||
1011 | size_t alloc_size; | 1012 | size_t alloc_size; |
1012 | int err; | 1013 | int err; |
1013 | 1014 | ||
@@ -1032,8 +1033,8 @@ int mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info, | |||
1032 | mlxsw_core->bus_priv = bus_priv; | 1033 | mlxsw_core->bus_priv = bus_priv; |
1033 | mlxsw_core->bus_info = mlxsw_bus_info; | 1034 | mlxsw_core->bus_info = mlxsw_bus_info; |
1034 | 1035 | ||
1035 | err = mlxsw_bus->init(bus_priv, mlxsw_core, mlxsw_driver->profile, | 1036 | res = mlxsw_driver->res_query_enabled ? &mlxsw_core->res : NULL; |
1036 | &mlxsw_core->res); | 1037 | err = mlxsw_bus->init(bus_priv, mlxsw_core, mlxsw_driver->profile, res); |
1037 | if (err) | 1038 | if (err) |
1038 | goto err_bus_init; | 1039 | goto err_bus_init; |
1039 | 1040 | ||
diff --git a/drivers/net/ethernet/mellanox/mlxsw/core.h b/drivers/net/ethernet/mellanox/mlxsw/core.h index 5ddafd74dc00..092d39399f3c 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core.h +++ b/drivers/net/ethernet/mellanox/mlxsw/core.h | |||
@@ -235,8 +235,7 @@ struct mlxsw_config_profile { | |||
235 | used_max_pkey:1, | 235 | used_max_pkey:1, |
236 | used_ar_sec:1, | 236 | used_ar_sec:1, |
237 | used_adaptive_routing_group_cap:1, | 237 | used_adaptive_routing_group_cap:1, |
238 | used_kvd_split_data:1; /* indicate for the kvd's values */ | 238 | used_kvd_sizes:1; |
239 | |||
240 | u8 max_vepa_channels; | 239 | u8 max_vepa_channels; |
241 | u16 max_mid; | 240 | u16 max_mid; |
242 | u16 max_pgt; | 241 | u16 max_pgt; |
@@ -256,10 +255,8 @@ struct mlxsw_config_profile { | |||
256 | u16 adaptive_routing_group_cap; | 255 | u16 adaptive_routing_group_cap; |
257 | u8 arn; | 256 | u8 arn; |
258 | u32 kvd_linear_size; | 257 | u32 kvd_linear_size; |
259 | u16 kvd_hash_granularity; | ||
260 | u8 kvd_hash_single_parts; | 258 | u8 kvd_hash_single_parts; |
261 | u8 kvd_hash_double_parts; | 259 | u8 kvd_hash_double_parts; |
262 | u8 resource_query_enable; | ||
263 | struct mlxsw_swid_config swid_config[MLXSW_CONFIG_PROFILE_SWID_COUNT]; | 260 | struct mlxsw_swid_config swid_config[MLXSW_CONFIG_PROFILE_SWID_COUNT]; |
264 | }; | 261 | }; |
265 | 262 | ||
@@ -316,6 +313,7 @@ struct mlxsw_driver { | |||
316 | u64 *p_linear_size); | 313 | u64 *p_linear_size); |
317 | u8 txhdr_len; | 314 | u8 txhdr_len; |
318 | const struct mlxsw_config_profile *profile; | 315 | const struct mlxsw_config_profile *profile; |
316 | bool res_query_enabled; | ||
319 | }; | 317 | }; |
320 | 318 | ||
321 | int mlxsw_core_kvd_sizes_get(struct mlxsw_core *mlxsw_core, | 319 | int mlxsw_core_kvd_sizes_get(struct mlxsw_core *mlxsw_core, |
@@ -326,14 +324,14 @@ int mlxsw_core_kvd_sizes_get(struct mlxsw_core *mlxsw_core, | |||
326 | bool mlxsw_core_res_valid(struct mlxsw_core *mlxsw_core, | 324 | bool mlxsw_core_res_valid(struct mlxsw_core *mlxsw_core, |
327 | enum mlxsw_res_id res_id); | 325 | enum mlxsw_res_id res_id); |
328 | 326 | ||
329 | #define MLXSW_CORE_RES_VALID(res, short_res_id) \ | 327 | #define MLXSW_CORE_RES_VALID(mlxsw_core, short_res_id) \ |
330 | mlxsw_core_res_valid(res, MLXSW_RES_ID_##short_res_id) | 328 | mlxsw_core_res_valid(mlxsw_core, MLXSW_RES_ID_##short_res_id) |
331 | 329 | ||
332 | u64 mlxsw_core_res_get(struct mlxsw_core *mlxsw_core, | 330 | u64 mlxsw_core_res_get(struct mlxsw_core *mlxsw_core, |
333 | enum mlxsw_res_id res_id); | 331 | enum mlxsw_res_id res_id); |
334 | 332 | ||
335 | #define MLXSW_CORE_RES_GET(res, short_res_id) \ | 333 | #define MLXSW_CORE_RES_GET(mlxsw_core, short_res_id) \ |
336 | mlxsw_core_res_get(res, MLXSW_RES_ID_##short_res_id) | 334 | mlxsw_core_res_get(mlxsw_core, MLXSW_RES_ID_##short_res_id) |
337 | 335 | ||
338 | #define MLXSW_BUS_F_TXRX BIT(0) | 336 | #define MLXSW_BUS_F_TXRX BIT(0) |
339 | 337 | ||
diff --git a/drivers/net/ethernet/mellanox/mlxsw/pci.c b/drivers/net/ethernet/mellanox/mlxsw/pci.c index e30c6ce3dcb4..3a9381977d6d 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/pci.c +++ b/drivers/net/ethernet/mellanox/mlxsw/pci.c | |||
@@ -1015,16 +1015,14 @@ mlxsw_pci_config_profile_swid_config(struct mlxsw_pci *mlxsw_pci, | |||
1015 | } | 1015 | } |
1016 | 1016 | ||
1017 | static int mlxsw_pci_resources_query(struct mlxsw_pci *mlxsw_pci, char *mbox, | 1017 | static int mlxsw_pci_resources_query(struct mlxsw_pci *mlxsw_pci, char *mbox, |
1018 | struct mlxsw_res *res, | 1018 | struct mlxsw_res *res) |
1019 | u8 query_enabled) | ||
1020 | { | 1019 | { |
1021 | int index, i; | 1020 | int index, i; |
1022 | u64 data; | 1021 | u64 data; |
1023 | u16 id; | 1022 | u16 id; |
1024 | int err; | 1023 | int err; |
1025 | 1024 | ||
1026 | /* Not all the versions support resources query */ | 1025 | if (!res) |
1027 | if (!query_enabled) | ||
1028 | return 0; | 1026 | return 0; |
1029 | 1027 | ||
1030 | mlxsw_cmd_mbox_zero(mbox); | 1028 | mlxsw_cmd_mbox_zero(mbox); |
@@ -1164,7 +1162,7 @@ static int mlxsw_pci_config_profile(struct mlxsw_pci *mlxsw_pci, char *mbox, | |||
1164 | mlxsw_cmd_mbox_config_profile_adaptive_routing_group_cap_set( | 1162 | mlxsw_cmd_mbox_config_profile_adaptive_routing_group_cap_set( |
1165 | mbox, profile->adaptive_routing_group_cap); | 1163 | mbox, profile->adaptive_routing_group_cap); |
1166 | } | 1164 | } |
1167 | if (MLXSW_RES_VALID(res, KVD_SIZE)) { | 1165 | if (profile->used_kvd_sizes && MLXSW_RES_VALID(res, KVD_SIZE)) { |
1168 | err = mlxsw_pci_profile_get_kvd_sizes(mlxsw_pci, profile, res); | 1166 | err = mlxsw_pci_profile_get_kvd_sizes(mlxsw_pci, profile, res); |
1169 | if (err) | 1167 | if (err) |
1170 | return err; | 1168 | return err; |
@@ -1376,8 +1374,7 @@ static int mlxsw_pci_init(void *bus_priv, struct mlxsw_core *mlxsw_core, | |||
1376 | if (err) | 1374 | if (err) |
1377 | goto err_boardinfo; | 1375 | goto err_boardinfo; |
1378 | 1376 | ||
1379 | err = mlxsw_pci_resources_query(mlxsw_pci, mbox, res, | 1377 | err = mlxsw_pci_resources_query(mlxsw_pci, mbox, res); |
1380 | profile->resource_query_enable); | ||
1381 | if (err) | 1378 | if (err) |
1382 | goto err_query_resources; | 1379 | goto err_query_resources; |
1383 | 1380 | ||
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c index 4aa84442e357..53fffd09d133 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c | |||
@@ -3793,8 +3793,7 @@ static const struct mlxsw_config_profile mlxsw_sp_config_profile = { | |||
3793 | .max_ib_mc = 0, | 3793 | .max_ib_mc = 0, |
3794 | .used_max_pkey = 1, | 3794 | .used_max_pkey = 1, |
3795 | .max_pkey = 0, | 3795 | .max_pkey = 0, |
3796 | .used_kvd_split_data = 1, | 3796 | .used_kvd_sizes = 1, |
3797 | .kvd_hash_granularity = MLXSW_SP_KVD_GRANULARITY, | ||
3798 | .kvd_hash_single_parts = 59, | 3797 | .kvd_hash_single_parts = 59, |
3799 | .kvd_hash_double_parts = 41, | 3798 | .kvd_hash_double_parts = 41, |
3800 | .kvd_linear_size = MLXSW_SP_KVD_LINEAR_SIZE, | 3799 | .kvd_linear_size = MLXSW_SP_KVD_LINEAR_SIZE, |
@@ -3804,7 +3803,6 @@ static const struct mlxsw_config_profile mlxsw_sp_config_profile = { | |||
3804 | .type = MLXSW_PORT_SWID_TYPE_ETH, | 3803 | .type = MLXSW_PORT_SWID_TYPE_ETH, |
3805 | } | 3804 | } |
3806 | }, | 3805 | }, |
3807 | .resource_query_enable = 1, | ||
3808 | }; | 3806 | }; |
3809 | 3807 | ||
3810 | static u64 mlxsw_sp_resource_kvd_linear_occ_get(struct devlink *devlink) | 3808 | static u64 mlxsw_sp_resource_kvd_linear_occ_get(struct devlink *devlink) |
@@ -3815,7 +3813,7 @@ static u64 mlxsw_sp_resource_kvd_linear_occ_get(struct devlink *devlink) | |||
3815 | return mlxsw_sp_kvdl_occ_get(mlxsw_sp); | 3813 | return mlxsw_sp_kvdl_occ_get(mlxsw_sp); |
3816 | } | 3814 | } |
3817 | 3815 | ||
3818 | static struct devlink_resource_ops mlxsw_sp_resource_kvd_linear_ops = { | 3816 | static const struct devlink_resource_ops mlxsw_sp_resource_kvd_linear_ops = { |
3819 | .occ_get = mlxsw_sp_resource_kvd_linear_occ_get, | 3817 | .occ_get = mlxsw_sp_resource_kvd_linear_occ_get, |
3820 | }; | 3818 | }; |
3821 | 3819 | ||
@@ -3894,7 +3892,7 @@ static int mlxsw_sp_resources_register(struct mlxsw_core *mlxsw_core) | |||
3894 | if (err) | 3892 | if (err) |
3895 | return err; | 3893 | return err; |
3896 | 3894 | ||
3897 | err = mlxsw_sp_kvdl_resources_register(devlink); | 3895 | err = mlxsw_sp_kvdl_resources_register(mlxsw_core); |
3898 | if (err) | 3896 | if (err) |
3899 | return err; | 3897 | return err; |
3900 | 3898 | ||
@@ -3902,7 +3900,7 @@ static int mlxsw_sp_resources_register(struct mlxsw_core *mlxsw_core) | |||
3902 | double_size *= profile->kvd_hash_double_parts; | 3900 | double_size *= profile->kvd_hash_double_parts; |
3903 | double_size /= profile->kvd_hash_double_parts + | 3901 | double_size /= profile->kvd_hash_double_parts + |
3904 | profile->kvd_hash_single_parts; | 3902 | profile->kvd_hash_single_parts; |
3905 | double_size = rounddown(double_size, profile->kvd_hash_granularity); | 3903 | double_size = rounddown(double_size, MLXSW_SP_KVD_GRANULARITY); |
3906 | err = devlink_resource_register(devlink, MLXSW_SP_RESOURCE_NAME_KVD_HASH_DOUBLE, | 3904 | err = devlink_resource_register(devlink, MLXSW_SP_RESOURCE_NAME_KVD_HASH_DOUBLE, |
3907 | double_size, | 3905 | double_size, |
3908 | MLXSW_SP_RESOURCE_KVD_HASH_DOUBLE, | 3906 | MLXSW_SP_RESOURCE_KVD_HASH_DOUBLE, |
@@ -3935,8 +3933,7 @@ static int mlxsw_sp_kvd_sizes_get(struct mlxsw_core *mlxsw_core, | |||
3935 | int err; | 3933 | int err; |
3936 | 3934 | ||
3937 | if (!MLXSW_CORE_RES_VALID(mlxsw_core, KVD_SINGLE_MIN_SIZE) || | 3935 | if (!MLXSW_CORE_RES_VALID(mlxsw_core, KVD_SINGLE_MIN_SIZE) || |
3938 | !MLXSW_CORE_RES_VALID(mlxsw_core, KVD_DOUBLE_MIN_SIZE) || | 3936 | !MLXSW_CORE_RES_VALID(mlxsw_core, KVD_DOUBLE_MIN_SIZE)) |
3939 | !profile->used_kvd_split_data) | ||
3940 | return -EIO; | 3937 | return -EIO; |
3941 | 3938 | ||
3942 | /* The hash part is what left of the kvd without the | 3939 | /* The hash part is what left of the kvd without the |
@@ -3962,7 +3959,7 @@ static int mlxsw_sp_kvd_sizes_get(struct mlxsw_core *mlxsw_core, | |||
3962 | double_size /= profile->kvd_hash_double_parts + | 3959 | double_size /= profile->kvd_hash_double_parts + |
3963 | profile->kvd_hash_single_parts; | 3960 | profile->kvd_hash_single_parts; |
3964 | *p_double_size = rounddown(double_size, | 3961 | *p_double_size = rounddown(double_size, |
3965 | profile->kvd_hash_granularity); | 3962 | MLXSW_SP_KVD_GRANULARITY); |
3966 | } | 3963 | } |
3967 | 3964 | ||
3968 | err = devlink_resource_size_get(devlink, | 3965 | err = devlink_resource_size_get(devlink, |
@@ -4004,6 +4001,7 @@ static struct mlxsw_driver mlxsw_sp_driver = { | |||
4004 | .kvd_sizes_get = mlxsw_sp_kvd_sizes_get, | 4001 | .kvd_sizes_get = mlxsw_sp_kvd_sizes_get, |
4005 | .txhdr_len = MLXSW_TXHDR_LEN, | 4002 | .txhdr_len = MLXSW_TXHDR_LEN, |
4006 | .profile = &mlxsw_sp_config_profile, | 4003 | .profile = &mlxsw_sp_config_profile, |
4004 | .res_query_enabled = true, | ||
4007 | }; | 4005 | }; |
4008 | 4006 | ||
4009 | bool mlxsw_sp_port_dev_check(const struct net_device *dev) | 4007 | bool mlxsw_sp_port_dev_check(const struct net_device *dev) |
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h index 21bee8f19894..82820ba43728 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h | |||
@@ -75,7 +75,7 @@ | |||
75 | #define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR_LARGE_CHUNKS "large_chunks" | 75 | #define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR_LARGE_CHUNKS "large_chunks" |
76 | 76 | ||
77 | enum mlxsw_sp_resource_id { | 77 | enum mlxsw_sp_resource_id { |
78 | MLXSW_SP_RESOURCE_KVD, | 78 | MLXSW_SP_RESOURCE_KVD = 1, |
79 | MLXSW_SP_RESOURCE_KVD_LINEAR, | 79 | MLXSW_SP_RESOURCE_KVD_LINEAR, |
80 | MLXSW_SP_RESOURCE_KVD_HASH_SINGLE, | 80 | MLXSW_SP_RESOURCE_KVD_HASH_SINGLE, |
81 | MLXSW_SP_RESOURCE_KVD_HASH_DOUBLE, | 81 | MLXSW_SP_RESOURCE_KVD_HASH_DOUBLE, |
@@ -443,7 +443,7 @@ int mlxsw_sp_kvdl_alloc_size_query(struct mlxsw_sp *mlxsw_sp, | |||
443 | unsigned int entry_count, | 443 | unsigned int entry_count, |
444 | unsigned int *p_alloc_size); | 444 | unsigned int *p_alloc_size); |
445 | u64 mlxsw_sp_kvdl_occ_get(const struct mlxsw_sp *mlxsw_sp); | 445 | u64 mlxsw_sp_kvdl_occ_get(const struct mlxsw_sp *mlxsw_sp); |
446 | int mlxsw_sp_kvdl_resources_register(struct devlink *devlink); | 446 | int mlxsw_sp_kvdl_resources_register(struct mlxsw_core *mlxsw_core); |
447 | 447 | ||
448 | struct mlxsw_sp_acl_rule_info { | 448 | struct mlxsw_sp_acl_rule_info { |
449 | unsigned int priority; | 449 | unsigned int priority; |
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_flex_actions.h b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_flex_actions.h index 2726192836ad..bd6d552d95b9 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_flex_actions.h +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_flex_actions.h | |||
@@ -33,8 +33,8 @@ | |||
33 | * POSSIBILITY OF SUCH DAMAGE. | 33 | * POSSIBILITY OF SUCH DAMAGE. |
34 | */ | 34 | */ |
35 | 35 | ||
36 | #ifndef _MLXSW_SPECTRUM_ACL_FLEX_KEYS_H | 36 | #ifndef _MLXSW_SPECTRUM_ACL_FLEX_ACTIONS_H |
37 | #define _MLXSW_SPECTRUM_ACL_FLEX_KEYS_H | 37 | #define _MLXSW_SPECTRUM_ACL_FLEX_ACTIONS_H |
38 | 38 | ||
39 | #include "spectrum.h" | 39 | #include "spectrum.h" |
40 | 40 | ||
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c index 85503e93b93f..8796db44dcc3 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c | |||
@@ -55,24 +55,47 @@ | |||
55 | #define MLXSW_SP_KVDL_LARGE_CHUNKS_END \ | 55 | #define MLXSW_SP_KVDL_LARGE_CHUNKS_END \ |
56 | (MLXSW_SP_KVDL_LARGE_CHUNKS_SIZE + MLXSW_SP_KVDL_LARGE_CHUNKS_BASE - 1) | 56 | (MLXSW_SP_KVDL_LARGE_CHUNKS_SIZE + MLXSW_SP_KVDL_LARGE_CHUNKS_BASE - 1) |
57 | 57 | ||
58 | #define MLXSW_SP_CHUNK_MAX 32 | 58 | #define MLXSW_SP_KVDL_SINGLE_ALLOC_SIZE 1 |
59 | #define MLXSW_SP_LARGE_CHUNK_MAX 512 | 59 | #define MLXSW_SP_KVDL_CHUNKS_ALLOC_SIZE 32 |
60 | #define MLXSW_SP_KVDL_LARGE_CHUNKS_ALLOC_SIZE 512 | ||
60 | 61 | ||
61 | struct mlxsw_sp_kvdl_part_info { | 62 | struct mlxsw_sp_kvdl_part_info { |
62 | unsigned int part_index; | 63 | unsigned int part_index; |
63 | unsigned int start_index; | 64 | unsigned int start_index; |
64 | unsigned int end_index; | 65 | unsigned int end_index; |
65 | unsigned int alloc_size; | 66 | unsigned int alloc_size; |
67 | enum mlxsw_sp_resource_id resource_id; | ||
68 | }; | ||
69 | |||
70 | enum mlxsw_sp_kvdl_part_id { | ||
71 | MLXSW_SP_KVDL_PART_ID_SINGLE, | ||
72 | MLXSW_SP_KVDL_PART_ID_CHUNKS, | ||
73 | MLXSW_SP_KVDL_PART_ID_LARGE_CHUNKS, | ||
74 | }; | ||
75 | |||
76 | #define MLXSW_SP_KVDL_PART_INFO(id) \ | ||
77 | [MLXSW_SP_KVDL_PART_ID_##id] = { \ | ||
78 | .start_index = MLXSW_SP_KVDL_##id##_BASE, \ | ||
79 | .end_index = MLXSW_SP_KVDL_##id##_END, \ | ||
80 | .alloc_size = MLXSW_SP_KVDL_##id##_ALLOC_SIZE, \ | ||
81 | .resource_id = MLXSW_SP_RESOURCE_KVD_LINEAR_##id, \ | ||
82 | } | ||
83 | |||
84 | static const struct mlxsw_sp_kvdl_part_info mlxsw_sp_kvdl_parts_info[] = { | ||
85 | MLXSW_SP_KVDL_PART_INFO(SINGLE), | ||
86 | MLXSW_SP_KVDL_PART_INFO(CHUNKS), | ||
87 | MLXSW_SP_KVDL_PART_INFO(LARGE_CHUNKS), | ||
66 | }; | 88 | }; |
67 | 89 | ||
90 | #define MLXSW_SP_KVDL_PARTS_INFO_LEN ARRAY_SIZE(mlxsw_sp_kvdl_parts_info) | ||
91 | |||
68 | struct mlxsw_sp_kvdl_part { | 92 | struct mlxsw_sp_kvdl_part { |
69 | struct list_head list; | 93 | struct mlxsw_sp_kvdl_part_info info; |
70 | struct mlxsw_sp_kvdl_part_info *info; | ||
71 | unsigned long usage[0]; /* Entries */ | 94 | unsigned long usage[0]; /* Entries */ |
72 | }; | 95 | }; |
73 | 96 | ||
74 | struct mlxsw_sp_kvdl { | 97 | struct mlxsw_sp_kvdl { |
75 | struct list_head parts_list; | 98 | struct mlxsw_sp_kvdl_part *parts[MLXSW_SP_KVDL_PARTS_INFO_LEN]; |
76 | }; | 99 | }; |
77 | 100 | ||
78 | static struct mlxsw_sp_kvdl_part * | 101 | static struct mlxsw_sp_kvdl_part * |
@@ -80,11 +103,13 @@ mlxsw_sp_kvdl_alloc_size_part(struct mlxsw_sp_kvdl *kvdl, | |||
80 | unsigned int alloc_size) | 103 | unsigned int alloc_size) |
81 | { | 104 | { |
82 | struct mlxsw_sp_kvdl_part *part, *min_part = NULL; | 105 | struct mlxsw_sp_kvdl_part *part, *min_part = NULL; |
106 | int i; | ||
83 | 107 | ||
84 | list_for_each_entry(part, &kvdl->parts_list, list) { | 108 | for (i = 0; i < MLXSW_SP_KVDL_PARTS_INFO_LEN; i++) { |
85 | if (alloc_size <= part->info->alloc_size && | 109 | part = kvdl->parts[i]; |
110 | if (alloc_size <= part->info.alloc_size && | ||
86 | (!min_part || | 111 | (!min_part || |
87 | part->info->alloc_size <= min_part->info->alloc_size)) | 112 | part->info.alloc_size <= min_part->info.alloc_size)) |
88 | min_part = part; | 113 | min_part = part; |
89 | } | 114 | } |
90 | 115 | ||
@@ -95,10 +120,12 @@ static struct mlxsw_sp_kvdl_part * | |||
95 | mlxsw_sp_kvdl_index_part(struct mlxsw_sp_kvdl *kvdl, u32 kvdl_index) | 120 | mlxsw_sp_kvdl_index_part(struct mlxsw_sp_kvdl *kvdl, u32 kvdl_index) |
96 | { | 121 | { |
97 | struct mlxsw_sp_kvdl_part *part; | 122 | struct mlxsw_sp_kvdl_part *part; |
123 | int i; | ||
98 | 124 | ||
99 | list_for_each_entry(part, &kvdl->parts_list, list) { | 125 | for (i = 0; i < MLXSW_SP_KVDL_PARTS_INFO_LEN; i++) { |
100 | if (kvdl_index >= part->info->start_index && | 126 | part = kvdl->parts[i]; |
101 | kvdl_index <= part->info->end_index) | 127 | if (kvdl_index >= part->info.start_index && |
128 | kvdl_index <= part->info.end_index) | ||
102 | return part; | 129 | return part; |
103 | } | 130 | } |
104 | 131 | ||
@@ -122,7 +149,7 @@ mlxsw_sp_kvdl_index_entry_index(const struct mlxsw_sp_kvdl_part_info *info, | |||
122 | static int mlxsw_sp_kvdl_part_alloc(struct mlxsw_sp_kvdl_part *part, | 149 | static int mlxsw_sp_kvdl_part_alloc(struct mlxsw_sp_kvdl_part *part, |
123 | u32 *p_kvdl_index) | 150 | u32 *p_kvdl_index) |
124 | { | 151 | { |
125 | const struct mlxsw_sp_kvdl_part_info *info = part->info; | 152 | const struct mlxsw_sp_kvdl_part_info *info = &part->info; |
126 | unsigned int entry_index, nr_entries; | 153 | unsigned int entry_index, nr_entries; |
127 | 154 | ||
128 | nr_entries = (info->end_index - info->start_index + 1) / | 155 | nr_entries = (info->end_index - info->start_index + 1) / |
@@ -132,8 +159,7 @@ static int mlxsw_sp_kvdl_part_alloc(struct mlxsw_sp_kvdl_part *part, | |||
132 | return -ENOBUFS; | 159 | return -ENOBUFS; |
133 | __set_bit(entry_index, part->usage); | 160 | __set_bit(entry_index, part->usage); |
134 | 161 | ||
135 | *p_kvdl_index = mlxsw_sp_entry_index_kvdl_index(part->info, | 162 | *p_kvdl_index = mlxsw_sp_entry_index_kvdl_index(info, entry_index); |
136 | entry_index); | ||
137 | 163 | ||
138 | return 0; | 164 | return 0; |
139 | } | 165 | } |
@@ -141,10 +167,10 @@ static int mlxsw_sp_kvdl_part_alloc(struct mlxsw_sp_kvdl_part *part, | |||
141 | static void mlxsw_sp_kvdl_part_free(struct mlxsw_sp_kvdl_part *part, | 167 | static void mlxsw_sp_kvdl_part_free(struct mlxsw_sp_kvdl_part *part, |
142 | u32 kvdl_index) | 168 | u32 kvdl_index) |
143 | { | 169 | { |
170 | const struct mlxsw_sp_kvdl_part_info *info = &part->info; | ||
144 | unsigned int entry_index; | 171 | unsigned int entry_index; |
145 | 172 | ||
146 | entry_index = mlxsw_sp_kvdl_index_entry_index(part->info, | 173 | entry_index = mlxsw_sp_kvdl_index_entry_index(info, kvdl_index); |
147 | kvdl_index); | ||
148 | __clear_bit(entry_index, part->usage); | 174 | __clear_bit(entry_index, part->usage); |
149 | } | 175 | } |
150 | 176 | ||
@@ -183,74 +209,30 @@ int mlxsw_sp_kvdl_alloc_size_query(struct mlxsw_sp *mlxsw_sp, | |||
183 | if (IS_ERR(part)) | 209 | if (IS_ERR(part)) |
184 | return PTR_ERR(part); | 210 | return PTR_ERR(part); |
185 | 211 | ||
186 | *p_alloc_size = part->info->alloc_size; | 212 | *p_alloc_size = part->info.alloc_size; |
187 | 213 | ||
188 | return 0; | 214 | return 0; |
189 | } | 215 | } |
190 | 216 | ||
191 | enum mlxsw_sp_kvdl_part_id { | 217 | static void mlxsw_sp_kvdl_part_update(struct mlxsw_sp_kvdl_part *part, |
192 | MLXSW_SP_KVDL_PART_SINGLE, | 218 | struct mlxsw_sp_kvdl_part *part_prev, |
193 | MLXSW_SP_KVDL_PART_CHUNKS, | 219 | unsigned int size) |
194 | MLXSW_SP_KVDL_PART_LARGE_CHUNKS, | ||
195 | }; | ||
196 | |||
197 | static const struct mlxsw_sp_kvdl_part_info kvdl_parts_info[] = { | ||
198 | { | ||
199 | .part_index = MLXSW_SP_KVDL_PART_SINGLE, | ||
200 | .start_index = MLXSW_SP_KVDL_SINGLE_BASE, | ||
201 | .end_index = MLXSW_SP_KVDL_SINGLE_END, | ||
202 | .alloc_size = 1, | ||
203 | }, | ||
204 | { | ||
205 | .part_index = MLXSW_SP_KVDL_PART_CHUNKS, | ||
206 | .start_index = MLXSW_SP_KVDL_CHUNKS_BASE, | ||
207 | .end_index = MLXSW_SP_KVDL_CHUNKS_END, | ||
208 | .alloc_size = MLXSW_SP_CHUNK_MAX, | ||
209 | }, | ||
210 | { | ||
211 | .part_index = MLXSW_SP_KVDL_PART_LARGE_CHUNKS, | ||
212 | .start_index = MLXSW_SP_KVDL_LARGE_CHUNKS_BASE, | ||
213 | .end_index = MLXSW_SP_KVDL_LARGE_CHUNKS_END, | ||
214 | .alloc_size = MLXSW_SP_LARGE_CHUNK_MAX, | ||
215 | }, | ||
216 | }; | ||
217 | |||
218 | static struct mlxsw_sp_kvdl_part * | ||
219 | mlxsw_sp_kvdl_part_find(struct mlxsw_sp *mlxsw_sp, unsigned int part_index) | ||
220 | { | ||
221 | struct mlxsw_sp_kvdl_part *part; | ||
222 | |||
223 | list_for_each_entry(part, &mlxsw_sp->kvdl->parts_list, list) { | ||
224 | if (part->info->part_index == part_index) | ||
225 | return part; | ||
226 | } | ||
227 | |||
228 | return NULL; | ||
229 | } | ||
230 | |||
231 | static void | ||
232 | mlxsw_sp_kvdl_part_update(struct mlxsw_sp *mlxsw_sp, | ||
233 | struct mlxsw_sp_kvdl_part *part, unsigned int size) | ||
234 | { | 220 | { |
235 | struct mlxsw_sp_kvdl_part_info *info = part->info; | ||
236 | |||
237 | if (list_is_last(&part->list, &mlxsw_sp->kvdl->parts_list)) { | ||
238 | info->end_index = size - 1; | ||
239 | } else { | ||
240 | struct mlxsw_sp_kvdl_part *last_part; | ||
241 | 221 | ||
242 | last_part = list_next_entry(part, list); | 222 | if (!part_prev) { |
243 | info->start_index = last_part->info->end_index + 1; | 223 | part->info.end_index = size - 1; |
244 | info->end_index = info->start_index + size - 1; | 224 | } else { |
225 | part->info.start_index = part_prev->info.end_index + 1; | ||
226 | part->info.end_index = part->info.start_index + size - 1; | ||
245 | } | 227 | } |
246 | } | 228 | } |
247 | 229 | ||
248 | static int mlxsw_sp_kvdl_part_init(struct mlxsw_sp *mlxsw_sp, | 230 | static struct mlxsw_sp_kvdl_part * |
249 | unsigned int part_index) | 231 | mlxsw_sp_kvdl_part_init(struct mlxsw_sp *mlxsw_sp, |
232 | const struct mlxsw_sp_kvdl_part_info *info, | ||
233 | struct mlxsw_sp_kvdl_part *part_prev) | ||
250 | { | 234 | { |
251 | struct devlink *devlink = priv_to_devlink(mlxsw_sp->core); | 235 | struct devlink *devlink = priv_to_devlink(mlxsw_sp->core); |
252 | const struct mlxsw_sp_kvdl_part_info *info; | ||
253 | enum mlxsw_sp_resource_id resource_id; | ||
254 | struct mlxsw_sp_kvdl_part *part; | 236 | struct mlxsw_sp_kvdl_part *part; |
255 | bool need_update = true; | 237 | bool need_update = true; |
256 | unsigned int nr_entries; | 238 | unsigned int nr_entries; |
@@ -258,23 +240,8 @@ static int mlxsw_sp_kvdl_part_init(struct mlxsw_sp *mlxsw_sp, | |||
258 | u64 resource_size; | 240 | u64 resource_size; |
259 | int err; | 241 | int err; |
260 | 242 | ||
261 | info = &kvdl_parts_info[part_index]; | 243 | err = devlink_resource_size_get(devlink, info->resource_id, |
262 | 244 | &resource_size); | |
263 | switch (part_index) { | ||
264 | case MLXSW_SP_KVDL_PART_SINGLE: | ||
265 | resource_id = MLXSW_SP_RESOURCE_KVD_LINEAR_SINGLE; | ||
266 | break; | ||
267 | case MLXSW_SP_KVDL_PART_CHUNKS: | ||
268 | resource_id = MLXSW_SP_RESOURCE_KVD_LINEAR_CHUNKS; | ||
269 | break; | ||
270 | case MLXSW_SP_KVDL_PART_LARGE_CHUNKS: | ||
271 | resource_id = MLXSW_SP_RESOURCE_KVD_LINEAR_LARGE_CHUNKS; | ||
272 | break; | ||
273 | default: | ||
274 | return -EINVAL; | ||
275 | } | ||
276 | |||
277 | err = devlink_resource_size_get(devlink, resource_id, &resource_size); | ||
278 | if (err) { | 245 | if (err) { |
279 | need_update = false; | 246 | need_update = false; |
280 | resource_size = info->end_index - info->start_index + 1; | 247 | resource_size = info->end_index - info->start_index + 1; |
@@ -284,86 +251,77 @@ static int mlxsw_sp_kvdl_part_init(struct mlxsw_sp *mlxsw_sp, | |||
284 | usage_size = BITS_TO_LONGS(nr_entries) * sizeof(unsigned long); | 251 | usage_size = BITS_TO_LONGS(nr_entries) * sizeof(unsigned long); |
285 | part = kzalloc(sizeof(*part) + usage_size, GFP_KERNEL); | 252 | part = kzalloc(sizeof(*part) + usage_size, GFP_KERNEL); |
286 | if (!part) | 253 | if (!part) |
287 | return -ENOMEM; | 254 | return ERR_PTR(-ENOMEM); |
288 | 255 | ||
289 | part->info = kmemdup(info, sizeof(*part->info), GFP_KERNEL); | 256 | memcpy(&part->info, info, sizeof(part->info)); |
290 | if (!part->info) | ||
291 | goto err_part_info_alloc; | ||
292 | 257 | ||
293 | list_add(&part->list, &mlxsw_sp->kvdl->parts_list); | ||
294 | if (need_update) | 258 | if (need_update) |
295 | mlxsw_sp_kvdl_part_update(mlxsw_sp, part, resource_size); | 259 | mlxsw_sp_kvdl_part_update(part, part_prev, resource_size); |
296 | return 0; | 260 | return part; |
297 | |||
298 | err_part_info_alloc: | ||
299 | kfree(part); | ||
300 | return -ENOMEM; | ||
301 | } | 261 | } |
302 | 262 | ||
303 | static void mlxsw_sp_kvdl_part_fini(struct mlxsw_sp *mlxsw_sp, | 263 | static void mlxsw_sp_kvdl_part_fini(struct mlxsw_sp_kvdl_part *part) |
304 | unsigned int part_index) | ||
305 | { | 264 | { |
306 | struct mlxsw_sp_kvdl_part *part; | ||
307 | |||
308 | part = mlxsw_sp_kvdl_part_find(mlxsw_sp, part_index); | ||
309 | if (!part) | ||
310 | return; | ||
311 | |||
312 | list_del(&part->list); | ||
313 | kfree(part->info); | ||
314 | kfree(part); | 265 | kfree(part); |
315 | } | 266 | } |
316 | 267 | ||
317 | static int mlxsw_sp_kvdl_parts_init(struct mlxsw_sp *mlxsw_sp) | 268 | static int mlxsw_sp_kvdl_parts_init(struct mlxsw_sp *mlxsw_sp) |
318 | { | 269 | { |
270 | struct mlxsw_sp_kvdl *kvdl = mlxsw_sp->kvdl; | ||
271 | const struct mlxsw_sp_kvdl_part_info *info; | ||
272 | struct mlxsw_sp_kvdl_part *part_prev = NULL; | ||
319 | int err, i; | 273 | int err, i; |
320 | 274 | ||
321 | INIT_LIST_HEAD(&mlxsw_sp->kvdl->parts_list); | 275 | for (i = 0; i < MLXSW_SP_KVDL_PARTS_INFO_LEN; i++) { |
322 | 276 | info = &mlxsw_sp_kvdl_parts_info[i]; | |
323 | for (i = 0; i < ARRAY_SIZE(kvdl_parts_info); i++) { | 277 | kvdl->parts[i] = mlxsw_sp_kvdl_part_init(mlxsw_sp, info, |
324 | err = mlxsw_sp_kvdl_part_init(mlxsw_sp, i); | 278 | part_prev); |
325 | if (err) | 279 | if (IS_ERR(kvdl->parts[i])) { |
280 | err = PTR_ERR(kvdl->parts[i]); | ||
326 | goto err_kvdl_part_init; | 281 | goto err_kvdl_part_init; |
282 | } | ||
283 | part_prev = kvdl->parts[i]; | ||
327 | } | 284 | } |
328 | |||
329 | return 0; | 285 | return 0; |
330 | 286 | ||
331 | err_kvdl_part_init: | 287 | err_kvdl_part_init: |
332 | for (i--; i >= 0; i--) | 288 | for (i--; i >= 0; i--) |
333 | mlxsw_sp_kvdl_part_fini(mlxsw_sp, i); | 289 | mlxsw_sp_kvdl_part_fini(kvdl->parts[i]); |
334 | return err; | 290 | return err; |
335 | } | 291 | } |
336 | 292 | ||
337 | static void mlxsw_sp_kvdl_parts_fini(struct mlxsw_sp *mlxsw_sp) | 293 | static void mlxsw_sp_kvdl_parts_fini(struct mlxsw_sp *mlxsw_sp) |
338 | { | 294 | { |
295 | struct mlxsw_sp_kvdl *kvdl = mlxsw_sp->kvdl; | ||
339 | int i; | 296 | int i; |
340 | 297 | ||
341 | for (i = ARRAY_SIZE(kvdl_parts_info) - 1; i >= 0; i--) | 298 | for (i = 0; i < MLXSW_SP_KVDL_PARTS_INFO_LEN; i++) |
342 | mlxsw_sp_kvdl_part_fini(mlxsw_sp, i); | 299 | mlxsw_sp_kvdl_part_fini(kvdl->parts[i]); |
343 | } | 300 | } |
344 | 301 | ||
345 | static u64 mlxsw_sp_kvdl_part_occ(struct mlxsw_sp_kvdl_part *part) | 302 | static u64 mlxsw_sp_kvdl_part_occ(struct mlxsw_sp_kvdl_part *part) |
346 | { | 303 | { |
304 | const struct mlxsw_sp_kvdl_part_info *info = &part->info; | ||
347 | unsigned int nr_entries; | 305 | unsigned int nr_entries; |
348 | int bit = -1; | 306 | int bit = -1; |
349 | u64 occ = 0; | 307 | u64 occ = 0; |
350 | 308 | ||
351 | nr_entries = (part->info->end_index - | 309 | nr_entries = (info->end_index - |
352 | part->info->start_index + 1) / | 310 | info->start_index + 1) / |
353 | part->info->alloc_size; | 311 | info->alloc_size; |
354 | while ((bit = find_next_bit(part->usage, nr_entries, bit + 1)) | 312 | while ((bit = find_next_bit(part->usage, nr_entries, bit + 1)) |
355 | < nr_entries) | 313 | < nr_entries) |
356 | occ += part->info->alloc_size; | 314 | occ += info->alloc_size; |
357 | return occ; | 315 | return occ; |
358 | } | 316 | } |
359 | 317 | ||
360 | u64 mlxsw_sp_kvdl_occ_get(const struct mlxsw_sp *mlxsw_sp) | 318 | u64 mlxsw_sp_kvdl_occ_get(const struct mlxsw_sp *mlxsw_sp) |
361 | { | 319 | { |
362 | struct mlxsw_sp_kvdl_part *part; | ||
363 | u64 occ = 0; | 320 | u64 occ = 0; |
321 | int i; | ||
364 | 322 | ||
365 | list_for_each_entry(part, &mlxsw_sp->kvdl->parts_list, list) | 323 | for (i = 0; i < MLXSW_SP_KVDL_PARTS_INFO_LEN; i++) |
366 | occ += mlxsw_sp_kvdl_part_occ(part); | 324 | occ += mlxsw_sp_kvdl_part_occ(mlxsw_sp->kvdl->parts[i]); |
367 | 325 | ||
368 | return occ; | 326 | return occ; |
369 | } | 327 | } |
@@ -374,10 +332,7 @@ static u64 mlxsw_sp_kvdl_single_occ_get(struct devlink *devlink) | |||
374 | struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core); | 332 | struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core); |
375 | struct mlxsw_sp_kvdl_part *part; | 333 | struct mlxsw_sp_kvdl_part *part; |
376 | 334 | ||
377 | part = mlxsw_sp_kvdl_part_find(mlxsw_sp, MLXSW_SP_KVDL_PART_SINGLE); | 335 | part = mlxsw_sp->kvdl->parts[MLXSW_SP_KVDL_PART_ID_SINGLE]; |
378 | if (!part) | ||
379 | return -EINVAL; | ||
380 | |||
381 | return mlxsw_sp_kvdl_part_occ(part); | 336 | return mlxsw_sp_kvdl_part_occ(part); |
382 | } | 337 | } |
383 | 338 | ||
@@ -387,10 +342,7 @@ static u64 mlxsw_sp_kvdl_chunks_occ_get(struct devlink *devlink) | |||
387 | struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core); | 342 | struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core); |
388 | struct mlxsw_sp_kvdl_part *part; | 343 | struct mlxsw_sp_kvdl_part *part; |
389 | 344 | ||
390 | part = mlxsw_sp_kvdl_part_find(mlxsw_sp, MLXSW_SP_KVDL_PART_CHUNKS); | 345 | part = mlxsw_sp->kvdl->parts[MLXSW_SP_KVDL_PART_ID_CHUNKS]; |
391 | if (!part) | ||
392 | return -EINVAL; | ||
393 | |||
394 | return mlxsw_sp_kvdl_part_occ(part); | 346 | return mlxsw_sp_kvdl_part_occ(part); |
395 | } | 347 | } |
396 | 348 | ||
@@ -400,87 +352,65 @@ static u64 mlxsw_sp_kvdl_large_chunks_occ_get(struct devlink *devlink) | |||
400 | struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core); | 352 | struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core); |
401 | struct mlxsw_sp_kvdl_part *part; | 353 | struct mlxsw_sp_kvdl_part *part; |
402 | 354 | ||
403 | part = mlxsw_sp_kvdl_part_find(mlxsw_sp, | 355 | part = mlxsw_sp->kvdl->parts[MLXSW_SP_KVDL_PART_ID_LARGE_CHUNKS]; |
404 | MLXSW_SP_KVDL_PART_LARGE_CHUNKS); | ||
405 | if (!part) | ||
406 | return -EINVAL; | ||
407 | |||
408 | return mlxsw_sp_kvdl_part_occ(part); | 356 | return mlxsw_sp_kvdl_part_occ(part); |
409 | } | 357 | } |
410 | 358 | ||
411 | static struct devlink_resource_ops mlxsw_sp_kvdl_single_ops = { | 359 | static const struct devlink_resource_ops mlxsw_sp_kvdl_single_ops = { |
412 | .occ_get = mlxsw_sp_kvdl_single_occ_get, | 360 | .occ_get = mlxsw_sp_kvdl_single_occ_get, |
413 | }; | 361 | }; |
414 | 362 | ||
415 | static struct devlink_resource_ops mlxsw_sp_kvdl_chunks_ops = { | 363 | static const struct devlink_resource_ops mlxsw_sp_kvdl_chunks_ops = { |
416 | .occ_get = mlxsw_sp_kvdl_chunks_occ_get, | 364 | .occ_get = mlxsw_sp_kvdl_chunks_occ_get, |
417 | }; | 365 | }; |
418 | 366 | ||
419 | static struct devlink_resource_ops mlxsw_sp_kvdl_chunks_large_ops = { | 367 | static const struct devlink_resource_ops mlxsw_sp_kvdl_chunks_large_ops = { |
420 | .occ_get = mlxsw_sp_kvdl_large_chunks_occ_get, | 368 | .occ_get = mlxsw_sp_kvdl_large_chunks_occ_get, |
421 | }; | 369 | }; |
422 | 370 | ||
423 | static struct devlink_resource_size_params mlxsw_sp_kvdl_single_size_params = { | 371 | int mlxsw_sp_kvdl_resources_register(struct mlxsw_core *mlxsw_core) |
424 | .size_min = 0, | ||
425 | .size_granularity = 1, | ||
426 | .unit = DEVLINK_RESOURCE_UNIT_ENTRY, | ||
427 | }; | ||
428 | |||
429 | static struct devlink_resource_size_params mlxsw_sp_kvdl_chunks_size_params = { | ||
430 | .size_min = 0, | ||
431 | .size_granularity = MLXSW_SP_CHUNK_MAX, | ||
432 | .unit = DEVLINK_RESOURCE_UNIT_ENTRY, | ||
433 | }; | ||
434 | |||
435 | static struct devlink_resource_size_params mlxsw_sp_kvdl_large_chunks_size_params = { | ||
436 | .size_min = 0, | ||
437 | .size_granularity = MLXSW_SP_LARGE_CHUNK_MAX, | ||
438 | .unit = DEVLINK_RESOURCE_UNIT_ENTRY, | ||
439 | }; | ||
440 | |||
441 | static void | ||
442 | mlxsw_sp_kvdl_resource_size_params_prepare(struct devlink *devlink) | ||
443 | { | 372 | { |
444 | struct mlxsw_core *mlxsw_core = devlink_priv(devlink); | 373 | struct devlink *devlink = priv_to_devlink(mlxsw_core); |
374 | static struct devlink_resource_size_params size_params; | ||
445 | u32 kvdl_max_size; | 375 | u32 kvdl_max_size; |
376 | int err; | ||
446 | 377 | ||
447 | kvdl_max_size = MLXSW_CORE_RES_GET(mlxsw_core, KVD_SIZE) - | 378 | kvdl_max_size = MLXSW_CORE_RES_GET(mlxsw_core, KVD_SIZE) - |
448 | MLXSW_CORE_RES_GET(mlxsw_core, KVD_SINGLE_MIN_SIZE) - | 379 | MLXSW_CORE_RES_GET(mlxsw_core, KVD_SINGLE_MIN_SIZE) - |
449 | MLXSW_CORE_RES_GET(mlxsw_core, KVD_DOUBLE_MIN_SIZE); | 380 | MLXSW_CORE_RES_GET(mlxsw_core, KVD_DOUBLE_MIN_SIZE); |
450 | 381 | ||
451 | mlxsw_sp_kvdl_single_size_params.size_max = kvdl_max_size; | 382 | devlink_resource_size_params_init(&size_params, 0, kvdl_max_size, |
452 | mlxsw_sp_kvdl_chunks_size_params.size_max = kvdl_max_size; | 383 | MLXSW_SP_KVDL_SINGLE_ALLOC_SIZE, |
453 | mlxsw_sp_kvdl_large_chunks_size_params.size_max = kvdl_max_size; | 384 | DEVLINK_RESOURCE_UNIT_ENTRY); |
454 | } | ||
455 | |||
456 | int mlxsw_sp_kvdl_resources_register(struct devlink *devlink) | ||
457 | { | ||
458 | int err; | ||
459 | |||
460 | mlxsw_sp_kvdl_resource_size_params_prepare(devlink); | ||
461 | err = devlink_resource_register(devlink, MLXSW_SP_RESOURCE_NAME_KVD_LINEAR_SINGLES, | 385 | err = devlink_resource_register(devlink, MLXSW_SP_RESOURCE_NAME_KVD_LINEAR_SINGLES, |
462 | MLXSW_SP_KVDL_SINGLE_SIZE, | 386 | MLXSW_SP_KVDL_SINGLE_SIZE, |
463 | MLXSW_SP_RESOURCE_KVD_LINEAR_SINGLE, | 387 | MLXSW_SP_RESOURCE_KVD_LINEAR_SINGLE, |
464 | MLXSW_SP_RESOURCE_KVD_LINEAR, | 388 | MLXSW_SP_RESOURCE_KVD_LINEAR, |
465 | &mlxsw_sp_kvdl_single_size_params, | 389 | &size_params, |
466 | &mlxsw_sp_kvdl_single_ops); | 390 | &mlxsw_sp_kvdl_single_ops); |
467 | if (err) | 391 | if (err) |
468 | return err; | 392 | return err; |
469 | 393 | ||
394 | devlink_resource_size_params_init(&size_params, 0, kvdl_max_size, | ||
395 | MLXSW_SP_KVDL_CHUNKS_ALLOC_SIZE, | ||
396 | DEVLINK_RESOURCE_UNIT_ENTRY); | ||
470 | err = devlink_resource_register(devlink, MLXSW_SP_RESOURCE_NAME_KVD_LINEAR_CHUNKS, | 397 | err = devlink_resource_register(devlink, MLXSW_SP_RESOURCE_NAME_KVD_LINEAR_CHUNKS, |
471 | MLXSW_SP_KVDL_CHUNKS_SIZE, | 398 | MLXSW_SP_KVDL_CHUNKS_SIZE, |
472 | MLXSW_SP_RESOURCE_KVD_LINEAR_CHUNKS, | 399 | MLXSW_SP_RESOURCE_KVD_LINEAR_CHUNKS, |
473 | MLXSW_SP_RESOURCE_KVD_LINEAR, | 400 | MLXSW_SP_RESOURCE_KVD_LINEAR, |
474 | &mlxsw_sp_kvdl_chunks_size_params, | 401 | &size_params, |
475 | &mlxsw_sp_kvdl_chunks_ops); | 402 | &mlxsw_sp_kvdl_chunks_ops); |
476 | if (err) | 403 | if (err) |
477 | return err; | 404 | return err; |
478 | 405 | ||
406 | devlink_resource_size_params_init(&size_params, 0, kvdl_max_size, | ||
407 | MLXSW_SP_KVDL_LARGE_CHUNKS_ALLOC_SIZE, | ||
408 | DEVLINK_RESOURCE_UNIT_ENTRY); | ||
479 | err = devlink_resource_register(devlink, MLXSW_SP_RESOURCE_NAME_KVD_LINEAR_LARGE_CHUNKS, | 409 | err = devlink_resource_register(devlink, MLXSW_SP_RESOURCE_NAME_KVD_LINEAR_LARGE_CHUNKS, |
480 | MLXSW_SP_KVDL_LARGE_CHUNKS_SIZE, | 410 | MLXSW_SP_KVDL_LARGE_CHUNKS_SIZE, |
481 | MLXSW_SP_RESOURCE_KVD_LINEAR_LARGE_CHUNKS, | 411 | MLXSW_SP_RESOURCE_KVD_LINEAR_LARGE_CHUNKS, |
482 | MLXSW_SP_RESOURCE_KVD_LINEAR, | 412 | MLXSW_SP_RESOURCE_KVD_LINEAR, |
483 | &mlxsw_sp_kvdl_large_chunks_size_params, | 413 | &size_params, |
484 | &mlxsw_sp_kvdl_chunks_large_ops); | 414 | &mlxsw_sp_kvdl_chunks_large_ops); |
485 | return err; | 415 | return err; |
486 | } | 416 | } |
diff --git a/drivers/net/ethernet/mellanox/mlxsw/switchib.c b/drivers/net/ethernet/mellanox/mlxsw/switchib.c index ab7a29846bfa..c698ec4fd9d4 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/switchib.c +++ b/drivers/net/ethernet/mellanox/mlxsw/switchib.c | |||
@@ -510,7 +510,6 @@ static const struct mlxsw_config_profile mlxsw_sib_config_profile = { | |||
510 | .type = MLXSW_PORT_SWID_TYPE_IB, | 510 | .type = MLXSW_PORT_SWID_TYPE_IB, |
511 | } | 511 | } |
512 | }, | 512 | }, |
513 | .resource_query_enable = 0, | ||
514 | }; | 513 | }; |
515 | 514 | ||
516 | static struct mlxsw_driver mlxsw_sib_driver = { | 515 | static struct mlxsw_driver mlxsw_sib_driver = { |
diff --git a/drivers/net/ethernet/mellanox/mlxsw/switchx2.c b/drivers/net/ethernet/mellanox/mlxsw/switchx2.c index c87b0934a405..a655c5850aa6 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/switchx2.c +++ b/drivers/net/ethernet/mellanox/mlxsw/switchx2.c | |||
@@ -1706,7 +1706,6 @@ static const struct mlxsw_config_profile mlxsw_sx_config_profile = { | |||
1706 | .type = MLXSW_PORT_SWID_TYPE_IB, | 1706 | .type = MLXSW_PORT_SWID_TYPE_IB, |
1707 | } | 1707 | } |
1708 | }, | 1708 | }, |
1709 | .resource_query_enable = 0, | ||
1710 | }; | 1709 | }; |
1711 | 1710 | ||
1712 | static struct mlxsw_driver mlxsw_sx_driver = { | 1711 | static struct mlxsw_driver mlxsw_sx_driver = { |