21 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
25 #include <linux/module.h>
27 #include <linux/device.h>
30 #include <linux/netdevice.h>
35 #include <linux/slab.h>
50 #define RING_SIZE_MIN 64
90 struct hv_device *device_obj = net_device_ctx->
device_ctx;
96 netdev_err(net,
"unable to open device (ret %d).\n", ret);
100 netif_start_queue(net);
105 static int netvsc_close(
struct net_device *net)
108 struct hv_device *device_obj = net_device_ctx->
device_ctx;
111 netif_tx_disable(net);
117 netdev_err(net,
"unable to close device (ret %d).\n", ret);
122 static void netvsc_xmit_completion(
void *
context)
142 npg_data = (((
unsigned long)skb->
data + skb_headlen(skb) - 1)
144 num_pages = skb_shinfo(skb)->nr_frags + npg_data + 2;
148 (num_pages *
sizeof(
struct hv_page_buffer)) +
153 netdev_err(net,
"unable to allocate hv_netvsc_packet\n");
156 net->
stats.tx_dropped++;
162 packet->
extension = (
void *)(
unsigned long)packet +
164 (num_pages *
sizeof(
struct hv_page_buffer));
177 packet->
page_buf[1].len = skb_headlen(skb);
182 for (i = 2; i <= npg_data; i++) {
190 + skb_headlen(skb) - 1) & (
PAGE_SIZE - 1)) + 1;
193 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
196 packet->
page_buf[i+npg_data+1].pfn =
199 packet->
page_buf[i+npg_data+1].len = skb_frag_size(f);
211 net->
stats.tx_packets++;
216 net->
stats.tx_dropped++;
233 net_device = hv_get_drvdata(device_obj);
234 net = net_device->
ndev;
237 netdev_err(net,
"got link status but net device "
238 "not initialized yet\n");
244 netif_wake_queue(net);
245 ndev_ctx = netdev_priv(net);
250 netif_tx_disable(net);
266 netdev_err(net,
"got receive callback but net device"
267 " not initialized yet\n");
275 ++net->
stats.rx_dropped;
291 net->
stats.rx_packets++;
304 static void netvsc_get_drvinfo(
struct net_device *net,
326 if (mtu < 68 || mtu > limit)
332 netif_tx_disable(ndev);
338 hv_set_drvdata(hdev, ndev);
341 netif_wake_queue(ndev);
347 static int netvsc_set_mac_addr(
struct net_device *ndev,
void *
p)
353 unsigned char save_aatype;
380 .ndo_open = netvsc_open,
381 .ndo_stop = netvsc_close,
382 .ndo_start_xmit = netvsc_start_xmit,
383 .ndo_set_rx_mode = netvsc_set_multicast_list,
384 .ndo_change_mtu = netvsc_change_mtu,
386 .ndo_set_mac_address = netvsc_set_mac_addr,
396 static void netvsc_send_garp(
struct work_struct *w)
403 net_device = hv_get_drvdata(ndev_ctx->
device_ctx);
404 net = net_device->
ndev;
409 static int netvsc_probe(
struct hv_device *
dev,
424 net_device_ctx = netdev_priv(net);
426 hv_set_drvdata(dev, net);
441 pr_err(
"Unable to register netdev.\n");
450 netdev_err(net,
"unable to add netvsc device (ret %d)\n", ret);
453 hv_set_drvdata(dev,
NULL);
464 static int netvsc_remove(
struct hv_device *dev)
470 net_device = hv_get_drvdata(dev);
471 net = net_device->
ndev;
474 dev_err(&dev->device,
"No net device to remove\n");
480 ndev_ctx = netdev_priv(net);
485 netif_tx_disable(net);
501 { VMBUS_DEVICE(0x63, 0x51, 0x61, 0xF8, 0x3E, 0xDF, 0xc5, 0x46,
502 0x91, 0x3F, 0xF2, 0xD2, 0xF9, 0x65, 0xED, 0x0E) },
509 static struct hv_driver netvsc_drv = {
510 .name = KBUILD_MODNAME,
511 .id_table = id_table,
512 .probe = netvsc_probe,
513 .remove = netvsc_remove,
516 static void __exit netvsc_drv_exit(
void)
521 static int __init netvsc_drv_init(
void)
525 pr_info(
"Increased ring_size to %d (min allowed)\n",
528 return vmbus_driver_register(&netvsc_drv);