2009-07-13 22:34:54 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2009, Microsoft Corporation.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
|
|
|
* Place - Suite 330, Boston, MA 02111-1307 USA.
|
|
|
|
*
|
|
|
|
* Authors:
|
2009-11-23 17:00:22 +00:00
|
|
|
* Haiyang Zhang <haiyangz@microsoft.com>
|
2009-07-13 22:34:54 +00:00
|
|
|
* Hank Janssen <hjanssen@microsoft.com>
|
|
|
|
*/
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/highmem.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/inetdevice.h>
|
|
|
|
#include <linux/etherdevice.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/in.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2010-05-07 23:52:17 +00:00
|
|
|
#include <linux/dmi.h>
|
|
|
|
#include <linux/pci.h>
|
2009-07-13 22:34:54 +00:00
|
|
|
#include <net/arp.h>
|
|
|
|
#include <net/route.h>
|
|
|
|
#include <net/sock.h>
|
|
|
|
#include <net/pkt_sched.h>
|
2009-08-19 23:14:47 +00:00
|
|
|
#include "osd.h"
|
2009-08-28 23:22:59 +00:00
|
|
|
#include "logging.h"
|
2010-05-06 05:52:28 +00:00
|
|
|
#include "version_info.h"
|
2009-08-19 23:21:28 +00:00
|
|
|
#include "vmbus.h"
|
2010-05-06 05:39:15 +00:00
|
|
|
#include "netvsc_api.h"
|
2009-07-13 22:34:54 +00:00
|
|
|
|
|
|
|
struct net_device_context {
|
2009-09-01 04:09:45 +00:00
|
|
|
/* point back to our device context */
|
2010-02-17 20:58:47 +00:00
|
|
|
struct vm_device *device_ctx;
|
2010-05-04 16:58:56 +00:00
|
|
|
unsigned long avail;
|
2009-07-13 22:34:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct netvsc_driver_context {
|
2009-07-27 20:47:24 +00:00
|
|
|
/* !! These must be the first 2 fields !! */
|
2009-08-27 22:58:15 +00:00
|
|
|
/* Which is a bug FIXME! */
|
2009-09-01 04:09:45 +00:00
|
|
|
struct driver_context drv_ctx;
|
2009-08-27 22:58:15 +00:00
|
|
|
struct netvsc_driver drv_obj;
|
2009-07-13 22:34:54 +00:00
|
|
|
};
|
|
|
|
|
2010-05-04 16:58:56 +00:00
|
|
|
#define PACKET_PAGES_LOWATER 8
|
|
|
|
/* Need this many pages to handle worst case fragmented packet */
|
|
|
|
#define PACKET_PAGES_HIWATER (MAX_SKB_FRAGS + 2)
|
|
|
|
|
2010-10-12 17:45:23 +00:00
|
|
|
static int ring_size = 128;
|
2010-05-04 16:58:53 +00:00
|
|
|
module_param(ring_size, int, S_IRUGO);
|
|
|
|
MODULE_PARM_DESC(ring_size, "Ring buffer size (# of pages)");
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* The one and only one */
|
2009-07-13 22:34:54 +00:00
|
|
|
static struct netvsc_driver_context g_netvsc_drv;
|
|
|
|
|
2010-11-15 19:55:33 +00:00
|
|
|
/* no-op so the netdev core doesn't return -EINVAL when modifying the the
|
|
|
|
* multicast address list in SIOCADDMULTI. hv is setup to get all multicast
|
|
|
|
* when it calls RndisFilterOnOpen() */
|
2009-07-15 19:45:20 +00:00
|
|
|
static void netvsc_set_multicast_list(struct net_device *net)
|
2009-07-13 22:34:54 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static int netvsc_open(struct net_device *net)
|
|
|
|
{
|
|
|
|
struct net_device_context *net_device_ctx = netdev_priv(net);
|
2009-07-28 15:32:53 +00:00
|
|
|
struct hv_device *device_obj = &net_device_ctx->device_ctx->device_obj;
|
2009-09-01 04:09:45 +00:00
|
|
|
int ret = 0;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2009-09-01 04:09:45 +00:00
|
|
|
if (netif_carrier_ok(net)) {
|
2009-07-27 20:47:24 +00:00
|
|
|
/* Open up the device */
|
2010-12-10 20:03:57 +00:00
|
|
|
ret = rndis_filter_open(device_obj);
|
2009-09-01 04:09:45 +00:00
|
|
|
if (ret != 0) {
|
|
|
|
DPRINT_ERR(NETVSC_DRV,
|
|
|
|
"unable to open device (ret %d).", ret);
|
2009-07-13 22:34:54 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
netif_start_queue(net);
|
2009-09-01 04:09:45 +00:00
|
|
|
} else {
|
2009-07-13 22:34:54 +00:00
|
|
|
DPRINT_ERR(NETVSC_DRV, "unable to open device...link is down.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int netvsc_close(struct net_device *net)
|
|
|
|
{
|
|
|
|
struct net_device_context *net_device_ctx = netdev_priv(net);
|
2009-07-28 15:32:53 +00:00
|
|
|
struct hv_device *device_obj = &net_device_ctx->device_ctx->device_obj;
|
2009-09-01 04:09:45 +00:00
|
|
|
int ret;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
|
|
|
netif_stop_queue(net);
|
|
|
|
|
2010-12-10 20:03:57 +00:00
|
|
|
ret = rndis_filter_close(device_obj);
|
2009-07-13 22:34:54 +00:00
|
|
|
if (ret != 0)
|
|
|
|
DPRINT_ERR(NETVSC_DRV, "unable to close device (ret %d).", ret);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void netvsc_xmit_completion(void *context)
|
|
|
|
{
|
2009-07-29 12:10:10 +00:00
|
|
|
struct hv_netvsc_packet *packet = (struct hv_netvsc_packet *)context;
|
2009-09-01 04:09:45 +00:00
|
|
|
struct sk_buff *skb = (struct sk_buff *)
|
2010-12-10 20:03:58 +00:00
|
|
|
(unsigned long)packet->completion.send.send_completion_tid;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
|
|
|
kfree(packet);
|
|
|
|
|
2009-09-01 04:09:45 +00:00
|
|
|
if (skb) {
|
2010-05-04 16:58:52 +00:00
|
|
|
struct net_device *net = skb->dev;
|
2010-05-04 16:58:56 +00:00
|
|
|
struct net_device_context *net_device_ctx = netdev_priv(net);
|
|
|
|
unsigned int num_pages = skb_shinfo(skb)->nr_frags + 2;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2010-05-04 16:58:56 +00:00
|
|
|
dev_kfree_skb_any(skb);
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2011-02-08 14:55:49 +00:00
|
|
|
net_device_ctx->avail += num_pages;
|
|
|
|
if (net_device_ctx->avail >= PACKET_PAGES_HIWATER)
|
2010-05-04 16:58:56 +00:00
|
|
|
netif_wake_queue(net);
|
2009-07-13 22:34:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-01 04:09:45 +00:00
|
|
|
static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net)
|
2009-07-13 22:34:54 +00:00
|
|
|
{
|
|
|
|
struct net_device_context *net_device_ctx = netdev_priv(net);
|
2009-09-01 04:09:45 +00:00
|
|
|
struct driver_context *driver_ctx =
|
|
|
|
driver_to_driver_context(net_device_ctx->device_ctx->device.driver);
|
|
|
|
struct netvsc_driver_context *net_drv_ctx =
|
|
|
|
(struct netvsc_driver_context *)driver_ctx;
|
2009-08-27 22:58:15 +00:00
|
|
|
struct netvsc_driver *net_drv_obj = &net_drv_ctx->drv_obj;
|
2009-07-29 12:10:10 +00:00
|
|
|
struct hv_netvsc_packet *packet;
|
2009-09-01 04:09:45 +00:00
|
|
|
int ret;
|
2010-05-04 16:58:55 +00:00
|
|
|
unsigned int i, num_pages;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2009-09-01 04:09:45 +00:00
|
|
|
DPRINT_DBG(NETVSC_DRV, "xmit packet - len %d data_len %d",
|
|
|
|
skb->len, skb->data_len);
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2010-05-04 16:58:55 +00:00
|
|
|
/* Add 1 for skb->data and additional one for RNDIS */
|
|
|
|
num_pages = skb_shinfo(skb)->nr_frags + 1 + 1;
|
2010-05-04 16:58:56 +00:00
|
|
|
if (num_pages > net_device_ctx->avail)
|
|
|
|
return NETDEV_TX_BUSY;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* Allocate a netvsc packet based on # of frags. */
|
2009-09-01 04:09:45 +00:00
|
|
|
packet = kzalloc(sizeof(struct hv_netvsc_packet) +
|
2010-05-04 16:58:55 +00:00
|
|
|
(num_pages * sizeof(struct hv_page_buffer)) +
|
2010-12-10 20:03:58 +00:00
|
|
|
net_drv_obj->req_ext_size, GFP_ATOMIC);
|
2009-09-01 04:09:45 +00:00
|
|
|
if (!packet) {
|
2010-05-04 16:58:56 +00:00
|
|
|
/* out of memory, silently drop packet */
|
2009-07-29 12:10:10 +00:00
|
|
|
DPRINT_ERR(NETVSC_DRV, "unable to allocate hv_netvsc_packet");
|
2010-05-04 16:58:56 +00:00
|
|
|
|
|
|
|
dev_kfree_skb(skb);
|
|
|
|
net->stats.tx_dropped++;
|
|
|
|
return NETDEV_TX_OK;
|
2009-07-13 22:34:54 +00:00
|
|
|
}
|
|
|
|
|
2010-12-10 20:03:58 +00:00
|
|
|
packet->extension = (void *)(unsigned long)packet +
|
2009-09-01 04:09:45 +00:00
|
|
|
sizeof(struct hv_netvsc_packet) +
|
2010-05-04 16:58:55 +00:00
|
|
|
(num_pages * sizeof(struct hv_page_buffer));
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* Setup the rndis header */
|
2010-12-10 20:03:58 +00:00
|
|
|
packet->page_buf_cnt = num_pages;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* TODO: Flush all write buffers/ memory fence ??? */
|
|
|
|
/* wmb(); */
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* Initialize it from the skb */
|
2010-12-10 20:03:58 +00:00
|
|
|
packet->total_data_buflen = skb->len;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2010-05-04 16:58:55 +00:00
|
|
|
/* Start filling in the page buffers starting after RNDIS buffer. */
|
2011-01-26 20:12:11 +00:00
|
|
|
packet->page_buf[1].pfn = virt_to_phys(skb->data) >> PAGE_SHIFT;
|
|
|
|
packet->page_buf[1].offset
|
2010-05-04 16:58:55 +00:00
|
|
|
= (unsigned long)skb->data & (PAGE_SIZE - 1);
|
2011-01-26 20:12:11 +00:00
|
|
|
packet->page_buf[1].len = skb_headlen(skb);
|
2010-05-04 16:58:55 +00:00
|
|
|
|
|
|
|
/* Additional fragments are after SKB data */
|
|
|
|
for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
|
|
|
|
skb_frag_t *f = &skb_shinfo(skb)->frags[i];
|
|
|
|
|
2011-01-26 20:12:11 +00:00
|
|
|
packet->page_buf[i+2].pfn = page_to_pfn(f->page);
|
|
|
|
packet->page_buf[i+2].offset = f->page_offset;
|
|
|
|
packet->page_buf[i+2].len = f->size;
|
2009-07-13 22:34:54 +00:00
|
|
|
}
|
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* Set the completion routine */
|
2010-12-10 20:03:58 +00:00
|
|
|
packet->completion.send.send_completion = netvsc_xmit_completion;
|
|
|
|
packet->completion.send.send_completion_ctx = packet;
|
|
|
|
packet->completion.send.send_completion_tid = (unsigned long)skb;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2010-12-10 20:03:58 +00:00
|
|
|
ret = net_drv_obj->send(&net_device_ctx->device_ctx->device_obj,
|
2009-09-01 04:09:45 +00:00
|
|
|
packet);
|
|
|
|
if (ret == 0) {
|
2010-03-10 01:42:33 +00:00
|
|
|
net->stats.tx_bytes += skb->len;
|
|
|
|
net->stats.tx_packets++;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2010-05-04 16:58:56 +00:00
|
|
|
DPRINT_DBG(NETVSC_DRV, "# of xmits %lu total size %lu",
|
|
|
|
net->stats.tx_packets,
|
|
|
|
net->stats.tx_bytes);
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2011-02-08 14:55:49 +00:00
|
|
|
net_device_ctx->avail -= num_pages;
|
|
|
|
if (net_device_ctx->avail < PACKET_PAGES_LOWATER)
|
2010-05-04 16:58:56 +00:00
|
|
|
netif_stop_queue(net);
|
|
|
|
} else {
|
|
|
|
/* we are shutting down or bus overloaded, just drop packet */
|
2010-03-10 01:42:33 +00:00
|
|
|
net->stats.tx_dropped++;
|
2010-05-04 16:58:56 +00:00
|
|
|
netvsc_xmit_completion(packet);
|
2009-07-13 22:34:54 +00:00
|
|
|
}
|
|
|
|
|
2010-05-04 16:58:56 +00:00
|
|
|
return NETDEV_TX_OK;
|
2009-07-13 22:34:54 +00:00
|
|
|
}
|
|
|
|
|
2010-03-04 22:11:00 +00:00
|
|
|
/*
|
2009-09-01 04:09:45 +00:00
|
|
|
* netvsc_linkstatus_callback - Link up/down notification
|
|
|
|
*/
|
|
|
|
static void netvsc_linkstatus_callback(struct hv_device *device_obj,
|
|
|
|
unsigned int status)
|
2009-07-13 22:34:54 +00:00
|
|
|
{
|
2010-02-17 20:58:47 +00:00
|
|
|
struct vm_device *device_ctx = to_vm_device(device_obj);
|
2009-09-01 04:09:45 +00:00
|
|
|
struct net_device *net = dev_get_drvdata(&device_ctx->device);
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2009-09-01 04:09:45 +00:00
|
|
|
if (!net) {
|
|
|
|
DPRINT_ERR(NETVSC_DRV, "got link status but net device "
|
|
|
|
"not initialized yet");
|
2009-07-13 22:34:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-09-01 04:09:45 +00:00
|
|
|
if (status == 1) {
|
2009-07-13 22:34:54 +00:00
|
|
|
netif_carrier_on(net);
|
|
|
|
netif_wake_queue(net);
|
2011-02-02 21:42:58 +00:00
|
|
|
netif_notify_peers(net);
|
2009-09-01 04:09:45 +00:00
|
|
|
} else {
|
2009-07-13 22:34:54 +00:00
|
|
|
netif_carrier_off(net);
|
|
|
|
netif_stop_queue(net);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-04 22:11:00 +00:00
|
|
|
/*
|
|
|
|
* netvsc_recv_callback - Callback when we receive a packet from the
|
|
|
|
* "wire" on the specified device.
|
2009-09-01 04:09:45 +00:00
|
|
|
*/
|
|
|
|
static int netvsc_recv_callback(struct hv_device *device_obj,
|
|
|
|
struct hv_netvsc_packet *packet)
|
2009-07-13 22:34:54 +00:00
|
|
|
{
|
2010-02-17 20:58:47 +00:00
|
|
|
struct vm_device *device_ctx = to_vm_device(device_obj);
|
2009-07-24 18:00:39 +00:00
|
|
|
struct net_device *net = dev_get_drvdata(&device_ctx->device);
|
2009-07-13 22:34:54 +00:00
|
|
|
struct sk_buff *skb;
|
|
|
|
void *data;
|
2009-09-01 04:09:45 +00:00
|
|
|
int i;
|
2009-07-13 22:34:54 +00:00
|
|
|
unsigned long flags;
|
|
|
|
|
2009-09-01 04:09:45 +00:00
|
|
|
if (!net) {
|
|
|
|
DPRINT_ERR(NETVSC_DRV, "got receive callback but net device "
|
|
|
|
"not initialized yet");
|
2009-07-13 22:34:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-03-10 01:42:17 +00:00
|
|
|
/* Allocate a skb - TODO direct I/O to pages? */
|
2010-12-10 20:03:58 +00:00
|
|
|
skb = netdev_alloc_skb_ip_align(net, packet->total_data_buflen);
|
2010-03-10 01:42:17 +00:00
|
|
|
if (unlikely(!skb)) {
|
|
|
|
++net->stats.rx_dropped;
|
|
|
|
return 0;
|
|
|
|
}
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* for kmap_atomic */
|
2009-07-13 22:34:54 +00:00
|
|
|
local_irq_save(flags);
|
|
|
|
|
2009-09-01 04:09:45 +00:00
|
|
|
/*
|
|
|
|
* Copy to skb. This copy is needed here since the memory pointed by
|
|
|
|
* hv_netvsc_packet cannot be deallocated
|
|
|
|
*/
|
2010-12-10 20:03:58 +00:00
|
|
|
for (i = 0; i < packet->page_buf_cnt; i++) {
|
2011-01-26 20:12:11 +00:00
|
|
|
data = kmap_atomic(pfn_to_page(packet->page_buf[i].pfn),
|
2009-09-01 04:09:45 +00:00
|
|
|
KM_IRQ1);
|
|
|
|
data = (void *)(unsigned long)data +
|
2011-01-26 20:12:11 +00:00
|
|
|
packet->page_buf[i].offset;
|
2009-09-01 04:09:45 +00:00
|
|
|
|
2011-01-26 20:12:11 +00:00
|
|
|
memcpy(skb_put(skb, packet->page_buf[i].len), data,
|
|
|
|
packet->page_buf[i].len);
|
2009-09-01 04:09:45 +00:00
|
|
|
|
|
|
|
kunmap_atomic((void *)((unsigned long)data -
|
2011-01-26 20:12:11 +00:00
|
|
|
packet->page_buf[i].offset), KM_IRQ1);
|
2009-07-13 22:34:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
local_irq_restore(flags);
|
|
|
|
|
|
|
|
skb->protocol = eth_type_trans(skb, net);
|
|
|
|
skb->ip_summed = CHECKSUM_NONE;
|
|
|
|
|
2010-03-10 01:42:17 +00:00
|
|
|
net->stats.rx_packets++;
|
|
|
|
net->stats.rx_bytes += skb->len;
|
|
|
|
|
2009-09-01 04:09:45 +00:00
|
|
|
/*
|
|
|
|
* Pass the skb back up. Network stack will deallocate the skb when it
|
2010-03-10 01:42:17 +00:00
|
|
|
* is done.
|
|
|
|
* TODO - use NAPI?
|
2009-09-01 04:09:45 +00:00
|
|
|
*/
|
2010-03-10 01:42:17 +00:00
|
|
|
netif_rx(skb);
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2009-09-01 04:09:45 +00:00
|
|
|
DPRINT_DBG(NETVSC_DRV, "# of recvs %lu total size %lu",
|
2010-03-10 01:42:33 +00:00
|
|
|
net->stats.rx_packets, net->stats.rx_bytes);
|
2009-07-13 22:34:54 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-05-04 16:58:57 +00:00
|
|
|
static void netvsc_get_drvinfo(struct net_device *net,
|
|
|
|
struct ethtool_drvinfo *info)
|
|
|
|
{
|
|
|
|
strcpy(info->driver, "hv_netvsc");
|
|
|
|
strcpy(info->version, HV_DRV_VERSION);
|
|
|
|
strcpy(info->fw_version, "N/A");
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct ethtool_ops ethtool_ops = {
|
|
|
|
.get_drvinfo = netvsc_get_drvinfo,
|
|
|
|
.get_sg = ethtool_op_get_sg,
|
|
|
|
.set_sg = ethtool_op_set_sg,
|
|
|
|
.get_link = ethtool_op_get_link,
|
|
|
|
};
|
|
|
|
|
2009-09-01 04:11:12 +00:00
|
|
|
static const struct net_device_ops device_ops = {
|
|
|
|
.ndo_open = netvsc_open,
|
|
|
|
.ndo_stop = netvsc_close,
|
|
|
|
.ndo_start_xmit = netvsc_start_xmit,
|
|
|
|
.ndo_set_multicast_list = netvsc_set_multicast_list,
|
2010-08-03 19:15:31 +00:00
|
|
|
.ndo_change_mtu = eth_change_mtu,
|
|
|
|
.ndo_validate_addr = eth_validate_addr,
|
|
|
|
.ndo_set_mac_address = eth_mac_addr,
|
2009-09-01 04:11:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int netvsc_probe(struct device *device)
|
|
|
|
{
|
|
|
|
struct driver_context *driver_ctx =
|
|
|
|
driver_to_driver_context(device->driver);
|
|
|
|
struct netvsc_driver_context *net_drv_ctx =
|
|
|
|
(struct netvsc_driver_context *)driver_ctx;
|
|
|
|
struct netvsc_driver *net_drv_obj = &net_drv_ctx->drv_obj;
|
2010-02-17 20:58:47 +00:00
|
|
|
struct vm_device *device_ctx = device_to_vm_device(device);
|
2009-09-01 04:11:12 +00:00
|
|
|
struct hv_device *device_obj = &device_ctx->device_obj;
|
|
|
|
struct net_device *net = NULL;
|
|
|
|
struct net_device_context *net_device_ctx;
|
|
|
|
struct netvsc_device_info device_info;
|
|
|
|
int ret;
|
|
|
|
|
2011-01-26 20:12:11 +00:00
|
|
|
if (!net_drv_obj->base.dev_add)
|
2009-09-01 04:11:12 +00:00
|
|
|
return -1;
|
|
|
|
|
2010-03-11 17:11:37 +00:00
|
|
|
net = alloc_etherdev(sizeof(struct net_device_context));
|
2009-09-01 04:11:12 +00:00
|
|
|
if (!net)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Set initial state */
|
|
|
|
netif_carrier_off(net);
|
|
|
|
|
|
|
|
net_device_ctx = netdev_priv(net);
|
|
|
|
net_device_ctx->device_ctx = device_ctx;
|
2010-05-04 16:58:56 +00:00
|
|
|
net_device_ctx->avail = ring_size;
|
2009-09-01 04:11:12 +00:00
|
|
|
dev_set_drvdata(device, net);
|
|
|
|
|
|
|
|
/* Notify the netvsc driver of the new device */
|
2011-01-26 20:12:11 +00:00
|
|
|
ret = net_drv_obj->base.dev_add(device_obj, &device_info);
|
2009-09-01 04:11:12 +00:00
|
|
|
if (ret != 0) {
|
|
|
|
free_netdev(net);
|
|
|
|
dev_set_drvdata(device, NULL);
|
|
|
|
|
|
|
|
DPRINT_ERR(NETVSC_DRV, "unable to add netvsc device (ret %d)",
|
|
|
|
ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If carrier is still off ie we did not get a link status callback,
|
|
|
|
* update it if necessary
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* FIXME: We should use a atomic or test/set instead to avoid getting
|
|
|
|
* out of sync with the device's link status
|
|
|
|
*/
|
|
|
|
if (!netif_carrier_ok(net))
|
2010-12-10 20:03:58 +00:00
|
|
|
if (!device_info.link_state)
|
2009-09-01 04:11:12 +00:00
|
|
|
netif_carrier_on(net);
|
|
|
|
|
2010-12-10 20:03:58 +00:00
|
|
|
memcpy(net->dev_addr, device_info.mac_adr, ETH_ALEN);
|
2009-09-01 04:11:12 +00:00
|
|
|
|
|
|
|
net->netdev_ops = &device_ops;
|
|
|
|
|
2010-05-04 16:58:55 +00:00
|
|
|
/* TODO: Add GSO and Checksum offload */
|
|
|
|
net->features = NETIF_F_SG;
|
|
|
|
|
2010-05-04 16:58:57 +00:00
|
|
|
SET_ETHTOOL_OPS(net, ðtool_ops);
|
2009-09-01 04:11:12 +00:00
|
|
|
SET_NETDEV_DEV(net, device);
|
|
|
|
|
|
|
|
ret = register_netdev(net);
|
|
|
|
if (ret != 0) {
|
|
|
|
/* Remove the device and release the resource */
|
2011-01-26 20:12:11 +00:00
|
|
|
net_drv_obj->base.dev_rm(device_obj);
|
2009-09-01 04:11:12 +00:00
|
|
|
free_netdev(net);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int netvsc_remove(struct device *device)
|
|
|
|
{
|
|
|
|
struct driver_context *driver_ctx =
|
|
|
|
driver_to_driver_context(device->driver);
|
|
|
|
struct netvsc_driver_context *net_drv_ctx =
|
|
|
|
(struct netvsc_driver_context *)driver_ctx;
|
|
|
|
struct netvsc_driver *net_drv_obj = &net_drv_ctx->drv_obj;
|
2010-02-17 20:58:47 +00:00
|
|
|
struct vm_device *device_ctx = device_to_vm_device(device);
|
2009-09-01 04:11:12 +00:00
|
|
|
struct net_device *net = dev_get_drvdata(&device_ctx->device);
|
|
|
|
struct hv_device *device_obj = &device_ctx->device_obj;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (net == NULL) {
|
|
|
|
DPRINT_INFO(NETVSC, "no net device to remove");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-26 20:12:11 +00:00
|
|
|
if (!net_drv_obj->base.dev_rm)
|
2009-09-01 04:11:12 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Stop outbound asap */
|
|
|
|
netif_stop_queue(net);
|
|
|
|
/* netif_carrier_off(net); */
|
|
|
|
|
|
|
|
unregister_netdev(net);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call to the vsc driver to let it know that the device is being
|
|
|
|
* removed
|
|
|
|
*/
|
2011-01-26 20:12:11 +00:00
|
|
|
ret = net_drv_obj->base.dev_rm(device_obj);
|
2009-09-01 04:11:12 +00:00
|
|
|
if (ret != 0) {
|
|
|
|
/* TODO: */
|
|
|
|
DPRINT_ERR(NETVSC, "unable to remove vsc device (ret %d)", ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
free_netdev(net);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-07-13 22:34:54 +00:00
|
|
|
static int netvsc_drv_exit_cb(struct device *dev, void *data)
|
|
|
|
{
|
|
|
|
struct device **curr = (struct device **)data;
|
2009-09-01 04:09:45 +00:00
|
|
|
|
2009-07-13 22:34:54 +00:00
|
|
|
*curr = dev;
|
2009-09-01 04:09:45 +00:00
|
|
|
/* stop iterating */
|
|
|
|
return 1;
|
2009-07-13 22:34:54 +00:00
|
|
|
}
|
|
|
|
|
2009-07-29 16:04:51 +00:00
|
|
|
static void netvsc_drv_exit(void)
|
2009-07-13 22:34:54 +00:00
|
|
|
{
|
2009-09-01 04:09:45 +00:00
|
|
|
struct netvsc_driver *netvsc_drv_obj = &g_netvsc_drv.drv_obj;
|
|
|
|
struct driver_context *drv_ctx = &g_netvsc_drv.drv_ctx;
|
|
|
|
struct device *current_dev;
|
2009-07-28 17:46:22 +00:00
|
|
|
int ret;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2009-09-01 04:09:45 +00:00
|
|
|
while (1) {
|
2009-07-13 22:34:54 +00:00
|
|
|
current_dev = NULL;
|
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* Get the device */
|
2009-07-28 17:46:22 +00:00
|
|
|
ret = driver_for_each_device(&drv_ctx->driver, NULL,
|
2009-09-01 04:09:45 +00:00
|
|
|
¤t_dev, netvsc_drv_exit_cb);
|
2009-07-28 17:46:22 +00:00
|
|
|
if (ret)
|
|
|
|
DPRINT_WARN(NETVSC_DRV,
|
|
|
|
"driver_for_each_device returned %d", ret);
|
|
|
|
|
2009-07-13 22:34:54 +00:00
|
|
|
if (current_dev == NULL)
|
|
|
|
break;
|
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* Initiate removal from the top-down */
|
2009-09-01 04:09:45 +00:00
|
|
|
DPRINT_INFO(NETVSC_DRV, "unregistering device (%p)...",
|
|
|
|
current_dev);
|
2009-07-13 22:34:54 +00:00
|
|
|
|
|
|
|
device_unregister(current_dev);
|
|
|
|
}
|
|
|
|
|
2011-01-26 20:12:11 +00:00
|
|
|
if (netvsc_drv_obj->base.cleanup)
|
|
|
|
netvsc_drv_obj->base.cleanup(&netvsc_drv_obj->base);
|
2009-07-13 22:34:54 +00:00
|
|
|
|
|
|
|
vmbus_child_driver_unregister(drv_ctx);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-09-02 18:53:59 +00:00
|
|
|
static int netvsc_drv_init(int (*drv_init)(struct hv_driver *drv))
|
2009-09-01 04:11:12 +00:00
|
|
|
{
|
|
|
|
struct netvsc_driver *net_drv_obj = &g_netvsc_drv.drv_obj;
|
|
|
|
struct driver_context *drv_ctx = &g_netvsc_drv.drv_ctx;
|
|
|
|
int ret;
|
|
|
|
|
2010-12-10 20:03:58 +00:00
|
|
|
net_drv_obj->ring_buf_size = ring_size * PAGE_SIZE;
|
|
|
|
net_drv_obj->recv_cb = netvsc_recv_callback;
|
|
|
|
net_drv_obj->link_status_change = netvsc_linkstatus_callback;
|
2009-09-01 04:11:12 +00:00
|
|
|
|
|
|
|
/* Callback to client driver to complete the initialization */
|
2010-12-10 20:03:58 +00:00
|
|
|
drv_init(&net_drv_obj->base);
|
2009-09-01 04:11:12 +00:00
|
|
|
|
2010-12-10 20:03:58 +00:00
|
|
|
drv_ctx->driver.name = net_drv_obj->base.name;
|
2011-01-26 20:12:11 +00:00
|
|
|
memcpy(&drv_ctx->class_id, &net_drv_obj->base.dev_type,
|
2009-09-01 04:11:12 +00:00
|
|
|
sizeof(struct hv_guid));
|
|
|
|
|
|
|
|
drv_ctx->probe = netvsc_probe;
|
|
|
|
drv_ctx->remove = netvsc_remove;
|
|
|
|
|
|
|
|
/* The driver belongs to vmbus */
|
|
|
|
ret = vmbus_child_driver_register(drv_ctx);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-05-07 23:52:17 +00:00
|
|
|
static const struct dmi_system_id __initconst
|
|
|
|
hv_netvsc_dmi_table[] __maybe_unused = {
|
|
|
|
{
|
|
|
|
.ident = "Hyper-V",
|
|
|
|
.matches = {
|
|
|
|
DMI_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"),
|
|
|
|
DMI_MATCH(DMI_PRODUCT_NAME, "Virtual Machine"),
|
|
|
|
DMI_MATCH(DMI_BOARD_NAME, "Virtual Machine"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{ },
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(dmi, hv_netvsc_dmi_table);
|
|
|
|
|
2009-07-13 22:34:54 +00:00
|
|
|
static int __init netvsc_init(void)
|
|
|
|
{
|
|
|
|
DPRINT_INFO(NETVSC_DRV, "Netvsc initializing....");
|
|
|
|
|
2010-05-07 23:52:17 +00:00
|
|
|
if (!dmi_check_system(hv_netvsc_dmi_table))
|
|
|
|
return -ENODEV;
|
|
|
|
|
2010-12-10 20:03:55 +00:00
|
|
|
return netvsc_drv_init(netvsc_initialize);
|
2009-07-13 22:34:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit netvsc_exit(void)
|
|
|
|
{
|
|
|
|
netvsc_drv_exit();
|
|
|
|
}
|
|
|
|
|
2010-05-07 23:52:17 +00:00
|
|
|
static const struct pci_device_id __initconst
|
|
|
|
hv_netvsc_pci_table[] __maybe_unused = {
|
|
|
|
{ PCI_DEVICE(0x1414, 0x5353) }, /* VGA compatible controller */
|
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(pci, hv_netvsc_pci_table);
|
|
|
|
|
2010-02-11 23:02:42 +00:00
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_VERSION(HV_DRV_VERSION);
|
2010-05-04 16:58:52 +00:00
|
|
|
MODULE_DESCRIPTION("Microsoft Hyper-V network driver");
|
2009-07-13 22:34:54 +00:00
|
|
|
|
|
|
|
module_init(netvsc_init);
|
|
|
|
module_exit(netvsc_exit);
|