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>
29 #include <linux/if_vlan.h>
30 #include <linux/nls.h>
32 #include "hyperv_net.h"
35 struct rndis_request {
36 struct list_head list_ent;
37 struct completion wait_event;
40 * FIXME: We assumed a fixed size response here. If we do ever need to
41 * handle a bigger response, we can either define a max response
42 * message or add a response buffer variable above this field
44 struct rndis_message response_msg;
46 /* Simplify allocation by having a netvsc packet inline */
47 struct hv_netvsc_packet pkt;
48 struct hv_page_buffer buf;
50 struct rndis_message request_msg;
52 * The buffer for the extended info after the RNDIS message. It's
53 * referenced based on the data offset in the RNDIS message. Its size
54 * is enough for current needs, and should be sufficient for the near
60 static void rndis_filter_send_completion(void *ctx);
62 static void rndis_filter_send_request_completion(void *ctx);
66 static struct rndis_device *get_rndis_device(void)
68 struct rndis_device *device;
70 device = kzalloc(sizeof(struct rndis_device), GFP_KERNEL);
74 spin_lock_init(&device->request_lock);
76 INIT_LIST_HEAD(&device->req_list);
78 device->state = RNDIS_DEV_UNINITIALIZED;
83 static struct rndis_request *get_rndis_request(struct rndis_device *dev,
87 struct rndis_request *request;
88 struct rndis_message *rndis_msg;
89 struct rndis_set_request *set;
92 request = kzalloc(sizeof(struct rndis_request), GFP_KERNEL);
96 init_completion(&request->wait_event);
98 rndis_msg = &request->request_msg;
99 rndis_msg->ndis_msg_type = msg_type;
100 rndis_msg->msg_len = msg_len;
103 * Set the request id. This field is always after the rndis header for
104 * request/response packet types so we just used the SetRequest as a
107 set = &rndis_msg->msg.set_req;
108 set->req_id = atomic_inc_return(&dev->new_req_id);
110 /* Add to the request list */
111 spin_lock_irqsave(&dev->request_lock, flags);
112 list_add_tail(&request->list_ent, &dev->req_list);
113 spin_unlock_irqrestore(&dev->request_lock, flags);
118 static void put_rndis_request(struct rndis_device *dev,
119 struct rndis_request *req)
123 spin_lock_irqsave(&dev->request_lock, flags);
124 list_del(&req->list_ent);
125 spin_unlock_irqrestore(&dev->request_lock, flags);
130 static void dump_rndis_message(struct hv_device *hv_dev,
131 struct rndis_message *rndis_msg)
133 struct net_device *netdev;
134 struct netvsc_device *net_device;
136 net_device = hv_get_drvdata(hv_dev);
137 netdev = net_device->ndev;
139 switch (rndis_msg->ndis_msg_type) {
140 case RNDIS_MSG_PACKET:
141 netdev_dbg(netdev, "RNDIS_MSG_PACKET (len %u, "
142 "data offset %u data len %u, # oob %u, "
143 "oob offset %u, oob len %u, pkt offset %u, "
146 rndis_msg->msg.pkt.data_offset,
147 rndis_msg->msg.pkt.data_len,
148 rndis_msg->msg.pkt.num_oob_data_elements,
149 rndis_msg->msg.pkt.oob_data_offset,
150 rndis_msg->msg.pkt.oob_data_len,
151 rndis_msg->msg.pkt.per_pkt_info_offset,
152 rndis_msg->msg.pkt.per_pkt_info_len);
155 case RNDIS_MSG_INIT_C:
156 netdev_dbg(netdev, "RNDIS_MSG_INIT_C "
157 "(len %u, id 0x%x, status 0x%x, major %d, minor %d, "
158 "device flags %d, max xfer size 0x%x, max pkts %u, "
161 rndis_msg->msg.init_complete.req_id,
162 rndis_msg->msg.init_complete.status,
163 rndis_msg->msg.init_complete.major_ver,
164 rndis_msg->msg.init_complete.minor_ver,
165 rndis_msg->msg.init_complete.dev_flags,
166 rndis_msg->msg.init_complete.max_xfer_size,
167 rndis_msg->msg.init_complete.
169 rndis_msg->msg.init_complete.
170 pkt_alignment_factor);
173 case RNDIS_MSG_QUERY_C:
174 netdev_dbg(netdev, "RNDIS_MSG_QUERY_C "
175 "(len %u, id 0x%x, status 0x%x, buf len %u, "
178 rndis_msg->msg.query_complete.req_id,
179 rndis_msg->msg.query_complete.status,
180 rndis_msg->msg.query_complete.
182 rndis_msg->msg.query_complete.
186 case RNDIS_MSG_SET_C:
188 "RNDIS_MSG_SET_C (len %u, id 0x%x, status 0x%x)\n",
190 rndis_msg->msg.set_complete.req_id,
191 rndis_msg->msg.set_complete.status);
194 case RNDIS_MSG_INDICATE:
195 netdev_dbg(netdev, "RNDIS_MSG_INDICATE "
196 "(len %u, status 0x%x, buf len %u, buf offset %u)\n",
198 rndis_msg->msg.indicate_status.status,
199 rndis_msg->msg.indicate_status.status_buflen,
200 rndis_msg->msg.indicate_status.status_buf_offset);
204 netdev_dbg(netdev, "0x%x (len %u)\n",
205 rndis_msg->ndis_msg_type,
211 static int rndis_filter_send_request(struct rndis_device *dev,
212 struct rndis_request *req)
215 struct hv_netvsc_packet *packet;
217 /* Setup the packet to send it */
220 packet->is_data_pkt = false;
221 packet->total_data_buflen = req->request_msg.msg_len;
222 packet->page_buf_cnt = 1;
224 packet->page_buf[0].pfn = virt_to_phys(&req->request_msg) >>
226 packet->page_buf[0].len = req->request_msg.msg_len;
227 packet->page_buf[0].offset =
228 (unsigned long)&req->request_msg & (PAGE_SIZE - 1);
230 packet->completion.send.send_completion_ctx = req;/* packet; */
231 packet->completion.send.send_completion =
232 rndis_filter_send_request_completion;
233 packet->completion.send.send_completion_tid = (unsigned long)dev;
235 ret = netvsc_send(dev->net_dev->dev, packet);
239 static void rndis_filter_receive_response(struct rndis_device *dev,
240 struct rndis_message *resp)
242 struct rndis_request *request = NULL;
245 struct net_device *ndev;
247 ndev = dev->net_dev->ndev;
249 spin_lock_irqsave(&dev->request_lock, flags);
250 list_for_each_entry(request, &dev->req_list, list_ent) {
252 * All request/response message contains RequestId as the 1st
255 if (request->request_msg.msg.init_req.req_id
256 == resp->msg.init_complete.req_id) {
261 spin_unlock_irqrestore(&dev->request_lock, flags);
264 if (resp->msg_len <= sizeof(struct rndis_message)) {
265 memcpy(&request->response_msg, resp,
269 "rndis response buffer overflow "
270 "detected (size %u max %zu)\n",
272 sizeof(struct rndis_filter_packet));
274 if (resp->ndis_msg_type ==
276 /* does not have a request id field */
277 request->response_msg.msg.reset_complete.
278 status = RNDIS_STATUS_BUFFER_OVERFLOW;
280 request->response_msg.msg.
281 init_complete.status =
282 RNDIS_STATUS_BUFFER_OVERFLOW;
286 complete(&request->wait_event);
289 "no rndis request found for this response "
290 "(id 0x%x res type 0x%x)\n",
291 resp->msg.init_complete.req_id,
292 resp->ndis_msg_type);
296 static void rndis_filter_receive_indicate_status(struct rndis_device *dev,
297 struct rndis_message *resp)
299 struct rndis_indicate_status *indicate =
300 &resp->msg.indicate_status;
302 if (indicate->status == RNDIS_STATUS_MEDIA_CONNECT) {
303 netvsc_linkstatus_callback(
304 dev->net_dev->dev, 1);
305 } else if (indicate->status == RNDIS_STATUS_MEDIA_DISCONNECT) {
306 netvsc_linkstatus_callback(
307 dev->net_dev->dev, 0);
316 * Get the Per-Packet-Info with the specified type
317 * return NULL if not found.
319 static inline void *rndis_get_ppi(struct rndis_packet *rpkt, u32 type)
321 struct rndis_per_packet_info *ppi;
324 if (rpkt->per_pkt_info_offset == 0)
327 ppi = (struct rndis_per_packet_info *)((ulong)rpkt +
328 rpkt->per_pkt_info_offset);
329 len = rpkt->per_pkt_info_len;
332 if (ppi->type == type)
333 return (void *)((ulong)ppi + ppi->ppi_offset);
335 ppi = (struct rndis_per_packet_info *)((ulong)ppi + ppi->size);
341 static void rndis_filter_receive_data(struct rndis_device *dev,
342 struct rndis_message *msg,
343 struct hv_netvsc_packet *pkt)
345 struct rndis_packet *rndis_pkt;
347 struct ndis_pkt_8021q_info *vlan;
349 rndis_pkt = &msg->msg.pkt;
352 * FIXME: Handle multiple rndis pkt msgs that maybe enclosed in this
353 * netvsc packet (ie TotalDataBufferLength != MessageLength)
356 /* Remove the rndis header and pass it back up the stack */
357 data_offset = RNDIS_HEADER_SIZE + rndis_pkt->data_offset;
359 pkt->total_data_buflen -= data_offset;
362 * Make sure we got a valid RNDIS message, now total_data_buflen
363 * should be the data packet size plus the trailer padding size
365 if (pkt->total_data_buflen < rndis_pkt->data_len) {
366 netdev_err(dev->net_dev->ndev, "rndis message buffer "
367 "overflow detected (got %u, min %u)"
368 "...dropping this message!\n",
369 pkt->total_data_buflen, rndis_pkt->data_len);
374 * Remove the rndis trailer padding from rndis packet message
375 * rndis_pkt->data_len tell us the real data length, we only copy
376 * the data packet to the stack, without the rndis trailer padding
378 pkt->total_data_buflen = rndis_pkt->data_len;
379 pkt->data = (void *)((unsigned long)pkt->data + data_offset);
381 pkt->is_data_pkt = true;
383 vlan = rndis_get_ppi(rndis_pkt, IEEE_8021Q_INFO);
385 pkt->vlan_tci = VLAN_TAG_PRESENT | vlan->vlanid |
386 (vlan->pri << VLAN_PRIO_SHIFT);
391 netvsc_recv_callback(dev->net_dev->dev, pkt);
394 int rndis_filter_receive(struct hv_device *dev,
395 struct hv_netvsc_packet *pkt)
397 struct netvsc_device *net_dev = hv_get_drvdata(dev);
398 struct rndis_device *rndis_dev;
399 struct rndis_message *rndis_msg;
400 struct net_device *ndev;
405 ndev = net_dev->ndev;
407 /* Make sure the rndis device state is initialized */
408 if (!net_dev->extension) {
409 netdev_err(ndev, "got rndis message but no rndis device - "
410 "dropping this message!\n");
414 rndis_dev = (struct rndis_device *)net_dev->extension;
415 if (rndis_dev->state == RNDIS_DEV_UNINITIALIZED) {
416 netdev_err(ndev, "got rndis message but rndis device "
417 "uninitialized...dropping this message!\n");
421 rndis_msg = pkt->data;
423 dump_rndis_message(dev, rndis_msg);
425 switch (rndis_msg->ndis_msg_type) {
426 case RNDIS_MSG_PACKET:
428 rndis_filter_receive_data(rndis_dev, rndis_msg, pkt);
431 case RNDIS_MSG_INIT_C:
432 case RNDIS_MSG_QUERY_C:
433 case RNDIS_MSG_SET_C:
434 /* completion msgs */
435 rndis_filter_receive_response(rndis_dev, rndis_msg);
438 case RNDIS_MSG_INDICATE:
439 /* notification msgs */
440 rndis_filter_receive_indicate_status(rndis_dev, rndis_msg);
444 "unhandled rndis message (type %u len %u)\n",
445 rndis_msg->ndis_msg_type,
453 static int rndis_filter_query_device(struct rndis_device *dev, u32 oid,
454 void *result, u32 *result_size)
456 struct rndis_request *request;
457 u32 inresult_size = *result_size;
458 struct rndis_query_request *query;
459 struct rndis_query_complete *query_complete;
467 request = get_rndis_request(dev, RNDIS_MSG_QUERY,
468 RNDIS_MESSAGE_SIZE(struct rndis_query_request));
474 /* Setup the rndis query */
475 query = &request->request_msg.msg.query_req;
477 query->info_buf_offset = sizeof(struct rndis_query_request);
478 query->info_buflen = 0;
479 query->dev_vc_handle = 0;
481 ret = rndis_filter_send_request(dev, request);
485 t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
491 /* Copy the response back */
492 query_complete = &request->response_msg.msg.query_complete;
494 if (query_complete->info_buflen > inresult_size) {
500 (void *)((unsigned long)query_complete +
501 query_complete->info_buf_offset),
502 query_complete->info_buflen);
504 *result_size = query_complete->info_buflen;
508 put_rndis_request(dev, request);
513 static int rndis_filter_query_device_mac(struct rndis_device *dev)
517 return rndis_filter_query_device(dev,
518 RNDIS_OID_802_3_PERMANENT_ADDRESS,
519 dev->hw_mac_adr, &size);
522 #define NWADR_STR "NetworkAddress"
523 #define NWADR_STRLEN 14
525 int rndis_filter_set_device_mac(struct hv_device *hdev, char *mac)
527 struct netvsc_device *nvdev = hv_get_drvdata(hdev);
528 struct rndis_device *rdev = nvdev->extension;
529 struct net_device *ndev = nvdev->ndev;
530 struct rndis_request *request;
531 struct rndis_set_request *set;
532 struct rndis_config_parameter_info *cpi;
533 wchar_t *cfg_nwadr, *cfg_mac;
534 struct rndis_set_complete *set_complete;
535 char macstr[2*ETH_ALEN+1];
536 u32 extlen = sizeof(struct rndis_config_parameter_info) +
537 2*NWADR_STRLEN + 4*ETH_ALEN;
540 request = get_rndis_request(rdev, RNDIS_MSG_SET,
541 RNDIS_MESSAGE_SIZE(struct rndis_set_request) + extlen);
545 set = &request->request_msg.msg.set_req;
546 set->oid = RNDIS_OID_GEN_RNDIS_CONFIG_PARAMETER;
547 set->info_buflen = extlen;
548 set->info_buf_offset = sizeof(struct rndis_set_request);
549 set->dev_vc_handle = 0;
551 cpi = (struct rndis_config_parameter_info *)((ulong)set +
552 set->info_buf_offset);
553 cpi->parameter_name_offset =
554 sizeof(struct rndis_config_parameter_info);
555 /* Multiply by 2 because host needs 2 bytes (utf16) for each char */
556 cpi->parameter_name_length = 2*NWADR_STRLEN;
557 cpi->parameter_type = RNDIS_CONFIG_PARAM_TYPE_STRING;
558 cpi->parameter_value_offset =
559 cpi->parameter_name_offset + cpi->parameter_name_length;
560 /* Multiply by 4 because each MAC byte displayed as 2 utf16 chars */
561 cpi->parameter_value_length = 4*ETH_ALEN;
563 cfg_nwadr = (wchar_t *)((ulong)cpi + cpi->parameter_name_offset);
564 cfg_mac = (wchar_t *)((ulong)cpi + cpi->parameter_value_offset);
565 ret = utf8s_to_utf16s(NWADR_STR, NWADR_STRLEN, UTF16_HOST_ENDIAN,
566 cfg_nwadr, NWADR_STRLEN);
569 snprintf(macstr, 2*ETH_ALEN+1, "%pm", mac);
570 ret = utf8s_to_utf16s(macstr, 2*ETH_ALEN, UTF16_HOST_ENDIAN,
571 cfg_mac, 2*ETH_ALEN);
575 ret = rndis_filter_send_request(rdev, request);
579 t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
581 netdev_err(ndev, "timeout before we got a set response...\n");
583 * can't put_rndis_request, since we may still receive a
588 set_complete = &request->response_msg.msg.set_complete;
589 if (set_complete->status != RNDIS_STATUS_SUCCESS)
594 put_rndis_request(rdev, request);
599 static int rndis_filter_query_device_link_status(struct rndis_device *dev)
601 u32 size = sizeof(u32);
605 ret = rndis_filter_query_device(dev,
606 RNDIS_OID_GEN_MEDIA_CONNECT_STATUS,
607 &link_status, &size);
608 dev->link_state = (link_status != 0) ? true : false;
613 int rndis_filter_set_packet_filter(struct rndis_device *dev, u32 new_filter)
615 struct rndis_request *request;
616 struct rndis_set_request *set;
617 struct rndis_set_complete *set_complete;
620 struct net_device *ndev;
622 ndev = dev->net_dev->ndev;
624 request = get_rndis_request(dev, RNDIS_MSG_SET,
625 RNDIS_MESSAGE_SIZE(struct rndis_set_request) +
632 /* Setup the rndis set */
633 set = &request->request_msg.msg.set_req;
634 set->oid = RNDIS_OID_GEN_CURRENT_PACKET_FILTER;
635 set->info_buflen = sizeof(u32);
636 set->info_buf_offset = sizeof(struct rndis_set_request);
638 memcpy((void *)(unsigned long)set + sizeof(struct rndis_set_request),
639 &new_filter, sizeof(u32));
641 ret = rndis_filter_send_request(dev, request);
645 t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
649 "timeout before we got a set response...\n");
652 * We can't deallocate the request since we may still receive a
653 * send completion for it.
657 set_complete = &request->response_msg.msg.set_complete;
658 status = set_complete->status;
663 put_rndis_request(dev, request);
669 static int rndis_filter_init_device(struct rndis_device *dev)
671 struct rndis_request *request;
672 struct rndis_initialize_request *init;
673 struct rndis_initialize_complete *init_complete;
677 request = get_rndis_request(dev, RNDIS_MSG_INIT,
678 RNDIS_MESSAGE_SIZE(struct rndis_initialize_request));
684 /* Setup the rndis set */
685 init = &request->request_msg.msg.init_req;
686 init->major_ver = RNDIS_MAJOR_VERSION;
687 init->minor_ver = RNDIS_MINOR_VERSION;
688 init->max_xfer_size = 0x4000;
690 dev->state = RNDIS_DEV_INITIALIZING;
692 ret = rndis_filter_send_request(dev, request);
694 dev->state = RNDIS_DEV_UNINITIALIZED;
699 t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
706 init_complete = &request->response_msg.msg.init_complete;
707 status = init_complete->status;
708 if (status == RNDIS_STATUS_SUCCESS) {
709 dev->state = RNDIS_DEV_INITIALIZED;
712 dev->state = RNDIS_DEV_UNINITIALIZED;
718 put_rndis_request(dev, request);
723 static void rndis_filter_halt_device(struct rndis_device *dev)
725 struct rndis_request *request;
726 struct rndis_halt_request *halt;
727 struct netvsc_device *nvdev = dev->net_dev;
728 struct hv_device *hdev = nvdev->dev;
731 /* Attempt to do a rndis device halt */
732 request = get_rndis_request(dev, RNDIS_MSG_HALT,
733 RNDIS_MESSAGE_SIZE(struct rndis_halt_request));
737 /* Setup the rndis set */
738 halt = &request->request_msg.msg.halt_req;
739 halt->req_id = atomic_inc_return(&dev->new_req_id);
741 /* Ignore return since this msg is optional. */
742 rndis_filter_send_request(dev, request);
744 dev->state = RNDIS_DEV_UNINITIALIZED;
747 spin_lock_irqsave(&hdev->channel->inbound_lock, flags);
748 nvdev->destroy = true;
749 spin_unlock_irqrestore(&hdev->channel->inbound_lock, flags);
751 /* Wait for all send completions */
752 wait_event(nvdev->wait_drain,
753 atomic_read(&nvdev->num_outstanding_sends) == 0);
756 put_rndis_request(dev, request);
760 static int rndis_filter_open_device(struct rndis_device *dev)
764 if (dev->state != RNDIS_DEV_INITIALIZED)
767 ret = rndis_filter_set_packet_filter(dev,
768 NDIS_PACKET_TYPE_BROADCAST |
769 NDIS_PACKET_TYPE_ALL_MULTICAST |
770 NDIS_PACKET_TYPE_DIRECTED);
772 dev->state = RNDIS_DEV_DATAINITIALIZED;
777 static int rndis_filter_close_device(struct rndis_device *dev)
781 if (dev->state != RNDIS_DEV_DATAINITIALIZED)
784 ret = rndis_filter_set_packet_filter(dev, 0);
786 dev->state = RNDIS_DEV_INITIALIZED;
791 int rndis_filter_device_add(struct hv_device *dev,
792 void *additional_info)
795 struct netvsc_device *net_device;
796 struct rndis_device *rndis_device;
797 struct netvsc_device_info *device_info = additional_info;
799 rndis_device = get_rndis_device();
804 * Let the inner driver handle this first to create the netvsc channel
805 * NOTE! Once the channel is created, we may get a receive callback
806 * (RndisFilterOnReceive()) before this call is completed
808 ret = netvsc_device_add(dev, additional_info);
815 /* Initialize the rndis device */
816 net_device = hv_get_drvdata(dev);
818 net_device->extension = rndis_device;
819 rndis_device->net_dev = net_device;
821 /* Send the rndis initialization message */
822 ret = rndis_filter_init_device(rndis_device);
824 rndis_filter_device_remove(dev);
828 /* Get the mac address */
829 ret = rndis_filter_query_device_mac(rndis_device);
831 rndis_filter_device_remove(dev);
835 memcpy(device_info->mac_adr, rndis_device->hw_mac_adr, ETH_ALEN);
837 rndis_filter_query_device_link_status(rndis_device);
839 device_info->link_state = rndis_device->link_state;
841 dev_info(&dev->device, "Device MAC %pM link state %s\n",
842 rndis_device->hw_mac_adr,
843 device_info->link_state ? "down" : "up");
848 void rndis_filter_device_remove(struct hv_device *dev)
850 struct netvsc_device *net_dev = hv_get_drvdata(dev);
851 struct rndis_device *rndis_dev = net_dev->extension;
853 /* Halt and release the rndis device */
854 rndis_filter_halt_device(rndis_dev);
857 net_dev->extension = NULL;
859 netvsc_device_remove(dev);
863 int rndis_filter_open(struct hv_device *dev)
865 struct netvsc_device *net_device = hv_get_drvdata(dev);
870 return rndis_filter_open_device(net_device->extension);
873 int rndis_filter_close(struct hv_device *dev)
875 struct netvsc_device *nvdev = hv_get_drvdata(dev);
880 return rndis_filter_close_device(nvdev->extension);
883 int rndis_filter_send(struct hv_device *dev,
884 struct hv_netvsc_packet *pkt)
887 struct rndis_filter_packet *filter_pkt;
888 struct rndis_message *rndis_msg;
889 struct rndis_packet *rndis_pkt;
891 bool isvlan = pkt->vlan_tci & VLAN_TAG_PRESENT;
893 /* Add the rndis header */
894 filter_pkt = (struct rndis_filter_packet *)pkt->extension;
896 rndis_msg = &filter_pkt->msg;
897 rndis_msg_size = RNDIS_MESSAGE_SIZE(struct rndis_packet);
899 rndis_msg_size += NDIS_VLAN_PPI_SIZE;
901 rndis_msg->ndis_msg_type = RNDIS_MSG_PACKET;
902 rndis_msg->msg_len = pkt->total_data_buflen +
905 rndis_pkt = &rndis_msg->msg.pkt;
906 rndis_pkt->data_offset = sizeof(struct rndis_packet);
908 rndis_pkt->data_offset += NDIS_VLAN_PPI_SIZE;
909 rndis_pkt->data_len = pkt->total_data_buflen;
912 struct rndis_per_packet_info *ppi;
913 struct ndis_pkt_8021q_info *vlan;
915 rndis_pkt->per_pkt_info_offset = sizeof(struct rndis_packet);
916 rndis_pkt->per_pkt_info_len = NDIS_VLAN_PPI_SIZE;
918 ppi = (struct rndis_per_packet_info *)((ulong)rndis_pkt +
919 rndis_pkt->per_pkt_info_offset);
920 ppi->size = NDIS_VLAN_PPI_SIZE;
921 ppi->type = IEEE_8021Q_INFO;
922 ppi->ppi_offset = sizeof(struct rndis_per_packet_info);
924 vlan = (struct ndis_pkt_8021q_info *)((ulong)ppi +
926 vlan->vlanid = pkt->vlan_tci & VLAN_VID_MASK;
927 vlan->pri = (pkt->vlan_tci & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
930 pkt->is_data_pkt = true;
931 pkt->page_buf[0].pfn = virt_to_phys(rndis_msg) >> PAGE_SHIFT;
932 pkt->page_buf[0].offset =
933 (unsigned long)rndis_msg & (PAGE_SIZE-1);
934 pkt->page_buf[0].len = rndis_msg_size;
936 /* Add one page_buf if the rndis msg goes beyond page boundary */
937 if (pkt->page_buf[0].offset + rndis_msg_size > PAGE_SIZE) {
939 for (i = pkt->page_buf_cnt; i > 1; i--)
940 pkt->page_buf[i] = pkt->page_buf[i-1];
942 pkt->page_buf[0].len = PAGE_SIZE - pkt->page_buf[0].offset;
943 pkt->page_buf[1].pfn = virt_to_phys((void *)((ulong)
944 rndis_msg + pkt->page_buf[0].len)) >> PAGE_SHIFT;
945 pkt->page_buf[1].offset = 0;
946 pkt->page_buf[1].len = rndis_msg_size - pkt->page_buf[0].len;
949 /* Save the packet send completion and context */
950 filter_pkt->completion = pkt->completion.send.send_completion;
951 filter_pkt->completion_ctx =
952 pkt->completion.send.send_completion_ctx;
955 pkt->completion.send.send_completion = rndis_filter_send_completion;
956 pkt->completion.send.send_completion_ctx = filter_pkt;
958 ret = netvsc_send(dev, pkt);
961 * Reset the completion to originals to allow retries from
964 pkt->completion.send.send_completion =
965 filter_pkt->completion;
966 pkt->completion.send.send_completion_ctx =
967 filter_pkt->completion_ctx;
973 static void rndis_filter_send_completion(void *ctx)
975 struct rndis_filter_packet *filter_pkt = ctx;
977 /* Pass it back to the original handler */
978 filter_pkt->completion(filter_pkt->completion_ctx);
982 static void rndis_filter_send_request_completion(void *ctx)