Linux 4.6-rc6
[cris-mirror.git] / include / net / devlink.h
blobc37d257891d62705ebbe9a18e3709bb31152e8ef
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>
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>
22 struct devlink_ops;
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);
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;
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);
54 static inline void *devlink_priv(struct devlink *devlink)
56 BUG_ON(!devlink);
57 return &devlink->priv;
60 static inline struct devlink *priv_to_devlink(void *priv)
62 BUG_ON(!priv);
63 return container_of(priv, struct devlink, priv);
66 struct ib_device;
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,
84 u32 split_group);
86 #else
88 static inline struct devlink *devlink_alloc(const struct devlink_ops *ops,
89 size_t priv_size)
91 return kzalloc(sizeof(struct devlink) + priv_size, GFP_KERNEL);
94 static inline int devlink_register(struct devlink *devlink, struct device *dev)
96 return 0;
99 static inline void devlink_unregister(struct devlink *devlink)
103 static inline void devlink_free(struct devlink *devlink)
105 kfree(devlink);
108 static inline int devlink_port_register(struct devlink *devlink,
109 struct devlink_port *devlink_port,
110 unsigned int port_index)
112 return 0;
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,
134 u32 split_group)
138 #endif
140 #endif /* _NET_DEVLINK_H_ */