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>
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
) {
286 DPRINT_DBG(NETVSC
, "found rndis request for "
287 "this response (id 0x%x req type 0x%x res "
289 request
->request_msg
.msg
.
291 request
->request_msg
.ndis_msg_type
,
292 resp
->ndis_msg_type
);
298 spin_unlock_irqrestore(&dev
->request_lock
, flags
);
301 if (resp
->msg_len
<= sizeof(struct rndis_message
)) {
302 memcpy(&request
->response_msg
, resp
,
305 DPRINT_ERR(NETVSC
, "rndis response buffer overflow "
306 "detected (size %u max %zu)",
308 sizeof(struct rndis_filter_packet
));
310 if (resp
->ndis_msg_type
==
311 REMOTE_NDIS_RESET_CMPLT
) {
312 /* does not have a request id field */
313 request
->response_msg
.msg
.reset_complete
.
314 status
= STATUS_BUFFER_OVERFLOW
;
316 request
->response_msg
.msg
.
317 init_complete
.status
=
318 STATUS_BUFFER_OVERFLOW
;
322 request
->wait_condition
= 1;
323 wake_up(&request
->wait_event
);
325 DPRINT_ERR(NETVSC
, "no rndis request found for this response "
326 "(id 0x%x res type 0x%x)",
327 resp
->msg
.init_complete
.req_id
,
328 resp
->ndis_msg_type
);
332 static void rndis_filter_receive_indicate_status(struct rndis_device
*dev
,
333 struct rndis_message
*resp
)
335 struct rndis_indicate_status
*indicate
=
336 &resp
->msg
.indicate_status
;
338 if (indicate
->status
== RNDIS_STATUS_MEDIA_CONNECT
) {
339 rndis_filter
.inner_drv
.link_status_change(
340 dev
->net_dev
->dev
, 1);
341 } else if (indicate
->status
== RNDIS_STATUS_MEDIA_DISCONNECT
) {
342 rndis_filter
.inner_drv
.link_status_change(
343 dev
->net_dev
->dev
, 0);
351 static void rndis_filter_receive_data(struct rndis_device
*dev
,
352 struct rndis_message
*msg
,
353 struct hv_netvsc_packet
*pkt
)
355 struct rndis_packet
*rndis_pkt
;
358 rndis_pkt
= &msg
->msg
.pkt
;
361 * FIXME: Handle multiple rndis pkt msgs that maybe enclosed in this
362 * netvsc packet (ie TotalDataBufferLength != MessageLength)
365 /* Remove the rndis header and pass it back up the stack */
366 data_offset
= RNDIS_HEADER_SIZE
+ rndis_pkt
->data_offset
;
368 pkt
->total_data_buflen
-= data_offset
;
369 pkt
->page_buf
[0].offset
+= data_offset
;
370 pkt
->page_buf
[0].len
-= data_offset
;
372 pkt
->is_data_pkt
= true;
374 rndis_filter
.inner_drv
.recv_cb(dev
->net_dev
->dev
,
378 static int rndis_filter_receive(struct hv_device
*dev
,
379 struct hv_netvsc_packet
*pkt
)
381 struct netvsc_device
*net_dev
= dev
->ext
;
382 struct rndis_device
*rndis_dev
;
383 struct rndis_message rndis_msg
;
384 struct rndis_message
*rndis_hdr
;
389 /* Make sure the rndis device state is initialized */
390 if (!net_dev
->extension
) {
391 DPRINT_ERR(NETVSC
, "got rndis message but no rndis device..."
392 "dropping this message!");
396 rndis_dev
= (struct rndis_device
*)net_dev
->extension
;
397 if (rndis_dev
->state
== RNDIS_DEV_UNINITIALIZED
) {
398 DPRINT_ERR(NETVSC
, "got rndis message but rndis device "
399 "uninitialized...dropping this message!");
403 rndis_hdr
= (struct rndis_message
*)kmap_atomic(
404 pfn_to_page(pkt
->page_buf
[0].pfn
), KM_IRQ0
);
406 rndis_hdr
= (void *)((unsigned long)rndis_hdr
+
407 pkt
->page_buf
[0].offset
);
409 /* Make sure we got a valid rndis message */
411 * FIXME: There seems to be a bug in set completion msg where its
412 * MessageLength is 16 bytes but the ByteCount field in the xfer page
413 * range shows 52 bytes
416 if (pkt
->total_data_buflen
!= rndis_hdr
->msg_len
) {
417 kunmap_atomic(rndis_hdr
- pkt
->page_buf
[0].offset
,
420 DPRINT_ERR(NETVSC
, "invalid rndis message? (expected %u "
421 "bytes got %u)...dropping this message!",
423 pkt
->total_data_buflen
);
428 if ((rndis_hdr
->ndis_msg_type
!= REMOTE_NDIS_PACKET_MSG
) &&
429 (rndis_hdr
->msg_len
> sizeof(struct rndis_message
))) {
430 DPRINT_ERR(NETVSC
, "incoming rndis message buffer overflow "
431 "detected (got %u, max %zu)...marking it an error!",
433 sizeof(struct rndis_message
));
436 memcpy(&rndis_msg
, rndis_hdr
,
437 (rndis_hdr
->msg_len
> sizeof(struct rndis_message
)) ?
438 sizeof(struct rndis_message
) :
441 kunmap_atomic(rndis_hdr
- pkt
->page_buf
[0].offset
, KM_IRQ0
);
443 dump_rndis_message(&rndis_msg
);
445 switch (rndis_msg
.ndis_msg_type
) {
446 case REMOTE_NDIS_PACKET_MSG
:
448 rndis_filter_receive_data(rndis_dev
, &rndis_msg
, pkt
);
451 case REMOTE_NDIS_INITIALIZE_CMPLT
:
452 case REMOTE_NDIS_QUERY_CMPLT
:
453 case REMOTE_NDIS_SET_CMPLT
:
454 /* completion msgs */
455 rndis_filter_receive_response(rndis_dev
, &rndis_msg
);
458 case REMOTE_NDIS_INDICATE_STATUS_MSG
:
459 /* notification msgs */
460 rndis_filter_receive_indicate_status(rndis_dev
, &rndis_msg
);
463 DPRINT_ERR(NETVSC
, "unhandled rndis message (type %u len %u)",
464 rndis_msg
.ndis_msg_type
,
472 static int rndis_filter_query_device(struct rndis_device
*dev
, u32 oid
,
473 void *result
, u32
*result_size
)
475 struct rndis_request
*request
;
476 u32 inresult_size
= *result_size
;
477 struct rndis_query_request
*query
;
478 struct rndis_query_complete
*query_complete
;
485 request
= get_rndis_request(dev
, REMOTE_NDIS_QUERY_MSG
,
486 RNDIS_MESSAGE_SIZE(struct rndis_query_request
));
492 /* Setup the rndis query */
493 query
= &request
->request_msg
.msg
.query_req
;
495 query
->info_buf_offset
= sizeof(struct rndis_query_request
);
496 query
->info_buflen
= 0;
497 query
->dev_vc_handle
= 0;
499 request
->wait_condition
= 0;
500 ret
= rndis_filter_send_request(dev
, request
);
504 wait_event_timeout(request
->wait_event
, request
->wait_condition
,
505 msecs_to_jiffies(1000));
506 if (request
->wait_condition
== 0) {
511 /* Copy the response back */
512 query_complete
= &request
->response_msg
.msg
.query_complete
;
514 if (query_complete
->info_buflen
> inresult_size
) {
520 (void *)((unsigned long)query_complete
+
521 query_complete
->info_buf_offset
),
522 query_complete
->info_buflen
);
524 *result_size
= query_complete
->info_buflen
;
528 put_rndis_request(dev
, request
);
533 static int rndis_filter_query_device_mac(struct rndis_device
*dev
)
537 return rndis_filter_query_device(dev
,
538 RNDIS_OID_802_3_PERMANENT_ADDRESS
,
539 dev
->hw_mac_adr
, &size
);
542 static int rndis_filter_query_device_link_status(struct rndis_device
*dev
)
544 u32 size
= sizeof(u32
);
546 return rndis_filter_query_device(dev
,
547 RNDIS_OID_GEN_MEDIA_CONNECT_STATUS
,
548 &dev
->link_stat
, &size
);
551 static int rndis_filter_set_packet_filter(struct rndis_device
*dev
,
554 struct rndis_request
*request
;
555 struct rndis_set_request
*set
;
556 struct rndis_set_complete
*set_complete
;
560 request
= get_rndis_request(dev
, REMOTE_NDIS_SET_MSG
,
561 RNDIS_MESSAGE_SIZE(struct rndis_set_request
) +
568 /* Setup the rndis set */
569 set
= &request
->request_msg
.msg
.set_req
;
570 set
->oid
= RNDIS_OID_GEN_CURRENT_PACKET_FILTER
;
571 set
->info_buflen
= sizeof(u32
);
572 set
->info_buf_offset
= sizeof(struct rndis_set_request
);
574 memcpy((void *)(unsigned long)set
+ sizeof(struct rndis_set_request
),
575 &new_filter
, sizeof(u32
));
577 request
->wait_condition
= 0;
578 ret
= rndis_filter_send_request(dev
, request
);
582 wait_event_timeout(request
->wait_event
, request
->wait_condition
,
583 msecs_to_jiffies(2000));
584 if (request
->wait_condition
== 0) {
586 DPRINT_ERR(NETVSC
, "timeout before we got a set response...");
588 * We can't deallocate the request since we may still receive a
589 * send completion for it.
595 set_complete
= &request
->response_msg
.msg
.set_complete
;
596 status
= set_complete
->status
;
601 put_rndis_request(dev
, request
);
606 int rndis_filter_init(struct netvsc_driver
*drv
)
608 DPRINT_DBG(NETVSC
, "sizeof(struct rndis_filter_packet) == %zd",
609 sizeof(struct rndis_filter_packet
));
611 drv
->req_ext_size
= sizeof(struct rndis_filter_packet
);
613 /* Driver->Context = rndisDriver; */
615 memset(&rndis_filter
, 0, sizeof(struct rndis_filter_driver_object
));
617 /*rndisDriver->Driver = Driver;
619 ASSERT(Driver->OnLinkStatusChanged);
620 rndisDriver->OnLinkStatusChanged = Driver->OnLinkStatusChanged;*/
622 /* Save the original dispatch handlers before we override it */
623 rndis_filter
.inner_drv
.base
.dev_add
= drv
->base
.dev_add
;
624 rndis_filter
.inner_drv
.base
.dev_rm
=
626 rndis_filter
.inner_drv
.base
.cleanup
= drv
->base
.cleanup
;
628 rndis_filter
.inner_drv
.send
= drv
->send
;
629 rndis_filter
.inner_drv
.recv_cb
= drv
->recv_cb
;
630 rndis_filter
.inner_drv
.link_status_change
=
631 drv
->link_status_change
;
634 drv
->base
.dev_add
= rndis_filte_device_add
;
635 drv
->base
.dev_rm
= rndis_filter_device_remove
;
636 drv
->base
.cleanup
= rndis_filter_cleanup
;
637 drv
->send
= rndis_filter_send
;
638 drv
->recv_cb
= rndis_filter_receive
;
643 static int rndis_filter_init_device(struct rndis_device
*dev
)
645 struct rndis_request
*request
;
646 struct rndis_initialize_request
*init
;
647 struct rndis_initialize_complete
*init_complete
;
651 request
= get_rndis_request(dev
, REMOTE_NDIS_INITIALIZE_MSG
,
652 RNDIS_MESSAGE_SIZE(struct rndis_initialize_request
));
658 /* Setup the rndis set */
659 init
= &request
->request_msg
.msg
.init_req
;
660 init
->major_ver
= RNDIS_MAJOR_VERSION
;
661 init
->minor_ver
= RNDIS_MINOR_VERSION
;
662 /* FIXME: Use 1536 - rounded ethernet frame size */
663 init
->max_xfer_size
= 2048;
665 dev
->state
= RNDIS_DEV_INITIALIZING
;
667 request
->wait_condition
= 0;
668 ret
= rndis_filter_send_request(dev
, request
);
670 dev
->state
= RNDIS_DEV_UNINITIALIZED
;
675 wait_event_timeout(request
->wait_event
, request
->wait_condition
,
676 msecs_to_jiffies(1000));
677 if (request
->wait_condition
== 0) {
682 init_complete
= &request
->response_msg
.msg
.init_complete
;
683 status
= init_complete
->status
;
684 if (status
== RNDIS_STATUS_SUCCESS
) {
685 dev
->state
= RNDIS_DEV_INITIALIZED
;
688 dev
->state
= RNDIS_DEV_UNINITIALIZED
;
694 put_rndis_request(dev
, request
);
699 static void rndis_filter_halt_device(struct rndis_device
*dev
)
701 struct rndis_request
*request
;
702 struct rndis_halt_request
*halt
;
704 /* Attempt to do a rndis device halt */
705 request
= get_rndis_request(dev
, REMOTE_NDIS_HALT_MSG
,
706 RNDIS_MESSAGE_SIZE(struct rndis_halt_request
));
710 /* Setup the rndis set */
711 halt
= &request
->request_msg
.msg
.halt_req
;
712 halt
->req_id
= atomic_inc_return(&dev
->new_req_id
);
714 /* Ignore return since this msg is optional. */
715 rndis_filter_send_request(dev
, request
);
717 dev
->state
= RNDIS_DEV_UNINITIALIZED
;
721 put_rndis_request(dev
, request
);
725 static int rndis_filter_open_device(struct rndis_device
*dev
)
729 if (dev
->state
!= RNDIS_DEV_INITIALIZED
)
732 ret
= rndis_filter_set_packet_filter(dev
,
733 NDIS_PACKET_TYPE_BROADCAST
|
734 NDIS_PACKET_TYPE_ALL_MULTICAST
|
735 NDIS_PACKET_TYPE_DIRECTED
);
737 dev
->state
= RNDIS_DEV_DATAINITIALIZED
;
742 static int rndis_filter_close_device(struct rndis_device
*dev
)
746 if (dev
->state
!= RNDIS_DEV_DATAINITIALIZED
)
749 ret
= rndis_filter_set_packet_filter(dev
, 0);
751 dev
->state
= RNDIS_DEV_INITIALIZED
;
756 static int rndis_filte_device_add(struct hv_device
*dev
,
757 void *additional_info
)
760 struct netvsc_device
*netDevice
;
761 struct rndis_device
*rndisDevice
;
762 struct netvsc_device_info
*deviceInfo
= additional_info
;
764 rndisDevice
= get_rndis_device();
768 DPRINT_DBG(NETVSC
, "rndis device object allocated - %p", rndisDevice
);
771 * Let the inner driver handle this first to create the netvsc channel
772 * NOTE! Once the channel is created, we may get a receive callback
773 * (RndisFilterOnReceive()) before this call is completed
775 ret
= rndis_filter
.inner_drv
.base
.dev_add(dev
, additional_info
);
782 /* Initialize the rndis device */
783 netDevice
= dev
->ext
;
785 netDevice
->extension
= rndisDevice
;
786 rndisDevice
->net_dev
= netDevice
;
788 /* Send the rndis initialization message */
789 ret
= rndis_filter_init_device(rndisDevice
);
792 * TODO: If rndis init failed, we will need to shut down the
797 /* Get the mac address */
798 ret
= rndis_filter_query_device_mac(rndisDevice
);
801 * TODO: shutdown rndis device and the channel
805 DPRINT_INFO(NETVSC
, "Device 0x%p mac addr %pM",
806 rndisDevice
, rndisDevice
->hw_mac_adr
);
808 memcpy(deviceInfo
->mac_adr
, rndisDevice
->hw_mac_adr
, ETH_ALEN
);
810 rndis_filter_query_device_link_status(rndisDevice
);
812 deviceInfo
->link_state
= rndisDevice
->link_stat
;
813 DPRINT_INFO(NETVSC
, "Device 0x%p link state %s", rndisDevice
,
814 ((deviceInfo
->link_state
) ? ("down") : ("up")));
819 static int rndis_filter_device_remove(struct hv_device
*dev
)
821 struct netvsc_device
*net_dev
= dev
->ext
;
822 struct rndis_device
*rndis_dev
= net_dev
->extension
;
824 /* Halt and release the rndis device */
825 rndis_filter_halt_device(rndis_dev
);
828 net_dev
->extension
= NULL
;
830 /* Pass control to inner driver to remove the device */
831 rndis_filter
.inner_drv
.base
.dev_rm(dev
);
836 static void rndis_filter_cleanup(struct hv_driver
*drv
)
840 int rndis_filter_open(struct hv_device
*dev
)
842 struct netvsc_device
*netDevice
= dev
->ext
;
847 return rndis_filter_open_device(netDevice
->extension
);
850 int rndis_filter_close(struct hv_device
*dev
)
852 struct netvsc_device
*netDevice
= dev
->ext
;
857 return rndis_filter_close_device(netDevice
->extension
);
860 static int rndis_filter_send(struct hv_device
*dev
,
861 struct hv_netvsc_packet
*pkt
)
864 struct rndis_filter_packet
*filterPacket
;
865 struct rndis_message
*rndisMessage
;
866 struct rndis_packet
*rndisPacket
;
867 u32 rndisMessageSize
;
869 /* Add the rndis header */
870 filterPacket
= (struct rndis_filter_packet
*)pkt
->extension
;
872 memset(filterPacket
, 0, sizeof(struct rndis_filter_packet
));
874 rndisMessage
= &filterPacket
->msg
;
875 rndisMessageSize
= RNDIS_MESSAGE_SIZE(struct rndis_packet
);
877 rndisMessage
->ndis_msg_type
= REMOTE_NDIS_PACKET_MSG
;
878 rndisMessage
->msg_len
= pkt
->total_data_buflen
+
881 rndisPacket
= &rndisMessage
->msg
.pkt
;
882 rndisPacket
->data_offset
= sizeof(struct rndis_packet
);
883 rndisPacket
->data_len
= pkt
->total_data_buflen
;
885 pkt
->is_data_pkt
= true;
886 pkt
->page_buf
[0].pfn
= virt_to_phys(rndisMessage
) >> PAGE_SHIFT
;
887 pkt
->page_buf
[0].offset
=
888 (unsigned long)rndisMessage
& (PAGE_SIZE
-1);
889 pkt
->page_buf
[0].len
= rndisMessageSize
;
891 /* Save the packet send completion and context */
892 filterPacket
->completion
= pkt
->completion
.send
.send_completion
;
893 filterPacket
->completion_ctx
=
894 pkt
->completion
.send
.send_completion_ctx
;
897 pkt
->completion
.send
.send_completion
= rndis_filter_send_completion
;
898 pkt
->completion
.send
.send_completion_ctx
= filterPacket
;
900 ret
= rndis_filter
.inner_drv
.send(dev
, pkt
);
903 * Reset the completion to originals to allow retries from
906 pkt
->completion
.send
.send_completion
=
907 filterPacket
->completion
;
908 pkt
->completion
.send
.send_completion_ctx
=
909 filterPacket
->completion_ctx
;
915 static void rndis_filter_send_completion(void *ctx
)
917 struct rndis_filter_packet
*filterPacket
= ctx
;
919 /* Pass it back to the original handler */
920 filterPacket
->completion(filterPacket
->completion_ctx
);
924 static void rndis_filter_send_request_completion(void *ctx
)