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 | c802db1 | 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> |
Michael Kelley | 8eb1b3c | 2017-05-30 11:36:56 -0700 | [diff] [blame] | 40 | #include <net/checksum.h> |
| 41 | #include <net/ip6_checksum.h> |
K. Y. Srinivasan | 3f335ea | 2011-05-12 19:34:15 -0700 | [diff] [blame] | 42 | |
K. Y. Srinivasan | 5ca7252 | 2011-05-12 19:34:37 -0700 | [diff] [blame] | 43 | #include "hyperv_net.h" |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 44 | |
Haiyang Zhang | fa85a6c | 2012-07-25 08:08:41 +0000 | [diff] [blame] | 45 | #define RING_SIZE_MIN 64 |
Vitaly Kuznetsov | 27a70af | 2015-11-27 11:39:55 +0100 | [diff] [blame] | 46 | #define LINKCHANGE_INT (2 * HZ) |
stephen hemminger | a50af86 | 2016-12-06 13:43:54 -0800 | [diff] [blame] | 47 | |
Hank Janssen | 99c8da0 | 2010-10-12 10:45:23 -0700 | [diff] [blame] | 48 | static int ring_size = 128; |
Stephen Hemminger | 450d7a4 | 2010-05-04 09:58:53 -0700 | [diff] [blame] | 49 | module_param(ring_size, int, S_IRUGO); |
| 50 | MODULE_PARM_DESC(ring_size, "Ring buffer size (# of pages)"); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 51 | |
Simon Xiao | 3f300ff | 2015-04-28 01:05:17 -0700 | [diff] [blame] | 52 | static const u32 default_msg = NETIF_MSG_DRV | NETIF_MSG_PROBE | |
| 53 | NETIF_MSG_LINK | NETIF_MSG_IFUP | |
| 54 | NETIF_MSG_IFDOWN | NETIF_MSG_RX_ERR | |
| 55 | NETIF_MSG_TX_ERR; |
| 56 | |
| 57 | static int debug = -1; |
| 58 | module_param(debug, int, S_IRUGO); |
| 59 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); |
| 60 | |
Haiyang Zhang | d426b2e | 2011-11-30 07:19:08 -0800 | [diff] [blame] | 61 | static void do_set_multicast(struct work_struct *w) |
| 62 | { |
Wenqi Ma | 792df87 | 2012-04-19 00:39:37 +0000 | [diff] [blame] | 63 | struct net_device_context *ndevctx = |
| 64 | container_of(w, struct net_device_context, work); |
Vitaly Kuznetsov | 0a1275c | 2016-05-13 13:55:23 +0200 | [diff] [blame] | 65 | struct hv_device *device_obj = ndevctx->device_ctx; |
| 66 | struct net_device *ndev = hv_get_drvdata(device_obj); |
stephen hemminger | 545a8e7 | 2017-03-22 14:51:00 -0700 | [diff] [blame] | 67 | struct netvsc_device *nvdev = rcu_dereference(ndevctx->nvdev); |
Haiyang Zhang | d426b2e | 2011-11-30 07:19:08 -0800 | [diff] [blame] | 68 | struct rndis_device *rdev; |
| 69 | |
Vitaly Kuznetsov | 0a1275c | 2016-05-13 13:55:23 +0200 | [diff] [blame] | 70 | if (!nvdev) |
Wenqi Ma | 792df87 | 2012-04-19 00:39:37 +0000 | [diff] [blame] | 71 | return; |
Haiyang Zhang | d426b2e | 2011-11-30 07:19:08 -0800 | [diff] [blame] | 72 | |
| 73 | rdev = nvdev->extension; |
| 74 | if (rdev == NULL) |
Wenqi Ma | 792df87 | 2012-04-19 00:39:37 +0000 | [diff] [blame] | 75 | return; |
Haiyang Zhang | d426b2e | 2011-11-30 07:19:08 -0800 | [diff] [blame] | 76 | |
Vitaly Kuznetsov | 0a1275c | 2016-05-13 13:55:23 +0200 | [diff] [blame] | 77 | if (ndev->flags & IFF_PROMISC) |
Haiyang Zhang | d426b2e | 2011-11-30 07:19:08 -0800 | [diff] [blame] | 78 | rndis_filter_set_packet_filter(rdev, |
| 79 | NDIS_PACKET_TYPE_PROMISCUOUS); |
| 80 | else |
| 81 | rndis_filter_set_packet_filter(rdev, |
| 82 | NDIS_PACKET_TYPE_BROADCAST | |
| 83 | NDIS_PACKET_TYPE_ALL_MULTICAST | |
| 84 | NDIS_PACKET_TYPE_DIRECTED); |
Haiyang Zhang | d426b2e | 2011-11-30 07:19:08 -0800 | [diff] [blame] | 85 | } |
| 86 | |
Greg Kroah-Hartman | 4e9bfef | 2009-07-15 12:45:20 -0700 | [diff] [blame] | 87 | static void netvsc_set_multicast_list(struct net_device *net) |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 88 | { |
Wenqi Ma | 792df87 | 2012-04-19 00:39:37 +0000 | [diff] [blame] | 89 | struct net_device_context *net_device_ctx = netdev_priv(net); |
Haiyang Zhang | d426b2e | 2011-11-30 07:19:08 -0800 | [diff] [blame] | 90 | |
Wenqi Ma | 792df87 | 2012-04-19 00:39:37 +0000 | [diff] [blame] | 91 | schedule_work(&net_device_ctx->work); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 94 | static int netvsc_open(struct net_device *net) |
| 95 | { |
Vitaly Kuznetsov | 2f5fa6c | 2016-06-03 17:51:00 +0200 | [diff] [blame] | 96 | struct netvsc_device *nvdev = net_device_to_netvsc_device(net); |
Haiyang Zhang | 891de74 | 2014-02-12 16:54:27 -0800 | [diff] [blame] | 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 */ |
Vitaly Kuznetsov | 2f5fa6c | 2016-06-03 17:51:00 +0200 | [diff] [blame] | 103 | ret = rndis_filter_open(nvdev); |
Haiyang Zhang | d515d0f | 2011-09-28 13:24:15 -0700 | [diff] [blame] | 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 | rdev = nvdev->extension; |
| 112 | if (!rdev->link_state) |
| 113 | netif_carrier_on(net); |
| 114 | |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 115 | return ret; |
| 116 | } |
| 117 | |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 118 | static int netvsc_close(struct net_device *net) |
| 119 | { |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 120 | struct net_device_context *net_device_ctx = netdev_priv(net); |
stephen hemminger | 545a8e7 | 2017-03-22 14:51:00 -0700 | [diff] [blame] | 121 | struct netvsc_device *nvdev = rtnl_dereference(net_device_ctx->nvdev); |
Greg Kroah-Hartman | 02fafbc | 2009-08-31 21:09:45 -0700 | [diff] [blame] | 122 | int ret; |
Haiyang Zhang | 2de8530 | 2015-07-13 13:09:16 -0700 | [diff] [blame] | 123 | u32 aread, awrite, i, msec = 10, retry = 0, retry_max = 20; |
| 124 | struct vmbus_channel *chn; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 125 | |
Haiyang Zhang | 0a28253 | 2012-02-02 07:17:59 +0000 | [diff] [blame] | 126 | netif_tx_disable(net); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 127 | |
Wenqi Ma | 792df87 | 2012-04-19 00:39:37 +0000 | [diff] [blame] | 128 | /* Make sure netvsc_set_multicast_list doesn't re-enable filter! */ |
| 129 | cancel_work_sync(&net_device_ctx->work); |
Vitaly Kuznetsov | 2f5fa6c | 2016-06-03 17:51:00 +0200 | [diff] [blame] | 130 | ret = rndis_filter_close(nvdev); |
Haiyang Zhang | 2de8530 | 2015-07-13 13:09:16 -0700 | [diff] [blame] | 131 | if (ret != 0) { |
Hank Janssen | eb335bc | 2011-03-29 13:58:48 -0700 | [diff] [blame] | 132 | netdev_err(net, "unable to close device (ret %d).\n", ret); |
Haiyang Zhang | 2de8530 | 2015-07-13 13:09:16 -0700 | [diff] [blame] | 133 | return ret; |
| 134 | } |
| 135 | |
| 136 | /* Ensure pending bytes in ring are read */ |
| 137 | while (true) { |
| 138 | aread = 0; |
| 139 | for (i = 0; i < nvdev->num_chn; i++) { |
stephen hemminger | b8b835a | 2017-01-24 13:06:07 -0800 | [diff] [blame] | 140 | chn = nvdev->chan_table[i].channel; |
Haiyang Zhang | 2de8530 | 2015-07-13 13:09:16 -0700 | [diff] [blame] | 141 | if (!chn) |
| 142 | continue; |
| 143 | |
| 144 | hv_get_ringbuffer_availbytes(&chn->inbound, &aread, |
| 145 | &awrite); |
| 146 | |
| 147 | if (aread) |
| 148 | break; |
| 149 | |
| 150 | hv_get_ringbuffer_availbytes(&chn->outbound, &aread, |
| 151 | &awrite); |
| 152 | |
| 153 | if (aread) |
| 154 | break; |
| 155 | } |
| 156 | |
| 157 | retry++; |
| 158 | if (retry > retry_max || aread == 0) |
| 159 | break; |
| 160 | |
| 161 | msleep(msec); |
| 162 | |
| 163 | if (msec < 1000) |
| 164 | msec *= 2; |
| 165 | } |
| 166 | |
| 167 | if (aread) { |
| 168 | netdev_err(net, "Ring buffer not empty after closing rndis\n"); |
| 169 | ret = -ETIMEDOUT; |
| 170 | } |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 171 | |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 172 | return ret; |
| 173 | } |
| 174 | |
KY Srinivasan | 8a00251 | 2014-03-08 19:23:14 -0800 | [diff] [blame] | 175 | static void *init_ppi_data(struct rndis_message *msg, u32 ppi_size, |
| 176 | int pkt_type) |
| 177 | { |
| 178 | struct rndis_packet *rndis_pkt; |
| 179 | struct rndis_per_packet_info *ppi; |
| 180 | |
| 181 | rndis_pkt = &msg->msg.pkt; |
| 182 | rndis_pkt->data_offset += ppi_size; |
| 183 | |
| 184 | ppi = (struct rndis_per_packet_info *)((void *)rndis_pkt + |
| 185 | rndis_pkt->per_pkt_info_offset + rndis_pkt->per_pkt_info_len); |
| 186 | |
| 187 | ppi->size = ppi_size; |
| 188 | ppi->type = pkt_type; |
| 189 | ppi->ppi_offset = sizeof(struct rndis_per_packet_info); |
| 190 | |
| 191 | rndis_pkt->per_pkt_info_len += ppi_size; |
| 192 | |
| 193 | return ppi; |
| 194 | } |
| 195 | |
Haiyang Zhang | f72860a | 2017-04-12 11:45:18 -0700 | [diff] [blame] | 196 | /* Azure hosts don't support non-TCP port numbers in hashing yet. We compute |
| 197 | * hash for non-TCP traffic with only IP numbers. |
| 198 | */ |
| 199 | static inline u32 netvsc_get_hash(struct sk_buff *skb, struct sock *sk) |
| 200 | { |
| 201 | struct flow_keys flow; |
| 202 | u32 hash; |
| 203 | static u32 hashrnd __read_mostly; |
| 204 | |
| 205 | net_get_random_once(&hashrnd, sizeof(hashrnd)); |
| 206 | |
| 207 | if (!skb_flow_dissect_flow_keys(skb, &flow, 0)) |
| 208 | return 0; |
| 209 | |
| 210 | if (flow.basic.ip_proto == IPPROTO_TCP) { |
| 211 | return skb_get_hash(skb); |
| 212 | } else { |
| 213 | if (flow.basic.n_proto == htons(ETH_P_IP)) |
| 214 | hash = jhash2((u32 *)&flow.addrs.v4addrs, 2, hashrnd); |
| 215 | else if (flow.basic.n_proto == htons(ETH_P_IPV6)) |
| 216 | hash = jhash2((u32 *)&flow.addrs.v6addrs, 8, hashrnd); |
| 217 | else |
| 218 | hash = 0; |
| 219 | |
| 220 | skb_set_hash(skb, hash, PKT_HASH_TYPE_L3); |
| 221 | } |
| 222 | |
| 223 | return hash; |
| 224 | } |
| 225 | |
Haiyang Zhang | 8db91f6 | 2017-04-12 11:35:05 -0700 | [diff] [blame] | 226 | static inline int netvsc_get_tx_queue(struct net_device *ndev, |
| 227 | struct sk_buff *skb, int old_idx) |
| 228 | { |
| 229 | const struct net_device_context *ndc = netdev_priv(ndev); |
| 230 | struct sock *sk = skb->sk; |
| 231 | int q_idx; |
| 232 | |
Haiyang Zhang | f72860a | 2017-04-12 11:45:18 -0700 | [diff] [blame] | 233 | q_idx = ndc->tx_send_table[netvsc_get_hash(skb, sk) & |
Haiyang Zhang | 8db91f6 | 2017-04-12 11:35:05 -0700 | [diff] [blame] | 234 | (VRSS_SEND_TAB_SIZE - 1)]; |
| 235 | |
| 236 | /* If queue index changed record the new value */ |
| 237 | if (q_idx != old_idx && |
| 238 | sk && sk_fullsock(sk) && rcu_access_pointer(sk->sk_dst_cache)) |
| 239 | sk_tx_queue_set(sk, q_idx); |
| 240 | |
| 241 | return q_idx; |
| 242 | } |
| 243 | |
stephen hemminger | d8e18ee | 2017-01-24 13:06:05 -0800 | [diff] [blame] | 244 | /* |
| 245 | * Select queue for transmit. |
| 246 | * |
| 247 | * If a valid queue has already been assigned, then use that. |
| 248 | * Otherwise compute tx queue based on hash and the send table. |
| 249 | * |
| 250 | * This is basically similar to default (__netdev_pick_tx) with the added step |
| 251 | * of using the host send_table when no other queue has been assigned. |
| 252 | * |
| 253 | * TODO support XPS - but get_xps_queue not exported |
| 254 | */ |
Haiyang Zhang | 5b54dac | 2014-04-21 10:20:28 -0700 | [diff] [blame] | 255 | static u16 netvsc_select_queue(struct net_device *ndev, struct sk_buff *skb, |
| 256 | void *accel_priv, select_queue_fallback_t fallback) |
| 257 | { |
stephen hemminger | 7ce1012 | 2017-03-09 14:58:29 -0800 | [diff] [blame] | 258 | unsigned int num_tx_queues = ndev->real_num_tx_queues; |
Haiyang Zhang | 8db91f6 | 2017-04-12 11:35:05 -0700 | [diff] [blame] | 259 | int q_idx = sk_tx_queue_get(skb->sk); |
Haiyang Zhang | 5b54dac | 2014-04-21 10:20:28 -0700 | [diff] [blame] | 260 | |
Haiyang Zhang | 8db91f6 | 2017-04-12 11:35:05 -0700 | [diff] [blame] | 261 | if (q_idx < 0 || skb->ooo_okay) { |
| 262 | /* If forwarding a packet, we use the recorded queue when |
| 263 | * available for better cache locality. |
| 264 | */ |
| 265 | if (skb_rx_queue_recorded(skb)) |
| 266 | q_idx = skb_get_rx_queue(skb); |
| 267 | else |
| 268 | q_idx = netvsc_get_tx_queue(ndev, skb, q_idx); |
stephen hemminger | d8e18ee | 2017-01-24 13:06:05 -0800 | [diff] [blame] | 269 | } |
| 270 | |
Haiyang Zhang | 8db91f6 | 2017-04-12 11:35:05 -0700 | [diff] [blame] | 271 | while (unlikely(q_idx >= num_tx_queues)) |
| 272 | q_idx -= num_tx_queues; |
| 273 | |
Haiyang Zhang | 5b54dac | 2014-04-21 10:20:28 -0700 | [diff] [blame] | 274 | return q_idx; |
| 275 | } |
| 276 | |
KY Srinivasan | 54a7357 | 2014-03-08 19:23:13 -0800 | [diff] [blame] | 277 | static u32 fill_pg_buf(struct page *page, u32 offset, u32 len, |
| 278 | struct hv_page_buffer *pb) |
| 279 | { |
| 280 | int j = 0; |
| 281 | |
| 282 | /* Deal with compund pages by ignoring unused part |
| 283 | * of the page. |
| 284 | */ |
| 285 | page += (offset >> PAGE_SHIFT); |
| 286 | offset &= ~PAGE_MASK; |
| 287 | |
| 288 | while (len > 0) { |
| 289 | unsigned long bytes; |
| 290 | |
| 291 | bytes = PAGE_SIZE - offset; |
| 292 | if (bytes > len) |
| 293 | bytes = len; |
| 294 | pb[j].pfn = page_to_pfn(page); |
| 295 | pb[j].offset = offset; |
| 296 | pb[j].len = bytes; |
| 297 | |
| 298 | offset += bytes; |
| 299 | len -= bytes; |
| 300 | |
| 301 | if (offset == PAGE_SIZE && len) { |
| 302 | page++; |
| 303 | offset = 0; |
| 304 | j++; |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | return j + 1; |
| 309 | } |
| 310 | |
KY Srinivasan | 8a00251 | 2014-03-08 19:23:14 -0800 | [diff] [blame] | 311 | static u32 init_page_array(void *hdr, u32 len, struct sk_buff *skb, |
KY Srinivasan | a9f2e2d | 2015-12-01 16:43:13 -0800 | [diff] [blame] | 312 | struct hv_netvsc_packet *packet, |
| 313 | struct hv_page_buffer **page_buf) |
KY Srinivasan | 54a7357 | 2014-03-08 19:23:13 -0800 | [diff] [blame] | 314 | { |
KY Srinivasan | a9f2e2d | 2015-12-01 16:43:13 -0800 | [diff] [blame] | 315 | struct hv_page_buffer *pb = *page_buf; |
KY Srinivasan | 54a7357 | 2014-03-08 19:23:13 -0800 | [diff] [blame] | 316 | u32 slots_used = 0; |
| 317 | char *data = skb->data; |
| 318 | int frags = skb_shinfo(skb)->nr_frags; |
| 319 | int i; |
| 320 | |
| 321 | /* The packet is laid out thus: |
Haiyang Zhang | aa0a34b | 2015-04-13 16:34:35 -0700 | [diff] [blame] | 322 | * 1. hdr: RNDIS header and PPI |
KY Srinivasan | 54a7357 | 2014-03-08 19:23:13 -0800 | [diff] [blame] | 323 | * 2. skb linear data |
| 324 | * 3. skb fragment data |
| 325 | */ |
| 326 | if (hdr != NULL) |
| 327 | slots_used += fill_pg_buf(virt_to_page(hdr), |
| 328 | offset_in_page(hdr), |
| 329 | len, &pb[slots_used]); |
| 330 | |
Haiyang Zhang | aa0a34b | 2015-04-13 16:34:35 -0700 | [diff] [blame] | 331 | packet->rmsg_size = len; |
| 332 | packet->rmsg_pgcnt = slots_used; |
| 333 | |
KY Srinivasan | 54a7357 | 2014-03-08 19:23:13 -0800 | [diff] [blame] | 334 | slots_used += fill_pg_buf(virt_to_page(data), |
| 335 | offset_in_page(data), |
| 336 | skb_headlen(skb), &pb[slots_used]); |
| 337 | |
| 338 | for (i = 0; i < frags; i++) { |
| 339 | skb_frag_t *frag = skb_shinfo(skb)->frags + i; |
| 340 | |
| 341 | slots_used += fill_pg_buf(skb_frag_page(frag), |
| 342 | frag->page_offset, |
| 343 | skb_frag_size(frag), &pb[slots_used]); |
| 344 | } |
KY Srinivasan | 8a00251 | 2014-03-08 19:23:14 -0800 | [diff] [blame] | 345 | return slots_used; |
KY Srinivasan | 54a7357 | 2014-03-08 19:23:13 -0800 | [diff] [blame] | 346 | } |
| 347 | |
stephen hemminger | 60b8666 | 2017-06-08 16:21:18 -0700 | [diff] [blame^] | 348 | /* Estimate number of page buffers neede to transmit |
| 349 | * Need at most 2 for RNDIS header plus skb body and fragments. |
| 350 | */ |
| 351 | static unsigned int netvsc_get_slots(const struct sk_buff *skb) |
KY Srinivasan | 54a7357 | 2014-03-08 19:23:13 -0800 | [diff] [blame] | 352 | { |
stephen hemminger | 60b8666 | 2017-06-08 16:21:18 -0700 | [diff] [blame^] | 353 | return PFN_UP(offset_in_page(skb->data) + skb_headlen(skb)) |
| 354 | + skb_shinfo(skb)->nr_frags |
| 355 | + 2; |
KY Srinivasan | 54a7357 | 2014-03-08 19:23:13 -0800 | [diff] [blame] | 356 | } |
| 357 | |
stephen hemminger | 23312a3 | 2017-01-24 13:05:59 -0800 | [diff] [blame] | 358 | static u32 net_checksum_info(struct sk_buff *skb) |
KY Srinivasan | 08cd04b | 2014-03-08 19:23:17 -0800 | [diff] [blame] | 359 | { |
stephen hemminger | 23312a3 | 2017-01-24 13:05:59 -0800 | [diff] [blame] | 360 | if (skb->protocol == htons(ETH_P_IP)) { |
| 361 | struct iphdr *ip = ip_hdr(skb); |
KY Srinivasan | 08cd04b | 2014-03-08 19:23:17 -0800 | [diff] [blame] | 362 | |
stephen hemminger | 23312a3 | 2017-01-24 13:05:59 -0800 | [diff] [blame] | 363 | if (ip->protocol == IPPROTO_TCP) |
| 364 | return TRANSPORT_INFO_IPV4_TCP; |
| 365 | else if (ip->protocol == IPPROTO_UDP) |
| 366 | return TRANSPORT_INFO_IPV4_UDP; |
KY Srinivasan | 08cd04b | 2014-03-08 19:23:17 -0800 | [diff] [blame] | 367 | } else { |
stephen hemminger | 23312a3 | 2017-01-24 13:05:59 -0800 | [diff] [blame] | 368 | struct ipv6hdr *ip6 = ipv6_hdr(skb); |
| 369 | |
| 370 | if (ip6->nexthdr == IPPROTO_TCP) |
| 371 | return TRANSPORT_INFO_IPV6_TCP; |
KY Srinivasan | 08cd04b | 2014-03-08 19:23:17 -0800 | [diff] [blame] | 372 | else if (ipv6_hdr(skb)->nexthdr == IPPROTO_UDP) |
stephen hemminger | 23312a3 | 2017-01-24 13:05:59 -0800 | [diff] [blame] | 373 | return TRANSPORT_INFO_IPV6_UDP; |
KY Srinivasan | 08cd04b | 2014-03-08 19:23:17 -0800 | [diff] [blame] | 374 | } |
| 375 | |
stephen hemminger | 23312a3 | 2017-01-24 13:05:59 -0800 | [diff] [blame] | 376 | return TRANSPORT_INFO_NOT_IP; |
KY Srinivasan | 08cd04b | 2014-03-08 19:23:17 -0800 | [diff] [blame] | 377 | } |
| 378 | |
Greg Kroah-Hartman | 02fafbc | 2009-08-31 21:09:45 -0700 | [diff] [blame] | 379 | 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] | 380 | { |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 381 | struct net_device_context *net_device_ctx = netdev_priv(net); |
Vitaly Kuznetsov | 981a1bd | 2015-04-08 17:54:05 +0200 | [diff] [blame] | 382 | struct hv_netvsc_packet *packet = NULL; |
Greg Kroah-Hartman | 02fafbc | 2009-08-31 21:09:45 -0700 | [diff] [blame] | 383 | int ret; |
KY Srinivasan | 8a00251 | 2014-03-08 19:23:14 -0800 | [diff] [blame] | 384 | unsigned int num_data_pgs; |
| 385 | struct rndis_message *rndis_msg; |
| 386 | struct rndis_packet *rndis_pkt; |
| 387 | u32 rndis_msg_size; |
KY Srinivasan | 8a00251 | 2014-03-08 19:23:14 -0800 | [diff] [blame] | 388 | struct rndis_per_packet_info *ppi; |
Haiyang Zhang | 307f099 | 2014-05-21 12:55:39 -0700 | [diff] [blame] | 389 | u32 hash; |
KY Srinivasan | b08cc79 | 2015-03-29 21:08:42 -0700 | [diff] [blame] | 390 | struct hv_page_buffer page_buf[MAX_PAGE_BUFFER_COUNT]; |
KY Srinivasan | a9f2e2d | 2015-12-01 16:43:13 -0800 | [diff] [blame] | 391 | struct hv_page_buffer *pb = page_buf; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 392 | |
stephen hemminger | 60b8666 | 2017-06-08 16:21:18 -0700 | [diff] [blame^] | 393 | /* We can only transmit MAX_PAGE_BUFFER_COUNT number |
Vitaly Kuznetsov | e88f7e0 | 2015-04-08 17:54:06 +0200 | [diff] [blame] | 394 | * of pages in a single packet. If skb is scattered around |
| 395 | * more pages we try linearizing it. |
KY Srinivasan | 54a7357 | 2014-03-08 19:23:13 -0800 | [diff] [blame] | 396 | */ |
stephen hemminger | 60b8666 | 2017-06-08 16:21:18 -0700 | [diff] [blame^] | 397 | num_data_pgs = netvsc_get_slots(skb); |
Stephen Hemminger | 0ab0514 | 2016-08-23 12:17:52 -0700 | [diff] [blame] | 398 | if (unlikely(num_data_pgs > MAX_PAGE_BUFFER_COUNT)) { |
Stephen Hemminger | 4323b47 | 2016-08-23 12:17:57 -0700 | [diff] [blame] | 399 | ++net_device_ctx->eth_stats.tx_scattered; |
| 400 | |
| 401 | if (skb_linearize(skb)) |
| 402 | goto no_memory; |
Stephen Hemminger | 0ab0514 | 2016-08-23 12:17:52 -0700 | [diff] [blame] | 403 | |
stephen hemminger | 60b8666 | 2017-06-08 16:21:18 -0700 | [diff] [blame^] | 404 | num_data_pgs = netvsc_get_slots(skb); |
Stephen Hemminger | 0ab0514 | 2016-08-23 12:17:52 -0700 | [diff] [blame] | 405 | if (num_data_pgs > MAX_PAGE_BUFFER_COUNT) { |
Stephen Hemminger | 4323b47 | 2016-08-23 12:17:57 -0700 | [diff] [blame] | 406 | ++net_device_ctx->eth_stats.tx_too_big; |
Stephen Hemminger | 0ab0514 | 2016-08-23 12:17:52 -0700 | [diff] [blame] | 407 | goto drop; |
| 408 | } |
KY Srinivasan | 54a7357 | 2014-03-08 19:23:13 -0800 | [diff] [blame] | 409 | } |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 410 | |
KY Srinivasan | c0eb454 | 2015-12-01 16:43:10 -0800 | [diff] [blame] | 411 | /* |
| 412 | * Place the rndis header in the skb head room and |
| 413 | * the skb->cb will be used for hv_netvsc_packet |
| 414 | * structure. |
| 415 | */ |
| 416 | ret = skb_cow_head(skb, RNDIS_AND_PPI_SIZE); |
Stephen Hemminger | 4323b47 | 2016-08-23 12:17:57 -0700 | [diff] [blame] | 417 | if (ret) |
| 418 | goto no_memory; |
| 419 | |
KY Srinivasan | c0eb454 | 2015-12-01 16:43:10 -0800 | [diff] [blame] | 420 | /* Use the skb control buffer for building up the packet */ |
| 421 | BUILD_BUG_ON(sizeof(struct hv_netvsc_packet) > |
| 422 | FIELD_SIZEOF(struct sk_buff, cb)); |
| 423 | packet = (struct hv_netvsc_packet *)skb->cb; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 424 | |
Haiyang Zhang | 5b54dac | 2014-04-21 10:20:28 -0700 | [diff] [blame] | 425 | packet->q_idx = skb_get_queue_mapping(skb); |
| 426 | |
Haiyang Zhang | 4d447c9 | 2011-12-15 13:45:17 -0800 | [diff] [blame] | 427 | packet->total_data_buflen = skb->len; |
stephen hemminger | 793e395 | 2017-01-24 13:06:12 -0800 | [diff] [blame] | 428 | packet->total_bytes = skb->len; |
| 429 | packet->total_packets = 1; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 430 | |
KY Srinivasan | c0eb454 | 2015-12-01 16:43:10 -0800 | [diff] [blame] | 431 | rndis_msg = (struct rndis_message *)skb->head; |
KY Srinivasan | b08cc79 | 2015-03-29 21:08:42 -0700 | [diff] [blame] | 432 | |
KY Srinivasan | 2447676 | 2015-12-01 16:43:06 -0800 | [diff] [blame] | 433 | memset(rndis_msg, 0, RNDIS_AND_PPI_SIZE); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 434 | |
KY Srinivasan | 8a00251 | 2014-03-08 19:23:14 -0800 | [diff] [blame] | 435 | /* Add the rndis header */ |
KY Srinivasan | 8a00251 | 2014-03-08 19:23:14 -0800 | [diff] [blame] | 436 | rndis_msg->ndis_msg_type = RNDIS_MSG_PACKET; |
| 437 | rndis_msg->msg_len = packet->total_data_buflen; |
| 438 | rndis_pkt = &rndis_msg->msg.pkt; |
| 439 | rndis_pkt->data_offset = sizeof(struct rndis_packet); |
| 440 | rndis_pkt->data_len = packet->total_data_buflen; |
| 441 | rndis_pkt->per_pkt_info_offset = sizeof(struct rndis_packet); |
| 442 | |
| 443 | rndis_msg_size = RNDIS_MESSAGE_SIZE(struct rndis_packet); |
| 444 | |
Haiyang Zhang | 307f099 | 2014-05-21 12:55:39 -0700 | [diff] [blame] | 445 | hash = skb_get_hash_raw(skb); |
| 446 | if (hash != 0 && net->real_num_tx_queues > 1) { |
| 447 | rndis_msg_size += NDIS_HASH_PPI_SIZE; |
| 448 | ppi = init_ppi_data(rndis_msg, NDIS_HASH_PPI_SIZE, |
| 449 | NBL_HASH_VALUE); |
| 450 | *(u32 *)((void *)ppi + ppi->ppi_offset) = hash; |
| 451 | } |
| 452 | |
Stephen Hemminger | 0ab0514 | 2016-08-23 12:17:52 -0700 | [diff] [blame] | 453 | if (skb_vlan_tag_present(skb)) { |
KY Srinivasan | 8a00251 | 2014-03-08 19:23:14 -0800 | [diff] [blame] | 454 | struct ndis_pkt_8021q_info *vlan; |
| 455 | |
| 456 | rndis_msg_size += NDIS_VLAN_PPI_SIZE; |
| 457 | ppi = init_ppi_data(rndis_msg, NDIS_VLAN_PPI_SIZE, |
| 458 | IEEE_8021Q_INFO); |
| 459 | vlan = (struct ndis_pkt_8021q_info *)((void *)ppi + |
| 460 | ppi->ppi_offset); |
KY Srinivasan | 760d1e3 | 2015-12-01 16:43:19 -0800 | [diff] [blame] | 461 | vlan->vlanid = skb->vlan_tci & VLAN_VID_MASK; |
| 462 | vlan->pri = (skb->vlan_tci & VLAN_PRIO_MASK) >> |
KY Srinivasan | 8a00251 | 2014-03-08 19:23:14 -0800 | [diff] [blame] | 463 | VLAN_PRIO_SHIFT; |
| 464 | } |
| 465 | |
stephen hemminger | 23312a3 | 2017-01-24 13:05:59 -0800 | [diff] [blame] | 466 | if (skb_is_gso(skb)) { |
Stephen Hemminger | 0ab0514 | 2016-08-23 12:17:52 -0700 | [diff] [blame] | 467 | struct ndis_tcp_lso_info *lso_info; |
| 468 | |
| 469 | rndis_msg_size += NDIS_LSO_PPI_SIZE; |
| 470 | ppi = init_ppi_data(rndis_msg, NDIS_LSO_PPI_SIZE, |
| 471 | TCP_LARGESEND_PKTINFO); |
| 472 | |
| 473 | lso_info = (struct ndis_tcp_lso_info *)((void *)ppi + |
| 474 | ppi->ppi_offset); |
| 475 | |
| 476 | lso_info->lso_v2_transmit.type = NDIS_TCP_LARGE_SEND_OFFLOAD_V2_TYPE; |
stephen hemminger | 23312a3 | 2017-01-24 13:05:59 -0800 | [diff] [blame] | 477 | if (skb->protocol == htons(ETH_P_IP)) { |
Stephen Hemminger | 0ab0514 | 2016-08-23 12:17:52 -0700 | [diff] [blame] | 478 | lso_info->lso_v2_transmit.ip_version = |
| 479 | NDIS_TCP_LARGE_SEND_OFFLOAD_IPV4; |
| 480 | ip_hdr(skb)->tot_len = 0; |
| 481 | ip_hdr(skb)->check = 0; |
| 482 | tcp_hdr(skb)->check = |
| 483 | ~csum_tcpudp_magic(ip_hdr(skb)->saddr, |
| 484 | ip_hdr(skb)->daddr, 0, IPPROTO_TCP, 0); |
| 485 | } else { |
| 486 | lso_info->lso_v2_transmit.ip_version = |
| 487 | NDIS_TCP_LARGE_SEND_OFFLOAD_IPV6; |
| 488 | ipv6_hdr(skb)->payload_len = 0; |
| 489 | tcp_hdr(skb)->check = |
| 490 | ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
| 491 | &ipv6_hdr(skb)->daddr, 0, IPPROTO_TCP, 0); |
| 492 | } |
stephen hemminger | 23312a3 | 2017-01-24 13:05:59 -0800 | [diff] [blame] | 493 | lso_info->lso_v2_transmit.tcp_header_offset = skb_transport_offset(skb); |
Stephen Hemminger | 0ab0514 | 2016-08-23 12:17:52 -0700 | [diff] [blame] | 494 | lso_info->lso_v2_transmit.mss = skb_shinfo(skb)->gso_size; |
stephen hemminger | ad19bc8 | 2016-10-11 14:03:07 -0700 | [diff] [blame] | 495 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
stephen hemminger | 23312a3 | 2017-01-24 13:05:59 -0800 | [diff] [blame] | 496 | if (net_checksum_info(skb) & net_device_ctx->tx_checksum_mask) { |
| 497 | struct ndis_tcp_ip_checksum_info *csum_info; |
| 498 | |
stephen hemminger | ad19bc8 | 2016-10-11 14:03:07 -0700 | [diff] [blame] | 499 | rndis_msg_size += NDIS_CSUM_PPI_SIZE; |
| 500 | ppi = init_ppi_data(rndis_msg, NDIS_CSUM_PPI_SIZE, |
| 501 | TCPIP_CHKSUM_PKTINFO); |
| 502 | |
| 503 | csum_info = (struct ndis_tcp_ip_checksum_info *)((void *)ppi + |
| 504 | ppi->ppi_offset); |
| 505 | |
stephen hemminger | 23312a3 | 2017-01-24 13:05:59 -0800 | [diff] [blame] | 506 | csum_info->transmit.tcp_header_offset = skb_transport_offset(skb); |
| 507 | |
| 508 | if (skb->protocol == htons(ETH_P_IP)) { |
stephen hemminger | ad19bc8 | 2016-10-11 14:03:07 -0700 | [diff] [blame] | 509 | csum_info->transmit.is_ipv4 = 1; |
stephen hemminger | 23312a3 | 2017-01-24 13:05:59 -0800 | [diff] [blame] | 510 | |
| 511 | if (ip_hdr(skb)->protocol == IPPROTO_TCP) |
| 512 | csum_info->transmit.tcp_checksum = 1; |
| 513 | else |
| 514 | csum_info->transmit.udp_checksum = 1; |
| 515 | } else { |
stephen hemminger | ad19bc8 | 2016-10-11 14:03:07 -0700 | [diff] [blame] | 516 | csum_info->transmit.is_ipv6 = 1; |
| 517 | |
stephen hemminger | 23312a3 | 2017-01-24 13:05:59 -0800 | [diff] [blame] | 518 | if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) |
| 519 | csum_info->transmit.tcp_checksum = 1; |
| 520 | else |
| 521 | csum_info->transmit.udp_checksum = 1; |
| 522 | } |
stephen hemminger | ad19bc8 | 2016-10-11 14:03:07 -0700 | [diff] [blame] | 523 | } else { |
stephen hemminger | 23312a3 | 2017-01-24 13:05:59 -0800 | [diff] [blame] | 524 | /* Can't do offload of this type of checksum */ |
stephen hemminger | ad19bc8 | 2016-10-11 14:03:07 -0700 | [diff] [blame] | 525 | if (skb_checksum_help(skb)) |
| 526 | goto drop; |
| 527 | } |
Stephen Hemminger | 0ab0514 | 2016-08-23 12:17:52 -0700 | [diff] [blame] | 528 | } |
KY Srinivasan | 08cd04b | 2014-03-08 19:23:17 -0800 | [diff] [blame] | 529 | |
KY Srinivasan | 8a00251 | 2014-03-08 19:23:14 -0800 | [diff] [blame] | 530 | /* Start filling in the page buffers with the rndis hdr */ |
| 531 | rndis_msg->msg_len += rndis_msg_size; |
Haiyang Zhang | 942396b | 2014-10-22 13:47:18 -0700 | [diff] [blame] | 532 | packet->total_data_buflen = rndis_msg->msg_len; |
KY Srinivasan | 8a00251 | 2014-03-08 19:23:14 -0800 | [diff] [blame] | 533 | packet->page_buf_cnt = init_page_array(rndis_msg, rndis_msg_size, |
KY Srinivasan | a9f2e2d | 2015-12-01 16:43:13 -0800 | [diff] [blame] | 534 | skb, packet, &pb); |
KY Srinivasan | 8a00251 | 2014-03-08 19:23:14 -0800 | [diff] [blame] | 535 | |
sixiao@microsoft.com | 76d13b5 | 2016-02-17 16:43:59 -0800 | [diff] [blame] | 536 | /* timestamp packet in software */ |
| 537 | skb_tx_timestamp(skb); |
KY Srinivasan | 3a3d9a0 | 2015-12-01 16:43:14 -0800 | [diff] [blame] | 538 | ret = netvsc_send(net_device_ctx->device_ctx, packet, |
| 539 | rndis_msg, &pb, skb); |
stephen hemminger | 793e395 | 2017-01-24 13:06:12 -0800 | [diff] [blame] | 540 | if (likely(ret == 0)) |
Stephen Hemminger | 0ab0514 | 2016-08-23 12:17:52 -0700 | [diff] [blame] | 541 | return NETDEV_TX_OK; |
Stephen Hemminger | 4323b47 | 2016-08-23 12:17:57 -0700 | [diff] [blame] | 542 | |
| 543 | if (ret == -EAGAIN) { |
| 544 | ++net_device_ctx->eth_stats.tx_busy; |
Stephen Hemminger | 0ab0514 | 2016-08-23 12:17:52 -0700 | [diff] [blame] | 545 | return NETDEV_TX_BUSY; |
Stephen Hemminger | 4323b47 | 2016-08-23 12:17:57 -0700 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | if (ret == -ENOSPC) |
| 549 | ++net_device_ctx->eth_stats.tx_no_space; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 550 | |
Stephen Hemminger | 0ab0514 | 2016-08-23 12:17:52 -0700 | [diff] [blame] | 551 | drop: |
| 552 | dev_kfree_skb_any(skb); |
| 553 | net->stats.tx_dropped++; |
| 554 | |
| 555 | return NETDEV_TX_OK; |
Stephen Hemminger | 4323b47 | 2016-08-23 12:17:57 -0700 | [diff] [blame] | 556 | |
| 557 | no_memory: |
| 558 | ++net_device_ctx->eth_stats.tx_no_memory; |
| 559 | goto drop; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 560 | } |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 561 | /* |
Greg Kroah-Hartman | 02fafbc | 2009-08-31 21:09:45 -0700 | [diff] [blame] | 562 | * netvsc_linkstatus_callback - Link up/down notification |
| 563 | */ |
K. Y. Srinivasan | 90ef117 | 2011-05-12 19:34:50 -0700 | [diff] [blame] | 564 | void netvsc_linkstatus_callback(struct hv_device *device_obj, |
Haiyang Zhang | 3a494e7 | 2014-06-19 18:34:36 -0700 | [diff] [blame] | 565 | struct rndis_message *resp) |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 566 | { |
Haiyang Zhang | 3a494e7 | 2014-06-19 18:34:36 -0700 | [diff] [blame] | 567 | struct rndis_indicate_status *indicate = &resp->msg.indicate_status; |
K. Y. Srinivasan | 2ddd5e5f | 2011-09-13 10:59:49 -0700 | [diff] [blame] | 568 | struct net_device *net; |
Haiyang Zhang | c996edc | 2011-04-06 15:18:00 -0700 | [diff] [blame] | 569 | struct net_device_context *ndev_ctx; |
Vitaly Kuznetsov | 27a70af | 2015-11-27 11:39:55 +0100 | [diff] [blame] | 570 | struct netvsc_reconfig *event; |
| 571 | unsigned long flags; |
| 572 | |
Haiyang Zhang | 7f5d5af | 2016-08-04 10:42:15 -0700 | [diff] [blame] | 573 | net = hv_get_drvdata(device_obj); |
| 574 | |
| 575 | if (!net) |
| 576 | return; |
| 577 | |
| 578 | ndev_ctx = netdev_priv(net); |
| 579 | |
| 580 | /* Update the physical link speed when changing to another vSwitch */ |
| 581 | if (indicate->status == RNDIS_STATUS_LINK_SPEED_CHANGE) { |
| 582 | u32 speed; |
| 583 | |
| 584 | speed = *(u32 *)((void *)indicate + indicate-> |
| 585 | status_buf_offset) / 10000; |
| 586 | ndev_ctx->speed = speed; |
| 587 | return; |
| 588 | } |
| 589 | |
| 590 | /* Handle these link change statuses below */ |
Vitaly Kuznetsov | 27a70af | 2015-11-27 11:39:55 +0100 | [diff] [blame] | 591 | if (indicate->status != RNDIS_STATUS_NETWORK_CHANGE && |
| 592 | indicate->status != RNDIS_STATUS_MEDIA_CONNECT && |
| 593 | indicate->status != RNDIS_STATUS_MEDIA_DISCONNECT) |
| 594 | return; |
K. Y. Srinivasan | 2ddd5e5f | 2011-09-13 10:59:49 -0700 | [diff] [blame] | 595 | |
Haiyang Zhang | 7f5d5af | 2016-08-04 10:42:15 -0700 | [diff] [blame] | 596 | if (net->reg_state != NETREG_REGISTERED) |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 597 | return; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 598 | |
Vitaly Kuznetsov | 27a70af | 2015-11-27 11:39:55 +0100 | [diff] [blame] | 599 | event = kzalloc(sizeof(*event), GFP_ATOMIC); |
| 600 | if (!event) |
| 601 | return; |
| 602 | event->event = indicate->status; |
| 603 | |
| 604 | spin_lock_irqsave(&ndev_ctx->lock, flags); |
| 605 | list_add_tail(&event->list, &ndev_ctx->reconfig_events); |
| 606 | spin_unlock_irqrestore(&ndev_ctx->lock, flags); |
| 607 | |
| 608 | schedule_delayed_work(&ndev_ctx->dwork, 0); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 609 | } |
| 610 | |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 611 | static struct sk_buff *netvsc_alloc_recv_skb(struct net_device *net, |
stephen hemminger | e91e7dd | 2017-02-27 10:26:51 -0800 | [diff] [blame] | 612 | struct napi_struct *napi, |
stephen hemminger | dc54a08 | 2017-01-24 13:06:08 -0800 | [diff] [blame] | 613 | const struct ndis_tcp_ip_checksum_info *csum_info, |
| 614 | const struct ndis_pkt_8021q_info *vlan, |
| 615 | void *data, u32 buflen) |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 616 | { |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 617 | struct sk_buff *skb; |
K. Y. Srinivasan | 2ddd5e5f | 2011-09-13 10:59:49 -0700 | [diff] [blame] | 618 | |
stephen hemminger | e91e7dd | 2017-02-27 10:26:51 -0800 | [diff] [blame] | 619 | skb = napi_alloc_skb(napi, buflen); |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 620 | if (!skb) |
| 621 | return skb; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 622 | |
Greg Kroah-Hartman | 02fafbc | 2009-08-31 21:09:45 -0700 | [diff] [blame] | 623 | /* |
| 624 | * Copy to skb. This copy is needed here since the memory pointed by |
| 625 | * hv_netvsc_packet cannot be deallocated |
| 626 | */ |
stephen hemminger | dc54a08 | 2017-01-24 13:06:08 -0800 | [diff] [blame] | 627 | memcpy(skb_put(skb, buflen), data, buflen); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 628 | |
| 629 | skb->protocol = eth_type_trans(skb, net); |
Stephen Hemminger | e52fed7 | 2016-10-23 21:32:47 -0700 | [diff] [blame] | 630 | |
| 631 | /* skb is already created with CHECKSUM_NONE */ |
| 632 | skb_checksum_none_assert(skb); |
| 633 | |
| 634 | /* |
| 635 | * In Linux, the IP checksum is always checked. |
| 636 | * Do L4 checksum offload if enabled and present. |
| 637 | */ |
| 638 | if (csum_info && (net->features & NETIF_F_RXCSUM)) { |
| 639 | if (csum_info->receive.tcp_checksum_succeeded || |
| 640 | csum_info->receive.udp_checksum_succeeded) |
KY Srinivasan | e3d605e | 2014-03-08 19:23:16 -0800 | [diff] [blame] | 641 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
KY Srinivasan | e3d605e | 2014-03-08 19:23:16 -0800 | [diff] [blame] | 642 | } |
| 643 | |
stephen hemminger | dc54a08 | 2017-01-24 13:06:08 -0800 | [diff] [blame] | 644 | if (vlan) { |
| 645 | u16 vlan_tci = vlan->vlanid | (vlan->pri << VLAN_PRIO_SHIFT); |
| 646 | |
Haiyang Zhang | 93725cb | 2013-06-17 15:36:49 -0700 | [diff] [blame] | 647 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), |
KY Srinivasan | 760d1e3 | 2015-12-01 16:43:19 -0800 | [diff] [blame] | 648 | vlan_tci); |
stephen hemminger | dc54a08 | 2017-01-24 13:06:08 -0800 | [diff] [blame] | 649 | } |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 650 | |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 651 | return skb; |
| 652 | } |
| 653 | |
| 654 | /* |
| 655 | * netvsc_recv_callback - Callback when we receive a packet from the |
| 656 | * "wire" on the specified device. |
| 657 | */ |
stephen hemminger | dc54a08 | 2017-01-24 13:06:08 -0800 | [diff] [blame] | 658 | int netvsc_recv_callback(struct net_device *net, |
| 659 | struct vmbus_channel *channel, |
| 660 | void *data, u32 len, |
| 661 | const struct ndis_tcp_ip_checksum_info *csum_info, |
| 662 | const struct ndis_pkt_8021q_info *vlan) |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 663 | { |
Vitaly Kuznetsov | 3d541ac | 2016-05-13 13:55:22 +0200 | [diff] [blame] | 664 | struct net_device_context *net_device_ctx = netdev_priv(net); |
stephen hemminger | 545a8e7 | 2017-03-22 14:51:00 -0700 | [diff] [blame] | 665 | struct netvsc_device *net_device; |
stephen hemminger | 742fe54 | 2017-02-27 10:26:50 -0800 | [diff] [blame] | 666 | u16 q_idx = channel->offermsg.offer.sub_channel_index; |
stephen hemminger | 545a8e7 | 2017-03-22 14:51:00 -0700 | [diff] [blame] | 667 | struct netvsc_channel *nvchan; |
Stephen Hemminger | f207c10 | 2016-09-22 16:56:33 -0700 | [diff] [blame] | 668 | struct net_device *vf_netdev; |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 669 | struct sk_buff *skb; |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 670 | struct netvsc_stats *rx_stats; |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 671 | |
Stephen Hemminger | 9cbcc42 | 2016-09-22 16:56:34 -0700 | [diff] [blame] | 672 | if (net->reg_state != NETREG_REGISTERED) |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 673 | return NVSP_STAT_FAIL; |
| 674 | |
Stephen Hemminger | 9cbcc42 | 2016-09-22 16:56:34 -0700 | [diff] [blame] | 675 | /* |
| 676 | * If necessary, inject this packet into the VF interface. |
| 677 | * On Hyper-V, multicast and brodcast packets are only delivered |
| 678 | * to the synthetic interface (after subjecting these to |
| 679 | * policy filters on the host). Deliver these via the VF |
| 680 | * interface in the guest. |
| 681 | */ |
stephen hemminger | 0719e72 | 2017-01-11 09:16:32 -0800 | [diff] [blame] | 682 | rcu_read_lock(); |
stephen hemminger | 545a8e7 | 2017-03-22 14:51:00 -0700 | [diff] [blame] | 683 | net_device = rcu_dereference(net_device_ctx->nvdev); |
| 684 | if (unlikely(!net_device)) |
| 685 | goto drop; |
| 686 | |
| 687 | nvchan = &net_device->chan_table[q_idx]; |
Stephen Hemminger | f207c10 | 2016-09-22 16:56:33 -0700 | [diff] [blame] | 688 | vf_netdev = rcu_dereference(net_device_ctx->vf_netdev); |
Stephen Hemminger | 9cbcc42 | 2016-09-22 16:56:34 -0700 | [diff] [blame] | 689 | if (vf_netdev && (vf_netdev->flags & IFF_UP)) |
| 690 | net = vf_netdev; |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 691 | |
| 692 | /* Allocate a skb - TODO direct I/O to pages? */ |
stephen hemminger | e91e7dd | 2017-02-27 10:26:51 -0800 | [diff] [blame] | 693 | skb = netvsc_alloc_recv_skb(net, &nvchan->napi, |
| 694 | csum_info, vlan, data, len); |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 695 | if (unlikely(!skb)) { |
stephen hemminger | 545a8e7 | 2017-03-22 14:51:00 -0700 | [diff] [blame] | 696 | drop: |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 697 | ++net->stats.rx_dropped; |
stephen hemminger | 0719e72 | 2017-01-11 09:16:32 -0800 | [diff] [blame] | 698 | rcu_read_unlock(); |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 699 | return NVSP_STAT_FAIL; |
| 700 | } |
Haiyang Zhang | 5b54dac | 2014-04-21 10:20:28 -0700 | [diff] [blame] | 701 | |
Stephen Hemminger | 9cbcc42 | 2016-09-22 16:56:34 -0700 | [diff] [blame] | 702 | if (net != vf_netdev) |
Simon Xiao | 6c80f3f | 2017-01-24 13:06:13 -0800 | [diff] [blame] | 703 | skb_record_rx_queue(skb, q_idx); |
Stephen Hemminger | 9cbcc42 | 2016-09-22 16:56:34 -0700 | [diff] [blame] | 704 | |
| 705 | /* |
| 706 | * Even if injecting the packet, record the statistics |
| 707 | * on the synthetic device because modifying the VF device |
| 708 | * statistics will not work correctly. |
| 709 | */ |
stephen hemminger | 742fe54 | 2017-02-27 10:26:50 -0800 | [diff] [blame] | 710 | rx_stats = &nvchan->rx_stats; |
sixiao@microsoft.com | 4b02b58 | 2015-05-15 02:33:03 -0700 | [diff] [blame] | 711 | u64_stats_update_begin(&rx_stats->syncp); |
sixiao@microsoft.com | 7eafd9b | 2015-05-14 01:00:25 -0700 | [diff] [blame] | 712 | rx_stats->packets++; |
stephen hemminger | dc54a08 | 2017-01-24 13:06:08 -0800 | [diff] [blame] | 713 | rx_stats->bytes += len; |
Stephen Hemminger | f7ad75b | 2016-09-22 16:56:35 -0700 | [diff] [blame] | 714 | |
| 715 | if (skb->pkt_type == PACKET_BROADCAST) |
| 716 | ++rx_stats->broadcast; |
| 717 | else if (skb->pkt_type == PACKET_MULTICAST) |
| 718 | ++rx_stats->multicast; |
sixiao@microsoft.com | 4b02b58 | 2015-05-15 02:33:03 -0700 | [diff] [blame] | 719 | u64_stats_update_end(&rx_stats->syncp); |
Stephen Hemminger | 9495c28 | 2010-03-09 17:42:17 -0800 | [diff] [blame] | 720 | |
stephen hemminger | 742fe54 | 2017-02-27 10:26:50 -0800 | [diff] [blame] | 721 | napi_gro_receive(&nvchan->napi, skb); |
stephen hemminger | 0719e72 | 2017-01-11 09:16:32 -0800 | [diff] [blame] | 722 | rcu_read_unlock(); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 723 | |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 724 | return 0; |
| 725 | } |
| 726 | |
Stephen Hemminger | f82f4ad | 2010-05-04 09:58:57 -0700 | [diff] [blame] | 727 | static void netvsc_get_drvinfo(struct net_device *net, |
| 728 | struct ethtool_drvinfo *info) |
| 729 | { |
Jiri Pirko | 7826d43 | 2013-01-06 00:44:26 +0000 | [diff] [blame] | 730 | strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver)); |
Jiri Pirko | 7826d43 | 2013-01-06 00:44:26 +0000 | [diff] [blame] | 731 | strlcpy(info->fw_version, "N/A", sizeof(info->fw_version)); |
Stephen Hemminger | f82f4ad | 2010-05-04 09:58:57 -0700 | [diff] [blame] | 732 | } |
| 733 | |
Andrew Schwartzmeyer | 5999537 | 2015-02-26 16:27:14 -0800 | [diff] [blame] | 734 | static void netvsc_get_channels(struct net_device *net, |
| 735 | struct ethtool_channels *channel) |
| 736 | { |
| 737 | struct net_device_context *net_device_ctx = netdev_priv(net); |
stephen hemminger | 545a8e7 | 2017-03-22 14:51:00 -0700 | [diff] [blame] | 738 | struct netvsc_device *nvdev = rtnl_dereference(net_device_ctx->nvdev); |
Andrew Schwartzmeyer | 5999537 | 2015-02-26 16:27:14 -0800 | [diff] [blame] | 739 | |
| 740 | if (nvdev) { |
| 741 | channel->max_combined = nvdev->max_chn; |
| 742 | channel->combined_count = nvdev->num_chn; |
| 743 | } |
| 744 | } |
| 745 | |
stephen hemminger | 2b01888 | 2017-01-24 13:06:03 -0800 | [diff] [blame] | 746 | static int netvsc_set_queues(struct net_device *net, struct hv_device *dev, |
| 747 | u32 num_chn) |
| 748 | { |
| 749 | struct netvsc_device_info device_info; |
| 750 | int ret; |
| 751 | |
| 752 | memset(&device_info, 0, sizeof(device_info)); |
| 753 | device_info.num_chn = num_chn; |
| 754 | device_info.ring_size = ring_size; |
| 755 | device_info.max_num_vrss_chns = num_chn; |
| 756 | |
| 757 | ret = rndis_filter_device_add(dev, &device_info); |
| 758 | if (ret) |
| 759 | return ret; |
| 760 | |
| 761 | ret = netif_set_real_num_tx_queues(net, num_chn); |
| 762 | if (ret) |
| 763 | return ret; |
| 764 | |
| 765 | ret = netif_set_real_num_rx_queues(net, num_chn); |
| 766 | |
| 767 | return ret; |
| 768 | } |
| 769 | |
Andrew Schwartzmeyer | b5960e6 | 2015-08-11 17:14:32 -0700 | [diff] [blame] | 770 | static int netvsc_set_channels(struct net_device *net, |
| 771 | struct ethtool_channels *channels) |
| 772 | { |
| 773 | struct net_device_context *net_device_ctx = netdev_priv(net); |
| 774 | struct hv_device *dev = net_device_ctx->device_ctx; |
stephen hemminger | 545a8e7 | 2017-03-22 14:51:00 -0700 | [diff] [blame] | 775 | struct netvsc_device *nvdev = rtnl_dereference(net_device_ctx->nvdev); |
stephen hemminger | 2b01888 | 2017-01-24 13:06:03 -0800 | [diff] [blame] | 776 | unsigned int count = channels->combined_count; |
stephen hemminger | 163891d | 2017-03-22 14:50:58 -0700 | [diff] [blame] | 777 | bool was_running; |
stephen hemminger | 2b01888 | 2017-01-24 13:06:03 -0800 | [diff] [blame] | 778 | int ret; |
| 779 | |
| 780 | /* We do not support separate count for rx, tx, or other */ |
| 781 | if (count == 0 || |
| 782 | channels->rx_count || channels->tx_count || channels->other_count) |
| 783 | return -EINVAL; |
| 784 | |
| 785 | if (count > net->num_tx_queues || count > net->num_rx_queues) |
| 786 | return -EINVAL; |
Andrew Schwartzmeyer | b5960e6 | 2015-08-11 17:14:32 -0700 | [diff] [blame] | 787 | |
stephen hemminger | a0be450 | 2017-03-22 14:51:01 -0700 | [diff] [blame] | 788 | if (!nvdev || nvdev->destroy) |
Andrew Schwartzmeyer | b5960e6 | 2015-08-11 17:14:32 -0700 | [diff] [blame] | 789 | return -ENODEV; |
| 790 | |
stephen hemminger | 2b01888 | 2017-01-24 13:06:03 -0800 | [diff] [blame] | 791 | if (nvdev->nvsp_version < NVSP_PROTOCOL_VERSION_5) |
Andrew Schwartzmeyer | b5960e6 | 2015-08-11 17:14:32 -0700 | [diff] [blame] | 792 | return -EINVAL; |
| 793 | |
stephen hemminger | 2b01888 | 2017-01-24 13:06:03 -0800 | [diff] [blame] | 794 | if (count > nvdev->max_chn) |
| 795 | return -EINVAL; |
Andrew Schwartzmeyer | b5960e6 | 2015-08-11 17:14:32 -0700 | [diff] [blame] | 796 | |
stephen hemminger | 163891d | 2017-03-22 14:50:58 -0700 | [diff] [blame] | 797 | was_running = netif_running(net); |
| 798 | if (was_running) { |
| 799 | ret = netvsc_close(net); |
| 800 | if (ret) |
| 801 | return ret; |
| 802 | } |
Andrew Schwartzmeyer | b5960e6 | 2015-08-11 17:14:32 -0700 | [diff] [blame] | 803 | |
stephen hemminger | 2289f0a | 2017-01-24 13:06:10 -0800 | [diff] [blame] | 804 | rndis_filter_device_remove(dev, nvdev); |
Andrew Schwartzmeyer | b5960e6 | 2015-08-11 17:14:32 -0700 | [diff] [blame] | 805 | |
stephen hemminger | 2b01888 | 2017-01-24 13:06:03 -0800 | [diff] [blame] | 806 | ret = netvsc_set_queues(net, dev, count); |
| 807 | if (ret == 0) |
| 808 | nvdev->num_chn = count; |
| 809 | else |
| 810 | netvsc_set_queues(net, dev, nvdev->num_chn); |
Andrew Schwartzmeyer | b5960e6 | 2015-08-11 17:14:32 -0700 | [diff] [blame] | 811 | |
stephen hemminger | 163891d | 2017-03-22 14:50:58 -0700 | [diff] [blame] | 812 | if (was_running) |
| 813 | ret = netvsc_open(net); |
| 814 | |
Vitaly Kuznetsov | 1bdcec8 | 2016-05-13 13:55:21 +0200 | [diff] [blame] | 815 | /* We may have missed link change notifications */ |
| 816 | schedule_delayed_work(&net_device_ctx->dwork, 0); |
Andrew Schwartzmeyer | b5960e6 | 2015-08-11 17:14:32 -0700 | [diff] [blame] | 817 | |
| 818 | return ret; |
Andrew Schwartzmeyer | b5960e6 | 2015-08-11 17:14:32 -0700 | [diff] [blame] | 819 | } |
| 820 | |
Philippe Reynes | 5e8456f | 2017-03-08 23:41:04 +0100 | [diff] [blame] | 821 | static bool |
| 822 | netvsc_validate_ethtool_ss_cmd(const struct ethtool_link_ksettings *cmd) |
sixiao@microsoft.com | 49eb938 | 2016-02-25 15:24:08 -0800 | [diff] [blame] | 823 | { |
Philippe Reynes | 5e8456f | 2017-03-08 23:41:04 +0100 | [diff] [blame] | 824 | struct ethtool_link_ksettings diff1 = *cmd; |
| 825 | struct ethtool_link_ksettings diff2 = {}; |
sixiao@microsoft.com | 49eb938 | 2016-02-25 15:24:08 -0800 | [diff] [blame] | 826 | |
Philippe Reynes | 5e8456f | 2017-03-08 23:41:04 +0100 | [diff] [blame] | 827 | diff1.base.speed = 0; |
| 828 | diff1.base.duplex = 0; |
sixiao@microsoft.com | 49eb938 | 2016-02-25 15:24:08 -0800 | [diff] [blame] | 829 | /* advertising and cmd are usually set */ |
Philippe Reynes | 5e8456f | 2017-03-08 23:41:04 +0100 | [diff] [blame] | 830 | ethtool_link_ksettings_zero_link_mode(&diff1, advertising); |
| 831 | diff1.base.cmd = 0; |
sixiao@microsoft.com | 49eb938 | 2016-02-25 15:24:08 -0800 | [diff] [blame] | 832 | /* We set port to PORT_OTHER */ |
Philippe Reynes | 5e8456f | 2017-03-08 23:41:04 +0100 | [diff] [blame] | 833 | diff2.base.port = PORT_OTHER; |
sixiao@microsoft.com | 49eb938 | 2016-02-25 15:24:08 -0800 | [diff] [blame] | 834 | |
| 835 | return !memcmp(&diff1, &diff2, sizeof(diff1)); |
| 836 | } |
| 837 | |
| 838 | static void netvsc_init_settings(struct net_device *dev) |
| 839 | { |
| 840 | struct net_device_context *ndc = netdev_priv(dev); |
| 841 | |
| 842 | ndc->speed = SPEED_UNKNOWN; |
Simon Xiao | f3c9d40e | 2017-04-14 14:42:58 -0700 | [diff] [blame] | 843 | ndc->duplex = DUPLEX_FULL; |
sixiao@microsoft.com | 49eb938 | 2016-02-25 15:24:08 -0800 | [diff] [blame] | 844 | } |
| 845 | |
Philippe Reynes | 5e8456f | 2017-03-08 23:41:04 +0100 | [diff] [blame] | 846 | static int netvsc_get_link_ksettings(struct net_device *dev, |
| 847 | struct ethtool_link_ksettings *cmd) |
sixiao@microsoft.com | 49eb938 | 2016-02-25 15:24:08 -0800 | [diff] [blame] | 848 | { |
| 849 | struct net_device_context *ndc = netdev_priv(dev); |
| 850 | |
Philippe Reynes | 5e8456f | 2017-03-08 23:41:04 +0100 | [diff] [blame] | 851 | cmd->base.speed = ndc->speed; |
| 852 | cmd->base.duplex = ndc->duplex; |
| 853 | cmd->base.port = PORT_OTHER; |
sixiao@microsoft.com | 49eb938 | 2016-02-25 15:24:08 -0800 | [diff] [blame] | 854 | |
| 855 | return 0; |
| 856 | } |
| 857 | |
Philippe Reynes | 5e8456f | 2017-03-08 23:41:04 +0100 | [diff] [blame] | 858 | static int netvsc_set_link_ksettings(struct net_device *dev, |
| 859 | const struct ethtool_link_ksettings *cmd) |
sixiao@microsoft.com | 49eb938 | 2016-02-25 15:24:08 -0800 | [diff] [blame] | 860 | { |
| 861 | struct net_device_context *ndc = netdev_priv(dev); |
| 862 | u32 speed; |
| 863 | |
Philippe Reynes | 5e8456f | 2017-03-08 23:41:04 +0100 | [diff] [blame] | 864 | speed = cmd->base.speed; |
sixiao@microsoft.com | 49eb938 | 2016-02-25 15:24:08 -0800 | [diff] [blame] | 865 | if (!ethtool_validate_speed(speed) || |
Philippe Reynes | 5e8456f | 2017-03-08 23:41:04 +0100 | [diff] [blame] | 866 | !ethtool_validate_duplex(cmd->base.duplex) || |
sixiao@microsoft.com | 49eb938 | 2016-02-25 15:24:08 -0800 | [diff] [blame] | 867 | !netvsc_validate_ethtool_ss_cmd(cmd)) |
| 868 | return -EINVAL; |
| 869 | |
| 870 | ndc->speed = speed; |
Philippe Reynes | 5e8456f | 2017-03-08 23:41:04 +0100 | [diff] [blame] | 871 | ndc->duplex = cmd->base.duplex; |
sixiao@microsoft.com | 49eb938 | 2016-02-25 15:24:08 -0800 | [diff] [blame] | 872 | |
| 873 | return 0; |
| 874 | } |
| 875 | |
Haiyang Zhang | 4d447c9 | 2011-12-15 13:45:17 -0800 | [diff] [blame] | 876 | static int netvsc_change_mtu(struct net_device *ndev, int mtu) |
| 877 | { |
| 878 | struct net_device_context *ndevctx = netdev_priv(ndev); |
stephen hemminger | 545a8e7 | 2017-03-22 14:51:00 -0700 | [diff] [blame] | 879 | struct netvsc_device *nvdev = rtnl_dereference(ndevctx->nvdev); |
Vitaly Kuznetsov | 3d541ac | 2016-05-13 13:55:22 +0200 | [diff] [blame] | 880 | struct hv_device *hdev = ndevctx->device_ctx; |
Haiyang Zhang | 4d447c9 | 2011-12-15 13:45:17 -0800 | [diff] [blame] | 881 | struct netvsc_device_info device_info; |
stephen hemminger | 163891d | 2017-03-22 14:50:58 -0700 | [diff] [blame] | 882 | bool was_running; |
K. Y. Srinivasan | 386f576 | 2017-03-24 20:54:37 -0700 | [diff] [blame] | 883 | int ret = 0; |
Haiyang Zhang | 4d447c9 | 2011-12-15 13:45:17 -0800 | [diff] [blame] | 884 | |
stephen hemminger | a0be450 | 2017-03-22 14:51:01 -0700 | [diff] [blame] | 885 | if (!nvdev || nvdev->destroy) |
Haiyang Zhang | 4d447c9 | 2011-12-15 13:45:17 -0800 | [diff] [blame] | 886 | return -ENODEV; |
| 887 | |
stephen hemminger | 163891d | 2017-03-22 14:50:58 -0700 | [diff] [blame] | 888 | was_running = netif_running(ndev); |
| 889 | if (was_running) { |
| 890 | ret = netvsc_close(ndev); |
| 891 | if (ret) |
| 892 | return ret; |
| 893 | } |
Haiyang Zhang | 2de8530 | 2015-07-13 13:09:16 -0700 | [diff] [blame] | 894 | |
Andrew Schwartzmeyer | 8ebdcc5 | 2015-08-11 17:14:31 -0700 | [diff] [blame] | 895 | memset(&device_info, 0, sizeof(device_info)); |
Haiyang Zhang | 4d447c9 | 2011-12-15 13:45:17 -0800 | [diff] [blame] | 896 | device_info.ring_size = ring_size; |
stephen hemminger | 2b01888 | 2017-01-24 13:06:03 -0800 | [diff] [blame] | 897 | device_info.num_chn = nvdev->num_chn; |
| 898 | device_info.max_num_vrss_chns = nvdev->num_chn; |
Dexuan Cui | 152669b | 2017-03-02 13:00:53 +0000 | [diff] [blame] | 899 | |
Dexuan Cui | 152669b | 2017-03-02 13:00:53 +0000 | [diff] [blame] | 900 | rndis_filter_device_remove(hdev, nvdev); |
| 901 | |
| 902 | /* 'nvdev' has been freed in rndis_filter_device_remove() -> |
| 903 | * netvsc_device_remove () -> free_netvsc_device(). |
| 904 | * We mustn't access it before it's re-created in |
| 905 | * rndis_filter_device_add() -> netvsc_device_add(). |
| 906 | */ |
| 907 | |
| 908 | ndev->mtu = mtu; |
| 909 | |
Haiyang Zhang | 4d447c9 | 2011-12-15 13:45:17 -0800 | [diff] [blame] | 910 | rndis_filter_device_add(hdev, &device_info); |
Haiyang Zhang | 4d447c9 | 2011-12-15 13:45:17 -0800 | [diff] [blame] | 911 | |
stephen hemminger | 163891d | 2017-03-22 14:50:58 -0700 | [diff] [blame] | 912 | if (was_running) |
| 913 | ret = netvsc_open(ndev); |
| 914 | |
Vitaly Kuznetsov | 1bdcec8 | 2016-05-13 13:55:21 +0200 | [diff] [blame] | 915 | /* We may have missed link change notifications */ |
| 916 | schedule_delayed_work(&ndevctx->dwork, 0); |
| 917 | |
Haiyang Zhang | 2de8530 | 2015-07-13 13:09:16 -0700 | [diff] [blame] | 918 | return ret; |
Haiyang Zhang | 4d447c9 | 2011-12-15 13:45:17 -0800 | [diff] [blame] | 919 | } |
| 920 | |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 921 | static void netvsc_get_stats64(struct net_device *net, |
| 922 | struct rtnl_link_stats64 *t) |
sixiao@microsoft.com | 7eafd9b | 2015-05-14 01:00:25 -0700 | [diff] [blame] | 923 | { |
| 924 | struct net_device_context *ndev_ctx = netdev_priv(net); |
stephen hemminger | 776e726 | 2017-04-14 14:42:57 -0700 | [diff] [blame] | 925 | struct netvsc_device *nvdev = rcu_dereference_rtnl(ndev_ctx->nvdev); |
Simon Xiao | 6c80f3f | 2017-01-24 13:06:13 -0800 | [diff] [blame] | 926 | int i; |
sixiao@microsoft.com | 7eafd9b | 2015-05-14 01:00:25 -0700 | [diff] [blame] | 927 | |
Simon Xiao | 6c80f3f | 2017-01-24 13:06:13 -0800 | [diff] [blame] | 928 | if (!nvdev) |
| 929 | return; |
| 930 | |
| 931 | for (i = 0; i < nvdev->num_chn; i++) { |
| 932 | const struct netvsc_channel *nvchan = &nvdev->chan_table[i]; |
| 933 | const struct netvsc_stats *stats; |
| 934 | u64 packets, bytes, multicast; |
sixiao@microsoft.com | 7eafd9b | 2015-05-14 01:00:25 -0700 | [diff] [blame] | 935 | unsigned int start; |
| 936 | |
Simon Xiao | 6c80f3f | 2017-01-24 13:06:13 -0800 | [diff] [blame] | 937 | stats = &nvchan->tx_stats; |
sixiao@microsoft.com | 7eafd9b | 2015-05-14 01:00:25 -0700 | [diff] [blame] | 938 | do { |
Simon Xiao | 6c80f3f | 2017-01-24 13:06:13 -0800 | [diff] [blame] | 939 | start = u64_stats_fetch_begin_irq(&stats->syncp); |
| 940 | packets = stats->packets; |
| 941 | bytes = stats->bytes; |
| 942 | } while (u64_stats_fetch_retry_irq(&stats->syncp, start)); |
sixiao@microsoft.com | 7eafd9b | 2015-05-14 01:00:25 -0700 | [diff] [blame] | 943 | |
Simon Xiao | 6c80f3f | 2017-01-24 13:06:13 -0800 | [diff] [blame] | 944 | t->tx_bytes += bytes; |
| 945 | t->tx_packets += packets; |
| 946 | |
| 947 | stats = &nvchan->rx_stats; |
sixiao@microsoft.com | 7eafd9b | 2015-05-14 01:00:25 -0700 | [diff] [blame] | 948 | do { |
Simon Xiao | 6c80f3f | 2017-01-24 13:06:13 -0800 | [diff] [blame] | 949 | start = u64_stats_fetch_begin_irq(&stats->syncp); |
| 950 | packets = stats->packets; |
| 951 | bytes = stats->bytes; |
| 952 | multicast = stats->multicast + stats->broadcast; |
| 953 | } while (u64_stats_fetch_retry_irq(&stats->syncp, start)); |
sixiao@microsoft.com | 7eafd9b | 2015-05-14 01:00:25 -0700 | [diff] [blame] | 954 | |
Simon Xiao | 6c80f3f | 2017-01-24 13:06:13 -0800 | [diff] [blame] | 955 | t->rx_bytes += bytes; |
| 956 | t->rx_packets += packets; |
| 957 | t->multicast += multicast; |
sixiao@microsoft.com | 7eafd9b | 2015-05-14 01:00:25 -0700 | [diff] [blame] | 958 | } |
| 959 | |
| 960 | t->tx_dropped = net->stats.tx_dropped; |
Simon Xiao | b512472 | 2017-02-17 11:36:20 -0800 | [diff] [blame] | 961 | t->tx_errors = net->stats.tx_errors; |
sixiao@microsoft.com | 7eafd9b | 2015-05-14 01:00:25 -0700 | [diff] [blame] | 962 | |
| 963 | t->rx_dropped = net->stats.rx_dropped; |
| 964 | t->rx_errors = net->stats.rx_errors; |
sixiao@microsoft.com | 7eafd9b | 2015-05-14 01:00:25 -0700 | [diff] [blame] | 965 | } |
Haiyang Zhang | 1ce09e8 | 2012-07-10 07:19:22 +0000 | [diff] [blame] | 966 | |
| 967 | static int netvsc_set_mac_addr(struct net_device *ndev, void *p) |
| 968 | { |
Haiyang Zhang | 1ce09e8 | 2012-07-10 07:19:22 +0000 | [diff] [blame] | 969 | struct sockaddr *addr = p; |
Jianjun Kong | 9a4c831 | 2013-01-18 16:52:09 +0000 | [diff] [blame] | 970 | char save_adr[ETH_ALEN]; |
Haiyang Zhang | 1ce09e8 | 2012-07-10 07:19:22 +0000 | [diff] [blame] | 971 | unsigned char save_aatype; |
| 972 | int err; |
| 973 | |
| 974 | memcpy(save_adr, ndev->dev_addr, ETH_ALEN); |
| 975 | save_aatype = ndev->addr_assign_type; |
| 976 | |
| 977 | err = eth_mac_addr(ndev, p); |
| 978 | if (err != 0) |
| 979 | return err; |
| 980 | |
Vitaly Kuznetsov | e834da9a | 2016-06-03 17:51:01 +0200 | [diff] [blame] | 981 | err = rndis_filter_set_device_mac(ndev, addr->sa_data); |
Haiyang Zhang | 1ce09e8 | 2012-07-10 07:19:22 +0000 | [diff] [blame] | 982 | if (err != 0) { |
| 983 | /* roll back to saved MAC */ |
| 984 | memcpy(ndev->dev_addr, save_adr, ETH_ALEN); |
| 985 | ndev->addr_assign_type = save_aatype; |
| 986 | } |
| 987 | |
| 988 | return err; |
| 989 | } |
| 990 | |
Stephen Hemminger | 4323b47 | 2016-08-23 12:17:57 -0700 | [diff] [blame] | 991 | static const struct { |
| 992 | char name[ETH_GSTRING_LEN]; |
| 993 | u16 offset; |
| 994 | } netvsc_stats[] = { |
| 995 | { "tx_scattered", offsetof(struct netvsc_ethtool_stats, tx_scattered) }, |
| 996 | { "tx_no_memory", offsetof(struct netvsc_ethtool_stats, tx_no_memory) }, |
| 997 | { "tx_no_space", offsetof(struct netvsc_ethtool_stats, tx_no_space) }, |
| 998 | { "tx_too_big", offsetof(struct netvsc_ethtool_stats, tx_too_big) }, |
| 999 | { "tx_busy", offsetof(struct netvsc_ethtool_stats, tx_busy) }, |
| 1000 | }; |
| 1001 | |
Simon Xiao | 6c80f3f | 2017-01-24 13:06:13 -0800 | [diff] [blame] | 1002 | #define NETVSC_GLOBAL_STATS_LEN ARRAY_SIZE(netvsc_stats) |
| 1003 | |
| 1004 | /* 4 statistics per queue (rx/tx packets/bytes) */ |
| 1005 | #define NETVSC_QUEUE_STATS_LEN(dev) ((dev)->num_chn * 4) |
| 1006 | |
Stephen Hemminger | 4323b47 | 2016-08-23 12:17:57 -0700 | [diff] [blame] | 1007 | static int netvsc_get_sset_count(struct net_device *dev, int string_set) |
| 1008 | { |
Simon Xiao | 6c80f3f | 2017-01-24 13:06:13 -0800 | [diff] [blame] | 1009 | struct net_device_context *ndc = netdev_priv(dev); |
stephen hemminger | 545a8e7 | 2017-03-22 14:51:00 -0700 | [diff] [blame] | 1010 | struct netvsc_device *nvdev = rcu_dereference(ndc->nvdev); |
| 1011 | |
| 1012 | if (!nvdev) |
| 1013 | return -ENODEV; |
Simon Xiao | 6c80f3f | 2017-01-24 13:06:13 -0800 | [diff] [blame] | 1014 | |
Stephen Hemminger | 4323b47 | 2016-08-23 12:17:57 -0700 | [diff] [blame] | 1015 | switch (string_set) { |
| 1016 | case ETH_SS_STATS: |
Simon Xiao | 6c80f3f | 2017-01-24 13:06:13 -0800 | [diff] [blame] | 1017 | return NETVSC_GLOBAL_STATS_LEN + NETVSC_QUEUE_STATS_LEN(nvdev); |
Stephen Hemminger | 4323b47 | 2016-08-23 12:17:57 -0700 | [diff] [blame] | 1018 | default: |
| 1019 | return -EINVAL; |
| 1020 | } |
| 1021 | } |
| 1022 | |
| 1023 | static void netvsc_get_ethtool_stats(struct net_device *dev, |
| 1024 | struct ethtool_stats *stats, u64 *data) |
| 1025 | { |
| 1026 | struct net_device_context *ndc = netdev_priv(dev); |
stephen hemminger | 545a8e7 | 2017-03-22 14:51:00 -0700 | [diff] [blame] | 1027 | struct netvsc_device *nvdev = rcu_dereference(ndc->nvdev); |
Stephen Hemminger | 4323b47 | 2016-08-23 12:17:57 -0700 | [diff] [blame] | 1028 | const void *nds = &ndc->eth_stats; |
Simon Xiao | 6c80f3f | 2017-01-24 13:06:13 -0800 | [diff] [blame] | 1029 | const struct netvsc_stats *qstats; |
| 1030 | unsigned int start; |
| 1031 | u64 packets, bytes; |
| 1032 | int i, j; |
Stephen Hemminger | 4323b47 | 2016-08-23 12:17:57 -0700 | [diff] [blame] | 1033 | |
stephen hemminger | 545a8e7 | 2017-03-22 14:51:00 -0700 | [diff] [blame] | 1034 | if (!nvdev) |
| 1035 | return; |
| 1036 | |
Simon Xiao | 6c80f3f | 2017-01-24 13:06:13 -0800 | [diff] [blame] | 1037 | for (i = 0; i < NETVSC_GLOBAL_STATS_LEN; i++) |
Stephen Hemminger | 4323b47 | 2016-08-23 12:17:57 -0700 | [diff] [blame] | 1038 | data[i] = *(unsigned long *)(nds + netvsc_stats[i].offset); |
Simon Xiao | 6c80f3f | 2017-01-24 13:06:13 -0800 | [diff] [blame] | 1039 | |
| 1040 | for (j = 0; j < nvdev->num_chn; j++) { |
| 1041 | qstats = &nvdev->chan_table[j].tx_stats; |
| 1042 | |
| 1043 | do { |
| 1044 | start = u64_stats_fetch_begin_irq(&qstats->syncp); |
| 1045 | packets = qstats->packets; |
| 1046 | bytes = qstats->bytes; |
| 1047 | } while (u64_stats_fetch_retry_irq(&qstats->syncp, start)); |
| 1048 | data[i++] = packets; |
| 1049 | data[i++] = bytes; |
| 1050 | |
| 1051 | qstats = &nvdev->chan_table[j].rx_stats; |
| 1052 | do { |
| 1053 | start = u64_stats_fetch_begin_irq(&qstats->syncp); |
| 1054 | packets = qstats->packets; |
| 1055 | bytes = qstats->bytes; |
| 1056 | } while (u64_stats_fetch_retry_irq(&qstats->syncp, start)); |
| 1057 | data[i++] = packets; |
| 1058 | data[i++] = bytes; |
| 1059 | } |
Stephen Hemminger | 4323b47 | 2016-08-23 12:17:57 -0700 | [diff] [blame] | 1060 | } |
| 1061 | |
| 1062 | static void netvsc_get_strings(struct net_device *dev, u32 stringset, u8 *data) |
| 1063 | { |
Simon Xiao | 6c80f3f | 2017-01-24 13:06:13 -0800 | [diff] [blame] | 1064 | struct net_device_context *ndc = netdev_priv(dev); |
stephen hemminger | 545a8e7 | 2017-03-22 14:51:00 -0700 | [diff] [blame] | 1065 | struct netvsc_device *nvdev = rcu_dereference(ndc->nvdev); |
Simon Xiao | 6c80f3f | 2017-01-24 13:06:13 -0800 | [diff] [blame] | 1066 | u8 *p = data; |
Stephen Hemminger | 4323b47 | 2016-08-23 12:17:57 -0700 | [diff] [blame] | 1067 | int i; |
| 1068 | |
stephen hemminger | 545a8e7 | 2017-03-22 14:51:00 -0700 | [diff] [blame] | 1069 | if (!nvdev) |
| 1070 | return; |
| 1071 | |
Stephen Hemminger | 4323b47 | 2016-08-23 12:17:57 -0700 | [diff] [blame] | 1072 | switch (stringset) { |
| 1073 | case ETH_SS_STATS: |
| 1074 | for (i = 0; i < ARRAY_SIZE(netvsc_stats); i++) |
Simon Xiao | 6c80f3f | 2017-01-24 13:06:13 -0800 | [diff] [blame] | 1075 | memcpy(p + i * ETH_GSTRING_LEN, |
Stephen Hemminger | 4323b47 | 2016-08-23 12:17:57 -0700 | [diff] [blame] | 1076 | netvsc_stats[i].name, ETH_GSTRING_LEN); |
Simon Xiao | 6c80f3f | 2017-01-24 13:06:13 -0800 | [diff] [blame] | 1077 | |
| 1078 | p += i * ETH_GSTRING_LEN; |
| 1079 | for (i = 0; i < nvdev->num_chn; i++) { |
| 1080 | sprintf(p, "tx_queue_%u_packets", i); |
| 1081 | p += ETH_GSTRING_LEN; |
| 1082 | sprintf(p, "tx_queue_%u_bytes", i); |
| 1083 | p += ETH_GSTRING_LEN; |
| 1084 | sprintf(p, "rx_queue_%u_packets", i); |
| 1085 | p += ETH_GSTRING_LEN; |
| 1086 | sprintf(p, "rx_queue_%u_bytes", i); |
| 1087 | p += ETH_GSTRING_LEN; |
| 1088 | } |
| 1089 | |
Stephen Hemminger | 4323b47 | 2016-08-23 12:17:57 -0700 | [diff] [blame] | 1090 | break; |
| 1091 | } |
| 1092 | } |
| 1093 | |
stephen hemminger | b448f4e | 2017-01-24 13:06:00 -0800 | [diff] [blame] | 1094 | static int |
stephen hemminger | b5a5dc8 | 2017-01-24 13:06:01 -0800 | [diff] [blame] | 1095 | netvsc_get_rss_hash_opts(struct netvsc_device *nvdev, |
| 1096 | struct ethtool_rxnfc *info) |
| 1097 | { |
| 1098 | info->data = RXH_IP_SRC | RXH_IP_DST; |
| 1099 | |
| 1100 | switch (info->flow_type) { |
| 1101 | case TCP_V4_FLOW: |
| 1102 | case TCP_V6_FLOW: |
| 1103 | info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; |
| 1104 | /* fallthrough */ |
| 1105 | case UDP_V4_FLOW: |
| 1106 | case UDP_V6_FLOW: |
| 1107 | case IPV4_FLOW: |
| 1108 | case IPV6_FLOW: |
| 1109 | break; |
| 1110 | default: |
| 1111 | info->data = 0; |
| 1112 | break; |
| 1113 | } |
| 1114 | |
| 1115 | return 0; |
| 1116 | } |
| 1117 | |
| 1118 | static int |
stephen hemminger | b448f4e | 2017-01-24 13:06:00 -0800 | [diff] [blame] | 1119 | netvsc_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info, |
| 1120 | u32 *rules) |
| 1121 | { |
| 1122 | struct net_device_context *ndc = netdev_priv(dev); |
stephen hemminger | 545a8e7 | 2017-03-22 14:51:00 -0700 | [diff] [blame] | 1123 | struct netvsc_device *nvdev = rcu_dereference(ndc->nvdev); |
| 1124 | |
| 1125 | if (!nvdev) |
| 1126 | return -ENODEV; |
stephen hemminger | b448f4e | 2017-01-24 13:06:00 -0800 | [diff] [blame] | 1127 | |
| 1128 | switch (info->cmd) { |
| 1129 | case ETHTOOL_GRXRINGS: |
| 1130 | info->data = nvdev->num_chn; |
| 1131 | return 0; |
stephen hemminger | b5a5dc8 | 2017-01-24 13:06:01 -0800 | [diff] [blame] | 1132 | |
| 1133 | case ETHTOOL_GRXFH: |
| 1134 | return netvsc_get_rss_hash_opts(nvdev, info); |
stephen hemminger | b448f4e | 2017-01-24 13:06:00 -0800 | [diff] [blame] | 1135 | } |
| 1136 | return -EOPNOTSUPP; |
| 1137 | } |
| 1138 | |
Richard Weinberger | 316158f | 2014-07-09 16:23:59 +0200 | [diff] [blame] | 1139 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1140 | static void netvsc_poll_controller(struct net_device *net) |
| 1141 | { |
| 1142 | /* As netvsc_start_xmit() works synchronous we don't have to |
| 1143 | * trigger anything here. |
| 1144 | */ |
| 1145 | } |
| 1146 | #endif |
Haiyang Zhang | 1ce09e8 | 2012-07-10 07:19:22 +0000 | [diff] [blame] | 1147 | |
stephen hemminger | 962f3fe | 2017-01-24 13:06:02 -0800 | [diff] [blame] | 1148 | static u32 netvsc_get_rxfh_key_size(struct net_device *dev) |
| 1149 | { |
| 1150 | return NETVSC_HASH_KEYLEN; |
| 1151 | } |
| 1152 | |
| 1153 | static u32 netvsc_rss_indir_size(struct net_device *dev) |
| 1154 | { |
stephen hemminger | ff4a441 | 2017-01-24 13:06:04 -0800 | [diff] [blame] | 1155 | return ITAB_NUM; |
stephen hemminger | 962f3fe | 2017-01-24 13:06:02 -0800 | [diff] [blame] | 1156 | } |
| 1157 | |
| 1158 | static int netvsc_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, |
| 1159 | u8 *hfunc) |
| 1160 | { |
| 1161 | struct net_device_context *ndc = netdev_priv(dev); |
stephen hemminger | 545a8e7 | 2017-03-22 14:51:00 -0700 | [diff] [blame] | 1162 | struct netvsc_device *ndev = rcu_dereference(ndc->nvdev); |
Colin Ian King | eb996ed | 2017-03-25 14:26:39 +0000 | [diff] [blame] | 1163 | struct rndis_device *rndis_dev; |
stephen hemminger | ff4a441 | 2017-01-24 13:06:04 -0800 | [diff] [blame] | 1164 | int i; |
stephen hemminger | 962f3fe | 2017-01-24 13:06:02 -0800 | [diff] [blame] | 1165 | |
stephen hemminger | 545a8e7 | 2017-03-22 14:51:00 -0700 | [diff] [blame] | 1166 | if (!ndev) |
| 1167 | return -ENODEV; |
| 1168 | |
stephen hemminger | 962f3fe | 2017-01-24 13:06:02 -0800 | [diff] [blame] | 1169 | if (hfunc) |
| 1170 | *hfunc = ETH_RSS_HASH_TOP; /* Toeplitz */ |
| 1171 | |
Colin Ian King | eb996ed | 2017-03-25 14:26:39 +0000 | [diff] [blame] | 1172 | rndis_dev = ndev->extension; |
stephen hemminger | ff4a441 | 2017-01-24 13:06:04 -0800 | [diff] [blame] | 1173 | if (indir) { |
| 1174 | for (i = 0; i < ITAB_NUM; i++) |
| 1175 | indir[i] = rndis_dev->ind_table[i]; |
| 1176 | } |
| 1177 | |
stephen hemminger | 962f3fe | 2017-01-24 13:06:02 -0800 | [diff] [blame] | 1178 | if (key) |
| 1179 | memcpy(key, rndis_dev->rss_key, NETVSC_HASH_KEYLEN); |
| 1180 | |
| 1181 | return 0; |
| 1182 | } |
| 1183 | |
| 1184 | static int netvsc_set_rxfh(struct net_device *dev, const u32 *indir, |
| 1185 | const u8 *key, const u8 hfunc) |
| 1186 | { |
| 1187 | struct net_device_context *ndc = netdev_priv(dev); |
stephen hemminger | 545a8e7 | 2017-03-22 14:51:00 -0700 | [diff] [blame] | 1188 | struct netvsc_device *ndev = rtnl_dereference(ndc->nvdev); |
Colin Ian King | eb996ed | 2017-03-25 14:26:39 +0000 | [diff] [blame] | 1189 | struct rndis_device *rndis_dev; |
stephen hemminger | ff4a441 | 2017-01-24 13:06:04 -0800 | [diff] [blame] | 1190 | int i; |
stephen hemminger | 962f3fe | 2017-01-24 13:06:02 -0800 | [diff] [blame] | 1191 | |
stephen hemminger | 545a8e7 | 2017-03-22 14:51:00 -0700 | [diff] [blame] | 1192 | if (!ndev) |
| 1193 | return -ENODEV; |
| 1194 | |
stephen hemminger | 962f3fe | 2017-01-24 13:06:02 -0800 | [diff] [blame] | 1195 | if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP) |
| 1196 | return -EOPNOTSUPP; |
| 1197 | |
Colin Ian King | eb996ed | 2017-03-25 14:26:39 +0000 | [diff] [blame] | 1198 | rndis_dev = ndev->extension; |
stephen hemminger | ff4a441 | 2017-01-24 13:06:04 -0800 | [diff] [blame] | 1199 | if (indir) { |
| 1200 | for (i = 0; i < ITAB_NUM; i++) |
| 1201 | if (indir[i] >= dev->num_rx_queues) |
| 1202 | return -EINVAL; |
| 1203 | |
| 1204 | for (i = 0; i < ITAB_NUM; i++) |
| 1205 | rndis_dev->ind_table[i] = indir[i]; |
| 1206 | } |
| 1207 | |
| 1208 | if (!key) { |
| 1209 | if (!indir) |
| 1210 | return 0; |
| 1211 | |
| 1212 | key = rndis_dev->rss_key; |
| 1213 | } |
stephen hemminger | 962f3fe | 2017-01-24 13:06:02 -0800 | [diff] [blame] | 1214 | |
| 1215 | return rndis_filter_set_rss_param(rndis_dev, key, ndev->num_chn); |
| 1216 | } |
| 1217 | |
Stephen Hemminger | f82f4ad | 2010-05-04 09:58:57 -0700 | [diff] [blame] | 1218 | static const struct ethtool_ops ethtool_ops = { |
| 1219 | .get_drvinfo = netvsc_get_drvinfo, |
Stephen Hemminger | f82f4ad | 2010-05-04 09:58:57 -0700 | [diff] [blame] | 1220 | .get_link = ethtool_op_get_link, |
Stephen Hemminger | 4323b47 | 2016-08-23 12:17:57 -0700 | [diff] [blame] | 1221 | .get_ethtool_stats = netvsc_get_ethtool_stats, |
| 1222 | .get_sset_count = netvsc_get_sset_count, |
| 1223 | .get_strings = netvsc_get_strings, |
Andrew Schwartzmeyer | 5999537 | 2015-02-26 16:27:14 -0800 | [diff] [blame] | 1224 | .get_channels = netvsc_get_channels, |
Andrew Schwartzmeyer | b5960e6 | 2015-08-11 17:14:32 -0700 | [diff] [blame] | 1225 | .set_channels = netvsc_set_channels, |
sixiao@microsoft.com | 76d13b5 | 2016-02-17 16:43:59 -0800 | [diff] [blame] | 1226 | .get_ts_info = ethtool_op_get_ts_info, |
stephen hemminger | b448f4e | 2017-01-24 13:06:00 -0800 | [diff] [blame] | 1227 | .get_rxnfc = netvsc_get_rxnfc, |
stephen hemminger | 962f3fe | 2017-01-24 13:06:02 -0800 | [diff] [blame] | 1228 | .get_rxfh_key_size = netvsc_get_rxfh_key_size, |
| 1229 | .get_rxfh_indir_size = netvsc_rss_indir_size, |
| 1230 | .get_rxfh = netvsc_get_rxfh, |
| 1231 | .set_rxfh = netvsc_set_rxfh, |
Philippe Reynes | 5e8456f | 2017-03-08 23:41:04 +0100 | [diff] [blame] | 1232 | .get_link_ksettings = netvsc_get_link_ksettings, |
| 1233 | .set_link_ksettings = netvsc_set_link_ksettings, |
Stephen Hemminger | f82f4ad | 2010-05-04 09:58:57 -0700 | [diff] [blame] | 1234 | }; |
| 1235 | |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1236 | static const struct net_device_ops device_ops = { |
| 1237 | .ndo_open = netvsc_open, |
| 1238 | .ndo_stop = netvsc_close, |
| 1239 | .ndo_start_xmit = netvsc_start_xmit, |
Jiri Pirko | afc4b13 | 2011-08-16 06:29:01 +0000 | [diff] [blame] | 1240 | .ndo_set_rx_mode = netvsc_set_multicast_list, |
Haiyang Zhang | 4d447c9 | 2011-12-15 13:45:17 -0800 | [diff] [blame] | 1241 | .ndo_change_mtu = netvsc_change_mtu, |
Haiyang Zhang | b681b58 | 2010-08-03 19:15:31 +0000 | [diff] [blame] | 1242 | .ndo_validate_addr = eth_validate_addr, |
Haiyang Zhang | 1ce09e8 | 2012-07-10 07:19:22 +0000 | [diff] [blame] | 1243 | .ndo_set_mac_address = netvsc_set_mac_addr, |
Haiyang Zhang | 5b54dac | 2014-04-21 10:20:28 -0700 | [diff] [blame] | 1244 | .ndo_select_queue = netvsc_select_queue, |
sixiao@microsoft.com | 7eafd9b | 2015-05-14 01:00:25 -0700 | [diff] [blame] | 1245 | .ndo_get_stats64 = netvsc_get_stats64, |
Richard Weinberger | 316158f | 2014-07-09 16:23:59 +0200 | [diff] [blame] | 1246 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1247 | .ndo_poll_controller = netvsc_poll_controller, |
| 1248 | #endif |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1249 | }; |
| 1250 | |
Haiyang Zhang | c996edc | 2011-04-06 15:18:00 -0700 | [diff] [blame] | 1251 | /* |
Vitaly Kuznetsov | 27a70af | 2015-11-27 11:39:55 +0100 | [diff] [blame] | 1252 | * Handle link status changes. For RNDIS_STATUS_NETWORK_CHANGE emulate link |
| 1253 | * down/up sequence. In case of RNDIS_STATUS_MEDIA_CONNECT when carrier is |
| 1254 | * present send GARP packet to network peers with netif_notify_peers(). |
Haiyang Zhang | c996edc | 2011-04-06 15:18:00 -0700 | [diff] [blame] | 1255 | */ |
Haiyang Zhang | 891de74 | 2014-02-12 16:54:27 -0800 | [diff] [blame] | 1256 | static void netvsc_link_change(struct work_struct *w) |
Haiyang Zhang | c996edc | 2011-04-06 15:18:00 -0700 | [diff] [blame] | 1257 | { |
Vitaly Kuznetsov | 0a1275c | 2016-05-13 13:55:23 +0200 | [diff] [blame] | 1258 | struct net_device_context *ndev_ctx = |
| 1259 | container_of(w, struct net_device_context, dwork.work); |
| 1260 | struct hv_device *device_obj = ndev_ctx->device_ctx; |
| 1261 | struct net_device *net = hv_get_drvdata(device_obj); |
K. Y. Srinivasan | 2ddd5e5f | 2011-09-13 10:59:49 -0700 | [diff] [blame] | 1262 | struct netvsc_device *net_device; |
Haiyang Zhang | 891de74 | 2014-02-12 16:54:27 -0800 | [diff] [blame] | 1263 | struct rndis_device *rdev; |
Vitaly Kuznetsov | 27a70af | 2015-11-27 11:39:55 +0100 | [diff] [blame] | 1264 | struct netvsc_reconfig *event = NULL; |
| 1265 | bool notify = false, reschedule = false; |
| 1266 | unsigned long flags, next_reconfig, delay; |
Haiyang Zhang | c996edc | 2011-04-06 15:18:00 -0700 | [diff] [blame] | 1267 | |
Vitaly Kuznetsov | 1bdcec8 | 2016-05-13 13:55:21 +0200 | [diff] [blame] | 1268 | rtnl_lock(); |
stephen hemminger | a0be450 | 2017-03-22 14:51:01 -0700 | [diff] [blame] | 1269 | net_device = rtnl_dereference(ndev_ctx->nvdev); |
| 1270 | if (!net_device) |
Vitaly Kuznetsov | 1bdcec8 | 2016-05-13 13:55:21 +0200 | [diff] [blame] | 1271 | goto out_unlock; |
| 1272 | |
Haiyang Zhang | 891de74 | 2014-02-12 16:54:27 -0800 | [diff] [blame] | 1273 | rdev = net_device->extension; |
Haiyang Zhang | 891de74 | 2014-02-12 16:54:27 -0800 | [diff] [blame] | 1274 | |
Vitaly Kuznetsov | 27a70af | 2015-11-27 11:39:55 +0100 | [diff] [blame] | 1275 | next_reconfig = ndev_ctx->last_reconfig + LINKCHANGE_INT; |
| 1276 | if (time_is_after_jiffies(next_reconfig)) { |
| 1277 | /* link_watch only sends one notification with current state |
| 1278 | * per second, avoid doing reconfig more frequently. Handle |
| 1279 | * wrap around. |
| 1280 | */ |
| 1281 | delay = next_reconfig - jiffies; |
| 1282 | delay = delay < LINKCHANGE_INT ? delay : LINKCHANGE_INT; |
| 1283 | schedule_delayed_work(&ndev_ctx->dwork, delay); |
Vitaly Kuznetsov | 1bdcec8 | 2016-05-13 13:55:21 +0200 | [diff] [blame] | 1284 | goto out_unlock; |
Vitaly Kuznetsov | 27a70af | 2015-11-27 11:39:55 +0100 | [diff] [blame] | 1285 | } |
| 1286 | ndev_ctx->last_reconfig = jiffies; |
| 1287 | |
| 1288 | spin_lock_irqsave(&ndev_ctx->lock, flags); |
| 1289 | if (!list_empty(&ndev_ctx->reconfig_events)) { |
| 1290 | event = list_first_entry(&ndev_ctx->reconfig_events, |
| 1291 | struct netvsc_reconfig, list); |
| 1292 | list_del(&event->list); |
| 1293 | reschedule = !list_empty(&ndev_ctx->reconfig_events); |
| 1294 | } |
| 1295 | spin_unlock_irqrestore(&ndev_ctx->lock, flags); |
| 1296 | |
| 1297 | if (!event) |
Vitaly Kuznetsov | 1bdcec8 | 2016-05-13 13:55:21 +0200 | [diff] [blame] | 1298 | goto out_unlock; |
Vitaly Kuznetsov | 27a70af | 2015-11-27 11:39:55 +0100 | [diff] [blame] | 1299 | |
| 1300 | switch (event->event) { |
| 1301 | /* Only the following events are possible due to the check in |
| 1302 | * netvsc_linkstatus_callback() |
| 1303 | */ |
| 1304 | case RNDIS_STATUS_MEDIA_CONNECT: |
| 1305 | if (rdev->link_state) { |
| 1306 | rdev->link_state = false; |
| 1307 | netif_carrier_on(net); |
| 1308 | netif_tx_wake_all_queues(net); |
| 1309 | } else { |
| 1310 | notify = true; |
Haiyang Zhang | 3a494e7 | 2014-06-19 18:34:36 -0700 | [diff] [blame] | 1311 | } |
Vitaly Kuznetsov | 27a70af | 2015-11-27 11:39:55 +0100 | [diff] [blame] | 1312 | kfree(event); |
| 1313 | break; |
| 1314 | case RNDIS_STATUS_MEDIA_DISCONNECT: |
| 1315 | if (!rdev->link_state) { |
| 1316 | rdev->link_state = true; |
| 1317 | netif_carrier_off(net); |
| 1318 | netif_tx_stop_all_queues(net); |
| 1319 | } |
| 1320 | kfree(event); |
| 1321 | break; |
| 1322 | case RNDIS_STATUS_NETWORK_CHANGE: |
| 1323 | /* Only makes sense if carrier is present */ |
| 1324 | if (!rdev->link_state) { |
| 1325 | rdev->link_state = true; |
| 1326 | netif_carrier_off(net); |
| 1327 | netif_tx_stop_all_queues(net); |
| 1328 | event->event = RNDIS_STATUS_MEDIA_CONNECT; |
| 1329 | spin_lock_irqsave(&ndev_ctx->lock, flags); |
Haiyang Zhang | 15cfd40 | 2016-04-21 16:13:01 -0700 | [diff] [blame] | 1330 | list_add(&event->list, &ndev_ctx->reconfig_events); |
Vitaly Kuznetsov | 27a70af | 2015-11-27 11:39:55 +0100 | [diff] [blame] | 1331 | spin_unlock_irqrestore(&ndev_ctx->lock, flags); |
| 1332 | reschedule = true; |
| 1333 | } |
| 1334 | break; |
Haiyang Zhang | 891de74 | 2014-02-12 16:54:27 -0800 | [diff] [blame] | 1335 | } |
| 1336 | |
| 1337 | rtnl_unlock(); |
| 1338 | |
| 1339 | if (notify) |
| 1340 | netdev_notify_peers(net); |
Vitaly Kuznetsov | 27a70af | 2015-11-27 11:39:55 +0100 | [diff] [blame] | 1341 | |
| 1342 | /* link_watch only sends one notification with current state per |
| 1343 | * second, handle next reconfig event in 2 seconds. |
| 1344 | */ |
| 1345 | if (reschedule) |
| 1346 | schedule_delayed_work(&ndev_ctx->dwork, LINKCHANGE_INT); |
Vitaly Kuznetsov | 1bdcec8 | 2016-05-13 13:55:21 +0200 | [diff] [blame] | 1347 | |
| 1348 | return; |
| 1349 | |
| 1350 | out_unlock: |
| 1351 | rtnl_unlock(); |
Haiyang Zhang | c996edc | 2011-04-06 15:18:00 -0700 | [diff] [blame] | 1352 | } |
| 1353 | |
Stephen Hemminger | e8ff40d | 2016-09-22 16:56:32 -0700 | [diff] [blame] | 1354 | static struct net_device *get_netvsc_bymac(const u8 *mac) |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 1355 | { |
Stephen Hemminger | e8ff40d | 2016-09-22 16:56:32 -0700 | [diff] [blame] | 1356 | struct net_device *dev; |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 1357 | |
Stephen Hemminger | 8737caa | 2016-08-23 12:17:44 -0700 | [diff] [blame] | 1358 | ASSERT_RTNL(); |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 1359 | |
| 1360 | for_each_netdev(&init_net, dev) { |
Stephen Hemminger | e8ff40d | 2016-09-22 16:56:32 -0700 | [diff] [blame] | 1361 | if (dev->netdev_ops != &device_ops) |
| 1362 | continue; /* not a netvsc device */ |
| 1363 | |
| 1364 | if (ether_addr_equal(mac, dev->perm_addr)) |
| 1365 | return dev; |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 1366 | } |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 1367 | |
Stephen Hemminger | e8ff40d | 2016-09-22 16:56:32 -0700 | [diff] [blame] | 1368 | return NULL; |
| 1369 | } |
| 1370 | |
Stephen Hemminger | f207c10 | 2016-09-22 16:56:33 -0700 | [diff] [blame] | 1371 | static struct net_device *get_netvsc_byref(struct net_device *vf_netdev) |
Stephen Hemminger | e8ff40d | 2016-09-22 16:56:32 -0700 | [diff] [blame] | 1372 | { |
| 1373 | struct net_device *dev; |
| 1374 | |
| 1375 | ASSERT_RTNL(); |
| 1376 | |
| 1377 | for_each_netdev(&init_net, dev) { |
| 1378 | struct net_device_context *net_device_ctx; |
| 1379 | |
| 1380 | if (dev->netdev_ops != &device_ops) |
| 1381 | continue; /* not a netvsc device */ |
| 1382 | |
| 1383 | net_device_ctx = netdev_priv(dev); |
| 1384 | if (net_device_ctx->nvdev == NULL) |
| 1385 | continue; /* device is removed */ |
| 1386 | |
Stephen Hemminger | f207c10 | 2016-09-22 16:56:33 -0700 | [diff] [blame] | 1387 | if (rtnl_dereference(net_device_ctx->vf_netdev) == vf_netdev) |
Stephen Hemminger | e8ff40d | 2016-09-22 16:56:32 -0700 | [diff] [blame] | 1388 | return dev; /* a match */ |
| 1389 | } |
| 1390 | |
| 1391 | return NULL; |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 1392 | } |
| 1393 | |
| 1394 | static int netvsc_register_vf(struct net_device *vf_netdev) |
| 1395 | { |
Vitaly Kuznetsov | 0a1275c | 2016-05-13 13:55:23 +0200 | [diff] [blame] | 1396 | struct net_device *ndev; |
| 1397 | struct net_device_context *net_device_ctx; |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 1398 | struct netvsc_device *netvsc_dev; |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 1399 | |
Stephen Hemminger | e8ff40d | 2016-09-22 16:56:32 -0700 | [diff] [blame] | 1400 | if (vf_netdev->addr_len != ETH_ALEN) |
| 1401 | return NOTIFY_DONE; |
| 1402 | |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 1403 | /* |
| 1404 | * We will use the MAC address to locate the synthetic interface to |
| 1405 | * associate with the VF interface. If we don't find a matching |
| 1406 | * synthetic interface, move on. |
| 1407 | */ |
Stephen Hemminger | e8ff40d | 2016-09-22 16:56:32 -0700 | [diff] [blame] | 1408 | ndev = get_netvsc_bymac(vf_netdev->perm_addr); |
Vitaly Kuznetsov | 0a1275c | 2016-05-13 13:55:23 +0200 | [diff] [blame] | 1409 | if (!ndev) |
| 1410 | return NOTIFY_DONE; |
| 1411 | |
| 1412 | net_device_ctx = netdev_priv(ndev); |
stephen hemminger | 545a8e7 | 2017-03-22 14:51:00 -0700 | [diff] [blame] | 1413 | netvsc_dev = rtnl_dereference(net_device_ctx->nvdev); |
Stephen Hemminger | f207c10 | 2016-09-22 16:56:33 -0700 | [diff] [blame] | 1414 | if (!netvsc_dev || rtnl_dereference(net_device_ctx->vf_netdev)) |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 1415 | return NOTIFY_DONE; |
| 1416 | |
Vitaly Kuznetsov | 0a1275c | 2016-05-13 13:55:23 +0200 | [diff] [blame] | 1417 | netdev_info(ndev, "VF registering: %s\n", vf_netdev->name); |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 1418 | /* |
| 1419 | * Take a reference on the module. |
| 1420 | */ |
| 1421 | try_module_get(THIS_MODULE); |
Stephen Hemminger | 07d0f00 | 2016-09-22 16:56:30 -0700 | [diff] [blame] | 1422 | |
| 1423 | dev_hold(vf_netdev); |
Stephen Hemminger | f207c10 | 2016-09-22 16:56:33 -0700 | [diff] [blame] | 1424 | rcu_assign_pointer(net_device_ctx->vf_netdev, vf_netdev); |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 1425 | return NOTIFY_OK; |
| 1426 | } |
| 1427 | |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 1428 | static int netvsc_vf_up(struct net_device *vf_netdev) |
| 1429 | { |
Vitaly Kuznetsov | 0a1275c | 2016-05-13 13:55:23 +0200 | [diff] [blame] | 1430 | struct net_device *ndev; |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 1431 | struct netvsc_device *netvsc_dev; |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 1432 | struct net_device_context *net_device_ctx; |
| 1433 | |
Stephen Hemminger | e8ff40d | 2016-09-22 16:56:32 -0700 | [diff] [blame] | 1434 | ndev = get_netvsc_byref(vf_netdev); |
Vitaly Kuznetsov | 0a1275c | 2016-05-13 13:55:23 +0200 | [diff] [blame] | 1435 | if (!ndev) |
| 1436 | return NOTIFY_DONE; |
| 1437 | |
| 1438 | net_device_ctx = netdev_priv(ndev); |
stephen hemminger | 545a8e7 | 2017-03-22 14:51:00 -0700 | [diff] [blame] | 1439 | netvsc_dev = rtnl_dereference(net_device_ctx->nvdev); |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 1440 | |
Vitaly Kuznetsov | 0a1275c | 2016-05-13 13:55:23 +0200 | [diff] [blame] | 1441 | netdev_info(ndev, "VF up: %s\n", vf_netdev->name); |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 1442 | |
| 1443 | /* |
| 1444 | * Open the device before switching data path. |
| 1445 | */ |
Vitaly Kuznetsov | 2f5fa6c | 2016-06-03 17:51:00 +0200 | [diff] [blame] | 1446 | rndis_filter_open(netvsc_dev); |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 1447 | |
| 1448 | /* |
| 1449 | * notify the host to switch the data path. |
| 1450 | */ |
Vitaly Kuznetsov | 0a1275c | 2016-05-13 13:55:23 +0200 | [diff] [blame] | 1451 | netvsc_switch_datapath(ndev, true); |
| 1452 | netdev_info(ndev, "Data path switched to VF: %s\n", vf_netdev->name); |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 1453 | |
Vitaly Kuznetsov | 0a1275c | 2016-05-13 13:55:23 +0200 | [diff] [blame] | 1454 | netif_carrier_off(ndev); |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 1455 | |
Vitaly Kuznetsov | d072218 | 2016-08-15 17:48:40 +0200 | [diff] [blame] | 1456 | /* Now notify peers through VF device. */ |
| 1457 | call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, vf_netdev); |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 1458 | |
| 1459 | return NOTIFY_OK; |
| 1460 | } |
| 1461 | |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 1462 | static int netvsc_vf_down(struct net_device *vf_netdev) |
| 1463 | { |
Vitaly Kuznetsov | 0a1275c | 2016-05-13 13:55:23 +0200 | [diff] [blame] | 1464 | struct net_device *ndev; |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 1465 | struct netvsc_device *netvsc_dev; |
| 1466 | struct net_device_context *net_device_ctx; |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 1467 | |
Stephen Hemminger | e8ff40d | 2016-09-22 16:56:32 -0700 | [diff] [blame] | 1468 | ndev = get_netvsc_byref(vf_netdev); |
Vitaly Kuznetsov | 0a1275c | 2016-05-13 13:55:23 +0200 | [diff] [blame] | 1469 | if (!ndev) |
| 1470 | return NOTIFY_DONE; |
| 1471 | |
| 1472 | net_device_ctx = netdev_priv(ndev); |
stephen hemminger | 545a8e7 | 2017-03-22 14:51:00 -0700 | [diff] [blame] | 1473 | netvsc_dev = rtnl_dereference(net_device_ctx->nvdev); |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 1474 | |
Vitaly Kuznetsov | 0a1275c | 2016-05-13 13:55:23 +0200 | [diff] [blame] | 1475 | netdev_info(ndev, "VF down: %s\n", vf_netdev->name); |
Vitaly Kuznetsov | 0a1275c | 2016-05-13 13:55:23 +0200 | [diff] [blame] | 1476 | netvsc_switch_datapath(ndev, false); |
| 1477 | netdev_info(ndev, "Data path switched from VF: %s\n", vf_netdev->name); |
Vitaly Kuznetsov | 2f5fa6c | 2016-06-03 17:51:00 +0200 | [diff] [blame] | 1478 | rndis_filter_close(netvsc_dev); |
Vitaly Kuznetsov | 0a1275c | 2016-05-13 13:55:23 +0200 | [diff] [blame] | 1479 | netif_carrier_on(ndev); |
Vitaly Kuznetsov | d072218 | 2016-08-15 17:48:40 +0200 | [diff] [blame] | 1480 | |
| 1481 | /* Now notify peers through netvsc device. */ |
| 1482 | call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, ndev); |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 1483 | |
| 1484 | return NOTIFY_OK; |
| 1485 | } |
| 1486 | |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 1487 | static int netvsc_unregister_vf(struct net_device *vf_netdev) |
| 1488 | { |
Vitaly Kuznetsov | 0a1275c | 2016-05-13 13:55:23 +0200 | [diff] [blame] | 1489 | struct net_device *ndev; |
Vitaly Kuznetsov | 0a1275c | 2016-05-13 13:55:23 +0200 | [diff] [blame] | 1490 | struct net_device_context *net_device_ctx; |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 1491 | |
Stephen Hemminger | e8ff40d | 2016-09-22 16:56:32 -0700 | [diff] [blame] | 1492 | ndev = get_netvsc_byref(vf_netdev); |
Vitaly Kuznetsov | 0a1275c | 2016-05-13 13:55:23 +0200 | [diff] [blame] | 1493 | if (!ndev) |
| 1494 | return NOTIFY_DONE; |
| 1495 | |
| 1496 | net_device_ctx = netdev_priv(ndev); |
Stephen Hemminger | e8ff40d | 2016-09-22 16:56:32 -0700 | [diff] [blame] | 1497 | |
Vitaly Kuznetsov | 0a1275c | 2016-05-13 13:55:23 +0200 | [diff] [blame] | 1498 | netdev_info(ndev, "VF unregistering: %s\n", vf_netdev->name); |
Stephen Hemminger | f207c10 | 2016-09-22 16:56:33 -0700 | [diff] [blame] | 1499 | |
| 1500 | RCU_INIT_POINTER(net_device_ctx->vf_netdev, NULL); |
Stephen Hemminger | 07d0f00 | 2016-09-22 16:56:30 -0700 | [diff] [blame] | 1501 | dev_put(vf_netdev); |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 1502 | module_put(THIS_MODULE); |
| 1503 | return NOTIFY_OK; |
| 1504 | } |
| 1505 | |
K. Y. Srinivasan | 8494689 | 2011-09-13 10:59:38 -0700 | [diff] [blame] | 1506 | static int netvsc_probe(struct hv_device *dev, |
| 1507 | const struct hv_vmbus_device_id *dev_id) |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1508 | { |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1509 | struct net_device *net = NULL; |
| 1510 | struct net_device_context *net_device_ctx; |
| 1511 | struct netvsc_device_info device_info; |
Haiyang Zhang | 5b54dac | 2014-04-21 10:20:28 -0700 | [diff] [blame] | 1512 | struct netvsc_device *nvdev; |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1513 | int ret; |
| 1514 | |
Haiyang Zhang | 5b54dac | 2014-04-21 10:20:28 -0700 | [diff] [blame] | 1515 | net = alloc_etherdev_mq(sizeof(struct net_device_context), |
stephen hemminger | 2b01888 | 2017-01-24 13:06:03 -0800 | [diff] [blame] | 1516 | VRSS_CHANNEL_MAX); |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1517 | if (!net) |
K. Y. Srinivasan | 51a805d | 2011-08-25 09:49:11 -0700 | [diff] [blame] | 1518 | return -ENOMEM; |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1519 | |
Haiyang Zhang | 1b07da5 | 2014-03-04 14:11:06 -0800 | [diff] [blame] | 1520 | netif_carrier_off(net); |
| 1521 | |
Haiyang Zhang | b37879e | 2016-08-04 10:42:14 -0700 | [diff] [blame] | 1522 | netvsc_init_settings(net); |
| 1523 | |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1524 | net_device_ctx = netdev_priv(net); |
K. Y. Srinivasan | 9efd21e | 2011-04-29 13:45:10 -0700 | [diff] [blame] | 1525 | net_device_ctx->device_ctx = dev; |
Simon Xiao | 3f300ff | 2015-04-28 01:05:17 -0700 | [diff] [blame] | 1526 | net_device_ctx->msg_enable = netif_msg_init(debug, default_msg); |
| 1527 | if (netif_msg_probe(net_device_ctx)) |
| 1528 | netdev_dbg(net, "netvsc msg_enable: %d\n", |
| 1529 | net_device_ctx->msg_enable); |
| 1530 | |
K. Y. Srinivasan | 2ddd5e5f | 2011-09-13 10:59:49 -0700 | [diff] [blame] | 1531 | hv_set_drvdata(dev, net); |
Vitaly Kuznetsov | f580aec | 2016-05-13 13:55:20 +0200 | [diff] [blame] | 1532 | |
Haiyang Zhang | 891de74 | 2014-02-12 16:54:27 -0800 | [diff] [blame] | 1533 | INIT_DELAYED_WORK(&net_device_ctx->dwork, netvsc_link_change); |
Wenqi Ma | 792df87 | 2012-04-19 00:39:37 +0000 | [diff] [blame] | 1534 | INIT_WORK(&net_device_ctx->work, do_set_multicast); |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1535 | |
Vitaly Kuznetsov | 27a70af | 2015-11-27 11:39:55 +0100 | [diff] [blame] | 1536 | spin_lock_init(&net_device_ctx->lock); |
| 1537 | INIT_LIST_HEAD(&net_device_ctx->reconfig_events); |
| 1538 | |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1539 | net->netdev_ops = &device_ops; |
Wilfried Klaebe | 7ad24ea | 2014-05-11 00:12:32 +0000 | [diff] [blame] | 1540 | net->ethtool_ops = ðtool_ops; |
K. Y. Srinivasan | 9efd21e | 2011-04-29 13:45:10 -0700 | [diff] [blame] | 1541 | SET_NETDEV_DEV(net, &dev->device); |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1542 | |
Vitaly Kuznetsov | 14a03cf | 2016-02-05 17:29:08 +0100 | [diff] [blame] | 1543 | /* We always need headroom for rndis header */ |
| 1544 | net->needed_headroom = RNDIS_AND_PPI_SIZE; |
| 1545 | |
Haiyang Zhang | 692e084 | 2011-09-01 12:19:43 -0700 | [diff] [blame] | 1546 | /* Notify the netvsc driver of the new device */ |
Andrew Schwartzmeyer | 8ebdcc5 | 2015-08-11 17:14:31 -0700 | [diff] [blame] | 1547 | memset(&device_info, 0, sizeof(device_info)); |
Haiyang Zhang | 692e084 | 2011-09-01 12:19:43 -0700 | [diff] [blame] | 1548 | device_info.ring_size = ring_size; |
stephen hemminger | 3071ada | 2017-03-22 14:50:59 -0700 | [diff] [blame] | 1549 | device_info.num_chn = VRSS_CHANNEL_DEFAULT; |
Haiyang Zhang | 692e084 | 2011-09-01 12:19:43 -0700 | [diff] [blame] | 1550 | ret = rndis_filter_device_add(dev, &device_info); |
| 1551 | if (ret != 0) { |
| 1552 | netdev_err(net, "unable to add netvsc device (ret %d)\n", ret); |
Simon Xiao | 6c80f3f | 2017-01-24 13:06:13 -0800 | [diff] [blame] | 1553 | free_netdev(net); |
K. Y. Srinivasan | 2ddd5e5f | 2011-09-13 10:59:49 -0700 | [diff] [blame] | 1554 | hv_set_drvdata(dev, NULL); |
Haiyang Zhang | 692e084 | 2011-09-01 12:19:43 -0700 | [diff] [blame] | 1555 | return ret; |
| 1556 | } |
| 1557 | memcpy(net->dev_addr, device_info.mac_adr, ETH_ALEN); |
| 1558 | |
stephen hemminger | 23312a3 | 2017-01-24 13:05:59 -0800 | [diff] [blame] | 1559 | /* hw_features computed in rndis_filter_device_add */ |
| 1560 | net->features = net->hw_features | |
| 1561 | NETIF_F_HIGHDMA | NETIF_F_SG | |
| 1562 | NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX; |
| 1563 | net->vlan_features = net->features; |
| 1564 | |
stephen hemminger | 545a8e7 | 2017-03-22 14:51:00 -0700 | [diff] [blame] | 1565 | /* RCU not necessary here, device not registered */ |
Vitaly Kuznetsov | 3d541ac | 2016-05-13 13:55:22 +0200 | [diff] [blame] | 1566 | nvdev = net_device_ctx->nvdev; |
Haiyang Zhang | 5b54dac | 2014-04-21 10:20:28 -0700 | [diff] [blame] | 1567 | netif_set_real_num_tx_queues(net, nvdev->num_chn); |
| 1568 | netif_set_real_num_rx_queues(net, nvdev->num_chn); |
Haiyang Zhang | 5b54dac | 2014-04-21 10:20:28 -0700 | [diff] [blame] | 1569 | |
Jarod Wilson | d0c2c99 | 2016-10-20 13:55:21 -0400 | [diff] [blame] | 1570 | /* MTU range: 68 - 1500 or 65521 */ |
| 1571 | net->min_mtu = NETVSC_MTU_MIN; |
| 1572 | if (nvdev->nvsp_version >= NVSP_PROTOCOL_VERSION_2) |
| 1573 | net->max_mtu = NETVSC_MTU - ETH_HLEN; |
| 1574 | else |
| 1575 | net->max_mtu = ETH_DATA_LEN; |
| 1576 | |
Haiyang Zhang | a68f961 | 2013-12-20 16:52:31 -0800 | [diff] [blame] | 1577 | ret = register_netdev(net); |
| 1578 | if (ret != 0) { |
| 1579 | pr_err("Unable to register netdev.\n"); |
stephen hemminger | 2289f0a | 2017-01-24 13:06:10 -0800 | [diff] [blame] | 1580 | rndis_filter_device_remove(dev, nvdev); |
Simon Xiao | 6c80f3f | 2017-01-24 13:06:13 -0800 | [diff] [blame] | 1581 | free_netdev(net); |
Haiyang Zhang | a68f961 | 2013-12-20 16:52:31 -0800 | [diff] [blame] | 1582 | } |
| 1583 | |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1584 | return ret; |
| 1585 | } |
| 1586 | |
K. Y. Srinivasan | 415b023 | 2011-04-29 13:45:12 -0700 | [diff] [blame] | 1587 | static int netvsc_remove(struct hv_device *dev) |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1588 | { |
K. Y. Srinivasan | 2ddd5e5f | 2011-09-13 10:59:49 -0700 | [diff] [blame] | 1589 | struct net_device *net; |
Haiyang Zhang | 122a5f6 | 2011-05-27 06:21:55 -0700 | [diff] [blame] | 1590 | struct net_device_context *ndev_ctx; |
K. Y. Srinivasan | 2ddd5e5f | 2011-09-13 10:59:49 -0700 | [diff] [blame] | 1591 | |
Vitaly Kuznetsov | 3d541ac | 2016-05-13 13:55:22 +0200 | [diff] [blame] | 1592 | net = hv_get_drvdata(dev); |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1593 | |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1594 | if (net == NULL) { |
K. Y. Srinivasan | 415b023 | 2011-04-29 13:45:12 -0700 | [diff] [blame] | 1595 | dev_err(&dev->device, "No net device to remove\n"); |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1596 | return 0; |
| 1597 | } |
| 1598 | |
Haiyang Zhang | 122a5f6 | 2011-05-27 06:21:55 -0700 | [diff] [blame] | 1599 | ndev_ctx = netdev_priv(net); |
Vitaly Kuznetsov | 3d541ac | 2016-05-13 13:55:22 +0200 | [diff] [blame] | 1600 | |
stephen hemminger | a0be450 | 2017-03-22 14:51:01 -0700 | [diff] [blame] | 1601 | netif_device_detach(net); |
Vitaly Kuznetsov | f580aec | 2016-05-13 13:55:20 +0200 | [diff] [blame] | 1602 | |
Haiyang Zhang | 122a5f6 | 2011-05-27 06:21:55 -0700 | [diff] [blame] | 1603 | cancel_delayed_work_sync(&ndev_ctx->dwork); |
Wenqi Ma | 792df87 | 2012-04-19 00:39:37 +0000 | [diff] [blame] | 1604 | cancel_work_sync(&ndev_ctx->work); |
Haiyang Zhang | 122a5f6 | 2011-05-27 06:21:55 -0700 | [diff] [blame] | 1605 | |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1606 | /* |
| 1607 | * Call to the vsc driver to let it know that the device is being |
stephen hemminger | a0be450 | 2017-03-22 14:51:01 -0700 | [diff] [blame] | 1608 | * removed. Also blocks mtu and channel changes. |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1609 | */ |
stephen hemminger | a0be450 | 2017-03-22 14:51:01 -0700 | [diff] [blame] | 1610 | rtnl_lock(); |
stephen hemminger | 2289f0a | 2017-01-24 13:06:10 -0800 | [diff] [blame] | 1611 | rndis_filter_device_remove(dev, ndev_ctx->nvdev); |
stephen hemminger | a0be450 | 2017-03-22 14:51:01 -0700 | [diff] [blame] | 1612 | rtnl_unlock(); |
| 1613 | |
| 1614 | unregister_netdev(net); |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1615 | |
Vitaly Kuznetsov | 3d541ac | 2016-05-13 13:55:22 +0200 | [diff] [blame] | 1616 | hv_set_drvdata(dev, NULL); |
| 1617 | |
Simon Xiao | 6c80f3f | 2017-01-24 13:06:13 -0800 | [diff] [blame] | 1618 | free_netdev(net); |
Haiyang Zhang | df06bcf | 2011-05-23 09:03:47 -0700 | [diff] [blame] | 1619 | return 0; |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1620 | } |
| 1621 | |
K. Y. Srinivasan | 345c4cc | 2011-08-25 09:48:34 -0700 | [diff] [blame] | 1622 | static const struct hv_vmbus_device_id id_table[] = { |
Greg Kroah-Hartman | c45cf2d | 2011-08-25 11:41:33 -0700 | [diff] [blame] | 1623 | /* Network guid */ |
K. Y. Srinivasan | 8f50594 | 2013-01-23 17:42:42 -0800 | [diff] [blame] | 1624 | { HV_NIC_GUID, }, |
Greg Kroah-Hartman | c45cf2d | 2011-08-25 11:41:33 -0700 | [diff] [blame] | 1625 | { }, |
K. Y. Srinivasan | 345c4cc | 2011-08-25 09:48:34 -0700 | [diff] [blame] | 1626 | }; |
| 1627 | |
| 1628 | MODULE_DEVICE_TABLE(vmbus, id_table); |
| 1629 | |
K. Y. Srinivasan | f1542a6 | 2011-05-10 07:55:16 -0700 | [diff] [blame] | 1630 | /* The one and only one */ |
K. Y. Srinivasan | fde0ef9 | 2011-05-12 19:35:08 -0700 | [diff] [blame] | 1631 | static struct hv_driver netvsc_drv = { |
Haiyang Zhang | d31b20f | 2012-03-07 10:02:00 +0000 | [diff] [blame] | 1632 | .name = KBUILD_MODNAME, |
K. Y. Srinivasan | 345c4cc | 2011-08-25 09:48:34 -0700 | [diff] [blame] | 1633 | .id_table = id_table, |
K. Y. Srinivasan | fde0ef9 | 2011-05-12 19:35:08 -0700 | [diff] [blame] | 1634 | .probe = netvsc_probe, |
| 1635 | .remove = netvsc_remove, |
K. Y. Srinivasan | d489097 | 2011-05-10 07:55:17 -0700 | [diff] [blame] | 1636 | }; |
K. Y. Srinivasan | f1542a6 | 2011-05-10 07:55:16 -0700 | [diff] [blame] | 1637 | |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 1638 | /* |
| 1639 | * On Hyper-V, every VF interface is matched with a corresponding |
| 1640 | * synthetic interface. The synthetic interface is presented first |
| 1641 | * to the guest. When the corresponding VF instance is registered, |
| 1642 | * we will take care of switching the data path. |
| 1643 | */ |
| 1644 | static int netvsc_netdev_event(struct notifier_block *this, |
| 1645 | unsigned long event, void *ptr) |
| 1646 | { |
| 1647 | struct net_device *event_dev = netdev_notifier_info_to_dev(ptr); |
| 1648 | |
Stephen Hemminger | ee837a1 | 2016-09-22 16:56:31 -0700 | [diff] [blame] | 1649 | /* Skip our own events */ |
| 1650 | if (event_dev->netdev_ops == &device_ops) |
| 1651 | return NOTIFY_DONE; |
| 1652 | |
| 1653 | /* Avoid non-Ethernet type devices */ |
| 1654 | if (event_dev->type != ARPHRD_ETHER) |
| 1655 | return NOTIFY_DONE; |
| 1656 | |
Vitaly Kuznetsov | 0dbff14 | 2016-08-15 17:48:43 +0200 | [diff] [blame] | 1657 | /* Avoid Vlan dev with same MAC registering as VF */ |
Parav Pandit | d0d7b10 | 2017-02-04 11:00:49 -0600 | [diff] [blame] | 1658 | if (is_vlan_dev(event_dev)) |
Vitaly Kuznetsov | 0dbff14 | 2016-08-15 17:48:43 +0200 | [diff] [blame] | 1659 | return NOTIFY_DONE; |
| 1660 | |
| 1661 | /* Avoid Bonding master dev with same MAC registering as VF */ |
Stephen Hemminger | ee837a1 | 2016-09-22 16:56:31 -0700 | [diff] [blame] | 1662 | if ((event_dev->priv_flags & IFF_BONDING) && |
| 1663 | (event_dev->flags & IFF_MASTER)) |
Haiyang Zhang | cb2911f | 2016-06-02 12:02:04 -0700 | [diff] [blame] | 1664 | return NOTIFY_DONE; |
| 1665 | |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 1666 | switch (event) { |
| 1667 | case NETDEV_REGISTER: |
| 1668 | return netvsc_register_vf(event_dev); |
| 1669 | case NETDEV_UNREGISTER: |
| 1670 | return netvsc_unregister_vf(event_dev); |
| 1671 | case NETDEV_UP: |
| 1672 | return netvsc_vf_up(event_dev); |
| 1673 | case NETDEV_DOWN: |
| 1674 | return netvsc_vf_down(event_dev); |
| 1675 | default: |
| 1676 | return NOTIFY_DONE; |
| 1677 | } |
| 1678 | } |
| 1679 | |
| 1680 | static struct notifier_block netvsc_netdev_notifier = { |
| 1681 | .notifier_call = netvsc_netdev_event, |
| 1682 | }; |
| 1683 | |
K. Y. Srinivasan | a9869c9 | 2011-05-12 19:35:17 -0700 | [diff] [blame] | 1684 | static void __exit netvsc_drv_exit(void) |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 1685 | { |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 1686 | unregister_netdevice_notifier(&netvsc_netdev_notifier); |
Greg Kroah-Hartman | 768fa21 | 2011-08-25 15:07:32 -0700 | [diff] [blame] | 1687 | vmbus_driver_unregister(&netvsc_drv); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 1688 | } |
| 1689 | |
K. Y. Srinivasan | 1fde28c | 2011-05-12 19:35:16 -0700 | [diff] [blame] | 1690 | static int __init netvsc_drv_init(void) |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1691 | { |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 1692 | int ret; |
| 1693 | |
Haiyang Zhang | fa85a6c | 2012-07-25 08:08:41 +0000 | [diff] [blame] | 1694 | if (ring_size < RING_SIZE_MIN) { |
| 1695 | ring_size = RING_SIZE_MIN; |
| 1696 | pr_info("Increased ring_size to %d (min allowed)\n", |
| 1697 | ring_size); |
| 1698 | } |
KY Srinivasan | 84bf9ce | 2016-04-14 16:31:54 -0700 | [diff] [blame] | 1699 | ret = vmbus_driver_register(&netvsc_drv); |
| 1700 | |
| 1701 | if (ret) |
| 1702 | return ret; |
| 1703 | |
| 1704 | register_netdevice_notifier(&netvsc_netdev_notifier); |
| 1705 | return 0; |
Greg Kroah-Hartman | df2fff2 | 2009-08-31 21:11:12 -0700 | [diff] [blame] | 1706 | } |
| 1707 | |
Hank Janssen | 26c14cc | 2010-02-11 23:02:42 +0000 | [diff] [blame] | 1708 | MODULE_LICENSE("GPL"); |
Stephen Hemminger | 7880fc5 | 2010-05-04 09:58:52 -0700 | [diff] [blame] | 1709 | MODULE_DESCRIPTION("Microsoft Hyper-V network driver"); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 1710 | |
K. Y. Srinivasan | 1fde28c | 2011-05-12 19:35:16 -0700 | [diff] [blame] | 1711 | module_init(netvsc_drv_init); |
K. Y. Srinivasan | a9869c9 | 2011-05-12 19:35:17 -0700 | [diff] [blame] | 1712 | module_exit(netvsc_drv_exit); |