Skip to contentSkip to conversation

hyperv: Add support for virtual Receive Side Scaling (vRSS)

PATCH Superseded Haiyang Zhang 4 participants 6 messages Mar 18, 2014 – Mar 20, 2014

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Haiyang Zhang

author maintainer
#0 lore raw

PATCH v3 1/1 hyperv: Add support for virtual Receive Side Scaling (vRSS)

This feature allows multiple channels to be used by each virtual NIC. It is available on Hyper-V host 2012 R2.

---
 drivers/net/hyperv/hyperv_net.h   |  112 ++++++++++++++++++++++-
 drivers/net/hyperv/netvsc.c       |  134 +++++++++++++++++++++-----
 drivers/net/hyperv/netvsc_drv.c   |  102 +++++++++++++++++++-
 drivers/net/hyperv/rndis_filter.c |  187 ++++++++++++++++++++++++++++++++++++-
 4 files changed, 503 insertions(+), 32 deletions(-)
drivers/net/hyperv/hyperv_net.h +111 -1
index 13010b4..c2d72f6 100644
@@ -28,6 +28,98 @@
 #include <linux/hyperv.h>
 #include <linux/rndis.h>
 
+/* RSS related */
+#define OID_GEN_RECEIVE_SCALE_CAPABILITIES 0x00010203  /* query only */
+#define OID_GEN_RECEIVE_SCALE_PARAMETERS 0x00010204  /* query and set */
+
+#define NDIS_OBJECT_TYPE_RSS_CAPABILITIES 0x88
+#define NDIS_OBJECT_TYPE_RSS_PARAMETERS 0x89
+
+#define NDIS_RECEIVE_SCALE_CAPABILITIES_REVISION_2 2
+#define NDIS_RECEIVE_SCALE_PARAMETERS_REVISION_2 2
+
+struct ndis_obj_header {
+	u8 type;
+	u8 rev;
+	u16 size;
+} __packed;
+
+
+/* ndis_recv_scale_cap/cap_flag */
+#define NDIS_RSS_CAPS_MESSAGE_SIGNALED_INTERRUPTS 0x01000000
+#define NDIS_RSS_CAPS_CLASSIFICATION_AT_ISR       0x02000000
+#define NDIS_RSS_CAPS_CLASSIFICATION_AT_DPC       0x04000000
+#define NDIS_RSS_CAPS_USING_MSI_X                 0x08000000
+#define NDIS_RSS_CAPS_RSS_AVAILABLE_ON_PORTS      0x10000000
+#define NDIS_RSS_CAPS_SUPPORTS_MSI_X              0x20000000
+#define NDIS_RSS_CAPS_HASH_TYPE_TCP_IPV4          0x00000100
+#define NDIS_RSS_CAPS_HASH_TYPE_TCP_IPV6          0x00000200
+#define NDIS_RSS_CAPS_HASH_TYPE_TCP_IPV6_EX       0x00000400
+
+struct ndis_recv_scale_cap { /* NDIS_RECEIVE_SCALE_CAPABILITIES */
+	struct ndis_obj_header hdr;
+	u32 cap_flag;
+	u32 num_int_msg;
+	u32 num_recv_que;
+	u16 num_indirect_tabent;
+} __packed;
+
+
+/* ndis_recv_scale_param flags */
+#define NDIS_RSS_PARAM_FLAG_BASE_CPU_UNCHANGED     0x0001
+#define NDIS_RSS_PARAM_FLAG_HASH_INFO_UNCHANGED    0x0002
+#define NDIS_RSS_PARAM_FLAG_ITABLE_UNCHANGED       0x0004
+#define NDIS_RSS_PARAM_FLAG_HASH_KEY_UNCHANGED     0x0008
+#define NDIS_RSS_PARAM_FLAG_DISABLE_RSS            0x0010
+
+/* Hash info bits */
+#define NDIS_HASH_FUNC_TOEPLITZ 0x00000001
+#define NDIS_HASH_IPV4          0x00000100
+#define NDIS_HASH_TCP_IPV4      0x00000200
+#define NDIS_HASH_IPV6          0x00000400
+#define NDIS_HASH_IPV6_EX       0x00000800
+#define NDIS_HASH_TCP_IPV6      0x00001000
+#define NDIS_HASH_TCP_IPV6_EX   0x00002000
+
+#define NDIS_RSS_INDIRECTION_TABLE_MAX_SIZE_REVISION_2 (128 * 4)
+#define NDIS_RSS_HASH_SECRET_KEY_MAX_SIZE_REVISION_2   40
+
+#define ITAB_NUM 128
+#define HASH_KEYLEN NDIS_RSS_HASH_SECRET_KEY_MAX_SIZE_REVISION_2
+extern u8 netvsc_hash_key[];
+
+struct ndis_recv_scale_param { /* NDIS_RECEIVE_SCALE_PARAMETERS */
+	struct ndis_obj_header hdr;
+
+	/* Qualifies the rest of the information */
+	u16 flag;
+
+	/* The base CPU number to do receive processing. not used */
+	u16 base_cpu_number;
+
+	/* This describes the hash function and type being enabled */
+	u32 hashinfo;
+
+	/* The size of indirection table array */
+	u16 indirect_tabsize;
+
+	/* The offset of the indirection table from the beginning of this
+	 * structure
+	 */
+	u32 indirect_taboffset;
+
+	/* The size of the hash secret key */
+	u16 hashkey_size;
+
+	/* The offset of the secret key from the beginning of this structure */
+	u32 kashkey_offset;
+
+	u32 processor_masks_offset;
+	u32 num_processor_masks;
+	u32 processor_masks_entry_size;
+};
+
+
 /* Fwd declaration */
 struct hv_netvsc_packet;
 struct ndis_tcp_ip_checksum_info;
@@ -39,6 +131,8 @@ struct xferpage_packet {
 
 	/* # of netvsc packets this xfer packet contains */
 	u32 count;
+
+	struct vmbus_channel *channel;
 };
 
 /*
@@ -54,6 +148,9 @@ struct hv_netvsc_packet {
 	bool is_data_pkt;
 	u16 vlan_tci;
 
+	u16 q_idx;
+	struct vmbus_channel *channel;
+
 	/*
 	 * Valid only for receives when we break a xfer page packet
 	 * into multiple netvsc packets
@@ -120,6 +217,7 @@ void netvsc_linkstatus_callback(struct hv_device *device_obj,
 int netvsc_recv_callback(struct hv_device *device_obj,
 			struct hv_netvsc_packet *packet,
 			struct ndis_tcp_ip_checksum_info *csum_info);
+extern void netvsc_channel_cb(void *context);
 int rndis_filter_open(struct hv_device *dev);
 int rndis_filter_close(struct hv_device *dev);
 int rndis_filter_device_add(struct hv_device *dev,
@@ -522,6 +620,8 @@ struct nvsp_message {
 
 #define NETVSC_PACKET_SIZE                      2048
 
+#define VRSS_SEND_TAB_SIZE 16
+
 /* Per netvsc channel-specific */
 struct netvsc_device {
 	struct hv_device *dev;
@@ -555,10 +655,20 @@ struct netvsc_device {
 
 	struct net_device *ndev;
 
+	struct vmbus_channel *chn_table[NR_CPUS];
+	u32 send_table[VRSS_SEND_TAB_SIZE];
+	u32 num_chn;
+	atomic_t queue_sends[NR_CPUS];
+
 	/* Holds rndis device info */
 	void *extension;
-	/* The recive buffer for this device */
+
+	int ring_size;
+
+	/* The primary channel callback buffer */
 	unsigned char cb_buffer[NETVSC_PACKET_SIZE];
+	/* The sub channel callback buffer */
+	unsigned char *sub_cb_buf;
 };
 
 /* NdisInitialize message */
drivers/net/hyperv/netvsc.c +108 -26

293 lines not on this page · raw message

drivers/net/hyperv/netvsc_drv.c +99 -3

152 lines not on this page · raw message

drivers/net/hyperv/rndis_filter.c +185 -2

235 lines not on this page · raw message

Signature · 1 line
1.7.4.1
maintainer
#1 lore raw

From: Haiyang Zhang <[email protected]>
Date: Tue, 18 Mar 2014 15:15:22 -0700

drivers/net/hyperv/hyperv_net.h line 48

Quoted 8 lines
drivers/net/hyperv/hyperv_net.h +8 -0
+struct ndis_obj_header {
+	u8 type;
+	u8 rev;
+	u16 size;
+} __packed;
+
+
+/* ndis_recv_scale_cap/cap_flag */

One empty line is sufficient, we don't need two of them here.

Quoted 1 line

+extern u8 netvsc_hash_key[];

We no longer use extern in header file function declarations.

drivers/net/hyperv/hyperv_net.h line 123

Quoted 7 lines
drivers/net/hyperv/hyperv_net.h +6 -0
+	u32 processor_masks_offset;
+	u32 num_processor_masks;
+	u32 processor_masks_entry_size;
+};
+
+
 /* Fwd declaration */

Again, one empty line is enough.

drivers/net/hyperv/hyperv_net.h void netvsc_linkstatus_callback(struct hv_device *device_obj, · line 220

Quoted 5 lines
drivers/net/hyperv/hyperv_net.h +1 -0
@@ -120,6 +217,7 @@ void netvsc_linkstatus_callback(struct hv_device *device_obj,
 int netvsc_recv_callback(struct hv_device *device_obj,
 			struct hv_netvsc_packet *packet,
 			struct ndis_tcp_ip_checksum_info *csum_info);
+extern void netvsc_channel_cb(void *context);

Again, please remove this extern in function declarations.

drivers/net/hyperv/netvsc.c static void netvsc_send_completion(struct netvsc_device *net_device, · line 505

Quoted 4 lines
drivers/net/hyperv/netvsc.c +4 -0
+		if (netif_tx_queue_stopped(netdev_get_tx_queue(ndev, q_idx)) &&
+			!net_device->start_remove &&
+			(hv_ringbuf_avail_percent(&channel->outbound) >
+			RING_AVAIL_PERCENT_HIWATER || queue_sends < 1))

For the second time, this is not properly indented. Multi-line conditionals should be formatted like this:

	if (CONDITION1 OPERATOR
	    CONDITION2 OPERATOR
	    ...)

etc. For example, this specifically should be:

		if (netif_tx_queue_stopped(netdev_get_tx_queue(ndev, q_idx)) &&
		    !net_device->start_remove &&
		    (hv_ringbuf_avail_percent(&channel->outbound) >
		     RING_AVAIL_PERCENT_HIWATER || queue_sends < 1))

Generally speaking, if you are only using TAB characters to indent, you are probably doing it wrong.

You should use the appropriate number of TAB _and_ SPACE characters necessary to start the line at exactly the first column after the openning parenthesis of the appropriate construct.

drivers/net/hyperv/netvsc_drv.c static int netvsc_probe(struct hv_device *dev, · line 766

Quoted 13 lines
drivers/net/hyperv/netvsc_drv.c +3 -1
@@ -668,9 +756,11 @@ static int netvsc_probe(struct hv_device *dev,
 	struct net_device *net = NULL;
 	struct net_device_context *net_device_ctx;
 	struct netvsc_device_info device_info;
+	struct netvsc_device *nvdev;
 	int ret;
 
-	net = alloc_etherdev(sizeof(struct net_device_context));
+	net = alloc_etherdev_mq(sizeof(struct net_device_context),
+				num_online_cpus());
 	if (!net)
 		return -ENOMEM;
 

num_online_cpus() can change, will your driver accomodate this?

drivers/net/hyperv/rndis_filter.c cleanup: · line 785

Quoted 4 lines
drivers/net/hyperv/rndis_filter.c +3 -0
+}
+
+
 static int rndis_filter_query_device_link_status(struct rndis_device *dev)

One empty line is sufficient.

drivers/net/hyperv/rndis_filter.c static int rndis_filter_close_device(struct rndis_device *dev) · line 977

Quoted 4 lines

}

drivers/net/hyperv/rndis_filter.c +2 -0
+
+static void netvsc_sc_open(struct vmbus_channel *new_sc)

Likewise.

drivers/net/hyperv/rndis_filter.c static int rndis_filter_close_device(struct rndis_device *dev) · line 993

Quoted 3 lines
drivers/net/hyperv/rndis_filter.c +3 -0
+	ret = vmbus_open(new_sc, nvscdev->ring_size * PAGE_SIZE,
+		nvscdev->ring_size * PAGE_SIZE, NULL, 0,
+		netvsc_channel_cb, new_sc);

When function arguments span multiple lines the function call shall be indented as:

	func(A, B, C,
	     D, E, F);

That is, the second and subsequent lines are indented, using the appropriate number of TAB _and_ SPACE characters, necessary to reach exactly the first column after the openning parenthesis.

There are several other cases of this, please audit your entire submission for this problem.

If proper indentation causes lines to significantly exceed 80 columns, consider helper functions or local variables to allieve the problem.

drivers/net/hyperv/rndis_filter.c int rndis_filter_device_add(struct hv_device *dev, · line 1085

Quoted 2 lines
drivers/net/hyperv/rndis_filter.c +2 -0
+	ret = rndis_filter_query_device(rndis_device,
+		OID_GEN_RECEIVE_SCALE_CAPABILITIES, &rsscap, &rsscap_size);

Same problem.

#2 lore raw

Hello.

Quoted 3 lines · David Miller
Quoted 1 line

+extern u8 netvsc_hash_key[];

We no longer use extern in header file function declarations.

Wait, this is a variable declaration. :-)

WBR, Sergei

#3 lore raw
Quoted 8 lines · On Thu, 20 Mar 2014 00:56:05 +0300 Sergei Shtylyov…
Quoted 3 lines · David Miller
Quoted 1 line

+extern u8 netvsc_hash_key[];

We no longer use extern in header file function declarations.

Wait, this is a variable declaration. :-)

And the need for the extern on variable declarations was one reason I gave for not removing it from the function declarations (consistency is good :-)).

Signature · 2 lines
Cheers,
Stephen Rothwell                    [email protected]

_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

maintainer
#4 lore raw
In reply to Sergei Shtylyov

From: Sergei Shtylyov <[email protected]>
Date: Thu, 20 Mar 2014 00:56:05 +0300

Quoted 9 lines

Hello.

Quoted 3 lines · David Miller
Quoted 1 line

+extern u8 netvsc_hash_key[];

We no longer use extern in header file function declarations.

Wait, this is a variable declaration. :-)

My bad :)

author maintainer
#5 lore raw
In reply to David Miller
Quoted 8 lines

-----Original Message-----

drivers/net/hyperv/hyperv_net.h line 48

Quoted 3 lines
drivers/net/hyperv/hyperv_net.h +3 -0
+
+
+/* ndis_recv_scale_cap/cap_flag */

One empty line is sufficient, we don't need two of them here.

I will fix this and other formats you pointed out below, also check the whole patch for similar issues.

Quoted 8 lines

drivers/net/hyperv/netvsc_drv.c static int netvsc_probe(struct hv_device *dev, · line 765

Quoted 6 lines
drivers/net/hyperv/netvsc_drv.c +2 -1
-	net = alloc_etherdev(sizeof(struct net_device_context));
+	net = alloc_etherdev_mq(sizeof(struct net_device_context),
+				num_online_cpus());
 	if (!net)
 		return -ENOMEM;

num_online_cpus() can change, will your driver accomodate this?

HyperV currently doesn't support hot-add/remove cpu, so this is constant for this driver.

Thanks,
- Haiyang