2 * include/net/devlink.h - Network physical device Netlink interface
3 * Copyright (c) 2016 Mellanox Technologies. All rights reserved.
4 * Copyright (c) 2016 Jiri Pirko <jiri@mellanox.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 #ifndef _NET_DEVLINK_H_
12 #define _NET_DEVLINK_H_
14 #include <linux/device.h>
15 #include <linux/slab.h>
16 #include <linux/gfp.h>
17 #include <linux/list.h>
18 #include <linux/netdevice.h>
19 #include <net/net_namespace.h>
20 #include <uapi/linux/devlink.h>
25 struct list_head list
;
26 struct list_head port_list
;
27 struct list_head sb_list
;
28 const struct devlink_ops
*ops
;
31 char priv
[0] __aligned(NETDEV_ALIGN
);
35 struct list_head list
;
36 struct devlink
*devlink
;
39 enum devlink_port_type type
;
40 enum devlink_port_type desired_type
;
46 struct devlink_sb_pool_info
{
47 enum devlink_sb_pool_type pool_type
;
49 enum devlink_sb_threshold_type threshold_type
;
53 int (*port_type_set
)(struct devlink_port
*devlink_port
,
54 enum devlink_port_type port_type
);
55 int (*port_split
)(struct devlink
*devlink
, unsigned int port_index
,
57 int (*port_unsplit
)(struct devlink
*devlink
, unsigned int port_index
);
58 int (*sb_pool_get
)(struct devlink
*devlink
, unsigned int sb_index
,
60 struct devlink_sb_pool_info
*pool_info
);
61 int (*sb_pool_set
)(struct devlink
*devlink
, unsigned int sb_index
,
62 u16 pool_index
, u32 size
,
63 enum devlink_sb_threshold_type threshold_type
);
64 int (*sb_port_pool_get
)(struct devlink_port
*devlink_port
,
65 unsigned int sb_index
, u16 pool_index
,
67 int (*sb_port_pool_set
)(struct devlink_port
*devlink_port
,
68 unsigned int sb_index
, u16 pool_index
,
70 int (*sb_tc_pool_bind_get
)(struct devlink_port
*devlink_port
,
71 unsigned int sb_index
,
73 enum devlink_sb_pool_type pool_type
,
74 u16
*p_pool_index
, u32
*p_threshold
);
75 int (*sb_tc_pool_bind_set
)(struct devlink_port
*devlink_port
,
76 unsigned int sb_index
,
78 enum devlink_sb_pool_type pool_type
,
79 u16 pool_index
, u32 threshold
);
80 int (*sb_occ_snapshot
)(struct devlink
*devlink
,
81 unsigned int sb_index
);
82 int (*sb_occ_max_clear
)(struct devlink
*devlink
,
83 unsigned int sb_index
);
84 int (*sb_occ_port_pool_get
)(struct devlink_port
*devlink_port
,
85 unsigned int sb_index
, u16 pool_index
,
86 u32
*p_cur
, u32
*p_max
);
87 int (*sb_occ_tc_port_bind_get
)(struct devlink_port
*devlink_port
,
88 unsigned int sb_index
,
90 enum devlink_sb_pool_type pool_type
,
91 u32
*p_cur
, u32
*p_max
);
93 int (*eswitch_mode_get
)(struct devlink
*devlink
, u16
*p_mode
);
94 int (*eswitch_mode_set
)(struct devlink
*devlink
, u16 mode
);
95 int (*eswitch_inline_mode_get
)(struct devlink
*devlink
, u8
*p_inline_mode
);
96 int (*eswitch_inline_mode_set
)(struct devlink
*devlink
, u8 inline_mode
);
99 static inline void *devlink_priv(struct devlink
*devlink
)
102 return &devlink
->priv
;
105 static inline struct devlink
*priv_to_devlink(void *priv
)
108 return container_of(priv
, struct devlink
, priv
);
113 #if IS_ENABLED(CONFIG_NET_DEVLINK)
115 struct devlink
*devlink_alloc(const struct devlink_ops
*ops
, size_t priv_size
);
116 int devlink_register(struct devlink
*devlink
, struct device
*dev
);
117 void devlink_unregister(struct devlink
*devlink
);
118 void devlink_free(struct devlink
*devlink
);
119 int devlink_port_register(struct devlink
*devlink
,
120 struct devlink_port
*devlink_port
,
121 unsigned int port_index
);
122 void devlink_port_unregister(struct devlink_port
*devlink_port
);
123 void devlink_port_type_eth_set(struct devlink_port
*devlink_port
,
124 struct net_device
*netdev
);
125 void devlink_port_type_ib_set(struct devlink_port
*devlink_port
,
126 struct ib_device
*ibdev
);
127 void devlink_port_type_clear(struct devlink_port
*devlink_port
);
128 void devlink_port_split_set(struct devlink_port
*devlink_port
,
130 int devlink_sb_register(struct devlink
*devlink
, unsigned int sb_index
,
131 u32 size
, u16 ingress_pools_count
,
132 u16 egress_pools_count
, u16 ingress_tc_count
,
133 u16 egress_tc_count
);
134 void devlink_sb_unregister(struct devlink
*devlink
, unsigned int sb_index
);
138 static inline struct devlink
*devlink_alloc(const struct devlink_ops
*ops
,
141 return kzalloc(sizeof(struct devlink
) + priv_size
, GFP_KERNEL
);
144 static inline int devlink_register(struct devlink
*devlink
, struct device
*dev
)
149 static inline void devlink_unregister(struct devlink
*devlink
)
153 static inline void devlink_free(struct devlink
*devlink
)
158 static inline int devlink_port_register(struct devlink
*devlink
,
159 struct devlink_port
*devlink_port
,
160 unsigned int port_index
)
165 static inline void devlink_port_unregister(struct devlink_port
*devlink_port
)
169 static inline void devlink_port_type_eth_set(struct devlink_port
*devlink_port
,
170 struct net_device
*netdev
)
174 static inline void devlink_port_type_ib_set(struct devlink_port
*devlink_port
,
175 struct ib_device
*ibdev
)
179 static inline void devlink_port_type_clear(struct devlink_port
*devlink_port
)
183 static inline void devlink_port_split_set(struct devlink_port
*devlink_port
,
188 static inline int devlink_sb_register(struct devlink
*devlink
,
189 unsigned int sb_index
, u32 size
,
190 u16 ingress_pools_count
,
191 u16 egress_pools_count
,
192 u16 ingress_tc_count
,
198 static inline void devlink_sb_unregister(struct devlink
*devlink
,
199 unsigned int sb_index
)
205 #endif /* _NET_DEVLINK_H_ */