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