blob: d4c2823a6fabe910db28ced5e3506da964505ca6 [file] [log] [blame]
Hemant Kumar9d6016c2012-01-05 16:27:24 -08001/* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
Hemant Kumar37c35e42011-09-14 23:44:19 -07002 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#include <linux/mii.h>
14#include <linux/if_arp.h>
15#include <linux/etherdevice.h>
Hemant Kumar7bf94262012-04-18 17:25:10 -070016#include <linux/debugfs.h>
17#include <linux/seq_file.h>
Hemant Kumar37c35e42011-09-14 23:44:19 -070018#include <linux/usb.h>
19#include <linux/usb/usbnet.h>
20#include <linux/msm_rmnet.h>
21
22#include "rmnet_usb_ctrl.h"
23
24#define RMNET_DATA_LEN 2000
25#define HEADROOM_FOR_QOS 8
26
Hemant Kumar37c35e42011-09-14 23:44:19 -070027static int data_msg_dbg_mask;
28
29enum {
30 DEBUG_MASK_LVL0 = 1U << 0,
31 DEBUG_MASK_LVL1 = 1U << 1,
32 DEBUG_MASK_LVL2 = 1U << 2,
33};
34
35#define DBG(m, x...) do { \
36 if (data_msg_dbg_mask & m) \
37 pr_info(x); \
38} while (0)
39
40/*echo dbg_mask > /sys/class/net/rmnet_usbx/dbg_mask*/
41static ssize_t dbg_mask_store(struct device *d,
42 struct device_attribute *attr,
43 const char *buf, size_t n)
44{
45 unsigned int dbg_mask;
46 struct net_device *dev = to_net_dev(d);
47 struct usbnet *unet = netdev_priv(dev);
48
49 if (!dev)
50 return -ENODEV;
51
52 sscanf(buf, "%u", &dbg_mask);
53 /*enable dbg msgs for data driver*/
54 data_msg_dbg_mask = dbg_mask;
55
56 /*set default msg level*/
57 unet->msg_enable = NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK;
58
59 /*enable netif_xxx msgs*/
60 if (dbg_mask & DEBUG_MASK_LVL0)
61 unet->msg_enable |= NETIF_MSG_IFUP | NETIF_MSG_IFDOWN;
62 if (dbg_mask & DEBUG_MASK_LVL1)
63 unet->msg_enable |= NETIF_MSG_TX_ERR | NETIF_MSG_RX_ERR
64 | NETIF_MSG_TX_QUEUED | NETIF_MSG_TX_DONE
65 | NETIF_MSG_RX_STATUS;
66
67 return n;
68}
69
70static ssize_t dbg_mask_show(struct device *d,
71 struct device_attribute *attr, char *buf)
72{
73 return snprintf(buf, PAGE_SIZE, "%d\n", data_msg_dbg_mask);
74}
75
76static DEVICE_ATTR(dbg_mask, 0644, dbg_mask_show, dbg_mask_store);
77
78#define DBG0(x...) DBG(DEBUG_MASK_LVL0, x)
79#define DBG1(x...) DBG(DEBUG_MASK_LVL1, x)
80#define DBG2(x...) DBG(DEBUG_MASK_LVL2, x)
81
82static void rmnet_usb_setup(struct net_device *);
83static int rmnet_ioctl(struct net_device *, struct ifreq *, int);
84
85static int rmnet_usb_suspend(struct usb_interface *iface, pm_message_t message)
86{
87 struct usbnet *unet;
88 struct rmnet_ctrl_dev *dev;
89 int time = 0;
90 int retval = 0;
91
92 unet = usb_get_intfdata(iface);
93 if (!unet) {
94 pr_err("%s:data device not found\n", __func__);
95 retval = -ENODEV;
96 goto fail;
97 }
98
99 dev = (struct rmnet_ctrl_dev *)unet->data[1];
100 if (!dev) {
101 dev_err(&unet->udev->dev, "%s: ctrl device not found\n",
102 __func__);
103 retval = -ENODEV;
104 goto fail;
105 }
106
107 retval = usbnet_suspend(iface, message);
108 if (!retval) {
109 if (message.event & PM_EVENT_SUSPEND) {
110 time = usb_wait_anchor_empty_timeout(&dev->tx_submitted,
111 1000);
112 if (!time)
113 usb_kill_anchored_urbs(&dev->tx_submitted);
114
115 retval = rmnet_usb_ctrl_stop_rx(dev);
116 iface->dev.power.power_state.event = message.event;
117 }
118 /* TBD : do we need to set/clear usbnet->udev->reset_resume*/
119 } else
120 dev_dbg(&unet->udev->dev,
121 "%s: device is busy can not suspend\n", __func__);
122
123fail:
124 return retval;
125}
126
127static int rmnet_usb_resume(struct usb_interface *iface)
128{
129 int retval = 0;
130 int oldstate;
131 struct usbnet *unet;
132 struct rmnet_ctrl_dev *dev;
133
134 unet = usb_get_intfdata(iface);
135 if (!unet) {
136 pr_err("%s:data device not found\n", __func__);
137 retval = -ENODEV;
138 goto fail;
139 }
140
141 dev = (struct rmnet_ctrl_dev *)unet->data[1];
142 if (!dev) {
143 dev_err(&unet->udev->dev, "%s: ctrl device not found\n",
144 __func__);
145 retval = -ENODEV;
146 goto fail;
147 }
148 oldstate = iface->dev.power.power_state.event;
149 iface->dev.power.power_state.event = PM_EVENT_ON;
150
151 retval = usbnet_resume(iface);
152 if (!retval) {
Hemant Kumar37c35e42011-09-14 23:44:19 -0700153 if (oldstate & PM_EVENT_SUSPEND)
154 retval = rmnet_usb_ctrl_start(dev);
155 }
156fail:
157 return retval;
158}
159
160static int rmnet_usb_bind(struct usbnet *usbnet, struct usb_interface *iface)
161{
162 struct usb_host_endpoint *endpoint = NULL;
163 struct usb_host_endpoint *bulk_in = NULL;
164 struct usb_host_endpoint *bulk_out = NULL;
165 struct usb_host_endpoint *int_in = NULL;
166 struct usb_device *udev;
167 int status = 0;
168 int i;
169 int numends;
170
171 udev = interface_to_usbdev(iface);
172 numends = iface->cur_altsetting->desc.bNumEndpoints;
173 for (i = 0; i < numends; i++) {
174 endpoint = iface->cur_altsetting->endpoint + i;
175 if (!endpoint) {
176 dev_err(&udev->dev, "%s: invalid endpoint %u\n",
177 __func__, i);
178 status = -EINVAL;
179 goto out;
180 }
181 if (usb_endpoint_is_bulk_in(&endpoint->desc))
182 bulk_in = endpoint;
183 else if (usb_endpoint_is_bulk_out(&endpoint->desc))
184 bulk_out = endpoint;
185 else if (usb_endpoint_is_int_in(&endpoint->desc))
186 int_in = endpoint;
187 }
188
189 if (!bulk_in || !bulk_out || !int_in) {
190 dev_err(&udev->dev, "%s: invalid endpoints\n", __func__);
191 status = -EINVAL;
192 goto out;
193 }
194 usbnet->in = usb_rcvbulkpipe(usbnet->udev,
195 bulk_in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
196 usbnet->out = usb_sndbulkpipe(usbnet->udev,
197 bulk_out->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
198 usbnet->status = int_in;
199
200 /*change name of net device to rmnet_usbx here*/
201 strlcpy(usbnet->net->name, "rmnet_usb%d", IFNAMSIZ);
202
203 /*TBD: update rx_urb_size, curently set to eth frame len by usbnet*/
204out:
205 return status;
206}
207
208static struct sk_buff *rmnet_usb_tx_fixup(struct usbnet *dev,
209 struct sk_buff *skb, gfp_t flags)
210{
211 struct QMI_QOS_HDR_S *qmih;
212
213 if (test_bit(RMNET_MODE_QOS, &dev->data[0])) {
214 qmih = (struct QMI_QOS_HDR_S *)
215 skb_push(skb, sizeof(struct QMI_QOS_HDR_S));
216 qmih->version = 1;
217 qmih->flags = 0;
218 qmih->flow_id = skb->mark;
219 }
220
221 DBG1("[%s] Tx packet #%lu len=%d mark=0x%x\n",
222 dev->net->name, dev->net->stats.tx_packets, skb->len, skb->mark);
223
224 return skb;
225}
226
227static __be16 rmnet_ip_type_trans(struct sk_buff *skb,
228 struct net_device *dev)
229{
230 __be16 protocol = 0;
231
232 skb->dev = dev;
233
234 switch (skb->data[0] & 0xf0) {
235 case 0x40:
236 protocol = htons(ETH_P_IP);
237 break;
238 case 0x60:
239 protocol = htons(ETH_P_IPV6);
240 break;
241 default:
242 pr_err("[%s] rmnet_recv() L3 protocol decode error: 0x%02x",
243 dev->name, skb->data[0] & 0xf0);
244 }
245
246 return protocol;
247}
248
249static int rmnet_usb_rx_fixup(struct usbnet *dev,
250 struct sk_buff *skb)
251{
252
253 if (test_bit(RMNET_MODE_LLP_IP, &dev->data[0]))
254 skb->protocol = rmnet_ip_type_trans(skb, dev->net);
255 else /*set zero for eth mode*/
256 skb->protocol = 0;
257
258 DBG1("[%s] Rx packet #%lu len=%d\n",
259 dev->net->name, dev->net->stats.rx_packets, skb->len);
260
261 return 1;
262}
263
Jack Phamf77b9962012-02-23 18:45:43 -0800264static int rmnet_usb_manage_power(struct usbnet *dev, int on)
265{
266 dev->intf->needs_remote_wakeup = on;
267 return 0;
268}
269
Hemant Kumar37c35e42011-09-14 23:44:19 -0700270static int rmnet_change_mtu(struct net_device *dev, int new_mtu)
271{
272 if (0 > new_mtu || RMNET_DATA_LEN < new_mtu)
273 return -EINVAL;
274
275 DBG0("[%s] MTU change: old=%d new=%d\n", dev->name, dev->mtu, new_mtu);
276
277 dev->mtu = new_mtu;
278
279 return 0;
280}
281
282static struct net_device_stats *rmnet_get_stats(struct net_device *dev)
283{
284 return &dev->stats;
285}
286
287static const struct net_device_ops rmnet_usb_ops_ether = {
288 .ndo_open = usbnet_open,
289 .ndo_stop = usbnet_stop,
290 .ndo_start_xmit = usbnet_start_xmit,
291 .ndo_get_stats = rmnet_get_stats,
292 /*.ndo_set_multicast_list = rmnet_set_multicast_list,*/
293 .ndo_tx_timeout = usbnet_tx_timeout,
294 .ndo_do_ioctl = rmnet_ioctl,
295 .ndo_change_mtu = usbnet_change_mtu,
296 .ndo_set_mac_address = eth_mac_addr,
297 .ndo_validate_addr = eth_validate_addr,
298};
299
300static const struct net_device_ops rmnet_usb_ops_ip = {
301 .ndo_open = usbnet_open,
302 .ndo_stop = usbnet_stop,
303 .ndo_start_xmit = usbnet_start_xmit,
304 .ndo_get_stats = rmnet_get_stats,
305 /*.ndo_set_multicast_list = rmnet_set_multicast_list,*/
306 .ndo_tx_timeout = usbnet_tx_timeout,
307 .ndo_do_ioctl = rmnet_ioctl,
308 .ndo_change_mtu = rmnet_change_mtu,
309 .ndo_set_mac_address = 0,
310 .ndo_validate_addr = 0,
311};
312
313
314static int rmnet_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
315{
316 struct usbnet *unet = netdev_priv(dev);
317 u32 old_opmode;
318 int prev_mtu = dev->mtu;
319 int rc = 0;
320
321 old_opmode = unet->data[0]; /*data[0] saves operation mode*/
322 /* Process IOCTL command */
323 switch (cmd) {
324 case RMNET_IOCTL_SET_LLP_ETHERNET: /*Set Ethernet protocol*/
325 /* Perform Ethernet config only if in IP mode currently*/
326 if (test_bit(RMNET_MODE_LLP_IP, &unet->data[0])) {
327 ether_setup(dev);
328 random_ether_addr(dev->dev_addr);
329 dev->mtu = prev_mtu;
330 dev->netdev_ops = &rmnet_usb_ops_ether;
331 clear_bit(RMNET_MODE_LLP_IP, &unet->data[0]);
332 set_bit(RMNET_MODE_LLP_ETH, &unet->data[0]);
333 DBG0("[%s] rmnet_ioctl(): set Ethernet protocol mode\n",
334 dev->name);
335 }
336 break;
337
338 case RMNET_IOCTL_SET_LLP_IP: /* Set RAWIP protocol*/
339 /* Perform IP config only if in Ethernet mode currently*/
340 if (test_bit(RMNET_MODE_LLP_ETH, &unet->data[0])) {
341
342 /* Undo config done in ether_setup() */
343 dev->header_ops = 0; /* No header */
344 dev->type = ARPHRD_RAWIP;
345 dev->hard_header_len = 0;
346 dev->mtu = prev_mtu;
347 dev->addr_len = 0;
348 dev->flags &= ~(IFF_BROADCAST | IFF_MULTICAST);
349 dev->needed_headroom = HEADROOM_FOR_QOS;
350 dev->netdev_ops = &rmnet_usb_ops_ip;
351 clear_bit(RMNET_MODE_LLP_ETH, &unet->data[0]);
352 set_bit(RMNET_MODE_LLP_IP, &unet->data[0]);
353 DBG0("[%s] rmnet_ioctl(): set IP protocol mode\n",
354 dev->name);
355 }
356 break;
357
358 case RMNET_IOCTL_GET_LLP: /* Get link protocol state */
359 ifr->ifr_ifru.ifru_data = (void *)(unet->data[0]
360 & (RMNET_MODE_LLP_ETH
361 | RMNET_MODE_LLP_IP));
362 break;
363
364 case RMNET_IOCTL_SET_QOS_ENABLE: /* Set QoS header enabled*/
365 set_bit(RMNET_MODE_QOS, &unet->data[0]);
366 DBG0("[%s] rmnet_ioctl(): set QMI QOS header enable\n",
367 dev->name);
368 break;
369
370 case RMNET_IOCTL_SET_QOS_DISABLE: /* Set QoS header disabled */
371 clear_bit(RMNET_MODE_QOS, &unet->data[0]);
372 DBG0("[%s] rmnet_ioctl(): set QMI QOS header disable\n",
373 dev->name);
374 break;
375
376 case RMNET_IOCTL_GET_QOS: /* Get QoS header state */
377 ifr->ifr_ifru.ifru_data = (void *)(unet->data[0]
378 & RMNET_MODE_QOS);
379 break;
380
381 case RMNET_IOCTL_GET_OPMODE: /* Get operation mode*/
382 ifr->ifr_ifru.ifru_data = (void *)unet->data[0];
383 break;
384
385 case RMNET_IOCTL_OPEN: /* Open transport port */
386 rc = usbnet_open(dev);
387 DBG0("[%s] rmnet_ioctl(): open transport port\n", dev->name);
388 break;
389
390 case RMNET_IOCTL_CLOSE: /* Close transport port*/
391 rc = usbnet_stop(dev);
392 DBG0("[%s] rmnet_ioctl(): close transport port\n", dev->name);
393 break;
394
395 default:
396 dev_err(&unet->udev->dev, "[%s] error: "
397 "rmnet_ioct called for unsupported cmd[%d]",
398 dev->name, cmd);
399 return -EINVAL;
400 }
401
402 DBG2("[%s] %s: cmd=0x%x opmode old=0x%08x new=0x%08lx\n",
403 dev->name, __func__, cmd, old_opmode, unet->data[0]);
404
405 return rc;
406}
407
408static void rmnet_usb_setup(struct net_device *dev)
409{
410 /* Using Ethernet mode by default */
411 dev->netdev_ops = &rmnet_usb_ops_ether;
412
413 /* set this after calling ether_setup */
414 dev->mtu = RMNET_DATA_LEN;
415
416 dev->needed_headroom = HEADROOM_FOR_QOS;
417 random_ether_addr(dev->dev_addr);
418 dev->watchdog_timeo = 1000; /* 10 seconds? */
419}
420
Hemant Kumar7bf94262012-04-18 17:25:10 -0700421static int rmnet_usb_data_status(struct seq_file *s, void *unused)
422{
423 struct usbnet *unet = s->private;
424
425 seq_printf(s, "RMNET_MODE_LLP_IP: %d\n",
426 test_bit(RMNET_MODE_LLP_IP, &unet->data[0]));
427 seq_printf(s, "RMNET_MODE_LLP_ETH: %d\n",
428 test_bit(RMNET_MODE_LLP_ETH, &unet->data[0]));
429 seq_printf(s, "RMNET_MODE_QOS: %d\n",
430 test_bit(RMNET_MODE_QOS, &unet->data[0]));
431 seq_printf(s, "Net MTU: %u\n", unet->net->mtu);
432 seq_printf(s, "rx_urb_size: %u\n", unet->rx_urb_size);
433 seq_printf(s, "rx skb q len: %u\n", unet->rxq.qlen);
434 seq_printf(s, "rx skb done q len: %u\n", unet->done.qlen);
435 seq_printf(s, "rx errors: %lu\n", unet->net->stats.rx_errors);
436 seq_printf(s, "rx over errors: %lu\n",
437 unet->net->stats.rx_over_errors);
438 seq_printf(s, "rx length errors: %lu\n",
439 unet->net->stats.rx_length_errors);
440 seq_printf(s, "rx packets: %lu\n", unet->net->stats.rx_packets);
441 seq_printf(s, "rx bytes: %lu\n", unet->net->stats.rx_bytes);
442 seq_printf(s, "tx skb q len: %u\n", unet->txq.qlen);
443 seq_printf(s, "tx errors: %lu\n", unet->net->stats.tx_errors);
444 seq_printf(s, "tx packets: %lu\n", unet->net->stats.tx_packets);
445 seq_printf(s, "tx bytes: %lu\n", unet->net->stats.tx_bytes);
446 seq_printf(s, "suspend count: %d\n", unet->suspend_count);
447 seq_printf(s, "EVENT_DEV_OPEN: %d\n",
448 test_bit(EVENT_DEV_OPEN, &unet->flags));
449 seq_printf(s, "EVENT_TX_HALT: %d\n",
450 test_bit(EVENT_TX_HALT, &unet->flags));
451 seq_printf(s, "EVENT_RX_HALT: %d\n",
452 test_bit(EVENT_RX_HALT, &unet->flags));
453 seq_printf(s, "EVENT_RX_MEMORY: %d\n",
454 test_bit(EVENT_RX_MEMORY, &unet->flags));
455 seq_printf(s, "EVENT_DEV_ASLEEP: %d\n",
456 test_bit(EVENT_DEV_ASLEEP, &unet->flags));
457
458 return 0;
459}
460
461static int rmnet_usb_data_status_open(struct inode *inode, struct file *file)
462{
463 return single_open(file, rmnet_usb_data_status, inode->i_private);
464}
465
466const struct file_operations rmnet_usb_data_fops = {
467 .open = rmnet_usb_data_status_open,
468 .read = seq_read,
469 .llseek = seq_lseek,
470 .release = single_release,
471};
472
473static struct dentry *rmnet_usb_data_dbg_root;
474static int rmnet_usb_data_debugfs_init(struct usbnet *unet)
475{
476 struct dentry *rmnet_usb_data_dentry;
477
478 rmnet_usb_data_dbg_root = debugfs_create_dir(unet->net->name, NULL);
479
480 if (!rmnet_usb_data_dbg_root || IS_ERR(rmnet_usb_data_dbg_root))
481 return -ENODEV;
482
483 rmnet_usb_data_dentry = debugfs_create_file("status",
484 S_IRUGO | S_IWUSR,
485 rmnet_usb_data_dbg_root, unet,
486 &rmnet_usb_data_fops);
487
488 if (!rmnet_usb_data_dentry) {
489 debugfs_remove_recursive(rmnet_usb_data_dbg_root);
490 return -ENODEV;
491 }
492
493 return 0;
494}
495
496static void rmnet_usb_data_debugfs_cleanup(void)
497{
498 debugfs_remove_recursive(rmnet_usb_data_dbg_root);
499}
500
Hemant Kumar37c35e42011-09-14 23:44:19 -0700501static int rmnet_usb_probe(struct usb_interface *iface,
502 const struct usb_device_id *prod)
503{
504 struct usbnet *unet;
505 struct usb_device *udev;
Hemant Kumar9d6016c2012-01-05 16:27:24 -0800506 struct driver_info *info;
507 unsigned int iface_num;
508 static int first_rmnet_iface_num = -EINVAL;
509 int status = 0;
Hemant Kumar37c35e42011-09-14 23:44:19 -0700510
511 udev = interface_to_usbdev(iface);
512 iface_num = iface->cur_altsetting->desc.bInterfaceNumber;
513 if (iface->num_altsetting != 1) {
514 dev_err(&udev->dev, "%s invalid num_altsetting %u\n",
515 __func__, iface->num_altsetting);
516 status = -EINVAL;
517 goto out;
518 }
519
Hemant Kumar9d6016c2012-01-05 16:27:24 -0800520 info = (struct driver_info *)prod->driver_info;
521 if (!test_bit(iface_num, &info->data))
522 return -ENODEV;
Hemant Kumar37c35e42011-09-14 23:44:19 -0700523
Hemant Kumar9d6016c2012-01-05 16:27:24 -0800524 status = usbnet_probe(iface, prod);
525 if (status < 0) {
526 dev_err(&udev->dev, "usbnet_probe failed %d\n", status);
527 goto out;
Hemant Kumar37c35e42011-09-14 23:44:19 -0700528 }
Hemant Kumar9d6016c2012-01-05 16:27:24 -0800529 unet = usb_get_intfdata(iface);
530
531 /*set rmnet operation mode to eth by default*/
532 set_bit(RMNET_MODE_LLP_ETH, &unet->data[0]);
533
534 /*update net device*/
535 rmnet_usb_setup(unet->net);
536
537 /*create /sys/class/net/rmnet_usbx/dbg_mask*/
538 status = device_create_file(&unet->net->dev, &dev_attr_dbg_mask);
539 if (status)
540 goto out;
541
542 if (first_rmnet_iface_num == -EINVAL)
543 first_rmnet_iface_num = iface_num;
544
545 /*save control device intstance */
546 unet->data[1] = (unsigned long)ctrl_dev \
547 [iface_num - first_rmnet_iface_num];
548
549 status = rmnet_usb_ctrl_probe(iface, unet->status,
550 (struct rmnet_ctrl_dev *)unet->data[1]);
Jack Pham42346cf2012-03-13 12:49:07 -0700551 if (status)
552 goto out;
553
Hemant Kumar7bf94262012-04-18 17:25:10 -0700554 status = rmnet_usb_data_debugfs_init(unet);
555 if (status)
556 dev_dbg(&udev->dev, "mode debugfs file is not available\n");
557
Jack Pham42346cf2012-03-13 12:49:07 -0700558 /* allow modem to wake up suspended system */
559 device_set_wakeup_enable(&udev->dev, 1);
Hemant Kumar37c35e42011-09-14 23:44:19 -0700560out:
561 return status;
562}
563
564static void rmnet_usb_disconnect(struct usb_interface *intf)
565{
566 struct usbnet *unet;
567 struct usb_device *udev;
568 struct rmnet_ctrl_dev *dev;
Hemant Kumar37c35e42011-09-14 23:44:19 -0700569
570 udev = interface_to_usbdev(intf);
Jack Pham42346cf2012-03-13 12:49:07 -0700571 device_set_wakeup_enable(&udev->dev, 0);
Hemant Kumar37c35e42011-09-14 23:44:19 -0700572
Hemant Kumar7bf94262012-04-18 17:25:10 -0700573 rmnet_usb_data_debugfs_cleanup();
574
Hemant Kumar9d6016c2012-01-05 16:27:24 -0800575 unet = usb_get_intfdata(intf);
576 if (!unet) {
577 dev_err(&udev->dev, "%s:data device not found\n", __func__);
578 return;
Hemant Kumar37c35e42011-09-14 23:44:19 -0700579 }
Hemant Kumar9d6016c2012-01-05 16:27:24 -0800580
581 dev = (struct rmnet_ctrl_dev *)unet->data[1];
582 if (!dev) {
583 dev_err(&udev->dev, "%s:ctrl device not found\n", __func__);
584 return;
585 }
586 unet->data[0] = 0;
587 unet->data[1] = 0;
588 rmnet_usb_ctrl_disconnect(dev);
589 device_remove_file(&unet->net->dev, &dev_attr_dbg_mask);
590 usbnet_disconnect(intf);
Hemant Kumar37c35e42011-09-14 23:44:19 -0700591}
592
Hemant Kumar9d6016c2012-01-05 16:27:24 -0800593/*bit position represents interface number*/
594#define PID9034_IFACE_MASK 0xF0
595#define PID9048_IFACE_MASK 0x1E0
Hemant Kumarbf024812012-02-24 12:58:56 -0800596#define PID904C_IFACE_MASK 0x1C0
Hemant Kumar9d6016c2012-01-05 16:27:24 -0800597
598static const struct driver_info rmnet_info_pid9034 = {
Hemant Kumar37c35e42011-09-14 23:44:19 -0700599 .description = "RmNET net device",
600 .bind = rmnet_usb_bind,
601 .tx_fixup = rmnet_usb_tx_fixup,
602 .rx_fixup = rmnet_usb_rx_fixup,
Jack Phamf77b9962012-02-23 18:45:43 -0800603 .manage_power = rmnet_usb_manage_power,
Hemant Kumar9d6016c2012-01-05 16:27:24 -0800604 .data = PID9034_IFACE_MASK,
605};
606
607static const struct driver_info rmnet_info_pid9048 = {
608 .description = "RmNET net device",
609 .bind = rmnet_usb_bind,
610 .tx_fixup = rmnet_usb_tx_fixup,
611 .rx_fixup = rmnet_usb_rx_fixup,
Jack Phamf77b9962012-02-23 18:45:43 -0800612 .manage_power = rmnet_usb_manage_power,
Hemant Kumar9d6016c2012-01-05 16:27:24 -0800613 .data = PID9048_IFACE_MASK,
Hemant Kumar37c35e42011-09-14 23:44:19 -0700614};
615
Hemant Kumarbf024812012-02-24 12:58:56 -0800616static const struct driver_info rmnet_info_pid904c = {
617 .description = "RmNET net device",
618 .bind = rmnet_usb_bind,
619 .tx_fixup = rmnet_usb_tx_fixup,
620 .rx_fixup = rmnet_usb_rx_fixup,
Jack Phamf77b9962012-02-23 18:45:43 -0800621 .manage_power = rmnet_usb_manage_power,
Hemant Kumarbf024812012-02-24 12:58:56 -0800622 .data = PID904C_IFACE_MASK,
623};
624
Hemant Kumar37c35e42011-09-14 23:44:19 -0700625static const struct usb_device_id vidpids[] = {
626 {
Hemant Kumar9d6016c2012-01-05 16:27:24 -0800627 USB_DEVICE(0x05c6, 0x9034), /* MDM9x15*/
628 .driver_info = (unsigned long)&rmnet_info_pid9034,
Hemant Kumar37c35e42011-09-14 23:44:19 -0700629 },
Hemant Kumar9d6016c2012-01-05 16:27:24 -0800630 {
631 USB_DEVICE(0x05c6, 0x9048), /* MDM9x15*/
632 .driver_info = (unsigned long)&rmnet_info_pid9048,
633 },
Hemant Kumarbf024812012-02-24 12:58:56 -0800634 {
635 USB_DEVICE(0x05c6, 0x904c), /* MDM9x15*/
636 .driver_info = (unsigned long)&rmnet_info_pid904c,
637 },
Hemant Kumar9d6016c2012-01-05 16:27:24 -0800638
639 { }, /* Terminating entry */
Hemant Kumar37c35e42011-09-14 23:44:19 -0700640};
641
642MODULE_DEVICE_TABLE(usb, vidpids);
643
644static struct usb_driver rmnet_usb = {
645 .name = "rmnet_usb",
646 .id_table = vidpids,
647 .probe = rmnet_usb_probe,
648 .disconnect = rmnet_usb_disconnect,
649 .suspend = rmnet_usb_suspend,
650 .resume = rmnet_usb_resume,
651 .supports_autosuspend = true,
652};
653
654static int __init rmnet_usb_init(void)
655{
656 int retval;
657
658 retval = usb_register(&rmnet_usb);
659 if (retval) {
660 err("usb_register failed: %d", retval);
661 return retval;
662 }
663 /* initialize rmnet ctrl device here*/
664 retval = rmnet_usb_ctrl_init();
665 if (retval) {
666 usb_deregister(&rmnet_usb);
667 err("rmnet_usb_cmux_init failed: %d", retval);
668 return retval;
669 }
670
671 return 0;
672}
673module_init(rmnet_usb_init);
674
675static void __exit rmnet_usb_exit(void)
676{
677 rmnet_usb_ctrl_exit();
678 usb_deregister(&rmnet_usb);
679}
680module_exit(rmnet_usb_exit);
681
682MODULE_DESCRIPTION("msm rmnet usb device");
683MODULE_LICENSE("GPL v2");