blob: aee7b581e88313b6a5247e4666ad41b0e12b5dfc [file] [log] [blame]
David Brownell45fe3b82008-06-19 18:20:04 -07001/*
2 * f_rndis.c -- RNDIS link function driver
3 *
4 * Copyright (C) 2003-2005,2008 David Brownell
5 * Copyright (C) 2003-2004 Robert Schwebel, Benedikt Spranger
6 * Copyright (C) 2008 Nokia Corporation
Michal Nazarewiczb97503f2009-10-28 16:57:30 +01007 * Copyright (C) 2009 Samsung Electronics
Michal Nazarewicz54b83602012-01-13 15:05:16 +01008 * Author: Michal Nazarewicz (mina86@mina86.com)
David Brownell45fe3b82008-06-19 18:20:04 -07009 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
David Brownell45fe3b82008-06-19 18:20:04 -070014 */
15
16/* #define VERBOSE_DEBUG */
17
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090018#include <linux/slab.h>
David Brownell45fe3b82008-06-19 18:20:04 -070019#include <linux/kernel.h>
20#include <linux/device.h>
21#include <linux/etherdevice.h>
22
Arun Sharma60063492011-07-26 16:09:06 -070023#include <linux/atomic.h>
David Brownell45fe3b82008-06-19 18:20:04 -070024
25#include "u_ether.h"
26#include "rndis.h"
27
David Brownell45fe3b82008-06-19 18:20:04 -070028/*
29 * This function is an RNDIS Ethernet port -- a Microsoft protocol that's
30 * been promoted instead of the standard CDC Ethernet. The published RNDIS
31 * spec is ambiguous, incomplete, and needlessly complex. Variants such as
32 * ActiveSync have even worse status in terms of specification.
33 *
34 * In short: it's a protocol controlled by (and for) Microsoft, not for an
35 * Open ecosystem or markets. Linux supports it *only* because Microsoft
36 * doesn't support the CDC Ethernet standard.
37 *
38 * The RNDIS data transfer model is complex, with multiple Ethernet packets
39 * per USB message, and out of band data. The control model is built around
40 * what's essentially an "RNDIS RPC" protocol. It's all wrapped in a CDC ACM
41 * (modem, not Ethernet) veneer, with those ACM descriptors being entirely
42 * useless (they're ignored). RNDIS expects to be the only function in its
43 * configuration, so it's no real help if you need composite devices; and
44 * it expects to be the first configuration too.
45 *
46 * There is a single technical advantage of RNDIS over CDC Ethernet, if you
47 * discount the fluff that its RPC can be made to deliver: it doesn't need
48 * a NOP altsetting for the data interface. That lets it work on some of the
49 * "so smart it's stupid" hardware which takes over configuration changes
50 * from the software, and adds restrictions like "no altsettings".
51 *
52 * Unfortunately MSFT's RNDIS drivers are buggy. They hang or oops, and
53 * have all sorts of contrary-to-specification oddities that can prevent
54 * them from working sanely. Since bugfixes (or accurate specs, letting
55 * Linux work around those bugs) are unlikely to ever come from MSFT, you
56 * may want to avoid using RNDIS on purely operational grounds.
57 *
58 * Omissions from the RNDIS 1.0 specification include:
59 *
60 * - Power management ... references data that's scattered around lots
61 * of other documentation, which is incorrect/incomplete there too.
62 *
63 * - There are various undocumented protocol requirements, like the need
64 * to send garbage in some control-OUT messages.
65 *
66 * - MS-Windows drivers sometimes emit undocumented requests.
67 */
68
Vijayavardhan Vennapusac76dced2013-05-27 15:00:52 +053069static unsigned int rndis_dl_max_pkt_per_xfer = 3;
70module_param(rndis_dl_max_pkt_per_xfer, uint, S_IRUGO | S_IWUSR);
71MODULE_PARM_DESC(rndis_dl_max_pkt_per_xfer,
72 "Maximum packets per transfer for DL aggregation");
Vamsi Krishna7f21ac82013-04-17 21:41:33 -070073
Vamsi Krishna39f8c462013-05-15 14:10:27 -070074static unsigned int rndis_ul_max_pkt_per_xfer = 3;
Vamsi Krishna7f21ac82013-04-17 21:41:33 -070075module_param(rndis_ul_max_pkt_per_xfer, uint, S_IRUGO | S_IWUSR);
76MODULE_PARM_DESC(rndis_ul_max_pkt_per_xfer,
Vamsi Krishna915ae192013-05-13 15:39:56 -070077 "Maximum packets per transfer for UL aggregation");
Vamsi Krishna7f21ac82013-04-17 21:41:33 -070078
David Brownell45fe3b82008-06-19 18:20:04 -070079struct f_rndis {
80 struct gether port;
81 u8 ctrl_id, data_id;
82 u8 ethaddr[ETH_ALEN];
Benoit Gobyda8a44a2011-12-16 20:00:01 -080083 u32 vendorID;
84 const char *manufacturer;
David Brownell45fe3b82008-06-19 18:20:04 -070085 int config;
86
David Brownell45fe3b82008-06-19 18:20:04 -070087 struct usb_ep *notify;
David Brownell45fe3b82008-06-19 18:20:04 -070088 struct usb_request *notify_req;
89 atomic_t notify_count;
90};
91
92static inline struct f_rndis *func_to_rndis(struct usb_function *f)
93{
94 return container_of(f, struct f_rndis, port.func);
95}
96
97/* peak (theoretical) bulk transfer rate in bits-per-second */
98static unsigned int bitrate(struct usb_gadget *g)
99{
Paul Zimmerman04617db2011-06-27 14:13:18 -0700100 if (gadget_is_superspeed(g) && g->speed == USB_SPEED_SUPER)
101 return 13 * 1024 * 8 * 1000 * 8;
102 else if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
David Brownell45fe3b82008-06-19 18:20:04 -0700103 return 13 * 512 * 8 * 1000 * 8;
104 else
Paul Zimmerman04617db2011-06-27 14:13:18 -0700105 return 19 * 64 * 1 * 1000 * 8;
David Brownell45fe3b82008-06-19 18:20:04 -0700106}
107
108/*-------------------------------------------------------------------------*/
109
110/*
111 */
112
113#define LOG2_STATUS_INTERVAL_MSEC 5 /* 1 << 5 == 32 msec */
114#define STATUS_BYTECOUNT 8 /* 8 bytes data */
115
116
117/* interface descriptor: */
118
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200119static struct usb_interface_descriptor rndis_control_intf = {
David Brownell45fe3b82008-06-19 18:20:04 -0700120 .bLength = sizeof rndis_control_intf,
121 .bDescriptorType = USB_DT_INTERFACE,
122
123 /* .bInterfaceNumber = DYNAMIC */
124 /* status endpoint is optional; this could be patched later */
125 .bNumEndpoints = 1,
126 .bInterfaceClass = USB_CLASS_COMM,
127 .bInterfaceSubClass = USB_CDC_SUBCLASS_ACM,
128 .bInterfaceProtocol = USB_CDC_ACM_PROTO_VENDOR,
129 /* .iInterface = DYNAMIC */
130};
131
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200132static struct usb_cdc_header_desc header_desc = {
David Brownell45fe3b82008-06-19 18:20:04 -0700133 .bLength = sizeof header_desc,
134 .bDescriptorType = USB_DT_CS_INTERFACE,
135 .bDescriptorSubType = USB_CDC_HEADER_TYPE,
136
Harvey Harrison551509d2009-02-11 14:11:36 -0800137 .bcdCDC = cpu_to_le16(0x0110),
David Brownell45fe3b82008-06-19 18:20:04 -0700138};
139
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200140static struct usb_cdc_call_mgmt_descriptor call_mgmt_descriptor = {
David Brownell45fe3b82008-06-19 18:20:04 -0700141 .bLength = sizeof call_mgmt_descriptor,
142 .bDescriptorType = USB_DT_CS_INTERFACE,
143 .bDescriptorSubType = USB_CDC_CALL_MANAGEMENT_TYPE,
144
145 .bmCapabilities = 0x00,
146 .bDataInterface = 0x01,
147};
148
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200149static struct usb_cdc_acm_descriptor rndis_acm_descriptor = {
Michal Nazarewiczb97503f2009-10-28 16:57:30 +0100150 .bLength = sizeof rndis_acm_descriptor,
David Brownell45fe3b82008-06-19 18:20:04 -0700151 .bDescriptorType = USB_DT_CS_INTERFACE,
152 .bDescriptorSubType = USB_CDC_ACM_TYPE,
153
154 .bmCapabilities = 0x00,
155};
156
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200157static struct usb_cdc_union_desc rndis_union_desc = {
David Brownell45fe3b82008-06-19 18:20:04 -0700158 .bLength = sizeof(rndis_union_desc),
159 .bDescriptorType = USB_DT_CS_INTERFACE,
160 .bDescriptorSubType = USB_CDC_UNION_TYPE,
161 /* .bMasterInterface0 = DYNAMIC */
162 /* .bSlaveInterface0 = DYNAMIC */
163};
164
165/* the data interface has two bulk endpoints */
166
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200167static struct usb_interface_descriptor rndis_data_intf = {
David Brownell45fe3b82008-06-19 18:20:04 -0700168 .bLength = sizeof rndis_data_intf,
169 .bDescriptorType = USB_DT_INTERFACE,
170
171 /* .bInterfaceNumber = DYNAMIC */
David Brownell45fe3b82008-06-19 18:20:04 -0700172 .bNumEndpoints = 2,
173 .bInterfaceClass = USB_CLASS_CDC_DATA,
174 .bInterfaceSubClass = 0,
175 .bInterfaceProtocol = 0,
176 /* .iInterface = DYNAMIC */
177};
178
Michal Nazarewiczb97503f2009-10-28 16:57:30 +0100179
180static struct usb_interface_assoc_descriptor
181rndis_iad_descriptor = {
182 .bLength = sizeof rndis_iad_descriptor,
183 .bDescriptorType = USB_DT_INTERFACE_ASSOCIATION,
184
185 .bFirstInterface = 0, /* XXX, hardcoded */
186 .bInterfaceCount = 2, // control + data
187 .bFunctionClass = USB_CLASS_COMM,
188 .bFunctionSubClass = USB_CDC_SUBCLASS_ETHERNET,
189 .bFunctionProtocol = USB_CDC_PROTO_NONE,
190 /* .iFunction = DYNAMIC */
191};
192
David Brownell45fe3b82008-06-19 18:20:04 -0700193/* full speed support: */
194
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200195static struct usb_endpoint_descriptor fs_notify_desc = {
David Brownell45fe3b82008-06-19 18:20:04 -0700196 .bLength = USB_DT_ENDPOINT_SIZE,
197 .bDescriptorType = USB_DT_ENDPOINT,
198
199 .bEndpointAddress = USB_DIR_IN,
200 .bmAttributes = USB_ENDPOINT_XFER_INT,
Harvey Harrison551509d2009-02-11 14:11:36 -0800201 .wMaxPacketSize = cpu_to_le16(STATUS_BYTECOUNT),
David Brownell45fe3b82008-06-19 18:20:04 -0700202 .bInterval = 1 << LOG2_STATUS_INTERVAL_MSEC,
203};
204
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200205static struct usb_endpoint_descriptor fs_in_desc = {
David Brownell45fe3b82008-06-19 18:20:04 -0700206 .bLength = USB_DT_ENDPOINT_SIZE,
207 .bDescriptorType = USB_DT_ENDPOINT,
208
209 .bEndpointAddress = USB_DIR_IN,
210 .bmAttributes = USB_ENDPOINT_XFER_BULK,
211};
212
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200213static struct usb_endpoint_descriptor fs_out_desc = {
David Brownell45fe3b82008-06-19 18:20:04 -0700214 .bLength = USB_DT_ENDPOINT_SIZE,
215 .bDescriptorType = USB_DT_ENDPOINT,
216
217 .bEndpointAddress = USB_DIR_OUT,
218 .bmAttributes = USB_ENDPOINT_XFER_BULK,
219};
220
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200221static struct usb_descriptor_header *eth_fs_function[] = {
Michal Nazarewiczb97503f2009-10-28 16:57:30 +0100222 (struct usb_descriptor_header *) &rndis_iad_descriptor,
Paul Zimmerman04617db2011-06-27 14:13:18 -0700223
David Brownell45fe3b82008-06-19 18:20:04 -0700224 /* control interface matches ACM, not Ethernet */
225 (struct usb_descriptor_header *) &rndis_control_intf,
226 (struct usb_descriptor_header *) &header_desc,
227 (struct usb_descriptor_header *) &call_mgmt_descriptor,
Michal Nazarewiczb97503f2009-10-28 16:57:30 +0100228 (struct usb_descriptor_header *) &rndis_acm_descriptor,
David Brownell45fe3b82008-06-19 18:20:04 -0700229 (struct usb_descriptor_header *) &rndis_union_desc,
230 (struct usb_descriptor_header *) &fs_notify_desc,
Paul Zimmerman04617db2011-06-27 14:13:18 -0700231
David Brownell45fe3b82008-06-19 18:20:04 -0700232 /* data interface has no altsetting */
233 (struct usb_descriptor_header *) &rndis_data_intf,
234 (struct usb_descriptor_header *) &fs_in_desc,
235 (struct usb_descriptor_header *) &fs_out_desc,
236 NULL,
237};
238
239/* high speed support: */
240
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200241static struct usb_endpoint_descriptor hs_notify_desc = {
David Brownell45fe3b82008-06-19 18:20:04 -0700242 .bLength = USB_DT_ENDPOINT_SIZE,
243 .bDescriptorType = USB_DT_ENDPOINT,
244
245 .bEndpointAddress = USB_DIR_IN,
246 .bmAttributes = USB_ENDPOINT_XFER_INT,
Harvey Harrison551509d2009-02-11 14:11:36 -0800247 .wMaxPacketSize = cpu_to_le16(STATUS_BYTECOUNT),
David Brownell45fe3b82008-06-19 18:20:04 -0700248 .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4,
249};
Paul Zimmerman04617db2011-06-27 14:13:18 -0700250
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200251static struct usb_endpoint_descriptor hs_in_desc = {
David Brownell45fe3b82008-06-19 18:20:04 -0700252 .bLength = USB_DT_ENDPOINT_SIZE,
253 .bDescriptorType = USB_DT_ENDPOINT,
254
255 .bEndpointAddress = USB_DIR_IN,
256 .bmAttributes = USB_ENDPOINT_XFER_BULK,
Harvey Harrison551509d2009-02-11 14:11:36 -0800257 .wMaxPacketSize = cpu_to_le16(512),
David Brownell45fe3b82008-06-19 18:20:04 -0700258};
259
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200260static struct usb_endpoint_descriptor hs_out_desc = {
David Brownell45fe3b82008-06-19 18:20:04 -0700261 .bLength = USB_DT_ENDPOINT_SIZE,
262 .bDescriptorType = USB_DT_ENDPOINT,
263
264 .bEndpointAddress = USB_DIR_OUT,
265 .bmAttributes = USB_ENDPOINT_XFER_BULK,
Harvey Harrison551509d2009-02-11 14:11:36 -0800266 .wMaxPacketSize = cpu_to_le16(512),
David Brownell45fe3b82008-06-19 18:20:04 -0700267};
268
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200269static struct usb_descriptor_header *eth_hs_function[] = {
Michal Nazarewiczb97503f2009-10-28 16:57:30 +0100270 (struct usb_descriptor_header *) &rndis_iad_descriptor,
Paul Zimmerman04617db2011-06-27 14:13:18 -0700271
David Brownell45fe3b82008-06-19 18:20:04 -0700272 /* control interface matches ACM, not Ethernet */
273 (struct usb_descriptor_header *) &rndis_control_intf,
274 (struct usb_descriptor_header *) &header_desc,
275 (struct usb_descriptor_header *) &call_mgmt_descriptor,
Michal Nazarewiczb97503f2009-10-28 16:57:30 +0100276 (struct usb_descriptor_header *) &rndis_acm_descriptor,
David Brownell45fe3b82008-06-19 18:20:04 -0700277 (struct usb_descriptor_header *) &rndis_union_desc,
278 (struct usb_descriptor_header *) &hs_notify_desc,
Paul Zimmerman04617db2011-06-27 14:13:18 -0700279
David Brownell45fe3b82008-06-19 18:20:04 -0700280 /* data interface has no altsetting */
281 (struct usb_descriptor_header *) &rndis_data_intf,
282 (struct usb_descriptor_header *) &hs_in_desc,
283 (struct usb_descriptor_header *) &hs_out_desc,
284 NULL,
285};
286
Paul Zimmerman04617db2011-06-27 14:13:18 -0700287/* super speed support: */
288
289static struct usb_endpoint_descriptor ss_notify_desc = {
290 .bLength = USB_DT_ENDPOINT_SIZE,
291 .bDescriptorType = USB_DT_ENDPOINT,
292
293 .bEndpointAddress = USB_DIR_IN,
294 .bmAttributes = USB_ENDPOINT_XFER_INT,
295 .wMaxPacketSize = cpu_to_le16(STATUS_BYTECOUNT),
296 .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4,
297};
298
299static struct usb_ss_ep_comp_descriptor ss_intr_comp_desc = {
300 .bLength = sizeof ss_intr_comp_desc,
301 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
302
303 /* the following 3 values can be tweaked if necessary */
304 /* .bMaxBurst = 0, */
305 /* .bmAttributes = 0, */
306 .wBytesPerInterval = cpu_to_le16(STATUS_BYTECOUNT),
307};
308
309static struct usb_endpoint_descriptor ss_in_desc = {
310 .bLength = USB_DT_ENDPOINT_SIZE,
311 .bDescriptorType = USB_DT_ENDPOINT,
312
313 .bEndpointAddress = USB_DIR_IN,
314 .bmAttributes = USB_ENDPOINT_XFER_BULK,
315 .wMaxPacketSize = cpu_to_le16(1024),
316};
317
318static struct usb_endpoint_descriptor ss_out_desc = {
319 .bLength = USB_DT_ENDPOINT_SIZE,
320 .bDescriptorType = USB_DT_ENDPOINT,
321
322 .bEndpointAddress = USB_DIR_OUT,
323 .bmAttributes = USB_ENDPOINT_XFER_BULK,
324 .wMaxPacketSize = cpu_to_le16(1024),
325};
326
327static struct usb_ss_ep_comp_descriptor ss_bulk_comp_desc = {
328 .bLength = sizeof ss_bulk_comp_desc,
329 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
330
331 /* the following 2 values can be tweaked if necessary */
332 /* .bMaxBurst = 0, */
333 /* .bmAttributes = 0, */
334};
335
336static struct usb_descriptor_header *eth_ss_function[] = {
337 (struct usb_descriptor_header *) &rndis_iad_descriptor,
338
339 /* control interface matches ACM, not Ethernet */
340 (struct usb_descriptor_header *) &rndis_control_intf,
341 (struct usb_descriptor_header *) &header_desc,
342 (struct usb_descriptor_header *) &call_mgmt_descriptor,
343 (struct usb_descriptor_header *) &rndis_acm_descriptor,
344 (struct usb_descriptor_header *) &rndis_union_desc,
345 (struct usb_descriptor_header *) &ss_notify_desc,
346 (struct usb_descriptor_header *) &ss_intr_comp_desc,
347
348 /* data interface has no altsetting */
349 (struct usb_descriptor_header *) &rndis_data_intf,
350 (struct usb_descriptor_header *) &ss_in_desc,
351 (struct usb_descriptor_header *) &ss_bulk_comp_desc,
352 (struct usb_descriptor_header *) &ss_out_desc,
353 (struct usb_descriptor_header *) &ss_bulk_comp_desc,
354 NULL,
355};
356
David Brownell45fe3b82008-06-19 18:20:04 -0700357/* string descriptors: */
358
359static struct usb_string rndis_string_defs[] = {
360 [0].s = "RNDIS Communications Control",
361 [1].s = "RNDIS Ethernet Data",
Michal Nazarewiczb97503f2009-10-28 16:57:30 +0100362 [2].s = "RNDIS",
David Brownell45fe3b82008-06-19 18:20:04 -0700363 { } /* end of list */
364};
365
366static struct usb_gadget_strings rndis_string_table = {
367 .language = 0x0409, /* en-us */
368 .strings = rndis_string_defs,
369};
370
371static struct usb_gadget_strings *rndis_strings[] = {
372 &rndis_string_table,
373 NULL,
374};
375
376/*-------------------------------------------------------------------------*/
377
Brian Niebuhr9b39e9d2009-08-14 10:04:22 -0500378static struct sk_buff *rndis_add_header(struct gether *port,
379 struct sk_buff *skb)
David Brownell45fe3b82008-06-19 18:20:04 -0700380{
Brian Niebuhr9b39e9d2009-08-14 10:04:22 -0500381 struct sk_buff *skb2;
Mayank Rana9a42ad22013-09-30 16:51:14 +0530382 struct rndis_packet_msg_type *header = NULL;
383 struct f_rndis *rndis = func_to_rndis(&port->func);
Brian Niebuhr9b39e9d2009-08-14 10:04:22 -0500384
Mayank Rana9a42ad22013-09-30 16:51:14 +0530385 if (rndis->port.multi_pkt_xfer) {
386 if (port->header) {
387 header = port->header;
388 memset(header, 0, sizeof(*header));
389 header->MessageType = cpu_to_le32(REMOTE_NDIS_PACKET_MSG);
390 header->MessageLength = cpu_to_le32(skb->len +
391 sizeof(*header));
392 header->DataOffset = cpu_to_le32(36);
393 header->DataLength = cpu_to_le32(skb->len);
394 pr_debug("MessageLength:%d DataLength:%d\n",
395 header->MessageLength,
396 header->DataLength);
397 return skb;
398 } else {
399 pr_err("RNDIS header is NULL.\n");
400 return NULL;
401 }
402 } else {
403 skb2 = skb_realloc_headroom(skb,
404 sizeof(struct rndis_packet_msg_type));
405 if (skb2)
406 rndis_add_hdr(skb2);
Brian Niebuhr9b39e9d2009-08-14 10:04:22 -0500407
Mayank Rana9a42ad22013-09-30 16:51:14 +0530408 dev_kfree_skb_any(skb);
409 return skb2;
410 }
David Brownell45fe3b82008-06-19 18:20:04 -0700411}
412
413static void rndis_response_available(void *_rndis)
414{
415 struct f_rndis *rndis = _rndis;
416 struct usb_request *req = rndis->notify_req;
417 struct usb_composite_dev *cdev = rndis->port.func.config->cdev;
418 __le32 *data = req->buf;
419 int status;
420
Richard Röjforsff349502008-11-15 19:53:24 -0800421 if (atomic_inc_return(&rndis->notify_count) != 1)
David Brownell45fe3b82008-06-19 18:20:04 -0700422 return;
423
424 /* Send RNDIS RESPONSE_AVAILABLE notification; a
425 * USB_CDC_NOTIFY_RESPONSE_AVAILABLE "should" work too
426 *
427 * This is the only notification defined by RNDIS.
428 */
429 data[0] = cpu_to_le32(1);
430 data[1] = cpu_to_le32(0);
431
432 status = usb_ep_queue(rndis->notify, req, GFP_ATOMIC);
433 if (status) {
434 atomic_dec(&rndis->notify_count);
435 DBG(cdev, "notify/0 --> %d\n", status);
436 }
437}
438
439static void rndis_response_complete(struct usb_ep *ep, struct usb_request *req)
440{
441 struct f_rndis *rndis = req->context;
Chiranjeevi Velempati46874732013-01-31 14:35:46 +0530442 struct usb_composite_dev *cdev;
David Brownell45fe3b82008-06-19 18:20:04 -0700443 int status = req->status;
444
Chiranjeevi Velempati46874732013-01-31 14:35:46 +0530445 if (!rndis->port.func.config || !rndis->port.func.config->cdev)
446 return;
447 else
448 cdev = rndis->port.func.config->cdev;
449
David Brownell45fe3b82008-06-19 18:20:04 -0700450 /* after TX:
451 * - USB_CDC_GET_ENCAPSULATED_RESPONSE (ep0/control)
452 * - RNDIS_RESPONSE_AVAILABLE (status/irq)
453 */
454 switch (status) {
455 case -ECONNRESET:
456 case -ESHUTDOWN:
457 /* connection gone */
458 atomic_set(&rndis->notify_count, 0);
459 break;
460 default:
461 DBG(cdev, "RNDIS %s response error %d, %d/%d\n",
462 ep->name, status,
463 req->actual, req->length);
464 /* FALLTHROUGH */
465 case 0:
466 if (ep != rndis->notify)
467 break;
468
469 /* handle multiple pending RNDIS_RESPONSE_AVAILABLE
470 * notifications by resending until we're done
471 */
472 if (atomic_dec_and_test(&rndis->notify_count))
473 break;
474 status = usb_ep_queue(rndis->notify, req, GFP_ATOMIC);
475 if (status) {
476 atomic_dec(&rndis->notify_count);
477 DBG(cdev, "notify/1 --> %d\n", status);
478 }
479 break;
480 }
481}
482
483static void rndis_command_complete(struct usb_ep *ep, struct usb_request *req)
484{
485 struct f_rndis *rndis = req->context;
Chiranjeevi Velempati46874732013-01-31 14:35:46 +0530486 struct usb_composite_dev *cdev;
David Brownell45fe3b82008-06-19 18:20:04 -0700487 int status;
Mayank Rana5b165cb2012-05-25 19:52:45 +0530488 rndis_init_msg_type *buf;
David Brownell45fe3b82008-06-19 18:20:04 -0700489
Chiranjeevi Velempati46874732013-01-31 14:35:46 +0530490 if (!rndis->port.func.config || !rndis->port.func.config->cdev)
491 return;
492 else
493 cdev = rndis->port.func.config->cdev;
494
David Brownell45fe3b82008-06-19 18:20:04 -0700495 /* received RNDIS command from USB_CDC_SEND_ENCAPSULATED_COMMAND */
496// spin_lock(&dev->lock);
497 status = rndis_msg_parser(rndis->config, (u8 *) req->buf);
498 if (status < 0)
499 ERROR(cdev, "RNDIS command error %d, %d/%d\n",
500 status, req->actual, req->length);
Mayank Rana5b165cb2012-05-25 19:52:45 +0530501
502 buf = (rndis_init_msg_type *)req->buf;
503
504 if (buf->MessageType == REMOTE_NDIS_INITIALIZE_MSG) {
505 if (buf->MaxTransferSize > 2048)
506 rndis->port.multi_pkt_xfer = 1;
507 else
508 rndis->port.multi_pkt_xfer = 0;
509 DBG(cdev, "%s: MaxTransferSize: %d : Multi_pkt_txr: %s\n",
510 __func__, buf->MaxTransferSize,
511 rndis->port.multi_pkt_xfer ? "enabled" :
512 "disabled");
Vijayavardhan Vennapusac76dced2013-05-27 15:00:52 +0530513 if (rndis_dl_max_pkt_per_xfer <= 1)
Mayank Rana93df2752012-09-12 18:12:46 +0530514 rndis->port.multi_pkt_xfer = 0;
Mayank Rana5b165cb2012-05-25 19:52:45 +0530515 }
David Brownell45fe3b82008-06-19 18:20:04 -0700516// spin_unlock(&dev->lock);
517}
518
519static int
520rndis_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)
521{
522 struct f_rndis *rndis = func_to_rndis(f);
523 struct usb_composite_dev *cdev = f->config->cdev;
524 struct usb_request *req = cdev->req;
525 int value = -EOPNOTSUPP;
526 u16 w_index = le16_to_cpu(ctrl->wIndex);
527 u16 w_value = le16_to_cpu(ctrl->wValue);
528 u16 w_length = le16_to_cpu(ctrl->wLength);
529
530 /* composite driver infrastructure handles everything except
531 * CDC class messages; interface activation uses set_alt().
532 */
533 switch ((ctrl->bRequestType << 8) | ctrl->bRequest) {
534
535 /* RNDIS uses the CDC command encapsulation mechanism to implement
536 * an RPC scheme, with much getting/setting of attributes by OID.
537 */
538 case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
539 | USB_CDC_SEND_ENCAPSULATED_COMMAND:
Felipe Balbi472b9122011-05-13 16:53:48 +0300540 if (w_value || w_index != rndis->ctrl_id)
David Brownell45fe3b82008-06-19 18:20:04 -0700541 goto invalid;
542 /* read the request; process it later */
543 value = w_length;
544 req->complete = rndis_command_complete;
545 req->context = rndis;
546 /* later, rndis_response_available() sends a notification */
547 break;
548
549 case ((USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
550 | USB_CDC_GET_ENCAPSULATED_RESPONSE:
551 if (w_value || w_index != rndis->ctrl_id)
552 goto invalid;
553 else {
554 u8 *buf;
555 u32 n;
556
557 /* return the result */
558 buf = rndis_get_next_response(rndis->config, &n);
559 if (buf) {
560 memcpy(req->buf, buf, n);
561 req->complete = rndis_response_complete;
Lukasz Majewskif1356172012-02-10 09:54:51 +0100562 req->context = rndis;
David Brownell45fe3b82008-06-19 18:20:04 -0700563 rndis_free_response(rndis->config, buf);
564 value = n;
565 }
566 /* else stalls ... spec says to avoid that */
567 }
568 break;
569
570 default:
571invalid:
572 VDBG(cdev, "invalid control req%02x.%02x v%04x i%04x l%d\n",
573 ctrl->bRequestType, ctrl->bRequest,
574 w_value, w_index, w_length);
575 }
576
577 /* respond with data transfer or status phase? */
578 if (value >= 0) {
579 DBG(cdev, "rndis req%02x.%02x v%04x i%04x l%d\n",
580 ctrl->bRequestType, ctrl->bRequest,
581 w_value, w_index, w_length);
David Brownell090b9012009-03-20 01:08:20 -0700582 req->zero = (value < w_length);
David Brownell45fe3b82008-06-19 18:20:04 -0700583 req->length = value;
584 value = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC);
585 if (value < 0)
586 ERROR(cdev, "rndis response on err %d\n", value);
587 }
588
589 /* device either stalls (value < 0) or reports success */
590 return value;
591}
592
593
594static int rndis_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
595{
596 struct f_rndis *rndis = func_to_rndis(f);
597 struct usb_composite_dev *cdev = f->config->cdev;
598
599 /* we know alt == 0 */
600
601 if (intf == rndis->ctrl_id) {
602 if (rndis->notify->driver_data) {
603 VDBG(cdev, "reset rndis control %d\n", intf);
604 usb_ep_disable(rndis->notify);
Tatyana Brokhmanea2a1df72011-06-28 16:33:50 +0300605 }
606 if (!rndis->notify->desc) {
David Brownell45fe3b82008-06-19 18:20:04 -0700607 VDBG(cdev, "init rndis ctrl %d\n", intf);
Tatyana Brokhmanea2a1df72011-06-28 16:33:50 +0300608 if (config_ep_by_speed(cdev->gadget, f, rndis->notify))
609 goto fail;
David Brownell45fe3b82008-06-19 18:20:04 -0700610 }
Tatyana Brokhman72c973d2011-06-28 16:33:48 +0300611 usb_ep_enable(rndis->notify);
David Brownell45fe3b82008-06-19 18:20:04 -0700612 rndis->notify->driver_data = rndis;
613
614 } else if (intf == rndis->data_id) {
615 struct net_device *net;
616
617 if (rndis->port.in_ep->driver_data) {
618 DBG(cdev, "reset rndis\n");
619 gether_disconnect(&rndis->port);
Maulik Mankad830d1b12009-05-29 18:34:40 +0530620 }
621
Tatyana Brokhmanea2a1df72011-06-28 16:33:50 +0300622 if (!rndis->port.in_ep->desc || !rndis->port.out_ep->desc) {
David Brownell45fe3b82008-06-19 18:20:04 -0700623 DBG(cdev, "init rndis\n");
Tatyana Brokhmanea2a1df72011-06-28 16:33:50 +0300624 if (config_ep_by_speed(cdev->gadget, f,
625 rndis->port.in_ep) ||
626 config_ep_by_speed(cdev->gadget, f,
627 rndis->port.out_ep)) {
628 rndis->port.in_ep->desc = NULL;
629 rndis->port.out_ep->desc = NULL;
630 goto fail;
631 }
David Brownell45fe3b82008-06-19 18:20:04 -0700632 }
633
634 /* Avoid ZLPs; they can be troublesome. */
635 rndis->port.is_zlp_ok = false;
636
637 /* RNDIS should be in the "RNDIS uninitialized" state,
638 * either never activated or after rndis_uninit().
639 *
640 * We don't want data to flow here until a nonzero packet
641 * filter is set, at which point it enters "RNDIS data
642 * initialized" state ... but we do want the endpoints
643 * to be activated. It's a strange little state.
644 *
645 * REVISIT the RNDIS gadget code has done this wrong for a
646 * very long time. We need another call to the link layer
647 * code -- gether_updown(...bool) maybe -- to do it right.
648 */
649 rndis->port.cdc_filter = 0;
650
651 DBG(cdev, "RNDIS RX/TX early activation ... \n");
652 net = gether_connect(&rndis->port);
653 if (IS_ERR(net))
654 return PTR_ERR(net);
655
656 rndis_set_param_dev(rndis->config, net,
657 &rndis->port.cdc_filter);
658 } else
659 goto fail;
660
661 return 0;
662fail:
663 return -EINVAL;
664}
665
666static void rndis_disable(struct usb_function *f)
667{
668 struct f_rndis *rndis = func_to_rndis(f);
669 struct usb_composite_dev *cdev = f->config->cdev;
670
671 if (!rndis->notify->driver_data)
672 return;
673
674 DBG(cdev, "rndis deactivated\n");
675
676 rndis_uninit(rndis->config);
677 gether_disconnect(&rndis->port);
678
679 usb_ep_disable(rndis->notify);
680 rndis->notify->driver_data = NULL;
681}
682
683/*-------------------------------------------------------------------------*/
684
685/*
686 * This isn't quite the same mechanism as CDC Ethernet, since the
687 * notification scheme passes less data, but the same set of link
688 * states must be tested. A key difference is that altsettings are
689 * not used to tell whether the link should send packets or not.
690 */
691
692static void rndis_open(struct gether *geth)
693{
694 struct f_rndis *rndis = func_to_rndis(&geth->func);
695 struct usb_composite_dev *cdev = geth->func.config->cdev;
696
697 DBG(cdev, "%s\n", __func__);
698
699 rndis_set_param_medium(rndis->config, NDIS_MEDIUM_802_3,
700 bitrate(cdev->gadget) / 100);
701 rndis_signal_connect(rndis->config);
702}
703
704static void rndis_close(struct gether *geth)
705{
706 struct f_rndis *rndis = func_to_rndis(&geth->func);
707
708 DBG(geth->func.config->cdev, "%s\n", __func__);
709
710 rndis_set_param_medium(rndis->config, NDIS_MEDIUM_802_3, 0);
711 rndis_signal_disconnect(rndis->config);
712}
713
714/*-------------------------------------------------------------------------*/
715
716/* ethernet function driver setup/binding */
717
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200718static int
David Brownell45fe3b82008-06-19 18:20:04 -0700719rndis_bind(struct usb_configuration *c, struct usb_function *f)
720{
721 struct usb_composite_dev *cdev = c->cdev;
722 struct f_rndis *rndis = func_to_rndis(f);
723 int status;
724 struct usb_ep *ep;
725
726 /* allocate instance-specific interface IDs */
727 status = usb_interface_id(c, f);
728 if (status < 0)
729 goto fail;
730 rndis->ctrl_id = status;
Michal Nazarewiczb97503f2009-10-28 16:57:30 +0100731 rndis_iad_descriptor.bFirstInterface = status;
David Brownell45fe3b82008-06-19 18:20:04 -0700732
733 rndis_control_intf.bInterfaceNumber = status;
734 rndis_union_desc.bMasterInterface0 = status;
735
736 status = usb_interface_id(c, f);
737 if (status < 0)
738 goto fail;
739 rndis->data_id = status;
740
741 rndis_data_intf.bInterfaceNumber = status;
742 rndis_union_desc.bSlaveInterface0 = status;
743
744 status = -ENODEV;
745
746 /* allocate instance-specific endpoints */
747 ep = usb_ep_autoconfig(cdev->gadget, &fs_in_desc);
748 if (!ep)
749 goto fail;
750 rndis->port.in_ep = ep;
751 ep->driver_data = cdev; /* claim */
752
753 ep = usb_ep_autoconfig(cdev->gadget, &fs_out_desc);
754 if (!ep)
755 goto fail;
756 rndis->port.out_ep = ep;
757 ep->driver_data = cdev; /* claim */
758
759 /* NOTE: a status/notification endpoint is, strictly speaking,
760 * optional. We don't treat it that way though! It's simpler,
761 * and some newer profiles don't treat it as optional.
762 */
763 ep = usb_ep_autoconfig(cdev->gadget, &fs_notify_desc);
764 if (!ep)
765 goto fail;
766 rndis->notify = ep;
767 ep->driver_data = cdev; /* claim */
768
769 status = -ENOMEM;
770
771 /* allocate notification request and buffer */
772 rndis->notify_req = usb_ep_alloc_request(ep, GFP_KERNEL);
773 if (!rndis->notify_req)
774 goto fail;
775 rndis->notify_req->buf = kmalloc(STATUS_BYTECOUNT, GFP_KERNEL);
776 if (!rndis->notify_req->buf)
777 goto fail;
778 rndis->notify_req->length = STATUS_BYTECOUNT;
779 rndis->notify_req->context = rndis;
780 rndis->notify_req->complete = rndis_response_complete;
781
782 /* copy descriptors, and track endpoint copies */
783 f->descriptors = usb_copy_descriptors(eth_fs_function);
784 if (!f->descriptors)
785 goto fail;
786
David Brownell45fe3b82008-06-19 18:20:04 -0700787 /* support all relevant hardware speeds... we expect that when
788 * hardware is dual speed, all bulk-capable endpoints work at
789 * both speeds
790 */
791 if (gadget_is_dualspeed(c->cdev->gadget)) {
792 hs_in_desc.bEndpointAddress =
793 fs_in_desc.bEndpointAddress;
794 hs_out_desc.bEndpointAddress =
795 fs_out_desc.bEndpointAddress;
David Brownell7c124142008-11-24 23:11:03 -0800796 hs_notify_desc.bEndpointAddress =
797 fs_notify_desc.bEndpointAddress;
David Brownell45fe3b82008-06-19 18:20:04 -0700798
799 /* copy descriptors, and track endpoint copies */
800 f->hs_descriptors = usb_copy_descriptors(eth_hs_function);
David Brownell45fe3b82008-06-19 18:20:04 -0700801 if (!f->hs_descriptors)
802 goto fail;
David Brownell45fe3b82008-06-19 18:20:04 -0700803 }
804
Paul Zimmerman04617db2011-06-27 14:13:18 -0700805 if (gadget_is_superspeed(c->cdev->gadget)) {
806 ss_in_desc.bEndpointAddress =
807 fs_in_desc.bEndpointAddress;
808 ss_out_desc.bEndpointAddress =
809 fs_out_desc.bEndpointAddress;
810 ss_notify_desc.bEndpointAddress =
811 fs_notify_desc.bEndpointAddress;
812
813 /* copy descriptors, and track endpoint copies */
814 f->ss_descriptors = usb_copy_descriptors(eth_ss_function);
815 if (!f->ss_descriptors)
816 goto fail;
817 }
818
David Brownell45fe3b82008-06-19 18:20:04 -0700819 rndis->port.open = rndis_open;
820 rndis->port.close = rndis_close;
821
822 status = rndis_register(rndis_response_available, rndis);
823 if (status < 0)
824 goto fail;
825 rndis->config = status;
826
827 rndis_set_param_medium(rndis->config, NDIS_MEDIUM_802_3, 0);
828 rndis_set_host_mac(rndis->config, rndis->ethaddr);
Vamsi Krishna7f21ac82013-04-17 21:41:33 -0700829 rndis_set_max_pkt_xfer(rndis->config, rndis_ul_max_pkt_per_xfer);
David Brownell45fe3b82008-06-19 18:20:04 -0700830
Benoit Gobyda8a44a2011-12-16 20:00:01 -0800831 if (rndis->manufacturer && rndis->vendorID &&
832 rndis_set_param_vendor(rndis->config, rndis->vendorID,
833 rndis->manufacturer))
834 goto fail;
David Brownell45fe3b82008-06-19 18:20:04 -0700835
836 /* NOTE: all that is done without knowing or caring about
837 * the network link ... which is unavailable to this code
838 * until we're activated via set_alt().
839 */
840
841 DBG(cdev, "RNDIS: %s speed IN/%s OUT/%s NOTIFY/%s\n",
Paul Zimmerman04617db2011-06-27 14:13:18 -0700842 gadget_is_superspeed(c->cdev->gadget) ? "super" :
David Brownell45fe3b82008-06-19 18:20:04 -0700843 gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full",
844 rndis->port.in_ep->name, rndis->port.out_ep->name,
845 rndis->notify->name);
846 return 0;
847
848fail:
Paul Zimmerman04617db2011-06-27 14:13:18 -0700849 if (gadget_is_superspeed(c->cdev->gadget) && f->ss_descriptors)
850 usb_free_descriptors(f->ss_descriptors);
David Brownell45fe3b82008-06-19 18:20:04 -0700851 if (gadget_is_dualspeed(c->cdev->gadget) && f->hs_descriptors)
852 usb_free_descriptors(f->hs_descriptors);
853 if (f->descriptors)
854 usb_free_descriptors(f->descriptors);
855
856 if (rndis->notify_req) {
857 kfree(rndis->notify_req->buf);
858 usb_ep_free_request(rndis->notify, rndis->notify_req);
859 }
860
861 /* we might as well release our claims on endpoints */
862 if (rndis->notify)
863 rndis->notify->driver_data = NULL;
Tatyana Brokhman72c973d2011-06-28 16:33:48 +0300864 if (rndis->port.out_ep->desc)
David Brownell45fe3b82008-06-19 18:20:04 -0700865 rndis->port.out_ep->driver_data = NULL;
Tatyana Brokhman72c973d2011-06-28 16:33:48 +0300866 if (rndis->port.in_ep->desc)
David Brownell45fe3b82008-06-19 18:20:04 -0700867 rndis->port.in_ep->driver_data = NULL;
868
869 ERROR(cdev, "%s: can't bind, err %d\n", f->name, status);
870
871 return status;
872}
873
874static void
875rndis_unbind(struct usb_configuration *c, struct usb_function *f)
876{
877 struct f_rndis *rndis = func_to_rndis(f);
878
879 rndis_deregister(rndis->config);
880 rndis_exit();
881
Paul Zimmerman04617db2011-06-27 14:13:18 -0700882 if (gadget_is_superspeed(c->cdev->gadget))
883 usb_free_descriptors(f->ss_descriptors);
David Brownell45fe3b82008-06-19 18:20:04 -0700884 if (gadget_is_dualspeed(c->cdev->gadget))
885 usb_free_descriptors(f->hs_descriptors);
886 usb_free_descriptors(f->descriptors);
887
888 kfree(rndis->notify_req->buf);
889 usb_ep_free_request(rndis->notify, rndis->notify_req);
890
891 kfree(rndis);
892}
893
894/* Some controllers can't support RNDIS ... */
895static inline bool can_support_rndis(struct usb_configuration *c)
896{
David Brownell45fe3b82008-06-19 18:20:04 -0700897 /* everything else is *presumably* fine */
898 return true;
899}
900
901/**
902 * rndis_bind_config - add RNDIS network link to a configuration
903 * @c: the configuration to support the network link
904 * @ethaddr: a buffer in which the ethernet address of the host side
905 * side of the link was recorded
906 * Context: single threaded during gadget setup
907 *
908 * Returns zero on success, else negative errno.
909 *
910 * Caller must have called @gether_setup(). Caller is also responsible
911 * for calling @gether_cleanup() before module unload.
912 */
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200913int
914rndis_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
David Brownell45fe3b82008-06-19 18:20:04 -0700915{
Benoit Gobyda8a44a2011-12-16 20:00:01 -0800916 return rndis_bind_config_vendor(c, ethaddr, 0, NULL);
917}
918
919int
920rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
921 u32 vendorID, const char *manufacturer)
922{
David Brownell45fe3b82008-06-19 18:20:04 -0700923 struct f_rndis *rndis;
924 int status;
925
926 if (!can_support_rndis(c) || !ethaddr)
927 return -EINVAL;
928
Benoit Gobya6ccb732012-01-20 14:42:41 -0800929 /* setup RNDIS itself */
930 status = rndis_init();
931 if (status < 0)
932 return status;
933
David Brownell45fe3b82008-06-19 18:20:04 -0700934 /* maybe allocate device-global string IDs */
935 if (rndis_string_defs[0].id == 0) {
936
David Brownell45fe3b82008-06-19 18:20:04 -0700937 /* control interface label */
938 status = usb_string_id(c->cdev);
939 if (status < 0)
940 return status;
941 rndis_string_defs[0].id = status;
942 rndis_control_intf.iInterface = status;
943
944 /* data interface label */
945 status = usb_string_id(c->cdev);
946 if (status < 0)
947 return status;
948 rndis_string_defs[1].id = status;
949 rndis_data_intf.iInterface = status;
Michal Nazarewiczb97503f2009-10-28 16:57:30 +0100950
951 /* IAD iFunction label */
952 status = usb_string_id(c->cdev);
953 if (status < 0)
954 return status;
955 rndis_string_defs[2].id = status;
956 rndis_iad_descriptor.iFunction = status;
David Brownell45fe3b82008-06-19 18:20:04 -0700957 }
958
959 /* allocate and initialize one new instance */
960 status = -ENOMEM;
961 rndis = kzalloc(sizeof *rndis, GFP_KERNEL);
962 if (!rndis)
963 goto fail;
964
965 memcpy(rndis->ethaddr, ethaddr, ETH_ALEN);
Benoit Gobyda8a44a2011-12-16 20:00:01 -0800966 rndis->vendorID = vendorID;
967 rndis->manufacturer = manufacturer;
David Brownell45fe3b82008-06-19 18:20:04 -0700968
969 /* RNDIS activates when the host changes this filter */
970 rndis->port.cdc_filter = 0;
971
972 /* RNDIS has special (and complex) framing */
973 rndis->port.header_len = sizeof(struct rndis_packet_msg_type);
974 rndis->port.wrap = rndis_add_header;
975 rndis->port.unwrap = rndis_rm_hdr;
Vamsi Krishna7f21ac82013-04-17 21:41:33 -0700976 rndis->port.ul_max_pkts_per_xfer = rndis_ul_max_pkt_per_xfer;
Vijayavardhan Vennapusac76dced2013-05-27 15:00:52 +0530977 rndis->port.dl_max_pkts_per_xfer = rndis_dl_max_pkt_per_xfer;
David Brownell45fe3b82008-06-19 18:20:04 -0700978
979 rndis->port.func.name = "rndis";
980 rndis->port.func.strings = rndis_strings;
981 /* descriptors are per-instance copies */
982 rndis->port.func.bind = rndis_bind;
983 rndis->port.func.unbind = rndis_unbind;
984 rndis->port.func.set_alt = rndis_set_alt;
985 rndis->port.func.setup = rndis_setup;
986 rndis->port.func.disable = rndis_disable;
987
988 status = usb_add_function(c, &rndis->port.func);
989 if (status) {
990 kfree(rndis);
991fail:
992 rndis_exit();
993 }
994 return status;
995}