blob: 26282f726547b6ceec69309221dfed0127b554f0 [file] [log] [blame]
Arun Kumar Neelakantam406e5692013-01-17 18:58:04 +05301/* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 */
13
14/*
15 * BAM DMUX module.
16 */
17
18#define DEBUG
19
20#include <linux/delay.h>
21#include <linux/module.h>
22#include <linux/netdevice.h>
23#include <linux/platform_device.h>
24#include <linux/sched.h>
25#include <linux/skbuff.h>
26#include <linux/debugfs.h>
Jeff Hugoaab7ebc2011-09-07 16:46:04 -060027#include <linux/clk.h>
Jeff Hugoae3a85e2011-12-02 17:10:18 -070028#include <linux/wakelock.h>
Eric Holmberg878923a2012-01-10 14:28:19 -070029#include <linux/kfifo.h>
Jeff Hugo3910ee12012-08-21 14:08:20 -060030#include <linux/of.h>
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +053031#include <mach/msm_ipc_logging.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070032#include <mach/sps.h>
33#include <mach/bam_dmux.h>
Jeff Hugoade1f842011-08-03 15:53:59 -060034#include <mach/msm_smsm.h>
Jeff Hugo6e7a92a2011-10-24 05:25:13 -060035#include <mach/subsystem_notif.h>
Jeff Hugo75913c82011-12-05 15:59:01 -070036#include <mach/socinfo.h>
Jeff Hugo4838f412012-01-20 11:19:37 -070037#include <mach/subsystem_restart.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070038
39#define BAM_CH_LOCAL_OPEN 0x1
40#define BAM_CH_REMOTE_OPEN 0x2
Jeff Hugo6e7a92a2011-10-24 05:25:13 -060041#define BAM_CH_IN_RESET 0x4
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070042
43#define BAM_MUX_HDR_MAGIC_NO 0x33fc
44
Eric Holmberg006057d2012-01-11 10:10:42 -070045#define BAM_MUX_HDR_CMD_DATA 0
46#define BAM_MUX_HDR_CMD_OPEN 1
47#define BAM_MUX_HDR_CMD_CLOSE 2
48#define BAM_MUX_HDR_CMD_STATUS 3 /* unused */
49#define BAM_MUX_HDR_CMD_OPEN_NO_A2_PC 4
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070050
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070051
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -070052#define LOW_WATERMARK 2
53#define HIGH_WATERMARK 4
Anurag Singhdcd8b4e2012-07-30 16:46:37 -070054#define DEFAULT_POLLING_MIN_SLEEP (950)
55#define MAX_POLLING_SLEEP (6050)
56#define MIN_POLLING_SLEEP (950)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070057
58static int msm_bam_dmux_debug_enable;
59module_param_named(debug_enable, msm_bam_dmux_debug_enable,
60 int, S_IRUGO | S_IWUSR | S_IWGRP);
Anurag Singhdcd8b4e2012-07-30 16:46:37 -070061static int POLLING_MIN_SLEEP = 950;
62module_param_named(min_sleep, POLLING_MIN_SLEEP,
63 int, S_IRUGO | S_IWUSR | S_IWGRP);
64static int POLLING_MAX_SLEEP = 1050;
65module_param_named(max_sleep, POLLING_MAX_SLEEP,
66 int, S_IRUGO | S_IWUSR | S_IWGRP);
67static int POLLING_INACTIVITY = 40;
68module_param_named(inactivity, POLLING_INACTIVITY,
69 int, S_IRUGO | S_IWUSR | S_IWGRP);
70static int bam_adaptive_timer_enabled = 1;
71module_param_named(adaptive_timer_enabled,
72 bam_adaptive_timer_enabled,
73 int, S_IRUGO | S_IWUSR | S_IWGRP);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070074
75#if defined(DEBUG)
76static uint32_t bam_dmux_read_cnt;
77static uint32_t bam_dmux_write_cnt;
78static uint32_t bam_dmux_write_cpy_cnt;
79static uint32_t bam_dmux_write_cpy_bytes;
Eric Holmberg2fddbcd2011-11-28 18:25:57 -070080static uint32_t bam_dmux_tx_sps_failure_cnt;
Eric Holmberg6074aba2012-01-18 17:59:44 -070081static uint32_t bam_dmux_tx_stall_cnt;
Eric Holmberg1f1255d2012-02-22 13:37:21 -070082static atomic_t bam_dmux_ack_out_cnt = ATOMIC_INIT(0);
83static atomic_t bam_dmux_ack_in_cnt = ATOMIC_INIT(0);
84static atomic_t bam_dmux_a2_pwr_cntl_in_cnt = ATOMIC_INIT(0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070085
86#define DBG(x...) do { \
87 if (msm_bam_dmux_debug_enable) \
88 pr_debug(x); \
89 } while (0)
90
91#define DBG_INC_READ_CNT(x) do { \
92 bam_dmux_read_cnt += (x); \
93 if (msm_bam_dmux_debug_enable) \
94 pr_debug("%s: total read bytes %u\n", \
95 __func__, bam_dmux_read_cnt); \
96 } while (0)
97
98#define DBG_INC_WRITE_CNT(x) do { \
99 bam_dmux_write_cnt += (x); \
100 if (msm_bam_dmux_debug_enable) \
101 pr_debug("%s: total written bytes %u\n", \
102 __func__, bam_dmux_write_cnt); \
103 } while (0)
104
105#define DBG_INC_WRITE_CPY(x) do { \
106 bam_dmux_write_cpy_bytes += (x); \
107 bam_dmux_write_cpy_cnt++; \
108 if (msm_bam_dmux_debug_enable) \
109 pr_debug("%s: total write copy cnt %u, bytes %u\n", \
110 __func__, bam_dmux_write_cpy_cnt, \
111 bam_dmux_write_cpy_bytes); \
112 } while (0)
Eric Holmberg2fddbcd2011-11-28 18:25:57 -0700113
114#define DBG_INC_TX_SPS_FAILURE_CNT() do { \
115 bam_dmux_tx_sps_failure_cnt++; \
116} while (0)
117
Eric Holmberg6074aba2012-01-18 17:59:44 -0700118#define DBG_INC_TX_STALL_CNT() do { \
119 bam_dmux_tx_stall_cnt++; \
120} while (0)
121
Eric Holmberg1f1255d2012-02-22 13:37:21 -0700122#define DBG_INC_ACK_OUT_CNT() \
123 atomic_inc(&bam_dmux_ack_out_cnt)
124
125#define DBG_INC_A2_POWER_CONTROL_IN_CNT() \
126 atomic_inc(&bam_dmux_a2_pwr_cntl_in_cnt)
127
128#define DBG_INC_ACK_IN_CNT() \
129 atomic_inc(&bam_dmux_ack_in_cnt)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700130#else
131#define DBG(x...) do { } while (0)
132#define DBG_INC_READ_CNT(x...) do { } while (0)
133#define DBG_INC_WRITE_CNT(x...) do { } while (0)
134#define DBG_INC_WRITE_CPY(x...) do { } while (0)
Eric Holmberg2fddbcd2011-11-28 18:25:57 -0700135#define DBG_INC_TX_SPS_FAILURE_CNT() do { } while (0)
Eric Holmberg6074aba2012-01-18 17:59:44 -0700136#define DBG_INC_TX_STALL_CNT() do { } while (0)
Eric Holmberg1f1255d2012-02-22 13:37:21 -0700137#define DBG_INC_ACK_OUT_CNT() do { } while (0)
138#define DBG_INC_A2_POWER_CONTROL_IN_CNT() \
139 do { } while (0)
140#define DBG_INC_ACK_IN_CNT() do { } while (0)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700141#endif
142
143struct bam_ch_info {
144 uint32_t status;
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600145 void (*notify)(void *, int, unsigned long);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700146 void *priv;
147 spinlock_t lock;
Jeff Hugo7960abd2011-08-02 15:39:38 -0600148 struct platform_device *pdev;
149 char name[BAM_DMUX_CH_NAME_MAX_LEN];
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700150 int num_tx_pkts;
151 int use_wm;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700152};
153
154struct tx_pkt_info {
155 struct sk_buff *skb;
156 dma_addr_t dma_address;
157 char is_cmd;
158 uint32_t len;
159 struct work_struct work;
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600160 struct list_head list_node;
Eric Holmberg878923a2012-01-10 14:28:19 -0700161 unsigned ts_sec;
162 unsigned long ts_nsec;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700163};
164
165struct rx_pkt_info {
166 struct sk_buff *skb;
167 dma_addr_t dma_address;
168 struct work_struct work;
Jeff Hugo949080a2011-08-30 11:58:56 -0600169 struct list_head list_node;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700170};
171
172#define A2_NUM_PIPES 6
173#define A2_SUMMING_THRESHOLD 4096
174#define A2_DEFAULT_DESCRIPTORS 32
175#define A2_PHYS_BASE 0x124C2000
176#define A2_PHYS_SIZE 0x2000
177#define BUFFER_SIZE 2048
178#define NUM_BUFFERS 32
Jeff Hugo3910ee12012-08-21 14:08:20 -0600179
180#ifndef A2_BAM_IRQ
181#define A2_BAM_IRQ -1
182#endif
183
184static void *a2_phys_base;
185static uint32_t a2_phys_size;
186static int a2_bam_irq;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700187static struct sps_bam_props a2_props;
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600188static u32 a2_device_handle;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700189static struct sps_pipe *bam_tx_pipe;
190static struct sps_pipe *bam_rx_pipe;
191static struct sps_connect tx_connection;
192static struct sps_connect rx_connection;
193static struct sps_mem_buffer tx_desc_mem_buf;
194static struct sps_mem_buffer rx_desc_mem_buf;
195static struct sps_register_event tx_register_event;
Jeff Hugo33dbc002011-08-25 15:52:53 -0600196static struct sps_register_event rx_register_event;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700197
198static struct bam_ch_info bam_ch[BAM_DMUX_NUM_CHANNELS];
199static int bam_mux_initialized;
200
Jeff Hugo949080a2011-08-30 11:58:56 -0600201static int polling_mode;
Anurag Singhdcd8b4e2012-07-30 16:46:37 -0700202static unsigned long rx_timer_interval;
Jeff Hugo949080a2011-08-30 11:58:56 -0600203
204static LIST_HEAD(bam_rx_pool);
Jeff Hugoc9749932011-11-02 17:50:40 -0600205static DEFINE_MUTEX(bam_rx_pool_mutexlock);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700206static int bam_rx_pool_len;
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600207static LIST_HEAD(bam_tx_pool);
Jeff Hugoc9749932011-11-02 17:50:40 -0600208static DEFINE_SPINLOCK(bam_tx_pool_spinlock);
Eric Holmberga623da82012-07-12 09:37:09 -0600209static DEFINE_MUTEX(bam_pdev_mutexlock);
Jeff Hugo949080a2011-08-30 11:58:56 -0600210
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700211struct bam_mux_hdr {
212 uint16_t magic_num;
213 uint8_t reserved;
214 uint8_t cmd;
215 uint8_t pad_len;
216 uint8_t ch_id;
217 uint16_t pkt_len;
218};
219
Jeff Hugod98b1082011-10-24 10:30:23 -0600220static void notify_all(int event, unsigned long data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700221static void bam_mux_write_done(struct work_struct *work);
222static void handle_bam_mux_cmd(struct work_struct *work);
Jeff Hugo949080a2011-08-30 11:58:56 -0600223static void rx_timer_work_func(struct work_struct *work);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700224
Jeff Hugo949080a2011-08-30 11:58:56 -0600225static DECLARE_WORK(rx_timer_work, rx_timer_work_func);
Jeff Hugo988e7ba2012-10-03 15:53:54 -0600226static struct delayed_work queue_rx_work;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700227
228static struct workqueue_struct *bam_mux_rx_workqueue;
229static struct workqueue_struct *bam_mux_tx_workqueue;
230
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600231/* A2 power collaspe */
232#define UL_TIMEOUT_DELAY 1000 /* in ms */
Jeff Hugo0b13a352012-03-17 23:18:30 -0600233#define ENABLE_DISCONNECT_ACK 0x1
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 Hugoa82a95c2012-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 Meer6fbf32c2013-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 Meer6fbf32c2013-01-31 17:06:44 +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 Meer6fbf32c2013-01-31 17:06:44 +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 Meerf800bba2013-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)
355
Eric Holmberg878923a2012-01-10 14:28:19 -0700356static 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 Meer6fbf32c2013-01-31 17:06:44 +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 Meer6fbf32c2013-01-31 17:06:44 +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 Hugo988e7ba2012-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 Hugo988e7ba2012-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 Hugo988e7ba2012-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 Hugo988e7ba2012-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 Hugo988e7ba2012-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,
Jeff Hugoc85df962013-04-05 13:22:48 -0600436 BUFFER_SIZE, info, 0);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700437 if (ret) {
Eric Holmberg00cf8692012-07-16 14:21:19 -0600438 list_del(&info->list_node);
439 rx_len_cached = --bam_rx_pool_len;
440 mutex_unlock(&bam_rx_pool_mutexlock);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700441 DMUX_LOG_KERR("%s: sps_transfer_one failed %d\n",
442 __func__, ret);
Eric Holmberg00cf8692012-07-16 14:21:19 -0600443
444 dma_unmap_single(NULL, info->dma_address, BUFFER_SIZE,
445 DMA_FROM_DEVICE);
446
447 goto fail_skb;
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700448 }
Eric Holmberg00cf8692012-07-16 14:21:19 -0600449 mutex_unlock(&bam_rx_pool_mutexlock);
450
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700451 }
452 return;
453
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700454fail_skb:
455 dev_kfree_skb_any(info->skb);
456
457fail_info:
458 kfree(info);
459
460fail:
Arun Kumar Neelakantam799447f2012-12-13 18:06:49 +0530461 if (rx_len_cached == 0 && !in_global_reset) {
Jeff Hugo988e7ba2012-10-03 15:53:54 -0600462 DMUX_LOG_KERR("%s: rescheduling\n", __func__);
463 schedule_delayed_work(&queue_rx_work, msecs_to_jiffies(100));
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700464 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700465}
466
Jeff Hugo988e7ba2012-10-03 15:53:54 -0600467static void queue_rx_work_func(struct work_struct *work)
468{
469 queue_rx();
470}
471
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700472static void bam_mux_process_data(struct sk_buff *rx_skb)
473{
474 unsigned long flags;
475 struct bam_mux_hdr *rx_hdr;
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600476 unsigned long event_data;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700477
478 rx_hdr = (struct bam_mux_hdr *)rx_skb->data;
479
480 rx_skb->data = (unsigned char *)(rx_hdr + 1);
481 rx_skb->tail = rx_skb->data + rx_hdr->pkt_len;
482 rx_skb->len = rx_hdr->pkt_len;
Jeff Hugoee88f672011-10-04 17:14:52 -0600483 rx_skb->truesize = rx_hdr->pkt_len + sizeof(struct sk_buff);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700484
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600485 event_data = (unsigned long)(rx_skb);
486
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700487 spin_lock_irqsave(&bam_ch[rx_hdr->ch_id].lock, flags);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600488 if (bam_ch[rx_hdr->ch_id].notify)
489 bam_ch[rx_hdr->ch_id].notify(
490 bam_ch[rx_hdr->ch_id].priv, BAM_DMUX_RECEIVE,
491 event_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700492 else
493 dev_kfree_skb_any(rx_skb);
494 spin_unlock_irqrestore(&bam_ch[rx_hdr->ch_id].lock, flags);
495
496 queue_rx();
497}
498
Eric Holmberg006057d2012-01-11 10:10:42 -0700499static inline void handle_bam_mux_cmd_open(struct bam_mux_hdr *rx_hdr)
500{
501 unsigned long flags;
502 int ret;
503
Eric Holmberga623da82012-07-12 09:37:09 -0600504 mutex_lock(&bam_pdev_mutexlock);
505 if (in_global_reset) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530506 BAM_DMUX_LOG("%s: open cid %d aborted due to ssr\n",
Eric Holmberga623da82012-07-12 09:37:09 -0600507 __func__, rx_hdr->ch_id);
508 mutex_unlock(&bam_pdev_mutexlock);
509 queue_rx();
510 return;
511 }
Eric Holmberg006057d2012-01-11 10:10:42 -0700512 spin_lock_irqsave(&bam_ch[rx_hdr->ch_id].lock, flags);
513 bam_ch[rx_hdr->ch_id].status |= BAM_CH_REMOTE_OPEN;
514 bam_ch[rx_hdr->ch_id].num_tx_pkts = 0;
515 spin_unlock_irqrestore(&bam_ch[rx_hdr->ch_id].lock, flags);
Eric Holmberg006057d2012-01-11 10:10:42 -0700516 ret = platform_device_add(bam_ch[rx_hdr->ch_id].pdev);
517 if (ret)
518 pr_err("%s: platform_device_add() error: %d\n",
519 __func__, ret);
Eric Holmberga623da82012-07-12 09:37:09 -0600520 mutex_unlock(&bam_pdev_mutexlock);
521 queue_rx();
Eric Holmberg006057d2012-01-11 10:10:42 -0700522}
523
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700524static void handle_bam_mux_cmd(struct work_struct *work)
525{
526 unsigned long flags;
527 struct bam_mux_hdr *rx_hdr;
528 struct rx_pkt_info *info;
529 struct sk_buff *rx_skb;
530
531 info = container_of(work, struct rx_pkt_info, work);
532 rx_skb = info->skb;
Jeff Hugo949080a2011-08-30 11:58:56 -0600533 dma_unmap_single(NULL, info->dma_address, BUFFER_SIZE, DMA_FROM_DEVICE);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700534 kfree(info);
535
536 rx_hdr = (struct bam_mux_hdr *)rx_skb->data;
537
538 DBG_INC_READ_CNT(sizeof(struct bam_mux_hdr));
539 DBG("%s: magic %x reserved %d cmd %d pad %d ch %d len %d\n", __func__,
540 rx_hdr->magic_num, rx_hdr->reserved, rx_hdr->cmd,
541 rx_hdr->pad_len, rx_hdr->ch_id, rx_hdr->pkt_len);
542 if (rx_hdr->magic_num != BAM_MUX_HDR_MAGIC_NO) {
Eric Holmberg878923a2012-01-10 14:28:19 -0700543 DMUX_LOG_KERR("%s: dropping invalid hdr. magic %x"
544 " reserved %d cmd %d"
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700545 " pad %d ch %d len %d\n", __func__,
546 rx_hdr->magic_num, rx_hdr->reserved, rx_hdr->cmd,
547 rx_hdr->pad_len, rx_hdr->ch_id, rx_hdr->pkt_len);
548 dev_kfree_skb_any(rx_skb);
549 queue_rx();
550 return;
551 }
Eric Holmberg9ff40a52011-11-17 19:17:00 -0700552
553 if (rx_hdr->ch_id >= BAM_DMUX_NUM_CHANNELS) {
Eric Holmberg878923a2012-01-10 14:28:19 -0700554 DMUX_LOG_KERR("%s: dropping invalid LCID %d"
555 " reserved %d cmd %d"
Eric Holmberg9ff40a52011-11-17 19:17:00 -0700556 " pad %d ch %d len %d\n", __func__,
557 rx_hdr->ch_id, rx_hdr->reserved, rx_hdr->cmd,
558 rx_hdr->pad_len, rx_hdr->ch_id, rx_hdr->pkt_len);
559 dev_kfree_skb_any(rx_skb);
560 queue_rx();
561 return;
562 }
563
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700564 switch (rx_hdr->cmd) {
565 case BAM_MUX_HDR_CMD_DATA:
566 DBG_INC_READ_CNT(rx_hdr->pkt_len);
567 bam_mux_process_data(rx_skb);
568 break;
569 case BAM_MUX_HDR_CMD_OPEN:
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530570 BAM_DMUX_LOG("%s: opening cid %d PC enabled\n", __func__,
Eric Holmberg878923a2012-01-10 14:28:19 -0700571 rx_hdr->ch_id);
Eric Holmberg006057d2012-01-11 10:10:42 -0700572 handle_bam_mux_cmd_open(rx_hdr);
Jeff Hugob1e7c582012-06-20 15:02:11 -0600573 if (!(rx_hdr->reserved & ENABLE_DISCONNECT_ACK)) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530574 BAM_DMUX_LOG("%s: deactivating disconnect ack\n",
Jeff Hugod7d2b062012-07-24 14:29:56 -0600575 __func__);
Jeff Hugob1e7c582012-06-20 15:02:11 -0600576 disconnect_ack = 0;
Jeff Hugo0b13a352012-03-17 23:18:30 -0600577 }
Eric Holmberg006057d2012-01-11 10:10:42 -0700578 dev_kfree_skb_any(rx_skb);
579 break;
580 case BAM_MUX_HDR_CMD_OPEN_NO_A2_PC:
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530581 BAM_DMUX_LOG("%s: opening cid %d PC disabled\n", __func__,
Eric Holmberg006057d2012-01-11 10:10:42 -0700582 rx_hdr->ch_id);
583
584 if (!a2_pc_disabled) {
585 a2_pc_disabled = 1;
Jeff Hugo322179f2012-02-29 10:52:34 -0700586 ul_wakeup();
Eric Holmberg006057d2012-01-11 10:10:42 -0700587 }
588
589 handle_bam_mux_cmd_open(rx_hdr);
Eric Holmberge779dba2011-11-04 18:22:01 -0600590 dev_kfree_skb_any(rx_skb);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700591 break;
592 case BAM_MUX_HDR_CMD_CLOSE:
593 /* probably should drop pending write */
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530594 BAM_DMUX_LOG("%s: closing cid %d\n", __func__,
Eric Holmberg878923a2012-01-10 14:28:19 -0700595 rx_hdr->ch_id);
Eric Holmberga623da82012-07-12 09:37:09 -0600596 mutex_lock(&bam_pdev_mutexlock);
597 if (in_global_reset) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +0530598 BAM_DMUX_LOG("%s: close cid %d aborted due to ssr\n",
Eric Holmberga623da82012-07-12 09:37:09 -0600599 __func__, rx_hdr->ch_id);
600 mutex_unlock(&bam_pdev_mutexlock);
601 break;
602 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700603 spin_lock_irqsave(&bam_ch[rx_hdr->ch_id].lock, flags);
604 bam_ch[rx_hdr->ch_id].status &= ~BAM_CH_REMOTE_OPEN;
605 spin_unlock_irqrestore(&bam_ch[rx_hdr->ch_id].lock, flags);
Jeff Hugo7960abd2011-08-02 15:39:38 -0600606 platform_device_unregister(bam_ch[rx_hdr->ch_id].pdev);
607 bam_ch[rx_hdr->ch_id].pdev =
608 platform_device_alloc(bam_ch[rx_hdr->ch_id].name, 2);
609 if (!bam_ch[rx_hdr->ch_id].pdev)
610 pr_err("%s: platform_device_alloc failed\n", __func__);
Eric Holmberga623da82012-07-12 09:37:09 -0600611 mutex_unlock(&bam_pdev_mutexlock);
Eric Holmberge779dba2011-11-04 18:22:01 -0600612 dev_kfree_skb_any(rx_skb);
Eric Holmberga623da82012-07-12 09:37:09 -0600613 queue_rx();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700614 break;
615 default:
Eric Holmberg878923a2012-01-10 14:28:19 -0700616 DMUX_LOG_KERR("%s: dropping invalid hdr. magic %x"
617 " reserved %d cmd %d pad %d ch %d len %d\n",
618 __func__, rx_hdr->magic_num, rx_hdr->reserved,
619 rx_hdr->cmd, rx_hdr->pad_len, rx_hdr->ch_id,
620 rx_hdr->pkt_len);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700621 dev_kfree_skb_any(rx_skb);
622 queue_rx();
623 return;
624 }
625}
626
627static int bam_mux_write_cmd(void *data, uint32_t len)
628{
629 int rc;
630 struct tx_pkt_info *pkt;
631 dma_addr_t dma_address;
Jeff Hugo626303bf2011-11-21 11:43:28 -0700632 unsigned long flags;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700633
Eric Holmbergd83cd2b2011-11-04 15:54:17 -0600634 pkt = kmalloc(sizeof(struct tx_pkt_info), GFP_ATOMIC);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700635 if (pkt == NULL) {
636 pr_err("%s: mem alloc for tx_pkt_info failed\n", __func__);
637 rc = -ENOMEM;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700638 return rc;
639 }
640
641 dma_address = dma_map_single(NULL, data, len,
642 DMA_TO_DEVICE);
643 if (!dma_address) {
644 pr_err("%s: dma_map_single() failed\n", __func__);
Jeff Hugo96cb7482011-12-07 13:28:31 -0700645 kfree(pkt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700646 rc = -ENOMEM;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700647 return rc;
648 }
649 pkt->skb = (struct sk_buff *)(data);
650 pkt->len = len;
651 pkt->dma_address = dma_address;
652 pkt->is_cmd = 1;
Eric Holmberg878923a2012-01-10 14:28:19 -0700653 set_tx_timestamp(pkt);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600654 INIT_WORK(&pkt->work, bam_mux_write_done);
Jeff Hugo626303bf2011-11-21 11:43:28 -0700655 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600656 list_add_tail(&pkt->list_node, &bam_tx_pool);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700657 rc = sps_transfer_one(bam_tx_pipe, dma_address, len,
Jeff Hugoc85df962013-04-05 13:22:48 -0600658 pkt, SPS_IOVEC_FLAG_EOT);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600659 if (rc) {
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700660 DMUX_LOG_KERR("%s sps_transfer_one failed rc=%d\n",
661 __func__, rc);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600662 list_del(&pkt->list_node);
Eric Holmberg2fddbcd2011-11-28 18:25:57 -0700663 DBG_INC_TX_SPS_FAILURE_CNT();
Jeff Hugo626303bf2011-11-21 11:43:28 -0700664 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700665 dma_unmap_single(NULL, pkt->dma_address,
666 pkt->len,
667 DMA_TO_DEVICE);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600668 kfree(pkt);
Jeff Hugobb6da952012-01-16 15:02:42 -0700669 } else {
670 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600671 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700672
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600673 ul_packet_written = 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700674 return rc;
675}
676
677static void bam_mux_write_done(struct work_struct *work)
678{
679 struct sk_buff *skb;
680 struct bam_mux_hdr *hdr;
681 struct tx_pkt_info *info;
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700682 struct tx_pkt_info *info_expected;
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600683 unsigned long event_data;
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700684 unsigned long flags;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700685
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600686 if (in_global_reset)
687 return;
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700688
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700689 info = container_of(work, struct tx_pkt_info, work);
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700690
691 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
692 info_expected = list_first_entry(&bam_tx_pool,
693 struct tx_pkt_info, list_node);
694 if (unlikely(info != info_expected)) {
Eric Holmberg878923a2012-01-10 14:28:19 -0700695 struct tx_pkt_info *errant_pkt;
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700696
Eric Holmberg878923a2012-01-10 14:28:19 -0700697 DMUX_LOG_KERR("%s: bam_tx_pool mismatch .next=%p,"
698 " list_node=%p, ts=%u.%09lu\n",
699 __func__, bam_tx_pool.next, &info->list_node,
700 info->ts_sec, info->ts_nsec
701 );
702
703 list_for_each_entry(errant_pkt, &bam_tx_pool, list_node) {
704 DMUX_LOG_KERR("%s: node=%p ts=%u.%09lu\n", __func__,
705 &errant_pkt->list_node, errant_pkt->ts_sec,
706 errant_pkt->ts_nsec);
707
708 }
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700709 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
710 BUG();
711 }
712 list_del(&info->list_node);
713 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
714
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600715 if (info->is_cmd) {
716 kfree(info->skb);
717 kfree(info);
718 return;
719 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700720 skb = info->skb;
721 kfree(info);
722 hdr = (struct bam_mux_hdr *)skb->data;
Eric Holmberg9fdef262012-02-14 11:46:05 -0700723 DBG_INC_WRITE_CNT(skb->len);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600724 event_data = (unsigned long)(skb);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700725 spin_lock_irqsave(&bam_ch[hdr->ch_id].lock, flags);
726 bam_ch[hdr->ch_id].num_tx_pkts--;
727 spin_unlock_irqrestore(&bam_ch[hdr->ch_id].lock, flags);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600728 if (bam_ch[hdr->ch_id].notify)
729 bam_ch[hdr->ch_id].notify(
730 bam_ch[hdr->ch_id].priv, BAM_DMUX_WRITE_DONE,
731 event_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700732 else
733 dev_kfree_skb_any(skb);
734}
735
736int msm_bam_dmux_write(uint32_t id, struct sk_buff *skb)
737{
738 int rc = 0;
739 struct bam_mux_hdr *hdr;
740 unsigned long flags;
741 struct sk_buff *new_skb = NULL;
742 dma_addr_t dma_address;
743 struct tx_pkt_info *pkt;
744
745 if (id >= BAM_DMUX_NUM_CHANNELS)
746 return -EINVAL;
747 if (!skb)
748 return -EINVAL;
749 if (!bam_mux_initialized)
750 return -ENODEV;
751
752 DBG("%s: writing to ch %d len %d\n", __func__, id, skb->len);
753 spin_lock_irqsave(&bam_ch[id].lock, flags);
754 if (!bam_ch_is_open(id)) {
755 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
756 pr_err("%s: port not open: %d\n", __func__, bam_ch[id].status);
757 return -ENODEV;
758 }
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700759
760 if (bam_ch[id].use_wm &&
761 (bam_ch[id].num_tx_pkts >= HIGH_WATERMARK)) {
762 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
763 pr_err("%s: watermark exceeded: %d\n", __func__, id);
764 return -EAGAIN;
765 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700766 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
767
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600768 read_lock(&ul_wakeup_lock);
Jeff Hugo061ce672011-10-21 17:15:32 -0600769 if (!bam_is_connected) {
770 read_unlock(&ul_wakeup_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600771 ul_wakeup();
Jeff Hugo4838f412012-01-20 11:19:37 -0700772 if (unlikely(in_global_reset == 1))
773 return -EFAULT;
Jeff Hugo061ce672011-10-21 17:15:32 -0600774 read_lock(&ul_wakeup_lock);
Jeff Hugod98b1082011-10-24 10:30:23 -0600775 notify_all(BAM_DMUX_UL_CONNECTED, (unsigned long)(NULL));
Jeff Hugo061ce672011-10-21 17:15:32 -0600776 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600777
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700778 /* if skb do not have any tailroom for padding,
779 copy the skb into a new expanded skb */
780 if ((skb->len & 0x3) && (skb_tailroom(skb) < (4 - (skb->len & 0x3)))) {
781 /* revisit, probably dev_alloc_skb and memcpy is effecient */
782 new_skb = skb_copy_expand(skb, skb_headroom(skb),
783 4 - (skb->len & 0x3), GFP_ATOMIC);
784 if (new_skb == NULL) {
785 pr_err("%s: cannot allocate skb\n", __func__);
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600786 goto write_fail;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700787 }
788 dev_kfree_skb_any(skb);
789 skb = new_skb;
790 DBG_INC_WRITE_CPY(skb->len);
791 }
792
793 hdr = (struct bam_mux_hdr *)skb_push(skb, sizeof(struct bam_mux_hdr));
794
795 /* caller should allocate for hdr and padding
796 hdr is fine, padding is tricky */
797 hdr->magic_num = BAM_MUX_HDR_MAGIC_NO;
798 hdr->cmd = BAM_MUX_HDR_CMD_DATA;
799 hdr->reserved = 0;
800 hdr->ch_id = id;
801 hdr->pkt_len = skb->len - sizeof(struct bam_mux_hdr);
802 if (skb->len & 0x3)
803 skb_put(skb, 4 - (skb->len & 0x3));
804
805 hdr->pad_len = skb->len - (sizeof(struct bam_mux_hdr) + hdr->pkt_len);
806
807 DBG("%s: data %p, tail %p skb len %d pkt len %d pad len %d\n",
808 __func__, skb->data, skb->tail, skb->len,
809 hdr->pkt_len, hdr->pad_len);
810
811 pkt = kmalloc(sizeof(struct tx_pkt_info), GFP_ATOMIC);
812 if (pkt == NULL) {
813 pr_err("%s: mem alloc for tx_pkt_info failed\n", __func__);
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600814 goto write_fail2;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700815 }
816
817 dma_address = dma_map_single(NULL, skb->data, skb->len,
818 DMA_TO_DEVICE);
819 if (!dma_address) {
820 pr_err("%s: dma_map_single() failed\n", __func__);
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600821 goto write_fail3;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700822 }
823 pkt->skb = skb;
824 pkt->dma_address = dma_address;
825 pkt->is_cmd = 0;
Eric Holmberg878923a2012-01-10 14:28:19 -0700826 set_tx_timestamp(pkt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700827 INIT_WORK(&pkt->work, bam_mux_write_done);
Jeff Hugo626303bf2011-11-21 11:43:28 -0700828 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600829 list_add_tail(&pkt->list_node, &bam_tx_pool);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700830 rc = sps_transfer_one(bam_tx_pipe, dma_address, skb->len,
Jeff Hugoc85df962013-04-05 13:22:48 -0600831 pkt, SPS_IOVEC_FLAG_EOT);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600832 if (rc) {
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700833 DMUX_LOG_KERR("%s sps_transfer_one failed rc=%d\n",
834 __func__, rc);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600835 list_del(&pkt->list_node);
Eric Holmberg2fddbcd2011-11-28 18:25:57 -0700836 DBG_INC_TX_SPS_FAILURE_CNT();
Jeff Hugo626303bf2011-11-21 11:43:28 -0700837 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700838 dma_unmap_single(NULL, pkt->dma_address,
839 pkt->skb->len, DMA_TO_DEVICE);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600840 kfree(pkt);
Jeff Hugo872bd062011-11-15 17:47:21 -0700841 if (new_skb)
842 dev_kfree_skb_any(new_skb);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700843 } else {
Jeff Hugobb6da952012-01-16 15:02:42 -0700844 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700845 spin_lock_irqsave(&bam_ch[id].lock, flags);
846 bam_ch[id].num_tx_pkts++;
847 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600848 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600849 ul_packet_written = 1;
850 read_unlock(&ul_wakeup_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700851 return rc;
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600852
853write_fail3:
854 kfree(pkt);
855write_fail2:
Arun Kumar Neelakantam406e5692013-01-17 18:58:04 +0530856 skb_pull(skb, sizeof(struct bam_mux_hdr));
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600857 if (new_skb)
858 dev_kfree_skb_any(new_skb);
859write_fail:
860 read_unlock(&ul_wakeup_lock);
861 return -ENOMEM;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700862}
863
864int msm_bam_dmux_open(uint32_t id, void *priv,
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600865 void (*notify)(void *, int, unsigned long))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700866{
867 struct bam_mux_hdr *hdr;
868 unsigned long flags;
869 int rc = 0;
870
871 DBG("%s: opening ch %d\n", __func__, id);
Eric Holmberg5d775432011-11-09 10:23:35 -0700872 if (!bam_mux_initialized) {
873 DBG("%s: not inititialized\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700874 return -ENODEV;
Eric Holmberg5d775432011-11-09 10:23:35 -0700875 }
876 if (id >= BAM_DMUX_NUM_CHANNELS) {
877 pr_err("%s: invalid channel id %d\n", __func__, id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700878 return -EINVAL;
Eric Holmberg5d775432011-11-09 10:23:35 -0700879 }
880 if (notify == NULL) {
881 pr_err("%s: notify function is NULL\n", __func__);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600882 return -EINVAL;
Eric Holmberg5d775432011-11-09 10:23:35 -0700883 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700884
885 hdr = kmalloc(sizeof(struct bam_mux_hdr), GFP_KERNEL);
886 if (hdr == NULL) {
887 pr_err("%s: hdr kmalloc failed. ch: %d\n", __func__, id);
888 return -ENOMEM;
889 }
890 spin_lock_irqsave(&bam_ch[id].lock, flags);
891 if (bam_ch_is_open(id)) {
892 DBG("%s: Already opened %d\n", __func__, id);
893 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
894 kfree(hdr);
895 goto open_done;
896 }
897 if (!bam_ch_is_remote_open(id)) {
898 DBG("%s: Remote not open; ch: %d\n", __func__, id);
899 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
900 kfree(hdr);
Eric Holmberg5d775432011-11-09 10:23:35 -0700901 return -ENODEV;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700902 }
903
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600904 bam_ch[id].notify = notify;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700905 bam_ch[id].priv = priv;
906 bam_ch[id].status |= BAM_CH_LOCAL_OPEN;
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700907 bam_ch[id].num_tx_pkts = 0;
908 bam_ch[id].use_wm = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700909 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
910
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600911 read_lock(&ul_wakeup_lock);
Jeff Hugo061ce672011-10-21 17:15:32 -0600912 if (!bam_is_connected) {
913 read_unlock(&ul_wakeup_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600914 ul_wakeup();
Brent Hronik96630422013-05-01 16:38:43 -0600915 if (unlikely(in_global_reset == 1)) {
916 kfree(hdr);
Jeff Hugo4838f412012-01-20 11:19:37 -0700917 return -EFAULT;
Brent Hronik96630422013-05-01 16:38:43 -0600918 }
Jeff Hugo061ce672011-10-21 17:15:32 -0600919 read_lock(&ul_wakeup_lock);
Jeff Hugod98b1082011-10-24 10:30:23 -0600920 notify_all(BAM_DMUX_UL_CONNECTED, (unsigned long)(NULL));
Jeff Hugo061ce672011-10-21 17:15:32 -0600921 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600922
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700923 hdr->magic_num = BAM_MUX_HDR_MAGIC_NO;
924 hdr->cmd = BAM_MUX_HDR_CMD_OPEN;
925 hdr->reserved = 0;
926 hdr->ch_id = id;
927 hdr->pkt_len = 0;
928 hdr->pad_len = 0;
929
930 rc = bam_mux_write_cmd((void *)hdr, sizeof(struct bam_mux_hdr));
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600931 read_unlock(&ul_wakeup_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700932
933open_done:
934 DBG("%s: opened ch %d\n", __func__, id);
935 return rc;
936}
937
938int msm_bam_dmux_close(uint32_t id)
939{
940 struct bam_mux_hdr *hdr;
941 unsigned long flags;
942 int rc;
943
944 if (id >= BAM_DMUX_NUM_CHANNELS)
945 return -EINVAL;
946 DBG("%s: closing ch %d\n", __func__, id);
947 if (!bam_mux_initialized)
948 return -ENODEV;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700949
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600950 read_lock(&ul_wakeup_lock);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600951 if (!bam_is_connected && !bam_ch_is_in_reset(id)) {
Jeff Hugo061ce672011-10-21 17:15:32 -0600952 read_unlock(&ul_wakeup_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600953 ul_wakeup();
Jeff Hugo4838f412012-01-20 11:19:37 -0700954 if (unlikely(in_global_reset == 1))
955 return -EFAULT;
Jeff Hugo061ce672011-10-21 17:15:32 -0600956 read_lock(&ul_wakeup_lock);
Jeff Hugod98b1082011-10-24 10:30:23 -0600957 notify_all(BAM_DMUX_UL_CONNECTED, (unsigned long)(NULL));
Jeff Hugo061ce672011-10-21 17:15:32 -0600958 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600959
Jeff Hugo061ce672011-10-21 17:15:32 -0600960 spin_lock_irqsave(&bam_ch[id].lock, flags);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600961 bam_ch[id].notify = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700962 bam_ch[id].priv = NULL;
963 bam_ch[id].status &= ~BAM_CH_LOCAL_OPEN;
964 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
965
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600966 if (bam_ch_is_in_reset(id)) {
967 read_unlock(&ul_wakeup_lock);
968 bam_ch[id].status &= ~BAM_CH_IN_RESET;
969 return 0;
970 }
971
Jeff Hugobb5802f2011-11-02 17:10:29 -0600972 hdr = kmalloc(sizeof(struct bam_mux_hdr), GFP_ATOMIC);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700973 if (hdr == NULL) {
974 pr_err("%s: hdr kmalloc failed. ch: %d\n", __func__, id);
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600975 read_unlock(&ul_wakeup_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700976 return -ENOMEM;
977 }
978 hdr->magic_num = BAM_MUX_HDR_MAGIC_NO;
979 hdr->cmd = BAM_MUX_HDR_CMD_CLOSE;
980 hdr->reserved = 0;
981 hdr->ch_id = id;
982 hdr->pkt_len = 0;
983 hdr->pad_len = 0;
984
985 rc = bam_mux_write_cmd((void *)hdr, sizeof(struct bam_mux_hdr));
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600986 read_unlock(&ul_wakeup_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700987
988 DBG("%s: closed ch %d\n", __func__, id);
989 return rc;
990}
991
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700992int msm_bam_dmux_is_ch_full(uint32_t id)
993{
994 unsigned long flags;
995 int ret;
996
997 if (id >= BAM_DMUX_NUM_CHANNELS)
998 return -EINVAL;
999
1000 spin_lock_irqsave(&bam_ch[id].lock, flags);
1001 bam_ch[id].use_wm = 1;
1002 ret = bam_ch[id].num_tx_pkts >= HIGH_WATERMARK;
1003 DBG("%s: ch %d num tx pkts=%d, HWM=%d\n", __func__,
1004 id, bam_ch[id].num_tx_pkts, ret);
1005 if (!bam_ch_is_local_open(id)) {
1006 ret = -ENODEV;
1007 pr_err("%s: port not open: %d\n", __func__, bam_ch[id].status);
1008 }
1009 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
1010
1011 return ret;
1012}
1013
1014int msm_bam_dmux_is_ch_low(uint32_t id)
1015{
Eric Holmberged3ca0a2012-04-09 15:44:58 -06001016 unsigned long flags;
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -07001017 int ret;
1018
1019 if (id >= BAM_DMUX_NUM_CHANNELS)
1020 return -EINVAL;
1021
Eric Holmberged3ca0a2012-04-09 15:44:58 -06001022 spin_lock_irqsave(&bam_ch[id].lock, flags);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -07001023 bam_ch[id].use_wm = 1;
1024 ret = bam_ch[id].num_tx_pkts <= LOW_WATERMARK;
1025 DBG("%s: ch %d num tx pkts=%d, LWM=%d\n", __func__,
1026 id, bam_ch[id].num_tx_pkts, ret);
1027 if (!bam_ch_is_local_open(id)) {
1028 ret = -ENODEV;
1029 pr_err("%s: port not open: %d\n", __func__, bam_ch[id].status);
1030 }
Eric Holmberged3ca0a2012-04-09 15:44:58 -06001031 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -07001032
1033 return ret;
1034}
1035
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001036static void rx_switch_to_interrupt_mode(void)
1037{
1038 struct sps_connect cur_rx_conn;
1039 struct sps_iovec iov;
1040 struct rx_pkt_info *info;
1041 int ret;
1042
1043 /*
1044 * Attempt to enable interrupts - if this fails,
1045 * continue polling and we will retry later.
1046 */
1047 ret = sps_get_config(bam_rx_pipe, &cur_rx_conn);
1048 if (ret) {
1049 pr_err("%s: sps_get_config() failed %d\n", __func__, ret);
1050 goto fail;
1051 }
1052
1053 rx_register_event.options = SPS_O_EOT;
1054 ret = sps_register_event(bam_rx_pipe, &rx_register_event);
1055 if (ret) {
1056 pr_err("%s: sps_register_event() failed %d\n", __func__, ret);
1057 goto fail;
1058 }
1059
1060 cur_rx_conn.options = SPS_O_AUTO_ENABLE |
1061 SPS_O_EOT | SPS_O_ACK_TRANSFERS;
1062 ret = sps_set_config(bam_rx_pipe, &cur_rx_conn);
1063 if (ret) {
1064 pr_err("%s: sps_set_config() failed %d\n", __func__, ret);
1065 goto fail;
1066 }
1067 polling_mode = 0;
Eric Holmberg006057d2012-01-11 10:10:42 -07001068 release_wakelock();
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001069
1070 /* handle any rx packets before interrupt was enabled */
1071 while (bam_connection_is_active && !polling_mode) {
1072 ret = sps_get_iovec(bam_rx_pipe, &iov);
1073 if (ret) {
1074 pr_err("%s: sps_get_iovec failed %d\n",
1075 __func__, ret);
1076 break;
1077 }
1078 if (iov.addr == 0)
1079 break;
1080
1081 mutex_lock(&bam_rx_pool_mutexlock);
1082 if (unlikely(list_empty(&bam_rx_pool))) {
Eric Holmberg00cf8692012-07-16 14:21:19 -06001083 DMUX_LOG_KERR("%s: have iovec %p but rx pool empty\n",
1084 __func__, (void *)iov.addr);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001085 mutex_unlock(&bam_rx_pool_mutexlock);
1086 continue;
1087 }
1088 info = list_first_entry(&bam_rx_pool, struct rx_pkt_info,
1089 list_node);
Eric Holmberg00cf8692012-07-16 14:21:19 -06001090 if (info->dma_address != iov.addr) {
1091 DMUX_LOG_KERR("%s: iovec %p != dma %p\n",
1092 __func__,
1093 (void *)iov.addr,
1094 (void *)info->dma_address);
1095 list_for_each_entry(info, &bam_rx_pool, list_node) {
1096 DMUX_LOG_KERR("%s: dma %p\n", __func__,
1097 (void *)info->dma_address);
1098 if (iov.addr == info->dma_address)
1099 break;
1100 }
1101 }
1102 BUG_ON(info->dma_address != iov.addr);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001103 list_del(&info->list_node);
Eric Holmbergb5b08e52012-01-20 14:19:00 -07001104 --bam_rx_pool_len;
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001105 mutex_unlock(&bam_rx_pool_mutexlock);
1106 handle_bam_mux_cmd(&info->work);
1107 }
1108 return;
1109
1110fail:
1111 pr_err("%s: reverting to polling\n", __func__);
Jeff Hugofff43af92012-03-29 17:54:52 -06001112 queue_work_on(0, bam_mux_rx_workqueue, &rx_timer_work);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001113}
1114
Jeff Hugo949080a2011-08-30 11:58:56 -06001115static void rx_timer_work_func(struct work_struct *work)
1116{
1117 struct sps_iovec iov;
Jeff Hugo949080a2011-08-30 11:58:56 -06001118 struct rx_pkt_info *info;
1119 int inactive_cycles = 0;
1120 int ret;
Anurag Singhdcd8b4e2012-07-30 16:46:37 -07001121 u32 buffs_unused, buffs_used;
Jeff Hugo949080a2011-08-30 11:58:56 -06001122
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001123 while (bam_connection_is_active) { /* timer loop */
Jeff Hugo949080a2011-08-30 11:58:56 -06001124 ++inactive_cycles;
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001125 while (bam_connection_is_active) { /* deplete queue loop */
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001126 if (in_global_reset)
1127 return;
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001128
1129 ret = sps_get_iovec(bam_rx_pipe, &iov);
1130 if (ret) {
1131 pr_err("%s: sps_get_iovec failed %d\n",
1132 __func__, ret);
1133 break;
1134 }
Jeff Hugo949080a2011-08-30 11:58:56 -06001135 if (iov.addr == 0)
1136 break;
1137 inactive_cycles = 0;
Jeff Hugoc9749932011-11-02 17:50:40 -06001138 mutex_lock(&bam_rx_pool_mutexlock);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001139 if (unlikely(list_empty(&bam_rx_pool))) {
Eric Holmberg00cf8692012-07-16 14:21:19 -06001140 DMUX_LOG_KERR(
1141 "%s: have iovec %p but rx pool empty\n",
1142 __func__, (void *)iov.addr);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001143 mutex_unlock(&bam_rx_pool_mutexlock);
1144 continue;
1145 }
1146 info = list_first_entry(&bam_rx_pool,
1147 struct rx_pkt_info, list_node);
Eric Holmberg00cf8692012-07-16 14:21:19 -06001148 if (info->dma_address != iov.addr) {
1149 DMUX_LOG_KERR("%s: iovec %p != dma %p\n",
1150 __func__,
1151 (void *)iov.addr,
1152 (void *)info->dma_address);
1153 list_for_each_entry(info, &bam_rx_pool,
1154 list_node) {
1155 DMUX_LOG_KERR("%s: dma %p\n", __func__,
1156 (void *)info->dma_address);
1157 if (iov.addr == info->dma_address)
1158 break;
1159 }
1160 }
1161 BUG_ON(info->dma_address != iov.addr);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001162 list_del(&info->list_node);
Eric Holmberg00cf8692012-07-16 14:21:19 -06001163 --bam_rx_pool_len;
Jeff Hugoc9749932011-11-02 17:50:40 -06001164 mutex_unlock(&bam_rx_pool_mutexlock);
Jeff Hugo949080a2011-08-30 11:58:56 -06001165 handle_bam_mux_cmd(&info->work);
1166 }
1167
Anurag Singhdcd8b4e2012-07-30 16:46:37 -07001168 if (inactive_cycles >= POLLING_INACTIVITY) {
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001169 rx_switch_to_interrupt_mode();
1170 break;
Jeff Hugo949080a2011-08-30 11:58:56 -06001171 }
1172
Anurag Singhdcd8b4e2012-07-30 16:46:37 -07001173 if (bam_adaptive_timer_enabled) {
1174 usleep_range(rx_timer_interval, rx_timer_interval + 50);
1175
1176 ret = sps_get_unused_desc_num(bam_rx_pipe,
1177 &buffs_unused);
1178
1179 if (ret) {
1180 pr_err("%s: error getting num buffers unused after sleep\n",
1181 __func__);
1182
1183 break;
1184 }
1185
1186 buffs_used = NUM_BUFFERS - buffs_unused;
1187
1188 if (buffs_unused == 0) {
1189 rx_timer_interval = MIN_POLLING_SLEEP;
1190 } else {
1191 if (buffs_used > 0) {
1192 rx_timer_interval =
1193 (2 * NUM_BUFFERS *
1194 rx_timer_interval)/
1195 (3 * buffs_used);
1196 } else {
1197 rx_timer_interval =
1198 MAX_POLLING_SLEEP;
1199 }
1200 }
1201
1202 if (rx_timer_interval > MAX_POLLING_SLEEP)
1203 rx_timer_interval = MAX_POLLING_SLEEP;
1204 else if (rx_timer_interval < MIN_POLLING_SLEEP)
1205 rx_timer_interval = MIN_POLLING_SLEEP;
1206 } else {
1207 usleep_range(POLLING_MIN_SLEEP, POLLING_MAX_SLEEP);
1208 }
Jeff Hugo949080a2011-08-30 11:58:56 -06001209 }
1210}
1211
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001212static void bam_mux_tx_notify(struct sps_event_notify *notify)
1213{
1214 struct tx_pkt_info *pkt;
1215
1216 DBG("%s: event %d notified\n", __func__, notify->event_id);
1217
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001218 if (in_global_reset)
1219 return;
1220
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001221 switch (notify->event_id) {
1222 case SPS_EVENT_EOT:
1223 pkt = notify->data.transfer.user;
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001224 if (!pkt->is_cmd)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001225 dma_unmap_single(NULL, pkt->dma_address,
1226 pkt->skb->len,
1227 DMA_TO_DEVICE);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001228 else
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001229 dma_unmap_single(NULL, pkt->dma_address,
1230 pkt->len,
1231 DMA_TO_DEVICE);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001232 queue_work(bam_mux_tx_workqueue, &pkt->work);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001233 break;
1234 default:
1235 pr_err("%s: recieved unexpected event id %d\n", __func__,
1236 notify->event_id);
1237 }
1238}
1239
Jeff Hugo33dbc002011-08-25 15:52:53 -06001240static void bam_mux_rx_notify(struct sps_event_notify *notify)
1241{
Jeff Hugo949080a2011-08-30 11:58:56 -06001242 int ret;
1243 struct sps_connect cur_rx_conn;
Jeff Hugo33dbc002011-08-25 15:52:53 -06001244
1245 DBG("%s: event %d notified\n", __func__, notify->event_id);
1246
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001247 if (in_global_reset)
1248 return;
1249
Jeff Hugo33dbc002011-08-25 15:52:53 -06001250 switch (notify->event_id) {
1251 case SPS_EVENT_EOT:
Jeff Hugo949080a2011-08-30 11:58:56 -06001252 /* attempt to disable interrupts in this pipe */
1253 if (!polling_mode) {
1254 ret = sps_get_config(bam_rx_pipe, &cur_rx_conn);
1255 if (ret) {
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001256 pr_err("%s: sps_get_config() failed %d, interrupts"
1257 " not disabled\n", __func__, ret);
Jeff Hugo949080a2011-08-30 11:58:56 -06001258 break;
1259 }
Jeff Hugoa9d32ba2011-11-21 14:59:48 -07001260 cur_rx_conn.options = SPS_O_AUTO_ENABLE |
Jeff Hugo949080a2011-08-30 11:58:56 -06001261 SPS_O_ACK_TRANSFERS | SPS_O_POLL;
1262 ret = sps_set_config(bam_rx_pipe, &cur_rx_conn);
1263 if (ret) {
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001264 pr_err("%s: sps_set_config() failed %d, interrupts"
1265 " not disabled\n", __func__, ret);
Jeff Hugo949080a2011-08-30 11:58:56 -06001266 break;
1267 }
Eric Holmberg006057d2012-01-11 10:10:42 -07001268 grab_wakelock();
Jeff Hugo949080a2011-08-30 11:58:56 -06001269 polling_mode = 1;
Jeff Hugofff43af92012-03-29 17:54:52 -06001270 /*
1271 * run on core 0 so that netif_rx() in rmnet uses only
1272 * one queue
1273 */
1274 queue_work_on(0, bam_mux_rx_workqueue, &rx_timer_work);
Jeff Hugo949080a2011-08-30 11:58:56 -06001275 }
Jeff Hugo33dbc002011-08-25 15:52:53 -06001276 break;
1277 default:
1278 pr_err("%s: recieved unexpected event id %d\n", __func__,
1279 notify->event_id);
1280 }
1281}
1282
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001283#ifdef CONFIG_DEBUG_FS
1284
1285static int debug_tbl(char *buf, int max)
1286{
1287 int i = 0;
1288 int j;
1289
1290 for (j = 0; j < BAM_DMUX_NUM_CHANNELS; ++j) {
1291 i += scnprintf(buf + i, max - i,
1292 "ch%02d local open=%s remote open=%s\n",
1293 j, bam_ch_is_local_open(j) ? "Y" : "N",
1294 bam_ch_is_remote_open(j) ? "Y" : "N");
1295 }
1296
1297 return i;
1298}
1299
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07001300static int debug_ul_pkt_cnt(char *buf, int max)
1301{
1302 struct list_head *p;
1303 unsigned long flags;
1304 int n = 0;
1305
1306 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
1307 __list_for_each(p, &bam_tx_pool) {
1308 ++n;
1309 }
1310 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
1311
1312 return scnprintf(buf, max, "Number of UL packets in flight: %d\n", n);
1313}
1314
1315static int debug_stats(char *buf, int max)
1316{
1317 int i = 0;
1318
1319 i += scnprintf(buf + i, max - i,
Eric Holmberg9fdef262012-02-14 11:46:05 -07001320 "skb read cnt: %u\n"
1321 "skb write cnt: %u\n"
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07001322 "skb copy cnt: %u\n"
1323 "skb copy bytes: %u\n"
Eric Holmberg6074aba2012-01-18 17:59:44 -07001324 "sps tx failures: %u\n"
Eric Holmbergb5b08e52012-01-20 14:19:00 -07001325 "sps tx stalls: %u\n"
Eric Holmberg1f1255d2012-02-22 13:37:21 -07001326 "rx queue len: %d\n"
1327 "a2 ack out cnt: %d\n"
1328 "a2 ack in cnt: %d\n"
1329 "a2 pwr cntl in: %d\n",
Eric Holmberg9fdef262012-02-14 11:46:05 -07001330 bam_dmux_read_cnt,
1331 bam_dmux_write_cnt,
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07001332 bam_dmux_write_cpy_cnt,
1333 bam_dmux_write_cpy_bytes,
Eric Holmberg6074aba2012-01-18 17:59:44 -07001334 bam_dmux_tx_sps_failure_cnt,
Eric Holmbergb5b08e52012-01-20 14:19:00 -07001335 bam_dmux_tx_stall_cnt,
Eric Holmberg1f1255d2012-02-22 13:37:21 -07001336 bam_rx_pool_len,
1337 atomic_read(&bam_dmux_ack_out_cnt),
1338 atomic_read(&bam_dmux_ack_in_cnt),
1339 atomic_read(&bam_dmux_a2_pwr_cntl_in_cnt)
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07001340 );
1341
1342 return i;
1343}
1344
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001345#define DEBUG_BUFMAX 4096
1346static char debug_buffer[DEBUG_BUFMAX];
1347
1348static ssize_t debug_read(struct file *file, char __user *buf,
1349 size_t count, loff_t *ppos)
1350{
1351 int (*fill)(char *buf, int max) = file->private_data;
1352 int bsize = fill(debug_buffer, DEBUG_BUFMAX);
1353 return simple_read_from_buffer(buf, count, ppos, debug_buffer, bsize);
1354}
1355
1356static int debug_open(struct inode *inode, struct file *file)
1357{
1358 file->private_data = inode->i_private;
1359 return 0;
1360}
1361
1362
1363static const struct file_operations debug_ops = {
1364 .read = debug_read,
1365 .open = debug_open,
1366};
1367
1368static void debug_create(const char *name, mode_t mode,
1369 struct dentry *dent,
1370 int (*fill)(char *buf, int max))
1371{
Eric Holmberge4ac80b2012-01-12 09:21:59 -07001372 struct dentry *file;
1373
1374 file = debugfs_create_file(name, mode, dent, fill, &debug_ops);
1375 if (IS_ERR(file))
1376 pr_err("%s: debugfs create failed %d\n", __func__,
1377 (int)PTR_ERR(file));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001378}
1379
1380#endif
1381
Jeff Hugod98b1082011-10-24 10:30:23 -06001382static void notify_all(int event, unsigned long data)
1383{
1384 int i;
Jeff Hugocb798022012-04-09 14:55:40 -06001385 struct list_head *temp;
1386 struct outside_notify_func *func;
Jeff Hugod98b1082011-10-24 10:30:23 -06001387
Jeff Hugoac8152a2013-04-19 11:05:19 -06001388 BAM_DMUX_LOG("%s: event=%d, data=%lu\n", __func__, event, data);
1389
Jeff Hugod98b1082011-10-24 10:30:23 -06001390 for (i = 0; i < BAM_DMUX_NUM_CHANNELS; ++i) {
Jeff Hugoac8152a2013-04-19 11:05:19 -06001391 if (bam_ch_is_open(i))
Jeff Hugod98b1082011-10-24 10:30:23 -06001392 bam_ch[i].notify(bam_ch[i].priv, event, data);
1393 }
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 Meer6fbf32c2013-01-31 17:06:44 +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 Meer6fbf32c2013-01-31 17:06:44 +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 Meer6fbf32c2013-01-31 17:06:44 +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 Meer6fbf32c2013-01-31 17:06:44 +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{
Jeff Hugob8156d72013-06-04 12:51:10 -06001578 int ret = 0;
1579
1580 DMUX_LOG_KERR("%s: modem timeout: BAM DMUX disabled for SSR\n",
1581 __func__);
Eric Holmberg90285e22012-02-22 12:33:05 -07001582 in_global_reset = 1;
Jeff Hugob8156d72013-06-04 12:51:10 -06001583 ret = subsystem_restart("modem");
1584 if (ret == -ENODEV)
1585 panic("modem subsystem restart failed\n");
Eric Holmberg90285e22012-02-22 12:33:05 -07001586 return 1;
Jeff Hugo4838f412012-01-20 11:19:37 -07001587}
1588
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001589static void ul_wakeup(void)
1590{
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001591 int ret;
Jeff Hugo5f57ec92012-05-14 13:34:28 -06001592 int do_vote_dfab = 0;
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001593
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001594 mutex_lock(&wakeup_lock);
1595 if (bam_is_connected) { /* bam got connected before lock grabbed */
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301596 BAM_DMUX_LOG("%s Already awake\n", __func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001597 mutex_unlock(&wakeup_lock);
1598 return;
1599 }
Eric Holmberg878923a2012-01-10 14:28:19 -07001600
Jeff Hugoc2696142012-05-03 11:42:13 -06001601 /*
Jeff Hugof5001732012-08-27 13:19:09 -06001602 * if this gets hit, that means restart_notifier_cb() has started
1603 * but probably not finished, thus we know SSR has happened, but
1604 * haven't been able to send that info to our clients yet.
1605 * in that case, abort the ul_wakeup() so that we don't undo any
1606 * work restart_notifier_cb() has done. The clients will be notified
1607 * shortly. No cleanup necessary (reschedule the wakeup) as our and
1608 * their SSR handling will cover it
1609 */
1610 if (unlikely(in_global_reset == 1)) {
1611 mutex_unlock(&wakeup_lock);
1612 return;
1613 }
1614
1615 /*
Jeff Hugoc2696142012-05-03 11:42:13 -06001616 * if someone is voting for UL before bam is inited (modem up first
1617 * time), set flag for init to kickoff ul wakeup once bam is inited
1618 */
1619 mutex_lock(&delayed_ul_vote_lock);
1620 if (unlikely(!bam_mux_initialized)) {
1621 need_delayed_ul_vote = 1;
1622 mutex_unlock(&delayed_ul_vote_lock);
1623 mutex_unlock(&wakeup_lock);
1624 return;
1625 }
1626 mutex_unlock(&delayed_ul_vote_lock);
1627
Eric Holmberg006057d2012-01-11 10:10:42 -07001628 if (a2_pc_disabled) {
1629 /*
1630 * don't grab the wakelock the first time because it is
1631 * already grabbed when a2 powers on
1632 */
Jeff Hugo5f57ec92012-05-14 13:34:28 -06001633 if (likely(a2_pc_disabled_wakelock_skipped)) {
Eric Holmberg006057d2012-01-11 10:10:42 -07001634 grab_wakelock();
Jeff Hugo5f57ec92012-05-14 13:34:28 -06001635 do_vote_dfab = 1; /* vote must occur after wait */
1636 } else {
Jeff Hugo583a6da2012-02-03 11:37:30 -07001637 a2_pc_disabled_wakelock_skipped = 1;
Jeff Hugo5f57ec92012-05-14 13:34:28 -06001638 }
Eric Holmberg006057d2012-01-11 10:10:42 -07001639 if (wait_for_dfab) {
Jeff Hugo66f7f1e2012-01-16 14:30:42 -07001640 ret = wait_for_completion_timeout(
Eric Holmberg006057d2012-01-11 10:10:42 -07001641 &dfab_unvote_completion, HZ);
1642 BUG_ON(ret == 0);
1643 }
Jeff Hugo5f57ec92012-05-14 13:34:28 -06001644 if (likely(do_vote_dfab))
1645 vote_dfab();
Eric Holmberg006057d2012-01-11 10:10:42 -07001646 schedule_delayed_work(&ul_timeout_work,
1647 msecs_to_jiffies(UL_TIMEOUT_DELAY));
1648 bam_is_connected = 1;
1649 mutex_unlock(&wakeup_lock);
1650 return;
1651 }
1652
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001653 /*
1654 * must wait for the previous power down request to have been acked
1655 * chances are it already came in and this will just fall through
1656 * instead of waiting
1657 */
1658 if (wait_for_ack) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301659 BAM_DMUX_LOG("%s waiting for previous ack\n", __func__);
Jeff Hugo66f7f1e2012-01-16 14:30:42 -07001660 ret = wait_for_completion_timeout(
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001661 &ul_wakeup_ack_completion, HZ);
Eric Holmberg006057d2012-01-11 10:10:42 -07001662 wait_for_ack = 0;
Jeff Hugo4838f412012-01-20 11:19:37 -07001663 if (unlikely(ret == 0) && ssrestart_check()) {
1664 mutex_unlock(&wakeup_lock);
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301665 BAM_DMUX_LOG("%s timeout previous ack\n", __func__);
Jeff Hugo4838f412012-01-20 11:19:37 -07001666 return;
1667 }
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001668 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001669 INIT_COMPLETION(ul_wakeup_ack_completion);
Eric Holmberg878923a2012-01-10 14:28:19 -07001670 power_vote(1);
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301671 BAM_DMUX_LOG("%s waiting for wakeup ack\n", __func__);
Jeff Hugo66f7f1e2012-01-16 14:30:42 -07001672 ret = wait_for_completion_timeout(&ul_wakeup_ack_completion, HZ);
Jeff Hugo4838f412012-01-20 11:19:37 -07001673 if (unlikely(ret == 0) && ssrestart_check()) {
1674 mutex_unlock(&wakeup_lock);
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301675 BAM_DMUX_LOG("%s timeout wakeup ack\n", __func__);
Jeff Hugo4838f412012-01-20 11:19:37 -07001676 return;
1677 }
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301678 BAM_DMUX_LOG("%s waiting completion\n", __func__);
Jeff Hugo66f7f1e2012-01-16 14:30:42 -07001679 ret = wait_for_completion_timeout(&bam_connection_completion, HZ);
Jeff Hugo4838f412012-01-20 11:19:37 -07001680 if (unlikely(ret == 0) && ssrestart_check()) {
1681 mutex_unlock(&wakeup_lock);
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301682 BAM_DMUX_LOG("%s timeout power on\n", __func__);
Jeff Hugo4838f412012-01-20 11:19:37 -07001683 return;
1684 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001685
1686 bam_is_connected = 1;
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301687 BAM_DMUX_LOG("%s complete\n", __func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001688 schedule_delayed_work(&ul_timeout_work,
1689 msecs_to_jiffies(UL_TIMEOUT_DELAY));
1690 mutex_unlock(&wakeup_lock);
1691}
1692
1693static void reconnect_to_bam(void)
1694{
1695 int i;
1696
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001697 in_global_reset = 0;
Jeff Hugoa82a95c2012-12-14 17:56:19 -07001698 in_ssr = 0;
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001699 vote_dfab();
Jeff Hugo18792a32012-06-20 15:25:55 -06001700 if (!power_management_only_mode) {
Jeff Hugoa82a95c2012-12-14 17:56:19 -07001701 if (ssr_skipped_disconnect) {
1702 /* delayed to here to prevent bus stall */
1703 sps_disconnect(bam_tx_pipe);
1704 sps_disconnect(bam_rx_pipe);
1705 __memzero(rx_desc_mem_buf.base, rx_desc_mem_buf.size);
1706 __memzero(tx_desc_mem_buf.base, tx_desc_mem_buf.size);
1707 }
1708 ssr_skipped_disconnect = 0;
Jeff Hugo18792a32012-06-20 15:25:55 -06001709 i = sps_device_reset(a2_device_handle);
1710 if (i)
1711 pr_err("%s: device reset failed rc = %d\n", __func__,
1712 i);
1713 i = sps_connect(bam_tx_pipe, &tx_connection);
1714 if (i)
1715 pr_err("%s: tx connection failed rc = %d\n", __func__,
1716 i);
1717 i = sps_connect(bam_rx_pipe, &rx_connection);
1718 if (i)
1719 pr_err("%s: rx connection failed rc = %d\n", __func__,
1720 i);
1721 i = sps_register_event(bam_tx_pipe, &tx_register_event);
1722 if (i)
1723 pr_err("%s: tx event reg failed rc = %d\n", __func__,
1724 i);
1725 i = sps_register_event(bam_rx_pipe, &rx_register_event);
1726 if (i)
1727 pr_err("%s: rx event reg failed rc = %d\n", __func__,
1728 i);
1729 }
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001730
1731 bam_connection_is_active = 1;
1732
1733 if (polling_mode)
1734 rx_switch_to_interrupt_mode();
1735
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001736 toggle_apps_ack();
1737 complete_all(&bam_connection_completion);
Jeff Hugo18792a32012-06-20 15:25:55 -06001738 if (!power_management_only_mode)
1739 queue_rx();
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001740}
1741
1742static void disconnect_to_bam(void)
1743{
1744 struct list_head *node;
1745 struct rx_pkt_info *info;
Eric Holmberg454d9da2012-01-12 09:37:14 -07001746 unsigned long flags;
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001747
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001748 bam_connection_is_active = 0;
Eric Holmberg454d9da2012-01-12 09:37:14 -07001749
1750 /* handle disconnect during active UL */
1751 write_lock_irqsave(&ul_wakeup_lock, flags);
1752 if (bam_is_connected) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301753 BAM_DMUX_LOG("%s: UL active - forcing powerdown\n", __func__);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001754 ul_powerdown();
1755 }
1756 write_unlock_irqrestore(&ul_wakeup_lock, flags);
1757 ul_powerdown_finish();
1758
1759 /* tear down BAM connection */
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001760 INIT_COMPLETION(bam_connection_completion);
Jeff Hugoa82a95c2012-12-14 17:56:19 -07001761
1762 /* in_ssr documentation/assumptions found in restart_notifier_cb */
Jeff Hugo18792a32012-06-20 15:25:55 -06001763 if (!power_management_only_mode) {
Jeff Hugoa82a95c2012-12-14 17:56:19 -07001764 if (likely(!in_ssr)) {
Jeff Hugof7ae7a62013-04-19 11:18:32 -06001765 BAM_DMUX_LOG("%s: disconnect tx\n", __func__);
Jeff Hugoa82a95c2012-12-14 17:56:19 -07001766 sps_disconnect(bam_tx_pipe);
Jeff Hugof7ae7a62013-04-19 11:18:32 -06001767 BAM_DMUX_LOG("%s: disconnect rx\n", __func__);
Jeff Hugoa82a95c2012-12-14 17:56:19 -07001768 sps_disconnect(bam_rx_pipe);
1769 __memzero(rx_desc_mem_buf.base, rx_desc_mem_buf.size);
1770 __memzero(tx_desc_mem_buf.base, tx_desc_mem_buf.size);
Jeff Hugof7ae7a62013-04-19 11:18:32 -06001771 BAM_DMUX_LOG("%s: device reset\n", __func__);
Jeff Hugoa82a95c2012-12-14 17:56:19 -07001772 sps_device_reset(a2_device_handle);
1773 } else {
1774 ssr_skipped_disconnect = 1;
1775 }
Jeff Hugo18792a32012-06-20 15:25:55 -06001776 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001777 unvote_dfab();
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001778
1779 mutex_lock(&bam_rx_pool_mutexlock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001780 while (!list_empty(&bam_rx_pool)) {
1781 node = bam_rx_pool.next;
1782 list_del(node);
1783 info = container_of(node, struct rx_pkt_info, list_node);
1784 dma_unmap_single(NULL, info->dma_address, BUFFER_SIZE,
1785 DMA_FROM_DEVICE);
1786 dev_kfree_skb_any(info->skb);
1787 kfree(info);
1788 }
Eric Holmbergb5b08e52012-01-20 14:19:00 -07001789 bam_rx_pool_len = 0;
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001790 mutex_unlock(&bam_rx_pool_mutexlock);
Eric Holmberg878923a2012-01-10 14:28:19 -07001791
Jeff Hugo0b13a352012-03-17 23:18:30 -06001792 if (disconnect_ack)
1793 toggle_apps_ack();
1794
Eric Holmberg878923a2012-01-10 14:28:19 -07001795 verify_tx_queue_is_empty(__func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001796}
1797
1798static void vote_dfab(void)
1799{
Jeff Hugoca0caa82011-12-05 16:05:23 -07001800 int rc;
1801
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301802 BAM_DMUX_LOG("%s\n", __func__);
Eric Holmberg006057d2012-01-11 10:10:42 -07001803 mutex_lock(&dfab_status_lock);
1804 if (dfab_is_on) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301805 BAM_DMUX_LOG("%s: dfab is already on\n", __func__);
Eric Holmberg006057d2012-01-11 10:10:42 -07001806 mutex_unlock(&dfab_status_lock);
1807 return;
1808 }
Jeff Hugod0befde2012-08-09 15:32:49 -06001809 if (dfab_clk) {
1810 rc = clk_prepare_enable(dfab_clk);
1811 if (rc)
1812 DMUX_LOG_KERR("bam_dmux vote for dfab failed rc = %d\n",
1813 rc);
1814 }
1815 if (xo_clk) {
1816 rc = clk_prepare_enable(xo_clk);
1817 if (rc)
1818 DMUX_LOG_KERR("bam_dmux vote for xo failed rc = %d\n",
1819 rc);
1820 }
Eric Holmberg006057d2012-01-11 10:10:42 -07001821 dfab_is_on = 1;
1822 mutex_unlock(&dfab_status_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001823}
1824
1825static void unvote_dfab(void)
1826{
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301827 BAM_DMUX_LOG("%s\n", __func__);
Eric Holmberg006057d2012-01-11 10:10:42 -07001828 mutex_lock(&dfab_status_lock);
1829 if (!dfab_is_on) {
1830 DMUX_LOG_KERR("%s: dfab is already off\n", __func__);
1831 dump_stack();
1832 mutex_unlock(&dfab_status_lock);
1833 return;
1834 }
Jeff Hugod0befde2012-08-09 15:32:49 -06001835 if (dfab_clk)
1836 clk_disable_unprepare(dfab_clk);
1837 if (xo_clk)
1838 clk_disable_unprepare(xo_clk);
Eric Holmberg006057d2012-01-11 10:10:42 -07001839 dfab_is_on = 0;
1840 mutex_unlock(&dfab_status_lock);
1841}
1842
1843/* reference counting wrapper around wakelock */
1844static void grab_wakelock(void)
1845{
1846 unsigned long flags;
1847
1848 spin_lock_irqsave(&wakelock_reference_lock, flags);
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301849 BAM_DMUX_LOG("%s: ref count = %d\n", __func__,
Eric Holmberg006057d2012-01-11 10:10:42 -07001850 wakelock_reference_count);
1851 if (wakelock_reference_count == 0)
1852 wake_lock(&bam_wakelock);
1853 ++wakelock_reference_count;
1854 spin_unlock_irqrestore(&wakelock_reference_lock, flags);
1855}
1856
1857static void release_wakelock(void)
1858{
1859 unsigned long flags;
1860
1861 spin_lock_irqsave(&wakelock_reference_lock, flags);
1862 if (wakelock_reference_count == 0) {
1863 DMUX_LOG_KERR("%s: bam_dmux wakelock not locked\n", __func__);
1864 dump_stack();
1865 spin_unlock_irqrestore(&wakelock_reference_lock, flags);
1866 return;
1867 }
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301868 BAM_DMUX_LOG("%s: ref count = %d\n", __func__,
Eric Holmberg006057d2012-01-11 10:10:42 -07001869 wakelock_reference_count);
1870 --wakelock_reference_count;
1871 if (wakelock_reference_count == 0)
1872 wake_unlock(&bam_wakelock);
1873 spin_unlock_irqrestore(&wakelock_reference_lock, flags);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001874}
1875
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001876static int restart_notifier_cb(struct notifier_block *this,
1877 unsigned long code,
1878 void *data)
1879{
1880 int i;
1881 struct list_head *node;
1882 struct tx_pkt_info *info;
1883 int temp_remote_status;
Jeff Hugo626303bf2011-11-21 11:43:28 -07001884 unsigned long flags;
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001885
Jeff Hugoa82a95c2012-12-14 17:56:19 -07001886 /*
1887 * Bam_dmux counts on the fact that the BEFORE_SHUTDOWN level of
1888 * notifications are guarenteed to execute before the AFTER_SHUTDOWN
1889 * level of notifications, and that BEFORE_SHUTDOWN always occurs in
1890 * all SSR events, no matter what triggered the SSR. Also, bam_dmux
1891 * assumes that SMD does its SSR processing in the AFTER_SHUTDOWN level
1892 * thus bam_dmux is guarenteed to detect SSR before SMD, since the
1893 * callbacks for all the drivers within the AFTER_SHUTDOWN level could
1894 * occur in any order. Bam_dmux uses this knowledge to skip accessing
1895 * the bam hardware when disconnect_to_bam() is triggered by SMD's SSR
1896 * processing. We do not wat to access the bam hardware during SSR
1897 * because a watchdog crash from a bus stall would likely occur.
1898 */
Jeff Hugo199294b2013-02-25 13:46:56 -07001899 if (code == SUBSYS_BEFORE_SHUTDOWN) {
1900 in_global_reset = 1;
Jeff Hugoa82a95c2012-12-14 17:56:19 -07001901 in_ssr = 1;
Zaheerulla Meerf800bba2013-02-13 15:49:14 +05301902 BAM_DMUX_LOG("%s: begin\n", __func__);
Jeff Hugo199294b2013-02-25 13:46:56 -07001903 flush_workqueue(bam_mux_rx_workqueue);
1904 }
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001905 if (code != SUBSYS_AFTER_SHUTDOWN)
1906 return NOTIFY_DONE;
1907
Eric Holmberg454d9da2012-01-12 09:37:14 -07001908 /* Handle uplink Powerdown */
1909 write_lock_irqsave(&ul_wakeup_lock, flags);
1910 if (bam_is_connected) {
1911 ul_powerdown();
1912 wait_for_ack = 0;
1913 }
Jeff Hugo4838f412012-01-20 11:19:37 -07001914 /*
1915 * if modem crash during ul_wakeup(), power_vote is 1, needs to be
1916 * reset to 0. harmless if bam_is_connected check above passes
1917 */
1918 power_vote(0);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001919 write_unlock_irqrestore(&ul_wakeup_lock, flags);
1920 ul_powerdown_finish();
Eric Holmberg006057d2012-01-11 10:10:42 -07001921 a2_pc_disabled = 0;
Jeff Hugo583a6da2012-02-03 11:37:30 -07001922 a2_pc_disabled_wakelock_skipped = 0;
Jeff Hugof62029d2012-07-17 13:39:53 -06001923 disconnect_ack = 1;
Eric Holmberg454d9da2012-01-12 09:37:14 -07001924
1925 /* Cleanup Channel States */
Eric Holmberga623da82012-07-12 09:37:09 -06001926 mutex_lock(&bam_pdev_mutexlock);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001927 for (i = 0; i < BAM_DMUX_NUM_CHANNELS; ++i) {
1928 temp_remote_status = bam_ch_is_remote_open(i);
1929 bam_ch[i].status &= ~BAM_CH_REMOTE_OPEN;
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -07001930 bam_ch[i].num_tx_pkts = 0;
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001931 if (bam_ch_is_local_open(i))
1932 bam_ch[i].status |= BAM_CH_IN_RESET;
1933 if (temp_remote_status) {
1934 platform_device_unregister(bam_ch[i].pdev);
1935 bam_ch[i].pdev = platform_device_alloc(
1936 bam_ch[i].name, 2);
1937 }
1938 }
Eric Holmberga623da82012-07-12 09:37:09 -06001939 mutex_unlock(&bam_pdev_mutexlock);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001940
1941 /* Cleanup pending UL data */
Jeff Hugo626303bf2011-11-21 11:43:28 -07001942 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001943 while (!list_empty(&bam_tx_pool)) {
1944 node = bam_tx_pool.next;
1945 list_del(node);
1946 info = container_of(node, struct tx_pkt_info,
1947 list_node);
1948 if (!info->is_cmd) {
1949 dma_unmap_single(NULL, info->dma_address,
1950 info->skb->len,
1951 DMA_TO_DEVICE);
1952 dev_kfree_skb_any(info->skb);
1953 } else {
1954 dma_unmap_single(NULL, info->dma_address,
1955 info->len,
1956 DMA_TO_DEVICE);
1957 kfree(info->skb);
1958 }
1959 kfree(info);
1960 }
Jeff Hugo626303bf2011-11-21 11:43:28 -07001961 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001962
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05301963 BAM_DMUX_LOG("%s: complete\n", __func__);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001964 return NOTIFY_DONE;
1965}
1966
Jeff Hugo9dea05c2011-12-21 12:23:05 -07001967static int bam_init(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001968{
1969 u32 h;
1970 dma_addr_t dma_addr;
1971 int ret;
1972 void *a2_virt_addr;
Jeff Hugo4b2890d2012-01-16 16:14:21 -07001973 int skip_iounmap = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001974
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001975 vote_dfab();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001976 /* init BAM */
Jeff Hugo3910ee12012-08-21 14:08:20 -06001977 a2_virt_addr = ioremap_nocache((unsigned long)(a2_phys_base),
1978 a2_phys_size);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001979 if (!a2_virt_addr) {
1980 pr_err("%s: ioremap failed\n", __func__);
1981 ret = -ENOMEM;
Jeff Hugo994a92d2012-01-05 13:25:21 -07001982 goto ioremap_failed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001983 }
Jeff Hugo3910ee12012-08-21 14:08:20 -06001984 a2_props.phys_addr = (u32)(a2_phys_base);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001985 a2_props.virt_addr = a2_virt_addr;
Jeff Hugo3910ee12012-08-21 14:08:20 -06001986 a2_props.virt_size = a2_phys_size;
1987 a2_props.irq = a2_bam_irq;
Jeff Hugo927cba62011-11-11 11:49:52 -07001988 a2_props.options = SPS_BAM_OPT_IRQ_WAKEUP;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001989 a2_props.num_pipes = A2_NUM_PIPES;
1990 a2_props.summing_threshold = A2_SUMMING_THRESHOLD;
Jeff Hugo75913c82011-12-05 15:59:01 -07001991 if (cpu_is_msm9615())
1992 a2_props.manage = SPS_BAM_MGR_DEVICE_REMOTE;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001993 /* need to free on tear down */
1994 ret = sps_register_bam_device(&a2_props, &h);
1995 if (ret < 0) {
1996 pr_err("%s: register bam error %d\n", __func__, ret);
1997 goto register_bam_failed;
1998 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001999 a2_device_handle = h;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002000
2001 bam_tx_pipe = sps_alloc_endpoint();
2002 if (bam_tx_pipe == NULL) {
2003 pr_err("%s: tx alloc endpoint failed\n", __func__);
2004 ret = -ENOMEM;
Jeff Hugo8ff4a812012-01-17 11:03:13 -07002005 goto tx_alloc_endpoint_failed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002006 }
2007 ret = sps_get_config(bam_tx_pipe, &tx_connection);
2008 if (ret) {
2009 pr_err("%s: tx get config failed %d\n", __func__, ret);
2010 goto tx_get_config_failed;
2011 }
2012
2013 tx_connection.source = SPS_DEV_HANDLE_MEM;
2014 tx_connection.src_pipe_index = 0;
2015 tx_connection.destination = h;
2016 tx_connection.dest_pipe_index = 4;
2017 tx_connection.mode = SPS_MODE_DEST;
2018 tx_connection.options = SPS_O_AUTO_ENABLE | SPS_O_EOT;
2019 tx_desc_mem_buf.size = 0x800; /* 2k */
2020 tx_desc_mem_buf.base = dma_alloc_coherent(NULL, tx_desc_mem_buf.size,
2021 &dma_addr, 0);
2022 if (tx_desc_mem_buf.base == NULL) {
2023 pr_err("%s: tx memory alloc failed\n", __func__);
2024 ret = -ENOMEM;
Jeff Hugo8ff4a812012-01-17 11:03:13 -07002025 goto tx_get_config_failed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002026 }
2027 tx_desc_mem_buf.phys_base = dma_addr;
2028 memset(tx_desc_mem_buf.base, 0x0, tx_desc_mem_buf.size);
2029 tx_connection.desc = tx_desc_mem_buf;
2030 tx_connection.event_thresh = 0x10;
2031
2032 ret = sps_connect(bam_tx_pipe, &tx_connection);
2033 if (ret < 0) {
2034 pr_err("%s: tx connect error %d\n", __func__, ret);
2035 goto tx_connect_failed;
2036 }
2037
2038 bam_rx_pipe = sps_alloc_endpoint();
2039 if (bam_rx_pipe == NULL) {
2040 pr_err("%s: rx alloc endpoint failed\n", __func__);
2041 ret = -ENOMEM;
Jeff Hugo8ff4a812012-01-17 11:03:13 -07002042 goto rx_alloc_endpoint_failed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002043 }
2044 ret = sps_get_config(bam_rx_pipe, &rx_connection);
2045 if (ret) {
2046 pr_err("%s: rx get config failed %d\n", __func__, ret);
2047 goto rx_get_config_failed;
2048 }
2049
2050 rx_connection.source = h;
2051 rx_connection.src_pipe_index = 5;
2052 rx_connection.destination = SPS_DEV_HANDLE_MEM;
2053 rx_connection.dest_pipe_index = 1;
2054 rx_connection.mode = SPS_MODE_SRC;
Jeff Hugo949080a2011-08-30 11:58:56 -06002055 rx_connection.options = SPS_O_AUTO_ENABLE | SPS_O_EOT |
2056 SPS_O_ACK_TRANSFERS;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002057 rx_desc_mem_buf.size = 0x800; /* 2k */
2058 rx_desc_mem_buf.base = dma_alloc_coherent(NULL, rx_desc_mem_buf.size,
2059 &dma_addr, 0);
2060 if (rx_desc_mem_buf.base == NULL) {
2061 pr_err("%s: rx memory alloc failed\n", __func__);
2062 ret = -ENOMEM;
2063 goto rx_mem_failed;
2064 }
2065 rx_desc_mem_buf.phys_base = dma_addr;
2066 memset(rx_desc_mem_buf.base, 0x0, rx_desc_mem_buf.size);
2067 rx_connection.desc = rx_desc_mem_buf;
2068 rx_connection.event_thresh = 0x10;
2069
2070 ret = sps_connect(bam_rx_pipe, &rx_connection);
2071 if (ret < 0) {
2072 pr_err("%s: rx connect error %d\n", __func__, ret);
2073 goto rx_connect_failed;
2074 }
2075
2076 tx_register_event.options = SPS_O_EOT;
2077 tx_register_event.mode = SPS_TRIGGER_CALLBACK;
2078 tx_register_event.xfer_done = NULL;
2079 tx_register_event.callback = bam_mux_tx_notify;
2080 tx_register_event.user = NULL;
2081 ret = sps_register_event(bam_tx_pipe, &tx_register_event);
2082 if (ret < 0) {
2083 pr_err("%s: tx register event error %d\n", __func__, ret);
2084 goto rx_event_reg_failed;
2085 }
2086
Jeff Hugo33dbc002011-08-25 15:52:53 -06002087 rx_register_event.options = SPS_O_EOT;
2088 rx_register_event.mode = SPS_TRIGGER_CALLBACK;
2089 rx_register_event.xfer_done = NULL;
2090 rx_register_event.callback = bam_mux_rx_notify;
2091 rx_register_event.user = NULL;
2092 ret = sps_register_event(bam_rx_pipe, &rx_register_event);
2093 if (ret < 0) {
2094 pr_err("%s: tx register event error %d\n", __func__, ret);
2095 goto rx_event_reg_failed;
2096 }
2097
Jeff Hugoc2696142012-05-03 11:42:13 -06002098 mutex_lock(&delayed_ul_vote_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002099 bam_mux_initialized = 1;
Jeff Hugoc2696142012-05-03 11:42:13 -06002100 if (need_delayed_ul_vote) {
2101 need_delayed_ul_vote = 0;
2102 msm_bam_dmux_kickoff_ul_wakeup();
2103 }
2104 mutex_unlock(&delayed_ul_vote_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002105 toggle_apps_ack();
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06002106 bam_connection_is_active = 1;
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002107 complete_all(&bam_connection_completion);
Jeff Hugo2fb555e2012-03-14 16:33:47 -06002108 queue_rx();
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002109 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002110
2111rx_event_reg_failed:
2112 sps_disconnect(bam_rx_pipe);
2113rx_connect_failed:
2114 dma_free_coherent(NULL, rx_desc_mem_buf.size, rx_desc_mem_buf.base,
2115 rx_desc_mem_buf.phys_base);
2116rx_mem_failed:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002117rx_get_config_failed:
2118 sps_free_endpoint(bam_rx_pipe);
Jeff Hugo8ff4a812012-01-17 11:03:13 -07002119rx_alloc_endpoint_failed:
2120 sps_disconnect(bam_tx_pipe);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002121tx_connect_failed:
2122 dma_free_coherent(NULL, tx_desc_mem_buf.size, tx_desc_mem_buf.base,
2123 tx_desc_mem_buf.phys_base);
2124tx_get_config_failed:
2125 sps_free_endpoint(bam_tx_pipe);
Jeff Hugo8ff4a812012-01-17 11:03:13 -07002126tx_alloc_endpoint_failed:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002127 sps_deregister_bam_device(h);
Jeff Hugo4b2890d2012-01-16 16:14:21 -07002128 /*
2129 * sps_deregister_bam_device() calls iounmap. calling iounmap on the
2130 * same handle below will cause a crash, so skip it if we've freed
2131 * the handle here.
2132 */
2133 skip_iounmap = 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002134register_bam_failed:
Jeff Hugo4b2890d2012-01-16 16:14:21 -07002135 if (!skip_iounmap)
2136 iounmap(a2_virt_addr);
Jeff Hugo994a92d2012-01-05 13:25:21 -07002137ioremap_failed:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002138 /*destroy_workqueue(bam_mux_workqueue);*/
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002139 return ret;
2140}
2141
2142static int bam_init_fallback(void)
2143{
2144 u32 h;
2145 int ret;
2146 void *a2_virt_addr;
2147
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002148 /* init BAM */
Jeff Hugo3910ee12012-08-21 14:08:20 -06002149 a2_virt_addr = ioremap_nocache((unsigned long)(a2_phys_base),
2150 a2_phys_size);
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002151 if (!a2_virt_addr) {
2152 pr_err("%s: ioremap failed\n", __func__);
2153 ret = -ENOMEM;
2154 goto ioremap_failed;
2155 }
Jeff Hugo3910ee12012-08-21 14:08:20 -06002156 a2_props.phys_addr = (u32)(a2_phys_base);
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002157 a2_props.virt_addr = a2_virt_addr;
Jeff Hugo3910ee12012-08-21 14:08:20 -06002158 a2_props.virt_size = a2_phys_size;
2159 a2_props.irq = a2_bam_irq;
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002160 a2_props.options = SPS_BAM_OPT_IRQ_WAKEUP;
2161 a2_props.num_pipes = A2_NUM_PIPES;
2162 a2_props.summing_threshold = A2_SUMMING_THRESHOLD;
2163 if (cpu_is_msm9615())
2164 a2_props.manage = SPS_BAM_MGR_DEVICE_REMOTE;
2165 ret = sps_register_bam_device(&a2_props, &h);
2166 if (ret < 0) {
2167 pr_err("%s: register bam error %d\n", __func__, ret);
2168 goto register_bam_failed;
2169 }
2170 a2_device_handle = h;
Jeff Hugoc2696142012-05-03 11:42:13 -06002171
2172 mutex_lock(&delayed_ul_vote_lock);
2173 bam_mux_initialized = 1;
2174 if (need_delayed_ul_vote) {
2175 need_delayed_ul_vote = 0;
2176 msm_bam_dmux_kickoff_ul_wakeup();
2177 }
2178 mutex_unlock(&delayed_ul_vote_lock);
Jeff Hugo2bec9772012-04-05 12:25:16 -06002179 toggle_apps_ack();
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002180
Jeff Hugo18792a32012-06-20 15:25:55 -06002181 power_management_only_mode = 1;
2182 bam_connection_is_active = 1;
2183 complete_all(&bam_connection_completion);
2184
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002185 return 0;
2186
2187register_bam_failed:
Jeff Hugo4b2890d2012-01-16 16:14:21 -07002188 iounmap(a2_virt_addr);
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002189ioremap_failed:
2190 return ret;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002191}
Jeff Hugoade1f842011-08-03 15:53:59 -06002192
Jeff Hugoa670b762012-03-15 15:58:28 -06002193static void msm9615_bam_init(void)
Eric Holmberg604ab252012-01-15 00:01:18 -07002194{
2195 int ret = 0;
2196
2197 ret = bam_init();
2198 if (ret) {
2199 ret = bam_init_fallback();
2200 if (ret)
2201 pr_err("%s: bam init fallback failed: %d",
2202 __func__, ret);
2203 }
2204}
2205
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002206static void toggle_apps_ack(void)
2207{
2208 static unsigned int clear_bit; /* 0 = set the bit, else clear bit */
Eric Holmberg878923a2012-01-10 14:28:19 -07002209
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302210 BAM_DMUX_LOG("%s: apps ack %d->%d\n", __func__,
Eric Holmberg878923a2012-01-10 14:28:19 -07002211 clear_bit & 0x1, ~clear_bit & 0x1);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002212 smsm_change_state(SMSM_APPS_STATE,
2213 clear_bit & SMSM_A2_POWER_CONTROL_ACK,
2214 ~clear_bit & SMSM_A2_POWER_CONTROL_ACK);
2215 clear_bit = ~clear_bit;
Eric Holmberg1f1255d2012-02-22 13:37:21 -07002216 DBG_INC_ACK_OUT_CNT();
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002217}
2218
Jeff Hugoade1f842011-08-03 15:53:59 -06002219static void bam_dmux_smsm_cb(void *priv, uint32_t old_state, uint32_t new_state)
2220{
Jeff Hugo4b7c7b32012-04-18 16:25:14 -06002221 static int last_processed_state;
2222
2223 mutex_lock(&smsm_cb_lock);
Eric Holmberg878923a2012-01-10 14:28:19 -07002224 bam_dmux_power_state = new_state & SMSM_A2_POWER_CONTROL ? 1 : 0;
Eric Holmberg1f1255d2012-02-22 13:37:21 -07002225 DBG_INC_A2_POWER_CONTROL_IN_CNT();
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302226 BAM_DMUX_LOG("%s: 0x%08x -> 0x%08x\n", __func__, old_state,
Eric Holmberg878923a2012-01-10 14:28:19 -07002227 new_state);
Jeff Hugo4b7c7b32012-04-18 16:25:14 -06002228 if (last_processed_state == (new_state & SMSM_A2_POWER_CONTROL)) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302229 BAM_DMUX_LOG("%s: already processed this state\n", __func__);
Jeff Hugo4b7c7b32012-04-18 16:25:14 -06002230 mutex_unlock(&smsm_cb_lock);
2231 return;
2232 }
2233
2234 last_processed_state = new_state & SMSM_A2_POWER_CONTROL;
Eric Holmberg878923a2012-01-10 14:28:19 -07002235
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002236 if (bam_mux_initialized && new_state & SMSM_A2_POWER_CONTROL) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302237 BAM_DMUX_LOG("%s: reconnect\n", __func__);
Eric Holmberg006057d2012-01-11 10:10:42 -07002238 grab_wakelock();
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002239 reconnect_to_bam();
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002240 } else if (bam_mux_initialized &&
2241 !(new_state & SMSM_A2_POWER_CONTROL)) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302242 BAM_DMUX_LOG("%s: disconnect\n", __func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002243 disconnect_to_bam();
Eric Holmberg006057d2012-01-11 10:10:42 -07002244 release_wakelock();
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002245 } else if (new_state & SMSM_A2_POWER_CONTROL) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302246 BAM_DMUX_LOG("%s: init\n", __func__);
Eric Holmberg006057d2012-01-11 10:10:42 -07002247 grab_wakelock();
Jeff Hugoa670b762012-03-15 15:58:28 -06002248 if (cpu_is_msm9615())
2249 msm9615_bam_init();
2250 else
Eric Holmberg604ab252012-01-15 00:01:18 -07002251 bam_init();
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002252 } else {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302253 BAM_DMUX_LOG("%s: bad state change\n", __func__);
Jeff Hugoade1f842011-08-03 15:53:59 -06002254 pr_err("%s: unsupported state change\n", __func__);
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002255 }
Jeff Hugo4b7c7b32012-04-18 16:25:14 -06002256 mutex_unlock(&smsm_cb_lock);
Jeff Hugoade1f842011-08-03 15:53:59 -06002257
2258}
2259
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002260static void bam_dmux_smsm_ack_cb(void *priv, uint32_t old_state,
2261 uint32_t new_state)
2262{
Eric Holmberg1f1255d2012-02-22 13:37:21 -07002263 DBG_INC_ACK_IN_CNT();
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302264 BAM_DMUX_LOG("%s: 0x%08x -> 0x%08x\n", __func__, old_state,
Eric Holmberg878923a2012-01-10 14:28:19 -07002265 new_state);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002266 complete_all(&ul_wakeup_ack_completion);
2267}
2268
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002269static int bam_dmux_probe(struct platform_device *pdev)
2270{
2271 int rc;
Jeff Hugo3910ee12012-08-21 14:08:20 -06002272 struct resource *r;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002273
2274 DBG("%s probe called\n", __func__);
2275 if (bam_mux_initialized)
2276 return 0;
2277
Jeff Hugo3910ee12012-08-21 14:08:20 -06002278 if (pdev->dev.of_node) {
2279 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2280 if (!r) {
2281 pr_err("%s: reg field missing\n", __func__);
2282 return -ENODEV;
2283 }
2284 a2_phys_base = (void *)(r->start);
2285 a2_phys_size = (uint32_t)(resource_size(r));
2286 a2_bam_irq = platform_get_irq(pdev, 0);
2287 if (a2_bam_irq == -ENXIO) {
2288 pr_err("%s: irq field missing\n", __func__);
2289 return -ENODEV;
2290 }
2291 DBG("%s: base:%p size:%x irq:%d\n", __func__,
2292 a2_phys_base,
2293 a2_phys_size,
2294 a2_bam_irq);
2295 } else { /* fallback to default init data */
2296 a2_phys_base = (void *)(A2_PHYS_BASE);
2297 a2_phys_size = A2_PHYS_SIZE;
2298 a2_bam_irq = A2_BAM_IRQ;
2299 }
2300
Stephen Boyd69d35e32012-02-14 15:33:30 -08002301 xo_clk = clk_get(&pdev->dev, "xo");
2302 if (IS_ERR(xo_clk)) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302303 BAM_DMUX_LOG("%s: did not get xo clock\n", __func__);
Jeff Hugod0befde2012-08-09 15:32:49 -06002304 xo_clk = NULL;
Stephen Boyd69d35e32012-02-14 15:33:30 -08002305 }
Stephen Boyd1c51a492011-10-26 12:11:47 -07002306 dfab_clk = clk_get(&pdev->dev, "bus_clk");
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002307 if (IS_ERR(dfab_clk)) {
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302308 BAM_DMUX_LOG("%s: did not get dfab clock\n", __func__);
Jeff Hugod0befde2012-08-09 15:32:49 -06002309 dfab_clk = NULL;
2310 } else {
2311 rc = clk_set_rate(dfab_clk, 64000000);
2312 if (rc)
2313 pr_err("%s: unable to set dfab clock rate\n", __func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002314 }
2315
Jeff Hugofff43af92012-03-29 17:54:52 -06002316 /*
2317 * setup the workqueue so that it can be pinned to core 0 and not
2318 * block the watchdog pet function, so that netif_rx() in rmnet
2319 * only uses one queue.
2320 */
2321 bam_mux_rx_workqueue = alloc_workqueue("bam_dmux_rx",
2322 WQ_MEM_RECLAIM | WQ_CPU_INTENSIVE, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002323 if (!bam_mux_rx_workqueue)
2324 return -ENOMEM;
2325
2326 bam_mux_tx_workqueue = create_singlethread_workqueue("bam_dmux_tx");
2327 if (!bam_mux_tx_workqueue) {
2328 destroy_workqueue(bam_mux_rx_workqueue);
2329 return -ENOMEM;
2330 }
2331
Jeff Hugo7960abd2011-08-02 15:39:38 -06002332 for (rc = 0; rc < BAM_DMUX_NUM_CHANNELS; ++rc) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002333 spin_lock_init(&bam_ch[rc].lock);
Jeff Hugo7960abd2011-08-02 15:39:38 -06002334 scnprintf(bam_ch[rc].name, BAM_DMUX_CH_NAME_MAX_LEN,
2335 "bam_dmux_ch_%d", rc);
2336 /* bus 2, ie a2 stream 2 */
2337 bam_ch[rc].pdev = platform_device_alloc(bam_ch[rc].name, 2);
2338 if (!bam_ch[rc].pdev) {
2339 pr_err("%s: platform device alloc failed\n", __func__);
2340 destroy_workqueue(bam_mux_rx_workqueue);
2341 destroy_workqueue(bam_mux_tx_workqueue);
2342 return -ENOMEM;
2343 }
2344 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002345
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002346 init_completion(&ul_wakeup_ack_completion);
2347 init_completion(&bam_connection_completion);
Eric Holmberg006057d2012-01-11 10:10:42 -07002348 init_completion(&dfab_unvote_completion);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002349 INIT_DELAYED_WORK(&ul_timeout_work, ul_timeout);
Jeff Hugo988e7ba2012-10-03 15:53:54 -06002350 INIT_DELAYED_WORK(&queue_rx_work, queue_rx_work_func);
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002351 wake_lock_init(&bam_wakelock, WAKE_LOCK_SUSPEND, "bam_dmux_wakelock");
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002352
Jeff Hugoade1f842011-08-03 15:53:59 -06002353 rc = smsm_state_cb_register(SMSM_MODEM_STATE, SMSM_A2_POWER_CONTROL,
2354 bam_dmux_smsm_cb, NULL);
2355
2356 if (rc) {
2357 destroy_workqueue(bam_mux_rx_workqueue);
2358 destroy_workqueue(bam_mux_tx_workqueue);
2359 pr_err("%s: smsm cb register failed, rc: %d\n", __func__, rc);
2360 return -ENOMEM;
2361 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002362
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002363 rc = smsm_state_cb_register(SMSM_MODEM_STATE, SMSM_A2_POWER_CONTROL_ACK,
2364 bam_dmux_smsm_ack_cb, NULL);
2365
2366 if (rc) {
2367 destroy_workqueue(bam_mux_rx_workqueue);
2368 destroy_workqueue(bam_mux_tx_workqueue);
2369 smsm_state_cb_deregister(SMSM_MODEM_STATE,
2370 SMSM_A2_POWER_CONTROL,
2371 bam_dmux_smsm_cb, NULL);
2372 pr_err("%s: smsm ack cb register failed, rc: %d\n", __func__,
2373 rc);
2374 for (rc = 0; rc < BAM_DMUX_NUM_CHANNELS; ++rc)
2375 platform_device_put(bam_ch[rc].pdev);
2376 return -ENOMEM;
2377 }
2378
Eric Holmbergfd1e2ae2011-11-15 18:28:17 -07002379 if (smsm_get_state(SMSM_MODEM_STATE) & SMSM_A2_POWER_CONTROL)
2380 bam_dmux_smsm_cb(NULL, 0, smsm_get_state(SMSM_MODEM_STATE));
2381
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002382 return 0;
2383}
2384
Jeff Hugo3910ee12012-08-21 14:08:20 -06002385static struct of_device_id msm_match_table[] = {
2386 {.compatible = "qcom,bam_dmux"},
2387 {},
2388};
2389
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002390static struct platform_driver bam_dmux_driver = {
2391 .probe = bam_dmux_probe,
2392 .driver = {
2393 .name = "BAM_RMNT",
2394 .owner = THIS_MODULE,
Jeff Hugo3910ee12012-08-21 14:08:20 -06002395 .of_match_table = msm_match_table,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002396 },
2397};
2398
2399static int __init bam_dmux_init(void)
2400{
2401#ifdef CONFIG_DEBUG_FS
2402 struct dentry *dent;
2403
2404 dent = debugfs_create_dir("bam_dmux", 0);
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07002405 if (!IS_ERR(dent)) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002406 debug_create("tbl", 0444, dent, debug_tbl);
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07002407 debug_create("ul_pkt_cnt", 0444, dent, debug_ul_pkt_cnt);
2408 debug_create("stats", 0444, dent, debug_stats);
2409 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002410#endif
Zaheerulla Meer6fbf32c2013-01-31 17:06:44 +05302411
2412 bam_ipc_log_txt = ipc_log_context_create(BAM_IPC_LOG_PAGES, "bam_dmux");
2413 if (!bam_ipc_log_txt) {
2414 pr_err("%s : unable to create IPC Logging Context", __func__);
Eric Holmberg878923a2012-01-10 14:28:19 -07002415 }
2416
Anurag Singhdcd8b4e2012-07-30 16:46:37 -07002417 rx_timer_interval = DEFAULT_POLLING_MIN_SLEEP;
2418
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06002419 subsys_notif_register_notifier("modem", &restart_notifier);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002420 return platform_driver_register(&bam_dmux_driver);
2421}
2422
Jeff Hugoade1f842011-08-03 15:53:59 -06002423late_initcall(bam_dmux_init); /* needs to init after SMD */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002424MODULE_DESCRIPTION("MSM BAM DMUX");
2425MODULE_LICENSE("GPL v2");