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