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:
|
|
|
|
* Haiyang Zhang <haiyangz@microsoft.com>
|
|
|
|
* Hank Janssen <hjanssen@microsoft.com>
|
|
|
|
*/
|
2009-07-14 22:08:20 +00:00
|
|
|
#include <linux/kernel.h>
|
2011-02-11 17:59:43 +00:00
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/wait.h>
|
2009-07-29 21:00:15 +00: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 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2009-09-02 16:17:52 +00:00
|
|
|
#include <linux/io.h>
|
2010-05-04 16:58:54 +00:00
|
|
|
#include <linux/if_ether.h>
|
2011-03-29 20:58:48 +00:00
|
|
|
#include <linux/netdevice.h>
|
2011-05-13 02:34:15 +00:00
|
|
|
|
2011-05-13 02:34:37 +00:00
|
|
|
#include "hyperv_net.h"
|
2009-07-13 22:34:54 +00:00
|
|
|
|
|
|
|
|
2009-08-28 23:26:27 +00:00
|
|
|
struct rndis_request {
|
2010-12-10 20:03:56 +00:00
|
|
|
struct list_head list_ent;
|
2011-05-10 14:55:42 +00:00
|
|
|
struct completion wait_event;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2009-09-02 16:17:52 +00:00
|
|
|
/*
|
|
|
|
* FIXME: We assumed a fixed size response here. If we do ever need to
|
|
|
|
* handle a bigger response, we can either define a max response
|
|
|
|
* message or add a response buffer variable above this field
|
|
|
|
*/
|
2010-12-10 20:03:56 +00:00
|
|
|
struct rndis_message response_msg;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* Simplify allocation by having a netvsc packet inline */
|
2010-12-10 20:03:56 +00:00
|
|
|
struct hv_netvsc_packet pkt;
|
|
|
|
struct hv_page_buffer buf;
|
2009-07-27 20:47:24 +00:00
|
|
|
/* FIXME: We assumed a fixed size request here. */
|
2010-12-10 20:03:56 +00:00
|
|
|
struct rndis_message request_msg;
|
2009-08-28 23:26:27 +00:00
|
|
|
};
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2010-12-10 20:03:57 +00:00
|
|
|
static void rndis_filter_send_completion(void *ctx);
|
2009-09-02 16:17:52 +00:00
|
|
|
|
2010-12-10 20:03:57 +00:00
|
|
|
static void rndis_filter_send_request_completion(void *ctx);
|
2009-07-27 20:47:24 +00:00
|
|
|
|
|
|
|
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2010-12-10 20:03:57 +00:00
|
|
|
static struct rndis_device *get_rndis_device(void)
|
2009-07-13 22:34:54 +00:00
|
|
|
{
|
2009-08-28 23:26:27 +00:00
|
|
|
struct rndis_device *device;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2009-08-28 23:26:27 +00:00
|
|
|
device = kzalloc(sizeof(struct rndis_device), GFP_KERNEL);
|
2009-07-13 22:34:54 +00:00
|
|
|
if (!device)
|
|
|
|
return NULL;
|
|
|
|
|
2009-07-15 21:55:29 +00:00
|
|
|
spin_lock_init(&device->request_lock);
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2010-12-10 20:03:56 +00:00
|
|
|
INIT_LIST_HEAD(&device->req_list);
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2010-12-10 20:03:56 +00:00
|
|
|
device->state = RNDIS_DEV_UNINITIALIZED;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
|
|
|
return device;
|
|
|
|
}
|
|
|
|
|
2010-12-10 20:03:57 +00:00
|
|
|
static struct rndis_request *get_rndis_request(struct rndis_device *dev,
|
2010-12-10 20:03:56 +00:00
|
|
|
u32 msg_type,
|
|
|
|
u32 msg_len)
|
2009-07-13 22:34:54 +00:00
|
|
|
{
|
2009-08-28 23:26:27 +00:00
|
|
|
struct rndis_request *request;
|
2010-12-10 20:03:56 +00:00
|
|
|
struct rndis_message *rndis_msg;
|
2009-08-19 23:26:24 +00:00
|
|
|
struct rndis_set_request *set;
|
2009-07-15 21:55:29 +00:00
|
|
|
unsigned long flags;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2009-08-28 23:26:27 +00:00
|
|
|
request = kzalloc(sizeof(struct rndis_request), GFP_KERNEL);
|
2009-07-13 22:34:54 +00:00
|
|
|
if (!request)
|
|
|
|
return NULL;
|
|
|
|
|
2011-05-10 14:55:42 +00:00
|
|
|
init_completion(&request->wait_event);
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2010-12-10 20:03:56 +00:00
|
|
|
rndis_msg = &request->request_msg;
|
2010-12-10 20:04:00 +00:00
|
|
|
rndis_msg->ndis_msg_type = msg_type;
|
|
|
|
rndis_msg->msg_len = msg_len;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2009-09-02 16:17:52 +00: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 20:04:00 +00:00
|
|
|
set = &rndis_msg->msg.set_req;
|
|
|
|
set->req_id = atomic_inc_return(&dev->new_req_id);
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* Add to the request list */
|
2010-12-10 20:03:56 +00: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-13 22:34:54 +00:00
|
|
|
|
|
|
|
return request;
|
|
|
|
}
|
|
|
|
|
2010-12-10 20:03:57 +00:00
|
|
|
static void put_rndis_request(struct rndis_device *dev,
|
2010-12-10 20:03:56 +00:00
|
|
|
struct rndis_request *req)
|
2009-07-13 22:34:54 +00:00
|
|
|
{
|
2009-07-15 21:55:29 +00:00
|
|
|
unsigned long flags;
|
|
|
|
|
2010-12-10 20:03:56 +00:00
|
|
|
spin_lock_irqsave(&dev->request_lock, flags);
|
|
|
|
list_del(&req->list_ent);
|
|
|
|
spin_unlock_irqrestore(&dev->request_lock, flags);
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2010-12-10 20:03:56 +00:00
|
|
|
kfree(req);
|
2009-07-13 22:34:54 +00:00
|
|
|
}
|
|
|
|
|
2011-05-27 13:21:54 +00:00
|
|
|
static void dump_rndis_message(struct hv_device *hv_dev,
|
|
|
|
struct rndis_message *rndis_msg)
|
2009-07-13 22:34:54 +00:00
|
|
|
{
|
2011-09-13 17:59:49 +00:00
|
|
|
struct net_device *netdev;
|
|
|
|
struct netvsc_device *net_device;
|
|
|
|
|
|
|
|
net_device = hv_get_drvdata(hv_dev);
|
|
|
|
netdev = net_device->ndev;
|
2011-05-27 13:21:54 +00:00
|
|
|
|
2010-12-10 20:04:00 +00:00
|
|
|
switch (rndis_msg->ndis_msg_type) {
|
2009-07-13 22:34:54 +00:00
|
|
|
case REMOTE_NDIS_PACKET_MSG:
|
2011-05-27 13:21:54 +00:00
|
|
|
netdev_dbg(netdev, "REMOTE_NDIS_PACKET_MSG (len %u, "
|
2009-09-02 16:17:52 +00:00
|
|
|
"data offset %u data len %u, # oob %u, "
|
|
|
|
"oob offset %u, oob len %u, pkt offset %u, "
|
2011-05-27 13:21:54 +00:00
|
|
|
"pkt len %u\n",
|
2010-12-10 20:04:00 +00: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-13 22:34:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case REMOTE_NDIS_INITIALIZE_CMPLT:
|
2011-05-27 13:21:54 +00:00
|
|
|
netdev_dbg(netdev, "REMOTE_NDIS_INITIALIZE_CMPLT "
|
2009-09-02 16:17:52 +00: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 13:21:54 +00:00
|
|
|
"pkt aligned %u)\n",
|
2010-12-10 20:04:00 +00: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-13 22:34:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case REMOTE_NDIS_QUERY_CMPLT:
|
2011-05-27 13:21:54 +00:00
|
|
|
netdev_dbg(netdev, "REMOTE_NDIS_QUERY_CMPLT "
|
2009-09-02 16:17:52 +00:00
|
|
|
"(len %u, id 0x%x, status 0x%x, buf len %u, "
|
2011-05-27 13:21:54 +00:00
|
|
|
"buf offset %u)\n",
|
2010-12-10 20:04:00 +00: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-13 22:34:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case REMOTE_NDIS_SET_CMPLT:
|
2011-05-27 13:21:54 +00:00
|
|
|
netdev_dbg(netdev,
|
|
|
|
"REMOTE_NDIS_SET_CMPLT (len %u, id 0x%x, status 0x%x)\n",
|
2010-12-10 20:04:00 +00:00
|
|
|
rndis_msg->msg_len,
|
|
|
|
rndis_msg->msg.set_complete.req_id,
|
|
|
|
rndis_msg->msg.set_complete.status);
|
2009-07-13 22:34:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case REMOTE_NDIS_INDICATE_STATUS_MSG:
|
2011-05-27 13:21:54 +00:00
|
|
|
netdev_dbg(netdev, "REMOTE_NDIS_INDICATE_STATUS_MSG "
|
|
|
|
"(len %u, status 0x%x, buf len %u, buf offset %u)\n",
|
2010-12-10 20:04:00 +00: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-13 22:34:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2011-05-27 13:21:54 +00:00
|
|
|
netdev_dbg(netdev, "0x%x (len %u)\n",
|
2010-12-10 20:04:00 +00:00
|
|
|
rndis_msg->ndis_msg_type,
|
|
|
|
rndis_msg->msg_len);
|
2009-07-13 22:34:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-10 20:03:57 +00:00
|
|
|
static int rndis_filter_send_request(struct rndis_device *dev,
|
2010-12-10 20:03:56 +00:00
|
|
|
struct rndis_request *req)
|
2009-07-13 22:34:54 +00:00
|
|
|
{
|
2009-09-02 16:17:52 +00:00
|
|
|
int ret;
|
2009-07-29 12:10:10 +00:00
|
|
|
struct hv_netvsc_packet *packet;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* Setup the packet to send it */
|
2010-12-10 20:03:56 +00:00
|
|
|
packet = &req->pkt;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2010-12-10 20:03:58 +00:00
|
|
|
packet->is_data_pkt = false;
|
2010-12-10 20:04:00 +00:00
|
|
|
packet->total_data_buflen = req->request_msg.msg_len;
|
2010-12-10 20:03:58 +00:00
|
|
|
packet->page_buf_cnt = 1;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2011-01-26 20:12:11 +00:00
|
|
|
packet->page_buf[0].pfn = virt_to_phys(&req->request_msg) >>
|
2009-09-02 16:17:52 +00:00
|
|
|
PAGE_SHIFT;
|
2011-01-26 20:12:11 +00:00
|
|
|
packet->page_buf[0].len = req->request_msg.msg_len;
|
|
|
|
packet->page_buf[0].offset =
|
2010-12-10 20:03:56 +00:00
|
|
|
(unsigned long)&req->request_msg & (PAGE_SIZE - 1);
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2010-12-10 20:03:58 +00:00
|
|
|
packet->completion.send.send_completion_ctx = req;/* packet; */
|
|
|
|
packet->completion.send.send_completion =
|
2010-12-10 20:03:57 +00:00
|
|
|
rndis_filter_send_request_completion;
|
2010-12-10 20:03:58 +00:00
|
|
|
packet->completion.send.send_completion_tid = (unsigned long)dev;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2011-05-13 02:34:55 +00:00
|
|
|
ret = netvsc_send(dev->net_dev->dev, packet);
|
2009-07-13 22:34:54 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-12-10 20:03:57 +00:00
|
|
|
static void rndis_filter_receive_response(struct rndis_device *dev,
|
2010-12-10 20:03:56 +00:00
|
|
|
struct rndis_message *resp)
|
2009-07-13 22:34:54 +00:00
|
|
|
{
|
2009-08-28 23:26:27 +00:00
|
|
|
struct rndis_request *request = NULL;
|
2009-07-15 19:46:44 +00:00
|
|
|
bool found = false;
|
2009-07-15 21:55:29 +00:00
|
|
|
unsigned long flags;
|
2011-09-13 17:59:49 +00:00
|
|
|
struct net_device *ndev;
|
|
|
|
|
|
|
|
ndev = dev->net_dev->ndev;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2010-12-10 20:03:56 +00:00
|
|
|
spin_lock_irqsave(&dev->request_lock, flags);
|
|
|
|
list_for_each_entry(request, &dev->req_list, list_ent) {
|
2009-09-02 16:17:52 +00:00
|
|
|
/*
|
|
|
|
* All request/response message contains RequestId as the 1st
|
|
|
|
* field
|
|
|
|
*/
|
2010-12-10 20:04:00 +00:00
|
|
|
if (request->request_msg.msg.init_req.req_id
|
|
|
|
== resp->msg.init_complete.req_id) {
|
2009-07-15 19:46:44 +00:00
|
|
|
found = true;
|
2009-07-13 22:34:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-12-10 20:03:56 +00:00
|
|
|
spin_unlock_irqrestore(&dev->request_lock, flags);
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2009-09-02 16:17:52 +00:00
|
|
|
if (found) {
|
2010-12-10 20:04:00 +00:00
|
|
|
if (resp->msg_len <= sizeof(struct rndis_message)) {
|
2010-12-10 20:03:56 +00:00
|
|
|
memcpy(&request->response_msg, resp,
|
2010-12-10 20:04:00 +00:00
|
|
|
resp->msg_len);
|
2009-09-02 16:17:52 +00:00
|
|
|
} else {
|
2011-09-01 19:19:41 +00:00
|
|
|
netdev_err(ndev,
|
2011-03-29 20:58:48 +00:00
|
|
|
"rndis response buffer overflow "
|
|
|
|
"detected (size %u max %zu)\n",
|
|
|
|
resp->msg_len,
|
|
|
|
sizeof(struct rndis_filter_packet));
|
2009-09-02 16:17:52 +00:00
|
|
|
|
2010-12-10 20:04:00 +00:00
|
|
|
if (resp->ndis_msg_type ==
|
2009-09-02 16:17:52 +00:00
|
|
|
REMOTE_NDIS_RESET_CMPLT) {
|
|
|
|
/* does not have a request id field */
|
2010-12-10 20:04:00 +00:00
|
|
|
request->response_msg.msg.reset_complete.
|
|
|
|
status = STATUS_BUFFER_OVERFLOW;
|
2009-09-02 16:17:52 +00:00
|
|
|
} else {
|
2010-12-10 20:04:00 +00:00
|
|
|
request->response_msg.msg.
|
|
|
|
init_complete.status =
|
2010-12-10 20:03:56 +00:00
|
|
|
STATUS_BUFFER_OVERFLOW;
|
2009-07-13 22:34:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-10 14:55:42 +00:00
|
|
|
complete(&request->wait_event);
|
2009-09-02 16:17:52 +00:00
|
|
|
} else {
|
2011-09-01 19:19:41 +00:00
|
|
|
netdev_err(ndev,
|
2011-03-29 20:58:48 +00: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-13 22:34:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-10 20:03:57 +00:00
|
|
|
static void rndis_filter_receive_indicate_status(struct rndis_device *dev,
|
2010-12-10 20:03:56 +00:00
|
|
|
struct rndis_message *resp)
|
2009-07-13 22:34:54 +00:00
|
|
|
{
|
2009-09-02 16:17:52 +00:00
|
|
|
struct rndis_indicate_status *indicate =
|
2010-12-10 20:04:00 +00:00
|
|
|
&resp->msg.indicate_status;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2010-12-10 20:04:00 +00:00
|
|
|
if (indicate->status == RNDIS_STATUS_MEDIA_CONNECT) {
|
2011-05-13 02:34:56 +00:00
|
|
|
netvsc_linkstatus_callback(
|
2010-12-10 20:03:59 +00:00
|
|
|
dev->net_dev->dev, 1);
|
2010-12-10 20:04:00 +00:00
|
|
|
} else if (indicate->status == RNDIS_STATUS_MEDIA_DISCONNECT) {
|
2011-05-13 02:34:56 +00:00
|
|
|
netvsc_linkstatus_callback(
|
2010-12-10 20:03:59 +00:00
|
|
|
dev->net_dev->dev, 0);
|
2009-09-02 16:17:52 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* TODO:
|
|
|
|
*/
|
2009-07-13 22:34:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-10 20:03:57 +00:00
|
|
|
static void rndis_filter_receive_data(struct rndis_device *dev,
|
2010-12-10 20:03:56 +00:00
|
|
|
struct rndis_message *msg,
|
|
|
|
struct hv_netvsc_packet *pkt)
|
2009-07-13 22:34:54 +00:00
|
|
|
{
|
2010-12-10 20:03:56 +00:00
|
|
|
struct rndis_packet *rndis_pkt;
|
|
|
|
u32 data_offset;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2010-12-10 20:04:00 +00:00
|
|
|
rndis_pkt = &msg->msg.pkt;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2009-09-02 16:17:52 +00:00
|
|
|
/*
|
|
|
|
* FIXME: Handle multiple rndis pkt msgs that maybe enclosed in this
|
|
|
|
* netvsc packet (ie TotalDataBufferLength != MessageLength)
|
|
|
|
*/
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* Remove the rndis header and pass it back up the stack */
|
2010-12-10 20:04:00 +00:00
|
|
|
data_offset = RNDIS_HEADER_SIZE + rndis_pkt->data_offset;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2010-12-10 20:03:58 +00:00
|
|
|
pkt->total_data_buflen -= data_offset;
|
2012-02-01 20:17:23 +00: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 21:45:15 +00:00
|
|
|
pkt->data = (void *)((unsigned long)pkt->data + data_offset);
|
2011-09-01 19:19:47 +00:00
|
|
|
|
2010-12-10 20:03:58 +00:00
|
|
|
pkt->is_data_pkt = true;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2011-05-13 02:34:57 +00:00
|
|
|
netvsc_recv_callback(dev->net_dev->dev, pkt);
|
2009-07-13 22:34:54 +00:00
|
|
|
}
|
|
|
|
|
2011-05-13 02:34:52 +00:00
|
|
|
int rndis_filter_receive(struct hv_device *dev,
|
2010-12-10 20:03:56 +00:00
|
|
|
struct hv_netvsc_packet *pkt)
|
2009-07-13 22:34:54 +00:00
|
|
|
{
|
2011-09-13 17:59:49 +00:00
|
|
|
struct netvsc_device *net_dev = hv_get_drvdata(dev);
|
2010-12-10 20:03:56 +00:00
|
|
|
struct rndis_device *rndis_dev;
|
|
|
|
struct rndis_message rndis_msg;
|
|
|
|
struct rndis_message *rndis_hdr;
|
2011-09-13 17:59:49 +00:00
|
|
|
struct net_device *ndev;
|
|
|
|
|
2010-12-10 20:03:56 +00:00
|
|
|
if (!net_dev)
|
2010-05-05 19:27:47 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
2011-10-06 17:10:56 +00:00
|
|
|
ndev = net_dev->ndev;
|
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* Make sure the rndis device state is initialized */
|
2010-12-10 20:03:59 +00:00
|
|
|
if (!net_dev->extension) {
|
2011-09-01 19:19:41 +00:00
|
|
|
netdev_err(ndev, "got rndis message but no rndis device - "
|
2011-03-29 20:58:48 +00:00
|
|
|
"dropping this message!\n");
|
2011-08-25 16:49:17 +00:00
|
|
|
return -ENODEV;
|
2009-07-13 22:34:54 +00:00
|
|
|
}
|
|
|
|
|
2010-12-10 20:03:59 +00:00
|
|
|
rndis_dev = (struct rndis_device *)net_dev->extension;
|
2010-12-10 20:03:56 +00:00
|
|
|
if (rndis_dev->state == RNDIS_DEV_UNINITIALIZED) {
|
2011-09-01 19:19:41 +00:00
|
|
|
netdev_err(ndev, "got rndis message but rndis device "
|
2011-03-29 20:58:48 +00:00
|
|
|
"uninitialized...dropping this message!\n");
|
2011-08-25 16:49:17 +00:00
|
|
|
return -ENODEV;
|
2009-07-13 22:34:54 +00:00
|
|
|
}
|
|
|
|
|
2011-12-15 21:45:15 +00:00
|
|
|
rndis_hdr = pkt->data;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* Make sure we got a valid rndis message */
|
2010-12-10 20:04:00 +00:00
|
|
|
if ((rndis_hdr->ndis_msg_type != REMOTE_NDIS_PACKET_MSG) &&
|
|
|
|
(rndis_hdr->msg_len > sizeof(struct rndis_message))) {
|
2011-09-01 19:19:41 +00:00
|
|
|
netdev_err(ndev, "incoming rndis message buffer overflow "
|
2011-03-29 20:58:48 +00:00
|
|
|
"detected (got %u, max %zu)..marking it an error!\n",
|
2010-12-10 20:04:00 +00:00
|
|
|
rndis_hdr->msg_len,
|
2009-09-02 16:17:52 +00:00
|
|
|
sizeof(struct rndis_message));
|
2009-07-13 22:34:54 +00:00
|
|
|
}
|
|
|
|
|
2010-12-10 20:03:56 +00:00
|
|
|
memcpy(&rndis_msg, rndis_hdr,
|
2010-12-10 20:04:00 +00:00
|
|
|
(rndis_hdr->msg_len > sizeof(struct rndis_message)) ?
|
2009-09-02 16:17:52 +00:00
|
|
|
sizeof(struct rndis_message) :
|
2010-12-10 20:04:00 +00:00
|
|
|
rndis_hdr->msg_len);
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2011-05-27 13:21:54 +00:00
|
|
|
dump_rndis_message(dev, &rndis_msg);
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2010-12-10 20:04:00 +00:00
|
|
|
switch (rndis_msg.ndis_msg_type) {
|
2009-07-13 22:34:54 +00:00
|
|
|
case REMOTE_NDIS_PACKET_MSG:
|
2009-09-02 16:17:52 +00:00
|
|
|
/* data msg */
|
2010-12-10 20:03:57 +00:00
|
|
|
rndis_filter_receive_data(rndis_dev, &rndis_msg, pkt);
|
2009-07-13 22:34:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case REMOTE_NDIS_INITIALIZE_CMPLT:
|
|
|
|
case REMOTE_NDIS_QUERY_CMPLT:
|
|
|
|
case REMOTE_NDIS_SET_CMPLT:
|
2009-09-02 16:17:52 +00:00
|
|
|
/* completion msgs */
|
2010-12-10 20:03:57 +00:00
|
|
|
rndis_filter_receive_response(rndis_dev, &rndis_msg);
|
2009-07-13 22:34:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case REMOTE_NDIS_INDICATE_STATUS_MSG:
|
2009-09-02 16:17:52 +00:00
|
|
|
/* notification msgs */
|
2010-12-10 20:03:57 +00:00
|
|
|
rndis_filter_receive_indicate_status(rndis_dev, &rndis_msg);
|
2009-07-13 22:34:54 +00:00
|
|
|
break;
|
|
|
|
default:
|
2011-09-01 19:19:41 +00:00
|
|
|
netdev_err(ndev,
|
2011-03-29 20:58:48 +00:00
|
|
|
"unhandled rndis message (type %u len %u)\n",
|
2010-12-10 20:04:00 +00:00
|
|
|
rndis_msg.ndis_msg_type,
|
|
|
|
rndis_msg.msg_len);
|
2009-07-13 22:34:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-12-10 20:03:57 +00:00
|
|
|
static int rndis_filter_query_device(struct rndis_device *dev, u32 oid,
|
2010-12-10 20:03:56 +00:00
|
|
|
void *result, u32 *result_size)
|
2009-07-13 22:34:54 +00:00
|
|
|
{
|
2009-08-28 23:26:27 +00:00
|
|
|
struct rndis_request *request;
|
2010-12-10 20:03:56 +00:00
|
|
|
u32 inresult_size = *result_size;
|
2009-08-19 23:26:24 +00:00
|
|
|
struct rndis_query_request *query;
|
2010-12-10 20:03:56 +00:00
|
|
|
struct rndis_query_complete *query_complete;
|
2009-09-02 16:17:52 +00:00
|
|
|
int ret = 0;
|
2011-05-10 14:55:42 +00:00
|
|
|
int t;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2010-12-10 20:03:56 +00:00
|
|
|
if (!result)
|
2010-05-05 19:27:47 +00:00
|
|
|
return -EINVAL;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2010-12-10 20:03:56 +00:00
|
|
|
*result_size = 0;
|
2010-12-10 20:03:57 +00:00
|
|
|
request = get_rndis_request(dev, REMOTE_NDIS_QUERY_MSG,
|
2009-09-02 16:17:52 +00:00
|
|
|
RNDIS_MESSAGE_SIZE(struct rndis_query_request));
|
|
|
|
if (!request) {
|
2011-08-25 16:49:18 +00:00
|
|
|
ret = -ENOMEM;
|
2011-08-25 16:49:24 +00:00
|
|
|
goto cleanup;
|
2009-07-13 22:34:54 +00:00
|
|
|
}
|
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* Setup the rndis query */
|
2010-12-10 20:04:00 +00: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-13 22:34:54 +00:00
|
|
|
|
2010-12-10 20:03:57 +00:00
|
|
|
ret = rndis_filter_send_request(dev, request);
|
2009-07-13 22:34:54 +00:00
|
|
|
if (ret != 0)
|
2011-08-25 16:49:24 +00:00
|
|
|
goto cleanup;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2011-06-16 20:16:35 +00:00
|
|
|
t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
|
2011-05-10 14:55:42 +00:00
|
|
|
if (t == 0) {
|
2011-02-11 17:59:43 +00:00
|
|
|
ret = -ETIMEDOUT;
|
2011-08-25 16:49:24 +00:00
|
|
|
goto cleanup;
|
2011-02-11 17:59:43 +00:00
|
|
|
}
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* Copy the response back */
|
2010-12-10 20:04:00 +00:00
|
|
|
query_complete = &request->response_msg.msg.query_complete;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2010-12-10 20:04:00 +00:00
|
|
|
if (query_complete->info_buflen > inresult_size) {
|
2009-07-13 22:34:54 +00:00
|
|
|
ret = -1;
|
2011-08-25 16:49:24 +00:00
|
|
|
goto cleanup;
|
2009-07-13 22:34:54 +00:00
|
|
|
}
|
|
|
|
|
2010-12-10 20:03:56 +00:00
|
|
|
memcpy(result,
|
|
|
|
(void *)((unsigned long)query_complete +
|
2010-12-10 20:04:00 +00:00
|
|
|
query_complete->info_buf_offset),
|
|
|
|
query_complete->info_buflen);
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2010-12-10 20:04:00 +00:00
|
|
|
*result_size = query_complete->info_buflen;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2011-08-25 16:49:24 +00:00
|
|
|
cleanup:
|
2009-07-13 22:34:54 +00:00
|
|
|
if (request)
|
2010-12-10 20:03:57 +00:00
|
|
|
put_rndis_request(dev, request);
|
2009-07-13 22:34:54 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-12-10 20:03:57 +00:00
|
|
|
static int rndis_filter_query_device_mac(struct rndis_device *dev)
|
2009-07-13 22:34:54 +00:00
|
|
|
{
|
2010-05-04 16:58:54 +00:00
|
|
|
u32 size = ETH_ALEN;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2010-12-10 20:03:57 +00:00
|
|
|
return rndis_filter_query_device(dev,
|
2009-09-02 16:17:52 +00:00
|
|
|
RNDIS_OID_802_3_PERMANENT_ADDRESS,
|
2010-12-10 20:03:56 +00:00
|
|
|
dev->hw_mac_adr, &size);
|
2009-07-13 22:34:54 +00:00
|
|
|
}
|
|
|
|
|
2010-12-10 20:03:57 +00:00
|
|
|
static int rndis_filter_query_device_link_status(struct rndis_device *dev)
|
2009-07-13 22:34:54 +00:00
|
|
|
{
|
2009-09-02 16:17:52 +00:00
|
|
|
u32 size = sizeof(u32);
|
2011-09-13 22:21:27 +00:00
|
|
|
u32 link_status;
|
|
|
|
int ret;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2011-09-13 22:21:27 +00:00
|
|
|
ret = rndis_filter_query_device(dev,
|
2009-09-02 16:17:52 +00:00
|
|
|
RNDIS_OID_GEN_MEDIA_CONNECT_STATUS,
|
2011-09-13 22:21:27 +00:00
|
|
|
&link_status, &size);
|
|
|
|
dev->link_state = (link_status != 0) ? true : false;
|
|
|
|
|
|
|
|
return ret;
|
2009-07-13 22:34:54 +00:00
|
|
|
}
|
|
|
|
|
2011-11-30 15:19:08 +00:00
|
|
|
int rndis_filter_set_packet_filter(struct rndis_device *dev, u32 new_filter)
|
2009-07-13 22:34:54 +00:00
|
|
|
{
|
2009-08-28 23:26:27 +00:00
|
|
|
struct rndis_request *request;
|
2009-08-19 23:26:24 +00:00
|
|
|
struct rndis_set_request *set;
|
2010-12-10 20:03:56 +00:00
|
|
|
struct rndis_set_complete *set_complete;
|
2009-07-14 22:09:36 +00:00
|
|
|
u32 status;
|
2011-05-10 14:55:42 +00:00
|
|
|
int ret, t;
|
2011-09-13 17:59:49 +00:00
|
|
|
struct net_device *ndev;
|
|
|
|
|
|
|
|
ndev = dev->net_dev->ndev;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2010-12-10 20:03:57 +00:00
|
|
|
request = get_rndis_request(dev, REMOTE_NDIS_SET_MSG,
|
2009-09-02 16:17:52 +00:00
|
|
|
RNDIS_MESSAGE_SIZE(struct rndis_set_request) +
|
|
|
|
sizeof(u32));
|
|
|
|
if (!request) {
|
2011-08-25 16:49:19 +00:00
|
|
|
ret = -ENOMEM;
|
2011-08-25 16:49:24 +00:00
|
|
|
goto cleanup;
|
2009-07-13 22:34:54 +00:00
|
|
|
}
|
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* Setup the rndis set */
|
2010-12-10 20:04:00 +00: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-13 22:34:54 +00:00
|
|
|
|
2009-09-02 16:17:52 +00:00
|
|
|
memcpy((void *)(unsigned long)set + sizeof(struct rndis_set_request),
|
2010-12-10 20:03:56 +00:00
|
|
|
&new_filter, sizeof(u32));
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2010-12-10 20:03:57 +00:00
|
|
|
ret = rndis_filter_send_request(dev, request);
|
2009-07-13 22:34:54 +00:00
|
|
|
if (ret != 0)
|
2011-08-25 16:49:24 +00:00
|
|
|
goto cleanup;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2011-06-16 20:16:35 +00:00
|
|
|
t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
|
2011-05-10 14:55:42 +00:00
|
|
|
|
|
|
|
if (t == 0) {
|
2011-09-01 19:19:41 +00:00
|
|
|
netdev_err(ndev,
|
2011-03-29 20:58:48 +00:00
|
|
|
"timeout before we got a set response...\n");
|
2009-09-02 16:17:52 +00:00
|
|
|
/*
|
2011-03-31 01:57:33 +00:00
|
|
|
* We can't deallocate the request since we may still receive a
|
2009-09-02 16:17:52 +00:00
|
|
|
* send completion for it.
|
|
|
|
*/
|
2011-08-25 16:49:25 +00:00
|
|
|
goto exit;
|
2009-09-02 16:17:52 +00:00
|
|
|
} else {
|
2010-12-10 20:04:00 +00:00
|
|
|
set_complete = &request->response_msg.msg.set_complete;
|
|
|
|
status = set_complete->status;
|
2009-07-13 22:34:54 +00:00
|
|
|
}
|
|
|
|
|
2011-08-25 16:49:24 +00:00
|
|
|
cleanup:
|
2009-07-13 22:34:54 +00:00
|
|
|
if (request)
|
2010-12-10 20:03:57 +00:00
|
|
|
put_rndis_request(dev, request);
|
2011-08-25 16:49:25 +00:00
|
|
|
exit:
|
2009-07-13 22:34:54 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-10 20:03:57 +00:00
|
|
|
static int rndis_filter_init_device(struct rndis_device *dev)
|
2009-07-13 22:34:54 +00:00
|
|
|
{
|
2009-08-28 23:26:27 +00:00
|
|
|
struct rndis_request *request;
|
2009-08-19 23:26:24 +00:00
|
|
|
struct rndis_initialize_request *init;
|
2010-12-10 20:03:56 +00:00
|
|
|
struct rndis_initialize_complete *init_complete;
|
2009-07-14 22:09:36 +00:00
|
|
|
u32 status;
|
2011-05-10 14:55:42 +00:00
|
|
|
int ret, t;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2010-12-10 20:03:57 +00:00
|
|
|
request = get_rndis_request(dev, REMOTE_NDIS_INITIALIZE_MSG,
|
2009-09-02 16:17:52 +00:00
|
|
|
RNDIS_MESSAGE_SIZE(struct rndis_initialize_request));
|
|
|
|
if (!request) {
|
2011-08-25 16:49:20 +00:00
|
|
|
ret = -ENOMEM;
|
2011-08-25 16:49:24 +00:00
|
|
|
goto cleanup;
|
2009-07-13 22:34:54 +00:00
|
|
|
}
|
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* Setup the rndis set */
|
2010-12-10 20:04:00 +00:00
|
|
|
init = &request->request_msg.msg.init_req;
|
|
|
|
init->major_ver = RNDIS_MAJOR_VERSION;
|
|
|
|
init->minor_ver = RNDIS_MINOR_VERSION;
|
2009-09-02 16:17:52 +00:00
|
|
|
/* FIXME: Use 1536 - rounded ethernet frame size */
|
2010-12-10 20:04:00 +00:00
|
|
|
init->max_xfer_size = 2048;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2010-12-10 20:03:56 +00:00
|
|
|
dev->state = RNDIS_DEV_INITIALIZING;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2010-12-10 20:03:57 +00:00
|
|
|
ret = rndis_filter_send_request(dev, request);
|
2009-09-02 16:17:52 +00:00
|
|
|
if (ret != 0) {
|
2010-12-10 20:03:56 +00:00
|
|
|
dev->state = RNDIS_DEV_UNINITIALIZED;
|
2011-08-25 16:49:24 +00:00
|
|
|
goto cleanup;
|
2009-07-13 22:34:54 +00:00
|
|
|
}
|
|
|
|
|
2011-02-11 17:59:43 +00:00
|
|
|
|
2011-06-16 20:16:35 +00:00
|
|
|
t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
|
2011-05-10 14:55:42 +00:00
|
|
|
|
|
|
|
if (t == 0) {
|
2011-02-11 17:59:43 +00:00
|
|
|
ret = -ETIMEDOUT;
|
2011-08-25 16:49:24 +00:00
|
|
|
goto cleanup;
|
2011-02-11 17:59:43 +00:00
|
|
|
}
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2010-12-10 20:04:00 +00:00
|
|
|
init_complete = &request->response_msg.msg.init_complete;
|
|
|
|
status = init_complete->status;
|
2009-09-02 16:17:52 +00:00
|
|
|
if (status == RNDIS_STATUS_SUCCESS) {
|
2010-12-10 20:03:56 +00:00
|
|
|
dev->state = RNDIS_DEV_INITIALIZED;
|
2009-07-13 22:34:54 +00:00
|
|
|
ret = 0;
|
2009-09-02 16:17:52 +00:00
|
|
|
} else {
|
2010-12-10 20:03:56 +00:00
|
|
|
dev->state = RNDIS_DEV_UNINITIALIZED;
|
2011-08-25 16:49:20 +00:00
|
|
|
ret = -EINVAL;
|
2009-07-13 22:34:54 +00:00
|
|
|
}
|
|
|
|
|
2011-08-25 16:49:24 +00:00
|
|
|
cleanup:
|
2009-07-13 22:34:54 +00:00
|
|
|
if (request)
|
2010-12-10 20:03:57 +00:00
|
|
|
put_rndis_request(dev, request);
|
2009-07-13 22:34:54 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-12-10 20:03:57 +00:00
|
|
|
static void rndis_filter_halt_device(struct rndis_device *dev)
|
2009-07-13 22:34:54 +00:00
|
|
|
{
|
2009-08-28 23:26:27 +00:00
|
|
|
struct rndis_request *request;
|
2009-08-19 23:26:24 +00:00
|
|
|
struct rndis_halt_request *halt;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* Attempt to do a rndis device halt */
|
2010-12-10 20:03:57 +00:00
|
|
|
request = get_rndis_request(dev, REMOTE_NDIS_HALT_MSG,
|
2009-09-02 16:17:52 +00:00
|
|
|
RNDIS_MESSAGE_SIZE(struct rndis_halt_request));
|
2009-07-13 22:34:54 +00:00
|
|
|
if (!request)
|
2011-08-25 16:49:24 +00:00
|
|
|
goto cleanup;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* Setup the rndis set */
|
2010-12-10 20:04:00 +00:00
|
|
|
halt = &request->request_msg.msg.halt_req;
|
|
|
|
halt->req_id = atomic_inc_return(&dev->new_req_id);
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* Ignore return since this msg is optional. */
|
2010-12-10 20:03:57 +00:00
|
|
|
rndis_filter_send_request(dev, request);
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2010-12-10 20:03:56 +00:00
|
|
|
dev->state = RNDIS_DEV_UNINITIALIZED;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2011-08-25 16:49:24 +00:00
|
|
|
cleanup:
|
2009-07-13 22:34:54 +00:00
|
|
|
if (request)
|
2010-12-10 20:03:57 +00:00
|
|
|
put_rndis_request(dev, request);
|
2009-07-13 22:34:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-12-10 20:03:57 +00:00
|
|
|
static int rndis_filter_open_device(struct rndis_device *dev)
|
2009-07-13 22:34:54 +00:00
|
|
|
{
|
2009-09-02 16:17:52 +00:00
|
|
|
int ret;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2010-12-10 20:03:56 +00:00
|
|
|
if (dev->state != RNDIS_DEV_INITIALIZED)
|
2009-07-13 22:34:54 +00:00
|
|
|
return 0;
|
|
|
|
|
2010-12-10 20:03:57 +00:00
|
|
|
ret = rndis_filter_set_packet_filter(dev,
|
2009-09-02 16:17:52 +00:00
|
|
|
NDIS_PACKET_TYPE_BROADCAST |
|
2010-04-19 15:32:11 +00:00
|
|
|
NDIS_PACKET_TYPE_ALL_MULTICAST |
|
2009-09-02 16:17:52 +00:00
|
|
|
NDIS_PACKET_TYPE_DIRECTED);
|
2009-07-13 22:34:54 +00:00
|
|
|
if (ret == 0)
|
2010-12-10 20:03:56 +00:00
|
|
|
dev->state = RNDIS_DEV_DATAINITIALIZED;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-12-10 20:03:57 +00:00
|
|
|
static int rndis_filter_close_device(struct rndis_device *dev)
|
2009-07-13 22:34:54 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2010-12-10 20:03:56 +00:00
|
|
|
if (dev->state != RNDIS_DEV_DATAINITIALIZED)
|
2009-07-13 22:34:54 +00:00
|
|
|
return 0;
|
|
|
|
|
2010-12-10 20:03:57 +00:00
|
|
|
ret = rndis_filter_set_packet_filter(dev, 0);
|
2009-07-13 22:34:54 +00:00
|
|
|
if (ret == 0)
|
2010-12-10 20:03:56 +00:00
|
|
|
dev->state = RNDIS_DEV_INITIALIZED;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-05-23 16:03:49 +00:00
|
|
|
int rndis_filter_device_add(struct hv_device *dev,
|
2010-12-10 20:03:56 +00:00
|
|
|
void *additional_info)
|
2009-07-13 22:34:54 +00:00
|
|
|
{
|
|
|
|
int ret;
|
2011-09-13 17:59:54 +00:00
|
|
|
struct netvsc_device *net_device;
|
2011-09-13 17:59:55 +00:00
|
|
|
struct rndis_device *rndis_device;
|
2011-09-13 17:59:56 +00:00
|
|
|
struct netvsc_device_info *device_info = additional_info;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2011-09-13 17:59:55 +00:00
|
|
|
rndis_device = get_rndis_device();
|
|
|
|
if (!rndis_device)
|
2011-08-25 16:49:21 +00:00
|
|
|
return -ENODEV;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2009-09-02 16:17:52 +00: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 14:55:00 +00:00
|
|
|
ret = netvsc_device_add(dev, additional_info);
|
2009-09-02 16:17:52 +00:00
|
|
|
if (ret != 0) {
|
2011-09-13 17:59:55 +00:00
|
|
|
kfree(rndis_device);
|
2009-07-13 22:34:54 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
|
|
|
|
/* Initialize the rndis device */
|
2011-09-13 17:59:54 +00:00
|
|
|
net_device = hv_get_drvdata(dev);
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2011-09-13 17:59:55 +00:00
|
|
|
net_device->extension = rndis_device;
|
|
|
|
rndis_device->net_dev = net_device;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* Send the rndis initialization message */
|
2011-09-13 17:59:55 +00:00
|
|
|
ret = rndis_filter_init_device(rndis_device);
|
2009-09-02 16:17:52 +00:00
|
|
|
if (ret != 0) {
|
|
|
|
/*
|
|
|
|
* TODO: If rndis init failed, we will need to shut down the
|
|
|
|
* channel
|
|
|
|
*/
|
2009-07-13 22:34:54 +00:00
|
|
|
}
|
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* Get the mac address */
|
2011-09-13 17:59:55 +00:00
|
|
|
ret = rndis_filter_query_device_mac(rndis_device);
|
2009-09-02 16:17:52 +00:00
|
|
|
if (ret != 0) {
|
|
|
|
/*
|
|
|
|
* TODO: shutdown rndis device and the channel
|
|
|
|
*/
|
2009-07-13 22:34:54 +00:00
|
|
|
}
|
|
|
|
|
2011-09-13 17:59:56 +00:00
|
|
|
memcpy(device_info->mac_adr, rndis_device->hw_mac_adr, ETH_ALEN);
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2011-09-13 17:59:55 +00:00
|
|
|
rndis_filter_query_device_link_status(rndis_device);
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2011-09-13 22:21:27 +00:00
|
|
|
device_info->link_state = rndis_device->link_state;
|
2011-03-29 20:58:48 +00:00
|
|
|
|
2011-09-13 22:21:27 +00:00
|
|
|
dev_info(&dev->device, "Device MAC %pM link state %s\n",
|
2011-09-13 17:59:55 +00:00
|
|
|
rndis_device->hw_mac_adr,
|
2011-09-13 22:21:27 +00:00
|
|
|
device_info->link_state ? "down" : "up");
|
2009-07-13 22:34:54 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-05-23 16:03:47 +00:00
|
|
|
void rndis_filter_device_remove(struct hv_device *dev)
|
2009-07-13 22:34:54 +00:00
|
|
|
{
|
2011-09-13 17:59:49 +00:00
|
|
|
struct netvsc_device *net_dev = hv_get_drvdata(dev);
|
2010-12-10 20:03:59 +00:00
|
|
|
struct rndis_device *rndis_dev = net_dev->extension;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* Halt and release the rndis device */
|
2010-12-10 20:03:57 +00:00
|
|
|
rndis_filter_halt_device(rndis_dev);
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2010-12-10 20:03:56 +00:00
|
|
|
kfree(rndis_dev);
|
2010-12-10 20:03:59 +00:00
|
|
|
net_dev->extension = NULL;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2011-05-10 14:55:02 +00:00
|
|
|
netvsc_device_remove(dev);
|
2009-07-13 22:34:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-10 20:03:57 +00:00
|
|
|
int rndis_filter_open(struct hv_device *dev)
|
2009-07-13 22:34:54 +00:00
|
|
|
{
|
2011-09-13 17:59:54 +00:00
|
|
|
struct netvsc_device *net_device = hv_get_drvdata(dev);
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2011-09-13 17:59:54 +00:00
|
|
|
if (!net_device)
|
2010-05-05 19:27:47 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
2011-09-13 17:59:54 +00:00
|
|
|
return rndis_filter_open_device(net_device->extension);
|
2009-07-13 22:34:54 +00:00
|
|
|
}
|
|
|
|
|
2010-12-10 20:03:57 +00:00
|
|
|
int rndis_filter_close(struct hv_device *dev)
|
2009-07-13 22:34:54 +00:00
|
|
|
{
|
2012-02-05 12:13:08 +00:00
|
|
|
struct netvsc_device *nvdev = hv_get_drvdata(dev);
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2012-02-05 12:13:08 +00:00
|
|
|
if (!nvdev)
|
2010-05-05 19:27:47 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
2012-02-05 12:13:08 +00:00
|
|
|
return rndis_filter_close_device(nvdev->extension);
|
2009-07-13 22:34:54 +00:00
|
|
|
}
|
|
|
|
|
2011-05-13 02:34:53 +00:00
|
|
|
int rndis_filter_send(struct hv_device *dev,
|
2010-12-10 20:03:56 +00:00
|
|
|
struct hv_netvsc_packet *pkt)
|
2009-07-13 22:34:54 +00:00
|
|
|
{
|
2009-09-02 16:17:52 +00:00
|
|
|
int ret;
|
2012-02-05 12:13:08 +00:00
|
|
|
struct rndis_filter_packet *filter_pkt;
|
|
|
|
struct rndis_message *rndis_msg;
|
|
|
|
struct rndis_packet *rndis_pkt;
|
|
|
|
u32 rndis_msg_size;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* Add the rndis header */
|
2012-02-05 12:13:08 +00:00
|
|
|
filter_pkt = (struct rndis_filter_packet *)pkt->extension;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2012-02-05 12:13:08 +00:00
|
|
|
rndis_msg = &filter_pkt->msg;
|
|
|
|
rndis_msg_size = RNDIS_MESSAGE_SIZE(struct rndis_packet);
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2012-02-05 12:13:08 +00:00
|
|
|
rndis_msg->ndis_msg_type = REMOTE_NDIS_PACKET_MSG;
|
|
|
|
rndis_msg->msg_len = pkt->total_data_buflen +
|
|
|
|
rndis_msg_size;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2012-02-05 12:13:08 +00:00
|
|
|
rndis_pkt = &rndis_msg->msg.pkt;
|
|
|
|
rndis_pkt->data_offset = sizeof(struct rndis_packet);
|
|
|
|
rndis_pkt->data_len = pkt->total_data_buflen;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2010-12-10 20:03:58 +00:00
|
|
|
pkt->is_data_pkt = true;
|
2012-02-05 12:13:08 +00:00
|
|
|
pkt->page_buf[0].pfn = virt_to_phys(rndis_msg) >> PAGE_SHIFT;
|
2011-01-26 20:12:11 +00:00
|
|
|
pkt->page_buf[0].offset =
|
2012-02-05 12:13:08 +00:00
|
|
|
(unsigned long)rndis_msg & (PAGE_SIZE-1);
|
|
|
|
pkt->page_buf[0].len = rndis_msg_size;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2012-02-02 07:18:00 +00:00
|
|
|
/* Add one page_buf if the rndis msg goes beyond page boundary */
|
2012-02-05 12:13:08 +00:00
|
|
|
if (pkt->page_buf[0].offset + rndis_msg_size > PAGE_SIZE) {
|
2012-02-02 07:18:00 +00: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 12:13:08 +00:00
|
|
|
rndis_msg + pkt->page_buf[0].len)) >> PAGE_SHIFT;
|
2012-02-02 07:18:00 +00:00
|
|
|
pkt->page_buf[1].offset = 0;
|
2012-02-05 12:13:08 +00:00
|
|
|
pkt->page_buf[1].len = rndis_msg_size - pkt->page_buf[0].len;
|
2012-02-02 07:18:00 +00:00
|
|
|
}
|
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* Save the packet send completion and context */
|
2012-02-05 12:13:08 +00:00
|
|
|
filter_pkt->completion = pkt->completion.send.send_completion;
|
|
|
|
filter_pkt->completion_ctx =
|
2010-12-10 20:03:58 +00:00
|
|
|
pkt->completion.send.send_completion_ctx;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* Use ours */
|
2010-12-10 20:03:58 +00:00
|
|
|
pkt->completion.send.send_completion = rndis_filter_send_completion;
|
2012-02-05 12:13:08 +00:00
|
|
|
pkt->completion.send.send_completion_ctx = filter_pkt;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2011-05-13 02:34:55 +00:00
|
|
|
ret = netvsc_send(dev, pkt);
|
2009-09-02 16:17:52 +00:00
|
|
|
if (ret != 0) {
|
|
|
|
/*
|
|
|
|
* Reset the completion to originals to allow retries from
|
|
|
|
* above
|
|
|
|
*/
|
2010-12-10 20:03:58 +00:00
|
|
|
pkt->completion.send.send_completion =
|
2012-02-05 12:13:08 +00:00
|
|
|
filter_pkt->completion;
|
2010-12-10 20:03:58 +00:00
|
|
|
pkt->completion.send.send_completion_ctx =
|
2012-02-05 12:13:08 +00:00
|
|
|
filter_pkt->completion_ctx;
|
2009-07-13 22:34:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-12-10 20:03:57 +00:00
|
|
|
static void rndis_filter_send_completion(void *ctx)
|
2009-07-13 22:34:54 +00:00
|
|
|
{
|
2012-02-05 12:13:08 +00:00
|
|
|
struct rndis_filter_packet *filter_pkt = ctx;
|
2009-07-13 22:34:54 +00:00
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* Pass it back to the original handler */
|
2012-02-05 12:13:08 +00:00
|
|
|
filter_pkt->completion(filter_pkt->completion_ctx);
|
2009-07-13 22:34:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-10 20:03:57 +00:00
|
|
|
static void rndis_filter_send_request_completion(void *ctx)
|
2009-07-13 22:34:54 +00:00
|
|
|
{
|
2009-07-27 20:47:24 +00:00
|
|
|
/* Noop */
|
2009-07-13 22:34:54 +00:00
|
|
|
}
|