2009-07-14 00:34:54 +02: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:
|
|
|
|
* Haiyang Zhang <haiyangz@microsoft.com>
|
|
|
|
* Hank Janssen <hjanssen@microsoft.com>
|
|
|
|
*/
|
2009-07-15 00:08:20 +02:00
|
|
|
#include <linux/kernel.h>
|
2011-02-11 18:59:43 +01:00
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/wait.h>
|
2009-07-29 23:00:15 +02:00
|
|
|
#include <linux/highmem.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 09:04:11 +01:00
|
|
|
#include <linux/slab.h>
|
2009-09-02 18:17:52 +02:00
|
|
|
#include <linux/io.h>
|
2010-05-04 18:58:54 +02:00
|
|
|
#include <linux/if_ether.h>
|
2011-03-29 22:58:48 +02:00
|
|
|
#include <linux/netdevice.h>
|
2012-03-12 11:20:50 +01:00
|
|
|
#include <linux/if_vlan.h>
|
2012-07-10 09:19:22 +02:00
|
|
|
#include <linux/nls.h>
|
2011-05-13 04:34:15 +02:00
|
|
|
|
2011-05-13 04:34:37 +02:00
|
|
|
#include "hyperv_net.h"
|
2009-07-14 00:34:54 +02:00
|
|
|
|
|
|
|
|
2012-10-02 07:30:24 +02:00
|
|
|
#define RNDIS_EXT_LEN 100
|
2009-08-29 01:26:27 +02:00
|
|
|
struct rndis_request {
|
2010-12-10 21:03:56 +01:00
|
|
|
struct list_head list_ent;
|
2011-05-10 16:55:42 +02:00
|
|
|
struct completion wait_event;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2012-10-02 07:30:24 +02:00
|
|
|
struct rndis_message response_msg;
|
2009-09-02 18:17:52 +02:00
|
|
|
/*
|
2012-10-02 07:30:24 +02:00
|
|
|
* The buffer for extended info after the RNDIS response message. It's
|
|
|
|
* referenced based on the data offset in the RNDIS message. Its size
|
|
|
|
* is enough for current needs, and should be sufficient for the near
|
|
|
|
* future.
|
2009-09-02 18:17:52 +02:00
|
|
|
*/
|
2012-10-02 07:30:24 +02:00
|
|
|
u8 response_ext[RNDIS_EXT_LEN];
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* Simplify allocation by having a netvsc packet inline */
|
2010-12-10 21:03:56 +01:00
|
|
|
struct hv_netvsc_packet pkt;
|
2012-10-02 07:30:21 +02:00
|
|
|
/* Set 2 pages for rndis requests crossing page boundary */
|
|
|
|
struct hv_page_buffer buf[2];
|
2012-08-09 10:04:18 +02:00
|
|
|
|
2010-12-10 21:03:56 +01:00
|
|
|
struct rndis_message request_msg;
|
2012-08-09 10:04:18 +02:00
|
|
|
/*
|
2012-10-02 07:30:24 +02:00
|
|
|
* The buffer for the extended info after the RNDIS request message.
|
|
|
|
* It is referenced and sized in a similar way as response_ext.
|
2012-08-09 10:04:18 +02:00
|
|
|
*/
|
2012-10-02 07:30:24 +02:00
|
|
|
u8 request_ext[RNDIS_EXT_LEN];
|
2009-08-29 01:26:27 +02:00
|
|
|
};
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2010-12-10 21:03:57 +01:00
|
|
|
static void rndis_filter_send_completion(void *ctx);
|
2009-09-02 18:17:52 +02:00
|
|
|
|
2010-12-10 21:03:57 +01:00
|
|
|
static void rndis_filter_send_request_completion(void *ctx);
|
2009-07-27 22:47:24 +02:00
|
|
|
|
|
|
|
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2010-12-10 21:03:57 +01:00
|
|
|
static struct rndis_device *get_rndis_device(void)
|
2009-07-14 00:34:54 +02:00
|
|
|
{
|
2009-08-29 01:26:27 +02:00
|
|
|
struct rndis_device *device;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2009-08-29 01:26:27 +02:00
|
|
|
device = kzalloc(sizeof(struct rndis_device), GFP_KERNEL);
|
2009-07-14 00:34:54 +02:00
|
|
|
if (!device)
|
|
|
|
return NULL;
|
|
|
|
|
2009-07-15 23:55:29 +02:00
|
|
|
spin_lock_init(&device->request_lock);
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2010-12-10 21:03:56 +01:00
|
|
|
INIT_LIST_HEAD(&device->req_list);
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2010-12-10 21:03:56 +01:00
|
|
|
device->state = RNDIS_DEV_UNINITIALIZED;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
|
|
|
return device;
|
|
|
|
}
|
|
|
|
|
2010-12-10 21:03:57 +01:00
|
|
|
static struct rndis_request *get_rndis_request(struct rndis_device *dev,
|
2010-12-10 21:03:56 +01:00
|
|
|
u32 msg_type,
|
|
|
|
u32 msg_len)
|
2009-07-14 00:34:54 +02:00
|
|
|
{
|
2009-08-29 01:26:27 +02:00
|
|
|
struct rndis_request *request;
|
2010-12-10 21:03:56 +01:00
|
|
|
struct rndis_message *rndis_msg;
|
2009-08-20 01:26:24 +02:00
|
|
|
struct rndis_set_request *set;
|
2009-07-15 23:55:29 +02:00
|
|
|
unsigned long flags;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2009-08-29 01:26:27 +02:00
|
|
|
request = kzalloc(sizeof(struct rndis_request), GFP_KERNEL);
|
2009-07-14 00:34:54 +02:00
|
|
|
if (!request)
|
|
|
|
return NULL;
|
|
|
|
|
2011-05-10 16:55:42 +02:00
|
|
|
init_completion(&request->wait_event);
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2010-12-10 21:03:56 +01:00
|
|
|
rndis_msg = &request->request_msg;
|
2010-12-10 21:04:00 +01:00
|
|
|
rndis_msg->ndis_msg_type = msg_type;
|
|
|
|
rndis_msg->msg_len = msg_len;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2009-09-02 18:17:52 +02:00
|
|
|
/*
|
|
|
|
* Set the request id. This field is always after the rndis header for
|
|
|
|
* request/response packet types so we just used the SetRequest as a
|
|
|
|
* template
|
|
|
|
*/
|
2010-12-10 21:04:00 +01:00
|
|
|
set = &rndis_msg->msg.set_req;
|
|
|
|
set->req_id = atomic_inc_return(&dev->new_req_id);
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* Add to the request list */
|
2010-12-10 21:03:56 +01:00
|
|
|
spin_lock_irqsave(&dev->request_lock, flags);
|
|
|
|
list_add_tail(&request->list_ent, &dev->req_list);
|
|
|
|
spin_unlock_irqrestore(&dev->request_lock, flags);
|
2009-07-14 00:34:54 +02:00
|
|
|
|
|
|
|
return request;
|
|
|
|
}
|
|
|
|
|
2010-12-10 21:03:57 +01:00
|
|
|
static void put_rndis_request(struct rndis_device *dev,
|
2010-12-10 21:03:56 +01:00
|
|
|
struct rndis_request *req)
|
2009-07-14 00:34:54 +02:00
|
|
|
{
|
2009-07-15 23:55:29 +02:00
|
|
|
unsigned long flags;
|
|
|
|
|
2010-12-10 21:03:56 +01:00
|
|
|
spin_lock_irqsave(&dev->request_lock, flags);
|
|
|
|
list_del(&req->list_ent);
|
|
|
|
spin_unlock_irqrestore(&dev->request_lock, flags);
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2010-12-10 21:03:56 +01:00
|
|
|
kfree(req);
|
2009-07-14 00:34:54 +02:00
|
|
|
}
|
|
|
|
|
2011-05-27 15:21:54 +02:00
|
|
|
static void dump_rndis_message(struct hv_device *hv_dev,
|
|
|
|
struct rndis_message *rndis_msg)
|
2009-07-14 00:34:54 +02:00
|
|
|
{
|
2011-09-13 19:59:49 +02:00
|
|
|
struct net_device *netdev;
|
|
|
|
struct netvsc_device *net_device;
|
|
|
|
|
|
|
|
net_device = hv_get_drvdata(hv_dev);
|
|
|
|
netdev = net_device->ndev;
|
2011-05-27 15:21:54 +02:00
|
|
|
|
2010-12-10 21:04:00 +01:00
|
|
|
switch (rndis_msg->ndis_msg_type) {
|
2012-05-12 00:17:07 +02:00
|
|
|
case RNDIS_MSG_PACKET:
|
|
|
|
netdev_dbg(netdev, "RNDIS_MSG_PACKET (len %u, "
|
2009-09-02 18:17:52 +02:00
|
|
|
"data offset %u data len %u, # oob %u, "
|
|
|
|
"oob offset %u, oob len %u, pkt offset %u, "
|
2011-05-27 15:21:54 +02:00
|
|
|
"pkt len %u\n",
|
2010-12-10 21:04:00 +01:00
|
|
|
rndis_msg->msg_len,
|
|
|
|
rndis_msg->msg.pkt.data_offset,
|
|
|
|
rndis_msg->msg.pkt.data_len,
|
|
|
|
rndis_msg->msg.pkt.num_oob_data_elements,
|
|
|
|
rndis_msg->msg.pkt.oob_data_offset,
|
|
|
|
rndis_msg->msg.pkt.oob_data_len,
|
|
|
|
rndis_msg->msg.pkt.per_pkt_info_offset,
|
|
|
|
rndis_msg->msg.pkt.per_pkt_info_len);
|
2009-07-14 00:34:54 +02:00
|
|
|
break;
|
|
|
|
|
2012-05-12 00:17:07 +02:00
|
|
|
case RNDIS_MSG_INIT_C:
|
|
|
|
netdev_dbg(netdev, "RNDIS_MSG_INIT_C "
|
2009-09-02 18:17:52 +02:00
|
|
|
"(len %u, id 0x%x, status 0x%x, major %d, minor %d, "
|
|
|
|
"device flags %d, max xfer size 0x%x, max pkts %u, "
|
2011-05-27 15:21:54 +02:00
|
|
|
"pkt aligned %u)\n",
|
2010-12-10 21:04:00 +01:00
|
|
|
rndis_msg->msg_len,
|
|
|
|
rndis_msg->msg.init_complete.req_id,
|
|
|
|
rndis_msg->msg.init_complete.status,
|
|
|
|
rndis_msg->msg.init_complete.major_ver,
|
|
|
|
rndis_msg->msg.init_complete.minor_ver,
|
|
|
|
rndis_msg->msg.init_complete.dev_flags,
|
|
|
|
rndis_msg->msg.init_complete.max_xfer_size,
|
|
|
|
rndis_msg->msg.init_complete.
|
|
|
|
max_pkt_per_msg,
|
|
|
|
rndis_msg->msg.init_complete.
|
|
|
|
pkt_alignment_factor);
|
2009-07-14 00:34:54 +02:00
|
|
|
break;
|
|
|
|
|
2012-05-12 00:17:07 +02:00
|
|
|
case RNDIS_MSG_QUERY_C:
|
|
|
|
netdev_dbg(netdev, "RNDIS_MSG_QUERY_C "
|
2009-09-02 18:17:52 +02:00
|
|
|
"(len %u, id 0x%x, status 0x%x, buf len %u, "
|
2011-05-27 15:21:54 +02:00
|
|
|
"buf offset %u)\n",
|
2010-12-10 21:04:00 +01:00
|
|
|
rndis_msg->msg_len,
|
|
|
|
rndis_msg->msg.query_complete.req_id,
|
|
|
|
rndis_msg->msg.query_complete.status,
|
|
|
|
rndis_msg->msg.query_complete.
|
|
|
|
info_buflen,
|
|
|
|
rndis_msg->msg.query_complete.
|
|
|
|
info_buf_offset);
|
2009-07-14 00:34:54 +02:00
|
|
|
break;
|
|
|
|
|
2012-05-12 00:17:07 +02:00
|
|
|
case RNDIS_MSG_SET_C:
|
2011-05-27 15:21:54 +02:00
|
|
|
netdev_dbg(netdev,
|
2012-05-12 00:17:07 +02:00
|
|
|
"RNDIS_MSG_SET_C (len %u, id 0x%x, status 0x%x)\n",
|
2010-12-10 21:04:00 +01:00
|
|
|
rndis_msg->msg_len,
|
|
|
|
rndis_msg->msg.set_complete.req_id,
|
|
|
|
rndis_msg->msg.set_complete.status);
|
2009-07-14 00:34:54 +02:00
|
|
|
break;
|
|
|
|
|
2012-05-12 00:17:07 +02:00
|
|
|
case RNDIS_MSG_INDICATE:
|
|
|
|
netdev_dbg(netdev, "RNDIS_MSG_INDICATE "
|
2011-05-27 15:21:54 +02:00
|
|
|
"(len %u, status 0x%x, buf len %u, buf offset %u)\n",
|
2010-12-10 21:04:00 +01:00
|
|
|
rndis_msg->msg_len,
|
|
|
|
rndis_msg->msg.indicate_status.status,
|
|
|
|
rndis_msg->msg.indicate_status.status_buflen,
|
|
|
|
rndis_msg->msg.indicate_status.status_buf_offset);
|
2009-07-14 00:34:54 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2011-05-27 15:21:54 +02:00
|
|
|
netdev_dbg(netdev, "0x%x (len %u)\n",
|
2010-12-10 21:04:00 +01:00
|
|
|
rndis_msg->ndis_msg_type,
|
|
|
|
rndis_msg->msg_len);
|
2009-07-14 00:34:54 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-10 21:03:57 +01:00
|
|
|
static int rndis_filter_send_request(struct rndis_device *dev,
|
2010-12-10 21:03:56 +01:00
|
|
|
struct rndis_request *req)
|
2009-07-14 00:34:54 +02:00
|
|
|
{
|
2009-09-02 18:17:52 +02:00
|
|
|
int ret;
|
2009-07-29 14:10:10 +02:00
|
|
|
struct hv_netvsc_packet *packet;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* Setup the packet to send it */
|
2010-12-10 21:03:56 +01:00
|
|
|
packet = &req->pkt;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2010-12-10 21:03:58 +01:00
|
|
|
packet->is_data_pkt = false;
|
2010-12-10 21:04:00 +01:00
|
|
|
packet->total_data_buflen = req->request_msg.msg_len;
|
2010-12-10 21:03:58 +01:00
|
|
|
packet->page_buf_cnt = 1;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2011-01-26 21:12:11 +01:00
|
|
|
packet->page_buf[0].pfn = virt_to_phys(&req->request_msg) >>
|
2009-09-02 18:17:52 +02:00
|
|
|
PAGE_SHIFT;
|
2011-01-26 21:12:11 +01:00
|
|
|
packet->page_buf[0].len = req->request_msg.msg_len;
|
|
|
|
packet->page_buf[0].offset =
|
2010-12-10 21:03:56 +01:00
|
|
|
(unsigned long)&req->request_msg & (PAGE_SIZE - 1);
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2012-10-02 07:30:21 +02:00
|
|
|
/* Add one page_buf when request_msg crossing page boundary */
|
|
|
|
if (packet->page_buf[0].offset + packet->page_buf[0].len > PAGE_SIZE) {
|
|
|
|
packet->page_buf_cnt++;
|
|
|
|
packet->page_buf[0].len = PAGE_SIZE -
|
|
|
|
packet->page_buf[0].offset;
|
|
|
|
packet->page_buf[1].pfn = virt_to_phys((void *)&req->request_msg
|
|
|
|
+ packet->page_buf[0].len) >> PAGE_SHIFT;
|
|
|
|
packet->page_buf[1].offset = 0;
|
|
|
|
packet->page_buf[1].len = req->request_msg.msg_len -
|
|
|
|
packet->page_buf[0].len;
|
|
|
|
}
|
|
|
|
|
2010-12-10 21:03:58 +01:00
|
|
|
packet->completion.send.send_completion_ctx = req;/* packet; */
|
|
|
|
packet->completion.send.send_completion =
|
2010-12-10 21:03:57 +01:00
|
|
|
rndis_filter_send_request_completion;
|
2010-12-10 21:03:58 +01:00
|
|
|
packet->completion.send.send_completion_tid = (unsigned long)dev;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2011-05-13 04:34:55 +02:00
|
|
|
ret = netvsc_send(dev->net_dev->dev, packet);
|
2009-07-14 00:34:54 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-12-10 21:03:57 +01:00
|
|
|
static void rndis_filter_receive_response(struct rndis_device *dev,
|
2010-12-10 21:03:56 +01:00
|
|
|
struct rndis_message *resp)
|
2009-07-14 00:34:54 +02:00
|
|
|
{
|
2009-08-29 01:26:27 +02:00
|
|
|
struct rndis_request *request = NULL;
|
2009-07-15 21:46:44 +02:00
|
|
|
bool found = false;
|
2009-07-15 23:55:29 +02:00
|
|
|
unsigned long flags;
|
2011-09-13 19:59:49 +02:00
|
|
|
struct net_device *ndev;
|
|
|
|
|
|
|
|
ndev = dev->net_dev->ndev;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2010-12-10 21:03:56 +01:00
|
|
|
spin_lock_irqsave(&dev->request_lock, flags);
|
|
|
|
list_for_each_entry(request, &dev->req_list, list_ent) {
|
2009-09-02 18:17:52 +02:00
|
|
|
/*
|
|
|
|
* All request/response message contains RequestId as the 1st
|
|
|
|
* field
|
|
|
|
*/
|
2010-12-10 21:04:00 +01:00
|
|
|
if (request->request_msg.msg.init_req.req_id
|
|
|
|
== resp->msg.init_complete.req_id) {
|
2009-07-15 21:46:44 +02:00
|
|
|
found = true;
|
2009-07-14 00:34:54 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-12-10 21:03:56 +01:00
|
|
|
spin_unlock_irqrestore(&dev->request_lock, flags);
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2009-09-02 18:17:52 +02:00
|
|
|
if (found) {
|
2012-10-02 07:30:24 +02:00
|
|
|
if (resp->msg_len <=
|
|
|
|
sizeof(struct rndis_message) + RNDIS_EXT_LEN) {
|
2010-12-10 21:03:56 +01:00
|
|
|
memcpy(&request->response_msg, resp,
|
2010-12-10 21:04:00 +01:00
|
|
|
resp->msg_len);
|
2009-09-02 18:17:52 +02:00
|
|
|
} else {
|
2011-09-01 21:19:41 +02:00
|
|
|
netdev_err(ndev,
|
2011-03-29 22:58:48 +02:00
|
|
|
"rndis response buffer overflow "
|
|
|
|
"detected (size %u max %zu)\n",
|
|
|
|
resp->msg_len,
|
|
|
|
sizeof(struct rndis_filter_packet));
|
2009-09-02 18:17:52 +02:00
|
|
|
|
2010-12-10 21:04:00 +01:00
|
|
|
if (resp->ndis_msg_type ==
|
2012-05-12 00:17:07 +02:00
|
|
|
RNDIS_MSG_RESET_C) {
|
2009-09-02 18:17:52 +02:00
|
|
|
/* does not have a request id field */
|
2010-12-10 21:04:00 +01:00
|
|
|
request->response_msg.msg.reset_complete.
|
2012-05-12 00:15:59 +02:00
|
|
|
status = RNDIS_STATUS_BUFFER_OVERFLOW;
|
2009-09-02 18:17:52 +02:00
|
|
|
} else {
|
2010-12-10 21:04:00 +01:00
|
|
|
request->response_msg.msg.
|
|
|
|
init_complete.status =
|
2012-05-12 00:15:59 +02:00
|
|
|
RNDIS_STATUS_BUFFER_OVERFLOW;
|
2009-07-14 00:34:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-10 16:55:42 +02:00
|
|
|
complete(&request->wait_event);
|
2009-09-02 18:17:52 +02:00
|
|
|
} else {
|
2011-09-01 21:19:41 +02:00
|
|
|
netdev_err(ndev,
|
2011-03-29 22:58:48 +02:00
|
|
|
"no rndis request found for this response "
|
|
|
|
"(id 0x%x res type 0x%x)\n",
|
|
|
|
resp->msg.init_complete.req_id,
|
|
|
|
resp->ndis_msg_type);
|
2009-07-14 00:34:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-10 21:03:57 +01:00
|
|
|
static void rndis_filter_receive_indicate_status(struct rndis_device *dev,
|
2010-12-10 21:03:56 +01:00
|
|
|
struct rndis_message *resp)
|
2009-07-14 00:34:54 +02:00
|
|
|
{
|
2009-09-02 18:17:52 +02:00
|
|
|
struct rndis_indicate_status *indicate =
|
2010-12-10 21:04:00 +01:00
|
|
|
&resp->msg.indicate_status;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2010-12-10 21:04:00 +01:00
|
|
|
if (indicate->status == RNDIS_STATUS_MEDIA_CONNECT) {
|
2011-05-13 04:34:56 +02:00
|
|
|
netvsc_linkstatus_callback(
|
2010-12-10 21:03:59 +01:00
|
|
|
dev->net_dev->dev, 1);
|
2010-12-10 21:04:00 +01:00
|
|
|
} else if (indicate->status == RNDIS_STATUS_MEDIA_DISCONNECT) {
|
2011-05-13 04:34:56 +02:00
|
|
|
netvsc_linkstatus_callback(
|
2010-12-10 21:03:59 +01:00
|
|
|
dev->net_dev->dev, 0);
|
2009-09-02 18:17:52 +02:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* TODO:
|
|
|
|
*/
|
2009-07-14 00:34:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-12 11:20:50 +01:00
|
|
|
/*
|
|
|
|
* Get the Per-Packet-Info with the specified type
|
|
|
|
* return NULL if not found.
|
|
|
|
*/
|
|
|
|
static inline void *rndis_get_ppi(struct rndis_packet *rpkt, u32 type)
|
|
|
|
{
|
|
|
|
struct rndis_per_packet_info *ppi;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if (rpkt->per_pkt_info_offset == 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ppi = (struct rndis_per_packet_info *)((ulong)rpkt +
|
|
|
|
rpkt->per_pkt_info_offset);
|
|
|
|
len = rpkt->per_pkt_info_len;
|
|
|
|
|
|
|
|
while (len > 0) {
|
|
|
|
if (ppi->type == type)
|
|
|
|
return (void *)((ulong)ppi + ppi->ppi_offset);
|
|
|
|
len -= ppi->size;
|
|
|
|
ppi = (struct rndis_per_packet_info *)((ulong)ppi + ppi->size);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-12-10 21:03:57 +01:00
|
|
|
static void rndis_filter_receive_data(struct rndis_device *dev,
|
2010-12-10 21:03:56 +01:00
|
|
|
struct rndis_message *msg,
|
|
|
|
struct hv_netvsc_packet *pkt)
|
2009-07-14 00:34:54 +02:00
|
|
|
{
|
2010-12-10 21:03:56 +01:00
|
|
|
struct rndis_packet *rndis_pkt;
|
|
|
|
u32 data_offset;
|
2012-03-12 11:20:50 +01:00
|
|
|
struct ndis_pkt_8021q_info *vlan;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2010-12-10 21:04:00 +01:00
|
|
|
rndis_pkt = &msg->msg.pkt;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2009-09-02 18:17:52 +02:00
|
|
|
/*
|
|
|
|
* FIXME: Handle multiple rndis pkt msgs that maybe enclosed in this
|
|
|
|
* netvsc packet (ie TotalDataBufferLength != MessageLength)
|
|
|
|
*/
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* Remove the rndis header and pass it back up the stack */
|
2010-12-10 21:04:00 +01:00
|
|
|
data_offset = RNDIS_HEADER_SIZE + rndis_pkt->data_offset;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2010-12-10 21:03:58 +01:00
|
|
|
pkt->total_data_buflen -= data_offset;
|
2012-02-01 21:17:23 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure we got a valid RNDIS message, now total_data_buflen
|
|
|
|
* should be the data packet size plus the trailer padding size
|
|
|
|
*/
|
|
|
|
if (pkt->total_data_buflen < rndis_pkt->data_len) {
|
|
|
|
netdev_err(dev->net_dev->ndev, "rndis message buffer "
|
|
|
|
"overflow detected (got %u, min %u)"
|
|
|
|
"...dropping this message!\n",
|
|
|
|
pkt->total_data_buflen, rndis_pkt->data_len);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove the rndis trailer padding from rndis packet message
|
|
|
|
* rndis_pkt->data_len tell us the real data length, we only copy
|
|
|
|
* the data packet to the stack, without the rndis trailer padding
|
|
|
|
*/
|
|
|
|
pkt->total_data_buflen = rndis_pkt->data_len;
|
2011-12-15 22:45:15 +01:00
|
|
|
pkt->data = (void *)((unsigned long)pkt->data + data_offset);
|
2011-09-01 21:19:47 +02:00
|
|
|
|
2010-12-10 21:03:58 +01:00
|
|
|
pkt->is_data_pkt = true;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2012-03-12 11:20:50 +01:00
|
|
|
vlan = rndis_get_ppi(rndis_pkt, IEEE_8021Q_INFO);
|
|
|
|
if (vlan) {
|
|
|
|
pkt->vlan_tci = VLAN_TAG_PRESENT | vlan->vlanid |
|
|
|
|
(vlan->pri << VLAN_PRIO_SHIFT);
|
|
|
|
} else {
|
|
|
|
pkt->vlan_tci = 0;
|
|
|
|
}
|
|
|
|
|
2011-05-13 04:34:57 +02:00
|
|
|
netvsc_recv_callback(dev->net_dev->dev, pkt);
|
2009-07-14 00:34:54 +02:00
|
|
|
}
|
|
|
|
|
2011-05-13 04:34:52 +02:00
|
|
|
int rndis_filter_receive(struct hv_device *dev,
|
2010-12-10 21:03:56 +01:00
|
|
|
struct hv_netvsc_packet *pkt)
|
2009-07-14 00:34:54 +02:00
|
|
|
{
|
2011-09-13 19:59:49 +02:00
|
|
|
struct netvsc_device *net_dev = hv_get_drvdata(dev);
|
2010-12-10 21:03:56 +01:00
|
|
|
struct rndis_device *rndis_dev;
|
2012-03-12 11:20:49 +01:00
|
|
|
struct rndis_message *rndis_msg;
|
2011-09-13 19:59:49 +02:00
|
|
|
struct net_device *ndev;
|
2012-10-02 07:30:23 +02:00
|
|
|
int ret = 0;
|
2011-09-13 19:59:49 +02:00
|
|
|
|
2012-10-02 07:30:23 +02:00
|
|
|
if (!net_dev) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto exit;
|
|
|
|
}
|
2010-05-05 21:27:47 +02:00
|
|
|
|
2011-10-06 19:10:56 +02:00
|
|
|
ndev = net_dev->ndev;
|
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* Make sure the rndis device state is initialized */
|
2010-12-10 21:03:59 +01:00
|
|
|
if (!net_dev->extension) {
|
2011-09-01 21:19:41 +02:00
|
|
|
netdev_err(ndev, "got rndis message but no rndis device - "
|
2011-03-29 22:58:48 +02:00
|
|
|
"dropping this message!\n");
|
2012-10-02 07:30:23 +02:00
|
|
|
ret = -ENODEV;
|
|
|
|
goto exit;
|
2009-07-14 00:34:54 +02:00
|
|
|
}
|
|
|
|
|
2010-12-10 21:03:59 +01:00
|
|
|
rndis_dev = (struct rndis_device *)net_dev->extension;
|
2010-12-10 21:03:56 +01:00
|
|
|
if (rndis_dev->state == RNDIS_DEV_UNINITIALIZED) {
|
2011-09-01 21:19:41 +02:00
|
|
|
netdev_err(ndev, "got rndis message but rndis device "
|
2011-03-29 22:58:48 +02:00
|
|
|
"uninitialized...dropping this message!\n");
|
2012-10-02 07:30:23 +02:00
|
|
|
ret = -ENODEV;
|
|
|
|
goto exit;
|
2009-07-14 00:34:54 +02:00
|
|
|
}
|
|
|
|
|
2012-03-12 11:20:49 +01:00
|
|
|
rndis_msg = pkt->data;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2012-03-12 11:20:49 +01:00
|
|
|
dump_rndis_message(dev, rndis_msg);
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2012-03-12 11:20:49 +01:00
|
|
|
switch (rndis_msg->ndis_msg_type) {
|
2012-05-12 00:17:07 +02:00
|
|
|
case RNDIS_MSG_PACKET:
|
2009-09-02 18:17:52 +02:00
|
|
|
/* data msg */
|
2012-03-12 11:20:49 +01:00
|
|
|
rndis_filter_receive_data(rndis_dev, rndis_msg, pkt);
|
2009-07-14 00:34:54 +02:00
|
|
|
break;
|
|
|
|
|
2012-05-12 00:17:07 +02:00
|
|
|
case RNDIS_MSG_INIT_C:
|
|
|
|
case RNDIS_MSG_QUERY_C:
|
|
|
|
case RNDIS_MSG_SET_C:
|
2009-09-02 18:17:52 +02:00
|
|
|
/* completion msgs */
|
2012-03-12 11:20:49 +01:00
|
|
|
rndis_filter_receive_response(rndis_dev, rndis_msg);
|
2009-07-14 00:34:54 +02:00
|
|
|
break;
|
|
|
|
|
2012-05-12 00:17:07 +02:00
|
|
|
case RNDIS_MSG_INDICATE:
|
2009-09-02 18:17:52 +02:00
|
|
|
/* notification msgs */
|
2012-03-12 11:20:49 +01:00
|
|
|
rndis_filter_receive_indicate_status(rndis_dev, rndis_msg);
|
2009-07-14 00:34:54 +02:00
|
|
|
break;
|
|
|
|
default:
|
2011-09-01 21:19:41 +02:00
|
|
|
netdev_err(ndev,
|
2011-03-29 22:58:48 +02:00
|
|
|
"unhandled rndis message (type %u len %u)\n",
|
2012-03-12 11:20:49 +01:00
|
|
|
rndis_msg->ndis_msg_type,
|
|
|
|
rndis_msg->msg_len);
|
2009-07-14 00:34:54 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-10-02 07:30:23 +02:00
|
|
|
exit:
|
|
|
|
if (ret != 0)
|
|
|
|
pkt->status = NVSP_STAT_FAIL;
|
|
|
|
|
|
|
|
return ret;
|
2009-07-14 00:34:54 +02:00
|
|
|
}
|
|
|
|
|
2010-12-10 21:03:57 +01:00
|
|
|
static int rndis_filter_query_device(struct rndis_device *dev, u32 oid,
|
2010-12-10 21:03:56 +01:00
|
|
|
void *result, u32 *result_size)
|
2009-07-14 00:34:54 +02:00
|
|
|
{
|
2009-08-29 01:26:27 +02:00
|
|
|
struct rndis_request *request;
|
2010-12-10 21:03:56 +01:00
|
|
|
u32 inresult_size = *result_size;
|
2009-08-20 01:26:24 +02:00
|
|
|
struct rndis_query_request *query;
|
2010-12-10 21:03:56 +01:00
|
|
|
struct rndis_query_complete *query_complete;
|
2009-09-02 18:17:52 +02:00
|
|
|
int ret = 0;
|
2011-05-10 16:55:42 +02:00
|
|
|
int t;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2010-12-10 21:03:56 +01:00
|
|
|
if (!result)
|
2010-05-05 21:27:47 +02:00
|
|
|
return -EINVAL;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2010-12-10 21:03:56 +01:00
|
|
|
*result_size = 0;
|
2012-05-12 00:17:07 +02:00
|
|
|
request = get_rndis_request(dev, RNDIS_MSG_QUERY,
|
2009-09-02 18:17:52 +02:00
|
|
|
RNDIS_MESSAGE_SIZE(struct rndis_query_request));
|
|
|
|
if (!request) {
|
2011-08-25 18:49:18 +02:00
|
|
|
ret = -ENOMEM;
|
2011-08-25 18:49:24 +02:00
|
|
|
goto cleanup;
|
2009-07-14 00:34:54 +02:00
|
|
|
}
|
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* Setup the rndis query */
|
2010-12-10 21:04:00 +01:00
|
|
|
query = &request->request_msg.msg.query_req;
|
|
|
|
query->oid = oid;
|
|
|
|
query->info_buf_offset = sizeof(struct rndis_query_request);
|
|
|
|
query->info_buflen = 0;
|
|
|
|
query->dev_vc_handle = 0;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2010-12-10 21:03:57 +01:00
|
|
|
ret = rndis_filter_send_request(dev, request);
|
2009-07-14 00:34:54 +02:00
|
|
|
if (ret != 0)
|
2011-08-25 18:49:24 +02:00
|
|
|
goto cleanup;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2011-06-16 22:16:35 +02:00
|
|
|
t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
|
2011-05-10 16:55:42 +02:00
|
|
|
if (t == 0) {
|
2011-02-11 18:59:43 +01:00
|
|
|
ret = -ETIMEDOUT;
|
2011-08-25 18:49:24 +02:00
|
|
|
goto cleanup;
|
2011-02-11 18:59:43 +01:00
|
|
|
}
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* Copy the response back */
|
2010-12-10 21:04:00 +01:00
|
|
|
query_complete = &request->response_msg.msg.query_complete;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2010-12-10 21:04:00 +01:00
|
|
|
if (query_complete->info_buflen > inresult_size) {
|
2009-07-14 00:34:54 +02:00
|
|
|
ret = -1;
|
2011-08-25 18:49:24 +02:00
|
|
|
goto cleanup;
|
2009-07-14 00:34:54 +02:00
|
|
|
}
|
|
|
|
|
2010-12-10 21:03:56 +01:00
|
|
|
memcpy(result,
|
|
|
|
(void *)((unsigned long)query_complete +
|
2010-12-10 21:04:00 +01:00
|
|
|
query_complete->info_buf_offset),
|
|
|
|
query_complete->info_buflen);
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2010-12-10 21:04:00 +01:00
|
|
|
*result_size = query_complete->info_buflen;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2011-08-25 18:49:24 +02:00
|
|
|
cleanup:
|
2009-07-14 00:34:54 +02:00
|
|
|
if (request)
|
2010-12-10 21:03:57 +01:00
|
|
|
put_rndis_request(dev, request);
|
2009-07-14 00:34:54 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-12-10 21:03:57 +01:00
|
|
|
static int rndis_filter_query_device_mac(struct rndis_device *dev)
|
2009-07-14 00:34:54 +02:00
|
|
|
{
|
2010-05-04 18:58:54 +02:00
|
|
|
u32 size = ETH_ALEN;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2010-12-10 21:03:57 +01:00
|
|
|
return rndis_filter_query_device(dev,
|
2009-09-02 18:17:52 +02:00
|
|
|
RNDIS_OID_802_3_PERMANENT_ADDRESS,
|
2010-12-10 21:03:56 +01:00
|
|
|
dev->hw_mac_adr, &size);
|
2009-07-14 00:34:54 +02:00
|
|
|
}
|
|
|
|
|
2012-07-10 09:19:22 +02:00
|
|
|
#define NWADR_STR "NetworkAddress"
|
|
|
|
#define NWADR_STRLEN 14
|
|
|
|
|
|
|
|
int rndis_filter_set_device_mac(struct hv_device *hdev, char *mac)
|
|
|
|
{
|
|
|
|
struct netvsc_device *nvdev = hv_get_drvdata(hdev);
|
|
|
|
struct rndis_device *rdev = nvdev->extension;
|
|
|
|
struct net_device *ndev = nvdev->ndev;
|
|
|
|
struct rndis_request *request;
|
|
|
|
struct rndis_set_request *set;
|
|
|
|
struct rndis_config_parameter_info *cpi;
|
|
|
|
wchar_t *cfg_nwadr, *cfg_mac;
|
|
|
|
struct rndis_set_complete *set_complete;
|
|
|
|
char macstr[2*ETH_ALEN+1];
|
|
|
|
u32 extlen = sizeof(struct rndis_config_parameter_info) +
|
|
|
|
2*NWADR_STRLEN + 4*ETH_ALEN;
|
|
|
|
int ret, t;
|
|
|
|
|
|
|
|
request = get_rndis_request(rdev, RNDIS_MSG_SET,
|
|
|
|
RNDIS_MESSAGE_SIZE(struct rndis_set_request) + extlen);
|
|
|
|
if (!request)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
set = &request->request_msg.msg.set_req;
|
|
|
|
set->oid = RNDIS_OID_GEN_RNDIS_CONFIG_PARAMETER;
|
|
|
|
set->info_buflen = extlen;
|
|
|
|
set->info_buf_offset = sizeof(struct rndis_set_request);
|
|
|
|
set->dev_vc_handle = 0;
|
|
|
|
|
|
|
|
cpi = (struct rndis_config_parameter_info *)((ulong)set +
|
|
|
|
set->info_buf_offset);
|
|
|
|
cpi->parameter_name_offset =
|
|
|
|
sizeof(struct rndis_config_parameter_info);
|
|
|
|
/* Multiply by 2 because host needs 2 bytes (utf16) for each char */
|
|
|
|
cpi->parameter_name_length = 2*NWADR_STRLEN;
|
|
|
|
cpi->parameter_type = RNDIS_CONFIG_PARAM_TYPE_STRING;
|
|
|
|
cpi->parameter_value_offset =
|
|
|
|
cpi->parameter_name_offset + cpi->parameter_name_length;
|
|
|
|
/* Multiply by 4 because each MAC byte displayed as 2 utf16 chars */
|
|
|
|
cpi->parameter_value_length = 4*ETH_ALEN;
|
|
|
|
|
|
|
|
cfg_nwadr = (wchar_t *)((ulong)cpi + cpi->parameter_name_offset);
|
|
|
|
cfg_mac = (wchar_t *)((ulong)cpi + cpi->parameter_value_offset);
|
|
|
|
ret = utf8s_to_utf16s(NWADR_STR, NWADR_STRLEN, UTF16_HOST_ENDIAN,
|
|
|
|
cfg_nwadr, NWADR_STRLEN);
|
|
|
|
if (ret < 0)
|
|
|
|
goto cleanup;
|
|
|
|
snprintf(macstr, 2*ETH_ALEN+1, "%pm", mac);
|
|
|
|
ret = utf8s_to_utf16s(macstr, 2*ETH_ALEN, UTF16_HOST_ENDIAN,
|
|
|
|
cfg_mac, 2*ETH_ALEN);
|
|
|
|
if (ret < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = rndis_filter_send_request(rdev, request);
|
|
|
|
if (ret != 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
|
|
|
|
if (t == 0) {
|
|
|
|
netdev_err(ndev, "timeout before we got a set response...\n");
|
|
|
|
/*
|
|
|
|
* can't put_rndis_request, since we may still receive a
|
|
|
|
* send-completion.
|
|
|
|
*/
|
|
|
|
return -EBUSY;
|
|
|
|
} else {
|
|
|
|
set_complete = &request->response_msg.msg.set_complete;
|
|
|
|
if (set_complete->status != RNDIS_STATUS_SUCCESS)
|
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
put_rndis_request(rdev, request);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-10 21:03:57 +01:00
|
|
|
static int rndis_filter_query_device_link_status(struct rndis_device *dev)
|
2009-07-14 00:34:54 +02:00
|
|
|
{
|
2009-09-02 18:17:52 +02:00
|
|
|
u32 size = sizeof(u32);
|
2011-09-14 00:21:27 +02:00
|
|
|
u32 link_status;
|
|
|
|
int ret;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2011-09-14 00:21:27 +02:00
|
|
|
ret = rndis_filter_query_device(dev,
|
2009-09-02 18:17:52 +02:00
|
|
|
RNDIS_OID_GEN_MEDIA_CONNECT_STATUS,
|
2011-09-14 00:21:27 +02:00
|
|
|
&link_status, &size);
|
|
|
|
dev->link_state = (link_status != 0) ? true : false;
|
|
|
|
|
|
|
|
return ret;
|
2009-07-14 00:34:54 +02:00
|
|
|
}
|
|
|
|
|
2011-11-30 16:19:08 +01:00
|
|
|
int rndis_filter_set_packet_filter(struct rndis_device *dev, u32 new_filter)
|
2009-07-14 00:34:54 +02:00
|
|
|
{
|
2009-08-29 01:26:27 +02:00
|
|
|
struct rndis_request *request;
|
2009-08-20 01:26:24 +02:00
|
|
|
struct rndis_set_request *set;
|
2010-12-10 21:03:56 +01:00
|
|
|
struct rndis_set_complete *set_complete;
|
2009-07-15 00:09:36 +02:00
|
|
|
u32 status;
|
2011-05-10 16:55:42 +02:00
|
|
|
int ret, t;
|
2011-09-13 19:59:49 +02:00
|
|
|
struct net_device *ndev;
|
|
|
|
|
|
|
|
ndev = dev->net_dev->ndev;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2012-05-12 00:17:07 +02:00
|
|
|
request = get_rndis_request(dev, RNDIS_MSG_SET,
|
2009-09-02 18:17:52 +02:00
|
|
|
RNDIS_MESSAGE_SIZE(struct rndis_set_request) +
|
|
|
|
sizeof(u32));
|
|
|
|
if (!request) {
|
2011-08-25 18:49:19 +02:00
|
|
|
ret = -ENOMEM;
|
2011-08-25 18:49:24 +02:00
|
|
|
goto cleanup;
|
2009-07-14 00:34:54 +02:00
|
|
|
}
|
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* Setup the rndis set */
|
2010-12-10 21:04:00 +01:00
|
|
|
set = &request->request_msg.msg.set_req;
|
|
|
|
set->oid = RNDIS_OID_GEN_CURRENT_PACKET_FILTER;
|
|
|
|
set->info_buflen = sizeof(u32);
|
|
|
|
set->info_buf_offset = sizeof(struct rndis_set_request);
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2009-09-02 18:17:52 +02:00
|
|
|
memcpy((void *)(unsigned long)set + sizeof(struct rndis_set_request),
|
2010-12-10 21:03:56 +01:00
|
|
|
&new_filter, sizeof(u32));
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2010-12-10 21:03:57 +01:00
|
|
|
ret = rndis_filter_send_request(dev, request);
|
2009-07-14 00:34:54 +02:00
|
|
|
if (ret != 0)
|
2011-08-25 18:49:24 +02:00
|
|
|
goto cleanup;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2011-06-16 22:16:35 +02:00
|
|
|
t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
|
2011-05-10 16:55:42 +02:00
|
|
|
|
|
|
|
if (t == 0) {
|
2011-09-01 21:19:41 +02:00
|
|
|
netdev_err(ndev,
|
2011-03-29 22:58:48 +02:00
|
|
|
"timeout before we got a set response...\n");
|
2012-10-02 07:30:20 +02:00
|
|
|
ret = -ETIMEDOUT;
|
2009-09-02 18:17:52 +02:00
|
|
|
/*
|
2011-03-31 03:57:33 +02:00
|
|
|
* We can't deallocate the request since we may still receive a
|
2009-09-02 18:17:52 +02:00
|
|
|
* send completion for it.
|
|
|
|
*/
|
2011-08-25 18:49:25 +02:00
|
|
|
goto exit;
|
2009-09-02 18:17:52 +02:00
|
|
|
} else {
|
2010-12-10 21:04:00 +01:00
|
|
|
set_complete = &request->response_msg.msg.set_complete;
|
|
|
|
status = set_complete->status;
|
2009-07-14 00:34:54 +02:00
|
|
|
}
|
|
|
|
|
2011-08-25 18:49:24 +02:00
|
|
|
cleanup:
|
2009-07-14 00:34:54 +02:00
|
|
|
if (request)
|
2010-12-10 21:03:57 +01:00
|
|
|
put_rndis_request(dev, request);
|
2011-08-25 18:49:25 +02:00
|
|
|
exit:
|
2009-07-14 00:34:54 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-10 21:03:57 +01:00
|
|
|
static int rndis_filter_init_device(struct rndis_device *dev)
|
2009-07-14 00:34:54 +02:00
|
|
|
{
|
2009-08-29 01:26:27 +02:00
|
|
|
struct rndis_request *request;
|
2009-08-20 01:26:24 +02:00
|
|
|
struct rndis_initialize_request *init;
|
2010-12-10 21:03:56 +01:00
|
|
|
struct rndis_initialize_complete *init_complete;
|
2009-07-15 00:09:36 +02:00
|
|
|
u32 status;
|
2011-05-10 16:55:42 +02:00
|
|
|
int ret, t;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2012-05-12 00:17:07 +02:00
|
|
|
request = get_rndis_request(dev, RNDIS_MSG_INIT,
|
2009-09-02 18:17:52 +02:00
|
|
|
RNDIS_MESSAGE_SIZE(struct rndis_initialize_request));
|
|
|
|
if (!request) {
|
2011-08-25 18:49:20 +02:00
|
|
|
ret = -ENOMEM;
|
2011-08-25 18:49:24 +02:00
|
|
|
goto cleanup;
|
2009-07-14 00:34:54 +02:00
|
|
|
}
|
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* Setup the rndis set */
|
2010-12-10 21:04:00 +01:00
|
|
|
init = &request->request_msg.msg.init_req;
|
|
|
|
init->major_ver = RNDIS_MAJOR_VERSION;
|
|
|
|
init->minor_ver = RNDIS_MINOR_VERSION;
|
2012-10-02 07:30:19 +02:00
|
|
|
init->max_xfer_size = 0x4000;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2010-12-10 21:03:56 +01:00
|
|
|
dev->state = RNDIS_DEV_INITIALIZING;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2010-12-10 21:03:57 +01:00
|
|
|
ret = rndis_filter_send_request(dev, request);
|
2009-09-02 18:17:52 +02:00
|
|
|
if (ret != 0) {
|
2010-12-10 21:03:56 +01:00
|
|
|
dev->state = RNDIS_DEV_UNINITIALIZED;
|
2011-08-25 18:49:24 +02:00
|
|
|
goto cleanup;
|
2009-07-14 00:34:54 +02:00
|
|
|
}
|
|
|
|
|
2011-02-11 18:59:43 +01:00
|
|
|
|
2011-06-16 22:16:35 +02:00
|
|
|
t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
|
2011-05-10 16:55:42 +02:00
|
|
|
|
|
|
|
if (t == 0) {
|
2011-02-11 18:59:43 +01:00
|
|
|
ret = -ETIMEDOUT;
|
2011-08-25 18:49:24 +02:00
|
|
|
goto cleanup;
|
2011-02-11 18:59:43 +01:00
|
|
|
}
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2010-12-10 21:04:00 +01:00
|
|
|
init_complete = &request->response_msg.msg.init_complete;
|
|
|
|
status = init_complete->status;
|
2009-09-02 18:17:52 +02:00
|
|
|
if (status == RNDIS_STATUS_SUCCESS) {
|
2010-12-10 21:03:56 +01:00
|
|
|
dev->state = RNDIS_DEV_INITIALIZED;
|
2009-07-14 00:34:54 +02:00
|
|
|
ret = 0;
|
2009-09-02 18:17:52 +02:00
|
|
|
} else {
|
2010-12-10 21:03:56 +01:00
|
|
|
dev->state = RNDIS_DEV_UNINITIALIZED;
|
2011-08-25 18:49:20 +02:00
|
|
|
ret = -EINVAL;
|
2009-07-14 00:34:54 +02:00
|
|
|
}
|
|
|
|
|
2011-08-25 18:49:24 +02:00
|
|
|
cleanup:
|
2009-07-14 00:34:54 +02:00
|
|
|
if (request)
|
2010-12-10 21:03:57 +01:00
|
|
|
put_rndis_request(dev, request);
|
2009-07-14 00:34:54 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-12-10 21:03:57 +01:00
|
|
|
static void rndis_filter_halt_device(struct rndis_device *dev)
|
2009-07-14 00:34:54 +02:00
|
|
|
{
|
2009-08-29 01:26:27 +02:00
|
|
|
struct rndis_request *request;
|
2009-08-20 01:26:24 +02:00
|
|
|
struct rndis_halt_request *halt;
|
2012-08-03 11:32:18 +02:00
|
|
|
struct netvsc_device *nvdev = dev->net_dev;
|
|
|
|
struct hv_device *hdev = nvdev->dev;
|
|
|
|
ulong flags;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* Attempt to do a rndis device halt */
|
2012-05-12 00:17:07 +02:00
|
|
|
request = get_rndis_request(dev, RNDIS_MSG_HALT,
|
2009-09-02 18:17:52 +02:00
|
|
|
RNDIS_MESSAGE_SIZE(struct rndis_halt_request));
|
2009-07-14 00:34:54 +02:00
|
|
|
if (!request)
|
2011-08-25 18:49:24 +02:00
|
|
|
goto cleanup;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* Setup the rndis set */
|
2010-12-10 21:04:00 +01:00
|
|
|
halt = &request->request_msg.msg.halt_req;
|
|
|
|
halt->req_id = atomic_inc_return(&dev->new_req_id);
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* Ignore return since this msg is optional. */
|
2010-12-10 21:03:57 +01:00
|
|
|
rndis_filter_send_request(dev, request);
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2010-12-10 21:03:56 +01:00
|
|
|
dev->state = RNDIS_DEV_UNINITIALIZED;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2011-08-25 18:49:24 +02:00
|
|
|
cleanup:
|
2012-08-03 11:32:18 +02:00
|
|
|
spin_lock_irqsave(&hdev->channel->inbound_lock, flags);
|
|
|
|
nvdev->destroy = true;
|
|
|
|
spin_unlock_irqrestore(&hdev->channel->inbound_lock, flags);
|
|
|
|
|
|
|
|
/* Wait for all send completions */
|
|
|
|
wait_event(nvdev->wait_drain,
|
|
|
|
atomic_read(&nvdev->num_outstanding_sends) == 0);
|
|
|
|
|
2009-07-14 00:34:54 +02:00
|
|
|
if (request)
|
2010-12-10 21:03:57 +01:00
|
|
|
put_rndis_request(dev, request);
|
2009-07-14 00:34:54 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-12-10 21:03:57 +01:00
|
|
|
static int rndis_filter_open_device(struct rndis_device *dev)
|
2009-07-14 00:34:54 +02:00
|
|
|
{
|
2009-09-02 18:17:52 +02:00
|
|
|
int ret;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2010-12-10 21:03:56 +01:00
|
|
|
if (dev->state != RNDIS_DEV_INITIALIZED)
|
2009-07-14 00:34:54 +02:00
|
|
|
return 0;
|
|
|
|
|
2010-12-10 21:03:57 +01:00
|
|
|
ret = rndis_filter_set_packet_filter(dev,
|
2009-09-02 18:17:52 +02:00
|
|
|
NDIS_PACKET_TYPE_BROADCAST |
|
2010-04-19 17:32:11 +02:00
|
|
|
NDIS_PACKET_TYPE_ALL_MULTICAST |
|
2009-09-02 18:17:52 +02:00
|
|
|
NDIS_PACKET_TYPE_DIRECTED);
|
2009-07-14 00:34:54 +02:00
|
|
|
if (ret == 0)
|
2010-12-10 21:03:56 +01:00
|
|
|
dev->state = RNDIS_DEV_DATAINITIALIZED;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-12-10 21:03:57 +01:00
|
|
|
static int rndis_filter_close_device(struct rndis_device *dev)
|
2009-07-14 00:34:54 +02:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2010-12-10 21:03:56 +01:00
|
|
|
if (dev->state != RNDIS_DEV_DATAINITIALIZED)
|
2009-07-14 00:34:54 +02:00
|
|
|
return 0;
|
|
|
|
|
2010-12-10 21:03:57 +01:00
|
|
|
ret = rndis_filter_set_packet_filter(dev, 0);
|
2009-07-14 00:34:54 +02:00
|
|
|
if (ret == 0)
|
2010-12-10 21:03:56 +01:00
|
|
|
dev->state = RNDIS_DEV_INITIALIZED;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-05-23 18:03:49 +02:00
|
|
|
int rndis_filter_device_add(struct hv_device *dev,
|
2010-12-10 21:03:56 +01:00
|
|
|
void *additional_info)
|
2009-07-14 00:34:54 +02:00
|
|
|
{
|
|
|
|
int ret;
|
2011-09-13 19:59:54 +02:00
|
|
|
struct netvsc_device *net_device;
|
2011-09-13 19:59:55 +02:00
|
|
|
struct rndis_device *rndis_device;
|
2011-09-13 19:59:56 +02:00
|
|
|
struct netvsc_device_info *device_info = additional_info;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2011-09-13 19:59:55 +02:00
|
|
|
rndis_device = get_rndis_device();
|
|
|
|
if (!rndis_device)
|
2011-08-25 18:49:21 +02:00
|
|
|
return -ENODEV;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2009-09-02 18:17:52 +02:00
|
|
|
/*
|
|
|
|
* Let the inner driver handle this first to create the netvsc channel
|
|
|
|
* NOTE! Once the channel is created, we may get a receive callback
|
|
|
|
* (RndisFilterOnReceive()) before this call is completed
|
|
|
|
*/
|
2011-05-10 16:55:00 +02:00
|
|
|
ret = netvsc_device_add(dev, additional_info);
|
2009-09-02 18:17:52 +02:00
|
|
|
if (ret != 0) {
|
2011-09-13 19:59:55 +02:00
|
|
|
kfree(rndis_device);
|
2009-07-14 00:34:54 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
|
|
|
|
/* Initialize the rndis device */
|
2011-09-13 19:59:54 +02:00
|
|
|
net_device = hv_get_drvdata(dev);
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2011-09-13 19:59:55 +02:00
|
|
|
net_device->extension = rndis_device;
|
|
|
|
rndis_device->net_dev = net_device;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* Send the rndis initialization message */
|
2011-09-13 19:59:55 +02:00
|
|
|
ret = rndis_filter_init_device(rndis_device);
|
2009-09-02 18:17:52 +02:00
|
|
|
if (ret != 0) {
|
2012-07-25 10:08:42 +02:00
|
|
|
rndis_filter_device_remove(dev);
|
|
|
|
return ret;
|
2009-07-14 00:34:54 +02:00
|
|
|
}
|
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* Get the mac address */
|
2011-09-13 19:59:55 +02:00
|
|
|
ret = rndis_filter_query_device_mac(rndis_device);
|
2009-09-02 18:17:52 +02:00
|
|
|
if (ret != 0) {
|
2012-07-25 10:08:42 +02:00
|
|
|
rndis_filter_device_remove(dev);
|
|
|
|
return ret;
|
2009-07-14 00:34:54 +02:00
|
|
|
}
|
|
|
|
|
2011-09-13 19:59:56 +02:00
|
|
|
memcpy(device_info->mac_adr, rndis_device->hw_mac_adr, ETH_ALEN);
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2011-09-13 19:59:55 +02:00
|
|
|
rndis_filter_query_device_link_status(rndis_device);
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2011-09-14 00:21:27 +02:00
|
|
|
device_info->link_state = rndis_device->link_state;
|
2011-03-29 22:58:48 +02:00
|
|
|
|
2011-09-14 00:21:27 +02:00
|
|
|
dev_info(&dev->device, "Device MAC %pM link state %s\n",
|
2011-09-13 19:59:55 +02:00
|
|
|
rndis_device->hw_mac_adr,
|
2011-09-14 00:21:27 +02:00
|
|
|
device_info->link_state ? "down" : "up");
|
2009-07-14 00:34:54 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-05-23 18:03:47 +02:00
|
|
|
void rndis_filter_device_remove(struct hv_device *dev)
|
2009-07-14 00:34:54 +02:00
|
|
|
{
|
2011-09-13 19:59:49 +02:00
|
|
|
struct netvsc_device *net_dev = hv_get_drvdata(dev);
|
2010-12-10 21:03:59 +01:00
|
|
|
struct rndis_device *rndis_dev = net_dev->extension;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* Halt and release the rndis device */
|
2010-12-10 21:03:57 +01:00
|
|
|
rndis_filter_halt_device(rndis_dev);
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2010-12-10 21:03:56 +01:00
|
|
|
kfree(rndis_dev);
|
2010-12-10 21:03:59 +01:00
|
|
|
net_dev->extension = NULL;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2011-05-10 16:55:02 +02:00
|
|
|
netvsc_device_remove(dev);
|
2009-07-14 00:34:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-10 21:03:57 +01:00
|
|
|
int rndis_filter_open(struct hv_device *dev)
|
2009-07-14 00:34:54 +02:00
|
|
|
{
|
2011-09-13 19:59:54 +02:00
|
|
|
struct netvsc_device *net_device = hv_get_drvdata(dev);
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2011-09-13 19:59:54 +02:00
|
|
|
if (!net_device)
|
2010-05-05 21:27:47 +02:00
|
|
|
return -EINVAL;
|
|
|
|
|
2011-09-13 19:59:54 +02:00
|
|
|
return rndis_filter_open_device(net_device->extension);
|
2009-07-14 00:34:54 +02:00
|
|
|
}
|
|
|
|
|
2010-12-10 21:03:57 +01:00
|
|
|
int rndis_filter_close(struct hv_device *dev)
|
2009-07-14 00:34:54 +02:00
|
|
|
{
|
2012-02-05 13:13:08 +01:00
|
|
|
struct netvsc_device *nvdev = hv_get_drvdata(dev);
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2012-02-05 13:13:08 +01:00
|
|
|
if (!nvdev)
|
2010-05-05 21:27:47 +02:00
|
|
|
return -EINVAL;
|
|
|
|
|
2012-02-05 13:13:08 +01:00
|
|
|
return rndis_filter_close_device(nvdev->extension);
|
2009-07-14 00:34:54 +02:00
|
|
|
}
|
|
|
|
|
2011-05-13 04:34:53 +02:00
|
|
|
int rndis_filter_send(struct hv_device *dev,
|
2010-12-10 21:03:56 +01:00
|
|
|
struct hv_netvsc_packet *pkt)
|
2009-07-14 00:34:54 +02:00
|
|
|
{
|
2009-09-02 18:17:52 +02:00
|
|
|
int ret;
|
2012-02-05 13:13:08 +01:00
|
|
|
struct rndis_filter_packet *filter_pkt;
|
|
|
|
struct rndis_message *rndis_msg;
|
|
|
|
struct rndis_packet *rndis_pkt;
|
|
|
|
u32 rndis_msg_size;
|
2012-03-12 11:20:50 +01:00
|
|
|
bool isvlan = pkt->vlan_tci & VLAN_TAG_PRESENT;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* Add the rndis header */
|
2012-02-05 13:13:08 +01:00
|
|
|
filter_pkt = (struct rndis_filter_packet *)pkt->extension;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2012-02-05 13:13:08 +01:00
|
|
|
rndis_msg = &filter_pkt->msg;
|
|
|
|
rndis_msg_size = RNDIS_MESSAGE_SIZE(struct rndis_packet);
|
2012-03-12 11:20:50 +01:00
|
|
|
if (isvlan)
|
|
|
|
rndis_msg_size += NDIS_VLAN_PPI_SIZE;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2012-05-12 00:17:07 +02:00
|
|
|
rndis_msg->ndis_msg_type = RNDIS_MSG_PACKET;
|
2012-02-05 13:13:08 +01:00
|
|
|
rndis_msg->msg_len = pkt->total_data_buflen +
|
|
|
|
rndis_msg_size;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2012-02-05 13:13:08 +01:00
|
|
|
rndis_pkt = &rndis_msg->msg.pkt;
|
|
|
|
rndis_pkt->data_offset = sizeof(struct rndis_packet);
|
2012-03-12 11:20:50 +01:00
|
|
|
if (isvlan)
|
|
|
|
rndis_pkt->data_offset += NDIS_VLAN_PPI_SIZE;
|
2012-02-05 13:13:08 +01:00
|
|
|
rndis_pkt->data_len = pkt->total_data_buflen;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2012-03-12 11:20:50 +01:00
|
|
|
if (isvlan) {
|
|
|
|
struct rndis_per_packet_info *ppi;
|
|
|
|
struct ndis_pkt_8021q_info *vlan;
|
|
|
|
|
|
|
|
rndis_pkt->per_pkt_info_offset = sizeof(struct rndis_packet);
|
|
|
|
rndis_pkt->per_pkt_info_len = NDIS_VLAN_PPI_SIZE;
|
|
|
|
|
|
|
|
ppi = (struct rndis_per_packet_info *)((ulong)rndis_pkt +
|
|
|
|
rndis_pkt->per_pkt_info_offset);
|
|
|
|
ppi->size = NDIS_VLAN_PPI_SIZE;
|
|
|
|
ppi->type = IEEE_8021Q_INFO;
|
|
|
|
ppi->ppi_offset = sizeof(struct rndis_per_packet_info);
|
|
|
|
|
|
|
|
vlan = (struct ndis_pkt_8021q_info *)((ulong)ppi +
|
|
|
|
ppi->ppi_offset);
|
|
|
|
vlan->vlanid = pkt->vlan_tci & VLAN_VID_MASK;
|
|
|
|
vlan->pri = (pkt->vlan_tci & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
|
|
|
|
}
|
|
|
|
|
2010-12-10 21:03:58 +01:00
|
|
|
pkt->is_data_pkt = true;
|
2012-02-05 13:13:08 +01:00
|
|
|
pkt->page_buf[0].pfn = virt_to_phys(rndis_msg) >> PAGE_SHIFT;
|
2011-01-26 21:12:11 +01:00
|
|
|
pkt->page_buf[0].offset =
|
2012-02-05 13:13:08 +01:00
|
|
|
(unsigned long)rndis_msg & (PAGE_SIZE-1);
|
|
|
|
pkt->page_buf[0].len = rndis_msg_size;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2012-02-02 08:18:00 +01:00
|
|
|
/* Add one page_buf if the rndis msg goes beyond page boundary */
|
2012-02-05 13:13:08 +01:00
|
|
|
if (pkt->page_buf[0].offset + rndis_msg_size > PAGE_SIZE) {
|
2012-02-02 08:18:00 +01:00
|
|
|
int i;
|
|
|
|
for (i = pkt->page_buf_cnt; i > 1; i--)
|
|
|
|
pkt->page_buf[i] = pkt->page_buf[i-1];
|
|
|
|
pkt->page_buf_cnt++;
|
|
|
|
pkt->page_buf[0].len = PAGE_SIZE - pkt->page_buf[0].offset;
|
|
|
|
pkt->page_buf[1].pfn = virt_to_phys((void *)((ulong)
|
2012-02-05 13:13:08 +01:00
|
|
|
rndis_msg + pkt->page_buf[0].len)) >> PAGE_SHIFT;
|
2012-02-02 08:18:00 +01:00
|
|
|
pkt->page_buf[1].offset = 0;
|
2012-02-05 13:13:08 +01:00
|
|
|
pkt->page_buf[1].len = rndis_msg_size - pkt->page_buf[0].len;
|
2012-02-02 08:18:00 +01:00
|
|
|
}
|
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* Save the packet send completion and context */
|
2012-02-05 13:13:08 +01:00
|
|
|
filter_pkt->completion = pkt->completion.send.send_completion;
|
|
|
|
filter_pkt->completion_ctx =
|
2010-12-10 21:03:58 +01:00
|
|
|
pkt->completion.send.send_completion_ctx;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* Use ours */
|
2010-12-10 21:03:58 +01:00
|
|
|
pkt->completion.send.send_completion = rndis_filter_send_completion;
|
2012-02-05 13:13:08 +01:00
|
|
|
pkt->completion.send.send_completion_ctx = filter_pkt;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2011-05-13 04:34:55 +02:00
|
|
|
ret = netvsc_send(dev, pkt);
|
2009-09-02 18:17:52 +02:00
|
|
|
if (ret != 0) {
|
|
|
|
/*
|
|
|
|
* Reset the completion to originals to allow retries from
|
|
|
|
* above
|
|
|
|
*/
|
2010-12-10 21:03:58 +01:00
|
|
|
pkt->completion.send.send_completion =
|
2012-02-05 13:13:08 +01:00
|
|
|
filter_pkt->completion;
|
2010-12-10 21:03:58 +01:00
|
|
|
pkt->completion.send.send_completion_ctx =
|
2012-02-05 13:13:08 +01:00
|
|
|
filter_pkt->completion_ctx;
|
2009-07-14 00:34:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-12-10 21:03:57 +01:00
|
|
|
static void rndis_filter_send_completion(void *ctx)
|
2009-07-14 00:34:54 +02:00
|
|
|
{
|
2012-02-05 13:13:08 +01:00
|
|
|
struct rndis_filter_packet *filter_pkt = ctx;
|
2009-07-14 00:34:54 +02:00
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* Pass it back to the original handler */
|
2012-02-05 13:13:08 +01:00
|
|
|
filter_pkt->completion(filter_pkt->completion_ctx);
|
2009-07-14 00:34:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-10 21:03:57 +01:00
|
|
|
static void rndis_filter_send_request_completion(void *ctx)
|
2009-07-14 00:34:54 +02:00
|
|
|
{
|
2009-07-27 22:47:24 +02:00
|
|
|
/* Noop */
|
2009-07-14 00:34:54 +02:00
|
|
|
}
|