2 * Copyright (c) 2009, Microsoft Corporation.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15 * Place - Suite 330, Boston, MA 02111-1307 USA.
18 * Haiyang Zhang <haiyangz@microsoft.com>
19 * Hank Janssen <hjanssen@microsoft.com>
21 #include <linux/kernel.h>
22 #include <linux/sched.h>
23 #include <linux/wait.h>
24 #include <linux/highmem.h>
25 #include <linux/slab.h>
27 #include <linux/if_ether.h>
28 #include <linux/netdevice.h>
31 #include "netvsc_api.h"
32 #include "rndis_filter.h"
35 struct rndis_filter_driver_object
{
36 /* The original driver */
37 struct netvsc_driver inner_drv
;
40 enum rndis_device_state
{
41 RNDIS_DEV_UNINITIALIZED
= 0,
42 RNDIS_DEV_INITIALIZING
,
43 RNDIS_DEV_INITIALIZED
,
44 RNDIS_DEV_DATAINITIALIZED
,
48 struct netvsc_device
*net_dev
;
50 enum rndis_device_state state
;
54 spinlock_t request_lock
;
55 struct list_head req_list
;
57 unsigned char hw_mac_adr
[ETH_ALEN
];
60 struct rndis_request
{
61 struct list_head list_ent
;
63 wait_queue_head_t wait_event
;
66 * FIXME: We assumed a fixed size response here. If we do ever need to
67 * handle a bigger response, we can either define a max response
68 * message or add a response buffer variable above this field
70 struct rndis_message response_msg
;
72 /* Simplify allocation by having a netvsc packet inline */
73 struct hv_netvsc_packet pkt
;
74 struct hv_page_buffer buf
;
75 /* FIXME: We assumed a fixed size request here. */
76 struct rndis_message request_msg
;
80 struct rndis_filter_packet
{
82 void (*completion
)(void *context
);
83 struct rndis_message msg
;
87 static int rndis_filte_device_add(struct hv_device
*dev
,
88 void *additional_info
);
90 static int rndis_filter_device_remove(struct hv_device
*dev
);
92 static void rndis_filter_cleanup(struct hv_driver
*drv
);
94 static int rndis_filter_send(struct hv_device
*dev
,
95 struct hv_netvsc_packet
*pkt
);
97 static void rndis_filter_send_completion(void *ctx
);
99 static void rndis_filter_send_request_completion(void *ctx
);
102 /* The one and only */
103 static struct rndis_filter_driver_object rndis_filter
;
105 static struct rndis_device
*get_rndis_device(void)
107 struct rndis_device
*device
;
109 device
= kzalloc(sizeof(struct rndis_device
), GFP_KERNEL
);
113 spin_lock_init(&device
->request_lock
);
115 INIT_LIST_HEAD(&device
->req_list
);
117 device
->state
= RNDIS_DEV_UNINITIALIZED
;
122 static struct rndis_request
*get_rndis_request(struct rndis_device
*dev
,
126 struct rndis_request
*request
;
127 struct rndis_message
*rndis_msg
;
128 struct rndis_set_request
*set
;
131 request
= kzalloc(sizeof(struct rndis_request
), GFP_KERNEL
);
135 init_waitqueue_head(&request
->wait_event
);
137 rndis_msg
= &request
->request_msg
;
138 rndis_msg
->ndis_msg_type
= msg_type
;
139 rndis_msg
->msg_len
= msg_len
;
142 * Set the request id. This field is always after the rndis header for
143 * request/response packet types so we just used the SetRequest as a
146 set
= &rndis_msg
->msg
.set_req
;
147 set
->req_id
= atomic_inc_return(&dev
->new_req_id
);
149 /* Add to the request list */
150 spin_lock_irqsave(&dev
->request_lock
, flags
);
151 list_add_tail(&request
->list_ent
, &dev
->req_list
);
152 spin_unlock_irqrestore(&dev
->request_lock
, flags
);
157 static void put_rndis_request(struct rndis_device
*dev
,
158 struct rndis_request
*req
)
162 spin_lock_irqsave(&dev
->request_lock
, flags
);
163 list_del(&req
->list_ent
);
164 spin_unlock_irqrestore(&dev
->request_lock
, flags
);
169 static void dump_rndis_message(struct rndis_message
*rndis_msg
)
171 switch (rndis_msg
->ndis_msg_type
) {
172 case REMOTE_NDIS_PACKET_MSG
:
173 DPRINT_DBG(NETVSC
, "REMOTE_NDIS_PACKET_MSG (len %u, "
174 "data offset %u data len %u, # oob %u, "
175 "oob offset %u, oob len %u, pkt offset %u, "
178 rndis_msg
->msg
.pkt
.data_offset
,
179 rndis_msg
->msg
.pkt
.data_len
,
180 rndis_msg
->msg
.pkt
.num_oob_data_elements
,
181 rndis_msg
->msg
.pkt
.oob_data_offset
,
182 rndis_msg
->msg
.pkt
.oob_data_len
,
183 rndis_msg
->msg
.pkt
.per_pkt_info_offset
,
184 rndis_msg
->msg
.pkt
.per_pkt_info_len
);
187 case REMOTE_NDIS_INITIALIZE_CMPLT
:
188 DPRINT_DBG(NETVSC
, "REMOTE_NDIS_INITIALIZE_CMPLT "
189 "(len %u, id 0x%x, status 0x%x, major %d, minor %d, "
190 "device flags %d, max xfer size 0x%x, max pkts %u, "
193 rndis_msg
->msg
.init_complete
.req_id
,
194 rndis_msg
->msg
.init_complete
.status
,
195 rndis_msg
->msg
.init_complete
.major_ver
,
196 rndis_msg
->msg
.init_complete
.minor_ver
,
197 rndis_msg
->msg
.init_complete
.dev_flags
,
198 rndis_msg
->msg
.init_complete
.max_xfer_size
,
199 rndis_msg
->msg
.init_complete
.
201 rndis_msg
->msg
.init_complete
.
202 pkt_alignment_factor
);
205 case REMOTE_NDIS_QUERY_CMPLT
:
206 DPRINT_DBG(NETVSC
, "REMOTE_NDIS_QUERY_CMPLT "
207 "(len %u, id 0x%x, status 0x%x, buf len %u, "
210 rndis_msg
->msg
.query_complete
.req_id
,
211 rndis_msg
->msg
.query_complete
.status
,
212 rndis_msg
->msg
.query_complete
.
214 rndis_msg
->msg
.query_complete
.
218 case REMOTE_NDIS_SET_CMPLT
:
220 "REMOTE_NDIS_SET_CMPLT (len %u, id 0x%x, status 0x%x)",
222 rndis_msg
->msg
.set_complete
.req_id
,
223 rndis_msg
->msg
.set_complete
.status
);
226 case REMOTE_NDIS_INDICATE_STATUS_MSG
:
227 DPRINT_DBG(NETVSC
, "REMOTE_NDIS_INDICATE_STATUS_MSG "
228 "(len %u, status 0x%x, buf len %u, buf offset %u)",
230 rndis_msg
->msg
.indicate_status
.status
,
231 rndis_msg
->msg
.indicate_status
.status_buflen
,
232 rndis_msg
->msg
.indicate_status
.status_buf_offset
);
236 DPRINT_DBG(NETVSC
, "0x%x (len %u)",
237 rndis_msg
->ndis_msg_type
,
243 static int rndis_filter_send_request(struct rndis_device
*dev
,
244 struct rndis_request
*req
)
247 struct hv_netvsc_packet
*packet
;
249 /* Setup the packet to send it */
252 packet
->is_data_pkt
= false;
253 packet
->total_data_buflen
= req
->request_msg
.msg_len
;
254 packet
->page_buf_cnt
= 1;
256 packet
->page_buf
[0].pfn
= virt_to_phys(&req
->request_msg
) >>
258 packet
->page_buf
[0].len
= req
->request_msg
.msg_len
;
259 packet
->page_buf
[0].offset
=
260 (unsigned long)&req
->request_msg
& (PAGE_SIZE
- 1);
262 packet
->completion
.send
.send_completion_ctx
= req
;/* packet; */
263 packet
->completion
.send
.send_completion
=
264 rndis_filter_send_request_completion
;
265 packet
->completion
.send
.send_completion_tid
= (unsigned long)dev
;
267 ret
= rndis_filter
.inner_drv
.send(dev
->net_dev
->dev
, packet
);
271 static void rndis_filter_receive_response(struct rndis_device
*dev
,
272 struct rndis_message
*resp
)
274 struct rndis_request
*request
= NULL
;
278 spin_lock_irqsave(&dev
->request_lock
, flags
);
279 list_for_each_entry(request
, &dev
->req_list
, list_ent
) {
281 * All request/response message contains RequestId as the 1st
284 if (request
->request_msg
.msg
.init_req
.req_id
285 == resp
->msg
.init_complete
.req_id
) {
290 spin_unlock_irqrestore(&dev
->request_lock
, flags
);
293 if (resp
->msg_len
<= sizeof(struct rndis_message
)) {
294 memcpy(&request
->response_msg
, resp
,
297 dev_err(&dev
->net_dev
->dev
->device
,
298 "rndis response buffer overflow "
299 "detected (size %u max %zu)\n",
301 sizeof(struct rndis_filter_packet
));
303 if (resp
->ndis_msg_type
==
304 REMOTE_NDIS_RESET_CMPLT
) {
305 /* does not have a request id field */
306 request
->response_msg
.msg
.reset_complete
.
307 status
= STATUS_BUFFER_OVERFLOW
;
309 request
->response_msg
.msg
.
310 init_complete
.status
=
311 STATUS_BUFFER_OVERFLOW
;
315 request
->wait_condition
= 1;
316 wake_up(&request
->wait_event
);
318 dev_err(&dev
->net_dev
->dev
->device
,
319 "no rndis request found for this response "
320 "(id 0x%x res type 0x%x)\n",
321 resp
->msg
.init_complete
.req_id
,
322 resp
->ndis_msg_type
);
326 static void rndis_filter_receive_indicate_status(struct rndis_device
*dev
,
327 struct rndis_message
*resp
)
329 struct rndis_indicate_status
*indicate
=
330 &resp
->msg
.indicate_status
;
332 if (indicate
->status
== RNDIS_STATUS_MEDIA_CONNECT
) {
333 rndis_filter
.inner_drv
.link_status_change(
334 dev
->net_dev
->dev
, 1);
335 } else if (indicate
->status
== RNDIS_STATUS_MEDIA_DISCONNECT
) {
336 rndis_filter
.inner_drv
.link_status_change(
337 dev
->net_dev
->dev
, 0);
345 static void rndis_filter_receive_data(struct rndis_device
*dev
,
346 struct rndis_message
*msg
,
347 struct hv_netvsc_packet
*pkt
)
349 struct rndis_packet
*rndis_pkt
;
352 rndis_pkt
= &msg
->msg
.pkt
;
355 * FIXME: Handle multiple rndis pkt msgs that maybe enclosed in this
356 * netvsc packet (ie TotalDataBufferLength != MessageLength)
359 /* Remove the rndis header and pass it back up the stack */
360 data_offset
= RNDIS_HEADER_SIZE
+ rndis_pkt
->data_offset
;
362 pkt
->total_data_buflen
-= data_offset
;
363 pkt
->page_buf
[0].offset
+= data_offset
;
364 pkt
->page_buf
[0].len
-= data_offset
;
366 pkt
->is_data_pkt
= true;
368 rndis_filter
.inner_drv
.recv_cb(dev
->net_dev
->dev
,
372 static int rndis_filter_receive(struct hv_device
*dev
,
373 struct hv_netvsc_packet
*pkt
)
375 struct netvsc_device
*net_dev
= dev
->ext
;
376 struct rndis_device
*rndis_dev
;
377 struct rndis_message rndis_msg
;
378 struct rndis_message
*rndis_hdr
;
383 /* Make sure the rndis device state is initialized */
384 if (!net_dev
->extension
) {
385 dev_err(&dev
->device
, "got rndis message but no rndis device - "
386 "dropping this message!\n");
390 rndis_dev
= (struct rndis_device
*)net_dev
->extension
;
391 if (rndis_dev
->state
== RNDIS_DEV_UNINITIALIZED
) {
392 dev_err(&dev
->device
, "got rndis message but rndis device "
393 "uninitialized...dropping this message!\n");
397 rndis_hdr
= (struct rndis_message
*)kmap_atomic(
398 pfn_to_page(pkt
->page_buf
[0].pfn
), KM_IRQ0
);
400 rndis_hdr
= (void *)((unsigned long)rndis_hdr
+
401 pkt
->page_buf
[0].offset
);
403 /* Make sure we got a valid rndis message */
405 * FIXME: There seems to be a bug in set completion msg where its
406 * MessageLength is 16 bytes but the ByteCount field in the xfer page
407 * range shows 52 bytes
410 if (pkt
->total_data_buflen
!= rndis_hdr
->msg_len
) {
411 kunmap_atomic(rndis_hdr
- pkt
->page_buf
[0].offset
,
414 dev_err(&dev
->device
, "invalid rndis message? (expected %u "
415 "bytes got %u)...dropping this message!\n",
417 pkt
->total_data_buflen
);
422 if ((rndis_hdr
->ndis_msg_type
!= REMOTE_NDIS_PACKET_MSG
) &&
423 (rndis_hdr
->msg_len
> sizeof(struct rndis_message
))) {
424 dev_err(&dev
->device
, "incoming rndis message buffer overflow "
425 "detected (got %u, max %zu)..marking it an error!\n",
427 sizeof(struct rndis_message
));
430 memcpy(&rndis_msg
, rndis_hdr
,
431 (rndis_hdr
->msg_len
> sizeof(struct rndis_message
)) ?
432 sizeof(struct rndis_message
) :
435 kunmap_atomic(rndis_hdr
- pkt
->page_buf
[0].offset
, KM_IRQ0
);
437 dump_rndis_message(&rndis_msg
);
439 switch (rndis_msg
.ndis_msg_type
) {
440 case REMOTE_NDIS_PACKET_MSG
:
442 rndis_filter_receive_data(rndis_dev
, &rndis_msg
, pkt
);
445 case REMOTE_NDIS_INITIALIZE_CMPLT
:
446 case REMOTE_NDIS_QUERY_CMPLT
:
447 case REMOTE_NDIS_SET_CMPLT
:
448 /* completion msgs */
449 rndis_filter_receive_response(rndis_dev
, &rndis_msg
);
452 case REMOTE_NDIS_INDICATE_STATUS_MSG
:
453 /* notification msgs */
454 rndis_filter_receive_indicate_status(rndis_dev
, &rndis_msg
);
457 dev_err(&dev
->device
,
458 "unhandled rndis message (type %u len %u)\n",
459 rndis_msg
.ndis_msg_type
,
467 static int rndis_filter_query_device(struct rndis_device
*dev
, u32 oid
,
468 void *result
, u32
*result_size
)
470 struct rndis_request
*request
;
471 u32 inresult_size
= *result_size
;
472 struct rndis_query_request
*query
;
473 struct rndis_query_complete
*query_complete
;
480 request
= get_rndis_request(dev
, REMOTE_NDIS_QUERY_MSG
,
481 RNDIS_MESSAGE_SIZE(struct rndis_query_request
));
487 /* Setup the rndis query */
488 query
= &request
->request_msg
.msg
.query_req
;
490 query
->info_buf_offset
= sizeof(struct rndis_query_request
);
491 query
->info_buflen
= 0;
492 query
->dev_vc_handle
= 0;
494 request
->wait_condition
= 0;
495 ret
= rndis_filter_send_request(dev
, request
);
499 wait_event_timeout(request
->wait_event
, request
->wait_condition
,
500 msecs_to_jiffies(1000));
501 if (request
->wait_condition
== 0) {
506 /* Copy the response back */
507 query_complete
= &request
->response_msg
.msg
.query_complete
;
509 if (query_complete
->info_buflen
> inresult_size
) {
515 (void *)((unsigned long)query_complete
+
516 query_complete
->info_buf_offset
),
517 query_complete
->info_buflen
);
519 *result_size
= query_complete
->info_buflen
;
523 put_rndis_request(dev
, request
);
528 static int rndis_filter_query_device_mac(struct rndis_device
*dev
)
532 return rndis_filter_query_device(dev
,
533 RNDIS_OID_802_3_PERMANENT_ADDRESS
,
534 dev
->hw_mac_adr
, &size
);
537 static int rndis_filter_query_device_link_status(struct rndis_device
*dev
)
539 u32 size
= sizeof(u32
);
541 return rndis_filter_query_device(dev
,
542 RNDIS_OID_GEN_MEDIA_CONNECT_STATUS
,
543 &dev
->link_stat
, &size
);
546 static int rndis_filter_set_packet_filter(struct rndis_device
*dev
,
549 struct rndis_request
*request
;
550 struct rndis_set_request
*set
;
551 struct rndis_set_complete
*set_complete
;
555 request
= get_rndis_request(dev
, REMOTE_NDIS_SET_MSG
,
556 RNDIS_MESSAGE_SIZE(struct rndis_set_request
) +
563 /* Setup the rndis set */
564 set
= &request
->request_msg
.msg
.set_req
;
565 set
->oid
= RNDIS_OID_GEN_CURRENT_PACKET_FILTER
;
566 set
->info_buflen
= sizeof(u32
);
567 set
->info_buf_offset
= sizeof(struct rndis_set_request
);
569 memcpy((void *)(unsigned long)set
+ sizeof(struct rndis_set_request
),
570 &new_filter
, sizeof(u32
));
572 request
->wait_condition
= 0;
573 ret
= rndis_filter_send_request(dev
, request
);
577 wait_event_timeout(request
->wait_event
, request
->wait_condition
,
578 msecs_to_jiffies(2000));
579 if (request
->wait_condition
== 0) {
581 dev_err(&dev
->net_dev
->dev
->device
,
582 "timeout before we got a set response...\n");
584 * We can't deallocate the request since we may still receive a
585 * send completion for it.
591 set_complete
= &request
->response_msg
.msg
.set_complete
;
592 status
= set_complete
->status
;
597 put_rndis_request(dev
, request
);
602 int rndis_filter_init(struct netvsc_driver
*drv
)
604 drv
->req_ext_size
= sizeof(struct rndis_filter_packet
);
606 /* Driver->Context = rndisDriver; */
608 memset(&rndis_filter
, 0, sizeof(struct rndis_filter_driver_object
));
610 /*rndisDriver->Driver = Driver;
612 ASSERT(Driver->OnLinkStatusChanged);
613 rndisDriver->OnLinkStatusChanged = Driver->OnLinkStatusChanged;*/
615 /* Save the original dispatch handlers before we override it */
616 rndis_filter
.inner_drv
.base
.dev_add
= drv
->base
.dev_add
;
617 rndis_filter
.inner_drv
.base
.dev_rm
=
619 rndis_filter
.inner_drv
.base
.cleanup
= drv
->base
.cleanup
;
621 rndis_filter
.inner_drv
.send
= drv
->send
;
622 rndis_filter
.inner_drv
.recv_cb
= drv
->recv_cb
;
623 rndis_filter
.inner_drv
.link_status_change
=
624 drv
->link_status_change
;
627 drv
->base
.dev_add
= rndis_filte_device_add
;
628 drv
->base
.dev_rm
= rndis_filter_device_remove
;
629 drv
->base
.cleanup
= rndis_filter_cleanup
;
630 drv
->send
= rndis_filter_send
;
631 drv
->recv_cb
= rndis_filter_receive
;
636 static int rndis_filter_init_device(struct rndis_device
*dev
)
638 struct rndis_request
*request
;
639 struct rndis_initialize_request
*init
;
640 struct rndis_initialize_complete
*init_complete
;
644 request
= get_rndis_request(dev
, REMOTE_NDIS_INITIALIZE_MSG
,
645 RNDIS_MESSAGE_SIZE(struct rndis_initialize_request
));
651 /* Setup the rndis set */
652 init
= &request
->request_msg
.msg
.init_req
;
653 init
->major_ver
= RNDIS_MAJOR_VERSION
;
654 init
->minor_ver
= RNDIS_MINOR_VERSION
;
655 /* FIXME: Use 1536 - rounded ethernet frame size */
656 init
->max_xfer_size
= 2048;
658 dev
->state
= RNDIS_DEV_INITIALIZING
;
660 request
->wait_condition
= 0;
661 ret
= rndis_filter_send_request(dev
, request
);
663 dev
->state
= RNDIS_DEV_UNINITIALIZED
;
668 wait_event_timeout(request
->wait_event
, request
->wait_condition
,
669 msecs_to_jiffies(1000));
670 if (request
->wait_condition
== 0) {
675 init_complete
= &request
->response_msg
.msg
.init_complete
;
676 status
= init_complete
->status
;
677 if (status
== RNDIS_STATUS_SUCCESS
) {
678 dev
->state
= RNDIS_DEV_INITIALIZED
;
681 dev
->state
= RNDIS_DEV_UNINITIALIZED
;
687 put_rndis_request(dev
, request
);
692 static void rndis_filter_halt_device(struct rndis_device
*dev
)
694 struct rndis_request
*request
;
695 struct rndis_halt_request
*halt
;
697 /* Attempt to do a rndis device halt */
698 request
= get_rndis_request(dev
, REMOTE_NDIS_HALT_MSG
,
699 RNDIS_MESSAGE_SIZE(struct rndis_halt_request
));
703 /* Setup the rndis set */
704 halt
= &request
->request_msg
.msg
.halt_req
;
705 halt
->req_id
= atomic_inc_return(&dev
->new_req_id
);
707 /* Ignore return since this msg is optional. */
708 rndis_filter_send_request(dev
, request
);
710 dev
->state
= RNDIS_DEV_UNINITIALIZED
;
714 put_rndis_request(dev
, request
);
718 static int rndis_filter_open_device(struct rndis_device
*dev
)
722 if (dev
->state
!= RNDIS_DEV_INITIALIZED
)
725 ret
= rndis_filter_set_packet_filter(dev
,
726 NDIS_PACKET_TYPE_BROADCAST
|
727 NDIS_PACKET_TYPE_ALL_MULTICAST
|
728 NDIS_PACKET_TYPE_DIRECTED
);
730 dev
->state
= RNDIS_DEV_DATAINITIALIZED
;
735 static int rndis_filter_close_device(struct rndis_device
*dev
)
739 if (dev
->state
!= RNDIS_DEV_DATAINITIALIZED
)
742 ret
= rndis_filter_set_packet_filter(dev
, 0);
744 dev
->state
= RNDIS_DEV_INITIALIZED
;
749 static int rndis_filte_device_add(struct hv_device
*dev
,
750 void *additional_info
)
753 struct netvsc_device
*netDevice
;
754 struct rndis_device
*rndisDevice
;
755 struct netvsc_device_info
*deviceInfo
= additional_info
;
757 rndisDevice
= get_rndis_device();
762 * Let the inner driver handle this first to create the netvsc channel
763 * NOTE! Once the channel is created, we may get a receive callback
764 * (RndisFilterOnReceive()) before this call is completed
766 ret
= rndis_filter
.inner_drv
.base
.dev_add(dev
, additional_info
);
773 /* Initialize the rndis device */
774 netDevice
= dev
->ext
;
776 netDevice
->extension
= rndisDevice
;
777 rndisDevice
->net_dev
= netDevice
;
779 /* Send the rndis initialization message */
780 ret
= rndis_filter_init_device(rndisDevice
);
783 * TODO: If rndis init failed, we will need to shut down the
788 /* Get the mac address */
789 ret
= rndis_filter_query_device_mac(rndisDevice
);
792 * TODO: shutdown rndis device and the channel
796 memcpy(deviceInfo
->mac_adr
, rndisDevice
->hw_mac_adr
, ETH_ALEN
);
798 rndis_filter_query_device_link_status(rndisDevice
);
800 deviceInfo
->link_state
= rndisDevice
->link_stat
;
802 dev_info(&dev
->device
, "Device MAC %pM link state %s",
803 rndisDevice
->hw_mac_adr
,
804 ((deviceInfo
->link_state
) ? ("down\n") : ("up\n")));
809 static int rndis_filter_device_remove(struct hv_device
*dev
)
811 struct netvsc_device
*net_dev
= dev
->ext
;
812 struct rndis_device
*rndis_dev
= net_dev
->extension
;
814 /* Halt and release the rndis device */
815 rndis_filter_halt_device(rndis_dev
);
818 net_dev
->extension
= NULL
;
820 /* Pass control to inner driver to remove the device */
821 rndis_filter
.inner_drv
.base
.dev_rm(dev
);
826 static void rndis_filter_cleanup(struct hv_driver
*drv
)
830 int rndis_filter_open(struct hv_device
*dev
)
832 struct netvsc_device
*netDevice
= dev
->ext
;
837 return rndis_filter_open_device(netDevice
->extension
);
840 int rndis_filter_close(struct hv_device
*dev
)
842 struct netvsc_device
*netDevice
= dev
->ext
;
847 return rndis_filter_close_device(netDevice
->extension
);
850 static int rndis_filter_send(struct hv_device
*dev
,
851 struct hv_netvsc_packet
*pkt
)
854 struct rndis_filter_packet
*filterPacket
;
855 struct rndis_message
*rndisMessage
;
856 struct rndis_packet
*rndisPacket
;
857 u32 rndisMessageSize
;
859 /* Add the rndis header */
860 filterPacket
= (struct rndis_filter_packet
*)pkt
->extension
;
862 memset(filterPacket
, 0, sizeof(struct rndis_filter_packet
));
864 rndisMessage
= &filterPacket
->msg
;
865 rndisMessageSize
= RNDIS_MESSAGE_SIZE(struct rndis_packet
);
867 rndisMessage
->ndis_msg_type
= REMOTE_NDIS_PACKET_MSG
;
868 rndisMessage
->msg_len
= pkt
->total_data_buflen
+
871 rndisPacket
= &rndisMessage
->msg
.pkt
;
872 rndisPacket
->data_offset
= sizeof(struct rndis_packet
);
873 rndisPacket
->data_len
= pkt
->total_data_buflen
;
875 pkt
->is_data_pkt
= true;
876 pkt
->page_buf
[0].pfn
= virt_to_phys(rndisMessage
) >> PAGE_SHIFT
;
877 pkt
->page_buf
[0].offset
=
878 (unsigned long)rndisMessage
& (PAGE_SIZE
-1);
879 pkt
->page_buf
[0].len
= rndisMessageSize
;
881 /* Save the packet send completion and context */
882 filterPacket
->completion
= pkt
->completion
.send
.send_completion
;
883 filterPacket
->completion_ctx
=
884 pkt
->completion
.send
.send_completion_ctx
;
887 pkt
->completion
.send
.send_completion
= rndis_filter_send_completion
;
888 pkt
->completion
.send
.send_completion_ctx
= filterPacket
;
890 ret
= rndis_filter
.inner_drv
.send(dev
, pkt
);
893 * Reset the completion to originals to allow retries from
896 pkt
->completion
.send
.send_completion
=
897 filterPacket
->completion
;
898 pkt
->completion
.send
.send_completion_ctx
=
899 filterPacket
->completion_ctx
;
905 static void rndis_filter_send_completion(void *ctx
)
907 struct rndis_filter_packet
*filterPacket
= ctx
;
909 /* Pass it back to the original handler */
910 filterPacket
->completion(filterPacket
->completion_ctx
);
914 static void rndis_filter_send_request_completion(void *ctx
)