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, see <http://www.gnu.org/licenses/>.
17 * Haiyang Zhang <haiyangz@microsoft.com>
18 * Hank Janssen <hjanssen@microsoft.com>
20 #include <linux/kernel.h>
21 #include <linux/sched.h>
22 #include <linux/wait.h>
23 #include <linux/highmem.h>
24 #include <linux/slab.h>
26 #include <linux/if_ether.h>
27 #include <linux/netdevice.h>
28 #include <linux/if_vlan.h>
29 #include <linux/nls.h>
31 #include "hyperv_net.h"
34 #define RNDIS_EXT_LEN 100
35 struct rndis_request {
36 struct list_head list_ent;
37 struct completion wait_event;
39 struct rndis_message response_msg;
41 * The buffer for extended info after the RNDIS response message. It's
42 * referenced based on the data offset in the RNDIS message. Its size
43 * is enough for current needs, and should be sufficient for the near
46 u8 response_ext[RNDIS_EXT_LEN];
48 /* Simplify allocation by having a netvsc packet inline */
49 struct hv_netvsc_packet pkt;
50 /* Set 2 pages for rndis requests crossing page boundary */
51 struct hv_page_buffer buf[2];
53 struct rndis_message request_msg;
55 * The buffer for the extended info after the RNDIS request message.
56 * It is referenced and sized in a similar way as response_ext.
58 u8 request_ext[RNDIS_EXT_LEN];
61 static struct rndis_device *get_rndis_device(void)
63 struct rndis_device *device;
65 device = kzalloc(sizeof(struct rndis_device), GFP_KERNEL);
69 spin_lock_init(&device->request_lock);
71 INIT_LIST_HEAD(&device->req_list);
73 device->state = RNDIS_DEV_UNINITIALIZED;
78 static struct rndis_request *get_rndis_request(struct rndis_device *dev,
82 struct rndis_request *request;
83 struct rndis_message *rndis_msg;
84 struct rndis_set_request *set;
87 request = kzalloc(sizeof(struct rndis_request), GFP_KERNEL);
91 init_completion(&request->wait_event);
93 rndis_msg = &request->request_msg;
94 rndis_msg->ndis_msg_type = msg_type;
95 rndis_msg->msg_len = msg_len;
98 * Set the request id. This field is always after the rndis header for
99 * request/response packet types so we just used the SetRequest as a
102 set = &rndis_msg->msg.set_req;
103 set->req_id = atomic_inc_return(&dev->new_req_id);
105 /* Add to the request list */
106 spin_lock_irqsave(&dev->request_lock, flags);
107 list_add_tail(&request->list_ent, &dev->req_list);
108 spin_unlock_irqrestore(&dev->request_lock, flags);
113 static void put_rndis_request(struct rndis_device *dev,
114 struct rndis_request *req)
118 spin_lock_irqsave(&dev->request_lock, flags);
119 list_del(&req->list_ent);
120 spin_unlock_irqrestore(&dev->request_lock, flags);
125 static void dump_rndis_message(struct hv_device *hv_dev,
126 struct rndis_message *rndis_msg)
128 struct net_device *netdev;
129 struct netvsc_device *net_device;
131 net_device = hv_get_drvdata(hv_dev);
132 netdev = net_device->ndev;
134 switch (rndis_msg->ndis_msg_type) {
135 case RNDIS_MSG_PACKET:
136 netdev_dbg(netdev, "RNDIS_MSG_PACKET (len %u, "
137 "data offset %u data len %u, # oob %u, "
138 "oob offset %u, oob len %u, pkt offset %u, "
141 rndis_msg->msg.pkt.data_offset,
142 rndis_msg->msg.pkt.data_len,
143 rndis_msg->msg.pkt.num_oob_data_elements,
144 rndis_msg->msg.pkt.oob_data_offset,
145 rndis_msg->msg.pkt.oob_data_len,
146 rndis_msg->msg.pkt.per_pkt_info_offset,
147 rndis_msg->msg.pkt.per_pkt_info_len);
150 case RNDIS_MSG_INIT_C:
151 netdev_dbg(netdev, "RNDIS_MSG_INIT_C "
152 "(len %u, id 0x%x, status 0x%x, major %d, minor %d, "
153 "device flags %d, max xfer size 0x%x, max pkts %u, "
156 rndis_msg->msg.init_complete.req_id,
157 rndis_msg->msg.init_complete.status,
158 rndis_msg->msg.init_complete.major_ver,
159 rndis_msg->msg.init_complete.minor_ver,
160 rndis_msg->msg.init_complete.dev_flags,
161 rndis_msg->msg.init_complete.max_xfer_size,
162 rndis_msg->msg.init_complete.
164 rndis_msg->msg.init_complete.
165 pkt_alignment_factor);
168 case RNDIS_MSG_QUERY_C:
169 netdev_dbg(netdev, "RNDIS_MSG_QUERY_C "
170 "(len %u, id 0x%x, status 0x%x, buf len %u, "
173 rndis_msg->msg.query_complete.req_id,
174 rndis_msg->msg.query_complete.status,
175 rndis_msg->msg.query_complete.
177 rndis_msg->msg.query_complete.
181 case RNDIS_MSG_SET_C:
183 "RNDIS_MSG_SET_C (len %u, id 0x%x, status 0x%x)\n",
185 rndis_msg->msg.set_complete.req_id,
186 rndis_msg->msg.set_complete.status);
189 case RNDIS_MSG_INDICATE:
190 netdev_dbg(netdev, "RNDIS_MSG_INDICATE "
191 "(len %u, status 0x%x, buf len %u, buf offset %u)\n",
193 rndis_msg->msg.indicate_status.status,
194 rndis_msg->msg.indicate_status.status_buflen,
195 rndis_msg->msg.indicate_status.status_buf_offset);
199 netdev_dbg(netdev, "0x%x (len %u)\n",
200 rndis_msg->ndis_msg_type,
206 static int rndis_filter_send_request(struct rndis_device *dev,
207 struct rndis_request *req)
210 struct hv_netvsc_packet *packet;
212 /* Setup the packet to send it */
215 packet->is_data_pkt = false;
216 packet->total_data_buflen = req->request_msg.msg_len;
217 packet->page_buf_cnt = 1;
219 packet->page_buf[0].pfn = virt_to_phys(&req->request_msg) >>
221 packet->page_buf[0].len = req->request_msg.msg_len;
222 packet->page_buf[0].offset =
223 (unsigned long)&req->request_msg & (PAGE_SIZE - 1);
225 /* Add one page_buf when request_msg crossing page boundary */
226 if (packet->page_buf[0].offset + packet->page_buf[0].len > PAGE_SIZE) {
227 packet->page_buf_cnt++;
228 packet->page_buf[0].len = PAGE_SIZE -
229 packet->page_buf[0].offset;
230 packet->page_buf[1].pfn = virt_to_phys((void *)&req->request_msg
231 + packet->page_buf[0].len) >> PAGE_SHIFT;
232 packet->page_buf[1].offset = 0;
233 packet->page_buf[1].len = req->request_msg.msg_len -
234 packet->page_buf[0].len;
237 packet->completion.send.send_completion = NULL;
239 ret = netvsc_send(dev->net_dev->dev, packet);
243 static void rndis_filter_receive_response(struct rndis_device *dev,
244 struct rndis_message *resp)
246 struct rndis_request *request = NULL;
249 struct net_device *ndev;
251 ndev = dev->net_dev->ndev;
253 spin_lock_irqsave(&dev->request_lock, flags);
254 list_for_each_entry(request, &dev->req_list, list_ent) {
256 * All request/response message contains RequestId as the 1st
259 if (request->request_msg.msg.init_req.req_id
260 == resp->msg.init_complete.req_id) {
265 spin_unlock_irqrestore(&dev->request_lock, flags);
269 sizeof(struct rndis_message) + RNDIS_EXT_LEN) {
270 memcpy(&request->response_msg, resp,
274 "rndis response buffer overflow "
275 "detected (size %u max %zu)\n",
277 sizeof(struct rndis_message));
279 if (resp->ndis_msg_type ==
281 /* does not have a request id field */
282 request->response_msg.msg.reset_complete.
283 status = RNDIS_STATUS_BUFFER_OVERFLOW;
285 request->response_msg.msg.
286 init_complete.status =
287 RNDIS_STATUS_BUFFER_OVERFLOW;
291 complete(&request->wait_event);
294 "no rndis request found for this response "
295 "(id 0x%x res type 0x%x)\n",
296 resp->msg.init_complete.req_id,
297 resp->ndis_msg_type);
301 static void rndis_filter_receive_indicate_status(struct rndis_device *dev,
302 struct rndis_message *resp)
304 struct rndis_indicate_status *indicate =
305 &resp->msg.indicate_status;
307 if (indicate->status == RNDIS_STATUS_MEDIA_CONNECT) {
308 netvsc_linkstatus_callback(
309 dev->net_dev->dev, 1);
310 } else if (indicate->status == RNDIS_STATUS_MEDIA_DISCONNECT) {
311 netvsc_linkstatus_callback(
312 dev->net_dev->dev, 0);
321 * Get the Per-Packet-Info with the specified type
322 * return NULL if not found.
324 static inline void *rndis_get_ppi(struct rndis_packet *rpkt, u32 type)
326 struct rndis_per_packet_info *ppi;
329 if (rpkt->per_pkt_info_offset == 0)
332 ppi = (struct rndis_per_packet_info *)((ulong)rpkt +
333 rpkt->per_pkt_info_offset);
334 len = rpkt->per_pkt_info_len;
337 if (ppi->type == type)
338 return (void *)((ulong)ppi + ppi->ppi_offset);
340 ppi = (struct rndis_per_packet_info *)((ulong)ppi + ppi->size);
346 static void rndis_filter_receive_data(struct rndis_device *dev,
347 struct rndis_message *msg,
348 struct hv_netvsc_packet *pkt)
350 struct rndis_packet *rndis_pkt;
352 struct ndis_pkt_8021q_info *vlan;
354 rndis_pkt = &msg->msg.pkt;
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;
408 ndev = net_dev->ndev;
410 /* Make sure the rndis device state is initialized */
411 if (!net_dev->extension) {
412 netdev_err(ndev, "got rndis message but no rndis device - "
413 "dropping this message!\n");
418 rndis_dev = (struct rndis_device *)net_dev->extension;
419 if (rndis_dev->state == RNDIS_DEV_UNINITIALIZED) {
420 netdev_err(ndev, "got rndis message but rndis device "
421 "uninitialized...dropping this message!\n");
426 rndis_msg = pkt->data;
428 dump_rndis_message(dev, rndis_msg);
430 switch (rndis_msg->ndis_msg_type) {
431 case RNDIS_MSG_PACKET:
433 rndis_filter_receive_data(rndis_dev, rndis_msg, pkt);
436 case RNDIS_MSG_INIT_C:
437 case RNDIS_MSG_QUERY_C:
438 case RNDIS_MSG_SET_C:
439 /* completion msgs */
440 rndis_filter_receive_response(rndis_dev, rndis_msg);
443 case RNDIS_MSG_INDICATE:
444 /* notification msgs */
445 rndis_filter_receive_indicate_status(rndis_dev, rndis_msg);
449 "unhandled rndis message (type %u len %u)\n",
450 rndis_msg->ndis_msg_type,
457 pkt->status = NVSP_STAT_FAIL;
462 static int rndis_filter_query_device(struct rndis_device *dev, u32 oid,
463 void *result, u32 *result_size)
465 struct rndis_request *request;
466 u32 inresult_size = *result_size;
467 struct rndis_query_request *query;
468 struct rndis_query_complete *query_complete;
476 request = get_rndis_request(dev, RNDIS_MSG_QUERY,
477 RNDIS_MESSAGE_SIZE(struct rndis_query_request));
483 /* Setup the rndis query */
484 query = &request->request_msg.msg.query_req;
486 query->info_buf_offset = sizeof(struct rndis_query_request);
487 query->info_buflen = 0;
488 query->dev_vc_handle = 0;
490 ret = rndis_filter_send_request(dev, request);
494 t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
500 /* Copy the response back */
501 query_complete = &request->response_msg.msg.query_complete;
503 if (query_complete->info_buflen > inresult_size) {
509 (void *)((unsigned long)query_complete +
510 query_complete->info_buf_offset),
511 query_complete->info_buflen);
513 *result_size = query_complete->info_buflen;
517 put_rndis_request(dev, request);
522 static int rndis_filter_query_device_mac(struct rndis_device *dev)
526 return rndis_filter_query_device(dev,
527 RNDIS_OID_802_3_PERMANENT_ADDRESS,
528 dev->hw_mac_adr, &size);
531 #define NWADR_STR "NetworkAddress"
532 #define NWADR_STRLEN 14
534 int rndis_filter_set_device_mac(struct hv_device *hdev, char *mac)
536 struct netvsc_device *nvdev = hv_get_drvdata(hdev);
537 struct rndis_device *rdev = nvdev->extension;
538 struct net_device *ndev = nvdev->ndev;
539 struct rndis_request *request;
540 struct rndis_set_request *set;
541 struct rndis_config_parameter_info *cpi;
542 wchar_t *cfg_nwadr, *cfg_mac;
543 struct rndis_set_complete *set_complete;
544 char macstr[2*ETH_ALEN+1];
545 u32 extlen = sizeof(struct rndis_config_parameter_info) +
546 2*NWADR_STRLEN + 4*ETH_ALEN;
549 request = get_rndis_request(rdev, RNDIS_MSG_SET,
550 RNDIS_MESSAGE_SIZE(struct rndis_set_request) + extlen);
554 set = &request->request_msg.msg.set_req;
555 set->oid = RNDIS_OID_GEN_RNDIS_CONFIG_PARAMETER;
556 set->info_buflen = extlen;
557 set->info_buf_offset = sizeof(struct rndis_set_request);
558 set->dev_vc_handle = 0;
560 cpi = (struct rndis_config_parameter_info *)((ulong)set +
561 set->info_buf_offset);
562 cpi->parameter_name_offset =
563 sizeof(struct rndis_config_parameter_info);
564 /* Multiply by 2 because host needs 2 bytes (utf16) for each char */
565 cpi->parameter_name_length = 2*NWADR_STRLEN;
566 cpi->parameter_type = RNDIS_CONFIG_PARAM_TYPE_STRING;
567 cpi->parameter_value_offset =
568 cpi->parameter_name_offset + cpi->parameter_name_length;
569 /* Multiply by 4 because each MAC byte displayed as 2 utf16 chars */
570 cpi->parameter_value_length = 4*ETH_ALEN;
572 cfg_nwadr = (wchar_t *)((ulong)cpi + cpi->parameter_name_offset);
573 cfg_mac = (wchar_t *)((ulong)cpi + cpi->parameter_value_offset);
574 ret = utf8s_to_utf16s(NWADR_STR, NWADR_STRLEN, UTF16_HOST_ENDIAN,
575 cfg_nwadr, NWADR_STRLEN);
578 snprintf(macstr, 2*ETH_ALEN+1, "%pm", mac);
579 ret = utf8s_to_utf16s(macstr, 2*ETH_ALEN, UTF16_HOST_ENDIAN,
580 cfg_mac, 2*ETH_ALEN);
584 ret = rndis_filter_send_request(rdev, request);
588 t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
590 netdev_err(ndev, "timeout before we got a set response...\n");
592 * can't put_rndis_request, since we may still receive a
597 set_complete = &request->response_msg.msg.set_complete;
598 if (set_complete->status != RNDIS_STATUS_SUCCESS) {
599 netdev_err(ndev, "Fail to set MAC on host side:0x%x\n",
600 set_complete->status);
606 put_rndis_request(rdev, request);
610 int rndis_filter_set_offload_params(struct hv_device *hdev,
611 struct ndis_offload_params *req_offloads)
613 struct netvsc_device *nvdev = hv_get_drvdata(hdev);
614 struct rndis_device *rdev = nvdev->extension;
615 struct net_device *ndev = nvdev->ndev;
616 struct rndis_request *request;
617 struct rndis_set_request *set;
618 struct ndis_offload_params *offload_params;
619 struct rndis_set_complete *set_complete;
620 u32 extlen = sizeof(struct ndis_offload_params);
623 request = get_rndis_request(rdev, RNDIS_MSG_SET,
624 RNDIS_MESSAGE_SIZE(struct rndis_set_request) + extlen);
628 set = &request->request_msg.msg.set_req;
629 set->oid = OID_TCP_OFFLOAD_PARAMETERS;
630 set->info_buflen = extlen;
631 set->info_buf_offset = sizeof(struct rndis_set_request);
632 set->dev_vc_handle = 0;
634 offload_params = (struct ndis_offload_params *)((ulong)set +
635 set->info_buf_offset);
636 *offload_params = *req_offloads;
637 offload_params->header.type = NDIS_OBJECT_TYPE_DEFAULT;
638 offload_params->header.revision = NDIS_OFFLOAD_PARAMETERS_REVISION_3;
639 offload_params->header.size = extlen;
641 ret = rndis_filter_send_request(rdev, request);
645 t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
647 netdev_err(ndev, "timeout before we got aOFFLOAD set response...\n");
648 /* can't put_rndis_request, since we may still receive a
653 set_complete = &request->response_msg.msg.set_complete;
654 if (set_complete->status != RNDIS_STATUS_SUCCESS) {
655 netdev_err(ndev, "Fail to set MAC on host side:0x%x\n",
656 set_complete->status);
662 put_rndis_request(rdev, request);
666 static int rndis_filter_query_device_link_status(struct rndis_device *dev)
668 u32 size = sizeof(u32);
672 ret = rndis_filter_query_device(dev,
673 RNDIS_OID_GEN_MEDIA_CONNECT_STATUS,
674 &link_status, &size);
675 dev->link_state = (link_status != 0) ? true : false;
680 int rndis_filter_set_packet_filter(struct rndis_device *dev, u32 new_filter)
682 struct rndis_request *request;
683 struct rndis_set_request *set;
684 struct rndis_set_complete *set_complete;
687 struct net_device *ndev;
689 ndev = dev->net_dev->ndev;
691 request = get_rndis_request(dev, RNDIS_MSG_SET,
692 RNDIS_MESSAGE_SIZE(struct rndis_set_request) +
699 /* Setup the rndis set */
700 set = &request->request_msg.msg.set_req;
701 set->oid = RNDIS_OID_GEN_CURRENT_PACKET_FILTER;
702 set->info_buflen = sizeof(u32);
703 set->info_buf_offset = sizeof(struct rndis_set_request);
705 memcpy((void *)(unsigned long)set + sizeof(struct rndis_set_request),
706 &new_filter, sizeof(u32));
708 ret = rndis_filter_send_request(dev, request);
712 t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
716 "timeout before we got a set response...\n");
719 * We can't deallocate the request since we may still receive a
720 * send completion for it.
724 set_complete = &request->response_msg.msg.set_complete;
725 status = set_complete->status;
730 put_rndis_request(dev, request);
736 static int rndis_filter_init_device(struct rndis_device *dev)
738 struct rndis_request *request;
739 struct rndis_initialize_request *init;
740 struct rndis_initialize_complete *init_complete;
744 request = get_rndis_request(dev, RNDIS_MSG_INIT,
745 RNDIS_MESSAGE_SIZE(struct rndis_initialize_request));
751 /* Setup the rndis set */
752 init = &request->request_msg.msg.init_req;
753 init->major_ver = RNDIS_MAJOR_VERSION;
754 init->minor_ver = RNDIS_MINOR_VERSION;
755 init->max_xfer_size = 0x4000;
757 dev->state = RNDIS_DEV_INITIALIZING;
759 ret = rndis_filter_send_request(dev, request);
761 dev->state = RNDIS_DEV_UNINITIALIZED;
766 t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
773 init_complete = &request->response_msg.msg.init_complete;
774 status = init_complete->status;
775 if (status == RNDIS_STATUS_SUCCESS) {
776 dev->state = RNDIS_DEV_INITIALIZED;
779 dev->state = RNDIS_DEV_UNINITIALIZED;
785 put_rndis_request(dev, request);
790 static void rndis_filter_halt_device(struct rndis_device *dev)
792 struct rndis_request *request;
793 struct rndis_halt_request *halt;
794 struct netvsc_device *nvdev = dev->net_dev;
795 struct hv_device *hdev = nvdev->dev;
798 /* Attempt to do a rndis device halt */
799 request = get_rndis_request(dev, RNDIS_MSG_HALT,
800 RNDIS_MESSAGE_SIZE(struct rndis_halt_request));
804 /* Setup the rndis set */
805 halt = &request->request_msg.msg.halt_req;
806 halt->req_id = atomic_inc_return(&dev->new_req_id);
808 /* Ignore return since this msg is optional. */
809 rndis_filter_send_request(dev, request);
811 dev->state = RNDIS_DEV_UNINITIALIZED;
814 spin_lock_irqsave(&hdev->channel->inbound_lock, flags);
815 nvdev->destroy = true;
816 spin_unlock_irqrestore(&hdev->channel->inbound_lock, flags);
818 /* Wait for all send completions */
819 wait_event(nvdev->wait_drain,
820 atomic_read(&nvdev->num_outstanding_sends) == 0);
823 put_rndis_request(dev, request);
827 static int rndis_filter_open_device(struct rndis_device *dev)
831 if (dev->state != RNDIS_DEV_INITIALIZED)
834 ret = rndis_filter_set_packet_filter(dev,
835 NDIS_PACKET_TYPE_BROADCAST |
836 NDIS_PACKET_TYPE_ALL_MULTICAST |
837 NDIS_PACKET_TYPE_DIRECTED);
839 dev->state = RNDIS_DEV_DATAINITIALIZED;
844 static int rndis_filter_close_device(struct rndis_device *dev)
848 if (dev->state != RNDIS_DEV_DATAINITIALIZED)
851 ret = rndis_filter_set_packet_filter(dev, 0);
853 dev->state = RNDIS_DEV_INITIALIZED;
858 int rndis_filter_device_add(struct hv_device *dev,
859 void *additional_info)
862 struct netvsc_device *net_device;
863 struct rndis_device *rndis_device;
864 struct netvsc_device_info *device_info = additional_info;
865 struct ndis_offload_params offloads;
867 rndis_device = get_rndis_device();
872 * Let the inner driver handle this first to create the netvsc channel
873 * NOTE! Once the channel is created, we may get a receive callback
874 * (RndisFilterOnReceive()) before this call is completed
876 ret = netvsc_device_add(dev, additional_info);
883 /* Initialize the rndis device */
884 net_device = hv_get_drvdata(dev);
886 net_device->extension = rndis_device;
887 rndis_device->net_dev = net_device;
889 /* Send the rndis initialization message */
890 ret = rndis_filter_init_device(rndis_device);
892 rndis_filter_device_remove(dev);
896 /* Get the mac address */
897 ret = rndis_filter_query_device_mac(rndis_device);
899 rndis_filter_device_remove(dev);
903 memcpy(device_info->mac_adr, rndis_device->hw_mac_adr, ETH_ALEN);
905 /* Turn on the offloads; the host supports all of the relevant
908 memset(&offloads, 0, sizeof(struct ndis_offload_params));
909 /* A value of zero means "no change"; now turn on what we
912 offloads.ip_v4_csum = NDIS_OFFLOAD_PARAMETERS_TX_RX_ENABLED;
913 offloads.tcp_ip_v4_csum = NDIS_OFFLOAD_PARAMETERS_TX_RX_ENABLED;
914 offloads.udp_ip_v4_csum = NDIS_OFFLOAD_PARAMETERS_TX_RX_ENABLED;
915 offloads.tcp_ip_v6_csum = NDIS_OFFLOAD_PARAMETERS_TX_RX_ENABLED;
916 offloads.udp_ip_v6_csum = NDIS_OFFLOAD_PARAMETERS_TX_RX_ENABLED;
917 offloads.lso_v2_ipv4 = NDIS_OFFLOAD_PARAMETERS_LSOV2_ENABLED;
920 ret = rndis_filter_set_offload_params(dev, &offloads);
925 rndis_filter_query_device_link_status(rndis_device);
927 device_info->link_state = rndis_device->link_state;
929 dev_info(&dev->device, "Device MAC %pM link state %s\n",
930 rndis_device->hw_mac_adr,
931 device_info->link_state ? "down" : "up");
936 rndis_filter_device_remove(dev);
940 void rndis_filter_device_remove(struct hv_device *dev)
942 struct netvsc_device *net_dev = hv_get_drvdata(dev);
943 struct rndis_device *rndis_dev = net_dev->extension;
945 /* Halt and release the rndis device */
946 rndis_filter_halt_device(rndis_dev);
949 net_dev->extension = NULL;
951 netvsc_device_remove(dev);
955 int rndis_filter_open(struct hv_device *dev)
957 struct netvsc_device *net_device = hv_get_drvdata(dev);
962 return rndis_filter_open_device(net_device->extension);
965 int rndis_filter_close(struct hv_device *dev)
967 struct netvsc_device *nvdev = hv_get_drvdata(dev);
972 return rndis_filter_close_device(nvdev->extension);