blob: 833b213ccea2aec78eabe00f1879123ee8629609 [file] [log] [blame]
Arun Kumar Neelakantam381cd542013-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 Hugo7bf02052012-08-21 14:08:20 -060030#include <linux/of.h>
Zaheerulla Meeraa9fd5c2013-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
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700174#define A2_PHYS_BASE 0x124C2000
175#define A2_PHYS_SIZE 0x2000
176#define BUFFER_SIZE 2048
177#define NUM_BUFFERS 32
Jeff Hugo7bf02052012-08-21 14:08:20 -0600178
179#ifndef A2_BAM_IRQ
180#define A2_BAM_IRQ -1
181#endif
182
183static void *a2_phys_base;
184static uint32_t a2_phys_size;
185static int a2_bam_irq;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700186static struct sps_bam_props a2_props;
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600187static u32 a2_device_handle;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700188static struct sps_pipe *bam_tx_pipe;
189static struct sps_pipe *bam_rx_pipe;
190static struct sps_connect tx_connection;
191static struct sps_connect rx_connection;
192static struct sps_mem_buffer tx_desc_mem_buf;
193static struct sps_mem_buffer rx_desc_mem_buf;
194static struct sps_register_event tx_register_event;
Jeff Hugo33dbc002011-08-25 15:52:53 -0600195static struct sps_register_event rx_register_event;
Jeff Hugo0682dad2012-10-22 11:34:28 -0600196static bool satellite_mode;
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 Hugoad75d8d2012-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
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600234static void toggle_apps_ack(void);
235static void reconnect_to_bam(void);
236static void disconnect_to_bam(void);
237static void ul_wakeup(void);
238static void ul_timeout(struct work_struct *work);
239static void vote_dfab(void);
240static void unvote_dfab(void);
Jeff Hugod98b1082011-10-24 10:30:23 -0600241static void kickoff_ul_wakeup_func(struct work_struct *work);
Eric Holmberg006057d2012-01-11 10:10:42 -0700242static void grab_wakelock(void);
243static void release_wakelock(void);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600244
245static int bam_is_connected;
246static DEFINE_MUTEX(wakeup_lock);
247static struct completion ul_wakeup_ack_completion;
248static struct completion bam_connection_completion;
249static struct delayed_work ul_timeout_work;
250static int ul_packet_written;
Eric Holmbergbc9f21c2012-01-18 11:33:33 -0700251static atomic_t ul_ondemand_vote = ATOMIC_INIT(0);
Stephen Boyd69d35e32012-02-14 15:33:30 -0800252static struct clk *dfab_clk, *xo_clk;
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600253static DEFINE_RWLOCK(ul_wakeup_lock);
Jeff Hugod98b1082011-10-24 10:30:23 -0600254static DECLARE_WORK(kickoff_ul_wakeup, kickoff_ul_wakeup_func);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600255static int bam_connection_is_active;
Jeff Hugof6c1c1e2011-12-01 17:43:49 -0700256static int wait_for_ack;
Jeff Hugoae3a85e2011-12-02 17:10:18 -0700257static struct wake_lock bam_wakelock;
Eric Holmberg006057d2012-01-11 10:10:42 -0700258static int a2_pc_disabled;
259static DEFINE_MUTEX(dfab_status_lock);
260static int dfab_is_on;
261static int wait_for_dfab;
262static struct completion dfab_unvote_completion;
263static DEFINE_SPINLOCK(wakelock_reference_lock);
264static int wakelock_reference_count;
Jeff Hugo583a6da2012-02-03 11:37:30 -0700265static int a2_pc_disabled_wakelock_skipped;
Jeff Hugob1e7c582012-06-20 15:02:11 -0600266static int disconnect_ack = 1;
Jeff Hugocb798022012-04-09 14:55:40 -0600267static LIST_HEAD(bam_other_notify_funcs);
Jeff Hugo4b7c7b32012-04-18 16:25:14 -0600268static DEFINE_MUTEX(smsm_cb_lock);
Jeff Hugoc2696142012-05-03 11:42:13 -0600269static DEFINE_MUTEX(delayed_ul_vote_lock);
270static int need_delayed_ul_vote;
Jeff Hugo18792a32012-06-20 15:25:55 -0600271static int power_management_only_mode;
Jeff Hugo73f356f2012-12-14 17:56:19 -0700272static int in_ssr;
273static int ssr_skipped_disconnect;
Jeff Hugocb798022012-04-09 14:55:40 -0600274
275struct outside_notify_func {
276 void (*notify)(void *, int, unsigned long);
277 void *priv;
278 struct list_head list_node;
279};
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600280/* End A2 power collaspe */
281
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600282/* subsystem restart */
283static int restart_notifier_cb(struct notifier_block *this,
284 unsigned long code,
285 void *data);
286
287static struct notifier_block restart_notifier = {
288 .notifier_call = restart_notifier_cb,
289};
290static int in_global_reset;
291/* end subsystem restart */
292
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700293#define bam_ch_is_open(x) \
294 (bam_ch[(x)].status == (BAM_CH_LOCAL_OPEN | BAM_CH_REMOTE_OPEN))
295
296#define bam_ch_is_local_open(x) \
297 (bam_ch[(x)].status & BAM_CH_LOCAL_OPEN)
298
299#define bam_ch_is_remote_open(x) \
300 (bam_ch[(x)].status & BAM_CH_REMOTE_OPEN)
301
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600302#define bam_ch_is_in_reset(x) \
303 (bam_ch[(x)].status & BAM_CH_IN_RESET)
304
Eric Holmberg878923a2012-01-10 14:28:19 -0700305struct kfifo bam_dmux_state_log;
Eric Holmberg878923a2012-01-10 14:28:19 -0700306static int bam_dmux_uplink_vote;
307static int bam_dmux_power_state;
308
Zaheerulla Meeraa9fd5c2013-01-31 17:06:44 +0530309static void *bam_ipc_log_txt;
310
311#define BAM_IPC_LOG_PAGES 5
312
Eric Holmberg878923a2012-01-10 14:28:19 -0700313/**
314 * Log a state change along with a small message.
Eric Holmberg878923a2012-01-10 14:28:19 -0700315 * Complete size of messsage is limited to @todo.
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +0530316 * Logging is done using IPC Logging infrastructure.
317 *
318 * States
319 * D: 1 = Power collapse disabled
320 * R: 1 = in global reset
321 * P: 1 = BAM is powered up
322 * A: 1 = BAM initialized and ready for data
323 * V: 1 = Uplink vote for power
324 * U: 1 = Uplink active
325 * W: 1 = Uplink Wait-for-ack
326 * A: 1 = Uplink ACK received
327 * #: >=1 On-demand uplink vote
328 * D: 1 = Disconnect ACK active
Eric Holmberg878923a2012-01-10 14:28:19 -0700329 */
Eric Holmberg878923a2012-01-10 14:28:19 -0700330
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +0530331#define BAM_DMUX_LOG(fmt, args...) \
332do { \
333 if (bam_ipc_log_txt) { \
334 ipc_log_string(bam_ipc_log_txt, \
335 "<DMUX> %c%c%c%c %c%c%c%c%d%c " fmt, \
336 a2_pc_disabled ? 'D' : 'd', \
337 in_global_reset ? 'R' : 'r', \
338 bam_dmux_power_state ? 'P' : 'p', \
339 bam_connection_is_active ? 'A' : 'a', \
340 bam_dmux_uplink_vote ? 'V' : 'v', \
341 bam_is_connected ? 'U' : 'u', \
342 wait_for_ack ? 'W' : 'w', \
343 ul_wakeup_ack_completion.done ? 'A' : 'a', \
344 atomic_read(&ul_ondemand_vote), \
345 disconnect_ack ? 'D' : 'd', \
346 args); \
347 } \
348} while (0)
Eric Holmberg878923a2012-01-10 14:28:19 -0700349
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +0530350#define DMUX_LOG_KERR(fmt, args...) \
351do { \
352 BAM_DMUX_LOG(fmt, args); \
353 pr_err(fmt, args); \
354} while (0)
Eric Holmberg878923a2012-01-10 14:28:19 -0700355
356static inline void set_tx_timestamp(struct tx_pkt_info *pkt)
357{
358 unsigned long long t_now;
359
360 t_now = sched_clock();
361 pkt->ts_nsec = do_div(t_now, 1000000000U);
362 pkt->ts_sec = (unsigned)t_now;
363}
364
365static inline void verify_tx_queue_is_empty(const char *func)
366{
367 unsigned long flags;
368 struct tx_pkt_info *info;
369 int reported = 0;
370
371 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
372 list_for_each_entry(info, &bam_tx_pool, list_node) {
373 if (!reported) {
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +0530374 BAM_DMUX_LOG("%s: tx pool not empty\n", func);
Eric Holmberg454d9da2012-01-12 09:37:14 -0700375 if (!in_global_reset)
376 pr_err("%s: tx pool not empty\n", func);
Eric Holmberg878923a2012-01-10 14:28:19 -0700377 reported = 1;
378 }
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +0530379 BAM_DMUX_LOG("%s: node=%p ts=%u.%09lu\n", __func__,
Eric Holmberg454d9da2012-01-12 09:37:14 -0700380 &info->list_node, info->ts_sec, info->ts_nsec);
381 if (!in_global_reset)
382 pr_err("%s: node=%p ts=%u.%09lu\n", __func__,
383 &info->list_node, info->ts_sec, info->ts_nsec);
Eric Holmberg878923a2012-01-10 14:28:19 -0700384 }
385 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
386}
387
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700388static void queue_rx(void)
389{
390 void *ptr;
391 struct rx_pkt_info *info;
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700392 int ret;
393 int rx_len_cached;
Jeff Hugo949080a2011-08-30 11:58:56 -0600394
Jeff Hugoc9749932011-11-02 17:50:40 -0600395 mutex_lock(&bam_rx_pool_mutexlock);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700396 rx_len_cached = bam_rx_pool_len;
Jeff Hugoc9749932011-11-02 17:50:40 -0600397 mutex_unlock(&bam_rx_pool_mutexlock);
Jeff Hugo949080a2011-08-30 11:58:56 -0600398
Jeff Hugoad75d8d2012-10-03 15:53:54 -0600399 while (bam_connection_is_active && rx_len_cached < NUM_BUFFERS) {
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700400 if (in_global_reset)
401 goto fail;
402
Jeff Hugoad75d8d2012-10-03 15:53:54 -0600403 info = kmalloc(sizeof(struct rx_pkt_info),
404 GFP_NOWAIT | __GFP_NOWARN);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700405 if (!info) {
Jeff Hugoad75d8d2012-10-03 15:53:54 -0600406 DMUX_LOG_KERR(
407 "%s: unable to alloc rx_pkt_info, will retry later\n",
408 __func__);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700409 goto fail;
410 }
411
412 INIT_WORK(&info->work, handle_bam_mux_cmd);
413
Jeff Hugoad75d8d2012-10-03 15:53:54 -0600414 info->skb = __dev_alloc_skb(BUFFER_SIZE,
415 GFP_NOWAIT | __GFP_NOWARN);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700416 if (info->skb == NULL) {
Jeff Hugoad75d8d2012-10-03 15:53:54 -0600417 DMUX_LOG_KERR(
418 "%s: unable to alloc skb, will retry later\n",
419 __func__);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700420 goto fail_info;
421 }
422 ptr = skb_put(info->skb, BUFFER_SIZE);
423
424 info->dma_address = dma_map_single(NULL, ptr, BUFFER_SIZE,
425 DMA_FROM_DEVICE);
426 if (info->dma_address == 0 || info->dma_address == ~0) {
427 DMUX_LOG_KERR("%s: dma_map_single failure %p for %p\n",
428 __func__, (void *)info->dma_address, ptr);
429 goto fail_skb;
430 }
431
432 mutex_lock(&bam_rx_pool_mutexlock);
433 list_add_tail(&info->list_node, &bam_rx_pool);
434 rx_len_cached = ++bam_rx_pool_len;
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700435 ret = sps_transfer_one(bam_rx_pipe, info->dma_address,
436 BUFFER_SIZE, info,
437 SPS_IOVEC_FLAG_INT | SPS_IOVEC_FLAG_EOT);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700438 if (ret) {
Eric Holmberg00cf8692012-07-16 14:21:19 -0600439 list_del(&info->list_node);
440 rx_len_cached = --bam_rx_pool_len;
441 mutex_unlock(&bam_rx_pool_mutexlock);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700442 DMUX_LOG_KERR("%s: sps_transfer_one failed %d\n",
443 __func__, ret);
Eric Holmberg00cf8692012-07-16 14:21:19 -0600444
445 dma_unmap_single(NULL, info->dma_address, BUFFER_SIZE,
446 DMA_FROM_DEVICE);
447
448 goto fail_skb;
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700449 }
Eric Holmberg00cf8692012-07-16 14:21:19 -0600450 mutex_unlock(&bam_rx_pool_mutexlock);
451
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700452 }
453 return;
454
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700455fail_skb:
456 dev_kfree_skb_any(info->skb);
457
458fail_info:
459 kfree(info);
460
461fail:
Arun Kumar Neelakantamd932d032012-12-13 18:06:49 +0530462 if (rx_len_cached == 0 && !in_global_reset) {
Jeff Hugoad75d8d2012-10-03 15:53:54 -0600463 DMUX_LOG_KERR("%s: rescheduling\n", __func__);
464 schedule_delayed_work(&queue_rx_work, msecs_to_jiffies(100));
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700465 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700466}
467
Jeff Hugoad75d8d2012-10-03 15:53:54 -0600468static void queue_rx_work_func(struct work_struct *work)
469{
470 queue_rx();
471}
472
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700473static void bam_mux_process_data(struct sk_buff *rx_skb)
474{
475 unsigned long flags;
476 struct bam_mux_hdr *rx_hdr;
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600477 unsigned long event_data;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700478
479 rx_hdr = (struct bam_mux_hdr *)rx_skb->data;
480
481 rx_skb->data = (unsigned char *)(rx_hdr + 1);
482 rx_skb->tail = rx_skb->data + rx_hdr->pkt_len;
483 rx_skb->len = rx_hdr->pkt_len;
Jeff Hugoee88f672011-10-04 17:14:52 -0600484 rx_skb->truesize = rx_hdr->pkt_len + sizeof(struct sk_buff);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700485
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600486 event_data = (unsigned long)(rx_skb);
487
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700488 spin_lock_irqsave(&bam_ch[rx_hdr->ch_id].lock, flags);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600489 if (bam_ch[rx_hdr->ch_id].notify)
490 bam_ch[rx_hdr->ch_id].notify(
491 bam_ch[rx_hdr->ch_id].priv, BAM_DMUX_RECEIVE,
492 event_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700493 else
494 dev_kfree_skb_any(rx_skb);
495 spin_unlock_irqrestore(&bam_ch[rx_hdr->ch_id].lock, flags);
496
497 queue_rx();
498}
499
Eric Holmberg006057d2012-01-11 10:10:42 -0700500static inline void handle_bam_mux_cmd_open(struct bam_mux_hdr *rx_hdr)
501{
502 unsigned long flags;
503 int ret;
504
Eric Holmberga623da82012-07-12 09:37:09 -0600505 mutex_lock(&bam_pdev_mutexlock);
506 if (in_global_reset) {
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +0530507 BAM_DMUX_LOG("%s: open cid %d aborted due to ssr\n",
Eric Holmberga623da82012-07-12 09:37:09 -0600508 __func__, rx_hdr->ch_id);
509 mutex_unlock(&bam_pdev_mutexlock);
510 queue_rx();
511 return;
512 }
Eric Holmberg006057d2012-01-11 10:10:42 -0700513 spin_lock_irqsave(&bam_ch[rx_hdr->ch_id].lock, flags);
514 bam_ch[rx_hdr->ch_id].status |= BAM_CH_REMOTE_OPEN;
515 bam_ch[rx_hdr->ch_id].num_tx_pkts = 0;
516 spin_unlock_irqrestore(&bam_ch[rx_hdr->ch_id].lock, flags);
Eric Holmberg006057d2012-01-11 10:10:42 -0700517 ret = platform_device_add(bam_ch[rx_hdr->ch_id].pdev);
518 if (ret)
519 pr_err("%s: platform_device_add() error: %d\n",
520 __func__, ret);
Eric Holmberga623da82012-07-12 09:37:09 -0600521 mutex_unlock(&bam_pdev_mutexlock);
522 queue_rx();
Eric Holmberg006057d2012-01-11 10:10:42 -0700523}
524
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700525static void handle_bam_mux_cmd(struct work_struct *work)
526{
527 unsigned long flags;
528 struct bam_mux_hdr *rx_hdr;
529 struct rx_pkt_info *info;
530 struct sk_buff *rx_skb;
531
532 info = container_of(work, struct rx_pkt_info, work);
533 rx_skb = info->skb;
Jeff Hugo949080a2011-08-30 11:58:56 -0600534 dma_unmap_single(NULL, info->dma_address, BUFFER_SIZE, DMA_FROM_DEVICE);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700535 kfree(info);
536
537 rx_hdr = (struct bam_mux_hdr *)rx_skb->data;
538
539 DBG_INC_READ_CNT(sizeof(struct bam_mux_hdr));
540 DBG("%s: magic %x reserved %d cmd %d pad %d ch %d len %d\n", __func__,
541 rx_hdr->magic_num, rx_hdr->reserved, rx_hdr->cmd,
542 rx_hdr->pad_len, rx_hdr->ch_id, rx_hdr->pkt_len);
543 if (rx_hdr->magic_num != BAM_MUX_HDR_MAGIC_NO) {
Eric Holmberg878923a2012-01-10 14:28:19 -0700544 DMUX_LOG_KERR("%s: dropping invalid hdr. magic %x"
545 " reserved %d cmd %d"
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700546 " pad %d ch %d len %d\n", __func__,
547 rx_hdr->magic_num, rx_hdr->reserved, rx_hdr->cmd,
548 rx_hdr->pad_len, rx_hdr->ch_id, rx_hdr->pkt_len);
549 dev_kfree_skb_any(rx_skb);
550 queue_rx();
551 return;
552 }
Eric Holmberg9ff40a52011-11-17 19:17:00 -0700553
554 if (rx_hdr->ch_id >= BAM_DMUX_NUM_CHANNELS) {
Eric Holmberg878923a2012-01-10 14:28:19 -0700555 DMUX_LOG_KERR("%s: dropping invalid LCID %d"
556 " reserved %d cmd %d"
Eric Holmberg9ff40a52011-11-17 19:17:00 -0700557 " pad %d ch %d len %d\n", __func__,
558 rx_hdr->ch_id, rx_hdr->reserved, rx_hdr->cmd,
559 rx_hdr->pad_len, rx_hdr->ch_id, rx_hdr->pkt_len);
560 dev_kfree_skb_any(rx_skb);
561 queue_rx();
562 return;
563 }
564
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700565 switch (rx_hdr->cmd) {
566 case BAM_MUX_HDR_CMD_DATA:
567 DBG_INC_READ_CNT(rx_hdr->pkt_len);
568 bam_mux_process_data(rx_skb);
569 break;
570 case BAM_MUX_HDR_CMD_OPEN:
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +0530571 BAM_DMUX_LOG("%s: opening cid %d PC enabled\n", __func__,
Eric Holmberg878923a2012-01-10 14:28:19 -0700572 rx_hdr->ch_id);
Eric Holmberg006057d2012-01-11 10:10:42 -0700573 handle_bam_mux_cmd_open(rx_hdr);
Jeff Hugob1e7c582012-06-20 15:02:11 -0600574 if (!(rx_hdr->reserved & ENABLE_DISCONNECT_ACK)) {
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +0530575 BAM_DMUX_LOG("%s: deactivating disconnect ack\n",
Jeff Hugod7d2b062012-07-24 14:29:56 -0600576 __func__);
Jeff Hugob1e7c582012-06-20 15:02:11 -0600577 disconnect_ack = 0;
Jeff Hugo0b13a352012-03-17 23:18:30 -0600578 }
Eric Holmberg006057d2012-01-11 10:10:42 -0700579 dev_kfree_skb_any(rx_skb);
580 break;
581 case BAM_MUX_HDR_CMD_OPEN_NO_A2_PC:
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +0530582 BAM_DMUX_LOG("%s: opening cid %d PC disabled\n", __func__,
Eric Holmberg006057d2012-01-11 10:10:42 -0700583 rx_hdr->ch_id);
584
585 if (!a2_pc_disabled) {
586 a2_pc_disabled = 1;
Jeff Hugo322179f2012-02-29 10:52:34 -0700587 ul_wakeup();
Eric Holmberg006057d2012-01-11 10:10:42 -0700588 }
589
590 handle_bam_mux_cmd_open(rx_hdr);
Eric Holmberge779dba2011-11-04 18:22:01 -0600591 dev_kfree_skb_any(rx_skb);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700592 break;
593 case BAM_MUX_HDR_CMD_CLOSE:
594 /* probably should drop pending write */
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +0530595 BAM_DMUX_LOG("%s: closing cid %d\n", __func__,
Eric Holmberg878923a2012-01-10 14:28:19 -0700596 rx_hdr->ch_id);
Eric Holmberga623da82012-07-12 09:37:09 -0600597 mutex_lock(&bam_pdev_mutexlock);
598 if (in_global_reset) {
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +0530599 BAM_DMUX_LOG("%s: close cid %d aborted due to ssr\n",
Eric Holmberga623da82012-07-12 09:37:09 -0600600 __func__, rx_hdr->ch_id);
601 mutex_unlock(&bam_pdev_mutexlock);
602 break;
603 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700604 spin_lock_irqsave(&bam_ch[rx_hdr->ch_id].lock, flags);
605 bam_ch[rx_hdr->ch_id].status &= ~BAM_CH_REMOTE_OPEN;
606 spin_unlock_irqrestore(&bam_ch[rx_hdr->ch_id].lock, flags);
Jeff Hugo7960abd2011-08-02 15:39:38 -0600607 platform_device_unregister(bam_ch[rx_hdr->ch_id].pdev);
608 bam_ch[rx_hdr->ch_id].pdev =
609 platform_device_alloc(bam_ch[rx_hdr->ch_id].name, 2);
610 if (!bam_ch[rx_hdr->ch_id].pdev)
611 pr_err("%s: platform_device_alloc failed\n", __func__);
Eric Holmberga623da82012-07-12 09:37:09 -0600612 mutex_unlock(&bam_pdev_mutexlock);
Eric Holmberge779dba2011-11-04 18:22:01 -0600613 dev_kfree_skb_any(rx_skb);
Eric Holmberga623da82012-07-12 09:37:09 -0600614 queue_rx();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700615 break;
616 default:
Eric Holmberg878923a2012-01-10 14:28:19 -0700617 DMUX_LOG_KERR("%s: dropping invalid hdr. magic %x"
618 " reserved %d cmd %d pad %d ch %d len %d\n",
619 __func__, rx_hdr->magic_num, rx_hdr->reserved,
620 rx_hdr->cmd, rx_hdr->pad_len, rx_hdr->ch_id,
621 rx_hdr->pkt_len);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700622 dev_kfree_skb_any(rx_skb);
623 queue_rx();
624 return;
625 }
626}
627
628static int bam_mux_write_cmd(void *data, uint32_t len)
629{
630 int rc;
631 struct tx_pkt_info *pkt;
632 dma_addr_t dma_address;
Jeff Hugo626303bf2011-11-21 11:43:28 -0700633 unsigned long flags;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700634
Eric Holmbergd83cd2b2011-11-04 15:54:17 -0600635 pkt = kmalloc(sizeof(struct tx_pkt_info), GFP_ATOMIC);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700636 if (pkt == NULL) {
637 pr_err("%s: mem alloc for tx_pkt_info failed\n", __func__);
638 rc = -ENOMEM;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700639 return rc;
640 }
641
642 dma_address = dma_map_single(NULL, data, len,
643 DMA_TO_DEVICE);
644 if (!dma_address) {
645 pr_err("%s: dma_map_single() failed\n", __func__);
Jeff Hugo96cb7482011-12-07 13:28:31 -0700646 kfree(pkt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700647 rc = -ENOMEM;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700648 return rc;
649 }
650 pkt->skb = (struct sk_buff *)(data);
651 pkt->len = len;
652 pkt->dma_address = dma_address;
653 pkt->is_cmd = 1;
Eric Holmberg878923a2012-01-10 14:28:19 -0700654 set_tx_timestamp(pkt);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600655 INIT_WORK(&pkt->work, bam_mux_write_done);
Jeff Hugo626303bf2011-11-21 11:43:28 -0700656 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600657 list_add_tail(&pkt->list_node, &bam_tx_pool);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700658 rc = sps_transfer_one(bam_tx_pipe, dma_address, len,
659 pkt, SPS_IOVEC_FLAG_INT | SPS_IOVEC_FLAG_EOT);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600660 if (rc) {
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700661 DMUX_LOG_KERR("%s sps_transfer_one failed rc=%d\n",
662 __func__, rc);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600663 list_del(&pkt->list_node);
Eric Holmberg2fddbcd2011-11-28 18:25:57 -0700664 DBG_INC_TX_SPS_FAILURE_CNT();
Jeff Hugo626303bf2011-11-21 11:43:28 -0700665 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700666 dma_unmap_single(NULL, pkt->dma_address,
667 pkt->len,
668 DMA_TO_DEVICE);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600669 kfree(pkt);
Jeff Hugobb6da952012-01-16 15:02:42 -0700670 } else {
671 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600672 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700673
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600674 ul_packet_written = 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700675 return rc;
676}
677
678static void bam_mux_write_done(struct work_struct *work)
679{
680 struct sk_buff *skb;
681 struct bam_mux_hdr *hdr;
682 struct tx_pkt_info *info;
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700683 struct tx_pkt_info *info_expected;
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600684 unsigned long event_data;
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700685 unsigned long flags;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700686
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600687 if (in_global_reset)
688 return;
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700689
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700690 info = container_of(work, struct tx_pkt_info, work);
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700691
692 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
693 info_expected = list_first_entry(&bam_tx_pool,
694 struct tx_pkt_info, list_node);
695 if (unlikely(info != info_expected)) {
Eric Holmberg878923a2012-01-10 14:28:19 -0700696 struct tx_pkt_info *errant_pkt;
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700697
Eric Holmberg878923a2012-01-10 14:28:19 -0700698 DMUX_LOG_KERR("%s: bam_tx_pool mismatch .next=%p,"
699 " list_node=%p, ts=%u.%09lu\n",
700 __func__, bam_tx_pool.next, &info->list_node,
701 info->ts_sec, info->ts_nsec
702 );
703
704 list_for_each_entry(errant_pkt, &bam_tx_pool, list_node) {
705 DMUX_LOG_KERR("%s: node=%p ts=%u.%09lu\n", __func__,
706 &errant_pkt->list_node, errant_pkt->ts_sec,
707 errant_pkt->ts_nsec);
708
709 }
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700710 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
711 BUG();
712 }
713 list_del(&info->list_node);
714 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
715
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600716 if (info->is_cmd) {
717 kfree(info->skb);
718 kfree(info);
719 return;
720 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700721 skb = info->skb;
722 kfree(info);
723 hdr = (struct bam_mux_hdr *)skb->data;
Eric Holmberg9fdef262012-02-14 11:46:05 -0700724 DBG_INC_WRITE_CNT(skb->len);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600725 event_data = (unsigned long)(skb);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700726 spin_lock_irqsave(&bam_ch[hdr->ch_id].lock, flags);
727 bam_ch[hdr->ch_id].num_tx_pkts--;
728 spin_unlock_irqrestore(&bam_ch[hdr->ch_id].lock, flags);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600729 if (bam_ch[hdr->ch_id].notify)
730 bam_ch[hdr->ch_id].notify(
731 bam_ch[hdr->ch_id].priv, BAM_DMUX_WRITE_DONE,
732 event_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700733 else
734 dev_kfree_skb_any(skb);
735}
736
737int msm_bam_dmux_write(uint32_t id, struct sk_buff *skb)
738{
739 int rc = 0;
740 struct bam_mux_hdr *hdr;
741 unsigned long flags;
742 struct sk_buff *new_skb = NULL;
743 dma_addr_t dma_address;
744 struct tx_pkt_info *pkt;
745
746 if (id >= BAM_DMUX_NUM_CHANNELS)
747 return -EINVAL;
748 if (!skb)
749 return -EINVAL;
750 if (!bam_mux_initialized)
751 return -ENODEV;
752
753 DBG("%s: writing to ch %d len %d\n", __func__, id, skb->len);
754 spin_lock_irqsave(&bam_ch[id].lock, flags);
755 if (!bam_ch_is_open(id)) {
756 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
757 pr_err("%s: port not open: %d\n", __func__, bam_ch[id].status);
758 return -ENODEV;
759 }
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700760
761 if (bam_ch[id].use_wm &&
762 (bam_ch[id].num_tx_pkts >= HIGH_WATERMARK)) {
763 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
764 pr_err("%s: watermark exceeded: %d\n", __func__, id);
765 return -EAGAIN;
766 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700767 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
768
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600769 read_lock(&ul_wakeup_lock);
Jeff Hugo061ce672011-10-21 17:15:32 -0600770 if (!bam_is_connected) {
771 read_unlock(&ul_wakeup_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600772 ul_wakeup();
Jeff Hugo4838f412012-01-20 11:19:37 -0700773 if (unlikely(in_global_reset == 1))
774 return -EFAULT;
Jeff Hugo061ce672011-10-21 17:15:32 -0600775 read_lock(&ul_wakeup_lock);
Jeff Hugod98b1082011-10-24 10:30:23 -0600776 notify_all(BAM_DMUX_UL_CONNECTED, (unsigned long)(NULL));
Jeff Hugo061ce672011-10-21 17:15:32 -0600777 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600778
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700779 /* if skb do not have any tailroom for padding,
780 copy the skb into a new expanded skb */
781 if ((skb->len & 0x3) && (skb_tailroom(skb) < (4 - (skb->len & 0x3)))) {
782 /* revisit, probably dev_alloc_skb and memcpy is effecient */
783 new_skb = skb_copy_expand(skb, skb_headroom(skb),
784 4 - (skb->len & 0x3), GFP_ATOMIC);
785 if (new_skb == NULL) {
786 pr_err("%s: cannot allocate skb\n", __func__);
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600787 goto write_fail;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700788 }
789 dev_kfree_skb_any(skb);
790 skb = new_skb;
791 DBG_INC_WRITE_CPY(skb->len);
792 }
793
794 hdr = (struct bam_mux_hdr *)skb_push(skb, sizeof(struct bam_mux_hdr));
795
796 /* caller should allocate for hdr and padding
797 hdr is fine, padding is tricky */
798 hdr->magic_num = BAM_MUX_HDR_MAGIC_NO;
799 hdr->cmd = BAM_MUX_HDR_CMD_DATA;
800 hdr->reserved = 0;
801 hdr->ch_id = id;
802 hdr->pkt_len = skb->len - sizeof(struct bam_mux_hdr);
803 if (skb->len & 0x3)
804 skb_put(skb, 4 - (skb->len & 0x3));
805
806 hdr->pad_len = skb->len - (sizeof(struct bam_mux_hdr) + hdr->pkt_len);
807
808 DBG("%s: data %p, tail %p skb len %d pkt len %d pad len %d\n",
809 __func__, skb->data, skb->tail, skb->len,
810 hdr->pkt_len, hdr->pad_len);
811
812 pkt = kmalloc(sizeof(struct tx_pkt_info), GFP_ATOMIC);
813 if (pkt == NULL) {
814 pr_err("%s: mem alloc for tx_pkt_info failed\n", __func__);
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600815 goto write_fail2;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700816 }
817
818 dma_address = dma_map_single(NULL, skb->data, skb->len,
819 DMA_TO_DEVICE);
820 if (!dma_address) {
821 pr_err("%s: dma_map_single() failed\n", __func__);
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600822 goto write_fail3;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700823 }
824 pkt->skb = skb;
825 pkt->dma_address = dma_address;
826 pkt->is_cmd = 0;
Eric Holmberg878923a2012-01-10 14:28:19 -0700827 set_tx_timestamp(pkt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700828 INIT_WORK(&pkt->work, bam_mux_write_done);
Jeff Hugo626303bf2011-11-21 11:43:28 -0700829 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600830 list_add_tail(&pkt->list_node, &bam_tx_pool);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700831 rc = sps_transfer_one(bam_tx_pipe, dma_address, skb->len,
832 pkt, SPS_IOVEC_FLAG_INT | SPS_IOVEC_FLAG_EOT);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600833 if (rc) {
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700834 DMUX_LOG_KERR("%s sps_transfer_one failed rc=%d\n",
835 __func__, rc);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600836 list_del(&pkt->list_node);
Eric Holmberg2fddbcd2011-11-28 18:25:57 -0700837 DBG_INC_TX_SPS_FAILURE_CNT();
Jeff Hugo626303bf2011-11-21 11:43:28 -0700838 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700839 dma_unmap_single(NULL, pkt->dma_address,
840 pkt->skb->len, DMA_TO_DEVICE);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600841 kfree(pkt);
Jeff Hugo872bd062011-11-15 17:47:21 -0700842 if (new_skb)
843 dev_kfree_skb_any(new_skb);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700844 } else {
Jeff Hugobb6da952012-01-16 15:02:42 -0700845 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700846 spin_lock_irqsave(&bam_ch[id].lock, flags);
847 bam_ch[id].num_tx_pkts++;
848 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600849 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600850 ul_packet_written = 1;
851 read_unlock(&ul_wakeup_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700852 return rc;
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600853
854write_fail3:
855 kfree(pkt);
856write_fail2:
Arun Kumar Neelakantam381cd542013-01-17 18:58:04 +0530857 skb_pull(skb, sizeof(struct bam_mux_hdr));
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600858 if (new_skb)
859 dev_kfree_skb_any(new_skb);
860write_fail:
861 read_unlock(&ul_wakeup_lock);
862 return -ENOMEM;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700863}
864
865int msm_bam_dmux_open(uint32_t id, void *priv,
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600866 void (*notify)(void *, int, unsigned long))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700867{
868 struct bam_mux_hdr *hdr;
869 unsigned long flags;
870 int rc = 0;
871
872 DBG("%s: opening ch %d\n", __func__, id);
Eric Holmberg5d775432011-11-09 10:23:35 -0700873 if (!bam_mux_initialized) {
874 DBG("%s: not inititialized\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700875 return -ENODEV;
Eric Holmberg5d775432011-11-09 10:23:35 -0700876 }
877 if (id >= BAM_DMUX_NUM_CHANNELS) {
878 pr_err("%s: invalid channel id %d\n", __func__, id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700879 return -EINVAL;
Eric Holmberg5d775432011-11-09 10:23:35 -0700880 }
881 if (notify == NULL) {
882 pr_err("%s: notify function is NULL\n", __func__);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600883 return -EINVAL;
Eric Holmberg5d775432011-11-09 10:23:35 -0700884 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700885
886 hdr = kmalloc(sizeof(struct bam_mux_hdr), GFP_KERNEL);
887 if (hdr == NULL) {
888 pr_err("%s: hdr kmalloc failed. ch: %d\n", __func__, id);
889 return -ENOMEM;
890 }
891 spin_lock_irqsave(&bam_ch[id].lock, flags);
892 if (bam_ch_is_open(id)) {
893 DBG("%s: Already opened %d\n", __func__, id);
894 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
895 kfree(hdr);
896 goto open_done;
897 }
898 if (!bam_ch_is_remote_open(id)) {
899 DBG("%s: Remote not open; ch: %d\n", __func__, id);
900 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
901 kfree(hdr);
Eric Holmberg5d775432011-11-09 10:23:35 -0700902 return -ENODEV;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700903 }
904
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600905 bam_ch[id].notify = notify;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700906 bam_ch[id].priv = priv;
907 bam_ch[id].status |= BAM_CH_LOCAL_OPEN;
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700908 bam_ch[id].num_tx_pkts = 0;
909 bam_ch[id].use_wm = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700910 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
911
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600912 read_lock(&ul_wakeup_lock);
Jeff Hugo061ce672011-10-21 17:15:32 -0600913 if (!bam_is_connected) {
914 read_unlock(&ul_wakeup_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600915 ul_wakeup();
Jeff Hugo4838f412012-01-20 11:19:37 -0700916 if (unlikely(in_global_reset == 1))
917 return -EFAULT;
Jeff Hugo061ce672011-10-21 17:15:32 -0600918 read_lock(&ul_wakeup_lock);
Jeff Hugod98b1082011-10-24 10:30:23 -0600919 notify_all(BAM_DMUX_UL_CONNECTED, (unsigned long)(NULL));
Jeff Hugo061ce672011-10-21 17:15:32 -0600920 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600921
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700922 hdr->magic_num = BAM_MUX_HDR_MAGIC_NO;
923 hdr->cmd = BAM_MUX_HDR_CMD_OPEN;
924 hdr->reserved = 0;
925 hdr->ch_id = id;
926 hdr->pkt_len = 0;
927 hdr->pad_len = 0;
928
929 rc = bam_mux_write_cmd((void *)hdr, sizeof(struct bam_mux_hdr));
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600930 read_unlock(&ul_wakeup_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700931
932open_done:
933 DBG("%s: opened ch %d\n", __func__, id);
934 return rc;
935}
936
937int msm_bam_dmux_close(uint32_t id)
938{
939 struct bam_mux_hdr *hdr;
940 unsigned long flags;
941 int rc;
942
943 if (id >= BAM_DMUX_NUM_CHANNELS)
944 return -EINVAL;
945 DBG("%s: closing ch %d\n", __func__, id);
946 if (!bam_mux_initialized)
947 return -ENODEV;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700948
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600949 read_lock(&ul_wakeup_lock);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600950 if (!bam_is_connected && !bam_ch_is_in_reset(id)) {
Jeff Hugo061ce672011-10-21 17:15:32 -0600951 read_unlock(&ul_wakeup_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600952 ul_wakeup();
Jeff Hugo4838f412012-01-20 11:19:37 -0700953 if (unlikely(in_global_reset == 1))
954 return -EFAULT;
Jeff Hugo061ce672011-10-21 17:15:32 -0600955 read_lock(&ul_wakeup_lock);
Jeff Hugod98b1082011-10-24 10:30:23 -0600956 notify_all(BAM_DMUX_UL_CONNECTED, (unsigned long)(NULL));
Jeff Hugo061ce672011-10-21 17:15:32 -0600957 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600958
Jeff Hugo061ce672011-10-21 17:15:32 -0600959 spin_lock_irqsave(&bam_ch[id].lock, flags);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600960 bam_ch[id].notify = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700961 bam_ch[id].priv = NULL;
962 bam_ch[id].status &= ~BAM_CH_LOCAL_OPEN;
963 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
964
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600965 if (bam_ch_is_in_reset(id)) {
966 read_unlock(&ul_wakeup_lock);
967 bam_ch[id].status &= ~BAM_CH_IN_RESET;
968 return 0;
969 }
970
Jeff Hugobb5802f2011-11-02 17:10:29 -0600971 hdr = kmalloc(sizeof(struct bam_mux_hdr), GFP_ATOMIC);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700972 if (hdr == NULL) {
973 pr_err("%s: hdr kmalloc failed. ch: %d\n", __func__, id);
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600974 read_unlock(&ul_wakeup_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700975 return -ENOMEM;
976 }
977 hdr->magic_num = BAM_MUX_HDR_MAGIC_NO;
978 hdr->cmd = BAM_MUX_HDR_CMD_CLOSE;
979 hdr->reserved = 0;
980 hdr->ch_id = id;
981 hdr->pkt_len = 0;
982 hdr->pad_len = 0;
983
984 rc = bam_mux_write_cmd((void *)hdr, sizeof(struct bam_mux_hdr));
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600985 read_unlock(&ul_wakeup_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700986
987 DBG("%s: closed ch %d\n", __func__, id);
988 return rc;
989}
990
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700991int msm_bam_dmux_is_ch_full(uint32_t id)
992{
993 unsigned long flags;
994 int ret;
995
996 if (id >= BAM_DMUX_NUM_CHANNELS)
997 return -EINVAL;
998
999 spin_lock_irqsave(&bam_ch[id].lock, flags);
1000 bam_ch[id].use_wm = 1;
1001 ret = bam_ch[id].num_tx_pkts >= HIGH_WATERMARK;
1002 DBG("%s: ch %d num tx pkts=%d, HWM=%d\n", __func__,
1003 id, bam_ch[id].num_tx_pkts, ret);
1004 if (!bam_ch_is_local_open(id)) {
1005 ret = -ENODEV;
1006 pr_err("%s: port not open: %d\n", __func__, bam_ch[id].status);
1007 }
1008 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
1009
1010 return ret;
1011}
1012
1013int msm_bam_dmux_is_ch_low(uint32_t id)
1014{
Eric Holmberged3ca0a2012-04-09 15:44:58 -06001015 unsigned long flags;
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -07001016 int ret;
1017
1018 if (id >= BAM_DMUX_NUM_CHANNELS)
1019 return -EINVAL;
1020
Eric Holmberged3ca0a2012-04-09 15:44:58 -06001021 spin_lock_irqsave(&bam_ch[id].lock, flags);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -07001022 bam_ch[id].use_wm = 1;
1023 ret = bam_ch[id].num_tx_pkts <= LOW_WATERMARK;
1024 DBG("%s: ch %d num tx pkts=%d, LWM=%d\n", __func__,
1025 id, bam_ch[id].num_tx_pkts, ret);
1026 if (!bam_ch_is_local_open(id)) {
1027 ret = -ENODEV;
1028 pr_err("%s: port not open: %d\n", __func__, bam_ch[id].status);
1029 }
Eric Holmberged3ca0a2012-04-09 15:44:58 -06001030 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -07001031
1032 return ret;
1033}
1034
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001035static void rx_switch_to_interrupt_mode(void)
1036{
1037 struct sps_connect cur_rx_conn;
1038 struct sps_iovec iov;
1039 struct rx_pkt_info *info;
1040 int ret;
1041
1042 /*
1043 * Attempt to enable interrupts - if this fails,
1044 * continue polling and we will retry later.
1045 */
1046 ret = sps_get_config(bam_rx_pipe, &cur_rx_conn);
1047 if (ret) {
1048 pr_err("%s: sps_get_config() failed %d\n", __func__, ret);
1049 goto fail;
1050 }
1051
1052 rx_register_event.options = SPS_O_EOT;
1053 ret = sps_register_event(bam_rx_pipe, &rx_register_event);
1054 if (ret) {
1055 pr_err("%s: sps_register_event() failed %d\n", __func__, ret);
1056 goto fail;
1057 }
1058
1059 cur_rx_conn.options = SPS_O_AUTO_ENABLE |
1060 SPS_O_EOT | SPS_O_ACK_TRANSFERS;
1061 ret = sps_set_config(bam_rx_pipe, &cur_rx_conn);
1062 if (ret) {
1063 pr_err("%s: sps_set_config() failed %d\n", __func__, ret);
1064 goto fail;
1065 }
1066 polling_mode = 0;
Eric Holmberg006057d2012-01-11 10:10:42 -07001067 release_wakelock();
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001068
1069 /* handle any rx packets before interrupt was enabled */
1070 while (bam_connection_is_active && !polling_mode) {
1071 ret = sps_get_iovec(bam_rx_pipe, &iov);
1072 if (ret) {
1073 pr_err("%s: sps_get_iovec failed %d\n",
1074 __func__, ret);
1075 break;
1076 }
1077 if (iov.addr == 0)
1078 break;
1079
1080 mutex_lock(&bam_rx_pool_mutexlock);
1081 if (unlikely(list_empty(&bam_rx_pool))) {
Eric Holmberg00cf8692012-07-16 14:21:19 -06001082 DMUX_LOG_KERR("%s: have iovec %p but rx pool empty\n",
1083 __func__, (void *)iov.addr);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001084 mutex_unlock(&bam_rx_pool_mutexlock);
1085 continue;
1086 }
1087 info = list_first_entry(&bam_rx_pool, struct rx_pkt_info,
1088 list_node);
Eric Holmberg00cf8692012-07-16 14:21:19 -06001089 if (info->dma_address != iov.addr) {
1090 DMUX_LOG_KERR("%s: iovec %p != dma %p\n",
1091 __func__,
1092 (void *)iov.addr,
1093 (void *)info->dma_address);
1094 list_for_each_entry(info, &bam_rx_pool, list_node) {
1095 DMUX_LOG_KERR("%s: dma %p\n", __func__,
1096 (void *)info->dma_address);
1097 if (iov.addr == info->dma_address)
1098 break;
1099 }
1100 }
1101 BUG_ON(info->dma_address != iov.addr);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001102 list_del(&info->list_node);
Eric Holmbergb5b08e52012-01-20 14:19:00 -07001103 --bam_rx_pool_len;
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001104 mutex_unlock(&bam_rx_pool_mutexlock);
1105 handle_bam_mux_cmd(&info->work);
1106 }
1107 return;
1108
1109fail:
1110 pr_err("%s: reverting to polling\n", __func__);
Jeff Hugofff43af92012-03-29 17:54:52 -06001111 queue_work_on(0, bam_mux_rx_workqueue, &rx_timer_work);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001112}
1113
Jeff Hugo949080a2011-08-30 11:58:56 -06001114static void rx_timer_work_func(struct work_struct *work)
1115{
1116 struct sps_iovec iov;
Jeff Hugo949080a2011-08-30 11:58:56 -06001117 struct rx_pkt_info *info;
1118 int inactive_cycles = 0;
1119 int ret;
Anurag Singhdcd8b4e2012-07-30 16:46:37 -07001120 u32 buffs_unused, buffs_used;
Jeff Hugo949080a2011-08-30 11:58:56 -06001121
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001122 while (bam_connection_is_active) { /* timer loop */
Jeff Hugo949080a2011-08-30 11:58:56 -06001123 ++inactive_cycles;
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001124 while (bam_connection_is_active) { /* deplete queue loop */
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001125 if (in_global_reset)
1126 return;
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001127
1128 ret = sps_get_iovec(bam_rx_pipe, &iov);
1129 if (ret) {
1130 pr_err("%s: sps_get_iovec failed %d\n",
1131 __func__, ret);
1132 break;
1133 }
Jeff Hugo949080a2011-08-30 11:58:56 -06001134 if (iov.addr == 0)
1135 break;
1136 inactive_cycles = 0;
Jeff Hugoc9749932011-11-02 17:50:40 -06001137 mutex_lock(&bam_rx_pool_mutexlock);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001138 if (unlikely(list_empty(&bam_rx_pool))) {
Eric Holmberg00cf8692012-07-16 14:21:19 -06001139 DMUX_LOG_KERR(
1140 "%s: have iovec %p but rx pool empty\n",
1141 __func__, (void *)iov.addr);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001142 mutex_unlock(&bam_rx_pool_mutexlock);
1143 continue;
1144 }
1145 info = list_first_entry(&bam_rx_pool,
1146 struct rx_pkt_info, list_node);
Eric Holmberg00cf8692012-07-16 14:21:19 -06001147 if (info->dma_address != iov.addr) {
1148 DMUX_LOG_KERR("%s: iovec %p != dma %p\n",
1149 __func__,
1150 (void *)iov.addr,
1151 (void *)info->dma_address);
1152 list_for_each_entry(info, &bam_rx_pool,
1153 list_node) {
1154 DMUX_LOG_KERR("%s: dma %p\n", __func__,
1155 (void *)info->dma_address);
1156 if (iov.addr == info->dma_address)
1157 break;
1158 }
1159 }
1160 BUG_ON(info->dma_address != iov.addr);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001161 list_del(&info->list_node);
Eric Holmberg00cf8692012-07-16 14:21:19 -06001162 --bam_rx_pool_len;
Jeff Hugoc9749932011-11-02 17:50:40 -06001163 mutex_unlock(&bam_rx_pool_mutexlock);
Jeff Hugo949080a2011-08-30 11:58:56 -06001164 handle_bam_mux_cmd(&info->work);
1165 }
1166
Anurag Singhdcd8b4e2012-07-30 16:46:37 -07001167 if (inactive_cycles >= POLLING_INACTIVITY) {
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001168 rx_switch_to_interrupt_mode();
1169 break;
Jeff Hugo949080a2011-08-30 11:58:56 -06001170 }
1171
Anurag Singhdcd8b4e2012-07-30 16:46:37 -07001172 if (bam_adaptive_timer_enabled) {
1173 usleep_range(rx_timer_interval, rx_timer_interval + 50);
1174
1175 ret = sps_get_unused_desc_num(bam_rx_pipe,
1176 &buffs_unused);
1177
1178 if (ret) {
1179 pr_err("%s: error getting num buffers unused after sleep\n",
1180 __func__);
1181
1182 break;
1183 }
1184
1185 buffs_used = NUM_BUFFERS - buffs_unused;
1186
1187 if (buffs_unused == 0) {
1188 rx_timer_interval = MIN_POLLING_SLEEP;
1189 } else {
1190 if (buffs_used > 0) {
1191 rx_timer_interval =
1192 (2 * NUM_BUFFERS *
1193 rx_timer_interval)/
1194 (3 * buffs_used);
1195 } else {
1196 rx_timer_interval =
1197 MAX_POLLING_SLEEP;
1198 }
1199 }
1200
1201 if (rx_timer_interval > MAX_POLLING_SLEEP)
1202 rx_timer_interval = MAX_POLLING_SLEEP;
1203 else if (rx_timer_interval < MIN_POLLING_SLEEP)
1204 rx_timer_interval = MIN_POLLING_SLEEP;
1205 } else {
1206 usleep_range(POLLING_MIN_SLEEP, POLLING_MAX_SLEEP);
1207 }
Jeff Hugo949080a2011-08-30 11:58:56 -06001208 }
1209}
1210
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001211static void bam_mux_tx_notify(struct sps_event_notify *notify)
1212{
1213 struct tx_pkt_info *pkt;
1214
1215 DBG("%s: event %d notified\n", __func__, notify->event_id);
1216
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001217 if (in_global_reset)
1218 return;
1219
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001220 switch (notify->event_id) {
1221 case SPS_EVENT_EOT:
1222 pkt = notify->data.transfer.user;
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001223 if (!pkt->is_cmd)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001224 dma_unmap_single(NULL, pkt->dma_address,
1225 pkt->skb->len,
1226 DMA_TO_DEVICE);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001227 else
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001228 dma_unmap_single(NULL, pkt->dma_address,
1229 pkt->len,
1230 DMA_TO_DEVICE);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001231 queue_work(bam_mux_tx_workqueue, &pkt->work);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001232 break;
1233 default:
1234 pr_err("%s: recieved unexpected event id %d\n", __func__,
1235 notify->event_id);
1236 }
1237}
1238
Jeff Hugo33dbc002011-08-25 15:52:53 -06001239static void bam_mux_rx_notify(struct sps_event_notify *notify)
1240{
Jeff Hugo949080a2011-08-30 11:58:56 -06001241 int ret;
1242 struct sps_connect cur_rx_conn;
Jeff Hugo33dbc002011-08-25 15:52:53 -06001243
1244 DBG("%s: event %d notified\n", __func__, notify->event_id);
1245
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001246 if (in_global_reset)
1247 return;
1248
Jeff Hugo33dbc002011-08-25 15:52:53 -06001249 switch (notify->event_id) {
1250 case SPS_EVENT_EOT:
Jeff Hugo949080a2011-08-30 11:58:56 -06001251 /* attempt to disable interrupts in this pipe */
1252 if (!polling_mode) {
1253 ret = sps_get_config(bam_rx_pipe, &cur_rx_conn);
1254 if (ret) {
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001255 pr_err("%s: sps_get_config() failed %d, interrupts"
1256 " not disabled\n", __func__, ret);
Jeff Hugo949080a2011-08-30 11:58:56 -06001257 break;
1258 }
Jeff Hugoa9d32ba2011-11-21 14:59:48 -07001259 cur_rx_conn.options = SPS_O_AUTO_ENABLE |
Jeff Hugo949080a2011-08-30 11:58:56 -06001260 SPS_O_ACK_TRANSFERS | SPS_O_POLL;
1261 ret = sps_set_config(bam_rx_pipe, &cur_rx_conn);
1262 if (ret) {
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001263 pr_err("%s: sps_set_config() failed %d, interrupts"
1264 " not disabled\n", __func__, ret);
Jeff Hugo949080a2011-08-30 11:58:56 -06001265 break;
1266 }
Eric Holmberg006057d2012-01-11 10:10:42 -07001267 grab_wakelock();
Jeff Hugo949080a2011-08-30 11:58:56 -06001268 polling_mode = 1;
Jeff Hugofff43af92012-03-29 17:54:52 -06001269 /*
1270 * run on core 0 so that netif_rx() in rmnet uses only
1271 * one queue
1272 */
1273 queue_work_on(0, bam_mux_rx_workqueue, &rx_timer_work);
Jeff Hugo949080a2011-08-30 11:58:56 -06001274 }
Jeff Hugo33dbc002011-08-25 15:52:53 -06001275 break;
1276 default:
1277 pr_err("%s: recieved unexpected event id %d\n", __func__,
1278 notify->event_id);
1279 }
1280}
1281
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001282#ifdef CONFIG_DEBUG_FS
1283
1284static int debug_tbl(char *buf, int max)
1285{
1286 int i = 0;
1287 int j;
1288
1289 for (j = 0; j < BAM_DMUX_NUM_CHANNELS; ++j) {
1290 i += scnprintf(buf + i, max - i,
1291 "ch%02d local open=%s remote open=%s\n",
1292 j, bam_ch_is_local_open(j) ? "Y" : "N",
1293 bam_ch_is_remote_open(j) ? "Y" : "N");
1294 }
1295
1296 return i;
1297}
1298
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07001299static int debug_ul_pkt_cnt(char *buf, int max)
1300{
1301 struct list_head *p;
1302 unsigned long flags;
1303 int n = 0;
1304
1305 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
1306 __list_for_each(p, &bam_tx_pool) {
1307 ++n;
1308 }
1309 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
1310
1311 return scnprintf(buf, max, "Number of UL packets in flight: %d\n", n);
1312}
1313
1314static int debug_stats(char *buf, int max)
1315{
1316 int i = 0;
1317
1318 i += scnprintf(buf + i, max - i,
Eric Holmberg9fdef262012-02-14 11:46:05 -07001319 "skb read cnt: %u\n"
1320 "skb write cnt: %u\n"
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07001321 "skb copy cnt: %u\n"
1322 "skb copy bytes: %u\n"
Eric Holmberg6074aba2012-01-18 17:59:44 -07001323 "sps tx failures: %u\n"
Eric Holmbergb5b08e52012-01-20 14:19:00 -07001324 "sps tx stalls: %u\n"
Eric Holmberg1f1255d2012-02-22 13:37:21 -07001325 "rx queue len: %d\n"
1326 "a2 ack out cnt: %d\n"
1327 "a2 ack in cnt: %d\n"
1328 "a2 pwr cntl in: %d\n",
Eric Holmberg9fdef262012-02-14 11:46:05 -07001329 bam_dmux_read_cnt,
1330 bam_dmux_write_cnt,
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07001331 bam_dmux_write_cpy_cnt,
1332 bam_dmux_write_cpy_bytes,
Eric Holmberg6074aba2012-01-18 17:59:44 -07001333 bam_dmux_tx_sps_failure_cnt,
Eric Holmbergb5b08e52012-01-20 14:19:00 -07001334 bam_dmux_tx_stall_cnt,
Eric Holmberg1f1255d2012-02-22 13:37:21 -07001335 bam_rx_pool_len,
1336 atomic_read(&bam_dmux_ack_out_cnt),
1337 atomic_read(&bam_dmux_ack_in_cnt),
1338 atomic_read(&bam_dmux_a2_pwr_cntl_in_cnt)
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07001339 );
1340
1341 return i;
1342}
1343
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001344#define DEBUG_BUFMAX 4096
1345static char debug_buffer[DEBUG_BUFMAX];
1346
1347static ssize_t debug_read(struct file *file, char __user *buf,
1348 size_t count, loff_t *ppos)
1349{
1350 int (*fill)(char *buf, int max) = file->private_data;
1351 int bsize = fill(debug_buffer, DEBUG_BUFMAX);
1352 return simple_read_from_buffer(buf, count, ppos, debug_buffer, bsize);
1353}
1354
1355static int debug_open(struct inode *inode, struct file *file)
1356{
1357 file->private_data = inode->i_private;
1358 return 0;
1359}
1360
1361
1362static const struct file_operations debug_ops = {
1363 .read = debug_read,
1364 .open = debug_open,
1365};
1366
1367static void debug_create(const char *name, mode_t mode,
1368 struct dentry *dent,
1369 int (*fill)(char *buf, int max))
1370{
Eric Holmberge4ac80b2012-01-12 09:21:59 -07001371 struct dentry *file;
1372
1373 file = debugfs_create_file(name, mode, dent, fill, &debug_ops);
1374 if (IS_ERR(file))
1375 pr_err("%s: debugfs create failed %d\n", __func__,
1376 (int)PTR_ERR(file));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001377}
1378
1379#endif
1380
Jeff Hugod98b1082011-10-24 10:30:23 -06001381static void notify_all(int event, unsigned long data)
1382{
1383 int i;
Jeff Hugocb798022012-04-09 14:55:40 -06001384 struct list_head *temp;
1385 struct outside_notify_func *func;
Jeff Hugod98b1082011-10-24 10:30:23 -06001386
1387 for (i = 0; i < BAM_DMUX_NUM_CHANNELS; ++i) {
Eric Holmberg454d9da2012-01-12 09:37:14 -07001388 if (bam_ch_is_open(i)) {
Jeff Hugod98b1082011-10-24 10:30:23 -06001389 bam_ch[i].notify(bam_ch[i].priv, event, data);
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05301390 BAM_DMUX_LOG("%s: cid=%d, event=%d, data=%lu\n",
Eric Holmberg454d9da2012-01-12 09:37:14 -07001391 __func__, i, event, data);
1392 }
Jeff Hugod98b1082011-10-24 10:30:23 -06001393 }
Jeff Hugocb798022012-04-09 14:55:40 -06001394
1395 __list_for_each(temp, &bam_other_notify_funcs) {
1396 func = container_of(temp, struct outside_notify_func,
1397 list_node);
1398 func->notify(func->priv, event, data);
1399 }
Jeff Hugod98b1082011-10-24 10:30:23 -06001400}
1401
1402static void kickoff_ul_wakeup_func(struct work_struct *work)
1403{
1404 read_lock(&ul_wakeup_lock);
1405 if (!bam_is_connected) {
1406 read_unlock(&ul_wakeup_lock);
1407 ul_wakeup();
Jeff Hugo4838f412012-01-20 11:19:37 -07001408 if (unlikely(in_global_reset == 1))
1409 return;
Jeff Hugod98b1082011-10-24 10:30:23 -06001410 read_lock(&ul_wakeup_lock);
1411 ul_packet_written = 1;
1412 notify_all(BAM_DMUX_UL_CONNECTED, (unsigned long)(NULL));
1413 }
1414 read_unlock(&ul_wakeup_lock);
1415}
1416
Eric Holmbergbc9f21c2012-01-18 11:33:33 -07001417int msm_bam_dmux_kickoff_ul_wakeup(void)
Jeff Hugod98b1082011-10-24 10:30:23 -06001418{
Eric Holmbergbc9f21c2012-01-18 11:33:33 -07001419 int is_connected;
1420
1421 read_lock(&ul_wakeup_lock);
1422 ul_packet_written = 1;
1423 is_connected = bam_is_connected;
1424 if (!is_connected)
1425 queue_work(bam_mux_tx_workqueue, &kickoff_ul_wakeup);
1426 read_unlock(&ul_wakeup_lock);
1427
1428 return is_connected;
Jeff Hugod98b1082011-10-24 10:30:23 -06001429}
1430
Eric Holmberg878923a2012-01-10 14:28:19 -07001431static void power_vote(int vote)
1432{
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05301433 BAM_DMUX_LOG("%s: curr=%d, vote=%d\n", __func__,
Eric Holmberg878923a2012-01-10 14:28:19 -07001434 bam_dmux_uplink_vote, vote);
1435
1436 if (bam_dmux_uplink_vote == vote)
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05301437 BAM_DMUX_LOG("%s: warning - duplicate power vote\n", __func__);
Eric Holmberg878923a2012-01-10 14:28:19 -07001438
1439 bam_dmux_uplink_vote = vote;
1440 if (vote)
1441 smsm_change_state(SMSM_APPS_STATE, 0, SMSM_A2_POWER_CONTROL);
1442 else
1443 smsm_change_state(SMSM_APPS_STATE, SMSM_A2_POWER_CONTROL, 0);
1444}
1445
Eric Holmberg454d9da2012-01-12 09:37:14 -07001446/*
1447 * @note: Must be called with ul_wakeup_lock locked.
1448 */
1449static inline void ul_powerdown(void)
1450{
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05301451 BAM_DMUX_LOG("%s: powerdown\n", __func__);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001452 verify_tx_queue_is_empty(__func__);
1453
1454 if (a2_pc_disabled) {
1455 wait_for_dfab = 1;
1456 INIT_COMPLETION(dfab_unvote_completion);
1457 release_wakelock();
1458 } else {
1459 wait_for_ack = 1;
1460 INIT_COMPLETION(ul_wakeup_ack_completion);
1461 power_vote(0);
1462 }
1463 bam_is_connected = 0;
1464 notify_all(BAM_DMUX_UL_DISCONNECTED, (unsigned long)(NULL));
1465}
1466
1467static inline void ul_powerdown_finish(void)
1468{
1469 if (a2_pc_disabled && wait_for_dfab) {
1470 unvote_dfab();
1471 complete_all(&dfab_unvote_completion);
1472 wait_for_dfab = 0;
1473 }
1474}
1475
Eric Holmbergbc9f21c2012-01-18 11:33:33 -07001476/*
1477 * Votes for UL power and returns current power state.
1478 *
1479 * @returns true if currently connected
1480 */
1481int msm_bam_dmux_ul_power_vote(void)
1482{
1483 int is_connected;
1484
1485 read_lock(&ul_wakeup_lock);
1486 atomic_inc(&ul_ondemand_vote);
1487 is_connected = bam_is_connected;
1488 if (!is_connected)
1489 queue_work(bam_mux_tx_workqueue, &kickoff_ul_wakeup);
1490 read_unlock(&ul_wakeup_lock);
1491
1492 return is_connected;
1493}
1494
1495/*
1496 * Unvotes for UL power.
1497 *
1498 * @returns true if vote count is 0 (UL shutdown possible)
1499 */
1500int msm_bam_dmux_ul_power_unvote(void)
1501{
1502 int vote;
1503
1504 read_lock(&ul_wakeup_lock);
1505 vote = atomic_dec_return(&ul_ondemand_vote);
1506 if (unlikely(vote) < 0)
1507 DMUX_LOG_KERR("%s: invalid power vote %d\n", __func__, vote);
1508 read_unlock(&ul_wakeup_lock);
1509
1510 return vote == 0;
1511}
1512
Jeff Hugocb798022012-04-09 14:55:40 -06001513int msm_bam_dmux_reg_notify(void *priv,
1514 void (*notify)(void *priv, int event_type,
1515 unsigned long data))
1516{
1517 struct outside_notify_func *func;
1518
1519 if (!notify)
1520 return -EINVAL;
1521
1522 func = kmalloc(sizeof(struct outside_notify_func), GFP_KERNEL);
1523 if (!func)
1524 return -ENOMEM;
1525
1526 func->notify = notify;
1527 func->priv = priv;
1528 list_add(&func->list_node, &bam_other_notify_funcs);
1529
1530 return 0;
1531}
1532
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001533static void ul_timeout(struct work_struct *work)
1534{
Jeff Hugoc040a5b2011-11-15 14:26:01 -07001535 unsigned long flags;
1536 int ret;
1537
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001538 if (in_global_reset)
1539 return;
Jeff Hugoc040a5b2011-11-15 14:26:01 -07001540 ret = write_trylock_irqsave(&ul_wakeup_lock, flags);
1541 if (!ret) { /* failed to grab lock, reschedule and bail */
1542 schedule_delayed_work(&ul_timeout_work,
1543 msecs_to_jiffies(UL_TIMEOUT_DELAY));
1544 return;
1545 }
Eric Holmberg454d9da2012-01-12 09:37:14 -07001546 if (bam_is_connected) {
Eric Holmberg6074aba2012-01-18 17:59:44 -07001547 if (!ul_packet_written) {
1548 spin_lock(&bam_tx_pool_spinlock);
1549 if (!list_empty(&bam_tx_pool)) {
1550 struct tx_pkt_info *info;
1551
1552 info = list_first_entry(&bam_tx_pool,
1553 struct tx_pkt_info, list_node);
1554 DMUX_LOG_KERR("%s: UL delayed ts=%u.%09lu\n",
1555 __func__, info->ts_sec, info->ts_nsec);
1556 DBG_INC_TX_STALL_CNT();
1557 ul_packet_written = 1;
1558 }
1559 spin_unlock(&bam_tx_pool_spinlock);
1560 }
1561
Eric Holmbergbc9f21c2012-01-18 11:33:33 -07001562 if (ul_packet_written || atomic_read(&ul_ondemand_vote)) {
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05301563 BAM_DMUX_LOG("%s: pkt written %d\n",
Eric Holmbergbc9f21c2012-01-18 11:33:33 -07001564 __func__, ul_packet_written);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001565 ul_packet_written = 0;
1566 schedule_delayed_work(&ul_timeout_work,
1567 msecs_to_jiffies(UL_TIMEOUT_DELAY));
Eric Holmberg006057d2012-01-11 10:10:42 -07001568 } else {
Eric Holmberg454d9da2012-01-12 09:37:14 -07001569 ul_powerdown();
Eric Holmberg006057d2012-01-11 10:10:42 -07001570 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001571 }
Jeff Hugoc040a5b2011-11-15 14:26:01 -07001572 write_unlock_irqrestore(&ul_wakeup_lock, flags);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001573 ul_powerdown_finish();
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001574}
Jeff Hugo4838f412012-01-20 11:19:37 -07001575
1576static int ssrestart_check(void)
1577{
Eric Holmberg90285e22012-02-22 12:33:05 -07001578 DMUX_LOG_KERR("%s: modem timeout: BAM DMUX disabled\n", __func__);
1579 in_global_reset = 1;
1580 if (get_restart_level() <= RESET_SOC)
1581 DMUX_LOG_KERR("%s: ssrestart not enabled\n", __func__);
1582 return 1;
Jeff Hugo4838f412012-01-20 11:19:37 -07001583}
1584
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001585static void ul_wakeup(void)
1586{
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001587 int ret;
Jeff Hugo5f57ec92012-05-14 13:34:28 -06001588 int do_vote_dfab = 0;
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001589
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001590 mutex_lock(&wakeup_lock);
1591 if (bam_is_connected) { /* bam got connected before lock grabbed */
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05301592 BAM_DMUX_LOG("%s Already awake\n", __func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001593 mutex_unlock(&wakeup_lock);
1594 return;
1595 }
Eric Holmberg878923a2012-01-10 14:28:19 -07001596
Jeff Hugoc2696142012-05-03 11:42:13 -06001597 /*
Jeff Hugo00424ff2012-08-27 13:19:09 -06001598 * if this gets hit, that means restart_notifier_cb() has started
1599 * but probably not finished, thus we know SSR has happened, but
1600 * haven't been able to send that info to our clients yet.
1601 * in that case, abort the ul_wakeup() so that we don't undo any
1602 * work restart_notifier_cb() has done. The clients will be notified
1603 * shortly. No cleanup necessary (reschedule the wakeup) as our and
1604 * their SSR handling will cover it
1605 */
1606 if (unlikely(in_global_reset == 1)) {
1607 mutex_unlock(&wakeup_lock);
1608 return;
1609 }
1610
1611 /*
Jeff Hugoc2696142012-05-03 11:42:13 -06001612 * if someone is voting for UL before bam is inited (modem up first
1613 * time), set flag for init to kickoff ul wakeup once bam is inited
1614 */
1615 mutex_lock(&delayed_ul_vote_lock);
1616 if (unlikely(!bam_mux_initialized)) {
1617 need_delayed_ul_vote = 1;
1618 mutex_unlock(&delayed_ul_vote_lock);
1619 mutex_unlock(&wakeup_lock);
1620 return;
1621 }
1622 mutex_unlock(&delayed_ul_vote_lock);
1623
Eric Holmberg006057d2012-01-11 10:10:42 -07001624 if (a2_pc_disabled) {
1625 /*
1626 * don't grab the wakelock the first time because it is
1627 * already grabbed when a2 powers on
1628 */
Jeff Hugo5f57ec92012-05-14 13:34:28 -06001629 if (likely(a2_pc_disabled_wakelock_skipped)) {
Eric Holmberg006057d2012-01-11 10:10:42 -07001630 grab_wakelock();
Jeff Hugo5f57ec92012-05-14 13:34:28 -06001631 do_vote_dfab = 1; /* vote must occur after wait */
1632 } else {
Jeff Hugo583a6da2012-02-03 11:37:30 -07001633 a2_pc_disabled_wakelock_skipped = 1;
Jeff Hugo5f57ec92012-05-14 13:34:28 -06001634 }
Eric Holmberg006057d2012-01-11 10:10:42 -07001635 if (wait_for_dfab) {
Jeff Hugo66f7f1e2012-01-16 14:30:42 -07001636 ret = wait_for_completion_timeout(
Eric Holmberg006057d2012-01-11 10:10:42 -07001637 &dfab_unvote_completion, HZ);
1638 BUG_ON(ret == 0);
1639 }
Jeff Hugo5f57ec92012-05-14 13:34:28 -06001640 if (likely(do_vote_dfab))
1641 vote_dfab();
Eric Holmberg006057d2012-01-11 10:10:42 -07001642 schedule_delayed_work(&ul_timeout_work,
1643 msecs_to_jiffies(UL_TIMEOUT_DELAY));
1644 bam_is_connected = 1;
1645 mutex_unlock(&wakeup_lock);
1646 return;
1647 }
1648
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001649 /*
1650 * must wait for the previous power down request to have been acked
1651 * chances are it already came in and this will just fall through
1652 * instead of waiting
1653 */
1654 if (wait_for_ack) {
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05301655 BAM_DMUX_LOG("%s waiting for previous ack\n", __func__);
Jeff Hugo66f7f1e2012-01-16 14:30:42 -07001656 ret = wait_for_completion_timeout(
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001657 &ul_wakeup_ack_completion, HZ);
Eric Holmberg006057d2012-01-11 10:10:42 -07001658 wait_for_ack = 0;
Jeff Hugo4838f412012-01-20 11:19:37 -07001659 if (unlikely(ret == 0) && ssrestart_check()) {
1660 mutex_unlock(&wakeup_lock);
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05301661 BAM_DMUX_LOG("%s timeout previous ack\n", __func__);
Jeff Hugo4838f412012-01-20 11:19:37 -07001662 return;
1663 }
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001664 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001665 INIT_COMPLETION(ul_wakeup_ack_completion);
Eric Holmberg878923a2012-01-10 14:28:19 -07001666 power_vote(1);
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05301667 BAM_DMUX_LOG("%s waiting for wakeup ack\n", __func__);
Jeff Hugo66f7f1e2012-01-16 14:30:42 -07001668 ret = wait_for_completion_timeout(&ul_wakeup_ack_completion, HZ);
Jeff Hugo4838f412012-01-20 11:19:37 -07001669 if (unlikely(ret == 0) && ssrestart_check()) {
1670 mutex_unlock(&wakeup_lock);
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05301671 BAM_DMUX_LOG("%s timeout wakeup ack\n", __func__);
Jeff Hugo4838f412012-01-20 11:19:37 -07001672 return;
1673 }
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05301674 BAM_DMUX_LOG("%s waiting completion\n", __func__);
Jeff Hugo66f7f1e2012-01-16 14:30:42 -07001675 ret = wait_for_completion_timeout(&bam_connection_completion, HZ);
Jeff Hugo4838f412012-01-20 11:19:37 -07001676 if (unlikely(ret == 0) && ssrestart_check()) {
1677 mutex_unlock(&wakeup_lock);
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05301678 BAM_DMUX_LOG("%s timeout power on\n", __func__);
Jeff Hugo4838f412012-01-20 11:19:37 -07001679 return;
1680 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001681
1682 bam_is_connected = 1;
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05301683 BAM_DMUX_LOG("%s complete\n", __func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001684 schedule_delayed_work(&ul_timeout_work,
1685 msecs_to_jiffies(UL_TIMEOUT_DELAY));
1686 mutex_unlock(&wakeup_lock);
1687}
1688
1689static void reconnect_to_bam(void)
1690{
1691 int i;
1692
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001693 in_global_reset = 0;
Jeff Hugo73f356f2012-12-14 17:56:19 -07001694 in_ssr = 0;
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001695 vote_dfab();
Jeff Hugo18792a32012-06-20 15:25:55 -06001696 if (!power_management_only_mode) {
Jeff Hugo73f356f2012-12-14 17:56:19 -07001697 if (ssr_skipped_disconnect) {
1698 /* delayed to here to prevent bus stall */
1699 sps_disconnect(bam_tx_pipe);
1700 sps_disconnect(bam_rx_pipe);
1701 __memzero(rx_desc_mem_buf.base, rx_desc_mem_buf.size);
1702 __memzero(tx_desc_mem_buf.base, tx_desc_mem_buf.size);
1703 }
1704 ssr_skipped_disconnect = 0;
Jeff Hugo18792a32012-06-20 15:25:55 -06001705 i = sps_device_reset(a2_device_handle);
1706 if (i)
1707 pr_err("%s: device reset failed rc = %d\n", __func__,
1708 i);
1709 i = sps_connect(bam_tx_pipe, &tx_connection);
1710 if (i)
1711 pr_err("%s: tx connection failed rc = %d\n", __func__,
1712 i);
1713 i = sps_connect(bam_rx_pipe, &rx_connection);
1714 if (i)
1715 pr_err("%s: rx connection failed rc = %d\n", __func__,
1716 i);
1717 i = sps_register_event(bam_tx_pipe, &tx_register_event);
1718 if (i)
1719 pr_err("%s: tx event reg failed rc = %d\n", __func__,
1720 i);
1721 i = sps_register_event(bam_rx_pipe, &rx_register_event);
1722 if (i)
1723 pr_err("%s: rx event reg failed rc = %d\n", __func__,
1724 i);
1725 }
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001726
1727 bam_connection_is_active = 1;
1728
1729 if (polling_mode)
1730 rx_switch_to_interrupt_mode();
1731
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001732 toggle_apps_ack();
1733 complete_all(&bam_connection_completion);
Jeff Hugo18792a32012-06-20 15:25:55 -06001734 if (!power_management_only_mode)
1735 queue_rx();
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001736}
1737
1738static void disconnect_to_bam(void)
1739{
1740 struct list_head *node;
1741 struct rx_pkt_info *info;
Eric Holmberg454d9da2012-01-12 09:37:14 -07001742 unsigned long flags;
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001743
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001744 bam_connection_is_active = 0;
Eric Holmberg454d9da2012-01-12 09:37:14 -07001745
1746 /* handle disconnect during active UL */
1747 write_lock_irqsave(&ul_wakeup_lock, flags);
1748 if (bam_is_connected) {
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05301749 BAM_DMUX_LOG("%s: UL active - forcing powerdown\n", __func__);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001750 ul_powerdown();
1751 }
1752 write_unlock_irqrestore(&ul_wakeup_lock, flags);
1753 ul_powerdown_finish();
1754
1755 /* tear down BAM connection */
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001756 INIT_COMPLETION(bam_connection_completion);
Jeff Hugo73f356f2012-12-14 17:56:19 -07001757
1758 /* in_ssr documentation/assumptions found in restart_notifier_cb */
1759 if (!power_management_only_mode) {
1760 if (likely(!in_ssr)) {
1761 sps_disconnect(bam_tx_pipe);
1762 sps_disconnect(bam_rx_pipe);
1763 __memzero(rx_desc_mem_buf.base, rx_desc_mem_buf.size);
1764 __memzero(tx_desc_mem_buf.base, tx_desc_mem_buf.size);
1765 sps_device_reset(a2_device_handle);
1766 } else {
1767 ssr_skipped_disconnect = 1;
1768 }
1769 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001770 unvote_dfab();
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001771
1772 mutex_lock(&bam_rx_pool_mutexlock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001773 while (!list_empty(&bam_rx_pool)) {
1774 node = bam_rx_pool.next;
1775 list_del(node);
1776 info = container_of(node, struct rx_pkt_info, list_node);
1777 dma_unmap_single(NULL, info->dma_address, BUFFER_SIZE,
1778 DMA_FROM_DEVICE);
1779 dev_kfree_skb_any(info->skb);
1780 kfree(info);
1781 }
Eric Holmbergb5b08e52012-01-20 14:19:00 -07001782 bam_rx_pool_len = 0;
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001783 mutex_unlock(&bam_rx_pool_mutexlock);
Eric Holmberg878923a2012-01-10 14:28:19 -07001784
Jeff Hugo0b13a352012-03-17 23:18:30 -06001785 if (disconnect_ack)
1786 toggle_apps_ack();
1787
Eric Holmberg878923a2012-01-10 14:28:19 -07001788 verify_tx_queue_is_empty(__func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001789}
1790
1791static void vote_dfab(void)
1792{
Jeff Hugoca0caa82011-12-05 16:05:23 -07001793 int rc;
1794
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05301795 BAM_DMUX_LOG("%s\n", __func__);
Eric Holmberg006057d2012-01-11 10:10:42 -07001796 mutex_lock(&dfab_status_lock);
1797 if (dfab_is_on) {
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05301798 BAM_DMUX_LOG("%s: dfab is already on\n", __func__);
Eric Holmberg006057d2012-01-11 10:10:42 -07001799 mutex_unlock(&dfab_status_lock);
1800 return;
1801 }
Jeff Hugo0c9371a2012-08-09 15:32:49 -06001802 if (dfab_clk) {
1803 rc = clk_prepare_enable(dfab_clk);
1804 if (rc)
1805 DMUX_LOG_KERR("bam_dmux vote for dfab failed rc = %d\n",
1806 rc);
1807 }
1808 if (xo_clk) {
1809 rc = clk_prepare_enable(xo_clk);
1810 if (rc)
1811 DMUX_LOG_KERR("bam_dmux vote for xo failed rc = %d\n",
1812 rc);
1813 }
Eric Holmberg006057d2012-01-11 10:10:42 -07001814 dfab_is_on = 1;
1815 mutex_unlock(&dfab_status_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001816}
1817
1818static void unvote_dfab(void)
1819{
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05301820 BAM_DMUX_LOG("%s\n", __func__);
Eric Holmberg006057d2012-01-11 10:10:42 -07001821 mutex_lock(&dfab_status_lock);
1822 if (!dfab_is_on) {
1823 DMUX_LOG_KERR("%s: dfab is already off\n", __func__);
1824 dump_stack();
1825 mutex_unlock(&dfab_status_lock);
1826 return;
1827 }
Jeff Hugo0c9371a2012-08-09 15:32:49 -06001828 if (dfab_clk)
1829 clk_disable_unprepare(dfab_clk);
1830 if (xo_clk)
1831 clk_disable_unprepare(xo_clk);
Eric Holmberg006057d2012-01-11 10:10:42 -07001832 dfab_is_on = 0;
1833 mutex_unlock(&dfab_status_lock);
1834}
1835
1836/* reference counting wrapper around wakelock */
1837static void grab_wakelock(void)
1838{
1839 unsigned long flags;
1840
1841 spin_lock_irqsave(&wakelock_reference_lock, flags);
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05301842 BAM_DMUX_LOG("%s: ref count = %d\n", __func__,
Eric Holmberg006057d2012-01-11 10:10:42 -07001843 wakelock_reference_count);
1844 if (wakelock_reference_count == 0)
1845 wake_lock(&bam_wakelock);
1846 ++wakelock_reference_count;
1847 spin_unlock_irqrestore(&wakelock_reference_lock, flags);
1848}
1849
1850static void release_wakelock(void)
1851{
1852 unsigned long flags;
1853
1854 spin_lock_irqsave(&wakelock_reference_lock, flags);
1855 if (wakelock_reference_count == 0) {
1856 DMUX_LOG_KERR("%s: bam_dmux wakelock not locked\n", __func__);
1857 dump_stack();
1858 spin_unlock_irqrestore(&wakelock_reference_lock, flags);
1859 return;
1860 }
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05301861 BAM_DMUX_LOG("%s: ref count = %d\n", __func__,
Eric Holmberg006057d2012-01-11 10:10:42 -07001862 wakelock_reference_count);
1863 --wakelock_reference_count;
1864 if (wakelock_reference_count == 0)
1865 wake_unlock(&bam_wakelock);
1866 spin_unlock_irqrestore(&wakelock_reference_lock, flags);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001867}
1868
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001869static int restart_notifier_cb(struct notifier_block *this,
1870 unsigned long code,
1871 void *data)
1872{
1873 int i;
1874 struct list_head *node;
1875 struct tx_pkt_info *info;
1876 int temp_remote_status;
Jeff Hugo626303bf2011-11-21 11:43:28 -07001877 unsigned long flags;
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001878
Jeff Hugo73f356f2012-12-14 17:56:19 -07001879 /*
1880 * Bam_dmux counts on the fact that the BEFORE_SHUTDOWN level of
1881 * notifications are guarenteed to execute before the AFTER_SHUTDOWN
1882 * level of notifications, and that BEFORE_SHUTDOWN always occurs in
1883 * all SSR events, no matter what triggered the SSR. Also, bam_dmux
1884 * assumes that SMD does its SSR processing in the AFTER_SHUTDOWN level
1885 * thus bam_dmux is guarenteed to detect SSR before SMD, since the
1886 * callbacks for all the drivers within the AFTER_SHUTDOWN level could
1887 * occur in any order. Bam_dmux uses this knowledge to skip accessing
1888 * the bam hardware when disconnect_to_bam() is triggered by SMD's SSR
1889 * processing. We do not wat to access the bam hardware during SSR
1890 * because a watchdog crash from a bus stall would likely occur.
1891 */
Jeff Hugob6f72f12013-02-25 13:46:56 -07001892 if (code == SUBSYS_BEFORE_SHUTDOWN) {
1893 in_global_reset = 1;
Jeff Hugo73f356f2012-12-14 17:56:19 -07001894 in_ssr = 1;
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05301895 BAM_DMUX_LOG("%s: begin\n", __func__);
Jeff Hugob6f72f12013-02-25 13:46:56 -07001896 flush_workqueue(bam_mux_rx_workqueue);
1897 }
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001898 if (code != SUBSYS_AFTER_SHUTDOWN)
1899 return NOTIFY_DONE;
1900
Eric Holmberg454d9da2012-01-12 09:37:14 -07001901 /* Handle uplink Powerdown */
1902 write_lock_irqsave(&ul_wakeup_lock, flags);
1903 if (bam_is_connected) {
1904 ul_powerdown();
1905 wait_for_ack = 0;
1906 }
Jeff Hugo4838f412012-01-20 11:19:37 -07001907 /*
1908 * if modem crash during ul_wakeup(), power_vote is 1, needs to be
1909 * reset to 0. harmless if bam_is_connected check above passes
1910 */
1911 power_vote(0);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001912 write_unlock_irqrestore(&ul_wakeup_lock, flags);
1913 ul_powerdown_finish();
Eric Holmberg006057d2012-01-11 10:10:42 -07001914 a2_pc_disabled = 0;
Jeff Hugo583a6da2012-02-03 11:37:30 -07001915 a2_pc_disabled_wakelock_skipped = 0;
Jeff Hugof62029d2012-07-17 13:39:53 -06001916 disconnect_ack = 1;
Eric Holmberg454d9da2012-01-12 09:37:14 -07001917
1918 /* Cleanup Channel States */
Eric Holmberga623da82012-07-12 09:37:09 -06001919 mutex_lock(&bam_pdev_mutexlock);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001920 for (i = 0; i < BAM_DMUX_NUM_CHANNELS; ++i) {
1921 temp_remote_status = bam_ch_is_remote_open(i);
1922 bam_ch[i].status &= ~BAM_CH_REMOTE_OPEN;
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -07001923 bam_ch[i].num_tx_pkts = 0;
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001924 if (bam_ch_is_local_open(i))
1925 bam_ch[i].status |= BAM_CH_IN_RESET;
1926 if (temp_remote_status) {
1927 platform_device_unregister(bam_ch[i].pdev);
1928 bam_ch[i].pdev = platform_device_alloc(
1929 bam_ch[i].name, 2);
1930 }
1931 }
Eric Holmberga623da82012-07-12 09:37:09 -06001932 mutex_unlock(&bam_pdev_mutexlock);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001933
1934 /* Cleanup pending UL data */
Jeff Hugo626303bf2011-11-21 11:43:28 -07001935 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001936 while (!list_empty(&bam_tx_pool)) {
1937 node = bam_tx_pool.next;
1938 list_del(node);
1939 info = container_of(node, struct tx_pkt_info,
1940 list_node);
1941 if (!info->is_cmd) {
1942 dma_unmap_single(NULL, info->dma_address,
1943 info->skb->len,
1944 DMA_TO_DEVICE);
1945 dev_kfree_skb_any(info->skb);
1946 } else {
1947 dma_unmap_single(NULL, info->dma_address,
1948 info->len,
1949 DMA_TO_DEVICE);
1950 kfree(info->skb);
1951 }
1952 kfree(info);
1953 }
Jeff Hugo626303bf2011-11-21 11:43:28 -07001954 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001955
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05301956 BAM_DMUX_LOG("%s: complete\n", __func__);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001957 return NOTIFY_DONE;
1958}
1959
Jeff Hugo9dea05c2011-12-21 12:23:05 -07001960static int bam_init(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001961{
1962 u32 h;
1963 dma_addr_t dma_addr;
1964 int ret;
1965 void *a2_virt_addr;
Jeff Hugo4b2890d2012-01-16 16:14:21 -07001966 int skip_iounmap = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001967
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001968 vote_dfab();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001969 /* init BAM */
Jeff Hugo7bf02052012-08-21 14:08:20 -06001970 a2_virt_addr = ioremap_nocache((unsigned long)(a2_phys_base),
1971 a2_phys_size);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001972 if (!a2_virt_addr) {
1973 pr_err("%s: ioremap failed\n", __func__);
1974 ret = -ENOMEM;
Jeff Hugo994a92d2012-01-05 13:25:21 -07001975 goto ioremap_failed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001976 }
Jeff Hugo7bf02052012-08-21 14:08:20 -06001977 a2_props.phys_addr = (u32)(a2_phys_base);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001978 a2_props.virt_addr = a2_virt_addr;
Jeff Hugo7bf02052012-08-21 14:08:20 -06001979 a2_props.virt_size = a2_phys_size;
1980 a2_props.irq = a2_bam_irq;
Jeff Hugo927cba62011-11-11 11:49:52 -07001981 a2_props.options = SPS_BAM_OPT_IRQ_WAKEUP;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001982 a2_props.num_pipes = A2_NUM_PIPES;
1983 a2_props.summing_threshold = A2_SUMMING_THRESHOLD;
Jeff Hugo0682dad2012-10-22 11:34:28 -06001984 if (cpu_is_msm9615() || satellite_mode)
Jeff Hugo75913c82011-12-05 15:59:01 -07001985 a2_props.manage = SPS_BAM_MGR_DEVICE_REMOTE;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001986 /* need to free on tear down */
1987 ret = sps_register_bam_device(&a2_props, &h);
1988 if (ret < 0) {
1989 pr_err("%s: register bam error %d\n", __func__, ret);
1990 goto register_bam_failed;
1991 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001992 a2_device_handle = h;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001993
1994 bam_tx_pipe = sps_alloc_endpoint();
1995 if (bam_tx_pipe == NULL) {
1996 pr_err("%s: tx alloc endpoint failed\n", __func__);
1997 ret = -ENOMEM;
Jeff Hugo8ff4a812012-01-17 11:03:13 -07001998 goto tx_alloc_endpoint_failed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001999 }
2000 ret = sps_get_config(bam_tx_pipe, &tx_connection);
2001 if (ret) {
2002 pr_err("%s: tx get config failed %d\n", __func__, ret);
2003 goto tx_get_config_failed;
2004 }
2005
2006 tx_connection.source = SPS_DEV_HANDLE_MEM;
2007 tx_connection.src_pipe_index = 0;
2008 tx_connection.destination = h;
2009 tx_connection.dest_pipe_index = 4;
2010 tx_connection.mode = SPS_MODE_DEST;
2011 tx_connection.options = SPS_O_AUTO_ENABLE | SPS_O_EOT;
2012 tx_desc_mem_buf.size = 0x800; /* 2k */
2013 tx_desc_mem_buf.base = dma_alloc_coherent(NULL, tx_desc_mem_buf.size,
2014 &dma_addr, 0);
2015 if (tx_desc_mem_buf.base == NULL) {
2016 pr_err("%s: tx memory alloc failed\n", __func__);
2017 ret = -ENOMEM;
Jeff Hugo8ff4a812012-01-17 11:03:13 -07002018 goto tx_get_config_failed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002019 }
2020 tx_desc_mem_buf.phys_base = dma_addr;
2021 memset(tx_desc_mem_buf.base, 0x0, tx_desc_mem_buf.size);
2022 tx_connection.desc = tx_desc_mem_buf;
2023 tx_connection.event_thresh = 0x10;
2024
2025 ret = sps_connect(bam_tx_pipe, &tx_connection);
2026 if (ret < 0) {
2027 pr_err("%s: tx connect error %d\n", __func__, ret);
2028 goto tx_connect_failed;
2029 }
2030
2031 bam_rx_pipe = sps_alloc_endpoint();
2032 if (bam_rx_pipe == NULL) {
2033 pr_err("%s: rx alloc endpoint failed\n", __func__);
2034 ret = -ENOMEM;
Jeff Hugo8ff4a812012-01-17 11:03:13 -07002035 goto rx_alloc_endpoint_failed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002036 }
2037 ret = sps_get_config(bam_rx_pipe, &rx_connection);
2038 if (ret) {
2039 pr_err("%s: rx get config failed %d\n", __func__, ret);
2040 goto rx_get_config_failed;
2041 }
2042
2043 rx_connection.source = h;
2044 rx_connection.src_pipe_index = 5;
2045 rx_connection.destination = SPS_DEV_HANDLE_MEM;
2046 rx_connection.dest_pipe_index = 1;
2047 rx_connection.mode = SPS_MODE_SRC;
Jeff Hugo949080a2011-08-30 11:58:56 -06002048 rx_connection.options = SPS_O_AUTO_ENABLE | SPS_O_EOT |
2049 SPS_O_ACK_TRANSFERS;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002050 rx_desc_mem_buf.size = 0x800; /* 2k */
2051 rx_desc_mem_buf.base = dma_alloc_coherent(NULL, rx_desc_mem_buf.size,
2052 &dma_addr, 0);
2053 if (rx_desc_mem_buf.base == NULL) {
2054 pr_err("%s: rx memory alloc failed\n", __func__);
2055 ret = -ENOMEM;
2056 goto rx_mem_failed;
2057 }
2058 rx_desc_mem_buf.phys_base = dma_addr;
2059 memset(rx_desc_mem_buf.base, 0x0, rx_desc_mem_buf.size);
2060 rx_connection.desc = rx_desc_mem_buf;
2061 rx_connection.event_thresh = 0x10;
2062
2063 ret = sps_connect(bam_rx_pipe, &rx_connection);
2064 if (ret < 0) {
2065 pr_err("%s: rx connect error %d\n", __func__, ret);
2066 goto rx_connect_failed;
2067 }
2068
2069 tx_register_event.options = SPS_O_EOT;
2070 tx_register_event.mode = SPS_TRIGGER_CALLBACK;
2071 tx_register_event.xfer_done = NULL;
2072 tx_register_event.callback = bam_mux_tx_notify;
2073 tx_register_event.user = NULL;
2074 ret = sps_register_event(bam_tx_pipe, &tx_register_event);
2075 if (ret < 0) {
2076 pr_err("%s: tx register event error %d\n", __func__, ret);
2077 goto rx_event_reg_failed;
2078 }
2079
Jeff Hugo33dbc002011-08-25 15:52:53 -06002080 rx_register_event.options = SPS_O_EOT;
2081 rx_register_event.mode = SPS_TRIGGER_CALLBACK;
2082 rx_register_event.xfer_done = NULL;
2083 rx_register_event.callback = bam_mux_rx_notify;
2084 rx_register_event.user = NULL;
2085 ret = sps_register_event(bam_rx_pipe, &rx_register_event);
2086 if (ret < 0) {
2087 pr_err("%s: tx register event error %d\n", __func__, ret);
2088 goto rx_event_reg_failed;
2089 }
2090
Jeff Hugoc2696142012-05-03 11:42:13 -06002091 mutex_lock(&delayed_ul_vote_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002092 bam_mux_initialized = 1;
Jeff Hugoc2696142012-05-03 11:42:13 -06002093 if (need_delayed_ul_vote) {
2094 need_delayed_ul_vote = 0;
2095 msm_bam_dmux_kickoff_ul_wakeup();
2096 }
2097 mutex_unlock(&delayed_ul_vote_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002098 toggle_apps_ack();
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06002099 bam_connection_is_active = 1;
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002100 complete_all(&bam_connection_completion);
Jeff Hugo2fb555e2012-03-14 16:33:47 -06002101 queue_rx();
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002102 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002103
2104rx_event_reg_failed:
2105 sps_disconnect(bam_rx_pipe);
2106rx_connect_failed:
2107 dma_free_coherent(NULL, rx_desc_mem_buf.size, rx_desc_mem_buf.base,
2108 rx_desc_mem_buf.phys_base);
2109rx_mem_failed:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002110rx_get_config_failed:
2111 sps_free_endpoint(bam_rx_pipe);
Jeff Hugo8ff4a812012-01-17 11:03:13 -07002112rx_alloc_endpoint_failed:
2113 sps_disconnect(bam_tx_pipe);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002114tx_connect_failed:
2115 dma_free_coherent(NULL, tx_desc_mem_buf.size, tx_desc_mem_buf.base,
2116 tx_desc_mem_buf.phys_base);
2117tx_get_config_failed:
2118 sps_free_endpoint(bam_tx_pipe);
Jeff Hugo8ff4a812012-01-17 11:03:13 -07002119tx_alloc_endpoint_failed:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002120 sps_deregister_bam_device(h);
Jeff Hugo4b2890d2012-01-16 16:14:21 -07002121 /*
2122 * sps_deregister_bam_device() calls iounmap. calling iounmap on the
2123 * same handle below will cause a crash, so skip it if we've freed
2124 * the handle here.
2125 */
2126 skip_iounmap = 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002127register_bam_failed:
Jeff Hugo4b2890d2012-01-16 16:14:21 -07002128 if (!skip_iounmap)
2129 iounmap(a2_virt_addr);
Jeff Hugo994a92d2012-01-05 13:25:21 -07002130ioremap_failed:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002131 /*destroy_workqueue(bam_mux_workqueue);*/
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002132 return ret;
2133}
2134
2135static int bam_init_fallback(void)
2136{
2137 u32 h;
2138 int ret;
2139 void *a2_virt_addr;
2140
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002141 /* init BAM */
Jeff Hugo7bf02052012-08-21 14:08:20 -06002142 a2_virt_addr = ioremap_nocache((unsigned long)(a2_phys_base),
2143 a2_phys_size);
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002144 if (!a2_virt_addr) {
2145 pr_err("%s: ioremap failed\n", __func__);
2146 ret = -ENOMEM;
2147 goto ioremap_failed;
2148 }
Jeff Hugo7bf02052012-08-21 14:08:20 -06002149 a2_props.phys_addr = (u32)(a2_phys_base);
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002150 a2_props.virt_addr = a2_virt_addr;
Jeff Hugo7bf02052012-08-21 14:08:20 -06002151 a2_props.virt_size = a2_phys_size;
2152 a2_props.irq = a2_bam_irq;
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002153 a2_props.options = SPS_BAM_OPT_IRQ_WAKEUP;
2154 a2_props.num_pipes = A2_NUM_PIPES;
2155 a2_props.summing_threshold = A2_SUMMING_THRESHOLD;
Jeff Hugo0682dad2012-10-22 11:34:28 -06002156 if (cpu_is_msm9615() || satellite_mode)
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002157 a2_props.manage = SPS_BAM_MGR_DEVICE_REMOTE;
2158 ret = sps_register_bam_device(&a2_props, &h);
2159 if (ret < 0) {
2160 pr_err("%s: register bam error %d\n", __func__, ret);
2161 goto register_bam_failed;
2162 }
2163 a2_device_handle = h;
Jeff Hugoc2696142012-05-03 11:42:13 -06002164
2165 mutex_lock(&delayed_ul_vote_lock);
2166 bam_mux_initialized = 1;
2167 if (need_delayed_ul_vote) {
2168 need_delayed_ul_vote = 0;
2169 msm_bam_dmux_kickoff_ul_wakeup();
2170 }
2171 mutex_unlock(&delayed_ul_vote_lock);
Jeff Hugo2bec9772012-04-05 12:25:16 -06002172 toggle_apps_ack();
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002173
Jeff Hugo18792a32012-06-20 15:25:55 -06002174 power_management_only_mode = 1;
2175 bam_connection_is_active = 1;
2176 complete_all(&bam_connection_completion);
2177
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002178 return 0;
2179
2180register_bam_failed:
Jeff Hugo4b2890d2012-01-16 16:14:21 -07002181 iounmap(a2_virt_addr);
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002182ioremap_failed:
2183 return ret;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002184}
Jeff Hugoade1f842011-08-03 15:53:59 -06002185
Jeff Hugoa670b762012-03-15 15:58:28 -06002186static void msm9615_bam_init(void)
Eric Holmberg604ab252012-01-15 00:01:18 -07002187{
2188 int ret = 0;
2189
2190 ret = bam_init();
2191 if (ret) {
2192 ret = bam_init_fallback();
2193 if (ret)
2194 pr_err("%s: bam init fallback failed: %d",
2195 __func__, ret);
2196 }
2197}
2198
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002199static void toggle_apps_ack(void)
2200{
2201 static unsigned int clear_bit; /* 0 = set the bit, else clear bit */
Eric Holmberg878923a2012-01-10 14:28:19 -07002202
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05302203 BAM_DMUX_LOG("%s: apps ack %d->%d\n", __func__,
Eric Holmberg878923a2012-01-10 14:28:19 -07002204 clear_bit & 0x1, ~clear_bit & 0x1);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002205 smsm_change_state(SMSM_APPS_STATE,
2206 clear_bit & SMSM_A2_POWER_CONTROL_ACK,
2207 ~clear_bit & SMSM_A2_POWER_CONTROL_ACK);
2208 clear_bit = ~clear_bit;
Eric Holmberg1f1255d2012-02-22 13:37:21 -07002209 DBG_INC_ACK_OUT_CNT();
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002210}
2211
Jeff Hugoade1f842011-08-03 15:53:59 -06002212static void bam_dmux_smsm_cb(void *priv, uint32_t old_state, uint32_t new_state)
2213{
Jeff Hugo4b7c7b32012-04-18 16:25:14 -06002214 static int last_processed_state;
2215
2216 mutex_lock(&smsm_cb_lock);
Eric Holmberg878923a2012-01-10 14:28:19 -07002217 bam_dmux_power_state = new_state & SMSM_A2_POWER_CONTROL ? 1 : 0;
Eric Holmberg1f1255d2012-02-22 13:37:21 -07002218 DBG_INC_A2_POWER_CONTROL_IN_CNT();
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05302219 BAM_DMUX_LOG("%s: 0x%08x -> 0x%08x\n", __func__, old_state,
Eric Holmberg878923a2012-01-10 14:28:19 -07002220 new_state);
Jeff Hugo4b7c7b32012-04-18 16:25:14 -06002221 if (last_processed_state == (new_state & SMSM_A2_POWER_CONTROL)) {
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05302222 BAM_DMUX_LOG("%s: already processed this state\n", __func__);
Jeff Hugo4b7c7b32012-04-18 16:25:14 -06002223 mutex_unlock(&smsm_cb_lock);
2224 return;
2225 }
2226
2227 last_processed_state = new_state & SMSM_A2_POWER_CONTROL;
Eric Holmberg878923a2012-01-10 14:28:19 -07002228
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002229 if (bam_mux_initialized && new_state & SMSM_A2_POWER_CONTROL) {
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05302230 BAM_DMUX_LOG("%s: reconnect\n", __func__);
Eric Holmberg006057d2012-01-11 10:10:42 -07002231 grab_wakelock();
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002232 reconnect_to_bam();
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002233 } else if (bam_mux_initialized &&
2234 !(new_state & SMSM_A2_POWER_CONTROL)) {
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05302235 BAM_DMUX_LOG("%s: disconnect\n", __func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002236 disconnect_to_bam();
Eric Holmberg006057d2012-01-11 10:10:42 -07002237 release_wakelock();
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002238 } else if (new_state & SMSM_A2_POWER_CONTROL) {
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05302239 BAM_DMUX_LOG("%s: init\n", __func__);
Eric Holmberg006057d2012-01-11 10:10:42 -07002240 grab_wakelock();
Jeff Hugoa670b762012-03-15 15:58:28 -06002241 if (cpu_is_msm9615())
2242 msm9615_bam_init();
2243 else
Eric Holmberg604ab252012-01-15 00:01:18 -07002244 bam_init();
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002245 } else {
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05302246 BAM_DMUX_LOG("%s: bad state change\n", __func__);
Jeff Hugoade1f842011-08-03 15:53:59 -06002247 pr_err("%s: unsupported state change\n", __func__);
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002248 }
Jeff Hugo4b7c7b32012-04-18 16:25:14 -06002249 mutex_unlock(&smsm_cb_lock);
Jeff Hugoade1f842011-08-03 15:53:59 -06002250
2251}
2252
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002253static void bam_dmux_smsm_ack_cb(void *priv, uint32_t old_state,
2254 uint32_t new_state)
2255{
Eric Holmberg1f1255d2012-02-22 13:37:21 -07002256 DBG_INC_ACK_IN_CNT();
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05302257 BAM_DMUX_LOG("%s: 0x%08x -> 0x%08x\n", __func__, old_state,
Eric Holmberg878923a2012-01-10 14:28:19 -07002258 new_state);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002259 complete_all(&ul_wakeup_ack_completion);
2260}
2261
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002262static int bam_dmux_probe(struct platform_device *pdev)
2263{
2264 int rc;
Jeff Hugo7bf02052012-08-21 14:08:20 -06002265 struct resource *r;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002266
2267 DBG("%s probe called\n", __func__);
2268 if (bam_mux_initialized)
2269 return 0;
2270
Jeff Hugo7bf02052012-08-21 14:08:20 -06002271 if (pdev->dev.of_node) {
2272 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2273 if (!r) {
2274 pr_err("%s: reg field missing\n", __func__);
2275 return -ENODEV;
2276 }
2277 a2_phys_base = (void *)(r->start);
2278 a2_phys_size = (uint32_t)(resource_size(r));
2279 a2_bam_irq = platform_get_irq(pdev, 0);
2280 if (a2_bam_irq == -ENXIO) {
2281 pr_err("%s: irq field missing\n", __func__);
2282 return -ENODEV;
2283 }
Jeff Hugo0682dad2012-10-22 11:34:28 -06002284 satellite_mode = of_property_read_bool(pdev->dev.of_node,
2285 "qcom,satellite-mode");
2286
2287 DBG("%s: base:%p size:%x irq:%d satellite:%d\n", __func__,
Jeff Hugo7bf02052012-08-21 14:08:20 -06002288 a2_phys_base,
2289 a2_phys_size,
Jeff Hugo0682dad2012-10-22 11:34:28 -06002290 a2_bam_irq,
2291 satellite_mode);
Jeff Hugo7bf02052012-08-21 14:08:20 -06002292 } else { /* fallback to default init data */
2293 a2_phys_base = (void *)(A2_PHYS_BASE);
2294 a2_phys_size = A2_PHYS_SIZE;
2295 a2_bam_irq = A2_BAM_IRQ;
2296 }
2297
Stephen Boyd69d35e32012-02-14 15:33:30 -08002298 xo_clk = clk_get(&pdev->dev, "xo");
2299 if (IS_ERR(xo_clk)) {
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05302300 BAM_DMUX_LOG("%s: did not get xo clock\n", __func__);
Jeff Hugo0c9371a2012-08-09 15:32:49 -06002301 xo_clk = NULL;
Stephen Boyd69d35e32012-02-14 15:33:30 -08002302 }
Stephen Boyd1c51a492011-10-26 12:11:47 -07002303 dfab_clk = clk_get(&pdev->dev, "bus_clk");
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002304 if (IS_ERR(dfab_clk)) {
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05302305 BAM_DMUX_LOG("%s: did not get dfab clock\n", __func__);
Jeff Hugo0c9371a2012-08-09 15:32:49 -06002306 dfab_clk = NULL;
2307 } else {
2308 rc = clk_set_rate(dfab_clk, 64000000);
2309 if (rc)
2310 pr_err("%s: unable to set dfab clock rate\n", __func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002311 }
2312
Jeff Hugofff43af92012-03-29 17:54:52 -06002313 /*
2314 * setup the workqueue so that it can be pinned to core 0 and not
2315 * block the watchdog pet function, so that netif_rx() in rmnet
2316 * only uses one queue.
2317 */
2318 bam_mux_rx_workqueue = alloc_workqueue("bam_dmux_rx",
2319 WQ_MEM_RECLAIM | WQ_CPU_INTENSIVE, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002320 if (!bam_mux_rx_workqueue)
2321 return -ENOMEM;
2322
2323 bam_mux_tx_workqueue = create_singlethread_workqueue("bam_dmux_tx");
2324 if (!bam_mux_tx_workqueue) {
2325 destroy_workqueue(bam_mux_rx_workqueue);
2326 return -ENOMEM;
2327 }
2328
Jeff Hugo7960abd2011-08-02 15:39:38 -06002329 for (rc = 0; rc < BAM_DMUX_NUM_CHANNELS; ++rc) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002330 spin_lock_init(&bam_ch[rc].lock);
Jeff Hugo7960abd2011-08-02 15:39:38 -06002331 scnprintf(bam_ch[rc].name, BAM_DMUX_CH_NAME_MAX_LEN,
2332 "bam_dmux_ch_%d", rc);
2333 /* bus 2, ie a2 stream 2 */
2334 bam_ch[rc].pdev = platform_device_alloc(bam_ch[rc].name, 2);
2335 if (!bam_ch[rc].pdev) {
2336 pr_err("%s: platform device alloc failed\n", __func__);
2337 destroy_workqueue(bam_mux_rx_workqueue);
2338 destroy_workqueue(bam_mux_tx_workqueue);
2339 return -ENOMEM;
2340 }
2341 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002342
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002343 init_completion(&ul_wakeup_ack_completion);
2344 init_completion(&bam_connection_completion);
Eric Holmberg006057d2012-01-11 10:10:42 -07002345 init_completion(&dfab_unvote_completion);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002346 INIT_DELAYED_WORK(&ul_timeout_work, ul_timeout);
Jeff Hugoad75d8d2012-10-03 15:53:54 -06002347 INIT_DELAYED_WORK(&queue_rx_work, queue_rx_work_func);
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002348 wake_lock_init(&bam_wakelock, WAKE_LOCK_SUSPEND, "bam_dmux_wakelock");
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002349
Jeff Hugoade1f842011-08-03 15:53:59 -06002350 rc = smsm_state_cb_register(SMSM_MODEM_STATE, SMSM_A2_POWER_CONTROL,
2351 bam_dmux_smsm_cb, NULL);
2352
2353 if (rc) {
2354 destroy_workqueue(bam_mux_rx_workqueue);
2355 destroy_workqueue(bam_mux_tx_workqueue);
2356 pr_err("%s: smsm cb register failed, rc: %d\n", __func__, rc);
2357 return -ENOMEM;
2358 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002359
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002360 rc = smsm_state_cb_register(SMSM_MODEM_STATE, SMSM_A2_POWER_CONTROL_ACK,
2361 bam_dmux_smsm_ack_cb, NULL);
2362
2363 if (rc) {
2364 destroy_workqueue(bam_mux_rx_workqueue);
2365 destroy_workqueue(bam_mux_tx_workqueue);
2366 smsm_state_cb_deregister(SMSM_MODEM_STATE,
2367 SMSM_A2_POWER_CONTROL,
2368 bam_dmux_smsm_cb, NULL);
2369 pr_err("%s: smsm ack cb register failed, rc: %d\n", __func__,
2370 rc);
2371 for (rc = 0; rc < BAM_DMUX_NUM_CHANNELS; ++rc)
2372 platform_device_put(bam_ch[rc].pdev);
2373 return -ENOMEM;
2374 }
2375
Eric Holmbergfd1e2ae2011-11-15 18:28:17 -07002376 if (smsm_get_state(SMSM_MODEM_STATE) & SMSM_A2_POWER_CONTROL)
2377 bam_dmux_smsm_cb(NULL, 0, smsm_get_state(SMSM_MODEM_STATE));
2378
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002379 return 0;
2380}
2381
Jeff Hugo7bf02052012-08-21 14:08:20 -06002382static struct of_device_id msm_match_table[] = {
2383 {.compatible = "qcom,bam_dmux"},
2384 {},
2385};
2386
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002387static struct platform_driver bam_dmux_driver = {
2388 .probe = bam_dmux_probe,
2389 .driver = {
2390 .name = "BAM_RMNT",
2391 .owner = THIS_MODULE,
Jeff Hugo7bf02052012-08-21 14:08:20 -06002392 .of_match_table = msm_match_table,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002393 },
2394};
2395
2396static int __init bam_dmux_init(void)
2397{
2398#ifdef CONFIG_DEBUG_FS
2399 struct dentry *dent;
2400
2401 dent = debugfs_create_dir("bam_dmux", 0);
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07002402 if (!IS_ERR(dent)) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002403 debug_create("tbl", 0444, dent, debug_tbl);
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07002404 debug_create("ul_pkt_cnt", 0444, dent, debug_ul_pkt_cnt);
2405 debug_create("stats", 0444, dent, debug_stats);
2406 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002407#endif
Zaheerulla Meeraa9fd5c2013-01-31 17:06:44 +05302408
2409 bam_ipc_log_txt = ipc_log_context_create(BAM_IPC_LOG_PAGES, "bam_dmux");
2410 if (!bam_ipc_log_txt) {
2411 pr_err("%s : unable to create IPC Logging Context", __func__);
Eric Holmberg878923a2012-01-10 14:28:19 -07002412 }
2413
Anurag Singhdcd8b4e2012-07-30 16:46:37 -07002414 rx_timer_interval = DEFAULT_POLLING_MIN_SLEEP;
2415
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06002416 subsys_notif_register_notifier("modem", &restart_notifier);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002417 return platform_driver_register(&bam_dmux_driver);
2418}
2419
Jeff Hugoade1f842011-08-03 15:53:59 -06002420late_initcall(bam_dmux_init); /* needs to init after SMD */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002421MODULE_DESCRIPTION("MSM BAM DMUX");
2422MODULE_LICENSE("GPL v2");