blob: 3b3758e00d3a6a3fc5582a97e7901754849de77e [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* Copyright (c) 2011, Code Aurora Forum. All rights reserved.
2 *
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
14/*
15 * RMNET BAM Module.
16 */
17
18#include <linux/module.h>
19#include <linux/kernel.h>
20#include <linux/string.h>
21#include <linux/delay.h>
22#include <linux/errno.h>
23#include <linux/interrupt.h>
24#include <linux/init.h>
25#include <linux/netdevice.h>
26#include <linux/etherdevice.h>
27#include <linux/skbuff.h>
28#include <linux/wakelock.h>
29#include <linux/if_arp.h>
30#include <linux/msm_rmnet.h>
Jeff Hugo24dfa0c2011-10-07 17:55:06 -060031#include <linux/platform_device.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070032
33#ifdef CONFIG_HAS_EARLYSUSPEND
34#include <linux/earlysuspend.h>
35#endif
36
37#include <mach/bam_dmux.h>
38
39/* Debug message support */
40static int msm_rmnet_bam_debug_mask;
41module_param_named(debug_enable, msm_rmnet_bam_debug_mask,
42 int, S_IRUGO | S_IWUSR | S_IWGRP);
43
44#define DEBUG_MASK_LVL0 (1U << 0)
45#define DEBUG_MASK_LVL1 (1U << 1)
46#define DEBUG_MASK_LVL2 (1U << 2)
47
48#define DBG(m, x...) do { \
49 if (msm_rmnet_bam_debug_mask & m) \
50 pr_info(x); \
51} while (0)
52#define DBG0(x...) DBG(DEBUG_MASK_LVL0, x)
53#define DBG1(x...) DBG(DEBUG_MASK_LVL1, x)
54#define DBG2(x...) DBG(DEBUG_MASK_LVL2, x)
55
56/* Configure device instances */
57#define RMNET_DEVICE_COUNT (8)
58
59/* allow larger frames */
60#define RMNET_DATA_LEN 2000
61
62#define DEVICE_ID_INVALID -1
63
64#define DEVICE_INACTIVE 0
65#define DEVICE_ACTIVE 1
66
67#define HEADROOM_FOR_BAM 8 /* for mux header */
68#define HEADROOM_FOR_QOS 8
69#define TAILROOM 8 /* for padding by mux layer */
70
71struct rmnet_private {
72 struct net_device_stats stats;
73 uint32_t ch_id;
74#ifdef CONFIG_MSM_RMNET_DEBUG
75 ktime_t last_packet;
76 unsigned long wakeups_xmit;
77 unsigned long wakeups_rcv;
78 unsigned long timeout_us;
79#endif
80 struct sk_buff *skb;
81 spinlock_t lock;
82 struct tasklet_struct tsklt;
83 u32 operation_mode; /* IOCTL specified mode (protocol, QoS header) */
84 uint8_t device_up;
Jeff Hugobac7ea22011-10-24 10:58:48 -060085 uint8_t waiting_for_ul;
Jeff Hugo24dfa0c2011-10-07 17:55:06 -060086 uint8_t in_reset;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070087};
88
Jeff Hugobac7ea22011-10-24 10:58:48 -060089static uint8_t ul_is_connected;
90
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070091#ifdef CONFIG_MSM_RMNET_DEBUG
92static unsigned long timeout_us;
93
94#ifdef CONFIG_HAS_EARLYSUSPEND
95/*
96 * If early suspend is enabled then we specify two timeout values,
97 * screen on (default), and screen is off.
98 */
99static unsigned long timeout_suspend_us;
100static struct device *rmnet0;
101
102/* Set timeout in us when the screen is off. */
103static ssize_t timeout_suspend_store(struct device *d,
104 struct device_attribute *attr,
105 const char *buf, size_t n)
106{
107 timeout_suspend_us = strict_strtoul(buf, NULL, 10);
108 return n;
109}
110
111static ssize_t timeout_suspend_show(struct device *d,
112 struct device_attribute *attr,
113 char *buf)
114{
115 return sprintf(buf, "%lu\n", (unsigned long) timeout_suspend_us);
116}
117
118static DEVICE_ATTR(timeout_suspend, 0664, timeout_suspend_show,
119 timeout_suspend_store);
120
121static void rmnet_early_suspend(struct early_suspend *handler)
122{
123 if (rmnet0) {
124 struct rmnet_private *p = netdev_priv(to_net_dev(rmnet0));
125 p->timeout_us = timeout_suspend_us;
126 }
127}
128
129static void rmnet_late_resume(struct early_suspend *handler)
130{
131 if (rmnet0) {
132 struct rmnet_private *p = netdev_priv(to_net_dev(rmnet0));
133 p->timeout_us = timeout_us;
134 }
135}
136
137static struct early_suspend rmnet_power_suspend = {
138 .suspend = rmnet_early_suspend,
139 .resume = rmnet_late_resume,
140};
141
142static int __init rmnet_late_init(void)
143{
144 register_early_suspend(&rmnet_power_suspend);
145 return 0;
146}
147
148late_initcall(rmnet_late_init);
149#endif
150
151/* Returns 1 if packet caused rmnet to wakeup, 0 otherwise. */
152static int rmnet_cause_wakeup(struct rmnet_private *p)
153{
154 int ret = 0;
155 ktime_t now;
156 if (p->timeout_us == 0) /* Check if disabled */
157 return 0;
158
159 /* Use real (wall) time. */
160 now = ktime_get_real();
161
162 if (ktime_us_delta(now, p->last_packet) > p->timeout_us)
163 ret = 1;
164
165 p->last_packet = now;
166 return ret;
167}
168
169static ssize_t wakeups_xmit_show(struct device *d,
170 struct device_attribute *attr,
171 char *buf)
172{
173 struct rmnet_private *p = netdev_priv(to_net_dev(d));
174 return sprintf(buf, "%lu\n", p->wakeups_xmit);
175}
176
177DEVICE_ATTR(wakeups_xmit, 0444, wakeups_xmit_show, NULL);
178
179static ssize_t wakeups_rcv_show(struct device *d, struct device_attribute *attr,
180 char *buf)
181{
182 struct rmnet_private *p = netdev_priv(to_net_dev(d));
183 return sprintf(buf, "%lu\n", p->wakeups_rcv);
184}
185
186DEVICE_ATTR(wakeups_rcv, 0444, wakeups_rcv_show, NULL);
187
188/* Set timeout in us. */
189static ssize_t timeout_store(struct device *d, struct device_attribute *attr,
190 const char *buf, size_t n)
191{
192#ifndef CONFIG_HAS_EARLYSUSPEND
193 struct rmnet_private *p = netdev_priv(to_net_dev(d));
194 p->timeout_us = timeout_us = strict_strtoul(buf, NULL, 10);
195#else
196/* If using early suspend/resume hooks do not write the value on store. */
197 timeout_us = strict_strtoul(buf, NULL, 10);
198#endif
199 return n;
200}
201
202static ssize_t timeout_show(struct device *d, struct device_attribute *attr,
203 char *buf)
204{
205 struct rmnet_private *p = netdev_priv(to_net_dev(d));
206 p = netdev_priv(to_net_dev(d));
207 return sprintf(buf, "%lu\n", timeout_us);
208}
209
210DEVICE_ATTR(timeout, 0664, timeout_show, timeout_store);
211#endif
212
213
214/* Forward declaration */
215static int rmnet_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
216
217static __be16 rmnet_ip_type_trans(struct sk_buff *skb, struct net_device *dev)
218{
219 __be16 protocol = 0;
220
221 skb->dev = dev;
222
223 /* Determine L3 protocol */
224 switch (skb->data[0] & 0xf0) {
225 case 0x40:
226 protocol = htons(ETH_P_IP);
227 break;
228 case 0x60:
229 protocol = htons(ETH_P_IPV6);
230 break;
231 default:
232 pr_err("[%s] rmnet_recv() L3 protocol decode error: 0x%02x",
233 dev->name, skb->data[0] & 0xf0);
234 /* skb will be dropped in upper layer for unknown protocol */
235 }
236 return protocol;
237}
238
239static int count_this_packet(void *_hdr, int len)
240{
241 struct ethhdr *hdr = _hdr;
242
243 if (len >= ETH_HLEN && hdr->h_proto == htons(ETH_P_ARP))
244 return 0;
245
246 return 1;
247}
248
249/* Rx Callback, Called in Work Queue context */
250static void bam_recv_notify(void *dev, struct sk_buff *skb)
251{
252 struct rmnet_private *p = netdev_priv(dev);
253 unsigned long flags;
254 u32 opmode;
255
256 if (skb) {
257 skb->dev = dev;
258 /* Handle Rx frame format */
259 spin_lock_irqsave(&p->lock, flags);
260 opmode = p->operation_mode;
261 spin_unlock_irqrestore(&p->lock, flags);
262
263 if (RMNET_IS_MODE_IP(opmode)) {
264 /* Driver in IP mode */
265 skb->protocol = rmnet_ip_type_trans(skb, dev);
266 } else {
267 /* Driver in Ethernet mode */
268 skb->protocol = eth_type_trans(skb, dev);
269 }
270 if (RMNET_IS_MODE_IP(opmode) ||
271 count_this_packet(skb->data, skb->len)) {
272#ifdef CONFIG_MSM_RMNET_DEBUG
273 p->wakeups_rcv += rmnet_cause_wakeup(p);
274#endif
275 p->stats.rx_packets++;
276 p->stats.rx_bytes += skb->len;
277 }
278 DBG1("[%s] Rx packet #%lu len=%d\n",
279 ((struct net_device *)dev)->name,
280 p->stats.rx_packets, skb->len);
281
282 /* Deliver to network stack */
283 netif_rx(skb);
284 } else
285 pr_err("[%s] %s: No skb received",
286 ((struct net_device *)dev)->name, __func__);
287}
288
289static int _rmnet_xmit(struct sk_buff *skb, struct net_device *dev)
290{
291 struct rmnet_private *p = netdev_priv(dev);
292 int bam_ret;
293 struct QMI_QOS_HDR_S *qmih;
294 u32 opmode;
295 unsigned long flags;
296
297 /* For QoS mode, prepend QMI header and assign flow ID from skb->mark */
298 spin_lock_irqsave(&p->lock, flags);
299 opmode = p->operation_mode;
300 spin_unlock_irqrestore(&p->lock, flags);
301
302 if (RMNET_IS_MODE_QOS(opmode)) {
303 qmih = (struct QMI_QOS_HDR_S *)
304 skb_push(skb, sizeof(struct QMI_QOS_HDR_S));
305 qmih->version = 1;
306 qmih->flags = 0;
307 qmih->flow_id = skb->mark;
308 }
309
310 dev->trans_start = jiffies;
311 bam_ret = msm_bam_dmux_write(p->ch_id, skb);
312
313 if (bam_ret != 0) {
314 pr_err("[%s] %s: write returned error %d",
315 dev->name, __func__, bam_ret);
316 goto xmit_out;
317 }
318
319 if (count_this_packet(skb->data, skb->len)) {
320 p->stats.tx_packets++;
321 p->stats.tx_bytes += skb->len;
322#ifdef CONFIG_MSM_RMNET_DEBUG
323 p->wakeups_xmit += rmnet_cause_wakeup(p);
324#endif
325 }
326 DBG1("[%s] Tx packet #%lu len=%d mark=0x%x\n",
327 dev->name, p->stats.tx_packets, skb->len, skb->mark);
328
329 return 0;
330xmit_out:
331 /* data xmited, safe to release skb */
332 dev_kfree_skb_any(skb);
333 return 0;
334}
335
336static void bam_write_done(void *dev, struct sk_buff *skb)
337{
338 DBG1("%s: write complete\n", __func__);
339 dev_kfree_skb_any(skb);
340 netif_wake_queue(dev);
341}
342
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600343static void bam_notify(void *dev, int event, unsigned long data)
344{
Jeff Hugobac7ea22011-10-24 10:58:48 -0600345 struct rmnet_private *p = netdev_priv(dev);
346
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600347 switch (event) {
348 case BAM_DMUX_RECEIVE:
349 bam_recv_notify(dev, (struct sk_buff *)(data));
350 break;
351 case BAM_DMUX_WRITE_DONE:
352 bam_write_done(dev, (struct sk_buff *)(data));
353 break;
Jeff Hugobac7ea22011-10-24 10:58:48 -0600354 case BAM_DMUX_UL_CONNECTED:
355 ul_is_connected = 1;
356 if (p->waiting_for_ul) {
357 netif_wake_queue(dev);
358 p->waiting_for_ul = 0;
359 }
360 break;
361 case BAM_DMUX_UL_DISCONNECTED:
362 ul_is_connected = 0;
363 break;
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600364 }
365}
366
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700367static int __rmnet_open(struct net_device *dev)
368{
369 int r;
370 struct rmnet_private *p = netdev_priv(dev);
371
372 DBG0("[%s] __rmnet_open()\n", dev->name);
373
374 if (!p->device_up) {
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600375 r = msm_bam_dmux_open(p->ch_id, dev, bam_notify);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700376
Eric Holmberg70385482011-11-09 10:33:51 -0700377 if (r < 0) {
378 DBG0("%s: ch=%d failed with rc %d\n",
379 __func__, p->ch_id, r);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700380 return -ENODEV;
Eric Holmberg70385482011-11-09 10:33:51 -0700381 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700382 }
383
384 p->device_up = DEVICE_ACTIVE;
385 return 0;
386}
387
388static int rmnet_open(struct net_device *dev)
389{
390 int rc = 0;
391
392 DBG0("[%s] rmnet_open()\n", dev->name);
393
394 rc = __rmnet_open(dev);
395
396 if (rc == 0)
397 netif_start_queue(dev);
398
399 return rc;
400}
401
402
403static int __rmnet_close(struct net_device *dev)
404{
405 struct rmnet_private *p = netdev_priv(dev);
406 int rc = 0;
407
408 if (p->device_up) {
409 /* do not close rmnet port once up, this causes
410 remote side to hang if tried to open again */
411 p->device_up = DEVICE_INACTIVE;
412 return rc;
413 } else
414 return -EBADF;
415}
416
417
418static int rmnet_stop(struct net_device *dev)
419{
420 DBG0("[%s] rmnet_stop()\n", dev->name);
421
422 __rmnet_close(dev);
423 netif_stop_queue(dev);
424
425 return 0;
426}
427
428static int rmnet_change_mtu(struct net_device *dev, int new_mtu)
429{
430 if (0 > new_mtu || RMNET_DATA_LEN < new_mtu)
431 return -EINVAL;
432
433 DBG0("[%s] MTU change: old=%d new=%d\n",
434 dev->name, dev->mtu, new_mtu);
435 dev->mtu = new_mtu;
436
437 return 0;
438}
439
440static int rmnet_xmit(struct sk_buff *skb, struct net_device *dev)
441{
Jeff Hugobac7ea22011-10-24 10:58:48 -0600442 struct rmnet_private *p = netdev_priv(dev);
443
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700444 if (netif_queue_stopped(dev)) {
445 pr_err("[%s]fatal: rmnet_xmit called when "
446 "netif_queue is stopped", dev->name);
447 return 0;
448 }
449
450 netif_stop_queue(dev);
Jeff Hugobac7ea22011-10-24 10:58:48 -0600451 if (!ul_is_connected) {
452 p->waiting_for_ul = 1;
453 msm_bam_dmux_kickoff_ul_wakeup();
454 return NETDEV_TX_BUSY;
455 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700456 _rmnet_xmit(skb, dev);
457
458 return 0;
459}
460
461static struct net_device_stats *rmnet_get_stats(struct net_device *dev)
462{
463 struct rmnet_private *p = netdev_priv(dev);
464 return &p->stats;
465}
466
467static void rmnet_set_multicast_list(struct net_device *dev)
468{
469}
470
471static void rmnet_tx_timeout(struct net_device *dev)
472{
473 pr_warning("[%s] rmnet_tx_timeout()\n", dev->name);
474}
475
476static const struct net_device_ops rmnet_ops_ether = {
477 .ndo_open = rmnet_open,
478 .ndo_stop = rmnet_stop,
479 .ndo_start_xmit = rmnet_xmit,
480 .ndo_get_stats = rmnet_get_stats,
481 .ndo_set_multicast_list = rmnet_set_multicast_list,
482 .ndo_tx_timeout = rmnet_tx_timeout,
483 .ndo_do_ioctl = rmnet_ioctl,
484 .ndo_change_mtu = rmnet_change_mtu,
485 .ndo_set_mac_address = eth_mac_addr,
486 .ndo_validate_addr = eth_validate_addr,
487};
488
489static const struct net_device_ops rmnet_ops_ip = {
490 .ndo_open = rmnet_open,
491 .ndo_stop = rmnet_stop,
492 .ndo_start_xmit = rmnet_xmit,
493 .ndo_get_stats = rmnet_get_stats,
494 .ndo_set_multicast_list = rmnet_set_multicast_list,
495 .ndo_tx_timeout = rmnet_tx_timeout,
496 .ndo_do_ioctl = rmnet_ioctl,
497 .ndo_change_mtu = rmnet_change_mtu,
498 .ndo_set_mac_address = 0,
499 .ndo_validate_addr = 0,
500};
501
502static int rmnet_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
503{
504 struct rmnet_private *p = netdev_priv(dev);
505 u32 old_opmode = p->operation_mode;
506 unsigned long flags;
507 int prev_mtu = dev->mtu;
508 int rc = 0;
509
510 /* Process IOCTL command */
511 switch (cmd) {
512 case RMNET_IOCTL_SET_LLP_ETHERNET: /* Set Ethernet protocol */
513 /* Perform Ethernet config only if in IP mode currently*/
514 if (p->operation_mode & RMNET_MODE_LLP_IP) {
515 ether_setup(dev);
516 random_ether_addr(dev->dev_addr);
517 dev->mtu = prev_mtu;
518
519 dev->netdev_ops = &rmnet_ops_ether;
520 spin_lock_irqsave(&p->lock, flags);
521 p->operation_mode &= ~RMNET_MODE_LLP_IP;
522 p->operation_mode |= RMNET_MODE_LLP_ETH;
523 spin_unlock_irqrestore(&p->lock, flags);
524 DBG0("[%s] rmnet_ioctl(): "
525 "set Ethernet protocol mode\n",
526 dev->name);
527 }
528 break;
529
530 case RMNET_IOCTL_SET_LLP_IP: /* Set RAWIP protocol */
531 /* Perform IP config only if in Ethernet mode currently*/
532 if (p->operation_mode & RMNET_MODE_LLP_ETH) {
533
534 /* Undo config done in ether_setup() */
535 dev->header_ops = 0; /* No header */
536 dev->type = ARPHRD_RAWIP;
537 dev->hard_header_len = 0;
538 dev->mtu = prev_mtu;
539 dev->addr_len = 0;
540 dev->flags &= ~(IFF_BROADCAST|
541 IFF_MULTICAST);
542
543 dev->needed_headroom = HEADROOM_FOR_BAM +
544 HEADROOM_FOR_QOS;
545 dev->needed_tailroom = TAILROOM;
546 dev->netdev_ops = &rmnet_ops_ip;
547 spin_lock_irqsave(&p->lock, flags);
548 p->operation_mode &= ~RMNET_MODE_LLP_ETH;
549 p->operation_mode |= RMNET_MODE_LLP_IP;
550 spin_unlock_irqrestore(&p->lock, flags);
551 DBG0("[%s] rmnet_ioctl(): "
552 "set IP protocol mode\n",
553 dev->name);
554 }
555 break;
556
557 case RMNET_IOCTL_GET_LLP: /* Get link protocol state */
558 ifr->ifr_ifru.ifru_data =
559 (void *)(p->operation_mode &
560 (RMNET_MODE_LLP_ETH|RMNET_MODE_LLP_IP));
561 break;
562
563 case RMNET_IOCTL_SET_QOS_ENABLE: /* Set QoS header enabled */
564 spin_lock_irqsave(&p->lock, flags);
565 p->operation_mode |= RMNET_MODE_QOS;
566 spin_unlock_irqrestore(&p->lock, flags);
567 DBG0("[%s] rmnet_ioctl(): set QMI QOS header enable\n",
568 dev->name);
569 break;
570
571 case RMNET_IOCTL_SET_QOS_DISABLE: /* Set QoS header disabled */
572 spin_lock_irqsave(&p->lock, flags);
573 p->operation_mode &= ~RMNET_MODE_QOS;
574 spin_unlock_irqrestore(&p->lock, flags);
575 DBG0("[%s] rmnet_ioctl(): set QMI QOS header disable\n",
576 dev->name);
577 break;
578
579 case RMNET_IOCTL_GET_QOS: /* Get QoS header state */
580 ifr->ifr_ifru.ifru_data =
581 (void *)(p->operation_mode & RMNET_MODE_QOS);
582 break;
583
584 case RMNET_IOCTL_GET_OPMODE: /* Get operation mode */
585 ifr->ifr_ifru.ifru_data = (void *)p->operation_mode;
586 break;
587
588 case RMNET_IOCTL_OPEN: /* Open transport port */
589 rc = __rmnet_open(dev);
590 DBG0("[%s] rmnet_ioctl(): open transport port\n",
591 dev->name);
592 break;
593
594 case RMNET_IOCTL_CLOSE: /* Close transport port */
595 rc = __rmnet_close(dev);
596 DBG0("[%s] rmnet_ioctl(): close transport port\n",
597 dev->name);
598 break;
599
600 default:
601 pr_err("[%s] error: rmnet_ioct called for unsupported cmd[%d]",
602 dev->name, cmd);
603 return -EINVAL;
604 }
605
606 DBG2("[%s] %s: cmd=0x%x opmode old=0x%08x new=0x%08x\n",
607 dev->name, __func__, cmd, old_opmode, p->operation_mode);
608 return rc;
609}
610
611static void __init rmnet_setup(struct net_device *dev)
612{
613 /* Using Ethernet mode by default */
614 dev->netdev_ops = &rmnet_ops_ether;
615 ether_setup(dev);
616
617 /* set this after calling ether_setup */
618 dev->mtu = RMNET_DATA_LEN;
619 dev->needed_headroom = HEADROOM_FOR_BAM + HEADROOM_FOR_QOS ;
620 dev->needed_tailroom = TAILROOM;
621 random_ether_addr(dev->dev_addr);
622
623 dev->watchdog_timeo = 1000; /* 10 seconds? */
624}
625
Jeff Hugo24dfa0c2011-10-07 17:55:06 -0600626static struct net_device *netdevs[RMNET_DEVICE_COUNT];
627static struct platform_driver bam_rmnet_drivers[RMNET_DEVICE_COUNT];
628
629static int bam_rmnet_probe(struct platform_device *pdev)
630{
631 int i;
632 char name[BAM_DMUX_CH_NAME_MAX_LEN];
633 struct rmnet_private *p;
634
635 for (i = 0; i < RMNET_DEVICE_COUNT; ++i) {
636 scnprintf(name, BAM_DMUX_CH_NAME_MAX_LEN, "bam_dmux_ch_%d", i);
637 if (!strncmp(pdev->name, name, BAM_DMUX_CH_NAME_MAX_LEN))
638 break;
639 }
640
641 p = netdev_priv(netdevs[i]);
642 if (p->in_reset) {
643 p->in_reset = 0;
644 msm_bam_dmux_open(p->ch_id, netdevs[i], bam_notify);
645 netif_carrier_on(netdevs[i]);
646 netif_start_queue(netdevs[i]);
647 }
648
649 return 0;
650}
651
652static int bam_rmnet_remove(struct platform_device *pdev)
653{
654 int i;
655 char name[BAM_DMUX_CH_NAME_MAX_LEN];
656 struct rmnet_private *p;
657
658 for (i = 0; i < RMNET_DEVICE_COUNT; ++i) {
659 scnprintf(name, BAM_DMUX_CH_NAME_MAX_LEN, "bam_dmux_ch_%d", i);
660 if (!strncmp(pdev->name, name, BAM_DMUX_CH_NAME_MAX_LEN))
661 break;
662 }
663
664 p = netdev_priv(netdevs[i]);
665 p->in_reset = 1;
666 msm_bam_dmux_close(p->ch_id);
667 netif_carrier_off(netdevs[i]);
668 netif_stop_queue(netdevs[i]);
669 return 0;
670}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700671
672static int __init rmnet_init(void)
673{
674 int ret;
675 struct device *d;
676 struct net_device *dev;
677 struct rmnet_private *p;
678 unsigned n;
Jeff Hugo24dfa0c2011-10-07 17:55:06 -0600679 char *tempname;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700680
681 pr_info("%s: BAM devices[%d]\n", __func__, RMNET_DEVICE_COUNT);
682
683#ifdef CONFIG_MSM_RMNET_DEBUG
684 timeout_us = 0;
685#ifdef CONFIG_HAS_EARLYSUSPEND
686 timeout_suspend_us = 0;
687#endif
688#endif
689
690 for (n = 0; n < RMNET_DEVICE_COUNT; n++) {
691 dev = alloc_netdev(sizeof(struct rmnet_private),
692 "rmnet%d", rmnet_setup);
693
Eric Holmberg70385482011-11-09 10:33:51 -0700694 if (!dev) {
695 pr_err("%s: no memory for netdev %d\n", __func__, n);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700696 return -ENOMEM;
Eric Holmberg70385482011-11-09 10:33:51 -0700697 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700698
Jeff Hugo24dfa0c2011-10-07 17:55:06 -0600699 netdevs[n] = dev;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700700 d = &(dev->dev);
701 p = netdev_priv(dev);
702 /* Initial config uses Ethernet */
703 p->operation_mode = RMNET_MODE_LLP_ETH;
704 p->ch_id = n;
Jeff Hugobac7ea22011-10-24 10:58:48 -0600705 p->waiting_for_ul = 0;
Jeff Hugo24dfa0c2011-10-07 17:55:06 -0600706 p->in_reset = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700707 spin_lock_init(&p->lock);
708#ifdef CONFIG_MSM_RMNET_DEBUG
709 p->timeout_us = timeout_us;
710 p->wakeups_xmit = p->wakeups_rcv = 0;
711#endif
712
713 ret = register_netdev(dev);
714 if (ret) {
Eric Holmberg70385482011-11-09 10:33:51 -0700715 pr_err("%s: unable to register netdev"
716 " %d rc=%d\n", __func__, n, ret);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700717 free_netdev(dev);
718 return ret;
719 }
720
721#ifdef CONFIG_MSM_RMNET_DEBUG
722 if (device_create_file(d, &dev_attr_timeout))
723 continue;
724 if (device_create_file(d, &dev_attr_wakeups_xmit))
725 continue;
726 if (device_create_file(d, &dev_attr_wakeups_rcv))
727 continue;
728#ifdef CONFIG_HAS_EARLYSUSPEND
729 if (device_create_file(d, &dev_attr_timeout_suspend))
730 continue;
731
732 /* Only care about rmnet0 for suspend/resume tiemout hooks. */
733 if (n == 0)
734 rmnet0 = d;
735#endif
736#endif
Jeff Hugo24dfa0c2011-10-07 17:55:06 -0600737 bam_rmnet_drivers[n].probe = bam_rmnet_probe;
738 bam_rmnet_drivers[n].remove = bam_rmnet_remove;
739 tempname = kmalloc(BAM_DMUX_CH_NAME_MAX_LEN, GFP_KERNEL);
740 if (tempname == NULL)
741 return -ENOMEM;
742 scnprintf(tempname, BAM_DMUX_CH_NAME_MAX_LEN, "bam_dmux_ch_%d",
743 n);
744 bam_rmnet_drivers[n].driver.name = tempname;
745 bam_rmnet_drivers[n].driver.owner = THIS_MODULE;
746 ret = platform_driver_register(&bam_rmnet_drivers[n]);
Eric Holmbergbd4c3842011-11-08 13:48:19 -0700747 if (ret) {
748 pr_err("%s: registration failed n=%d rc=%d\n",
749 __func__, n, ret);
Jeff Hugo24dfa0c2011-10-07 17:55:06 -0600750 return ret;
Eric Holmbergbd4c3842011-11-08 13:48:19 -0700751 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700752 }
753 return 0;
754}
755
756module_init(rmnet_init);
757MODULE_DESCRIPTION("MSM RMNET BAM TRANSPORT");
758MODULE_LICENSE("GPL v2");
759