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