blob: 4d26e3cc8e5e248fefef394dfcb74d2db8f6131f [file] [log] [blame]
Arun Kumar Neelakantam406e5692013-01-17 18:58:04 +05301/* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 */
13
14/*
15 * BAM DMUX module.
16 */
17
18#define DEBUG
19
20#include <linux/delay.h>
21#include <linux/module.h>
22#include <linux/netdevice.h>
23#include <linux/platform_device.h>
24#include <linux/sched.h>
25#include <linux/skbuff.h>
26#include <linux/debugfs.h>
Jeff Hugoaab7ebc2011-09-07 16:46:04 -060027#include <linux/clk.h>
Jeff Hugoae3a85e2011-12-02 17:10:18 -070028#include <linux/wakelock.h>
Eric Holmberg878923a2012-01-10 14:28:19 -070029#include <linux/kfifo.h>
Jeff Hugo3910ee12012-08-21 14:08:20 -060030#include <linux/of.h>
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +053031#include <mach/msm_ipc_logging.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070032#include <mach/sps.h>
33#include <mach/bam_dmux.h>
Jeff Hugoade1f842011-08-03 15:53:59 -060034#include <mach/msm_smsm.h>
Jeff Hugo6e7a92a2011-10-24 05:25:13 -060035#include <mach/subsystem_notif.h>
Jeff Hugo75913c82011-12-05 15:59:01 -070036#include <mach/socinfo.h>
Jeff Hugo4838f412012-01-20 11:19:37 -070037#include <mach/subsystem_restart.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070038
39#define BAM_CH_LOCAL_OPEN 0x1
40#define BAM_CH_REMOTE_OPEN 0x2
Jeff Hugo6e7a92a2011-10-24 05:25:13 -060041#define BAM_CH_IN_RESET 0x4
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070042
43#define BAM_MUX_HDR_MAGIC_NO 0x33fc
44
Eric Holmberg006057d2012-01-11 10:10:42 -070045#define BAM_MUX_HDR_CMD_DATA 0
46#define BAM_MUX_HDR_CMD_OPEN 1
47#define BAM_MUX_HDR_CMD_CLOSE 2
48#define BAM_MUX_HDR_CMD_STATUS 3 /* unused */
49#define BAM_MUX_HDR_CMD_OPEN_NO_A2_PC 4
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070050
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070051
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -070052#define LOW_WATERMARK 2
53#define HIGH_WATERMARK 4
Anurag Singhdcd8b4e2012-07-30 16:46:37 -070054#define DEFAULT_POLLING_MIN_SLEEP (950)
55#define MAX_POLLING_SLEEP (6050)
56#define MIN_POLLING_SLEEP (950)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070057
58static int msm_bam_dmux_debug_enable;
59module_param_named(debug_enable, msm_bam_dmux_debug_enable,
60 int, S_IRUGO | S_IWUSR | S_IWGRP);
Anurag Singhdcd8b4e2012-07-30 16:46:37 -070061static int POLLING_MIN_SLEEP = 950;
62module_param_named(min_sleep, POLLING_MIN_SLEEP,
63 int, S_IRUGO | S_IWUSR | S_IWGRP);
64static int POLLING_MAX_SLEEP = 1050;
65module_param_named(max_sleep, POLLING_MAX_SLEEP,
66 int, S_IRUGO | S_IWUSR | S_IWGRP);
67static int POLLING_INACTIVITY = 40;
68module_param_named(inactivity, POLLING_INACTIVITY,
69 int, S_IRUGO | S_IWUSR | S_IWGRP);
70static int bam_adaptive_timer_enabled = 1;
71module_param_named(adaptive_timer_enabled,
72 bam_adaptive_timer_enabled,
73 int, S_IRUGO | S_IWUSR | S_IWGRP);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070074
75#if defined(DEBUG)
76static uint32_t bam_dmux_read_cnt;
77static uint32_t bam_dmux_write_cnt;
78static uint32_t bam_dmux_write_cpy_cnt;
79static uint32_t bam_dmux_write_cpy_bytes;
Eric Holmberg2fddbcd2011-11-28 18:25:57 -070080static uint32_t bam_dmux_tx_sps_failure_cnt;
Eric Holmberg6074aba2012-01-18 17:59:44 -070081static uint32_t bam_dmux_tx_stall_cnt;
Eric Holmberg1f1255d2012-02-22 13:37:21 -070082static atomic_t bam_dmux_ack_out_cnt = ATOMIC_INIT(0);
83static atomic_t bam_dmux_ack_in_cnt = ATOMIC_INIT(0);
84static atomic_t bam_dmux_a2_pwr_cntl_in_cnt = ATOMIC_INIT(0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070085
86#define DBG(x...) do { \
87 if (msm_bam_dmux_debug_enable) \
88 pr_debug(x); \
89 } while (0)
90
91#define DBG_INC_READ_CNT(x) do { \
92 bam_dmux_read_cnt += (x); \
93 if (msm_bam_dmux_debug_enable) \
94 pr_debug("%s: total read bytes %u\n", \
95 __func__, bam_dmux_read_cnt); \
96 } while (0)
97
98#define DBG_INC_WRITE_CNT(x) do { \
99 bam_dmux_write_cnt += (x); \
100 if (msm_bam_dmux_debug_enable) \
101 pr_debug("%s: total written bytes %u\n", \
102 __func__, bam_dmux_write_cnt); \
103 } while (0)
104
105#define DBG_INC_WRITE_CPY(x) do { \
106 bam_dmux_write_cpy_bytes += (x); \
107 bam_dmux_write_cpy_cnt++; \
108 if (msm_bam_dmux_debug_enable) \
109 pr_debug("%s: total write copy cnt %u, bytes %u\n", \
110 __func__, bam_dmux_write_cpy_cnt, \
111 bam_dmux_write_cpy_bytes); \
112 } while (0)
Eric Holmberg2fddbcd2011-11-28 18:25:57 -0700113
114#define DBG_INC_TX_SPS_FAILURE_CNT() do { \
115 bam_dmux_tx_sps_failure_cnt++; \
116} while (0)
117
Eric Holmberg6074aba2012-01-18 17:59:44 -0700118#define DBG_INC_TX_STALL_CNT() do { \
119 bam_dmux_tx_stall_cnt++; \
120} while (0)
121
Eric Holmberg1f1255d2012-02-22 13:37:21 -0700122#define DBG_INC_ACK_OUT_CNT() \
123 atomic_inc(&bam_dmux_ack_out_cnt)
124
125#define DBG_INC_A2_POWER_CONTROL_IN_CNT() \
126 atomic_inc(&bam_dmux_a2_pwr_cntl_in_cnt)
127
128#define DBG_INC_ACK_IN_CNT() \
129 atomic_inc(&bam_dmux_ack_in_cnt)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700130#else
131#define DBG(x...) do { } while (0)
132#define DBG_INC_READ_CNT(x...) do { } while (0)
133#define DBG_INC_WRITE_CNT(x...) do { } while (0)
134#define DBG_INC_WRITE_CPY(x...) do { } while (0)
Eric Holmberg2fddbcd2011-11-28 18:25:57 -0700135#define DBG_INC_TX_SPS_FAILURE_CNT() do { } while (0)
Eric Holmberg6074aba2012-01-18 17:59:44 -0700136#define DBG_INC_TX_STALL_CNT() do { } while (0)
Eric Holmberg1f1255d2012-02-22 13:37:21 -0700137#define DBG_INC_ACK_OUT_CNT() do { } while (0)
138#define DBG_INC_A2_POWER_CONTROL_IN_CNT() \
139 do { } while (0)
140#define DBG_INC_ACK_IN_CNT() do { } while (0)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700141#endif
142
143struct bam_ch_info {
144 uint32_t status;
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600145 void (*notify)(void *, int, unsigned long);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700146 void *priv;
147 spinlock_t lock;
Jeff Hugo7960abd2011-08-02 15:39:38 -0600148 struct platform_device *pdev;
149 char name[BAM_DMUX_CH_NAME_MAX_LEN];
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700150 int num_tx_pkts;
151 int use_wm;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700152};
153
154struct tx_pkt_info {
155 struct sk_buff *skb;
156 dma_addr_t dma_address;
157 char is_cmd;
158 uint32_t len;
159 struct work_struct work;
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600160 struct list_head list_node;
Eric Holmberg878923a2012-01-10 14:28:19 -0700161 unsigned ts_sec;
162 unsigned long ts_nsec;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700163};
164
165struct rx_pkt_info {
166 struct sk_buff *skb;
167 dma_addr_t dma_address;
168 struct work_struct work;
Jeff Hugo949080a2011-08-30 11:58:56 -0600169 struct list_head list_node;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700170};
171
172#define A2_NUM_PIPES 6
173#define A2_SUMMING_THRESHOLD 4096
174#define A2_DEFAULT_DESCRIPTORS 32
175#define A2_PHYS_BASE 0x124C2000
176#define A2_PHYS_SIZE 0x2000
177#define BUFFER_SIZE 2048
178#define NUM_BUFFERS 32
Jeff Hugo3910ee12012-08-21 14:08:20 -0600179
180#ifndef A2_BAM_IRQ
181#define A2_BAM_IRQ -1
182#endif
183
184static void *a2_phys_base;
185static uint32_t a2_phys_size;
186static int a2_bam_irq;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700187static struct sps_bam_props a2_props;
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600188static u32 a2_device_handle;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700189static struct sps_pipe *bam_tx_pipe;
190static struct sps_pipe *bam_rx_pipe;
191static struct sps_connect tx_connection;
192static struct sps_connect rx_connection;
193static struct sps_mem_buffer tx_desc_mem_buf;
194static struct sps_mem_buffer rx_desc_mem_buf;
195static struct sps_register_event tx_register_event;
Jeff Hugo33dbc002011-08-25 15:52:53 -0600196static struct sps_register_event rx_register_event;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700197
198static struct bam_ch_info bam_ch[BAM_DMUX_NUM_CHANNELS];
199static int bam_mux_initialized;
200
Jeff Hugo949080a2011-08-30 11:58:56 -0600201static int polling_mode;
Anurag Singhdcd8b4e2012-07-30 16:46:37 -0700202static unsigned long rx_timer_interval;
Jeff Hugo949080a2011-08-30 11:58:56 -0600203
204static LIST_HEAD(bam_rx_pool);
Jeff Hugoc9749932011-11-02 17:50:40 -0600205static DEFINE_MUTEX(bam_rx_pool_mutexlock);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700206static int bam_rx_pool_len;
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600207static LIST_HEAD(bam_tx_pool);
Jeff Hugoc9749932011-11-02 17:50:40 -0600208static DEFINE_SPINLOCK(bam_tx_pool_spinlock);
Eric Holmberga623da82012-07-12 09:37:09 -0600209static DEFINE_MUTEX(bam_pdev_mutexlock);
Jeff Hugo949080a2011-08-30 11:58:56 -0600210
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700211struct bam_mux_hdr {
212 uint16_t magic_num;
213 uint8_t reserved;
214 uint8_t cmd;
215 uint8_t pad_len;
216 uint8_t ch_id;
217 uint16_t pkt_len;
218};
219
Jeff Hugod98b1082011-10-24 10:30:23 -0600220static void notify_all(int event, unsigned long data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700221static void bam_mux_write_done(struct work_struct *work);
222static void handle_bam_mux_cmd(struct work_struct *work);
Jeff Hugo949080a2011-08-30 11:58:56 -0600223static void rx_timer_work_func(struct work_struct *work);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700224
Jeff Hugo949080a2011-08-30 11:58:56 -0600225static DECLARE_WORK(rx_timer_work, rx_timer_work_func);
Jeff Hugo988e7ba2012-10-03 15:53:54 -0600226static struct delayed_work queue_rx_work;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700227
228static struct workqueue_struct *bam_mux_rx_workqueue;
229static struct workqueue_struct *bam_mux_tx_workqueue;
230
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600231/* A2 power collaspe */
232#define UL_TIMEOUT_DELAY 1000 /* in ms */
Jeff Hugo0b13a352012-03-17 23:18:30 -0600233#define ENABLE_DISCONNECT_ACK 0x1
Brent Hronik096f7d32013-06-28 15:43:08 -0600234#define SHUTDOWN_TIMEOUT_MS 500
Jeff Hugo1f317392013-07-24 16:28:52 -0600235#define UL_WAKEUP_TIMEOUT_MS 2000
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600236static void toggle_apps_ack(void);
237static void reconnect_to_bam(void);
238static void disconnect_to_bam(void);
239static void ul_wakeup(void);
240static void ul_timeout(struct work_struct *work);
241static void vote_dfab(void);
242static void unvote_dfab(void);
Jeff Hugod98b1082011-10-24 10:30:23 -0600243static void kickoff_ul_wakeup_func(struct work_struct *work);
Eric Holmberg006057d2012-01-11 10:10:42 -0700244static void grab_wakelock(void);
245static void release_wakelock(void);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600246
247static int bam_is_connected;
248static DEFINE_MUTEX(wakeup_lock);
249static struct completion ul_wakeup_ack_completion;
250static struct completion bam_connection_completion;
251static struct delayed_work ul_timeout_work;
252static int ul_packet_written;
Eric Holmbergbc9f21c2012-01-18 11:33:33 -0700253static atomic_t ul_ondemand_vote = ATOMIC_INIT(0);
Stephen Boyd69d35e32012-02-14 15:33:30 -0800254static struct clk *dfab_clk, *xo_clk;
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600255static DEFINE_RWLOCK(ul_wakeup_lock);
Jeff Hugod98b1082011-10-24 10:30:23 -0600256static DECLARE_WORK(kickoff_ul_wakeup, kickoff_ul_wakeup_func);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600257static int bam_connection_is_active;
Jeff Hugof6c1c1e2011-12-01 17:43:49 -0700258static int wait_for_ack;
Jeff Hugoae3a85e2011-12-02 17:10:18 -0700259static struct wake_lock bam_wakelock;
Eric Holmberg006057d2012-01-11 10:10:42 -0700260static int a2_pc_disabled;
261static DEFINE_MUTEX(dfab_status_lock);
262static int dfab_is_on;
263static int wait_for_dfab;
264static struct completion dfab_unvote_completion;
265static DEFINE_SPINLOCK(wakelock_reference_lock);
266static int wakelock_reference_count;
Jeff Hugo583a6da2012-02-03 11:37:30 -0700267static int a2_pc_disabled_wakelock_skipped;
Jeff Hugob1e7c582012-06-20 15:02:11 -0600268static int disconnect_ack = 1;
Jeff Hugocb798022012-04-09 14:55:40 -0600269static LIST_HEAD(bam_other_notify_funcs);
Jeff Hugo4b7c7b32012-04-18 16:25:14 -0600270static DEFINE_MUTEX(smsm_cb_lock);
Jeff Hugoc2696142012-05-03 11:42:13 -0600271static DEFINE_MUTEX(delayed_ul_vote_lock);
272static int need_delayed_ul_vote;
Jeff Hugo18792a32012-06-20 15:25:55 -0600273static int power_management_only_mode;
Jeff Hugoa82a95c2012-12-14 17:56:19 -0700274static int in_ssr;
275static int ssr_skipped_disconnect;
Brent Hronik096f7d32013-06-28 15:43:08 -0600276static struct completion shutdown_completion;
Jeff Hugocb798022012-04-09 14:55:40 -0600277
278struct outside_notify_func {
279 void (*notify)(void *, int, unsigned long);
280 void *priv;
281 struct list_head list_node;
282};
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600283/* End A2 power collaspe */
284
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600285/* subsystem restart */
286static int restart_notifier_cb(struct notifier_block *this,
287 unsigned long code,
288 void *data);
289
290static struct notifier_block restart_notifier = {
291 .notifier_call = restart_notifier_cb,
292};
293static int in_global_reset;
294/* end subsystem restart */
295
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700296#define bam_ch_is_open(x) \
297 (bam_ch[(x)].status == (BAM_CH_LOCAL_OPEN | BAM_CH_REMOTE_OPEN))
298
299#define bam_ch_is_local_open(x) \
300 (bam_ch[(x)].status & BAM_CH_LOCAL_OPEN)
301
302#define bam_ch_is_remote_open(x) \
303 (bam_ch[(x)].status & BAM_CH_REMOTE_OPEN)
304
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600305#define bam_ch_is_in_reset(x) \
306 (bam_ch[(x)].status & BAM_CH_IN_RESET)
307
Eric Holmberg878923a2012-01-10 14:28:19 -0700308struct kfifo bam_dmux_state_log;
Eric Holmberg878923a2012-01-10 14:28:19 -0700309static int bam_dmux_uplink_vote;
310static int bam_dmux_power_state;
311
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530312static void *bam_ipc_log_txt;
313
314#define BAM_IPC_LOG_PAGES 5
315
Eric Holmberg878923a2012-01-10 14:28:19 -0700316/**
317 * Log a state change along with a small message.
Eric Holmberg878923a2012-01-10 14:28:19 -0700318 * Complete size of messsage is limited to @todo.
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530319 * Logging is done using IPC Logging infrastructure.
320 *
321 * States
322 * D: 1 = Power collapse disabled
323 * R: 1 = in global reset
324 * P: 1 = BAM is powered up
325 * A: 1 = BAM initialized and ready for data
326 * V: 1 = Uplink vote for power
327 * U: 1 = Uplink active
328 * W: 1 = Uplink Wait-for-ack
329 * A: 1 = Uplink ACK received
330 * #: >=1 On-demand uplink vote
331 * D: 1 = Disconnect ACK active
Eric Holmberg878923a2012-01-10 14:28:19 -0700332 */
Eric Holmberg878923a2012-01-10 14:28:19 -0700333
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530334#define BAM_DMUX_LOG(fmt, args...) \
335do { \
336 if (bam_ipc_log_txt) { \
337 ipc_log_string(bam_ipc_log_txt, \
338 "<DMUX> %c%c%c%c %c%c%c%c%d%c " fmt, \
339 a2_pc_disabled ? 'D' : 'd', \
340 in_global_reset ? 'R' : 'r', \
341 bam_dmux_power_state ? 'P' : 'p', \
342 bam_connection_is_active ? 'A' : 'a', \
343 bam_dmux_uplink_vote ? 'V' : 'v', \
344 bam_is_connected ? 'U' : 'u', \
345 wait_for_ack ? 'W' : 'w', \
346 ul_wakeup_ack_completion.done ? 'A' : 'a', \
347 atomic_read(&ul_ondemand_vote), \
348 disconnect_ack ? 'D' : 'd', \
349 args); \
350 } \
351} while (0)
Eric Holmberg878923a2012-01-10 14:28:19 -0700352
Zaheerulla Meerf800bba2013-02-13 15:49:14 +0530353#define DMUX_LOG_KERR(fmt, args...) \
354do { \
355 BAM_DMUX_LOG(fmt, args); \
356 pr_err(fmt, args); \
357} while (0)
358
Eric Holmberg878923a2012-01-10 14:28:19 -0700359static inline void set_tx_timestamp(struct tx_pkt_info *pkt)
360{
361 unsigned long long t_now;
362
363 t_now = sched_clock();
364 pkt->ts_nsec = do_div(t_now, 1000000000U);
365 pkt->ts_sec = (unsigned)t_now;
366}
367
368static inline void verify_tx_queue_is_empty(const char *func)
369{
370 unsigned long flags;
371 struct tx_pkt_info *info;
372 int reported = 0;
373
374 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
375 list_for_each_entry(info, &bam_tx_pool, list_node) {
376 if (!reported) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530377 BAM_DMUX_LOG("%s: tx pool not empty\n", func);
Eric Holmberg454d9da2012-01-12 09:37:14 -0700378 if (!in_global_reset)
379 pr_err("%s: tx pool not empty\n", func);
Eric Holmberg878923a2012-01-10 14:28:19 -0700380 reported = 1;
381 }
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530382 BAM_DMUX_LOG("%s: node=%p ts=%u.%09lu\n", __func__,
Eric Holmberg454d9da2012-01-12 09:37:14 -0700383 &info->list_node, info->ts_sec, info->ts_nsec);
384 if (!in_global_reset)
385 pr_err("%s: node=%p ts=%u.%09lu\n", __func__,
386 &info->list_node, info->ts_sec, info->ts_nsec);
Eric Holmberg878923a2012-01-10 14:28:19 -0700387 }
388 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
389}
390
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700391static void queue_rx(void)
392{
393 void *ptr;
394 struct rx_pkt_info *info;
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700395 int ret;
396 int rx_len_cached;
Jeff Hugo949080a2011-08-30 11:58:56 -0600397
Jeff Hugoc9749932011-11-02 17:50:40 -0600398 mutex_lock(&bam_rx_pool_mutexlock);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700399 rx_len_cached = bam_rx_pool_len;
Jeff Hugoc9749932011-11-02 17:50:40 -0600400 mutex_unlock(&bam_rx_pool_mutexlock);
Jeff Hugo949080a2011-08-30 11:58:56 -0600401
Jeff Hugo988e7ba2012-10-03 15:53:54 -0600402 while (bam_connection_is_active && rx_len_cached < NUM_BUFFERS) {
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700403 if (in_global_reset)
404 goto fail;
405
Jeff Hugo988e7ba2012-10-03 15:53:54 -0600406 info = kmalloc(sizeof(struct rx_pkt_info),
407 GFP_NOWAIT | __GFP_NOWARN);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700408 if (!info) {
Jeff Hugo988e7ba2012-10-03 15:53:54 -0600409 DMUX_LOG_KERR(
410 "%s: unable to alloc rx_pkt_info, will retry later\n",
411 __func__);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700412 goto fail;
413 }
414
415 INIT_WORK(&info->work, handle_bam_mux_cmd);
416
Jeff Hugo988e7ba2012-10-03 15:53:54 -0600417 info->skb = __dev_alloc_skb(BUFFER_SIZE,
418 GFP_NOWAIT | __GFP_NOWARN);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700419 if (info->skb == NULL) {
Jeff Hugo988e7ba2012-10-03 15:53:54 -0600420 DMUX_LOG_KERR(
421 "%s: unable to alloc skb, will retry later\n",
422 __func__);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700423 goto fail_info;
424 }
425 ptr = skb_put(info->skb, BUFFER_SIZE);
426
427 info->dma_address = dma_map_single(NULL, ptr, BUFFER_SIZE,
428 DMA_FROM_DEVICE);
429 if (info->dma_address == 0 || info->dma_address == ~0) {
430 DMUX_LOG_KERR("%s: dma_map_single failure %p for %p\n",
431 __func__, (void *)info->dma_address, ptr);
432 goto fail_skb;
433 }
434
435 mutex_lock(&bam_rx_pool_mutexlock);
436 list_add_tail(&info->list_node, &bam_rx_pool);
437 rx_len_cached = ++bam_rx_pool_len;
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700438 ret = sps_transfer_one(bam_rx_pipe, info->dma_address,
Jeff Hugoc85df962013-04-05 13:22:48 -0600439 BUFFER_SIZE, info, 0);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700440 if (ret) {
Eric Holmberg00cf8692012-07-16 14:21:19 -0600441 list_del(&info->list_node);
442 rx_len_cached = --bam_rx_pool_len;
443 mutex_unlock(&bam_rx_pool_mutexlock);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700444 DMUX_LOG_KERR("%s: sps_transfer_one failed %d\n",
445 __func__, ret);
Eric Holmberg00cf8692012-07-16 14:21:19 -0600446
447 dma_unmap_single(NULL, info->dma_address, BUFFER_SIZE,
448 DMA_FROM_DEVICE);
449
450 goto fail_skb;
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700451 }
Eric Holmberg00cf8692012-07-16 14:21:19 -0600452 mutex_unlock(&bam_rx_pool_mutexlock);
453
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700454 }
455 return;
456
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700457fail_skb:
458 dev_kfree_skb_any(info->skb);
459
460fail_info:
461 kfree(info);
462
463fail:
Arun Kumar Neelakantam799447f2012-12-13 18:06:49 +0530464 if (rx_len_cached == 0 && !in_global_reset) {
Jeff Hugo988e7ba2012-10-03 15:53:54 -0600465 DMUX_LOG_KERR("%s: rescheduling\n", __func__);
466 schedule_delayed_work(&queue_rx_work, msecs_to_jiffies(100));
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700467 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700468}
469
Jeff Hugo988e7ba2012-10-03 15:53:54 -0600470static void queue_rx_work_func(struct work_struct *work)
471{
472 queue_rx();
473}
474
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700475static void bam_mux_process_data(struct sk_buff *rx_skb)
476{
477 unsigned long flags;
478 struct bam_mux_hdr *rx_hdr;
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600479 unsigned long event_data;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700480
481 rx_hdr = (struct bam_mux_hdr *)rx_skb->data;
482
483 rx_skb->data = (unsigned char *)(rx_hdr + 1);
484 rx_skb->tail = rx_skb->data + rx_hdr->pkt_len;
485 rx_skb->len = rx_hdr->pkt_len;
Jeff Hugoee88f672011-10-04 17:14:52 -0600486 rx_skb->truesize = rx_hdr->pkt_len + sizeof(struct sk_buff);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700487
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600488 event_data = (unsigned long)(rx_skb);
489
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700490 spin_lock_irqsave(&bam_ch[rx_hdr->ch_id].lock, flags);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600491 if (bam_ch[rx_hdr->ch_id].notify)
492 bam_ch[rx_hdr->ch_id].notify(
493 bam_ch[rx_hdr->ch_id].priv, BAM_DMUX_RECEIVE,
494 event_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700495 else
496 dev_kfree_skb_any(rx_skb);
497 spin_unlock_irqrestore(&bam_ch[rx_hdr->ch_id].lock, flags);
498
499 queue_rx();
500}
501
Eric Holmberg006057d2012-01-11 10:10:42 -0700502static inline void handle_bam_mux_cmd_open(struct bam_mux_hdr *rx_hdr)
503{
504 unsigned long flags;
505 int ret;
506
Eric Holmberga623da82012-07-12 09:37:09 -0600507 mutex_lock(&bam_pdev_mutexlock);
508 if (in_global_reset) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530509 BAM_DMUX_LOG("%s: open cid %d aborted due to ssr\n",
Eric Holmberga623da82012-07-12 09:37:09 -0600510 __func__, rx_hdr->ch_id);
511 mutex_unlock(&bam_pdev_mutexlock);
512 queue_rx();
513 return;
514 }
Eric Holmberg006057d2012-01-11 10:10:42 -0700515 spin_lock_irqsave(&bam_ch[rx_hdr->ch_id].lock, flags);
516 bam_ch[rx_hdr->ch_id].status |= BAM_CH_REMOTE_OPEN;
517 bam_ch[rx_hdr->ch_id].num_tx_pkts = 0;
518 spin_unlock_irqrestore(&bam_ch[rx_hdr->ch_id].lock, flags);
Eric Holmberg006057d2012-01-11 10:10:42 -0700519 ret = platform_device_add(bam_ch[rx_hdr->ch_id].pdev);
520 if (ret)
521 pr_err("%s: platform_device_add() error: %d\n",
522 __func__, ret);
Eric Holmberga623da82012-07-12 09:37:09 -0600523 mutex_unlock(&bam_pdev_mutexlock);
524 queue_rx();
Eric Holmberg006057d2012-01-11 10:10:42 -0700525}
526
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700527static void handle_bam_mux_cmd(struct work_struct *work)
528{
529 unsigned long flags;
530 struct bam_mux_hdr *rx_hdr;
531 struct rx_pkt_info *info;
532 struct sk_buff *rx_skb;
533
534 info = container_of(work, struct rx_pkt_info, work);
535 rx_skb = info->skb;
Jeff Hugo949080a2011-08-30 11:58:56 -0600536 dma_unmap_single(NULL, info->dma_address, BUFFER_SIZE, DMA_FROM_DEVICE);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700537 kfree(info);
538
539 rx_hdr = (struct bam_mux_hdr *)rx_skb->data;
540
541 DBG_INC_READ_CNT(sizeof(struct bam_mux_hdr));
542 DBG("%s: magic %x reserved %d cmd %d pad %d ch %d len %d\n", __func__,
543 rx_hdr->magic_num, rx_hdr->reserved, rx_hdr->cmd,
544 rx_hdr->pad_len, rx_hdr->ch_id, rx_hdr->pkt_len);
545 if (rx_hdr->magic_num != BAM_MUX_HDR_MAGIC_NO) {
Eric Holmberg878923a2012-01-10 14:28:19 -0700546 DMUX_LOG_KERR("%s: dropping invalid hdr. magic %x"
547 " reserved %d cmd %d"
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700548 " pad %d ch %d len %d\n", __func__,
549 rx_hdr->magic_num, rx_hdr->reserved, rx_hdr->cmd,
550 rx_hdr->pad_len, rx_hdr->ch_id, rx_hdr->pkt_len);
551 dev_kfree_skb_any(rx_skb);
552 queue_rx();
553 return;
554 }
Eric Holmberg9ff40a52011-11-17 19:17:00 -0700555
556 if (rx_hdr->ch_id >= BAM_DMUX_NUM_CHANNELS) {
Eric Holmberg878923a2012-01-10 14:28:19 -0700557 DMUX_LOG_KERR("%s: dropping invalid LCID %d"
558 " reserved %d cmd %d"
Eric Holmberg9ff40a52011-11-17 19:17:00 -0700559 " pad %d ch %d len %d\n", __func__,
560 rx_hdr->ch_id, rx_hdr->reserved, rx_hdr->cmd,
561 rx_hdr->pad_len, rx_hdr->ch_id, rx_hdr->pkt_len);
562 dev_kfree_skb_any(rx_skb);
563 queue_rx();
564 return;
565 }
566
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700567 switch (rx_hdr->cmd) {
568 case BAM_MUX_HDR_CMD_DATA:
569 DBG_INC_READ_CNT(rx_hdr->pkt_len);
570 bam_mux_process_data(rx_skb);
571 break;
572 case BAM_MUX_HDR_CMD_OPEN:
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530573 BAM_DMUX_LOG("%s: opening cid %d PC enabled\n", __func__,
Eric Holmberg878923a2012-01-10 14:28:19 -0700574 rx_hdr->ch_id);
Eric Holmberg006057d2012-01-11 10:10:42 -0700575 handle_bam_mux_cmd_open(rx_hdr);
Jeff Hugob1e7c582012-06-20 15:02:11 -0600576 if (!(rx_hdr->reserved & ENABLE_DISCONNECT_ACK)) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530577 BAM_DMUX_LOG("%s: deactivating disconnect ack\n",
Jeff Hugod7d2b062012-07-24 14:29:56 -0600578 __func__);
Jeff Hugob1e7c582012-06-20 15:02:11 -0600579 disconnect_ack = 0;
Jeff Hugo0b13a352012-03-17 23:18:30 -0600580 }
Eric Holmberg006057d2012-01-11 10:10:42 -0700581 dev_kfree_skb_any(rx_skb);
582 break;
583 case BAM_MUX_HDR_CMD_OPEN_NO_A2_PC:
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530584 BAM_DMUX_LOG("%s: opening cid %d PC disabled\n", __func__,
Eric Holmberg006057d2012-01-11 10:10:42 -0700585 rx_hdr->ch_id);
586
587 if (!a2_pc_disabled) {
588 a2_pc_disabled = 1;
Jeff Hugo322179f2012-02-29 10:52:34 -0700589 ul_wakeup();
Eric Holmberg006057d2012-01-11 10:10:42 -0700590 }
591
592 handle_bam_mux_cmd_open(rx_hdr);
Eric Holmberge779dba2011-11-04 18:22:01 -0600593 dev_kfree_skb_any(rx_skb);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700594 break;
595 case BAM_MUX_HDR_CMD_CLOSE:
596 /* probably should drop pending write */
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530597 BAM_DMUX_LOG("%s: closing cid %d\n", __func__,
Eric Holmberg878923a2012-01-10 14:28:19 -0700598 rx_hdr->ch_id);
Eric Holmberga623da82012-07-12 09:37:09 -0600599 mutex_lock(&bam_pdev_mutexlock);
600 if (in_global_reset) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530601 BAM_DMUX_LOG("%s: close cid %d aborted due to ssr\n",
Eric Holmberga623da82012-07-12 09:37:09 -0600602 __func__, rx_hdr->ch_id);
603 mutex_unlock(&bam_pdev_mutexlock);
604 break;
605 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700606 spin_lock_irqsave(&bam_ch[rx_hdr->ch_id].lock, flags);
607 bam_ch[rx_hdr->ch_id].status &= ~BAM_CH_REMOTE_OPEN;
608 spin_unlock_irqrestore(&bam_ch[rx_hdr->ch_id].lock, flags);
Jeff Hugo7960abd2011-08-02 15:39:38 -0600609 platform_device_unregister(bam_ch[rx_hdr->ch_id].pdev);
610 bam_ch[rx_hdr->ch_id].pdev =
611 platform_device_alloc(bam_ch[rx_hdr->ch_id].name, 2);
612 if (!bam_ch[rx_hdr->ch_id].pdev)
613 pr_err("%s: platform_device_alloc failed\n", __func__);
Eric Holmberga623da82012-07-12 09:37:09 -0600614 mutex_unlock(&bam_pdev_mutexlock);
Eric Holmberge779dba2011-11-04 18:22:01 -0600615 dev_kfree_skb_any(rx_skb);
Eric Holmberga623da82012-07-12 09:37:09 -0600616 queue_rx();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700617 break;
618 default:
Eric Holmberg878923a2012-01-10 14:28:19 -0700619 DMUX_LOG_KERR("%s: dropping invalid hdr. magic %x"
620 " reserved %d cmd %d pad %d ch %d len %d\n",
621 __func__, rx_hdr->magic_num, rx_hdr->reserved,
622 rx_hdr->cmd, rx_hdr->pad_len, rx_hdr->ch_id,
623 rx_hdr->pkt_len);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700624 dev_kfree_skb_any(rx_skb);
625 queue_rx();
626 return;
627 }
628}
629
630static int bam_mux_write_cmd(void *data, uint32_t len)
631{
632 int rc;
633 struct tx_pkt_info *pkt;
634 dma_addr_t dma_address;
Jeff Hugo626303bf2011-11-21 11:43:28 -0700635 unsigned long flags;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700636
Eric Holmbergd83cd2b2011-11-04 15:54:17 -0600637 pkt = kmalloc(sizeof(struct tx_pkt_info), GFP_ATOMIC);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700638 if (pkt == NULL) {
639 pr_err("%s: mem alloc for tx_pkt_info failed\n", __func__);
640 rc = -ENOMEM;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700641 return rc;
642 }
643
644 dma_address = dma_map_single(NULL, data, len,
645 DMA_TO_DEVICE);
646 if (!dma_address) {
647 pr_err("%s: dma_map_single() failed\n", __func__);
Jeff Hugo96cb7482011-12-07 13:28:31 -0700648 kfree(pkt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700649 rc = -ENOMEM;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700650 return rc;
651 }
652 pkt->skb = (struct sk_buff *)(data);
653 pkt->len = len;
654 pkt->dma_address = dma_address;
655 pkt->is_cmd = 1;
Eric Holmberg878923a2012-01-10 14:28:19 -0700656 set_tx_timestamp(pkt);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600657 INIT_WORK(&pkt->work, bam_mux_write_done);
Jeff Hugo626303bf2011-11-21 11:43:28 -0700658 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600659 list_add_tail(&pkt->list_node, &bam_tx_pool);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700660 rc = sps_transfer_one(bam_tx_pipe, dma_address, len,
Jeff Hugoc85df962013-04-05 13:22:48 -0600661 pkt, SPS_IOVEC_FLAG_EOT);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600662 if (rc) {
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700663 DMUX_LOG_KERR("%s sps_transfer_one failed rc=%d\n",
664 __func__, rc);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600665 list_del(&pkt->list_node);
Eric Holmberg2fddbcd2011-11-28 18:25:57 -0700666 DBG_INC_TX_SPS_FAILURE_CNT();
Jeff Hugo626303bf2011-11-21 11:43:28 -0700667 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700668 dma_unmap_single(NULL, pkt->dma_address,
669 pkt->len,
670 DMA_TO_DEVICE);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600671 kfree(pkt);
Jeff Hugobb6da952012-01-16 15:02:42 -0700672 } else {
673 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600674 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700675
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600676 ul_packet_written = 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700677 return rc;
678}
679
680static void bam_mux_write_done(struct work_struct *work)
681{
682 struct sk_buff *skb;
683 struct bam_mux_hdr *hdr;
684 struct tx_pkt_info *info;
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700685 struct tx_pkt_info *info_expected;
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600686 unsigned long event_data;
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700687 unsigned long flags;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700688
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600689 if (in_global_reset)
690 return;
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700691
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700692 info = container_of(work, struct tx_pkt_info, work);
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700693
694 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
695 info_expected = list_first_entry(&bam_tx_pool,
696 struct tx_pkt_info, list_node);
697 if (unlikely(info != info_expected)) {
Eric Holmberg878923a2012-01-10 14:28:19 -0700698 struct tx_pkt_info *errant_pkt;
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700699
Eric Holmberg878923a2012-01-10 14:28:19 -0700700 DMUX_LOG_KERR("%s: bam_tx_pool mismatch .next=%p,"
701 " list_node=%p, ts=%u.%09lu\n",
702 __func__, bam_tx_pool.next, &info->list_node,
703 info->ts_sec, info->ts_nsec
704 );
705
706 list_for_each_entry(errant_pkt, &bam_tx_pool, list_node) {
707 DMUX_LOG_KERR("%s: node=%p ts=%u.%09lu\n", __func__,
708 &errant_pkt->list_node, errant_pkt->ts_sec,
709 errant_pkt->ts_nsec);
710
711 }
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700712 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
713 BUG();
714 }
715 list_del(&info->list_node);
716 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
717
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600718 if (info->is_cmd) {
719 kfree(info->skb);
720 kfree(info);
721 return;
722 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700723 skb = info->skb;
724 kfree(info);
725 hdr = (struct bam_mux_hdr *)skb->data;
Eric Holmberg9fdef262012-02-14 11:46:05 -0700726 DBG_INC_WRITE_CNT(skb->len);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600727 event_data = (unsigned long)(skb);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700728 spin_lock_irqsave(&bam_ch[hdr->ch_id].lock, flags);
729 bam_ch[hdr->ch_id].num_tx_pkts--;
730 spin_unlock_irqrestore(&bam_ch[hdr->ch_id].lock, flags);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600731 if (bam_ch[hdr->ch_id].notify)
732 bam_ch[hdr->ch_id].notify(
733 bam_ch[hdr->ch_id].priv, BAM_DMUX_WRITE_DONE,
734 event_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700735 else
736 dev_kfree_skb_any(skb);
737}
738
739int msm_bam_dmux_write(uint32_t id, struct sk_buff *skb)
740{
741 int rc = 0;
742 struct bam_mux_hdr *hdr;
743 unsigned long flags;
744 struct sk_buff *new_skb = NULL;
745 dma_addr_t dma_address;
746 struct tx_pkt_info *pkt;
747
748 if (id >= BAM_DMUX_NUM_CHANNELS)
749 return -EINVAL;
750 if (!skb)
751 return -EINVAL;
752 if (!bam_mux_initialized)
753 return -ENODEV;
754
755 DBG("%s: writing to ch %d len %d\n", __func__, id, skb->len);
756 spin_lock_irqsave(&bam_ch[id].lock, flags);
757 if (!bam_ch_is_open(id)) {
758 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
759 pr_err("%s: port not open: %d\n", __func__, bam_ch[id].status);
760 return -ENODEV;
761 }
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700762
763 if (bam_ch[id].use_wm &&
764 (bam_ch[id].num_tx_pkts >= HIGH_WATERMARK)) {
765 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
766 pr_err("%s: watermark exceeded: %d\n", __func__, id);
767 return -EAGAIN;
768 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700769 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
770
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600771 read_lock(&ul_wakeup_lock);
Jeff Hugo061ce672011-10-21 17:15:32 -0600772 if (!bam_is_connected) {
773 read_unlock(&ul_wakeup_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600774 ul_wakeup();
Jeff Hugo4838f412012-01-20 11:19:37 -0700775 if (unlikely(in_global_reset == 1))
776 return -EFAULT;
Jeff Hugo061ce672011-10-21 17:15:32 -0600777 read_lock(&ul_wakeup_lock);
Jeff Hugod98b1082011-10-24 10:30:23 -0600778 notify_all(BAM_DMUX_UL_CONNECTED, (unsigned long)(NULL));
Jeff Hugo061ce672011-10-21 17:15:32 -0600779 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600780
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700781 /* if skb do not have any tailroom for padding,
782 copy the skb into a new expanded skb */
783 if ((skb->len & 0x3) && (skb_tailroom(skb) < (4 - (skb->len & 0x3)))) {
784 /* revisit, probably dev_alloc_skb and memcpy is effecient */
785 new_skb = skb_copy_expand(skb, skb_headroom(skb),
786 4 - (skb->len & 0x3), GFP_ATOMIC);
787 if (new_skb == NULL) {
788 pr_err("%s: cannot allocate skb\n", __func__);
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600789 goto write_fail;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700790 }
791 dev_kfree_skb_any(skb);
792 skb = new_skb;
793 DBG_INC_WRITE_CPY(skb->len);
794 }
795
796 hdr = (struct bam_mux_hdr *)skb_push(skb, sizeof(struct bam_mux_hdr));
797
798 /* caller should allocate for hdr and padding
799 hdr is fine, padding is tricky */
800 hdr->magic_num = BAM_MUX_HDR_MAGIC_NO;
801 hdr->cmd = BAM_MUX_HDR_CMD_DATA;
802 hdr->reserved = 0;
803 hdr->ch_id = id;
804 hdr->pkt_len = skb->len - sizeof(struct bam_mux_hdr);
805 if (skb->len & 0x3)
806 skb_put(skb, 4 - (skb->len & 0x3));
807
808 hdr->pad_len = skb->len - (sizeof(struct bam_mux_hdr) + hdr->pkt_len);
809
810 DBG("%s: data %p, tail %p skb len %d pkt len %d pad len %d\n",
811 __func__, skb->data, skb->tail, skb->len,
812 hdr->pkt_len, hdr->pad_len);
813
814 pkt = kmalloc(sizeof(struct tx_pkt_info), GFP_ATOMIC);
815 if (pkt == NULL) {
816 pr_err("%s: mem alloc for tx_pkt_info failed\n", __func__);
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600817 goto write_fail2;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700818 }
819
820 dma_address = dma_map_single(NULL, skb->data, skb->len,
821 DMA_TO_DEVICE);
822 if (!dma_address) {
823 pr_err("%s: dma_map_single() failed\n", __func__);
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600824 goto write_fail3;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700825 }
826 pkt->skb = skb;
827 pkt->dma_address = dma_address;
828 pkt->is_cmd = 0;
Eric Holmberg878923a2012-01-10 14:28:19 -0700829 set_tx_timestamp(pkt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700830 INIT_WORK(&pkt->work, bam_mux_write_done);
Jeff Hugo626303bf2011-11-21 11:43:28 -0700831 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600832 list_add_tail(&pkt->list_node, &bam_tx_pool);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700833 rc = sps_transfer_one(bam_tx_pipe, dma_address, skb->len,
Jeff Hugoc85df962013-04-05 13:22:48 -0600834 pkt, SPS_IOVEC_FLAG_EOT);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600835 if (rc) {
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700836 DMUX_LOG_KERR("%s sps_transfer_one failed rc=%d\n",
837 __func__, rc);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600838 list_del(&pkt->list_node);
Eric Holmberg2fddbcd2011-11-28 18:25:57 -0700839 DBG_INC_TX_SPS_FAILURE_CNT();
Jeff Hugo626303bf2011-11-21 11:43:28 -0700840 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700841 dma_unmap_single(NULL, pkt->dma_address,
842 pkt->skb->len, DMA_TO_DEVICE);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600843 kfree(pkt);
Jeff Hugo872bd062011-11-15 17:47:21 -0700844 if (new_skb)
845 dev_kfree_skb_any(new_skb);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700846 } else {
Jeff Hugobb6da952012-01-16 15:02:42 -0700847 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700848 spin_lock_irqsave(&bam_ch[id].lock, flags);
849 bam_ch[id].num_tx_pkts++;
850 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600851 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600852 ul_packet_written = 1;
853 read_unlock(&ul_wakeup_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700854 return rc;
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600855
856write_fail3:
857 kfree(pkt);
858write_fail2:
Arun Kumar Neelakantam406e5692013-01-17 18:58:04 +0530859 skb_pull(skb, sizeof(struct bam_mux_hdr));
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600860 if (new_skb)
861 dev_kfree_skb_any(new_skb);
862write_fail:
863 read_unlock(&ul_wakeup_lock);
864 return -ENOMEM;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700865}
866
867int msm_bam_dmux_open(uint32_t id, void *priv,
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600868 void (*notify)(void *, int, unsigned long))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700869{
870 struct bam_mux_hdr *hdr;
871 unsigned long flags;
872 int rc = 0;
873
874 DBG("%s: opening ch %d\n", __func__, id);
Eric Holmberg5d775432011-11-09 10:23:35 -0700875 if (!bam_mux_initialized) {
876 DBG("%s: not inititialized\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700877 return -ENODEV;
Eric Holmberg5d775432011-11-09 10:23:35 -0700878 }
879 if (id >= BAM_DMUX_NUM_CHANNELS) {
880 pr_err("%s: invalid channel id %d\n", __func__, id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700881 return -EINVAL;
Eric Holmberg5d775432011-11-09 10:23:35 -0700882 }
883 if (notify == NULL) {
884 pr_err("%s: notify function is NULL\n", __func__);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600885 return -EINVAL;
Eric Holmberg5d775432011-11-09 10:23:35 -0700886 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700887
888 hdr = kmalloc(sizeof(struct bam_mux_hdr), GFP_KERNEL);
889 if (hdr == NULL) {
890 pr_err("%s: hdr kmalloc failed. ch: %d\n", __func__, id);
891 return -ENOMEM;
892 }
893 spin_lock_irqsave(&bam_ch[id].lock, flags);
894 if (bam_ch_is_open(id)) {
895 DBG("%s: Already opened %d\n", __func__, id);
896 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
897 kfree(hdr);
898 goto open_done;
899 }
900 if (!bam_ch_is_remote_open(id)) {
901 DBG("%s: Remote not open; ch: %d\n", __func__, id);
902 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
903 kfree(hdr);
Eric Holmberg5d775432011-11-09 10:23:35 -0700904 return -ENODEV;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700905 }
906
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600907 bam_ch[id].notify = notify;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700908 bam_ch[id].priv = priv;
909 bam_ch[id].status |= BAM_CH_LOCAL_OPEN;
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700910 bam_ch[id].num_tx_pkts = 0;
911 bam_ch[id].use_wm = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700912 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
913
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600914 read_lock(&ul_wakeup_lock);
Jeff Hugo061ce672011-10-21 17:15:32 -0600915 if (!bam_is_connected) {
916 read_unlock(&ul_wakeup_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600917 ul_wakeup();
Brent Hronik96630422013-05-01 16:38:43 -0600918 if (unlikely(in_global_reset == 1)) {
919 kfree(hdr);
Jeff Hugo4838f412012-01-20 11:19:37 -0700920 return -EFAULT;
Brent Hronik96630422013-05-01 16:38:43 -0600921 }
Jeff Hugo061ce672011-10-21 17:15:32 -0600922 read_lock(&ul_wakeup_lock);
Jeff Hugod98b1082011-10-24 10:30:23 -0600923 notify_all(BAM_DMUX_UL_CONNECTED, (unsigned long)(NULL));
Jeff Hugo061ce672011-10-21 17:15:32 -0600924 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600925
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700926 hdr->magic_num = BAM_MUX_HDR_MAGIC_NO;
927 hdr->cmd = BAM_MUX_HDR_CMD_OPEN;
928 hdr->reserved = 0;
929 hdr->ch_id = id;
930 hdr->pkt_len = 0;
931 hdr->pad_len = 0;
932
933 rc = bam_mux_write_cmd((void *)hdr, sizeof(struct bam_mux_hdr));
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600934 read_unlock(&ul_wakeup_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700935
936open_done:
937 DBG("%s: opened ch %d\n", __func__, id);
938 return rc;
939}
940
941int msm_bam_dmux_close(uint32_t id)
942{
943 struct bam_mux_hdr *hdr;
944 unsigned long flags;
945 int rc;
946
947 if (id >= BAM_DMUX_NUM_CHANNELS)
948 return -EINVAL;
949 DBG("%s: closing ch %d\n", __func__, id);
950 if (!bam_mux_initialized)
951 return -ENODEV;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700952
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600953 read_lock(&ul_wakeup_lock);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600954 if (!bam_is_connected && !bam_ch_is_in_reset(id)) {
Jeff Hugo061ce672011-10-21 17:15:32 -0600955 read_unlock(&ul_wakeup_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600956 ul_wakeup();
Jeff Hugo4838f412012-01-20 11:19:37 -0700957 if (unlikely(in_global_reset == 1))
958 return -EFAULT;
Jeff Hugo061ce672011-10-21 17:15:32 -0600959 read_lock(&ul_wakeup_lock);
Jeff Hugod98b1082011-10-24 10:30:23 -0600960 notify_all(BAM_DMUX_UL_CONNECTED, (unsigned long)(NULL));
Jeff Hugo061ce672011-10-21 17:15:32 -0600961 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600962
Jeff Hugo061ce672011-10-21 17:15:32 -0600963 spin_lock_irqsave(&bam_ch[id].lock, flags);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600964 bam_ch[id].notify = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700965 bam_ch[id].priv = NULL;
966 bam_ch[id].status &= ~BAM_CH_LOCAL_OPEN;
967 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
968
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600969 if (bam_ch_is_in_reset(id)) {
970 read_unlock(&ul_wakeup_lock);
971 bam_ch[id].status &= ~BAM_CH_IN_RESET;
972 return 0;
973 }
974
Jeff Hugobb5802f2011-11-02 17:10:29 -0600975 hdr = kmalloc(sizeof(struct bam_mux_hdr), GFP_ATOMIC);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700976 if (hdr == NULL) {
977 pr_err("%s: hdr kmalloc failed. ch: %d\n", __func__, id);
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600978 read_unlock(&ul_wakeup_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700979 return -ENOMEM;
980 }
981 hdr->magic_num = BAM_MUX_HDR_MAGIC_NO;
982 hdr->cmd = BAM_MUX_HDR_CMD_CLOSE;
983 hdr->reserved = 0;
984 hdr->ch_id = id;
985 hdr->pkt_len = 0;
986 hdr->pad_len = 0;
987
988 rc = bam_mux_write_cmd((void *)hdr, sizeof(struct bam_mux_hdr));
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600989 read_unlock(&ul_wakeup_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700990
991 DBG("%s: closed ch %d\n", __func__, id);
992 return rc;
993}
994
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700995int msm_bam_dmux_is_ch_full(uint32_t id)
996{
997 unsigned long flags;
998 int ret;
999
1000 if (id >= BAM_DMUX_NUM_CHANNELS)
1001 return -EINVAL;
1002
1003 spin_lock_irqsave(&bam_ch[id].lock, flags);
1004 bam_ch[id].use_wm = 1;
1005 ret = bam_ch[id].num_tx_pkts >= HIGH_WATERMARK;
1006 DBG("%s: ch %d num tx pkts=%d, HWM=%d\n", __func__,
1007 id, bam_ch[id].num_tx_pkts, ret);
1008 if (!bam_ch_is_local_open(id)) {
1009 ret = -ENODEV;
1010 pr_err("%s: port not open: %d\n", __func__, bam_ch[id].status);
1011 }
1012 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
1013
1014 return ret;
1015}
1016
1017int msm_bam_dmux_is_ch_low(uint32_t id)
1018{
Eric Holmberged3ca0a2012-04-09 15:44:58 -06001019 unsigned long flags;
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -07001020 int ret;
1021
1022 if (id >= BAM_DMUX_NUM_CHANNELS)
1023 return -EINVAL;
1024
Eric Holmberged3ca0a2012-04-09 15:44:58 -06001025 spin_lock_irqsave(&bam_ch[id].lock, flags);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -07001026 bam_ch[id].use_wm = 1;
1027 ret = bam_ch[id].num_tx_pkts <= LOW_WATERMARK;
1028 DBG("%s: ch %d num tx pkts=%d, LWM=%d\n", __func__,
1029 id, bam_ch[id].num_tx_pkts, ret);
1030 if (!bam_ch_is_local_open(id)) {
1031 ret = -ENODEV;
1032 pr_err("%s: port not open: %d\n", __func__, bam_ch[id].status);
1033 }
Eric Holmberged3ca0a2012-04-09 15:44:58 -06001034 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -07001035
1036 return ret;
1037}
1038
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001039static void rx_switch_to_interrupt_mode(void)
1040{
1041 struct sps_connect cur_rx_conn;
1042 struct sps_iovec iov;
1043 struct rx_pkt_info *info;
1044 int ret;
1045
1046 /*
1047 * Attempt to enable interrupts - if this fails,
1048 * continue polling and we will retry later.
1049 */
1050 ret = sps_get_config(bam_rx_pipe, &cur_rx_conn);
1051 if (ret) {
1052 pr_err("%s: sps_get_config() failed %d\n", __func__, ret);
1053 goto fail;
1054 }
1055
1056 rx_register_event.options = SPS_O_EOT;
1057 ret = sps_register_event(bam_rx_pipe, &rx_register_event);
1058 if (ret) {
1059 pr_err("%s: sps_register_event() failed %d\n", __func__, ret);
1060 goto fail;
1061 }
1062
1063 cur_rx_conn.options = SPS_O_AUTO_ENABLE |
1064 SPS_O_EOT | SPS_O_ACK_TRANSFERS;
1065 ret = sps_set_config(bam_rx_pipe, &cur_rx_conn);
1066 if (ret) {
1067 pr_err("%s: sps_set_config() failed %d\n", __func__, ret);
1068 goto fail;
1069 }
1070 polling_mode = 0;
Brent Hronik096f7d32013-06-28 15:43:08 -06001071 complete_all(&shutdown_completion);
Eric Holmberg006057d2012-01-11 10:10:42 -07001072 release_wakelock();
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001073
1074 /* handle any rx packets before interrupt was enabled */
1075 while (bam_connection_is_active && !polling_mode) {
1076 ret = sps_get_iovec(bam_rx_pipe, &iov);
1077 if (ret) {
1078 pr_err("%s: sps_get_iovec failed %d\n",
1079 __func__, ret);
1080 break;
1081 }
1082 if (iov.addr == 0)
1083 break;
1084
1085 mutex_lock(&bam_rx_pool_mutexlock);
1086 if (unlikely(list_empty(&bam_rx_pool))) {
Eric Holmberg00cf8692012-07-16 14:21:19 -06001087 DMUX_LOG_KERR("%s: have iovec %p but rx pool empty\n",
1088 __func__, (void *)iov.addr);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001089 mutex_unlock(&bam_rx_pool_mutexlock);
1090 continue;
1091 }
1092 info = list_first_entry(&bam_rx_pool, struct rx_pkt_info,
1093 list_node);
Eric Holmberg00cf8692012-07-16 14:21:19 -06001094 if (info->dma_address != iov.addr) {
1095 DMUX_LOG_KERR("%s: iovec %p != dma %p\n",
1096 __func__,
1097 (void *)iov.addr,
1098 (void *)info->dma_address);
1099 list_for_each_entry(info, &bam_rx_pool, list_node) {
1100 DMUX_LOG_KERR("%s: dma %p\n", __func__,
1101 (void *)info->dma_address);
1102 if (iov.addr == info->dma_address)
1103 break;
1104 }
1105 }
1106 BUG_ON(info->dma_address != iov.addr);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001107 list_del(&info->list_node);
Eric Holmbergb5b08e52012-01-20 14:19:00 -07001108 --bam_rx_pool_len;
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001109 mutex_unlock(&bam_rx_pool_mutexlock);
1110 handle_bam_mux_cmd(&info->work);
1111 }
1112 return;
1113
1114fail:
1115 pr_err("%s: reverting to polling\n", __func__);
Jeff Hugofff43af92012-03-29 17:54:52 -06001116 queue_work_on(0, bam_mux_rx_workqueue, &rx_timer_work);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001117}
1118
Jeff Hugo949080a2011-08-30 11:58:56 -06001119static void rx_timer_work_func(struct work_struct *work)
1120{
1121 struct sps_iovec iov;
Jeff Hugo949080a2011-08-30 11:58:56 -06001122 struct rx_pkt_info *info;
1123 int inactive_cycles = 0;
1124 int ret;
Anurag Singhdcd8b4e2012-07-30 16:46:37 -07001125 u32 buffs_unused, buffs_used;
Jeff Hugo949080a2011-08-30 11:58:56 -06001126
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001127 while (bam_connection_is_active) { /* timer loop */
Jeff Hugo949080a2011-08-30 11:58:56 -06001128 ++inactive_cycles;
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001129 while (bam_connection_is_active) { /* deplete queue loop */
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001130 if (in_global_reset)
1131 return;
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001132
1133 ret = sps_get_iovec(bam_rx_pipe, &iov);
1134 if (ret) {
1135 pr_err("%s: sps_get_iovec failed %d\n",
1136 __func__, ret);
1137 break;
1138 }
Jeff Hugo949080a2011-08-30 11:58:56 -06001139 if (iov.addr == 0)
1140 break;
1141 inactive_cycles = 0;
Jeff Hugoc9749932011-11-02 17:50:40 -06001142 mutex_lock(&bam_rx_pool_mutexlock);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001143 if (unlikely(list_empty(&bam_rx_pool))) {
Eric Holmberg00cf8692012-07-16 14:21:19 -06001144 DMUX_LOG_KERR(
1145 "%s: have iovec %p but rx pool empty\n",
1146 __func__, (void *)iov.addr);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001147 mutex_unlock(&bam_rx_pool_mutexlock);
1148 continue;
1149 }
1150 info = list_first_entry(&bam_rx_pool,
1151 struct rx_pkt_info, list_node);
Eric Holmberg00cf8692012-07-16 14:21:19 -06001152 if (info->dma_address != iov.addr) {
1153 DMUX_LOG_KERR("%s: iovec %p != dma %p\n",
1154 __func__,
1155 (void *)iov.addr,
1156 (void *)info->dma_address);
1157 list_for_each_entry(info, &bam_rx_pool,
1158 list_node) {
1159 DMUX_LOG_KERR("%s: dma %p\n", __func__,
1160 (void *)info->dma_address);
1161 if (iov.addr == info->dma_address)
1162 break;
1163 }
1164 }
1165 BUG_ON(info->dma_address != iov.addr);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001166 list_del(&info->list_node);
Eric Holmberg00cf8692012-07-16 14:21:19 -06001167 --bam_rx_pool_len;
Jeff Hugoc9749932011-11-02 17:50:40 -06001168 mutex_unlock(&bam_rx_pool_mutexlock);
Jeff Hugo949080a2011-08-30 11:58:56 -06001169 handle_bam_mux_cmd(&info->work);
1170 }
1171
Anurag Singhdcd8b4e2012-07-30 16:46:37 -07001172 if (inactive_cycles >= POLLING_INACTIVITY) {
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001173 rx_switch_to_interrupt_mode();
1174 break;
Jeff Hugo949080a2011-08-30 11:58:56 -06001175 }
1176
Anurag Singhdcd8b4e2012-07-30 16:46:37 -07001177 if (bam_adaptive_timer_enabled) {
1178 usleep_range(rx_timer_interval, rx_timer_interval + 50);
1179
1180 ret = sps_get_unused_desc_num(bam_rx_pipe,
1181 &buffs_unused);
1182
1183 if (ret) {
1184 pr_err("%s: error getting num buffers unused after sleep\n",
1185 __func__);
1186
1187 break;
1188 }
1189
1190 buffs_used = NUM_BUFFERS - buffs_unused;
1191
1192 if (buffs_unused == 0) {
1193 rx_timer_interval = MIN_POLLING_SLEEP;
1194 } else {
1195 if (buffs_used > 0) {
1196 rx_timer_interval =
1197 (2 * NUM_BUFFERS *
1198 rx_timer_interval)/
1199 (3 * buffs_used);
1200 } else {
1201 rx_timer_interval =
1202 MAX_POLLING_SLEEP;
1203 }
1204 }
1205
1206 if (rx_timer_interval > MAX_POLLING_SLEEP)
1207 rx_timer_interval = MAX_POLLING_SLEEP;
1208 else if (rx_timer_interval < MIN_POLLING_SLEEP)
1209 rx_timer_interval = MIN_POLLING_SLEEP;
1210 } else {
1211 usleep_range(POLLING_MIN_SLEEP, POLLING_MAX_SLEEP);
1212 }
Jeff Hugo949080a2011-08-30 11:58:56 -06001213 }
1214}
1215
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001216static void bam_mux_tx_notify(struct sps_event_notify *notify)
1217{
1218 struct tx_pkt_info *pkt;
1219
1220 DBG("%s: event %d notified\n", __func__, notify->event_id);
1221
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001222 if (in_global_reset)
1223 return;
1224
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001225 switch (notify->event_id) {
1226 case SPS_EVENT_EOT:
1227 pkt = notify->data.transfer.user;
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001228 if (!pkt->is_cmd)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001229 dma_unmap_single(NULL, pkt->dma_address,
1230 pkt->skb->len,
1231 DMA_TO_DEVICE);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001232 else
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001233 dma_unmap_single(NULL, pkt->dma_address,
1234 pkt->len,
1235 DMA_TO_DEVICE);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001236 queue_work(bam_mux_tx_workqueue, &pkt->work);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001237 break;
1238 default:
1239 pr_err("%s: recieved unexpected event id %d\n", __func__,
1240 notify->event_id);
1241 }
1242}
1243
Jeff Hugo33dbc002011-08-25 15:52:53 -06001244static void bam_mux_rx_notify(struct sps_event_notify *notify)
1245{
Jeff Hugo949080a2011-08-30 11:58:56 -06001246 int ret;
1247 struct sps_connect cur_rx_conn;
Jeff Hugo33dbc002011-08-25 15:52:53 -06001248
1249 DBG("%s: event %d notified\n", __func__, notify->event_id);
1250
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001251 if (in_global_reset)
1252 return;
1253
Jeff Hugo33dbc002011-08-25 15:52:53 -06001254 switch (notify->event_id) {
1255 case SPS_EVENT_EOT:
Jeff Hugo949080a2011-08-30 11:58:56 -06001256 /* attempt to disable interrupts in this pipe */
1257 if (!polling_mode) {
1258 ret = sps_get_config(bam_rx_pipe, &cur_rx_conn);
1259 if (ret) {
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001260 pr_err("%s: sps_get_config() failed %d, interrupts"
1261 " not disabled\n", __func__, ret);
Jeff Hugo949080a2011-08-30 11:58:56 -06001262 break;
1263 }
Jeff Hugoa9d32ba2011-11-21 14:59:48 -07001264 cur_rx_conn.options = SPS_O_AUTO_ENABLE |
Jeff Hugo949080a2011-08-30 11:58:56 -06001265 SPS_O_ACK_TRANSFERS | SPS_O_POLL;
1266 ret = sps_set_config(bam_rx_pipe, &cur_rx_conn);
1267 if (ret) {
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001268 pr_err("%s: sps_set_config() failed %d, interrupts"
1269 " not disabled\n", __func__, ret);
Jeff Hugo949080a2011-08-30 11:58:56 -06001270 break;
1271 }
Brent Hronik096f7d32013-06-28 15:43:08 -06001272 INIT_COMPLETION(shutdown_completion);
Eric Holmberg006057d2012-01-11 10:10:42 -07001273 grab_wakelock();
Jeff Hugo949080a2011-08-30 11:58:56 -06001274 polling_mode = 1;
Jeff Hugofff43af92012-03-29 17:54:52 -06001275 /*
1276 * run on core 0 so that netif_rx() in rmnet uses only
1277 * one queue
1278 */
1279 queue_work_on(0, bam_mux_rx_workqueue, &rx_timer_work);
Jeff Hugo949080a2011-08-30 11:58:56 -06001280 }
Jeff Hugo33dbc002011-08-25 15:52:53 -06001281 break;
1282 default:
1283 pr_err("%s: recieved unexpected event id %d\n", __func__,
1284 notify->event_id);
1285 }
1286}
1287
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001288#ifdef CONFIG_DEBUG_FS
1289
1290static int debug_tbl(char *buf, int max)
1291{
1292 int i = 0;
1293 int j;
1294
1295 for (j = 0; j < BAM_DMUX_NUM_CHANNELS; ++j) {
1296 i += scnprintf(buf + i, max - i,
1297 "ch%02d local open=%s remote open=%s\n",
1298 j, bam_ch_is_local_open(j) ? "Y" : "N",
1299 bam_ch_is_remote_open(j) ? "Y" : "N");
1300 }
1301
1302 return i;
1303}
1304
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07001305static int debug_ul_pkt_cnt(char *buf, int max)
1306{
1307 struct list_head *p;
1308 unsigned long flags;
1309 int n = 0;
1310
1311 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
1312 __list_for_each(p, &bam_tx_pool) {
1313 ++n;
1314 }
1315 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
1316
1317 return scnprintf(buf, max, "Number of UL packets in flight: %d\n", n);
1318}
1319
1320static int debug_stats(char *buf, int max)
1321{
1322 int i = 0;
1323
1324 i += scnprintf(buf + i, max - i,
Eric Holmberg9fdef262012-02-14 11:46:05 -07001325 "skb read cnt: %u\n"
1326 "skb write cnt: %u\n"
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07001327 "skb copy cnt: %u\n"
1328 "skb copy bytes: %u\n"
Eric Holmberg6074aba2012-01-18 17:59:44 -07001329 "sps tx failures: %u\n"
Eric Holmbergb5b08e52012-01-20 14:19:00 -07001330 "sps tx stalls: %u\n"
Eric Holmberg1f1255d2012-02-22 13:37:21 -07001331 "rx queue len: %d\n"
1332 "a2 ack out cnt: %d\n"
1333 "a2 ack in cnt: %d\n"
1334 "a2 pwr cntl in: %d\n",
Eric Holmberg9fdef262012-02-14 11:46:05 -07001335 bam_dmux_read_cnt,
1336 bam_dmux_write_cnt,
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07001337 bam_dmux_write_cpy_cnt,
1338 bam_dmux_write_cpy_bytes,
Eric Holmberg6074aba2012-01-18 17:59:44 -07001339 bam_dmux_tx_sps_failure_cnt,
Eric Holmbergb5b08e52012-01-20 14:19:00 -07001340 bam_dmux_tx_stall_cnt,
Eric Holmberg1f1255d2012-02-22 13:37:21 -07001341 bam_rx_pool_len,
1342 atomic_read(&bam_dmux_ack_out_cnt),
1343 atomic_read(&bam_dmux_ack_in_cnt),
1344 atomic_read(&bam_dmux_a2_pwr_cntl_in_cnt)
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07001345 );
1346
1347 return i;
1348}
1349
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001350#define DEBUG_BUFMAX 4096
1351static char debug_buffer[DEBUG_BUFMAX];
1352
1353static ssize_t debug_read(struct file *file, char __user *buf,
1354 size_t count, loff_t *ppos)
1355{
1356 int (*fill)(char *buf, int max) = file->private_data;
1357 int bsize = fill(debug_buffer, DEBUG_BUFMAX);
1358 return simple_read_from_buffer(buf, count, ppos, debug_buffer, bsize);
1359}
1360
1361static int debug_open(struct inode *inode, struct file *file)
1362{
1363 file->private_data = inode->i_private;
1364 return 0;
1365}
1366
1367
1368static const struct file_operations debug_ops = {
1369 .read = debug_read,
1370 .open = debug_open,
1371};
1372
1373static void debug_create(const char *name, mode_t mode,
1374 struct dentry *dent,
1375 int (*fill)(char *buf, int max))
1376{
Eric Holmberge4ac80b2012-01-12 09:21:59 -07001377 struct dentry *file;
1378
1379 file = debugfs_create_file(name, mode, dent, fill, &debug_ops);
1380 if (IS_ERR(file))
1381 pr_err("%s: debugfs create failed %d\n", __func__,
1382 (int)PTR_ERR(file));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001383}
1384
1385#endif
1386
Jeff Hugod98b1082011-10-24 10:30:23 -06001387static void notify_all(int event, unsigned long data)
1388{
1389 int i;
Jeff Hugocb798022012-04-09 14:55:40 -06001390 struct list_head *temp;
1391 struct outside_notify_func *func;
Jeff Hugod98b1082011-10-24 10:30:23 -06001392
Jeff Hugoac8152a2013-04-19 11:05:19 -06001393 BAM_DMUX_LOG("%s: event=%d, data=%lu\n", __func__, event, data);
1394
Jeff Hugod98b1082011-10-24 10:30:23 -06001395 for (i = 0; i < BAM_DMUX_NUM_CHANNELS; ++i) {
Jeff Hugoac8152a2013-04-19 11:05:19 -06001396 if (bam_ch_is_open(i))
Jeff Hugod98b1082011-10-24 10:30:23 -06001397 bam_ch[i].notify(bam_ch[i].priv, event, data);
1398 }
Jeff Hugocb798022012-04-09 14:55:40 -06001399
1400 __list_for_each(temp, &bam_other_notify_funcs) {
1401 func = container_of(temp, struct outside_notify_func,
1402 list_node);
1403 func->notify(func->priv, event, data);
1404 }
Jeff Hugod98b1082011-10-24 10:30:23 -06001405}
1406
1407static void kickoff_ul_wakeup_func(struct work_struct *work)
1408{
1409 read_lock(&ul_wakeup_lock);
1410 if (!bam_is_connected) {
1411 read_unlock(&ul_wakeup_lock);
1412 ul_wakeup();
Jeff Hugo4838f412012-01-20 11:19:37 -07001413 if (unlikely(in_global_reset == 1))
1414 return;
Jeff Hugod98b1082011-10-24 10:30:23 -06001415 read_lock(&ul_wakeup_lock);
1416 ul_packet_written = 1;
1417 notify_all(BAM_DMUX_UL_CONNECTED, (unsigned long)(NULL));
1418 }
1419 read_unlock(&ul_wakeup_lock);
1420}
1421
Eric Holmbergbc9f21c2012-01-18 11:33:33 -07001422int msm_bam_dmux_kickoff_ul_wakeup(void)
Jeff Hugod98b1082011-10-24 10:30:23 -06001423{
Eric Holmbergbc9f21c2012-01-18 11:33:33 -07001424 int is_connected;
1425
1426 read_lock(&ul_wakeup_lock);
1427 ul_packet_written = 1;
1428 is_connected = bam_is_connected;
1429 if (!is_connected)
1430 queue_work(bam_mux_tx_workqueue, &kickoff_ul_wakeup);
1431 read_unlock(&ul_wakeup_lock);
1432
1433 return is_connected;
Jeff Hugod98b1082011-10-24 10:30:23 -06001434}
1435
Eric Holmberg878923a2012-01-10 14:28:19 -07001436static void power_vote(int vote)
1437{
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301438 BAM_DMUX_LOG("%s: curr=%d, vote=%d\n", __func__,
Eric Holmberg878923a2012-01-10 14:28:19 -07001439 bam_dmux_uplink_vote, vote);
1440
1441 if (bam_dmux_uplink_vote == vote)
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301442 BAM_DMUX_LOG("%s: warning - duplicate power vote\n", __func__);
Eric Holmberg878923a2012-01-10 14:28:19 -07001443
1444 bam_dmux_uplink_vote = vote;
1445 if (vote)
1446 smsm_change_state(SMSM_APPS_STATE, 0, SMSM_A2_POWER_CONTROL);
1447 else
1448 smsm_change_state(SMSM_APPS_STATE, SMSM_A2_POWER_CONTROL, 0);
1449}
1450
Eric Holmberg454d9da2012-01-12 09:37:14 -07001451/*
1452 * @note: Must be called with ul_wakeup_lock locked.
1453 */
1454static inline void ul_powerdown(void)
1455{
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301456 BAM_DMUX_LOG("%s: powerdown\n", __func__);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001457 verify_tx_queue_is_empty(__func__);
1458
1459 if (a2_pc_disabled) {
1460 wait_for_dfab = 1;
1461 INIT_COMPLETION(dfab_unvote_completion);
1462 release_wakelock();
1463 } else {
1464 wait_for_ack = 1;
1465 INIT_COMPLETION(ul_wakeup_ack_completion);
1466 power_vote(0);
1467 }
1468 bam_is_connected = 0;
1469 notify_all(BAM_DMUX_UL_DISCONNECTED, (unsigned long)(NULL));
1470}
1471
1472static inline void ul_powerdown_finish(void)
1473{
1474 if (a2_pc_disabled && wait_for_dfab) {
1475 unvote_dfab();
1476 complete_all(&dfab_unvote_completion);
1477 wait_for_dfab = 0;
1478 }
1479}
1480
Eric Holmbergbc9f21c2012-01-18 11:33:33 -07001481/*
1482 * Votes for UL power and returns current power state.
1483 *
1484 * @returns true if currently connected
1485 */
1486int msm_bam_dmux_ul_power_vote(void)
1487{
1488 int is_connected;
1489
1490 read_lock(&ul_wakeup_lock);
1491 atomic_inc(&ul_ondemand_vote);
1492 is_connected = bam_is_connected;
1493 if (!is_connected)
1494 queue_work(bam_mux_tx_workqueue, &kickoff_ul_wakeup);
1495 read_unlock(&ul_wakeup_lock);
1496
1497 return is_connected;
1498}
1499
1500/*
1501 * Unvotes for UL power.
1502 *
1503 * @returns true if vote count is 0 (UL shutdown possible)
1504 */
1505int msm_bam_dmux_ul_power_unvote(void)
1506{
1507 int vote;
1508
1509 read_lock(&ul_wakeup_lock);
1510 vote = atomic_dec_return(&ul_ondemand_vote);
1511 if (unlikely(vote) < 0)
1512 DMUX_LOG_KERR("%s: invalid power vote %d\n", __func__, vote);
1513 read_unlock(&ul_wakeup_lock);
1514
1515 return vote == 0;
1516}
1517
Jeff Hugocb798022012-04-09 14:55:40 -06001518int msm_bam_dmux_reg_notify(void *priv,
1519 void (*notify)(void *priv, int event_type,
1520 unsigned long data))
1521{
1522 struct outside_notify_func *func;
1523
1524 if (!notify)
1525 return -EINVAL;
1526
1527 func = kmalloc(sizeof(struct outside_notify_func), GFP_KERNEL);
1528 if (!func)
1529 return -ENOMEM;
1530
1531 func->notify = notify;
1532 func->priv = priv;
1533 list_add(&func->list_node, &bam_other_notify_funcs);
1534
1535 return 0;
1536}
1537
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001538static void ul_timeout(struct work_struct *work)
1539{
Jeff Hugoc040a5b2011-11-15 14:26:01 -07001540 unsigned long flags;
1541 int ret;
1542
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001543 if (in_global_reset)
1544 return;
Jeff Hugoc040a5b2011-11-15 14:26:01 -07001545 ret = write_trylock_irqsave(&ul_wakeup_lock, flags);
1546 if (!ret) { /* failed to grab lock, reschedule and bail */
1547 schedule_delayed_work(&ul_timeout_work,
1548 msecs_to_jiffies(UL_TIMEOUT_DELAY));
1549 return;
1550 }
Eric Holmberg454d9da2012-01-12 09:37:14 -07001551 if (bam_is_connected) {
Eric Holmberg6074aba2012-01-18 17:59:44 -07001552 if (!ul_packet_written) {
1553 spin_lock(&bam_tx_pool_spinlock);
1554 if (!list_empty(&bam_tx_pool)) {
1555 struct tx_pkt_info *info;
1556
1557 info = list_first_entry(&bam_tx_pool,
1558 struct tx_pkt_info, list_node);
1559 DMUX_LOG_KERR("%s: UL delayed ts=%u.%09lu\n",
1560 __func__, info->ts_sec, info->ts_nsec);
1561 DBG_INC_TX_STALL_CNT();
1562 ul_packet_written = 1;
1563 }
1564 spin_unlock(&bam_tx_pool_spinlock);
1565 }
1566
Eric Holmbergbc9f21c2012-01-18 11:33:33 -07001567 if (ul_packet_written || atomic_read(&ul_ondemand_vote)) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301568 BAM_DMUX_LOG("%s: pkt written %d\n",
Eric Holmbergbc9f21c2012-01-18 11:33:33 -07001569 __func__, ul_packet_written);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001570 ul_packet_written = 0;
1571 schedule_delayed_work(&ul_timeout_work,
1572 msecs_to_jiffies(UL_TIMEOUT_DELAY));
Eric Holmberg006057d2012-01-11 10:10:42 -07001573 } else {
Eric Holmberg454d9da2012-01-12 09:37:14 -07001574 ul_powerdown();
Eric Holmberg006057d2012-01-11 10:10:42 -07001575 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001576 }
Jeff Hugoc040a5b2011-11-15 14:26:01 -07001577 write_unlock_irqrestore(&ul_wakeup_lock, flags);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001578 ul_powerdown_finish();
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001579}
Jeff Hugo4838f412012-01-20 11:19:37 -07001580
1581static int ssrestart_check(void)
1582{
Jeff Hugob8156d72013-06-04 12:51:10 -06001583 int ret = 0;
1584
1585 DMUX_LOG_KERR("%s: modem timeout: BAM DMUX disabled for SSR\n",
1586 __func__);
Eric Holmberg90285e22012-02-22 12:33:05 -07001587 in_global_reset = 1;
Jeff Hugob8156d72013-06-04 12:51:10 -06001588 ret = subsystem_restart("modem");
1589 if (ret == -ENODEV)
1590 panic("modem subsystem restart failed\n");
Eric Holmberg90285e22012-02-22 12:33:05 -07001591 return 1;
Jeff Hugo4838f412012-01-20 11:19:37 -07001592}
1593
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001594static void ul_wakeup(void)
1595{
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001596 int ret;
Jeff Hugo5f57ec92012-05-14 13:34:28 -06001597 int do_vote_dfab = 0;
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001598
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001599 mutex_lock(&wakeup_lock);
1600 if (bam_is_connected) { /* bam got connected before lock grabbed */
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301601 BAM_DMUX_LOG("%s Already awake\n", __func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001602 mutex_unlock(&wakeup_lock);
1603 return;
1604 }
Eric Holmberg878923a2012-01-10 14:28:19 -07001605
Jeff Hugoc2696142012-05-03 11:42:13 -06001606 /*
Jeff Hugof5001732012-08-27 13:19:09 -06001607 * if this gets hit, that means restart_notifier_cb() has started
1608 * but probably not finished, thus we know SSR has happened, but
1609 * haven't been able to send that info to our clients yet.
1610 * in that case, abort the ul_wakeup() so that we don't undo any
1611 * work restart_notifier_cb() has done. The clients will be notified
1612 * shortly. No cleanup necessary (reschedule the wakeup) as our and
1613 * their SSR handling will cover it
1614 */
1615 if (unlikely(in_global_reset == 1)) {
1616 mutex_unlock(&wakeup_lock);
1617 return;
1618 }
1619
1620 /*
Jeff Hugoc2696142012-05-03 11:42:13 -06001621 * if someone is voting for UL before bam is inited (modem up first
1622 * time), set flag for init to kickoff ul wakeup once bam is inited
1623 */
1624 mutex_lock(&delayed_ul_vote_lock);
1625 if (unlikely(!bam_mux_initialized)) {
1626 need_delayed_ul_vote = 1;
1627 mutex_unlock(&delayed_ul_vote_lock);
1628 mutex_unlock(&wakeup_lock);
1629 return;
1630 }
1631 mutex_unlock(&delayed_ul_vote_lock);
1632
Eric Holmberg006057d2012-01-11 10:10:42 -07001633 if (a2_pc_disabled) {
1634 /*
1635 * don't grab the wakelock the first time because it is
1636 * already grabbed when a2 powers on
1637 */
Jeff Hugo5f57ec92012-05-14 13:34:28 -06001638 if (likely(a2_pc_disabled_wakelock_skipped)) {
Eric Holmberg006057d2012-01-11 10:10:42 -07001639 grab_wakelock();
Jeff Hugo5f57ec92012-05-14 13:34:28 -06001640 do_vote_dfab = 1; /* vote must occur after wait */
1641 } else {
Jeff Hugo583a6da2012-02-03 11:37:30 -07001642 a2_pc_disabled_wakelock_skipped = 1;
Jeff Hugo5f57ec92012-05-14 13:34:28 -06001643 }
Eric Holmberg006057d2012-01-11 10:10:42 -07001644 if (wait_for_dfab) {
Jeff Hugo66f7f1e2012-01-16 14:30:42 -07001645 ret = wait_for_completion_timeout(
Eric Holmberg006057d2012-01-11 10:10:42 -07001646 &dfab_unvote_completion, HZ);
1647 BUG_ON(ret == 0);
1648 }
Jeff Hugo5f57ec92012-05-14 13:34:28 -06001649 if (likely(do_vote_dfab))
1650 vote_dfab();
Eric Holmberg006057d2012-01-11 10:10:42 -07001651 schedule_delayed_work(&ul_timeout_work,
1652 msecs_to_jiffies(UL_TIMEOUT_DELAY));
1653 bam_is_connected = 1;
1654 mutex_unlock(&wakeup_lock);
1655 return;
1656 }
1657
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001658 /*
1659 * must wait for the previous power down request to have been acked
1660 * chances are it already came in and this will just fall through
1661 * instead of waiting
1662 */
1663 if (wait_for_ack) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301664 BAM_DMUX_LOG("%s waiting for previous ack\n", __func__);
Jeff Hugo66f7f1e2012-01-16 14:30:42 -07001665 ret = wait_for_completion_timeout(
Jeff Hugo1f317392013-07-24 16:28:52 -06001666 &ul_wakeup_ack_completion,
1667 msecs_to_jiffies(UL_WAKEUP_TIMEOUT_MS));
Eric Holmberg006057d2012-01-11 10:10:42 -07001668 wait_for_ack = 0;
Jeff Hugo4838f412012-01-20 11:19:37 -07001669 if (unlikely(ret == 0) && ssrestart_check()) {
1670 mutex_unlock(&wakeup_lock);
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301671 BAM_DMUX_LOG("%s timeout previous ack\n", __func__);
Jeff Hugo4838f412012-01-20 11:19:37 -07001672 return;
1673 }
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001674 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001675 INIT_COMPLETION(ul_wakeup_ack_completion);
Eric Holmberg878923a2012-01-10 14:28:19 -07001676 power_vote(1);
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301677 BAM_DMUX_LOG("%s waiting for wakeup ack\n", __func__);
Jeff Hugo1f317392013-07-24 16:28:52 -06001678 ret = wait_for_completion_timeout(&ul_wakeup_ack_completion,
1679 msecs_to_jiffies(UL_WAKEUP_TIMEOUT_MS));
Jeff Hugo4838f412012-01-20 11:19:37 -07001680 if (unlikely(ret == 0) && ssrestart_check()) {
1681 mutex_unlock(&wakeup_lock);
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301682 BAM_DMUX_LOG("%s timeout wakeup ack\n", __func__);
Jeff Hugo4838f412012-01-20 11:19:37 -07001683 return;
1684 }
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301685 BAM_DMUX_LOG("%s waiting completion\n", __func__);
Jeff Hugo1f317392013-07-24 16:28:52 -06001686 ret = wait_for_completion_timeout(&bam_connection_completion,
1687 msecs_to_jiffies(UL_WAKEUP_TIMEOUT_MS));
Jeff Hugo4838f412012-01-20 11:19:37 -07001688 if (unlikely(ret == 0) && ssrestart_check()) {
1689 mutex_unlock(&wakeup_lock);
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301690 BAM_DMUX_LOG("%s timeout power on\n", __func__);
Jeff Hugo4838f412012-01-20 11:19:37 -07001691 return;
1692 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001693
1694 bam_is_connected = 1;
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301695 BAM_DMUX_LOG("%s complete\n", __func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001696 schedule_delayed_work(&ul_timeout_work,
1697 msecs_to_jiffies(UL_TIMEOUT_DELAY));
1698 mutex_unlock(&wakeup_lock);
1699}
1700
1701static void reconnect_to_bam(void)
1702{
1703 int i;
1704
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001705 in_global_reset = 0;
Jeff Hugoa82a95c2012-12-14 17:56:19 -07001706 in_ssr = 0;
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001707 vote_dfab();
Jeff Hugo18792a32012-06-20 15:25:55 -06001708 if (!power_management_only_mode) {
Jeff Hugoa82a95c2012-12-14 17:56:19 -07001709 if (ssr_skipped_disconnect) {
1710 /* delayed to here to prevent bus stall */
1711 sps_disconnect(bam_tx_pipe);
1712 sps_disconnect(bam_rx_pipe);
1713 __memzero(rx_desc_mem_buf.base, rx_desc_mem_buf.size);
1714 __memzero(tx_desc_mem_buf.base, tx_desc_mem_buf.size);
1715 }
1716 ssr_skipped_disconnect = 0;
Jeff Hugo18792a32012-06-20 15:25:55 -06001717 i = sps_device_reset(a2_device_handle);
1718 if (i)
1719 pr_err("%s: device reset failed rc = %d\n", __func__,
1720 i);
1721 i = sps_connect(bam_tx_pipe, &tx_connection);
1722 if (i)
1723 pr_err("%s: tx connection failed rc = %d\n", __func__,
1724 i);
1725 i = sps_connect(bam_rx_pipe, &rx_connection);
1726 if (i)
1727 pr_err("%s: rx connection failed rc = %d\n", __func__,
1728 i);
1729 i = sps_register_event(bam_tx_pipe, &tx_register_event);
1730 if (i)
1731 pr_err("%s: tx event reg failed rc = %d\n", __func__,
1732 i);
1733 i = sps_register_event(bam_rx_pipe, &rx_register_event);
1734 if (i)
1735 pr_err("%s: rx event reg failed rc = %d\n", __func__,
1736 i);
1737 }
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001738
1739 bam_connection_is_active = 1;
1740
1741 if (polling_mode)
1742 rx_switch_to_interrupt_mode();
1743
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001744 toggle_apps_ack();
1745 complete_all(&bam_connection_completion);
Jeff Hugo18792a32012-06-20 15:25:55 -06001746 if (!power_management_only_mode)
1747 queue_rx();
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001748}
1749
1750static void disconnect_to_bam(void)
1751{
1752 struct list_head *node;
1753 struct rx_pkt_info *info;
Eric Holmberg454d9da2012-01-12 09:37:14 -07001754 unsigned long flags;
Brent Hronik096f7d32013-06-28 15:43:08 -06001755 unsigned long time_remaining;
1756
1757 time_remaining = wait_for_completion_timeout(&shutdown_completion,
1758 msecs_to_jiffies(SHUTDOWN_TIMEOUT_MS));
1759 if (time_remaining == 0) {
1760 pr_err("%s: shutdown completion timed out\n", __func__);
1761 ssrestart_check();
1762 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001763
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001764 bam_connection_is_active = 0;
Eric Holmberg454d9da2012-01-12 09:37:14 -07001765
1766 /* handle disconnect during active UL */
1767 write_lock_irqsave(&ul_wakeup_lock, flags);
1768 if (bam_is_connected) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301769 BAM_DMUX_LOG("%s: UL active - forcing powerdown\n", __func__);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001770 ul_powerdown();
1771 }
1772 write_unlock_irqrestore(&ul_wakeup_lock, flags);
1773 ul_powerdown_finish();
1774
1775 /* tear down BAM connection */
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001776 INIT_COMPLETION(bam_connection_completion);
Jeff Hugoa82a95c2012-12-14 17:56:19 -07001777
1778 /* in_ssr documentation/assumptions found in restart_notifier_cb */
Jeff Hugo18792a32012-06-20 15:25:55 -06001779 if (!power_management_only_mode) {
Jeff Hugoa82a95c2012-12-14 17:56:19 -07001780 if (likely(!in_ssr)) {
Jeff Hugof7ae7a62013-04-19 11:18:32 -06001781 BAM_DMUX_LOG("%s: disconnect tx\n", __func__);
Jeff Hugoa82a95c2012-12-14 17:56:19 -07001782 sps_disconnect(bam_tx_pipe);
Jeff Hugof7ae7a62013-04-19 11:18:32 -06001783 BAM_DMUX_LOG("%s: disconnect rx\n", __func__);
Jeff Hugoa82a95c2012-12-14 17:56:19 -07001784 sps_disconnect(bam_rx_pipe);
1785 __memzero(rx_desc_mem_buf.base, rx_desc_mem_buf.size);
1786 __memzero(tx_desc_mem_buf.base, tx_desc_mem_buf.size);
Jeff Hugof7ae7a62013-04-19 11:18:32 -06001787 BAM_DMUX_LOG("%s: device reset\n", __func__);
Jeff Hugoa82a95c2012-12-14 17:56:19 -07001788 sps_device_reset(a2_device_handle);
1789 } else {
1790 ssr_skipped_disconnect = 1;
1791 }
Jeff Hugo18792a32012-06-20 15:25:55 -06001792 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001793 unvote_dfab();
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001794
1795 mutex_lock(&bam_rx_pool_mutexlock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001796 while (!list_empty(&bam_rx_pool)) {
1797 node = bam_rx_pool.next;
1798 list_del(node);
1799 info = container_of(node, struct rx_pkt_info, list_node);
1800 dma_unmap_single(NULL, info->dma_address, BUFFER_SIZE,
1801 DMA_FROM_DEVICE);
1802 dev_kfree_skb_any(info->skb);
1803 kfree(info);
1804 }
Eric Holmbergb5b08e52012-01-20 14:19:00 -07001805 bam_rx_pool_len = 0;
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001806 mutex_unlock(&bam_rx_pool_mutexlock);
Eric Holmberg878923a2012-01-10 14:28:19 -07001807
Jeff Hugo0b13a352012-03-17 23:18:30 -06001808 if (disconnect_ack)
1809 toggle_apps_ack();
1810
Eric Holmberg878923a2012-01-10 14:28:19 -07001811 verify_tx_queue_is_empty(__func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001812}
1813
1814static void vote_dfab(void)
1815{
Jeff Hugoca0caa82011-12-05 16:05:23 -07001816 int rc;
1817
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301818 BAM_DMUX_LOG("%s\n", __func__);
Eric Holmberg006057d2012-01-11 10:10:42 -07001819 mutex_lock(&dfab_status_lock);
1820 if (dfab_is_on) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301821 BAM_DMUX_LOG("%s: dfab is already on\n", __func__);
Eric Holmberg006057d2012-01-11 10:10:42 -07001822 mutex_unlock(&dfab_status_lock);
1823 return;
1824 }
Jeff Hugod0befde2012-08-09 15:32:49 -06001825 if (dfab_clk) {
1826 rc = clk_prepare_enable(dfab_clk);
1827 if (rc)
1828 DMUX_LOG_KERR("bam_dmux vote for dfab failed rc = %d\n",
1829 rc);
1830 }
1831 if (xo_clk) {
1832 rc = clk_prepare_enable(xo_clk);
1833 if (rc)
1834 DMUX_LOG_KERR("bam_dmux vote for xo failed rc = %d\n",
1835 rc);
1836 }
Eric Holmberg006057d2012-01-11 10:10:42 -07001837 dfab_is_on = 1;
1838 mutex_unlock(&dfab_status_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001839}
1840
1841static void unvote_dfab(void)
1842{
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301843 BAM_DMUX_LOG("%s\n", __func__);
Eric Holmberg006057d2012-01-11 10:10:42 -07001844 mutex_lock(&dfab_status_lock);
1845 if (!dfab_is_on) {
1846 DMUX_LOG_KERR("%s: dfab is already off\n", __func__);
1847 dump_stack();
1848 mutex_unlock(&dfab_status_lock);
1849 return;
1850 }
Jeff Hugod0befde2012-08-09 15:32:49 -06001851 if (dfab_clk)
1852 clk_disable_unprepare(dfab_clk);
1853 if (xo_clk)
1854 clk_disable_unprepare(xo_clk);
Eric Holmberg006057d2012-01-11 10:10:42 -07001855 dfab_is_on = 0;
1856 mutex_unlock(&dfab_status_lock);
1857}
1858
1859/* reference counting wrapper around wakelock */
1860static void grab_wakelock(void)
1861{
1862 unsigned long flags;
1863
1864 spin_lock_irqsave(&wakelock_reference_lock, flags);
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301865 BAM_DMUX_LOG("%s: ref count = %d\n", __func__,
Eric Holmberg006057d2012-01-11 10:10:42 -07001866 wakelock_reference_count);
1867 if (wakelock_reference_count == 0)
1868 wake_lock(&bam_wakelock);
1869 ++wakelock_reference_count;
1870 spin_unlock_irqrestore(&wakelock_reference_lock, flags);
1871}
1872
1873static void release_wakelock(void)
1874{
1875 unsigned long flags;
1876
1877 spin_lock_irqsave(&wakelock_reference_lock, flags);
1878 if (wakelock_reference_count == 0) {
1879 DMUX_LOG_KERR("%s: bam_dmux wakelock not locked\n", __func__);
1880 dump_stack();
1881 spin_unlock_irqrestore(&wakelock_reference_lock, flags);
1882 return;
1883 }
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301884 BAM_DMUX_LOG("%s: ref count = %d\n", __func__,
Eric Holmberg006057d2012-01-11 10:10:42 -07001885 wakelock_reference_count);
1886 --wakelock_reference_count;
1887 if (wakelock_reference_count == 0)
1888 wake_unlock(&bam_wakelock);
1889 spin_unlock_irqrestore(&wakelock_reference_lock, flags);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001890}
1891
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001892static int restart_notifier_cb(struct notifier_block *this,
1893 unsigned long code,
1894 void *data)
1895{
1896 int i;
1897 struct list_head *node;
1898 struct tx_pkt_info *info;
1899 int temp_remote_status;
Jeff Hugo626303bf2011-11-21 11:43:28 -07001900 unsigned long flags;
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001901
Jeff Hugoa82a95c2012-12-14 17:56:19 -07001902 /*
1903 * Bam_dmux counts on the fact that the BEFORE_SHUTDOWN level of
1904 * notifications are guarenteed to execute before the AFTER_SHUTDOWN
1905 * level of notifications, and that BEFORE_SHUTDOWN always occurs in
1906 * all SSR events, no matter what triggered the SSR. Also, bam_dmux
1907 * assumes that SMD does its SSR processing in the AFTER_SHUTDOWN level
1908 * thus bam_dmux is guarenteed to detect SSR before SMD, since the
1909 * callbacks for all the drivers within the AFTER_SHUTDOWN level could
1910 * occur in any order. Bam_dmux uses this knowledge to skip accessing
1911 * the bam hardware when disconnect_to_bam() is triggered by SMD's SSR
1912 * processing. We do not wat to access the bam hardware during SSR
1913 * because a watchdog crash from a bus stall would likely occur.
1914 */
Jeff Hugo199294b2013-02-25 13:46:56 -07001915 if (code == SUBSYS_BEFORE_SHUTDOWN) {
1916 in_global_reset = 1;
Jeff Hugoa82a95c2012-12-14 17:56:19 -07001917 in_ssr = 1;
Zaheerulla Meerf800bba2013-02-13 15:49:14 +05301918 BAM_DMUX_LOG("%s: begin\n", __func__);
Jeff Hugo199294b2013-02-25 13:46:56 -07001919 flush_workqueue(bam_mux_rx_workqueue);
1920 }
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001921 if (code != SUBSYS_AFTER_SHUTDOWN)
1922 return NOTIFY_DONE;
1923
Eric Holmberg454d9da2012-01-12 09:37:14 -07001924 /* Handle uplink Powerdown */
1925 write_lock_irqsave(&ul_wakeup_lock, flags);
1926 if (bam_is_connected) {
1927 ul_powerdown();
1928 wait_for_ack = 0;
1929 }
Jeff Hugo4838f412012-01-20 11:19:37 -07001930 /*
1931 * if modem crash during ul_wakeup(), power_vote is 1, needs to be
1932 * reset to 0. harmless if bam_is_connected check above passes
1933 */
1934 power_vote(0);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001935 write_unlock_irqrestore(&ul_wakeup_lock, flags);
1936 ul_powerdown_finish();
Eric Holmberg006057d2012-01-11 10:10:42 -07001937 a2_pc_disabled = 0;
Jeff Hugo583a6da2012-02-03 11:37:30 -07001938 a2_pc_disabled_wakelock_skipped = 0;
Jeff Hugof62029d2012-07-17 13:39:53 -06001939 disconnect_ack = 1;
Eric Holmberg454d9da2012-01-12 09:37:14 -07001940
1941 /* Cleanup Channel States */
Eric Holmberga623da82012-07-12 09:37:09 -06001942 mutex_lock(&bam_pdev_mutexlock);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001943 for (i = 0; i < BAM_DMUX_NUM_CHANNELS; ++i) {
1944 temp_remote_status = bam_ch_is_remote_open(i);
1945 bam_ch[i].status &= ~BAM_CH_REMOTE_OPEN;
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -07001946 bam_ch[i].num_tx_pkts = 0;
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001947 if (bam_ch_is_local_open(i))
1948 bam_ch[i].status |= BAM_CH_IN_RESET;
1949 if (temp_remote_status) {
1950 platform_device_unregister(bam_ch[i].pdev);
1951 bam_ch[i].pdev = platform_device_alloc(
1952 bam_ch[i].name, 2);
1953 }
1954 }
Eric Holmberga623da82012-07-12 09:37:09 -06001955 mutex_unlock(&bam_pdev_mutexlock);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001956
1957 /* Cleanup pending UL data */
Jeff Hugo626303bf2011-11-21 11:43:28 -07001958 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001959 while (!list_empty(&bam_tx_pool)) {
1960 node = bam_tx_pool.next;
1961 list_del(node);
1962 info = container_of(node, struct tx_pkt_info,
1963 list_node);
1964 if (!info->is_cmd) {
1965 dma_unmap_single(NULL, info->dma_address,
1966 info->skb->len,
1967 DMA_TO_DEVICE);
1968 dev_kfree_skb_any(info->skb);
1969 } else {
1970 dma_unmap_single(NULL, info->dma_address,
1971 info->len,
1972 DMA_TO_DEVICE);
1973 kfree(info->skb);
1974 }
1975 kfree(info);
1976 }
Jeff Hugo626303bf2011-11-21 11:43:28 -07001977 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001978
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301979 BAM_DMUX_LOG("%s: complete\n", __func__);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001980 return NOTIFY_DONE;
1981}
1982
Jeff Hugo9dea05c2011-12-21 12:23:05 -07001983static int bam_init(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001984{
1985 u32 h;
1986 dma_addr_t dma_addr;
1987 int ret;
1988 void *a2_virt_addr;
Jeff Hugo4b2890d2012-01-16 16:14:21 -07001989 int skip_iounmap = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001990
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001991 vote_dfab();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001992 /* init BAM */
Jeff Hugo3910ee12012-08-21 14:08:20 -06001993 a2_virt_addr = ioremap_nocache((unsigned long)(a2_phys_base),
1994 a2_phys_size);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001995 if (!a2_virt_addr) {
1996 pr_err("%s: ioremap failed\n", __func__);
1997 ret = -ENOMEM;
Jeff Hugo994a92d2012-01-05 13:25:21 -07001998 goto ioremap_failed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001999 }
Jeff Hugo3910ee12012-08-21 14:08:20 -06002000 a2_props.phys_addr = (u32)(a2_phys_base);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002001 a2_props.virt_addr = a2_virt_addr;
Jeff Hugo3910ee12012-08-21 14:08:20 -06002002 a2_props.virt_size = a2_phys_size;
2003 a2_props.irq = a2_bam_irq;
Jeff Hugo927cba62011-11-11 11:49:52 -07002004 a2_props.options = SPS_BAM_OPT_IRQ_WAKEUP;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002005 a2_props.num_pipes = A2_NUM_PIPES;
2006 a2_props.summing_threshold = A2_SUMMING_THRESHOLD;
Jeff Hugo75913c82011-12-05 15:59:01 -07002007 if (cpu_is_msm9615())
2008 a2_props.manage = SPS_BAM_MGR_DEVICE_REMOTE;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002009 /* need to free on tear down */
2010 ret = sps_register_bam_device(&a2_props, &h);
2011 if (ret < 0) {
2012 pr_err("%s: register bam error %d\n", __func__, ret);
2013 goto register_bam_failed;
2014 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002015 a2_device_handle = h;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002016
2017 bam_tx_pipe = sps_alloc_endpoint();
2018 if (bam_tx_pipe == NULL) {
2019 pr_err("%s: tx alloc endpoint failed\n", __func__);
2020 ret = -ENOMEM;
Jeff Hugo8ff4a812012-01-17 11:03:13 -07002021 goto tx_alloc_endpoint_failed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002022 }
2023 ret = sps_get_config(bam_tx_pipe, &tx_connection);
2024 if (ret) {
2025 pr_err("%s: tx get config failed %d\n", __func__, ret);
2026 goto tx_get_config_failed;
2027 }
2028
2029 tx_connection.source = SPS_DEV_HANDLE_MEM;
2030 tx_connection.src_pipe_index = 0;
2031 tx_connection.destination = h;
2032 tx_connection.dest_pipe_index = 4;
2033 tx_connection.mode = SPS_MODE_DEST;
2034 tx_connection.options = SPS_O_AUTO_ENABLE | SPS_O_EOT;
2035 tx_desc_mem_buf.size = 0x800; /* 2k */
2036 tx_desc_mem_buf.base = dma_alloc_coherent(NULL, tx_desc_mem_buf.size,
2037 &dma_addr, 0);
2038 if (tx_desc_mem_buf.base == NULL) {
2039 pr_err("%s: tx memory alloc failed\n", __func__);
2040 ret = -ENOMEM;
Jeff Hugo8ff4a812012-01-17 11:03:13 -07002041 goto tx_get_config_failed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002042 }
2043 tx_desc_mem_buf.phys_base = dma_addr;
2044 memset(tx_desc_mem_buf.base, 0x0, tx_desc_mem_buf.size);
2045 tx_connection.desc = tx_desc_mem_buf;
2046 tx_connection.event_thresh = 0x10;
2047
2048 ret = sps_connect(bam_tx_pipe, &tx_connection);
2049 if (ret < 0) {
2050 pr_err("%s: tx connect error %d\n", __func__, ret);
2051 goto tx_connect_failed;
2052 }
2053
2054 bam_rx_pipe = sps_alloc_endpoint();
2055 if (bam_rx_pipe == NULL) {
2056 pr_err("%s: rx alloc endpoint failed\n", __func__);
2057 ret = -ENOMEM;
Jeff Hugo8ff4a812012-01-17 11:03:13 -07002058 goto rx_alloc_endpoint_failed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002059 }
2060 ret = sps_get_config(bam_rx_pipe, &rx_connection);
2061 if (ret) {
2062 pr_err("%s: rx get config failed %d\n", __func__, ret);
2063 goto rx_get_config_failed;
2064 }
2065
2066 rx_connection.source = h;
2067 rx_connection.src_pipe_index = 5;
2068 rx_connection.destination = SPS_DEV_HANDLE_MEM;
2069 rx_connection.dest_pipe_index = 1;
2070 rx_connection.mode = SPS_MODE_SRC;
Jeff Hugo949080a2011-08-30 11:58:56 -06002071 rx_connection.options = SPS_O_AUTO_ENABLE | SPS_O_EOT |
2072 SPS_O_ACK_TRANSFERS;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002073 rx_desc_mem_buf.size = 0x800; /* 2k */
2074 rx_desc_mem_buf.base = dma_alloc_coherent(NULL, rx_desc_mem_buf.size,
2075 &dma_addr, 0);
2076 if (rx_desc_mem_buf.base == NULL) {
2077 pr_err("%s: rx memory alloc failed\n", __func__);
2078 ret = -ENOMEM;
2079 goto rx_mem_failed;
2080 }
2081 rx_desc_mem_buf.phys_base = dma_addr;
2082 memset(rx_desc_mem_buf.base, 0x0, rx_desc_mem_buf.size);
2083 rx_connection.desc = rx_desc_mem_buf;
2084 rx_connection.event_thresh = 0x10;
2085
2086 ret = sps_connect(bam_rx_pipe, &rx_connection);
2087 if (ret < 0) {
2088 pr_err("%s: rx connect error %d\n", __func__, ret);
2089 goto rx_connect_failed;
2090 }
2091
2092 tx_register_event.options = SPS_O_EOT;
2093 tx_register_event.mode = SPS_TRIGGER_CALLBACK;
2094 tx_register_event.xfer_done = NULL;
2095 tx_register_event.callback = bam_mux_tx_notify;
2096 tx_register_event.user = NULL;
2097 ret = sps_register_event(bam_tx_pipe, &tx_register_event);
2098 if (ret < 0) {
2099 pr_err("%s: tx register event error %d\n", __func__, ret);
2100 goto rx_event_reg_failed;
2101 }
2102
Jeff Hugo33dbc002011-08-25 15:52:53 -06002103 rx_register_event.options = SPS_O_EOT;
2104 rx_register_event.mode = SPS_TRIGGER_CALLBACK;
2105 rx_register_event.xfer_done = NULL;
2106 rx_register_event.callback = bam_mux_rx_notify;
2107 rx_register_event.user = NULL;
2108 ret = sps_register_event(bam_rx_pipe, &rx_register_event);
2109 if (ret < 0) {
2110 pr_err("%s: tx register event error %d\n", __func__, ret);
2111 goto rx_event_reg_failed;
2112 }
2113
Jeff Hugoc2696142012-05-03 11:42:13 -06002114 mutex_lock(&delayed_ul_vote_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002115 bam_mux_initialized = 1;
Jeff Hugoc2696142012-05-03 11:42:13 -06002116 if (need_delayed_ul_vote) {
2117 need_delayed_ul_vote = 0;
2118 msm_bam_dmux_kickoff_ul_wakeup();
2119 }
2120 mutex_unlock(&delayed_ul_vote_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002121 toggle_apps_ack();
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06002122 bam_connection_is_active = 1;
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002123 complete_all(&bam_connection_completion);
Jeff Hugo2fb555e2012-03-14 16:33:47 -06002124 queue_rx();
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002125 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002126
2127rx_event_reg_failed:
2128 sps_disconnect(bam_rx_pipe);
2129rx_connect_failed:
2130 dma_free_coherent(NULL, rx_desc_mem_buf.size, rx_desc_mem_buf.base,
2131 rx_desc_mem_buf.phys_base);
2132rx_mem_failed:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002133rx_get_config_failed:
2134 sps_free_endpoint(bam_rx_pipe);
Jeff Hugo8ff4a812012-01-17 11:03:13 -07002135rx_alloc_endpoint_failed:
2136 sps_disconnect(bam_tx_pipe);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002137tx_connect_failed:
2138 dma_free_coherent(NULL, tx_desc_mem_buf.size, tx_desc_mem_buf.base,
2139 tx_desc_mem_buf.phys_base);
2140tx_get_config_failed:
2141 sps_free_endpoint(bam_tx_pipe);
Jeff Hugo8ff4a812012-01-17 11:03:13 -07002142tx_alloc_endpoint_failed:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002143 sps_deregister_bam_device(h);
Jeff Hugo4b2890d2012-01-16 16:14:21 -07002144 /*
2145 * sps_deregister_bam_device() calls iounmap. calling iounmap on the
2146 * same handle below will cause a crash, so skip it if we've freed
2147 * the handle here.
2148 */
2149 skip_iounmap = 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002150register_bam_failed:
Jeff Hugo4b2890d2012-01-16 16:14:21 -07002151 if (!skip_iounmap)
2152 iounmap(a2_virt_addr);
Jeff Hugo994a92d2012-01-05 13:25:21 -07002153ioremap_failed:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002154 /*destroy_workqueue(bam_mux_workqueue);*/
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002155 return ret;
2156}
2157
2158static int bam_init_fallback(void)
2159{
2160 u32 h;
2161 int ret;
2162 void *a2_virt_addr;
2163
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002164 /* init BAM */
Jeff Hugo3910ee12012-08-21 14:08:20 -06002165 a2_virt_addr = ioremap_nocache((unsigned long)(a2_phys_base),
2166 a2_phys_size);
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002167 if (!a2_virt_addr) {
2168 pr_err("%s: ioremap failed\n", __func__);
2169 ret = -ENOMEM;
2170 goto ioremap_failed;
2171 }
Jeff Hugo3910ee12012-08-21 14:08:20 -06002172 a2_props.phys_addr = (u32)(a2_phys_base);
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002173 a2_props.virt_addr = a2_virt_addr;
Jeff Hugo3910ee12012-08-21 14:08:20 -06002174 a2_props.virt_size = a2_phys_size;
2175 a2_props.irq = a2_bam_irq;
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002176 a2_props.options = SPS_BAM_OPT_IRQ_WAKEUP;
2177 a2_props.num_pipes = A2_NUM_PIPES;
2178 a2_props.summing_threshold = A2_SUMMING_THRESHOLD;
2179 if (cpu_is_msm9615())
2180 a2_props.manage = SPS_BAM_MGR_DEVICE_REMOTE;
2181 ret = sps_register_bam_device(&a2_props, &h);
2182 if (ret < 0) {
2183 pr_err("%s: register bam error %d\n", __func__, ret);
2184 goto register_bam_failed;
2185 }
2186 a2_device_handle = h;
Jeff Hugoc2696142012-05-03 11:42:13 -06002187
2188 mutex_lock(&delayed_ul_vote_lock);
2189 bam_mux_initialized = 1;
2190 if (need_delayed_ul_vote) {
2191 need_delayed_ul_vote = 0;
2192 msm_bam_dmux_kickoff_ul_wakeup();
2193 }
2194 mutex_unlock(&delayed_ul_vote_lock);
Jeff Hugo2bec9772012-04-05 12:25:16 -06002195 toggle_apps_ack();
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002196
Jeff Hugo18792a32012-06-20 15:25:55 -06002197 power_management_only_mode = 1;
2198 bam_connection_is_active = 1;
2199 complete_all(&bam_connection_completion);
2200
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002201 return 0;
2202
2203register_bam_failed:
Jeff Hugo4b2890d2012-01-16 16:14:21 -07002204 iounmap(a2_virt_addr);
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002205ioremap_failed:
2206 return ret;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002207}
Jeff Hugoade1f842011-08-03 15:53:59 -06002208
Jeff Hugoa670b762012-03-15 15:58:28 -06002209static void msm9615_bam_init(void)
Eric Holmberg604ab252012-01-15 00:01:18 -07002210{
2211 int ret = 0;
2212
2213 ret = bam_init();
2214 if (ret) {
2215 ret = bam_init_fallback();
2216 if (ret)
2217 pr_err("%s: bam init fallback failed: %d",
2218 __func__, ret);
2219 }
2220}
2221
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002222static void toggle_apps_ack(void)
2223{
2224 static unsigned int clear_bit; /* 0 = set the bit, else clear bit */
Eric Holmberg878923a2012-01-10 14:28:19 -07002225
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302226 BAM_DMUX_LOG("%s: apps ack %d->%d\n", __func__,
Eric Holmberg878923a2012-01-10 14:28:19 -07002227 clear_bit & 0x1, ~clear_bit & 0x1);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002228 smsm_change_state(SMSM_APPS_STATE,
2229 clear_bit & SMSM_A2_POWER_CONTROL_ACK,
2230 ~clear_bit & SMSM_A2_POWER_CONTROL_ACK);
2231 clear_bit = ~clear_bit;
Eric Holmberg1f1255d2012-02-22 13:37:21 -07002232 DBG_INC_ACK_OUT_CNT();
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002233}
2234
Jeff Hugoade1f842011-08-03 15:53:59 -06002235static void bam_dmux_smsm_cb(void *priv, uint32_t old_state, uint32_t new_state)
2236{
Jeff Hugo4b7c7b32012-04-18 16:25:14 -06002237 static int last_processed_state;
2238
2239 mutex_lock(&smsm_cb_lock);
Eric Holmberg878923a2012-01-10 14:28:19 -07002240 bam_dmux_power_state = new_state & SMSM_A2_POWER_CONTROL ? 1 : 0;
Eric Holmberg1f1255d2012-02-22 13:37:21 -07002241 DBG_INC_A2_POWER_CONTROL_IN_CNT();
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302242 BAM_DMUX_LOG("%s: 0x%08x -> 0x%08x\n", __func__, old_state,
Eric Holmberg878923a2012-01-10 14:28:19 -07002243 new_state);
Jeff Hugo4b7c7b32012-04-18 16:25:14 -06002244 if (last_processed_state == (new_state & SMSM_A2_POWER_CONTROL)) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302245 BAM_DMUX_LOG("%s: already processed this state\n", __func__);
Jeff Hugo4b7c7b32012-04-18 16:25:14 -06002246 mutex_unlock(&smsm_cb_lock);
2247 return;
2248 }
2249
2250 last_processed_state = new_state & SMSM_A2_POWER_CONTROL;
Eric Holmberg878923a2012-01-10 14:28:19 -07002251
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002252 if (bam_mux_initialized && new_state & SMSM_A2_POWER_CONTROL) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302253 BAM_DMUX_LOG("%s: reconnect\n", __func__);
Eric Holmberg006057d2012-01-11 10:10:42 -07002254 grab_wakelock();
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002255 reconnect_to_bam();
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002256 } else if (bam_mux_initialized &&
2257 !(new_state & SMSM_A2_POWER_CONTROL)) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302258 BAM_DMUX_LOG("%s: disconnect\n", __func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002259 disconnect_to_bam();
Eric Holmberg006057d2012-01-11 10:10:42 -07002260 release_wakelock();
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002261 } else if (new_state & SMSM_A2_POWER_CONTROL) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302262 BAM_DMUX_LOG("%s: init\n", __func__);
Eric Holmberg006057d2012-01-11 10:10:42 -07002263 grab_wakelock();
Jeff Hugoa670b762012-03-15 15:58:28 -06002264 if (cpu_is_msm9615())
2265 msm9615_bam_init();
2266 else
Eric Holmberg604ab252012-01-15 00:01:18 -07002267 bam_init();
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002268 } else {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302269 BAM_DMUX_LOG("%s: bad state change\n", __func__);
Jeff Hugoade1f842011-08-03 15:53:59 -06002270 pr_err("%s: unsupported state change\n", __func__);
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002271 }
Jeff Hugo4b7c7b32012-04-18 16:25:14 -06002272 mutex_unlock(&smsm_cb_lock);
Jeff Hugoade1f842011-08-03 15:53:59 -06002273
2274}
2275
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002276static void bam_dmux_smsm_ack_cb(void *priv, uint32_t old_state,
2277 uint32_t new_state)
2278{
Eric Holmberg1f1255d2012-02-22 13:37:21 -07002279 DBG_INC_ACK_IN_CNT();
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302280 BAM_DMUX_LOG("%s: 0x%08x -> 0x%08x\n", __func__, old_state,
Eric Holmberg878923a2012-01-10 14:28:19 -07002281 new_state);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002282 complete_all(&ul_wakeup_ack_completion);
2283}
2284
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002285static int bam_dmux_probe(struct platform_device *pdev)
2286{
2287 int rc;
Jeff Hugo3910ee12012-08-21 14:08:20 -06002288 struct resource *r;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002289
2290 DBG("%s probe called\n", __func__);
2291 if (bam_mux_initialized)
2292 return 0;
2293
Jeff Hugo3910ee12012-08-21 14:08:20 -06002294 if (pdev->dev.of_node) {
2295 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2296 if (!r) {
2297 pr_err("%s: reg field missing\n", __func__);
2298 return -ENODEV;
2299 }
2300 a2_phys_base = (void *)(r->start);
2301 a2_phys_size = (uint32_t)(resource_size(r));
2302 a2_bam_irq = platform_get_irq(pdev, 0);
2303 if (a2_bam_irq == -ENXIO) {
2304 pr_err("%s: irq field missing\n", __func__);
2305 return -ENODEV;
2306 }
2307 DBG("%s: base:%p size:%x irq:%d\n", __func__,
2308 a2_phys_base,
2309 a2_phys_size,
2310 a2_bam_irq);
2311 } else { /* fallback to default init data */
2312 a2_phys_base = (void *)(A2_PHYS_BASE);
2313 a2_phys_size = A2_PHYS_SIZE;
2314 a2_bam_irq = A2_BAM_IRQ;
2315 }
2316
Stephen Boyd69d35e32012-02-14 15:33:30 -08002317 xo_clk = clk_get(&pdev->dev, "xo");
2318 if (IS_ERR(xo_clk)) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302319 BAM_DMUX_LOG("%s: did not get xo clock\n", __func__);
Jeff Hugod0befde2012-08-09 15:32:49 -06002320 xo_clk = NULL;
Stephen Boyd69d35e32012-02-14 15:33:30 -08002321 }
Stephen Boyd1c51a492011-10-26 12:11:47 -07002322 dfab_clk = clk_get(&pdev->dev, "bus_clk");
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002323 if (IS_ERR(dfab_clk)) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302324 BAM_DMUX_LOG("%s: did not get dfab clock\n", __func__);
Jeff Hugod0befde2012-08-09 15:32:49 -06002325 dfab_clk = NULL;
2326 } else {
2327 rc = clk_set_rate(dfab_clk, 64000000);
2328 if (rc)
2329 pr_err("%s: unable to set dfab clock rate\n", __func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002330 }
2331
Jeff Hugofff43af92012-03-29 17:54:52 -06002332 /*
2333 * setup the workqueue so that it can be pinned to core 0 and not
2334 * block the watchdog pet function, so that netif_rx() in rmnet
2335 * only uses one queue.
2336 */
2337 bam_mux_rx_workqueue = alloc_workqueue("bam_dmux_rx",
2338 WQ_MEM_RECLAIM | WQ_CPU_INTENSIVE, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002339 if (!bam_mux_rx_workqueue)
2340 return -ENOMEM;
2341
2342 bam_mux_tx_workqueue = create_singlethread_workqueue("bam_dmux_tx");
2343 if (!bam_mux_tx_workqueue) {
2344 destroy_workqueue(bam_mux_rx_workqueue);
2345 return -ENOMEM;
2346 }
2347
Jeff Hugo7960abd2011-08-02 15:39:38 -06002348 for (rc = 0; rc < BAM_DMUX_NUM_CHANNELS; ++rc) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002349 spin_lock_init(&bam_ch[rc].lock);
Jeff Hugo7960abd2011-08-02 15:39:38 -06002350 scnprintf(bam_ch[rc].name, BAM_DMUX_CH_NAME_MAX_LEN,
2351 "bam_dmux_ch_%d", rc);
2352 /* bus 2, ie a2 stream 2 */
2353 bam_ch[rc].pdev = platform_device_alloc(bam_ch[rc].name, 2);
2354 if (!bam_ch[rc].pdev) {
2355 pr_err("%s: platform device alloc failed\n", __func__);
2356 destroy_workqueue(bam_mux_rx_workqueue);
2357 destroy_workqueue(bam_mux_tx_workqueue);
2358 return -ENOMEM;
2359 }
2360 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002361
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002362 init_completion(&ul_wakeup_ack_completion);
2363 init_completion(&bam_connection_completion);
Eric Holmberg006057d2012-01-11 10:10:42 -07002364 init_completion(&dfab_unvote_completion);
Brent Hronik096f7d32013-06-28 15:43:08 -06002365 init_completion(&shutdown_completion);
2366 complete_all(&shutdown_completion);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002367 INIT_DELAYED_WORK(&ul_timeout_work, ul_timeout);
Jeff Hugo988e7ba2012-10-03 15:53:54 -06002368 INIT_DELAYED_WORK(&queue_rx_work, queue_rx_work_func);
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002369 wake_lock_init(&bam_wakelock, WAKE_LOCK_SUSPEND, "bam_dmux_wakelock");
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002370
Jeff Hugoade1f842011-08-03 15:53:59 -06002371 rc = smsm_state_cb_register(SMSM_MODEM_STATE, SMSM_A2_POWER_CONTROL,
2372 bam_dmux_smsm_cb, NULL);
2373
2374 if (rc) {
2375 destroy_workqueue(bam_mux_rx_workqueue);
2376 destroy_workqueue(bam_mux_tx_workqueue);
2377 pr_err("%s: smsm cb register failed, rc: %d\n", __func__, rc);
2378 return -ENOMEM;
2379 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002380
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002381 rc = smsm_state_cb_register(SMSM_MODEM_STATE, SMSM_A2_POWER_CONTROL_ACK,
2382 bam_dmux_smsm_ack_cb, NULL);
2383
2384 if (rc) {
2385 destroy_workqueue(bam_mux_rx_workqueue);
2386 destroy_workqueue(bam_mux_tx_workqueue);
2387 smsm_state_cb_deregister(SMSM_MODEM_STATE,
2388 SMSM_A2_POWER_CONTROL,
2389 bam_dmux_smsm_cb, NULL);
2390 pr_err("%s: smsm ack cb register failed, rc: %d\n", __func__,
2391 rc);
2392 for (rc = 0; rc < BAM_DMUX_NUM_CHANNELS; ++rc)
2393 platform_device_put(bam_ch[rc].pdev);
2394 return -ENOMEM;
2395 }
2396
Eric Holmbergfd1e2ae2011-11-15 18:28:17 -07002397 if (smsm_get_state(SMSM_MODEM_STATE) & SMSM_A2_POWER_CONTROL)
2398 bam_dmux_smsm_cb(NULL, 0, smsm_get_state(SMSM_MODEM_STATE));
2399
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002400 return 0;
2401}
2402
Jeff Hugo3910ee12012-08-21 14:08:20 -06002403static struct of_device_id msm_match_table[] = {
2404 {.compatible = "qcom,bam_dmux"},
2405 {},
2406};
2407
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002408static struct platform_driver bam_dmux_driver = {
2409 .probe = bam_dmux_probe,
2410 .driver = {
2411 .name = "BAM_RMNT",
2412 .owner = THIS_MODULE,
Jeff Hugo3910ee12012-08-21 14:08:20 -06002413 .of_match_table = msm_match_table,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002414 },
2415};
2416
2417static int __init bam_dmux_init(void)
2418{
2419#ifdef CONFIG_DEBUG_FS
2420 struct dentry *dent;
2421
2422 dent = debugfs_create_dir("bam_dmux", 0);
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07002423 if (!IS_ERR(dent)) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002424 debug_create("tbl", 0444, dent, debug_tbl);
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07002425 debug_create("ul_pkt_cnt", 0444, dent, debug_ul_pkt_cnt);
2426 debug_create("stats", 0444, dent, debug_stats);
2427 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002428#endif
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302429
2430 bam_ipc_log_txt = ipc_log_context_create(BAM_IPC_LOG_PAGES, "bam_dmux");
2431 if (!bam_ipc_log_txt) {
2432 pr_err("%s : unable to create IPC Logging Context", __func__);
Eric Holmberg878923a2012-01-10 14:28:19 -07002433 }
2434
Anurag Singhdcd8b4e2012-07-30 16:46:37 -07002435 rx_timer_interval = DEFAULT_POLLING_MIN_SLEEP;
2436
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06002437 subsys_notif_register_notifier("modem", &restart_notifier);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002438 return platform_driver_register(&bam_dmux_driver);
2439}
2440
Jeff Hugoade1f842011-08-03 15:53:59 -06002441late_initcall(bam_dmux_init); /* needs to init after SMD */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002442MODULE_DESCRIPTION("MSM BAM DMUX");
2443MODULE_LICENSE("GPL v2");