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