extend set/get netlink for embedded
Subsystems (4)
cover extend set/get netlink for embedded
This extends the PF_BRIDGE setlink and getlink so that they can be used generically outside of the Linux bridge module. Doing this allows embedded devices to use the same netlink interface that the software bridge is currently using.
In this patchset I opted to create two new ndo ops ndo_bridge_setlink and ndo_bridge_getlink. These ops pass the nlmsghdr to the device for handling. The netlink message is extended to support nested IFLA_AF_SPEC attributes. A IFLA_BRIDGE_FLAGS attribute is used to determine the target of the message either a master netdev is the target or the target is "self" indicating the target is the netdev. In this way we can send netlink msg to an embedded device or the linux sw bridge or both. If the set completes sucessfully the flag is cleared in this way we can learn what failed in the both case. This scheme is similar to how FDB updates are handled. If no flag attribute is present the message is sent to the master device to support the existing messages.
An initial IFLA_BRIDGE_MODE attribute is added to indicate if the bridge is in a VEPA mode or VEB mode. This is most useful for SR-IOV device and can be used to indicate support for VF to VF or VF to PF traffic. Without this we have no way of knowing this other then trial and error because not all hardware supports this.
In the future additional attributes can be added to handle other attributes. We could for example move some of the linux bridge sysfs attributes here if we want a netlink interface for them. This should also allow DSA switches to use the bridging tools. See RFC patch from Lennert
http://patchwork.ozlabs.org/patch/16578/
I could have simply added the VEPA attribute handling to the rtnl_setlink() routine but it seemed like a good feature to have all the bridging events and configuration on the same type. Also this should allow more powerful offloaded switches like the hardware supported via DSA access to the bridge control interface.
Also I think this interface should allow Vlad to add his port based VLAN interface here as well.
Any feedback/criticism appreciated thanks!
---
John Fastabend (3):
ixgbe: add setlink, getlink support to ixgbe and ixgbevf
net: set and query VEB/VEPA bridge mode via PF_BRIDGE
net: create generic bridge ops
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 59 ++++++ drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c | 3 drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c | 10 + include/linux/netdevice.h | 10 + include/linux/rtnetlink.h | 3 include/uapi/linux/if_bridge.h | 18 ++ net/bridge/br_device.c | 2 net/bridge/br_netlink.c | 75 +------- net/bridge/br_private.h | 7 + net/core/rtnetlink.c | 207 +++++++++++++++++++++ 10 files changed, 328 insertions(+), 66 deletions(-)
Signature · 1 line
Signature
PATCH 1/3 net: create generic bridge ops
The PF_BRIDGE:RTM_{GET|SET}LINK nlmsg family and type are currently embedded in the ./net/bridge module. This prohibits them from being used by other bridging devices. One example of this being hardware that has embedded bridging components.
In order to use these nlmsg types more generically this patch adds two net_device_ops hooks. One to set link bridge attributes and another to dump the current bride attributes.
ndo_bridge_setlink()
ndo_bridge_getlink()
---
include/linux/netdevice.h | 10 ++++++ net/bridge/br_device.c | 2 + net/bridge/br_netlink.c | 73 +++++++---------------------------------- net/bridge/br_private.h | 3 ++ net/core/rtnetlink.c | 80 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 108 insertions(+), 60 deletions(-)
include/linux/netdevice.h +10 -0
@@ -887,6 +887,10 @@ struct netdev_fcoe_hbainfo {* struct net_device *dev, int idx) * Used to add FDB entries to dump requests. Implementers should add * entries to skb and update idx with the number of entries. +* +* int (*ndo_bridge_setlink)(struct net_device *dev, struct nlmsghdr *nlh) +* int (*ndo_bridge_getlink)(struct sk_buff *skb, u32 pid, u32 seq, +* struct net_device *dev) */ struct net_device_ops {int (*ndo_init)(struct net_device *dev);
@@ -998,6 +1002,12 @@ struct net_device_ops {struct netlink_callback *cb, struct net_device *dev, int idx); + +int (*ndo_bridge_setlink)(struct net_device *dev, +struct nlmsghdr *nlh); +int (*ndo_bridge_getlink)(struct sk_buff *skb, +u32 pid,u32 seq, +struct net_device *dev); };/*
net/bridge/br_device.c +2 -0
@@ -313,6 +313,8 @@ static const struct net_device_ops br_netdev_ops = { .ndo_fdb_add = br_fdb_add, .ndo_fdb_del = br_fdb_delete, .ndo_fdb_dump = br_fdb_dump, + .ndo_bridge_getlink = br_getlink, + .ndo_bridge_setlink = br_setlink, };static void br_dev_free (struct net_device *dev)
net/bridge/br_netlink.c +13 -60
106 lines not on this page · raw message
net/bridge/br_private.h +3 -0
@@ -553,6 +553,9 @@ extern struct rtnl_link_ops br_link_ops;extern int br_netlink_init (void );extern void br_netlink_fini (void );extern void br_ifinfo_notify (int event,struct net_bridge_port *port); +extern int br_setlink (struct net_device *dev,struct nlmsghdr *nlmsg); +extern int br_getlink (struct sk_buff *skb,u32 pid,u32 seq, +struct net_device *dev);#ifdef CONFIG_SYSFS /* br_sysfs_if.c */
net/core/rtnetlink.c +80 -0
91 lines not on this page · raw message
PATCH 2/3 net: set and query VEB/VEPA bridge mode via PF_BRIDGE
In reply to John FastabendHardware switches may support enabling and disabling the loopback switch which puts the device in a VEPA mode defined in the IEEE 802.1Qbg specification. In this mode frames are not switched in the hardware but sent directly to the switch. SR-IOV capable NICs will likely support this mode I am aware of at least two such devices. Also I am told (but don't have any of this hardware available) that there are devices that only support VEPA modes. In these cases it is important at a minimum to be able to query these attributes.
This patch adds an additional IFLA_BRIDGE_MODE attribute that can be set and dumped via the PF_BRIDGE:{SET|GET}LINK operations. Also anticipating bridge attributes that may be common for both embedded bridges and software bridges this adds a flags attribute IFLA_BRIDGE_FLAGS currently used to determine if the command or event is being generated to/from an embedded bridge or software bridge. Finally, the event generation is pulled out of the bridge module and into rtnetlink proper.
For example using the macvlan driver in VEPA mode on top of an embedded switch requires putting the embedded switch into a VEPA mode to get the expected results.
-------- --------
| VEPA | | VEPA | <-- macvlan vepa edge relays
-------- --------
| |
| |
------------------
| VEPA | <-- embedded switch in NIC
------------------
|
|
-------------------
| external switch | <-- shiny new physical
------------------- switch with VEPA supportA packet sent from the macvlan VEPA at the top could be loopbacked on the embedded switch and never seen by the external switch. So in order for this to work the embedded switch needs to be set in the VEPA state via the above described commands.
By making these attributes nested in IFLA_AF_SPEC we allow future extensions to be made as needed.
---
include/uapi/linux/if_bridge.h | 18 ++++++++ net/bridge/br_netlink.c | 2 - net/bridge/br_private.h | 4 +- net/core/rtnetlink.c | 85 ++++++++++++++++++++++++++++++++++++++-- 4 files changed, 102 insertions(+), 7 deletions(-)
include/uapi/linux/if_bridge.h +18 -0
@@ -97,5 +97,23 @@ struct __fdb_entry { __u16 unused; }; +/* Bridge Flags */ +#define BRIDGE_FLAGS_MASTER 1/* Bridge command to/from master */ +#define BRIDGE_FLAGS_SELF 2/* Bridge command to/from lowerdev */ +#define BRIDGE_MODE_VEB 0/* Default loopback mode */ +#define BRIDGE_MODE_VEPA 1/* 802.1Qbg defined VEPA mode */ + +/* Bridge management nested attributes +* [IFLA_AF_SPEC] = { +* [IFLA_BRIDGE_FLAGS] +* [IFLA_BRIDGE_MODE] +* } +*/ +enum { +IFLA_BRIDGE_FLAGS , +IFLA_BRIDGE_MODE , + __IFLA_BRIDGE_MAX, +}; +#define IFLA_BRIDGE_MAX (__IFLA_BRIDGE_MAX - 1)#endif /* _UAPI_LINUX_IF_BRIDGE_H */
net/bridge/br_netlink.c +0 -2
@@ -166,8 +166,6 @@ int br_setlink(struct net_device *dev, struct nlmsghdr *nlh)br_port_state_selection (p->br);spin_unlock_bh (&p->br->lock); -br_ifinfo_notify (RTM_NEWLINK , p); -return 0 ; }
net/bridge/br_private.h +3 -1
@@ -158,7 +158,9 @@ struct net_bridge_portstatic inline struct net_bridge_port *br_port_get_rcu (const struct net_device *dev) { -struct net_bridge_port *port =rcu_dereference (dev->rx_handler_data); +struct net_bridge_port *port = +rcu_dereference_rtnl (dev->rx_handler_data); +return br_port_exists (dev) ? port :NULL ; }
net/core/rtnetlink.c +81 -4
109 lines not on this page · raw message
David Miller
maintainerWhere is patch #2?
Quoted 12 lines
-----Original Message-----
From: David Miller [mailto:[email protected]]
Sent: Wednesday, October 24, 2012 11:13 AM
To: Fastabend, John R
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Waskiewicz Jr, Peter P; Kirsher, Jeffrey T; [email protected]; [email protected]; Rose, Gregory V; [email protected]
Subject: Re: [net-next PATCH v1 0/3] extend set/get netlink for embedded
Quoted 1 line
Where is patch #2?
I received it and I saw netdev on the address list. Maybe it suffered some misadventure while traveling along the intertubes.
- Greg
Quoted 12 lines · Gregory V
Quoted 12 lines
-----Original Message-----
From: David Miller [mailto:[email protected]]
Sent: Wednesday, October 24, 2012 11:13 AM
To: Fastabend, John R
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Waskiewicz Jr, Peter P; Kirsher, Jeffrey T; [email protected]; [email protected]; Rose, Gregory V; [email protected]
Subject: Re: [net-next PATCH v1 0/3] extend set/get netlink for embedded
Quoted 6 lines
Quoted 1 line
Where is patch #2?
I received it and I saw netdev on the address list. Maybe it suffered some misadventure while traveling along the intertubes.
- Greg
Sorry I have no idea what happened to it. Anyways I see v2 on patchworks and netdev now. Thanks.
Quoted 3 lines · David Miller
Where is patch #2?
Apparently lost in the ether I was hoping it would show up. Sending a v2 sorry for the hassle hope it works this time.
.John
PATCH 3/3 ixgbe: add setlink, getlink support to ixgbe and ixgbevf
In reply to John FastabendThis adds support for the net device ops to manage the embedded hardware bridge on ixgbe devices. With this patch the bridge mode can be toggled between VEB and VEPA to support stacking macvlan devices or using the embedded switch without any SW component in 802.1Qbg/br environments.
Additionally, this adds source address pruning to the ixgbevf driver to prune any frames sent back from a reflective relay on the switch. This is required because the existing hardware does not support this. Without it frames get pushed into the stack with its own src mac which is invalid per 802.1Qbg VEPA definition.
---
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 59 ++++++++++++++++++++- drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c | 3 + drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c | 10 ++++ include/linux/rtnetlink.h | 3 + net/core/rtnetlink.c | 50 ++++++++++++++++++ 5 files changed, 122 insertions(+), 3 deletions(-)
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +56 -3
@@ -44,6 +44,7 @@#include <linux/ethtool.h> #include <linux/if.h> #include <linux/if_vlan.h> +#include <linux/if_bridge.h> #include <linux/prefetch.h> #include <scsi/fc/fc_fcoe.h>
@@ -3224,7 +3225,6 @@ static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)IXGBE_WRITE_REG (hw,IXGBE_VFRE (reg_offset ^1 ), reg_offset -1 );IXGBE_WRITE_REG (hw,IXGBE_VFTE (reg_offset), (~0 ) << vf_shift);IXGBE_WRITE_REG (hw,IXGBE_VFTE (reg_offset ^1 ), reg_offset -1 ); -IXGBE_WRITE_REG (hw,IXGBE_PFDTXGSWC ,IXGBE_PFDTXGSWC_VT_LBEN );/* Map PF MAC address in RAR Entry 0 to first pool following VFs */ hw->mac.ops.set_vmdq (hw,0 ,VMDQ_P (0 ));
@@ -3247,8 +3247,6 @@ static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)IXGBE_WRITE_REG (hw,IXGBE_GCR_EXT , gcr_ext); -/* enable Tx loopback for VF/PF communication */ -IXGBE_WRITE_REG (hw,IXGBE_PFDTXGSWC ,IXGBE_PFDTXGSWC_VT_LBEN );/* Enable MAC Anti-Spoofing */ hw->mac.ops.set_mac_anti_spoofing(hw, (adapter->num_vfs != 0),
@@ -7025,6 +7023,59 @@ static int ixgbe_ndo_fdb_dump(struct sk_buff *skb,return idx; } +static int ixgbe_ndo_bridge_setlink (struct net_device *dev, +struct nlmsghdr *nlh) +{ +struct ixgbe_adapter *adapter =netdev_priv (dev); +struct nlattr *attr, *br_spec; +int rem; + +if (!(adapter->flags &IXGBE_FLAG_SRIOV_ENABLED )) +return -EOPNOTSUPP ; + + br_spec =nlmsg_find_attr (nlh,sizeof (struct ifinfomsg ),IFLA_AF_SPEC ); + +nla_for_each_nested (attr, br_spec, rem) { +__u16 mode; +u32 reg =0 ; + +if (nla_type (attr) !=IFLA_BRIDGE_MODE ) +continue ; + + mode =nla_get_u16 (attr); +if (mode ==BRIDGE_MODE_VEPA ) + reg =0 ; +else if (mode ==BRIDGE_MODE_VEB ) + reg =IXGBE_PFDTXGSWC_VT_LBEN ; +else +return -EINVAL ; + +IXGBE_WRITE_REG (&adapter->hw,IXGBE_PFDTXGSWC , reg); + +e_info (drv,"enabling bridge mode: %s\n" , + mode ==BRIDGE_MODE_VEPA ?"VEPA" :"VEB" ); + } + +return 0 ; +} + +static int ixgbe_ndo_bridge_getlink (struct sk_buff *skb,u32 pid,u32 seq, +struct net_device *dev) +{ +struct ixgbe_adapter *adapter =netdev_priv (dev); +u16 mode; + +if (!(adapter->flags &IXGBE_FLAG_SRIOV_ENABLED )) +return 0 ; + +if (IXGBE_READ_REG (&adapter->hw,IXGBE_PFDTXGSWC ) &1 ) + mode =BRIDGE_MODE_VEB ; +else + mode =BRIDGE_MODE_VEPA ; + +return ndo_dflt_bridge_getlink (skb, pid, seq, dev, mode); +} +static const struct net_device_ops ixgbe_netdev_ops = { .ndo_open = ixgbe_open, .ndo_stop = ixgbe_close,
@@ -7064,6 +7115,8 @@ static const struct net_device_ops ixgbe_netdev_ops = { .ndo_fdb_add = ixgbe_ndo_fdb_add, .ndo_fdb_del = ixgbe_ndo_fdb_del, .ndo_fdb_dump = ixgbe_ndo_fdb_dump, + .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink, + .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink, };/**
drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c +3 -0
@@ -117,6 +117,9 @@ void ixgbe_enable_sriov(struct ixgbe_adapter *adapter, } } +/* Initialize default switching mode VEB */ +IXGBE_WRITE_REG (hw,IXGBE_PFDTXGSWC ,IXGBE_PFDTXGSWC_VT_LBEN ); +/* If call to enable VFs succeeded then allocate memory * for per VF control structures. */
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +10 -0
@@ -478,6 +478,16 @@ static bool ixgbevf_clean_rx_irq(struct ixgbevf_q_vector *q_vector, } skb->protocol =eth_type_trans (skb, rx_ring->netdev); +/* Workaround hardware that can't do proper VEPA multicast +* source pruning. +*/ +if ((skb->pkt_type & (PACKET_BROADCAST |PACKET_MULTICAST )) && + !(compare_ether_addr (adapter->netdev->dev_addr, +eth_hdr (skb)->h_source))) { +dev_kfree_skb_irq (skb); + goto next_desc; + } +ixgbevf_receive_skb (q_vector, skb, staterr, rx_desc); next_desc:
include/linux/rtnetlink.h +3 -0
@@ -69,4 +69,7 @@ extern int ndo_dflt_fdb_dump(struct sk_buff *skb,struct netlink_callback *cb, struct net_device *dev, int idx); + +extern int ndo_dflt_bridge_getlink (struct sk_buff *skb,u32 pid,u32 seq, +struct net_device *dev,u16 mode);#endif /* __LINUX_RTNETLINK_H */
net/core/rtnetlink.c +50 -0
56 lines not on this page · raw message