Skip to content

Commit bf79747

Browse files
jpirkodavem330
authored andcommitted
devlink: add shared buffer configuration
Define userspace API and drivers API for configuration of shared buffers. Four basic objects are defined: shared buffer - attributes are size, number of pools and TCs pool - chunk of sharedbuffer definition, it has some size and either static or dynamic threshold port pool threshold - to set per-port threshold for each pool port tc threshold bind - to bind port and TC to specified pool with threshold. Signed-off-by: Jiri Pirko <jiri@mellanox.com> Reviewed-by: Ido Schimmel <idosch@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent f38ba95 commit bf79747

3 files changed

Lines changed: 1044 additions & 0 deletions

File tree

‎include/net/devlink.h‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ struct devlink_ops;
2424
struct devlink {
2525
struct list_head list;
2626
struct list_head port_list;
27+
struct list_head sb_list;
2728
const struct devlink_ops *ops;
2829
struct device *dev;
2930
possible_net_t _net;
@@ -42,13 +43,41 @@ struct devlink_port {
4243
u32 split_group;
4344
};
4445

46+
struct devlink_sb_pool_info {
47+
enum devlink_sb_pool_type pool_type;
48+
u32 size;
49+
enum devlink_sb_threshold_type threshold_type;
50+
};
51+
4552
struct devlink_ops {
4653
size_t priv_size;
4754
int (*port_type_set)(struct devlink_port *devlink_port,
4855
enum devlink_port_type port_type);
4956
int (*port_split)(struct devlink *devlink, unsigned int port_index,
5057
unsigned int count);
5158
int (*port_unsplit)(struct devlink *devlink, unsigned int port_index);
59+
int (*sb_pool_get)(struct devlink *devlink, unsigned int sb_index,
60+
u16 pool_index,
61+
struct devlink_sb_pool_info *pool_info);
62+
int (*sb_pool_set)(struct devlink *devlink, unsigned int sb_index,
63+
u16 pool_index, u32 size,
64+
enum devlink_sb_threshold_type threshold_type);
65+
int (*sb_port_pool_get)(struct devlink_port *devlink_port,
66+
unsigned int sb_index, u16 pool_index,
67+
u32 *p_threshold);
68+
int (*sb_port_pool_set)(struct devlink_port *devlink_port,
69+
unsigned int sb_index, u16 pool_index,
70+
u32 threshold);
71+
int (*sb_tc_pool_bind_get)(struct devlink_port *devlink_port,
72+
unsigned int sb_index,
73+
u16 tc_index,
74+
enum devlink_sb_pool_type pool_type,
75+
u16 *p_pool_index, u32 *p_threshold);
76+
int (*sb_tc_pool_bind_set)(struct devlink_port *devlink_port,
77+
unsigned int sb_index,
78+
u16 tc_index,
79+
enum devlink_sb_pool_type pool_type,
80+
u16 pool_index, u32 threshold);
5281
};
5382

5483
static inline void *devlink_priv(struct devlink *devlink)
@@ -82,6 +111,11 @@ void devlink_port_type_ib_set(struct devlink_port *devlink_port,
82111
void devlink_port_type_clear(struct devlink_port *devlink_port);
83112
void devlink_port_split_set(struct devlink_port *devlink_port,
84113
u32 split_group);
114+
int devlink_sb_register(struct devlink *devlink, unsigned int sb_index,
115+
u32 size, u16 ingress_pools_count,
116+
u16 egress_pools_count, u16 ingress_tc_count,
117+
u16 egress_tc_count);
118+
void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index);
85119

86120
#else
87121

@@ -135,6 +169,19 @@ static inline void devlink_port_split_set(struct devlink_port *devlink_port,
135169
{
136170
}
137171

172+
static inline int devlink_sb_register(struct devlink *devlink,
173+
unsigned int sb_index, u32 size,
174+
u16 ingress_pools_count,
175+
u16 egress_pools_count, u16 tc_count)
176+
{
177+
return 0;
178+
}
179+
180+
static inline void devlink_sb_unregister(struct devlink *devlink,
181+
unsigned int sb_index)
182+
{
183+
}
184+
138185
#endif
139186

140187
#endif /* _NET_DEVLINK_H_ */

‎include/uapi/linux/devlink.h‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,26 @@ enum devlink_command {
3333
DEVLINK_CMD_PORT_SPLIT,
3434
DEVLINK_CMD_PORT_UNSPLIT,
3535

36+
DEVLINK_CMD_SB_GET, /* can dump */
37+
DEVLINK_CMD_SB_SET,
38+
DEVLINK_CMD_SB_NEW,
39+
DEVLINK_CMD_SB_DEL,
40+
41+
DEVLINK_CMD_SB_POOL_GET, /* can dump */
42+
DEVLINK_CMD_SB_POOL_SET,
43+
DEVLINK_CMD_SB_POOL_NEW,
44+
DEVLINK_CMD_SB_POOL_DEL,
45+
46+
DEVLINK_CMD_SB_PORT_POOL_GET, /* can dump */
47+
DEVLINK_CMD_SB_PORT_POOL_SET,
48+
DEVLINK_CMD_SB_PORT_POOL_NEW,
49+
DEVLINK_CMD_SB_PORT_POOL_DEL,
50+
51+
DEVLINK_CMD_SB_TC_POOL_BIND_GET, /* can dump */
52+
DEVLINK_CMD_SB_TC_POOL_BIND_SET,
53+
DEVLINK_CMD_SB_TC_POOL_BIND_NEW,
54+
DEVLINK_CMD_SB_TC_POOL_BIND_DEL,
55+
3656
/* add new commands above here */
3757

3858
__DEVLINK_CMD_MAX,
@@ -46,6 +66,31 @@ enum devlink_port_type {
4666
DEVLINK_PORT_TYPE_IB,
4767
};
4868

69+
enum devlink_sb_pool_type {
70+
DEVLINK_SB_POOL_TYPE_INGRESS,
71+
DEVLINK_SB_POOL_TYPE_EGRESS,
72+
};
73+
74+
/* static threshold - limiting the maximum number of bytes.
75+
* dynamic threshold - limiting the maximum number of bytes
76+
* based on the currently available free space in the shared buffer pool.
77+
* In this mode, the maximum quota is calculated based
78+
* on the following formula:
79+
* max_quota = alpha / (1 + alpha) * Free_Buffer
80+
* While Free_Buffer is the amount of none-occupied buffer associated to
81+
* the relevant pool.
82+
* The value range which can be passed is 0-20 and serves
83+
* for computation of alpha by following formula:
84+
* alpha = 2 ^ (passed_value - 10)
85+
*/
86+
87+
enum devlink_sb_threshold_type {
88+
DEVLINK_SB_THRESHOLD_TYPE_STATIC,
89+
DEVLINK_SB_THRESHOLD_TYPE_DYNAMIC,
90+
};
91+
92+
#define DEVLINK_SB_THRESHOLD_TO_ALPHA_MAX 20
93+
4994
enum devlink_attr {
5095
/* don't change the order or add anything between, this is ABI! */
5196
DEVLINK_ATTR_UNSPEC,
@@ -62,6 +107,18 @@ enum devlink_attr {
62107
DEVLINK_ATTR_PORT_IBDEV_NAME, /* string */
63108
DEVLINK_ATTR_PORT_SPLIT_COUNT, /* u32 */
64109
DEVLINK_ATTR_PORT_SPLIT_GROUP, /* u32 */
110+
DEVLINK_ATTR_SB_INDEX, /* u32 */
111+
DEVLINK_ATTR_SB_SIZE, /* u32 */
112+
DEVLINK_ATTR_SB_INGRESS_POOL_COUNT, /* u16 */
113+
DEVLINK_ATTR_SB_EGRESS_POOL_COUNT, /* u16 */
114+
DEVLINK_ATTR_SB_INGRESS_TC_COUNT, /* u16 */
115+
DEVLINK_ATTR_SB_EGRESS_TC_COUNT, /* u16 */
116+
DEVLINK_ATTR_SB_POOL_INDEX, /* u16 */
117+
DEVLINK_ATTR_SB_POOL_TYPE, /* u8 */
118+
DEVLINK_ATTR_SB_POOL_SIZE, /* u32 */
119+
DEVLINK_ATTR_SB_POOL_THRESHOLD_TYPE, /* u8 */
120+
DEVLINK_ATTR_SB_THRESHOLD, /* u32 */
121+
DEVLINK_ATTR_SB_TC_INDEX, /* u16 */
65122

66123
/* add new attributes above here, update the policy in devlink.c */
67124

0 commit comments

Comments
 (0)