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 const struct devlink_ops
*ops
;
30 char priv
[0] __aligned(NETDEV_ALIGN
);
34 struct list_head list
;
35 struct devlink
*devlink
;
38 enum devlink_port_type type
;
39 enum devlink_port_type desired_type
;
47 int (*port_type_set
)(struct devlink_port
*devlink_port
,
48 enum devlink_port_type port_type
);
49 int (*port_split
)(struct devlink
*devlink
, unsigned int port_index
,
51 int (*port_unsplit
)(struct devlink
*devlink
, unsigned int port_index
);
54 static inline void *devlink_priv(struct devlink
*devlink
)
57 return &devlink
->priv
;
60 static inline struct devlink
*priv_to_devlink(void *priv
)
63 return container_of(priv
, struct devlink
, priv
);
68 #if IS_ENABLED(CONFIG_NET_DEVLINK)
70 struct devlink
*devlink_alloc(const struct devlink_ops
*ops
, size_t priv_size
);
71 int devlink_register(struct devlink
*devlink
, struct device
*dev
);
72 void devlink_unregister(struct devlink
*devlink
);
73 void devlink_free(struct devlink
*devlink
);
74 int devlink_port_register(struct devlink
*devlink
,
75 struct devlink_port
*devlink_port
,
76 unsigned int port_index
);
77 void devlink_port_unregister(struct devlink_port
*devlink_port
);
78 void devlink_port_type_eth_set(struct devlink_port
*devlink_port
,
79 struct net_device
*netdev
);
80 void devlink_port_type_ib_set(struct devlink_port
*devlink_port
,
81 struct ib_device
*ibdev
);
82 void devlink_port_type_clear(struct devlink_port
*devlink_port
);
83 void devlink_port_split_set(struct devlink_port
*devlink_port
,
88 static inline struct devlink
*devlink_alloc(const struct devlink_ops
*ops
,
91 return kzalloc(sizeof(struct devlink
) + priv_size
, GFP_KERNEL
);
94 static inline int devlink_register(struct devlink
*devlink
, struct device
*dev
)
99 static inline void devlink_unregister(struct devlink
*devlink
)
103 static inline void devlink_free(struct devlink
*devlink
)
108 static inline int devlink_port_register(struct devlink
*devlink
,
109 struct devlink_port
*devlink_port
,
110 unsigned int port_index
)
115 static inline void devlink_port_unregister(struct devlink_port
*devlink_port
)
119 static inline void devlink_port_type_eth_set(struct devlink_port
*devlink_port
,
120 struct net_device
*netdev
)
124 static inline void devlink_port_type_ib_set(struct devlink_port
*devlink_port
,
125 struct ib_device
*ibdev
)
129 static inline void devlink_port_type_clear(struct devlink_port
*devlink_port
)
133 static inline void devlink_port_split_set(struct devlink_port
*devlink_port
,
140 #endif /* _NET_DEVLINK_H_ */