Skip to contentSkip to conversation

ethtool: Introduce n-tuple filter programming support

PATCH Superseded Jeff Kirsher 4 participants 9 messages Feb 4, 2010

Subsystems (3)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/3 ethtool: Introduce n-tuple filter programming support

From: Peter Waskiewicz <[email protected]>

This patchset enables the ethtool layer to program n-tuple filters to an underlying device. The idea is to allow capable hardware to have static rules applied that can assist steering flows into appropriate queues.

Hardware that is known to support these types of filters today are ixgbe and niu.

---

 include/linux/ethtool.h   |   45 ++++++
 include/linux/netdevice.h |    3 
 net/core/dev.c            |    9 +
 net/core/ethtool.c        |  335 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 391 insertions(+), 1 deletions(-)
include/linux/ethtool.h +45 -0
index ef4a2d8..3e20dee 100644
@@ -14,6 +14,7 @@
 #define _LINUX_ETHTOOL_H
 
 #include <linux/types.h>
+#include <linux/rculist.h>
 
 /* This should work for both 32 and 64 bit userland. */
 struct ethtool_cmd {
@@ -242,6 +243,7 @@ enum ethtool_stringset {
 	ETH_SS_TEST		= 0,
 	ETH_SS_STATS,
 	ETH_SS_PRIV_FLAGS,
+	ETH_SS_NTUPLE_FILTERS,
 };
 
 /* for passing string sets for data tagging */
@@ -290,6 +292,7 @@ struct ethtool_perm_addr {
  */
 enum ethtool_flags {
 	ETH_FLAG_LRO		= (1 << 15),	/* LRO is enabled */
+	ETH_FLAG_NTUPLE		= (1 << 27),	/* N-tuple filters enabled */
 };
 
 /* The following structures are for supporting RX network flow
@@ -363,6 +366,43 @@ struct ethtool_rxnfc {
 	__u32				rule_locs[0];
 };
 
+struct ethtool_rx_ntuple_flow_spec {
+	__u32		 flow_type;
+	union {
+		struct ethtool_tcpip4_spec		tcp_ip4_spec;
+		struct ethtool_tcpip4_spec		udp_ip4_spec;
+		struct ethtool_tcpip4_spec		sctp_ip4_spec;
+		struct ethtool_ah_espip4_spec		ah_ip4_spec;
+		struct ethtool_ah_espip4_spec		esp_ip4_spec;
+		struct ethtool_rawip4_spec		raw_ip4_spec;
+		struct ethtool_ether_spec		ether_spec;
+		struct ethtool_usrip4_spec		usr_ip4_spec;
+		__u8					hdata[64];
+	} h_u, m_u; /* entry, mask */
+
+	__u16	        vlan_tag;
+	__u16	        vlan_tag_mask;
+	__u64		data;      /* user-defined flow spec data */
+	__u64		data_mask; /* user-defined flow spec mask */
+
+	/* signed to distinguish between queue and actions (DROP) */
+	__s32		action;
+#define ETHTOOL_RXNTUPLE_ACTION_DROP -1
+	struct list_head list;
+};
+
+struct ethtool_rx_ntuple_list {
+#define ETHTOOL_MAX_NTUPLE_LIST_ENTRY 1024
+#define ETHTOOL_MAX_NTUPLE_STRING_PER_ENTRY 14
+	struct list_head	list;
+	int			count;
+};
+
+struct ethtool_rx_ntuple {
+	__u32					cmd;
+	struct ethtool_rx_ntuple_flow_spec	fs;
+};
+
 #define ETHTOOL_FLASH_MAX_FILENAME	128
 enum ethtool_flash_op_type {
 	ETHTOOL_FLASH_ALL_REGIONS	= 0,
@@ -500,6 +540,8 @@ struct ethtool_ops {
 	int	(*set_rxnfc)(struct net_device *, struct ethtool_rxnfc *);
 	int     (*flash_device)(struct net_device *, struct ethtool_flash *);
 	int	(*reset)(struct net_device *, u32 *);
+	int	(*set_rx_ntuple)(struct net_device *, struct ethtool_rx_ntuple *);
+	int	(*get_rx_ntuple)(struct net_device *, u32 stringset, void *);
 };
 #endif /* __KERNEL__ */
 
@@ -559,6 +601,9 @@ struct ethtool_ops {
 #define	ETHTOOL_FLASHDEV	0x00000033 /* Flash firmware to device */
 #define	ETHTOOL_RESET		0x00000034 /* Reset hardware */
 
+#define ETHTOOL_SRXNTUPLE	0x00000035 /* Add an n-tuple filter to device */
+#define ETHTOOL_GRXNTUPLE	0x00000036 /* Get n-tuple filters from device */
+
 /* compatibility with older code */
 #define SPARC_ETH_GSET		ETHTOOL_GSET
 #define SPARC_ETH_SSET		ETHTOOL_SSET
include/linux/netdevice.h +3 -0
index 93a32a5..34edf5e 100644
@@ -740,6 +740,7 @@ struct net_device {
 #define NETIF_F_FCOE_CRC	(1 << 24) /* FCoE CRC32 */
 #define NETIF_F_SCTP_CSUM	(1 << 25) /* SCTP checksum offload */
 #define NETIF_F_FCOE_MTU	(1 << 26) /* Supports max FCoE MTU, 2158 bytes*/
+#define NETIF_F_NTUPLE		(1 << 27) /* N-tuple filters supported */
 
 	/* Segmentation offload features */
 #define NETIF_F_GSO_SHIFT	16
@@ -948,6 +949,8 @@ struct net_device {
 	/* max exchange id for FCoE LRO by ddp */
 	unsigned int		fcoe_ddp_xid;
 #endif
+	/* n-tuple filter list attached to this device */
+	struct ethtool_rx_ntuple_list ethtool_ntuple_list;
 };
 #define to_net_dev(d) container_of(d, struct net_device, dev)
 
net/core/dev.c +9 -0
index 2cba5c5..0b0f241 100644
@@ -5392,6 +5392,8 @@ struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name,
 
 	netdev_init_queues(dev);
 
+	INIT_LIST_HEAD(&dev->ethtool_ntuple_list.list);
+	dev->ethtool_ntuple_list.count = 0;
 	INIT_LIST_HEAD(&dev->napi_list);
 	INIT_LIST_HEAD(&dev->unreg_list);
 	INIT_LIST_HEAD(&dev->link_watch_list);
@@ -5420,6 +5422,7 @@ EXPORT_SYMBOL(alloc_netdev_mq);
 void free_netdev(struct net_device *dev)
 {
 	struct napi_struct *p, *n;
+	struct ethtool_rx_ntuple_flow_spec *fs, *f;
 
 	release_net(dev_net(dev));
 
@@ -5428,6 +5431,12 @@ void free_netdev(struct net_device *dev)
 	/* Flush device addresses */
 	dev_addr_flush(dev);
 
+	/* Clear ethtool n-tuple list */
+	list_for_each_entry_safe(fs, f, &dev->ethtool_ntuple_list.list, list) {
+		list_del(&fs->list);
+	}
+	dev->ethtool_ntuple_list.count = 0;
+
 	list_for_each_entry_safe(p, n, &dev->napi_list, dev_list)
 		netif_napi_del(p);
 
net/core/ethtool.c +334 -1

380 lines not on this page · raw message

#1 lore raw

PATCH v2 2/3 ixgbe: Add support for the new ethtool n-tuple programming interface

From: PJ Waskiewicz <[email protected]>

This patch adds n-tuple filter programming to 82599.

---

 drivers/net/ixgbe/ixgbe.h         |    4 +
 drivers/net/ixgbe/ixgbe_82599.c   |  106 +++++++++++++++++++++++++++++++----
 drivers/net/ixgbe/ixgbe_ethtool.c |  111 ++++++++++++++++++++++++++++++++++++-
 drivers/net/ixgbe/ixgbe_main.c    |   13 ++++
 drivers/net/ixgbe/ixgbe_type.h    |    9 +++
 5 files changed, 225 insertions(+), 18 deletions(-)
drivers/net/ixgbe/ixgbe.h +4 -0
index bffbe0d..19e94ee 100644
@@ -453,6 +453,10 @@ extern s32 ixgbe_init_fdir_perfect_82599(struct ixgbe_hw *hw, u32 pballoc);
 extern s32 ixgbe_fdir_add_signature_filter_82599(struct ixgbe_hw *hw,
                                                  struct ixgbe_atr_input *input,
                                                  u8 queue);
+extern s32 ixgbe_fdir_add_perfect_filter_82599(struct ixgbe_hw *hw,
+                                      struct ixgbe_atr_input *input,
+                                      struct ixgbe_atr_input_masks *input_masks,
+                                      u16 soft_id, u8 queue);
 extern s32 ixgbe_atr_set_vlan_id_82599(struct ixgbe_atr_input *input,
                                        u16 vlan_id);
 extern s32 ixgbe_atr_set_src_ipv4_82599(struct ixgbe_atr_input *input,
drivers/net/ixgbe/ixgbe_82599.c +93 -13

197 lines not on this page · raw message

drivers/net/ixgbe/ixgbe_ethtool.c +108 -3

143 lines not on this page · raw message

drivers/net/ixgbe/ixgbe_main.c +11 -2
index 2a3c831..ca57e74 100644
@@ -4187,6 +4187,7 @@ static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
 {
 	struct ixgbe_hw *hw = &adapter->hw;
 	struct pci_dev *pdev = adapter->pdev;
+	struct net_device *dev = adapter->netdev;
 	unsigned int rss;
 #ifdef CONFIG_IXGBE_DCB
 	int j;
@@ -4214,10 +4215,18 @@ static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
 		adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
 		adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
 		adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
-		adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
+		if (dev->features & NETIF_F_NTUPLE) {
+			/* Flow Director perfect filter enabled */
+			adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
+			adapter->atr_sample_rate = 0;
+			spin_lock_init(&adapter->fdir_perfect_lock);
+		} else {
+			/* Flow Director hash filters enabled */
+			adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
+			adapter->atr_sample_rate = 20;
+		}
 		adapter->ring_feature[RING_F_FDIR].indices =
 		                                         IXGBE_MAX_FDIR_INDICES;
-		adapter->atr_sample_rate = 20;
 		adapter->fdir_pballoc = 0;
 #ifdef IXGBE_FCOE
 		adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
drivers/net/ixgbe/ixgbe_type.h +9 -0
index 0db67c1..2be9074 100644
@@ -2129,6 +2129,15 @@ struct ixgbe_atr_input {
 	u8 byte_stream[42];
 };
 
+struct ixgbe_atr_input_masks {
+	u32 src_ip_mask;
+	u32 dst_ip_mask;
+	u16 src_port_mask;
+	u16 dst_port_mask;
+	u16 vlan_id_mask;
+	u16 data_mask;
+};
+
 enum ixgbe_eeprom_type {
 	ixgbe_eeprom_uninitialized = 0,
 	ixgbe_eeprom_spi,
#2 lore raw

PATCH v2 3/3 ixgbe: Bump driver version up

In reply to Jeff Kirsher

From: Peter Waskiewicz <[email protected]>

Driver has gone under significant changes, the version should reflect that.

---

 drivers/net/ixgbe/ixgbe_main.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/net/ixgbe/ixgbe_main.c +1 -1
index ca57e74..c308b59 100644
@@ -51,7 +51,7 @@ char ixgbe_driver_name[] = "ixgbe";
 static const char ixgbe_driver_string[] =
                               "Intel(R) 10 Gigabit PCI Express Network Driver";
 
-#define DRV_VERSION "2.0.44-k2"
+#define DRV_VERSION "2.0.62-k2"
 const char ixgbe_driver_version[] = DRV_VERSION;
 static char ixgbe_copyright[] = "Copyright (c) 1999-2010 Intel Corporation.";
 
maintainer
#3 lore raw
In reply to Jeff Kirsher

From: Jeff Kirsher <[email protected]>
Date: Wed, 03 Feb 2010 23:48:13 -0800

include/linux/ethtool.h struct ethtool_rxnfc { · line 392

Quoted 3 lines
include/linux/ethtool.h +3 -0
+#define ETHTOOL_RXNTUPLE_ACTION_DROP -1
+	struct list_head list;
+};

You can't do this.

You put the list_head here in the kernel header, which BTW can be used by userspace too, and then you elide it in the ethtool utility copy of the header.

Use an encapsulator if you must inside of the kernel, but keep the userspace visible data structure clean of RCU and list_head kernel datastructures.

Thanks.

#4 lore raw
Quoted 9 lines · David Miller

From: Jeff Kirsher <[email protected]>
Date: Wed, 03 Feb 2010 23:48:13 -0800

include/linux/ethtool.h struct ethtool_rxnfc { · line 392

Quoted 3 lines
include/linux/ethtool.h +3 -0
+#define ETHTOOL_RXNTUPLE_ACTION_DROP -1
+	struct list_head list;
+};

You can't do this.

Quoted 7 lines

You put the list_head here in the kernel header, which BTW can be used by userspace too, and then you elide it in the ethtool utility copy of the header.

Use an encapsulator if you must inside of the kernel, but keep the userspace visible data structure clean of RCU and list_head kernel datastructures.

Ok. I'll respin this asap. Thanks for the quick review Dave.

-PJ

#5 lore raw
Quoted 15 lines · Peter P
Quoted 13 lines · David Miller

From: Jeff Kirsher<[email protected]>
Date: Wed, 03 Feb 2010 23:48:13 -0800

include/linux/ethtool.h struct ethtool_rxnfc { · line 392

Quoted 3 lines
include/linux/ethtool.h +3 -0
+#define ETHTOOL_RXNTUPLE_ACTION_DROP -1
+	struct list_head list;
+};

You can't do this.

You put the list_head here in the kernel header, which BTW can be used by userspace too, and then you elide it in the ethtool utility copy of the header.

Quoted 5 lines
Quoted 3 lines

Use an encapsulator if you must inside of the kernel, but keep the userspace visible data structure clean of RCU and list_head kernel datastructures.

Ok. I'll respin this asap. Thanks for the quick review Dave.

Great. I'll look for the updated userspace patch, too, and put it into the ethtool-2.6.34 pile (ie. ethtool-net-next).

Jeff

#6 lore raw
Quoted 16 lines · Jeff Garzik
Quoted 15 lines · Peter P
Quoted 13 lines · David Miller

From: Jeff Kirsher<[email protected]>
Date: Wed, 03 Feb 2010 23:48:13 -0800

include/linux/ethtool.h struct ethtool_rxnfc { · line 392

Quoted 3 lines
include/linux/ethtool.h +3 -0
+#define ETHTOOL_RXNTUPLE_ACTION_DROP -1
+	struct list_head list;
+};

You can't do this.

You put the list_head here in the kernel header, which BTW can be used by userspace too, and then you elide it in the ethtool utility copy of the header.

Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

Use an encapsulator if you must inside of the kernel, but keep the userspace visible data structure clean of RCU and list_head kernel datastructures.

Ok. I'll respin this asap. Thanks for the quick review Dave.

Great. I'll look for the updated userspace patch, too, and put it into the ethtool-2.6.34 pile (ie. ethtool-net-next).

I didn't plan on respinning the userspace side. I put a container wrapped around the flow_spec struct to do the list management in the kernel. This shouldn't need a change to userspace.

Cheers,
-PJ

#7 lore raw
Quoted 23 lines · Peter P Waskiewicz Jr
Quoted 22 lines · Jeff Garzik
Quoted 20 lines · Peter P
Quoted 9 lines · David Miller

From: Jeff Kirsher<[email protected]>
Date: Wed, 03 Feb 2010 23:48:13 -0800

include/linux/ethtool.h struct ethtool_rxnfc { · line 392

Quoted 3 lines
include/linux/ethtool.h +3 -0
+#define ETHTOOL_RXNTUPLE_ACTION_DROP -1
+	struct list_head list;
+};

You can't do this.

Quoted 7 lines

You put the list_head here in the kernel header, which BTW can be used by userspace too, and then you elide it in the ethtool utility copy of the header.

Use an encapsulator if you must inside of the kernel, but keep the userspace visible data structure clean of RCU and list_head kernel datastructures.

Ok. I'll respin this asap. Thanks for the quick review Dave.

Quoted 7 lines
Quoted 3 lines

Great. I'll look for the updated userspace patch, too, and put it into the ethtool-2.6.34 pile (ie. ethtool-net-next).

I didn't plan on respinning the userspace side. I put a container wrapped around the flow_spec struct to do the list management in the kernel. This shouldn't need a change to userspace.

Well, I figured there would be some trivial tweaks and patch offsets, because we want to keep the kernel ethtool.h and userspace ethtool-copy.h headers in sync.

Either way, no big deal. I'll make sure net-next and ethtool match up, after your userspace patch is applied, one way or the other.

Jeff

#8 lore raw
Quoted 32 lines · Jeff Garzik
Quoted 23 lines · Peter P Waskiewicz Jr
Quoted 22 lines · Jeff Garzik
Quoted 20 lines · Peter P
Quoted 9 lines · David Miller

From: Jeff Kirsher<[email protected]>
Date: Wed, 03 Feb 2010 23:48:13 -0800

include/linux/ethtool.h struct ethtool_rxnfc { · line 392

Quoted 3 lines
include/linux/ethtool.h +3 -0
+#define ETHTOOL_RXNTUPLE_ACTION_DROP -1
+	struct list_head list;
+};

You can't do this.

Quoted 7 lines

You put the list_head here in the kernel header, which BTW can be used by userspace too, and then you elide it in the ethtool utility copy of the header.

Use an encapsulator if you must inside of the kernel, but keep the userspace visible data structure clean of RCU and list_head kernel datastructures.

Ok. I'll respin this asap. Thanks for the quick review Dave.

Quoted 7 lines
Quoted 3 lines

Great. I'll look for the updated userspace patch, too, and put it into the ethtool-2.6.34 pile (ie. ethtool-net-next).

I didn't plan on respinning the userspace side. I put a container wrapped around the flow_spec struct to do the list management in the kernel. This shouldn't need a change to userspace.

Quoted 6 lines

Well, I figured there would be some trivial tweaks and patch offsets, because we want to keep the kernel ethtool.h and userspace ethtool-copy.h headers in sync.

Either way, no big deal. I'll make sure net-next and ethtool match up, after your userspace patch is applied, one way or the other.

Well, my "fixing" of the kernel side will make the structures align now.

Thanks for staying on top of this though. :-)

-PJ