Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 1 | /* |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 2 | * Copyright (c) 2009, Microsoft Corporation. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms and conditions of the GNU General Public License, |
| 6 | * version 2, as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 11 | * more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License along with |
Jeff Kirsher | adf8d3f | 2013-12-06 06:28:47 -0800 | [diff] [blame] | 14 | * this program; if not, see <http://www.gnu.org/licenses/>. |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 15 | * |
| 16 | * Authors: |
Haiyang Zhang | d0e94d1 | 2009-11-23 17:00:22 +0000 | [diff] [blame] | 17 | * Haiyang Zhang <haiyangz@microsoft.com> |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 18 | * Hank Janssen <hjanssen@microsoft.com> |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 19 | */ |
Hank Janssen | eb335bc | 2011-03-29 13:58:48 -0700 | [diff] [blame] | 20 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 21 | |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 22 | #include <linux/init.h> |
K. Y. Srinivasan | 9079ce6 | 2011-06-16 13:16:37 -0700 | [diff] [blame] | 23 | #include <linux/atomic.h> |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 24 | #include <linux/module.h> |
| 25 | #include <linux/highmem.h> |
| 26 | #include <linux/device.h> |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 27 | #include <linux/io.h> |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 28 | #include <linux/delay.h> |
| 29 | #include <linux/netdevice.h> |
| 30 | #include <linux/inetdevice.h> |
| 31 | #include <linux/etherdevice.h> |
| 32 | #include <linux/skbuff.h> |
Haiyang Zhang | c802db11 | 2013-05-28 06:15:56 +0000 | [diff] [blame] | 33 | #include <linux/if_vlan.h> |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 34 | #include <linux/in.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 35 | #include <linux/slab.h> |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 36 | #include <net/arp.h> |
| 37 | #include <net/route.h> |
| 38 | #include <net/sock.h> |
| 39 | #include <net/pkt_sched.h> |
K. Y. Srinivasan | 3f335ea | 2011-05-12 19:34:15 -0700 | [diff] [blame] | 40 | |
K. Y. Srinivasan | 5ca7252 | 2011-05-12 19:34:37 -0700 | [diff] [blame] | 41 | #include "hyperv_net.h" |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 42 | |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 43 | |
Haiyang Zhang | fa85a6c | 2012-07-25 08:08:41 +0000 | [diff] [blame] | 44 | #define RING_SIZE_MIN 64 |
Hank Janssen | 99c8da0 | 2010-10-12 10:45:23 -0700 | [diff] [blame] | 45 | static int ring_size = 128; |
Stephen Hemminger | 450d7a4 | 2010-05-04 09:58:53 -0700 | [diff] [blame] | 46 | module_param(ring_size, int, S_IRUGO); |
| 47 | MODULE_PARM_DESC(ring_size, "Ring buffer size (# of pages)"); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 48 | |
KY Srinivasan | e01ec21 | 2015-05-27 13:16:57 -0700 | [diff] [blame] | 49 | static int max_num_vrss_chns = 8; |
| 50 | |
Simon Xiao | 3f300ff | 2015-04-28 01:05:17 -0700 | [diff] [blame] | 51 | static const u32 default_msg = NETIF_MSG_DRV | NETIF_MSG_PROBE | |
| 52 | NETIF_MSG_LINK | NETIF_MSG_IFUP | |
| 53 | NETIF_MSG_IFDOWN | NETIF_MSG_RX_ERR | |
| 54 | NETIF_MSG_TX_ERR; |
| 55 | |
| 56 | static int debug = -1; |
| 57 | module_param(debug, int, S_IRUGO); |
| 58 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); |
| 59 | |
Haiyang Zhang | d426b2e | 2011-11-30 07:19:08 -0800 | [diff] [blame] | 60 | static void do_set_multicast(struct work_struct *w) |
| 61 | { |
Wenqi Ma | 792df87 | 2012-04-19 00:39:37 +0000 | [diff] [blame] | 62 | struct net_device_context *ndevctx = |
| 63 | container_of(w, struct net_device_context, work); |
Haiyang Zhang | d426b2e | 2011-11-30 07:19:08 -0800 | [diff] [blame] | 64 | struct netvsc_device *nvdev; |
| 65 | struct rndis_device *rdev; |
| 66 | |
| 67 | nvdev = hv_get_drvdata(ndevctx->device_ctx); |
Wenqi Ma | 792df87 | 2012-04-19 00:39:37 +0000 | [diff] [blame] | 68 | if (nvdev == NULL || nvdev->ndev == NULL) |
| 69 | return; |
Haiyang Zhang | d426b2e | 2011-11-30 07:19:08 -0800 | [diff] [blame] | 70 | |
| 71 | rdev = nvdev->extension; |
| 72 | if (rdev == NULL) |
Wenqi Ma | 792df87 | 2012-04-19 00:39:37 +0000 | [diff] [blame] | 73 | return; |
Haiyang Zhang | d426b2e | 2011-11-30 07:19:08 -0800 | [diff] [blame] | 74 | |
Wenqi Ma | 792df87 | 2012-04-19 00:39:37 +0000 | [diff] [blame] | 75 | if (nvdev->ndev->flags & IFF_PROMISC) |
Haiyang Zhang | d426b2e | 2011-11-30 07:19:08 -0800 | [diff] [blame] | 76 | rndis_filter_set_packet_filter(rdev, |
| 77 | NDIS_PACKET_TYPE_PROMISCUOUS); |
| 78 | else |
| 79 | rndis_filter_set_packet_filter(rdev, |
| 80 | NDIS_PACKET_TYPE_BROADCAST | |
| 81 | NDIS_PACKET_TYPE_ALL_MULTICAST | |
| 82 | NDIS_PACKET_TYPE_DIRECTED); |
Haiyang Zhang | d426b2e | 2011-11-30 07:19:08 -0800 | [diff] [blame] | 83 | } |
| 84 | |
Greg Kroah-Hartman | 4e9bfef | 2009-07-15 12:45:20 -0700 | [diff] [blame] | 85 | static void netvsc_set_multicast_list(struct net_device *net) |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 86 | { |
Wenqi Ma | 792df87 | 2012-04-19 00:39:37 +0000 | [diff] [blame] | 87 | struct net_device_context *net_device_ctx = netdev_priv(net); |
Haiyang Zhang | d426b2e | 2011-11-30 07:19:08 -0800 | [diff] [blame] | 88 | |
Wenqi Ma | 792df87 | 2012-04-19 00:39:37 +0000 | [diff] [blame] | 89 | schedule_work(&net_device_ctx->work); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 92 | static int netvsc_open(struct net_device *net) |
| 93 | { |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 94 | struct net_device_context *net_device_ctx = netdev_priv(net); |
K. Y. Srinivasan | 6bad88da | 2011-03-07 13:35:48 -0800 | [diff] [blame] | 95 | struct hv_device *device_obj = net_device_ctx->device_ctx; |
Haiyang Zhang | 891de74 | 2014-02-12 16:54:27 -0800 | [diff] [blame] | 96 | struct netvsc_device *nvdev; |
| 97 | struct rndis_device *rdev; |
Greg Kroah-Hartman | 02fafbc | 2009-08-31 21:09:45 -0700 | [diff] [blame] | 98 | int ret = 0; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 99 | |
Haiyang Zhang | 891de74 | 2014-02-12 16:54:27 -0800 | [diff] [blame] | 100 | netif_carrier_off(net); |
| 101 | |
Haiyang Zhang | d515d0f | 2011-09-28 13:24:15 -0700 | [diff] [blame] | 102 | /* Open up the device */ |
| 103 | ret = rndis_filter_open(device_obj); |
| 104 | if (ret != 0) { |
| 105 | netdev_err(net, "unable to open device (ret %d).\n", ret); |
| 106 | return ret; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Haiyang Zhang | 2de8530 | 2015-07-13 13:09:16 -0700 | [diff] [blame] | 109 | netif_tx_wake_all_queues(net); |
Haiyang Zhang | d515d0f | 2011-09-28 13:24:15 -0700 | [diff] [blame] | 110 | |
Haiyang Zhang | 891de74 | 2014-02-12 16:54:27 -0800 | [diff] [blame] | 111 | nvdev = hv_get_drvdata(device_obj); |
| 112 | rdev = nvdev->extension; |
| 113 | if (!rdev->link_state) |
| 114 | netif_carrier_on(net); |
| 115 | |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 116 | return ret; |
| 117 | } |
| 118 | |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 119 | static int netvsc_close(struct net_device *net) |
| 120 | { |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 121 | struct net_device_context *net_device_ctx = netdev_priv(net); |
K. Y. Srinivasan | 6bad88da | 2011-03-07 13:35:48 -0800 | [diff] [blame] | 122 | struct hv_device *device_obj = net_device_ctx->device_ctx; |
Haiyang Zhang | 2de8530 | 2015-07-13 13:09:16 -0700 | [diff] [blame] | 123 | struct netvsc_device *nvdev = hv_get_drvdata(device_obj); |
Greg Kroah-Hartman | 02fafbc | 2009-08-31 21:09:45 -0700 | [diff] [blame] | 124 | int ret; |
Haiyang Zhang | 2de8530 | 2015-07-13 13:09:16 -0700 | [diff] [blame] | 125 | u32 aread, awrite, i, msec = 10, retry = 0, retry_max = 20; |
| 126 | struct vmbus_channel *chn; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 127 | |
Haiyang Zhang | 0a28253 | 2012-02-02 07:17:59 +0000 | [diff] [blame] | 128 | netif_tx_disable(net); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 129 | |
Wenqi Ma | 792df87 | 2012-04-19 00:39:37 +0000 | [diff] [blame] | 130 | /* Make sure netvsc_set_multicast_list doesn't re-enable filter! */ |
| 131 | cancel_work_sync(&net_device_ctx->work); |
Haiyang Zhang | 9c26aa0 | 2010-12-10 12:03:57 -0800 | [diff] [blame] | 132 | ret = rndis_filter_close(device_obj); |
Haiyang Zhang | 2de8530 | 2015-07-13 13:09:16 -0700 | [diff] [blame] | 133 | if (ret != 0) { |
Hank Janssen | eb335bc | 2011-03-29 13:58:48 -0700 | [diff] [blame] | 134 | netdev_err(net, "unable to close device (ret %d).\n", ret); |
Haiyang Zhang | 2de8530 | 2015-07-13 13:09:16 -0700 | [diff] [blame] | 135 | return ret; |
| 136 | } |
| 137 | |
| 138 | /* Ensure pending bytes in ring are read */ |
| 139 | while (true) { |
| 140 | aread = 0; |
| 141 | for (i = 0; i < nvdev->num_chn; i++) { |
| 142 | chn = nvdev->chn_table[i]; |
| 143 | if (!chn) |
| 144 | continue; |
| 145 | |
| 146 | hv_get_ringbuffer_availbytes(&chn->inbound, &aread, |
| 147 | &awrite); |
| 148 | |
| 149 | if (aread) |
| 150 | break; |
| 151 | |
| 152 | hv_get_ringbuffer_availbytes(&chn->outbound, &aread, |
| 153 | &awrite); |
| 154 | |
| 155 | if (aread) |
| 156 | break; |
| 157 | } |
| 158 | |
| 159 | retry++; |
| 160 | if (retry > retry_max || aread == 0) |
| 161 | break; |
| 162 | |
| 163 | msleep(msec); |
| 164 | |
| 165 | if (msec < 1000) |
| 166 | msec *= 2; |
| 167 | } |
| 168 | |
| 169 | if (aread) { |
| 170 | netdev_err(net, "Ring buffer not empty after closing rndis\n"); |
| 171 | ret = -ETIMEDOUT; |
| 172 | } |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 173 | |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 174 | return ret; |
| 175 | } |
| 176 | |
KY Srinivasan | 8a00251 | 2014-03-08 19:23:14 -0800 | [diff] [blame] | 177 | static void *init_ppi_data(struct rndis_message *msg, u32 ppi_size, |
| 178 | int pkt_type) |
| 179 | { |
| 180 | struct rndis_packet *rndis_pkt; |
| 181 | struct rndis_per_packet_info *ppi; |
| 182 | |
| 183 | rndis_pkt = &msg->msg.pkt; |
| 184 | rndis_pkt->data_offset += ppi_size; |
| 185 | |
| 186 | ppi = (struct rndis_per_packet_info *)((void *)rndis_pkt + |
| 187 | rndis_pkt->per_pkt_info_offset + rndis_pkt->per_pkt_info_len); |
| 188 | |
| 189 | ppi->size = ppi_size; |
| 190 | ppi->type = pkt_type; |
| 191 | ppi->ppi_offset = sizeof(struct rndis_per_packet_info); |
| 192 | |
| 193 | rndis_pkt->per_pkt_info_len += ppi_size; |
| 194 | |
| 195 | return ppi; |
| 196 | } |
| 197 | |
Haiyang Zhang | 5b54dac | 2014-04-21 10:20:28 -0700 | [diff] [blame] | 198 | union sub_key { |
| 199 | u64 k; |
| 200 | struct { |
| 201 | u8 pad[3]; |
| 202 | u8 kb; |
| 203 | u32 ka; |
| 204 | }; |
| 205 | }; |
| 206 | |
| 207 | /* Toeplitz hash function |
| 208 | * data: network byte order |
| 209 | * return: host byte order |
| 210 | */ |
Haiyang Zhang | f88e671 | 2014-10-16 14:47:58 -0700 | [diff] [blame] | 211 | static u32 comp_hash(u8 *key, int klen, void *data, int dlen) |
Haiyang Zhang | 5b54dac | 2014-04-21 10:20:28 -0700 | [diff] [blame] | 212 | { |
| 213 | union sub_key subk; |
| 214 | int k_next = 4; |
| 215 | u8 dt; |
| 216 | int i, j; |
| 217 | u32 ret = 0; |
| 218 | |
| 219 | subk.k = 0; |
| 220 | subk.ka = ntohl(*(u32 *)key); |
| 221 | |
| 222 | for (i = 0; i < dlen; i++) { |
| 223 | subk.kb = key[k_next]; |
| 224 | k_next = (k_next + 1) % klen; |
Haiyang Zhang | f88e671 | 2014-10-16 14:47:58 -0700 | [diff] [blame] | 225 | dt = ((u8 *)data)[i]; |
Haiyang Zhang | 5b54dac | 2014-04-21 10:20:28 -0700 | [diff] [blame] | 226 | for (j = 0; j < 8; j++) { |
| 227 | if (dt & 0x80) |
| 228 | ret ^= subk.ka; |
| 229 | dt <<= 1; |
| 230 | subk.k <<= 1; |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | return ret; |
| 235 | } |
| 236 | |
| 237 | static bool netvsc_set_hash(u32 *hash, struct sk_buff *skb) |
| 238 | { |
Haiyang Zhang | f88e671 | 2014-10-16 14:47:58 -0700 | [diff] [blame] | 239 | struct flow_keys flow; |
Haiyang Zhang | 5b54dac | 2014-04-21 10:20:28 -0700 | [diff] [blame] | 240 | int data_len; |
Haiyang Zhang | 5b54dac | 2014-04-21 10:20:28 -0700 | [diff] [blame] | 241 | |
Tom Herbert | cd79a23 | 2015-09-01 09:24:27 -0700 | [diff] [blame] | 242 | if (!skb_flow_dissect_flow_keys(skb, &flow, 0) || |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 243 | !(flow.basic.n_proto == htons(ETH_P_IP) || |
| 244 | flow.basic.n_proto == htons(ETH_P_IPV6))) |
Haiyang Zhang | 5b54dac | 2014-04-21 10:20:28 -0700 | [diff] [blame] | 245 | return false; |
| 246 | |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 247 | if (flow.basic.ip_proto == IPPROTO_TCP) |
Haiyang Zhang | f88e671 | 2014-10-16 14:47:58 -0700 | [diff] [blame] | 248 | data_len = 12; |
| 249 | else |
| 250 | data_len = 8; |
Haiyang Zhang | 5b54dac | 2014-04-21 10:20:28 -0700 | [diff] [blame] | 251 | |
Haiyang Zhang | f88e671 | 2014-10-16 14:47:58 -0700 | [diff] [blame] | 252 | *hash = comp_hash(netvsc_hash_key, HASH_KEYLEN, &flow, data_len); |
Haiyang Zhang | 5b54dac | 2014-04-21 10:20:28 -0700 | [diff] [blame] | 253 | |
Haiyang Zhang | f88e671 | 2014-10-16 14:47:58 -0700 | [diff] [blame] | 254 | return true; |
Haiyang Zhang | 5b54dac | 2014-04-21 10:20:28 -0700 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | static u16 netvsc_select_queue(struct net_device *ndev, struct sk_buff *skb, |
| 258 | void *accel_priv, select_queue_fallback_t fallback) |
| 259 | { |
| 260 | struct net_device_context *net_device_ctx = netdev_priv(ndev); |
| 261 | struct hv_device *hdev = net_device_ctx->device_ctx; |
| 262 | struct netvsc_device *nvsc_dev = hv_get_drvdata(hdev); |
| 263 | u32 hash; |
| 264 | u16 q_idx = 0; |
| 265 | |
| 266 | if (nvsc_dev == NULL || ndev->real_num_tx_queues <= 1) |
| 267 | return 0; |
| 268 | |
Haiyang Zhang | 307f099 | 2014-05-21 12:55:39 -0700 | [diff] [blame] | 269 | if (netvsc_set_hash(&hash, skb)) { |
Haiyang Zhang | 5b54dac | 2014-04-21 10:20:28 -0700 | [diff] [blame] | 270 | q_idx = nvsc_dev->send_table[hash % VRSS_SEND_TAB_SIZE] % |
| 271 | ndev->real_num_tx_queues; |
Haiyang Zhang | 307f099 | 2014-05-21 12:55:39 -0700 | [diff] [blame] | 272 | skb_set_hash(skb, hash, PKT_HASH_TYPE_L3); |
| 273 | } |
Haiyang Zhang | 5b54dac | 2014-04-21 10:20:28 -0700 | [diff] [blame] | 274 | |
| 275 | return q_idx; |
| 276 | } |
| 277 | |
Haiyang Zhang | ee90b81 | 2015-04-06 15:22:54 -0700 | [diff] [blame] | 278 | void netvsc_xmit_completion(void *context) |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 279 | { |
Nicolas Palix | 4193d4f | 2009-07-29 14:10:10 +0200 | [diff] [blame] | 280 | struct hv_netvsc_packet *packet = (struct hv_netvsc_packet *)context; |
Greg Kroah-Hartman | 02fafbc | 2009-08-31 21:09:45 -0700 | [diff] [blame] | 281 | struct sk_buff *skb = (struct sk_buff *) |
Haiyang Zhang | 893f662 | 2014-04-21 14:54:44 -0700 | [diff] [blame] | 282 | (unsigned long)packet->send_completion_tid; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 283 | |
KY Srinivasan | cbacec7 | 2015-03-29 21:08:41 -0700 | [diff] [blame] | 284 | if (skb) |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 285 | dev_kfree_skb_any(skb); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 286 | } |
| 287 | |
KY Srinivasan | 54a7357 | 2014-03-08 19:23:13 -0800 | [diff] [blame] | 288 | static u32 fill_pg_buf(struct page *page, u32 offset, u32 len, |
| 289 | struct hv_page_buffer *pb) |
| 290 | { |
| 291 | int j = 0; |
| 292 | |
| 293 | /* Deal with compund pages by ignoring unused part |
| 294 | * of the page. |
| 295 | */ |
| 296 | page += (offset >> PAGE_SHIFT); |
| 297 | offset &= ~PAGE_MASK; |
| 298 | |
| 299 | while (len > 0) { |
| 300 | unsigned long bytes; |
| 301 | |
| 302 | bytes = PAGE_SIZE - offset; |
| 303 | if (bytes > len) |
| 304 | bytes = len; |
| 305 | pb[j].pfn = page_to_pfn(page); |
| 306 | pb[j].offset = offset; |
| 307 | pb[j].len = bytes; |
| 308 | |
| 309 | offset += bytes; |
| 310 | len -= bytes; |
| 311 | |
| 312 | if (offset == PAGE_SIZE && len) { |
| 313 | page++; |
| 314 | offset = 0; |
| 315 | j++; |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | return j + 1; |
| 320 | } |
| 321 | |
KY Srinivasan | 8a00251 | 2014-03-08 19:23:14 -0800 | [diff] [blame] | 322 | static u32 init_page_array(void *hdr, u32 len, struct sk_buff *skb, |
Haiyang Zhang | aa0a34b | 2015-04-13 16:34:35 -0700 | [diff] [blame] | 323 | struct hv_netvsc_packet *packet) |
KY Srinivasan | 54a7357 | 2014-03-08 19:23:13 -0800 | [diff] [blame] | 324 | { |
Haiyang Zhang | aa0a34b | 2015-04-13 16:34:35 -0700 | [diff] [blame] | 325 | struct hv_page_buffer *pb = packet->page_buf; |
KY Srinivasan | 54a7357 | 2014-03-08 19:23:13 -0800 | [diff] [blame] | 326 | u32 slots_used = 0; |
| 327 | char *data = skb->data; |
| 328 | int frags = skb_shinfo(skb)->nr_frags; |
| 329 | int i; |
| 330 | |
| 331 | /* The packet is laid out thus: |
Haiyang Zhang | aa0a34b | 2015-04-13 16:34:35 -0700 | [diff] [blame] | 332 | * 1. hdr: RNDIS header and PPI |
KY Srinivasan | 54a7357 | 2014-03-08 19:23:13 -0800 | [diff] [blame] | 333 | * 2. skb linear data |
| 334 | * 3. skb fragment data |
| 335 | */ |
| 336 | if (hdr != NULL) |
| 337 | slots_used += fill_pg_buf(virt_to_page(hdr), |
| 338 | offset_in_page(hdr), |
| 339 | len, &pb[slots_used]); |
| 340 | |
Haiyang Zhang | aa0a34b | 2015-04-13 16:34:35 -0700 | [diff] [blame] | 341 | packet->rmsg_size = len; |
| 342 | packet->rmsg_pgcnt = slots_used; |
| 343 | |
KY Srinivasan | 54a7357 | 2014-03-08 19:23:13 -0800 | [diff] [blame] | 344 | slots_used += fill_pg_buf(virt_to_page(data), |
| 345 | offset_in_page(data), |
| 346 | skb_headlen(skb), &pb[slots_used]); |
| 347 | |
| 348 | for (i = 0; i < frags; i++) { |
| 349 | skb_frag_t *frag = skb_shinfo(skb)->frags + i; |
| 350 | |
| 351 | slots_used += fill_pg_buf(skb_frag_page(frag), |
| 352 | frag->page_offset, |
| 353 | skb_frag_size(frag), &pb[slots_used]); |
| 354 | } |
KY Srinivasan | 8a00251 | 2014-03-08 19:23:14 -0800 | [diff] [blame] | 355 | return slots_used; |
KY Srinivasan | 54a7357 | 2014-03-08 19:23:13 -0800 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | static int count_skb_frag_slots(struct sk_buff *skb) |
| 359 | { |
| 360 | int i, frags = skb_shinfo(skb)->nr_frags; |
| 361 | int pages = 0; |
| 362 | |
| 363 | for (i = 0; i < frags; i++) { |
| 364 | skb_frag_t *frag = skb_shinfo(skb)->frags + i; |
| 365 | unsigned long size = skb_frag_size(frag); |
| 366 | unsigned long offset = frag->page_offset; |
| 367 | |
| 368 | /* Skip unused frames from start of page */ |
| 369 | offset &= ~PAGE_MASK; |
| 370 | pages += PFN_UP(offset + size); |
| 371 | } |
| 372 | return pages; |
| 373 | } |
| 374 | |
| 375 | static int netvsc_get_slots(struct sk_buff *skb) |
| 376 | { |
| 377 | char *data = skb->data; |
| 378 | unsigned int offset = offset_in_page(data); |
| 379 | unsigned int len = skb_headlen(skb); |
| 380 | int slots; |
| 381 | int frag_slots; |
| 382 | |
| 383 | slots = DIV_ROUND_UP(offset + len, PAGE_SIZE); |
| 384 | frag_slots = count_skb_frag_slots(skb); |
| 385 | return slots + frag_slots; |
| 386 | } |
| 387 | |
KY Srinivasan | 08cd04b | 2014-03-08 19:23:17 -0800 | [diff] [blame] | 388 | static u32 get_net_transport_info(struct sk_buff *skb, u32 *trans_off) |
| 389 | { |
| 390 | u32 ret_val = TRANSPORT_INFO_NOT_IP; |
| 391 | |
| 392 | if ((eth_hdr(skb)->h_proto != htons(ETH_P_IP)) && |
| 393 | (eth_hdr(skb)->h_proto != htons(ETH_P_IPV6))) { |
| 394 | goto not_ip; |
| 395 | } |
| 396 | |
| 397 | *trans_off = skb_transport_offset(skb); |
| 398 | |
| 399 | if ((eth_hdr(skb)->h_proto == htons(ETH_P_IP))) { |
| 400 | struct iphdr *iphdr = ip_hdr(skb); |
| 401 | |
| 402 | if (iphdr->protocol == IPPROTO_TCP) |
| 403 | ret_val = TRANSPORT_INFO_IPV4_TCP; |
| 404 | else if (iphdr->protocol == IPPROTO_UDP) |
| 405 | ret_val = TRANSPORT_INFO_IPV4_UDP; |
| 406 | } else { |
| 407 | if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) |
| 408 | ret_val = TRANSPORT_INFO_IPV6_TCP; |
| 409 | else if (ipv6_hdr(skb)->nexthdr == IPPROTO_UDP) |
| 410 | ret_val = TRANSPORT_INFO_IPV6_UDP; |
| 411 | } |
| 412 | |
| 413 | not_ip: |
| 414 | return ret_val; |
| 415 | } |
| 416 | |
Greg Kroah-Hartman | 02fafbc | 2009-08-31 21:09:45 -0700 | [diff] [blame] | 417 | static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net) |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 418 | { |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 419 | struct net_device_context *net_device_ctx = netdev_priv(net); |
Vitaly Kuznetsov | 981a1bd | 2015-04-08 17:54:05 +0200 | [diff] [blame] | 420 | struct hv_netvsc_packet *packet = NULL; |
Greg Kroah-Hartman | 02fafbc | 2009-08-31 21:09:45 -0700 | [diff] [blame] | 421 | int ret; |
KY Srinivasan | 8a00251 | 2014-03-08 19:23:14 -0800 | [diff] [blame] | 422 | unsigned int num_data_pgs; |
| 423 | struct rndis_message *rndis_msg; |
| 424 | struct rndis_packet *rndis_pkt; |
| 425 | u32 rndis_msg_size; |
| 426 | bool isvlan; |
Vitaly Kuznetsov | e88f7e0 | 2015-04-08 17:54:06 +0200 | [diff] [blame] | 427 | bool linear = false; |
KY Srinivasan | 8a00251 | 2014-03-08 19:23:14 -0800 | [diff] [blame] | 428 | struct rndis_per_packet_info *ppi; |
KY Srinivasan | 08cd04b | 2014-03-08 19:23:17 -0800 | [diff] [blame] | 429 | struct ndis_tcp_ip_checksum_info *csum_info; |
KY Srinivasan | 77bf548 | 2014-03-08 19:23:18 -0800 | [diff] [blame] | 430 | struct ndis_tcp_lso_info *lso_info; |
KY Srinivasan | 08cd04b | 2014-03-08 19:23:17 -0800 | [diff] [blame] | 431 | int hdr_offset; |
| 432 | u32 net_trans_info; |
Haiyang Zhang | 307f099 | 2014-05-21 12:55:39 -0700 | [diff] [blame] | 433 | u32 hash; |
Vitaly Kuznetsov | e88f7e0 | 2015-04-08 17:54:06 +0200 | [diff] [blame] | 434 | u32 skb_length; |
KY Srinivasan | b08cc79 | 2015-03-29 21:08:42 -0700 | [diff] [blame] | 435 | u32 pkt_sz; |
| 436 | struct hv_page_buffer page_buf[MAX_PAGE_BUFFER_COUNT]; |
sixiao@microsoft.com | 7eafd9b | 2015-05-14 01:00:25 -0700 | [diff] [blame] | 437 | struct netvsc_stats *tx_stats = this_cpu_ptr(net_device_ctx->tx_stats); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 438 | |
KY Srinivasan | 54a7357 | 2014-03-08 19:23:13 -0800 | [diff] [blame] | 439 | /* We will atmost need two pages to describe the rndis |
| 440 | * header. We can only transmit MAX_PAGE_BUFFER_COUNT number |
Vitaly Kuznetsov | e88f7e0 | 2015-04-08 17:54:06 +0200 | [diff] [blame] | 441 | * of pages in a single packet. If skb is scattered around |
| 442 | * more pages we try linearizing it. |
KY Srinivasan | 54a7357 | 2014-03-08 19:23:13 -0800 | [diff] [blame] | 443 | */ |
Vitaly Kuznetsov | e88f7e0 | 2015-04-08 17:54:06 +0200 | [diff] [blame] | 444 | |
| 445 | check_size: |
| 446 | skb_length = skb->len; |
KY Srinivasan | 8a00251 | 2014-03-08 19:23:14 -0800 | [diff] [blame] | 447 | num_data_pgs = netvsc_get_slots(skb) + 2; |
Vitaly Kuznetsov | e88f7e0 | 2015-04-08 17:54:06 +0200 | [diff] [blame] | 448 | if (num_data_pgs > MAX_PAGE_BUFFER_COUNT && linear) { |
| 449 | net_alert_ratelimited("packet too big: %u pages (%u bytes)\n", |
| 450 | num_data_pgs, skb->len); |
Vitaly Kuznetsov | 981a1bd | 2015-04-08 17:54:05 +0200 | [diff] [blame] | 451 | ret = -EFAULT; |
| 452 | goto drop; |
Vitaly Kuznetsov | e88f7e0 | 2015-04-08 17:54:06 +0200 | [diff] [blame] | 453 | } else if (num_data_pgs > MAX_PAGE_BUFFER_COUNT) { |
| 454 | if (skb_linearize(skb)) { |
| 455 | net_alert_ratelimited("failed to linearize skb\n"); |
| 456 | ret = -ENOMEM; |
| 457 | goto drop; |
| 458 | } |
| 459 | linear = true; |
| 460 | goto check_size; |
KY Srinivasan | 54a7357 | 2014-03-08 19:23:13 -0800 | [diff] [blame] | 461 | } |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 462 | |
Haiyang Zhang | 7215142 | 2015-04-06 15:22:53 -0700 | [diff] [blame] | 463 | pkt_sz = sizeof(struct hv_netvsc_packet) + RNDIS_AND_PPI_SIZE; |
Stephen Hemminger | b220f5f | 2010-05-04 09:58:56 -0700 | [diff] [blame] | 464 | |
KY Srinivasan | b56fc3c | 2015-04-28 17:59:48 -0700 | [diff] [blame] | 465 | ret = skb_cow_head(skb, pkt_sz); |
| 466 | if (ret) { |
| 467 | netdev_err(net, "unable to alloc hv_netvsc_packet\n"); |
| 468 | ret = -ENOMEM; |
| 469 | goto drop; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 470 | } |
KY Srinivasan | b56fc3c | 2015-04-28 17:59:48 -0700 | [diff] [blame] | 471 | /* Use the headroom for building up the packet */ |
| 472 | packet = (struct hv_netvsc_packet *)skb->head; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 473 | |
KY Srinivasan | b08cc79 | 2015-03-29 21:08:42 -0700 | [diff] [blame] | 474 | packet->status = 0; |
Haiyang Zhang | 7c3877f | 2015-03-26 09:03:37 -0700 | [diff] [blame] | 475 | packet->xmit_more = skb->xmit_more; |
| 476 | |
Haiyang Zhang | 1f5f3a7 | 2012-03-12 10:20:50 +0000 | [diff] [blame] | 477 | packet->vlan_tci = skb->vlan_tci; |
KY Srinivasan | b08cc79 | 2015-03-29 21:08:42 -0700 | [diff] [blame] | 478 | packet->page_buf = page_buf; |
Haiyang Zhang | 1f5f3a7 | 2012-03-12 10:20:50 +0000 | [diff] [blame] | 479 | |
Haiyang Zhang | 5b54dac | 2014-04-21 10:20:28 -0700 | [diff] [blame] | 480 | packet->q_idx = skb_get_queue_mapping(skb); |
| 481 | |
KY Srinivasan | 8a00251 | 2014-03-08 19:23:14 -0800 | [diff] [blame] | 482 | packet->is_data_pkt = true; |
Haiyang Zhang | 4d447c9 | 2011-12-15 13:45:17 -0800 | [diff] [blame] | 483 | packet->total_data_buflen = skb->len; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 484 | |
KY Srinivasan | 8a00251 | 2014-03-08 19:23:14 -0800 | [diff] [blame] | 485 | packet->rndis_msg = (struct rndis_message *)((unsigned long)packet + |
KY Srinivasan | b08cc79 | 2015-03-29 21:08:42 -0700 | [diff] [blame] | 486 | sizeof(struct hv_netvsc_packet)); |
| 487 | |
Haiyang Zhang | 7215142 | 2015-04-06 15:22:53 -0700 | [diff] [blame] | 488 | memset(packet->rndis_msg, 0, RNDIS_AND_PPI_SIZE); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 489 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 490 | /* Set the completion routine */ |
Haiyang Zhang | 893f662 | 2014-04-21 14:54:44 -0700 | [diff] [blame] | 491 | packet->send_completion = netvsc_xmit_completion; |
| 492 | packet->send_completion_ctx = packet; |
| 493 | packet->send_completion_tid = (unsigned long)skb; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 494 | |
KY Srinivasan | 8a00251 | 2014-03-08 19:23:14 -0800 | [diff] [blame] | 495 | isvlan = packet->vlan_tci & VLAN_TAG_PRESENT; |
| 496 | |
| 497 | /* Add the rndis header */ |
| 498 | rndis_msg = packet->rndis_msg; |
| 499 | rndis_msg->ndis_msg_type = RNDIS_MSG_PACKET; |
| 500 | rndis_msg->msg_len = packet->total_data_buflen; |
| 501 | rndis_pkt = &rndis_msg->msg.pkt; |
| 502 | rndis_pkt->data_offset = sizeof(struct rndis_packet); |
| 503 | rndis_pkt->data_len = packet->total_data_buflen; |
| 504 | rndis_pkt->per_pkt_info_offset = sizeof(struct rndis_packet); |
| 505 | |
| 506 | rndis_msg_size = RNDIS_MESSAGE_SIZE(struct rndis_packet); |
| 507 | |
Haiyang Zhang | 307f099 | 2014-05-21 12:55:39 -0700 | [diff] [blame] | 508 | hash = skb_get_hash_raw(skb); |
| 509 | if (hash != 0 && net->real_num_tx_queues > 1) { |
| 510 | rndis_msg_size += NDIS_HASH_PPI_SIZE; |
| 511 | ppi = init_ppi_data(rndis_msg, NDIS_HASH_PPI_SIZE, |
| 512 | NBL_HASH_VALUE); |
| 513 | *(u32 *)((void *)ppi + ppi->ppi_offset) = hash; |
| 514 | } |
| 515 | |
KY Srinivasan | 8a00251 | 2014-03-08 19:23:14 -0800 | [diff] [blame] | 516 | if (isvlan) { |
| 517 | struct ndis_pkt_8021q_info *vlan; |
| 518 | |
| 519 | rndis_msg_size += NDIS_VLAN_PPI_SIZE; |
| 520 | ppi = init_ppi_data(rndis_msg, NDIS_VLAN_PPI_SIZE, |
| 521 | IEEE_8021Q_INFO); |
| 522 | vlan = (struct ndis_pkt_8021q_info *)((void *)ppi + |
| 523 | ppi->ppi_offset); |
| 524 | vlan->vlanid = packet->vlan_tci & VLAN_VID_MASK; |
| 525 | vlan->pri = (packet->vlan_tci & VLAN_PRIO_MASK) >> |
| 526 | VLAN_PRIO_SHIFT; |
| 527 | } |
| 528 | |
KY Srinivasan | 08cd04b | 2014-03-08 19:23:17 -0800 | [diff] [blame] | 529 | net_trans_info = get_net_transport_info(skb, &hdr_offset); |
| 530 | if (net_trans_info == TRANSPORT_INFO_NOT_IP) |
| 531 | goto do_send; |
| 532 | |
| 533 | /* |
| 534 | * Setup the sendside checksum offload only if this is not a |
| 535 | * GSO packet. |
| 536 | */ |
| 537 | if (skb_is_gso(skb)) |
KY Srinivasan | 77bf548 | 2014-03-08 19:23:18 -0800 | [diff] [blame] | 538 | goto do_lso; |
KY Srinivasan | 08cd04b | 2014-03-08 19:23:17 -0800 | [diff] [blame] | 539 | |
KY Srinivasan | 22041fb | 2014-04-30 11:58:25 -0700 | [diff] [blame] | 540 | if ((skb->ip_summed == CHECKSUM_NONE) || |
| 541 | (skb->ip_summed == CHECKSUM_UNNECESSARY)) |
| 542 | goto do_send; |
| 543 | |
KY Srinivasan | 08cd04b | 2014-03-08 19:23:17 -0800 | [diff] [blame] | 544 | rndis_msg_size += NDIS_CSUM_PPI_SIZE; |
| 545 | ppi = init_ppi_data(rndis_msg, NDIS_CSUM_PPI_SIZE, |
| 546 | TCPIP_CHKSUM_PKTINFO); |
| 547 | |
| 548 | csum_info = (struct ndis_tcp_ip_checksum_info *)((void *)ppi + |
| 549 | ppi->ppi_offset); |
| 550 | |
| 551 | if (net_trans_info & (INFO_IPV4 << 16)) |
| 552 | csum_info->transmit.is_ipv4 = 1; |
| 553 | else |
| 554 | csum_info->transmit.is_ipv6 = 1; |
| 555 | |
| 556 | if (net_trans_info & INFO_TCP) { |
| 557 | csum_info->transmit.tcp_checksum = 1; |
| 558 | csum_info->transmit.tcp_header_offset = hdr_offset; |
| 559 | } else if (net_trans_info & INFO_UDP) { |
KY Srinivasan | af9893a | 2014-04-09 15:00:47 -0700 | [diff] [blame] | 560 | /* UDP checksum offload is not supported on ws2008r2. |
| 561 | * Furthermore, on ws2012 and ws2012r2, there are some |
| 562 | * issues with udp checksum offload from Linux guests. |
| 563 | * (these are host issues). |
| 564 | * For now compute the checksum here. |
| 565 | */ |
| 566 | struct udphdr *uh; |
| 567 | u16 udp_len; |
| 568 | |
| 569 | ret = skb_cow_head(skb, 0); |
| 570 | if (ret) |
| 571 | goto drop; |
| 572 | |
| 573 | uh = udp_hdr(skb); |
| 574 | udp_len = ntohs(uh->len); |
| 575 | uh->check = 0; |
| 576 | uh->check = csum_tcpudp_magic(ip_hdr(skb)->saddr, |
| 577 | ip_hdr(skb)->daddr, |
| 578 | udp_len, IPPROTO_UDP, |
| 579 | csum_partial(uh, udp_len, 0)); |
| 580 | if (uh->check == 0) |
| 581 | uh->check = CSUM_MANGLED_0; |
| 582 | |
| 583 | csum_info->transmit.udp_checksum = 0; |
KY Srinivasan | 08cd04b | 2014-03-08 19:23:17 -0800 | [diff] [blame] | 584 | } |
KY Srinivasan | 77bf548 | 2014-03-08 19:23:18 -0800 | [diff] [blame] | 585 | goto do_send; |
| 586 | |
| 587 | do_lso: |
| 588 | rndis_msg_size += NDIS_LSO_PPI_SIZE; |
| 589 | ppi = init_ppi_data(rndis_msg, NDIS_LSO_PPI_SIZE, |
| 590 | TCP_LARGESEND_PKTINFO); |
| 591 | |
| 592 | lso_info = (struct ndis_tcp_lso_info *)((void *)ppi + |
| 593 | ppi->ppi_offset); |
| 594 | |
| 595 | lso_info->lso_v2_transmit.type = NDIS_TCP_LARGE_SEND_OFFLOAD_V2_TYPE; |
| 596 | if (net_trans_info & (INFO_IPV4 << 16)) { |
| 597 | lso_info->lso_v2_transmit.ip_version = |
| 598 | NDIS_TCP_LARGE_SEND_OFFLOAD_IPV4; |
| 599 | ip_hdr(skb)->tot_len = 0; |
| 600 | ip_hdr(skb)->check = 0; |
| 601 | tcp_hdr(skb)->check = |
| 602 | ~csum_tcpudp_magic(ip_hdr(skb)->saddr, |
| 603 | ip_hdr(skb)->daddr, 0, IPPROTO_TCP, 0); |
| 604 | } else { |
| 605 | lso_info->lso_v2_transmit.ip_version = |
| 606 | NDIS_TCP_LARGE_SEND_OFFLOAD_IPV6; |
| 607 | ipv6_hdr(skb)->payload_len = 0; |
| 608 | tcp_hdr(skb)->check = |
| 609 | ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
| 610 | &ipv6_hdr(skb)->daddr, 0, IPPROTO_TCP, 0); |
| 611 | } |
| 612 | lso_info->lso_v2_transmit.tcp_header_offset = hdr_offset; |
| 613 | lso_info->lso_v2_transmit.mss = skb_shinfo(skb)->gso_size; |
KY Srinivasan | 08cd04b | 2014-03-08 19:23:17 -0800 | [diff] [blame] | 614 | |
| 615 | do_send: |
KY Srinivasan | 8a00251 | 2014-03-08 19:23:14 -0800 | [diff] [blame] | 616 | /* Start filling in the page buffers with the rndis hdr */ |
| 617 | rndis_msg->msg_len += rndis_msg_size; |
Haiyang Zhang | 942396b | 2014-10-22 13:47:18 -0700 | [diff] [blame] | 618 | packet->total_data_buflen = rndis_msg->msg_len; |
KY Srinivasan | 8a00251 | 2014-03-08 19:23:14 -0800 | [diff] [blame] | 619 | packet->page_buf_cnt = init_page_array(rndis_msg, rndis_msg_size, |
Haiyang Zhang | aa0a34b | 2015-04-13 16:34:35 -0700 | [diff] [blame] | 620 | skb, packet); |
KY Srinivasan | 8a00251 | 2014-03-08 19:23:14 -0800 | [diff] [blame] | 621 | |
| 622 | ret = netvsc_send(net_device_ctx->device_ctx, packet); |
| 623 | |
KY Srinivasan | af9893a | 2014-04-09 15:00:47 -0700 | [diff] [blame] | 624 | drop: |
Greg Kroah-Hartman | 02fafbc | 2009-08-31 21:09:45 -0700 | [diff] [blame] | 625 | if (ret == 0) { |
sixiao@microsoft.com | 4b02b58 | 2015-05-15 02:33:03 -0700 | [diff] [blame] | 626 | u64_stats_update_begin(&tx_stats->syncp); |
sixiao@microsoft.com | 7eafd9b | 2015-05-14 01:00:25 -0700 | [diff] [blame] | 627 | tx_stats->packets++; |
| 628 | tx_stats->bytes += skb_length; |
sixiao@microsoft.com | 4b02b58 | 2015-05-15 02:33:03 -0700 | [diff] [blame] | 629 | u64_stats_update_end(&tx_stats->syncp); |
Greg Kroah-Hartman | 02fafbc | 2009-08-31 21:09:45 -0700 | [diff] [blame] | 630 | } else { |
Haiyang Zhang | 33be96e | 2012-03-27 13:20:45 +0000 | [diff] [blame] | 631 | if (ret != -EAGAIN) { |
| 632 | dev_kfree_skb_any(skb); |
| 633 | net->stats.tx_dropped++; |
| 634 | } |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 635 | } |
| 636 | |
Haiyang Zhang | 33be96e | 2012-03-27 13:20:45 +0000 | [diff] [blame] | 637 | return (ret == -EAGAIN) ? NETDEV_TX_BUSY : NETDEV_TX_OK; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 638 | } |
| 639 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 640 | /* |
Greg Kroah-Hartman | 02fafbc | 2009-08-31 21:09:45 -0700 | [diff] [blame] | 641 | * netvsc_linkstatus_callback - Link up/down notification |
| 642 | */ |
K. Y. Srinivasan | 90ef117 | 2011-05-12 19:34:50 -0700 | [diff] [blame] | 643 | void netvsc_linkstatus_callback(struct hv_device *device_obj, |
Haiyang Zhang | 3a494e7 | 2014-06-19 18:34:36 -0700 | [diff] [blame] | 644 | struct rndis_message *resp) |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 645 | { |
Haiyang Zhang | 3a494e7 | 2014-06-19 18:34:36 -0700 | [diff] [blame] | 646 | struct rndis_indicate_status *indicate = &resp->msg.indicate_status; |
K. Y. Srinivasan | 2ddd5e5f | 2011-09-13 10:59:49 -0700 | [diff] [blame] | 647 | struct net_device *net; |
Haiyang Zhang | c996edc | 2011-04-06 15:18:00 -0700 | [diff] [blame] | 648 | struct net_device_context *ndev_ctx; |
K. Y. Srinivasan | 2ddd5e5f | 2011-09-13 10:59:49 -0700 | [diff] [blame] | 649 | struct netvsc_device *net_device; |
Haiyang Zhang | 891de74 | 2014-02-12 16:54:27 -0800 | [diff] [blame] | 650 | struct rndis_device *rdev; |
K. Y. Srinivasan | 2ddd5e5f | 2011-09-13 10:59:49 -0700 | [diff] [blame] | 651 | |
| 652 | net_device = hv_get_drvdata(device_obj); |
Haiyang Zhang | 891de74 | 2014-02-12 16:54:27 -0800 | [diff] [blame] | 653 | rdev = net_device->extension; |
| 654 | |
Haiyang Zhang | 3a494e7 | 2014-06-19 18:34:36 -0700 | [diff] [blame] | 655 | switch (indicate->status) { |
| 656 | case RNDIS_STATUS_MEDIA_CONNECT: |
| 657 | rdev->link_state = false; |
| 658 | break; |
| 659 | case RNDIS_STATUS_MEDIA_DISCONNECT: |
| 660 | rdev->link_state = true; |
| 661 | break; |
| 662 | case RNDIS_STATUS_NETWORK_CHANGE: |
| 663 | rdev->link_change = true; |
| 664 | break; |
| 665 | default: |
| 666 | return; |
| 667 | } |
Haiyang Zhang | 891de74 | 2014-02-12 16:54:27 -0800 | [diff] [blame] | 668 | |
K. Y. Srinivasan | 2ddd5e5f | 2011-09-13 10:59:49 -0700 | [diff] [blame] | 669 | net = net_device->ndev; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 670 | |
Haiyang Zhang | 891de74 | 2014-02-12 16:54:27 -0800 | [diff] [blame] | 671 | if (!net || net->reg_state != NETREG_REGISTERED) |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 672 | return; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 673 | |
Haiyang Zhang | 891de74 | 2014-02-12 16:54:27 -0800 | [diff] [blame] | 674 | ndev_ctx = netdev_priv(net); |
Haiyang Zhang | 3a494e7 | 2014-06-19 18:34:36 -0700 | [diff] [blame] | 675 | if (!rdev->link_state) { |
Haiyang Zhang | c4b6a2e | 2011-09-01 12:19:42 -0700 | [diff] [blame] | 676 | schedule_delayed_work(&ndev_ctx->dwork, 0); |
Haiyang Zhang | 122a5f6 | 2011-05-27 06:21:55 -0700 | [diff] [blame] | 677 | schedule_delayed_work(&ndev_ctx->dwork, msecs_to_jiffies(20)); |
Greg Kroah-Hartman | 02fafbc | 2009-08-31 21:09:45 -0700 | [diff] [blame] | 678 | } else { |
Haiyang Zhang | 891de74 | 2014-02-12 16:54:27 -0800 | [diff] [blame] | 679 | schedule_delayed_work(&ndev_ctx->dwork, 0); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 680 | } |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 681 | } |
| 682 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 683 | /* |
| 684 | * netvsc_recv_callback - Callback when we receive a packet from the |
| 685 | * "wire" on the specified device. |
Greg Kroah-Hartman | 02fafbc | 2009-08-31 21:09:45 -0700 | [diff] [blame] | 686 | */ |
K. Y. Srinivasan | f79adf8 | 2011-05-12 19:34:51 -0700 | [diff] [blame] | 687 | int netvsc_recv_callback(struct hv_device *device_obj, |
KY Srinivasan | e3d605e | 2014-03-08 19:23:16 -0800 | [diff] [blame] | 688 | struct hv_netvsc_packet *packet, |
| 689 | struct ndis_tcp_ip_checksum_info *csum_info) |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 690 | { |
Haiyang Zhang | 6f4c444 | 2012-02-05 12:13:09 +0000 | [diff] [blame] | 691 | struct net_device *net; |
sixiao@microsoft.com | 7eafd9b | 2015-05-14 01:00:25 -0700 | [diff] [blame] | 692 | struct net_device_context *net_device_ctx; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 693 | struct sk_buff *skb; |
sixiao@microsoft.com | 7eafd9b | 2015-05-14 01:00:25 -0700 | [diff] [blame] | 694 | struct netvsc_stats *rx_stats; |
K. Y. Srinivasan | 2ddd5e5f | 2011-09-13 10:59:49 -0700 | [diff] [blame] | 695 | |
Haiyang Zhang | 6f4c444 | 2012-02-05 12:13:09 +0000 | [diff] [blame] | 696 | net = ((struct netvsc_device *)hv_get_drvdata(device_obj))->ndev; |
Haiyang Zhang | a68f961 | 2013-12-20 16:52:31 -0800 | [diff] [blame] | 697 | if (!net || net->reg_state != NETREG_REGISTERED) { |
Haiyang Zhang | 63f6921 | 2012-10-02 05:30:23 +0000 | [diff] [blame] | 698 | packet->status = NVSP_STAT_FAIL; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 699 | return 0; |
| 700 | } |
sixiao@microsoft.com | 7eafd9b | 2015-05-14 01:00:25 -0700 | [diff] [blame] | 701 | net_device_ctx = netdev_priv(net); |
| 702 | rx_stats = this_cpu_ptr(net_device_ctx->rx_stats); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 703 | |
Stephen Hemminger | 9495c28 | 2010-03-09 17:42:17 -0800 | [diff] [blame] | 704 | /* Allocate a skb - TODO direct I/O to pages? */ |
Haiyang Zhang | 72a2f5b | 2010-12-10 12:03:58 -0800 | [diff] [blame] | 705 | skb = netdev_alloc_skb_ip_align(net, packet->total_data_buflen); |
Stephen Hemminger | 9495c28 | 2010-03-09 17:42:17 -0800 | [diff] [blame] | 706 | if (unlikely(!skb)) { |
| 707 | ++net->stats.rx_dropped; |
Haiyang Zhang | 63f6921 | 2012-10-02 05:30:23 +0000 | [diff] [blame] | 708 | packet->status = NVSP_STAT_FAIL; |
Stephen Hemminger | 9495c28 | 2010-03-09 17:42:17 -0800 | [diff] [blame] | 709 | return 0; |
| 710 | } |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 711 | |
Greg Kroah-Hartman | 02fafbc | 2009-08-31 21:09:45 -0700 | [diff] [blame] | 712 | /* |
| 713 | * Copy to skb. This copy is needed here since the memory pointed by |
| 714 | * hv_netvsc_packet cannot be deallocated |
| 715 | */ |
Haiyang Zhang | 4532634 | 2011-12-15 13:45:15 -0800 | [diff] [blame] | 716 | memcpy(skb_put(skb, packet->total_data_buflen), packet->data, |
| 717 | packet->total_data_buflen); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 718 | |
| 719 | skb->protocol = eth_type_trans(skb, net); |
KY Srinivasan | e3d605e | 2014-03-08 19:23:16 -0800 | [diff] [blame] | 720 | if (csum_info) { |
| 721 | /* We only look at the IP checksum here. |
| 722 | * Should we be dropping the packet if checksum |
| 723 | * failed? How do we deal with other checksums - TCP/UDP? |
| 724 | */ |
| 725 | if (csum_info->receive.ip_checksum_succeeded) |
| 726 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 727 | else |
| 728 | skb->ip_summed = CHECKSUM_NONE; |
| 729 | } |
| 730 | |
Haiyang Zhang | 93725cb | 2013-06-17 15:36:49 -0700 | [diff] [blame] | 731 | if (packet->vlan_tci & VLAN_TAG_PRESENT) |
| 732 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), |
| 733 | packet->vlan_tci); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 734 | |
Haiyang Zhang | 4baab26 | 2014-04-21 14:54:43 -0700 | [diff] [blame] | 735 | skb_record_rx_queue(skb, packet->channel-> |
Haiyang Zhang | e565e80 | 2014-05-08 15:14:10 -0700 | [diff] [blame] | 736 | offermsg.offer.sub_channel_index); |
Haiyang Zhang | 5b54dac | 2014-04-21 10:20:28 -0700 | [diff] [blame] | 737 | |
sixiao@microsoft.com | 4b02b58 | 2015-05-15 02:33:03 -0700 | [diff] [blame] | 738 | u64_stats_update_begin(&rx_stats->syncp); |
sixiao@microsoft.com | 7eafd9b | 2015-05-14 01:00:25 -0700 | [diff] [blame] | 739 | rx_stats->packets++; |
| 740 | rx_stats->bytes += packet->total_data_buflen; |
sixiao@microsoft.com | 4b02b58 | 2015-05-15 02:33:03 -0700 | [diff] [blame] | 741 | u64_stats_update_end(&rx_stats->syncp); |
Stephen Hemminger | 9495c28 | 2010-03-09 17:42:17 -0800 | [diff] [blame] | 742 | |
Greg Kroah-Hartman | 02fafbc | 2009-08-31 21:09:45 -0700 | [diff] [blame] | 743 | /* |
| 744 | * Pass the skb back up. Network stack will deallocate the skb when it |
Stephen Hemminger | 9495c28 | 2010-03-09 17:42:17 -0800 | [diff] [blame] | 745 | * is done. |
| 746 | * TODO - use NAPI? |
Greg Kroah-Hartman | 02fafbc | 2009-08-31 21:09:45 -0700 | [diff] [blame] | 747 | */ |
Stephen Hemminger | 9495c28 | 2010-03-09 17:42:17 -0800 | [diff] [blame] | 748 | netif_rx(skb); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 749 | |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 750 | return 0; |
| 751 | } |
| 752 | |
Stephen Hemminger | f82f4ad | 2010-05-04 09:58:57 -0700 | [diff] [blame] | 753 | static void netvsc_get_drvinfo(struct net_device *net, |
| 754 | struct ethtool_drvinfo *info) |
| 755 | { |
Jiri Pirko | 7826d43 | 2013-01-06 00:44:26 +0000 | [diff] [blame] | 756 | strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver)); |
Jiri Pirko | 7826d43 | 2013-01-06 00:44:26 +0000 | [diff] [blame] | 757 | strlcpy(info->fw_version, "N/A", sizeof(info->fw_version)); |
Stephen Hemminger | f82f4ad | 2010-05-04 09:58:57 -0700 | [diff] [blame] | 758 | } |
| 759 | |
Andrew Schwartzmeyer | 5999537 | 2015-02-26 16:27:14 -0800 | [diff] [blame] | 760 | static void netvsc_get_channels(struct net_device *net, |
| 761 | struct ethtool_channels *channel) |
| 762 | { |
| 763 | struct net_device_context *net_device_ctx = netdev_priv(net); |
| 764 | struct hv_device *dev = net_device_ctx->device_ctx; |
| 765 | struct netvsc_device *nvdev = hv_get_drvdata(dev); |
| 766 | |
| 767 | if (nvdev) { |
| 768 | channel->max_combined = nvdev->max_chn; |
| 769 | channel->combined_count = nvdev->num_chn; |
| 770 | } |
| 771 | } |
| 772 | |
Andrew Schwartzmeyer | b5960e6 | 2015-08-11 17:14:32 -0700 | [diff] [blame] | 773 | static int netvsc_set_channels(struct net_device *net, |
| 774 | struct ethtool_channels *channels) |
| 775 | { |
| 776 | struct net_device_context *net_device_ctx = netdev_priv(net); |
| 777 | struct hv_device *dev = net_device_ctx->device_ctx; |
| 778 | struct netvsc_device *nvdev = hv_get_drvdata(dev); |
| 779 | struct netvsc_device_info device_info; |
Andrew Schwartzmeyer | 954591b | 2015-08-18 20:06:32 -0700 | [diff] [blame] | 780 | u32 num_chn; |
| 781 | u32 max_chn; |
Andrew Schwartzmeyer | b5960e6 | 2015-08-11 17:14:32 -0700 | [diff] [blame] | 782 | int ret = 0; |
| 783 | bool recovering = false; |
| 784 | |
| 785 | if (!nvdev || nvdev->destroy) |
| 786 | return -ENODEV; |
| 787 | |
Andrew Schwartzmeyer | 954591b | 2015-08-18 20:06:32 -0700 | [diff] [blame] | 788 | num_chn = nvdev->num_chn; |
| 789 | max_chn = min_t(u32, nvdev->max_chn, num_online_cpus()); |
| 790 | |
Andrew Schwartzmeyer | b5960e6 | 2015-08-11 17:14:32 -0700 | [diff] [blame] | 791 | if (nvdev->nvsp_version < NVSP_PROTOCOL_VERSION_5) { |
| 792 | pr_info("vRSS unsupported before NVSP Version 5\n"); |
| 793 | return -EINVAL; |
| 794 | } |
| 795 | |
| 796 | /* We do not support rx, tx, or other */ |
| 797 | if (!channels || |
| 798 | channels->rx_count || |
| 799 | channels->tx_count || |
| 800 | channels->other_count || |
| 801 | (channels->combined_count < 1)) |
| 802 | return -EINVAL; |
| 803 | |
| 804 | if (channels->combined_count > max_chn) { |
| 805 | pr_info("combined channels too high, using %d\n", max_chn); |
| 806 | channels->combined_count = max_chn; |
| 807 | } |
| 808 | |
| 809 | ret = netvsc_close(net); |
| 810 | if (ret) |
| 811 | goto out; |
| 812 | |
| 813 | do_set: |
| 814 | nvdev->start_remove = true; |
| 815 | rndis_filter_device_remove(dev); |
| 816 | |
| 817 | nvdev->num_chn = channels->combined_count; |
| 818 | |
| 819 | net_device_ctx->device_ctx = dev; |
| 820 | hv_set_drvdata(dev, net); |
| 821 | |
| 822 | memset(&device_info, 0, sizeof(device_info)); |
| 823 | device_info.num_chn = nvdev->num_chn; /* passed to RNDIS */ |
| 824 | device_info.ring_size = ring_size; |
| 825 | device_info.max_num_vrss_chns = max_num_vrss_chns; |
| 826 | |
| 827 | ret = rndis_filter_device_add(dev, &device_info); |
| 828 | if (ret) { |
| 829 | if (recovering) { |
| 830 | netdev_err(net, "unable to add netvsc device (ret %d)\n", ret); |
| 831 | return ret; |
| 832 | } |
| 833 | goto recover; |
| 834 | } |
| 835 | |
| 836 | nvdev = hv_get_drvdata(dev); |
| 837 | |
| 838 | ret = netif_set_real_num_tx_queues(net, nvdev->num_chn); |
| 839 | if (ret) { |
| 840 | if (recovering) { |
| 841 | netdev_err(net, "could not set tx queue count (ret %d)\n", ret); |
| 842 | return ret; |
| 843 | } |
| 844 | goto recover; |
| 845 | } |
| 846 | |
| 847 | ret = netif_set_real_num_rx_queues(net, nvdev->num_chn); |
| 848 | if (ret) { |
| 849 | if (recovering) { |
| 850 | netdev_err(net, "could not set rx queue count (ret %d)\n", ret); |
| 851 | return ret; |
| 852 | } |
| 853 | goto recover; |
| 854 | } |
| 855 | |
| 856 | out: |
| 857 | netvsc_open(net); |
| 858 | |
| 859 | return ret; |
| 860 | |
| 861 | recover: |
| 862 | /* If the above failed, we attempt to recover through the same |
| 863 | * process but with the original number of channels. |
| 864 | */ |
| 865 | netdev_err(net, "could not set channels, recovering\n"); |
| 866 | recovering = true; |
| 867 | channels->combined_count = num_chn; |
| 868 | goto do_set; |
| 869 | } |
| 870 | |
Haiyang Zhang | 4d447c9 | 2011-12-15 13:45:17 -0800 | [diff] [blame] | 871 | static int netvsc_change_mtu(struct net_device *ndev, int mtu) |
| 872 | { |
| 873 | struct net_device_context *ndevctx = netdev_priv(ndev); |
| 874 | struct hv_device *hdev = ndevctx->device_ctx; |
| 875 | struct netvsc_device *nvdev = hv_get_drvdata(hdev); |
| 876 | struct netvsc_device_info device_info; |
| 877 | int limit = ETH_DATA_LEN; |
Haiyang Zhang | 2de8530 | 2015-07-13 13:09:16 -0700 | [diff] [blame] | 878 | int ret = 0; |
Haiyang Zhang | 4d447c9 | 2011-12-15 13:45:17 -0800 | [diff] [blame] | 879 | |
| 880 | if (nvdev == NULL || nvdev->destroy) |
| 881 | return -ENODEV; |
| 882 | |
Haiyang Zhang | a1eabb0 | 2014-02-19 15:49:45 -0800 | [diff] [blame] | 883 | if (nvdev->nvsp_version >= NVSP_PROTOCOL_VERSION_2) |
Haiyang Zhang | 4d3c9d3 | 2014-11-12 14:07:44 -0800 | [diff] [blame] | 884 | limit = NETVSC_MTU - ETH_HLEN; |
Haiyang Zhang | 4d447c9 | 2011-12-15 13:45:17 -0800 | [diff] [blame] | 885 | |
Haiyang Zhang | f9cbce3 | 2015-07-06 14:11:37 -0700 | [diff] [blame] | 886 | if (mtu < NETVSC_MTU_MIN || mtu > limit) |
Haiyang Zhang | 4d447c9 | 2011-12-15 13:45:17 -0800 | [diff] [blame] | 887 | return -EINVAL; |
| 888 | |
Haiyang Zhang | 2de8530 | 2015-07-13 13:09:16 -0700 | [diff] [blame] | 889 | ret = netvsc_close(ndev); |
| 890 | if (ret) |
| 891 | goto out; |
| 892 | |
Haiyang Zhang | 4d447c9 | 2011-12-15 13:45:17 -0800 | [diff] [blame] | 893 | nvdev->start_remove = true; |
Haiyang Zhang | 4d447c9 | 2011-12-15 13:45:17 -0800 | [diff] [blame] | 894 | rndis_filter_device_remove(hdev); |
| 895 | |
| 896 | ndev->mtu = mtu; |
| 897 | |
| 898 | ndevctx->device_ctx = hdev; |
| 899 | hv_set_drvdata(hdev, ndev); |
Andrew Schwartzmeyer | 8ebdcc5 | 2015-08-11 17:14:31 -0700 | [diff] [blame] | 900 | |
| 901 | memset(&device_info, 0, sizeof(device_info)); |
Haiyang Zhang | 4d447c9 | 2011-12-15 13:45:17 -0800 | [diff] [blame] | 902 | device_info.ring_size = ring_size; |
Andrew Schwartzmeyer | b5960e6 | 2015-08-11 17:14:32 -0700 | [diff] [blame] | 903 | device_info.num_chn = nvdev->num_chn; |
KY Srinivasan | e01ec21 | 2015-05-27 13:16:57 -0700 | [diff] [blame] | 904 | device_info.max_num_vrss_chns = max_num_vrss_chns; |
Haiyang Zhang | 4d447c9 | 2011-12-15 13:45:17 -0800 | [diff] [blame] | 905 | rndis_filter_device_add(hdev, &device_info); |
Haiyang Zhang | 4d447c9 | 2011-12-15 13:45:17 -0800 | [diff] [blame] | 906 | |
Haiyang Zhang | 2de8530 | 2015-07-13 13:09:16 -0700 | [diff] [blame] | 907 | out: |
| 908 | netvsc_open(ndev); |
| 909 | |
| 910 | return ret; |
Haiyang Zhang | 4d447c9 | 2011-12-15 13:45:17 -0800 | [diff] [blame] | 911 | } |
| 912 | |
sixiao@microsoft.com | 7eafd9b | 2015-05-14 01:00:25 -0700 | [diff] [blame] | 913 | static struct rtnl_link_stats64 *netvsc_get_stats64(struct net_device *net, |
| 914 | struct rtnl_link_stats64 *t) |
| 915 | { |
| 916 | struct net_device_context *ndev_ctx = netdev_priv(net); |
| 917 | int cpu; |
| 918 | |
| 919 | for_each_possible_cpu(cpu) { |
| 920 | struct netvsc_stats *tx_stats = per_cpu_ptr(ndev_ctx->tx_stats, |
| 921 | cpu); |
| 922 | struct netvsc_stats *rx_stats = per_cpu_ptr(ndev_ctx->rx_stats, |
| 923 | cpu); |
| 924 | u64 tx_packets, tx_bytes, rx_packets, rx_bytes; |
| 925 | unsigned int start; |
| 926 | |
| 927 | do { |
sixiao@microsoft.com | 4b02b58 | 2015-05-15 02:33:03 -0700 | [diff] [blame] | 928 | start = u64_stats_fetch_begin_irq(&tx_stats->syncp); |
sixiao@microsoft.com | 7eafd9b | 2015-05-14 01:00:25 -0700 | [diff] [blame] | 929 | tx_packets = tx_stats->packets; |
| 930 | tx_bytes = tx_stats->bytes; |
sixiao@microsoft.com | 4b02b58 | 2015-05-15 02:33:03 -0700 | [diff] [blame] | 931 | } while (u64_stats_fetch_retry_irq(&tx_stats->syncp, start)); |
sixiao@microsoft.com | 7eafd9b | 2015-05-14 01:00:25 -0700 | [diff] [blame] | 932 | |
| 933 | do { |
sixiao@microsoft.com | 4b02b58 | 2015-05-15 02:33:03 -0700 | [diff] [blame] | 934 | start = u64_stats_fetch_begin_irq(&rx_stats->syncp); |
sixiao@microsoft.com | 7eafd9b | 2015-05-14 01:00:25 -0700 | [diff] [blame] | 935 | rx_packets = rx_stats->packets; |
| 936 | rx_bytes = rx_stats->bytes; |
sixiao@microsoft.com | 4b02b58 | 2015-05-15 02:33:03 -0700 | [diff] [blame] | 937 | } while (u64_stats_fetch_retry_irq(&rx_stats->syncp, start)); |
sixiao@microsoft.com | 7eafd9b | 2015-05-14 01:00:25 -0700 | [diff] [blame] | 938 | |
| 939 | t->tx_bytes += tx_bytes; |
| 940 | t->tx_packets += tx_packets; |
| 941 | t->rx_bytes += rx_bytes; |
| 942 | t->rx_packets += rx_packets; |
| 943 | } |
| 944 | |
| 945 | t->tx_dropped = net->stats.tx_dropped; |
| 946 | t->tx_errors = net->stats.tx_dropped; |
| 947 | |
| 948 | t->rx_dropped = net->stats.rx_dropped; |
| 949 | t->rx_errors = net->stats.rx_errors; |
| 950 | |
| 951 | return t; |
| 952 | } |
Haiyang Zhang | 1ce09e8 | 2012-07-10 07:19:22 +0000 | [diff] [blame] | 953 | |
| 954 | static int netvsc_set_mac_addr(struct net_device *ndev, void *p) |
| 955 | { |
| 956 | struct net_device_context *ndevctx = netdev_priv(ndev); |
| 957 | struct hv_device *hdev = ndevctx->device_ctx; |
| 958 | struct sockaddr *addr = p; |
Jianjun Kong | 9a4c831 | 2013-01-18 16:52:09 +0000 | [diff] [blame] | 959 | char save_adr[ETH_ALEN]; |
Haiyang Zhang | 1ce09e8 | 2012-07-10 07:19:22 +0000 | [diff] [blame] | 960 | unsigned char save_aatype; |
| 961 | int err; |
| 962 | |
| 963 | memcpy(save_adr, ndev->dev_addr, ETH_ALEN); |
| 964 | save_aatype = ndev->addr_assign_type; |
| 965 | |
| 966 | err = eth_mac_addr(ndev, p); |
| 967 | if (err != 0) |
| 968 | return err; |
| 969 | |
| 970 | err = rndis_filter_set_device_mac(hdev, addr->sa_data); |
| 971 | if (err != 0) { |
| 972 | /* roll back to saved MAC */ |
| 973 | memcpy(ndev->dev_addr, save_adr, ETH_ALEN); |
| 974 | ndev->addr_assign_type = save_aatype; |
| 975 | } |
| 976 | |
| 977 | return err; |
| 978 | } |
| 979 | |
Richard Weinberger | 316158f | 2014-07-09 16:23:59 +0200 | [diff] [blame] | 980 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 981 | static void netvsc_poll_controller(struct net_device *net) |
| 982 | { |
| 983 | /* As netvsc_start_xmit() works synchronous we don't have to |
| 984 | * trigger anything here. |
| 985 | */ |
| 986 | } |
| 987 | #endif |
Haiyang Zhang | 1ce09e8 | 2012-07-10 07:19:22 +0000 | [diff] [blame] | 988 | |
Stephen Hemminger | f82f4ad | 2010-05-04 09:58:57 -0700 | [diff] [blame] | 989 | static const struct ethtool_ops ethtool_ops = { |
| 990 | .get_drvinfo = netvsc_get_drvinfo, |
Stephen Hemminger | f82f4ad | 2010-05-04 09:58:57 -0700 | [diff] [blame] | 991 | .get_link = ethtool_op_get_link, |
Andrew Schwartzmeyer | 5999537 | 2015-02-26 16:27:14 -0800 | [diff] [blame] | 992 | .get_channels = netvsc_get_channels, |
Andrew Schwartzmeyer | b5960e6 | 2015-08-11 17:14:32 -0700 | [diff] [blame] | 993 | .set_channels = netvsc_set_channels, |
Stephen Hemminger | f82f4ad | 2010-05-04 09:58:57 -0700 | [diff] [blame] | 994 | }; |
| 995 | |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 996 | static const struct net_device_ops device_ops = { |
| 997 | .ndo_open = netvsc_open, |
| 998 | .ndo_stop = netvsc_close, |
| 999 | .ndo_start_xmit = netvsc_start_xmit, |
Jiri Pirko | afc4b13 | 2011-08-16 06:29:01 +0000 | [diff] [blame] | 1000 | .ndo_set_rx_mode = netvsc_set_multicast_list, |
Haiyang Zhang | 4d447c9 | 2011-12-15 13:45:17 -0800 | [diff] [blame] | 1001 | .ndo_change_mtu = netvsc_change_mtu, |
Haiyang Zhang | b681b58 | 2010-08-03 19:15:31 +0000 | [diff] [blame] | 1002 | .ndo_validate_addr = eth_validate_addr, |
Haiyang Zhang | 1ce09e8 | 2012-07-10 07:19:22 +0000 | [diff] [blame] | 1003 | .ndo_set_mac_address = netvsc_set_mac_addr, |
Haiyang Zhang | 5b54dac | 2014-04-21 10:20:28 -0700 | [diff] [blame] | 1004 | .ndo_select_queue = netvsc_select_queue, |
sixiao@microsoft.com | 7eafd9b | 2015-05-14 01:00:25 -0700 | [diff] [blame] | 1005 | .ndo_get_stats64 = netvsc_get_stats64, |
Richard Weinberger | 316158f | 2014-07-09 16:23:59 +0200 | [diff] [blame] | 1006 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1007 | .ndo_poll_controller = netvsc_poll_controller, |
| 1008 | #endif |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1009 | }; |
| 1010 | |
Haiyang Zhang | c996edc | 2011-04-06 15:18:00 -0700 | [diff] [blame] | 1011 | /* |
| 1012 | * Send GARP packet to network peers after migrations. |
| 1013 | * After Quick Migration, the network is not immediately operational in the |
| 1014 | * current context when receiving RNDIS_STATUS_MEDIA_CONNECT event. So, add |
Haiyang Zhang | 122a5f6 | 2011-05-27 06:21:55 -0700 | [diff] [blame] | 1015 | * another netif_notify_peers() into a delayed work, otherwise GARP packet |
Haiyang Zhang | c996edc | 2011-04-06 15:18:00 -0700 | [diff] [blame] | 1016 | * will not be sent after quick migration, and cause network disconnection. |
Haiyang Zhang | 891de74 | 2014-02-12 16:54:27 -0800 | [diff] [blame] | 1017 | * Also, we update the carrier status here. |
Haiyang Zhang | c996edc | 2011-04-06 15:18:00 -0700 | [diff] [blame] | 1018 | */ |
Haiyang Zhang | 891de74 | 2014-02-12 16:54:27 -0800 | [diff] [blame] | 1019 | static void netvsc_link_change(struct work_struct *w) |
Haiyang Zhang | c996edc | 2011-04-06 15:18:00 -0700 | [diff] [blame] | 1020 | { |
| 1021 | struct net_device_context *ndev_ctx; |
| 1022 | struct net_device *net; |
K. Y. Srinivasan | 2ddd5e5f | 2011-09-13 10:59:49 -0700 | [diff] [blame] | 1023 | struct netvsc_device *net_device; |
Haiyang Zhang | 891de74 | 2014-02-12 16:54:27 -0800 | [diff] [blame] | 1024 | struct rndis_device *rdev; |
Haiyang Zhang | 3a494e7 | 2014-06-19 18:34:36 -0700 | [diff] [blame] | 1025 | bool notify, refresh = false; |
| 1026 | char *argv[] = { "/etc/init.d/network", "restart", NULL }; |
| 1027 | char *envp[] = { "HOME=/", "PATH=/sbin:/usr/sbin:/bin:/usr/bin", NULL }; |
Haiyang Zhang | 891de74 | 2014-02-12 16:54:27 -0800 | [diff] [blame] | 1028 | |
| 1029 | rtnl_lock(); |
Haiyang Zhang | c996edc | 2011-04-06 15:18:00 -0700 | [diff] [blame] | 1030 | |
Haiyang Zhang | 122a5f6 | 2011-05-27 06:21:55 -0700 | [diff] [blame] | 1031 | ndev_ctx = container_of(w, struct net_device_context, dwork.work); |
K. Y. Srinivasan | 2ddd5e5f | 2011-09-13 10:59:49 -0700 | [diff] [blame] | 1032 | net_device = hv_get_drvdata(ndev_ctx->device_ctx); |
Haiyang Zhang | 891de74 | 2014-02-12 16:54:27 -0800 | [diff] [blame] | 1033 | rdev = net_device->extension; |
K. Y. Srinivasan | 2ddd5e5f | 2011-09-13 10:59:49 -0700 | [diff] [blame] | 1034 | net = net_device->ndev; |
Haiyang Zhang | 891de74 | 2014-02-12 16:54:27 -0800 | [diff] [blame] | 1035 | |
| 1036 | if (rdev->link_state) { |
| 1037 | netif_carrier_off(net); |
| 1038 | notify = false; |
| 1039 | } else { |
| 1040 | netif_carrier_on(net); |
| 1041 | notify = true; |
Haiyang Zhang | 3a494e7 | 2014-06-19 18:34:36 -0700 | [diff] [blame] | 1042 | if (rdev->link_change) { |
| 1043 | rdev->link_change = false; |
| 1044 | refresh = true; |
| 1045 | } |
Haiyang Zhang | 891de74 | 2014-02-12 16:54:27 -0800 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | rtnl_unlock(); |
| 1049 | |
Haiyang Zhang | 3a494e7 | 2014-06-19 18:34:36 -0700 | [diff] [blame] | 1050 | if (refresh) |
| 1051 | call_usermodehelper(argv[0], argv, envp, UMH_WAIT_EXEC); |
| 1052 | |
Haiyang Zhang | 891de74 | 2014-02-12 16:54:27 -0800 | [diff] [blame] | 1053 | if (notify) |
| 1054 | netdev_notify_peers(net); |
Haiyang Zhang | c996edc | 2011-04-06 15:18:00 -0700 | [diff] [blame] | 1055 | } |
| 1056 | |
sixiao@microsoft.com | 7eafd9b | 2015-05-14 01:00:25 -0700 | [diff] [blame] | 1057 | static void netvsc_free_netdev(struct net_device *netdev) |
| 1058 | { |
| 1059 | struct net_device_context *net_device_ctx = netdev_priv(netdev); |
| 1060 | |
| 1061 | free_percpu(net_device_ctx->tx_stats); |
| 1062 | free_percpu(net_device_ctx->rx_stats); |
| 1063 | free_netdev(netdev); |
| 1064 | } |
Haiyang Zhang | c996edc | 2011-04-06 15:18:00 -0700 | [diff] [blame] | 1065 | |
K. Y. Srinivasan | 8494689 | 2011-09-13 10:59:38 -0700 | [diff] [blame] | 1066 | static int netvsc_probe(struct hv_device *dev, |
| 1067 | const struct hv_vmbus_device_id *dev_id) |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1068 | { |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1069 | struct net_device *net = NULL; |
| 1070 | struct net_device_context *net_device_ctx; |
| 1071 | struct netvsc_device_info device_info; |
Haiyang Zhang | 5b54dac | 2014-04-21 10:20:28 -0700 | [diff] [blame] | 1072 | struct netvsc_device *nvdev; |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1073 | int ret; |
KY Srinivasan | b08cc79 | 2015-03-29 21:08:42 -0700 | [diff] [blame] | 1074 | u32 max_needed_headroom; |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1075 | |
Haiyang Zhang | 5b54dac | 2014-04-21 10:20:28 -0700 | [diff] [blame] | 1076 | net = alloc_etherdev_mq(sizeof(struct net_device_context), |
| 1077 | num_online_cpus()); |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1078 | if (!net) |
K. Y. Srinivasan | 51a805d | 2011-08-25 09:49:11 -0700 | [diff] [blame] | 1079 | return -ENOMEM; |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1080 | |
KY Srinivasan | b08cc79 | 2015-03-29 21:08:42 -0700 | [diff] [blame] | 1081 | max_needed_headroom = sizeof(struct hv_netvsc_packet) + |
Haiyang Zhang | 7215142 | 2015-04-06 15:22:53 -0700 | [diff] [blame] | 1082 | RNDIS_AND_PPI_SIZE; |
KY Srinivasan | b08cc79 | 2015-03-29 21:08:42 -0700 | [diff] [blame] | 1083 | |
Haiyang Zhang | 1b07da5 | 2014-03-04 14:11:06 -0800 | [diff] [blame] | 1084 | netif_carrier_off(net); |
| 1085 | |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1086 | net_device_ctx = netdev_priv(net); |
K. Y. Srinivasan | 9efd21e | 2011-04-29 13:45:10 -0700 | [diff] [blame] | 1087 | net_device_ctx->device_ctx = dev; |
Simon Xiao | 3f300ff | 2015-04-28 01:05:17 -0700 | [diff] [blame] | 1088 | net_device_ctx->msg_enable = netif_msg_init(debug, default_msg); |
| 1089 | if (netif_msg_probe(net_device_ctx)) |
| 1090 | netdev_dbg(net, "netvsc msg_enable: %d\n", |
| 1091 | net_device_ctx->msg_enable); |
| 1092 | |
sixiao@microsoft.com | 7eafd9b | 2015-05-14 01:00:25 -0700 | [diff] [blame] | 1093 | net_device_ctx->tx_stats = netdev_alloc_pcpu_stats(struct netvsc_stats); |
| 1094 | if (!net_device_ctx->tx_stats) { |
| 1095 | free_netdev(net); |
| 1096 | return -ENOMEM; |
| 1097 | } |
| 1098 | net_device_ctx->rx_stats = netdev_alloc_pcpu_stats(struct netvsc_stats); |
| 1099 | if (!net_device_ctx->rx_stats) { |
| 1100 | free_percpu(net_device_ctx->tx_stats); |
| 1101 | free_netdev(net); |
| 1102 | return -ENOMEM; |
| 1103 | } |
| 1104 | |
K. Y. Srinivasan | 2ddd5e5f | 2011-09-13 10:59:49 -0700 | [diff] [blame] | 1105 | hv_set_drvdata(dev, net); |
Haiyang Zhang | 891de74 | 2014-02-12 16:54:27 -0800 | [diff] [blame] | 1106 | INIT_DELAYED_WORK(&net_device_ctx->dwork, netvsc_link_change); |
Wenqi Ma | 792df87 | 2012-04-19 00:39:37 +0000 | [diff] [blame] | 1107 | INIT_WORK(&net_device_ctx->work, do_set_multicast); |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1108 | |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1109 | net->netdev_ops = &device_ops; |
| 1110 | |
KY Srinivasan | 77bf548 | 2014-03-08 19:23:18 -0800 | [diff] [blame] | 1111 | net->hw_features = NETIF_F_RXCSUM | NETIF_F_SG | NETIF_F_IP_CSUM | |
| 1112 | NETIF_F_TSO; |
KY Srinivasan | 08cd04b | 2014-03-08 19:23:17 -0800 | [diff] [blame] | 1113 | net->features = NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_SG | NETIF_F_RXCSUM | |
KY Srinivasan | 77bf548 | 2014-03-08 19:23:18 -0800 | [diff] [blame] | 1114 | NETIF_F_IP_CSUM | NETIF_F_TSO; |
Stephen Hemminger | 6048718 | 2010-05-04 09:58:55 -0700 | [diff] [blame] | 1115 | |
Wilfried Klaebe | 7ad24ea | 2014-05-11 00:12:32 +0000 | [diff] [blame] | 1116 | net->ethtool_ops = ðtool_ops; |
K. Y. Srinivasan | 9efd21e | 2011-04-29 13:45:10 -0700 | [diff] [blame] | 1117 | SET_NETDEV_DEV(net, &dev->device); |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1118 | |
KY Srinivasan | b08cc79 | 2015-03-29 21:08:42 -0700 | [diff] [blame] | 1119 | /* |
| 1120 | * Request additional head room in the skb. |
| 1121 | * We will use this space to build the rndis |
| 1122 | * heaser and other state we need to maintain. |
| 1123 | */ |
| 1124 | net->needed_headroom = max_needed_headroom; |
| 1125 | |
Haiyang Zhang | 692e084 | 2011-09-01 12:19:43 -0700 | [diff] [blame] | 1126 | /* Notify the netvsc driver of the new device */ |
Andrew Schwartzmeyer | 8ebdcc5 | 2015-08-11 17:14:31 -0700 | [diff] [blame] | 1127 | memset(&device_info, 0, sizeof(device_info)); |
Haiyang Zhang | 692e084 | 2011-09-01 12:19:43 -0700 | [diff] [blame] | 1128 | device_info.ring_size = ring_size; |
KY Srinivasan | e01ec21 | 2015-05-27 13:16:57 -0700 | [diff] [blame] | 1129 | device_info.max_num_vrss_chns = max_num_vrss_chns; |
Haiyang Zhang | 692e084 | 2011-09-01 12:19:43 -0700 | [diff] [blame] | 1130 | ret = rndis_filter_device_add(dev, &device_info); |
| 1131 | if (ret != 0) { |
| 1132 | netdev_err(net, "unable to add netvsc device (ret %d)\n", ret); |
sixiao@microsoft.com | 7eafd9b | 2015-05-14 01:00:25 -0700 | [diff] [blame] | 1133 | netvsc_free_netdev(net); |
K. Y. Srinivasan | 2ddd5e5f | 2011-09-13 10:59:49 -0700 | [diff] [blame] | 1134 | hv_set_drvdata(dev, NULL); |
Haiyang Zhang | 692e084 | 2011-09-01 12:19:43 -0700 | [diff] [blame] | 1135 | return ret; |
| 1136 | } |
| 1137 | memcpy(net->dev_addr, device_info.mac_adr, ETH_ALEN); |
| 1138 | |
Haiyang Zhang | 5b54dac | 2014-04-21 10:20:28 -0700 | [diff] [blame] | 1139 | nvdev = hv_get_drvdata(dev); |
| 1140 | netif_set_real_num_tx_queues(net, nvdev->num_chn); |
| 1141 | netif_set_real_num_rx_queues(net, nvdev->num_chn); |
Haiyang Zhang | 5b54dac | 2014-04-21 10:20:28 -0700 | [diff] [blame] | 1142 | |
Haiyang Zhang | a68f961 | 2013-12-20 16:52:31 -0800 | [diff] [blame] | 1143 | ret = register_netdev(net); |
| 1144 | if (ret != 0) { |
| 1145 | pr_err("Unable to register netdev.\n"); |
| 1146 | rndis_filter_device_remove(dev); |
sixiao@microsoft.com | 7eafd9b | 2015-05-14 01:00:25 -0700 | [diff] [blame] | 1147 | netvsc_free_netdev(net); |
Haiyang Zhang | 1b07da5 | 2014-03-04 14:11:06 -0800 | [diff] [blame] | 1148 | } else { |
| 1149 | schedule_delayed_work(&net_device_ctx->dwork, 0); |
Haiyang Zhang | a68f961 | 2013-12-20 16:52:31 -0800 | [diff] [blame] | 1150 | } |
| 1151 | |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1152 | return ret; |
| 1153 | } |
| 1154 | |
K. Y. Srinivasan | 415b023 | 2011-04-29 13:45:12 -0700 | [diff] [blame] | 1155 | static int netvsc_remove(struct hv_device *dev) |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1156 | { |
K. Y. Srinivasan | 2ddd5e5f | 2011-09-13 10:59:49 -0700 | [diff] [blame] | 1157 | struct net_device *net; |
Haiyang Zhang | 122a5f6 | 2011-05-27 06:21:55 -0700 | [diff] [blame] | 1158 | struct net_device_context *ndev_ctx; |
K. Y. Srinivasan | 2ddd5e5f | 2011-09-13 10:59:49 -0700 | [diff] [blame] | 1159 | struct netvsc_device *net_device; |
| 1160 | |
| 1161 | net_device = hv_get_drvdata(dev); |
| 1162 | net = net_device->ndev; |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1163 | |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1164 | if (net == NULL) { |
K. Y. Srinivasan | 415b023 | 2011-04-29 13:45:12 -0700 | [diff] [blame] | 1165 | dev_err(&dev->device, "No net device to remove\n"); |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1166 | return 0; |
| 1167 | } |
| 1168 | |
Haiyang Zhang | 4d447c9 | 2011-12-15 13:45:17 -0800 | [diff] [blame] | 1169 | net_device->start_remove = true; |
| 1170 | |
Haiyang Zhang | 122a5f6 | 2011-05-27 06:21:55 -0700 | [diff] [blame] | 1171 | ndev_ctx = netdev_priv(net); |
| 1172 | cancel_delayed_work_sync(&ndev_ctx->dwork); |
Wenqi Ma | 792df87 | 2012-04-19 00:39:37 +0000 | [diff] [blame] | 1173 | cancel_work_sync(&ndev_ctx->work); |
Haiyang Zhang | 122a5f6 | 2011-05-27 06:21:55 -0700 | [diff] [blame] | 1174 | |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1175 | /* Stop outbound asap */ |
Haiyang Zhang | 0a28253 | 2012-02-02 07:17:59 +0000 | [diff] [blame] | 1176 | netif_tx_disable(net); |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1177 | |
| 1178 | unregister_netdev(net); |
| 1179 | |
| 1180 | /* |
| 1181 | * Call to the vsc driver to let it know that the device is being |
| 1182 | * removed |
| 1183 | */ |
Haiyang Zhang | df06bcf | 2011-05-23 09:03:47 -0700 | [diff] [blame] | 1184 | rndis_filter_device_remove(dev); |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1185 | |
sixiao@microsoft.com | 7eafd9b | 2015-05-14 01:00:25 -0700 | [diff] [blame] | 1186 | netvsc_free_netdev(net); |
Haiyang Zhang | df06bcf | 2011-05-23 09:03:47 -0700 | [diff] [blame] | 1187 | return 0; |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1188 | } |
| 1189 | |
K. Y. Srinivasan | 345c4cc | 2011-08-25 09:48:34 -0700 | [diff] [blame] | 1190 | static const struct hv_vmbus_device_id id_table[] = { |
Greg Kroah-Hartman | c45cf2d | 2011-08-25 11:41:33 -0700 | [diff] [blame] | 1191 | /* Network guid */ |
K. Y. Srinivasan | 8f50594 | 2013-01-23 17:42:42 -0800 | [diff] [blame] | 1192 | { HV_NIC_GUID, }, |
Greg Kroah-Hartman | c45cf2d | 2011-08-25 11:41:33 -0700 | [diff] [blame] | 1193 | { }, |
K. Y. Srinivasan | 345c4cc | 2011-08-25 09:48:34 -0700 | [diff] [blame] | 1194 | }; |
| 1195 | |
| 1196 | MODULE_DEVICE_TABLE(vmbus, id_table); |
| 1197 | |
K. Y. Srinivasan | f1542a66 | 2011-05-10 07:55:16 -0700 | [diff] [blame] | 1198 | /* The one and only one */ |
K. Y. Srinivasan | fde0ef9 | 2011-05-12 19:35:08 -0700 | [diff] [blame] | 1199 | static struct hv_driver netvsc_drv = { |
Haiyang Zhang | d31b20f | 2012-03-07 10:02:00 +0000 | [diff] [blame] | 1200 | .name = KBUILD_MODNAME, |
K. Y. Srinivasan | 345c4cc | 2011-08-25 09:48:34 -0700 | [diff] [blame] | 1201 | .id_table = id_table, |
K. Y. Srinivasan | fde0ef9 | 2011-05-12 19:35:08 -0700 | [diff] [blame] | 1202 | .probe = netvsc_probe, |
| 1203 | .remove = netvsc_remove, |
K. Y. Srinivasan | d489097 | 2011-05-10 07:55:17 -0700 | [diff] [blame] | 1204 | }; |
K. Y. Srinivasan | f1542a66 | 2011-05-10 07:55:16 -0700 | [diff] [blame] | 1205 | |
K. Y. Srinivasan | a9869c9 | 2011-05-12 19:35:17 -0700 | [diff] [blame] | 1206 | static void __exit netvsc_drv_exit(void) |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 1207 | { |
Greg Kroah-Hartman | 768fa21 | 2011-08-25 15:07:32 -0700 | [diff] [blame] | 1208 | vmbus_driver_unregister(&netvsc_drv); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 1209 | } |
| 1210 | |
K. Y. Srinivasan | 1fde28c | 2011-05-12 19:35:16 -0700 | [diff] [blame] | 1211 | static int __init netvsc_drv_init(void) |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1212 | { |
Haiyang Zhang | fa85a6c | 2012-07-25 08:08:41 +0000 | [diff] [blame] | 1213 | if (ring_size < RING_SIZE_MIN) { |
| 1214 | ring_size = RING_SIZE_MIN; |
| 1215 | pr_info("Increased ring_size to %d (min allowed)\n", |
| 1216 | ring_size); |
| 1217 | } |
Greg Kroah-Hartman | 768fa21 | 2011-08-25 15:07:32 -0700 | [diff] [blame] | 1218 | return vmbus_driver_register(&netvsc_drv); |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1219 | } |
| 1220 | |
Hank Janssen | 26c14cc | 2010-02-11 23:02:42 +0000 | [diff] [blame] | 1221 | MODULE_LICENSE("GPL"); |
Stephen Hemminger | 7880fc5 | 2010-05-04 09:58:52 -0700 | [diff] [blame] | 1222 | MODULE_DESCRIPTION("Microsoft Hyper-V network driver"); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 1223 | |
K. Y. Srinivasan | 1fde28c | 2011-05-12 19:35:16 -0700 | [diff] [blame] | 1224 | module_init(netvsc_drv_init); |
K. Y. Srinivasan | a9869c9 | 2011-05-12 19:35:17 -0700 | [diff] [blame] | 1225 | module_exit(netvsc_drv_exit); |