Chiranjeevi Velempati | a06b223 | 2013-01-04 10:10:52 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2011-2013, Linux Foundation. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 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 | #include <linux/kernel.h> |
| 14 | #include <linux/interrupt.h> |
| 15 | #include <linux/device.h> |
| 16 | #include <linux/delay.h> |
| 17 | #include <linux/slab.h> |
| 18 | #include <linux/termios.h> |
| 19 | #include <mach/msm_smd.h> |
| 20 | #include <linux/netdevice.h> |
| 21 | #include <mach/bam_dmux.h> |
| 22 | #include <linux/debugfs.h> |
| 23 | #include <linux/bitops.h> |
| 24 | #include <linux/termios.h> |
| 25 | |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 26 | #include <mach/usb_gadget_xport.h> |
Shimrit Malichi | 194fe12 | 2012-07-25 13:50:41 +0300 | [diff] [blame] | 27 | #include <linux/usb/msm_hsusb.h> |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 28 | #include <mach/usb_bam.h> |
| 29 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 30 | #include "u_rmnet.h" |
| 31 | |
| 32 | #define BAM_N_PORTS 1 |
Anna Perel | 2151516 | 2012-02-02 20:50:02 +0200 | [diff] [blame] | 33 | #define BAM2BAM_N_PORTS 3 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 34 | |
| 35 | static struct workqueue_struct *gbam_wq; |
| 36 | static int n_bam_ports; |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 37 | static int n_bam2bam_ports; |
Vijayavardhan Vennapusa | 08c3125 | 2011-12-21 13:02:49 +0530 | [diff] [blame] | 38 | static unsigned n_tx_req_queued; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 39 | static unsigned bam_ch_ids[] = { 8 }; |
| 40 | |
Jack Pham | effd4ae | 2011-08-03 16:49:36 -0700 | [diff] [blame] | 41 | static const char *bam_ch_names[] = { "bam_dmux_ch_8" }; |
| 42 | |
Vamsi Krishna | 8457955 | 2011-11-09 15:33:22 -0800 | [diff] [blame] | 43 | #define BAM_PENDING_LIMIT 220 |
Vamsi Krishna | 8f24f25 | 2011-11-02 11:46:08 -0700 | [diff] [blame] | 44 | #define BAM_MUX_TX_PKT_DROP_THRESHOLD 1000 |
Vamsi Krishna | 8457955 | 2011-11-09 15:33:22 -0800 | [diff] [blame] | 45 | #define BAM_MUX_RX_PKT_FCTRL_EN_TSHOLD 500 |
| 46 | #define BAM_MUX_RX_PKT_FCTRL_DIS_TSHOLD 300 |
Vamsi Krishna | 8f24f25 | 2011-11-02 11:46:08 -0700 | [diff] [blame] | 47 | #define BAM_MUX_RX_PKT_FLOW_CTRL_SUPPORT 1 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 48 | |
| 49 | #define BAM_MUX_HDR 8 |
| 50 | |
Vamsi Krishna | 8f24f25 | 2011-11-02 11:46:08 -0700 | [diff] [blame] | 51 | #define BAM_MUX_RX_Q_SIZE 16 |
| 52 | #define BAM_MUX_TX_Q_SIZE 200 |
Manu Gautam | 1520330 | 2012-09-26 11:12:54 +0530 | [diff] [blame] | 53 | #define BAM_MUX_RX_REQ_SIZE 2048 /* Must be 1KB aligned */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 54 | |
Vijayavardhan Vennapusa | 08c3125 | 2011-12-21 13:02:49 +0530 | [diff] [blame] | 55 | #define DL_INTR_THRESHOLD 20 |
| 56 | |
Vijayavardhan Vennapusa | 2001b03 | 2014-01-07 13:11:51 +0530 | [diff] [blame] | 57 | static unsigned int bam_pending_limit = BAM_PENDING_LIMIT; |
| 58 | module_param(bam_pending_limit, uint, S_IRUGO | S_IWUSR); |
| 59 | |
| 60 | static unsigned int bam_mux_tx_pkt_drop_thld = BAM_MUX_TX_PKT_DROP_THRESHOLD; |
Vamsi Krishna | 8f24f25 | 2011-11-02 11:46:08 -0700 | [diff] [blame] | 61 | module_param(bam_mux_tx_pkt_drop_thld, uint, S_IRUGO | S_IWUSR); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 62 | |
Vijayavardhan Vennapusa | 2001b03 | 2014-01-07 13:11:51 +0530 | [diff] [blame] | 63 | static unsigned int bam_mux_rx_fctrl_en_thld = BAM_MUX_RX_PKT_FCTRL_EN_TSHOLD; |
Vamsi Krishna | 8f24f25 | 2011-11-02 11:46:08 -0700 | [diff] [blame] | 64 | module_param(bam_mux_rx_fctrl_en_thld, uint, S_IRUGO | S_IWUSR); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 65 | |
Vijayavardhan Vennapusa | 2001b03 | 2014-01-07 13:11:51 +0530 | [diff] [blame] | 66 | static unsigned int bam_mux_rx_fctrl_support = BAM_MUX_RX_PKT_FLOW_CTRL_SUPPORT; |
Vamsi Krishna | 8f24f25 | 2011-11-02 11:46:08 -0700 | [diff] [blame] | 67 | module_param(bam_mux_rx_fctrl_support, uint, S_IRUGO | S_IWUSR); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 68 | |
Vijayavardhan Vennapusa | 2001b03 | 2014-01-07 13:11:51 +0530 | [diff] [blame] | 69 | static unsigned int bam_mux_rx_fctrl_dis_thld = BAM_MUX_RX_PKT_FCTRL_DIS_TSHOLD; |
Vamsi Krishna | 8f24f25 | 2011-11-02 11:46:08 -0700 | [diff] [blame] | 70 | module_param(bam_mux_rx_fctrl_dis_thld, uint, S_IRUGO | S_IWUSR); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 71 | |
Vijayavardhan Vennapusa | 2001b03 | 2014-01-07 13:11:51 +0530 | [diff] [blame] | 72 | static unsigned int bam_mux_tx_q_size = BAM_MUX_TX_Q_SIZE; |
Vamsi Krishna | 8f24f25 | 2011-11-02 11:46:08 -0700 | [diff] [blame] | 73 | module_param(bam_mux_tx_q_size, uint, S_IRUGO | S_IWUSR); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 74 | |
Vijayavardhan Vennapusa | 2001b03 | 2014-01-07 13:11:51 +0530 | [diff] [blame] | 75 | static unsigned int bam_mux_rx_q_size = BAM_MUX_RX_Q_SIZE; |
Vamsi Krishna | 8f24f25 | 2011-11-02 11:46:08 -0700 | [diff] [blame] | 76 | module_param(bam_mux_rx_q_size, uint, S_IRUGO | S_IWUSR); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 77 | |
Vijayavardhan Vennapusa | 2001b03 | 2014-01-07 13:11:51 +0530 | [diff] [blame] | 78 | static unsigned int bam_mux_rx_req_size = BAM_MUX_RX_REQ_SIZE; |
Vamsi Krishna | 8f24f25 | 2011-11-02 11:46:08 -0700 | [diff] [blame] | 79 | module_param(bam_mux_rx_req_size, uint, S_IRUGO | S_IWUSR); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 80 | |
Vijayavardhan Vennapusa | 2001b03 | 2014-01-07 13:11:51 +0530 | [diff] [blame] | 81 | static unsigned int dl_intr_threshold = DL_INTR_THRESHOLD; |
Vijayavardhan Vennapusa | 08c3125 | 2011-12-21 13:02:49 +0530 | [diff] [blame] | 82 | module_param(dl_intr_threshold, uint, S_IRUGO | S_IWUSR); |
| 83 | |
Jack Pham | effd4ae | 2011-08-03 16:49:36 -0700 | [diff] [blame] | 84 | #define BAM_CH_OPENED BIT(0) |
| 85 | #define BAM_CH_READY BIT(1) |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 86 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 87 | struct bam_ch_info { |
Jack Pham | effd4ae | 2011-08-03 16:49:36 -0700 | [diff] [blame] | 88 | unsigned long flags; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 89 | unsigned id; |
| 90 | |
| 91 | struct list_head tx_idle; |
| 92 | struct sk_buff_head tx_skb_q; |
| 93 | |
| 94 | struct list_head rx_idle; |
| 95 | struct sk_buff_head rx_skb_q; |
| 96 | |
| 97 | struct gbam_port *port; |
| 98 | struct work_struct write_tobam_w; |
Vijayavardhan Vennapusa | 929e579 | 2011-12-12 17:34:53 +0530 | [diff] [blame] | 99 | struct work_struct write_tohost_w; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 100 | |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 101 | struct usb_request *rx_req; |
| 102 | struct usb_request *tx_req; |
| 103 | |
Shimrit Malichi | 255b534 | 2012-08-02 21:01:43 +0300 | [diff] [blame] | 104 | u32 src_pipe_idx; |
| 105 | u32 dst_pipe_idx; |
Shimrit Malichi | dbf43d7 | 2013-03-16 03:32:27 +0200 | [diff] [blame] | 106 | u8 src_connection_idx; |
| 107 | u8 dst_connection_idx; |
Ofir Cohen | fdecb60 | 2012-11-16 15:50:01 +0200 | [diff] [blame] | 108 | enum transport_type trans; |
Ofir Cohen | 77848d6 | 2012-12-05 13:16:10 +0200 | [diff] [blame] | 109 | struct usb_bam_connect_ipa_params ipa_params; |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 110 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 111 | /* stats */ |
| 112 | unsigned int pending_with_bam; |
| 113 | unsigned int tohost_drp_cnt; |
| 114 | unsigned int tomodem_drp_cnt; |
| 115 | unsigned int tx_len; |
| 116 | unsigned int rx_len; |
| 117 | unsigned long to_modem; |
| 118 | unsigned long to_host; |
Vijayavardhan Vennapusa | 2001b03 | 2014-01-07 13:11:51 +0530 | [diff] [blame] | 119 | unsigned int rx_flow_control_disable; |
| 120 | unsigned int rx_flow_control_enable; |
| 121 | unsigned int rx_flow_control_triggered; |
| 122 | unsigned int max_num_pkts_pending_with_bam; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | struct gbam_port { |
| 126 | unsigned port_num; |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 127 | spinlock_t port_lock_ul; |
| 128 | spinlock_t port_lock_dl; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 129 | |
| 130 | struct grmnet *port_usb; |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 131 | struct grmnet *gr; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 132 | |
| 133 | struct bam_ch_info data_ch; |
| 134 | |
| 135 | struct work_struct connect_w; |
Vamsi Krishna | 1ad076d | 2011-11-10 15:03:30 -0800 | [diff] [blame] | 136 | struct work_struct disconnect_w; |
Bar Weiner | 84e1ba0 | 2013-07-18 09:08:03 +0300 | [diff] [blame] | 137 | struct work_struct suspend_w; |
| 138 | struct work_struct resume_w; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 139 | }; |
| 140 | |
| 141 | static struct bam_portmaster { |
| 142 | struct gbam_port *port; |
Jack Pham | effd4ae | 2011-08-03 16:49:36 -0700 | [diff] [blame] | 143 | struct platform_driver pdrv; |
| 144 | } bam_ports[BAM_N_PORTS]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 145 | |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 146 | struct gbam_port *bam2bam_ports[BAM2BAM_N_PORTS]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 147 | static void gbam_start_rx(struct gbam_port *port); |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 148 | static void gbam_start_endless_rx(struct gbam_port *port); |
| 149 | static void gbam_start_endless_tx(struct gbam_port *port); |
Amit Blay | 9452535 | 2012-12-24 11:23:27 +0200 | [diff] [blame] | 150 | static int gbam_peer_reset_cb(void *param); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 151 | |
| 152 | /*---------------misc functions---------------- */ |
| 153 | static void gbam_free_requests(struct usb_ep *ep, struct list_head *head) |
| 154 | { |
| 155 | struct usb_request *req; |
| 156 | |
| 157 | while (!list_empty(head)) { |
| 158 | req = list_entry(head->next, struct usb_request, list); |
| 159 | list_del(&req->list); |
| 160 | usb_ep_free_request(ep, req); |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | static int gbam_alloc_requests(struct usb_ep *ep, struct list_head *head, |
| 165 | int num, |
| 166 | void (*cb)(struct usb_ep *ep, struct usb_request *), |
| 167 | gfp_t flags) |
| 168 | { |
| 169 | int i; |
| 170 | struct usb_request *req; |
| 171 | |
| 172 | pr_debug("%s: ep:%p head:%p num:%d cb:%p", __func__, |
| 173 | ep, head, num, cb); |
| 174 | |
| 175 | for (i = 0; i < num; i++) { |
| 176 | req = usb_ep_alloc_request(ep, flags); |
| 177 | if (!req) { |
| 178 | pr_debug("%s: req allocated:%d\n", __func__, i); |
| 179 | return list_empty(head) ? -ENOMEM : 0; |
| 180 | } |
| 181 | req->complete = cb; |
| 182 | list_add(&req->list, head); |
| 183 | } |
| 184 | |
| 185 | return 0; |
| 186 | } |
| 187 | /*--------------------------------------------- */ |
| 188 | |
| 189 | /*------------data_path----------------------------*/ |
Chiranjeevi Velempati | e510592 | 2012-01-19 12:25:26 +0530 | [diff] [blame] | 190 | static void gbam_write_data_tohost(struct gbam_port *port) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 191 | { |
| 192 | unsigned long flags; |
Chiranjeevi Velempati | e510592 | 2012-01-19 12:25:26 +0530 | [diff] [blame] | 193 | struct bam_ch_info *d = &port->data_ch; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 194 | struct sk_buff *skb; |
| 195 | int ret; |
| 196 | struct usb_request *req; |
| 197 | struct usb_ep *ep; |
| 198 | |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 199 | spin_lock_irqsave(&port->port_lock_dl, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 200 | if (!port->port_usb) { |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 201 | spin_unlock_irqrestore(&port->port_lock_dl, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 202 | return; |
| 203 | } |
| 204 | |
| 205 | ep = port->port_usb->in; |
| 206 | |
| 207 | while (!list_empty(&d->tx_idle)) { |
| 208 | skb = __skb_dequeue(&d->tx_skb_q); |
| 209 | if (!skb) { |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 210 | spin_unlock_irqrestore(&port->port_lock_dl, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 211 | return; |
| 212 | } |
| 213 | req = list_first_entry(&d->tx_idle, |
| 214 | struct usb_request, |
| 215 | list); |
| 216 | req->context = skb; |
| 217 | req->buf = skb->data; |
| 218 | req->length = skb->len; |
Vijayavardhan Vennapusa | 08c3125 | 2011-12-21 13:02:49 +0530 | [diff] [blame] | 219 | n_tx_req_queued++; |
| 220 | if (n_tx_req_queued == dl_intr_threshold) { |
| 221 | req->no_interrupt = 0; |
| 222 | n_tx_req_queued = 0; |
| 223 | } else { |
| 224 | req->no_interrupt = 1; |
| 225 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 226 | |
Rajkumar Raghupathy | f05df31 | 2013-06-04 17:57:49 +0530 | [diff] [blame] | 227 | /* Send ZLP in case packet length is multiple of maxpacksize */ |
| 228 | req->zero = 1; |
| 229 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 230 | list_del(&req->list); |
| 231 | |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 232 | spin_unlock(&port->port_lock_dl); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 233 | ret = usb_ep_queue(ep, req, GFP_ATOMIC); |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 234 | spin_lock(&port->port_lock_dl); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 235 | if (ret) { |
Chiranjeevi Velempati | a06b223 | 2013-01-04 10:10:52 +0530 | [diff] [blame] | 236 | pr_err("%s: usb epIn failed with %d\n", __func__, ret); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 237 | list_add(&req->list, &d->tx_idle); |
| 238 | dev_kfree_skb_any(skb); |
| 239 | break; |
| 240 | } |
| 241 | d->to_host++; |
| 242 | } |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 243 | spin_unlock_irqrestore(&port->port_lock_dl, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 244 | } |
| 245 | |
Chiranjeevi Velempati | e510592 | 2012-01-19 12:25:26 +0530 | [diff] [blame] | 246 | static void gbam_write_data_tohost_w(struct work_struct *w) |
| 247 | { |
| 248 | struct bam_ch_info *d; |
| 249 | struct gbam_port *port; |
| 250 | |
| 251 | d = container_of(w, struct bam_ch_info, write_tohost_w); |
| 252 | port = d->port; |
| 253 | |
| 254 | gbam_write_data_tohost(port); |
| 255 | } |
| 256 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 257 | void gbam_data_recv_cb(void *p, struct sk_buff *skb) |
| 258 | { |
| 259 | struct gbam_port *port = p; |
| 260 | struct bam_ch_info *d = &port->data_ch; |
| 261 | unsigned long flags; |
| 262 | |
| 263 | if (!skb) |
| 264 | return; |
| 265 | |
| 266 | pr_debug("%s: p:%p#%d d:%p skb_len:%d\n", __func__, |
| 267 | port, port->port_num, d, skb->len); |
| 268 | |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 269 | spin_lock_irqsave(&port->port_lock_dl, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 270 | if (!port->port_usb) { |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 271 | spin_unlock_irqrestore(&port->port_lock_dl, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 272 | dev_kfree_skb_any(skb); |
| 273 | return; |
| 274 | } |
| 275 | |
Vamsi Krishna | 8f24f25 | 2011-11-02 11:46:08 -0700 | [diff] [blame] | 276 | if (d->tx_skb_q.qlen > bam_mux_tx_pkt_drop_thld) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 277 | d->tohost_drp_cnt++; |
| 278 | if (printk_ratelimit()) |
| 279 | pr_err("%s: tx pkt dropped: tx_drop_cnt:%u\n", |
| 280 | __func__, d->tohost_drp_cnt); |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 281 | spin_unlock_irqrestore(&port->port_lock_dl, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 282 | dev_kfree_skb_any(skb); |
| 283 | return; |
| 284 | } |
| 285 | |
| 286 | __skb_queue_tail(&d->tx_skb_q, skb); |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 287 | spin_unlock_irqrestore(&port->port_lock_dl, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 288 | |
Chiranjeevi Velempati | e510592 | 2012-01-19 12:25:26 +0530 | [diff] [blame] | 289 | gbam_write_data_tohost(port); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | void gbam_data_write_done(void *p, struct sk_buff *skb) |
| 293 | { |
| 294 | struct gbam_port *port = p; |
| 295 | struct bam_ch_info *d = &port->data_ch; |
| 296 | unsigned long flags; |
| 297 | |
| 298 | if (!skb) |
| 299 | return; |
| 300 | |
| 301 | dev_kfree_skb_any(skb); |
| 302 | |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 303 | spin_lock_irqsave(&port->port_lock_ul, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 304 | |
| 305 | d->pending_with_bam--; |
| 306 | |
| 307 | pr_debug("%s: port:%p d:%p tom:%lu pbam:%u, pno:%d\n", __func__, |
| 308 | port, d, d->to_modem, |
| 309 | d->pending_with_bam, port->port_num); |
| 310 | |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 311 | spin_unlock_irqrestore(&port->port_lock_ul, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 312 | |
Vamsi Krishna | 8457955 | 2011-11-09 15:33:22 -0800 | [diff] [blame] | 313 | queue_work(gbam_wq, &d->write_tobam_w); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | static void gbam_data_write_tobam(struct work_struct *w) |
| 317 | { |
| 318 | struct gbam_port *port; |
| 319 | struct bam_ch_info *d; |
| 320 | struct sk_buff *skb; |
| 321 | unsigned long flags; |
| 322 | int ret; |
Vamsi Krishna | 8457955 | 2011-11-09 15:33:22 -0800 | [diff] [blame] | 323 | int qlen; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 324 | |
| 325 | d = container_of(w, struct bam_ch_info, write_tobam_w); |
| 326 | port = d->port; |
| 327 | |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 328 | spin_lock_irqsave(&port->port_lock_ul, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 329 | if (!port->port_usb) { |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 330 | spin_unlock_irqrestore(&port->port_lock_ul, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 331 | return; |
| 332 | } |
| 333 | |
Vijayavardhan Vennapusa | 2001b03 | 2014-01-07 13:11:51 +0530 | [diff] [blame] | 334 | while (d->pending_with_bam < bam_pending_limit) { |
Vamsi Krishna | 2327c7915 | 2011-11-08 16:12:42 -0800 | [diff] [blame] | 335 | skb = __skb_dequeue(&d->rx_skb_q); |
Vamsi Krishna | 625c28e | 2011-12-16 22:34:49 -0800 | [diff] [blame] | 336 | if (!skb) |
| 337 | break; |
| 338 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 339 | d->pending_with_bam++; |
| 340 | d->to_modem++; |
| 341 | |
| 342 | pr_debug("%s: port:%p d:%p tom:%lu pbam:%u pno:%d\n", __func__, |
| 343 | port, d, d->to_modem, d->pending_with_bam, |
| 344 | port->port_num); |
| 345 | |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 346 | spin_unlock_irqrestore(&port->port_lock_ul, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 347 | ret = msm_bam_dmux_write(d->id, skb); |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 348 | spin_lock_irqsave(&port->port_lock_ul, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 349 | if (ret) { |
| 350 | pr_debug("%s: write error:%d\n", __func__, ret); |
| 351 | d->pending_with_bam--; |
| 352 | d->to_modem--; |
| 353 | d->tomodem_drp_cnt++; |
| 354 | dev_kfree_skb_any(skb); |
| 355 | break; |
| 356 | } |
Vijayavardhan Vennapusa | 2001b03 | 2014-01-07 13:11:51 +0530 | [diff] [blame] | 357 | if (d->pending_with_bam > d->max_num_pkts_pending_with_bam) |
| 358 | d->max_num_pkts_pending_with_bam = d->pending_with_bam; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 359 | } |
Vamsi Krishna | 8457955 | 2011-11-09 15:33:22 -0800 | [diff] [blame] | 360 | |
| 361 | qlen = d->rx_skb_q.qlen; |
| 362 | |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 363 | spin_unlock_irqrestore(&port->port_lock_ul, flags); |
Vamsi Krishna | 8457955 | 2011-11-09 15:33:22 -0800 | [diff] [blame] | 364 | |
Vijayavardhan Vennapusa | 2001b03 | 2014-01-07 13:11:51 +0530 | [diff] [blame] | 365 | if (qlen < bam_mux_rx_fctrl_dis_thld) { |
| 366 | if (d->rx_flow_control_triggered) { |
| 367 | d->rx_flow_control_disable++; |
| 368 | d->rx_flow_control_triggered = 0; |
| 369 | } |
Vamsi Krishna | 8457955 | 2011-11-09 15:33:22 -0800 | [diff] [blame] | 370 | gbam_start_rx(port); |
Vijayavardhan Vennapusa | 2001b03 | 2014-01-07 13:11:51 +0530 | [diff] [blame] | 371 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 372 | } |
| 373 | /*-------------------------------------------------------------*/ |
| 374 | |
| 375 | static void gbam_epin_complete(struct usb_ep *ep, struct usb_request *req) |
| 376 | { |
| 377 | struct gbam_port *port = ep->driver_data; |
| 378 | struct bam_ch_info *d; |
| 379 | struct sk_buff *skb = req->context; |
| 380 | int status = req->status; |
| 381 | |
| 382 | switch (status) { |
| 383 | case 0: |
| 384 | /* successful completion */ |
Manu Gautam | 06277e4 | 2013-04-01 15:07:29 +0530 | [diff] [blame] | 385 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 386 | case -ECONNRESET: |
| 387 | case -ESHUTDOWN: |
| 388 | /* connection gone */ |
Manu Gautam | 06277e4 | 2013-04-01 15:07:29 +0530 | [diff] [blame] | 389 | dev_kfree_skb_any(skb); |
| 390 | usb_ep_free_request(ep, req); |
| 391 | return; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 392 | default: |
| 393 | pr_err("%s: data tx ep error %d\n", |
| 394 | __func__, status); |
| 395 | break; |
| 396 | } |
| 397 | |
| 398 | dev_kfree_skb_any(skb); |
| 399 | |
| 400 | if (!port) |
| 401 | return; |
| 402 | |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 403 | spin_lock(&port->port_lock_dl); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 404 | d = &port->data_ch; |
| 405 | list_add_tail(&req->list, &d->tx_idle); |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 406 | spin_unlock(&port->port_lock_dl); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 407 | |
Vijayavardhan Vennapusa | 929e579 | 2011-12-12 17:34:53 +0530 | [diff] [blame] | 408 | queue_work(gbam_wq, &d->write_tohost_w); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | static void |
| 412 | gbam_epout_complete(struct usb_ep *ep, struct usb_request *req) |
| 413 | { |
| 414 | struct gbam_port *port = ep->driver_data; |
| 415 | struct bam_ch_info *d = &port->data_ch; |
| 416 | struct sk_buff *skb = req->context; |
| 417 | int status = req->status; |
| 418 | int queue = 0; |
| 419 | |
| 420 | switch (status) { |
| 421 | case 0: |
| 422 | skb_put(skb, req->actual); |
| 423 | queue = 1; |
| 424 | break; |
| 425 | case -ECONNRESET: |
| 426 | case -ESHUTDOWN: |
| 427 | /* cable disconnection */ |
| 428 | dev_kfree_skb_any(skb); |
| 429 | req->buf = 0; |
| 430 | usb_ep_free_request(ep, req); |
| 431 | return; |
| 432 | default: |
| 433 | if (printk_ratelimit()) |
| 434 | pr_err("%s: %s response error %d, %d/%d\n", |
| 435 | __func__, ep->name, status, |
| 436 | req->actual, req->length); |
| 437 | dev_kfree_skb_any(skb); |
| 438 | break; |
| 439 | } |
| 440 | |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 441 | spin_lock(&port->port_lock_ul); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 442 | if (queue) { |
| 443 | __skb_queue_tail(&d->rx_skb_q, skb); |
| 444 | queue_work(gbam_wq, &d->write_tobam_w); |
| 445 | } |
| 446 | |
| 447 | /* TODO: Handle flow control gracefully by having |
| 448 | * having call back mechanism from bam driver |
| 449 | */ |
Vamsi Krishna | 8f24f25 | 2011-11-02 11:46:08 -0700 | [diff] [blame] | 450 | if (bam_mux_rx_fctrl_support && |
Vamsi Krishna | 8457955 | 2011-11-09 15:33:22 -0800 | [diff] [blame] | 451 | d->rx_skb_q.qlen >= bam_mux_rx_fctrl_en_thld) { |
Vijayavardhan Vennapusa | 2001b03 | 2014-01-07 13:11:51 +0530 | [diff] [blame] | 452 | if (!d->rx_flow_control_triggered) { |
| 453 | d->rx_flow_control_triggered = 1; |
| 454 | d->rx_flow_control_enable++; |
| 455 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 456 | list_add_tail(&req->list, &d->rx_idle); |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 457 | spin_unlock(&port->port_lock_ul); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 458 | return; |
| 459 | } |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 460 | spin_unlock(&port->port_lock_ul); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 461 | |
Vamsi Krishna | 8f24f25 | 2011-11-02 11:46:08 -0700 | [diff] [blame] | 462 | skb = alloc_skb(bam_mux_rx_req_size + BAM_MUX_HDR, GFP_ATOMIC); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 463 | if (!skb) { |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 464 | spin_lock(&port->port_lock_ul); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 465 | list_add_tail(&req->list, &d->rx_idle); |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 466 | spin_unlock(&port->port_lock_ul); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 467 | return; |
| 468 | } |
| 469 | skb_reserve(skb, BAM_MUX_HDR); |
| 470 | |
| 471 | req->buf = skb->data; |
Vamsi Krishna | 8f24f25 | 2011-11-02 11:46:08 -0700 | [diff] [blame] | 472 | req->length = bam_mux_rx_req_size; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 473 | req->context = skb; |
| 474 | |
| 475 | status = usb_ep_queue(ep, req, GFP_ATOMIC); |
| 476 | if (status) { |
| 477 | dev_kfree_skb_any(skb); |
| 478 | |
| 479 | if (printk_ratelimit()) |
| 480 | pr_err("%s: data rx enqueue err %d\n", |
| 481 | __func__, status); |
| 482 | |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 483 | spin_lock(&port->port_lock_ul); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 484 | list_add_tail(&req->list, &d->rx_idle); |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 485 | spin_unlock(&port->port_lock_ul); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 486 | } |
| 487 | } |
| 488 | |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 489 | static void gbam_endless_rx_complete(struct usb_ep *ep, struct usb_request *req) |
| 490 | { |
| 491 | int status = req->status; |
| 492 | |
| 493 | pr_debug("%s status: %d\n", __func__, status); |
| 494 | } |
| 495 | |
| 496 | static void gbam_endless_tx_complete(struct usb_ep *ep, struct usb_request *req) |
| 497 | { |
| 498 | int status = req->status; |
| 499 | |
| 500 | pr_debug("%s status: %d\n", __func__, status); |
| 501 | } |
| 502 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 503 | static void gbam_start_rx(struct gbam_port *port) |
| 504 | { |
| 505 | struct usb_request *req; |
| 506 | struct bam_ch_info *d; |
| 507 | struct usb_ep *ep; |
| 508 | unsigned long flags; |
| 509 | int ret; |
| 510 | struct sk_buff *skb; |
| 511 | |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 512 | spin_lock_irqsave(&port->port_lock_ul, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 513 | if (!port->port_usb) { |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 514 | spin_unlock_irqrestore(&port->port_lock_ul, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 515 | return; |
| 516 | } |
| 517 | |
| 518 | d = &port->data_ch; |
| 519 | ep = port->port_usb->out; |
| 520 | |
| 521 | while (port->port_usb && !list_empty(&d->rx_idle)) { |
Vamsi Krishna | 8457955 | 2011-11-09 15:33:22 -0800 | [diff] [blame] | 522 | |
| 523 | if (bam_mux_rx_fctrl_support && |
| 524 | d->rx_skb_q.qlen >= bam_mux_rx_fctrl_en_thld) |
| 525 | break; |
| 526 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 527 | req = list_first_entry(&d->rx_idle, struct usb_request, list); |
| 528 | |
Vamsi Krishna | 8f24f25 | 2011-11-02 11:46:08 -0700 | [diff] [blame] | 529 | skb = alloc_skb(bam_mux_rx_req_size + BAM_MUX_HDR, GFP_ATOMIC); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 530 | if (!skb) |
| 531 | break; |
| 532 | skb_reserve(skb, BAM_MUX_HDR); |
| 533 | |
| 534 | list_del(&req->list); |
| 535 | req->buf = skb->data; |
Vamsi Krishna | 8f24f25 | 2011-11-02 11:46:08 -0700 | [diff] [blame] | 536 | req->length = bam_mux_rx_req_size; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 537 | req->context = skb; |
| 538 | |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 539 | spin_unlock_irqrestore(&port->port_lock_ul, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 540 | ret = usb_ep_queue(ep, req, GFP_ATOMIC); |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 541 | spin_lock_irqsave(&port->port_lock_ul, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 542 | if (ret) { |
| 543 | dev_kfree_skb_any(skb); |
| 544 | |
| 545 | if (printk_ratelimit()) |
Chiranjeevi Velempati | a06b223 | 2013-01-04 10:10:52 +0530 | [diff] [blame] | 546 | pr_err("%s: rx queue failed %d\n", |
| 547 | __func__, ret); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 548 | |
| 549 | if (port->port_usb) |
| 550 | list_add(&req->list, &d->rx_idle); |
| 551 | else |
| 552 | usb_ep_free_request(ep, req); |
| 553 | break; |
| 554 | } |
| 555 | } |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 556 | spin_unlock_irqrestore(&port->port_lock_ul, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 557 | } |
| 558 | |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 559 | static void gbam_start_endless_rx(struct gbam_port *port) |
| 560 | { |
| 561 | struct bam_ch_info *d = &port->data_ch; |
| 562 | int status; |
| 563 | |
Lena Salman | a12bc32 | 2013-07-02 15:04:42 +0300 | [diff] [blame] | 564 | spin_lock(&port->port_lock_ul); |
Lena Salman | 05b544f | 2013-05-13 15:49:10 +0300 | [diff] [blame] | 565 | if (!port->port_usb) { |
Lena Salman | a12bc32 | 2013-07-02 15:04:42 +0300 | [diff] [blame] | 566 | spin_unlock(&port->port_lock_ul); |
Lena Salman | 05b544f | 2013-05-13 15:49:10 +0300 | [diff] [blame] | 567 | pr_err("%s: port->port_usb is NULL", __func__); |
Amit Blay | 9452535 | 2012-12-24 11:23:27 +0200 | [diff] [blame] | 568 | return; |
Lena Salman | 05b544f | 2013-05-13 15:49:10 +0300 | [diff] [blame] | 569 | } |
Amit Blay | 9452535 | 2012-12-24 11:23:27 +0200 | [diff] [blame] | 570 | |
Lena Salman | 05b544f | 2013-05-13 15:49:10 +0300 | [diff] [blame] | 571 | pr_debug("%s: enqueue\n", __func__); |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 572 | status = usb_ep_queue(port->port_usb->out, d->rx_req, GFP_ATOMIC); |
| 573 | if (status) |
| 574 | pr_err("%s: error enqueuing transfer, %d\n", __func__, status); |
Lena Salman | a12bc32 | 2013-07-02 15:04:42 +0300 | [diff] [blame] | 575 | spin_unlock(&port->port_lock_ul); |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | static void gbam_start_endless_tx(struct gbam_port *port) |
| 579 | { |
| 580 | struct bam_ch_info *d = &port->data_ch; |
| 581 | int status; |
| 582 | |
Lena Salman | a12bc32 | 2013-07-02 15:04:42 +0300 | [diff] [blame] | 583 | spin_lock(&port->port_lock_dl); |
Lena Salman | 05b544f | 2013-05-13 15:49:10 +0300 | [diff] [blame] | 584 | if (!port->port_usb) { |
Lena Salman | a12bc32 | 2013-07-02 15:04:42 +0300 | [diff] [blame] | 585 | spin_unlock(&port->port_lock_dl); |
Lena Salman | 05b544f | 2013-05-13 15:49:10 +0300 | [diff] [blame] | 586 | pr_err("%s: port->port_usb is NULL", __func__); |
Amit Blay | 9452535 | 2012-12-24 11:23:27 +0200 | [diff] [blame] | 587 | return; |
Lena Salman | 05b544f | 2013-05-13 15:49:10 +0300 | [diff] [blame] | 588 | } |
Amit Blay | 9452535 | 2012-12-24 11:23:27 +0200 | [diff] [blame] | 589 | |
Lena Salman | 05b544f | 2013-05-13 15:49:10 +0300 | [diff] [blame] | 590 | pr_debug("%s: enqueue\n", __func__); |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 591 | status = usb_ep_queue(port->port_usb->in, d->tx_req, GFP_ATOMIC); |
| 592 | if (status) |
| 593 | pr_err("%s: error enqueuing transfer, %d\n", __func__, status); |
Lena Salman | a12bc32 | 2013-07-02 15:04:42 +0300 | [diff] [blame] | 594 | spin_unlock(&port->port_lock_dl); |
| 595 | |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 596 | } |
| 597 | |
Lena Salman | 05b544f | 2013-05-13 15:49:10 +0300 | [diff] [blame] | 598 | static void gbam_stop_endless_rx(struct gbam_port *port) |
| 599 | { |
| 600 | struct bam_ch_info *d = &port->data_ch; |
| 601 | int status; |
| 602 | |
Lena Salman | a12bc32 | 2013-07-02 15:04:42 +0300 | [diff] [blame] | 603 | spin_lock(&port->port_lock_ul); |
Lena Salman | 05b544f | 2013-05-13 15:49:10 +0300 | [diff] [blame] | 604 | if (!port->port_usb) { |
Lena Salman | a12bc32 | 2013-07-02 15:04:42 +0300 | [diff] [blame] | 605 | spin_unlock(&port->port_lock_ul); |
Lena Salman | 05b544f | 2013-05-13 15:49:10 +0300 | [diff] [blame] | 606 | pr_err("%s: port->port_usb is NULL", __func__); |
| 607 | return; |
| 608 | } |
| 609 | pr_debug("%s: dequeue\n", __func__); |
| 610 | |
| 611 | status = usb_ep_dequeue(port->port_usb->out, d->rx_req); |
| 612 | if (status) |
| 613 | pr_err("%s: error dequeuing transfer, %d\n", __func__, status); |
Lena Salman | a12bc32 | 2013-07-02 15:04:42 +0300 | [diff] [blame] | 614 | spin_unlock(&port->port_lock_ul); |
Lena Salman | 05b544f | 2013-05-13 15:49:10 +0300 | [diff] [blame] | 615 | } |
Lena Salman | a12bc32 | 2013-07-02 15:04:42 +0300 | [diff] [blame] | 616 | |
Lena Salman | 05b544f | 2013-05-13 15:49:10 +0300 | [diff] [blame] | 617 | static void gbam_stop_endless_tx(struct gbam_port *port) |
| 618 | { |
| 619 | struct bam_ch_info *d = &port->data_ch; |
| 620 | int status; |
| 621 | |
Lena Salman | a12bc32 | 2013-07-02 15:04:42 +0300 | [diff] [blame] | 622 | spin_lock(&port->port_lock_dl); |
Lena Salman | 05b544f | 2013-05-13 15:49:10 +0300 | [diff] [blame] | 623 | if (!port->port_usb) { |
Lena Salman | a12bc32 | 2013-07-02 15:04:42 +0300 | [diff] [blame] | 624 | spin_unlock(&port->port_lock_dl); |
Lena Salman | 05b544f | 2013-05-13 15:49:10 +0300 | [diff] [blame] | 625 | pr_err("%s: port->port_usb is NULL", __func__); |
| 626 | return; |
| 627 | } |
| 628 | |
| 629 | pr_debug("%s: dequeue\n", __func__); |
| 630 | status = usb_ep_dequeue(port->port_usb->in, d->tx_req); |
| 631 | if (status) |
| 632 | pr_err("%s: error dequeuing transfer, %d\n", __func__, status); |
Lena Salman | a12bc32 | 2013-07-02 15:04:42 +0300 | [diff] [blame] | 633 | spin_unlock(&port->port_lock_dl); |
Lena Salman | 05b544f | 2013-05-13 15:49:10 +0300 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | static void gbam_start(void *param, enum usb_bam_pipe_dir dir) |
| 637 | { |
| 638 | struct gbam_port *port = param; |
| 639 | |
| 640 | if (dir == USB_TO_PEER_PERIPHERAL) |
| 641 | gbam_start_endless_rx(port); |
| 642 | else |
| 643 | gbam_start_endless_tx(port); |
| 644 | } |
| 645 | |
| 646 | static void gbam_stop(void *param, enum usb_bam_pipe_dir dir) |
| 647 | { |
| 648 | struct gbam_port *port = param; |
| 649 | |
| 650 | if (dir == USB_TO_PEER_PERIPHERAL) |
| 651 | gbam_stop_endless_rx(port); |
| 652 | else |
| 653 | gbam_stop_endless_tx(port); |
| 654 | } |
| 655 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 656 | static void gbam_start_io(struct gbam_port *port) |
| 657 | { |
| 658 | unsigned long flags; |
| 659 | struct usb_ep *ep; |
| 660 | int ret; |
| 661 | struct bam_ch_info *d; |
| 662 | |
| 663 | pr_debug("%s: port:%p\n", __func__, port); |
| 664 | |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 665 | spin_lock_irqsave(&port->port_lock_ul, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 666 | if (!port->port_usb) { |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 667 | spin_unlock_irqrestore(&port->port_lock_ul, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 668 | return; |
| 669 | } |
| 670 | |
| 671 | d = &port->data_ch; |
| 672 | ep = port->port_usb->out; |
Vamsi Krishna | 8f24f25 | 2011-11-02 11:46:08 -0700 | [diff] [blame] | 673 | ret = gbam_alloc_requests(ep, &d->rx_idle, bam_mux_rx_q_size, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 674 | gbam_epout_complete, GFP_ATOMIC); |
| 675 | if (ret) { |
| 676 | pr_err("%s: rx req allocation failed\n", __func__); |
Manu Gautam | 2482334 | 2013-06-13 16:33:49 +0530 | [diff] [blame] | 677 | spin_unlock_irqrestore(&port->port_lock_ul, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 678 | return; |
| 679 | } |
| 680 | |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 681 | spin_unlock_irqrestore(&port->port_lock_ul, flags); |
| 682 | spin_lock_irqsave(&port->port_lock_dl, flags); |
Chiranjeevi Velempati | 44d0298 | 2013-02-17 22:09:08 +0530 | [diff] [blame] | 683 | if (!port->port_usb) { |
| 684 | gbam_free_requests(ep, &d->rx_idle); |
| 685 | spin_unlock_irqrestore(&port->port_lock_dl, flags); |
| 686 | return; |
| 687 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 688 | ep = port->port_usb->in; |
Vamsi Krishna | 8f24f25 | 2011-11-02 11:46:08 -0700 | [diff] [blame] | 689 | ret = gbam_alloc_requests(ep, &d->tx_idle, bam_mux_tx_q_size, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 690 | gbam_epin_complete, GFP_ATOMIC); |
| 691 | if (ret) { |
| 692 | pr_err("%s: tx req allocation failed\n", __func__); |
| 693 | gbam_free_requests(ep, &d->rx_idle); |
Manu Gautam | 2482334 | 2013-06-13 16:33:49 +0530 | [diff] [blame] | 694 | spin_unlock_irqrestore(&port->port_lock_dl, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 695 | return; |
| 696 | } |
| 697 | |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 698 | spin_unlock_irqrestore(&port->port_lock_dl, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 699 | |
| 700 | /* queue out requests */ |
| 701 | gbam_start_rx(port); |
| 702 | } |
| 703 | |
Jeff Hugo | 1c4531c | 2011-08-02 14:55:37 -0600 | [diff] [blame] | 704 | static void gbam_notify(void *p, int event, unsigned long data) |
| 705 | { |
| 706 | switch (event) { |
| 707 | case BAM_DMUX_RECEIVE: |
| 708 | gbam_data_recv_cb(p, (struct sk_buff *)(data)); |
| 709 | break; |
| 710 | case BAM_DMUX_WRITE_DONE: |
| 711 | gbam_data_write_done(p, (struct sk_buff *)(data)); |
| 712 | break; |
| 713 | } |
| 714 | } |
| 715 | |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 716 | static void gbam_free_buffers(struct gbam_port *port) |
| 717 | { |
| 718 | struct sk_buff *skb; |
| 719 | unsigned long flags; |
| 720 | struct bam_ch_info *d; |
| 721 | |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 722 | spin_lock_irqsave(&port->port_lock_ul, flags); |
Jeff Ohlstein | 6f8c5fc | 2012-01-17 13:08:39 -0800 | [diff] [blame] | 723 | spin_lock(&port->port_lock_dl); |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 724 | |
| 725 | if (!port || !port->port_usb) |
| 726 | goto free_buf_out; |
| 727 | |
| 728 | d = &port->data_ch; |
| 729 | |
| 730 | gbam_free_requests(port->port_usb->in, &d->tx_idle); |
| 731 | gbam_free_requests(port->port_usb->out, &d->rx_idle); |
| 732 | |
| 733 | while ((skb = __skb_dequeue(&d->tx_skb_q))) |
| 734 | dev_kfree_skb_any(skb); |
| 735 | |
| 736 | while ((skb = __skb_dequeue(&d->rx_skb_q))) |
| 737 | dev_kfree_skb_any(skb); |
| 738 | |
| 739 | free_buf_out: |
Jeff Ohlstein | 6f8c5fc | 2012-01-17 13:08:39 -0800 | [diff] [blame] | 740 | spin_unlock(&port->port_lock_dl); |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 741 | spin_unlock_irqrestore(&port->port_lock_ul, flags); |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 742 | } |
| 743 | |
Vamsi Krishna | 1ad076d | 2011-11-10 15:03:30 -0800 | [diff] [blame] | 744 | static void gbam_disconnect_work(struct work_struct *w) |
| 745 | { |
| 746 | struct gbam_port *port = |
| 747 | container_of(w, struct gbam_port, disconnect_w); |
| 748 | struct bam_ch_info *d = &port->data_ch; |
| 749 | |
| 750 | if (!test_bit(BAM_CH_OPENED, &d->flags)) |
| 751 | return; |
| 752 | |
| 753 | msm_bam_dmux_close(d->id); |
| 754 | clear_bit(BAM_CH_OPENED, &d->flags); |
| 755 | } |
| 756 | |
Ofir Cohen | fdecb60 | 2012-11-16 15:50:01 +0200 | [diff] [blame] | 757 | static void gbam2bam_disconnect_work(struct work_struct *w) |
| 758 | { |
Shimrit Malichi | 419fdac | 2013-01-16 14:35:31 +0200 | [diff] [blame] | 759 | struct gbam_port *port = |
| 760 | container_of(w, struct gbam_port, disconnect_w); |
Ofir Cohen | fdecb60 | 2012-11-16 15:50:01 +0200 | [diff] [blame] | 761 | struct bam_ch_info *d = &port->data_ch; |
| 762 | int ret; |
| 763 | |
| 764 | if (d->trans == USB_GADGET_XPORT_BAM2BAM_IPA) { |
Shimrit Malichi | dbf43d7 | 2013-03-16 03:32:27 +0200 | [diff] [blame] | 765 | ret = usb_bam_disconnect_ipa(&d->ipa_params); |
Ofir Cohen | fdecb60 | 2012-11-16 15:50:01 +0200 | [diff] [blame] | 766 | if (ret) |
| 767 | pr_err("%s: usb_bam_disconnect_ipa failed: err:%d\n", |
| 768 | __func__, ret); |
Lena Salman | 7c0e979 | 2013-06-20 14:36:54 +0300 | [diff] [blame] | 769 | teth_bridge_disconnect(); |
Ofir Cohen | fdecb60 | 2012-11-16 15:50:01 +0200 | [diff] [blame] | 770 | } |
| 771 | } |
| 772 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 773 | static void gbam_connect_work(struct work_struct *w) |
| 774 | { |
| 775 | struct gbam_port *port = container_of(w, struct gbam_port, connect_w); |
| 776 | struct bam_ch_info *d = &port->data_ch; |
| 777 | int ret; |
Vamsi Krishna | 1ad076d | 2011-11-10 15:03:30 -0800 | [diff] [blame] | 778 | unsigned long flags; |
| 779 | |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 780 | spin_lock_irqsave(&port->port_lock_ul, flags); |
Jeff Ohlstein | 6f8c5fc | 2012-01-17 13:08:39 -0800 | [diff] [blame] | 781 | spin_lock(&port->port_lock_dl); |
Vamsi Krishna | 1ad076d | 2011-11-10 15:03:30 -0800 | [diff] [blame] | 782 | if (!port->port_usb) { |
Jeff Ohlstein | 6f8c5fc | 2012-01-17 13:08:39 -0800 | [diff] [blame] | 783 | spin_unlock(&port->port_lock_dl); |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 784 | spin_unlock_irqrestore(&port->port_lock_ul, flags); |
Vamsi Krishna | 1ad076d | 2011-11-10 15:03:30 -0800 | [diff] [blame] | 785 | return; |
| 786 | } |
Jeff Ohlstein | 6f8c5fc | 2012-01-17 13:08:39 -0800 | [diff] [blame] | 787 | spin_unlock(&port->port_lock_dl); |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 788 | spin_unlock_irqrestore(&port->port_lock_ul, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 789 | |
Jack Pham | effd4ae | 2011-08-03 16:49:36 -0700 | [diff] [blame] | 790 | if (!test_bit(BAM_CH_READY, &d->flags)) |
| 791 | return; |
| 792 | |
Jeff Hugo | 1c4531c | 2011-08-02 14:55:37 -0600 | [diff] [blame] | 793 | ret = msm_bam_dmux_open(d->id, port, gbam_notify); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 794 | if (ret) { |
| 795 | pr_err("%s: unable open bam ch:%d err:%d\n", |
| 796 | __func__, d->id, ret); |
| 797 | return; |
| 798 | } |
Jack Pham | effd4ae | 2011-08-03 16:49:36 -0700 | [diff] [blame] | 799 | set_bit(BAM_CH_OPENED, &d->flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 800 | |
| 801 | gbam_start_io(port); |
| 802 | |
| 803 | pr_debug("%s: done\n", __func__); |
| 804 | } |
| 805 | |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 806 | static void gbam2bam_connect_work(struct work_struct *w) |
Jack Pham | effd4ae | 2011-08-03 16:49:36 -0700 | [diff] [blame] | 807 | { |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 808 | struct gbam_port *port = container_of(w, struct gbam_port, connect_w); |
Shimrit Malichi | 085a3d2 | 2013-03-10 10:30:08 +0200 | [diff] [blame] | 809 | struct teth_bridge_connect_params connect_params; |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 810 | struct bam_ch_info *d = &port->data_ch; |
| 811 | u32 sps_params; |
Shimrit Malichi | 085a3d2 | 2013-03-10 10:30:08 +0200 | [diff] [blame] | 812 | ipa_notify_cb usb_notify_cb; |
| 813 | void *priv; |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 814 | int ret; |
Shimrit Malichi | 841fe17 | 2013-04-23 11:52:19 +0300 | [diff] [blame] | 815 | unsigned long flags; |
Jack Pham | effd4ae | 2011-08-03 16:49:36 -0700 | [diff] [blame] | 816 | |
Ofir Cohen | fdecb60 | 2012-11-16 15:50:01 +0200 | [diff] [blame] | 817 | if (d->trans == USB_GADGET_XPORT_BAM2BAM) { |
Bar Weiner | 189bb3c | 2013-06-09 14:24:56 +0300 | [diff] [blame] | 818 | usb_bam_reset_complete(); |
Shimrit Malichi | dbf43d7 | 2013-03-16 03:32:27 +0200 | [diff] [blame] | 819 | ret = usb_bam_connect(d->src_connection_idx, &d->src_pipe_idx); |
Ofir Cohen | fdecb60 | 2012-11-16 15:50:01 +0200 | [diff] [blame] | 820 | if (ret) { |
Shimrit Malichi | dbf43d7 | 2013-03-16 03:32:27 +0200 | [diff] [blame] | 821 | pr_err("%s: usb_bam_connect (src) failed: err:%d\n", |
| 822 | __func__, ret); |
| 823 | return; |
| 824 | } |
| 825 | ret = usb_bam_connect(d->dst_connection_idx, &d->dst_pipe_idx); |
| 826 | if (ret) { |
| 827 | pr_err("%s: usb_bam_connect (dst) failed: err:%d\n", |
Ofir Cohen | fdecb60 | 2012-11-16 15:50:01 +0200 | [diff] [blame] | 828 | __func__, ret); |
| 829 | return; |
| 830 | } |
| 831 | } else if (d->trans == USB_GADGET_XPORT_BAM2BAM_IPA) { |
Shimrit Malichi | 085a3d2 | 2013-03-10 10:30:08 +0200 | [diff] [blame] | 832 | ret = teth_bridge_init(&usb_notify_cb, &priv); |
| 833 | if (ret) { |
| 834 | pr_err("%s:teth_bridge_init() failed\n", __func__); |
| 835 | return; |
| 836 | } |
| 837 | d->ipa_params.notify = usb_notify_cb; |
| 838 | d->ipa_params.priv = priv; |
| 839 | d->ipa_params.ipa_ep_cfg.mode.mode = IPA_BASIC; |
| 840 | |
Lena Salman | abde35d | 2013-04-25 15:29:43 +0300 | [diff] [blame] | 841 | d->ipa_params.client = IPA_CLIENT_USB_PROD; |
| 842 | d->ipa_params.dir = USB_TO_PEER_PERIPHERAL; |
Ofir Cohen | 77848d6 | 2012-12-05 13:16:10 +0200 | [diff] [blame] | 843 | ret = usb_bam_connect_ipa(&d->ipa_params); |
Ofir Cohen | fdecb60 | 2012-11-16 15:50:01 +0200 | [diff] [blame] | 844 | if (ret) { |
| 845 | pr_err("%s: usb_bam_connect_ipa failed: err:%d\n", |
| 846 | __func__, ret); |
| 847 | return; |
| 848 | } |
| 849 | |
Lena Salman | abde35d | 2013-04-25 15:29:43 +0300 | [diff] [blame] | 850 | d->ipa_params.client = IPA_CLIENT_USB_CONS; |
| 851 | d->ipa_params.dir = PEER_PERIPHERAL_TO_USB; |
Ofir Cohen | 77848d6 | 2012-12-05 13:16:10 +0200 | [diff] [blame] | 852 | ret = usb_bam_connect_ipa(&d->ipa_params); |
Ofir Cohen | fdecb60 | 2012-11-16 15:50:01 +0200 | [diff] [blame] | 853 | if (ret) { |
| 854 | pr_err("%s: usb_bam_connect_ipa failed: err:%d\n", |
| 855 | __func__, ret); |
| 856 | return; |
| 857 | } |
Shimrit Malichi | 085a3d2 | 2013-03-10 10:30:08 +0200 | [diff] [blame] | 858 | |
| 859 | connect_params.ipa_usb_pipe_hdl = d->ipa_params.prod_clnt_hdl; |
| 860 | connect_params.usb_ipa_pipe_hdl = d->ipa_params.cons_clnt_hdl; |
| 861 | connect_params.tethering_mode = TETH_TETHERING_MODE_RMNET; |
| 862 | ret = teth_bridge_connect(&connect_params); |
| 863 | if (ret) { |
| 864 | pr_err("%s:teth_bridge_connect() failed\n", __func__); |
| 865 | return; |
| 866 | } |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 867 | } |
Jack Pham | effd4ae | 2011-08-03 16:49:36 -0700 | [diff] [blame] | 868 | |
Shimrit Malichi | 841fe17 | 2013-04-23 11:52:19 +0300 | [diff] [blame] | 869 | spin_lock_irqsave(&port->port_lock_ul, flags); |
| 870 | spin_lock(&port->port_lock_dl); |
| 871 | if (!port->port_usb) { |
| 872 | pr_debug("%s: usb cable is disconnected, exiting\n", __func__); |
| 873 | spin_unlock(&port->port_lock_dl); |
| 874 | spin_unlock_irqrestore(&port->port_lock_ul, flags); |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 875 | return; |
Shimrit Malichi | 841fe17 | 2013-04-23 11:52:19 +0300 | [diff] [blame] | 876 | } |
| 877 | d->rx_req = usb_ep_alloc_request(port->port_usb->out, GFP_ATOMIC); |
| 878 | if (!d->rx_req) { |
| 879 | spin_unlock(&port->port_lock_dl); |
| 880 | spin_unlock_irqrestore(&port->port_lock_ul, flags); |
| 881 | pr_err("%s: out of memory\n", __func__); |
| 882 | return; |
| 883 | } |
Jack Pham | effd4ae | 2011-08-03 16:49:36 -0700 | [diff] [blame] | 884 | |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 885 | d->rx_req->context = port; |
| 886 | d->rx_req->complete = gbam_endless_rx_complete; |
| 887 | d->rx_req->length = 0; |
Bar Weiner | 8475d63 | 2013-06-13 11:29:49 +0300 | [diff] [blame] | 888 | d->rx_req->no_interrupt = 1; |
Ido Shayevitz | d1cb16c | 2012-03-28 18:57:47 +0200 | [diff] [blame] | 889 | sps_params = (MSM_SPS_MODE | d->src_pipe_idx | |
| 890 | MSM_VENDOR_ID) & ~MSM_IS_FINITE_TRANSFER; |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 891 | d->rx_req->udc_priv = sps_params; |
Shimrit Malichi | 841fe17 | 2013-04-23 11:52:19 +0300 | [diff] [blame] | 892 | |
| 893 | d->tx_req = usb_ep_alloc_request(port->port_usb->in, GFP_ATOMIC); |
| 894 | spin_unlock(&port->port_lock_dl); |
| 895 | spin_unlock_irqrestore(&port->port_lock_ul, flags); |
| 896 | if (!d->tx_req) { |
| 897 | pr_err("%s: out of memory\n", __func__); |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 898 | return; |
Shimrit Malichi | 841fe17 | 2013-04-23 11:52:19 +0300 | [diff] [blame] | 899 | } |
Jack Pham | effd4ae | 2011-08-03 16:49:36 -0700 | [diff] [blame] | 900 | |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 901 | d->tx_req->context = port; |
| 902 | d->tx_req->complete = gbam_endless_tx_complete; |
| 903 | d->tx_req->length = 0; |
Bar Weiner | 8475d63 | 2013-06-13 11:29:49 +0300 | [diff] [blame] | 904 | d->tx_req->no_interrupt = 1; |
Ido Shayevitz | d1cb16c | 2012-03-28 18:57:47 +0200 | [diff] [blame] | 905 | sps_params = (MSM_SPS_MODE | d->dst_pipe_idx | |
| 906 | MSM_VENDOR_ID) & ~MSM_IS_FINITE_TRANSFER; |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 907 | d->tx_req->udc_priv = sps_params; |
Jack Pham | effd4ae | 2011-08-03 16:49:36 -0700 | [diff] [blame] | 908 | |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 909 | /* queue in & out requests */ |
| 910 | gbam_start_endless_rx(port); |
| 911 | gbam_start_endless_tx(port); |
Jack Pham | effd4ae | 2011-08-03 16:49:36 -0700 | [diff] [blame] | 912 | |
Amit Blay | 9452535 | 2012-12-24 11:23:27 +0200 | [diff] [blame] | 913 | if (d->trans == USB_GADGET_XPORT_BAM2BAM && port->port_num == 0) { |
| 914 | /* Register for peer reset callback */ |
Shimrit Malichi | dbf43d7 | 2013-03-16 03:32:27 +0200 | [diff] [blame] | 915 | usb_bam_register_peer_reset_cb(gbam_peer_reset_cb, port); |
Amit Blay | 9452535 | 2012-12-24 11:23:27 +0200 | [diff] [blame] | 916 | |
| 917 | ret = usb_bam_client_ready(true); |
| 918 | if (ret) { |
| 919 | pr_err("%s: usb_bam_client_ready failed: err:%d\n", |
| 920 | __func__, ret); |
| 921 | return; |
| 922 | } |
| 923 | } |
| 924 | |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 925 | pr_debug("%s: done\n", __func__); |
Jack Pham | effd4ae | 2011-08-03 16:49:36 -0700 | [diff] [blame] | 926 | } |
| 927 | |
Bar Weiner | 84e1ba0 | 2013-07-18 09:08:03 +0300 | [diff] [blame] | 928 | static int gbam_wake_cb(void *param) |
| 929 | { |
| 930 | struct gbam_port *port = (struct gbam_port *)param; |
| 931 | struct bam_ch_info *d; |
| 932 | struct f_rmnet *dev; |
| 933 | |
| 934 | dev = port_to_rmnet(port->gr); |
| 935 | d = &port->data_ch; |
| 936 | |
| 937 | pr_debug("%s: woken up by peer\n", __func__); |
| 938 | |
| 939 | return usb_gadget_wakeup(dev->cdev->gadget); |
| 940 | } |
| 941 | |
| 942 | static void gbam2bam_suspend_work(struct work_struct *w) |
| 943 | { |
| 944 | struct gbam_port *port = container_of(w, struct gbam_port, suspend_w); |
| 945 | struct bam_ch_info *d = &port->data_ch; |
| 946 | |
| 947 | pr_debug("%s: suspend work started\n", __func__); |
| 948 | |
| 949 | usb_bam_register_wake_cb(d->dst_connection_idx, gbam_wake_cb, port); |
| 950 | if (d->trans == USB_GADGET_XPORT_BAM2BAM_IPA) { |
| 951 | usb_bam_register_start_stop_cbs(gbam_start, gbam_stop, port); |
| 952 | usb_bam_suspend(&d->ipa_params); |
| 953 | } |
| 954 | } |
| 955 | |
| 956 | static void gbam2bam_resume_work(struct work_struct *w) |
| 957 | { |
| 958 | struct gbam_port *port = container_of(w, struct gbam_port, resume_w); |
| 959 | struct bam_ch_info *d = &port->data_ch; |
| 960 | |
| 961 | pr_debug("%s: resume work started\n", __func__); |
| 962 | |
| 963 | usb_bam_register_wake_cb(d->dst_connection_idx, NULL, NULL); |
| 964 | if (d->trans == USB_GADGET_XPORT_BAM2BAM_IPA) |
| 965 | usb_bam_resume(&d->ipa_params); |
| 966 | } |
| 967 | |
Amit Blay | 9452535 | 2012-12-24 11:23:27 +0200 | [diff] [blame] | 968 | static int gbam_peer_reset_cb(void *param) |
| 969 | { |
| 970 | struct gbam_port *port = (struct gbam_port *)param; |
| 971 | struct bam_ch_info *d; |
| 972 | struct f_rmnet *dev; |
| 973 | struct usb_gadget *gadget; |
| 974 | int ret; |
| 975 | bool reenable_eps = false; |
| 976 | |
| 977 | dev = port_to_rmnet(port->gr); |
| 978 | d = &port->data_ch; |
| 979 | |
| 980 | gadget = dev->cdev->gadget; |
| 981 | |
| 982 | pr_debug("%s: reset by peer\n", __func__); |
| 983 | |
| 984 | /* Disable the relevant EPs if currently EPs are enabled */ |
| 985 | if (port->port_usb && port->port_usb->in && |
| 986 | port->port_usb->in->driver_data) { |
| 987 | usb_ep_disable(port->port_usb->out); |
| 988 | usb_ep_disable(port->port_usb->in); |
| 989 | |
| 990 | port->port_usb->in->driver_data = NULL; |
| 991 | port->port_usb->out->driver_data = NULL; |
| 992 | reenable_eps = true; |
| 993 | } |
| 994 | |
| 995 | /* Disable BAM */ |
| 996 | msm_hw_bam_disable(1); |
| 997 | |
| 998 | /* Reset BAM */ |
Bar Weiner | 189bb3c | 2013-06-09 14:24:56 +0300 | [diff] [blame] | 999 | ret = usb_bam_a2_reset(0); |
Amit Blay | 9452535 | 2012-12-24 11:23:27 +0200 | [diff] [blame] | 1000 | if (ret) { |
| 1001 | pr_err("%s: BAM reset failed %d\n", __func__, ret); |
| 1002 | goto reenable_eps; |
| 1003 | } |
| 1004 | |
| 1005 | /* Enable BAM */ |
| 1006 | msm_hw_bam_disable(0); |
| 1007 | |
| 1008 | reenable_eps: |
| 1009 | /* Re-Enable the relevant EPs, if EPs were originally enabled */ |
| 1010 | if (reenable_eps) { |
| 1011 | ret = usb_ep_enable(port->port_usb->in); |
| 1012 | if (ret) { |
| 1013 | pr_err("%s: usb_ep_enable failed eptype:IN ep:%p", |
| 1014 | __func__, port->port_usb->in); |
| 1015 | return ret; |
| 1016 | } |
| 1017 | port->port_usb->in->driver_data = port; |
| 1018 | |
| 1019 | ret = usb_ep_enable(port->port_usb->out); |
| 1020 | if (ret) { |
| 1021 | pr_err("%s: usb_ep_enable failed eptype:OUT ep:%p", |
| 1022 | __func__, port->port_usb->out); |
| 1023 | port->port_usb->in->driver_data = 0; |
| 1024 | return ret; |
| 1025 | } |
| 1026 | port->port_usb->out->driver_data = port; |
| 1027 | |
| 1028 | gbam_start_endless_rx(port); |
| 1029 | gbam_start_endless_tx(port); |
| 1030 | } |
| 1031 | |
| 1032 | /* Unregister the peer reset callback */ |
| 1033 | if (d->trans == USB_GADGET_XPORT_BAM2BAM && port->port_num == 0) |
Shimrit Malichi | dbf43d7 | 2013-03-16 03:32:27 +0200 | [diff] [blame] | 1034 | usb_bam_register_peer_reset_cb(NULL, NULL); |
Amit Blay | 9452535 | 2012-12-24 11:23:27 +0200 | [diff] [blame] | 1035 | |
| 1036 | return 0; |
| 1037 | } |
| 1038 | |
Jack Pham | effd4ae | 2011-08-03 16:49:36 -0700 | [diff] [blame] | 1039 | /* BAM data channel ready, allow attempt to open */ |
| 1040 | static int gbam_data_ch_probe(struct platform_device *pdev) |
| 1041 | { |
| 1042 | struct gbam_port *port; |
| 1043 | struct bam_ch_info *d; |
| 1044 | int i; |
| 1045 | unsigned long flags; |
| 1046 | |
| 1047 | pr_debug("%s: name:%s\n", __func__, pdev->name); |
| 1048 | |
| 1049 | for (i = 0; i < n_bam_ports; i++) { |
| 1050 | port = bam_ports[i].port; |
| 1051 | d = &port->data_ch; |
| 1052 | |
| 1053 | if (!strncmp(bam_ch_names[i], pdev->name, |
| 1054 | BAM_DMUX_CH_NAME_MAX_LEN)) { |
| 1055 | set_bit(BAM_CH_READY, &d->flags); |
| 1056 | |
| 1057 | /* if usb is online, try opening bam_ch */ |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 1058 | spin_lock_irqsave(&port->port_lock_ul, flags); |
Jeff Ohlstein | 6f8c5fc | 2012-01-17 13:08:39 -0800 | [diff] [blame] | 1059 | spin_lock(&port->port_lock_dl); |
Jack Pham | effd4ae | 2011-08-03 16:49:36 -0700 | [diff] [blame] | 1060 | if (port->port_usb) |
| 1061 | queue_work(gbam_wq, &port->connect_w); |
Jeff Ohlstein | 6f8c5fc | 2012-01-17 13:08:39 -0800 | [diff] [blame] | 1062 | spin_unlock(&port->port_lock_dl); |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 1063 | spin_unlock_irqrestore(&port->port_lock_ul, flags); |
Jack Pham | effd4ae | 2011-08-03 16:49:36 -0700 | [diff] [blame] | 1064 | |
| 1065 | break; |
| 1066 | } |
| 1067 | } |
| 1068 | |
| 1069 | return 0; |
| 1070 | } |
| 1071 | |
| 1072 | /* BAM data channel went inactive, so close it */ |
| 1073 | static int gbam_data_ch_remove(struct platform_device *pdev) |
| 1074 | { |
| 1075 | struct gbam_port *port; |
| 1076 | struct bam_ch_info *d; |
| 1077 | struct usb_ep *ep_in = NULL; |
| 1078 | struct usb_ep *ep_out = NULL; |
| 1079 | unsigned long flags; |
| 1080 | int i; |
| 1081 | |
| 1082 | pr_debug("%s: name:%s\n", __func__, pdev->name); |
| 1083 | |
| 1084 | for (i = 0; i < n_bam_ports; i++) { |
| 1085 | if (!strncmp(bam_ch_names[i], pdev->name, |
| 1086 | BAM_DMUX_CH_NAME_MAX_LEN)) { |
| 1087 | port = bam_ports[i].port; |
| 1088 | d = &port->data_ch; |
| 1089 | |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 1090 | spin_lock_irqsave(&port->port_lock_ul, flags); |
Jeff Ohlstein | 6f8c5fc | 2012-01-17 13:08:39 -0800 | [diff] [blame] | 1091 | spin_lock(&port->port_lock_dl); |
Jack Pham | effd4ae | 2011-08-03 16:49:36 -0700 | [diff] [blame] | 1092 | if (port->port_usb) { |
| 1093 | ep_in = port->port_usb->in; |
| 1094 | ep_out = port->port_usb->out; |
| 1095 | } |
Jeff Ohlstein | 6f8c5fc | 2012-01-17 13:08:39 -0800 | [diff] [blame] | 1096 | spin_unlock(&port->port_lock_dl); |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 1097 | spin_unlock_irqrestore(&port->port_lock_ul, flags); |
Jack Pham | effd4ae | 2011-08-03 16:49:36 -0700 | [diff] [blame] | 1098 | |
| 1099 | if (ep_in) |
| 1100 | usb_ep_fifo_flush(ep_in); |
| 1101 | if (ep_out) |
| 1102 | usb_ep_fifo_flush(ep_out); |
| 1103 | |
| 1104 | gbam_free_buffers(port); |
| 1105 | |
| 1106 | msm_bam_dmux_close(d->id); |
| 1107 | |
Vamsi Krishna | 7658bd1 | 2012-01-13 10:32:00 -0800 | [diff] [blame] | 1108 | /* bam dmux will free all pending skbs */ |
| 1109 | d->pending_with_bam = 0; |
| 1110 | |
Jack Pham | effd4ae | 2011-08-03 16:49:36 -0700 | [diff] [blame] | 1111 | clear_bit(BAM_CH_READY, &d->flags); |
| 1112 | clear_bit(BAM_CH_OPENED, &d->flags); |
| 1113 | } |
| 1114 | } |
| 1115 | |
| 1116 | return 0; |
| 1117 | } |
| 1118 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1119 | static void gbam_port_free(int portno) |
| 1120 | { |
| 1121 | struct gbam_port *port = bam_ports[portno].port; |
Jack Pham | effd4ae | 2011-08-03 16:49:36 -0700 | [diff] [blame] | 1122 | struct platform_driver *pdrv = &bam_ports[portno].pdrv; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1123 | |
Jack Pham | effd4ae | 2011-08-03 16:49:36 -0700 | [diff] [blame] | 1124 | if (port) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1125 | kfree(port); |
Jack Pham | effd4ae | 2011-08-03 16:49:36 -0700 | [diff] [blame] | 1126 | platform_driver_unregister(pdrv); |
| 1127 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1128 | } |
| 1129 | |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 1130 | static void gbam2bam_port_free(int portno) |
| 1131 | { |
| 1132 | struct gbam_port *port = bam2bam_ports[portno]; |
| 1133 | |
| 1134 | kfree(port); |
| 1135 | } |
| 1136 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1137 | static int gbam_port_alloc(int portno) |
| 1138 | { |
| 1139 | struct gbam_port *port; |
| 1140 | struct bam_ch_info *d; |
Jack Pham | effd4ae | 2011-08-03 16:49:36 -0700 | [diff] [blame] | 1141 | struct platform_driver *pdrv; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1142 | |
| 1143 | port = kzalloc(sizeof(struct gbam_port), GFP_KERNEL); |
| 1144 | if (!port) |
| 1145 | return -ENOMEM; |
| 1146 | |
| 1147 | port->port_num = portno; |
| 1148 | |
| 1149 | /* port initialization */ |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 1150 | spin_lock_init(&port->port_lock_ul); |
| 1151 | spin_lock_init(&port->port_lock_dl); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1152 | INIT_WORK(&port->connect_w, gbam_connect_work); |
Vamsi Krishna | 1ad076d | 2011-11-10 15:03:30 -0800 | [diff] [blame] | 1153 | INIT_WORK(&port->disconnect_w, gbam_disconnect_work); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1154 | |
| 1155 | /* data ch */ |
| 1156 | d = &port->data_ch; |
| 1157 | d->port = port; |
| 1158 | INIT_LIST_HEAD(&d->tx_idle); |
| 1159 | INIT_LIST_HEAD(&d->rx_idle); |
| 1160 | INIT_WORK(&d->write_tobam_w, gbam_data_write_tobam); |
Chiranjeevi Velempati | e510592 | 2012-01-19 12:25:26 +0530 | [diff] [blame] | 1161 | INIT_WORK(&d->write_tohost_w, gbam_write_data_tohost_w); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1162 | skb_queue_head_init(&d->tx_skb_q); |
| 1163 | skb_queue_head_init(&d->rx_skb_q); |
| 1164 | d->id = bam_ch_ids[portno]; |
| 1165 | |
| 1166 | bam_ports[portno].port = port; |
| 1167 | |
Jack Pham | effd4ae | 2011-08-03 16:49:36 -0700 | [diff] [blame] | 1168 | pdrv = &bam_ports[portno].pdrv; |
| 1169 | pdrv->probe = gbam_data_ch_probe; |
| 1170 | pdrv->remove = gbam_data_ch_remove; |
| 1171 | pdrv->driver.name = bam_ch_names[portno]; |
| 1172 | pdrv->driver.owner = THIS_MODULE; |
| 1173 | |
| 1174 | platform_driver_register(pdrv); |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 1175 | pr_debug("%s: port:%p portno:%d\n", __func__, port, portno); |
| 1176 | |
| 1177 | return 0; |
| 1178 | } |
| 1179 | |
| 1180 | static int gbam2bam_port_alloc(int portno) |
| 1181 | { |
| 1182 | struct gbam_port *port; |
| 1183 | struct bam_ch_info *d; |
| 1184 | |
| 1185 | port = kzalloc(sizeof(struct gbam_port), GFP_KERNEL); |
| 1186 | if (!port) |
| 1187 | return -ENOMEM; |
| 1188 | |
| 1189 | port->port_num = portno; |
| 1190 | |
| 1191 | /* port initialization */ |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 1192 | spin_lock_init(&port->port_lock_ul); |
| 1193 | spin_lock_init(&port->port_lock_dl); |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 1194 | |
| 1195 | INIT_WORK(&port->connect_w, gbam2bam_connect_work); |
Ofir Cohen | fdecb60 | 2012-11-16 15:50:01 +0200 | [diff] [blame] | 1196 | INIT_WORK(&port->disconnect_w, gbam2bam_disconnect_work); |
Bar Weiner | 84e1ba0 | 2013-07-18 09:08:03 +0300 | [diff] [blame] | 1197 | INIT_WORK(&port->suspend_w, gbam2bam_suspend_work); |
| 1198 | INIT_WORK(&port->resume_w, gbam2bam_resume_work); |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 1199 | |
| 1200 | /* data ch */ |
| 1201 | d = &port->data_ch; |
| 1202 | d->port = port; |
| 1203 | bam2bam_ports[portno] = port; |
Jack Pham | effd4ae | 2011-08-03 16:49:36 -0700 | [diff] [blame] | 1204 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1205 | pr_debug("%s: port:%p portno:%d\n", __func__, port, portno); |
| 1206 | |
| 1207 | return 0; |
| 1208 | } |
| 1209 | |
| 1210 | #if defined(CONFIG_DEBUG_FS) |
| 1211 | #define DEBUG_BUF_SIZE 1024 |
| 1212 | static ssize_t gbam_read_stats(struct file *file, char __user *ubuf, |
| 1213 | size_t count, loff_t *ppos) |
| 1214 | { |
| 1215 | struct gbam_port *port; |
| 1216 | struct bam_ch_info *d; |
| 1217 | char *buf; |
| 1218 | unsigned long flags; |
| 1219 | int ret; |
| 1220 | int i; |
| 1221 | int temp = 0; |
| 1222 | |
| 1223 | buf = kzalloc(sizeof(char) * DEBUG_BUF_SIZE, GFP_KERNEL); |
| 1224 | if (!buf) |
| 1225 | return -ENOMEM; |
| 1226 | |
| 1227 | for (i = 0; i < n_bam_ports; i++) { |
| 1228 | port = bam_ports[i].port; |
| 1229 | if (!port) |
| 1230 | continue; |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 1231 | spin_lock_irqsave(&port->port_lock_ul, flags); |
Jeff Ohlstein | 6f8c5fc | 2012-01-17 13:08:39 -0800 | [diff] [blame] | 1232 | spin_lock(&port->port_lock_dl); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1233 | |
| 1234 | d = &port->data_ch; |
| 1235 | |
| 1236 | temp += scnprintf(buf + temp, DEBUG_BUF_SIZE - temp, |
| 1237 | "#PORT:%d port:%p data_ch:%p#\n" |
| 1238 | "dpkts_to_usbhost: %lu\n" |
| 1239 | "dpkts_to_modem: %lu\n" |
| 1240 | "dpkts_pwith_bam: %u\n" |
| 1241 | "to_usbhost_dcnt: %u\n" |
| 1242 | "tomodem__dcnt: %u\n" |
Vijayavardhan Vennapusa | 2001b03 | 2014-01-07 13:11:51 +0530 | [diff] [blame] | 1243 | "rx_flow_control_disable_count: %u\n" |
| 1244 | "rx_flow_control_enable_count: %u\n" |
| 1245 | "rx_flow_control_triggered: %u\n" |
| 1246 | "max_num_pkts_pending_with_bam: %u\n" |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1247 | "tx_buf_len: %u\n" |
Vamsi Krishna | 8457955 | 2011-11-09 15:33:22 -0800 | [diff] [blame] | 1248 | "rx_buf_len: %u\n" |
Jack Pham | effd4ae | 2011-08-03 16:49:36 -0700 | [diff] [blame] | 1249 | "data_ch_open: %d\n" |
| 1250 | "data_ch_ready: %d\n", |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1251 | i, port, &port->data_ch, |
| 1252 | d->to_host, d->to_modem, |
| 1253 | d->pending_with_bam, |
| 1254 | d->tohost_drp_cnt, d->tomodem_drp_cnt, |
Vijayavardhan Vennapusa | 2001b03 | 2014-01-07 13:11:51 +0530 | [diff] [blame] | 1255 | d->rx_flow_control_disable, |
| 1256 | d->rx_flow_control_enable, |
| 1257 | d->rx_flow_control_triggered, |
| 1258 | d->max_num_pkts_pending_with_bam, |
Vamsi Krishna | 8457955 | 2011-11-09 15:33:22 -0800 | [diff] [blame] | 1259 | d->tx_skb_q.qlen, d->rx_skb_q.qlen, |
Jack Pham | effd4ae | 2011-08-03 16:49:36 -0700 | [diff] [blame] | 1260 | test_bit(BAM_CH_OPENED, &d->flags), |
| 1261 | test_bit(BAM_CH_READY, &d->flags)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1262 | |
Jeff Ohlstein | 6f8c5fc | 2012-01-17 13:08:39 -0800 | [diff] [blame] | 1263 | spin_unlock(&port->port_lock_dl); |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 1264 | spin_unlock_irqrestore(&port->port_lock_ul, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1265 | } |
| 1266 | |
| 1267 | ret = simple_read_from_buffer(ubuf, count, ppos, buf, temp); |
| 1268 | |
| 1269 | kfree(buf); |
| 1270 | |
| 1271 | return ret; |
| 1272 | } |
| 1273 | |
| 1274 | static ssize_t gbam_reset_stats(struct file *file, const char __user *buf, |
| 1275 | size_t count, loff_t *ppos) |
| 1276 | { |
| 1277 | struct gbam_port *port; |
| 1278 | struct bam_ch_info *d; |
| 1279 | int i; |
| 1280 | unsigned long flags; |
| 1281 | |
| 1282 | for (i = 0; i < n_bam_ports; i++) { |
| 1283 | port = bam_ports[i].port; |
| 1284 | if (!port) |
| 1285 | continue; |
| 1286 | |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 1287 | spin_lock_irqsave(&port->port_lock_ul, flags); |
Jeff Ohlstein | 6f8c5fc | 2012-01-17 13:08:39 -0800 | [diff] [blame] | 1288 | spin_lock(&port->port_lock_dl); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1289 | |
| 1290 | d = &port->data_ch; |
| 1291 | |
| 1292 | d->to_host = 0; |
| 1293 | d->to_modem = 0; |
| 1294 | d->pending_with_bam = 0; |
| 1295 | d->tohost_drp_cnt = 0; |
| 1296 | d->tomodem_drp_cnt = 0; |
Vijayavardhan Vennapusa | 2001b03 | 2014-01-07 13:11:51 +0530 | [diff] [blame] | 1297 | d->rx_flow_control_disable = 0; |
| 1298 | d->rx_flow_control_enable = 0; |
| 1299 | d->rx_flow_control_triggered = 0; |
| 1300 | d->max_num_pkts_pending_with_bam = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1301 | |
Jeff Ohlstein | 6f8c5fc | 2012-01-17 13:08:39 -0800 | [diff] [blame] | 1302 | spin_unlock(&port->port_lock_dl); |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 1303 | spin_unlock_irqrestore(&port->port_lock_ul, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1304 | } |
| 1305 | return count; |
| 1306 | } |
| 1307 | |
| 1308 | const struct file_operations gbam_stats_ops = { |
| 1309 | .read = gbam_read_stats, |
| 1310 | .write = gbam_reset_stats, |
| 1311 | }; |
| 1312 | |
Tarun Gupta | 44ad2bb | 2013-09-30 18:01:58 +0530 | [diff] [blame] | 1313 | struct dentry *gbam_dent; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1314 | static void gbam_debugfs_init(void) |
| 1315 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1316 | struct dentry *dfile; |
| 1317 | |
Tarun Gupta | 44ad2bb | 2013-09-30 18:01:58 +0530 | [diff] [blame] | 1318 | gbam_dent = debugfs_create_dir("usb_rmnet", 0); |
| 1319 | if (!gbam_dent || IS_ERR(gbam_dent)) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1320 | return; |
| 1321 | |
Tarun Gupta | 44ad2bb | 2013-09-30 18:01:58 +0530 | [diff] [blame] | 1322 | dfile = debugfs_create_file("status", 0444, gbam_dent, 0, |
| 1323 | &gbam_stats_ops); |
| 1324 | if (!dfile || IS_ERR(dfile)) { |
| 1325 | debugfs_remove(gbam_dent); |
| 1326 | gbam_dent = NULL; |
| 1327 | return; |
| 1328 | } |
| 1329 | } |
| 1330 | static void gbam_debugfs_remove(void) |
| 1331 | { |
| 1332 | debugfs_remove_recursive(gbam_dent); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1333 | } |
| 1334 | #else |
Tarun Gupta | 44ad2bb | 2013-09-30 18:01:58 +0530 | [diff] [blame] | 1335 | static inline void gbam_debugfs_init(void) {} |
| 1336 | static inline void gbam_debugfs_remove(void) {} |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1337 | #endif |
| 1338 | |
Ofir Cohen | 77848d6 | 2012-12-05 13:16:10 +0200 | [diff] [blame] | 1339 | void gbam_disconnect(struct grmnet *gr, u8 port_num, enum transport_type trans) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1340 | { |
| 1341 | struct gbam_port *port; |
| 1342 | unsigned long flags; |
| 1343 | struct bam_ch_info *d; |
| 1344 | |
| 1345 | pr_debug("%s: grmnet:%p port#%d\n", __func__, gr, port_num); |
| 1346 | |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 1347 | if (trans == USB_GADGET_XPORT_BAM && |
| 1348 | port_num >= n_bam_ports) { |
| 1349 | pr_err("%s: invalid bam portno#%d\n", |
| 1350 | __func__, port_num); |
| 1351 | return; |
| 1352 | } |
| 1353 | |
Ofir Cohen | fdecb60 | 2012-11-16 15:50:01 +0200 | [diff] [blame] | 1354 | if ((trans == USB_GADGET_XPORT_BAM2BAM || |
| 1355 | trans == USB_GADGET_XPORT_BAM2BAM_IPA) && |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 1356 | port_num >= n_bam2bam_ports) { |
| 1357 | pr_err("%s: invalid bam2bam portno#%d\n", |
| 1358 | __func__, port_num); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1359 | return; |
| 1360 | } |
| 1361 | |
| 1362 | if (!gr) { |
| 1363 | pr_err("%s: grmnet port is null\n", __func__); |
| 1364 | return; |
| 1365 | } |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 1366 | if (trans == USB_GADGET_XPORT_BAM) |
| 1367 | port = bam_ports[port_num].port; |
| 1368 | else |
| 1369 | port = bam2bam_ports[port_num]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1370 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1371 | d = &port->data_ch; |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 1372 | port->gr = gr; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1373 | |
Ido Shayevitz | eb8d831 | 2012-09-10 11:13:11 +0300 | [diff] [blame] | 1374 | if (trans == USB_GADGET_XPORT_BAM) |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 1375 | gbam_free_buffers(port); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1376 | |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 1377 | spin_lock_irqsave(&port->port_lock_ul, flags); |
Jeff Ohlstein | 6f8c5fc | 2012-01-17 13:08:39 -0800 | [diff] [blame] | 1378 | spin_lock(&port->port_lock_dl); |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 1379 | port->port_usb = 0; |
Vijayavardhan Vennapusa | 08c3125 | 2011-12-21 13:02:49 +0530 | [diff] [blame] | 1380 | n_tx_req_queued = 0; |
Jeff Ohlstein | 6f8c5fc | 2012-01-17 13:08:39 -0800 | [diff] [blame] | 1381 | spin_unlock(&port->port_lock_dl); |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 1382 | spin_unlock_irqrestore(&port->port_lock_ul, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1383 | |
Ido Shayevitz | eb8d831 | 2012-09-10 11:13:11 +0300 | [diff] [blame] | 1384 | /* disable endpoints */ |
| 1385 | usb_ep_disable(gr->out); |
| 1386 | usb_ep_disable(gr->in); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1387 | |
Ido Shayevitz | eb8d831 | 2012-09-10 11:13:11 +0300 | [diff] [blame] | 1388 | gr->in->driver_data = NULL; |
| 1389 | gr->out->driver_data = NULL; |
| 1390 | |
Ofir Cohen | fdecb60 | 2012-11-16 15:50:01 +0200 | [diff] [blame] | 1391 | if (trans == USB_GADGET_XPORT_BAM || |
| 1392 | trans == USB_GADGET_XPORT_BAM2BAM_IPA) |
Ido Shayevitz | eb8d831 | 2012-09-10 11:13:11 +0300 | [diff] [blame] | 1393 | queue_work(gbam_wq, &port->disconnect_w); |
Amit Blay | 9452535 | 2012-12-24 11:23:27 +0200 | [diff] [blame] | 1394 | else if (trans == USB_GADGET_XPORT_BAM2BAM) { |
| 1395 | if (port_num == 0) { |
| 1396 | if (usb_bam_client_ready(false)) { |
| 1397 | pr_err("%s: usb_bam_client_ready failed\n", |
| 1398 | __func__); |
| 1399 | } |
| 1400 | } |
| 1401 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1402 | } |
| 1403 | |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 1404 | int gbam_connect(struct grmnet *gr, u8 port_num, |
Shimrit Malichi | dbf43d7 | 2013-03-16 03:32:27 +0200 | [diff] [blame] | 1405 | enum transport_type trans, u8 src_connection_idx, |
| 1406 | u8 dst_connection_idx) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1407 | { |
| 1408 | struct gbam_port *port; |
| 1409 | struct bam_ch_info *d; |
| 1410 | int ret; |
| 1411 | unsigned long flags; |
| 1412 | |
| 1413 | pr_debug("%s: grmnet:%p port#%d\n", __func__, gr, port_num); |
| 1414 | |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 1415 | if (trans == USB_GADGET_XPORT_BAM && port_num >= n_bam_ports) { |
| 1416 | pr_err("%s: invalid portno#%d\n", __func__, port_num); |
| 1417 | return -ENODEV; |
| 1418 | } |
| 1419 | |
Ofir Cohen | fdecb60 | 2012-11-16 15:50:01 +0200 | [diff] [blame] | 1420 | if ((trans == USB_GADGET_XPORT_BAM2BAM || |
| 1421 | trans == USB_GADGET_XPORT_BAM2BAM_IPA) |
| 1422 | && port_num >= n_bam2bam_ports) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1423 | pr_err("%s: invalid portno#%d\n", __func__, port_num); |
| 1424 | return -ENODEV; |
| 1425 | } |
| 1426 | |
| 1427 | if (!gr) { |
| 1428 | pr_err("%s: grmnet port is null\n", __func__); |
| 1429 | return -ENODEV; |
| 1430 | } |
| 1431 | |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 1432 | if (trans == USB_GADGET_XPORT_BAM) |
| 1433 | port = bam_ports[port_num].port; |
| 1434 | else |
| 1435 | port = bam2bam_ports[port_num]; |
| 1436 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1437 | d = &port->data_ch; |
| 1438 | |
Ido Shayevitz | eb8d831 | 2012-09-10 11:13:11 +0300 | [diff] [blame] | 1439 | ret = usb_ep_enable(gr->in); |
| 1440 | if (ret) { |
| 1441 | pr_err("%s: usb_ep_enable failed eptype:IN ep:%p", |
| 1442 | __func__, gr->in); |
| 1443 | return ret; |
| 1444 | } |
| 1445 | gr->in->driver_data = port; |
Ofir Cohen | 4da266f | 2012-01-03 10:19:29 +0200 | [diff] [blame] | 1446 | |
Ido Shayevitz | eb8d831 | 2012-09-10 11:13:11 +0300 | [diff] [blame] | 1447 | ret = usb_ep_enable(gr->out); |
| 1448 | if (ret) { |
| 1449 | pr_err("%s: usb_ep_enable failed eptype:OUT ep:%p", |
| 1450 | __func__, gr->out); |
| 1451 | gr->in->driver_data = 0; |
| 1452 | return ret; |
| 1453 | } |
| 1454 | gr->out->driver_data = port; |
Ofir Cohen | 4da266f | 2012-01-03 10:19:29 +0200 | [diff] [blame] | 1455 | |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 1456 | spin_lock_irqsave(&port->port_lock_ul, flags); |
Jeff Ohlstein | 6f8c5fc | 2012-01-17 13:08:39 -0800 | [diff] [blame] | 1457 | spin_lock(&port->port_lock_dl); |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 1458 | port->port_usb = gr; |
Ofir Cohen | 4da266f | 2012-01-03 10:19:29 +0200 | [diff] [blame] | 1459 | |
Ido Shayevitz | eb8d831 | 2012-09-10 11:13:11 +0300 | [diff] [blame] | 1460 | if (trans == USB_GADGET_XPORT_BAM) { |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 1461 | d->to_host = 0; |
| 1462 | d->to_modem = 0; |
| 1463 | d->pending_with_bam = 0; |
| 1464 | d->tohost_drp_cnt = 0; |
| 1465 | d->tomodem_drp_cnt = 0; |
Vijayavardhan Vennapusa | 2001b03 | 2014-01-07 13:11:51 +0530 | [diff] [blame] | 1466 | d->rx_flow_control_disable = 0; |
| 1467 | d->rx_flow_control_enable = 0; |
| 1468 | d->rx_flow_control_triggered = 0; |
| 1469 | d->max_num_pkts_pending_with_bam = 0; |
Ido Shayevitz | eb8d831 | 2012-09-10 11:13:11 +0300 | [diff] [blame] | 1470 | } |
| 1471 | |
Jeff Ohlstein | 6f8c5fc | 2012-01-17 13:08:39 -0800 | [diff] [blame] | 1472 | spin_unlock(&port->port_lock_dl); |
Vijayavardhan Vennapusa | a880853 | 2012-01-09 15:24:02 +0530 | [diff] [blame] | 1473 | spin_unlock_irqrestore(&port->port_lock_ul, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1474 | |
Ofir Cohen | 4da266f | 2012-01-03 10:19:29 +0200 | [diff] [blame] | 1475 | if (trans == USB_GADGET_XPORT_BAM2BAM) { |
| 1476 | port->gr = gr; |
Shimrit Malichi | dbf43d7 | 2013-03-16 03:32:27 +0200 | [diff] [blame] | 1477 | d->src_connection_idx = src_connection_idx; |
| 1478 | d->dst_connection_idx = dst_connection_idx; |
Ofir Cohen | fdecb60 | 2012-11-16 15:50:01 +0200 | [diff] [blame] | 1479 | } else if (trans == USB_GADGET_XPORT_BAM2BAM_IPA) { |
Ofir Cohen | fdecb60 | 2012-11-16 15:50:01 +0200 | [diff] [blame] | 1480 | port->gr = gr; |
Ofir Cohen | 77848d6 | 2012-12-05 13:16:10 +0200 | [diff] [blame] | 1481 | d->ipa_params.src_pipe = &(d->src_pipe_idx); |
| 1482 | d->ipa_params.dst_pipe = &(d->dst_pipe_idx); |
Shimrit Malichi | dbf43d7 | 2013-03-16 03:32:27 +0200 | [diff] [blame] | 1483 | d->ipa_params.src_idx = src_connection_idx; |
| 1484 | d->ipa_params.dst_idx = dst_connection_idx; |
Ofir Cohen | 4da266f | 2012-01-03 10:19:29 +0200 | [diff] [blame] | 1485 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1486 | |
Ofir Cohen | fdecb60 | 2012-11-16 15:50:01 +0200 | [diff] [blame] | 1487 | d->trans = trans; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1488 | queue_work(gbam_wq, &port->connect_w); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1489 | return 0; |
| 1490 | } |
| 1491 | |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 1492 | int gbam_setup(unsigned int no_bam_port, unsigned int no_bam2bam_port) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1493 | { |
| 1494 | int i; |
| 1495 | int ret; |
| 1496 | |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 1497 | pr_debug("%s: requested BAM ports:%d and BAM2BAM ports:%d\n", |
| 1498 | __func__, no_bam_port, no_bam2bam_port); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1499 | |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 1500 | if ((!no_bam_port && !no_bam2bam_port) || no_bam_port > BAM_N_PORTS |
| 1501 | || no_bam2bam_port > BAM2BAM_N_PORTS) { |
| 1502 | pr_err("%s: Invalid num of ports count:%d,%d\n", |
| 1503 | __func__, no_bam_port, no_bam2bam_port); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1504 | return -EINVAL; |
| 1505 | } |
| 1506 | |
| 1507 | gbam_wq = alloc_workqueue("k_gbam", WQ_UNBOUND | WQ_MEM_RECLAIM, 1); |
| 1508 | if (!gbam_wq) { |
| 1509 | pr_err("%s: Unable to create workqueue gbam_wq\n", |
| 1510 | __func__); |
| 1511 | return -ENOMEM; |
| 1512 | } |
| 1513 | |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 1514 | for (i = 0; i < no_bam_port; i++) { |
Manu Gautam | d59b5d3 | 2011-09-09 14:47:08 +0530 | [diff] [blame] | 1515 | n_bam_ports++; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1516 | ret = gbam_port_alloc(i); |
| 1517 | if (ret) { |
Manu Gautam | d59b5d3 | 2011-09-09 14:47:08 +0530 | [diff] [blame] | 1518 | n_bam_ports--; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1519 | pr_err("%s: Unable to alloc port:%d\n", __func__, i); |
| 1520 | goto free_bam_ports; |
| 1521 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1522 | } |
| 1523 | |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 1524 | for (i = 0; i < no_bam2bam_port; i++) { |
| 1525 | n_bam2bam_ports++; |
| 1526 | ret = gbam2bam_port_alloc(i); |
| 1527 | if (ret) { |
| 1528 | n_bam2bam_ports--; |
| 1529 | pr_err("%s: Unable to alloc port:%d\n", __func__, i); |
| 1530 | goto free_bam_ports; |
| 1531 | } |
| 1532 | } |
Tarun Gupta | 44ad2bb | 2013-09-30 18:01:58 +0530 | [diff] [blame] | 1533 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1534 | gbam_debugfs_init(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1535 | return 0; |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 1536 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1537 | free_bam_ports: |
| 1538 | for (i = 0; i < n_bam_ports; i++) |
| 1539 | gbam_port_free(i); |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 1540 | for (i = 0; i < n_bam2bam_ports; i++) |
| 1541 | gbam2bam_port_free(i); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1542 | destroy_workqueue(gbam_wq); |
| 1543 | |
| 1544 | return ret; |
| 1545 | } |
Amit Blay | e5bb35e | 2012-05-08 20:38:20 +0300 | [diff] [blame] | 1546 | |
Tarun Gupta | 44ad2bb | 2013-09-30 18:01:58 +0530 | [diff] [blame] | 1547 | void gbam_cleanup(void) |
| 1548 | { |
| 1549 | gbam_debugfs_remove(); |
| 1550 | } |
| 1551 | |
Amit Blay | e5bb35e | 2012-05-08 20:38:20 +0300 | [diff] [blame] | 1552 | void gbam_suspend(struct grmnet *gr, u8 port_num, enum transport_type trans) |
| 1553 | { |
| 1554 | struct gbam_port *port; |
| 1555 | struct bam_ch_info *d; |
| 1556 | |
Ofir Cohen | fdecb60 | 2012-11-16 15:50:01 +0200 | [diff] [blame] | 1557 | if (trans != USB_GADGET_XPORT_BAM2BAM && |
| 1558 | trans != USB_GADGET_XPORT_BAM2BAM_IPA) |
Amit Blay | e5bb35e | 2012-05-08 20:38:20 +0300 | [diff] [blame] | 1559 | return; |
| 1560 | |
| 1561 | port = bam2bam_ports[port_num]; |
| 1562 | d = &port->data_ch; |
| 1563 | |
| 1564 | pr_debug("%s: suspended port %d\n", __func__, port_num); |
| 1565 | |
Bar Weiner | 84e1ba0 | 2013-07-18 09:08:03 +0300 | [diff] [blame] | 1566 | queue_work(gbam_wq, &port->suspend_w); |
Amit Blay | e5bb35e | 2012-05-08 20:38:20 +0300 | [diff] [blame] | 1567 | } |
| 1568 | |
| 1569 | void gbam_resume(struct grmnet *gr, u8 port_num, enum transport_type trans) |
| 1570 | { |
| 1571 | struct gbam_port *port; |
| 1572 | struct bam_ch_info *d; |
| 1573 | |
Ofir Cohen | fdecb60 | 2012-11-16 15:50:01 +0200 | [diff] [blame] | 1574 | if (trans != USB_GADGET_XPORT_BAM2BAM && |
| 1575 | trans != USB_GADGET_XPORT_BAM2BAM_IPA) |
Amit Blay | e5bb35e | 2012-05-08 20:38:20 +0300 | [diff] [blame] | 1576 | return; |
| 1577 | |
| 1578 | port = bam2bam_ports[port_num]; |
| 1579 | d = &port->data_ch; |
| 1580 | |
| 1581 | pr_debug("%s: resumed port %d\n", __func__, port_num); |
| 1582 | |
Bar Weiner | 84e1ba0 | 2013-07-18 09:08:03 +0300 | [diff] [blame] | 1583 | queue_work(gbam_wq, &port->resume_w); |
Amit Blay | e5bb35e | 2012-05-08 20:38:20 +0300 | [diff] [blame] | 1584 | } |