]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - include/net/devlink.h
Merge tag 'sound-4.6-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai...
[karo-tx-linux.git] / include / net / devlink.h
1 /*
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>
5  *
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.
10  */
11 #ifndef _NET_DEVLINK_H_
12 #define _NET_DEVLINK_H_
13
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>
21
22 struct devlink_ops;
23
24 struct devlink {
25         struct list_head list;
26         struct list_head port_list;
27         const struct devlink_ops *ops;
28         struct device *dev;
29         possible_net_t _net;
30         char priv[0] __aligned(NETDEV_ALIGN);
31 };
32
33 struct devlink_port {
34         struct list_head list;
35         struct devlink *devlink;
36         unsigned index;
37         bool registered;
38         enum devlink_port_type type;
39         enum devlink_port_type desired_type;
40         void *type_dev;
41         bool split;
42         u32 split_group;
43 };
44
45 struct devlink_ops {
46         size_t priv_size;
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,
50                           unsigned int count);
51         int (*port_unsplit)(struct devlink *devlink, unsigned int port_index);
52 };
53
54 static inline void *devlink_priv(struct devlink *devlink)
55 {
56         BUG_ON(!devlink);
57         return &devlink->priv;
58 }
59
60 static inline struct devlink *priv_to_devlink(void *priv)
61 {
62         BUG_ON(!priv);
63         return container_of(priv, struct devlink, priv);
64 }
65
66 struct ib_device;
67
68 #if IS_ENABLED(CONFIG_NET_DEVLINK)
69
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,
84                             u32 split_group);
85
86 #else
87
88 static inline struct devlink *devlink_alloc(const struct devlink_ops *ops,
89                                             size_t priv_size)
90 {
91         return kzalloc(sizeof(struct devlink) + priv_size, GFP_KERNEL);
92 }
93
94 static inline int devlink_register(struct devlink *devlink, struct device *dev)
95 {
96         return 0;
97 }
98
99 static inline void devlink_unregister(struct devlink *devlink)
100 {
101 }
102
103 static inline void devlink_free(struct devlink *devlink)
104 {
105         kfree(devlink);
106 }
107
108 static inline int devlink_port_register(struct devlink *devlink,
109                                         struct devlink_port *devlink_port,
110                                         unsigned int port_index)
111 {
112         return 0;
113 }
114
115 static inline void devlink_port_unregister(struct devlink_port *devlink_port)
116 {
117 }
118
119 static inline void devlink_port_type_eth_set(struct devlink_port *devlink_port,
120                                              struct net_device *netdev)
121 {
122 }
123
124 static inline void devlink_port_type_ib_set(struct devlink_port *devlink_port,
125                                             struct ib_device *ibdev)
126 {
127 }
128
129 static inline void devlink_port_type_clear(struct devlink_port *devlink_port)
130 {
131 }
132
133 static inline void devlink_port_split_set(struct devlink_port *devlink_port,
134                                           u32 split_group)
135 {
136 }
137
138 #endif
139
140 #endif /* _NET_DEVLINK_H_ */