Skip to content

Commit bfcd3a4

Browse files
jpirkodavem330
authored andcommitted
Introduce devlink infrastructure
Introduce devlink infrastructure for drivers to register and expose to userspace via generic Netlink interface. There are two basic objects defined: devlink - one instance for every "parent device", for example switch ASIC devlink port - one instance for every physical port of the device. This initial portion implements basic get/dump of objects to userspace. Also, port splitter and port type setting is implemented. Signed-off-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent bd070e2 commit bfcd3a4

6 files changed

Lines changed: 966 additions & 0 deletions

File tree

‎MAINTAINERS‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3499,6 +3499,14 @@ F: include/linux/device-mapper.h
34993499
F: include/linux/dm-*.h
35003500
F: include/uapi/linux/dm-*.h
35013501

3502+
DEVLINK
3503+
M: Jiri Pirko <jiri@mellanox.com>
3504+
L: netdev@vger.kernel.org
3505+
S: Supported
3506+
F: net/core/devlink.c
3507+
F: include/net/devlink.h
3508+
F: include/uapi/linux/devlink.h
3509+
35023510
DIALOG SEMICONDUCTOR DRIVERS
35033511
M: Support Opensource <support.opensource@diasemi.com>
35043512
W: http://www.dialog-semiconductor.com/products

‎include/net/devlink.h‎

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
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_ */

‎include/uapi/linux/devlink.h‎

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* include/uapi/linux/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+
12+
#ifndef _UAPI_LINUX_DEVLINK_H_
13+
#define _UAPI_LINUX_DEVLINK_H_
14+
15+
#define DEVLINK_GENL_NAME "devlink"
16+
#define DEVLINK_GENL_VERSION 0x1
17+
#define DEVLINK_GENL_MCGRP_CONFIG_NAME "config"
18+
19+
enum devlink_command {
20+
/* don't change the order or add anything between, this is ABI! */
21+
DEVLINK_CMD_UNSPEC,
22+
23+
DEVLINK_CMD_GET, /* can dump */
24+
DEVLINK_CMD_SET,
25+
DEVLINK_CMD_NEW,
26+
DEVLINK_CMD_DEL,
27+
28+
DEVLINK_CMD_PORT_GET, /* can dump */
29+
DEVLINK_CMD_PORT_SET,
30+
DEVLINK_CMD_PORT_NEW,
31+
DEVLINK_CMD_PORT_DEL,
32+
33+
DEVLINK_CMD_PORT_SPLIT,
34+
DEVLINK_CMD_PORT_UNSPLIT,
35+
36+
/* add new commands above here */
37+
38+
__DEVLINK_CMD_MAX,
39+
DEVLINK_CMD_MAX = __DEVLINK_CMD_MAX - 1
40+
};
41+
42+
enum devlink_port_type {
43+
DEVLINK_PORT_TYPE_NOTSET,
44+
DEVLINK_PORT_TYPE_AUTO,
45+
DEVLINK_PORT_TYPE_ETH,
46+
DEVLINK_PORT_TYPE_IB,
47+
};
48+
49+
enum devlink_attr {
50+
/* don't change the order or add anything between, this is ABI! */
51+
DEVLINK_ATTR_UNSPEC,
52+
53+
/* bus name + dev name together are a handle for devlink entity */
54+
DEVLINK_ATTR_BUS_NAME, /* string */
55+
DEVLINK_ATTR_DEV_NAME, /* string */
56+
57+
DEVLINK_ATTR_PORT_INDEX, /* u32 */
58+
DEVLINK_ATTR_PORT_TYPE, /* u16 */
59+
DEVLINK_ATTR_PORT_DESIRED_TYPE, /* u16 */
60+
DEVLINK_ATTR_PORT_NETDEV_IFINDEX, /* u32 */
61+
DEVLINK_ATTR_PORT_NETDEV_NAME, /* string */
62+
DEVLINK_ATTR_PORT_IBDEV_NAME, /* string */
63+
DEVLINK_ATTR_PORT_SPLIT_COUNT, /* u32 */
64+
DEVLINK_ATTR_PORT_SPLIT_GROUP, /* u32 */
65+
66+
/* add new attributes above here, update the policy in devlink.c */
67+
68+
__DEVLINK_ATTR_MAX,
69+
DEVLINK_ATTR_MAX = __DEVLINK_ATTR_MAX - 1
70+
};
71+
72+
#endif /* _UAPI_LINUX_DEVLINK_H_ */

‎net/Kconfig‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,13 @@ config DST_CACHE
396396
bool "dst cache"
397397
default n
398398

399+
config NET_DEVLINK
400+
tristate "Network physical/parent device Netlink interface"
401+
help
402+
Network physical/parent device Netlink interface provides
403+
infrastructure to support access to physical chip-wide config and
404+
monitoring.
405+
399406
endif # if NET
400407

401408
# Used by archs to tell that they support BPF_JIT

‎net/core/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ obj-$(CONFIG_CGROUP_NET_PRIO) += netprio_cgroup.o
2525
obj-$(CONFIG_CGROUP_NET_CLASSID) += netclassid_cgroup.o
2626
obj-$(CONFIG_LWTUNNEL) += lwtunnel.o
2727
obj-$(CONFIG_DST_CACHE) += dst_cache.o
28+
obj-$(CONFIG_NET_DEVLINK) += devlink.o

0 commit comments

Comments
 (0)