aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2017-01-24 16:29:02 -0500
committerDavid S. Miller <davem@davemloft.net>2017-01-24 16:29:02 -0500
commit264e6777f958d2b7b05619c65f89a1eaf5b4709e (patch)
treec18a6517376faaf348fa016bcc2dc1d3a73216ae
parentf2ceab0bafb97ec4cf895fda31fa2e0b1657870e (diff)
parent1130383c174499826a3f01486e574e89be17e2d2 (diff)
Merge branch 'netvsc-enhancements'
Stephen Hemminger says: ==================== netvsc driver enhancements for net-next Lots of little things in here. Support for minor more ethtool control, negotiation of offload parameters with host (based on FreeBSD) and several cleanups. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/hyperv/hyperv_net.h216
-rw-r--r--drivers/net/hyperv/netvsc.c321
-rw-r--r--drivers/net/hyperv/netvsc_drv.c569
-rw-r--r--drivers/net/hyperv/rndis_filter.c338
4 files changed, 850 insertions, 594 deletions
diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
index 3958adade7eb..d3e73ac158ae 100644
--- a/drivers/net/hyperv/hyperv_net.h
+++ b/drivers/net/hyperv/hyperv_net.h
@@ -34,6 +34,7 @@
34 34
35#define NDIS_OBJECT_TYPE_RSS_CAPABILITIES 0x88 35#define NDIS_OBJECT_TYPE_RSS_CAPABILITIES 0x88
36#define NDIS_OBJECT_TYPE_RSS_PARAMETERS 0x89 36#define NDIS_OBJECT_TYPE_RSS_PARAMETERS 0x89
37#define NDIS_OBJECT_TYPE_OFFLOAD 0xa7
37 38
38#define NDIS_RECEIVE_SCALE_CAPABILITIES_REVISION_2 2 39#define NDIS_RECEIVE_SCALE_CAPABILITIES_REVISION_2 2
39#define NDIS_RECEIVE_SCALE_PARAMETERS_REVISION_2 2 40#define NDIS_RECEIVE_SCALE_PARAMETERS_REVISION_2 2
@@ -118,6 +119,7 @@ struct ndis_recv_scale_param { /* NDIS_RECEIVE_SCALE_PARAMETERS */
118 119
119/* Fwd declaration */ 120/* Fwd declaration */
120struct ndis_tcp_ip_checksum_info; 121struct ndis_tcp_ip_checksum_info;
122struct ndis_pkt_8021q_info;
121 123
122/* 124/*
123 * Represent netvsc packet which contains 1 RNDIS and 1 ethernet frame 125 * Represent netvsc packet which contains 1 RNDIS and 1 ethernet frame
@@ -135,8 +137,10 @@ struct hv_netvsc_packet {
135 u8 page_buf_cnt; 137 u8 page_buf_cnt;
136 138
137 u16 q_idx; 139 u16 q_idx;
138 u32 send_buf_index; 140 u16 total_packets;
139 141
142 u32 total_bytes;
143 u32 send_buf_index;
140 u32 total_data_buflen; 144 u32 total_data_buflen;
141}; 145};
142 146
@@ -155,6 +159,8 @@ enum rndis_device_state {
155 RNDIS_DEV_DATAINITIALIZED, 159 RNDIS_DEV_DATAINITIALIZED,
156}; 160};
157 161
162#define NETVSC_HASH_KEYLEN 40
163
158struct rndis_device { 164struct rndis_device {
159 struct net_device *ndev; 165 struct net_device *ndev;
160 166
@@ -165,14 +171,17 @@ struct rndis_device {
165 spinlock_t request_lock; 171 spinlock_t request_lock;
166 struct list_head req_list; 172 struct list_head req_list;
167 173
168 unsigned char hw_mac_adr[ETH_ALEN]; 174 u8 hw_mac_adr[ETH_ALEN];
175 u8 rss_key[NETVSC_HASH_KEYLEN];
176 u16 ind_table[ITAB_NUM];
169}; 177};
170 178
171 179
172/* Interface */ 180/* Interface */
173struct rndis_message; 181struct rndis_message;
174struct netvsc_device; 182struct netvsc_device;
175int netvsc_device_add(struct hv_device *device, void *additional_info); 183int netvsc_device_add(struct hv_device *device,
184 const struct netvsc_device_info *info);
176void netvsc_device_remove(struct hv_device *device); 185void netvsc_device_remove(struct hv_device *device);
177int netvsc_send(struct hv_device *device, 186int netvsc_send(struct hv_device *device,
178 struct hv_netvsc_packet *packet, 187 struct hv_netvsc_packet *packet,
@@ -181,22 +190,25 @@ int netvsc_send(struct hv_device *device,
181 struct sk_buff *skb); 190 struct sk_buff *skb);
182void netvsc_linkstatus_callback(struct hv_device *device_obj, 191void netvsc_linkstatus_callback(struct hv_device *device_obj,
183 struct rndis_message *resp); 192 struct rndis_message *resp);
184int netvsc_recv_callback(struct hv_device *device_obj, 193int netvsc_recv_callback(struct net_device *net,
185 struct hv_netvsc_packet *packet, 194 struct vmbus_channel *channel,
186 void **data, 195 void *data, u32 len,
187 struct ndis_tcp_ip_checksum_info *csum_info, 196 const struct ndis_tcp_ip_checksum_info *csum_info,
188 struct vmbus_channel *channel, 197 const struct ndis_pkt_8021q_info *vlan);
189 u16 vlan_tci);
190void netvsc_channel_cb(void *context); 198void netvsc_channel_cb(void *context);
191int rndis_filter_open(struct netvsc_device *nvdev); 199int rndis_filter_open(struct netvsc_device *nvdev);
192int rndis_filter_close(struct netvsc_device *nvdev); 200int rndis_filter_close(struct netvsc_device *nvdev);
193int rndis_filter_device_add(struct hv_device *dev, 201int rndis_filter_device_add(struct hv_device *dev,
194 void *additional_info); 202 struct netvsc_device_info *info);
195void rndis_filter_device_remove(struct hv_device *dev); 203void rndis_filter_device_remove(struct hv_device *dev,
196int rndis_filter_receive(struct hv_device *dev, 204 struct netvsc_device *nvdev);
197 struct hv_netvsc_packet *pkt, 205int rndis_filter_set_rss_param(struct rndis_device *rdev,
198 void **data, 206 const u8 *key, int num_queue);
199 struct vmbus_channel *channel); 207int rndis_filter_receive(struct net_device *ndev,
208 struct netvsc_device *net_dev,
209 struct hv_device *dev,
210 struct vmbus_channel *channel,
211 void *data, u32 buflen);
200 212
201int rndis_filter_set_packet_filter(struct rndis_device *dev, u32 new_filter); 213int rndis_filter_set_packet_filter(struct rndis_device *dev, u32 new_filter);
202int rndis_filter_set_device_mac(struct net_device *ndev, char *mac); 214int rndis_filter_set_device_mac(struct net_device *ndev, char *mac);
@@ -622,6 +634,7 @@ struct nvsp_message {
622 634
623#define VRSS_SEND_TAB_SIZE 16 635#define VRSS_SEND_TAB_SIZE 16
624#define VRSS_CHANNEL_MAX 64 636#define VRSS_CHANNEL_MAX 64
637#define VRSS_CHANNEL_DEFAULT 8
625 638
626#define RNDIS_MAX_PKT_DEFAULT 8 639#define RNDIS_MAX_PKT_DEFAULT 8
627#define RNDIS_PKT_ALIGN_DEFAULT 8 640#define RNDIS_PKT_ALIGN_DEFAULT 8
@@ -685,8 +698,7 @@ struct net_device_context {
685 struct work_struct work; 698 struct work_struct work;
686 u32 msg_enable; /* debug level */ 699 u32 msg_enable; /* debug level */
687 700
688 struct netvsc_stats __percpu *tx_stats; 701 u32 tx_checksum_mask;
689 struct netvsc_stats __percpu *rx_stats;
690 702
691 /* Ethtool settings */ 703 /* Ethtool settings */
692 u8 duplex; 704 u8 duplex;
@@ -705,11 +717,21 @@ struct net_device_context {
705 u32 vf_serial; 717 u32 vf_serial;
706}; 718};
707 719
720/* Per channel data */
721struct netvsc_channel {
722 struct vmbus_channel *channel;
723 struct multi_send_data msd;
724 struct multi_recv_comp mrc;
725 atomic_t queue_sends;
726
727 struct netvsc_stats tx_stats;
728 struct netvsc_stats rx_stats;
729};
730
708/* Per netvsc device */ 731/* Per netvsc device */
709struct netvsc_device { 732struct netvsc_device {
710 u32 nvsp_version; 733 u32 nvsp_version;
711 734
712 atomic_t num_outstanding_sends;
713 wait_queue_head_t wait_drain; 735 wait_queue_head_t wait_drain;
714 bool destroy; 736 bool destroy;
715 737
@@ -735,32 +757,25 @@ struct netvsc_device {
735 757
736 struct nvsp_message revoke_packet; 758 struct nvsp_message revoke_packet;
737 759
738 struct vmbus_channel *chn_table[VRSS_CHANNEL_MAX];
739 u32 send_table[VRSS_SEND_TAB_SIZE]; 760 u32 send_table[VRSS_SEND_TAB_SIZE];
740 u32 max_chn; 761 u32 max_chn;
741 u32 num_chn; 762 u32 num_chn;
742 spinlock_t sc_lock; /* Protects num_sc_offered variable */ 763 spinlock_t sc_lock; /* Protects num_sc_offered variable */
743 u32 num_sc_offered; 764 u32 num_sc_offered;
744 atomic_t queue_sends[VRSS_CHANNEL_MAX];
745 765
746 /* Holds rndis device info */ 766 /* Holds rndis device info */
747 void *extension; 767 void *extension;
748 768
749 int ring_size; 769 int ring_size;
750 770
751 /* The primary channel callback buffer */
752 unsigned char *cb_buffer;
753 /* The sub channel callback buffer */
754 unsigned char *sub_cb_buf;
755
756 struct multi_send_data msd[VRSS_CHANNEL_MAX];
757 u32 max_pkt; /* max number of pkt in one send, e.g. 8 */ 771 u32 max_pkt; /* max number of pkt in one send, e.g. 8 */
758 u32 pkt_align; /* alignment bytes, e.g. 8 */ 772 u32 pkt_align; /* alignment bytes, e.g. 8 */
759 773
760 struct multi_recv_comp mrc[VRSS_CHANNEL_MAX];
761 atomic_t num_outstanding_recvs; 774 atomic_t num_outstanding_recvs;
762 775
763 atomic_t open_cnt; 776 atomic_t open_cnt;
777
778 struct netvsc_channel chan_table[VRSS_CHANNEL_MAX];
764}; 779};
765 780
766static inline struct netvsc_device * 781static inline struct netvsc_device *
@@ -939,7 +954,7 @@ struct ndis_pkt_8021q_info {
939 }; 954 };
940}; 955};
941 956
942struct ndis_oject_header { 957struct ndis_object_header {
943 u8 type; 958 u8 type;
944 u8 revision; 959 u8 revision;
945 u16 size; 960 u16 size;
@@ -947,6 +962,9 @@ struct ndis_oject_header {
947 962
948#define NDIS_OBJECT_TYPE_DEFAULT 0x80 963#define NDIS_OBJECT_TYPE_DEFAULT 0x80
949#define NDIS_OFFLOAD_PARAMETERS_REVISION_3 3 964#define NDIS_OFFLOAD_PARAMETERS_REVISION_3 3
965#define NDIS_OFFLOAD_PARAMETERS_REVISION_2 2
966#define NDIS_OFFLOAD_PARAMETERS_REVISION_1 1
967
950#define NDIS_OFFLOAD_PARAMETERS_NO_CHANGE 0 968#define NDIS_OFFLOAD_PARAMETERS_NO_CHANGE 0
951#define NDIS_OFFLOAD_PARAMETERS_LSOV2_DISABLED 1 969#define NDIS_OFFLOAD_PARAMETERS_LSOV2_DISABLED 1
952#define NDIS_OFFLOAD_PARAMETERS_LSOV2_ENABLED 2 970#define NDIS_OFFLOAD_PARAMETERS_LSOV2_ENABLED 2
@@ -973,8 +991,135 @@ struct ndis_oject_header {
973#define OID_TCP_CONNECTION_OFFLOAD_HARDWARE_CAPABILITIES 0xFC01020F /* query */ 991#define OID_TCP_CONNECTION_OFFLOAD_HARDWARE_CAPABILITIES 0xFC01020F /* query */
974#define OID_OFFLOAD_ENCAPSULATION 0x0101010A /* set/query */ 992#define OID_OFFLOAD_ENCAPSULATION 0x0101010A /* set/query */
975 993
994/*
995 * OID_TCP_OFFLOAD_HARDWARE_CAPABILITIES
996 * ndis_type: NDIS_OBJTYPE_OFFLOAD
997 */
998
999#define NDIS_OFFLOAD_ENCAP_NONE 0x0000
1000#define NDIS_OFFLOAD_ENCAP_NULL 0x0001
1001#define NDIS_OFFLOAD_ENCAP_8023 0x0002
1002#define NDIS_OFFLOAD_ENCAP_8023PQ 0x0004
1003#define NDIS_OFFLOAD_ENCAP_8023PQ_OOB 0x0008
1004#define NDIS_OFFLOAD_ENCAP_RFC1483 0x0010
1005
1006struct ndis_csum_offload {
1007 u32 ip4_txenc;
1008 u32 ip4_txcsum;
1009#define NDIS_TXCSUM_CAP_IP4OPT 0x001
1010#define NDIS_TXCSUM_CAP_TCP4OPT 0x004
1011#define NDIS_TXCSUM_CAP_TCP4 0x010
1012#define NDIS_TXCSUM_CAP_UDP4 0x040
1013#define NDIS_TXCSUM_CAP_IP4 0x100
1014
1015#define NDIS_TXCSUM_ALL_TCP4 (NDIS_TXCSUM_CAP_TCP4 | NDIS_TXCSUM_CAP_TCP4OPT)
1016
1017 u32 ip4_rxenc;
1018 u32 ip4_rxcsum;
1019#define NDIS_RXCSUM_CAP_IP4OPT 0x001
1020#define NDIS_RXCSUM_CAP_TCP4OPT 0x004
1021#define NDIS_RXCSUM_CAP_TCP4 0x010
1022#define NDIS_RXCSUM_CAP_UDP4 0x040
1023#define NDIS_RXCSUM_CAP_IP4 0x100
1024 u32 ip6_txenc;
1025 u32 ip6_txcsum;
1026#define NDIS_TXCSUM_CAP_IP6EXT 0x001
1027#define NDIS_TXCSUM_CAP_TCP6OPT 0x004
1028#define NDIS_TXCSUM_CAP_TCP6 0x010
1029#define NDIS_TXCSUM_CAP_UDP6 0x040
1030 u32 ip6_rxenc;
1031 u32 ip6_rxcsum;
1032#define NDIS_RXCSUM_CAP_IP6EXT 0x001
1033#define NDIS_RXCSUM_CAP_TCP6OPT 0x004
1034#define NDIS_RXCSUM_CAP_TCP6 0x010
1035#define NDIS_RXCSUM_CAP_UDP6 0x040
1036
1037#define NDIS_TXCSUM_ALL_TCP6 (NDIS_TXCSUM_CAP_TCP6 | \
1038 NDIS_TXCSUM_CAP_TCP6OPT | \
1039 NDIS_TXCSUM_CAP_IP6EXT)
1040};
1041
1042struct ndis_lsov1_offload {
1043 u32 encap;
1044 u32 maxsize;
1045 u32 minsegs;
1046 u32 opts;
1047};
1048
1049struct ndis_ipsecv1_offload {
1050 u32 encap;
1051 u32 ah_esp;
1052 u32 xport_tun;
1053 u32 ip4_opts;
1054 u32 flags;
1055 u32 ip4_ah;
1056 u32 ip4_esp;
1057};
1058
1059struct ndis_lsov2_offload {
1060 u32 ip4_encap;
1061 u32 ip4_maxsz;
1062 u32 ip4_minsg;
1063 u32 ip6_encap;
1064 u32 ip6_maxsz;
1065 u32 ip6_minsg;
1066 u32 ip6_opts;
1067#define NDIS_LSOV2_CAP_IP6EXT 0x001
1068#define NDIS_LSOV2_CAP_TCP6OPT 0x004
1069
1070#define NDIS_LSOV2_CAP_IP6 (NDIS_LSOV2_CAP_IP6EXT | \
1071 NDIS_LSOV2_CAP_TCP6OPT)
1072};
1073
1074struct ndis_ipsecv2_offload {
1075 u32 encap;
1076 u16 ip6;
1077 u16 ip4opt;
1078 u16 ip6ext;
1079 u16 ah;
1080 u16 esp;
1081 u16 ah_esp;
1082 u16 xport;
1083 u16 tun;
1084 u16 xport_tun;
1085 u16 lso;
1086 u16 extseq;
1087 u32 udp_esp;
1088 u32 auth;
1089 u32 crypto;
1090 u32 sa_caps;
1091};
1092
1093struct ndis_rsc_offload {
1094 u16 ip4;
1095 u16 ip6;
1096};
1097
1098struct ndis_encap_offload {
1099 u32 flags;
1100 u32 maxhdr;
1101};
1102
1103struct ndis_offload {
1104 struct ndis_object_header header;
1105 struct ndis_csum_offload csum;
1106 struct ndis_lsov1_offload lsov1;
1107 struct ndis_ipsecv1_offload ipsecv1;
1108 struct ndis_lsov2_offload lsov2;
1109 u32 flags;
1110 /* NDIS >= 6.1 */
1111 struct ndis_ipsecv2_offload ipsecv2;
1112 /* NDIS >= 6.30 */
1113 struct ndis_rsc_offload rsc;
1114 struct ndis_encap_offload encap_gre;
1115};
1116
1117#define NDIS_OFFLOAD_SIZE sizeof(struct ndis_offload)
1118#define NDIS_OFFLOAD_SIZE_6_0 offsetof(struct ndis_offload, ipsecv2)
1119#define NDIS_OFFLOAD_SIZE_6_1 offsetof(struct ndis_offload, rsc)
1120
976struct ndis_offload_params { 1121struct ndis_offload_params {
977 struct ndis_oject_header header; 1122 struct ndis_object_header header;
978 u8 ip_v4_csum; 1123 u8 ip_v4_csum;
979 u8 tcp_ip_v4_csum; 1124 u8 tcp_ip_v4_csum;
980 u8 udp_ip_v4_csum; 1125 u8 udp_ip_v4_csum;
@@ -1301,15 +1446,10 @@ struct rndis_message {
1301#define NDIS_PACKET_TYPE_FUNCTIONAL 0x00000400 1446#define NDIS_PACKET_TYPE_FUNCTIONAL 0x00000400
1302#define NDIS_PACKET_TYPE_MAC_FRAME 0x00000800 1447#define NDIS_PACKET_TYPE_MAC_FRAME 0x00000800
1303 1448
1304#define INFO_IPV4 2
1305#define INFO_IPV6 4
1306#define INFO_TCP 2
1307#define INFO_UDP 4
1308
1309#define TRANSPORT_INFO_NOT_IP 0 1449#define TRANSPORT_INFO_NOT_IP 0
1310#define TRANSPORT_INFO_IPV4_TCP ((INFO_IPV4 << 16) | INFO_TCP) 1450#define TRANSPORT_INFO_IPV4_TCP 0x01
1311#define TRANSPORT_INFO_IPV4_UDP ((INFO_IPV4 << 16) | INFO_UDP) 1451#define TRANSPORT_INFO_IPV4_UDP 0x02
1312#define TRANSPORT_INFO_IPV6_TCP ((INFO_IPV6 << 16) | INFO_TCP) 1452#define TRANSPORT_INFO_IPV6_TCP 0x10
1313#define TRANSPORT_INFO_IPV6_UDP ((INFO_IPV6 << 16) | INFO_UDP) 1453#define TRANSPORT_INFO_IPV6_UDP 0x20
1314 1454
1315#endif /* _HYPERV_NET_H */ 1455#endif /* _HYPERV_NET_H */
diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c
index 5a1cc089acb7..5cfdb1a1b4c1 100644
--- a/drivers/net/hyperv/netvsc.c
+++ b/drivers/net/hyperv/netvsc.c
@@ -67,14 +67,8 @@ static struct netvsc_device *alloc_net_device(void)
67 if (!net_device) 67 if (!net_device)
68 return NULL; 68 return NULL;
69 69
70 net_device->cb_buffer = kzalloc(NETVSC_PACKET_SIZE, GFP_KERNEL); 70 net_device->chan_table[0].mrc.buf
71 if (!net_device->cb_buffer) { 71 = vzalloc(NETVSC_RECVSLOT_MAX * sizeof(struct recv_comp_data));
72 kfree(net_device);
73 return NULL;
74 }
75
76 net_device->mrc[0].buf = vzalloc(NETVSC_RECVSLOT_MAX *
77 sizeof(struct recv_comp_data));
78 72
79 init_waitqueue_head(&net_device->wait_drain); 73 init_waitqueue_head(&net_device->wait_drain);
80 net_device->destroy = false; 74 net_device->destroy = false;
@@ -91,35 +85,28 @@ static void free_netvsc_device(struct netvsc_device *nvdev)
91 int i; 85 int i;
92 86
93 for (i = 0; i < VRSS_CHANNEL_MAX; i++) 87 for (i = 0; i < VRSS_CHANNEL_MAX; i++)
94 vfree(nvdev->mrc[i].buf); 88 vfree(nvdev->chan_table[i].mrc.buf);
95 89
96 kfree(nvdev->cb_buffer);
97 kfree(nvdev); 90 kfree(nvdev);
98} 91}
99 92
100static struct netvsc_device *get_outbound_net_device(struct hv_device *device)
101{
102 struct netvsc_device *net_device = hv_device_to_netvsc_device(device);
103 93
104 if (net_device && net_device->destroy) 94static inline bool netvsc_channel_idle(const struct netvsc_device *net_device,
105 net_device = NULL; 95 u16 q_idx)
96{
97 const struct netvsc_channel *nvchan = &net_device->chan_table[q_idx];
106 98
107 return net_device; 99 return atomic_read(&net_device->num_outstanding_recvs) == 0 &&
100 atomic_read(&nvchan->queue_sends) == 0;
108} 101}
109 102
110static struct netvsc_device *get_inbound_net_device(struct hv_device *device) 103static struct netvsc_device *get_outbound_net_device(struct hv_device *device)
111{ 104{
112 struct netvsc_device *net_device = hv_device_to_netvsc_device(device); 105 struct netvsc_device *net_device = hv_device_to_netvsc_device(device);
113 106
114 if (!net_device) 107 if (net_device && net_device->destroy)
115 goto get_in_err;
116
117 if (net_device->destroy &&
118 atomic_read(&net_device->num_outstanding_sends) == 0 &&
119 atomic_read(&net_device->num_outstanding_recvs) == 0)
120 net_device = NULL; 108 net_device = NULL;
121 109
122get_in_err:
123 return net_device; 110 return net_device;
124} 111}
125 112
@@ -584,7 +571,6 @@ void netvsc_device_remove(struct hv_device *device)
584 vmbus_close(device->channel); 571 vmbus_close(device->channel);
585 572
586 /* Release all resources */ 573 /* Release all resources */
587 vfree(net_device->sub_cb_buf);
588 free_netvsc_device(net_device); 574 free_netvsc_device(net_device);
589} 575}
590 576
@@ -620,29 +606,35 @@ static void netvsc_send_tx_complete(struct netvsc_device *net_device,
620 struct net_device *ndev = hv_get_drvdata(device); 606 struct net_device *ndev = hv_get_drvdata(device);
621 struct net_device_context *net_device_ctx = netdev_priv(ndev); 607 struct net_device_context *net_device_ctx = netdev_priv(ndev);
622 struct vmbus_channel *channel = device->channel; 608 struct vmbus_channel *channel = device->channel;
623 int num_outstanding_sends;
624 u16 q_idx = 0; 609 u16 q_idx = 0;
625 int queue_sends; 610 int queue_sends;
626 611
627 /* Notify the layer above us */ 612 /* Notify the layer above us */
628 if (likely(skb)) { 613 if (likely(skb)) {
629 struct hv_netvsc_packet *nvsc_packet 614 const struct hv_netvsc_packet *packet
630 = (struct hv_netvsc_packet *)skb->cb; 615 = (struct hv_netvsc_packet *)skb->cb;
631 u32 send_index = nvsc_packet->send_buf_index; 616 u32 send_index = packet->send_buf_index;
617 struct netvsc_stats *tx_stats;
632 618
633 if (send_index != NETVSC_INVALID_INDEX) 619 if (send_index != NETVSC_INVALID_INDEX)
634 netvsc_free_send_slot(net_device, send_index); 620 netvsc_free_send_slot(net_device, send_index);
635 q_idx = nvsc_packet->q_idx; 621 q_idx = packet->q_idx;
636 channel = incoming_channel; 622 channel = incoming_channel;
637 623
624 tx_stats = &net_device->chan_table[q_idx].tx_stats;
625
626 u64_stats_update_begin(&tx_stats->syncp);
627 tx_stats->packets += packet->total_packets;
628 tx_stats->bytes += packet->total_bytes;
629 u64_stats_update_end(&tx_stats->syncp);
630
638 dev_consume_skb_any(skb); 631 dev_consume_skb_any(skb);
639 } 632 }
640 633
641 num_outstanding_sends = 634 queue_sends =
642 atomic_dec_return(&net_device->num_outstanding_sends); 635 atomic_dec_return(&net_device->chan_table[q_idx].queue_sends);
643 queue_sends = atomic_dec_return(&net_device->queue_sends[q_idx]);
644 636
645 if (net_device->destroy && num_outstanding_sends == 0) 637 if (net_device->destroy && queue_sends == 0)
646 wake_up(&net_device->wait_drain); 638 wake_up(&net_device->wait_drain);
647 639
648 if (netif_tx_queue_stopped(netdev_get_tx_queue(ndev, q_idx)) && 640 if (netif_tx_queue_stopped(netdev_get_tx_queue(ndev, q_idx)) &&
@@ -688,27 +680,15 @@ static void netvsc_send_completion(struct netvsc_device *net_device,
688 680
689static u32 netvsc_get_next_send_section(struct netvsc_device *net_device) 681static u32 netvsc_get_next_send_section(struct netvsc_device *net_device)
690{ 682{
691 unsigned long index; 683 unsigned long *map_addr = net_device->send_section_map;
692 u32 max_words = net_device->map_words; 684 unsigned int i;
693 unsigned long *map_addr = (unsigned long *)net_device->send_section_map; 685
694 u32 section_cnt = net_device->send_section_cnt; 686 for_each_clear_bit(i, map_addr, net_device->map_words) {
695 int ret_val = NETVSC_INVALID_INDEX; 687 if (sync_test_and_set_bit(i, map_addr) == 0)
696 int i; 688 return i;
697 int prev_val;
698
699 for (i = 0; i < max_words; i++) {
700 if (!~(map_addr[i]))
701 continue;
702 index = ffz(map_addr[i]);
703 prev_val = sync_test_and_set_bit(index, &map_addr[i]);
704 if (prev_val)
705 continue;
706 if ((index + (i * BITS_PER_LONG)) >= section_cnt)
707 break;
708 ret_val = (index + (i * BITS_PER_LONG));
709 break;
710 } 689 }
711 return ret_val; 690
691 return NETVSC_INVALID_INDEX;
712} 692}
713 693
714static u32 netvsc_copy_to_send_buf(struct netvsc_device *net_device, 694static u32 netvsc_copy_to_send_buf(struct netvsc_device *net_device,
@@ -765,9 +745,11 @@ static inline int netvsc_send_pkt(
765 struct sk_buff *skb) 745 struct sk_buff *skb)
766{ 746{
767 struct nvsp_message nvmsg; 747 struct nvsp_message nvmsg;
768 u16 q_idx = packet->q_idx; 748 struct netvsc_channel *nvchan
769 struct vmbus_channel *out_channel = net_device->chn_table[q_idx]; 749 = &net_device->chan_table[packet->q_idx];
750 struct vmbus_channel *out_channel = nvchan->channel;
770 struct net_device *ndev = hv_get_drvdata(device); 751 struct net_device *ndev = hv_get_drvdata(device);
752 struct netdev_queue *txq = netdev_get_tx_queue(ndev, packet->q_idx);
771 u64 req_id; 753 u64 req_id;
772 int ret; 754 int ret;
773 struct hv_page_buffer *pgbuf; 755 struct hv_page_buffer *pgbuf;
@@ -827,23 +809,14 @@ static inline int netvsc_send_pkt(
827 } 809 }
828 810
829 if (ret == 0) { 811 if (ret == 0) {
830 atomic_inc(&net_device->num_outstanding_sends); 812 atomic_inc_return(&nvchan->queue_sends);
831 atomic_inc(&net_device->queue_sends[q_idx]);
832
833 if (ring_avail < RING_AVAIL_PERCENT_LOWATER) {
834 netif_tx_stop_queue(netdev_get_tx_queue(ndev, q_idx));
835 813
836 if (atomic_read(&net_device-> 814 if (ring_avail < RING_AVAIL_PERCENT_LOWATER)
837 queue_sends[q_idx]) < 1) 815 netif_tx_stop_queue(txq);
838 netif_tx_wake_queue(netdev_get_tx_queue(
839 ndev, q_idx));
840 }
841 } else if (ret == -EAGAIN) { 816 } else if (ret == -EAGAIN) {
842 netif_tx_stop_queue(netdev_get_tx_queue( 817 netif_tx_stop_queue(txq);
843 ndev, q_idx)); 818 if (atomic_read(&nvchan->queue_sends) < 1) {
844 if (atomic_read(&net_device->queue_sends[q_idx]) < 1) { 819 netif_tx_wake_queue(txq);
845 netif_tx_wake_queue(netdev_get_tx_queue(
846 ndev, q_idx));
847 ret = -ENOSPC; 820 ret = -ENOSPC;
848 } 821 }
849 } else { 822 } else {
@@ -874,8 +847,7 @@ int netvsc_send(struct hv_device *device,
874{ 847{
875 struct netvsc_device *net_device; 848 struct netvsc_device *net_device;
876 int ret = 0; 849 int ret = 0;
877 struct vmbus_channel *out_channel; 850 struct netvsc_channel *nvchan;
878 u16 q_idx = packet->q_idx;
879 u32 pktlen = packet->total_data_buflen, msd_len = 0; 851 u32 pktlen = packet->total_data_buflen, msd_len = 0;
880 unsigned int section_index = NETVSC_INVALID_INDEX; 852 unsigned int section_index = NETVSC_INVALID_INDEX;
881 struct multi_send_data *msdp; 853 struct multi_send_data *msdp;
@@ -895,8 +867,7 @@ int netvsc_send(struct hv_device *device,
895 if (!net_device->send_section_map) 867 if (!net_device->send_section_map)
896 return -EAGAIN; 868 return -EAGAIN;
897 869
898 out_channel = net_device->chn_table[q_idx]; 870 nvchan = &net_device->chan_table[packet->q_idx];
899
900 packet->send_buf_index = NETVSC_INVALID_INDEX; 871 packet->send_buf_index = NETVSC_INVALID_INDEX;
901 packet->cp_partial = false; 872 packet->cp_partial = false;
902 873
@@ -908,9 +879,8 @@ int netvsc_send(struct hv_device *device,
908 goto send_now; 879 goto send_now;
909 } 880 }
910 881
911 msdp = &net_device->msd[q_idx];
912
913 /* batch packets in send buffer if possible */ 882 /* batch packets in send buffer if possible */
883 msdp = &nvchan->msd;
914 if (msdp->pkt) 884 if (msdp->pkt)
915 msd_len = msdp->pkt->total_data_buflen; 885 msd_len = msdp->pkt->total_data_buflen;
916 886
@@ -950,6 +920,11 @@ int netvsc_send(struct hv_device *device,
950 packet->total_data_buflen += msd_len; 920 packet->total_data_buflen += msd_len;
951 } 921 }
952 922
923 if (msdp->pkt) {
924 packet->total_packets += msdp->pkt->total_packets;
925 packet->total_bytes += msdp->pkt->total_bytes;
926 }
927
953 if (msdp->skb) 928 if (msdp->skb)
954 dev_consume_skb_any(msdp->skb); 929 dev_consume_skb_any(msdp->skb);
955 930
@@ -1011,8 +986,9 @@ static int netvsc_send_recv_completion(struct vmbus_channel *channel,
1011static inline void count_recv_comp_slot(struct netvsc_device *nvdev, u16 q_idx, 986static inline void count_recv_comp_slot(struct netvsc_device *nvdev, u16 q_idx,
1012 u32 *filled, u32 *avail) 987 u32 *filled, u32 *avail)
1013{ 988{
1014 u32 first = nvdev->mrc[q_idx].first; 989 struct multi_recv_comp *mrc = &nvdev->chan_table[q_idx].mrc;
1015 u32 next = nvdev->mrc[q_idx].next; 990 u32 first = mrc->first;
991 u32 next = mrc->next;
1016 992
1017 *filled = (first > next) ? NETVSC_RECVSLOT_MAX - first + next : 993 *filled = (first > next) ? NETVSC_RECVSLOT_MAX - first + next :
1018 next - first; 994 next - first;
@@ -1024,26 +1000,26 @@ static inline void count_recv_comp_slot(struct netvsc_device *nvdev, u16 q_idx,
1024static inline struct recv_comp_data *read_recv_comp_slot(struct netvsc_device 1000static inline struct recv_comp_data *read_recv_comp_slot(struct netvsc_device
1025 *nvdev, u16 q_idx) 1001 *nvdev, u16 q_idx)
1026{ 1002{
1003 struct multi_recv_comp *mrc = &nvdev->chan_table[q_idx].mrc;
1027 u32 filled, avail; 1004 u32 filled, avail;
1028 1005
1029 if (!nvdev->mrc[q_idx].buf) 1006 if (unlikely(!mrc->buf))
1030 return NULL; 1007 return NULL;
1031 1008
1032 count_recv_comp_slot(nvdev, q_idx, &filled, &avail); 1009 count_recv_comp_slot(nvdev, q_idx, &filled, &avail);
1033 if (!filled) 1010 if (!filled)
1034 return NULL; 1011 return NULL;
1035 1012
1036 return nvdev->mrc[q_idx].buf + nvdev->mrc[q_idx].first * 1013 return mrc->buf + mrc->first * sizeof(struct recv_comp_data);
1037 sizeof(struct recv_comp_data);
1038} 1014}
1039 1015
1040/* Put the first filled slot back to available pool */ 1016/* Put the first filled slot back to available pool */
1041static inline void put_recv_comp_slot(struct netvsc_device *nvdev, u16 q_idx) 1017static inline void put_recv_comp_slot(struct netvsc_device *nvdev, u16 q_idx)
1042{ 1018{
1019 struct multi_recv_comp *mrc = &nvdev->chan_table[q_idx].mrc;
1043 int num_recv; 1020 int num_recv;
1044 1021
1045 nvdev->mrc[q_idx].first = (nvdev->mrc[q_idx].first + 1) % 1022 mrc->first = (mrc->first + 1) % NETVSC_RECVSLOT_MAX;
1046 NETVSC_RECVSLOT_MAX;
1047 1023
1048 num_recv = atomic_dec_return(&nvdev->num_outstanding_recvs); 1024 num_recv = atomic_dec_return(&nvdev->num_outstanding_recvs);
1049 1025
@@ -1078,13 +1054,14 @@ static void netvsc_chk_recv_comp(struct netvsc_device *nvdev,
1078static inline struct recv_comp_data *get_recv_comp_slot( 1054static inline struct recv_comp_data *get_recv_comp_slot(
1079 struct netvsc_device *nvdev, struct vmbus_channel *channel, u16 q_idx) 1055 struct netvsc_device *nvdev, struct vmbus_channel *channel, u16 q_idx)
1080{ 1056{
1057 struct multi_recv_comp *mrc = &nvdev->chan_table[q_idx].mrc;
1081 u32 filled, avail, next; 1058 u32 filled, avail, next;
1082 struct recv_comp_data *rcd; 1059 struct recv_comp_data *rcd;
1083 1060
1084 if (!nvdev->recv_section) 1061 if (unlikely(!nvdev->recv_section))
1085 return NULL; 1062 return NULL;
1086 1063
1087 if (!nvdev->mrc[q_idx].buf) 1064 if (unlikely(!mrc->buf))
1088 return NULL; 1065 return NULL;
1089 1066
1090 if (atomic_read(&nvdev->num_outstanding_recvs) > 1067 if (atomic_read(&nvdev->num_outstanding_recvs) >
@@ -1095,60 +1072,44 @@ static inline struct recv_comp_data *get_recv_comp_slot(
1095 if (!avail) 1072 if (!avail)
1096 return NULL; 1073 return NULL;
1097 1074
1098 next = nvdev->mrc[q_idx].next; 1075 next = mrc->next;
1099 rcd = nvdev->mrc[q_idx].buf + next * sizeof(struct recv_comp_data); 1076 rcd = mrc->buf + next * sizeof(struct recv_comp_data);
1100 nvdev->mrc[q_idx].next = (next + 1) % NETVSC_RECVSLOT_MAX; 1077 mrc->next = (next + 1) % NETVSC_RECVSLOT_MAX;
1101 1078
1102 atomic_inc(&nvdev->num_outstanding_recvs); 1079 atomic_inc(&nvdev->num_outstanding_recvs);
1103 1080
1104 return rcd; 1081 return rcd;
1105} 1082}
1106 1083
1107static void netvsc_receive(struct netvsc_device *net_device, 1084static void netvsc_receive(struct net_device *ndev,
1108 struct vmbus_channel *channel, 1085 struct netvsc_device *net_device,
1109 struct hv_device *device, 1086 struct net_device_context *net_device_ctx,
1110 struct vmpacket_descriptor *packet) 1087 struct hv_device *device,
1088 struct vmbus_channel *channel,
1089 struct vmtransfer_page_packet_header *vmxferpage_packet,
1090 struct nvsp_message *nvsp)
1111{ 1091{
1112 struct vmtransfer_page_packet_header *vmxferpage_packet; 1092 char *recv_buf = net_device->recv_buf;
1113 struct nvsp_message *nvsp_packet;
1114 struct hv_netvsc_packet nv_pkt;
1115 struct hv_netvsc_packet *netvsc_packet = &nv_pkt;
1116 u32 status = NVSP_STAT_SUCCESS; 1093 u32 status = NVSP_STAT_SUCCESS;
1117 int i; 1094 int i;
1118 int count = 0; 1095 int count = 0;
1119 struct net_device *ndev = hv_get_drvdata(device);
1120 void *data;
1121 int ret; 1096 int ret;
1122 struct recv_comp_data *rcd; 1097 struct recv_comp_data *rcd;
1123 u16 q_idx = channel->offermsg.offer.sub_channel_index; 1098 u16 q_idx = channel->offermsg.offer.sub_channel_index;
1124 1099
1125 /*
1126 * All inbound packets other than send completion should be xfer page
1127 * packet
1128 */
1129 if (packet->type != VM_PKT_DATA_USING_XFER_PAGES) {
1130 netdev_err(ndev, "Unknown packet type received - %d\n",
1131 packet->type);
1132 return;
1133 }
1134
1135 nvsp_packet = (struct nvsp_message *)((unsigned long)packet +
1136 (packet->offset8 << 3));
1137
1138 /* Make sure this is a valid nvsp packet */ 1100 /* Make sure this is a valid nvsp packet */
1139 if (nvsp_packet->hdr.msg_type != 1101 if (unlikely(nvsp->hdr.msg_type != NVSP_MSG1_TYPE_SEND_RNDIS_PKT)) {
1140 NVSP_MSG1_TYPE_SEND_RNDIS_PKT) { 1102 netif_err(net_device_ctx, rx_err, ndev,
1141 netdev_err(ndev, "Unknown nvsp packet type received-" 1103 "Unknown nvsp packet type received %u\n",
1142 " %d\n", nvsp_packet->hdr.msg_type); 1104 nvsp->hdr.msg_type);
1143 return; 1105 return;
1144 } 1106 }
1145 1107
1146 vmxferpage_packet = (struct vmtransfer_page_packet_header *)packet; 1108 if (unlikely(vmxferpage_packet->xfer_pageset_id != NETVSC_RECEIVE_BUFFER_ID)) {
1147 1109 netif_err(net_device_ctx, rx_err, ndev,
1148 if (vmxferpage_packet->xfer_pageset_id != NETVSC_RECEIVE_BUFFER_ID) { 1110 "Invalid xfer page set id - expecting %x got %x\n",
1149 netdev_err(ndev, "Invalid xfer page set id - " 1111 NETVSC_RECEIVE_BUFFER_ID,
1150 "expecting %x got %x\n", NETVSC_RECEIVE_BUFFER_ID, 1112 vmxferpage_packet->xfer_pageset_id);
1151 vmxferpage_packet->xfer_pageset_id);
1152 return; 1113 return;
1153 } 1114 }
1154 1115
@@ -1156,18 +1117,16 @@ static void netvsc_receive(struct netvsc_device *net_device,
1156 1117
1157 /* Each range represents 1 RNDIS pkt that contains 1 ethernet frame */ 1118 /* Each range represents 1 RNDIS pkt that contains 1 ethernet frame */
1158 for (i = 0; i < count; i++) { 1119 for (i = 0; i < count; i++) {
1159 /* Initialize the netvsc packet */ 1120 void *data = recv_buf
1160 data = (void *)((unsigned long)net_device-> 1121 + vmxferpage_packet->ranges[i].byte_offset;
1161 recv_buf + vmxferpage_packet->ranges[i].byte_offset); 1122 u32 buflen = vmxferpage_packet->ranges[i].byte_count;
1162 netvsc_packet->total_data_buflen =
1163 vmxferpage_packet->ranges[i].byte_count;
1164 1123
1165 /* Pass it to the upper layer */ 1124 /* Pass it to the upper layer */
1166 status = rndis_filter_receive(device, netvsc_packet, &data, 1125 status = rndis_filter_receive(ndev, net_device, device,
1167 channel); 1126 channel, data, buflen);
1168 } 1127 }
1169 1128
1170 if (!net_device->mrc[q_idx].buf) { 1129 if (!net_device->chan_table[q_idx].mrc.buf) {
1171 ret = netvsc_send_recv_completion(channel, 1130 ret = netvsc_send_recv_completion(channel,
1172 vmxferpage_packet->d.trans_id, 1131 vmxferpage_packet->d.trans_id,
1173 status); 1132 status);
@@ -1243,11 +1202,10 @@ static void netvsc_process_raw_pkt(struct hv_device *device,
1243 u64 request_id, 1202 u64 request_id,
1244 struct vmpacket_descriptor *desc) 1203 struct vmpacket_descriptor *desc)
1245{ 1204{
1246 struct nvsp_message *nvmsg;
1247 struct net_device_context *net_device_ctx = netdev_priv(ndev); 1205 struct net_device_context *net_device_ctx = netdev_priv(ndev);
1248 1206 struct nvsp_message *nvmsg
1249 nvmsg = (struct nvsp_message *)((unsigned long) 1207 = (struct nvsp_message *)((unsigned long)desc
1250 desc + (desc->offset8 << 3)); 1208 + (desc->offset8 << 3));
1251 1209
1252 switch (desc->type) { 1210 switch (desc->type) {
1253 case VM_PKT_COMP: 1211 case VM_PKT_COMP:
@@ -1255,7 +1213,10 @@ static void netvsc_process_raw_pkt(struct hv_device *device,
1255 break; 1213 break;
1256 1214
1257 case VM_PKT_DATA_USING_XFER_PAGES: 1215 case VM_PKT_DATA_USING_XFER_PAGES:
1258 netvsc_receive(net_device, channel, device, desc); 1216 netvsc_receive(ndev, net_device, net_device_ctx,
1217 device, channel,
1218 (struct vmtransfer_page_packet_header *)desc,
1219 nvmsg);
1259 break; 1220 break;
1260 1221
1261 case VM_PKT_DATA_INBAND: 1222 case VM_PKT_DATA_INBAND:
@@ -1271,16 +1232,11 @@ static void netvsc_process_raw_pkt(struct hv_device *device,
1271 1232
1272void netvsc_channel_cb(void *context) 1233void netvsc_channel_cb(void *context)
1273{ 1234{
1274 int ret; 1235 struct vmbus_channel *channel = context;
1275 struct vmbus_channel *channel = (struct vmbus_channel *)context;
1276 u16 q_idx = channel->offermsg.offer.sub_channel_index; 1236 u16 q_idx = channel->offermsg.offer.sub_channel_index;
1277 struct hv_device *device; 1237 struct hv_device *device;
1278 struct netvsc_device *net_device; 1238 struct netvsc_device *net_device;
1279 u32 bytes_recvd;
1280 u64 request_id;
1281 struct vmpacket_descriptor *desc; 1239 struct vmpacket_descriptor *desc;
1282 unsigned char *buffer;
1283 int bufferlen = NETVSC_PACKET_SIZE;
1284 struct net_device *ndev; 1240 struct net_device *ndev;
1285 bool need_to_commit = false; 1241 bool need_to_commit = false;
1286 1242
@@ -1289,68 +1245,25 @@ void netvsc_channel_cb(void *context)
1289 else 1245 else
1290 device = channel->device_obj; 1246 device = channel->device_obj;
1291 1247
1292 net_device = get_inbound_net_device(device);
1293 if (!net_device)
1294 return;
1295 ndev = hv_get_drvdata(device); 1248 ndev = hv_get_drvdata(device);
1296 buffer = get_per_channel_state(channel); 1249 if (unlikely(!ndev))
1297 1250 return;
1298 do {
1299 desc = get_next_pkt_raw(channel);
1300 if (desc != NULL) {
1301 netvsc_process_raw_pkt(device,
1302 channel,
1303 net_device,
1304 ndev,
1305 desc->trans_id,
1306 desc);
1307
1308 put_pkt_raw(channel, desc);
1309 need_to_commit = true;
1310 continue;
1311 }
1312 if (need_to_commit) {
1313 need_to_commit = false;
1314 commit_rd_index(channel);
1315 }
1316 1251
1317 ret = vmbus_recvpacket_raw(channel, buffer, bufferlen, 1252 net_device = net_device_to_netvsc_device(ndev);
1318 &bytes_recvd, &request_id); 1253 if (unlikely(net_device->destroy) &&
1319 if (ret == 0) { 1254 netvsc_channel_idle(net_device, q_idx))
1320 if (bytes_recvd > 0) { 1255 return;
1321 desc = (struct vmpacket_descriptor *)buffer; 1256
1322 netvsc_process_raw_pkt(device, 1257 while ((desc = get_next_pkt_raw(channel)) != NULL) {
1323 channel, 1258 netvsc_process_raw_pkt(device, channel, net_device,
1324 net_device, 1259 ndev, desc->trans_id, desc);
1325 ndev,
1326 request_id,
1327 desc);
1328 } else {
1329 /*
1330 * We are done for this pass.
1331 */
1332 break;
1333 }
1334
1335 } else if (ret == -ENOBUFS) {
1336 if (bufferlen > NETVSC_PACKET_SIZE)
1337 kfree(buffer);
1338 /* Handle large packet */
1339 buffer = kmalloc(bytes_recvd, GFP_ATOMIC);
1340 if (buffer == NULL) {
1341 /* Try again next time around */
1342 netdev_err(ndev,
1343 "unable to allocate buffer of size "
1344 "(%d)!!\n", bytes_recvd);
1345 break;
1346 }
1347
1348 bufferlen = bytes_recvd;
1349 }
1350 } while (1);
1351 1260
1352 if (bufferlen > NETVSC_PACKET_SIZE) 1261 put_pkt_raw(channel, desc);
1353 kfree(buffer); 1262 need_to_commit = true;
1263 }
1264
1265 if (need_to_commit)
1266 commit_rd_index(channel);
1354 1267
1355 netvsc_chk_recv_comp(net_device, channel, q_idx); 1268 netvsc_chk_recv_comp(net_device, channel, q_idx);
1356} 1269}
@@ -1359,11 +1272,11 @@ void netvsc_channel_cb(void *context)
1359 * netvsc_device_add - Callback when the device belonging to this 1272 * netvsc_device_add - Callback when the device belonging to this
1360 * driver is added 1273 * driver is added
1361 */ 1274 */
1362int netvsc_device_add(struct hv_device *device, void *additional_info) 1275int netvsc_device_add(struct hv_device *device,
1276 const struct netvsc_device_info *device_info)
1363{ 1277{
1364 int i, ret = 0; 1278 int i, ret = 0;
1365 int ring_size = 1279 int ring_size = device_info->ring_size;
1366 ((struct netvsc_device_info *)additional_info)->ring_size;
1367 struct netvsc_device *net_device; 1280 struct netvsc_device *net_device;
1368 struct net_device *ndev = hv_get_drvdata(device); 1281 struct net_device *ndev = hv_get_drvdata(device);
1369 struct net_device_context *net_device_ctx = netdev_priv(ndev); 1282 struct net_device_context *net_device_ctx = netdev_priv(ndev);
@@ -1374,8 +1287,6 @@ int netvsc_device_add(struct hv_device *device, void *additional_info)
1374 1287
1375 net_device->ring_size = ring_size; 1288 net_device->ring_size = ring_size;
1376 1289
1377 set_per_channel_state(device->channel, net_device->cb_buffer);
1378
1379 /* Open the channel */ 1290 /* Open the channel */
1380 ret = vmbus_open(device->channel, ring_size * PAGE_SIZE, 1291 ret = vmbus_open(device->channel, ring_size * PAGE_SIZE,
1381 ring_size * PAGE_SIZE, NULL, 0, 1292 ring_size * PAGE_SIZE, NULL, 0,
@@ -1394,7 +1305,7 @@ int netvsc_device_add(struct hv_device *device, void *additional_info)
1394 * opened. 1305 * opened.
1395 */ 1306 */
1396 for (i = 0; i < VRSS_CHANNEL_MAX; i++) 1307 for (i = 0; i < VRSS_CHANNEL_MAX; i++)
1397 net_device->chn_table[i] = device->channel; 1308 net_device->chan_table[i].channel = device->channel;
1398 1309
1399 /* Writing nvdev pointer unlocks netvsc_send(), make sure chn_table is 1310 /* Writing nvdev pointer unlocks netvsc_send(), make sure chn_table is
1400 * populated. 1311 * populated.
diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index eebeb9378bac..72b0c1f7496e 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -42,21 +42,11 @@
42 42
43#define RING_SIZE_MIN 64 43#define RING_SIZE_MIN 64
44#define LINKCHANGE_INT (2 * HZ) 44#define LINKCHANGE_INT (2 * HZ)
45#define NETVSC_HW_FEATURES (NETIF_F_RXCSUM | \
46 NETIF_F_SG | \
47 NETIF_F_TSO | \
48 NETIF_F_TSO6 | \
49 NETIF_F_HW_CSUM)
50
51/* Restrict GSO size to account for NVGRE */
52#define NETVSC_GSO_MAX_SIZE 62768
53 45
54static int ring_size = 128; 46static int ring_size = 128;
55module_param(ring_size, int, S_IRUGO); 47module_param(ring_size, int, S_IRUGO);
56MODULE_PARM_DESC(ring_size, "Ring buffer size (# of pages)"); 48MODULE_PARM_DESC(ring_size, "Ring buffer size (# of pages)");
57 49
58static int max_num_vrss_chns = 8;
59
60static const u32 default_msg = NETIF_MSG_DRV | NETIF_MSG_PROBE | 50static const u32 default_msg = NETIF_MSG_DRV | NETIF_MSG_PROBE |
61 NETIF_MSG_LINK | NETIF_MSG_IFUP | 51 NETIF_MSG_LINK | NETIF_MSG_IFUP |
62 NETIF_MSG_IFDOWN | NETIF_MSG_RX_ERR | 52 NETIF_MSG_IFDOWN | NETIF_MSG_RX_ERR |
@@ -145,7 +135,7 @@ static int netvsc_close(struct net_device *net)
145 while (true) { 135 while (true) {
146 aread = 0; 136 aread = 0;
147 for (i = 0; i < nvdev->num_chn; i++) { 137 for (i = 0; i < nvdev->num_chn; i++) {
148 chn = nvdev->chn_table[i]; 138 chn = nvdev->chan_table[i].channel;
149 if (!chn) 139 if (!chn)
150 continue; 140 continue;
151 141
@@ -201,22 +191,41 @@ static void *init_ppi_data(struct rndis_message *msg, u32 ppi_size,
201 return ppi; 191 return ppi;
202} 192}
203 193
194/*
195 * Select queue for transmit.
196 *
197 * If a valid queue has already been assigned, then use that.
198 * Otherwise compute tx queue based on hash and the send table.
199 *
200 * This is basically similar to default (__netdev_pick_tx) with the added step
201 * of using the host send_table when no other queue has been assigned.
202 *
203 * TODO support XPS - but get_xps_queue not exported
204 */
204static u16 netvsc_select_queue(struct net_device *ndev, struct sk_buff *skb, 205static u16 netvsc_select_queue(struct net_device *ndev, struct sk_buff *skb,
205 void *accel_priv, select_queue_fallback_t fallback) 206 void *accel_priv, select_queue_fallback_t fallback)
206{ 207{
207 struct net_device_context *net_device_ctx = netdev_priv(ndev); 208 struct net_device_context *net_device_ctx = netdev_priv(ndev);
208 struct netvsc_device *nvsc_dev = net_device_ctx->nvdev; 209 struct netvsc_device *nvsc_dev = net_device_ctx->nvdev;
209 u32 hash; 210 struct sock *sk = skb->sk;
210 u16 q_idx = 0; 211 int q_idx = sk_tx_queue_get(sk);
211 212
212 if (nvsc_dev == NULL || ndev->real_num_tx_queues <= 1) 213 if (q_idx < 0 || skb->ooo_okay ||
213 return 0; 214 q_idx >= ndev->real_num_tx_queues) {
215 u16 hash = __skb_tx_hash(ndev, skb, VRSS_SEND_TAB_SIZE);
216 int new_idx;
217
218 new_idx = nvsc_dev->send_table[hash]
219 % nvsc_dev->num_chn;
220
221 if (q_idx != new_idx && sk &&
222 sk_fullsock(sk) && rcu_access_pointer(sk->sk_dst_cache))
223 sk_tx_queue_set(sk, new_idx);
214 224
215 hash = skb_get_hash(skb); 225 q_idx = new_idx;
216 q_idx = nvsc_dev->send_table[hash % VRSS_SEND_TAB_SIZE] % 226 }
217 ndev->real_num_tx_queues;
218 227
219 if (!nvsc_dev->chn_table[q_idx]) 228 if (unlikely(!nvsc_dev->chan_table[q_idx].channel))
220 q_idx = 0; 229 q_idx = 0;
221 230
222 return q_idx; 231 return q_idx;
@@ -323,33 +332,25 @@ static int netvsc_get_slots(struct sk_buff *skb)
323 return slots + frag_slots; 332 return slots + frag_slots;
324} 333}
325 334
326static u32 get_net_transport_info(struct sk_buff *skb, u32 *trans_off) 335static u32 net_checksum_info(struct sk_buff *skb)
327{ 336{
328 u32 ret_val = TRANSPORT_INFO_NOT_IP; 337 if (skb->protocol == htons(ETH_P_IP)) {
329 338 struct iphdr *ip = ip_hdr(skb);
330 if ((eth_hdr(skb)->h_proto != htons(ETH_P_IP)) &&
331 (eth_hdr(skb)->h_proto != htons(ETH_P_IPV6))) {
332 goto not_ip;
333 }
334 339
335 *trans_off = skb_transport_offset(skb); 340 if (ip->protocol == IPPROTO_TCP)
336 341 return TRANSPORT_INFO_IPV4_TCP;
337 if ((eth_hdr(skb)->h_proto == htons(ETH_P_IP))) { 342 else if (ip->protocol == IPPROTO_UDP)
338 struct iphdr *iphdr = ip_hdr(skb); 343 return TRANSPORT_INFO_IPV4_UDP;
339
340 if (iphdr->protocol == IPPROTO_TCP)
341 ret_val = TRANSPORT_INFO_IPV4_TCP;
342 else if (iphdr->protocol == IPPROTO_UDP)
343 ret_val = TRANSPORT_INFO_IPV4_UDP;
344 } else { 344 } else {
345 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) 345 struct ipv6hdr *ip6 = ipv6_hdr(skb);
346 ret_val = TRANSPORT_INFO_IPV6_TCP; 346
347 if (ip6->nexthdr == IPPROTO_TCP)
348 return TRANSPORT_INFO_IPV6_TCP;
347 else if (ipv6_hdr(skb)->nexthdr == IPPROTO_UDP) 349 else if (ipv6_hdr(skb)->nexthdr == IPPROTO_UDP)
348 ret_val = TRANSPORT_INFO_IPV6_UDP; 350 return TRANSPORT_INFO_IPV6_UDP;
349 } 351 }
350 352
351not_ip: 353 return TRANSPORT_INFO_NOT_IP;
352 return ret_val;
353} 354}
354 355
355static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net) 356static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net)
@@ -362,11 +363,7 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net)
362 struct rndis_packet *rndis_pkt; 363 struct rndis_packet *rndis_pkt;
363 u32 rndis_msg_size; 364 u32 rndis_msg_size;
364 struct rndis_per_packet_info *ppi; 365 struct rndis_per_packet_info *ppi;
365 struct ndis_tcp_ip_checksum_info *csum_info;
366 int hdr_offset;
367 u32 net_trans_info;
368 u32 hash; 366 u32 hash;
369 u32 skb_length;
370 struct hv_page_buffer page_buf[MAX_PAGE_BUFFER_COUNT]; 367 struct hv_page_buffer page_buf[MAX_PAGE_BUFFER_COUNT];
371 struct hv_page_buffer *pb = page_buf; 368 struct hv_page_buffer *pb = page_buf;
372 369
@@ -376,7 +373,6 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net)
376 * more pages we try linearizing it. 373 * more pages we try linearizing it.
377 */ 374 */
378 375
379 skb_length = skb->len;
380 num_data_pgs = netvsc_get_slots(skb) + 2; 376 num_data_pgs = netvsc_get_slots(skb) + 2;
381 377
382 if (unlikely(num_data_pgs > MAX_PAGE_BUFFER_COUNT)) { 378 if (unlikely(num_data_pgs > MAX_PAGE_BUFFER_COUNT)) {
@@ -409,6 +405,8 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net)
409 packet->q_idx = skb_get_queue_mapping(skb); 405 packet->q_idx = skb_get_queue_mapping(skb);
410 406
411 packet->total_data_buflen = skb->len; 407 packet->total_data_buflen = skb->len;
408 packet->total_bytes = skb->len;
409 packet->total_packets = 1;
412 410
413 rndis_msg = (struct rndis_message *)skb->head; 411 rndis_msg = (struct rndis_message *)skb->head;
414 412
@@ -445,13 +443,7 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net)
445 VLAN_PRIO_SHIFT; 443 VLAN_PRIO_SHIFT;
446 } 444 }
447 445
448 net_trans_info = get_net_transport_info(skb, &hdr_offset); 446 if (skb_is_gso(skb)) {
449
450 /*
451 * Setup the sendside checksum offload only if this is not a
452 * GSO packet.
453 */
454 if ((net_trans_info & (INFO_TCP | INFO_UDP)) && skb_is_gso(skb)) {
455 struct ndis_tcp_lso_info *lso_info; 447 struct ndis_tcp_lso_info *lso_info;
456 448
457 rndis_msg_size += NDIS_LSO_PPI_SIZE; 449 rndis_msg_size += NDIS_LSO_PPI_SIZE;
@@ -462,7 +454,7 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net)
462 ppi->ppi_offset); 454 ppi->ppi_offset);
463 455
464 lso_info->lso_v2_transmit.type = NDIS_TCP_LARGE_SEND_OFFLOAD_V2_TYPE; 456 lso_info->lso_v2_transmit.type = NDIS_TCP_LARGE_SEND_OFFLOAD_V2_TYPE;
465 if (net_trans_info & (INFO_IPV4 << 16)) { 457 if (skb->protocol == htons(ETH_P_IP)) {
466 lso_info->lso_v2_transmit.ip_version = 458 lso_info->lso_v2_transmit.ip_version =
467 NDIS_TCP_LARGE_SEND_OFFLOAD_IPV4; 459 NDIS_TCP_LARGE_SEND_OFFLOAD_IPV4;
468 ip_hdr(skb)->tot_len = 0; 460 ip_hdr(skb)->tot_len = 0;
@@ -478,10 +470,12 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net)
478 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, 470 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
479 &ipv6_hdr(skb)->daddr, 0, IPPROTO_TCP, 0); 471 &ipv6_hdr(skb)->daddr, 0, IPPROTO_TCP, 0);
480 } 472 }
481 lso_info->lso_v2_transmit.tcp_header_offset = hdr_offset; 473 lso_info->lso_v2_transmit.tcp_header_offset = skb_transport_offset(skb);
482 lso_info->lso_v2_transmit.mss = skb_shinfo(skb)->gso_size; 474 lso_info->lso_v2_transmit.mss = skb_shinfo(skb)->gso_size;
483 } else if (skb->ip_summed == CHECKSUM_PARTIAL) { 475 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
484 if (net_trans_info & INFO_TCP) { 476 if (net_checksum_info(skb) & net_device_ctx->tx_checksum_mask) {
477 struct ndis_tcp_ip_checksum_info *csum_info;
478
485 rndis_msg_size += NDIS_CSUM_PPI_SIZE; 479 rndis_msg_size += NDIS_CSUM_PPI_SIZE;
486 ppi = init_ppi_data(rndis_msg, NDIS_CSUM_PPI_SIZE, 480 ppi = init_ppi_data(rndis_msg, NDIS_CSUM_PPI_SIZE,
487 TCPIP_CHKSUM_PKTINFO); 481 TCPIP_CHKSUM_PKTINFO);
@@ -489,15 +483,25 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net)
489 csum_info = (struct ndis_tcp_ip_checksum_info *)((void *)ppi + 483 csum_info = (struct ndis_tcp_ip_checksum_info *)((void *)ppi +
490 ppi->ppi_offset); 484 ppi->ppi_offset);
491 485
492 if (net_trans_info & (INFO_IPV4 << 16)) 486 csum_info->transmit.tcp_header_offset = skb_transport_offset(skb);
487
488 if (skb->protocol == htons(ETH_P_IP)) {
493 csum_info->transmit.is_ipv4 = 1; 489 csum_info->transmit.is_ipv4 = 1;
494 else 490
491 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
492 csum_info->transmit.tcp_checksum = 1;
493 else
494 csum_info->transmit.udp_checksum = 1;
495 } else {
495 csum_info->transmit.is_ipv6 = 1; 496 csum_info->transmit.is_ipv6 = 1;
496 497
497 csum_info->transmit.tcp_checksum = 1; 498 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
498 csum_info->transmit.tcp_header_offset = hdr_offset; 499 csum_info->transmit.tcp_checksum = 1;
500 else
501 csum_info->transmit.udp_checksum = 1;
502 }
499 } else { 503 } else {
500 /* UDP checksum (and other) offload is not supported. */ 504 /* Can't do offload of this type of checksum */
501 if (skb_checksum_help(skb)) 505 if (skb_checksum_help(skb))
502 goto drop; 506 goto drop;
503 } 507 }
@@ -513,15 +517,8 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net)
513 skb_tx_timestamp(skb); 517 skb_tx_timestamp(skb);
514 ret = netvsc_send(net_device_ctx->device_ctx, packet, 518 ret = netvsc_send(net_device_ctx->device_ctx, packet,
515 rndis_msg, &pb, skb); 519 rndis_msg, &pb, skb);
516 if (likely(ret == 0)) { 520 if (likely(ret == 0))
517 struct netvsc_stats *tx_stats = this_cpu_ptr(net_device_ctx->tx_stats);
518
519 u64_stats_update_begin(&tx_stats->syncp);
520 tx_stats->packets++;
521 tx_stats->bytes += skb_length;
522 u64_stats_update_end(&tx_stats->syncp);
523 return NETDEV_TX_OK; 521 return NETDEV_TX_OK;
524 }
525 522
526 if (ret == -EAGAIN) { 523 if (ret == -EAGAIN) {
527 ++net_device_ctx->eth_stats.tx_busy; 524 ++net_device_ctx->eth_stats.tx_busy;
@@ -541,7 +538,6 @@ no_memory:
541 ++net_device_ctx->eth_stats.tx_no_memory; 538 ++net_device_ctx->eth_stats.tx_no_memory;
542 goto drop; 539 goto drop;
543} 540}
544
545/* 541/*
546 * netvsc_linkstatus_callback - Link up/down notification 542 * netvsc_linkstatus_callback - Link up/down notification
547 */ 543 */
@@ -593,13 +589,13 @@ void netvsc_linkstatus_callback(struct hv_device *device_obj,
593} 589}
594 590
595static struct sk_buff *netvsc_alloc_recv_skb(struct net_device *net, 591static struct sk_buff *netvsc_alloc_recv_skb(struct net_device *net,
596 struct hv_netvsc_packet *packet, 592 const struct ndis_tcp_ip_checksum_info *csum_info,
597 struct ndis_tcp_ip_checksum_info *csum_info, 593 const struct ndis_pkt_8021q_info *vlan,
598 void *data, u16 vlan_tci) 594 void *data, u32 buflen)
599{ 595{
600 struct sk_buff *skb; 596 struct sk_buff *skb;
601 597
602 skb = netdev_alloc_skb_ip_align(net, packet->total_data_buflen); 598 skb = netdev_alloc_skb_ip_align(net, buflen);
603 if (!skb) 599 if (!skb)
604 return skb; 600 return skb;
605 601
@@ -607,8 +603,7 @@ static struct sk_buff *netvsc_alloc_recv_skb(struct net_device *net,
607 * Copy to skb. This copy is needed here since the memory pointed by 603 * Copy to skb. This copy is needed here since the memory pointed by
608 * hv_netvsc_packet cannot be deallocated 604 * hv_netvsc_packet cannot be deallocated
609 */ 605 */
610 memcpy(skb_put(skb, packet->total_data_buflen), data, 606 memcpy(skb_put(skb, buflen), data, buflen);
611 packet->total_data_buflen);
612 607
613 skb->protocol = eth_type_trans(skb, net); 608 skb->protocol = eth_type_trans(skb, net);
614 609
@@ -625,9 +620,12 @@ static struct sk_buff *netvsc_alloc_recv_skb(struct net_device *net,
625 skb->ip_summed = CHECKSUM_UNNECESSARY; 620 skb->ip_summed = CHECKSUM_UNNECESSARY;
626 } 621 }
627 622
628 if (vlan_tci & VLAN_TAG_PRESENT) 623 if (vlan) {
624 u16 vlan_tci = vlan->vlanid | (vlan->pri << VLAN_PRIO_SHIFT);
625
629 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), 626 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q),
630 vlan_tci); 627 vlan_tci);
628 }
631 629
632 return skb; 630 return skb;
633} 631}
@@ -636,18 +634,19 @@ static struct sk_buff *netvsc_alloc_recv_skb(struct net_device *net,
636 * netvsc_recv_callback - Callback when we receive a packet from the 634 * netvsc_recv_callback - Callback when we receive a packet from the
637 * "wire" on the specified device. 635 * "wire" on the specified device.
638 */ 636 */
639int netvsc_recv_callback(struct hv_device *device_obj, 637int netvsc_recv_callback(struct net_device *net,
640 struct hv_netvsc_packet *packet, 638 struct vmbus_channel *channel,
641 void **data, 639 void *data, u32 len,
642 struct ndis_tcp_ip_checksum_info *csum_info, 640 const struct ndis_tcp_ip_checksum_info *csum_info,
643 struct vmbus_channel *channel, 641 const struct ndis_pkt_8021q_info *vlan)
644 u16 vlan_tci)
645{ 642{
646 struct net_device *net = hv_get_drvdata(device_obj);
647 struct net_device_context *net_device_ctx = netdev_priv(net); 643 struct net_device_context *net_device_ctx = netdev_priv(net);
644 struct netvsc_device *net_device = net_device_ctx->nvdev;
648 struct net_device *vf_netdev; 645 struct net_device *vf_netdev;
649 struct sk_buff *skb; 646 struct sk_buff *skb;
650 struct netvsc_stats *rx_stats; 647 struct netvsc_stats *rx_stats;
648 u16 q_idx = channel->offermsg.offer.sub_channel_index;
649
651 650
652 if (net->reg_state != NETREG_REGISTERED) 651 if (net->reg_state != NETREG_REGISTERED)
653 return NVSP_STAT_FAIL; 652 return NVSP_STAT_FAIL;
@@ -665,7 +664,7 @@ int netvsc_recv_callback(struct hv_device *device_obj,
665 net = vf_netdev; 664 net = vf_netdev;
666 665
667 /* Allocate a skb - TODO direct I/O to pages? */ 666 /* Allocate a skb - TODO direct I/O to pages? */
668 skb = netvsc_alloc_recv_skb(net, packet, csum_info, *data, vlan_tci); 667 skb = netvsc_alloc_recv_skb(net, csum_info, vlan, data, len);
669 if (unlikely(!skb)) { 668 if (unlikely(!skb)) {
670 ++net->stats.rx_dropped; 669 ++net->stats.rx_dropped;
671 rcu_read_unlock(); 670 rcu_read_unlock();
@@ -673,18 +672,17 @@ int netvsc_recv_callback(struct hv_device *device_obj,
673 } 672 }
674 673
675 if (net != vf_netdev) 674 if (net != vf_netdev)
676 skb_record_rx_queue(skb, 675 skb_record_rx_queue(skb, q_idx);
677 channel->offermsg.offer.sub_channel_index);
678 676
679 /* 677 /*
680 * Even if injecting the packet, record the statistics 678 * Even if injecting the packet, record the statistics
681 * on the synthetic device because modifying the VF device 679 * on the synthetic device because modifying the VF device
682 * statistics will not work correctly. 680 * statistics will not work correctly.
683 */ 681 */
684 rx_stats = this_cpu_ptr(net_device_ctx->rx_stats); 682 rx_stats = &net_device->chan_table[q_idx].rx_stats;
685 u64_stats_update_begin(&rx_stats->syncp); 683 u64_stats_update_begin(&rx_stats->syncp);
686 rx_stats->packets++; 684 rx_stats->packets++;
687 rx_stats->bytes += packet->total_data_buflen; 685 rx_stats->bytes += len;
688 686
689 if (skb->pkt_type == PACKET_BROADCAST) 687 if (skb->pkt_type == PACKET_BROADCAST)
690 ++rx_stats->broadcast; 688 ++rx_stats->broadcast;
@@ -697,7 +695,7 @@ int netvsc_recv_callback(struct hv_device *device_obj,
697 * is done. 695 * is done.
698 * TODO - use NAPI? 696 * TODO - use NAPI?
699 */ 697 */
700 netif_rx(skb); 698 netif_receive_skb(skb);
701 rcu_read_unlock(); 699 rcu_read_unlock();
702 700
703 return 0; 701 return 0;
@@ -722,102 +720,76 @@ static void netvsc_get_channels(struct net_device *net,
722 } 720 }
723} 721}
724 722
723static int netvsc_set_queues(struct net_device *net, struct hv_device *dev,
724 u32 num_chn)
725{
726 struct netvsc_device_info device_info;
727 int ret;
728
729 memset(&device_info, 0, sizeof(device_info));
730 device_info.num_chn = num_chn;
731 device_info.ring_size = ring_size;
732 device_info.max_num_vrss_chns = num_chn;
733
734 ret = rndis_filter_device_add(dev, &device_info);
735 if (ret)
736 return ret;
737
738 ret = netif_set_real_num_tx_queues(net, num_chn);
739 if (ret)
740 return ret;
741
742 ret = netif_set_real_num_rx_queues(net, num_chn);
743
744 return ret;
745}
746
725static int netvsc_set_channels(struct net_device *net, 747static int netvsc_set_channels(struct net_device *net,
726 struct ethtool_channels *channels) 748 struct ethtool_channels *channels)
727{ 749{
728 struct net_device_context *net_device_ctx = netdev_priv(net); 750 struct net_device_context *net_device_ctx = netdev_priv(net);
729 struct hv_device *dev = net_device_ctx->device_ctx; 751 struct hv_device *dev = net_device_ctx->device_ctx;
730 struct netvsc_device *nvdev = net_device_ctx->nvdev; 752 struct netvsc_device *nvdev = net_device_ctx->nvdev;
731 struct netvsc_device_info device_info; 753 unsigned int count = channels->combined_count;
732 u32 num_chn; 754 int ret;
733 u32 max_chn; 755
734 int ret = 0; 756 /* We do not support separate count for rx, tx, or other */
735 bool recovering = false; 757 if (count == 0 ||
758 channels->rx_count || channels->tx_count || channels->other_count)
759 return -EINVAL;
760
761 if (count > net->num_tx_queues || count > net->num_rx_queues)
762 return -EINVAL;
736 763
737 if (net_device_ctx->start_remove || !nvdev || nvdev->destroy) 764 if (net_device_ctx->start_remove || !nvdev || nvdev->destroy)
738 return -ENODEV; 765 return -ENODEV;
739 766
740 num_chn = nvdev->num_chn; 767 if (nvdev->nvsp_version < NVSP_PROTOCOL_VERSION_5)
741 max_chn = min_t(u32, nvdev->max_chn, num_online_cpus());
742
743 if (nvdev->nvsp_version < NVSP_PROTOCOL_VERSION_5) {
744 pr_info("vRSS unsupported before NVSP Version 5\n");
745 return -EINVAL; 768 return -EINVAL;
746 }
747 769
748 /* We do not support rx, tx, or other */ 770 if (count > nvdev->max_chn)
749 if (!channels ||
750 channels->rx_count ||
751 channels->tx_count ||
752 channels->other_count ||
753 (channels->combined_count < 1))
754 return -EINVAL; 771 return -EINVAL;
755 772
756 if (channels->combined_count > max_chn) {
757 pr_info("combined channels too high, using %d\n", max_chn);
758 channels->combined_count = max_chn;
759 }
760
761 ret = netvsc_close(net); 773 ret = netvsc_close(net);
762 if (ret) 774 if (ret)
763 goto out; 775 return ret;
764 776
765 do_set:
766 net_device_ctx->start_remove = true; 777 net_device_ctx->start_remove = true;
767 rndis_filter_device_remove(dev); 778 rndis_filter_device_remove(dev, nvdev);
768
769 nvdev->num_chn = channels->combined_count;
770
771 memset(&device_info, 0, sizeof(device_info));
772 device_info.num_chn = nvdev->num_chn; /* passed to RNDIS */
773 device_info.ring_size = ring_size;
774 device_info.max_num_vrss_chns = max_num_vrss_chns;
775 779
776 ret = rndis_filter_device_add(dev, &device_info); 780 ret = netvsc_set_queues(net, dev, count);
777 if (ret) { 781 if (ret == 0)
778 if (recovering) { 782 nvdev->num_chn = count;
779 netdev_err(net, "unable to add netvsc device (ret %d)\n", ret); 783 else
780 return ret; 784 netvsc_set_queues(net, dev, nvdev->num_chn);
781 }
782 goto recover;
783 }
784
785 nvdev = net_device_ctx->nvdev;
786
787 ret = netif_set_real_num_tx_queues(net, nvdev->num_chn);
788 if (ret) {
789 if (recovering) {
790 netdev_err(net, "could not set tx queue count (ret %d)\n", ret);
791 return ret;
792 }
793 goto recover;
794 }
795
796 ret = netif_set_real_num_rx_queues(net, nvdev->num_chn);
797 if (ret) {
798 if (recovering) {
799 netdev_err(net, "could not set rx queue count (ret %d)\n", ret);
800 return ret;
801 }
802 goto recover;
803 }
804 785
805 out:
806 netvsc_open(net); 786 netvsc_open(net);
807 net_device_ctx->start_remove = false; 787 net_device_ctx->start_remove = false;
788
808 /* We may have missed link change notifications */ 789 /* We may have missed link change notifications */
809 schedule_delayed_work(&net_device_ctx->dwork, 0); 790 schedule_delayed_work(&net_device_ctx->dwork, 0);
810 791
811 return ret; 792 return ret;
812
813 recover:
814 /* If the above failed, we attempt to recover through the same
815 * process but with the original number of channels.
816 */
817 netdev_err(net, "could not set channels, recovering\n");
818 recovering = true;
819 channels->combined_count = num_chn;
820 goto do_set;
821} 793}
822 794
823static bool netvsc_validate_ethtool_ss_cmd(const struct ethtool_cmd *cmd) 795static bool netvsc_validate_ethtool_ss_cmd(const struct ethtool_cmd *cmd)
@@ -878,8 +850,7 @@ static int netvsc_change_mtu(struct net_device *ndev, int mtu)
878 struct netvsc_device *nvdev = ndevctx->nvdev; 850 struct netvsc_device *nvdev = ndevctx->nvdev;
879 struct hv_device *hdev = ndevctx->device_ctx; 851 struct hv_device *hdev = ndevctx->device_ctx;
880 struct netvsc_device_info device_info; 852 struct netvsc_device_info device_info;
881 u32 num_chn; 853 int ret;
882 int ret = 0;
883 854
884 if (ndevctx->start_remove || !nvdev || nvdev->destroy) 855 if (ndevctx->start_remove || !nvdev || nvdev->destroy)
885 return -ENODEV; 856 return -ENODEV;
@@ -888,17 +859,15 @@ static int netvsc_change_mtu(struct net_device *ndev, int mtu)
888 if (ret) 859 if (ret)
889 goto out; 860 goto out;
890 861
891 num_chn = nvdev->num_chn;
892
893 ndevctx->start_remove = true; 862 ndevctx->start_remove = true;
894 rndis_filter_device_remove(hdev); 863 rndis_filter_device_remove(hdev, nvdev);
895 864
896 ndev->mtu = mtu; 865 ndev->mtu = mtu;
897 866
898 memset(&device_info, 0, sizeof(device_info)); 867 memset(&device_info, 0, sizeof(device_info));
899 device_info.ring_size = ring_size; 868 device_info.ring_size = ring_size;
900 device_info.num_chn = num_chn; 869 device_info.num_chn = nvdev->num_chn;
901 device_info.max_num_vrss_chns = max_num_vrss_chns; 870 device_info.max_num_vrss_chns = nvdev->num_chn;
902 rndis_filter_device_add(hdev, &device_info); 871 rndis_filter_device_add(hdev, &device_info);
903 872
904out: 873out:
@@ -915,34 +884,39 @@ static void netvsc_get_stats64(struct net_device *net,
915 struct rtnl_link_stats64 *t) 884 struct rtnl_link_stats64 *t)
916{ 885{
917 struct net_device_context *ndev_ctx = netdev_priv(net); 886 struct net_device_context *ndev_ctx = netdev_priv(net);
918 int cpu; 887 struct netvsc_device *nvdev = ndev_ctx->nvdev;
919 888 int i;
920 for_each_possible_cpu(cpu) { 889
921 struct netvsc_stats *tx_stats = per_cpu_ptr(ndev_ctx->tx_stats, 890 if (!nvdev)
922 cpu); 891 return;
923 struct netvsc_stats *rx_stats = per_cpu_ptr(ndev_ctx->rx_stats, 892
924 cpu); 893 for (i = 0; i < nvdev->num_chn; i++) {
925 u64 tx_packets, tx_bytes, rx_packets, rx_bytes, rx_multicast; 894 const struct netvsc_channel *nvchan = &nvdev->chan_table[i];
895 const struct netvsc_stats *stats;
896 u64 packets, bytes, multicast;
926 unsigned int start; 897 unsigned int start;
927 898
899 stats = &nvchan->tx_stats;
928 do { 900 do {
929 start = u64_stats_fetch_begin_irq(&tx_stats->syncp); 901 start = u64_stats_fetch_begin_irq(&stats->syncp);
930 tx_packets = tx_stats->packets; 902 packets = stats->packets;
931 tx_bytes = tx_stats->bytes; 903 bytes = stats->bytes;
932 } while (u64_stats_fetch_retry_irq(&tx_stats->syncp, start)); 904 } while (u64_stats_fetch_retry_irq(&stats->syncp, start));
933 905
906 t->tx_bytes += bytes;
907 t->tx_packets += packets;
908
909 stats = &nvchan->rx_stats;
934 do { 910 do {
935 start = u64_stats_fetch_begin_irq(&rx_stats->syncp); 911 start = u64_stats_fetch_begin_irq(&stats->syncp);
936 rx_packets = rx_stats->packets; 912 packets = stats->packets;
937 rx_bytes = rx_stats->bytes; 913 bytes = stats->bytes;
938 rx_multicast = rx_stats->multicast + rx_stats->broadcast; 914 multicast = stats->multicast + stats->broadcast;
939 } while (u64_stats_fetch_retry_irq(&rx_stats->syncp, start)); 915 } while (u64_stats_fetch_retry_irq(&stats->syncp, start));
940 916
941 t->tx_bytes += tx_bytes; 917 t->rx_bytes += bytes;
942 t->tx_packets += tx_packets; 918 t->rx_packets += packets;
943 t->rx_bytes += rx_bytes; 919 t->multicast += multicast;
944 t->rx_packets += rx_packets;
945 t->multicast += rx_multicast;
946 } 920 }
947 921
948 t->tx_dropped = net->stats.tx_dropped; 922 t->tx_dropped = net->stats.tx_dropped;
@@ -987,11 +961,19 @@ static const struct {
987 { "tx_busy", offsetof(struct netvsc_ethtool_stats, tx_busy) }, 961 { "tx_busy", offsetof(struct netvsc_ethtool_stats, tx_busy) },
988}; 962};
989 963
964#define NETVSC_GLOBAL_STATS_LEN ARRAY_SIZE(netvsc_stats)
965
966/* 4 statistics per queue (rx/tx packets/bytes) */
967#define NETVSC_QUEUE_STATS_LEN(dev) ((dev)->num_chn * 4)
968
990static int netvsc_get_sset_count(struct net_device *dev, int string_set) 969static int netvsc_get_sset_count(struct net_device *dev, int string_set)
991{ 970{
971 struct net_device_context *ndc = netdev_priv(dev);
972 struct netvsc_device *nvdev = ndc->nvdev;
973
992 switch (string_set) { 974 switch (string_set) {
993 case ETH_SS_STATS: 975 case ETH_SS_STATS:
994 return ARRAY_SIZE(netvsc_stats); 976 return NETVSC_GLOBAL_STATS_LEN + NETVSC_QUEUE_STATS_LEN(nvdev);
995 default: 977 default:
996 return -EINVAL; 978 return -EINVAL;
997 } 979 }
@@ -1001,26 +983,109 @@ static void netvsc_get_ethtool_stats(struct net_device *dev,
1001 struct ethtool_stats *stats, u64 *data) 983 struct ethtool_stats *stats, u64 *data)
1002{ 984{
1003 struct net_device_context *ndc = netdev_priv(dev); 985 struct net_device_context *ndc = netdev_priv(dev);
986 struct netvsc_device *nvdev = ndc->nvdev;
1004 const void *nds = &ndc->eth_stats; 987 const void *nds = &ndc->eth_stats;
1005 int i; 988 const struct netvsc_stats *qstats;
989 unsigned int start;
990 u64 packets, bytes;
991 int i, j;
1006 992
1007 for (i = 0; i < ARRAY_SIZE(netvsc_stats); i++) 993 for (i = 0; i < NETVSC_GLOBAL_STATS_LEN; i++)
1008 data[i] = *(unsigned long *)(nds + netvsc_stats[i].offset); 994 data[i] = *(unsigned long *)(nds + netvsc_stats[i].offset);
995
996 for (j = 0; j < nvdev->num_chn; j++) {
997 qstats = &nvdev->chan_table[j].tx_stats;
998
999 do {
1000 start = u64_stats_fetch_begin_irq(&qstats->syncp);
1001 packets = qstats->packets;
1002 bytes = qstats->bytes;
1003 } while (u64_stats_fetch_retry_irq(&qstats->syncp, start));
1004 data[i++] = packets;
1005 data[i++] = bytes;
1006
1007 qstats = &nvdev->chan_table[j].rx_stats;
1008 do {
1009 start = u64_stats_fetch_begin_irq(&qstats->syncp);
1010 packets = qstats->packets;
1011 bytes = qstats->bytes;
1012 } while (u64_stats_fetch_retry_irq(&qstats->syncp, start));
1013 data[i++] = packets;
1014 data[i++] = bytes;
1015 }
1009} 1016}
1010 1017
1011static void netvsc_get_strings(struct net_device *dev, u32 stringset, u8 *data) 1018static void netvsc_get_strings(struct net_device *dev, u32 stringset, u8 *data)
1012{ 1019{
1020 struct net_device_context *ndc = netdev_priv(dev);
1021 struct netvsc_device *nvdev = ndc->nvdev;
1022 u8 *p = data;
1013 int i; 1023 int i;
1014 1024
1015 switch (stringset) { 1025 switch (stringset) {
1016 case ETH_SS_STATS: 1026 case ETH_SS_STATS:
1017 for (i = 0; i < ARRAY_SIZE(netvsc_stats); i++) 1027 for (i = 0; i < ARRAY_SIZE(netvsc_stats); i++)
1018 memcpy(data + i * ETH_GSTRING_LEN, 1028 memcpy(p + i * ETH_GSTRING_LEN,
1019 netvsc_stats[i].name, ETH_GSTRING_LEN); 1029 netvsc_stats[i].name, ETH_GSTRING_LEN);
1030
1031 p += i * ETH_GSTRING_LEN;
1032 for (i = 0; i < nvdev->num_chn; i++) {
1033 sprintf(p, "tx_queue_%u_packets", i);
1034 p += ETH_GSTRING_LEN;
1035 sprintf(p, "tx_queue_%u_bytes", i);
1036 p += ETH_GSTRING_LEN;
1037 sprintf(p, "rx_queue_%u_packets", i);
1038 p += ETH_GSTRING_LEN;
1039 sprintf(p, "rx_queue_%u_bytes", i);
1040 p += ETH_GSTRING_LEN;
1041 }
1042
1020 break; 1043 break;
1021 } 1044 }
1022} 1045}
1023 1046
1047static int
1048netvsc_get_rss_hash_opts(struct netvsc_device *nvdev,
1049 struct ethtool_rxnfc *info)
1050{
1051 info->data = RXH_IP_SRC | RXH_IP_DST;
1052
1053 switch (info->flow_type) {
1054 case TCP_V4_FLOW:
1055 case TCP_V6_FLOW:
1056 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1057 /* fallthrough */
1058 case UDP_V4_FLOW:
1059 case UDP_V6_FLOW:
1060 case IPV4_FLOW:
1061 case IPV6_FLOW:
1062 break;
1063 default:
1064 info->data = 0;
1065 break;
1066 }
1067
1068 return 0;
1069}
1070
1071static int
1072netvsc_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
1073 u32 *rules)
1074{
1075 struct net_device_context *ndc = netdev_priv(dev);
1076 struct netvsc_device *nvdev = ndc->nvdev;
1077
1078 switch (info->cmd) {
1079 case ETHTOOL_GRXRINGS:
1080 info->data = nvdev->num_chn;
1081 return 0;
1082
1083 case ETHTOOL_GRXFH:
1084 return netvsc_get_rss_hash_opts(nvdev, info);
1085 }
1086 return -EOPNOTSUPP;
1087}
1088
1024#ifdef CONFIG_NET_POLL_CONTROLLER 1089#ifdef CONFIG_NET_POLL_CONTROLLER
1025static void netvsc_poll_controller(struct net_device *net) 1090static void netvsc_poll_controller(struct net_device *net)
1026{ 1091{
@@ -1030,6 +1095,68 @@ static void netvsc_poll_controller(struct net_device *net)
1030} 1095}
1031#endif 1096#endif
1032 1097
1098static u32 netvsc_get_rxfh_key_size(struct net_device *dev)
1099{
1100 return NETVSC_HASH_KEYLEN;
1101}
1102
1103static u32 netvsc_rss_indir_size(struct net_device *dev)
1104{
1105 return ITAB_NUM;
1106}
1107
1108static int netvsc_get_rxfh(struct net_device *dev, u32 *indir, u8 *key,
1109 u8 *hfunc)
1110{
1111 struct net_device_context *ndc = netdev_priv(dev);
1112 struct netvsc_device *ndev = ndc->nvdev;
1113 struct rndis_device *rndis_dev = ndev->extension;
1114 int i;
1115
1116 if (hfunc)
1117 *hfunc = ETH_RSS_HASH_TOP; /* Toeplitz */
1118
1119 if (indir) {
1120 for (i = 0; i < ITAB_NUM; i++)
1121 indir[i] = rndis_dev->ind_table[i];
1122 }
1123
1124 if (key)
1125 memcpy(key, rndis_dev->rss_key, NETVSC_HASH_KEYLEN);
1126
1127 return 0;
1128}
1129
1130static int netvsc_set_rxfh(struct net_device *dev, const u32 *indir,
1131 const u8 *key, const u8 hfunc)
1132{
1133 struct net_device_context *ndc = netdev_priv(dev);
1134 struct netvsc_device *ndev = ndc->nvdev;
1135 struct rndis_device *rndis_dev = ndev->extension;
1136 int i;
1137
1138 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
1139 return -EOPNOTSUPP;
1140
1141 if (indir) {
1142 for (i = 0; i < ITAB_NUM; i++)
1143 if (indir[i] >= dev->num_rx_queues)
1144 return -EINVAL;
1145
1146 for (i = 0; i < ITAB_NUM; i++)
1147 rndis_dev->ind_table[i] = indir[i];
1148 }
1149
1150 if (!key) {
1151 if (!indir)
1152 return 0;
1153
1154 key = rndis_dev->rss_key;
1155 }
1156
1157 return rndis_filter_set_rss_param(rndis_dev, key, ndev->num_chn);
1158}
1159
1033static const struct ethtool_ops ethtool_ops = { 1160static const struct ethtool_ops ethtool_ops = {
1034 .get_drvinfo = netvsc_get_drvinfo, 1161 .get_drvinfo = netvsc_get_drvinfo,
1035 .get_link = ethtool_op_get_link, 1162 .get_link = ethtool_op_get_link,
@@ -1041,6 +1168,11 @@ static const struct ethtool_ops ethtool_ops = {
1041 .get_ts_info = ethtool_op_get_ts_info, 1168 .get_ts_info = ethtool_op_get_ts_info,
1042 .get_settings = netvsc_get_settings, 1169 .get_settings = netvsc_get_settings,
1043 .set_settings = netvsc_set_settings, 1170 .set_settings = netvsc_set_settings,
1171 .get_rxnfc = netvsc_get_rxnfc,
1172 .get_rxfh_key_size = netvsc_get_rxfh_key_size,
1173 .get_rxfh_indir_size = netvsc_rss_indir_size,
1174 .get_rxfh = netvsc_get_rxfh,
1175 .set_rxfh = netvsc_set_rxfh,
1044}; 1176};
1045 1177
1046static const struct net_device_ops device_ops = { 1178static const struct net_device_ops device_ops = {
@@ -1161,15 +1293,6 @@ out_unlock:
1161 rtnl_unlock(); 1293 rtnl_unlock();
1162} 1294}
1163 1295
1164static void netvsc_free_netdev(struct net_device *netdev)
1165{
1166 struct net_device_context *net_device_ctx = netdev_priv(netdev);
1167
1168 free_percpu(net_device_ctx->tx_stats);
1169 free_percpu(net_device_ctx->rx_stats);
1170 free_netdev(netdev);
1171}
1172
1173static struct net_device *get_netvsc_bymac(const u8 *mac) 1296static struct net_device *get_netvsc_bymac(const u8 *mac)
1174{ 1297{
1175 struct net_device *dev; 1298 struct net_device *dev;
@@ -1306,7 +1429,6 @@ static int netvsc_vf_down(struct net_device *vf_netdev)
1306static int netvsc_unregister_vf(struct net_device *vf_netdev) 1429static int netvsc_unregister_vf(struct net_device *vf_netdev)
1307{ 1430{
1308 struct net_device *ndev; 1431 struct net_device *ndev;
1309 struct netvsc_device *netvsc_dev;
1310 struct net_device_context *net_device_ctx; 1432 struct net_device_context *net_device_ctx;
1311 1433
1312 ndev = get_netvsc_byref(vf_netdev); 1434 ndev = get_netvsc_byref(vf_netdev);
@@ -1314,7 +1436,6 @@ static int netvsc_unregister_vf(struct net_device *vf_netdev)
1314 return NOTIFY_DONE; 1436 return NOTIFY_DONE;
1315 1437
1316 net_device_ctx = netdev_priv(ndev); 1438 net_device_ctx = netdev_priv(ndev);
1317 netvsc_dev = net_device_ctx->nvdev;
1318 1439
1319 netdev_info(ndev, "VF unregistering: %s\n", vf_netdev->name); 1440 netdev_info(ndev, "VF unregistering: %s\n", vf_netdev->name);
1320 1441
@@ -1334,7 +1455,7 @@ static int netvsc_probe(struct hv_device *dev,
1334 int ret; 1455 int ret;
1335 1456
1336 net = alloc_etherdev_mq(sizeof(struct net_device_context), 1457 net = alloc_etherdev_mq(sizeof(struct net_device_context),
1337 num_online_cpus()); 1458 VRSS_CHANNEL_MAX);
1338 if (!net) 1459 if (!net)
1339 return -ENOMEM; 1460 return -ENOMEM;
1340 1461
@@ -1349,18 +1470,6 @@ static int netvsc_probe(struct hv_device *dev,
1349 netdev_dbg(net, "netvsc msg_enable: %d\n", 1470 netdev_dbg(net, "netvsc msg_enable: %d\n",
1350 net_device_ctx->msg_enable); 1471 net_device_ctx->msg_enable);
1351 1472
1352 net_device_ctx->tx_stats = netdev_alloc_pcpu_stats(struct netvsc_stats);
1353 if (!net_device_ctx->tx_stats) {
1354 free_netdev(net);
1355 return -ENOMEM;
1356 }
1357 net_device_ctx->rx_stats = netdev_alloc_pcpu_stats(struct netvsc_stats);
1358 if (!net_device_ctx->rx_stats) {
1359 free_percpu(net_device_ctx->tx_stats);
1360 free_netdev(net);
1361 return -ENOMEM;
1362 }
1363
1364 hv_set_drvdata(dev, net); 1473 hv_set_drvdata(dev, net);
1365 1474
1366 net_device_ctx->start_remove = false; 1475 net_device_ctx->start_remove = false;
@@ -1372,10 +1481,6 @@ static int netvsc_probe(struct hv_device *dev,
1372 INIT_LIST_HEAD(&net_device_ctx->reconfig_events); 1481 INIT_LIST_HEAD(&net_device_ctx->reconfig_events);
1373 1482
1374 net->netdev_ops = &device_ops; 1483 net->netdev_ops = &device_ops;
1375
1376 net->hw_features = NETVSC_HW_FEATURES;
1377 net->features = NETVSC_HW_FEATURES | NETIF_F_HW_VLAN_CTAG_TX;
1378
1379 net->ethtool_ops = &ethtool_ops; 1484 net->ethtool_ops = &ethtool_ops;
1380 SET_NETDEV_DEV(net, &dev->device); 1485 SET_NETDEV_DEV(net, &dev->device);
1381 1486
@@ -1385,20 +1490,26 @@ static int netvsc_probe(struct hv_device *dev,
1385 /* Notify the netvsc driver of the new device */ 1490 /* Notify the netvsc driver of the new device */
1386 memset(&device_info, 0, sizeof(device_info)); 1491 memset(&device_info, 0, sizeof(device_info));
1387 device_info.ring_size = ring_size; 1492 device_info.ring_size = ring_size;
1388 device_info.max_num_vrss_chns = max_num_vrss_chns; 1493 device_info.max_num_vrss_chns = min_t(u32, VRSS_CHANNEL_DEFAULT,
1494 num_online_cpus());
1389 ret = rndis_filter_device_add(dev, &device_info); 1495 ret = rndis_filter_device_add(dev, &device_info);
1390 if (ret != 0) { 1496 if (ret != 0) {
1391 netdev_err(net, "unable to add netvsc device (ret %d)\n", ret); 1497 netdev_err(net, "unable to add netvsc device (ret %d)\n", ret);
1392 netvsc_free_netdev(net); 1498 free_netdev(net);
1393 hv_set_drvdata(dev, NULL); 1499 hv_set_drvdata(dev, NULL);
1394 return ret; 1500 return ret;
1395 } 1501 }
1396 memcpy(net->dev_addr, device_info.mac_adr, ETH_ALEN); 1502 memcpy(net->dev_addr, device_info.mac_adr, ETH_ALEN);
1397 1503
1504 /* hw_features computed in rndis_filter_device_add */
1505 net->features = net->hw_features |
1506 NETIF_F_HIGHDMA | NETIF_F_SG |
1507 NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX;
1508 net->vlan_features = net->features;
1509
1398 nvdev = net_device_ctx->nvdev; 1510 nvdev = net_device_ctx->nvdev;
1399 netif_set_real_num_tx_queues(net, nvdev->num_chn); 1511 netif_set_real_num_tx_queues(net, nvdev->num_chn);
1400 netif_set_real_num_rx_queues(net, nvdev->num_chn); 1512 netif_set_real_num_rx_queues(net, nvdev->num_chn);
1401 netif_set_gso_max_size(net, NETVSC_GSO_MAX_SIZE);
1402 1513
1403 /* MTU range: 68 - 1500 or 65521 */ 1514 /* MTU range: 68 - 1500 or 65521 */
1404 net->min_mtu = NETVSC_MTU_MIN; 1515 net->min_mtu = NETVSC_MTU_MIN;
@@ -1410,8 +1521,8 @@ static int netvsc_probe(struct hv_device *dev,
1410 ret = register_netdev(net); 1521 ret = register_netdev(net);
1411 if (ret != 0) { 1522 if (ret != 0) {
1412 pr_err("Unable to register netdev.\n"); 1523 pr_err("Unable to register netdev.\n");
1413 rndis_filter_device_remove(dev); 1524 rndis_filter_device_remove(dev, nvdev);
1414 netvsc_free_netdev(net); 1525 free_netdev(net);
1415 } 1526 }
1416 1527
1417 return ret; 1528 return ret;
@@ -1421,7 +1532,6 @@ static int netvsc_remove(struct hv_device *dev)
1421{ 1532{
1422 struct net_device *net; 1533 struct net_device *net;
1423 struct net_device_context *ndev_ctx; 1534 struct net_device_context *ndev_ctx;
1424 struct netvsc_device *net_device;
1425 1535
1426 net = hv_get_drvdata(dev); 1536 net = hv_get_drvdata(dev);
1427 1537
@@ -1431,7 +1541,6 @@ static int netvsc_remove(struct hv_device *dev)
1431 } 1541 }
1432 1542
1433 ndev_ctx = netdev_priv(net); 1543 ndev_ctx = netdev_priv(net);
1434 net_device = ndev_ctx->nvdev;
1435 1544
1436 /* Avoid racing with netvsc_change_mtu()/netvsc_set_channels() 1545 /* Avoid racing with netvsc_change_mtu()/netvsc_set_channels()
1437 * removing the device. 1546 * removing the device.
@@ -1452,11 +1561,11 @@ static int netvsc_remove(struct hv_device *dev)
1452 * Call to the vsc driver to let it know that the device is being 1561 * Call to the vsc driver to let it know that the device is being
1453 * removed 1562 * removed
1454 */ 1563 */
1455 rndis_filter_device_remove(dev); 1564 rndis_filter_device_remove(dev, ndev_ctx->nvdev);
1456 1565
1457 hv_set_drvdata(dev, NULL); 1566 hv_set_drvdata(dev, NULL);
1458 1567
1459 netvsc_free_netdev(net); 1568 free_netdev(net);
1460 return 0; 1569 return 0;
1461} 1570}
1462 1571
diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
index 8d90904e0e49..19356f56b7b1 100644
--- a/drivers/net/hyperv/rndis_filter.c
+++ b/drivers/net/hyperv/rndis_filter.c
@@ -57,6 +57,14 @@ struct rndis_request {
57 u8 request_ext[RNDIS_EXT_LEN]; 57 u8 request_ext[RNDIS_EXT_LEN];
58}; 58};
59 59
60static const u8 netvsc_hash_key[NETVSC_HASH_KEYLEN] = {
61 0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2,
62 0x41, 0x67, 0x25, 0x3d, 0x43, 0xa3, 0x8f, 0xb0,
63 0xd0, 0xca, 0x2b, 0xcb, 0xae, 0x7b, 0x30, 0xb4,
64 0x77, 0xcb, 0x2d, 0xa3, 0x80, 0x30, 0xf2, 0x0c,
65 0x6a, 0x42, 0xb7, 0x3b, 0xbe, 0xac, 0x01, 0xfa
66};
67
60static struct rndis_device *get_rndis_device(void) 68static struct rndis_device *get_rndis_device(void)
61{ 69{
62 struct rndis_device *device; 70 struct rndis_device *device;
@@ -124,7 +132,7 @@ static void put_rndis_request(struct rndis_device *dev,
124} 132}
125 133
126static void dump_rndis_message(struct hv_device *hv_dev, 134static void dump_rndis_message(struct hv_device *hv_dev,
127 struct rndis_message *rndis_msg) 135 const struct rndis_message *rndis_msg)
128{ 136{
129 struct net_device *netdev = hv_get_drvdata(hv_dev); 137 struct net_device *netdev = hv_get_drvdata(hv_dev);
130 138
@@ -339,102 +347,78 @@ static inline void *rndis_get_ppi(struct rndis_packet *rpkt, u32 type)
339 return NULL; 347 return NULL;
340} 348}
341 349
342static int rndis_filter_receive_data(struct rndis_device *dev, 350static int rndis_filter_receive_data(struct net_device *ndev,
343 struct rndis_message *msg, 351 struct rndis_device *dev,
344 struct hv_netvsc_packet *pkt, 352 struct rndis_message *msg,
345 void **data, 353 struct vmbus_channel *channel,
346 struct vmbus_channel *channel) 354 void *data, u32 data_buflen)
347{ 355{
348 struct rndis_packet *rndis_pkt; 356 struct rndis_packet *rndis_pkt = &msg->msg.pkt;
357 const struct ndis_tcp_ip_checksum_info *csum_info;
358 const struct ndis_pkt_8021q_info *vlan;
349 u32 data_offset; 359 u32 data_offset;
350 struct ndis_pkt_8021q_info *vlan;
351 struct ndis_tcp_ip_checksum_info *csum_info;
352 u16 vlan_tci = 0;
353 struct net_device_context *net_device_ctx = netdev_priv(dev->ndev);
354
355 rndis_pkt = &msg->msg.pkt;
356 360
357 /* Remove the rndis header and pass it back up the stack */ 361 /* Remove the rndis header and pass it back up the stack */
358 data_offset = RNDIS_HEADER_SIZE + rndis_pkt->data_offset; 362 data_offset = RNDIS_HEADER_SIZE + rndis_pkt->data_offset;
359 363
360 pkt->total_data_buflen -= data_offset; 364 data_buflen -= data_offset;
361 365
362 /* 366 /*
363 * Make sure we got a valid RNDIS message, now total_data_buflen 367 * Make sure we got a valid RNDIS message, now total_data_buflen
364 * should be the data packet size plus the trailer padding size 368 * should be the data packet size plus the trailer padding size
365 */ 369 */
366 if (pkt->total_data_buflen < rndis_pkt->data_len) { 370 if (unlikely(data_buflen < rndis_pkt->data_len)) {
367 netdev_err(dev->ndev, "rndis message buffer " 371 netdev_err(dev->ndev, "rndis message buffer "
368 "overflow detected (got %u, min %u)" 372 "overflow detected (got %u, min %u)"
369 "...dropping this message!\n", 373 "...dropping this message!\n",
370 pkt->total_data_buflen, rndis_pkt->data_len); 374 data_buflen, rndis_pkt->data_len);
371 return NVSP_STAT_FAIL; 375 return NVSP_STAT_FAIL;
372 } 376 }
373 377
378 vlan = rndis_get_ppi(rndis_pkt, IEEE_8021Q_INFO);
379
374 /* 380 /*
375 * Remove the rndis trailer padding from rndis packet message 381 * Remove the rndis trailer padding from rndis packet message
376 * rndis_pkt->data_len tell us the real data length, we only copy 382 * rndis_pkt->data_len tell us the real data length, we only copy
377 * the data packet to the stack, without the rndis trailer padding 383 * the data packet to the stack, without the rndis trailer padding
378 */ 384 */
379 pkt->total_data_buflen = rndis_pkt->data_len; 385 data = (void *)((unsigned long)data + data_offset);
380 *data = (void *)((unsigned long)(*data) + data_offset);
381
382 vlan = rndis_get_ppi(rndis_pkt, IEEE_8021Q_INFO);
383 if (vlan) {
384 vlan_tci = VLAN_TAG_PRESENT | vlan->vlanid |
385 (vlan->pri << VLAN_PRIO_SHIFT);
386 }
387
388 csum_info = rndis_get_ppi(rndis_pkt, TCPIP_CHKSUM_PKTINFO); 386 csum_info = rndis_get_ppi(rndis_pkt, TCPIP_CHKSUM_PKTINFO);
389 return netvsc_recv_callback(net_device_ctx->device_ctx, pkt, data, 387 return netvsc_recv_callback(ndev, channel,
390 csum_info, channel, vlan_tci); 388 data, rndis_pkt->data_len,
389 csum_info, vlan);
391} 390}
392 391
393int rndis_filter_receive(struct hv_device *dev, 392int rndis_filter_receive(struct net_device *ndev,
394 struct hv_netvsc_packet *pkt, 393 struct netvsc_device *net_dev,
395 void **data, 394 struct hv_device *dev,
396 struct vmbus_channel *channel) 395 struct vmbus_channel *channel,
396 void *data, u32 buflen)
397{ 397{
398 struct net_device *ndev = hv_get_drvdata(dev);
399 struct net_device_context *net_device_ctx = netdev_priv(ndev); 398 struct net_device_context *net_device_ctx = netdev_priv(ndev);
400 struct netvsc_device *net_dev = net_device_ctx->nvdev; 399 struct rndis_device *rndis_dev = net_dev->extension;
401 struct rndis_device *rndis_dev; 400 struct rndis_message *rndis_msg = data;
402 struct rndis_message *rndis_msg;
403 int ret = 0;
404
405 if (!net_dev) {
406 ret = NVSP_STAT_FAIL;
407 goto exit;
408 }
409 401
410 /* Make sure the rndis device state is initialized */ 402 /* Make sure the rndis device state is initialized */
411 if (!net_dev->extension) { 403 if (unlikely(!rndis_dev)) {
412 netdev_err(ndev, "got rndis message but no rndis device - " 404 netif_err(net_device_ctx, rx_err, ndev,
413 "dropping this message!\n"); 405 "got rndis message but no rndis device!\n");
414 ret = NVSP_STAT_FAIL; 406 return NVSP_STAT_FAIL;
415 goto exit;
416 } 407 }
417 408
418 rndis_dev = (struct rndis_device *)net_dev->extension; 409 if (unlikely(rndis_dev->state == RNDIS_DEV_UNINITIALIZED)) {
419 if (rndis_dev->state == RNDIS_DEV_UNINITIALIZED) { 410 netif_err(net_device_ctx, rx_err, ndev,
420 netdev_err(ndev, "got rndis message but rndis device " 411 "got rndis message uninitialized\n");
421 "uninitialized...dropping this message!\n"); 412 return NVSP_STAT_FAIL;
422 ret = NVSP_STAT_FAIL;
423 goto exit;
424 } 413 }
425 414
426 rndis_msg = *data; 415 if (netif_msg_rx_status(net_device_ctx))
427
428 if (netif_msg_rx_err(net_device_ctx))
429 dump_rndis_message(dev, rndis_msg); 416 dump_rndis_message(dev, rndis_msg);
430 417
431 switch (rndis_msg->ndis_msg_type) { 418 switch (rndis_msg->ndis_msg_type) {
432 case RNDIS_MSG_PACKET: 419 case RNDIS_MSG_PACKET:
433 /* data msg */ 420 return rndis_filter_receive_data(ndev, rndis_dev, rndis_msg,
434 ret = rndis_filter_receive_data(rndis_dev, rndis_msg, pkt, 421 channel, data, buflen);
435 data, channel);
436 break;
437
438 case RNDIS_MSG_INIT_C: 422 case RNDIS_MSG_INIT_C:
439 case RNDIS_MSG_QUERY_C: 423 case RNDIS_MSG_QUERY_C:
440 case RNDIS_MSG_SET_C: 424 case RNDIS_MSG_SET_C:
@@ -454,8 +438,7 @@ int rndis_filter_receive(struct hv_device *dev,
454 break; 438 break;
455 } 439 }
456 440
457exit: 441 return 0;
458 return ret;
459} 442}
460 443
461static int rndis_filter_query_device(struct rndis_device *dev, u32 oid, 444static int rndis_filter_query_device(struct rndis_device *dev, u32 oid,
@@ -485,7 +468,35 @@ static int rndis_filter_query_device(struct rndis_device *dev, u32 oid,
485 query->info_buflen = 0; 468 query->info_buflen = 0;
486 query->dev_vc_handle = 0; 469 query->dev_vc_handle = 0;
487 470
488 if (oid == OID_GEN_RECEIVE_SCALE_CAPABILITIES) { 471 if (oid == OID_TCP_OFFLOAD_HARDWARE_CAPABILITIES) {
472 struct net_device_context *ndevctx = netdev_priv(dev->ndev);
473 struct netvsc_device *nvdev = ndevctx->nvdev;
474 struct ndis_offload *hwcaps;
475 u32 nvsp_version = nvdev->nvsp_version;
476 u8 ndis_rev;
477 size_t size;
478
479 if (nvsp_version >= NVSP_PROTOCOL_VERSION_5) {
480 ndis_rev = NDIS_OFFLOAD_PARAMETERS_REVISION_3;
481 size = NDIS_OFFLOAD_SIZE;
482 } else if (nvsp_version >= NVSP_PROTOCOL_VERSION_4) {
483 ndis_rev = NDIS_OFFLOAD_PARAMETERS_REVISION_2;
484 size = NDIS_OFFLOAD_SIZE_6_1;
485 } else {
486 ndis_rev = NDIS_OFFLOAD_PARAMETERS_REVISION_1;
487 size = NDIS_OFFLOAD_SIZE_6_0;
488 }
489
490 request->request_msg.msg_len += size;
491 query->info_buflen = size;
492 hwcaps = (struct ndis_offload *)
493 ((unsigned long)query + query->info_buf_offset);
494
495 hwcaps->header.type = NDIS_OBJECT_TYPE_OFFLOAD;
496 hwcaps->header.revision = ndis_rev;
497 hwcaps->header.size = size;
498
499 } else if (oid == OID_GEN_RECEIVE_SCALE_CAPABILITIES) {
489 struct ndis_recv_scale_cap *cap; 500 struct ndis_recv_scale_cap *cap;
490 501
491 request->request_msg.msg_len += 502 request->request_msg.msg_len +=
@@ -526,6 +537,44 @@ cleanup:
526 return ret; 537 return ret;
527} 538}
528 539
540/* Get the hardware offload capabilities */
541static int
542rndis_query_hwcaps(struct rndis_device *dev, struct ndis_offload *caps)
543{
544 u32 caps_len = sizeof(*caps);
545 int ret;
546
547 memset(caps, 0, sizeof(*caps));
548
549 ret = rndis_filter_query_device(dev,
550 OID_TCP_OFFLOAD_HARDWARE_CAPABILITIES,
551 caps, &caps_len);
552 if (ret)
553 return ret;
554
555 if (caps->header.type != NDIS_OBJECT_TYPE_OFFLOAD) {
556 netdev_warn(dev->ndev, "invalid NDIS objtype %#x\n",
557 caps->header.type);
558 return -EINVAL;
559 }
560
561 if (caps->header.revision < NDIS_OFFLOAD_PARAMETERS_REVISION_1) {
562 netdev_warn(dev->ndev, "invalid NDIS objrev %x\n",
563 caps->header.revision);
564 return -EINVAL;
565 }
566
567 if (caps->header.size > caps_len ||
568 caps->header.size < NDIS_OFFLOAD_SIZE_6_0) {
569 netdev_warn(dev->ndev,
570 "invalid NDIS objsize %u, data size %u\n",
571 caps->header.size, caps_len);
572 return -EINVAL;
573 }
574
575 return 0;
576}
577
529static int rndis_filter_query_device_mac(struct rndis_device *dev) 578static int rndis_filter_query_device_mac(struct rndis_device *dev)
530{ 579{
531 u32 size = ETH_ALEN; 580 u32 size = ETH_ALEN;
@@ -663,23 +712,15 @@ cleanup:
663 return ret; 712 return ret;
664} 713}
665 714
666static const u8 netvsc_hash_key[] = { 715int rndis_filter_set_rss_param(struct rndis_device *rdev,
667 0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2, 716 const u8 *rss_key, int num_queue)
668 0x41, 0x67, 0x25, 0x3d, 0x43, 0xa3, 0x8f, 0xb0,
669 0xd0, 0xca, 0x2b, 0xcb, 0xae, 0x7b, 0x30, 0xb4,
670 0x77, 0xcb, 0x2d, 0xa3, 0x80, 0x30, 0xf2, 0x0c,
671 0x6a, 0x42, 0xb7, 0x3b, 0xbe, 0xac, 0x01, 0xfa
672};
673#define HASH_KEYLEN ARRAY_SIZE(netvsc_hash_key)
674
675static int rndis_filter_set_rss_param(struct rndis_device *rdev, int num_queue)
676{ 717{
677 struct net_device *ndev = rdev->ndev; 718 struct net_device *ndev = rdev->ndev;
678 struct rndis_request *request; 719 struct rndis_request *request;
679 struct rndis_set_request *set; 720 struct rndis_set_request *set;
680 struct rndis_set_complete *set_complete; 721 struct rndis_set_complete *set_complete;
681 u32 extlen = sizeof(struct ndis_recv_scale_param) + 722 u32 extlen = sizeof(struct ndis_recv_scale_param) +
682 4*ITAB_NUM + HASH_KEYLEN; 723 4 * ITAB_NUM + NETVSC_HASH_KEYLEN;
683 struct ndis_recv_scale_param *rssp; 724 struct ndis_recv_scale_param *rssp;
684 u32 *itab; 725 u32 *itab;
685 u8 *keyp; 726 u8 *keyp;
@@ -707,19 +748,18 @@ static int rndis_filter_set_rss_param(struct rndis_device *rdev, int num_queue)
707 NDIS_HASH_TCP_IPV6; 748 NDIS_HASH_TCP_IPV6;
708 rssp->indirect_tabsize = 4*ITAB_NUM; 749 rssp->indirect_tabsize = 4*ITAB_NUM;
709 rssp->indirect_taboffset = sizeof(struct ndis_recv_scale_param); 750 rssp->indirect_taboffset = sizeof(struct ndis_recv_scale_param);
710 rssp->hashkey_size = HASH_KEYLEN; 751 rssp->hashkey_size = NETVSC_HASH_KEYLEN;
711 rssp->kashkey_offset = rssp->indirect_taboffset + 752 rssp->kashkey_offset = rssp->indirect_taboffset +
712 rssp->indirect_tabsize; 753 rssp->indirect_tabsize;
713 754
714 /* Set indirection table entries */ 755 /* Set indirection table entries */
715 itab = (u32 *)(rssp + 1); 756 itab = (u32 *)(rssp + 1);
716 for (i = 0; i < ITAB_NUM; i++) 757 for (i = 0; i < ITAB_NUM; i++)
717 itab[i] = i % num_queue; 758 itab[i] = rdev->ind_table[i];
718 759
719 /* Set hask key values */ 760 /* Set hask key values */
720 keyp = (u8 *)((unsigned long)rssp + rssp->kashkey_offset); 761 keyp = (u8 *)((unsigned long)rssp + rssp->kashkey_offset);
721 for (i = 0; i < HASH_KEYLEN; i++) 762 memcpy(keyp, rss_key, NETVSC_HASH_KEYLEN);
722 keyp[i] = netvsc_hash_key[i];
723 763
724 ret = rndis_filter_send_request(rdev, request); 764 ret = rndis_filter_send_request(rdev, request);
725 if (ret != 0) 765 if (ret != 0)
@@ -727,7 +767,9 @@ static int rndis_filter_set_rss_param(struct rndis_device *rdev, int num_queue)
727 767
728 wait_for_completion(&request->wait_event); 768 wait_for_completion(&request->wait_event);
729 set_complete = &request->response_msg.msg.set_complete; 769 set_complete = &request->response_msg.msg.set_complete;
730 if (set_complete->status != RNDIS_STATUS_SUCCESS) { 770 if (set_complete->status == RNDIS_STATUS_SUCCESS)
771 memcpy(rdev->rss_key, rss_key, NETVSC_HASH_KEYLEN);
772 else {
731 netdev_err(ndev, "Fail to set RSS parameters:0x%x\n", 773 netdev_err(ndev, "Fail to set RSS parameters:0x%x\n",
732 set_complete->status); 774 set_complete->status);
733 ret = -EINVAL; 775 ret = -EINVAL;
@@ -778,7 +820,6 @@ int rndis_filter_set_packet_filter(struct rndis_device *dev, u32 new_filter)
778 struct rndis_request *request; 820 struct rndis_request *request;
779 struct rndis_set_request *set; 821 struct rndis_set_request *set;
780 struct rndis_set_complete *set_complete; 822 struct rndis_set_complete *set_complete;
781 u32 status;
782 int ret; 823 int ret;
783 824
784 request = get_rndis_request(dev, RNDIS_MSG_SET, 825 request = get_rndis_request(dev, RNDIS_MSG_SET,
@@ -805,8 +846,6 @@ int rndis_filter_set_packet_filter(struct rndis_device *dev, u32 new_filter)
805 wait_for_completion(&request->wait_event); 846 wait_for_completion(&request->wait_event);
806 847
807 set_complete = &request->response_msg.msg.set_complete; 848 set_complete = &request->response_msg.msg.set_complete;
808 status = set_complete->status;
809
810cleanup: 849cleanup:
811 if (request) 850 if (request)
812 put_rndis_request(dev, request); 851 put_rndis_request(dev, request);
@@ -864,6 +903,23 @@ cleanup:
864 return ret; 903 return ret;
865} 904}
866 905
906static bool netvsc_device_idle(const struct netvsc_device *nvdev)
907{
908 int i;
909
910 if (atomic_read(&nvdev->num_outstanding_recvs) > 0)
911 return false;
912
913 for (i = 0; i < nvdev->num_chn; i++) {
914 const struct netvsc_channel *nvchan = &nvdev->chan_table[i];
915
916 if (atomic_read(&nvchan->queue_sends) > 0)
917 return false;
918 }
919
920 return true;
921}
922
867static void rndis_filter_halt_device(struct rndis_device *dev) 923static void rndis_filter_halt_device(struct rndis_device *dev)
868{ 924{
869 struct rndis_request *request; 925 struct rndis_request *request;
@@ -894,9 +950,7 @@ cleanup:
894 spin_unlock_irqrestore(&hdev->channel->inbound_lock, flags); 950 spin_unlock_irqrestore(&hdev->channel->inbound_lock, flags);
895 951
896 /* Wait for all send completions */ 952 /* Wait for all send completions */
897 wait_event(nvdev->wait_drain, 953 wait_event(nvdev->wait_drain, netvsc_device_idle(nvdev));
898 atomic_read(&nvdev->num_outstanding_sends) == 0 &&
899 atomic_read(&nvdev->num_outstanding_recvs) == 0);
900 954
901 if (request) 955 if (request)
902 put_rndis_request(dev, request); 956 put_rndis_request(dev, request);
@@ -948,18 +1002,15 @@ static void netvsc_sc_open(struct vmbus_channel *new_sc)
948 if (chn_index >= nvscdev->num_chn) 1002 if (chn_index >= nvscdev->num_chn)
949 return; 1003 return;
950 1004
951 set_per_channel_state(new_sc, nvscdev->sub_cb_buf + (chn_index - 1) * 1005 nvscdev->chan_table[chn_index].mrc.buf
952 NETVSC_PACKET_SIZE); 1006 = vzalloc(NETVSC_RECVSLOT_MAX * sizeof(struct recv_comp_data));
953
954 nvscdev->mrc[chn_index].buf = vzalloc(NETVSC_RECVSLOT_MAX *
955 sizeof(struct recv_comp_data));
956 1007
957 ret = vmbus_open(new_sc, nvscdev->ring_size * PAGE_SIZE, 1008 ret = vmbus_open(new_sc, nvscdev->ring_size * PAGE_SIZE,
958 nvscdev->ring_size * PAGE_SIZE, NULL, 0, 1009 nvscdev->ring_size * PAGE_SIZE, NULL, 0,
959 netvsc_channel_cb, new_sc); 1010 netvsc_channel_cb, new_sc);
960 1011
961 if (ret == 0) 1012 if (ret == 0)
962 nvscdev->chn_table[chn_index] = new_sc; 1013 nvscdev->chan_table[chn_index].channel = new_sc;
963 1014
964 spin_lock_irqsave(&nvscdev->sc_lock, flags); 1015 spin_lock_irqsave(&nvscdev->sc_lock, flags);
965 nvscdev->num_sc_offered--; 1016 nvscdev->num_sc_offered--;
@@ -969,24 +1020,25 @@ static void netvsc_sc_open(struct vmbus_channel *new_sc)
969} 1020}
970 1021
971int rndis_filter_device_add(struct hv_device *dev, 1022int rndis_filter_device_add(struct hv_device *dev,
972 void *additional_info) 1023 struct netvsc_device_info *device_info)
973{ 1024{
974 int ret;
975 struct net_device *net = hv_get_drvdata(dev); 1025 struct net_device *net = hv_get_drvdata(dev);
976 struct net_device_context *net_device_ctx = netdev_priv(net); 1026 struct net_device_context *net_device_ctx = netdev_priv(net);
977 struct netvsc_device *net_device; 1027 struct netvsc_device *net_device;
978 struct rndis_device *rndis_device; 1028 struct rndis_device *rndis_device;
979 struct netvsc_device_info *device_info = additional_info; 1029 struct ndis_offload hwcaps;
980 struct ndis_offload_params offloads; 1030 struct ndis_offload_params offloads;
981 struct nvsp_message *init_packet; 1031 struct nvsp_message *init_packet;
982 struct ndis_recv_scale_cap rsscap; 1032 struct ndis_recv_scale_cap rsscap;
983 u32 rsscap_size = sizeof(struct ndis_recv_scale_cap); 1033 u32 rsscap_size = sizeof(struct ndis_recv_scale_cap);
1034 unsigned int gso_max_size = GSO_MAX_SIZE;
984 u32 mtu, size; 1035 u32 mtu, size;
985 u32 num_rss_qs; 1036 u32 num_rss_qs;
986 u32 sc_delta; 1037 u32 sc_delta;
987 const struct cpumask *node_cpu_mask; 1038 const struct cpumask *node_cpu_mask;
988 u32 num_possible_rss_qs; 1039 u32 num_possible_rss_qs;
989 unsigned long flags; 1040 unsigned long flags;
1041 int i, ret;
990 1042
991 rndis_device = get_rndis_device(); 1043 rndis_device = get_rndis_device();
992 if (!rndis_device) 1044 if (!rndis_device)
@@ -997,7 +1049,7 @@ int rndis_filter_device_add(struct hv_device *dev,
997 * NOTE! Once the channel is created, we may get a receive callback 1049 * NOTE! Once the channel is created, we may get a receive callback
998 * (RndisFilterOnReceive()) before this call is completed 1050 * (RndisFilterOnReceive()) before this call is completed
999 */ 1051 */
1000 ret = netvsc_device_add(dev, additional_info); 1052 ret = netvsc_device_add(dev, device_info);
1001 if (ret != 0) { 1053 if (ret != 0) {
1002 kfree(rndis_device); 1054 kfree(rndis_device);
1003 return ret; 1055 return ret;
@@ -1016,7 +1068,7 @@ int rndis_filter_device_add(struct hv_device *dev,
1016 /* Send the rndis initialization message */ 1068 /* Send the rndis initialization message */
1017 ret = rndis_filter_init_device(rndis_device); 1069 ret = rndis_filter_init_device(rndis_device);
1018 if (ret != 0) { 1070 if (ret != 0) {
1019 rndis_filter_device_remove(dev); 1071 rndis_filter_device_remove(dev, net_device);
1020 return ret; 1072 return ret;
1021 } 1073 }
1022 1074
@@ -1031,25 +1083,71 @@ int rndis_filter_device_add(struct hv_device *dev,
1031 /* Get the mac address */ 1083 /* Get the mac address */
1032 ret = rndis_filter_query_device_mac(rndis_device); 1084 ret = rndis_filter_query_device_mac(rndis_device);
1033 if (ret != 0) { 1085 if (ret != 0) {
1034 rndis_filter_device_remove(dev); 1086 rndis_filter_device_remove(dev, net_device);
1035 return ret; 1087 return ret;
1036 } 1088 }
1037 1089
1038 memcpy(device_info->mac_adr, rndis_device->hw_mac_adr, ETH_ALEN); 1090 memcpy(device_info->mac_adr, rndis_device->hw_mac_adr, ETH_ALEN);
1039 1091
1040 /* Turn on the offloads; the host supports all of the relevant 1092 /* Find HW offload capabilities */
1041 * offloads. 1093 ret = rndis_query_hwcaps(rndis_device, &hwcaps);
1042 */ 1094 if (ret != 0) {
1095 rndis_filter_device_remove(dev, net_device);
1096 return ret;
1097 }
1098
1099 /* A value of zero means "no change"; now turn on what we want. */
1043 memset(&offloads, 0, sizeof(struct ndis_offload_params)); 1100 memset(&offloads, 0, sizeof(struct ndis_offload_params));
1044 /* A value of zero means "no change"; now turn on what we 1101
1045 * want. 1102 /* Linux does not care about IP checksum, always does in kernel */
1046 */ 1103 offloads.ip_v4_csum = NDIS_OFFLOAD_PARAMETERS_TX_RX_DISABLED;
1047 offloads.ip_v4_csum = NDIS_OFFLOAD_PARAMETERS_TX_RX_ENABLED; 1104
1048 offloads.tcp_ip_v4_csum = NDIS_OFFLOAD_PARAMETERS_TX_RX_ENABLED; 1105 /* Compute tx offload settings based on hw capabilities */
1049 offloads.udp_ip_v4_csum = NDIS_OFFLOAD_PARAMETERS_TX_RX_ENABLED; 1106 net->hw_features = NETIF_F_RXCSUM;
1050 offloads.tcp_ip_v6_csum = NDIS_OFFLOAD_PARAMETERS_TX_RX_ENABLED; 1107
1051 offloads.udp_ip_v6_csum = NDIS_OFFLOAD_PARAMETERS_TX_RX_ENABLED; 1108 if ((hwcaps.csum.ip4_txcsum & NDIS_TXCSUM_ALL_TCP4) == NDIS_TXCSUM_ALL_TCP4) {
1052 offloads.lso_v2_ipv4 = NDIS_OFFLOAD_PARAMETERS_LSOV2_ENABLED; 1109 /* Can checksum TCP */
1110 net->hw_features |= NETIF_F_IP_CSUM;
1111 net_device_ctx->tx_checksum_mask |= TRANSPORT_INFO_IPV4_TCP;
1112
1113 offloads.tcp_ip_v4_csum = NDIS_OFFLOAD_PARAMETERS_TX_RX_ENABLED;
1114
1115 if (hwcaps.lsov2.ip4_encap & NDIS_OFFLOAD_ENCAP_8023) {
1116 offloads.lso_v2_ipv4 = NDIS_OFFLOAD_PARAMETERS_LSOV2_ENABLED;
1117 net->hw_features |= NETIF_F_TSO;
1118
1119 if (hwcaps.lsov2.ip4_maxsz < gso_max_size)
1120 gso_max_size = hwcaps.lsov2.ip4_maxsz;
1121 }
1122
1123 if (hwcaps.csum.ip4_txcsum & NDIS_TXCSUM_CAP_UDP4) {
1124 offloads.udp_ip_v4_csum = NDIS_OFFLOAD_PARAMETERS_TX_RX_ENABLED;
1125 net_device_ctx->tx_checksum_mask |= TRANSPORT_INFO_IPV4_UDP;
1126 }
1127 }
1128
1129 if ((hwcaps.csum.ip6_txcsum & NDIS_TXCSUM_ALL_TCP6) == NDIS_TXCSUM_ALL_TCP6) {
1130 net->hw_features |= NETIF_F_IPV6_CSUM;
1131
1132 offloads.tcp_ip_v6_csum = NDIS_OFFLOAD_PARAMETERS_TX_RX_ENABLED;
1133 net_device_ctx->tx_checksum_mask |= TRANSPORT_INFO_IPV6_TCP;
1134
1135 if ((hwcaps.lsov2.ip6_encap & NDIS_OFFLOAD_ENCAP_8023) &&
1136 (hwcaps.lsov2.ip6_opts & NDIS_LSOV2_CAP_IP6) == NDIS_LSOV2_CAP_IP6) {
1137 offloads.lso_v2_ipv6 = NDIS_OFFLOAD_PARAMETERS_LSOV2_ENABLED;
1138 net->hw_features |= NETIF_F_TSO6;
1139
1140 if (hwcaps.lsov2.ip6_maxsz < gso_max_size)
1141 gso_max_size = hwcaps.lsov2.ip6_maxsz;
1142 }
1143
1144 if (hwcaps.csum.ip6_txcsum & NDIS_TXCSUM_CAP_UDP6) {
1145 offloads.udp_ip_v6_csum = NDIS_OFFLOAD_PARAMETERS_TX_RX_ENABLED;
1146 net_device_ctx->tx_checksum_mask |= TRANSPORT_INFO_IPV6_UDP;
1147 }
1148 }
1149
1150 netif_set_gso_max_size(net, gso_max_size);
1053 1151
1054 ret = rndis_filter_set_offload_params(net, &offloads); 1152 ret = rndis_filter_set_offload_params(net, &offloads);
1055 if (ret) 1153 if (ret)
@@ -1094,19 +1192,16 @@ int rndis_filter_device_add(struct hv_device *dev,
1094 net_device->num_chn = min(num_possible_rss_qs, num_rss_qs); 1192 net_device->num_chn = min(num_possible_rss_qs, num_rss_qs);
1095 1193
1096 num_rss_qs = net_device->num_chn - 1; 1194 num_rss_qs = net_device->num_chn - 1;
1195
1196 for (i = 0; i < ITAB_NUM; i++)
1197 rndis_device->ind_table[i] = ethtool_rxfh_indir_default(i,
1198 net_device->num_chn);
1199
1097 net_device->num_sc_offered = num_rss_qs; 1200 net_device->num_sc_offered = num_rss_qs;
1098 1201
1099 if (net_device->num_chn == 1) 1202 if (net_device->num_chn == 1)
1100 goto out; 1203 goto out;
1101 1204
1102 net_device->sub_cb_buf = vzalloc((net_device->num_chn - 1) *
1103 NETVSC_PACKET_SIZE);
1104 if (!net_device->sub_cb_buf) {
1105 net_device->num_chn = 1;
1106 dev_info(&dev->device, "No memory for subchannels.\n");
1107 goto out;
1108 }
1109
1110 vmbus_set_sc_create_callback(dev->channel, netvsc_sc_open); 1205 vmbus_set_sc_create_callback(dev->channel, netvsc_sc_open);
1111 1206
1112 init_packet = &net_device->channel_init_pkt; 1207 init_packet = &net_device->channel_init_pkt;
@@ -1132,7 +1227,8 @@ int rndis_filter_device_add(struct hv_device *dev,
1132 net_device->num_chn = 1 + 1227 net_device->num_chn = 1 +
1133 init_packet->msg.v5_msg.subchn_comp.num_subchannels; 1228 init_packet->msg.v5_msg.subchn_comp.num_subchannels;
1134 1229
1135 ret = rndis_filter_set_rss_param(rndis_device, net_device->num_chn); 1230 ret = rndis_filter_set_rss_param(rndis_device, netvsc_hash_key,
1231 net_device->num_chn);
1136 1232
1137 /* 1233 /*
1138 * Set the number of sub-channels to be received. 1234 * Set the number of sub-channels to be received.
@@ -1152,13 +1248,13 @@ out:
1152 return 0; /* return 0 because primary channel can be used alone */ 1248 return 0; /* return 0 because primary channel can be used alone */
1153 1249
1154err_dev_remv: 1250err_dev_remv:
1155 rndis_filter_device_remove(dev); 1251 rndis_filter_device_remove(dev, net_device);
1156 return ret; 1252 return ret;
1157} 1253}
1158 1254
1159void rndis_filter_device_remove(struct hv_device *dev) 1255void rndis_filter_device_remove(struct hv_device *dev,
1256 struct netvsc_device *net_dev)
1160{ 1257{
1161 struct netvsc_device *net_dev = hv_device_to_netvsc_device(dev);
1162 struct rndis_device *rndis_dev = net_dev->extension; 1258 struct rndis_device *rndis_dev = net_dev->extension;
1163 1259
1164 /* If not all subchannel offers are complete, wait for them until 1260 /* If not all subchannel offers are complete, wait for them until