blob: f1abde4b4c7bcf290edf915334abd58ab0d382b5 [file] [log] [blame]
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001/* Copyright (c) 2011-2012, Code Aurora Forum. 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>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070030
31#include <mach/sps.h>
32#include <mach/bam_dmux.h>
Jeff Hugoade1f842011-08-03 15:53:59 -060033#include <mach/msm_smsm.h>
Jeff Hugo6e7a92a2011-10-24 05:25:13 -060034#include <mach/subsystem_notif.h>
Jeff Hugo75913c82011-12-05 15:59:01 -070035#include <mach/socinfo.h>
Jeff Hugo4838f412012-01-20 11:19:37 -070036#include <mach/subsystem_restart.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070037
38#define BAM_CH_LOCAL_OPEN 0x1
39#define BAM_CH_REMOTE_OPEN 0x2
Jeff Hugo6e7a92a2011-10-24 05:25:13 -060040#define BAM_CH_IN_RESET 0x4
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070041
42#define BAM_MUX_HDR_MAGIC_NO 0x33fc
43
Eric Holmberg006057d2012-01-11 10:10:42 -070044#define BAM_MUX_HDR_CMD_DATA 0
45#define BAM_MUX_HDR_CMD_OPEN 1
46#define BAM_MUX_HDR_CMD_CLOSE 2
47#define BAM_MUX_HDR_CMD_STATUS 3 /* unused */
48#define BAM_MUX_HDR_CMD_OPEN_NO_A2_PC 4
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070049
Jeff Hugo949080a2011-08-30 11:58:56 -060050#define POLLING_MIN_SLEEP 950 /* 0.95 ms */
51#define POLLING_MAX_SLEEP 1050 /* 1.05 ms */
52#define POLLING_INACTIVITY 40 /* cycles before switch to intr mode */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070053
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -070054#define LOW_WATERMARK 2
55#define HIGH_WATERMARK 4
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070056
57static int msm_bam_dmux_debug_enable;
58module_param_named(debug_enable, msm_bam_dmux_debug_enable,
59 int, S_IRUGO | S_IWUSR | S_IWGRP);
60
61#if defined(DEBUG)
62static uint32_t bam_dmux_read_cnt;
63static uint32_t bam_dmux_write_cnt;
64static uint32_t bam_dmux_write_cpy_cnt;
65static uint32_t bam_dmux_write_cpy_bytes;
Eric Holmberg2fddbcd2011-11-28 18:25:57 -070066static uint32_t bam_dmux_tx_sps_failure_cnt;
Eric Holmberg6074aba2012-01-18 17:59:44 -070067static uint32_t bam_dmux_tx_stall_cnt;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070068
69#define DBG(x...) do { \
70 if (msm_bam_dmux_debug_enable) \
71 pr_debug(x); \
72 } while (0)
73
74#define DBG_INC_READ_CNT(x) do { \
75 bam_dmux_read_cnt += (x); \
76 if (msm_bam_dmux_debug_enable) \
77 pr_debug("%s: total read bytes %u\n", \
78 __func__, bam_dmux_read_cnt); \
79 } while (0)
80
81#define DBG_INC_WRITE_CNT(x) do { \
82 bam_dmux_write_cnt += (x); \
83 if (msm_bam_dmux_debug_enable) \
84 pr_debug("%s: total written bytes %u\n", \
85 __func__, bam_dmux_write_cnt); \
86 } while (0)
87
88#define DBG_INC_WRITE_CPY(x) do { \
89 bam_dmux_write_cpy_bytes += (x); \
90 bam_dmux_write_cpy_cnt++; \
91 if (msm_bam_dmux_debug_enable) \
92 pr_debug("%s: total write copy cnt %u, bytes %u\n", \
93 __func__, bam_dmux_write_cpy_cnt, \
94 bam_dmux_write_cpy_bytes); \
95 } while (0)
Eric Holmberg2fddbcd2011-11-28 18:25:57 -070096
97#define DBG_INC_TX_SPS_FAILURE_CNT() do { \
98 bam_dmux_tx_sps_failure_cnt++; \
99} while (0)
100
Eric Holmberg6074aba2012-01-18 17:59:44 -0700101#define DBG_INC_TX_STALL_CNT() do { \
102 bam_dmux_tx_stall_cnt++; \
103} while (0)
104
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700105#else
106#define DBG(x...) do { } while (0)
107#define DBG_INC_READ_CNT(x...) do { } while (0)
108#define DBG_INC_WRITE_CNT(x...) do { } while (0)
109#define DBG_INC_WRITE_CPY(x...) do { } while (0)
Eric Holmberg2fddbcd2011-11-28 18:25:57 -0700110#define DBG_INC_TX_SPS_FAILURE_CNT() do { } while (0)
Eric Holmberg6074aba2012-01-18 17:59:44 -0700111#define DBG_INC_TX_STALL_CNT() do { } while (0)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700112#endif
113
114struct bam_ch_info {
115 uint32_t status;
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600116 void (*notify)(void *, int, unsigned long);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700117 void *priv;
118 spinlock_t lock;
Jeff Hugo7960abd2011-08-02 15:39:38 -0600119 struct platform_device *pdev;
120 char name[BAM_DMUX_CH_NAME_MAX_LEN];
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700121 int num_tx_pkts;
122 int use_wm;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700123};
124
125struct tx_pkt_info {
126 struct sk_buff *skb;
127 dma_addr_t dma_address;
128 char is_cmd;
129 uint32_t len;
130 struct work_struct work;
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600131 struct list_head list_node;
Eric Holmberg878923a2012-01-10 14:28:19 -0700132 unsigned ts_sec;
133 unsigned long ts_nsec;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700134};
135
136struct rx_pkt_info {
137 struct sk_buff *skb;
138 dma_addr_t dma_address;
139 struct work_struct work;
Jeff Hugo949080a2011-08-30 11:58:56 -0600140 struct list_head list_node;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700141};
142
143#define A2_NUM_PIPES 6
144#define A2_SUMMING_THRESHOLD 4096
145#define A2_DEFAULT_DESCRIPTORS 32
146#define A2_PHYS_BASE 0x124C2000
147#define A2_PHYS_SIZE 0x2000
148#define BUFFER_SIZE 2048
149#define NUM_BUFFERS 32
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700150static struct sps_bam_props a2_props;
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600151static u32 a2_device_handle;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700152static struct sps_pipe *bam_tx_pipe;
153static struct sps_pipe *bam_rx_pipe;
154static struct sps_connect tx_connection;
155static struct sps_connect rx_connection;
156static struct sps_mem_buffer tx_desc_mem_buf;
157static struct sps_mem_buffer rx_desc_mem_buf;
158static struct sps_register_event tx_register_event;
Jeff Hugo33dbc002011-08-25 15:52:53 -0600159static struct sps_register_event rx_register_event;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700160
161static struct bam_ch_info bam_ch[BAM_DMUX_NUM_CHANNELS];
162static int bam_mux_initialized;
163
Jeff Hugo949080a2011-08-30 11:58:56 -0600164static int polling_mode;
165
166static LIST_HEAD(bam_rx_pool);
Jeff Hugoc9749932011-11-02 17:50:40 -0600167static DEFINE_MUTEX(bam_rx_pool_mutexlock);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700168static int bam_rx_pool_len;
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600169static LIST_HEAD(bam_tx_pool);
Jeff Hugoc9749932011-11-02 17:50:40 -0600170static DEFINE_SPINLOCK(bam_tx_pool_spinlock);
Jeff Hugo949080a2011-08-30 11:58:56 -0600171
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700172struct bam_mux_hdr {
173 uint16_t magic_num;
174 uint8_t reserved;
175 uint8_t cmd;
176 uint8_t pad_len;
177 uint8_t ch_id;
178 uint16_t pkt_len;
179};
180
Jeff Hugod98b1082011-10-24 10:30:23 -0600181static void notify_all(int event, unsigned long data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700182static void bam_mux_write_done(struct work_struct *work);
183static void handle_bam_mux_cmd(struct work_struct *work);
Jeff Hugo949080a2011-08-30 11:58:56 -0600184static void rx_timer_work_func(struct work_struct *work);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700185
Jeff Hugo949080a2011-08-30 11:58:56 -0600186static DECLARE_WORK(rx_timer_work, rx_timer_work_func);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700187
188static struct workqueue_struct *bam_mux_rx_workqueue;
189static struct workqueue_struct *bam_mux_tx_workqueue;
190
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600191/* A2 power collaspe */
192#define UL_TIMEOUT_DELAY 1000 /* in ms */
193static void toggle_apps_ack(void);
194static void reconnect_to_bam(void);
195static void disconnect_to_bam(void);
196static void ul_wakeup(void);
197static void ul_timeout(struct work_struct *work);
198static void vote_dfab(void);
199static void unvote_dfab(void);
Jeff Hugod98b1082011-10-24 10:30:23 -0600200static void kickoff_ul_wakeup_func(struct work_struct *work);
Eric Holmberg006057d2012-01-11 10:10:42 -0700201static void grab_wakelock(void);
202static void release_wakelock(void);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600203
204static int bam_is_connected;
205static DEFINE_MUTEX(wakeup_lock);
206static struct completion ul_wakeup_ack_completion;
207static struct completion bam_connection_completion;
208static struct delayed_work ul_timeout_work;
209static int ul_packet_written;
Eric Holmbergbc9f21c2012-01-18 11:33:33 -0700210static atomic_t ul_ondemand_vote = ATOMIC_INIT(0);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600211static struct clk *dfab_clk;
212static DEFINE_RWLOCK(ul_wakeup_lock);
Jeff Hugod98b1082011-10-24 10:30:23 -0600213static DECLARE_WORK(kickoff_ul_wakeup, kickoff_ul_wakeup_func);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600214static int bam_connection_is_active;
Jeff Hugof6c1c1e2011-12-01 17:43:49 -0700215static int wait_for_ack;
Jeff Hugoae3a85e2011-12-02 17:10:18 -0700216static struct wake_lock bam_wakelock;
Eric Holmberg006057d2012-01-11 10:10:42 -0700217static int a2_pc_disabled;
218static DEFINE_MUTEX(dfab_status_lock);
219static int dfab_is_on;
220static int wait_for_dfab;
221static struct completion dfab_unvote_completion;
222static DEFINE_SPINLOCK(wakelock_reference_lock);
223static int wakelock_reference_count;
Eric Holmberg604ab252012-01-15 00:01:18 -0700224static struct delayed_work msm9615_bam_init_work;
Jeff Hugo583a6da2012-02-03 11:37:30 -0700225static int a2_pc_disabled_wakelock_skipped;
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600226/* End A2 power collaspe */
227
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600228/* subsystem restart */
229static int restart_notifier_cb(struct notifier_block *this,
230 unsigned long code,
231 void *data);
232
233static struct notifier_block restart_notifier = {
234 .notifier_call = restart_notifier_cb,
235};
236static int in_global_reset;
237/* end subsystem restart */
238
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700239#define bam_ch_is_open(x) \
240 (bam_ch[(x)].status == (BAM_CH_LOCAL_OPEN | BAM_CH_REMOTE_OPEN))
241
242#define bam_ch_is_local_open(x) \
243 (bam_ch[(x)].status & BAM_CH_LOCAL_OPEN)
244
245#define bam_ch_is_remote_open(x) \
246 (bam_ch[(x)].status & BAM_CH_REMOTE_OPEN)
247
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600248#define bam_ch_is_in_reset(x) \
249 (bam_ch[(x)].status & BAM_CH_IN_RESET)
250
Eric Holmberg878923a2012-01-10 14:28:19 -0700251#define LOG_MESSAGE_MAX_SIZE 80
252struct kfifo bam_dmux_state_log;
253static uint32_t bam_dmux_state_logging_disabled;
254static DEFINE_SPINLOCK(bam_dmux_logging_spinlock);
255static int bam_dmux_uplink_vote;
256static int bam_dmux_power_state;
257
258
259#define DMUX_LOG_KERR(fmt...) \
260do { \
261 bam_dmux_log(fmt); \
262 pr_err(fmt); \
263} while (0)
264
265/**
266 * Log a state change along with a small message.
267 *
268 * Complete size of messsage is limited to @todo.
269 */
270static void bam_dmux_log(const char *fmt, ...)
271{
272 char buff[LOG_MESSAGE_MAX_SIZE];
273 unsigned long flags;
274 va_list arg_list;
275 unsigned long long t_now;
276 unsigned long nanosec_rem;
277 int len = 0;
278
279 if (bam_dmux_state_logging_disabled)
280 return;
281
282 t_now = sched_clock();
283 nanosec_rem = do_div(t_now, 1000000000U);
284
285 /*
286 * States
Eric Holmberg006057d2012-01-11 10:10:42 -0700287 * D: 1 = Power collapse disabled
Eric Holmberg878923a2012-01-10 14:28:19 -0700288 * R: 1 = in global reset
289 * P: 1 = BAM is powered up
290 * A: 1 = BAM initialized and ready for data
291 *
292 * V: 1 = Uplink vote for power
293 * U: 1 = Uplink active
294 * W: 1 = Uplink Wait-for-ack
295 * A: 1 = Uplink ACK received
Eric Holmbergbc9f21c2012-01-18 11:33:33 -0700296 * #: >=1 On-demand uplink vote
Eric Holmberg878923a2012-01-10 14:28:19 -0700297 */
298 len += scnprintf(buff, sizeof(buff),
Eric Holmbergbc9f21c2012-01-18 11:33:33 -0700299 "<DMUX> %u.%09lu %c%c%c%c %c%c%c%c%d ",
Eric Holmberg878923a2012-01-10 14:28:19 -0700300 (unsigned)t_now, nanosec_rem,
Eric Holmberg006057d2012-01-11 10:10:42 -0700301 a2_pc_disabled ? 'D' : 'd',
Eric Holmberg878923a2012-01-10 14:28:19 -0700302 in_global_reset ? 'R' : 'r',
303 bam_dmux_power_state ? 'P' : 'p',
304 bam_connection_is_active ? 'A' : 'a',
305 bam_dmux_uplink_vote ? 'V' : 'v',
306 bam_is_connected ? 'U' : 'u',
307 wait_for_ack ? 'W' : 'w',
Eric Holmbergbc9f21c2012-01-18 11:33:33 -0700308 ul_wakeup_ack_completion.done ? 'A' : 'a',
309 atomic_read(&ul_ondemand_vote)
Eric Holmberg878923a2012-01-10 14:28:19 -0700310 );
311
312 va_start(arg_list, fmt);
313 len += vscnprintf(buff + len, sizeof(buff) - len, fmt, arg_list);
314 va_end(arg_list);
315 memset(buff + len, 0x0, sizeof(buff) - len);
316
317 spin_lock_irqsave(&bam_dmux_logging_spinlock, flags);
318 if (kfifo_avail(&bam_dmux_state_log) < LOG_MESSAGE_MAX_SIZE) {
319 char junk[LOG_MESSAGE_MAX_SIZE];
320 int ret;
321
322 ret = kfifo_out(&bam_dmux_state_log, junk, sizeof(junk));
323 if (ret != LOG_MESSAGE_MAX_SIZE) {
324 pr_err("%s: unable to empty log %d\n", __func__, ret);
325 spin_unlock_irqrestore(&bam_dmux_logging_spinlock,
326 flags);
327 return;
328 }
329 }
330 kfifo_in(&bam_dmux_state_log, buff, sizeof(buff));
331 spin_unlock_irqrestore(&bam_dmux_logging_spinlock, flags);
332}
333
334static inline void set_tx_timestamp(struct tx_pkt_info *pkt)
335{
336 unsigned long long t_now;
337
338 t_now = sched_clock();
339 pkt->ts_nsec = do_div(t_now, 1000000000U);
340 pkt->ts_sec = (unsigned)t_now;
341}
342
343static inline void verify_tx_queue_is_empty(const char *func)
344{
345 unsigned long flags;
346 struct tx_pkt_info *info;
347 int reported = 0;
348
349 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
350 list_for_each_entry(info, &bam_tx_pool, list_node) {
351 if (!reported) {
Eric Holmberg454d9da2012-01-12 09:37:14 -0700352 bam_dmux_log("%s: tx pool not empty\n", func);
353 if (!in_global_reset)
354 pr_err("%s: tx pool not empty\n", func);
Eric Holmberg878923a2012-01-10 14:28:19 -0700355 reported = 1;
356 }
Eric Holmberg454d9da2012-01-12 09:37:14 -0700357 bam_dmux_log("%s: node=%p ts=%u.%09lu\n", __func__,
358 &info->list_node, info->ts_sec, info->ts_nsec);
359 if (!in_global_reset)
360 pr_err("%s: node=%p ts=%u.%09lu\n", __func__,
361 &info->list_node, info->ts_sec, info->ts_nsec);
Eric Holmberg878923a2012-01-10 14:28:19 -0700362 }
363 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
364}
365
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700366static void queue_rx(void)
367{
368 void *ptr;
369 struct rx_pkt_info *info;
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700370 int ret;
371 int rx_len_cached;
Jeff Hugo949080a2011-08-30 11:58:56 -0600372
Jeff Hugoc9749932011-11-02 17:50:40 -0600373 mutex_lock(&bam_rx_pool_mutexlock);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700374 rx_len_cached = bam_rx_pool_len;
Jeff Hugoc9749932011-11-02 17:50:40 -0600375 mutex_unlock(&bam_rx_pool_mutexlock);
Jeff Hugo949080a2011-08-30 11:58:56 -0600376
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700377 while (rx_len_cached < NUM_BUFFERS) {
378 if (in_global_reset)
379 goto fail;
380
381 info = kmalloc(sizeof(struct rx_pkt_info), GFP_KERNEL);
382 if (!info) {
383 pr_err("%s: unable to alloc rx_pkt_info\n", __func__);
384 goto fail;
385 }
386
387 INIT_WORK(&info->work, handle_bam_mux_cmd);
388
389 info->skb = __dev_alloc_skb(BUFFER_SIZE, GFP_KERNEL);
390 if (info->skb == NULL) {
391 DMUX_LOG_KERR("%s: unable to alloc skb\n", __func__);
392 goto fail_info;
393 }
394 ptr = skb_put(info->skb, BUFFER_SIZE);
395
396 info->dma_address = dma_map_single(NULL, ptr, BUFFER_SIZE,
397 DMA_FROM_DEVICE);
398 if (info->dma_address == 0 || info->dma_address == ~0) {
399 DMUX_LOG_KERR("%s: dma_map_single failure %p for %p\n",
400 __func__, (void *)info->dma_address, ptr);
401 goto fail_skb;
402 }
403
404 mutex_lock(&bam_rx_pool_mutexlock);
405 list_add_tail(&info->list_node, &bam_rx_pool);
406 rx_len_cached = ++bam_rx_pool_len;
407 mutex_unlock(&bam_rx_pool_mutexlock);
408
409 ret = sps_transfer_one(bam_rx_pipe, info->dma_address,
410 BUFFER_SIZE, info,
411 SPS_IOVEC_FLAG_INT | SPS_IOVEC_FLAG_EOT);
412
413 if (ret) {
414 DMUX_LOG_KERR("%s: sps_transfer_one failed %d\n",
415 __func__, ret);
416 goto fail_transfer;
417 }
418 }
419 return;
420
421fail_transfer:
422 mutex_lock(&bam_rx_pool_mutexlock);
423 list_del(&info->list_node);
424 --bam_rx_pool_len;
425 rx_len_cached = bam_rx_pool_len;
426 mutex_unlock(&bam_rx_pool_mutexlock);
427
428 dma_unmap_single(NULL, info->dma_address, BUFFER_SIZE,
429 DMA_FROM_DEVICE);
430
431fail_skb:
432 dev_kfree_skb_any(info->skb);
433
434fail_info:
435 kfree(info);
436
437fail:
438 if (rx_len_cached == 0) {
439 DMUX_LOG_KERR("%s: RX queue failure\n", __func__);
440 in_global_reset = 1;
441 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700442}
443
444static void bam_mux_process_data(struct sk_buff *rx_skb)
445{
446 unsigned long flags;
447 struct bam_mux_hdr *rx_hdr;
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600448 unsigned long event_data;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700449
450 rx_hdr = (struct bam_mux_hdr *)rx_skb->data;
451
452 rx_skb->data = (unsigned char *)(rx_hdr + 1);
453 rx_skb->tail = rx_skb->data + rx_hdr->pkt_len;
454 rx_skb->len = rx_hdr->pkt_len;
Jeff Hugoee88f672011-10-04 17:14:52 -0600455 rx_skb->truesize = rx_hdr->pkt_len + sizeof(struct sk_buff);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700456
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600457 event_data = (unsigned long)(rx_skb);
458
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700459 spin_lock_irqsave(&bam_ch[rx_hdr->ch_id].lock, flags);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600460 if (bam_ch[rx_hdr->ch_id].notify)
461 bam_ch[rx_hdr->ch_id].notify(
462 bam_ch[rx_hdr->ch_id].priv, BAM_DMUX_RECEIVE,
463 event_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700464 else
465 dev_kfree_skb_any(rx_skb);
466 spin_unlock_irqrestore(&bam_ch[rx_hdr->ch_id].lock, flags);
467
468 queue_rx();
469}
470
Eric Holmberg006057d2012-01-11 10:10:42 -0700471static inline void handle_bam_mux_cmd_open(struct bam_mux_hdr *rx_hdr)
472{
473 unsigned long flags;
474 int ret;
475
476 spin_lock_irqsave(&bam_ch[rx_hdr->ch_id].lock, flags);
477 bam_ch[rx_hdr->ch_id].status |= BAM_CH_REMOTE_OPEN;
478 bam_ch[rx_hdr->ch_id].num_tx_pkts = 0;
479 spin_unlock_irqrestore(&bam_ch[rx_hdr->ch_id].lock, flags);
480 queue_rx();
481 ret = platform_device_add(bam_ch[rx_hdr->ch_id].pdev);
482 if (ret)
483 pr_err("%s: platform_device_add() error: %d\n",
484 __func__, ret);
485}
486
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700487static void handle_bam_mux_cmd(struct work_struct *work)
488{
489 unsigned long flags;
490 struct bam_mux_hdr *rx_hdr;
491 struct rx_pkt_info *info;
492 struct sk_buff *rx_skb;
493
494 info = container_of(work, struct rx_pkt_info, work);
495 rx_skb = info->skb;
Jeff Hugo949080a2011-08-30 11:58:56 -0600496 dma_unmap_single(NULL, info->dma_address, BUFFER_SIZE, DMA_FROM_DEVICE);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700497 kfree(info);
498
499 rx_hdr = (struct bam_mux_hdr *)rx_skb->data;
500
501 DBG_INC_READ_CNT(sizeof(struct bam_mux_hdr));
502 DBG("%s: magic %x reserved %d cmd %d pad %d ch %d len %d\n", __func__,
503 rx_hdr->magic_num, rx_hdr->reserved, rx_hdr->cmd,
504 rx_hdr->pad_len, rx_hdr->ch_id, rx_hdr->pkt_len);
505 if (rx_hdr->magic_num != BAM_MUX_HDR_MAGIC_NO) {
Eric Holmberg878923a2012-01-10 14:28:19 -0700506 DMUX_LOG_KERR("%s: dropping invalid hdr. magic %x"
507 " reserved %d cmd %d"
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700508 " pad %d ch %d len %d\n", __func__,
509 rx_hdr->magic_num, rx_hdr->reserved, rx_hdr->cmd,
510 rx_hdr->pad_len, rx_hdr->ch_id, rx_hdr->pkt_len);
511 dev_kfree_skb_any(rx_skb);
512 queue_rx();
513 return;
514 }
Eric Holmberg9ff40a52011-11-17 19:17:00 -0700515
516 if (rx_hdr->ch_id >= BAM_DMUX_NUM_CHANNELS) {
Eric Holmberg878923a2012-01-10 14:28:19 -0700517 DMUX_LOG_KERR("%s: dropping invalid LCID %d"
518 " reserved %d cmd %d"
Eric Holmberg9ff40a52011-11-17 19:17:00 -0700519 " pad %d ch %d len %d\n", __func__,
520 rx_hdr->ch_id, rx_hdr->reserved, rx_hdr->cmd,
521 rx_hdr->pad_len, rx_hdr->ch_id, rx_hdr->pkt_len);
522 dev_kfree_skb_any(rx_skb);
523 queue_rx();
524 return;
525 }
526
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700527 switch (rx_hdr->cmd) {
528 case BAM_MUX_HDR_CMD_DATA:
529 DBG_INC_READ_CNT(rx_hdr->pkt_len);
530 bam_mux_process_data(rx_skb);
531 break;
532 case BAM_MUX_HDR_CMD_OPEN:
Eric Holmberg006057d2012-01-11 10:10:42 -0700533 bam_dmux_log("%s: opening cid %d PC enabled\n", __func__,
Eric Holmberg878923a2012-01-10 14:28:19 -0700534 rx_hdr->ch_id);
Eric Holmberg006057d2012-01-11 10:10:42 -0700535 handle_bam_mux_cmd_open(rx_hdr);
536 dev_kfree_skb_any(rx_skb);
537 break;
538 case BAM_MUX_HDR_CMD_OPEN_NO_A2_PC:
539 bam_dmux_log("%s: opening cid %d PC disabled\n", __func__,
540 rx_hdr->ch_id);
541
542 if (!a2_pc_disabled) {
543 a2_pc_disabled = 1;
544 schedule_delayed_work(&ul_timeout_work,
545 msecs_to_jiffies(UL_TIMEOUT_DELAY));
546 }
547
548 handle_bam_mux_cmd_open(rx_hdr);
Eric Holmberge779dba2011-11-04 18:22:01 -0600549 dev_kfree_skb_any(rx_skb);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700550 break;
551 case BAM_MUX_HDR_CMD_CLOSE:
552 /* probably should drop pending write */
Eric Holmberg878923a2012-01-10 14:28:19 -0700553 bam_dmux_log("%s: closing cid %d\n", __func__,
554 rx_hdr->ch_id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700555 spin_lock_irqsave(&bam_ch[rx_hdr->ch_id].lock, flags);
556 bam_ch[rx_hdr->ch_id].status &= ~BAM_CH_REMOTE_OPEN;
557 spin_unlock_irqrestore(&bam_ch[rx_hdr->ch_id].lock, flags);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700558 queue_rx();
Jeff Hugo7960abd2011-08-02 15:39:38 -0600559 platform_device_unregister(bam_ch[rx_hdr->ch_id].pdev);
560 bam_ch[rx_hdr->ch_id].pdev =
561 platform_device_alloc(bam_ch[rx_hdr->ch_id].name, 2);
562 if (!bam_ch[rx_hdr->ch_id].pdev)
563 pr_err("%s: platform_device_alloc failed\n", __func__);
Eric Holmberge779dba2011-11-04 18:22:01 -0600564 dev_kfree_skb_any(rx_skb);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700565 break;
566 default:
Eric Holmberg878923a2012-01-10 14:28:19 -0700567 DMUX_LOG_KERR("%s: dropping invalid hdr. magic %x"
568 " reserved %d cmd %d pad %d ch %d len %d\n",
569 __func__, rx_hdr->magic_num, rx_hdr->reserved,
570 rx_hdr->cmd, rx_hdr->pad_len, rx_hdr->ch_id,
571 rx_hdr->pkt_len);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700572 dev_kfree_skb_any(rx_skb);
573 queue_rx();
574 return;
575 }
576}
577
578static int bam_mux_write_cmd(void *data, uint32_t len)
579{
580 int rc;
581 struct tx_pkt_info *pkt;
582 dma_addr_t dma_address;
Jeff Hugo626303bf2011-11-21 11:43:28 -0700583 unsigned long flags;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700584
Eric Holmbergd83cd2b2011-11-04 15:54:17 -0600585 pkt = kmalloc(sizeof(struct tx_pkt_info), GFP_ATOMIC);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700586 if (pkt == NULL) {
587 pr_err("%s: mem alloc for tx_pkt_info failed\n", __func__);
588 rc = -ENOMEM;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700589 return rc;
590 }
591
592 dma_address = dma_map_single(NULL, data, len,
593 DMA_TO_DEVICE);
594 if (!dma_address) {
595 pr_err("%s: dma_map_single() failed\n", __func__);
Jeff Hugo96cb7482011-12-07 13:28:31 -0700596 kfree(pkt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700597 rc = -ENOMEM;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700598 return rc;
599 }
600 pkt->skb = (struct sk_buff *)(data);
601 pkt->len = len;
602 pkt->dma_address = dma_address;
603 pkt->is_cmd = 1;
Eric Holmberg878923a2012-01-10 14:28:19 -0700604 set_tx_timestamp(pkt);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600605 INIT_WORK(&pkt->work, bam_mux_write_done);
Jeff Hugo626303bf2011-11-21 11:43:28 -0700606 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600607 list_add_tail(&pkt->list_node, &bam_tx_pool);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700608 rc = sps_transfer_one(bam_tx_pipe, dma_address, len,
609 pkt, SPS_IOVEC_FLAG_INT | SPS_IOVEC_FLAG_EOT);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600610 if (rc) {
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700611 DMUX_LOG_KERR("%s sps_transfer_one failed rc=%d\n",
612 __func__, rc);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600613 list_del(&pkt->list_node);
Eric Holmberg2fddbcd2011-11-28 18:25:57 -0700614 DBG_INC_TX_SPS_FAILURE_CNT();
Jeff Hugo626303bf2011-11-21 11:43:28 -0700615 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700616 dma_unmap_single(NULL, pkt->dma_address,
617 pkt->len,
618 DMA_TO_DEVICE);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600619 kfree(pkt);
Jeff Hugobb6da952012-01-16 15:02:42 -0700620 } else {
621 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600622 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700623
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600624 ul_packet_written = 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700625 return rc;
626}
627
628static void bam_mux_write_done(struct work_struct *work)
629{
630 struct sk_buff *skb;
631 struct bam_mux_hdr *hdr;
632 struct tx_pkt_info *info;
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700633 struct tx_pkt_info *info_expected;
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600634 unsigned long event_data;
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700635 unsigned long flags;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700636
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600637 if (in_global_reset)
638 return;
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700639
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700640 info = container_of(work, struct tx_pkt_info, work);
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700641
642 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
643 info_expected = list_first_entry(&bam_tx_pool,
644 struct tx_pkt_info, list_node);
645 if (unlikely(info != info_expected)) {
Eric Holmberg878923a2012-01-10 14:28:19 -0700646 struct tx_pkt_info *errant_pkt;
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700647
Eric Holmberg878923a2012-01-10 14:28:19 -0700648 DMUX_LOG_KERR("%s: bam_tx_pool mismatch .next=%p,"
649 " list_node=%p, ts=%u.%09lu\n",
650 __func__, bam_tx_pool.next, &info->list_node,
651 info->ts_sec, info->ts_nsec
652 );
653
654 list_for_each_entry(errant_pkt, &bam_tx_pool, list_node) {
655 DMUX_LOG_KERR("%s: node=%p ts=%u.%09lu\n", __func__,
656 &errant_pkt->list_node, errant_pkt->ts_sec,
657 errant_pkt->ts_nsec);
658
659 }
Eric Holmberg1cde7a62011-12-19 18:34:01 -0700660 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
661 BUG();
662 }
663 list_del(&info->list_node);
664 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
665
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600666 if (info->is_cmd) {
667 kfree(info->skb);
668 kfree(info);
669 return;
670 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700671 skb = info->skb;
672 kfree(info);
673 hdr = (struct bam_mux_hdr *)skb->data;
674 DBG_INC_WRITE_CNT(skb->data_len);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600675 event_data = (unsigned long)(skb);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700676 spin_lock_irqsave(&bam_ch[hdr->ch_id].lock, flags);
677 bam_ch[hdr->ch_id].num_tx_pkts--;
678 spin_unlock_irqrestore(&bam_ch[hdr->ch_id].lock, flags);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600679 if (bam_ch[hdr->ch_id].notify)
680 bam_ch[hdr->ch_id].notify(
681 bam_ch[hdr->ch_id].priv, BAM_DMUX_WRITE_DONE,
682 event_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700683 else
684 dev_kfree_skb_any(skb);
685}
686
687int msm_bam_dmux_write(uint32_t id, struct sk_buff *skb)
688{
689 int rc = 0;
690 struct bam_mux_hdr *hdr;
691 unsigned long flags;
692 struct sk_buff *new_skb = NULL;
693 dma_addr_t dma_address;
694 struct tx_pkt_info *pkt;
695
696 if (id >= BAM_DMUX_NUM_CHANNELS)
697 return -EINVAL;
698 if (!skb)
699 return -EINVAL;
700 if (!bam_mux_initialized)
701 return -ENODEV;
702
703 DBG("%s: writing to ch %d len %d\n", __func__, id, skb->len);
704 spin_lock_irqsave(&bam_ch[id].lock, flags);
705 if (!bam_ch_is_open(id)) {
706 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
707 pr_err("%s: port not open: %d\n", __func__, bam_ch[id].status);
708 return -ENODEV;
709 }
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700710
711 if (bam_ch[id].use_wm &&
712 (bam_ch[id].num_tx_pkts >= HIGH_WATERMARK)) {
713 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
714 pr_err("%s: watermark exceeded: %d\n", __func__, id);
715 return -EAGAIN;
716 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700717 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
718
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600719 read_lock(&ul_wakeup_lock);
Jeff Hugo061ce672011-10-21 17:15:32 -0600720 if (!bam_is_connected) {
721 read_unlock(&ul_wakeup_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600722 ul_wakeup();
Jeff Hugo4838f412012-01-20 11:19:37 -0700723 if (unlikely(in_global_reset == 1))
724 return -EFAULT;
Jeff Hugo061ce672011-10-21 17:15:32 -0600725 read_lock(&ul_wakeup_lock);
Jeff Hugod98b1082011-10-24 10:30:23 -0600726 notify_all(BAM_DMUX_UL_CONNECTED, (unsigned long)(NULL));
Jeff Hugo061ce672011-10-21 17:15:32 -0600727 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600728
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700729 /* if skb do not have any tailroom for padding,
730 copy the skb into a new expanded skb */
731 if ((skb->len & 0x3) && (skb_tailroom(skb) < (4 - (skb->len & 0x3)))) {
732 /* revisit, probably dev_alloc_skb and memcpy is effecient */
733 new_skb = skb_copy_expand(skb, skb_headroom(skb),
734 4 - (skb->len & 0x3), GFP_ATOMIC);
735 if (new_skb == NULL) {
736 pr_err("%s: cannot allocate skb\n", __func__);
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600737 goto write_fail;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700738 }
739 dev_kfree_skb_any(skb);
740 skb = new_skb;
741 DBG_INC_WRITE_CPY(skb->len);
742 }
743
744 hdr = (struct bam_mux_hdr *)skb_push(skb, sizeof(struct bam_mux_hdr));
745
746 /* caller should allocate for hdr and padding
747 hdr is fine, padding is tricky */
748 hdr->magic_num = BAM_MUX_HDR_MAGIC_NO;
749 hdr->cmd = BAM_MUX_HDR_CMD_DATA;
750 hdr->reserved = 0;
751 hdr->ch_id = id;
752 hdr->pkt_len = skb->len - sizeof(struct bam_mux_hdr);
753 if (skb->len & 0x3)
754 skb_put(skb, 4 - (skb->len & 0x3));
755
756 hdr->pad_len = skb->len - (sizeof(struct bam_mux_hdr) + hdr->pkt_len);
757
758 DBG("%s: data %p, tail %p skb len %d pkt len %d pad len %d\n",
759 __func__, skb->data, skb->tail, skb->len,
760 hdr->pkt_len, hdr->pad_len);
761
762 pkt = kmalloc(sizeof(struct tx_pkt_info), GFP_ATOMIC);
763 if (pkt == NULL) {
764 pr_err("%s: mem alloc for tx_pkt_info failed\n", __func__);
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600765 goto write_fail2;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700766 }
767
768 dma_address = dma_map_single(NULL, skb->data, skb->len,
769 DMA_TO_DEVICE);
770 if (!dma_address) {
771 pr_err("%s: dma_map_single() failed\n", __func__);
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600772 goto write_fail3;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700773 }
774 pkt->skb = skb;
775 pkt->dma_address = dma_address;
776 pkt->is_cmd = 0;
Eric Holmberg878923a2012-01-10 14:28:19 -0700777 set_tx_timestamp(pkt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700778 INIT_WORK(&pkt->work, bam_mux_write_done);
Jeff Hugo626303bf2011-11-21 11:43:28 -0700779 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600780 list_add_tail(&pkt->list_node, &bam_tx_pool);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700781 rc = sps_transfer_one(bam_tx_pipe, dma_address, skb->len,
782 pkt, SPS_IOVEC_FLAG_INT | SPS_IOVEC_FLAG_EOT);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600783 if (rc) {
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700784 DMUX_LOG_KERR("%s sps_transfer_one failed rc=%d\n",
785 __func__, rc);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600786 list_del(&pkt->list_node);
Eric Holmberg2fddbcd2011-11-28 18:25:57 -0700787 DBG_INC_TX_SPS_FAILURE_CNT();
Jeff Hugo626303bf2011-11-21 11:43:28 -0700788 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Eric Holmbergb5b08e52012-01-20 14:19:00 -0700789 dma_unmap_single(NULL, pkt->dma_address,
790 pkt->skb->len, DMA_TO_DEVICE);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600791 kfree(pkt);
Jeff Hugo872bd062011-11-15 17:47:21 -0700792 if (new_skb)
793 dev_kfree_skb_any(new_skb);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700794 } else {
Jeff Hugobb6da952012-01-16 15:02:42 -0700795 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700796 spin_lock_irqsave(&bam_ch[id].lock, flags);
797 bam_ch[id].num_tx_pkts++;
798 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
Jeff Hugo7b80c802011-11-04 16:12:20 -0600799 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600800 ul_packet_written = 1;
801 read_unlock(&ul_wakeup_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700802 return rc;
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600803
804write_fail3:
805 kfree(pkt);
806write_fail2:
807 if (new_skb)
808 dev_kfree_skb_any(new_skb);
809write_fail:
810 read_unlock(&ul_wakeup_lock);
811 return -ENOMEM;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700812}
813
814int msm_bam_dmux_open(uint32_t id, void *priv,
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600815 void (*notify)(void *, int, unsigned long))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700816{
817 struct bam_mux_hdr *hdr;
818 unsigned long flags;
819 int rc = 0;
820
821 DBG("%s: opening ch %d\n", __func__, id);
Eric Holmberg5d775432011-11-09 10:23:35 -0700822 if (!bam_mux_initialized) {
823 DBG("%s: not inititialized\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700824 return -ENODEV;
Eric Holmberg5d775432011-11-09 10:23:35 -0700825 }
826 if (id >= BAM_DMUX_NUM_CHANNELS) {
827 pr_err("%s: invalid channel id %d\n", __func__, id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700828 return -EINVAL;
Eric Holmberg5d775432011-11-09 10:23:35 -0700829 }
830 if (notify == NULL) {
831 pr_err("%s: notify function is NULL\n", __func__);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600832 return -EINVAL;
Eric Holmberg5d775432011-11-09 10:23:35 -0700833 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700834
835 hdr = kmalloc(sizeof(struct bam_mux_hdr), GFP_KERNEL);
836 if (hdr == NULL) {
837 pr_err("%s: hdr kmalloc failed. ch: %d\n", __func__, id);
838 return -ENOMEM;
839 }
840 spin_lock_irqsave(&bam_ch[id].lock, flags);
841 if (bam_ch_is_open(id)) {
842 DBG("%s: Already opened %d\n", __func__, id);
843 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
844 kfree(hdr);
845 goto open_done;
846 }
847 if (!bam_ch_is_remote_open(id)) {
848 DBG("%s: Remote not open; ch: %d\n", __func__, id);
849 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
850 kfree(hdr);
Eric Holmberg5d775432011-11-09 10:23:35 -0700851 return -ENODEV;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700852 }
853
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600854 bam_ch[id].notify = notify;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700855 bam_ch[id].priv = priv;
856 bam_ch[id].status |= BAM_CH_LOCAL_OPEN;
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700857 bam_ch[id].num_tx_pkts = 0;
858 bam_ch[id].use_wm = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700859 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
860
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600861 read_lock(&ul_wakeup_lock);
Jeff Hugo061ce672011-10-21 17:15:32 -0600862 if (!bam_is_connected) {
863 read_unlock(&ul_wakeup_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600864 ul_wakeup();
Jeff Hugo4838f412012-01-20 11:19:37 -0700865 if (unlikely(in_global_reset == 1))
866 return -EFAULT;
Jeff Hugo061ce672011-10-21 17:15:32 -0600867 read_lock(&ul_wakeup_lock);
Jeff Hugod98b1082011-10-24 10:30:23 -0600868 notify_all(BAM_DMUX_UL_CONNECTED, (unsigned long)(NULL));
Jeff Hugo061ce672011-10-21 17:15:32 -0600869 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600870
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700871 hdr->magic_num = BAM_MUX_HDR_MAGIC_NO;
872 hdr->cmd = BAM_MUX_HDR_CMD_OPEN;
873 hdr->reserved = 0;
874 hdr->ch_id = id;
875 hdr->pkt_len = 0;
876 hdr->pad_len = 0;
877
878 rc = bam_mux_write_cmd((void *)hdr, sizeof(struct bam_mux_hdr));
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600879 read_unlock(&ul_wakeup_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700880
881open_done:
882 DBG("%s: opened ch %d\n", __func__, id);
883 return rc;
884}
885
886int msm_bam_dmux_close(uint32_t id)
887{
888 struct bam_mux_hdr *hdr;
889 unsigned long flags;
890 int rc;
891
892 if (id >= BAM_DMUX_NUM_CHANNELS)
893 return -EINVAL;
894 DBG("%s: closing ch %d\n", __func__, id);
895 if (!bam_mux_initialized)
896 return -ENODEV;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700897
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600898 read_lock(&ul_wakeup_lock);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600899 if (!bam_is_connected && !bam_ch_is_in_reset(id)) {
Jeff Hugo061ce672011-10-21 17:15:32 -0600900 read_unlock(&ul_wakeup_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600901 ul_wakeup();
Jeff Hugo4838f412012-01-20 11:19:37 -0700902 if (unlikely(in_global_reset == 1))
903 return -EFAULT;
Jeff Hugo061ce672011-10-21 17:15:32 -0600904 read_lock(&ul_wakeup_lock);
Jeff Hugod98b1082011-10-24 10:30:23 -0600905 notify_all(BAM_DMUX_UL_CONNECTED, (unsigned long)(NULL));
Jeff Hugo061ce672011-10-21 17:15:32 -0600906 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600907
Jeff Hugo061ce672011-10-21 17:15:32 -0600908 spin_lock_irqsave(&bam_ch[id].lock, flags);
Jeff Hugo1c4531c2011-08-02 14:55:37 -0600909 bam_ch[id].notify = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700910 bam_ch[id].priv = NULL;
911 bam_ch[id].status &= ~BAM_CH_LOCAL_OPEN;
912 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
913
Jeff Hugo6e7a92a2011-10-24 05:25:13 -0600914 if (bam_ch_is_in_reset(id)) {
915 read_unlock(&ul_wakeup_lock);
916 bam_ch[id].status &= ~BAM_CH_IN_RESET;
917 return 0;
918 }
919
Jeff Hugobb5802f2011-11-02 17:10:29 -0600920 hdr = kmalloc(sizeof(struct bam_mux_hdr), GFP_ATOMIC);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700921 if (hdr == NULL) {
922 pr_err("%s: hdr kmalloc failed. ch: %d\n", __func__, id);
Jeff Hugoc6af54d2011-11-02 17:00:27 -0600923 read_unlock(&ul_wakeup_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700924 return -ENOMEM;
925 }
926 hdr->magic_num = BAM_MUX_HDR_MAGIC_NO;
927 hdr->cmd = BAM_MUX_HDR_CMD_CLOSE;
928 hdr->reserved = 0;
929 hdr->ch_id = id;
930 hdr->pkt_len = 0;
931 hdr->pad_len = 0;
932
933 rc = bam_mux_write_cmd((void *)hdr, sizeof(struct bam_mux_hdr));
Jeff Hugoaab7ebc2011-09-07 16:46:04 -0600934 read_unlock(&ul_wakeup_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700935
936 DBG("%s: closed ch %d\n", __func__, id);
937 return rc;
938}
939
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -0700940int msm_bam_dmux_is_ch_full(uint32_t id)
941{
942 unsigned long flags;
943 int ret;
944
945 if (id >= BAM_DMUX_NUM_CHANNELS)
946 return -EINVAL;
947
948 spin_lock_irqsave(&bam_ch[id].lock, flags);
949 bam_ch[id].use_wm = 1;
950 ret = bam_ch[id].num_tx_pkts >= HIGH_WATERMARK;
951 DBG("%s: ch %d num tx pkts=%d, HWM=%d\n", __func__,
952 id, bam_ch[id].num_tx_pkts, ret);
953 if (!bam_ch_is_local_open(id)) {
954 ret = -ENODEV;
955 pr_err("%s: port not open: %d\n", __func__, bam_ch[id].status);
956 }
957 spin_unlock_irqrestore(&bam_ch[id].lock, flags);
958
959 return ret;
960}
961
962int msm_bam_dmux_is_ch_low(uint32_t id)
963{
964 int ret;
965
966 if (id >= BAM_DMUX_NUM_CHANNELS)
967 return -EINVAL;
968
969 bam_ch[id].use_wm = 1;
970 ret = bam_ch[id].num_tx_pkts <= LOW_WATERMARK;
971 DBG("%s: ch %d num tx pkts=%d, LWM=%d\n", __func__,
972 id, bam_ch[id].num_tx_pkts, ret);
973 if (!bam_ch_is_local_open(id)) {
974 ret = -ENODEV;
975 pr_err("%s: port not open: %d\n", __func__, bam_ch[id].status);
976 }
977
978 return ret;
979}
980
Eric Holmberg8df0cdb2012-01-04 17:40:46 -0700981static void rx_switch_to_interrupt_mode(void)
982{
983 struct sps_connect cur_rx_conn;
984 struct sps_iovec iov;
985 struct rx_pkt_info *info;
986 int ret;
987
988 /*
989 * Attempt to enable interrupts - if this fails,
990 * continue polling and we will retry later.
991 */
992 ret = sps_get_config(bam_rx_pipe, &cur_rx_conn);
993 if (ret) {
994 pr_err("%s: sps_get_config() failed %d\n", __func__, ret);
995 goto fail;
996 }
997
998 rx_register_event.options = SPS_O_EOT;
999 ret = sps_register_event(bam_rx_pipe, &rx_register_event);
1000 if (ret) {
1001 pr_err("%s: sps_register_event() failed %d\n", __func__, ret);
1002 goto fail;
1003 }
1004
1005 cur_rx_conn.options = SPS_O_AUTO_ENABLE |
1006 SPS_O_EOT | SPS_O_ACK_TRANSFERS;
1007 ret = sps_set_config(bam_rx_pipe, &cur_rx_conn);
1008 if (ret) {
1009 pr_err("%s: sps_set_config() failed %d\n", __func__, ret);
1010 goto fail;
1011 }
1012 polling_mode = 0;
Eric Holmberg006057d2012-01-11 10:10:42 -07001013 release_wakelock();
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001014
1015 /* handle any rx packets before interrupt was enabled */
1016 while (bam_connection_is_active && !polling_mode) {
1017 ret = sps_get_iovec(bam_rx_pipe, &iov);
1018 if (ret) {
1019 pr_err("%s: sps_get_iovec failed %d\n",
1020 __func__, ret);
1021 break;
1022 }
1023 if (iov.addr == 0)
1024 break;
1025
1026 mutex_lock(&bam_rx_pool_mutexlock);
1027 if (unlikely(list_empty(&bam_rx_pool))) {
1028 mutex_unlock(&bam_rx_pool_mutexlock);
1029 continue;
1030 }
1031 info = list_first_entry(&bam_rx_pool, struct rx_pkt_info,
1032 list_node);
1033 list_del(&info->list_node);
Eric Holmbergb5b08e52012-01-20 14:19:00 -07001034 --bam_rx_pool_len;
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001035 mutex_unlock(&bam_rx_pool_mutexlock);
Eric Holmbergb5b08e52012-01-20 14:19:00 -07001036 if (info->dma_address != iov.addr)
1037 DMUX_LOG_KERR("%s: iovec %p != dma %p\n",
1038 __func__,
1039 (void *)info->dma_address, (void *)iov.addr);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001040 handle_bam_mux_cmd(&info->work);
1041 }
1042 return;
1043
1044fail:
1045 pr_err("%s: reverting to polling\n", __func__);
1046 queue_work(bam_mux_rx_workqueue, &rx_timer_work);
1047}
1048
Jeff Hugo949080a2011-08-30 11:58:56 -06001049static void rx_timer_work_func(struct work_struct *work)
1050{
1051 struct sps_iovec iov;
Jeff Hugo949080a2011-08-30 11:58:56 -06001052 struct rx_pkt_info *info;
1053 int inactive_cycles = 0;
1054 int ret;
Jeff Hugo949080a2011-08-30 11:58:56 -06001055
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001056 while (bam_connection_is_active) { /* timer loop */
Jeff Hugo949080a2011-08-30 11:58:56 -06001057 ++inactive_cycles;
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001058 while (bam_connection_is_active) { /* deplete queue loop */
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001059 if (in_global_reset)
1060 return;
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001061
1062 ret = sps_get_iovec(bam_rx_pipe, &iov);
1063 if (ret) {
1064 pr_err("%s: sps_get_iovec failed %d\n",
1065 __func__, ret);
1066 break;
1067 }
Jeff Hugo949080a2011-08-30 11:58:56 -06001068 if (iov.addr == 0)
1069 break;
1070 inactive_cycles = 0;
Jeff Hugoc9749932011-11-02 17:50:40 -06001071 mutex_lock(&bam_rx_pool_mutexlock);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001072 if (unlikely(list_empty(&bam_rx_pool))) {
1073 mutex_unlock(&bam_rx_pool_mutexlock);
1074 continue;
1075 }
1076 info = list_first_entry(&bam_rx_pool,
1077 struct rx_pkt_info, list_node);
Eric Holmbergb5b08e52012-01-20 14:19:00 -07001078 --bam_rx_pool_len;
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001079 list_del(&info->list_node);
Jeff Hugoc9749932011-11-02 17:50:40 -06001080 mutex_unlock(&bam_rx_pool_mutexlock);
Jeff Hugo949080a2011-08-30 11:58:56 -06001081 handle_bam_mux_cmd(&info->work);
1082 }
1083
1084 if (inactive_cycles == POLLING_INACTIVITY) {
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001085 rx_switch_to_interrupt_mode();
1086 break;
Jeff Hugo949080a2011-08-30 11:58:56 -06001087 }
1088
1089 usleep_range(POLLING_MIN_SLEEP, POLLING_MAX_SLEEP);
1090 }
1091}
1092
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001093static void bam_mux_tx_notify(struct sps_event_notify *notify)
1094{
1095 struct tx_pkt_info *pkt;
1096
1097 DBG("%s: event %d notified\n", __func__, notify->event_id);
1098
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001099 if (in_global_reset)
1100 return;
1101
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001102 switch (notify->event_id) {
1103 case SPS_EVENT_EOT:
1104 pkt = notify->data.transfer.user;
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001105 if (!pkt->is_cmd)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001106 dma_unmap_single(NULL, pkt->dma_address,
1107 pkt->skb->len,
1108 DMA_TO_DEVICE);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001109 else
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001110 dma_unmap_single(NULL, pkt->dma_address,
1111 pkt->len,
1112 DMA_TO_DEVICE);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001113 queue_work(bam_mux_tx_workqueue, &pkt->work);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001114 break;
1115 default:
1116 pr_err("%s: recieved unexpected event id %d\n", __func__,
1117 notify->event_id);
1118 }
1119}
1120
Jeff Hugo33dbc002011-08-25 15:52:53 -06001121static void bam_mux_rx_notify(struct sps_event_notify *notify)
1122{
Jeff Hugo949080a2011-08-30 11:58:56 -06001123 int ret;
1124 struct sps_connect cur_rx_conn;
Jeff Hugo33dbc002011-08-25 15:52:53 -06001125
1126 DBG("%s: event %d notified\n", __func__, notify->event_id);
1127
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001128 if (in_global_reset)
1129 return;
1130
Jeff Hugo33dbc002011-08-25 15:52:53 -06001131 switch (notify->event_id) {
1132 case SPS_EVENT_EOT:
Jeff Hugo949080a2011-08-30 11:58:56 -06001133 /* attempt to disable interrupts in this pipe */
1134 if (!polling_mode) {
1135 ret = sps_get_config(bam_rx_pipe, &cur_rx_conn);
1136 if (ret) {
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001137 pr_err("%s: sps_get_config() failed %d, interrupts"
1138 " not disabled\n", __func__, ret);
Jeff Hugo949080a2011-08-30 11:58:56 -06001139 break;
1140 }
Jeff Hugoa9d32ba2011-11-21 14:59:48 -07001141 cur_rx_conn.options = SPS_O_AUTO_ENABLE |
Jeff Hugo949080a2011-08-30 11:58:56 -06001142 SPS_O_ACK_TRANSFERS | SPS_O_POLL;
1143 ret = sps_set_config(bam_rx_pipe, &cur_rx_conn);
1144 if (ret) {
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001145 pr_err("%s: sps_set_config() failed %d, interrupts"
1146 " not disabled\n", __func__, ret);
Jeff Hugo949080a2011-08-30 11:58:56 -06001147 break;
1148 }
Eric Holmberg006057d2012-01-11 10:10:42 -07001149 grab_wakelock();
Jeff Hugo949080a2011-08-30 11:58:56 -06001150 polling_mode = 1;
1151 queue_work(bam_mux_rx_workqueue, &rx_timer_work);
1152 }
Jeff Hugo33dbc002011-08-25 15:52:53 -06001153 break;
1154 default:
1155 pr_err("%s: recieved unexpected event id %d\n", __func__,
1156 notify->event_id);
1157 }
1158}
1159
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001160#ifdef CONFIG_DEBUG_FS
1161
1162static int debug_tbl(char *buf, int max)
1163{
1164 int i = 0;
1165 int j;
1166
1167 for (j = 0; j < BAM_DMUX_NUM_CHANNELS; ++j) {
1168 i += scnprintf(buf + i, max - i,
1169 "ch%02d local open=%s remote open=%s\n",
1170 j, bam_ch_is_local_open(j) ? "Y" : "N",
1171 bam_ch_is_remote_open(j) ? "Y" : "N");
1172 }
1173
1174 return i;
1175}
1176
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07001177static int debug_ul_pkt_cnt(char *buf, int max)
1178{
1179 struct list_head *p;
1180 unsigned long flags;
1181 int n = 0;
1182
1183 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
1184 __list_for_each(p, &bam_tx_pool) {
1185 ++n;
1186 }
1187 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
1188
1189 return scnprintf(buf, max, "Number of UL packets in flight: %d\n", n);
1190}
1191
1192static int debug_stats(char *buf, int max)
1193{
1194 int i = 0;
1195
1196 i += scnprintf(buf + i, max - i,
1197 "skb copy cnt: %u\n"
1198 "skb copy bytes: %u\n"
Eric Holmberg6074aba2012-01-18 17:59:44 -07001199 "sps tx failures: %u\n"
Eric Holmbergb5b08e52012-01-20 14:19:00 -07001200 "sps tx stalls: %u\n"
1201 "rx queue len: %d\n",
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07001202 bam_dmux_write_cpy_cnt,
1203 bam_dmux_write_cpy_bytes,
Eric Holmberg6074aba2012-01-18 17:59:44 -07001204 bam_dmux_tx_sps_failure_cnt,
Eric Holmbergb5b08e52012-01-20 14:19:00 -07001205 bam_dmux_tx_stall_cnt,
1206 bam_rx_pool_len
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07001207 );
1208
1209 return i;
1210}
1211
Eric Holmberg878923a2012-01-10 14:28:19 -07001212static int debug_log(char *buff, int max, loff_t *ppos)
1213{
1214 unsigned long flags;
1215 int i = 0;
1216
1217 if (bam_dmux_state_logging_disabled) {
1218 i += scnprintf(buff - i, max - i, "Logging disabled\n");
1219 return i;
1220 }
1221
1222 if (*ppos == 0) {
1223 i += scnprintf(buff - i, max - i,
1224 "<DMUX> timestamp FLAGS [Message]\n"
1225 "FLAGS:\n"
Eric Holmberg006057d2012-01-11 10:10:42 -07001226 "\tD: 1 = Power collapse disabled\n"
Eric Holmberg878923a2012-01-10 14:28:19 -07001227 "\tR: 1 = in global reset\n"
1228 "\tP: 1 = BAM is powered up\n"
1229 "\tA: 1 = BAM initialized and ready for data\n"
1230 "\n"
1231 "\tV: 1 = Uplink vote for power\n"
1232 "\tU: 1 = Uplink active\n"
1233 "\tW: 1 = Uplink Wait-for-ack\n"
1234 "\tA: 1 = Uplink ACK received\n"
Eric Holmbergbc9f21c2012-01-18 11:33:33 -07001235 "\t#: >=1 On-demand uplink vote\n"
Eric Holmberg878923a2012-01-10 14:28:19 -07001236 );
1237 buff += i;
1238 }
1239
1240 spin_lock_irqsave(&bam_dmux_logging_spinlock, flags);
1241 while (kfifo_len(&bam_dmux_state_log)
1242 && (i + LOG_MESSAGE_MAX_SIZE) < max) {
1243 int k_len;
1244 k_len = kfifo_out(&bam_dmux_state_log,
1245 buff, LOG_MESSAGE_MAX_SIZE);
1246 if (k_len != LOG_MESSAGE_MAX_SIZE) {
1247 pr_err("%s: retrieve failure %d\n", __func__, k_len);
1248 break;
1249 }
1250
1251 /* keep non-null portion of string and add line break */
1252 k_len = strnlen(buff, LOG_MESSAGE_MAX_SIZE);
1253 buff += k_len;
1254 i += k_len;
1255 if (k_len && *(buff - 1) != '\n') {
1256 *buff++ = '\n';
1257 ++i;
1258 }
1259 }
1260 spin_unlock_irqrestore(&bam_dmux_logging_spinlock, flags);
1261
1262 return i;
1263}
1264
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001265#define DEBUG_BUFMAX 4096
1266static char debug_buffer[DEBUG_BUFMAX];
1267
1268static ssize_t debug_read(struct file *file, char __user *buf,
1269 size_t count, loff_t *ppos)
1270{
1271 int (*fill)(char *buf, int max) = file->private_data;
1272 int bsize = fill(debug_buffer, DEBUG_BUFMAX);
1273 return simple_read_from_buffer(buf, count, ppos, debug_buffer, bsize);
1274}
1275
Eric Holmberg878923a2012-01-10 14:28:19 -07001276static ssize_t debug_read_multiple(struct file *file, char __user *buff,
1277 size_t count, loff_t *ppos)
1278{
1279 int (*util_func)(char *buf, int max, loff_t *) = file->private_data;
1280 char *buffer;
1281 int bsize;
1282
1283 buffer = kmalloc(count, GFP_KERNEL);
1284 if (!buffer)
1285 return -ENOMEM;
1286
1287 bsize = util_func(buffer, count, ppos);
1288
1289 if (bsize >= 0) {
1290 if (copy_to_user(buff, buffer, bsize)) {
1291 kfree(buffer);
1292 return -EFAULT;
1293 }
1294 *ppos += bsize;
1295 }
1296 kfree(buffer);
1297 return bsize;
1298}
1299
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001300static int debug_open(struct inode *inode, struct file *file)
1301{
1302 file->private_data = inode->i_private;
1303 return 0;
1304}
1305
1306
1307static const struct file_operations debug_ops = {
1308 .read = debug_read,
1309 .open = debug_open,
1310};
1311
Eric Holmberg878923a2012-01-10 14:28:19 -07001312static const struct file_operations debug_ops_multiple = {
1313 .read = debug_read_multiple,
1314 .open = debug_open,
1315};
1316
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001317static void debug_create(const char *name, mode_t mode,
1318 struct dentry *dent,
1319 int (*fill)(char *buf, int max))
1320{
Eric Holmberge4ac80b2012-01-12 09:21:59 -07001321 struct dentry *file;
1322
1323 file = debugfs_create_file(name, mode, dent, fill, &debug_ops);
1324 if (IS_ERR(file))
1325 pr_err("%s: debugfs create failed %d\n", __func__,
1326 (int)PTR_ERR(file));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001327}
1328
Eric Holmberge4ac80b2012-01-12 09:21:59 -07001329static void debug_create_multiple(const char *name, mode_t mode,
1330 struct dentry *dent,
1331 int (*fill)(char *buf, int max, loff_t *ppos))
1332{
1333 struct dentry *file;
1334
1335 file = debugfs_create_file(name, mode, dent, fill, &debug_ops_multiple);
1336 if (IS_ERR(file))
1337 pr_err("%s: debugfs create failed %d\n", __func__,
1338 (int)PTR_ERR(file));
1339}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001340#endif
1341
Jeff Hugod98b1082011-10-24 10:30:23 -06001342static void notify_all(int event, unsigned long data)
1343{
1344 int i;
1345
1346 for (i = 0; i < BAM_DMUX_NUM_CHANNELS; ++i) {
Eric Holmberg454d9da2012-01-12 09:37:14 -07001347 if (bam_ch_is_open(i)) {
Jeff Hugod98b1082011-10-24 10:30:23 -06001348 bam_ch[i].notify(bam_ch[i].priv, event, data);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001349 bam_dmux_log("%s: cid=%d, event=%d, data=%lu\n",
1350 __func__, i, event, data);
1351 }
Jeff Hugod98b1082011-10-24 10:30:23 -06001352 }
1353}
1354
1355static void kickoff_ul_wakeup_func(struct work_struct *work)
1356{
1357 read_lock(&ul_wakeup_lock);
1358 if (!bam_is_connected) {
1359 read_unlock(&ul_wakeup_lock);
1360 ul_wakeup();
Jeff Hugo4838f412012-01-20 11:19:37 -07001361 if (unlikely(in_global_reset == 1))
1362 return;
Jeff Hugod98b1082011-10-24 10:30:23 -06001363 read_lock(&ul_wakeup_lock);
1364 ul_packet_written = 1;
1365 notify_all(BAM_DMUX_UL_CONNECTED, (unsigned long)(NULL));
1366 }
1367 read_unlock(&ul_wakeup_lock);
1368}
1369
Eric Holmbergbc9f21c2012-01-18 11:33:33 -07001370int msm_bam_dmux_kickoff_ul_wakeup(void)
Jeff Hugod98b1082011-10-24 10:30:23 -06001371{
Eric Holmbergbc9f21c2012-01-18 11:33:33 -07001372 int is_connected;
1373
1374 read_lock(&ul_wakeup_lock);
1375 ul_packet_written = 1;
1376 is_connected = bam_is_connected;
1377 if (!is_connected)
1378 queue_work(bam_mux_tx_workqueue, &kickoff_ul_wakeup);
1379 read_unlock(&ul_wakeup_lock);
1380
1381 return is_connected;
Jeff Hugod98b1082011-10-24 10:30:23 -06001382}
1383
Eric Holmberg878923a2012-01-10 14:28:19 -07001384static void power_vote(int vote)
1385{
1386 bam_dmux_log("%s: curr=%d, vote=%d\n", __func__,
1387 bam_dmux_uplink_vote, vote);
1388
1389 if (bam_dmux_uplink_vote == vote)
1390 bam_dmux_log("%s: warning - duplicate power vote\n", __func__);
1391
1392 bam_dmux_uplink_vote = vote;
1393 if (vote)
1394 smsm_change_state(SMSM_APPS_STATE, 0, SMSM_A2_POWER_CONTROL);
1395 else
1396 smsm_change_state(SMSM_APPS_STATE, SMSM_A2_POWER_CONTROL, 0);
1397}
1398
Eric Holmberg454d9da2012-01-12 09:37:14 -07001399/*
1400 * @note: Must be called with ul_wakeup_lock locked.
1401 */
1402static inline void ul_powerdown(void)
1403{
1404 bam_dmux_log("%s: powerdown\n", __func__);
1405 verify_tx_queue_is_empty(__func__);
1406
1407 if (a2_pc_disabled) {
1408 wait_for_dfab = 1;
1409 INIT_COMPLETION(dfab_unvote_completion);
1410 release_wakelock();
1411 } else {
1412 wait_for_ack = 1;
1413 INIT_COMPLETION(ul_wakeup_ack_completion);
1414 power_vote(0);
1415 }
1416 bam_is_connected = 0;
1417 notify_all(BAM_DMUX_UL_DISCONNECTED, (unsigned long)(NULL));
1418}
1419
1420static inline void ul_powerdown_finish(void)
1421{
1422 if (a2_pc_disabled && wait_for_dfab) {
1423 unvote_dfab();
1424 complete_all(&dfab_unvote_completion);
1425 wait_for_dfab = 0;
1426 }
1427}
1428
Eric Holmbergbc9f21c2012-01-18 11:33:33 -07001429/*
1430 * Votes for UL power and returns current power state.
1431 *
1432 * @returns true if currently connected
1433 */
1434int msm_bam_dmux_ul_power_vote(void)
1435{
1436 int is_connected;
1437
1438 read_lock(&ul_wakeup_lock);
1439 atomic_inc(&ul_ondemand_vote);
1440 is_connected = bam_is_connected;
1441 if (!is_connected)
1442 queue_work(bam_mux_tx_workqueue, &kickoff_ul_wakeup);
1443 read_unlock(&ul_wakeup_lock);
1444
1445 return is_connected;
1446}
1447
1448/*
1449 * Unvotes for UL power.
1450 *
1451 * @returns true if vote count is 0 (UL shutdown possible)
1452 */
1453int msm_bam_dmux_ul_power_unvote(void)
1454{
1455 int vote;
1456
1457 read_lock(&ul_wakeup_lock);
1458 vote = atomic_dec_return(&ul_ondemand_vote);
1459 if (unlikely(vote) < 0)
1460 DMUX_LOG_KERR("%s: invalid power vote %d\n", __func__, vote);
1461 read_unlock(&ul_wakeup_lock);
1462
1463 return vote == 0;
1464}
1465
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001466static void ul_timeout(struct work_struct *work)
1467{
Jeff Hugoc040a5b2011-11-15 14:26:01 -07001468 unsigned long flags;
1469 int ret;
1470
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001471 if (in_global_reset)
1472 return;
Jeff Hugoc040a5b2011-11-15 14:26:01 -07001473 ret = write_trylock_irqsave(&ul_wakeup_lock, flags);
1474 if (!ret) { /* failed to grab lock, reschedule and bail */
1475 schedule_delayed_work(&ul_timeout_work,
1476 msecs_to_jiffies(UL_TIMEOUT_DELAY));
1477 return;
1478 }
Eric Holmberg454d9da2012-01-12 09:37:14 -07001479 if (bam_is_connected) {
Eric Holmberg6074aba2012-01-18 17:59:44 -07001480 if (!ul_packet_written) {
1481 spin_lock(&bam_tx_pool_spinlock);
1482 if (!list_empty(&bam_tx_pool)) {
1483 struct tx_pkt_info *info;
1484
1485 info = list_first_entry(&bam_tx_pool,
1486 struct tx_pkt_info, list_node);
1487 DMUX_LOG_KERR("%s: UL delayed ts=%u.%09lu\n",
1488 __func__, info->ts_sec, info->ts_nsec);
1489 DBG_INC_TX_STALL_CNT();
1490 ul_packet_written = 1;
1491 }
1492 spin_unlock(&bam_tx_pool_spinlock);
1493 }
1494
Eric Holmbergbc9f21c2012-01-18 11:33:33 -07001495 if (ul_packet_written || atomic_read(&ul_ondemand_vote)) {
1496 bam_dmux_log("%s: pkt written %d\n",
1497 __func__, ul_packet_written);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001498 ul_packet_written = 0;
1499 schedule_delayed_work(&ul_timeout_work,
1500 msecs_to_jiffies(UL_TIMEOUT_DELAY));
Eric Holmberg006057d2012-01-11 10:10:42 -07001501 } else {
Eric Holmberg454d9da2012-01-12 09:37:14 -07001502 ul_powerdown();
Eric Holmberg006057d2012-01-11 10:10:42 -07001503 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001504 }
Jeff Hugoc040a5b2011-11-15 14:26:01 -07001505 write_unlock_irqrestore(&ul_wakeup_lock, flags);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001506 ul_powerdown_finish();
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001507}
Jeff Hugo4838f412012-01-20 11:19:37 -07001508
1509static int ssrestart_check(void)
1510{
1511 /*
1512 * if the restart level is RESET_SOC, SSR is not on
1513 * so the crashed modem will end up crashing the system
1514 * anyways, so use BUG() to report the error
1515 * else prepare for the restart event which should
1516 * happen soon
1517 */
1518 DMUX_LOG_KERR("%s: modem timeout\n", __func__);
1519 if (get_restart_level() <= RESET_SOC) {
1520 BUG();
1521 return 0;
1522 } else {
1523 in_global_reset = 1;
1524 return 1;
1525 }
1526}
1527
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001528static void ul_wakeup(void)
1529{
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001530 int ret;
1531
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001532 mutex_lock(&wakeup_lock);
1533 if (bam_is_connected) { /* bam got connected before lock grabbed */
Eric Holmberg878923a2012-01-10 14:28:19 -07001534 bam_dmux_log("%s Already awake\n", __func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001535 mutex_unlock(&wakeup_lock);
1536 return;
1537 }
Eric Holmberg878923a2012-01-10 14:28:19 -07001538
Eric Holmberg006057d2012-01-11 10:10:42 -07001539 if (a2_pc_disabled) {
1540 /*
1541 * don't grab the wakelock the first time because it is
1542 * already grabbed when a2 powers on
1543 */
Jeff Hugo583a6da2012-02-03 11:37:30 -07001544 if (likely(a2_pc_disabled_wakelock_skipped))
Eric Holmberg006057d2012-01-11 10:10:42 -07001545 grab_wakelock();
1546 else
Jeff Hugo583a6da2012-02-03 11:37:30 -07001547 a2_pc_disabled_wakelock_skipped = 1;
Eric Holmberg006057d2012-01-11 10:10:42 -07001548 if (wait_for_dfab) {
Jeff Hugo66f7f1e2012-01-16 14:30:42 -07001549 ret = wait_for_completion_timeout(
Eric Holmberg006057d2012-01-11 10:10:42 -07001550 &dfab_unvote_completion, HZ);
1551 BUG_ON(ret == 0);
1552 }
1553 vote_dfab();
1554 schedule_delayed_work(&ul_timeout_work,
1555 msecs_to_jiffies(UL_TIMEOUT_DELAY));
1556 bam_is_connected = 1;
1557 mutex_unlock(&wakeup_lock);
1558 return;
1559 }
1560
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001561 /*
1562 * must wait for the previous power down request to have been acked
1563 * chances are it already came in and this will just fall through
1564 * instead of waiting
1565 */
1566 if (wait_for_ack) {
Eric Holmberg878923a2012-01-10 14:28:19 -07001567 bam_dmux_log("%s waiting for previous ack\n", __func__);
Jeff Hugo66f7f1e2012-01-16 14:30:42 -07001568 ret = wait_for_completion_timeout(
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001569 &ul_wakeup_ack_completion, HZ);
Eric Holmberg006057d2012-01-11 10:10:42 -07001570 wait_for_ack = 0;
Jeff Hugo4838f412012-01-20 11:19:37 -07001571 if (unlikely(ret == 0) && ssrestart_check()) {
1572 mutex_unlock(&wakeup_lock);
1573 bam_dmux_log("%s timeout previous ack\n", __func__);
1574 return;
1575 }
Jeff Hugof6c1c1e2011-12-01 17:43:49 -07001576 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001577 INIT_COMPLETION(ul_wakeup_ack_completion);
Eric Holmberg878923a2012-01-10 14:28:19 -07001578 power_vote(1);
1579 bam_dmux_log("%s waiting for wakeup ack\n", __func__);
Jeff Hugo66f7f1e2012-01-16 14:30:42 -07001580 ret = wait_for_completion_timeout(&ul_wakeup_ack_completion, HZ);
Jeff Hugo4838f412012-01-20 11:19:37 -07001581 if (unlikely(ret == 0) && ssrestart_check()) {
1582 mutex_unlock(&wakeup_lock);
1583 bam_dmux_log("%s timeout wakeup ack\n", __func__);
1584 return;
1585 }
Eric Holmberg878923a2012-01-10 14:28:19 -07001586 bam_dmux_log("%s waiting completion\n", __func__);
Jeff Hugo66f7f1e2012-01-16 14:30:42 -07001587 ret = wait_for_completion_timeout(&bam_connection_completion, HZ);
Jeff Hugo4838f412012-01-20 11:19:37 -07001588 if (unlikely(ret == 0) && ssrestart_check()) {
1589 mutex_unlock(&wakeup_lock);
1590 bam_dmux_log("%s timeout power on\n", __func__);
1591 return;
1592 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001593
1594 bam_is_connected = 1;
Eric Holmberg878923a2012-01-10 14:28:19 -07001595 bam_dmux_log("%s complete\n", __func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001596 schedule_delayed_work(&ul_timeout_work,
1597 msecs_to_jiffies(UL_TIMEOUT_DELAY));
1598 mutex_unlock(&wakeup_lock);
1599}
1600
1601static void reconnect_to_bam(void)
1602{
1603 int i;
1604
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001605 in_global_reset = 0;
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001606 vote_dfab();
1607 i = sps_device_reset(a2_device_handle);
1608 if (i)
1609 pr_err("%s: device reset failed rc = %d\n", __func__, i);
1610 i = sps_connect(bam_tx_pipe, &tx_connection);
1611 if (i)
1612 pr_err("%s: tx connection failed rc = %d\n", __func__, i);
1613 i = sps_connect(bam_rx_pipe, &rx_connection);
1614 if (i)
1615 pr_err("%s: rx connection failed rc = %d\n", __func__, i);
1616 i = sps_register_event(bam_tx_pipe, &tx_register_event);
1617 if (i)
1618 pr_err("%s: tx event reg failed rc = %d\n", __func__, i);
1619 i = sps_register_event(bam_rx_pipe, &rx_register_event);
1620 if (i)
1621 pr_err("%s: rx event reg failed rc = %d\n", __func__, i);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001622
1623 bam_connection_is_active = 1;
1624
1625 if (polling_mode)
1626 rx_switch_to_interrupt_mode();
1627
Eric Holmbergb5b08e52012-01-20 14:19:00 -07001628 queue_rx();
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001629
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001630 toggle_apps_ack();
1631 complete_all(&bam_connection_completion);
1632}
1633
1634static void disconnect_to_bam(void)
1635{
1636 struct list_head *node;
1637 struct rx_pkt_info *info;
Eric Holmberg454d9da2012-01-12 09:37:14 -07001638 unsigned long flags;
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001639
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001640 bam_connection_is_active = 0;
Eric Holmberg454d9da2012-01-12 09:37:14 -07001641
1642 /* handle disconnect during active UL */
1643 write_lock_irqsave(&ul_wakeup_lock, flags);
1644 if (bam_is_connected) {
1645 bam_dmux_log("%s: UL active - forcing powerdown\n", __func__);
1646 ul_powerdown();
1647 }
1648 write_unlock_irqrestore(&ul_wakeup_lock, flags);
1649 ul_powerdown_finish();
1650
1651 /* tear down BAM connection */
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001652 INIT_COMPLETION(bam_connection_completion);
1653 sps_disconnect(bam_tx_pipe);
1654 sps_disconnect(bam_rx_pipe);
1655 unvote_dfab();
1656 __memzero(rx_desc_mem_buf.base, rx_desc_mem_buf.size);
1657 __memzero(tx_desc_mem_buf.base, tx_desc_mem_buf.size);
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001658
1659 mutex_lock(&bam_rx_pool_mutexlock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001660 while (!list_empty(&bam_rx_pool)) {
1661 node = bam_rx_pool.next;
1662 list_del(node);
1663 info = container_of(node, struct rx_pkt_info, list_node);
1664 dma_unmap_single(NULL, info->dma_address, BUFFER_SIZE,
1665 DMA_FROM_DEVICE);
1666 dev_kfree_skb_any(info->skb);
1667 kfree(info);
1668 }
Eric Holmbergb5b08e52012-01-20 14:19:00 -07001669 bam_rx_pool_len = 0;
Eric Holmberg8df0cdb2012-01-04 17:40:46 -07001670 mutex_unlock(&bam_rx_pool_mutexlock);
Eric Holmberg878923a2012-01-10 14:28:19 -07001671
1672 verify_tx_queue_is_empty(__func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001673}
1674
1675static void vote_dfab(void)
1676{
Jeff Hugoca0caa82011-12-05 16:05:23 -07001677 int rc;
1678
Eric Holmberg006057d2012-01-11 10:10:42 -07001679 bam_dmux_log("%s\n", __func__);
1680 mutex_lock(&dfab_status_lock);
1681 if (dfab_is_on) {
1682 bam_dmux_log("%s: dfab is already on\n", __func__);
1683 mutex_unlock(&dfab_status_lock);
1684 return;
1685 }
Jeff Hugo23a812b2012-01-13 13:43:42 -07001686 rc = clk_prepare_enable(dfab_clk);
Jeff Hugoca0caa82011-12-05 16:05:23 -07001687 if (rc)
Eric Holmberg006057d2012-01-11 10:10:42 -07001688 DMUX_LOG_KERR("bam_dmux vote for dfab failed rc = %d\n", rc);
1689 dfab_is_on = 1;
1690 mutex_unlock(&dfab_status_lock);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001691}
1692
1693static void unvote_dfab(void)
1694{
Eric Holmberg006057d2012-01-11 10:10:42 -07001695 bam_dmux_log("%s\n", __func__);
1696 mutex_lock(&dfab_status_lock);
1697 if (!dfab_is_on) {
1698 DMUX_LOG_KERR("%s: dfab is already off\n", __func__);
1699 dump_stack();
1700 mutex_unlock(&dfab_status_lock);
1701 return;
1702 }
Jeff Hugo23a812b2012-01-13 13:43:42 -07001703 clk_disable_unprepare(dfab_clk);
Eric Holmberg006057d2012-01-11 10:10:42 -07001704 dfab_is_on = 0;
1705 mutex_unlock(&dfab_status_lock);
1706}
1707
1708/* reference counting wrapper around wakelock */
1709static void grab_wakelock(void)
1710{
1711 unsigned long flags;
1712
1713 spin_lock_irqsave(&wakelock_reference_lock, flags);
1714 bam_dmux_log("%s: ref count = %d\n", __func__,
1715 wakelock_reference_count);
1716 if (wakelock_reference_count == 0)
1717 wake_lock(&bam_wakelock);
1718 ++wakelock_reference_count;
1719 spin_unlock_irqrestore(&wakelock_reference_lock, flags);
1720}
1721
1722static void release_wakelock(void)
1723{
1724 unsigned long flags;
1725
1726 spin_lock_irqsave(&wakelock_reference_lock, flags);
1727 if (wakelock_reference_count == 0) {
1728 DMUX_LOG_KERR("%s: bam_dmux wakelock not locked\n", __func__);
1729 dump_stack();
1730 spin_unlock_irqrestore(&wakelock_reference_lock, flags);
1731 return;
1732 }
1733 bam_dmux_log("%s: ref count = %d\n", __func__,
1734 wakelock_reference_count);
1735 --wakelock_reference_count;
1736 if (wakelock_reference_count == 0)
1737 wake_unlock(&bam_wakelock);
1738 spin_unlock_irqrestore(&wakelock_reference_lock, flags);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001739}
1740
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001741static int restart_notifier_cb(struct notifier_block *this,
1742 unsigned long code,
1743 void *data)
1744{
1745 int i;
1746 struct list_head *node;
1747 struct tx_pkt_info *info;
1748 int temp_remote_status;
Jeff Hugo626303bf2011-11-21 11:43:28 -07001749 unsigned long flags;
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001750
1751 if (code != SUBSYS_AFTER_SHUTDOWN)
1752 return NOTIFY_DONE;
1753
Eric Holmberg878923a2012-01-10 14:28:19 -07001754 bam_dmux_log("%s: begin\n", __func__);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001755 in_global_reset = 1;
Eric Holmberg454d9da2012-01-12 09:37:14 -07001756
1757 /* Handle uplink Powerdown */
1758 write_lock_irqsave(&ul_wakeup_lock, flags);
1759 if (bam_is_connected) {
1760 ul_powerdown();
1761 wait_for_ack = 0;
1762 }
Jeff Hugo4838f412012-01-20 11:19:37 -07001763 /*
1764 * if modem crash during ul_wakeup(), power_vote is 1, needs to be
1765 * reset to 0. harmless if bam_is_connected check above passes
1766 */
1767 power_vote(0);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001768 write_unlock_irqrestore(&ul_wakeup_lock, flags);
1769 ul_powerdown_finish();
Eric Holmberg006057d2012-01-11 10:10:42 -07001770 a2_pc_disabled = 0;
Jeff Hugo583a6da2012-02-03 11:37:30 -07001771 a2_pc_disabled_wakelock_skipped = 0;
Eric Holmberg454d9da2012-01-12 09:37:14 -07001772
1773 /* Cleanup Channel States */
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001774 for (i = 0; i < BAM_DMUX_NUM_CHANNELS; ++i) {
1775 temp_remote_status = bam_ch_is_remote_open(i);
1776 bam_ch[i].status &= ~BAM_CH_REMOTE_OPEN;
Karthikeyan Ramasubramanian7bf5ca82011-11-21 13:33:19 -07001777 bam_ch[i].num_tx_pkts = 0;
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001778 if (bam_ch_is_local_open(i))
1779 bam_ch[i].status |= BAM_CH_IN_RESET;
1780 if (temp_remote_status) {
1781 platform_device_unregister(bam_ch[i].pdev);
1782 bam_ch[i].pdev = platform_device_alloc(
1783 bam_ch[i].name, 2);
1784 }
1785 }
Eric Holmberg454d9da2012-01-12 09:37:14 -07001786
1787 /* Cleanup pending UL data */
Jeff Hugo626303bf2011-11-21 11:43:28 -07001788 spin_lock_irqsave(&bam_tx_pool_spinlock, flags);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001789 while (!list_empty(&bam_tx_pool)) {
1790 node = bam_tx_pool.next;
1791 list_del(node);
1792 info = container_of(node, struct tx_pkt_info,
1793 list_node);
1794 if (!info->is_cmd) {
1795 dma_unmap_single(NULL, info->dma_address,
1796 info->skb->len,
1797 DMA_TO_DEVICE);
1798 dev_kfree_skb_any(info->skb);
1799 } else {
1800 dma_unmap_single(NULL, info->dma_address,
1801 info->len,
1802 DMA_TO_DEVICE);
1803 kfree(info->skb);
1804 }
1805 kfree(info);
1806 }
Jeff Hugo626303bf2011-11-21 11:43:28 -07001807 spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags);
Eric Holmberg454d9da2012-01-12 09:37:14 -07001808
Eric Holmberg878923a2012-01-10 14:28:19 -07001809 bam_dmux_log("%s: complete\n", __func__);
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001810 return NOTIFY_DONE;
1811}
1812
Jeff Hugo9dea05c2011-12-21 12:23:05 -07001813static int bam_init(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001814{
1815 u32 h;
1816 dma_addr_t dma_addr;
1817 int ret;
1818 void *a2_virt_addr;
Jeff Hugo4b2890d2012-01-16 16:14:21 -07001819 int skip_iounmap = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001820
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001821 vote_dfab();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001822 /* init BAM */
1823 a2_virt_addr = ioremap_nocache(A2_PHYS_BASE, A2_PHYS_SIZE);
1824 if (!a2_virt_addr) {
1825 pr_err("%s: ioremap failed\n", __func__);
1826 ret = -ENOMEM;
Jeff Hugo994a92d2012-01-05 13:25:21 -07001827 goto ioremap_failed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001828 }
1829 a2_props.phys_addr = A2_PHYS_BASE;
1830 a2_props.virt_addr = a2_virt_addr;
1831 a2_props.virt_size = A2_PHYS_SIZE;
1832 a2_props.irq = A2_BAM_IRQ;
Jeff Hugo927cba62011-11-11 11:49:52 -07001833 a2_props.options = SPS_BAM_OPT_IRQ_WAKEUP;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001834 a2_props.num_pipes = A2_NUM_PIPES;
1835 a2_props.summing_threshold = A2_SUMMING_THRESHOLD;
Jeff Hugo75913c82011-12-05 15:59:01 -07001836 if (cpu_is_msm9615())
1837 a2_props.manage = SPS_BAM_MGR_DEVICE_REMOTE;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001838 /* need to free on tear down */
1839 ret = sps_register_bam_device(&a2_props, &h);
1840 if (ret < 0) {
1841 pr_err("%s: register bam error %d\n", __func__, ret);
1842 goto register_bam_failed;
1843 }
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001844 a2_device_handle = h;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001845
1846 bam_tx_pipe = sps_alloc_endpoint();
1847 if (bam_tx_pipe == NULL) {
1848 pr_err("%s: tx alloc endpoint failed\n", __func__);
1849 ret = -ENOMEM;
Jeff Hugo8ff4a812012-01-17 11:03:13 -07001850 goto tx_alloc_endpoint_failed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001851 }
1852 ret = sps_get_config(bam_tx_pipe, &tx_connection);
1853 if (ret) {
1854 pr_err("%s: tx get config failed %d\n", __func__, ret);
1855 goto tx_get_config_failed;
1856 }
1857
1858 tx_connection.source = SPS_DEV_HANDLE_MEM;
1859 tx_connection.src_pipe_index = 0;
1860 tx_connection.destination = h;
1861 tx_connection.dest_pipe_index = 4;
1862 tx_connection.mode = SPS_MODE_DEST;
1863 tx_connection.options = SPS_O_AUTO_ENABLE | SPS_O_EOT;
1864 tx_desc_mem_buf.size = 0x800; /* 2k */
1865 tx_desc_mem_buf.base = dma_alloc_coherent(NULL, tx_desc_mem_buf.size,
1866 &dma_addr, 0);
1867 if (tx_desc_mem_buf.base == NULL) {
1868 pr_err("%s: tx memory alloc failed\n", __func__);
1869 ret = -ENOMEM;
Jeff Hugo8ff4a812012-01-17 11:03:13 -07001870 goto tx_get_config_failed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001871 }
1872 tx_desc_mem_buf.phys_base = dma_addr;
1873 memset(tx_desc_mem_buf.base, 0x0, tx_desc_mem_buf.size);
1874 tx_connection.desc = tx_desc_mem_buf;
1875 tx_connection.event_thresh = 0x10;
1876
1877 ret = sps_connect(bam_tx_pipe, &tx_connection);
1878 if (ret < 0) {
1879 pr_err("%s: tx connect error %d\n", __func__, ret);
1880 goto tx_connect_failed;
1881 }
1882
1883 bam_rx_pipe = sps_alloc_endpoint();
1884 if (bam_rx_pipe == NULL) {
1885 pr_err("%s: rx alloc endpoint failed\n", __func__);
1886 ret = -ENOMEM;
Jeff Hugo8ff4a812012-01-17 11:03:13 -07001887 goto rx_alloc_endpoint_failed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001888 }
1889 ret = sps_get_config(bam_rx_pipe, &rx_connection);
1890 if (ret) {
1891 pr_err("%s: rx get config failed %d\n", __func__, ret);
1892 goto rx_get_config_failed;
1893 }
1894
1895 rx_connection.source = h;
1896 rx_connection.src_pipe_index = 5;
1897 rx_connection.destination = SPS_DEV_HANDLE_MEM;
1898 rx_connection.dest_pipe_index = 1;
1899 rx_connection.mode = SPS_MODE_SRC;
Jeff Hugo949080a2011-08-30 11:58:56 -06001900 rx_connection.options = SPS_O_AUTO_ENABLE | SPS_O_EOT |
1901 SPS_O_ACK_TRANSFERS;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001902 rx_desc_mem_buf.size = 0x800; /* 2k */
1903 rx_desc_mem_buf.base = dma_alloc_coherent(NULL, rx_desc_mem_buf.size,
1904 &dma_addr, 0);
1905 if (rx_desc_mem_buf.base == NULL) {
1906 pr_err("%s: rx memory alloc failed\n", __func__);
1907 ret = -ENOMEM;
1908 goto rx_mem_failed;
1909 }
1910 rx_desc_mem_buf.phys_base = dma_addr;
1911 memset(rx_desc_mem_buf.base, 0x0, rx_desc_mem_buf.size);
1912 rx_connection.desc = rx_desc_mem_buf;
1913 rx_connection.event_thresh = 0x10;
1914
1915 ret = sps_connect(bam_rx_pipe, &rx_connection);
1916 if (ret < 0) {
1917 pr_err("%s: rx connect error %d\n", __func__, ret);
1918 goto rx_connect_failed;
1919 }
1920
1921 tx_register_event.options = SPS_O_EOT;
1922 tx_register_event.mode = SPS_TRIGGER_CALLBACK;
1923 tx_register_event.xfer_done = NULL;
1924 tx_register_event.callback = bam_mux_tx_notify;
1925 tx_register_event.user = NULL;
1926 ret = sps_register_event(bam_tx_pipe, &tx_register_event);
1927 if (ret < 0) {
1928 pr_err("%s: tx register event error %d\n", __func__, ret);
1929 goto rx_event_reg_failed;
1930 }
1931
Jeff Hugo33dbc002011-08-25 15:52:53 -06001932 rx_register_event.options = SPS_O_EOT;
1933 rx_register_event.mode = SPS_TRIGGER_CALLBACK;
1934 rx_register_event.xfer_done = NULL;
1935 rx_register_event.callback = bam_mux_rx_notify;
1936 rx_register_event.user = NULL;
1937 ret = sps_register_event(bam_rx_pipe, &rx_register_event);
1938 if (ret < 0) {
1939 pr_err("%s: tx register event error %d\n", __func__, ret);
1940 goto rx_event_reg_failed;
1941 }
1942
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001943 bam_mux_initialized = 1;
Eric Holmbergb5b08e52012-01-20 14:19:00 -07001944 queue_rx();
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001945 toggle_apps_ack();
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06001946 bam_connection_is_active = 1;
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06001947 complete_all(&bam_connection_completion);
Jeff Hugo9dea05c2011-12-21 12:23:05 -07001948 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001949
1950rx_event_reg_failed:
1951 sps_disconnect(bam_rx_pipe);
1952rx_connect_failed:
1953 dma_free_coherent(NULL, rx_desc_mem_buf.size, rx_desc_mem_buf.base,
1954 rx_desc_mem_buf.phys_base);
1955rx_mem_failed:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001956rx_get_config_failed:
1957 sps_free_endpoint(bam_rx_pipe);
Jeff Hugo8ff4a812012-01-17 11:03:13 -07001958rx_alloc_endpoint_failed:
1959 sps_disconnect(bam_tx_pipe);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001960tx_connect_failed:
1961 dma_free_coherent(NULL, tx_desc_mem_buf.size, tx_desc_mem_buf.base,
1962 tx_desc_mem_buf.phys_base);
1963tx_get_config_failed:
1964 sps_free_endpoint(bam_tx_pipe);
Jeff Hugo8ff4a812012-01-17 11:03:13 -07001965tx_alloc_endpoint_failed:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001966 sps_deregister_bam_device(h);
Jeff Hugo4b2890d2012-01-16 16:14:21 -07001967 /*
1968 * sps_deregister_bam_device() calls iounmap. calling iounmap on the
1969 * same handle below will cause a crash, so skip it if we've freed
1970 * the handle here.
1971 */
1972 skip_iounmap = 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001973register_bam_failed:
Jeff Hugo4b2890d2012-01-16 16:14:21 -07001974 if (!skip_iounmap)
1975 iounmap(a2_virt_addr);
Jeff Hugo994a92d2012-01-05 13:25:21 -07001976ioremap_failed:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001977 /*destroy_workqueue(bam_mux_workqueue);*/
Jeff Hugo9dea05c2011-12-21 12:23:05 -07001978 return ret;
1979}
1980
1981static int bam_init_fallback(void)
1982{
1983 u32 h;
1984 int ret;
1985 void *a2_virt_addr;
1986
1987 unvote_dfab();
1988 /* init BAM */
1989 a2_virt_addr = ioremap_nocache(A2_PHYS_BASE, A2_PHYS_SIZE);
1990 if (!a2_virt_addr) {
1991 pr_err("%s: ioremap failed\n", __func__);
1992 ret = -ENOMEM;
1993 goto ioremap_failed;
1994 }
1995 a2_props.phys_addr = A2_PHYS_BASE;
1996 a2_props.virt_addr = a2_virt_addr;
1997 a2_props.virt_size = A2_PHYS_SIZE;
1998 a2_props.irq = A2_BAM_IRQ;
1999 a2_props.options = SPS_BAM_OPT_IRQ_WAKEUP;
2000 a2_props.num_pipes = A2_NUM_PIPES;
2001 a2_props.summing_threshold = A2_SUMMING_THRESHOLD;
2002 if (cpu_is_msm9615())
2003 a2_props.manage = SPS_BAM_MGR_DEVICE_REMOTE;
2004 ret = sps_register_bam_device(&a2_props, &h);
2005 if (ret < 0) {
2006 pr_err("%s: register bam error %d\n", __func__, ret);
2007 goto register_bam_failed;
2008 }
2009 a2_device_handle = h;
2010
2011 return 0;
2012
2013register_bam_failed:
Jeff Hugo4b2890d2012-01-16 16:14:21 -07002014 iounmap(a2_virt_addr);
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002015ioremap_failed:
2016 return ret;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002017}
Jeff Hugoade1f842011-08-03 15:53:59 -06002018
Eric Holmberg604ab252012-01-15 00:01:18 -07002019static void msm9615_bam_init(struct work_struct *work)
2020{
2021 int ret = 0;
2022
2023 ret = bam_init();
2024 if (ret) {
2025 ret = bam_init_fallback();
2026 if (ret)
2027 pr_err("%s: bam init fallback failed: %d",
2028 __func__, ret);
2029 }
2030}
2031
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002032static void toggle_apps_ack(void)
2033{
2034 static unsigned int clear_bit; /* 0 = set the bit, else clear bit */
Eric Holmberg878923a2012-01-10 14:28:19 -07002035
2036 bam_dmux_log("%s: apps ack %d->%d\n", __func__,
2037 clear_bit & 0x1, ~clear_bit & 0x1);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002038 smsm_change_state(SMSM_APPS_STATE,
2039 clear_bit & SMSM_A2_POWER_CONTROL_ACK,
2040 ~clear_bit & SMSM_A2_POWER_CONTROL_ACK);
2041 clear_bit = ~clear_bit;
2042}
2043
Jeff Hugoade1f842011-08-03 15:53:59 -06002044static void bam_dmux_smsm_cb(void *priv, uint32_t old_state, uint32_t new_state)
2045{
Eric Holmberg878923a2012-01-10 14:28:19 -07002046 bam_dmux_power_state = new_state & SMSM_A2_POWER_CONTROL ? 1 : 0;
2047 bam_dmux_log("%s: 0x%08x -> 0x%08x\n", __func__, old_state,
2048 new_state);
2049
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002050 if (bam_mux_initialized && new_state & SMSM_A2_POWER_CONTROL) {
Eric Holmberg878923a2012-01-10 14:28:19 -07002051 bam_dmux_log("%s: reconnect\n", __func__);
Eric Holmberg006057d2012-01-11 10:10:42 -07002052 grab_wakelock();
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002053 reconnect_to_bam();
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002054 } else if (bam_mux_initialized &&
2055 !(new_state & SMSM_A2_POWER_CONTROL)) {
Eric Holmberg878923a2012-01-10 14:28:19 -07002056 bam_dmux_log("%s: disconnect\n", __func__);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002057 disconnect_to_bam();
Eric Holmberg006057d2012-01-11 10:10:42 -07002058 release_wakelock();
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002059 } else if (new_state & SMSM_A2_POWER_CONTROL) {
Eric Holmberg878923a2012-01-10 14:28:19 -07002060 bam_dmux_log("%s: init\n", __func__);
Eric Holmberg006057d2012-01-11 10:10:42 -07002061 grab_wakelock();
Eric Holmberg604ab252012-01-15 00:01:18 -07002062 if (cpu_is_msm9615()) {
2063 /*
2064 * even though a2 has signaled it is ready via the
2065 * SMSM_A2_POWER_CONTROL bit, it has not yet
2066 * enabled the pipes as needed by sps_connect
2067 * in satallite mode. Add a short delay to give modem
2068 * time to enable the pipes.
2069 */
2070 schedule_delayed_work(&msm9615_bam_init_work,
2071 msecs_to_jiffies(100));
2072 } else {
2073 bam_init();
Jeff Hugo9dea05c2011-12-21 12:23:05 -07002074 }
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002075 } else {
Eric Holmberg878923a2012-01-10 14:28:19 -07002076 bam_dmux_log("%s: bad state change\n", __func__);
Jeff Hugoade1f842011-08-03 15:53:59 -06002077 pr_err("%s: unsupported state change\n", __func__);
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002078 }
Jeff Hugoade1f842011-08-03 15:53:59 -06002079
2080}
2081
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002082static void bam_dmux_smsm_ack_cb(void *priv, uint32_t old_state,
2083 uint32_t new_state)
2084{
Eric Holmberg878923a2012-01-10 14:28:19 -07002085 bam_dmux_log("%s: 0x%08x -> 0x%08x\n", __func__, old_state,
2086 new_state);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002087 complete_all(&ul_wakeup_ack_completion);
2088}
2089
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002090static int bam_dmux_probe(struct platform_device *pdev)
2091{
2092 int rc;
2093
2094 DBG("%s probe called\n", __func__);
2095 if (bam_mux_initialized)
2096 return 0;
2097
Stephen Boyd1c51a492011-10-26 12:11:47 -07002098 dfab_clk = clk_get(&pdev->dev, "bus_clk");
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002099 if (IS_ERR(dfab_clk)) {
2100 pr_err("%s: did not get dfab clock\n", __func__);
2101 return -EFAULT;
2102 }
2103
2104 rc = clk_set_rate(dfab_clk, 64000000);
2105 if (rc)
2106 pr_err("%s: unable to set dfab clock rate\n", __func__);
2107
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002108 bam_mux_rx_workqueue = create_singlethread_workqueue("bam_dmux_rx");
2109 if (!bam_mux_rx_workqueue)
2110 return -ENOMEM;
2111
2112 bam_mux_tx_workqueue = create_singlethread_workqueue("bam_dmux_tx");
2113 if (!bam_mux_tx_workqueue) {
2114 destroy_workqueue(bam_mux_rx_workqueue);
2115 return -ENOMEM;
2116 }
2117
Jeff Hugo7960abd2011-08-02 15:39:38 -06002118 for (rc = 0; rc < BAM_DMUX_NUM_CHANNELS; ++rc) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002119 spin_lock_init(&bam_ch[rc].lock);
Jeff Hugo7960abd2011-08-02 15:39:38 -06002120 scnprintf(bam_ch[rc].name, BAM_DMUX_CH_NAME_MAX_LEN,
2121 "bam_dmux_ch_%d", rc);
2122 /* bus 2, ie a2 stream 2 */
2123 bam_ch[rc].pdev = platform_device_alloc(bam_ch[rc].name, 2);
2124 if (!bam_ch[rc].pdev) {
2125 pr_err("%s: platform device alloc failed\n", __func__);
2126 destroy_workqueue(bam_mux_rx_workqueue);
2127 destroy_workqueue(bam_mux_tx_workqueue);
2128 return -ENOMEM;
2129 }
2130 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002131
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002132 init_completion(&ul_wakeup_ack_completion);
2133 init_completion(&bam_connection_completion);
Eric Holmberg006057d2012-01-11 10:10:42 -07002134 init_completion(&dfab_unvote_completion);
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002135 INIT_DELAYED_WORK(&ul_timeout_work, ul_timeout);
Eric Holmberg604ab252012-01-15 00:01:18 -07002136 INIT_DELAYED_WORK(&msm9615_bam_init_work, msm9615_bam_init);
Jeff Hugoae3a85e2011-12-02 17:10:18 -07002137 wake_lock_init(&bam_wakelock, WAKE_LOCK_SUSPEND, "bam_dmux_wakelock");
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002138
Jeff Hugoade1f842011-08-03 15:53:59 -06002139 rc = smsm_state_cb_register(SMSM_MODEM_STATE, SMSM_A2_POWER_CONTROL,
2140 bam_dmux_smsm_cb, NULL);
2141
2142 if (rc) {
2143 destroy_workqueue(bam_mux_rx_workqueue);
2144 destroy_workqueue(bam_mux_tx_workqueue);
2145 pr_err("%s: smsm cb register failed, rc: %d\n", __func__, rc);
2146 return -ENOMEM;
2147 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002148
Jeff Hugoaab7ebc2011-09-07 16:46:04 -06002149 rc = smsm_state_cb_register(SMSM_MODEM_STATE, SMSM_A2_POWER_CONTROL_ACK,
2150 bam_dmux_smsm_ack_cb, NULL);
2151
2152 if (rc) {
2153 destroy_workqueue(bam_mux_rx_workqueue);
2154 destroy_workqueue(bam_mux_tx_workqueue);
2155 smsm_state_cb_deregister(SMSM_MODEM_STATE,
2156 SMSM_A2_POWER_CONTROL,
2157 bam_dmux_smsm_cb, NULL);
2158 pr_err("%s: smsm ack cb register failed, rc: %d\n", __func__,
2159 rc);
2160 for (rc = 0; rc < BAM_DMUX_NUM_CHANNELS; ++rc)
2161 platform_device_put(bam_ch[rc].pdev);
2162 return -ENOMEM;
2163 }
2164
Eric Holmbergfd1e2ae2011-11-15 18:28:17 -07002165 if (smsm_get_state(SMSM_MODEM_STATE) & SMSM_A2_POWER_CONTROL)
2166 bam_dmux_smsm_cb(NULL, 0, smsm_get_state(SMSM_MODEM_STATE));
2167
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002168 return 0;
2169}
2170
2171static struct platform_driver bam_dmux_driver = {
2172 .probe = bam_dmux_probe,
2173 .driver = {
2174 .name = "BAM_RMNT",
2175 .owner = THIS_MODULE,
2176 },
2177};
2178
2179static int __init bam_dmux_init(void)
2180{
Eric Holmberg878923a2012-01-10 14:28:19 -07002181 int ret;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002182#ifdef CONFIG_DEBUG_FS
2183 struct dentry *dent;
2184
2185 dent = debugfs_create_dir("bam_dmux", 0);
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07002186 if (!IS_ERR(dent)) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002187 debug_create("tbl", 0444, dent, debug_tbl);
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07002188 debug_create("ul_pkt_cnt", 0444, dent, debug_ul_pkt_cnt);
2189 debug_create("stats", 0444, dent, debug_stats);
Eric Holmberge4ac80b2012-01-12 09:21:59 -07002190 debug_create_multiple("log", 0444, dent, debug_log);
Eric Holmberg2fddbcd2011-11-28 18:25:57 -07002191 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002192#endif
Eric Holmberg878923a2012-01-10 14:28:19 -07002193 ret = kfifo_alloc(&bam_dmux_state_log, PAGE_SIZE, GFP_KERNEL);
2194 if (ret) {
2195 pr_err("%s: failed to allocate log %d\n", __func__, ret);
2196 bam_dmux_state_logging_disabled = 1;
2197 }
2198
Jeff Hugo6e7a92a2011-10-24 05:25:13 -06002199 subsys_notif_register_notifier("modem", &restart_notifier);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002200 return platform_driver_register(&bam_dmux_driver);
2201}
2202
Jeff Hugoade1f842011-08-03 15:53:59 -06002203late_initcall(bam_dmux_init); /* needs to init after SMD */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002204MODULE_DESCRIPTION("MSM BAM DMUX");
2205MODULE_LICENSE("GPL v2");