Skip to content

Commit 007f790

Browse files
jpirkodavem330
authored andcommitted
net: introduce generic switch devices support
The goal of this is to provide a possibility to support various switch chips. Drivers should implement relevant ndos to do so. Now there is only one ndo defined: - for getting physical switch id is in place. Note that user can use random port netdevice to access the switch. Signed-off-by: Jiri Pirko <jiri@resnulli.us> Reviewed-by: Thomas Graf <tgraf@suug.ch> Acked-by: Andy Gospodarek <gospo@cumulusnetworks.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 02637fc commit 007f790

9 files changed

Lines changed: 161 additions & 0 deletions

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
Switch (and switch-ish) device drivers HOWTO
2+
===========================
3+
4+
Please note that the word "switch" is here used in very generic meaning.
5+
This include devices supporting L2/L3 but also various flow offloading chips,
6+
including switches embedded into SR-IOV NICs.
7+
8+
Lets describe a topology a bit. Imagine the following example:
9+
10+
+----------------------------+ +---------------+
11+
| SOME switch chip | | CPU |
12+
+----------------------------+ +---------------+
13+
port1 port2 port3 port4 MNGMNT | PCI-E |
14+
| | | | | +---------------+
15+
PHY PHY | | | | NIC0 NIC1
16+
| | | | | |
17+
| | +- PCI-E -+ | |
18+
| +------- MII -------+ |
19+
+------------- MII ------------+
20+
21+
In this example, there are two independent lines between the switch silicon
22+
and CPU. NIC0 and NIC1 drivers are not aware of a switch presence. They are
23+
separate from the switch driver. SOME switch chip is by managed by a driver
24+
via PCI-E device MNGMNT. Note that MNGMNT device, NIC0 and NIC1 may be
25+
connected to some other type of bus.
26+
27+
Now, for the previous example show the representation in kernel:
28+
29+
+----------------------------+ +---------------+
30+
| SOME switch chip | | CPU |
31+
+----------------------------+ +---------------+
32+
sw0p0 sw0p1 sw0p2 sw0p3 MNGMNT | PCI-E |
33+
| | | | | +---------------+
34+
PHY PHY | | | | eth0 eth1
35+
| | | | | |
36+
| | +- PCI-E -+ | |
37+
| +------- MII -------+ |
38+
+------------- MII ------------+
39+
40+
Lets call the example switch driver for SOME switch chip "SOMEswitch". This
41+
driver takes care of PCI-E device MNGMNT. There is a netdevice instance sw0pX
42+
created for each port of a switch. These netdevices are instances
43+
of "SOMEswitch" driver. sw0pX netdevices serve as a "representation"
44+
of the switch chip. eth0 and eth1 are instances of some other existing driver.
45+
46+
The only difference of the switch-port netdevice from the ordinary netdevice
47+
is that is implements couple more NDOs:
48+
49+
ndo_switch_parent_id_get - This returns the same ID for two port netdevices
50+
of the same physical switch chip. This is
51+
mandatory to be implemented by all switch drivers
52+
and serves the caller for recognition of a port
53+
netdevice.
54+
ndo_switch_parent_* - Functions that serve for a manipulation of the switch
55+
chip itself (it can be though of as a "parent" of the
56+
port, therefore the name). They are not port-specific.
57+
Caller might use arbitrary port netdevice of the same
58+
switch and it will make no difference.
59+
ndo_switch_port_* - Functions that serve for a port-specific manipulation.

‎MAINTAINERS‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9059,6 +9059,13 @@ F: lib/swiotlb.c
90599059
F: arch/*/kernel/pci-swiotlb.c
90609060
F: include/linux/swiotlb.h
90619061

9062+
SWITCHDEV
9063+
M: Jiri Pirko <jiri@resnulli.us>
9064+
L: netdev@vger.kernel.org
9065+
S: Supported
9066+
F: net/switchdev/
9067+
F: include/net/switchdev.h
9068+
90629069
SYNOPSYS ARC ARCHITECTURE
90639070
M: Vineet Gupta <vgupta@synopsys.com>
90649071
S: Supported

‎include/linux/netdevice.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,12 @@ typedef u16 (*select_queue_fallback_t)(struct net_device *dev,
10181018
* performing GSO on a packet. The device returns true if it is
10191019
* able to GSO the packet, false otherwise. If the return value is
10201020
* false the stack will do software GSO.
1021+
*
1022+
* int (*ndo_switch_parent_id_get)(struct net_device *dev,
1023+
* struct netdev_phys_item_id *psid);
1024+
* Called to get an ID of the switch chip this port is part of.
1025+
* If driver implements this, it indicates that it represents a port
1026+
* of a switch chip.
10211027
*/
10221028
struct net_device_ops {
10231029
int (*ndo_init)(struct net_device *dev);
@@ -1171,6 +1177,10 @@ struct net_device_ops {
11711177
int (*ndo_get_lock_subclass)(struct net_device *dev);
11721178
bool (*ndo_gso_check) (struct sk_buff *skb,
11731179
struct net_device *dev);
1180+
#ifdef CONFIG_NET_SWITCHDEV
1181+
int (*ndo_switch_parent_id_get)(struct net_device *dev,
1182+
struct netdev_phys_item_id *psid);
1183+
#endif
11741184
};
11751185

11761186
/**

‎include/net/switchdev.h‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* include/net/switchdev.h - Switch device API
3+
* Copyright (c) 2014 Jiri Pirko <jiri@resnulli.us>
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation; either version 2 of the License, or
8+
* (at your option) any later version.
9+
*/
10+
#ifndef _LINUX_SWITCHDEV_H_
11+
#define _LINUX_SWITCHDEV_H_
12+
13+
#include <linux/netdevice.h>
14+
15+
#ifdef CONFIG_NET_SWITCHDEV
16+
17+
int netdev_switch_parent_id_get(struct net_device *dev,
18+
struct netdev_phys_item_id *psid);
19+
20+
#else
21+
22+
static inline int netdev_switch_parent_id_get(struct net_device *dev,
23+
struct netdev_phys_item_id *psid)
24+
{
25+
return -EOPNOTSUPP;
26+
}
27+
28+
#endif
29+
30+
#endif /* _LINUX_SWITCHDEV_H_ */

‎net/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ source "net/vmw_vsock/Kconfig"
228228
source "net/netlink/Kconfig"
229229
source "net/mpls/Kconfig"
230230
source "net/hsr/Kconfig"
231+
source "net/switchdev/Kconfig"
231232

232233
config RPS
233234
boolean

‎net/Makefile‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,6 @@ obj-$(CONFIG_OPENVSWITCH) += openvswitch/
7373
obj-$(CONFIG_VSOCKETS) += vmw_vsock/
7474
obj-$(CONFIG_NET_MPLS_GSO) += mpls/
7575
obj-$(CONFIG_HSR) += hsr/
76+
ifneq ($(CONFIG_NET_SWITCHDEV),)
77+
obj-y += switchdev/
78+
endif

‎net/switchdev/Kconfig‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#
2+
# Configuration for Switch device support
3+
#
4+
5+
config NET_SWITCHDEV
6+
boolean "Switch (and switch-ish) device support (EXPERIMENTAL)"
7+
depends on INET
8+
---help---
9+
This module provides glue between core networking code and device
10+
drivers in order to support hardware switch chips in very generic
11+
meaning of the word "switch". This include devices supporting L2/L3 but
12+
also various flow offloading chips, including switches embedded into
13+
SR-IOV NICs.

‎net/switchdev/Makefile‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#
2+
# Makefile for the Switch device API
3+
#
4+
5+
obj-$(CONFIG_NET_SWITCHDEV) += switchdev.o

‎net/switchdev/switchdev.c‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* net/switchdev/switchdev.c - Switch device API
3+
* Copyright (c) 2014 Jiri Pirko <jiri@resnulli.us>
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation; either version 2 of the License, or
8+
* (at your option) any later version.
9+
*/
10+
11+
#include <linux/kernel.h>
12+
#include <linux/types.h>
13+
#include <linux/init.h>
14+
#include <linux/netdevice.h>
15+
#include <net/switchdev.h>
16+
17+
/**
18+
* netdev_switch_parent_id_get - Get ID of a switch
19+
* @dev: port device
20+
* @psid: switch ID
21+
*
22+
* Get ID of a switch this port is part of.
23+
*/
24+
int netdev_switch_parent_id_get(struct net_device *dev,
25+
struct netdev_phys_item_id *psid)
26+
{
27+
const struct net_device_ops *ops = dev->netdev_ops;
28+
29+
if (!ops->ndo_switch_parent_id_get)
30+
return -EOPNOTSUPP;
31+
return ops->ndo_switch_parent_id_get(dev, psid);
32+
}
33+
EXPORT_SYMBOL(netdev_switch_parent_id_get);

0 commit comments

Comments
 (0)