Commit | Line | Data |
---|---|---|
fceaf24a | 1 | /* |
fceaf24a HJ |
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 | |
14 | * this program; if not, write to the Free Software Foundation, Inc., 59 Temple | |
15 | * Place - Suite 330, Boston, MA 02111-1307 USA. | |
16 | * | |
17 | * Authors: | |
d0e94d17 | 18 | * Haiyang Zhang <haiyangz@microsoft.com> |
fceaf24a | 19 | * Hank Janssen <hjanssen@microsoft.com> |
fceaf24a | 20 | */ |
fceaf24a HJ |
21 | #include <linux/init.h> |
22 | #include <linux/module.h> | |
23 | #include <linux/highmem.h> | |
24 | #include <linux/device.h> | |
fceaf24a | 25 | #include <linux/io.h> |
fceaf24a HJ |
26 | #include <linux/delay.h> |
27 | #include <linux/netdevice.h> | |
28 | #include <linux/inetdevice.h> | |
29 | #include <linux/etherdevice.h> | |
30 | #include <linux/skbuff.h> | |
31 | #include <linux/in.h> | |
5a0e3ad6 | 32 | #include <linux/slab.h> |
06e719d8 S |
33 | #include <linux/dmi.h> |
34 | #include <linux/pci.h> | |
fceaf24a HJ |
35 | #include <net/arp.h> |
36 | #include <net/route.h> | |
37 | #include <net/sock.h> | |
38 | #include <net/pkt_sched.h> | |
4983b39a | 39 | #include "osd.h" |
645954c5 | 40 | #include "logging.h" |
2d82f6c7 | 41 | #include "version_info.h" |
870cde80 | 42 | #include "vmbus.h" |
a82c7a2a | 43 | #include "netvsc_api.h" |
fceaf24a | 44 | |
fceaf24a | 45 | struct net_device_context { |
02fafbc6 | 46 | /* point back to our device context */ |
f916a34d | 47 | struct vm_device *device_ctx; |
b220f5f9 | 48 | unsigned long avail; |
fceaf24a HJ |
49 | }; |
50 | ||
51 | struct netvsc_driver_context { | |
454f18a9 | 52 | /* !! These must be the first 2 fields !! */ |
7e23a6e9 | 53 | /* Which is a bug FIXME! */ |
02fafbc6 | 54 | struct driver_context drv_ctx; |
7e23a6e9 | 55 | struct netvsc_driver drv_obj; |
fceaf24a HJ |
56 | }; |
57 | ||
b220f5f9 SH |
58 | #define PACKET_PAGES_LOWATER 8 |
59 | /* Need this many pages to handle worst case fragmented packet */ | |
60 | #define PACKET_PAGES_HIWATER (MAX_SKB_FRAGS + 2) | |
61 | ||
99c8da0f | 62 | static int ring_size = 128; |
450d7a4b SH |
63 | module_param(ring_size, int, S_IRUGO); |
64 | MODULE_PARM_DESC(ring_size, "Ring buffer size (# of pages)"); | |
fceaf24a | 65 | |
454f18a9 | 66 | /* The one and only one */ |
fceaf24a HJ |
67 | static struct netvsc_driver_context g_netvsc_drv; |
68 | ||
0ff36f69 BP |
69 | /* no-op so the netdev core doesn't return -EINVAL when modifying the the |
70 | * multicast address list in SIOCADDMULTI. hv is setup to get all multicast | |
71 | * when it calls RndisFilterOnOpen() */ | |
4e9bfefa | 72 | static void netvsc_set_multicast_list(struct net_device *net) |
fceaf24a HJ |
73 | { |
74 | } | |
75 | ||
fceaf24a HJ |
76 | static int netvsc_open(struct net_device *net) |
77 | { | |
fceaf24a | 78 | struct net_device_context *net_device_ctx = netdev_priv(net); |
3d3b5518 | 79 | struct hv_device *device_obj = &net_device_ctx->device_ctx->device_obj; |
02fafbc6 | 80 | int ret = 0; |
fceaf24a | 81 | |
02fafbc6 | 82 | if (netif_carrier_ok(net)) { |
454f18a9 | 83 | /* Open up the device */ |
9c26aa0d | 84 | ret = rndis_filter_open(device_obj); |
02fafbc6 GKH |
85 | if (ret != 0) { |
86 | DPRINT_ERR(NETVSC_DRV, | |
87 | "unable to open device (ret %d).", ret); | |
fceaf24a HJ |
88 | return ret; |
89 | } | |
90 | ||
91 | netif_start_queue(net); | |
02fafbc6 | 92 | } else { |
fceaf24a HJ |
93 | DPRINT_ERR(NETVSC_DRV, "unable to open device...link is down."); |
94 | } | |
95 | ||
fceaf24a HJ |
96 | return ret; |
97 | } | |
98 | ||
fceaf24a HJ |
99 | static int netvsc_close(struct net_device *net) |
100 | { | |
fceaf24a | 101 | struct net_device_context *net_device_ctx = netdev_priv(net); |
3d3b5518 | 102 | struct hv_device *device_obj = &net_device_ctx->device_ctx->device_obj; |
02fafbc6 | 103 | int ret; |
fceaf24a | 104 | |
fceaf24a HJ |
105 | netif_stop_queue(net); |
106 | ||
9c26aa0d | 107 | ret = rndis_filter_close(device_obj); |
fceaf24a | 108 | if (ret != 0) |
fceaf24a | 109 | DPRINT_ERR(NETVSC_DRV, "unable to close device (ret %d).", ret); |
fceaf24a | 110 | |
fceaf24a HJ |
111 | return ret; |
112 | } | |
113 | ||
fceaf24a HJ |
114 | static void netvsc_xmit_completion(void *context) |
115 | { | |
4193d4f4 | 116 | struct hv_netvsc_packet *packet = (struct hv_netvsc_packet *)context; |
02fafbc6 | 117 | struct sk_buff *skb = (struct sk_buff *) |
72a2f5bd | 118 | (unsigned long)packet->completion.send.send_completion_tid; |
fceaf24a | 119 | |
fceaf24a HJ |
120 | kfree(packet); |
121 | ||
02fafbc6 | 122 | if (skb) { |
7880fc54 | 123 | struct net_device *net = skb->dev; |
b220f5f9 SH |
124 | struct net_device_context *net_device_ctx = netdev_priv(net); |
125 | unsigned int num_pages = skb_shinfo(skb)->nr_frags + 2; | |
fceaf24a | 126 | |
b220f5f9 | 127 | dev_kfree_skb_any(skb); |
fceaf24a | 128 | |
b220f5f9 SH |
129 | if ((net_device_ctx->avail += num_pages) >= PACKET_PAGES_HIWATER) |
130 | netif_wake_queue(net); | |
fceaf24a | 131 | } |
fceaf24a HJ |
132 | } |
133 | ||
02fafbc6 | 134 | static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net) |
fceaf24a | 135 | { |
fceaf24a | 136 | struct net_device_context *net_device_ctx = netdev_priv(net); |
02fafbc6 GKH |
137 | struct driver_context *driver_ctx = |
138 | driver_to_driver_context(net_device_ctx->device_ctx->device.driver); | |
139 | struct netvsc_driver_context *net_drv_ctx = | |
140 | (struct netvsc_driver_context *)driver_ctx; | |
7e23a6e9 | 141 | struct netvsc_driver *net_drv_obj = &net_drv_ctx->drv_obj; |
4193d4f4 | 142 | struct hv_netvsc_packet *packet; |
02fafbc6 | 143 | int ret; |
6048718d | 144 | unsigned int i, num_pages; |
fceaf24a | 145 | |
02fafbc6 GKH |
146 | DPRINT_DBG(NETVSC_DRV, "xmit packet - len %d data_len %d", |
147 | skb->len, skb->data_len); | |
fceaf24a | 148 | |
6048718d SH |
149 | /* Add 1 for skb->data and additional one for RNDIS */ |
150 | num_pages = skb_shinfo(skb)->nr_frags + 1 + 1; | |
b220f5f9 SH |
151 | if (num_pages > net_device_ctx->avail) |
152 | return NETDEV_TX_BUSY; | |
fceaf24a | 153 | |
454f18a9 | 154 | /* Allocate a netvsc packet based on # of frags. */ |
02fafbc6 | 155 | packet = kzalloc(sizeof(struct hv_netvsc_packet) + |
6048718d | 156 | (num_pages * sizeof(struct hv_page_buffer)) + |
72a2f5bd | 157 | net_drv_obj->req_ext_size, GFP_ATOMIC); |
02fafbc6 | 158 | if (!packet) { |
b220f5f9 | 159 | /* out of memory, silently drop packet */ |
4193d4f4 | 160 | DPRINT_ERR(NETVSC_DRV, "unable to allocate hv_netvsc_packet"); |
b220f5f9 SH |
161 | |
162 | dev_kfree_skb(skb); | |
163 | net->stats.tx_dropped++; | |
164 | return NETDEV_TX_OK; | |
fceaf24a HJ |
165 | } |
166 | ||
72a2f5bd | 167 | packet->extension = (void *)(unsigned long)packet + |
02fafbc6 | 168 | sizeof(struct hv_netvsc_packet) + |
6048718d | 169 | (num_pages * sizeof(struct hv_page_buffer)); |
fceaf24a | 170 | |
454f18a9 | 171 | /* Setup the rndis header */ |
72a2f5bd | 172 | packet->page_buf_cnt = num_pages; |
fceaf24a | 173 | |
454f18a9 BP |
174 | /* TODO: Flush all write buffers/ memory fence ??? */ |
175 | /* wmb(); */ | |
fceaf24a | 176 | |
454f18a9 | 177 | /* Initialize it from the skb */ |
72a2f5bd | 178 | packet->total_data_buflen = skb->len; |
fceaf24a | 179 | |
6048718d | 180 | /* Start filling in the page buffers starting after RNDIS buffer. */ |
72a2f5bd HZ |
181 | packet->page_buf[1].Pfn = virt_to_phys(skb->data) >> PAGE_SHIFT; |
182 | packet->page_buf[1].Offset | |
6048718d | 183 | = (unsigned long)skb->data & (PAGE_SIZE - 1); |
72a2f5bd | 184 | packet->page_buf[1].Length = skb_headlen(skb); |
6048718d SH |
185 | |
186 | /* Additional fragments are after SKB data */ | |
187 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { | |
188 | skb_frag_t *f = &skb_shinfo(skb)->frags[i]; | |
189 | ||
72a2f5bd HZ |
190 | packet->page_buf[i+2].Pfn = page_to_pfn(f->page); |
191 | packet->page_buf[i+2].Offset = f->page_offset; | |
192 | packet->page_buf[i+2].Length = f->size; | |
fceaf24a HJ |
193 | } |
194 | ||
454f18a9 | 195 | /* Set the completion routine */ |
72a2f5bd HZ |
196 | packet->completion.send.send_completion = netvsc_xmit_completion; |
197 | packet->completion.send.send_completion_ctx = packet; | |
198 | packet->completion.send.send_completion_tid = (unsigned long)skb; | |
fceaf24a | 199 | |
72a2f5bd | 200 | ret = net_drv_obj->send(&net_device_ctx->device_ctx->device_obj, |
02fafbc6 | 201 | packet); |
02fafbc6 | 202 | if (ret == 0) { |
b852fdce SH |
203 | net->stats.tx_bytes += skb->len; |
204 | net->stats.tx_packets++; | |
fceaf24a | 205 | |
b220f5f9 SH |
206 | DPRINT_DBG(NETVSC_DRV, "# of xmits %lu total size %lu", |
207 | net->stats.tx_packets, | |
208 | net->stats.tx_bytes); | |
fceaf24a | 209 | |
b220f5f9 SH |
210 | if ((net_device_ctx->avail -= num_pages) < PACKET_PAGES_LOWATER) |
211 | netif_stop_queue(net); | |
212 | } else { | |
213 | /* we are shutting down or bus overloaded, just drop packet */ | |
b852fdce | 214 | net->stats.tx_dropped++; |
b220f5f9 | 215 | netvsc_xmit_completion(packet); |
fceaf24a HJ |
216 | } |
217 | ||
b220f5f9 | 218 | return NETDEV_TX_OK; |
fceaf24a HJ |
219 | } |
220 | ||
3e189519 | 221 | /* |
02fafbc6 GKH |
222 | * netvsc_linkstatus_callback - Link up/down notification |
223 | */ | |
224 | static void netvsc_linkstatus_callback(struct hv_device *device_obj, | |
225 | unsigned int status) | |
fceaf24a | 226 | { |
f916a34d | 227 | struct vm_device *device_ctx = to_vm_device(device_obj); |
02fafbc6 | 228 | struct net_device *net = dev_get_drvdata(&device_ctx->device); |
fceaf24a | 229 | |
02fafbc6 GKH |
230 | if (!net) { |
231 | DPRINT_ERR(NETVSC_DRV, "got link status but net device " | |
232 | "not initialized yet"); | |
fceaf24a HJ |
233 | return; |
234 | } | |
235 | ||
02fafbc6 | 236 | if (status == 1) { |
fceaf24a HJ |
237 | netif_carrier_on(net); |
238 | netif_wake_queue(net); | |
02fafbc6 | 239 | } else { |
fceaf24a HJ |
240 | netif_carrier_off(net); |
241 | netif_stop_queue(net); | |
242 | } | |
fceaf24a HJ |
243 | } |
244 | ||
3e189519 HJ |
245 | /* |
246 | * netvsc_recv_callback - Callback when we receive a packet from the | |
247 | * "wire" on the specified device. | |
02fafbc6 GKH |
248 | */ |
249 | static int netvsc_recv_callback(struct hv_device *device_obj, | |
250 | struct hv_netvsc_packet *packet) | |
fceaf24a | 251 | { |
f916a34d | 252 | struct vm_device *device_ctx = to_vm_device(device_obj); |
621d7fb7 | 253 | struct net_device *net = dev_get_drvdata(&device_ctx->device); |
fceaf24a HJ |
254 | struct sk_buff *skb; |
255 | void *data; | |
02fafbc6 | 256 | int i; |
fceaf24a HJ |
257 | unsigned long flags; |
258 | ||
02fafbc6 GKH |
259 | if (!net) { |
260 | DPRINT_ERR(NETVSC_DRV, "got receive callback but net device " | |
261 | "not initialized yet"); | |
fceaf24a HJ |
262 | return 0; |
263 | } | |
264 | ||
9495c282 | 265 | /* Allocate a skb - TODO direct I/O to pages? */ |
72a2f5bd | 266 | skb = netdev_alloc_skb_ip_align(net, packet->total_data_buflen); |
9495c282 SH |
267 | if (unlikely(!skb)) { |
268 | ++net->stats.rx_dropped; | |
269 | return 0; | |
270 | } | |
fceaf24a | 271 | |
454f18a9 | 272 | /* for kmap_atomic */ |
fceaf24a HJ |
273 | local_irq_save(flags); |
274 | ||
02fafbc6 GKH |
275 | /* |
276 | * Copy to skb. This copy is needed here since the memory pointed by | |
277 | * hv_netvsc_packet cannot be deallocated | |
278 | */ | |
72a2f5bd HZ |
279 | for (i = 0; i < packet->page_buf_cnt; i++) { |
280 | data = kmap_atomic(pfn_to_page(packet->page_buf[i].Pfn), | |
02fafbc6 GKH |
281 | KM_IRQ1); |
282 | data = (void *)(unsigned long)data + | |
72a2f5bd | 283 | packet->page_buf[i].Offset; |
02fafbc6 | 284 | |
72a2f5bd HZ |
285 | memcpy(skb_put(skb, packet->page_buf[i].Length), data, |
286 | packet->page_buf[i].Length); | |
02fafbc6 GKH |
287 | |
288 | kunmap_atomic((void *)((unsigned long)data - | |
72a2f5bd | 289 | packet->page_buf[i].Offset), KM_IRQ1); |
fceaf24a HJ |
290 | } |
291 | ||
292 | local_irq_restore(flags); | |
293 | ||
294 | skb->protocol = eth_type_trans(skb, net); | |
fceaf24a HJ |
295 | skb->ip_summed = CHECKSUM_NONE; |
296 | ||
9495c282 SH |
297 | net->stats.rx_packets++; |
298 | net->stats.rx_bytes += skb->len; | |
299 | ||
02fafbc6 GKH |
300 | /* |
301 | * Pass the skb back up. Network stack will deallocate the skb when it | |
9495c282 SH |
302 | * is done. |
303 | * TODO - use NAPI? | |
02fafbc6 | 304 | */ |
9495c282 | 305 | netif_rx(skb); |
fceaf24a | 306 | |
02fafbc6 | 307 | DPRINT_DBG(NETVSC_DRV, "# of recvs %lu total size %lu", |
b852fdce | 308 | net->stats.rx_packets, net->stats.rx_bytes); |
fceaf24a | 309 | |
fceaf24a HJ |
310 | return 0; |
311 | } | |
312 | ||
f82f4ad7 SH |
313 | static void netvsc_get_drvinfo(struct net_device *net, |
314 | struct ethtool_drvinfo *info) | |
315 | { | |
316 | strcpy(info->driver, "hv_netvsc"); | |
317 | strcpy(info->version, HV_DRV_VERSION); | |
318 | strcpy(info->fw_version, "N/A"); | |
319 | } | |
320 | ||
321 | static const struct ethtool_ops ethtool_ops = { | |
322 | .get_drvinfo = netvsc_get_drvinfo, | |
323 | .get_sg = ethtool_op_get_sg, | |
324 | .set_sg = ethtool_op_set_sg, | |
325 | .get_link = ethtool_op_get_link, | |
326 | }; | |
327 | ||
df2fff28 GKH |
328 | static const struct net_device_ops device_ops = { |
329 | .ndo_open = netvsc_open, | |
330 | .ndo_stop = netvsc_close, | |
331 | .ndo_start_xmit = netvsc_start_xmit, | |
df2fff28 | 332 | .ndo_set_multicast_list = netvsc_set_multicast_list, |
b681b588 HZ |
333 | .ndo_change_mtu = eth_change_mtu, |
334 | .ndo_validate_addr = eth_validate_addr, | |
335 | .ndo_set_mac_address = eth_mac_addr, | |
df2fff28 GKH |
336 | }; |
337 | ||
338 | static int netvsc_probe(struct device *device) | |
339 | { | |
340 | struct driver_context *driver_ctx = | |
341 | driver_to_driver_context(device->driver); | |
342 | struct netvsc_driver_context *net_drv_ctx = | |
343 | (struct netvsc_driver_context *)driver_ctx; | |
344 | struct netvsc_driver *net_drv_obj = &net_drv_ctx->drv_obj; | |
f916a34d | 345 | struct vm_device *device_ctx = device_to_vm_device(device); |
df2fff28 GKH |
346 | struct hv_device *device_obj = &device_ctx->device_obj; |
347 | struct net_device *net = NULL; | |
348 | struct net_device_context *net_device_ctx; | |
349 | struct netvsc_device_info device_info; | |
350 | int ret; | |
351 | ||
72a2f5bd | 352 | if (!net_drv_obj->base.OnDeviceAdd) |
df2fff28 GKH |
353 | return -1; |
354 | ||
546d9e10 | 355 | net = alloc_etherdev(sizeof(struct net_device_context)); |
df2fff28 GKH |
356 | if (!net) |
357 | return -1; | |
358 | ||
359 | /* Set initial state */ | |
360 | netif_carrier_off(net); | |
df2fff28 GKH |
361 | |
362 | net_device_ctx = netdev_priv(net); | |
363 | net_device_ctx->device_ctx = device_ctx; | |
b220f5f9 | 364 | net_device_ctx->avail = ring_size; |
df2fff28 GKH |
365 | dev_set_drvdata(device, net); |
366 | ||
367 | /* Notify the netvsc driver of the new device */ | |
72a2f5bd | 368 | ret = net_drv_obj->base.OnDeviceAdd(device_obj, &device_info); |
df2fff28 GKH |
369 | if (ret != 0) { |
370 | free_netdev(net); | |
371 | dev_set_drvdata(device, NULL); | |
372 | ||
373 | DPRINT_ERR(NETVSC_DRV, "unable to add netvsc device (ret %d)", | |
374 | ret); | |
375 | return ret; | |
376 | } | |
377 | ||
378 | /* | |
379 | * If carrier is still off ie we did not get a link status callback, | |
380 | * update it if necessary | |
381 | */ | |
382 | /* | |
383 | * FIXME: We should use a atomic or test/set instead to avoid getting | |
384 | * out of sync with the device's link status | |
385 | */ | |
386 | if (!netif_carrier_ok(net)) | |
72a2f5bd | 387 | if (!device_info.link_state) |
df2fff28 GKH |
388 | netif_carrier_on(net); |
389 | ||
72a2f5bd | 390 | memcpy(net->dev_addr, device_info.mac_adr, ETH_ALEN); |
df2fff28 GKH |
391 | |
392 | net->netdev_ops = &device_ops; | |
393 | ||
6048718d SH |
394 | /* TODO: Add GSO and Checksum offload */ |
395 | net->features = NETIF_F_SG; | |
396 | ||
f82f4ad7 | 397 | SET_ETHTOOL_OPS(net, ðtool_ops); |
df2fff28 GKH |
398 | SET_NETDEV_DEV(net, device); |
399 | ||
400 | ret = register_netdev(net); | |
401 | if (ret != 0) { | |
402 | /* Remove the device and release the resource */ | |
72a2f5bd | 403 | net_drv_obj->base.OnDeviceRemove(device_obj); |
df2fff28 GKH |
404 | free_netdev(net); |
405 | } | |
406 | ||
df2fff28 GKH |
407 | return ret; |
408 | } | |
409 | ||
410 | static int netvsc_remove(struct device *device) | |
411 | { | |
412 | struct driver_context *driver_ctx = | |
413 | driver_to_driver_context(device->driver); | |
414 | struct netvsc_driver_context *net_drv_ctx = | |
415 | (struct netvsc_driver_context *)driver_ctx; | |
416 | struct netvsc_driver *net_drv_obj = &net_drv_ctx->drv_obj; | |
f916a34d | 417 | struct vm_device *device_ctx = device_to_vm_device(device); |
df2fff28 GKH |
418 | struct net_device *net = dev_get_drvdata(&device_ctx->device); |
419 | struct hv_device *device_obj = &device_ctx->device_obj; | |
420 | int ret; | |
421 | ||
df2fff28 GKH |
422 | if (net == NULL) { |
423 | DPRINT_INFO(NETVSC, "no net device to remove"); | |
df2fff28 GKH |
424 | return 0; |
425 | } | |
426 | ||
72a2f5bd | 427 | if (!net_drv_obj->base.OnDeviceRemove) |
df2fff28 | 428 | return -1; |
df2fff28 GKH |
429 | |
430 | /* Stop outbound asap */ | |
431 | netif_stop_queue(net); | |
432 | /* netif_carrier_off(net); */ | |
433 | ||
434 | unregister_netdev(net); | |
435 | ||
436 | /* | |
437 | * Call to the vsc driver to let it know that the device is being | |
438 | * removed | |
439 | */ | |
72a2f5bd | 440 | ret = net_drv_obj->base.OnDeviceRemove(device_obj); |
df2fff28 GKH |
441 | if (ret != 0) { |
442 | /* TODO: */ | |
443 | DPRINT_ERR(NETVSC, "unable to remove vsc device (ret %d)", ret); | |
444 | } | |
445 | ||
446 | free_netdev(net); | |
df2fff28 GKH |
447 | return ret; |
448 | } | |
449 | ||
fceaf24a HJ |
450 | static int netvsc_drv_exit_cb(struct device *dev, void *data) |
451 | { | |
452 | struct device **curr = (struct device **)data; | |
02fafbc6 | 453 | |
fceaf24a | 454 | *curr = dev; |
02fafbc6 GKH |
455 | /* stop iterating */ |
456 | return 1; | |
fceaf24a HJ |
457 | } |
458 | ||
bd1de709 | 459 | static void netvsc_drv_exit(void) |
fceaf24a | 460 | { |
02fafbc6 GKH |
461 | struct netvsc_driver *netvsc_drv_obj = &g_netvsc_drv.drv_obj; |
462 | struct driver_context *drv_ctx = &g_netvsc_drv.drv_ctx; | |
463 | struct device *current_dev; | |
2295ba2e | 464 | int ret; |
fceaf24a | 465 | |
02fafbc6 | 466 | while (1) { |
fceaf24a HJ |
467 | current_dev = NULL; |
468 | ||
454f18a9 | 469 | /* Get the device */ |
2295ba2e | 470 | ret = driver_for_each_device(&drv_ctx->driver, NULL, |
02fafbc6 | 471 | ¤t_dev, netvsc_drv_exit_cb); |
2295ba2e BP |
472 | if (ret) |
473 | DPRINT_WARN(NETVSC_DRV, | |
474 | "driver_for_each_device returned %d", ret); | |
475 | ||
fceaf24a HJ |
476 | if (current_dev == NULL) |
477 | break; | |
478 | ||
454f18a9 | 479 | /* Initiate removal from the top-down */ |
02fafbc6 GKH |
480 | DPRINT_INFO(NETVSC_DRV, "unregistering device (%p)...", |
481 | current_dev); | |
fceaf24a HJ |
482 | |
483 | device_unregister(current_dev); | |
484 | } | |
485 | ||
72a2f5bd HZ |
486 | if (netvsc_drv_obj->base.OnCleanup) |
487 | netvsc_drv_obj->base.OnCleanup(&netvsc_drv_obj->base); | |
fceaf24a HJ |
488 | |
489 | vmbus_child_driver_unregister(drv_ctx); | |
490 | ||
fceaf24a HJ |
491 | return; |
492 | } | |
493 | ||
21707bed | 494 | static int netvsc_drv_init(int (*drv_init)(struct hv_driver *drv)) |
df2fff28 GKH |
495 | { |
496 | struct netvsc_driver *net_drv_obj = &g_netvsc_drv.drv_obj; | |
497 | struct driver_context *drv_ctx = &g_netvsc_drv.drv_ctx; | |
498 | int ret; | |
499 | ||
72a2f5bd HZ |
500 | net_drv_obj->ring_buf_size = ring_size * PAGE_SIZE; |
501 | net_drv_obj->recv_cb = netvsc_recv_callback; | |
502 | net_drv_obj->link_status_change = netvsc_linkstatus_callback; | |
df2fff28 GKH |
503 | |
504 | /* Callback to client driver to complete the initialization */ | |
72a2f5bd | 505 | drv_init(&net_drv_obj->base); |
df2fff28 | 506 | |
72a2f5bd HZ |
507 | drv_ctx->driver.name = net_drv_obj->base.name; |
508 | memcpy(&drv_ctx->class_id, &net_drv_obj->base.deviceType, | |
df2fff28 GKH |
509 | sizeof(struct hv_guid)); |
510 | ||
511 | drv_ctx->probe = netvsc_probe; | |
512 | drv_ctx->remove = netvsc_remove; | |
513 | ||
514 | /* The driver belongs to vmbus */ | |
515 | ret = vmbus_child_driver_register(drv_ctx); | |
516 | ||
df2fff28 GKH |
517 | return ret; |
518 | } | |
519 | ||
06e719d8 S |
520 | static const struct dmi_system_id __initconst |
521 | hv_netvsc_dmi_table[] __maybe_unused = { | |
522 | { | |
523 | .ident = "Hyper-V", | |
524 | .matches = { | |
525 | DMI_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), | |
526 | DMI_MATCH(DMI_PRODUCT_NAME, "Virtual Machine"), | |
527 | DMI_MATCH(DMI_BOARD_NAME, "Virtual Machine"), | |
528 | }, | |
529 | }, | |
530 | { }, | |
531 | }; | |
532 | MODULE_DEVICE_TABLE(dmi, hv_netvsc_dmi_table); | |
533 | ||
fceaf24a HJ |
534 | static int __init netvsc_init(void) |
535 | { | |
fceaf24a HJ |
536 | DPRINT_INFO(NETVSC_DRV, "Netvsc initializing...."); |
537 | ||
06e719d8 S |
538 | if (!dmi_check_system(hv_netvsc_dmi_table)) |
539 | return -ENODEV; | |
540 | ||
5a71ae30 | 541 | return netvsc_drv_init(netvsc_initialize); |
fceaf24a HJ |
542 | } |
543 | ||
544 | static void __exit netvsc_exit(void) | |
545 | { | |
fceaf24a | 546 | netvsc_drv_exit(); |
fceaf24a HJ |
547 | } |
548 | ||
06e719d8 S |
549 | static const struct pci_device_id __initconst |
550 | hv_netvsc_pci_table[] __maybe_unused = { | |
551 | { PCI_DEVICE(0x1414, 0x5353) }, /* VGA compatible controller */ | |
552 | { 0 } | |
553 | }; | |
554 | MODULE_DEVICE_TABLE(pci, hv_netvsc_pci_table); | |
555 | ||
26c14cc1 HJ |
556 | MODULE_LICENSE("GPL"); |
557 | MODULE_VERSION(HV_DRV_VERSION); | |
7880fc54 | 558 | MODULE_DESCRIPTION("Microsoft Hyper-V network driver"); |
fceaf24a HJ |
559 | |
560 | module_init(netvsc_init); | |
561 | module_exit(netvsc_exit); |