blob: b5a75522bfcaf1bf1d1d8908914cc0a93c3118ef [file] [log] [blame]
Arun Kumar Neelakantam381cd542013-01-17 18:58:04 +05301/* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 */
13
14/*
15 * BAM DMUX module.
16 */
17
18#define DEBUG
19
20#include <linux/delay.h>
21#include <linux/module.h>
22#include <linux/netdevice.h>
23#include <linux/platform_device.h>
24#include <linux/sched.h>
25#include <linux/skbuff.h>
26#include <linux/debugfs.h>
Jeff Hugoaab7ebc2011-09-07 16:46:04 -060027#include <linux/clk.h>
Jeff Hugoae3a85e2011-12-02 17:10:18 -070028#include <linux/wakelock.h>
Eric Holmberg878923a2012-01-10 14:28:19 -070029#include <linux/kfifo.h>
Jeff Hugo7bf02052012-08-21 14:08:20 -060030#include <linux/of.h>
Zaheerulla Meeraa9fd5c2013-01-31 17:06:44 +053031#include <mach/msm_ipc_logging.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070032#include <mach/sps.h>
33#include <mach/bam_dmux.h>
Jeff Hugoade1f842011-08-03 15:53:59 -060034#include <mach/msm_smsm.h>
Jeff Hugo6e7a92a2011-10-24 05:25:13 -060035#include <mach/subsystem_notif.h>
Jeff Hugo75913c82011-12-05 15:59:01 -070036#include <mach/socinfo.h>
Jeff Hugo4838f412012-01-20 11:19:37 -070037#include <mach/subsystem_restart.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070038
39#define BAM_CH_LOCAL_OPEN 0x1
40#define BAM_CH_REMOTE_OPEN 0x2
Jeff Hugo6e7a92a2011-10-24 05:25:13 -060041#define BAM_CH_IN_RESET 0x4
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070042
43#define BAM_MUX_HDR_MAGIC_NO 0x33fc
44
Eric Holmberg006057d2012-01-11 10:10:42 -070045#define BAM_MUX_HDR_CMD_DATA 0
46#define BAM_MUX_HDR_CMD_OPEN 1
47#define BAM_MUX_HDR_CMD_CLOSE 2
48#define BAM_MUX_HDR_CMD_STATUS 3 /* unused */
49#define BAM_MUX_HDR_CMD_OPEN_NO_A2_PC 4
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070050
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070051
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -070052#define LOW_WATERMARK 2
53#define HIGH_WATERMARK 4
Anurag Singhdcd8b4e2012-07-30 16:46:37 -070054#define DEFAULT_POLLING_MIN_SLEEP (950)
55#define MAX_POLLING_SLEEP (6050)
56#define MIN_POLLING_SLEEP (950)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070057
58static int msm_bam_dmux_debug_enable;
59module_param_named(debug_enable, msm_bam_dmux_debug_enable,
60 int, S_IRUGO | S_IWUSR | S_IWGRP);
Anurag Singhdcd8b4e2012-07-30 16:46:37 -070061static int POLLING_MIN_SLEEP = 950;
62module_param_named(min_sleep, POLLING_MIN_SLEEP,
63 int, S_IRUGO | S_IWUSR | S_IWGRP);
64static int POLLING_MAX_SLEEP = 1050;
65module_param_named(max_sleep, POLLING_MAX_SLEEP,
66 int, S_IRUGO | S_IWUSR | S_IWGRP);
67static int POLLING_INACTIVITY = 40;
68module_param_named(inactivity, POLLING_INACTIVITY,
69 int, S_IRUGO | S_IWUSR | S_IWGRP);
70static int bam_adaptive_timer_enabled = 1;
71module_param_named(adaptive_timer_enabled,
72 bam_adaptive_timer_enabled,
73 int, S_IRUGO | S_IWUSR | S_IWGRP);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070074
75#if defined(DEBUG)
76static uint32_t bam_dmux_read_cnt;
77static uint32_t bam_dmux_write_cnt;
78static uint32_t bam_dmux_write_cpy_cnt;
79static uint32_t bam_dmux_write_cpy_bytes;
Eric Holmberg2fddbcd2011-11-28 18:25:57 -070080static uint32_t bam_dmux_tx_sps_failure_cnt;
Eric Holmberg6074aba2012-01-18 17:59:44 -070081static uint32_t bam_dmux_tx_stall_cnt;
Eric Holmberg1f1255d2012-02-22 13:37:21 -070082static atomic_t bam_dmux_ack_out_cnt = ATOMIC_INIT(0);
83static atomic_t bam_dmux_ack_in_cnt = ATOMIC_INIT(0);
84static atomic_t bam_dmux_a2_pwr_cntl_in_cnt = ATOMIC_INIT(0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070085
86#define DBG(x...) do { \
87 if (msm_bam_dmux_debug_enable) \
88 pr_debug(x); \
89 } while (0)
90
91#define DBG_INC_READ_CNT(x) do { \
92 bam_dmux_read_cnt += (x); \
93 if (msm_bam_dmux_debug_enable) \
94 pr_debug("%s: total read bytes %u\n", \
95 __func__, bam_dmux_read_cnt); \
96 } while (0)
97
98#define DBG_INC_WRITE_CNT(x) do { \
99 bam_dmux_write_cnt += (x); \
100 if (msm_bam_dmux_debug_enable) \
101 pr_debug("%s: total written bytes %u\n", \
102 __func__, bam_dmux_write_cnt); \
103 } while (0)
104
105#define DBG_INC_WRITE_CPY(x) do { \
106 bam_dmux_write_cpy_bytes += (x); \
107 bam_dmux_write_cpy_cnt++; \
108 if (msm_bam_dmux_debug_enable) \
109 pr_debug("%s: total write copy cnt %u, bytes %u\n", \
110 __func__, bam_dmux_write_cpy_cnt, \
111 bam_dmux_write_cpy_bytes); \
112 } while (0)
Eric Holmberg2fddbcd2011-11-28 18:25:57 -0700113
114#define DBG_INC_TX_SPS_FAILURE_CNT() do { \
115 bam_dmux_tx_sps_failure_cnt++; \
116} while (0)
117
Eric Holmberg6074aba2012-01-18 17:59:44 -0700118#define DBG_INC_TX_STALL_CNT() do { \
119 bam_dmux_tx_stall_cnt++; \
120} while (0)
121
Eric Holmberg1f1255d2012-02-22 13:37:21 -0700122#define DBG_INC_ACK_OUT_CNT() \
123 atomic_inc(&bam_dmux_ack_out_cnt)
124
125#define DBG_INC_A2_POWER_CONTROL_IN_CNT() \
126 atomic_inc(&bam_dmux_a2_pwr_cntl_in_cnt)
127
128#define DBG_INC_ACK_IN_CNT() \
129 atomic_inc(&bam_dmux_ack_in_cnt)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700130#else
131#define DBG(x...) do { } while (0)
132#define DBG_INC_READ_CNT(x...) do { } while (0)
133#define DBG_INC_WRITE_CNT(x...) do { } while (0)
134#define DBG_INC_WRITE_CPY(x...) do { } while (0)
Eric Holmberg2fddbcd2011-11-28 18:25:57 -0700135#define DBG_INC_TX_SPS_FAILURE_CNT() do { } while (0)
Eric Holmberg6074aba2012-01-18 17:59:44 -0700136#define DBG_INC_TX_STALL_CNT() do { } while (0)
Eric Holmberg1f1255d2012-02-22 13:37:21 -0700137#define DBG_INC_ACK_OUT_CNT() do { } while (0)
138#define DBG_INC_A2_POWER_CONTROL_IN_CNT() \
139 do { } while (0)
140#define DBG_INC_ACK_IN_CNT() do { } while (0)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700141#endif
142
143struct bam_ch_info {
144 uint32_t status;
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600145 void (*notify)(void *, int, unsigned long);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700146 void *priv;
147 spinlock_t lock;
Jeff Hugo7960abd2011-08-02 15:39:38 -0600148 struct platform_device *pdev;
149 char name[BAM_DMUX_CH_NAME_MAX_LEN];
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700150 int num_tx_pkts;
151 int use_wm;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700152};
153
154struct tx_pkt_info {
155 struct sk_buff *skb;
156 dma_addr_t dma_address;
157 char is_cmd;
158 uint32_t len;
159 struct work_struct work;
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600160 struct list_head list_node;
Eric Holmberg878923a2012-01-10 14:28:19 -0700161 unsigned ts_sec;
162 unsigned long ts_nsec;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700163};
164
165struct rx_pkt_info {
166 struct sk_buff *skb;
167 dma_addr_t dma_address;
168 struct work_struct work;
Jeff Hugo949080a2011-08-30 11:58:56 -0600169 struct list_head list_node;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700170};
171
172#define A2_NUM_PIPES 6
173#define A2_SUMMING_THRESHOLD 4096
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700174#define A2_PHYS_BASE 0x124C2000
175#define A2_PHYS_SIZE 0x2000
176#define BUFFER_SIZE 2048
Jeff Hugoc8058f82013-03-27 12:44:20 -0600177#define DEFAULT_NUM_BUFFERS 32
Jeff Hugo7bf02052012-08-21 14:08:20 -0600178
179#ifndef A2_BAM_IRQ
180#define A2_BAM_IRQ -1
181#endif
182
183static void *a2_phys_base;
184static uint32_t a2_phys_size;
185static int a2_bam_irq;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700186static struct sps_bam_props a2_props;
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600187static u32 a2_device_handle;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700188static struct sps_pipe *bam_tx_pipe;
189static struct sps_pipe *bam_rx_pipe;
190static struct sps_connect tx_connection;
191static struct sps_connect rx_connection;
192static struct sps_mem_buffer tx_desc_mem_buf;
193static struct sps_mem_buffer rx_desc_mem_buf;
194static struct sps_register_event tx_register_event;
Jeff Hugo33dbc002011-08-25 15:52:53 -0600195static struct sps_register_event rx_register_event;
Jeff Hugo0682dad2012-10-22 11:34:28 -0600196static bool satellite_mode;
Jeff Hugoc8058f82013-03-27 12:44:20 -0600197static uint32_t num_buffers;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700198
199static struct bam_ch_info bam_ch[BAM_DMUX_NUM_CHANNELS];
200static int bam_mux_initialized;
201
Jeff Hugo949080a2011-08-30 11:58:56 -0600202static int polling_mode;
Anurag Singhdcd8b4e2012-07-30 16:46:37 -0700203static unsigned long rx_timer_interval;
Jeff Hugo949080a2011-08-30 11:58:56 -0600204
205static LIST_HEAD(bam_rx_pool);
Jeff Hugoc9749932011-11-02 17:50:40 -0600206static DEFINE_MUTEX(bam_rx_pool_mutexlock);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700207static int bam_rx_pool_len;
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600208static LIST_HEAD(bam_tx_pool);
Jeff Hugoc9749932011-11-02 17:50:40 -0600209static DEFINE_SPINLOCK(bam_tx_pool_spinlock);
Eric Holmberga623da82012-07-12 09:37:09 -0600210static DEFINE_MUTEX(bam_pdev_mutexlock);
Jeff Hugo949080a2011-08-30 11:58:56 -0600211
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700212struct bam_mux_hdr {
213 uint16_t magic_num;
214 uint8_t reserved;
215 uint8_t cmd;
216 uint8_t pad_len;
217 uint8_t ch_id;
218 uint16_t pkt_len;
219};
220
Jeff Hugod98b1082011-10-24 10:30:23 -0600221static void notify_all(int event, unsigned long data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700222static void bam_mux_write_done(struct work_struct *work);
223static void handle_bam_mux_cmd(struct work_struct *work);
Jeff Hugo949080a2011-08-30 11:58:56 -0600224static void rx_timer_work_func(struct work_struct *work);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700225
Jeff Hugo949080a2011-08-30 11:58:56 -0600226static DECLARE_WORK(rx_timer_work, rx_timer_work_func);
Jeff Hugoad75d8d2012-10-03 15:53:54 -0600227static struct delayed_work queue_rx_work;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700228
229static struct workqueue_struct *bam_mux_rx_workqueue;
230static struct workqueue_struct *bam_mux_tx_workqueue;
231
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600232/* A2 power collaspe */
233#define UL_TIMEOUT_DELAY 1000 /* in ms */
Jeff Hugo0b13a352012-03-17 23:18:30 -0600234#define ENABLE_DISCONNECT_ACK 0x1
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600235static void toggle_apps_ack(void);
236static void reconnect_to_bam(void);
237static void disconnect_to_bam(void);
238static void ul_wakeup(void);
239static void ul_timeout(struct work_struct *work);
240static void vote_dfab(void);
241static void unvote_dfab(void);
Jeff Hugod98b1082011-10-24 10:30:23 -0600242static void kickoff_ul_wakeup_func(struct work_struct *work);
Eric Holmberg006057d2012-01-11 10:10:42 -0700243static void grab_wakelock(void);
244static void release_wakelock(void);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600245
246static int bam_is_connected;
247static DEFINE_MUTEX(wakeup_lock);
248static struct completion ul_wakeup_ack_completion;
249static struct completion bam_connection_completion;
250static struct delayed_work ul_timeout_work;
251static int ul_packet_written;
Eric Holmbergbc9f21c2012-01-18 11:33:33 -0700252static atomic_t ul_ondemand_vote = ATOMIC_INIT(0);
Stephen Boyd69d35e32012-02-14 15:33:30 -0800253static struct clk *dfab_clk, *xo_clk;
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600254static DEFINE_RWLOCK(ul_wakeup_lock);
Jeff Hugod98b1082011-10-24 10:30:23 -0600255static DECLARE_WORK(kickoff_ul_wakeup, kickoff_ul_wakeup_func);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600256static int bam_connection_is_active;
Jeff Hugof6c1c1e2011-12-01 17:43:49 -0700257static int wait_for_ack;
Jeff Hugoae3a85e2011-12-02 17:10:18 -0700258static struct wake_lock bam_wakelock;
Eric Holmberg006057d2012-01-11 10:10:42 -0700259static int a2_pc_disabled;
260static DEFINE_MUTEX(dfab_status_lock);
261static int dfab_is_on;
262static int wait_for_dfab;
263static struct completion dfab_unvote_completion;
264static DEFINE_SPINLOCK(wakelock_reference_lock);
265static int wakelock_reference_count;
Jeff Hugo583a6da2012-02-03 11:37:30 -0700266static int a2_pc_disabled_wakelock_skipped;
Jeff Hugob1e7c582012-06-20 15:02:11 -0600267static int disconnect_ack = 1;
Jeff Hugocb798022012-04-09 14:55:40 -0600268static LIST_HEAD(bam_other_notify_funcs);
Jeff Hugo4b7c7b32012-04-18 16:25:14 -0600269static DEFINE_MUTEX(smsm_cb_lock);
Jeff Hugoc2696142012-05-03 11:42:13 -0600270static DEFINE_MUTEX(delayed_ul_vote_lock);
271static int need_delayed_ul_vote;
Jeff Hugo18792a32012-06-20 15:25:55 -0600272static int power_management_only_mode;
Jeff Hugo73f356f2012-12-14 17:56:19 -0700273static int in_ssr;
274static int ssr_skipped_disconnect;
Jeff Hugocb798022012-04-09 14:55:40 -0600275
276struct outside_notify_func {
277 void (*notify)(void *, int, unsigned long);
278 void *priv;
279 struct list_head list_node;
280};
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600281/* End A2 power collaspe */
282
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600283/* subsystem restart */
284static int restart_notifier_cb(struct notifier_block *this,
285 unsigned long code,
286 void *data);
287
288static struct notifier_block restart_notifier = {
289 .notifier_call = restart_notifier_cb,
290};
291static int in_global_reset;
292/* end subsystem restart */
293
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700294#define bam_ch_is_open(x) \
295 (bam_ch[(x)].status == (BAM_CH_LOCAL_OPEN | BAM_CH_REMOTE_OPEN))
296
297#define bam_ch_is_local_open(x) \
298 (bam_ch[(x)].status & BAM_CH_LOCAL_OPEN)
299
300#define bam_ch_is_remote_open(x) \
301 (bam_ch[(x)].status & BAM_CH_REMOTE_OPEN)
302
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600303#define bam_ch_is_in_reset(x) \
304 (bam_ch[(x)].status & BAM_CH_IN_RESET)
305
Eric Holmberg878923a2012-01-10 14:28:19 -0700306struct kfifo bam_dmux_state_log;
Eric Holmberg878923a2012-01-10 14:28:19 -0700307static int bam_dmux_uplink_vote;
308static int bam_dmux_power_state;
309
Zaheerulla Meeraa9fd5c2013-01-31 17:06:44 +0530310static void *bam_ipc_log_txt;
311
312#define BAM_IPC_LOG_PAGES 5
313
Eric Holmberg878923a2012-01-10 14:28:19 -0700314/**
315 * Log a state change along with a small message.
Eric Holmberg878923a2012-01-10 14:28:19 -0700316 * Complete size of messsage is limited to @todo.
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +0530317 * Logging is done using IPC Logging infrastructure.
318 *
319 * States
320 * D: 1 = Power collapse disabled
321 * R: 1 = in global reset
322 * P: 1 = BAM is powered up
323 * A: 1 = BAM initialized and ready for data
324 * V: 1 = Uplink vote for power
325 * U: 1 = Uplink active
326 * W: 1 = Uplink Wait-for-ack
327 * A: 1 = Uplink ACK received
328 * #: >=1 On-demand uplink vote
329 * D: 1 = Disconnect ACK active
Eric Holmberg878923a2012-01-10 14:28:19 -0700330 */
Eric Holmberg878923a2012-01-10 14:28:19 -0700331
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +0530332#define BAM_DMUX_LOG(fmt, args...) \
333do { \
334 if (bam_ipc_log_txt) { \
335 ipc_log_string(bam_ipc_log_txt, \
336 "<DMUX> %c%c%c%c %c%c%c%c%d%c " fmt, \
337 a2_pc_disabled ? 'D' : 'd', \
338 in_global_reset ? 'R' : 'r', \
339 bam_dmux_power_state ? 'P' : 'p', \
340 bam_connection_is_active ? 'A' : 'a', \
341 bam_dmux_uplink_vote ? 'V' : 'v', \
342 bam_is_connected ? 'U' : 'u', \
343 wait_for_ack ? 'W' : 'w', \
344 ul_wakeup_ack_completion.done ? 'A' : 'a', \
345 atomic_read(&ul_ondemand_vote), \
346 disconnect_ack ? 'D' : 'd', \
347 args); \
348 } \
349} while (0)
Eric Holmberg878923a2012-01-10 14:28:19 -0700350
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +0530351#define DMUX_LOG_KERR(fmt, args...) \
352do { \
353 BAM_DMUX_LOG(fmt, args); \
354 pr_err(fmt, args); \
355} while (0)
Eric Holmberg878923a2012-01-10 14:28:19 -0700356
357static inline void set_tx_timestamp(struct tx_pkt_info *pkt)
358{
359 unsigned long long t_now;
360
361 t_now = sched_clock();
362 pkt->ts_nsec = do_div(t_now, 1000000000U);
363 pkt->ts_sec = (unsigned)t_now;
364}
365
366static inline void verify_tx_queue_is_empty(const char *func)
367{
368 unsigned long flags;
369 struct tx_pkt_info *info;
370 int reported = 0;
371
372 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
373 list_for_each_entry(info, &bam_tx_pool, list_node) {
374 if (!reported) {
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +0530375 BAM_DMUX_LOG("%s: tx pool not empty\n", func);
Eric Holmberg454d9da2012-01-12 09:37:14 -0700376 if (!in_global_reset)
377 pr_err("%s: tx pool not empty\n", func);
Eric Holmberg878923a2012-01-10 14:28:19 -0700378 reported = 1;
379 }
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +0530380 BAM_DMUX_LOG("%s: node=%p ts=%u.%09lu\n", __func__,
Eric Holmberg454d9da2012-01-12 09:37:14 -0700381 &info->list_node, info->ts_sec, info->ts_nsec);
382 if (!in_global_reset)
383 pr_err("%s: node=%p ts=%u.%09lu\n", __func__,
384 &info->list_node, info->ts_sec, info->ts_nsec);
Eric Holmberg878923a2012-01-10 14:28:19 -0700385 }
386 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
387}
388
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700389static void queue_rx(void)
390{
391 void *ptr;
392 struct rx_pkt_info *info;
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700393 int ret;
394 int rx_len_cached;
Jeff Hugo949080a2011-08-30 11:58:56 -0600395
Jeff Hugoc9749932011-11-02 17:50:40 -0600396 mutex_lock(&bam_rx_pool_mutexlock);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700397 rx_len_cached = bam_rx_pool_len;
Jeff Hugoc9749932011-11-02 17:50:40 -0600398 mutex_unlock(&bam_rx_pool_mutexlock);
Jeff Hugo949080a2011-08-30 11:58:56 -0600399
Jeff Hugoc8058f82013-03-27 12:44:20 -0600400 while (bam_connection_is_active && rx_len_cached < num_buffers) {
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700401 if (in_global_reset)
402 goto fail;
403
Jeff Hugoad75d8d2012-10-03 15:53:54 -0600404 info = kmalloc(sizeof(struct rx_pkt_info),
405 GFP_NOWAIT | __GFP_NOWARN);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700406 if (!info) {
Jeff Hugoad75d8d2012-10-03 15:53:54 -0600407 DMUX_LOG_KERR(
408 "%s: unable to alloc rx_pkt_info, will retry later\n",
409 __func__);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700410 goto fail;
411 }
412
413 INIT_WORK(&info->work, handle_bam_mux_cmd);
414
Jeff Hugoad75d8d2012-10-03 15:53:54 -0600415 info->skb = __dev_alloc_skb(BUFFER_SIZE,
416 GFP_NOWAIT | __GFP_NOWARN);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700417 if (info->skb == NULL) {
Jeff Hugoad75d8d2012-10-03 15:53:54 -0600418 DMUX_LOG_KERR(
419 "%s: unable to alloc skb, will retry later\n",
420 __func__);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700421 goto fail_info;
422 }
423 ptr = skb_put(info->skb, BUFFER_SIZE);
424
425 info->dma_address = dma_map_single(NULL, ptr, BUFFER_SIZE,
426 DMA_FROM_DEVICE);
427 if (info->dma_address == 0 || info->dma_address == ~0) {
428 DMUX_LOG_KERR("%s: dma_map_single failure %p for %p\n",
429 __func__, (void *)info->dma_address, ptr);
430 goto fail_skb;
431 }
432
433 mutex_lock(&bam_rx_pool_mutexlock);
434 list_add_tail(&info->list_node, &bam_rx_pool);
435 rx_len_cached = ++bam_rx_pool_len;
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700436 ret = sps_transfer_one(bam_rx_pipe, info->dma_address,
Jeff Hugo4e73b952013-04-05 13:22:48 -0600437 BUFFER_SIZE, info, 0);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700438 if (ret) {
Eric Holmberg00cf8692012-07-16 14:21:19 -0600439 list_del(&info->list_node);
440 rx_len_cached = --bam_rx_pool_len;
441 mutex_unlock(&bam_rx_pool_mutexlock);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700442 DMUX_LOG_KERR("%s: sps_transfer_one failed %d\n",
443 __func__, ret);
Eric Holmberg00cf8692012-07-16 14:21:19 -0600444
445 dma_unmap_single(NULL, info->dma_address, BUFFER_SIZE,
446 DMA_FROM_DEVICE);
447
448 goto fail_skb;
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700449 }
Eric Holmberg00cf8692012-07-16 14:21:19 -0600450 mutex_unlock(&bam_rx_pool_mutexlock);
451
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700452 }
453 return;
454
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700455fail_skb:
456 dev_kfree_skb_any(info->skb);
457
458fail_info:
459 kfree(info);
460
461fail:
Arun Kumar Neelakantamd932d032012-12-13 18:06:49 +0530462 if (rx_len_cached == 0 && !in_global_reset) {
Jeff Hugoad75d8d2012-10-03 15:53:54 -0600463 DMUX_LOG_KERR("%s: rescheduling\n", __func__);
464 schedule_delayed_work(&queue_rx_work, msecs_to_jiffies(100));
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700465 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700466}
467
Jeff Hugoad75d8d2012-10-03 15:53:54 -0600468static void queue_rx_work_func(struct work_struct *work)
469{
470 queue_rx();
471}
472
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700473static void bam_mux_process_data(struct sk_buff *rx_skb)
474{
475 unsigned long flags;
476 struct bam_mux_hdr *rx_hdr;
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600477 unsigned long event_data;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700478
479 rx_hdr = (struct bam_mux_hdr *)rx_skb->data;
480
481 rx_skb->data = (unsigned char *)(rx_hdr + 1);
482 rx_skb->tail = rx_skb->data + rx_hdr->pkt_len;
483 rx_skb->len = rx_hdr->pkt_len;
Jeff Hugoee88f672011-10-04 17:14:52 -0600484 rx_skb->truesize = rx_hdr->pkt_len + sizeof(struct sk_buff);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700485
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600486 event_data = (unsigned long)(rx_skb);
487
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700488 spin_lock_irqsave(&bam_ch[rx_hdr->ch_id].lock, flags);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600489 if (bam_ch[rx_hdr->ch_id].notify)
490 bam_ch[rx_hdr->ch_id].notify(
491 bam_ch[rx_hdr->ch_id].priv, BAM_DMUX_RECEIVE,
492 event_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700493 else
494 dev_kfree_skb_any(rx_skb);
495 spin_unlock_irqrestore(&bam_ch[rx_hdr->ch_id].lock, flags);
496
497 queue_rx();
498}
499
Eric Holmberg006057d2012-01-11 10:10:42 -0700500static inline void handle_bam_mux_cmd_open(struct bam_mux_hdr *rx_hdr)
501{
502 unsigned long flags;
503 int ret;
504
Eric Holmberga623da82012-07-12 09:37:09 -0600505 mutex_lock(&bam_pdev_mutexlock);
506 if (in_global_reset) {
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +0530507 BAM_DMUX_LOG("%s: open cid %d aborted due to ssr\n",
Eric Holmberga623da82012-07-12 09:37:09 -0600508 __func__, rx_hdr->ch_id);
509 mutex_unlock(&bam_pdev_mutexlock);
510 queue_rx();
511 return;
512 }
Eric Holmberg006057d2012-01-11 10:10:42 -0700513 spin_lock_irqsave(&bam_ch[rx_hdr->ch_id].lock, flags);
514 bam_ch[rx_hdr->ch_id].status |= BAM_CH_REMOTE_OPEN;
515 bam_ch[rx_hdr->ch_id].num_tx_pkts = 0;
516 spin_unlock_irqrestore(&bam_ch[rx_hdr->ch_id].lock, flags);
Eric Holmberg006057d2012-01-11 10:10:42 -0700517 ret = platform_device_add(bam_ch[rx_hdr->ch_id].pdev);
518 if (ret)
519 pr_err("%s: platform_device_add() error: %d\n",
520 __func__, ret);
Eric Holmberga623da82012-07-12 09:37:09 -0600521 mutex_unlock(&bam_pdev_mutexlock);
522 queue_rx();
Eric Holmberg006057d2012-01-11 10:10:42 -0700523}
524
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700525static void handle_bam_mux_cmd(struct work_struct *work)
526{
527 unsigned long flags;
528 struct bam_mux_hdr *rx_hdr;
529 struct rx_pkt_info *info;
530 struct sk_buff *rx_skb;
531
532 info = container_of(work, struct rx_pkt_info, work);
533 rx_skb = info->skb;
Jeff Hugo949080a2011-08-30 11:58:56 -0600534 dma_unmap_single(NULL, info->dma_address, BUFFER_SIZE, DMA_FROM_DEVICE);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700535 kfree(info);
536
537 rx_hdr = (struct bam_mux_hdr *)rx_skb->data;
538
539 DBG_INC_READ_CNT(sizeof(struct bam_mux_hdr));
540 DBG("%s: magic %x reserved %d cmd %d pad %d ch %d len %d\n", __func__,
541 rx_hdr->magic_num, rx_hdr->reserved, rx_hdr->cmd,
542 rx_hdr->pad_len, rx_hdr->ch_id, rx_hdr->pkt_len);
543 if (rx_hdr->magic_num != BAM_MUX_HDR_MAGIC_NO) {
Eric Holmberg878923a2012-01-10 14:28:19 -0700544 DMUX_LOG_KERR("%s: dropping invalid hdr. magic %x"
545 " reserved %d cmd %d"
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700546 " pad %d ch %d len %d\n", __func__,
547 rx_hdr->magic_num, rx_hdr->reserved, rx_hdr->cmd,
548 rx_hdr->pad_len, rx_hdr->ch_id, rx_hdr->pkt_len);
549 dev_kfree_skb_any(rx_skb);
550 queue_rx();
551 return;
552 }
Eric Holmberg9ff40a52011-11-17 19:17:00 -0700553
554 if (rx_hdr->ch_id >= BAM_DMUX_NUM_CHANNELS) {
Eric Holmberg878923a2012-01-10 14:28:19 -0700555 DMUX_LOG_KERR("%s: dropping invalid LCID %d"
556 " reserved %d cmd %d"
Eric Holmberg9ff40a52011-11-17 19:17:00 -0700557 " pad %d ch %d len %d\n", __func__,
558 rx_hdr->ch_id, rx_hdr->reserved, rx_hdr->cmd,
559 rx_hdr->pad_len, rx_hdr->ch_id, rx_hdr->pkt_len);
560 dev_kfree_skb_any(rx_skb);
561 queue_rx();
562 return;
563 }
564
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700565 switch (rx_hdr->cmd) {
566 case BAM_MUX_HDR_CMD_DATA:
567 DBG_INC_READ_CNT(rx_hdr->pkt_len);
568 bam_mux_process_data(rx_skb);
569 break;
570 case BAM_MUX_HDR_CMD_OPEN:
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +0530571 BAM_DMUX_LOG("%s: opening cid %d PC enabled\n", __func__,
Eric Holmberg878923a2012-01-10 14:28:19 -0700572 rx_hdr->ch_id);
Eric Holmberg006057d2012-01-11 10:10:42 -0700573 handle_bam_mux_cmd_open(rx_hdr);
Jeff Hugob1e7c582012-06-20 15:02:11 -0600574 if (!(rx_hdr->reserved & ENABLE_DISCONNECT_ACK)) {
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +0530575 BAM_DMUX_LOG("%s: deactivating disconnect ack\n",
Jeff Hugod7d2b062012-07-24 14:29:56 -0600576 __func__);
Jeff Hugob1e7c582012-06-20 15:02:11 -0600577 disconnect_ack = 0;
Jeff Hugo0b13a352012-03-17 23:18:30 -0600578 }
Eric Holmberg006057d2012-01-11 10:10:42 -0700579 dev_kfree_skb_any(rx_skb);
580 break;
581 case BAM_MUX_HDR_CMD_OPEN_NO_A2_PC:
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +0530582 BAM_DMUX_LOG("%s: opening cid %d PC disabled\n", __func__,
Eric Holmberg006057d2012-01-11 10:10:42 -0700583 rx_hdr->ch_id);
584
585 if (!a2_pc_disabled) {
586 a2_pc_disabled = 1;
Jeff Hugo322179f2012-02-29 10:52:34 -0700587 ul_wakeup();
Eric Holmberg006057d2012-01-11 10:10:42 -0700588 }
589
590 handle_bam_mux_cmd_open(rx_hdr);
Eric Holmberge779dba2011-11-04 18:22:01 -0600591 dev_kfree_skb_any(rx_skb);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700592 break;
593 case BAM_MUX_HDR_CMD_CLOSE:
594 /* probably should drop pending write */
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +0530595 BAM_DMUX_LOG("%s: closing cid %d\n", __func__,
Eric Holmberg878923a2012-01-10 14:28:19 -0700596 rx_hdr->ch_id);
Eric Holmberga623da82012-07-12 09:37:09 -0600597 mutex_lock(&bam_pdev_mutexlock);
598 if (in_global_reset) {
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +0530599 BAM_DMUX_LOG("%s: close cid %d aborted due to ssr\n",
Eric Holmberga623da82012-07-12 09:37:09 -0600600 __func__, rx_hdr->ch_id);
601 mutex_unlock(&bam_pdev_mutexlock);
602 break;
603 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700604 spin_lock_irqsave(&bam_ch[rx_hdr->ch_id].lock, flags);
605 bam_ch[rx_hdr->ch_id].status &= ~BAM_CH_REMOTE_OPEN;
606 spin_unlock_irqrestore(&bam_ch[rx_hdr->ch_id].lock, flags);
Jeff Hugo7960abd2011-08-02 15:39:38 -0600607 platform_device_unregister(bam_ch[rx_hdr->ch_id].pdev);
608 bam_ch[rx_hdr->ch_id].pdev =
609 platform_device_alloc(bam_ch[rx_hdr->ch_id].name, 2);
610 if (!bam_ch[rx_hdr->ch_id].pdev)
611 pr_err("%s: platform_device_alloc failed\n", __func__);
Eric Holmberga623da82012-07-12 09:37:09 -0600612 mutex_unlock(&bam_pdev_mutexlock);
Eric Holmberge779dba2011-11-04 18:22:01 -0600613 dev_kfree_skb_any(rx_skb);
Eric Holmberga623da82012-07-12 09:37:09 -0600614 queue_rx();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700615 break;
616 default:
Eric Holmberg878923a2012-01-10 14:28:19 -0700617 DMUX_LOG_KERR("%s: dropping invalid hdr. magic %x"
618 " reserved %d cmd %d pad %d ch %d len %d\n",
619 __func__, rx_hdr->magic_num, rx_hdr->reserved,
620 rx_hdr->cmd, rx_hdr->pad_len, rx_hdr->ch_id,
621 rx_hdr->pkt_len);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700622 dev_kfree_skb_any(rx_skb);
623 queue_rx();
624 return;
625 }
626}
627
628static int bam_mux_write_cmd(void *data, uint32_t len)
629{
630 int rc;
631 struct tx_pkt_info *pkt;
632 dma_addr_t dma_address;
Jeff Hugo626303bf2011-11-21 11:43:28 -0700633 unsigned long flags;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700634
Eric Holmbergd83cd2b2011-11-04 15:54:17 -0600635 pkt = kmalloc(sizeof(struct tx_pkt_info), GFP_ATOMIC);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700636 if (pkt == NULL) {
637 pr_err("%s: mem alloc for tx_pkt_info failed\n", __func__);
638 rc = -ENOMEM;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700639 return rc;
640 }
641
642 dma_address = dma_map_single(NULL, data, len,
643 DMA_TO_DEVICE);
644 if (!dma_address) {
645 pr_err("%s: dma_map_single() failed\n", __func__);
Jeff Hugo96cb7482011-12-07 13:28:31 -0700646 kfree(pkt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700647 rc = -ENOMEM;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700648 return rc;
649 }
650 pkt->skb = (struct sk_buff *)(data);
651 pkt->len = len;
652 pkt->dma_address = dma_address;
653 pkt->is_cmd = 1;
Eric Holmberg878923a2012-01-10 14:28:19 -0700654 set_tx_timestamp(pkt);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600655 INIT_WORK(&pkt->work, bam_mux_write_done);
Jeff Hugo626303bf2011-11-21 11:43:28 -0700656 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600657 list_add_tail(&pkt->list_node, &bam_tx_pool);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700658 rc = sps_transfer_one(bam_tx_pipe, dma_address, len,
Jeff Hugo4e73b952013-04-05 13:22:48 -0600659 pkt, SPS_IOVEC_FLAG_EOT);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600660 if (rc) {
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700661 DMUX_LOG_KERR("%s sps_transfer_one failed rc=%d\n",
662 __func__, rc);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600663 list_del(&pkt->list_node);
Eric Holmberg2fddbcd2011-11-28 18:25:57 -0700664 DBG_INC_TX_SPS_FAILURE_CNT();
Jeff Hugo626303bf2011-11-21 11:43:28 -0700665 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700666 dma_unmap_single(NULL, pkt->dma_address,
667 pkt->len,
668 DMA_TO_DEVICE);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600669 kfree(pkt);
Jeff Hugobb6da952012-01-16 15:02:42 -0700670 } else {
671 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600672 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700673
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600674 ul_packet_written = 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700675 return rc;
676}
677
678static void bam_mux_write_done(struct work_struct *work)
679{
680 struct sk_buff *skb;
681 struct bam_mux_hdr *hdr;
682 struct tx_pkt_info *info;
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700683 struct tx_pkt_info *info_expected;
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600684 unsigned long event_data;
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700685 unsigned long flags;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700686
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600687 if (in_global_reset)
688 return;
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700689
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700690 info = container_of(work, struct tx_pkt_info, work);
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700691
692 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
693 info_expected = list_first_entry(&bam_tx_pool,
694 struct tx_pkt_info, list_node);
695 if (unlikely(info != info_expected)) {
Eric Holmberg878923a2012-01-10 14:28:19 -0700696 struct tx_pkt_info *errant_pkt;
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700697
Eric Holmberg878923a2012-01-10 14:28:19 -0700698 DMUX_LOG_KERR("%s: bam_tx_pool mismatch .next=%p,"
699 " list_node=%p, ts=%u.%09lu\n",
700 __func__, bam_tx_pool.next, &info->list_node,
701 info->ts_sec, info->ts_nsec
702 );
703
704 list_for_each_entry(errant_pkt, &bam_tx_pool, list_node) {
705 DMUX_LOG_KERR("%s: node=%p ts=%u.%09lu\n", __func__,
706 &errant_pkt->list_node, errant_pkt->ts_sec,
707 errant_pkt->ts_nsec);
708
709 }
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700710 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
711 BUG();
712 }
713 list_del(&info->list_node);
714 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
715
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600716 if (info->is_cmd) {
717 kfree(info->skb);
718 kfree(info);
719 return;
720 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700721 skb = info->skb;
722 kfree(info);
723 hdr = (struct bam_mux_hdr *)skb->data;
Eric Holmberg9fdef262012-02-14 11:46:05 -0700724 DBG_INC_WRITE_CNT(skb->len);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600725 event_data = (unsigned long)(skb);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700726 spin_lock_irqsave(&bam_ch[hdr->ch_id].lock, flags);
727 bam_ch[hdr->ch_id].num_tx_pkts--;
728 spin_unlock_irqrestore(&bam_ch[hdr->ch_id].lock, flags);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600729 if (bam_ch[hdr->ch_id].notify)
730 bam_ch[hdr->ch_id].notify(
731 bam_ch[hdr->ch_id].priv, BAM_DMUX_WRITE_DONE,
732 event_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700733 else
734 dev_kfree_skb_any(skb);
735}
736
737int msm_bam_dmux_write(uint32_t id, struct sk_buff *skb)
738{
739 int rc = 0;
740 struct bam_mux_hdr *hdr;
741 unsigned long flags;
742 struct sk_buff *new_skb = NULL;
743 dma_addr_t dma_address;
744 struct tx_pkt_info *pkt;
745
746 if (id >= BAM_DMUX_NUM_CHANNELS)
747 return -EINVAL;
748 if (!skb)
749 return -EINVAL;
750 if (!bam_mux_initialized)
751 return -ENODEV;
752
753 DBG("%s: writing to ch %d len %d\n", __func__, id, skb->len);
754 spin_lock_irqsave(&bam_ch[id].lock, flags);
755 if (!bam_ch_is_open(id)) {
756 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
757 pr_err("%s: port not open: %d\n", __func__, bam_ch[id].status);
758 return -ENODEV;
759 }
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700760
761 if (bam_ch[id].use_wm &&
762 (bam_ch[id].num_tx_pkts >= HIGH_WATERMARK)) {
763 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
764 pr_err("%s: watermark exceeded: %d\n", __func__, id);
765 return -EAGAIN;
766 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700767 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
768
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600769 read_lock(&ul_wakeup_lock);
Jeff Hugo061ce672011-10-21 17:15:32 -0600770 if (!bam_is_connected) {
771 read_unlock(&ul_wakeup_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600772 ul_wakeup();
Jeff Hugo4838f412012-01-20 11:19:37 -0700773 if (unlikely(in_global_reset == 1))
774 return -EFAULT;
Jeff Hugo061ce672011-10-21 17:15:32 -0600775 read_lock(&ul_wakeup_lock);
Jeff Hugod98b1082011-10-24 10:30:23 -0600776 notify_all(BAM_DMUX_UL_CONNECTED, (unsigned long)(NULL));
Jeff Hugo061ce672011-10-21 17:15:32 -0600777 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600778
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700779 /* if skb do not have any tailroom for padding,
780 copy the skb into a new expanded skb */
781 if ((skb->len & 0x3) && (skb_tailroom(skb) < (4 - (skb->len & 0x3)))) {
782 /* revisit, probably dev_alloc_skb and memcpy is effecient */
783 new_skb = skb_copy_expand(skb, skb_headroom(skb),
784 4 - (skb->len & 0x3), GFP_ATOMIC);
785 if (new_skb == NULL) {
786 pr_err("%s: cannot allocate skb\n", __func__);
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600787 goto write_fail;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700788 }
789 dev_kfree_skb_any(skb);
790 skb = new_skb;
791 DBG_INC_WRITE_CPY(skb->len);
792 }
793
794 hdr = (struct bam_mux_hdr *)skb_push(skb, sizeof(struct bam_mux_hdr));
795
796 /* caller should allocate for hdr and padding
797 hdr is fine, padding is tricky */
798 hdr->magic_num = BAM_MUX_HDR_MAGIC_NO;
799 hdr->cmd = BAM_MUX_HDR_CMD_DATA;
800 hdr->reserved = 0;
801 hdr->ch_id = id;
802 hdr->pkt_len = skb->len - sizeof(struct bam_mux_hdr);
803 if (skb->len & 0x3)
804 skb_put(skb, 4 - (skb->len & 0x3));
805
806 hdr->pad_len = skb->len - (sizeof(struct bam_mux_hdr) + hdr->pkt_len);
807
808 DBG("%s: data %p, tail %p skb len %d pkt len %d pad len %d\n",
809 __func__, skb->data, skb->tail, skb->len,
810 hdr->pkt_len, hdr->pad_len);
811
812 pkt = kmalloc(sizeof(struct tx_pkt_info), GFP_ATOMIC);
813 if (pkt == NULL) {
814 pr_err("%s: mem alloc for tx_pkt_info failed\n", __func__);
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600815 goto write_fail2;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700816 }
817
818 dma_address = dma_map_single(NULL, skb->data, skb->len,
819 DMA_TO_DEVICE);
820 if (!dma_address) {
821 pr_err("%s: dma_map_single() failed\n", __func__);
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600822 goto write_fail3;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700823 }
824 pkt->skb = skb;
825 pkt->dma_address = dma_address;
826 pkt->is_cmd = 0;
Eric Holmberg878923a2012-01-10 14:28:19 -0700827 set_tx_timestamp(pkt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700828 INIT_WORK(&pkt->work, bam_mux_write_done);
Jeff Hugo626303bf2011-11-21 11:43:28 -0700829 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600830 list_add_tail(&pkt->list_node, &bam_tx_pool);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700831 rc = sps_transfer_one(bam_tx_pipe, dma_address, skb->len,
Jeff Hugo4e73b952013-04-05 13:22:48 -0600832 pkt, SPS_IOVEC_FLAG_EOT);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600833 if (rc) {
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700834 DMUX_LOG_KERR("%s sps_transfer_one failed rc=%d\n",
835 __func__, rc);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600836 list_del(&pkt->list_node);
Eric Holmberg2fddbcd2011-11-28 18:25:57 -0700837 DBG_INC_TX_SPS_FAILURE_CNT();
Jeff Hugo626303bf2011-11-21 11:43:28 -0700838 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700839 dma_unmap_single(NULL, pkt->dma_address,
840 pkt->skb->len, DMA_TO_DEVICE);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600841 kfree(pkt);
Jeff Hugo872bd062011-11-15 17:47:21 -0700842 if (new_skb)
843 dev_kfree_skb_any(new_skb);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700844 } else {
Jeff Hugobb6da952012-01-16 15:02:42 -0700845 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700846 spin_lock_irqsave(&bam_ch[id].lock, flags);
847 bam_ch[id].num_tx_pkts++;
848 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600849 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600850 ul_packet_written = 1;
851 read_unlock(&ul_wakeup_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700852 return rc;
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600853
854write_fail3:
855 kfree(pkt);
856write_fail2:
Arun Kumar Neelakantam381cd542013-01-17 18:58:04 +0530857 skb_pull(skb, sizeof(struct bam_mux_hdr));
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600858 if (new_skb)
859 dev_kfree_skb_any(new_skb);
860write_fail:
861 read_unlock(&ul_wakeup_lock);
862 return -ENOMEM;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700863}
864
865int msm_bam_dmux_open(uint32_t id, void *priv,
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600866 void (*notify)(void *, int, unsigned long))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700867{
868 struct bam_mux_hdr *hdr;
869 unsigned long flags;
870 int rc = 0;
871
872 DBG("%s: opening ch %d\n", __func__, id);
Eric Holmberg5d775432011-11-09 10:23:35 -0700873 if (!bam_mux_initialized) {
874 DBG("%s: not inititialized\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700875 return -ENODEV;
Eric Holmberg5d775432011-11-09 10:23:35 -0700876 }
877 if (id >= BAM_DMUX_NUM_CHANNELS) {
878 pr_err("%s: invalid channel id %d\n", __func__, id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700879 return -EINVAL;
Eric Holmberg5d775432011-11-09 10:23:35 -0700880 }
881 if (notify == NULL) {
882 pr_err("%s: notify function is NULL\n", __func__);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600883 return -EINVAL;
Eric Holmberg5d775432011-11-09 10:23:35 -0700884 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700885
886 hdr = kmalloc(sizeof(struct bam_mux_hdr), GFP_KERNEL);
887 if (hdr == NULL) {
888 pr_err("%s: hdr kmalloc failed. ch: %d\n", __func__, id);
889 return -ENOMEM;
890 }
891 spin_lock_irqsave(&bam_ch[id].lock, flags);
892 if (bam_ch_is_open(id)) {
893 DBG("%s: Already opened %d\n", __func__, id);
894 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
895 kfree(hdr);
896 goto open_done;
897 }
898 if (!bam_ch_is_remote_open(id)) {
899 DBG("%s: Remote not open; ch: %d\n", __func__, id);
900 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
901 kfree(hdr);
Eric Holmberg5d775432011-11-09 10:23:35 -0700902 return -ENODEV;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700903 }
904
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600905 bam_ch[id].notify = notify;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700906 bam_ch[id].priv = priv;
907 bam_ch[id].status |= BAM_CH_LOCAL_OPEN;
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700908 bam_ch[id].num_tx_pkts = 0;
909 bam_ch[id].use_wm = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700910 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
911
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600912 read_lock(&ul_wakeup_lock);
Jeff Hugo061ce672011-10-21 17:15:32 -0600913 if (!bam_is_connected) {
914 read_unlock(&ul_wakeup_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600915 ul_wakeup();
Brent Hronikd2353052013-04-17 15:07:19 -0600916 if (unlikely(in_global_reset == 1)) {
917 kfree(hdr);
Jeff Hugo4838f412012-01-20 11:19:37 -0700918 return -EFAULT;
Brent Hronikd2353052013-04-17 15:07:19 -0600919 }
Jeff Hugo061ce672011-10-21 17:15:32 -0600920 read_lock(&ul_wakeup_lock);
Jeff Hugod98b1082011-10-24 10:30:23 -0600921 notify_all(BAM_DMUX_UL_CONNECTED, (unsigned long)(NULL));
Jeff Hugo061ce672011-10-21 17:15:32 -0600922 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600923
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700924 hdr->magic_num = BAM_MUX_HDR_MAGIC_NO;
925 hdr->cmd = BAM_MUX_HDR_CMD_OPEN;
926 hdr->reserved = 0;
927 hdr->ch_id = id;
928 hdr->pkt_len = 0;
929 hdr->pad_len = 0;
930
931 rc = bam_mux_write_cmd((void *)hdr, sizeof(struct bam_mux_hdr));
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600932 read_unlock(&ul_wakeup_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700933
934open_done:
935 DBG("%s: opened ch %d\n", __func__, id);
936 return rc;
937}
938
939int msm_bam_dmux_close(uint32_t id)
940{
941 struct bam_mux_hdr *hdr;
942 unsigned long flags;
943 int rc;
944
945 if (id >= BAM_DMUX_NUM_CHANNELS)
946 return -EINVAL;
947 DBG("%s: closing ch %d\n", __func__, id);
948 if (!bam_mux_initialized)
949 return -ENODEV;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700950
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600951 read_lock(&ul_wakeup_lock);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600952 if (!bam_is_connected && !bam_ch_is_in_reset(id)) {
Jeff Hugo061ce672011-10-21 17:15:32 -0600953 read_unlock(&ul_wakeup_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600954 ul_wakeup();
Jeff Hugo4838f412012-01-20 11:19:37 -0700955 if (unlikely(in_global_reset == 1))
956 return -EFAULT;
Jeff Hugo061ce672011-10-21 17:15:32 -0600957 read_lock(&ul_wakeup_lock);
Jeff Hugod98b1082011-10-24 10:30:23 -0600958 notify_all(BAM_DMUX_UL_CONNECTED, (unsigned long)(NULL));
Jeff Hugo061ce672011-10-21 17:15:32 -0600959 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600960
Jeff Hugo061ce672011-10-21 17:15:32 -0600961 spin_lock_irqsave(&bam_ch[id].lock, flags);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600962 bam_ch[id].notify = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700963 bam_ch[id].priv = NULL;
964 bam_ch[id].status &= ~BAM_CH_LOCAL_OPEN;
965 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
966
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600967 if (bam_ch_is_in_reset(id)) {
968 read_unlock(&ul_wakeup_lock);
969 bam_ch[id].status &= ~BAM_CH_IN_RESET;
970 return 0;
971 }
972
Jeff Hugobb5802f2011-11-02 17:10:29 -0600973 hdr = kmalloc(sizeof(struct bam_mux_hdr), GFP_ATOMIC);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700974 if (hdr == NULL) {
975 pr_err("%s: hdr kmalloc failed. ch: %d\n", __func__, id);
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600976 read_unlock(&ul_wakeup_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700977 return -ENOMEM;
978 }
979 hdr->magic_num = BAM_MUX_HDR_MAGIC_NO;
980 hdr->cmd = BAM_MUX_HDR_CMD_CLOSE;
981 hdr->reserved = 0;
982 hdr->ch_id = id;
983 hdr->pkt_len = 0;
984 hdr->pad_len = 0;
985
986 rc = bam_mux_write_cmd((void *)hdr, sizeof(struct bam_mux_hdr));
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600987 read_unlock(&ul_wakeup_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700988
989 DBG("%s: closed ch %d\n", __func__, id);
990 return rc;
991}
992
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700993int msm_bam_dmux_is_ch_full(uint32_t id)
994{
995 unsigned long flags;
996 int ret;
997
998 if (id >= BAM_DMUX_NUM_CHANNELS)
999 return -EINVAL;
1000
1001 spin_lock_irqsave(&bam_ch[id].lock, flags);
1002 bam_ch[id].use_wm = 1;
1003 ret = bam_ch[id].num_tx_pkts >= HIGH_WATERMARK;
1004 DBG("%s: ch %d num tx pkts=%d, HWM=%d\n", __func__,
1005 id, bam_ch[id].num_tx_pkts, ret);
1006 if (!bam_ch_is_local_open(id)) {
1007 ret = -ENODEV;
1008 pr_err("%s: port not open: %d\n", __func__, bam_ch[id].status);
1009 }
1010 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
1011
1012 return ret;
1013}
1014
1015int msm_bam_dmux_is_ch_low(uint32_t id)
1016{
Eric Holmberged3ca0a2012-04-09 15:44:58 -06001017 unsigned long flags;
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -07001018 int ret;
1019
1020 if (id >= BAM_DMUX_NUM_CHANNELS)
1021 return -EINVAL;
1022
Eric Holmberged3ca0a2012-04-09 15:44:58 -06001023 spin_lock_irqsave(&bam_ch[id].lock, flags);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -07001024 bam_ch[id].use_wm = 1;
1025 ret = bam_ch[id].num_tx_pkts <= LOW_WATERMARK;
1026 DBG("%s: ch %d num tx pkts=%d, LWM=%d\n", __func__,
1027 id, bam_ch[id].num_tx_pkts, ret);
1028 if (!bam_ch_is_local_open(id)) {
1029 ret = -ENODEV;
1030 pr_err("%s: port not open: %d\n", __func__, bam_ch[id].status);
1031 }
Eric Holmberged3ca0a2012-04-09 15:44:58 -06001032 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -07001033
1034 return ret;
1035}
1036
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001037static void rx_switch_to_interrupt_mode(void)
1038{
1039 struct sps_connect cur_rx_conn;
1040 struct sps_iovec iov;
1041 struct rx_pkt_info *info;
1042 int ret;
1043
1044 /*
1045 * Attempt to enable interrupts - if this fails,
1046 * continue polling and we will retry later.
1047 */
1048 ret = sps_get_config(bam_rx_pipe, &cur_rx_conn);
1049 if (ret) {
1050 pr_err("%s: sps_get_config() failed %d\n", __func__, ret);
1051 goto fail;
1052 }
1053
1054 rx_register_event.options = SPS_O_EOT;
1055 ret = sps_register_event(bam_rx_pipe, &rx_register_event);
1056 if (ret) {
1057 pr_err("%s: sps_register_event() failed %d\n", __func__, ret);
1058 goto fail;
1059 }
1060
1061 cur_rx_conn.options = SPS_O_AUTO_ENABLE |
1062 SPS_O_EOT | SPS_O_ACK_TRANSFERS;
1063 ret = sps_set_config(bam_rx_pipe, &cur_rx_conn);
1064 if (ret) {
1065 pr_err("%s: sps_set_config() failed %d\n", __func__, ret);
1066 goto fail;
1067 }
1068 polling_mode = 0;
Eric Holmberg006057d2012-01-11 10:10:42 -07001069 release_wakelock();
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001070
1071 /* handle any rx packets before interrupt was enabled */
1072 while (bam_connection_is_active && !polling_mode) {
1073 ret = sps_get_iovec(bam_rx_pipe, &iov);
1074 if (ret) {
1075 pr_err("%s: sps_get_iovec failed %d\n",
1076 __func__, ret);
1077 break;
1078 }
1079 if (iov.addr == 0)
1080 break;
1081
1082 mutex_lock(&bam_rx_pool_mutexlock);
1083 if (unlikely(list_empty(&bam_rx_pool))) {
Eric Holmberg00cf8692012-07-16 14:21:19 -06001084 DMUX_LOG_KERR("%s: have iovec %p but rx pool empty\n",
1085 __func__, (void *)iov.addr);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001086 mutex_unlock(&bam_rx_pool_mutexlock);
1087 continue;
1088 }
1089 info = list_first_entry(&bam_rx_pool, struct rx_pkt_info,
1090 list_node);
Eric Holmberg00cf8692012-07-16 14:21:19 -06001091 if (info->dma_address != iov.addr) {
1092 DMUX_LOG_KERR("%s: iovec %p != dma %p\n",
1093 __func__,
1094 (void *)iov.addr,
1095 (void *)info->dma_address);
1096 list_for_each_entry(info, &bam_rx_pool, list_node) {
1097 DMUX_LOG_KERR("%s: dma %p\n", __func__,
1098 (void *)info->dma_address);
1099 if (iov.addr == info->dma_address)
1100 break;
1101 }
1102 }
1103 BUG_ON(info->dma_address != iov.addr);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001104 list_del(&info->list_node);
Eric Holmbergb5b08e52012-01-20 14:19:00 -07001105 --bam_rx_pool_len;
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001106 mutex_unlock(&bam_rx_pool_mutexlock);
1107 handle_bam_mux_cmd(&info->work);
1108 }
1109 return;
1110
1111fail:
1112 pr_err("%s: reverting to polling\n", __func__);
Jeff Hugofff43af92012-03-29 17:54:52 -06001113 queue_work_on(0, bam_mux_rx_workqueue, &rx_timer_work);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001114}
1115
Jeff Hugo949080a2011-08-30 11:58:56 -06001116static void rx_timer_work_func(struct work_struct *work)
1117{
1118 struct sps_iovec iov;
Jeff Hugo949080a2011-08-30 11:58:56 -06001119 struct rx_pkt_info *info;
1120 int inactive_cycles = 0;
1121 int ret;
Anurag Singhdcd8b4e2012-07-30 16:46:37 -07001122 u32 buffs_unused, buffs_used;
Jeff Hugo949080a2011-08-30 11:58:56 -06001123
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001124 while (bam_connection_is_active) { /* timer loop */
Jeff Hugo949080a2011-08-30 11:58:56 -06001125 ++inactive_cycles;
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001126 while (bam_connection_is_active) { /* deplete queue loop */
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001127 if (in_global_reset)
1128 return;
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001129
1130 ret = sps_get_iovec(bam_rx_pipe, &iov);
1131 if (ret) {
1132 pr_err("%s: sps_get_iovec failed %d\n",
1133 __func__, ret);
1134 break;
1135 }
Jeff Hugo949080a2011-08-30 11:58:56 -06001136 if (iov.addr == 0)
1137 break;
1138 inactive_cycles = 0;
Jeff Hugoc9749932011-11-02 17:50:40 -06001139 mutex_lock(&bam_rx_pool_mutexlock);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001140 if (unlikely(list_empty(&bam_rx_pool))) {
Eric Holmberg00cf8692012-07-16 14:21:19 -06001141 DMUX_LOG_KERR(
1142 "%s: have iovec %p but rx pool empty\n",
1143 __func__, (void *)iov.addr);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001144 mutex_unlock(&bam_rx_pool_mutexlock);
1145 continue;
1146 }
1147 info = list_first_entry(&bam_rx_pool,
1148 struct rx_pkt_info, list_node);
Eric Holmberg00cf8692012-07-16 14:21:19 -06001149 if (info->dma_address != iov.addr) {
1150 DMUX_LOG_KERR("%s: iovec %p != dma %p\n",
1151 __func__,
1152 (void *)iov.addr,
1153 (void *)info->dma_address);
1154 list_for_each_entry(info, &bam_rx_pool,
1155 list_node) {
1156 DMUX_LOG_KERR("%s: dma %p\n", __func__,
1157 (void *)info->dma_address);
1158 if (iov.addr == info->dma_address)
1159 break;
1160 }
1161 }
1162 BUG_ON(info->dma_address != iov.addr);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001163 list_del(&info->list_node);
Eric Holmberg00cf8692012-07-16 14:21:19 -06001164 --bam_rx_pool_len;
Jeff Hugoc9749932011-11-02 17:50:40 -06001165 mutex_unlock(&bam_rx_pool_mutexlock);
Jeff Hugo949080a2011-08-30 11:58:56 -06001166 handle_bam_mux_cmd(&info->work);
1167 }
1168
Anurag Singhdcd8b4e2012-07-30 16:46:37 -07001169 if (inactive_cycles >= POLLING_INACTIVITY) {
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001170 rx_switch_to_interrupt_mode();
1171 break;
Jeff Hugo949080a2011-08-30 11:58:56 -06001172 }
1173
Anurag Singhdcd8b4e2012-07-30 16:46:37 -07001174 if (bam_adaptive_timer_enabled) {
1175 usleep_range(rx_timer_interval, rx_timer_interval + 50);
1176
1177 ret = sps_get_unused_desc_num(bam_rx_pipe,
1178 &buffs_unused);
1179
1180 if (ret) {
1181 pr_err("%s: error getting num buffers unused after sleep\n",
1182 __func__);
1183
1184 break;
1185 }
1186
Jeff Hugoc8058f82013-03-27 12:44:20 -06001187 buffs_used = num_buffers - buffs_unused;
Anurag Singhdcd8b4e2012-07-30 16:46:37 -07001188
1189 if (buffs_unused == 0) {
1190 rx_timer_interval = MIN_POLLING_SLEEP;
1191 } else {
1192 if (buffs_used > 0) {
1193 rx_timer_interval =
Jeff Hugoc8058f82013-03-27 12:44:20 -06001194 (2 * num_buffers *
Anurag Singhdcd8b4e2012-07-30 16:46:37 -07001195 rx_timer_interval)/
1196 (3 * buffs_used);
1197 } else {
1198 rx_timer_interval =
1199 MAX_POLLING_SLEEP;
1200 }
1201 }
1202
1203 if (rx_timer_interval > MAX_POLLING_SLEEP)
1204 rx_timer_interval = MAX_POLLING_SLEEP;
1205 else if (rx_timer_interval < MIN_POLLING_SLEEP)
1206 rx_timer_interval = MIN_POLLING_SLEEP;
1207 } else {
1208 usleep_range(POLLING_MIN_SLEEP, POLLING_MAX_SLEEP);
1209 }
Jeff Hugo949080a2011-08-30 11:58:56 -06001210 }
1211}
1212
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001213static void bam_mux_tx_notify(struct sps_event_notify *notify)
1214{
1215 struct tx_pkt_info *pkt;
1216
1217 DBG("%s: event %d notified\n", __func__, notify->event_id);
1218
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001219 if (in_global_reset)
1220 return;
1221
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001222 switch (notify->event_id) {
1223 case SPS_EVENT_EOT:
1224 pkt = notify->data.transfer.user;
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001225 if (!pkt->is_cmd)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001226 dma_unmap_single(NULL, pkt->dma_address,
1227 pkt->skb->len,
1228 DMA_TO_DEVICE);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001229 else
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001230 dma_unmap_single(NULL, pkt->dma_address,
1231 pkt->len,
1232 DMA_TO_DEVICE);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001233 queue_work(bam_mux_tx_workqueue, &pkt->work);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001234 break;
1235 default:
1236 pr_err("%s: recieved unexpected event id %d\n", __func__,
1237 notify->event_id);
1238 }
1239}
1240
Jeff Hugo33dbc002011-08-25 15:52:53 -06001241static void bam_mux_rx_notify(struct sps_event_notify *notify)
1242{
Jeff Hugo949080a2011-08-30 11:58:56 -06001243 int ret;
1244 struct sps_connect cur_rx_conn;
Jeff Hugo33dbc002011-08-25 15:52:53 -06001245
1246 DBG("%s: event %d notified\n", __func__, notify->event_id);
1247
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001248 if (in_global_reset)
1249 return;
1250
Jeff Hugo33dbc002011-08-25 15:52:53 -06001251 switch (notify->event_id) {
1252 case SPS_EVENT_EOT:
Jeff Hugo949080a2011-08-30 11:58:56 -06001253 /* attempt to disable interrupts in this pipe */
1254 if (!polling_mode) {
1255 ret = sps_get_config(bam_rx_pipe, &cur_rx_conn);
1256 if (ret) {
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001257 pr_err("%s: sps_get_config() failed %d, interrupts"
1258 " not disabled\n", __func__, ret);
Jeff Hugo949080a2011-08-30 11:58:56 -06001259 break;
1260 }
Jeff Hugoa9d32ba2011-11-21 14:59:48 -07001261 cur_rx_conn.options = SPS_O_AUTO_ENABLE |
Jeff Hugo949080a2011-08-30 11:58:56 -06001262 SPS_O_ACK_TRANSFERS | SPS_O_POLL;
1263 ret = sps_set_config(bam_rx_pipe, &cur_rx_conn);
1264 if (ret) {
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001265 pr_err("%s: sps_set_config() failed %d, interrupts"
1266 " not disabled\n", __func__, ret);
Jeff Hugo949080a2011-08-30 11:58:56 -06001267 break;
1268 }
Eric Holmberg006057d2012-01-11 10:10:42 -07001269 grab_wakelock();
Jeff Hugo949080a2011-08-30 11:58:56 -06001270 polling_mode = 1;
Jeff Hugofff43af92012-03-29 17:54:52 -06001271 /*
1272 * run on core 0 so that netif_rx() in rmnet uses only
1273 * one queue
1274 */
1275 queue_work_on(0, bam_mux_rx_workqueue, &rx_timer_work);
Jeff Hugo949080a2011-08-30 11:58:56 -06001276 }
Jeff Hugo33dbc002011-08-25 15:52:53 -06001277 break;
1278 default:
1279 pr_err("%s: recieved unexpected event id %d\n", __func__,
1280 notify->event_id);
1281 }
1282}
1283
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001284#ifdef CONFIG_DEBUG_FS
1285
1286static int debug_tbl(char *buf, int max)
1287{
1288 int i = 0;
1289 int j;
1290
1291 for (j = 0; j < BAM_DMUX_NUM_CHANNELS; ++j) {
1292 i += scnprintf(buf + i, max - i,
1293 "ch%02d local open=%s remote open=%s\n",
1294 j, bam_ch_is_local_open(j) ? "Y" : "N",
1295 bam_ch_is_remote_open(j) ? "Y" : "N");
1296 }
1297
1298 return i;
1299}
1300
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07001301static int debug_ul_pkt_cnt(char *buf, int max)
1302{
1303 struct list_head *p;
1304 unsigned long flags;
1305 int n = 0;
1306
1307 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
1308 __list_for_each(p, &bam_tx_pool) {
1309 ++n;
1310 }
1311 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
1312
1313 return scnprintf(buf, max, "Number of UL packets in flight: %d\n", n);
1314}
1315
1316static int debug_stats(char *buf, int max)
1317{
1318 int i = 0;
1319
1320 i += scnprintf(buf + i, max - i,
Eric Holmberg9fdef262012-02-14 11:46:05 -07001321 "skb read cnt: %u\n"
1322 "skb write cnt: %u\n"
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07001323 "skb copy cnt: %u\n"
1324 "skb copy bytes: %u\n"
Eric Holmberg6074aba2012-01-18 17:59:44 -07001325 "sps tx failures: %u\n"
Eric Holmbergb5b08e52012-01-20 14:19:00 -07001326 "sps tx stalls: %u\n"
Eric Holmberg1f1255d2012-02-22 13:37:21 -07001327 "rx queue len: %d\n"
1328 "a2 ack out cnt: %d\n"
1329 "a2 ack in cnt: %d\n"
1330 "a2 pwr cntl in: %d\n",
Eric Holmberg9fdef262012-02-14 11:46:05 -07001331 bam_dmux_read_cnt,
1332 bam_dmux_write_cnt,
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07001333 bam_dmux_write_cpy_cnt,
1334 bam_dmux_write_cpy_bytes,
Eric Holmberg6074aba2012-01-18 17:59:44 -07001335 bam_dmux_tx_sps_failure_cnt,
Eric Holmbergb5b08e52012-01-20 14:19:00 -07001336 bam_dmux_tx_stall_cnt,
Eric Holmberg1f1255d2012-02-22 13:37:21 -07001337 bam_rx_pool_len,
1338 atomic_read(&bam_dmux_ack_out_cnt),
1339 atomic_read(&bam_dmux_ack_in_cnt),
1340 atomic_read(&bam_dmux_a2_pwr_cntl_in_cnt)
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07001341 );
1342
1343 return i;
1344}
1345
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001346#define DEBUG_BUFMAX 4096
1347static char debug_buffer[DEBUG_BUFMAX];
1348
1349static ssize_t debug_read(struct file *file, char __user *buf,
1350 size_t count, loff_t *ppos)
1351{
1352 int (*fill)(char *buf, int max) = file->private_data;
1353 int bsize = fill(debug_buffer, DEBUG_BUFMAX);
1354 return simple_read_from_buffer(buf, count, ppos, debug_buffer, bsize);
1355}
1356
1357static int debug_open(struct inode *inode, struct file *file)
1358{
1359 file->private_data = inode->i_private;
1360 return 0;
1361}
1362
1363
1364static const struct file_operations debug_ops = {
1365 .read = debug_read,
1366 .open = debug_open,
1367};
1368
1369static void debug_create(const char *name, mode_t mode,
1370 struct dentry *dent,
1371 int (*fill)(char *buf, int max))
1372{
Eric Holmberge4ac80b2012-01-12 09:21:59 -07001373 struct dentry *file;
1374
1375 file = debugfs_create_file(name, mode, dent, fill, &debug_ops);
1376 if (IS_ERR(file))
1377 pr_err("%s: debugfs create failed %d\n", __func__,
1378 (int)PTR_ERR(file));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001379}
1380
1381#endif
1382
Jeff Hugod98b1082011-10-24 10:30:23 -06001383static void notify_all(int event, unsigned long data)
1384{
1385 int i;
Jeff Hugocb798022012-04-09 14:55:40 -06001386 struct list_head *temp;
1387 struct outside_notify_func *func;
Jeff Hugod98b1082011-10-24 10:30:23 -06001388
Jeff Hugod432a3a2013-04-19 11:05:19 -06001389 BAM_DMUX_LOG("%s: event=%d, data=%lu\n", __func__, event, data);
1390
Jeff Hugod98b1082011-10-24 10:30:23 -06001391 for (i = 0; i < BAM_DMUX_NUM_CHANNELS; ++i) {
Jeff Hugod432a3a2013-04-19 11:05:19 -06001392 if (bam_ch_is_open(i))
Jeff Hugod98b1082011-10-24 10:30:23 -06001393 bam_ch[i].notify(bam_ch[i].priv, event, data);
1394 }
Jeff Hugocb798022012-04-09 14:55:40 -06001395
1396 __list_for_each(temp, &bam_other_notify_funcs) {
1397 func = container_of(temp, struct outside_notify_func,
1398 list_node);
1399 func->notify(func->priv, event, data);
1400 }
Jeff Hugod98b1082011-10-24 10:30:23 -06001401}
1402
1403static void kickoff_ul_wakeup_func(struct work_struct *work)
1404{
1405 read_lock(&ul_wakeup_lock);
1406 if (!bam_is_connected) {
1407 read_unlock(&ul_wakeup_lock);
1408 ul_wakeup();
Jeff Hugo4838f412012-01-20 11:19:37 -07001409 if (unlikely(in_global_reset == 1))
1410 return;
Jeff Hugod98b1082011-10-24 10:30:23 -06001411 read_lock(&ul_wakeup_lock);
1412 ul_packet_written = 1;
1413 notify_all(BAM_DMUX_UL_CONNECTED, (unsigned long)(NULL));
1414 }
1415 read_unlock(&ul_wakeup_lock);
1416}
1417
Eric Holmbergbc9f21c2012-01-18 11:33:33 -07001418int msm_bam_dmux_kickoff_ul_wakeup(void)
Jeff Hugod98b1082011-10-24 10:30:23 -06001419{
Eric Holmbergbc9f21c2012-01-18 11:33:33 -07001420 int is_connected;
1421
1422 read_lock(&ul_wakeup_lock);
1423 ul_packet_written = 1;
1424 is_connected = bam_is_connected;
1425 if (!is_connected)
1426 queue_work(bam_mux_tx_workqueue, &kickoff_ul_wakeup);
1427 read_unlock(&ul_wakeup_lock);
1428
1429 return is_connected;
Jeff Hugod98b1082011-10-24 10:30:23 -06001430}
1431
Eric Holmberg878923a2012-01-10 14:28:19 -07001432static void power_vote(int vote)
1433{
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05301434 BAM_DMUX_LOG("%s: curr=%d, vote=%d\n", __func__,
Eric Holmberg878923a2012-01-10 14:28:19 -07001435 bam_dmux_uplink_vote, vote);
1436
1437 if (bam_dmux_uplink_vote == vote)
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05301438 BAM_DMUX_LOG("%s: warning - duplicate power vote\n", __func__);
Eric Holmberg878923a2012-01-10 14:28:19 -07001439
1440 bam_dmux_uplink_vote = vote;
1441 if (vote)
1442 smsm_change_state(SMSM_APPS_STATE, 0, SMSM_A2_POWER_CONTROL);
1443 else
1444 smsm_change_state(SMSM_APPS_STATE, SMSM_A2_POWER_CONTROL, 0);
1445}
1446
Eric Holmberg454d9da2012-01-12 09:37:14 -07001447/*
1448 * @note: Must be called with ul_wakeup_lock locked.
1449 */
1450static inline void ul_powerdown(void)
1451{
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05301452 BAM_DMUX_LOG("%s: powerdown\n", __func__);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001453 verify_tx_queue_is_empty(__func__);
1454
1455 if (a2_pc_disabled) {
1456 wait_for_dfab = 1;
1457 INIT_COMPLETION(dfab_unvote_completion);
1458 release_wakelock();
1459 } else {
1460 wait_for_ack = 1;
1461 INIT_COMPLETION(ul_wakeup_ack_completion);
1462 power_vote(0);
1463 }
1464 bam_is_connected = 0;
1465 notify_all(BAM_DMUX_UL_DISCONNECTED, (unsigned long)(NULL));
1466}
1467
1468static inline void ul_powerdown_finish(void)
1469{
1470 if (a2_pc_disabled && wait_for_dfab) {
1471 unvote_dfab();
1472 complete_all(&dfab_unvote_completion);
1473 wait_for_dfab = 0;
1474 }
1475}
1476
Eric Holmbergbc9f21c2012-01-18 11:33:33 -07001477/*
1478 * Votes for UL power and returns current power state.
1479 *
1480 * @returns true if currently connected
1481 */
1482int msm_bam_dmux_ul_power_vote(void)
1483{
1484 int is_connected;
1485
1486 read_lock(&ul_wakeup_lock);
1487 atomic_inc(&ul_ondemand_vote);
1488 is_connected = bam_is_connected;
1489 if (!is_connected)
1490 queue_work(bam_mux_tx_workqueue, &kickoff_ul_wakeup);
1491 read_unlock(&ul_wakeup_lock);
1492
1493 return is_connected;
1494}
1495
1496/*
1497 * Unvotes for UL power.
1498 *
1499 * @returns true if vote count is 0 (UL shutdown possible)
1500 */
1501int msm_bam_dmux_ul_power_unvote(void)
1502{
1503 int vote;
1504
1505 read_lock(&ul_wakeup_lock);
1506 vote = atomic_dec_return(&ul_ondemand_vote);
1507 if (unlikely(vote) < 0)
1508 DMUX_LOG_KERR("%s: invalid power vote %d\n", __func__, vote);
1509 read_unlock(&ul_wakeup_lock);
1510
1511 return vote == 0;
1512}
1513
Jeff Hugocb798022012-04-09 14:55:40 -06001514int msm_bam_dmux_reg_notify(void *priv,
1515 void (*notify)(void *priv, int event_type,
1516 unsigned long data))
1517{
1518 struct outside_notify_func *func;
1519
1520 if (!notify)
1521 return -EINVAL;
1522
1523 func = kmalloc(sizeof(struct outside_notify_func), GFP_KERNEL);
1524 if (!func)
1525 return -ENOMEM;
1526
1527 func->notify = notify;
1528 func->priv = priv;
1529 list_add(&func->list_node, &bam_other_notify_funcs);
1530
1531 return 0;
1532}
1533
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001534static void ul_timeout(struct work_struct *work)
1535{
Jeff Hugoc040a5b2011-11-15 14:26:01 -07001536 unsigned long flags;
1537 int ret;
1538
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001539 if (in_global_reset)
1540 return;
Jeff Hugoc040a5b2011-11-15 14:26:01 -07001541 ret = write_trylock_irqsave(&ul_wakeup_lock, flags);
1542 if (!ret) { /* failed to grab lock, reschedule and bail */
1543 schedule_delayed_work(&ul_timeout_work,
1544 msecs_to_jiffies(UL_TIMEOUT_DELAY));
1545 return;
1546 }
Eric Holmberg454d9da2012-01-12 09:37:14 -07001547 if (bam_is_connected) {
Eric Holmberg6074aba2012-01-18 17:59:44 -07001548 if (!ul_packet_written) {
1549 spin_lock(&bam_tx_pool_spinlock);
1550 if (!list_empty(&bam_tx_pool)) {
1551 struct tx_pkt_info *info;
1552
1553 info = list_first_entry(&bam_tx_pool,
1554 struct tx_pkt_info, list_node);
1555 DMUX_LOG_KERR("%s: UL delayed ts=%u.%09lu\n",
1556 __func__, info->ts_sec, info->ts_nsec);
1557 DBG_INC_TX_STALL_CNT();
1558 ul_packet_written = 1;
1559 }
1560 spin_unlock(&bam_tx_pool_spinlock);
1561 }
1562
Eric Holmbergbc9f21c2012-01-18 11:33:33 -07001563 if (ul_packet_written || atomic_read(&ul_ondemand_vote)) {
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05301564 BAM_DMUX_LOG("%s: pkt written %d\n",
Eric Holmbergbc9f21c2012-01-18 11:33:33 -07001565 __func__, ul_packet_written);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001566 ul_packet_written = 0;
1567 schedule_delayed_work(&ul_timeout_work,
1568 msecs_to_jiffies(UL_TIMEOUT_DELAY));
Eric Holmberg006057d2012-01-11 10:10:42 -07001569 } else {
Eric Holmberg454d9da2012-01-12 09:37:14 -07001570 ul_powerdown();
Eric Holmberg006057d2012-01-11 10:10:42 -07001571 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001572 }
Jeff Hugoc040a5b2011-11-15 14:26:01 -07001573 write_unlock_irqrestore(&ul_wakeup_lock, flags);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001574 ul_powerdown_finish();
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001575}
Jeff Hugo4838f412012-01-20 11:19:37 -07001576
1577static int ssrestart_check(void)
1578{
Jeff Hugo8648e9a2013-06-04 12:51:10 -06001579 int ret = 0;
1580
1581 DMUX_LOG_KERR("%s: modem timeout: BAM DMUX disabled for SSR\n",
1582 __func__);
Eric Holmberg90285e22012-02-22 12:33:05 -07001583 in_global_reset = 1;
Jeff Hugo8648e9a2013-06-04 12:51:10 -06001584 ret = subsystem_restart("modem");
1585 if (ret == -ENODEV)
1586 panic("modem subsystem restart failed\n");
Eric Holmberg90285e22012-02-22 12:33:05 -07001587 return 1;
Jeff Hugo4838f412012-01-20 11:19:37 -07001588}
1589
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001590static void ul_wakeup(void)
1591{
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001592 int ret;
Jeff Hugo5f57ec92012-05-14 13:34:28 -06001593 int do_vote_dfab = 0;
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001594
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001595 mutex_lock(&wakeup_lock);
1596 if (bam_is_connected) { /* bam got connected before lock grabbed */
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05301597 BAM_DMUX_LOG("%s Already awake\n", __func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001598 mutex_unlock(&wakeup_lock);
1599 return;
1600 }
Eric Holmberg878923a2012-01-10 14:28:19 -07001601
Jeff Hugoc2696142012-05-03 11:42:13 -06001602 /*
Jeff Hugo00424ff2012-08-27 13:19:09 -06001603 * if this gets hit, that means restart_notifier_cb() has started
1604 * but probably not finished, thus we know SSR has happened, but
1605 * haven't been able to send that info to our clients yet.
1606 * in that case, abort the ul_wakeup() so that we don't undo any
1607 * work restart_notifier_cb() has done. The clients will be notified
1608 * shortly. No cleanup necessary (reschedule the wakeup) as our and
1609 * their SSR handling will cover it
1610 */
1611 if (unlikely(in_global_reset == 1)) {
1612 mutex_unlock(&wakeup_lock);
1613 return;
1614 }
1615
1616 /*
Jeff Hugoc2696142012-05-03 11:42:13 -06001617 * if someone is voting for UL before bam is inited (modem up first
1618 * time), set flag for init to kickoff ul wakeup once bam is inited
1619 */
1620 mutex_lock(&delayed_ul_vote_lock);
1621 if (unlikely(!bam_mux_initialized)) {
1622 need_delayed_ul_vote = 1;
1623 mutex_unlock(&delayed_ul_vote_lock);
1624 mutex_unlock(&wakeup_lock);
1625 return;
1626 }
1627 mutex_unlock(&delayed_ul_vote_lock);
1628
Eric Holmberg006057d2012-01-11 10:10:42 -07001629 if (a2_pc_disabled) {
1630 /*
1631 * don't grab the wakelock the first time because it is
1632 * already grabbed when a2 powers on
1633 */
Jeff Hugo5f57ec92012-05-14 13:34:28 -06001634 if (likely(a2_pc_disabled_wakelock_skipped)) {
Eric Holmberg006057d2012-01-11 10:10:42 -07001635 grab_wakelock();
Jeff Hugo5f57ec92012-05-14 13:34:28 -06001636 do_vote_dfab = 1; /* vote must occur after wait */
1637 } else {
Jeff Hugo583a6da2012-02-03 11:37:30 -07001638 a2_pc_disabled_wakelock_skipped = 1;
Jeff Hugo5f57ec92012-05-14 13:34:28 -06001639 }
Eric Holmberg006057d2012-01-11 10:10:42 -07001640 if (wait_for_dfab) {
Jeff Hugo66f7f1e2012-01-16 14:30:42 -07001641 ret = wait_for_completion_timeout(
Eric Holmberg006057d2012-01-11 10:10:42 -07001642 &dfab_unvote_completion, HZ);
1643 BUG_ON(ret == 0);
1644 }
Jeff Hugo5f57ec92012-05-14 13:34:28 -06001645 if (likely(do_vote_dfab))
1646 vote_dfab();
Eric Holmberg006057d2012-01-11 10:10:42 -07001647 schedule_delayed_work(&ul_timeout_work,
1648 msecs_to_jiffies(UL_TIMEOUT_DELAY));
1649 bam_is_connected = 1;
1650 mutex_unlock(&wakeup_lock);
1651 return;
1652 }
1653
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001654 /*
1655 * must wait for the previous power down request to have been acked
1656 * chances are it already came in and this will just fall through
1657 * instead of waiting
1658 */
1659 if (wait_for_ack) {
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05301660 BAM_DMUX_LOG("%s waiting for previous ack\n", __func__);
Jeff Hugo66f7f1e2012-01-16 14:30:42 -07001661 ret = wait_for_completion_timeout(
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001662 &ul_wakeup_ack_completion, HZ);
Eric Holmberg006057d2012-01-11 10:10:42 -07001663 wait_for_ack = 0;
Jeff Hugo4838f412012-01-20 11:19:37 -07001664 if (unlikely(ret == 0) && ssrestart_check()) {
1665 mutex_unlock(&wakeup_lock);
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05301666 BAM_DMUX_LOG("%s timeout previous ack\n", __func__);
Jeff Hugo4838f412012-01-20 11:19:37 -07001667 return;
1668 }
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001669 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001670 INIT_COMPLETION(ul_wakeup_ack_completion);
Eric Holmberg878923a2012-01-10 14:28:19 -07001671 power_vote(1);
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05301672 BAM_DMUX_LOG("%s waiting for wakeup ack\n", __func__);
Jeff Hugo66f7f1e2012-01-16 14:30:42 -07001673 ret = wait_for_completion_timeout(&ul_wakeup_ack_completion, HZ);
Jeff Hugo4838f412012-01-20 11:19:37 -07001674 if (unlikely(ret == 0) && ssrestart_check()) {
1675 mutex_unlock(&wakeup_lock);
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05301676 BAM_DMUX_LOG("%s timeout wakeup ack\n", __func__);
Jeff Hugo4838f412012-01-20 11:19:37 -07001677 return;
1678 }
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05301679 BAM_DMUX_LOG("%s waiting completion\n", __func__);
Jeff Hugo66f7f1e2012-01-16 14:30:42 -07001680 ret = wait_for_completion_timeout(&bam_connection_completion, HZ);
Jeff Hugo4838f412012-01-20 11:19:37 -07001681 if (unlikely(ret == 0) && ssrestart_check()) {
1682 mutex_unlock(&wakeup_lock);
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05301683 BAM_DMUX_LOG("%s timeout power on\n", __func__);
Jeff Hugo4838f412012-01-20 11:19:37 -07001684 return;
1685 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001686
1687 bam_is_connected = 1;
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05301688 BAM_DMUX_LOG("%s complete\n", __func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001689 schedule_delayed_work(&ul_timeout_work,
1690 msecs_to_jiffies(UL_TIMEOUT_DELAY));
1691 mutex_unlock(&wakeup_lock);
1692}
1693
1694static void reconnect_to_bam(void)
1695{
1696 int i;
1697
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001698 in_global_reset = 0;
Jeff Hugo73f356f2012-12-14 17:56:19 -07001699 in_ssr = 0;
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001700 vote_dfab();
Jeff Hugo18792a32012-06-20 15:25:55 -06001701 if (!power_management_only_mode) {
Jeff Hugo73f356f2012-12-14 17:56:19 -07001702 if (ssr_skipped_disconnect) {
1703 /* delayed to here to prevent bus stall */
1704 sps_disconnect(bam_tx_pipe);
1705 sps_disconnect(bam_rx_pipe);
1706 __memzero(rx_desc_mem_buf.base, rx_desc_mem_buf.size);
1707 __memzero(tx_desc_mem_buf.base, tx_desc_mem_buf.size);
1708 }
1709 ssr_skipped_disconnect = 0;
Jeff Hugo18792a32012-06-20 15:25:55 -06001710 i = sps_device_reset(a2_device_handle);
1711 if (i)
1712 pr_err("%s: device reset failed rc = %d\n", __func__,
1713 i);
1714 i = sps_connect(bam_tx_pipe, &tx_connection);
1715 if (i)
1716 pr_err("%s: tx connection failed rc = %d\n", __func__,
1717 i);
1718 i = sps_connect(bam_rx_pipe, &rx_connection);
1719 if (i)
1720 pr_err("%s: rx connection failed rc = %d\n", __func__,
1721 i);
1722 i = sps_register_event(bam_tx_pipe, &tx_register_event);
1723 if (i)
1724 pr_err("%s: tx event reg failed rc = %d\n", __func__,
1725 i);
1726 i = sps_register_event(bam_rx_pipe, &rx_register_event);
1727 if (i)
1728 pr_err("%s: rx event reg failed rc = %d\n", __func__,
1729 i);
1730 }
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001731
1732 bam_connection_is_active = 1;
1733
1734 if (polling_mode)
1735 rx_switch_to_interrupt_mode();
1736
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001737 toggle_apps_ack();
1738 complete_all(&bam_connection_completion);
Jeff Hugo18792a32012-06-20 15:25:55 -06001739 if (!power_management_only_mode)
1740 queue_rx();
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001741}
1742
1743static void disconnect_to_bam(void)
1744{
1745 struct list_head *node;
1746 struct rx_pkt_info *info;
Eric Holmberg454d9da2012-01-12 09:37:14 -07001747 unsigned long flags;
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001748
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001749 bam_connection_is_active = 0;
Eric Holmberg454d9da2012-01-12 09:37:14 -07001750
1751 /* handle disconnect during active UL */
1752 write_lock_irqsave(&ul_wakeup_lock, flags);
1753 if (bam_is_connected) {
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05301754 BAM_DMUX_LOG("%s: UL active - forcing powerdown\n", __func__);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001755 ul_powerdown();
1756 }
1757 write_unlock_irqrestore(&ul_wakeup_lock, flags);
1758 ul_powerdown_finish();
1759
1760 /* tear down BAM connection */
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001761 INIT_COMPLETION(bam_connection_completion);
Jeff Hugo73f356f2012-12-14 17:56:19 -07001762
1763 /* in_ssr documentation/assumptions found in restart_notifier_cb */
1764 if (!power_management_only_mode) {
1765 if (likely(!in_ssr)) {
Jeff Hugodaebad92013-04-19 11:18:32 -06001766 BAM_DMUX_LOG("%s: disconnect tx\n", __func__);
Jeff Hugo73f356f2012-12-14 17:56:19 -07001767 sps_disconnect(bam_tx_pipe);
Jeff Hugodaebad92013-04-19 11:18:32 -06001768 BAM_DMUX_LOG("%s: disconnect rx\n", __func__);
Jeff Hugo73f356f2012-12-14 17:56:19 -07001769 sps_disconnect(bam_rx_pipe);
1770 __memzero(rx_desc_mem_buf.base, rx_desc_mem_buf.size);
1771 __memzero(tx_desc_mem_buf.base, tx_desc_mem_buf.size);
Jeff Hugodaebad92013-04-19 11:18:32 -06001772 BAM_DMUX_LOG("%s: device reset\n", __func__);
Jeff Hugo73f356f2012-12-14 17:56:19 -07001773 sps_device_reset(a2_device_handle);
1774 } else {
1775 ssr_skipped_disconnect = 1;
1776 }
1777 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001778 unvote_dfab();
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001779
1780 mutex_lock(&bam_rx_pool_mutexlock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001781 while (!list_empty(&bam_rx_pool)) {
1782 node = bam_rx_pool.next;
1783 list_del(node);
1784 info = container_of(node, struct rx_pkt_info, list_node);
1785 dma_unmap_single(NULL, info->dma_address, BUFFER_SIZE,
1786 DMA_FROM_DEVICE);
1787 dev_kfree_skb_any(info->skb);
1788 kfree(info);
1789 }
Eric Holmbergb5b08e52012-01-20 14:19:00 -07001790 bam_rx_pool_len = 0;
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001791 mutex_unlock(&bam_rx_pool_mutexlock);
Eric Holmberg878923a2012-01-10 14:28:19 -07001792
Jeff Hugo0b13a352012-03-17 23:18:30 -06001793 if (disconnect_ack)
1794 toggle_apps_ack();
1795
Eric Holmberg878923a2012-01-10 14:28:19 -07001796 verify_tx_queue_is_empty(__func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001797}
1798
1799static void vote_dfab(void)
1800{
Jeff Hugoca0caa82011-12-05 16:05:23 -07001801 int rc;
1802
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05301803 BAM_DMUX_LOG("%s\n", __func__);
Eric Holmberg006057d2012-01-11 10:10:42 -07001804 mutex_lock(&dfab_status_lock);
1805 if (dfab_is_on) {
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05301806 BAM_DMUX_LOG("%s: dfab is already on\n", __func__);
Eric Holmberg006057d2012-01-11 10:10:42 -07001807 mutex_unlock(&dfab_status_lock);
1808 return;
1809 }
Jeff Hugo0c9371a2012-08-09 15:32:49 -06001810 if (dfab_clk) {
1811 rc = clk_prepare_enable(dfab_clk);
1812 if (rc)
1813 DMUX_LOG_KERR("bam_dmux vote for dfab failed rc = %d\n",
1814 rc);
1815 }
1816 if (xo_clk) {
1817 rc = clk_prepare_enable(xo_clk);
1818 if (rc)
1819 DMUX_LOG_KERR("bam_dmux vote for xo failed rc = %d\n",
1820 rc);
1821 }
Eric Holmberg006057d2012-01-11 10:10:42 -07001822 dfab_is_on = 1;
1823 mutex_unlock(&dfab_status_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001824}
1825
1826static void unvote_dfab(void)
1827{
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05301828 BAM_DMUX_LOG("%s\n", __func__);
Eric Holmberg006057d2012-01-11 10:10:42 -07001829 mutex_lock(&dfab_status_lock);
1830 if (!dfab_is_on) {
1831 DMUX_LOG_KERR("%s: dfab is already off\n", __func__);
1832 dump_stack();
1833 mutex_unlock(&dfab_status_lock);
1834 return;
1835 }
Jeff Hugo0c9371a2012-08-09 15:32:49 -06001836 if (dfab_clk)
1837 clk_disable_unprepare(dfab_clk);
1838 if (xo_clk)
1839 clk_disable_unprepare(xo_clk);
Eric Holmberg006057d2012-01-11 10:10:42 -07001840 dfab_is_on = 0;
1841 mutex_unlock(&dfab_status_lock);
1842}
1843
1844/* reference counting wrapper around wakelock */
1845static void grab_wakelock(void)
1846{
1847 unsigned long flags;
1848
1849 spin_lock_irqsave(&wakelock_reference_lock, flags);
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05301850 BAM_DMUX_LOG("%s: ref count = %d\n", __func__,
Eric Holmberg006057d2012-01-11 10:10:42 -07001851 wakelock_reference_count);
1852 if (wakelock_reference_count == 0)
1853 wake_lock(&bam_wakelock);
1854 ++wakelock_reference_count;
1855 spin_unlock_irqrestore(&wakelock_reference_lock, flags);
1856}
1857
1858static void release_wakelock(void)
1859{
1860 unsigned long flags;
1861
1862 spin_lock_irqsave(&wakelock_reference_lock, flags);
1863 if (wakelock_reference_count == 0) {
1864 DMUX_LOG_KERR("%s: bam_dmux wakelock not locked\n", __func__);
1865 dump_stack();
1866 spin_unlock_irqrestore(&wakelock_reference_lock, flags);
1867 return;
1868 }
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05301869 BAM_DMUX_LOG("%s: ref count = %d\n", __func__,
Eric Holmberg006057d2012-01-11 10:10:42 -07001870 wakelock_reference_count);
1871 --wakelock_reference_count;
1872 if (wakelock_reference_count == 0)
1873 wake_unlock(&bam_wakelock);
1874 spin_unlock_irqrestore(&wakelock_reference_lock, flags);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001875}
1876
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001877static int restart_notifier_cb(struct notifier_block *this,
1878 unsigned long code,
1879 void *data)
1880{
1881 int i;
1882 struct list_head *node;
1883 struct tx_pkt_info *info;
1884 int temp_remote_status;
Jeff Hugo626303bf2011-11-21 11:43:28 -07001885 unsigned long flags;
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001886
Jeff Hugo73f356f2012-12-14 17:56:19 -07001887 /*
1888 * Bam_dmux counts on the fact that the BEFORE_SHUTDOWN level of
1889 * notifications are guarenteed to execute before the AFTER_SHUTDOWN
1890 * level of notifications, and that BEFORE_SHUTDOWN always occurs in
1891 * all SSR events, no matter what triggered the SSR. Also, bam_dmux
1892 * assumes that SMD does its SSR processing in the AFTER_SHUTDOWN level
1893 * thus bam_dmux is guarenteed to detect SSR before SMD, since the
1894 * callbacks for all the drivers within the AFTER_SHUTDOWN level could
1895 * occur in any order. Bam_dmux uses this knowledge to skip accessing
1896 * the bam hardware when disconnect_to_bam() is triggered by SMD's SSR
1897 * processing. We do not wat to access the bam hardware during SSR
1898 * because a watchdog crash from a bus stall would likely occur.
1899 */
Jeff Hugob6f72f12013-02-25 13:46:56 -07001900 if (code == SUBSYS_BEFORE_SHUTDOWN) {
1901 in_global_reset = 1;
Jeff Hugo73f356f2012-12-14 17:56:19 -07001902 in_ssr = 1;
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05301903 BAM_DMUX_LOG("%s: begin\n", __func__);
Jeff Hugob6f72f12013-02-25 13:46:56 -07001904 flush_workqueue(bam_mux_rx_workqueue);
1905 }
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001906 if (code != SUBSYS_AFTER_SHUTDOWN)
1907 return NOTIFY_DONE;
1908
Eric Holmberg454d9da2012-01-12 09:37:14 -07001909 /* Handle uplink Powerdown */
1910 write_lock_irqsave(&ul_wakeup_lock, flags);
1911 if (bam_is_connected) {
1912 ul_powerdown();
1913 wait_for_ack = 0;
1914 }
Jeff Hugo4838f412012-01-20 11:19:37 -07001915 /*
1916 * if modem crash during ul_wakeup(), power_vote is 1, needs to be
1917 * reset to 0. harmless if bam_is_connected check above passes
1918 */
1919 power_vote(0);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001920 write_unlock_irqrestore(&ul_wakeup_lock, flags);
1921 ul_powerdown_finish();
Eric Holmberg006057d2012-01-11 10:10:42 -07001922 a2_pc_disabled = 0;
Jeff Hugo583a6da2012-02-03 11:37:30 -07001923 a2_pc_disabled_wakelock_skipped = 0;
Jeff Hugof62029d2012-07-17 13:39:53 -06001924 disconnect_ack = 1;
Eric Holmberg454d9da2012-01-12 09:37:14 -07001925
1926 /* Cleanup Channel States */
Eric Holmberga623da82012-07-12 09:37:09 -06001927 mutex_lock(&bam_pdev_mutexlock);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001928 for (i = 0; i < BAM_DMUX_NUM_CHANNELS; ++i) {
1929 temp_remote_status = bam_ch_is_remote_open(i);
1930 bam_ch[i].status &= ~BAM_CH_REMOTE_OPEN;
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -07001931 bam_ch[i].num_tx_pkts = 0;
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001932 if (bam_ch_is_local_open(i))
1933 bam_ch[i].status |= BAM_CH_IN_RESET;
1934 if (temp_remote_status) {
1935 platform_device_unregister(bam_ch[i].pdev);
1936 bam_ch[i].pdev = platform_device_alloc(
1937 bam_ch[i].name, 2);
1938 }
1939 }
Eric Holmberga623da82012-07-12 09:37:09 -06001940 mutex_unlock(&bam_pdev_mutexlock);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001941
1942 /* Cleanup pending UL data */
Jeff Hugo626303bf2011-11-21 11:43:28 -07001943 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001944 while (!list_empty(&bam_tx_pool)) {
1945 node = bam_tx_pool.next;
1946 list_del(node);
1947 info = container_of(node, struct tx_pkt_info,
1948 list_node);
1949 if (!info->is_cmd) {
1950 dma_unmap_single(NULL, info->dma_address,
1951 info->skb->len,
1952 DMA_TO_DEVICE);
1953 dev_kfree_skb_any(info->skb);
1954 } else {
1955 dma_unmap_single(NULL, info->dma_address,
1956 info->len,
1957 DMA_TO_DEVICE);
1958 kfree(info->skb);
1959 }
1960 kfree(info);
1961 }
Jeff Hugo626303bf2011-11-21 11:43:28 -07001962 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001963
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05301964 BAM_DMUX_LOG("%s: complete\n", __func__);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001965 return NOTIFY_DONE;
1966}
1967
Jeff Hugo9dea05c2011-12-21 12:23:05 -07001968static int bam_init(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001969{
1970 u32 h;
1971 dma_addr_t dma_addr;
1972 int ret;
1973 void *a2_virt_addr;
Jeff Hugo4b2890d2012-01-16 16:14:21 -07001974 int skip_iounmap = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001975
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001976 vote_dfab();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001977 /* init BAM */
Jeff Hugo7bf02052012-08-21 14:08:20 -06001978 a2_virt_addr = ioremap_nocache((unsigned long)(a2_phys_base),
1979 a2_phys_size);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001980 if (!a2_virt_addr) {
1981 pr_err("%s: ioremap failed\n", __func__);
1982 ret = -ENOMEM;
Jeff Hugo994a92d2012-01-05 13:25:21 -07001983 goto ioremap_failed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001984 }
Jeff Hugo7bf02052012-08-21 14:08:20 -06001985 a2_props.phys_addr = (u32)(a2_phys_base);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001986 a2_props.virt_addr = a2_virt_addr;
Jeff Hugo7bf02052012-08-21 14:08:20 -06001987 a2_props.virt_size = a2_phys_size;
1988 a2_props.irq = a2_bam_irq;
Jeff Hugo927cba62011-11-11 11:49:52 -07001989 a2_props.options = SPS_BAM_OPT_IRQ_WAKEUP;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001990 a2_props.num_pipes = A2_NUM_PIPES;
1991 a2_props.summing_threshold = A2_SUMMING_THRESHOLD;
Jeff Hugo02acb6e2013-04-09 13:50:09 -06001992 a2_props.constrained_logging = true;
1993 a2_props.logging_number = 1;
Jeff Hugo0682dad2012-10-22 11:34:28 -06001994 if (cpu_is_msm9615() || satellite_mode)
Jeff Hugo75913c82011-12-05 15:59:01 -07001995 a2_props.manage = SPS_BAM_MGR_DEVICE_REMOTE;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001996 /* need to free on tear down */
1997 ret = sps_register_bam_device(&a2_props, &h);
1998 if (ret < 0) {
1999 pr_err("%s: register bam error %d\n", __func__, ret);
2000 goto register_bam_failed;
2001 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002002 a2_device_handle = h;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002003
2004 bam_tx_pipe = sps_alloc_endpoint();
2005 if (bam_tx_pipe == NULL) {
2006 pr_err("%s: tx alloc endpoint failed\n", __func__);
2007 ret = -ENOMEM;
Jeff Hugo8ff4a812012-01-17 11:03:13 -07002008 goto tx_alloc_endpoint_failed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002009 }
2010 ret = sps_get_config(bam_tx_pipe, &tx_connection);
2011 if (ret) {
2012 pr_err("%s: tx get config failed %d\n", __func__, ret);
2013 goto tx_get_config_failed;
2014 }
2015
2016 tx_connection.source = SPS_DEV_HANDLE_MEM;
2017 tx_connection.src_pipe_index = 0;
2018 tx_connection.destination = h;
2019 tx_connection.dest_pipe_index = 4;
2020 tx_connection.mode = SPS_MODE_DEST;
2021 tx_connection.options = SPS_O_AUTO_ENABLE | SPS_O_EOT;
2022 tx_desc_mem_buf.size = 0x800; /* 2k */
2023 tx_desc_mem_buf.base = dma_alloc_coherent(NULL, tx_desc_mem_buf.size,
2024 &dma_addr, 0);
2025 if (tx_desc_mem_buf.base == NULL) {
2026 pr_err("%s: tx memory alloc failed\n", __func__);
2027 ret = -ENOMEM;
Jeff Hugo8ff4a812012-01-17 11:03:13 -07002028 goto tx_get_config_failed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002029 }
2030 tx_desc_mem_buf.phys_base = dma_addr;
2031 memset(tx_desc_mem_buf.base, 0x0, tx_desc_mem_buf.size);
2032 tx_connection.desc = tx_desc_mem_buf;
2033 tx_connection.event_thresh = 0x10;
2034
2035 ret = sps_connect(bam_tx_pipe, &tx_connection);
2036 if (ret < 0) {
2037 pr_err("%s: tx connect error %d\n", __func__, ret);
2038 goto tx_connect_failed;
2039 }
2040
2041 bam_rx_pipe = sps_alloc_endpoint();
2042 if (bam_rx_pipe == NULL) {
2043 pr_err("%s: rx alloc endpoint failed\n", __func__);
2044 ret = -ENOMEM;
Jeff Hugo8ff4a812012-01-17 11:03:13 -07002045 goto rx_alloc_endpoint_failed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002046 }
2047 ret = sps_get_config(bam_rx_pipe, &rx_connection);
2048 if (ret) {
2049 pr_err("%s: rx get config failed %d\n", __func__, ret);
2050 goto rx_get_config_failed;
2051 }
2052
2053 rx_connection.source = h;
2054 rx_connection.src_pipe_index = 5;
2055 rx_connection.destination = SPS_DEV_HANDLE_MEM;
2056 rx_connection.dest_pipe_index = 1;
2057 rx_connection.mode = SPS_MODE_SRC;
Jeff Hugo949080a2011-08-30 11:58:56 -06002058 rx_connection.options = SPS_O_AUTO_ENABLE | SPS_O_EOT |
2059 SPS_O_ACK_TRANSFERS;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002060 rx_desc_mem_buf.size = 0x800; /* 2k */
2061 rx_desc_mem_buf.base = dma_alloc_coherent(NULL, rx_desc_mem_buf.size,
2062 &dma_addr, 0);
2063 if (rx_desc_mem_buf.base == NULL) {
2064 pr_err("%s: rx memory alloc failed\n", __func__);
2065 ret = -ENOMEM;
2066 goto rx_mem_failed;
2067 }
2068 rx_desc_mem_buf.phys_base = dma_addr;
2069 memset(rx_desc_mem_buf.base, 0x0, rx_desc_mem_buf.size);
2070 rx_connection.desc = rx_desc_mem_buf;
2071 rx_connection.event_thresh = 0x10;
2072
2073 ret = sps_connect(bam_rx_pipe, &rx_connection);
2074 if (ret < 0) {
2075 pr_err("%s: rx connect error %d\n", __func__, ret);
2076 goto rx_connect_failed;
2077 }
2078
2079 tx_register_event.options = SPS_O_EOT;
2080 tx_register_event.mode = SPS_TRIGGER_CALLBACK;
2081 tx_register_event.xfer_done = NULL;
2082 tx_register_event.callback = bam_mux_tx_notify;
2083 tx_register_event.user = NULL;
2084 ret = sps_register_event(bam_tx_pipe, &tx_register_event);
2085 if (ret < 0) {
2086 pr_err("%s: tx register event error %d\n", __func__, ret);
2087 goto rx_event_reg_failed;
2088 }
2089
Jeff Hugo33dbc002011-08-25 15:52:53 -06002090 rx_register_event.options = SPS_O_EOT;
2091 rx_register_event.mode = SPS_TRIGGER_CALLBACK;
2092 rx_register_event.xfer_done = NULL;
2093 rx_register_event.callback = bam_mux_rx_notify;
2094 rx_register_event.user = NULL;
2095 ret = sps_register_event(bam_rx_pipe, &rx_register_event);
2096 if (ret < 0) {
2097 pr_err("%s: tx register event error %d\n", __func__, ret);
2098 goto rx_event_reg_failed;
2099 }
2100
Jeff Hugoc2696142012-05-03 11:42:13 -06002101 mutex_lock(&delayed_ul_vote_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002102 bam_mux_initialized = 1;
Jeff Hugoc2696142012-05-03 11:42:13 -06002103 if (need_delayed_ul_vote) {
2104 need_delayed_ul_vote = 0;
2105 msm_bam_dmux_kickoff_ul_wakeup();
2106 }
2107 mutex_unlock(&delayed_ul_vote_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002108 toggle_apps_ack();
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06002109 bam_connection_is_active = 1;
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002110 complete_all(&bam_connection_completion);
Jeff Hugo2fb555e2012-03-14 16:33:47 -06002111 queue_rx();
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002112 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002113
2114rx_event_reg_failed:
2115 sps_disconnect(bam_rx_pipe);
2116rx_connect_failed:
2117 dma_free_coherent(NULL, rx_desc_mem_buf.size, rx_desc_mem_buf.base,
2118 rx_desc_mem_buf.phys_base);
2119rx_mem_failed:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002120rx_get_config_failed:
2121 sps_free_endpoint(bam_rx_pipe);
Jeff Hugo8ff4a812012-01-17 11:03:13 -07002122rx_alloc_endpoint_failed:
2123 sps_disconnect(bam_tx_pipe);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002124tx_connect_failed:
2125 dma_free_coherent(NULL, tx_desc_mem_buf.size, tx_desc_mem_buf.base,
2126 tx_desc_mem_buf.phys_base);
2127tx_get_config_failed:
2128 sps_free_endpoint(bam_tx_pipe);
Jeff Hugo8ff4a812012-01-17 11:03:13 -07002129tx_alloc_endpoint_failed:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002130 sps_deregister_bam_device(h);
Jeff Hugo4b2890d2012-01-16 16:14:21 -07002131 /*
2132 * sps_deregister_bam_device() calls iounmap. calling iounmap on the
2133 * same handle below will cause a crash, so skip it if we've freed
2134 * the handle here.
2135 */
2136 skip_iounmap = 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002137register_bam_failed:
Jeff Hugo4b2890d2012-01-16 16:14:21 -07002138 if (!skip_iounmap)
2139 iounmap(a2_virt_addr);
Jeff Hugo994a92d2012-01-05 13:25:21 -07002140ioremap_failed:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002141 /*destroy_workqueue(bam_mux_workqueue);*/
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002142 return ret;
2143}
2144
2145static int bam_init_fallback(void)
2146{
2147 u32 h;
2148 int ret;
2149 void *a2_virt_addr;
2150
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002151 /* init BAM */
Jeff Hugo7bf02052012-08-21 14:08:20 -06002152 a2_virt_addr = ioremap_nocache((unsigned long)(a2_phys_base),
2153 a2_phys_size);
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002154 if (!a2_virt_addr) {
2155 pr_err("%s: ioremap failed\n", __func__);
2156 ret = -ENOMEM;
2157 goto ioremap_failed;
2158 }
Jeff Hugo7bf02052012-08-21 14:08:20 -06002159 a2_props.phys_addr = (u32)(a2_phys_base);
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002160 a2_props.virt_addr = a2_virt_addr;
Jeff Hugo7bf02052012-08-21 14:08:20 -06002161 a2_props.virt_size = a2_phys_size;
2162 a2_props.irq = a2_bam_irq;
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002163 a2_props.options = SPS_BAM_OPT_IRQ_WAKEUP;
2164 a2_props.num_pipes = A2_NUM_PIPES;
2165 a2_props.summing_threshold = A2_SUMMING_THRESHOLD;
Jeff Hugo0682dad2012-10-22 11:34:28 -06002166 if (cpu_is_msm9615() || satellite_mode)
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002167 a2_props.manage = SPS_BAM_MGR_DEVICE_REMOTE;
2168 ret = sps_register_bam_device(&a2_props, &h);
2169 if (ret < 0) {
2170 pr_err("%s: register bam error %d\n", __func__, ret);
2171 goto register_bam_failed;
2172 }
2173 a2_device_handle = h;
Jeff Hugoc2696142012-05-03 11:42:13 -06002174
2175 mutex_lock(&delayed_ul_vote_lock);
2176 bam_mux_initialized = 1;
2177 if (need_delayed_ul_vote) {
2178 need_delayed_ul_vote = 0;
2179 msm_bam_dmux_kickoff_ul_wakeup();
2180 }
2181 mutex_unlock(&delayed_ul_vote_lock);
Jeff Hugo2bec9772012-04-05 12:25:16 -06002182 toggle_apps_ack();
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002183
Jeff Hugo18792a32012-06-20 15:25:55 -06002184 power_management_only_mode = 1;
2185 bam_connection_is_active = 1;
2186 complete_all(&bam_connection_completion);
2187
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002188 return 0;
2189
2190register_bam_failed:
Jeff Hugo4b2890d2012-01-16 16:14:21 -07002191 iounmap(a2_virt_addr);
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002192ioremap_failed:
2193 return ret;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002194}
Jeff Hugoade1f842011-08-03 15:53:59 -06002195
Jeff Hugoa670b762012-03-15 15:58:28 -06002196static void msm9615_bam_init(void)
Eric Holmberg604ab252012-01-15 00:01:18 -07002197{
2198 int ret = 0;
2199
2200 ret = bam_init();
2201 if (ret) {
2202 ret = bam_init_fallback();
2203 if (ret)
2204 pr_err("%s: bam init fallback failed: %d",
2205 __func__, ret);
2206 }
2207}
2208
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002209static void toggle_apps_ack(void)
2210{
2211 static unsigned int clear_bit; /* 0 = set the bit, else clear bit */
Eric Holmberg878923a2012-01-10 14:28:19 -07002212
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05302213 BAM_DMUX_LOG("%s: apps ack %d->%d\n", __func__,
Eric Holmberg878923a2012-01-10 14:28:19 -07002214 clear_bit & 0x1, ~clear_bit & 0x1);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002215 smsm_change_state(SMSM_APPS_STATE,
2216 clear_bit & SMSM_A2_POWER_CONTROL_ACK,
2217 ~clear_bit & SMSM_A2_POWER_CONTROL_ACK);
2218 clear_bit = ~clear_bit;
Eric Holmberg1f1255d2012-02-22 13:37:21 -07002219 DBG_INC_ACK_OUT_CNT();
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002220}
2221
Jeff Hugoade1f842011-08-03 15:53:59 -06002222static void bam_dmux_smsm_cb(void *priv, uint32_t old_state, uint32_t new_state)
2223{
Jeff Hugo4b7c7b32012-04-18 16:25:14 -06002224 static int last_processed_state;
2225
2226 mutex_lock(&smsm_cb_lock);
Eric Holmberg878923a2012-01-10 14:28:19 -07002227 bam_dmux_power_state = new_state & SMSM_A2_POWER_CONTROL ? 1 : 0;
Eric Holmberg1f1255d2012-02-22 13:37:21 -07002228 DBG_INC_A2_POWER_CONTROL_IN_CNT();
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05302229 BAM_DMUX_LOG("%s: 0x%08x -> 0x%08x\n", __func__, old_state,
Eric Holmberg878923a2012-01-10 14:28:19 -07002230 new_state);
Jeff Hugo4b7c7b32012-04-18 16:25:14 -06002231 if (last_processed_state == (new_state & SMSM_A2_POWER_CONTROL)) {
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05302232 BAM_DMUX_LOG("%s: already processed this state\n", __func__);
Jeff Hugo4b7c7b32012-04-18 16:25:14 -06002233 mutex_unlock(&smsm_cb_lock);
2234 return;
2235 }
2236
2237 last_processed_state = new_state & SMSM_A2_POWER_CONTROL;
Eric Holmberg878923a2012-01-10 14:28:19 -07002238
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002239 if (bam_mux_initialized && new_state & SMSM_A2_POWER_CONTROL) {
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05302240 BAM_DMUX_LOG("%s: reconnect\n", __func__);
Eric Holmberg006057d2012-01-11 10:10:42 -07002241 grab_wakelock();
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002242 reconnect_to_bam();
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002243 } else if (bam_mux_initialized &&
2244 !(new_state & SMSM_A2_POWER_CONTROL)) {
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05302245 BAM_DMUX_LOG("%s: disconnect\n", __func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002246 disconnect_to_bam();
Eric Holmberg006057d2012-01-11 10:10:42 -07002247 release_wakelock();
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002248 } else if (new_state & SMSM_A2_POWER_CONTROL) {
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05302249 BAM_DMUX_LOG("%s: init\n", __func__);
Eric Holmberg006057d2012-01-11 10:10:42 -07002250 grab_wakelock();
Jeff Hugoa670b762012-03-15 15:58:28 -06002251 if (cpu_is_msm9615())
2252 msm9615_bam_init();
2253 else
Eric Holmberg604ab252012-01-15 00:01:18 -07002254 bam_init();
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002255 } else {
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05302256 BAM_DMUX_LOG("%s: bad state change\n", __func__);
Jeff Hugoade1f842011-08-03 15:53:59 -06002257 pr_err("%s: unsupported state change\n", __func__);
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002258 }
Jeff Hugo4b7c7b32012-04-18 16:25:14 -06002259 mutex_unlock(&smsm_cb_lock);
Jeff Hugoade1f842011-08-03 15:53:59 -06002260
2261}
2262
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002263static void bam_dmux_smsm_ack_cb(void *priv, uint32_t old_state,
2264 uint32_t new_state)
2265{
Eric Holmberg1f1255d2012-02-22 13:37:21 -07002266 DBG_INC_ACK_IN_CNT();
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05302267 BAM_DMUX_LOG("%s: 0x%08x -> 0x%08x\n", __func__, old_state,
Eric Holmberg878923a2012-01-10 14:28:19 -07002268 new_state);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002269 complete_all(&ul_wakeup_ack_completion);
2270}
2271
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002272static int bam_dmux_probe(struct platform_device *pdev)
2273{
2274 int rc;
Jeff Hugo7bf02052012-08-21 14:08:20 -06002275 struct resource *r;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002276
2277 DBG("%s probe called\n", __func__);
2278 if (bam_mux_initialized)
2279 return 0;
2280
Jeff Hugo7bf02052012-08-21 14:08:20 -06002281 if (pdev->dev.of_node) {
2282 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2283 if (!r) {
2284 pr_err("%s: reg field missing\n", __func__);
2285 return -ENODEV;
2286 }
2287 a2_phys_base = (void *)(r->start);
2288 a2_phys_size = (uint32_t)(resource_size(r));
2289 a2_bam_irq = platform_get_irq(pdev, 0);
2290 if (a2_bam_irq == -ENXIO) {
2291 pr_err("%s: irq field missing\n", __func__);
2292 return -ENODEV;
2293 }
Jeff Hugo0682dad2012-10-22 11:34:28 -06002294 satellite_mode = of_property_read_bool(pdev->dev.of_node,
2295 "qcom,satellite-mode");
2296
Jeff Hugoc8058f82013-03-27 12:44:20 -06002297 rc = of_property_read_u32(pdev->dev.of_node,
2298 "qcom,rx-ring-size",
2299 &num_buffers);
2300 if (rc) {
2301 DBG("%s: falling back to num_buffs default, rc:%d\n",
2302 __func__, rc);
2303 num_buffers = DEFAULT_NUM_BUFFERS;
2304 }
2305
2306 DBG("%s: base:%p size:%x irq:%d satellite:%d num_buffs:%d\n",
2307 __func__,
Jeff Hugo7bf02052012-08-21 14:08:20 -06002308 a2_phys_base,
2309 a2_phys_size,
Jeff Hugo0682dad2012-10-22 11:34:28 -06002310 a2_bam_irq,
Jeff Hugoc8058f82013-03-27 12:44:20 -06002311 satellite_mode,
2312 num_buffers);
Jeff Hugo7bf02052012-08-21 14:08:20 -06002313 } else { /* fallback to default init data */
2314 a2_phys_base = (void *)(A2_PHYS_BASE);
2315 a2_phys_size = A2_PHYS_SIZE;
2316 a2_bam_irq = A2_BAM_IRQ;
Jeff Hugoc8058f82013-03-27 12:44:20 -06002317 num_buffers = DEFAULT_NUM_BUFFERS;
Jeff Hugo7bf02052012-08-21 14:08:20 -06002318 }
2319
Stephen Boyd69d35e32012-02-14 15:33:30 -08002320 xo_clk = clk_get(&pdev->dev, "xo");
2321 if (IS_ERR(xo_clk)) {
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05302322 BAM_DMUX_LOG("%s: did not get xo clock\n", __func__);
Jeff Hugo0c9371a2012-08-09 15:32:49 -06002323 xo_clk = NULL;
Stephen Boyd69d35e32012-02-14 15:33:30 -08002324 }
Stephen Boyd1c51a492011-10-26 12:11:47 -07002325 dfab_clk = clk_get(&pdev->dev, "bus_clk");
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002326 if (IS_ERR(dfab_clk)) {
Zaheerulla Meerffb54ce2013-02-13 15:49:14 +05302327 BAM_DMUX_LOG("%s: did not get dfab clock\n", __func__);
Jeff Hugo0c9371a2012-08-09 15:32:49 -06002328 dfab_clk = NULL;
2329 } else {
2330 rc = clk_set_rate(dfab_clk, 64000000);
2331 if (rc)
2332 pr_err("%s: unable to set dfab clock rate\n", __func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002333 }
2334
Jeff Hugofff43af92012-03-29 17:54:52 -06002335 /*
2336 * setup the workqueue so that it can be pinned to core 0 and not
2337 * block the watchdog pet function, so that netif_rx() in rmnet
2338 * only uses one queue.
2339 */
2340 bam_mux_rx_workqueue = alloc_workqueue("bam_dmux_rx",
2341 WQ_MEM_RECLAIM | WQ_CPU_INTENSIVE, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002342 if (!bam_mux_rx_workqueue)
2343 return -ENOMEM;
2344
2345 bam_mux_tx_workqueue = create_singlethread_workqueue("bam_dmux_tx");
2346 if (!bam_mux_tx_workqueue) {
2347 destroy_workqueue(bam_mux_rx_workqueue);
2348 return -ENOMEM;
2349 }
2350
Jeff Hugo7960abd2011-08-02 15:39:38 -06002351 for (rc = 0; rc < BAM_DMUX_NUM_CHANNELS; ++rc) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002352 spin_lock_init(&bam_ch[rc].lock);
Jeff Hugo7960abd2011-08-02 15:39:38 -06002353 scnprintf(bam_ch[rc].name, BAM_DMUX_CH_NAME_MAX_LEN,
2354 "bam_dmux_ch_%d", rc);
2355 /* bus 2, ie a2 stream 2 */
2356 bam_ch[rc].pdev = platform_device_alloc(bam_ch[rc].name, 2);
2357 if (!bam_ch[rc].pdev) {
2358 pr_err("%s: platform device alloc failed\n", __func__);
2359 destroy_workqueue(bam_mux_rx_workqueue);
2360 destroy_workqueue(bam_mux_tx_workqueue);
2361 return -ENOMEM;
2362 }
2363 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002364
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002365 init_completion(&ul_wakeup_ack_completion);
2366 init_completion(&bam_connection_completion);
Eric Holmberg006057d2012-01-11 10:10:42 -07002367 init_completion(&dfab_unvote_completion);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002368 INIT_DELAYED_WORK(&ul_timeout_work, ul_timeout);
Jeff Hugoad75d8d2012-10-03 15:53:54 -06002369 INIT_DELAYED_WORK(&queue_rx_work, queue_rx_work_func);
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002370 wake_lock_init(&bam_wakelock, WAKE_LOCK_SUSPEND, "bam_dmux_wakelock");
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002371
Jeff Hugoade1f842011-08-03 15:53:59 -06002372 rc = smsm_state_cb_register(SMSM_MODEM_STATE, SMSM_A2_POWER_CONTROL,
2373 bam_dmux_smsm_cb, NULL);
2374
2375 if (rc) {
2376 destroy_workqueue(bam_mux_rx_workqueue);
2377 destroy_workqueue(bam_mux_tx_workqueue);
2378 pr_err("%s: smsm cb register failed, rc: %d\n", __func__, rc);
2379 return -ENOMEM;
2380 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002381
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002382 rc = smsm_state_cb_register(SMSM_MODEM_STATE, SMSM_A2_POWER_CONTROL_ACK,
2383 bam_dmux_smsm_ack_cb, NULL);
2384
2385 if (rc) {
2386 destroy_workqueue(bam_mux_rx_workqueue);
2387 destroy_workqueue(bam_mux_tx_workqueue);
2388 smsm_state_cb_deregister(SMSM_MODEM_STATE,
2389 SMSM_A2_POWER_CONTROL,
2390 bam_dmux_smsm_cb, NULL);
2391 pr_err("%s: smsm ack cb register failed, rc: %d\n", __func__,
2392 rc);
2393 for (rc = 0; rc < BAM_DMUX_NUM_CHANNELS; ++rc)
2394 platform_device_put(bam_ch[rc].pdev);
2395 return -ENOMEM;
2396 }
2397
Eric Holmbergfd1e2ae2011-11-15 18:28:17 -07002398 if (smsm_get_state(SMSM_MODEM_STATE) & SMSM_A2_POWER_CONTROL)
2399 bam_dmux_smsm_cb(NULL, 0, smsm_get_state(SMSM_MODEM_STATE));
2400
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002401 return 0;
2402}
2403
Jeff Hugo7bf02052012-08-21 14:08:20 -06002404static struct of_device_id msm_match_table[] = {
2405 {.compatible = "qcom,bam_dmux"},
2406 {},
2407};
2408
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002409static struct platform_driver bam_dmux_driver = {
2410 .probe = bam_dmux_probe,
2411 .driver = {
2412 .name = "BAM_RMNT",
2413 .owner = THIS_MODULE,
Jeff Hugo7bf02052012-08-21 14:08:20 -06002414 .of_match_table = msm_match_table,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002415 },
2416};
2417
2418static int __init bam_dmux_init(void)
2419{
2420#ifdef CONFIG_DEBUG_FS
2421 struct dentry *dent;
2422
2423 dent = debugfs_create_dir("bam_dmux", 0);
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07002424 if (!IS_ERR(dent)) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002425 debug_create("tbl", 0444, dent, debug_tbl);
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07002426 debug_create("ul_pkt_cnt", 0444, dent, debug_ul_pkt_cnt);
2427 debug_create("stats", 0444, dent, debug_stats);
2428 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002429#endif
Zaheerulla Meeraa9fd5c2013-01-31 17:06:44 +05302430
2431 bam_ipc_log_txt = ipc_log_context_create(BAM_IPC_LOG_PAGES, "bam_dmux");
2432 if (!bam_ipc_log_txt) {
2433 pr_err("%s : unable to create IPC Logging Context", __func__);
Eric Holmberg878923a2012-01-10 14:28:19 -07002434 }
2435
Anurag Singhdcd8b4e2012-07-30 16:46:37 -07002436 rx_timer_interval = DEFAULT_POLLING_MIN_SLEEP;
2437
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06002438 subsys_notif_register_notifier("modem", &restart_notifier);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002439 return platform_driver_register(&bam_dmux_driver);
2440}
2441
Jeff Hugoade1f842011-08-03 15:53:59 -06002442late_initcall(bam_dmux_init); /* needs to init after SMD */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002443MODULE_DESCRIPTION("MSM BAM DMUX");
2444MODULE_LICENSE("GPL v2");