Arun Kumar Neelakantam | 406e569 | 2013-01-17 18:58:04 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2 | * |
| 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 Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 27 | #include <linux/clk.h> |
Jeff Hugo | ae3a85e | 2011-12-02 17:10:18 -0700 | [diff] [blame] | 28 | #include <linux/wakelock.h> |
Eric Holmberg | 878923a | 2012-01-10 14:28:19 -0700 | [diff] [blame] | 29 | #include <linux/kfifo.h> |
Jeff Hugo | 3910ee1 | 2012-08-21 14:08:20 -0600 | [diff] [blame] | 30 | #include <linux/of.h> |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 31 | #include <mach/msm_ipc_logging.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 32 | #include <mach/sps.h> |
| 33 | #include <mach/bam_dmux.h> |
Jeff Hugo | ade1f84 | 2011-08-03 15:53:59 -0600 | [diff] [blame] | 34 | #include <mach/msm_smsm.h> |
Jeff Hugo | 6e7a92a | 2011-10-24 05:25:13 -0600 | [diff] [blame] | 35 | #include <mach/subsystem_notif.h> |
Jeff Hugo | 75913c8 | 2011-12-05 15:59:01 -0700 | [diff] [blame] | 36 | #include <mach/socinfo.h> |
Jeff Hugo | 4838f41 | 2012-01-20 11:19:37 -0700 | [diff] [blame] | 37 | #include <mach/subsystem_restart.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 38 | |
| 39 | #define BAM_CH_LOCAL_OPEN 0x1 |
| 40 | #define BAM_CH_REMOTE_OPEN 0x2 |
Jeff Hugo | 6e7a92a | 2011-10-24 05:25:13 -0600 | [diff] [blame] | 41 | #define BAM_CH_IN_RESET 0x4 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 42 | |
| 43 | #define BAM_MUX_HDR_MAGIC_NO 0x33fc |
| 44 | |
Eric Holmberg | 006057d | 2012-01-11 10:10:42 -0700 | [diff] [blame] | 45 | #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 Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 50 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 51 | |
Karthikeyan Ramasubramanian | 7bf5ca8 | 2011-11-21 13:33:19 -0700 | [diff] [blame] | 52 | #define LOW_WATERMARK 2 |
| 53 | #define HIGH_WATERMARK 4 |
Anurag Singh | dcd8b4e | 2012-07-30 16:46:37 -0700 | [diff] [blame] | 54 | #define DEFAULT_POLLING_MIN_SLEEP (950) |
| 55 | #define MAX_POLLING_SLEEP (6050) |
| 56 | #define MIN_POLLING_SLEEP (950) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 57 | |
| 58 | static int msm_bam_dmux_debug_enable; |
| 59 | module_param_named(debug_enable, msm_bam_dmux_debug_enable, |
| 60 | int, S_IRUGO | S_IWUSR | S_IWGRP); |
Anurag Singh | dcd8b4e | 2012-07-30 16:46:37 -0700 | [diff] [blame] | 61 | static int POLLING_MIN_SLEEP = 950; |
| 62 | module_param_named(min_sleep, POLLING_MIN_SLEEP, |
| 63 | int, S_IRUGO | S_IWUSR | S_IWGRP); |
| 64 | static int POLLING_MAX_SLEEP = 1050; |
| 65 | module_param_named(max_sleep, POLLING_MAX_SLEEP, |
| 66 | int, S_IRUGO | S_IWUSR | S_IWGRP); |
| 67 | static int POLLING_INACTIVITY = 40; |
| 68 | module_param_named(inactivity, POLLING_INACTIVITY, |
| 69 | int, S_IRUGO | S_IWUSR | S_IWGRP); |
| 70 | static int bam_adaptive_timer_enabled = 1; |
| 71 | module_param_named(adaptive_timer_enabled, |
| 72 | bam_adaptive_timer_enabled, |
| 73 | int, S_IRUGO | S_IWUSR | S_IWGRP); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 74 | |
| 75 | #if defined(DEBUG) |
| 76 | static uint32_t bam_dmux_read_cnt; |
| 77 | static uint32_t bam_dmux_write_cnt; |
| 78 | static uint32_t bam_dmux_write_cpy_cnt; |
| 79 | static uint32_t bam_dmux_write_cpy_bytes; |
Eric Holmberg | 2fddbcd | 2011-11-28 18:25:57 -0700 | [diff] [blame] | 80 | static uint32_t bam_dmux_tx_sps_failure_cnt; |
Eric Holmberg | 6074aba | 2012-01-18 17:59:44 -0700 | [diff] [blame] | 81 | static uint32_t bam_dmux_tx_stall_cnt; |
Eric Holmberg | 1f1255d | 2012-02-22 13:37:21 -0700 | [diff] [blame] | 82 | static atomic_t bam_dmux_ack_out_cnt = ATOMIC_INIT(0); |
| 83 | static atomic_t bam_dmux_ack_in_cnt = ATOMIC_INIT(0); |
| 84 | static atomic_t bam_dmux_a2_pwr_cntl_in_cnt = ATOMIC_INIT(0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 85 | |
| 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 Holmberg | 2fddbcd | 2011-11-28 18:25:57 -0700 | [diff] [blame] | 113 | |
| 114 | #define DBG_INC_TX_SPS_FAILURE_CNT() do { \ |
| 115 | bam_dmux_tx_sps_failure_cnt++; \ |
| 116 | } while (0) |
| 117 | |
Eric Holmberg | 6074aba | 2012-01-18 17:59:44 -0700 | [diff] [blame] | 118 | #define DBG_INC_TX_STALL_CNT() do { \ |
| 119 | bam_dmux_tx_stall_cnt++; \ |
| 120 | } while (0) |
| 121 | |
Eric Holmberg | 1f1255d | 2012-02-22 13:37:21 -0700 | [diff] [blame] | 122 | #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 Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 130 | #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 Holmberg | 2fddbcd | 2011-11-28 18:25:57 -0700 | [diff] [blame] | 135 | #define DBG_INC_TX_SPS_FAILURE_CNT() do { } while (0) |
Eric Holmberg | 6074aba | 2012-01-18 17:59:44 -0700 | [diff] [blame] | 136 | #define DBG_INC_TX_STALL_CNT() do { } while (0) |
Eric Holmberg | 1f1255d | 2012-02-22 13:37:21 -0700 | [diff] [blame] | 137 | #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 Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 141 | #endif |
| 142 | |
| 143 | struct bam_ch_info { |
| 144 | uint32_t status; |
Jeff Hugo | 1c4531c | 2011-08-02 14:55:37 -0600 | [diff] [blame] | 145 | void (*notify)(void *, int, unsigned long); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 146 | void *priv; |
| 147 | spinlock_t lock; |
Jeff Hugo | 7960abd | 2011-08-02 15:39:38 -0600 | [diff] [blame] | 148 | struct platform_device *pdev; |
| 149 | char name[BAM_DMUX_CH_NAME_MAX_LEN]; |
Karthikeyan Ramasubramanian | 7bf5ca8 | 2011-11-21 13:33:19 -0700 | [diff] [blame] | 150 | int num_tx_pkts; |
| 151 | int use_wm; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 152 | }; |
| 153 | |
| 154 | struct 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 Hugo | 6e7a92a | 2011-10-24 05:25:13 -0600 | [diff] [blame] | 160 | struct list_head list_node; |
Eric Holmberg | 878923a | 2012-01-10 14:28:19 -0700 | [diff] [blame] | 161 | unsigned ts_sec; |
| 162 | unsigned long ts_nsec; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 163 | }; |
| 164 | |
| 165 | struct rx_pkt_info { |
| 166 | struct sk_buff *skb; |
| 167 | dma_addr_t dma_address; |
| 168 | struct work_struct work; |
Jeff Hugo | 949080a | 2011-08-30 11:58:56 -0600 | [diff] [blame] | 169 | struct list_head list_node; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 170 | }; |
| 171 | |
| 172 | #define A2_NUM_PIPES 6 |
| 173 | #define A2_SUMMING_THRESHOLD 4096 |
| 174 | #define A2_DEFAULT_DESCRIPTORS 32 |
| 175 | #define A2_PHYS_BASE 0x124C2000 |
| 176 | #define A2_PHYS_SIZE 0x2000 |
| 177 | #define BUFFER_SIZE 2048 |
| 178 | #define NUM_BUFFERS 32 |
Jeff Hugo | 3910ee1 | 2012-08-21 14:08:20 -0600 | [diff] [blame] | 179 | |
| 180 | #ifndef A2_BAM_IRQ |
| 181 | #define A2_BAM_IRQ -1 |
| 182 | #endif |
| 183 | |
| 184 | static void *a2_phys_base; |
| 185 | static uint32_t a2_phys_size; |
| 186 | static int a2_bam_irq; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 187 | static struct sps_bam_props a2_props; |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 188 | static u32 a2_device_handle; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 189 | static struct sps_pipe *bam_tx_pipe; |
| 190 | static struct sps_pipe *bam_rx_pipe; |
| 191 | static struct sps_connect tx_connection; |
| 192 | static struct sps_connect rx_connection; |
| 193 | static struct sps_mem_buffer tx_desc_mem_buf; |
| 194 | static struct sps_mem_buffer rx_desc_mem_buf; |
| 195 | static struct sps_register_event tx_register_event; |
Jeff Hugo | 33dbc00 | 2011-08-25 15:52:53 -0600 | [diff] [blame] | 196 | static struct sps_register_event rx_register_event; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 197 | |
| 198 | static struct bam_ch_info bam_ch[BAM_DMUX_NUM_CHANNELS]; |
| 199 | static int bam_mux_initialized; |
| 200 | |
Jeff Hugo | 949080a | 2011-08-30 11:58:56 -0600 | [diff] [blame] | 201 | static int polling_mode; |
Anurag Singh | dcd8b4e | 2012-07-30 16:46:37 -0700 | [diff] [blame] | 202 | static unsigned long rx_timer_interval; |
Jeff Hugo | 949080a | 2011-08-30 11:58:56 -0600 | [diff] [blame] | 203 | |
| 204 | static LIST_HEAD(bam_rx_pool); |
Jeff Hugo | c974993 | 2011-11-02 17:50:40 -0600 | [diff] [blame] | 205 | static DEFINE_MUTEX(bam_rx_pool_mutexlock); |
Eric Holmberg | b5b08e5 | 2012-01-20 14:19:00 -0700 | [diff] [blame] | 206 | static int bam_rx_pool_len; |
Jeff Hugo | 6e7a92a | 2011-10-24 05:25:13 -0600 | [diff] [blame] | 207 | static LIST_HEAD(bam_tx_pool); |
Jeff Hugo | c974993 | 2011-11-02 17:50:40 -0600 | [diff] [blame] | 208 | static DEFINE_SPINLOCK(bam_tx_pool_spinlock); |
Eric Holmberg | a623da8 | 2012-07-12 09:37:09 -0600 | [diff] [blame] | 209 | static DEFINE_MUTEX(bam_pdev_mutexlock); |
Jeff Hugo | 949080a | 2011-08-30 11:58:56 -0600 | [diff] [blame] | 210 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 211 | struct bam_mux_hdr { |
| 212 | uint16_t magic_num; |
| 213 | uint8_t reserved; |
| 214 | uint8_t cmd; |
| 215 | uint8_t pad_len; |
| 216 | uint8_t ch_id; |
| 217 | uint16_t pkt_len; |
| 218 | }; |
| 219 | |
Jeff Hugo | d98b108 | 2011-10-24 10:30:23 -0600 | [diff] [blame] | 220 | static void notify_all(int event, unsigned long data); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 221 | static void bam_mux_write_done(struct work_struct *work); |
| 222 | static void handle_bam_mux_cmd(struct work_struct *work); |
Jeff Hugo | 949080a | 2011-08-30 11:58:56 -0600 | [diff] [blame] | 223 | static void rx_timer_work_func(struct work_struct *work); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 224 | |
Jeff Hugo | 949080a | 2011-08-30 11:58:56 -0600 | [diff] [blame] | 225 | static DECLARE_WORK(rx_timer_work, rx_timer_work_func); |
Jeff Hugo | 988e7ba | 2012-10-03 15:53:54 -0600 | [diff] [blame] | 226 | static struct delayed_work queue_rx_work; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 227 | |
| 228 | static struct workqueue_struct *bam_mux_rx_workqueue; |
| 229 | static struct workqueue_struct *bam_mux_tx_workqueue; |
| 230 | |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 231 | /* A2 power collaspe */ |
| 232 | #define UL_TIMEOUT_DELAY 1000 /* in ms */ |
Jeff Hugo | 0b13a35 | 2012-03-17 23:18:30 -0600 | [diff] [blame] | 233 | #define ENABLE_DISCONNECT_ACK 0x1 |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 234 | static void toggle_apps_ack(void); |
| 235 | static void reconnect_to_bam(void); |
| 236 | static void disconnect_to_bam(void); |
| 237 | static void ul_wakeup(void); |
| 238 | static void ul_timeout(struct work_struct *work); |
| 239 | static void vote_dfab(void); |
| 240 | static void unvote_dfab(void); |
Jeff Hugo | d98b108 | 2011-10-24 10:30:23 -0600 | [diff] [blame] | 241 | static void kickoff_ul_wakeup_func(struct work_struct *work); |
Eric Holmberg | 006057d | 2012-01-11 10:10:42 -0700 | [diff] [blame] | 242 | static void grab_wakelock(void); |
| 243 | static void release_wakelock(void); |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 244 | |
| 245 | static int bam_is_connected; |
| 246 | static DEFINE_MUTEX(wakeup_lock); |
| 247 | static struct completion ul_wakeup_ack_completion; |
| 248 | static struct completion bam_connection_completion; |
| 249 | static struct delayed_work ul_timeout_work; |
| 250 | static int ul_packet_written; |
Eric Holmberg | bc9f21c | 2012-01-18 11:33:33 -0700 | [diff] [blame] | 251 | static atomic_t ul_ondemand_vote = ATOMIC_INIT(0); |
Stephen Boyd | 69d35e3 | 2012-02-14 15:33:30 -0800 | [diff] [blame] | 252 | static struct clk *dfab_clk, *xo_clk; |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 253 | static DEFINE_RWLOCK(ul_wakeup_lock); |
Jeff Hugo | d98b108 | 2011-10-24 10:30:23 -0600 | [diff] [blame] | 254 | static DECLARE_WORK(kickoff_ul_wakeup, kickoff_ul_wakeup_func); |
Jeff Hugo | 6e7a92a | 2011-10-24 05:25:13 -0600 | [diff] [blame] | 255 | static int bam_connection_is_active; |
Jeff Hugo | f6c1c1e | 2011-12-01 17:43:49 -0700 | [diff] [blame] | 256 | static int wait_for_ack; |
Jeff Hugo | ae3a85e | 2011-12-02 17:10:18 -0700 | [diff] [blame] | 257 | static struct wake_lock bam_wakelock; |
Eric Holmberg | 006057d | 2012-01-11 10:10:42 -0700 | [diff] [blame] | 258 | static int a2_pc_disabled; |
| 259 | static DEFINE_MUTEX(dfab_status_lock); |
| 260 | static int dfab_is_on; |
| 261 | static int wait_for_dfab; |
| 262 | static struct completion dfab_unvote_completion; |
| 263 | static DEFINE_SPINLOCK(wakelock_reference_lock); |
| 264 | static int wakelock_reference_count; |
Jeff Hugo | 583a6da | 2012-02-03 11:37:30 -0700 | [diff] [blame] | 265 | static int a2_pc_disabled_wakelock_skipped; |
Jeff Hugo | b1e7c58 | 2012-06-20 15:02:11 -0600 | [diff] [blame] | 266 | static int disconnect_ack = 1; |
Jeff Hugo | cb79802 | 2012-04-09 14:55:40 -0600 | [diff] [blame] | 267 | static LIST_HEAD(bam_other_notify_funcs); |
Jeff Hugo | 4b7c7b3 | 2012-04-18 16:25:14 -0600 | [diff] [blame] | 268 | static DEFINE_MUTEX(smsm_cb_lock); |
Jeff Hugo | c269614 | 2012-05-03 11:42:13 -0600 | [diff] [blame] | 269 | static DEFINE_MUTEX(delayed_ul_vote_lock); |
| 270 | static int need_delayed_ul_vote; |
Jeff Hugo | 18792a3 | 2012-06-20 15:25:55 -0600 | [diff] [blame] | 271 | static int power_management_only_mode; |
Jeff Hugo | a82a95c | 2012-12-14 17:56:19 -0700 | [diff] [blame] | 272 | static int in_ssr; |
| 273 | static int ssr_skipped_disconnect; |
Jeff Hugo | cb79802 | 2012-04-09 14:55:40 -0600 | [diff] [blame] | 274 | |
| 275 | struct outside_notify_func { |
| 276 | void (*notify)(void *, int, unsigned long); |
| 277 | void *priv; |
| 278 | struct list_head list_node; |
| 279 | }; |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 280 | /* End A2 power collaspe */ |
| 281 | |
Jeff Hugo | 6e7a92a | 2011-10-24 05:25:13 -0600 | [diff] [blame] | 282 | /* subsystem restart */ |
| 283 | static int restart_notifier_cb(struct notifier_block *this, |
| 284 | unsigned long code, |
| 285 | void *data); |
| 286 | |
| 287 | static struct notifier_block restart_notifier = { |
| 288 | .notifier_call = restart_notifier_cb, |
| 289 | }; |
| 290 | static int in_global_reset; |
| 291 | /* end subsystem restart */ |
| 292 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 293 | #define bam_ch_is_open(x) \ |
| 294 | (bam_ch[(x)].status == (BAM_CH_LOCAL_OPEN | BAM_CH_REMOTE_OPEN)) |
| 295 | |
| 296 | #define bam_ch_is_local_open(x) \ |
| 297 | (bam_ch[(x)].status & BAM_CH_LOCAL_OPEN) |
| 298 | |
| 299 | #define bam_ch_is_remote_open(x) \ |
| 300 | (bam_ch[(x)].status & BAM_CH_REMOTE_OPEN) |
| 301 | |
Jeff Hugo | 6e7a92a | 2011-10-24 05:25:13 -0600 | [diff] [blame] | 302 | #define bam_ch_is_in_reset(x) \ |
| 303 | (bam_ch[(x)].status & BAM_CH_IN_RESET) |
| 304 | |
Eric Holmberg | 878923a | 2012-01-10 14:28:19 -0700 | [diff] [blame] | 305 | struct kfifo bam_dmux_state_log; |
Eric Holmberg | 878923a | 2012-01-10 14:28:19 -0700 | [diff] [blame] | 306 | static int bam_dmux_uplink_vote; |
| 307 | static int bam_dmux_power_state; |
| 308 | |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 309 | static void *bam_ipc_log_txt; |
| 310 | |
| 311 | #define BAM_IPC_LOG_PAGES 5 |
| 312 | |
Eric Holmberg | 878923a | 2012-01-10 14:28:19 -0700 | [diff] [blame] | 313 | /** |
| 314 | * Log a state change along with a small message. |
Eric Holmberg | 878923a | 2012-01-10 14:28:19 -0700 | [diff] [blame] | 315 | * Complete size of messsage is limited to @todo. |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 316 | * Logging is done using IPC Logging infrastructure. |
| 317 | * |
| 318 | * States |
| 319 | * D: 1 = Power collapse disabled |
| 320 | * R: 1 = in global reset |
| 321 | * P: 1 = BAM is powered up |
| 322 | * A: 1 = BAM initialized and ready for data |
| 323 | * V: 1 = Uplink vote for power |
| 324 | * U: 1 = Uplink active |
| 325 | * W: 1 = Uplink Wait-for-ack |
| 326 | * A: 1 = Uplink ACK received |
| 327 | * #: >=1 On-demand uplink vote |
| 328 | * D: 1 = Disconnect ACK active |
Eric Holmberg | 878923a | 2012-01-10 14:28:19 -0700 | [diff] [blame] | 329 | */ |
Eric Holmberg | 878923a | 2012-01-10 14:28:19 -0700 | [diff] [blame] | 330 | |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 331 | #define BAM_DMUX_LOG(fmt, args...) \ |
| 332 | do { \ |
| 333 | if (bam_ipc_log_txt) { \ |
| 334 | ipc_log_string(bam_ipc_log_txt, \ |
| 335 | "<DMUX> %c%c%c%c %c%c%c%c%d%c " fmt, \ |
| 336 | a2_pc_disabled ? 'D' : 'd', \ |
| 337 | in_global_reset ? 'R' : 'r', \ |
| 338 | bam_dmux_power_state ? 'P' : 'p', \ |
| 339 | bam_connection_is_active ? 'A' : 'a', \ |
| 340 | bam_dmux_uplink_vote ? 'V' : 'v', \ |
| 341 | bam_is_connected ? 'U' : 'u', \ |
| 342 | wait_for_ack ? 'W' : 'w', \ |
| 343 | ul_wakeup_ack_completion.done ? 'A' : 'a', \ |
| 344 | atomic_read(&ul_ondemand_vote), \ |
| 345 | disconnect_ack ? 'D' : 'd', \ |
| 346 | args); \ |
| 347 | } \ |
| 348 | } while (0) |
Eric Holmberg | 878923a | 2012-01-10 14:28:19 -0700 | [diff] [blame] | 349 | |
Zaheerulla Meer | f800bba | 2013-02-13 15:49:14 +0530 | [diff] [blame] | 350 | #define DMUX_LOG_KERR(fmt, args...) \ |
| 351 | do { \ |
| 352 | BAM_DMUX_LOG(fmt, args); \ |
| 353 | pr_err(fmt, args); \ |
| 354 | } while (0) |
| 355 | |
Eric Holmberg | 878923a | 2012-01-10 14:28:19 -0700 | [diff] [blame] | 356 | static inline void set_tx_timestamp(struct tx_pkt_info *pkt) |
| 357 | { |
| 358 | unsigned long long t_now; |
| 359 | |
| 360 | t_now = sched_clock(); |
| 361 | pkt->ts_nsec = do_div(t_now, 1000000000U); |
| 362 | pkt->ts_sec = (unsigned)t_now; |
| 363 | } |
| 364 | |
| 365 | static inline void verify_tx_queue_is_empty(const char *func) |
| 366 | { |
| 367 | unsigned long flags; |
| 368 | struct tx_pkt_info *info; |
| 369 | int reported = 0; |
| 370 | |
| 371 | spin_lock_irqsave(&bam_tx_pool_spinlock, flags); |
| 372 | list_for_each_entry(info, &bam_tx_pool, list_node) { |
| 373 | if (!reported) { |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 374 | BAM_DMUX_LOG("%s: tx pool not empty\n", func); |
Eric Holmberg | 454d9da | 2012-01-12 09:37:14 -0700 | [diff] [blame] | 375 | if (!in_global_reset) |
| 376 | pr_err("%s: tx pool not empty\n", func); |
Eric Holmberg | 878923a | 2012-01-10 14:28:19 -0700 | [diff] [blame] | 377 | reported = 1; |
| 378 | } |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 379 | BAM_DMUX_LOG("%s: node=%p ts=%u.%09lu\n", __func__, |
Eric Holmberg | 454d9da | 2012-01-12 09:37:14 -0700 | [diff] [blame] | 380 | &info->list_node, info->ts_sec, info->ts_nsec); |
| 381 | if (!in_global_reset) |
| 382 | pr_err("%s: node=%p ts=%u.%09lu\n", __func__, |
| 383 | &info->list_node, info->ts_sec, info->ts_nsec); |
Eric Holmberg | 878923a | 2012-01-10 14:28:19 -0700 | [diff] [blame] | 384 | } |
| 385 | spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags); |
| 386 | } |
| 387 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 388 | static void queue_rx(void) |
| 389 | { |
| 390 | void *ptr; |
| 391 | struct rx_pkt_info *info; |
Eric Holmberg | b5b08e5 | 2012-01-20 14:19:00 -0700 | [diff] [blame] | 392 | int ret; |
| 393 | int rx_len_cached; |
Jeff Hugo | 949080a | 2011-08-30 11:58:56 -0600 | [diff] [blame] | 394 | |
Jeff Hugo | c974993 | 2011-11-02 17:50:40 -0600 | [diff] [blame] | 395 | mutex_lock(&bam_rx_pool_mutexlock); |
Eric Holmberg | b5b08e5 | 2012-01-20 14:19:00 -0700 | [diff] [blame] | 396 | rx_len_cached = bam_rx_pool_len; |
Jeff Hugo | c974993 | 2011-11-02 17:50:40 -0600 | [diff] [blame] | 397 | mutex_unlock(&bam_rx_pool_mutexlock); |
Jeff Hugo | 949080a | 2011-08-30 11:58:56 -0600 | [diff] [blame] | 398 | |
Jeff Hugo | 988e7ba | 2012-10-03 15:53:54 -0600 | [diff] [blame] | 399 | while (bam_connection_is_active && rx_len_cached < NUM_BUFFERS) { |
Eric Holmberg | b5b08e5 | 2012-01-20 14:19:00 -0700 | [diff] [blame] | 400 | if (in_global_reset) |
| 401 | goto fail; |
| 402 | |
Jeff Hugo | 988e7ba | 2012-10-03 15:53:54 -0600 | [diff] [blame] | 403 | info = kmalloc(sizeof(struct rx_pkt_info), |
| 404 | GFP_NOWAIT | __GFP_NOWARN); |
Eric Holmberg | b5b08e5 | 2012-01-20 14:19:00 -0700 | [diff] [blame] | 405 | if (!info) { |
Jeff Hugo | 988e7ba | 2012-10-03 15:53:54 -0600 | [diff] [blame] | 406 | DMUX_LOG_KERR( |
| 407 | "%s: unable to alloc rx_pkt_info, will retry later\n", |
| 408 | __func__); |
Eric Holmberg | b5b08e5 | 2012-01-20 14:19:00 -0700 | [diff] [blame] | 409 | goto fail; |
| 410 | } |
| 411 | |
| 412 | INIT_WORK(&info->work, handle_bam_mux_cmd); |
| 413 | |
Jeff Hugo | 988e7ba | 2012-10-03 15:53:54 -0600 | [diff] [blame] | 414 | info->skb = __dev_alloc_skb(BUFFER_SIZE, |
| 415 | GFP_NOWAIT | __GFP_NOWARN); |
Eric Holmberg | b5b08e5 | 2012-01-20 14:19:00 -0700 | [diff] [blame] | 416 | if (info->skb == NULL) { |
Jeff Hugo | 988e7ba | 2012-10-03 15:53:54 -0600 | [diff] [blame] | 417 | DMUX_LOG_KERR( |
| 418 | "%s: unable to alloc skb, will retry later\n", |
| 419 | __func__); |
Eric Holmberg | b5b08e5 | 2012-01-20 14:19:00 -0700 | [diff] [blame] | 420 | goto fail_info; |
| 421 | } |
| 422 | ptr = skb_put(info->skb, BUFFER_SIZE); |
| 423 | |
| 424 | info->dma_address = dma_map_single(NULL, ptr, BUFFER_SIZE, |
| 425 | DMA_FROM_DEVICE); |
| 426 | if (info->dma_address == 0 || info->dma_address == ~0) { |
| 427 | DMUX_LOG_KERR("%s: dma_map_single failure %p for %p\n", |
| 428 | __func__, (void *)info->dma_address, ptr); |
| 429 | goto fail_skb; |
| 430 | } |
| 431 | |
| 432 | mutex_lock(&bam_rx_pool_mutexlock); |
| 433 | list_add_tail(&info->list_node, &bam_rx_pool); |
| 434 | rx_len_cached = ++bam_rx_pool_len; |
Eric Holmberg | b5b08e5 | 2012-01-20 14:19:00 -0700 | [diff] [blame] | 435 | ret = sps_transfer_one(bam_rx_pipe, info->dma_address, |
Jeff Hugo | c85df96 | 2013-04-05 13:22:48 -0600 | [diff] [blame] | 436 | BUFFER_SIZE, info, 0); |
Eric Holmberg | b5b08e5 | 2012-01-20 14:19:00 -0700 | [diff] [blame] | 437 | if (ret) { |
Eric Holmberg | 00cf869 | 2012-07-16 14:21:19 -0600 | [diff] [blame] | 438 | list_del(&info->list_node); |
| 439 | rx_len_cached = --bam_rx_pool_len; |
| 440 | mutex_unlock(&bam_rx_pool_mutexlock); |
Eric Holmberg | b5b08e5 | 2012-01-20 14:19:00 -0700 | [diff] [blame] | 441 | DMUX_LOG_KERR("%s: sps_transfer_one failed %d\n", |
| 442 | __func__, ret); |
Eric Holmberg | 00cf869 | 2012-07-16 14:21:19 -0600 | [diff] [blame] | 443 | |
| 444 | dma_unmap_single(NULL, info->dma_address, BUFFER_SIZE, |
| 445 | DMA_FROM_DEVICE); |
| 446 | |
| 447 | goto fail_skb; |
Eric Holmberg | b5b08e5 | 2012-01-20 14:19:00 -0700 | [diff] [blame] | 448 | } |
Eric Holmberg | 00cf869 | 2012-07-16 14:21:19 -0600 | [diff] [blame] | 449 | mutex_unlock(&bam_rx_pool_mutexlock); |
| 450 | |
Eric Holmberg | b5b08e5 | 2012-01-20 14:19:00 -0700 | [diff] [blame] | 451 | } |
| 452 | return; |
| 453 | |
Eric Holmberg | b5b08e5 | 2012-01-20 14:19:00 -0700 | [diff] [blame] | 454 | fail_skb: |
| 455 | dev_kfree_skb_any(info->skb); |
| 456 | |
| 457 | fail_info: |
| 458 | kfree(info); |
| 459 | |
| 460 | fail: |
Arun Kumar Neelakantam | 799447f | 2012-12-13 18:06:49 +0530 | [diff] [blame] | 461 | if (rx_len_cached == 0 && !in_global_reset) { |
Jeff Hugo | 988e7ba | 2012-10-03 15:53:54 -0600 | [diff] [blame] | 462 | DMUX_LOG_KERR("%s: rescheduling\n", __func__); |
| 463 | schedule_delayed_work(&queue_rx_work, msecs_to_jiffies(100)); |
Eric Holmberg | b5b08e5 | 2012-01-20 14:19:00 -0700 | [diff] [blame] | 464 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 465 | } |
| 466 | |
Jeff Hugo | 988e7ba | 2012-10-03 15:53:54 -0600 | [diff] [blame] | 467 | static void queue_rx_work_func(struct work_struct *work) |
| 468 | { |
| 469 | queue_rx(); |
| 470 | } |
| 471 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 472 | static void bam_mux_process_data(struct sk_buff *rx_skb) |
| 473 | { |
| 474 | unsigned long flags; |
| 475 | struct bam_mux_hdr *rx_hdr; |
Jeff Hugo | 1c4531c | 2011-08-02 14:55:37 -0600 | [diff] [blame] | 476 | unsigned long event_data; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 477 | |
| 478 | rx_hdr = (struct bam_mux_hdr *)rx_skb->data; |
| 479 | |
| 480 | rx_skb->data = (unsigned char *)(rx_hdr + 1); |
| 481 | rx_skb->tail = rx_skb->data + rx_hdr->pkt_len; |
| 482 | rx_skb->len = rx_hdr->pkt_len; |
Jeff Hugo | ee88f67 | 2011-10-04 17:14:52 -0600 | [diff] [blame] | 483 | rx_skb->truesize = rx_hdr->pkt_len + sizeof(struct sk_buff); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 484 | |
Jeff Hugo | 1c4531c | 2011-08-02 14:55:37 -0600 | [diff] [blame] | 485 | event_data = (unsigned long)(rx_skb); |
| 486 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 487 | spin_lock_irqsave(&bam_ch[rx_hdr->ch_id].lock, flags); |
Jeff Hugo | 1c4531c | 2011-08-02 14:55:37 -0600 | [diff] [blame] | 488 | if (bam_ch[rx_hdr->ch_id].notify) |
| 489 | bam_ch[rx_hdr->ch_id].notify( |
| 490 | bam_ch[rx_hdr->ch_id].priv, BAM_DMUX_RECEIVE, |
| 491 | event_data); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 492 | else |
| 493 | dev_kfree_skb_any(rx_skb); |
| 494 | spin_unlock_irqrestore(&bam_ch[rx_hdr->ch_id].lock, flags); |
| 495 | |
| 496 | queue_rx(); |
| 497 | } |
| 498 | |
Eric Holmberg | 006057d | 2012-01-11 10:10:42 -0700 | [diff] [blame] | 499 | static inline void handle_bam_mux_cmd_open(struct bam_mux_hdr *rx_hdr) |
| 500 | { |
| 501 | unsigned long flags; |
| 502 | int ret; |
| 503 | |
Eric Holmberg | a623da8 | 2012-07-12 09:37:09 -0600 | [diff] [blame] | 504 | mutex_lock(&bam_pdev_mutexlock); |
| 505 | if (in_global_reset) { |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 506 | BAM_DMUX_LOG("%s: open cid %d aborted due to ssr\n", |
Eric Holmberg | a623da8 | 2012-07-12 09:37:09 -0600 | [diff] [blame] | 507 | __func__, rx_hdr->ch_id); |
| 508 | mutex_unlock(&bam_pdev_mutexlock); |
| 509 | queue_rx(); |
| 510 | return; |
| 511 | } |
Eric Holmberg | 006057d | 2012-01-11 10:10:42 -0700 | [diff] [blame] | 512 | spin_lock_irqsave(&bam_ch[rx_hdr->ch_id].lock, flags); |
| 513 | bam_ch[rx_hdr->ch_id].status |= BAM_CH_REMOTE_OPEN; |
| 514 | bam_ch[rx_hdr->ch_id].num_tx_pkts = 0; |
| 515 | spin_unlock_irqrestore(&bam_ch[rx_hdr->ch_id].lock, flags); |
Eric Holmberg | 006057d | 2012-01-11 10:10:42 -0700 | [diff] [blame] | 516 | ret = platform_device_add(bam_ch[rx_hdr->ch_id].pdev); |
| 517 | if (ret) |
| 518 | pr_err("%s: platform_device_add() error: %d\n", |
| 519 | __func__, ret); |
Eric Holmberg | a623da8 | 2012-07-12 09:37:09 -0600 | [diff] [blame] | 520 | mutex_unlock(&bam_pdev_mutexlock); |
| 521 | queue_rx(); |
Eric Holmberg | 006057d | 2012-01-11 10:10:42 -0700 | [diff] [blame] | 522 | } |
| 523 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 524 | static void handle_bam_mux_cmd(struct work_struct *work) |
| 525 | { |
| 526 | unsigned long flags; |
| 527 | struct bam_mux_hdr *rx_hdr; |
| 528 | struct rx_pkt_info *info; |
| 529 | struct sk_buff *rx_skb; |
| 530 | |
| 531 | info = container_of(work, struct rx_pkt_info, work); |
| 532 | rx_skb = info->skb; |
Jeff Hugo | 949080a | 2011-08-30 11:58:56 -0600 | [diff] [blame] | 533 | dma_unmap_single(NULL, info->dma_address, BUFFER_SIZE, DMA_FROM_DEVICE); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 534 | kfree(info); |
| 535 | |
| 536 | rx_hdr = (struct bam_mux_hdr *)rx_skb->data; |
| 537 | |
| 538 | DBG_INC_READ_CNT(sizeof(struct bam_mux_hdr)); |
| 539 | DBG("%s: magic %x reserved %d cmd %d pad %d ch %d len %d\n", __func__, |
| 540 | rx_hdr->magic_num, rx_hdr->reserved, rx_hdr->cmd, |
| 541 | rx_hdr->pad_len, rx_hdr->ch_id, rx_hdr->pkt_len); |
| 542 | if (rx_hdr->magic_num != BAM_MUX_HDR_MAGIC_NO) { |
Eric Holmberg | 878923a | 2012-01-10 14:28:19 -0700 | [diff] [blame] | 543 | DMUX_LOG_KERR("%s: dropping invalid hdr. magic %x" |
| 544 | " reserved %d cmd %d" |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 545 | " pad %d ch %d len %d\n", __func__, |
| 546 | rx_hdr->magic_num, rx_hdr->reserved, rx_hdr->cmd, |
| 547 | rx_hdr->pad_len, rx_hdr->ch_id, rx_hdr->pkt_len); |
| 548 | dev_kfree_skb_any(rx_skb); |
| 549 | queue_rx(); |
| 550 | return; |
| 551 | } |
Eric Holmberg | 9ff40a5 | 2011-11-17 19:17:00 -0700 | [diff] [blame] | 552 | |
| 553 | if (rx_hdr->ch_id >= BAM_DMUX_NUM_CHANNELS) { |
Eric Holmberg | 878923a | 2012-01-10 14:28:19 -0700 | [diff] [blame] | 554 | DMUX_LOG_KERR("%s: dropping invalid LCID %d" |
| 555 | " reserved %d cmd %d" |
Eric Holmberg | 9ff40a5 | 2011-11-17 19:17:00 -0700 | [diff] [blame] | 556 | " pad %d ch %d len %d\n", __func__, |
| 557 | rx_hdr->ch_id, rx_hdr->reserved, rx_hdr->cmd, |
| 558 | rx_hdr->pad_len, rx_hdr->ch_id, rx_hdr->pkt_len); |
| 559 | dev_kfree_skb_any(rx_skb); |
| 560 | queue_rx(); |
| 561 | return; |
| 562 | } |
| 563 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 564 | switch (rx_hdr->cmd) { |
| 565 | case BAM_MUX_HDR_CMD_DATA: |
| 566 | DBG_INC_READ_CNT(rx_hdr->pkt_len); |
| 567 | bam_mux_process_data(rx_skb); |
| 568 | break; |
| 569 | case BAM_MUX_HDR_CMD_OPEN: |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 570 | BAM_DMUX_LOG("%s: opening cid %d PC enabled\n", __func__, |
Eric Holmberg | 878923a | 2012-01-10 14:28:19 -0700 | [diff] [blame] | 571 | rx_hdr->ch_id); |
Eric Holmberg | 006057d | 2012-01-11 10:10:42 -0700 | [diff] [blame] | 572 | handle_bam_mux_cmd_open(rx_hdr); |
Jeff Hugo | b1e7c58 | 2012-06-20 15:02:11 -0600 | [diff] [blame] | 573 | if (!(rx_hdr->reserved & ENABLE_DISCONNECT_ACK)) { |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 574 | BAM_DMUX_LOG("%s: deactivating disconnect ack\n", |
Jeff Hugo | d7d2b06 | 2012-07-24 14:29:56 -0600 | [diff] [blame] | 575 | __func__); |
Jeff Hugo | b1e7c58 | 2012-06-20 15:02:11 -0600 | [diff] [blame] | 576 | disconnect_ack = 0; |
Jeff Hugo | 0b13a35 | 2012-03-17 23:18:30 -0600 | [diff] [blame] | 577 | } |
Eric Holmberg | 006057d | 2012-01-11 10:10:42 -0700 | [diff] [blame] | 578 | dev_kfree_skb_any(rx_skb); |
| 579 | break; |
| 580 | case BAM_MUX_HDR_CMD_OPEN_NO_A2_PC: |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 581 | BAM_DMUX_LOG("%s: opening cid %d PC disabled\n", __func__, |
Eric Holmberg | 006057d | 2012-01-11 10:10:42 -0700 | [diff] [blame] | 582 | rx_hdr->ch_id); |
| 583 | |
| 584 | if (!a2_pc_disabled) { |
| 585 | a2_pc_disabled = 1; |
Jeff Hugo | 322179f | 2012-02-29 10:52:34 -0700 | [diff] [blame] | 586 | ul_wakeup(); |
Eric Holmberg | 006057d | 2012-01-11 10:10:42 -0700 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | handle_bam_mux_cmd_open(rx_hdr); |
Eric Holmberg | e779dba | 2011-11-04 18:22:01 -0600 | [diff] [blame] | 590 | dev_kfree_skb_any(rx_skb); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 591 | break; |
| 592 | case BAM_MUX_HDR_CMD_CLOSE: |
| 593 | /* probably should drop pending write */ |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 594 | BAM_DMUX_LOG("%s: closing cid %d\n", __func__, |
Eric Holmberg | 878923a | 2012-01-10 14:28:19 -0700 | [diff] [blame] | 595 | rx_hdr->ch_id); |
Eric Holmberg | a623da8 | 2012-07-12 09:37:09 -0600 | [diff] [blame] | 596 | mutex_lock(&bam_pdev_mutexlock); |
| 597 | if (in_global_reset) { |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 598 | BAM_DMUX_LOG("%s: close cid %d aborted due to ssr\n", |
Eric Holmberg | a623da8 | 2012-07-12 09:37:09 -0600 | [diff] [blame] | 599 | __func__, rx_hdr->ch_id); |
| 600 | mutex_unlock(&bam_pdev_mutexlock); |
| 601 | break; |
| 602 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 603 | spin_lock_irqsave(&bam_ch[rx_hdr->ch_id].lock, flags); |
| 604 | bam_ch[rx_hdr->ch_id].status &= ~BAM_CH_REMOTE_OPEN; |
| 605 | spin_unlock_irqrestore(&bam_ch[rx_hdr->ch_id].lock, flags); |
Jeff Hugo | 7960abd | 2011-08-02 15:39:38 -0600 | [diff] [blame] | 606 | platform_device_unregister(bam_ch[rx_hdr->ch_id].pdev); |
| 607 | bam_ch[rx_hdr->ch_id].pdev = |
| 608 | platform_device_alloc(bam_ch[rx_hdr->ch_id].name, 2); |
| 609 | if (!bam_ch[rx_hdr->ch_id].pdev) |
| 610 | pr_err("%s: platform_device_alloc failed\n", __func__); |
Eric Holmberg | a623da8 | 2012-07-12 09:37:09 -0600 | [diff] [blame] | 611 | mutex_unlock(&bam_pdev_mutexlock); |
Eric Holmberg | e779dba | 2011-11-04 18:22:01 -0600 | [diff] [blame] | 612 | dev_kfree_skb_any(rx_skb); |
Eric Holmberg | a623da8 | 2012-07-12 09:37:09 -0600 | [diff] [blame] | 613 | queue_rx(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 614 | break; |
| 615 | default: |
Eric Holmberg | 878923a | 2012-01-10 14:28:19 -0700 | [diff] [blame] | 616 | DMUX_LOG_KERR("%s: dropping invalid hdr. magic %x" |
| 617 | " reserved %d cmd %d pad %d ch %d len %d\n", |
| 618 | __func__, rx_hdr->magic_num, rx_hdr->reserved, |
| 619 | rx_hdr->cmd, rx_hdr->pad_len, rx_hdr->ch_id, |
| 620 | rx_hdr->pkt_len); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 621 | dev_kfree_skb_any(rx_skb); |
| 622 | queue_rx(); |
| 623 | return; |
| 624 | } |
| 625 | } |
| 626 | |
| 627 | static int bam_mux_write_cmd(void *data, uint32_t len) |
| 628 | { |
| 629 | int rc; |
| 630 | struct tx_pkt_info *pkt; |
| 631 | dma_addr_t dma_address; |
Jeff Hugo | 626303bf | 2011-11-21 11:43:28 -0700 | [diff] [blame] | 632 | unsigned long flags; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 633 | |
Eric Holmberg | d83cd2b | 2011-11-04 15:54:17 -0600 | [diff] [blame] | 634 | pkt = kmalloc(sizeof(struct tx_pkt_info), GFP_ATOMIC); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 635 | if (pkt == NULL) { |
| 636 | pr_err("%s: mem alloc for tx_pkt_info failed\n", __func__); |
| 637 | rc = -ENOMEM; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 638 | return rc; |
| 639 | } |
| 640 | |
| 641 | dma_address = dma_map_single(NULL, data, len, |
| 642 | DMA_TO_DEVICE); |
| 643 | if (!dma_address) { |
| 644 | pr_err("%s: dma_map_single() failed\n", __func__); |
Jeff Hugo | 96cb748 | 2011-12-07 13:28:31 -0700 | [diff] [blame] | 645 | kfree(pkt); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 646 | rc = -ENOMEM; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 647 | return rc; |
| 648 | } |
| 649 | pkt->skb = (struct sk_buff *)(data); |
| 650 | pkt->len = len; |
| 651 | pkt->dma_address = dma_address; |
| 652 | pkt->is_cmd = 1; |
Eric Holmberg | 878923a | 2012-01-10 14:28:19 -0700 | [diff] [blame] | 653 | set_tx_timestamp(pkt); |
Jeff Hugo | 6e7a92a | 2011-10-24 05:25:13 -0600 | [diff] [blame] | 654 | INIT_WORK(&pkt->work, bam_mux_write_done); |
Jeff Hugo | 626303bf | 2011-11-21 11:43:28 -0700 | [diff] [blame] | 655 | spin_lock_irqsave(&bam_tx_pool_spinlock, flags); |
Jeff Hugo | 6e7a92a | 2011-10-24 05:25:13 -0600 | [diff] [blame] | 656 | list_add_tail(&pkt->list_node, &bam_tx_pool); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 657 | rc = sps_transfer_one(bam_tx_pipe, dma_address, len, |
Jeff Hugo | c85df96 | 2013-04-05 13:22:48 -0600 | [diff] [blame] | 658 | pkt, SPS_IOVEC_FLAG_EOT); |
Jeff Hugo | 7b80c80 | 2011-11-04 16:12:20 -0600 | [diff] [blame] | 659 | if (rc) { |
Eric Holmberg | b5b08e5 | 2012-01-20 14:19:00 -0700 | [diff] [blame] | 660 | DMUX_LOG_KERR("%s sps_transfer_one failed rc=%d\n", |
| 661 | __func__, rc); |
Jeff Hugo | 7b80c80 | 2011-11-04 16:12:20 -0600 | [diff] [blame] | 662 | list_del(&pkt->list_node); |
Eric Holmberg | 2fddbcd | 2011-11-28 18:25:57 -0700 | [diff] [blame] | 663 | DBG_INC_TX_SPS_FAILURE_CNT(); |
Jeff Hugo | 626303bf | 2011-11-21 11:43:28 -0700 | [diff] [blame] | 664 | spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags); |
Eric Holmberg | b5b08e5 | 2012-01-20 14:19:00 -0700 | [diff] [blame] | 665 | dma_unmap_single(NULL, pkt->dma_address, |
| 666 | pkt->len, |
| 667 | DMA_TO_DEVICE); |
Jeff Hugo | 7b80c80 | 2011-11-04 16:12:20 -0600 | [diff] [blame] | 668 | kfree(pkt); |
Jeff Hugo | bb6da95 | 2012-01-16 15:02:42 -0700 | [diff] [blame] | 669 | } else { |
| 670 | spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags); |
Jeff Hugo | 7b80c80 | 2011-11-04 16:12:20 -0600 | [diff] [blame] | 671 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 672 | |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 673 | ul_packet_written = 1; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 674 | return rc; |
| 675 | } |
| 676 | |
| 677 | static void bam_mux_write_done(struct work_struct *work) |
| 678 | { |
| 679 | struct sk_buff *skb; |
| 680 | struct bam_mux_hdr *hdr; |
| 681 | struct tx_pkt_info *info; |
Eric Holmberg | 1cde7a6 | 2011-12-19 18:34:01 -0700 | [diff] [blame] | 682 | struct tx_pkt_info *info_expected; |
Jeff Hugo | 1c4531c | 2011-08-02 14:55:37 -0600 | [diff] [blame] | 683 | unsigned long event_data; |
Karthikeyan Ramasubramanian | 7bf5ca8 | 2011-11-21 13:33:19 -0700 | [diff] [blame] | 684 | unsigned long flags; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 685 | |
Jeff Hugo | 6e7a92a | 2011-10-24 05:25:13 -0600 | [diff] [blame] | 686 | if (in_global_reset) |
| 687 | return; |
Eric Holmberg | 1cde7a6 | 2011-12-19 18:34:01 -0700 | [diff] [blame] | 688 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 689 | info = container_of(work, struct tx_pkt_info, work); |
Eric Holmberg | 1cde7a6 | 2011-12-19 18:34:01 -0700 | [diff] [blame] | 690 | |
| 691 | spin_lock_irqsave(&bam_tx_pool_spinlock, flags); |
| 692 | info_expected = list_first_entry(&bam_tx_pool, |
| 693 | struct tx_pkt_info, list_node); |
| 694 | if (unlikely(info != info_expected)) { |
Eric Holmberg | 878923a | 2012-01-10 14:28:19 -0700 | [diff] [blame] | 695 | struct tx_pkt_info *errant_pkt; |
Eric Holmberg | 1cde7a6 | 2011-12-19 18:34:01 -0700 | [diff] [blame] | 696 | |
Eric Holmberg | 878923a | 2012-01-10 14:28:19 -0700 | [diff] [blame] | 697 | DMUX_LOG_KERR("%s: bam_tx_pool mismatch .next=%p," |
| 698 | " list_node=%p, ts=%u.%09lu\n", |
| 699 | __func__, bam_tx_pool.next, &info->list_node, |
| 700 | info->ts_sec, info->ts_nsec |
| 701 | ); |
| 702 | |
| 703 | list_for_each_entry(errant_pkt, &bam_tx_pool, list_node) { |
| 704 | DMUX_LOG_KERR("%s: node=%p ts=%u.%09lu\n", __func__, |
| 705 | &errant_pkt->list_node, errant_pkt->ts_sec, |
| 706 | errant_pkt->ts_nsec); |
| 707 | |
| 708 | } |
Eric Holmberg | 1cde7a6 | 2011-12-19 18:34:01 -0700 | [diff] [blame] | 709 | spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags); |
| 710 | BUG(); |
| 711 | } |
| 712 | list_del(&info->list_node); |
| 713 | spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags); |
| 714 | |
Jeff Hugo | 6e7a92a | 2011-10-24 05:25:13 -0600 | [diff] [blame] | 715 | if (info->is_cmd) { |
| 716 | kfree(info->skb); |
| 717 | kfree(info); |
| 718 | return; |
| 719 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 720 | skb = info->skb; |
| 721 | kfree(info); |
| 722 | hdr = (struct bam_mux_hdr *)skb->data; |
Eric Holmberg | 9fdef26 | 2012-02-14 11:46:05 -0700 | [diff] [blame] | 723 | DBG_INC_WRITE_CNT(skb->len); |
Jeff Hugo | 1c4531c | 2011-08-02 14:55:37 -0600 | [diff] [blame] | 724 | event_data = (unsigned long)(skb); |
Karthikeyan Ramasubramanian | 7bf5ca8 | 2011-11-21 13:33:19 -0700 | [diff] [blame] | 725 | spin_lock_irqsave(&bam_ch[hdr->ch_id].lock, flags); |
| 726 | bam_ch[hdr->ch_id].num_tx_pkts--; |
| 727 | spin_unlock_irqrestore(&bam_ch[hdr->ch_id].lock, flags); |
Jeff Hugo | 1c4531c | 2011-08-02 14:55:37 -0600 | [diff] [blame] | 728 | if (bam_ch[hdr->ch_id].notify) |
| 729 | bam_ch[hdr->ch_id].notify( |
| 730 | bam_ch[hdr->ch_id].priv, BAM_DMUX_WRITE_DONE, |
| 731 | event_data); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 732 | else |
| 733 | dev_kfree_skb_any(skb); |
| 734 | } |
| 735 | |
| 736 | int msm_bam_dmux_write(uint32_t id, struct sk_buff *skb) |
| 737 | { |
| 738 | int rc = 0; |
| 739 | struct bam_mux_hdr *hdr; |
| 740 | unsigned long flags; |
| 741 | struct sk_buff *new_skb = NULL; |
| 742 | dma_addr_t dma_address; |
| 743 | struct tx_pkt_info *pkt; |
| 744 | |
| 745 | if (id >= BAM_DMUX_NUM_CHANNELS) |
| 746 | return -EINVAL; |
| 747 | if (!skb) |
| 748 | return -EINVAL; |
| 749 | if (!bam_mux_initialized) |
| 750 | return -ENODEV; |
| 751 | |
| 752 | DBG("%s: writing to ch %d len %d\n", __func__, id, skb->len); |
| 753 | spin_lock_irqsave(&bam_ch[id].lock, flags); |
| 754 | if (!bam_ch_is_open(id)) { |
| 755 | spin_unlock_irqrestore(&bam_ch[id].lock, flags); |
| 756 | pr_err("%s: port not open: %d\n", __func__, bam_ch[id].status); |
| 757 | return -ENODEV; |
| 758 | } |
Karthikeyan Ramasubramanian | 7bf5ca8 | 2011-11-21 13:33:19 -0700 | [diff] [blame] | 759 | |
| 760 | if (bam_ch[id].use_wm && |
| 761 | (bam_ch[id].num_tx_pkts >= HIGH_WATERMARK)) { |
| 762 | spin_unlock_irqrestore(&bam_ch[id].lock, flags); |
| 763 | pr_err("%s: watermark exceeded: %d\n", __func__, id); |
| 764 | return -EAGAIN; |
| 765 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 766 | spin_unlock_irqrestore(&bam_ch[id].lock, flags); |
| 767 | |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 768 | read_lock(&ul_wakeup_lock); |
Jeff Hugo | 061ce67 | 2011-10-21 17:15:32 -0600 | [diff] [blame] | 769 | if (!bam_is_connected) { |
| 770 | read_unlock(&ul_wakeup_lock); |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 771 | ul_wakeup(); |
Jeff Hugo | 4838f41 | 2012-01-20 11:19:37 -0700 | [diff] [blame] | 772 | if (unlikely(in_global_reset == 1)) |
| 773 | return -EFAULT; |
Jeff Hugo | 061ce67 | 2011-10-21 17:15:32 -0600 | [diff] [blame] | 774 | read_lock(&ul_wakeup_lock); |
Jeff Hugo | d98b108 | 2011-10-24 10:30:23 -0600 | [diff] [blame] | 775 | notify_all(BAM_DMUX_UL_CONNECTED, (unsigned long)(NULL)); |
Jeff Hugo | 061ce67 | 2011-10-21 17:15:32 -0600 | [diff] [blame] | 776 | } |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 777 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 778 | /* if skb do not have any tailroom for padding, |
| 779 | copy the skb into a new expanded skb */ |
| 780 | if ((skb->len & 0x3) && (skb_tailroom(skb) < (4 - (skb->len & 0x3)))) { |
| 781 | /* revisit, probably dev_alloc_skb and memcpy is effecient */ |
| 782 | new_skb = skb_copy_expand(skb, skb_headroom(skb), |
| 783 | 4 - (skb->len & 0x3), GFP_ATOMIC); |
| 784 | if (new_skb == NULL) { |
| 785 | pr_err("%s: cannot allocate skb\n", __func__); |
Jeff Hugo | c6af54d | 2011-11-02 17:00:27 -0600 | [diff] [blame] | 786 | goto write_fail; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 787 | } |
| 788 | dev_kfree_skb_any(skb); |
| 789 | skb = new_skb; |
| 790 | DBG_INC_WRITE_CPY(skb->len); |
| 791 | } |
| 792 | |
| 793 | hdr = (struct bam_mux_hdr *)skb_push(skb, sizeof(struct bam_mux_hdr)); |
| 794 | |
| 795 | /* caller should allocate for hdr and padding |
| 796 | hdr is fine, padding is tricky */ |
| 797 | hdr->magic_num = BAM_MUX_HDR_MAGIC_NO; |
| 798 | hdr->cmd = BAM_MUX_HDR_CMD_DATA; |
| 799 | hdr->reserved = 0; |
| 800 | hdr->ch_id = id; |
| 801 | hdr->pkt_len = skb->len - sizeof(struct bam_mux_hdr); |
| 802 | if (skb->len & 0x3) |
| 803 | skb_put(skb, 4 - (skb->len & 0x3)); |
| 804 | |
| 805 | hdr->pad_len = skb->len - (sizeof(struct bam_mux_hdr) + hdr->pkt_len); |
| 806 | |
| 807 | DBG("%s: data %p, tail %p skb len %d pkt len %d pad len %d\n", |
| 808 | __func__, skb->data, skb->tail, skb->len, |
| 809 | hdr->pkt_len, hdr->pad_len); |
| 810 | |
| 811 | pkt = kmalloc(sizeof(struct tx_pkt_info), GFP_ATOMIC); |
| 812 | if (pkt == NULL) { |
| 813 | pr_err("%s: mem alloc for tx_pkt_info failed\n", __func__); |
Jeff Hugo | c6af54d | 2011-11-02 17:00:27 -0600 | [diff] [blame] | 814 | goto write_fail2; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | dma_address = dma_map_single(NULL, skb->data, skb->len, |
| 818 | DMA_TO_DEVICE); |
| 819 | if (!dma_address) { |
| 820 | pr_err("%s: dma_map_single() failed\n", __func__); |
Jeff Hugo | c6af54d | 2011-11-02 17:00:27 -0600 | [diff] [blame] | 821 | goto write_fail3; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 822 | } |
| 823 | pkt->skb = skb; |
| 824 | pkt->dma_address = dma_address; |
| 825 | pkt->is_cmd = 0; |
Eric Holmberg | 878923a | 2012-01-10 14:28:19 -0700 | [diff] [blame] | 826 | set_tx_timestamp(pkt); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 827 | INIT_WORK(&pkt->work, bam_mux_write_done); |
Jeff Hugo | 626303bf | 2011-11-21 11:43:28 -0700 | [diff] [blame] | 828 | spin_lock_irqsave(&bam_tx_pool_spinlock, flags); |
Jeff Hugo | 6e7a92a | 2011-10-24 05:25:13 -0600 | [diff] [blame] | 829 | list_add_tail(&pkt->list_node, &bam_tx_pool); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 830 | rc = sps_transfer_one(bam_tx_pipe, dma_address, skb->len, |
Jeff Hugo | c85df96 | 2013-04-05 13:22:48 -0600 | [diff] [blame] | 831 | pkt, SPS_IOVEC_FLAG_EOT); |
Jeff Hugo | 7b80c80 | 2011-11-04 16:12:20 -0600 | [diff] [blame] | 832 | if (rc) { |
Eric Holmberg | b5b08e5 | 2012-01-20 14:19:00 -0700 | [diff] [blame] | 833 | DMUX_LOG_KERR("%s sps_transfer_one failed rc=%d\n", |
| 834 | __func__, rc); |
Jeff Hugo | 7b80c80 | 2011-11-04 16:12:20 -0600 | [diff] [blame] | 835 | list_del(&pkt->list_node); |
Eric Holmberg | 2fddbcd | 2011-11-28 18:25:57 -0700 | [diff] [blame] | 836 | DBG_INC_TX_SPS_FAILURE_CNT(); |
Jeff Hugo | 626303bf | 2011-11-21 11:43:28 -0700 | [diff] [blame] | 837 | spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags); |
Eric Holmberg | b5b08e5 | 2012-01-20 14:19:00 -0700 | [diff] [blame] | 838 | dma_unmap_single(NULL, pkt->dma_address, |
| 839 | pkt->skb->len, DMA_TO_DEVICE); |
Jeff Hugo | 7b80c80 | 2011-11-04 16:12:20 -0600 | [diff] [blame] | 840 | kfree(pkt); |
Jeff Hugo | 872bd06 | 2011-11-15 17:47:21 -0700 | [diff] [blame] | 841 | if (new_skb) |
| 842 | dev_kfree_skb_any(new_skb); |
Karthikeyan Ramasubramanian | 7bf5ca8 | 2011-11-21 13:33:19 -0700 | [diff] [blame] | 843 | } else { |
Jeff Hugo | bb6da95 | 2012-01-16 15:02:42 -0700 | [diff] [blame] | 844 | spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags); |
Karthikeyan Ramasubramanian | 7bf5ca8 | 2011-11-21 13:33:19 -0700 | [diff] [blame] | 845 | spin_lock_irqsave(&bam_ch[id].lock, flags); |
| 846 | bam_ch[id].num_tx_pkts++; |
| 847 | spin_unlock_irqrestore(&bam_ch[id].lock, flags); |
Jeff Hugo | 7b80c80 | 2011-11-04 16:12:20 -0600 | [diff] [blame] | 848 | } |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 849 | ul_packet_written = 1; |
| 850 | read_unlock(&ul_wakeup_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 851 | return rc; |
Jeff Hugo | c6af54d | 2011-11-02 17:00:27 -0600 | [diff] [blame] | 852 | |
| 853 | write_fail3: |
| 854 | kfree(pkt); |
| 855 | write_fail2: |
Arun Kumar Neelakantam | 406e569 | 2013-01-17 18:58:04 +0530 | [diff] [blame] | 856 | skb_pull(skb, sizeof(struct bam_mux_hdr)); |
Jeff Hugo | c6af54d | 2011-11-02 17:00:27 -0600 | [diff] [blame] | 857 | if (new_skb) |
| 858 | dev_kfree_skb_any(new_skb); |
| 859 | write_fail: |
| 860 | read_unlock(&ul_wakeup_lock); |
| 861 | return -ENOMEM; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 862 | } |
| 863 | |
| 864 | int msm_bam_dmux_open(uint32_t id, void *priv, |
Jeff Hugo | 1c4531c | 2011-08-02 14:55:37 -0600 | [diff] [blame] | 865 | void (*notify)(void *, int, unsigned long)) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 866 | { |
| 867 | struct bam_mux_hdr *hdr; |
| 868 | unsigned long flags; |
| 869 | int rc = 0; |
| 870 | |
| 871 | DBG("%s: opening ch %d\n", __func__, id); |
Eric Holmberg | 5d77543 | 2011-11-09 10:23:35 -0700 | [diff] [blame] | 872 | if (!bam_mux_initialized) { |
| 873 | DBG("%s: not inititialized\n", __func__); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 874 | return -ENODEV; |
Eric Holmberg | 5d77543 | 2011-11-09 10:23:35 -0700 | [diff] [blame] | 875 | } |
| 876 | if (id >= BAM_DMUX_NUM_CHANNELS) { |
| 877 | pr_err("%s: invalid channel id %d\n", __func__, id); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 878 | return -EINVAL; |
Eric Holmberg | 5d77543 | 2011-11-09 10:23:35 -0700 | [diff] [blame] | 879 | } |
| 880 | if (notify == NULL) { |
| 881 | pr_err("%s: notify function is NULL\n", __func__); |
Jeff Hugo | 1c4531c | 2011-08-02 14:55:37 -0600 | [diff] [blame] | 882 | return -EINVAL; |
Eric Holmberg | 5d77543 | 2011-11-09 10:23:35 -0700 | [diff] [blame] | 883 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 884 | |
| 885 | hdr = kmalloc(sizeof(struct bam_mux_hdr), GFP_KERNEL); |
| 886 | if (hdr == NULL) { |
| 887 | pr_err("%s: hdr kmalloc failed. ch: %d\n", __func__, id); |
| 888 | return -ENOMEM; |
| 889 | } |
| 890 | spin_lock_irqsave(&bam_ch[id].lock, flags); |
| 891 | if (bam_ch_is_open(id)) { |
| 892 | DBG("%s: Already opened %d\n", __func__, id); |
| 893 | spin_unlock_irqrestore(&bam_ch[id].lock, flags); |
| 894 | kfree(hdr); |
| 895 | goto open_done; |
| 896 | } |
| 897 | if (!bam_ch_is_remote_open(id)) { |
| 898 | DBG("%s: Remote not open; ch: %d\n", __func__, id); |
| 899 | spin_unlock_irqrestore(&bam_ch[id].lock, flags); |
| 900 | kfree(hdr); |
Eric Holmberg | 5d77543 | 2011-11-09 10:23:35 -0700 | [diff] [blame] | 901 | return -ENODEV; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 902 | } |
| 903 | |
Jeff Hugo | 1c4531c | 2011-08-02 14:55:37 -0600 | [diff] [blame] | 904 | bam_ch[id].notify = notify; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 905 | bam_ch[id].priv = priv; |
| 906 | bam_ch[id].status |= BAM_CH_LOCAL_OPEN; |
Karthikeyan Ramasubramanian | 7bf5ca8 | 2011-11-21 13:33:19 -0700 | [diff] [blame] | 907 | bam_ch[id].num_tx_pkts = 0; |
| 908 | bam_ch[id].use_wm = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 909 | spin_unlock_irqrestore(&bam_ch[id].lock, flags); |
| 910 | |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 911 | read_lock(&ul_wakeup_lock); |
Jeff Hugo | 061ce67 | 2011-10-21 17:15:32 -0600 | [diff] [blame] | 912 | if (!bam_is_connected) { |
| 913 | read_unlock(&ul_wakeup_lock); |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 914 | ul_wakeup(); |
Brent Hronik | 9663042 | 2013-05-01 16:38:43 -0600 | [diff] [blame] | 915 | if (unlikely(in_global_reset == 1)) { |
| 916 | kfree(hdr); |
Jeff Hugo | 4838f41 | 2012-01-20 11:19:37 -0700 | [diff] [blame] | 917 | return -EFAULT; |
Brent Hronik | 9663042 | 2013-05-01 16:38:43 -0600 | [diff] [blame] | 918 | } |
Jeff Hugo | 061ce67 | 2011-10-21 17:15:32 -0600 | [diff] [blame] | 919 | read_lock(&ul_wakeup_lock); |
Jeff Hugo | d98b108 | 2011-10-24 10:30:23 -0600 | [diff] [blame] | 920 | notify_all(BAM_DMUX_UL_CONNECTED, (unsigned long)(NULL)); |
Jeff Hugo | 061ce67 | 2011-10-21 17:15:32 -0600 | [diff] [blame] | 921 | } |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 922 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 923 | hdr->magic_num = BAM_MUX_HDR_MAGIC_NO; |
| 924 | hdr->cmd = BAM_MUX_HDR_CMD_OPEN; |
| 925 | hdr->reserved = 0; |
| 926 | hdr->ch_id = id; |
| 927 | hdr->pkt_len = 0; |
| 928 | hdr->pad_len = 0; |
| 929 | |
| 930 | rc = bam_mux_write_cmd((void *)hdr, sizeof(struct bam_mux_hdr)); |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 931 | read_unlock(&ul_wakeup_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 932 | |
| 933 | open_done: |
| 934 | DBG("%s: opened ch %d\n", __func__, id); |
| 935 | return rc; |
| 936 | } |
| 937 | |
| 938 | int msm_bam_dmux_close(uint32_t id) |
| 939 | { |
| 940 | struct bam_mux_hdr *hdr; |
| 941 | unsigned long flags; |
| 942 | int rc; |
| 943 | |
| 944 | if (id >= BAM_DMUX_NUM_CHANNELS) |
| 945 | return -EINVAL; |
| 946 | DBG("%s: closing ch %d\n", __func__, id); |
| 947 | if (!bam_mux_initialized) |
| 948 | return -ENODEV; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 949 | |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 950 | read_lock(&ul_wakeup_lock); |
Jeff Hugo | 6e7a92a | 2011-10-24 05:25:13 -0600 | [diff] [blame] | 951 | if (!bam_is_connected && !bam_ch_is_in_reset(id)) { |
Jeff Hugo | 061ce67 | 2011-10-21 17:15:32 -0600 | [diff] [blame] | 952 | read_unlock(&ul_wakeup_lock); |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 953 | ul_wakeup(); |
Jeff Hugo | 4838f41 | 2012-01-20 11:19:37 -0700 | [diff] [blame] | 954 | if (unlikely(in_global_reset == 1)) |
| 955 | return -EFAULT; |
Jeff Hugo | 061ce67 | 2011-10-21 17:15:32 -0600 | [diff] [blame] | 956 | read_lock(&ul_wakeup_lock); |
Jeff Hugo | d98b108 | 2011-10-24 10:30:23 -0600 | [diff] [blame] | 957 | notify_all(BAM_DMUX_UL_CONNECTED, (unsigned long)(NULL)); |
Jeff Hugo | 061ce67 | 2011-10-21 17:15:32 -0600 | [diff] [blame] | 958 | } |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 959 | |
Jeff Hugo | 061ce67 | 2011-10-21 17:15:32 -0600 | [diff] [blame] | 960 | spin_lock_irqsave(&bam_ch[id].lock, flags); |
Jeff Hugo | 1c4531c | 2011-08-02 14:55:37 -0600 | [diff] [blame] | 961 | bam_ch[id].notify = NULL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 962 | bam_ch[id].priv = NULL; |
| 963 | bam_ch[id].status &= ~BAM_CH_LOCAL_OPEN; |
| 964 | spin_unlock_irqrestore(&bam_ch[id].lock, flags); |
| 965 | |
Jeff Hugo | 6e7a92a | 2011-10-24 05:25:13 -0600 | [diff] [blame] | 966 | if (bam_ch_is_in_reset(id)) { |
| 967 | read_unlock(&ul_wakeup_lock); |
| 968 | bam_ch[id].status &= ~BAM_CH_IN_RESET; |
| 969 | return 0; |
| 970 | } |
| 971 | |
Jeff Hugo | bb5802f | 2011-11-02 17:10:29 -0600 | [diff] [blame] | 972 | hdr = kmalloc(sizeof(struct bam_mux_hdr), GFP_ATOMIC); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 973 | if (hdr == NULL) { |
| 974 | pr_err("%s: hdr kmalloc failed. ch: %d\n", __func__, id); |
Jeff Hugo | c6af54d | 2011-11-02 17:00:27 -0600 | [diff] [blame] | 975 | read_unlock(&ul_wakeup_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 976 | return -ENOMEM; |
| 977 | } |
| 978 | hdr->magic_num = BAM_MUX_HDR_MAGIC_NO; |
| 979 | hdr->cmd = BAM_MUX_HDR_CMD_CLOSE; |
| 980 | hdr->reserved = 0; |
| 981 | hdr->ch_id = id; |
| 982 | hdr->pkt_len = 0; |
| 983 | hdr->pad_len = 0; |
| 984 | |
| 985 | rc = bam_mux_write_cmd((void *)hdr, sizeof(struct bam_mux_hdr)); |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 986 | read_unlock(&ul_wakeup_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 987 | |
| 988 | DBG("%s: closed ch %d\n", __func__, id); |
| 989 | return rc; |
| 990 | } |
| 991 | |
Karthikeyan Ramasubramanian | 7bf5ca8 | 2011-11-21 13:33:19 -0700 | [diff] [blame] | 992 | int msm_bam_dmux_is_ch_full(uint32_t id) |
| 993 | { |
| 994 | unsigned long flags; |
| 995 | int ret; |
| 996 | |
| 997 | if (id >= BAM_DMUX_NUM_CHANNELS) |
| 998 | return -EINVAL; |
| 999 | |
| 1000 | spin_lock_irqsave(&bam_ch[id].lock, flags); |
| 1001 | bam_ch[id].use_wm = 1; |
| 1002 | ret = bam_ch[id].num_tx_pkts >= HIGH_WATERMARK; |
| 1003 | DBG("%s: ch %d num tx pkts=%d, HWM=%d\n", __func__, |
| 1004 | id, bam_ch[id].num_tx_pkts, ret); |
| 1005 | if (!bam_ch_is_local_open(id)) { |
| 1006 | ret = -ENODEV; |
| 1007 | pr_err("%s: port not open: %d\n", __func__, bam_ch[id].status); |
| 1008 | } |
| 1009 | spin_unlock_irqrestore(&bam_ch[id].lock, flags); |
| 1010 | |
| 1011 | return ret; |
| 1012 | } |
| 1013 | |
| 1014 | int msm_bam_dmux_is_ch_low(uint32_t id) |
| 1015 | { |
Eric Holmberg | ed3ca0a | 2012-04-09 15:44:58 -0600 | [diff] [blame] | 1016 | unsigned long flags; |
Karthikeyan Ramasubramanian | 7bf5ca8 | 2011-11-21 13:33:19 -0700 | [diff] [blame] | 1017 | int ret; |
| 1018 | |
| 1019 | if (id >= BAM_DMUX_NUM_CHANNELS) |
| 1020 | return -EINVAL; |
| 1021 | |
Eric Holmberg | ed3ca0a | 2012-04-09 15:44:58 -0600 | [diff] [blame] | 1022 | spin_lock_irqsave(&bam_ch[id].lock, flags); |
Karthikeyan Ramasubramanian | 7bf5ca8 | 2011-11-21 13:33:19 -0700 | [diff] [blame] | 1023 | bam_ch[id].use_wm = 1; |
| 1024 | ret = bam_ch[id].num_tx_pkts <= LOW_WATERMARK; |
| 1025 | DBG("%s: ch %d num tx pkts=%d, LWM=%d\n", __func__, |
| 1026 | id, bam_ch[id].num_tx_pkts, ret); |
| 1027 | if (!bam_ch_is_local_open(id)) { |
| 1028 | ret = -ENODEV; |
| 1029 | pr_err("%s: port not open: %d\n", __func__, bam_ch[id].status); |
| 1030 | } |
Eric Holmberg | ed3ca0a | 2012-04-09 15:44:58 -0600 | [diff] [blame] | 1031 | spin_unlock_irqrestore(&bam_ch[id].lock, flags); |
Karthikeyan Ramasubramanian | 7bf5ca8 | 2011-11-21 13:33:19 -0700 | [diff] [blame] | 1032 | |
| 1033 | return ret; |
| 1034 | } |
| 1035 | |
Eric Holmberg | 8df0cdb | 2012-01-04 17:40:46 -0700 | [diff] [blame] | 1036 | static void rx_switch_to_interrupt_mode(void) |
| 1037 | { |
| 1038 | struct sps_connect cur_rx_conn; |
| 1039 | struct sps_iovec iov; |
| 1040 | struct rx_pkt_info *info; |
| 1041 | int ret; |
| 1042 | |
| 1043 | /* |
| 1044 | * Attempt to enable interrupts - if this fails, |
| 1045 | * continue polling and we will retry later. |
| 1046 | */ |
| 1047 | ret = sps_get_config(bam_rx_pipe, &cur_rx_conn); |
| 1048 | if (ret) { |
| 1049 | pr_err("%s: sps_get_config() failed %d\n", __func__, ret); |
| 1050 | goto fail; |
| 1051 | } |
| 1052 | |
| 1053 | rx_register_event.options = SPS_O_EOT; |
| 1054 | ret = sps_register_event(bam_rx_pipe, &rx_register_event); |
| 1055 | if (ret) { |
| 1056 | pr_err("%s: sps_register_event() failed %d\n", __func__, ret); |
| 1057 | goto fail; |
| 1058 | } |
| 1059 | |
| 1060 | cur_rx_conn.options = SPS_O_AUTO_ENABLE | |
| 1061 | SPS_O_EOT | SPS_O_ACK_TRANSFERS; |
| 1062 | ret = sps_set_config(bam_rx_pipe, &cur_rx_conn); |
| 1063 | if (ret) { |
| 1064 | pr_err("%s: sps_set_config() failed %d\n", __func__, ret); |
| 1065 | goto fail; |
| 1066 | } |
| 1067 | polling_mode = 0; |
Eric Holmberg | 006057d | 2012-01-11 10:10:42 -0700 | [diff] [blame] | 1068 | release_wakelock(); |
Eric Holmberg | 8df0cdb | 2012-01-04 17:40:46 -0700 | [diff] [blame] | 1069 | |
| 1070 | /* handle any rx packets before interrupt was enabled */ |
| 1071 | while (bam_connection_is_active && !polling_mode) { |
| 1072 | ret = sps_get_iovec(bam_rx_pipe, &iov); |
| 1073 | if (ret) { |
| 1074 | pr_err("%s: sps_get_iovec failed %d\n", |
| 1075 | __func__, ret); |
| 1076 | break; |
| 1077 | } |
| 1078 | if (iov.addr == 0) |
| 1079 | break; |
| 1080 | |
| 1081 | mutex_lock(&bam_rx_pool_mutexlock); |
| 1082 | if (unlikely(list_empty(&bam_rx_pool))) { |
Eric Holmberg | 00cf869 | 2012-07-16 14:21:19 -0600 | [diff] [blame] | 1083 | DMUX_LOG_KERR("%s: have iovec %p but rx pool empty\n", |
| 1084 | __func__, (void *)iov.addr); |
Eric Holmberg | 8df0cdb | 2012-01-04 17:40:46 -0700 | [diff] [blame] | 1085 | mutex_unlock(&bam_rx_pool_mutexlock); |
| 1086 | continue; |
| 1087 | } |
| 1088 | info = list_first_entry(&bam_rx_pool, struct rx_pkt_info, |
| 1089 | list_node); |
Eric Holmberg | 00cf869 | 2012-07-16 14:21:19 -0600 | [diff] [blame] | 1090 | if (info->dma_address != iov.addr) { |
| 1091 | DMUX_LOG_KERR("%s: iovec %p != dma %p\n", |
| 1092 | __func__, |
| 1093 | (void *)iov.addr, |
| 1094 | (void *)info->dma_address); |
| 1095 | list_for_each_entry(info, &bam_rx_pool, list_node) { |
| 1096 | DMUX_LOG_KERR("%s: dma %p\n", __func__, |
| 1097 | (void *)info->dma_address); |
| 1098 | if (iov.addr == info->dma_address) |
| 1099 | break; |
| 1100 | } |
| 1101 | } |
| 1102 | BUG_ON(info->dma_address != iov.addr); |
Eric Holmberg | 8df0cdb | 2012-01-04 17:40:46 -0700 | [diff] [blame] | 1103 | list_del(&info->list_node); |
Eric Holmberg | b5b08e5 | 2012-01-20 14:19:00 -0700 | [diff] [blame] | 1104 | --bam_rx_pool_len; |
Eric Holmberg | 8df0cdb | 2012-01-04 17:40:46 -0700 | [diff] [blame] | 1105 | mutex_unlock(&bam_rx_pool_mutexlock); |
| 1106 | handle_bam_mux_cmd(&info->work); |
| 1107 | } |
| 1108 | return; |
| 1109 | |
| 1110 | fail: |
| 1111 | pr_err("%s: reverting to polling\n", __func__); |
Jeff Hugo | fff43af9 | 2012-03-29 17:54:52 -0600 | [diff] [blame] | 1112 | queue_work_on(0, bam_mux_rx_workqueue, &rx_timer_work); |
Eric Holmberg | 8df0cdb | 2012-01-04 17:40:46 -0700 | [diff] [blame] | 1113 | } |
| 1114 | |
Jeff Hugo | 949080a | 2011-08-30 11:58:56 -0600 | [diff] [blame] | 1115 | static void rx_timer_work_func(struct work_struct *work) |
| 1116 | { |
| 1117 | struct sps_iovec iov; |
Jeff Hugo | 949080a | 2011-08-30 11:58:56 -0600 | [diff] [blame] | 1118 | struct rx_pkt_info *info; |
| 1119 | int inactive_cycles = 0; |
| 1120 | int ret; |
Anurag Singh | dcd8b4e | 2012-07-30 16:46:37 -0700 | [diff] [blame] | 1121 | u32 buffs_unused, buffs_used; |
Jeff Hugo | 949080a | 2011-08-30 11:58:56 -0600 | [diff] [blame] | 1122 | |
Eric Holmberg | 8df0cdb | 2012-01-04 17:40:46 -0700 | [diff] [blame] | 1123 | while (bam_connection_is_active) { /* timer loop */ |
Jeff Hugo | 949080a | 2011-08-30 11:58:56 -0600 | [diff] [blame] | 1124 | ++inactive_cycles; |
Eric Holmberg | 8df0cdb | 2012-01-04 17:40:46 -0700 | [diff] [blame] | 1125 | while (bam_connection_is_active) { /* deplete queue loop */ |
Jeff Hugo | 6e7a92a | 2011-10-24 05:25:13 -0600 | [diff] [blame] | 1126 | if (in_global_reset) |
| 1127 | return; |
Eric Holmberg | 8df0cdb | 2012-01-04 17:40:46 -0700 | [diff] [blame] | 1128 | |
| 1129 | ret = sps_get_iovec(bam_rx_pipe, &iov); |
| 1130 | if (ret) { |
| 1131 | pr_err("%s: sps_get_iovec failed %d\n", |
| 1132 | __func__, ret); |
| 1133 | break; |
| 1134 | } |
Jeff Hugo | 949080a | 2011-08-30 11:58:56 -0600 | [diff] [blame] | 1135 | if (iov.addr == 0) |
| 1136 | break; |
| 1137 | inactive_cycles = 0; |
Jeff Hugo | c974993 | 2011-11-02 17:50:40 -0600 | [diff] [blame] | 1138 | mutex_lock(&bam_rx_pool_mutexlock); |
Eric Holmberg | 8df0cdb | 2012-01-04 17:40:46 -0700 | [diff] [blame] | 1139 | if (unlikely(list_empty(&bam_rx_pool))) { |
Eric Holmberg | 00cf869 | 2012-07-16 14:21:19 -0600 | [diff] [blame] | 1140 | DMUX_LOG_KERR( |
| 1141 | "%s: have iovec %p but rx pool empty\n", |
| 1142 | __func__, (void *)iov.addr); |
Eric Holmberg | 8df0cdb | 2012-01-04 17:40:46 -0700 | [diff] [blame] | 1143 | mutex_unlock(&bam_rx_pool_mutexlock); |
| 1144 | continue; |
| 1145 | } |
| 1146 | info = list_first_entry(&bam_rx_pool, |
| 1147 | struct rx_pkt_info, list_node); |
Eric Holmberg | 00cf869 | 2012-07-16 14:21:19 -0600 | [diff] [blame] | 1148 | if (info->dma_address != iov.addr) { |
| 1149 | DMUX_LOG_KERR("%s: iovec %p != dma %p\n", |
| 1150 | __func__, |
| 1151 | (void *)iov.addr, |
| 1152 | (void *)info->dma_address); |
| 1153 | list_for_each_entry(info, &bam_rx_pool, |
| 1154 | list_node) { |
| 1155 | DMUX_LOG_KERR("%s: dma %p\n", __func__, |
| 1156 | (void *)info->dma_address); |
| 1157 | if (iov.addr == info->dma_address) |
| 1158 | break; |
| 1159 | } |
| 1160 | } |
| 1161 | BUG_ON(info->dma_address != iov.addr); |
Eric Holmberg | 8df0cdb | 2012-01-04 17:40:46 -0700 | [diff] [blame] | 1162 | list_del(&info->list_node); |
Eric Holmberg | 00cf869 | 2012-07-16 14:21:19 -0600 | [diff] [blame] | 1163 | --bam_rx_pool_len; |
Jeff Hugo | c974993 | 2011-11-02 17:50:40 -0600 | [diff] [blame] | 1164 | mutex_unlock(&bam_rx_pool_mutexlock); |
Jeff Hugo | 949080a | 2011-08-30 11:58:56 -0600 | [diff] [blame] | 1165 | handle_bam_mux_cmd(&info->work); |
| 1166 | } |
| 1167 | |
Anurag Singh | dcd8b4e | 2012-07-30 16:46:37 -0700 | [diff] [blame] | 1168 | if (inactive_cycles >= POLLING_INACTIVITY) { |
Eric Holmberg | 8df0cdb | 2012-01-04 17:40:46 -0700 | [diff] [blame] | 1169 | rx_switch_to_interrupt_mode(); |
| 1170 | break; |
Jeff Hugo | 949080a | 2011-08-30 11:58:56 -0600 | [diff] [blame] | 1171 | } |
| 1172 | |
Anurag Singh | dcd8b4e | 2012-07-30 16:46:37 -0700 | [diff] [blame] | 1173 | if (bam_adaptive_timer_enabled) { |
| 1174 | usleep_range(rx_timer_interval, rx_timer_interval + 50); |
| 1175 | |
| 1176 | ret = sps_get_unused_desc_num(bam_rx_pipe, |
| 1177 | &buffs_unused); |
| 1178 | |
| 1179 | if (ret) { |
| 1180 | pr_err("%s: error getting num buffers unused after sleep\n", |
| 1181 | __func__); |
| 1182 | |
| 1183 | break; |
| 1184 | } |
| 1185 | |
| 1186 | buffs_used = NUM_BUFFERS - buffs_unused; |
| 1187 | |
| 1188 | if (buffs_unused == 0) { |
| 1189 | rx_timer_interval = MIN_POLLING_SLEEP; |
| 1190 | } else { |
| 1191 | if (buffs_used > 0) { |
| 1192 | rx_timer_interval = |
| 1193 | (2 * NUM_BUFFERS * |
| 1194 | rx_timer_interval)/ |
| 1195 | (3 * buffs_used); |
| 1196 | } else { |
| 1197 | rx_timer_interval = |
| 1198 | MAX_POLLING_SLEEP; |
| 1199 | } |
| 1200 | } |
| 1201 | |
| 1202 | if (rx_timer_interval > MAX_POLLING_SLEEP) |
| 1203 | rx_timer_interval = MAX_POLLING_SLEEP; |
| 1204 | else if (rx_timer_interval < MIN_POLLING_SLEEP) |
| 1205 | rx_timer_interval = MIN_POLLING_SLEEP; |
| 1206 | } else { |
| 1207 | usleep_range(POLLING_MIN_SLEEP, POLLING_MAX_SLEEP); |
| 1208 | } |
Jeff Hugo | 949080a | 2011-08-30 11:58:56 -0600 | [diff] [blame] | 1209 | } |
| 1210 | } |
| 1211 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1212 | static void bam_mux_tx_notify(struct sps_event_notify *notify) |
| 1213 | { |
| 1214 | struct tx_pkt_info *pkt; |
| 1215 | |
| 1216 | DBG("%s: event %d notified\n", __func__, notify->event_id); |
| 1217 | |
Jeff Hugo | 6e7a92a | 2011-10-24 05:25:13 -0600 | [diff] [blame] | 1218 | if (in_global_reset) |
| 1219 | return; |
| 1220 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1221 | switch (notify->event_id) { |
| 1222 | case SPS_EVENT_EOT: |
| 1223 | pkt = notify->data.transfer.user; |
Jeff Hugo | 6e7a92a | 2011-10-24 05:25:13 -0600 | [diff] [blame] | 1224 | if (!pkt->is_cmd) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1225 | dma_unmap_single(NULL, pkt->dma_address, |
| 1226 | pkt->skb->len, |
| 1227 | DMA_TO_DEVICE); |
Jeff Hugo | 6e7a92a | 2011-10-24 05:25:13 -0600 | [diff] [blame] | 1228 | else |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1229 | dma_unmap_single(NULL, pkt->dma_address, |
| 1230 | pkt->len, |
| 1231 | DMA_TO_DEVICE); |
Jeff Hugo | 6e7a92a | 2011-10-24 05:25:13 -0600 | [diff] [blame] | 1232 | queue_work(bam_mux_tx_workqueue, &pkt->work); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1233 | break; |
| 1234 | default: |
| 1235 | pr_err("%s: recieved unexpected event id %d\n", __func__, |
| 1236 | notify->event_id); |
| 1237 | } |
| 1238 | } |
| 1239 | |
Jeff Hugo | 33dbc00 | 2011-08-25 15:52:53 -0600 | [diff] [blame] | 1240 | static void bam_mux_rx_notify(struct sps_event_notify *notify) |
| 1241 | { |
Jeff Hugo | 949080a | 2011-08-30 11:58:56 -0600 | [diff] [blame] | 1242 | int ret; |
| 1243 | struct sps_connect cur_rx_conn; |
Jeff Hugo | 33dbc00 | 2011-08-25 15:52:53 -0600 | [diff] [blame] | 1244 | |
| 1245 | DBG("%s: event %d notified\n", __func__, notify->event_id); |
| 1246 | |
Jeff Hugo | 6e7a92a | 2011-10-24 05:25:13 -0600 | [diff] [blame] | 1247 | if (in_global_reset) |
| 1248 | return; |
| 1249 | |
Jeff Hugo | 33dbc00 | 2011-08-25 15:52:53 -0600 | [diff] [blame] | 1250 | switch (notify->event_id) { |
| 1251 | case SPS_EVENT_EOT: |
Jeff Hugo | 949080a | 2011-08-30 11:58:56 -0600 | [diff] [blame] | 1252 | /* attempt to disable interrupts in this pipe */ |
| 1253 | if (!polling_mode) { |
| 1254 | ret = sps_get_config(bam_rx_pipe, &cur_rx_conn); |
| 1255 | if (ret) { |
Eric Holmberg | 8df0cdb | 2012-01-04 17:40:46 -0700 | [diff] [blame] | 1256 | pr_err("%s: sps_get_config() failed %d, interrupts" |
| 1257 | " not disabled\n", __func__, ret); |
Jeff Hugo | 949080a | 2011-08-30 11:58:56 -0600 | [diff] [blame] | 1258 | break; |
| 1259 | } |
Jeff Hugo | a9d32ba | 2011-11-21 14:59:48 -0700 | [diff] [blame] | 1260 | cur_rx_conn.options = SPS_O_AUTO_ENABLE | |
Jeff Hugo | 949080a | 2011-08-30 11:58:56 -0600 | [diff] [blame] | 1261 | SPS_O_ACK_TRANSFERS | SPS_O_POLL; |
| 1262 | ret = sps_set_config(bam_rx_pipe, &cur_rx_conn); |
| 1263 | if (ret) { |
Eric Holmberg | 8df0cdb | 2012-01-04 17:40:46 -0700 | [diff] [blame] | 1264 | pr_err("%s: sps_set_config() failed %d, interrupts" |
| 1265 | " not disabled\n", __func__, ret); |
Jeff Hugo | 949080a | 2011-08-30 11:58:56 -0600 | [diff] [blame] | 1266 | break; |
| 1267 | } |
Eric Holmberg | 006057d | 2012-01-11 10:10:42 -0700 | [diff] [blame] | 1268 | grab_wakelock(); |
Jeff Hugo | 949080a | 2011-08-30 11:58:56 -0600 | [diff] [blame] | 1269 | polling_mode = 1; |
Jeff Hugo | fff43af9 | 2012-03-29 17:54:52 -0600 | [diff] [blame] | 1270 | /* |
| 1271 | * run on core 0 so that netif_rx() in rmnet uses only |
| 1272 | * one queue |
| 1273 | */ |
| 1274 | queue_work_on(0, bam_mux_rx_workqueue, &rx_timer_work); |
Jeff Hugo | 949080a | 2011-08-30 11:58:56 -0600 | [diff] [blame] | 1275 | } |
Jeff Hugo | 33dbc00 | 2011-08-25 15:52:53 -0600 | [diff] [blame] | 1276 | break; |
| 1277 | default: |
| 1278 | pr_err("%s: recieved unexpected event id %d\n", __func__, |
| 1279 | notify->event_id); |
| 1280 | } |
| 1281 | } |
| 1282 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1283 | #ifdef CONFIG_DEBUG_FS |
| 1284 | |
| 1285 | static int debug_tbl(char *buf, int max) |
| 1286 | { |
| 1287 | int i = 0; |
| 1288 | int j; |
| 1289 | |
| 1290 | for (j = 0; j < BAM_DMUX_NUM_CHANNELS; ++j) { |
| 1291 | i += scnprintf(buf + i, max - i, |
| 1292 | "ch%02d local open=%s remote open=%s\n", |
| 1293 | j, bam_ch_is_local_open(j) ? "Y" : "N", |
| 1294 | bam_ch_is_remote_open(j) ? "Y" : "N"); |
| 1295 | } |
| 1296 | |
| 1297 | return i; |
| 1298 | } |
| 1299 | |
Eric Holmberg | 2fddbcd | 2011-11-28 18:25:57 -0700 | [diff] [blame] | 1300 | static int debug_ul_pkt_cnt(char *buf, int max) |
| 1301 | { |
| 1302 | struct list_head *p; |
| 1303 | unsigned long flags; |
| 1304 | int n = 0; |
| 1305 | |
| 1306 | spin_lock_irqsave(&bam_tx_pool_spinlock, flags); |
| 1307 | __list_for_each(p, &bam_tx_pool) { |
| 1308 | ++n; |
| 1309 | } |
| 1310 | spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags); |
| 1311 | |
| 1312 | return scnprintf(buf, max, "Number of UL packets in flight: %d\n", n); |
| 1313 | } |
| 1314 | |
| 1315 | static int debug_stats(char *buf, int max) |
| 1316 | { |
| 1317 | int i = 0; |
| 1318 | |
| 1319 | i += scnprintf(buf + i, max - i, |
Eric Holmberg | 9fdef26 | 2012-02-14 11:46:05 -0700 | [diff] [blame] | 1320 | "skb read cnt: %u\n" |
| 1321 | "skb write cnt: %u\n" |
Eric Holmberg | 2fddbcd | 2011-11-28 18:25:57 -0700 | [diff] [blame] | 1322 | "skb copy cnt: %u\n" |
| 1323 | "skb copy bytes: %u\n" |
Eric Holmberg | 6074aba | 2012-01-18 17:59:44 -0700 | [diff] [blame] | 1324 | "sps tx failures: %u\n" |
Eric Holmberg | b5b08e5 | 2012-01-20 14:19:00 -0700 | [diff] [blame] | 1325 | "sps tx stalls: %u\n" |
Eric Holmberg | 1f1255d | 2012-02-22 13:37:21 -0700 | [diff] [blame] | 1326 | "rx queue len: %d\n" |
| 1327 | "a2 ack out cnt: %d\n" |
| 1328 | "a2 ack in cnt: %d\n" |
| 1329 | "a2 pwr cntl in: %d\n", |
Eric Holmberg | 9fdef26 | 2012-02-14 11:46:05 -0700 | [diff] [blame] | 1330 | bam_dmux_read_cnt, |
| 1331 | bam_dmux_write_cnt, |
Eric Holmberg | 2fddbcd | 2011-11-28 18:25:57 -0700 | [diff] [blame] | 1332 | bam_dmux_write_cpy_cnt, |
| 1333 | bam_dmux_write_cpy_bytes, |
Eric Holmberg | 6074aba | 2012-01-18 17:59:44 -0700 | [diff] [blame] | 1334 | bam_dmux_tx_sps_failure_cnt, |
Eric Holmberg | b5b08e5 | 2012-01-20 14:19:00 -0700 | [diff] [blame] | 1335 | bam_dmux_tx_stall_cnt, |
Eric Holmberg | 1f1255d | 2012-02-22 13:37:21 -0700 | [diff] [blame] | 1336 | bam_rx_pool_len, |
| 1337 | atomic_read(&bam_dmux_ack_out_cnt), |
| 1338 | atomic_read(&bam_dmux_ack_in_cnt), |
| 1339 | atomic_read(&bam_dmux_a2_pwr_cntl_in_cnt) |
Eric Holmberg | 2fddbcd | 2011-11-28 18:25:57 -0700 | [diff] [blame] | 1340 | ); |
| 1341 | |
| 1342 | return i; |
| 1343 | } |
| 1344 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1345 | #define DEBUG_BUFMAX 4096 |
| 1346 | static char debug_buffer[DEBUG_BUFMAX]; |
| 1347 | |
| 1348 | static ssize_t debug_read(struct file *file, char __user *buf, |
| 1349 | size_t count, loff_t *ppos) |
| 1350 | { |
| 1351 | int (*fill)(char *buf, int max) = file->private_data; |
| 1352 | int bsize = fill(debug_buffer, DEBUG_BUFMAX); |
| 1353 | return simple_read_from_buffer(buf, count, ppos, debug_buffer, bsize); |
| 1354 | } |
| 1355 | |
| 1356 | static int debug_open(struct inode *inode, struct file *file) |
| 1357 | { |
| 1358 | file->private_data = inode->i_private; |
| 1359 | return 0; |
| 1360 | } |
| 1361 | |
| 1362 | |
| 1363 | static const struct file_operations debug_ops = { |
| 1364 | .read = debug_read, |
| 1365 | .open = debug_open, |
| 1366 | }; |
| 1367 | |
| 1368 | static void debug_create(const char *name, mode_t mode, |
| 1369 | struct dentry *dent, |
| 1370 | int (*fill)(char *buf, int max)) |
| 1371 | { |
Eric Holmberg | e4ac80b | 2012-01-12 09:21:59 -0700 | [diff] [blame] | 1372 | struct dentry *file; |
| 1373 | |
| 1374 | file = debugfs_create_file(name, mode, dent, fill, &debug_ops); |
| 1375 | if (IS_ERR(file)) |
| 1376 | pr_err("%s: debugfs create failed %d\n", __func__, |
| 1377 | (int)PTR_ERR(file)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1378 | } |
| 1379 | |
| 1380 | #endif |
| 1381 | |
Jeff Hugo | d98b108 | 2011-10-24 10:30:23 -0600 | [diff] [blame] | 1382 | static void notify_all(int event, unsigned long data) |
| 1383 | { |
| 1384 | int i; |
Jeff Hugo | cb79802 | 2012-04-09 14:55:40 -0600 | [diff] [blame] | 1385 | struct list_head *temp; |
| 1386 | struct outside_notify_func *func; |
Jeff Hugo | d98b108 | 2011-10-24 10:30:23 -0600 | [diff] [blame] | 1387 | |
Jeff Hugo | ac8152a | 2013-04-19 11:05:19 -0600 | [diff] [blame] | 1388 | BAM_DMUX_LOG("%s: event=%d, data=%lu\n", __func__, event, data); |
| 1389 | |
Jeff Hugo | d98b108 | 2011-10-24 10:30:23 -0600 | [diff] [blame] | 1390 | for (i = 0; i < BAM_DMUX_NUM_CHANNELS; ++i) { |
Jeff Hugo | ac8152a | 2013-04-19 11:05:19 -0600 | [diff] [blame] | 1391 | if (bam_ch_is_open(i)) |
Jeff Hugo | d98b108 | 2011-10-24 10:30:23 -0600 | [diff] [blame] | 1392 | bam_ch[i].notify(bam_ch[i].priv, event, data); |
| 1393 | } |
Jeff Hugo | cb79802 | 2012-04-09 14:55:40 -0600 | [diff] [blame] | 1394 | |
| 1395 | __list_for_each(temp, &bam_other_notify_funcs) { |
| 1396 | func = container_of(temp, struct outside_notify_func, |
| 1397 | list_node); |
| 1398 | func->notify(func->priv, event, data); |
| 1399 | } |
Jeff Hugo | d98b108 | 2011-10-24 10:30:23 -0600 | [diff] [blame] | 1400 | } |
| 1401 | |
| 1402 | static void kickoff_ul_wakeup_func(struct work_struct *work) |
| 1403 | { |
| 1404 | read_lock(&ul_wakeup_lock); |
| 1405 | if (!bam_is_connected) { |
| 1406 | read_unlock(&ul_wakeup_lock); |
| 1407 | ul_wakeup(); |
Jeff Hugo | 4838f41 | 2012-01-20 11:19:37 -0700 | [diff] [blame] | 1408 | if (unlikely(in_global_reset == 1)) |
| 1409 | return; |
Jeff Hugo | d98b108 | 2011-10-24 10:30:23 -0600 | [diff] [blame] | 1410 | read_lock(&ul_wakeup_lock); |
| 1411 | ul_packet_written = 1; |
| 1412 | notify_all(BAM_DMUX_UL_CONNECTED, (unsigned long)(NULL)); |
| 1413 | } |
| 1414 | read_unlock(&ul_wakeup_lock); |
| 1415 | } |
| 1416 | |
Eric Holmberg | bc9f21c | 2012-01-18 11:33:33 -0700 | [diff] [blame] | 1417 | int msm_bam_dmux_kickoff_ul_wakeup(void) |
Jeff Hugo | d98b108 | 2011-10-24 10:30:23 -0600 | [diff] [blame] | 1418 | { |
Eric Holmberg | bc9f21c | 2012-01-18 11:33:33 -0700 | [diff] [blame] | 1419 | int is_connected; |
| 1420 | |
| 1421 | read_lock(&ul_wakeup_lock); |
| 1422 | ul_packet_written = 1; |
| 1423 | is_connected = bam_is_connected; |
| 1424 | if (!is_connected) |
| 1425 | queue_work(bam_mux_tx_workqueue, &kickoff_ul_wakeup); |
| 1426 | read_unlock(&ul_wakeup_lock); |
| 1427 | |
| 1428 | return is_connected; |
Jeff Hugo | d98b108 | 2011-10-24 10:30:23 -0600 | [diff] [blame] | 1429 | } |
| 1430 | |
Eric Holmberg | 878923a | 2012-01-10 14:28:19 -0700 | [diff] [blame] | 1431 | static void power_vote(int vote) |
| 1432 | { |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 1433 | BAM_DMUX_LOG("%s: curr=%d, vote=%d\n", __func__, |
Eric Holmberg | 878923a | 2012-01-10 14:28:19 -0700 | [diff] [blame] | 1434 | bam_dmux_uplink_vote, vote); |
| 1435 | |
| 1436 | if (bam_dmux_uplink_vote == vote) |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 1437 | BAM_DMUX_LOG("%s: warning - duplicate power vote\n", __func__); |
Eric Holmberg | 878923a | 2012-01-10 14:28:19 -0700 | [diff] [blame] | 1438 | |
| 1439 | bam_dmux_uplink_vote = vote; |
| 1440 | if (vote) |
| 1441 | smsm_change_state(SMSM_APPS_STATE, 0, SMSM_A2_POWER_CONTROL); |
| 1442 | else |
| 1443 | smsm_change_state(SMSM_APPS_STATE, SMSM_A2_POWER_CONTROL, 0); |
| 1444 | } |
| 1445 | |
Eric Holmberg | 454d9da | 2012-01-12 09:37:14 -0700 | [diff] [blame] | 1446 | /* |
| 1447 | * @note: Must be called with ul_wakeup_lock locked. |
| 1448 | */ |
| 1449 | static inline void ul_powerdown(void) |
| 1450 | { |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 1451 | BAM_DMUX_LOG("%s: powerdown\n", __func__); |
Eric Holmberg | 454d9da | 2012-01-12 09:37:14 -0700 | [diff] [blame] | 1452 | verify_tx_queue_is_empty(__func__); |
| 1453 | |
| 1454 | if (a2_pc_disabled) { |
| 1455 | wait_for_dfab = 1; |
| 1456 | INIT_COMPLETION(dfab_unvote_completion); |
| 1457 | release_wakelock(); |
| 1458 | } else { |
| 1459 | wait_for_ack = 1; |
| 1460 | INIT_COMPLETION(ul_wakeup_ack_completion); |
| 1461 | power_vote(0); |
| 1462 | } |
| 1463 | bam_is_connected = 0; |
| 1464 | notify_all(BAM_DMUX_UL_DISCONNECTED, (unsigned long)(NULL)); |
| 1465 | } |
| 1466 | |
| 1467 | static inline void ul_powerdown_finish(void) |
| 1468 | { |
| 1469 | if (a2_pc_disabled && wait_for_dfab) { |
| 1470 | unvote_dfab(); |
| 1471 | complete_all(&dfab_unvote_completion); |
| 1472 | wait_for_dfab = 0; |
| 1473 | } |
| 1474 | } |
| 1475 | |
Eric Holmberg | bc9f21c | 2012-01-18 11:33:33 -0700 | [diff] [blame] | 1476 | /* |
| 1477 | * Votes for UL power and returns current power state. |
| 1478 | * |
| 1479 | * @returns true if currently connected |
| 1480 | */ |
| 1481 | int msm_bam_dmux_ul_power_vote(void) |
| 1482 | { |
| 1483 | int is_connected; |
| 1484 | |
| 1485 | read_lock(&ul_wakeup_lock); |
| 1486 | atomic_inc(&ul_ondemand_vote); |
| 1487 | is_connected = bam_is_connected; |
| 1488 | if (!is_connected) |
| 1489 | queue_work(bam_mux_tx_workqueue, &kickoff_ul_wakeup); |
| 1490 | read_unlock(&ul_wakeup_lock); |
| 1491 | |
| 1492 | return is_connected; |
| 1493 | } |
| 1494 | |
| 1495 | /* |
| 1496 | * Unvotes for UL power. |
| 1497 | * |
| 1498 | * @returns true if vote count is 0 (UL shutdown possible) |
| 1499 | */ |
| 1500 | int msm_bam_dmux_ul_power_unvote(void) |
| 1501 | { |
| 1502 | int vote; |
| 1503 | |
| 1504 | read_lock(&ul_wakeup_lock); |
| 1505 | vote = atomic_dec_return(&ul_ondemand_vote); |
| 1506 | if (unlikely(vote) < 0) |
| 1507 | DMUX_LOG_KERR("%s: invalid power vote %d\n", __func__, vote); |
| 1508 | read_unlock(&ul_wakeup_lock); |
| 1509 | |
| 1510 | return vote == 0; |
| 1511 | } |
| 1512 | |
Jeff Hugo | cb79802 | 2012-04-09 14:55:40 -0600 | [diff] [blame] | 1513 | int msm_bam_dmux_reg_notify(void *priv, |
| 1514 | void (*notify)(void *priv, int event_type, |
| 1515 | unsigned long data)) |
| 1516 | { |
| 1517 | struct outside_notify_func *func; |
| 1518 | |
| 1519 | if (!notify) |
| 1520 | return -EINVAL; |
| 1521 | |
| 1522 | func = kmalloc(sizeof(struct outside_notify_func), GFP_KERNEL); |
| 1523 | if (!func) |
| 1524 | return -ENOMEM; |
| 1525 | |
| 1526 | func->notify = notify; |
| 1527 | func->priv = priv; |
| 1528 | list_add(&func->list_node, &bam_other_notify_funcs); |
| 1529 | |
| 1530 | return 0; |
| 1531 | } |
| 1532 | |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 1533 | static void ul_timeout(struct work_struct *work) |
| 1534 | { |
Jeff Hugo | c040a5b | 2011-11-15 14:26:01 -0700 | [diff] [blame] | 1535 | unsigned long flags; |
| 1536 | int ret; |
| 1537 | |
Jeff Hugo | 6e7a92a | 2011-10-24 05:25:13 -0600 | [diff] [blame] | 1538 | if (in_global_reset) |
| 1539 | return; |
Jeff Hugo | c040a5b | 2011-11-15 14:26:01 -0700 | [diff] [blame] | 1540 | ret = write_trylock_irqsave(&ul_wakeup_lock, flags); |
| 1541 | if (!ret) { /* failed to grab lock, reschedule and bail */ |
| 1542 | schedule_delayed_work(&ul_timeout_work, |
| 1543 | msecs_to_jiffies(UL_TIMEOUT_DELAY)); |
| 1544 | return; |
| 1545 | } |
Eric Holmberg | 454d9da | 2012-01-12 09:37:14 -0700 | [diff] [blame] | 1546 | if (bam_is_connected) { |
Eric Holmberg | 6074aba | 2012-01-18 17:59:44 -0700 | [diff] [blame] | 1547 | if (!ul_packet_written) { |
| 1548 | spin_lock(&bam_tx_pool_spinlock); |
| 1549 | if (!list_empty(&bam_tx_pool)) { |
| 1550 | struct tx_pkt_info *info; |
| 1551 | |
| 1552 | info = list_first_entry(&bam_tx_pool, |
| 1553 | struct tx_pkt_info, list_node); |
| 1554 | DMUX_LOG_KERR("%s: UL delayed ts=%u.%09lu\n", |
| 1555 | __func__, info->ts_sec, info->ts_nsec); |
| 1556 | DBG_INC_TX_STALL_CNT(); |
| 1557 | ul_packet_written = 1; |
| 1558 | } |
| 1559 | spin_unlock(&bam_tx_pool_spinlock); |
| 1560 | } |
| 1561 | |
Eric Holmberg | bc9f21c | 2012-01-18 11:33:33 -0700 | [diff] [blame] | 1562 | if (ul_packet_written || atomic_read(&ul_ondemand_vote)) { |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 1563 | BAM_DMUX_LOG("%s: pkt written %d\n", |
Eric Holmberg | bc9f21c | 2012-01-18 11:33:33 -0700 | [diff] [blame] | 1564 | __func__, ul_packet_written); |
Eric Holmberg | 454d9da | 2012-01-12 09:37:14 -0700 | [diff] [blame] | 1565 | ul_packet_written = 0; |
| 1566 | schedule_delayed_work(&ul_timeout_work, |
| 1567 | msecs_to_jiffies(UL_TIMEOUT_DELAY)); |
Eric Holmberg | 006057d | 2012-01-11 10:10:42 -0700 | [diff] [blame] | 1568 | } else { |
Eric Holmberg | 454d9da | 2012-01-12 09:37:14 -0700 | [diff] [blame] | 1569 | ul_powerdown(); |
Eric Holmberg | 006057d | 2012-01-11 10:10:42 -0700 | [diff] [blame] | 1570 | } |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 1571 | } |
Jeff Hugo | c040a5b | 2011-11-15 14:26:01 -0700 | [diff] [blame] | 1572 | write_unlock_irqrestore(&ul_wakeup_lock, flags); |
Eric Holmberg | 454d9da | 2012-01-12 09:37:14 -0700 | [diff] [blame] | 1573 | ul_powerdown_finish(); |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 1574 | } |
Jeff Hugo | 4838f41 | 2012-01-20 11:19:37 -0700 | [diff] [blame] | 1575 | |
| 1576 | static int ssrestart_check(void) |
| 1577 | { |
Jeff Hugo | b8156d7 | 2013-06-04 12:51:10 -0600 | [diff] [blame] | 1578 | int ret = 0; |
| 1579 | |
| 1580 | DMUX_LOG_KERR("%s: modem timeout: BAM DMUX disabled for SSR\n", |
| 1581 | __func__); |
Eric Holmberg | 90285e2 | 2012-02-22 12:33:05 -0700 | [diff] [blame] | 1582 | in_global_reset = 1; |
Jeff Hugo | b8156d7 | 2013-06-04 12:51:10 -0600 | [diff] [blame] | 1583 | ret = subsystem_restart("modem"); |
| 1584 | if (ret == -ENODEV) |
| 1585 | panic("modem subsystem restart failed\n"); |
Eric Holmberg | 90285e2 | 2012-02-22 12:33:05 -0700 | [diff] [blame] | 1586 | return 1; |
Jeff Hugo | 4838f41 | 2012-01-20 11:19:37 -0700 | [diff] [blame] | 1587 | } |
| 1588 | |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 1589 | static void ul_wakeup(void) |
| 1590 | { |
Jeff Hugo | f6c1c1e | 2011-12-01 17:43:49 -0700 | [diff] [blame] | 1591 | int ret; |
Jeff Hugo | 5f57ec9 | 2012-05-14 13:34:28 -0600 | [diff] [blame] | 1592 | int do_vote_dfab = 0; |
Jeff Hugo | f6c1c1e | 2011-12-01 17:43:49 -0700 | [diff] [blame] | 1593 | |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 1594 | mutex_lock(&wakeup_lock); |
| 1595 | if (bam_is_connected) { /* bam got connected before lock grabbed */ |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 1596 | BAM_DMUX_LOG("%s Already awake\n", __func__); |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 1597 | mutex_unlock(&wakeup_lock); |
| 1598 | return; |
| 1599 | } |
Eric Holmberg | 878923a | 2012-01-10 14:28:19 -0700 | [diff] [blame] | 1600 | |
Jeff Hugo | c269614 | 2012-05-03 11:42:13 -0600 | [diff] [blame] | 1601 | /* |
Jeff Hugo | f500173 | 2012-08-27 13:19:09 -0600 | [diff] [blame] | 1602 | * if this gets hit, that means restart_notifier_cb() has started |
| 1603 | * but probably not finished, thus we know SSR has happened, but |
| 1604 | * haven't been able to send that info to our clients yet. |
| 1605 | * in that case, abort the ul_wakeup() so that we don't undo any |
| 1606 | * work restart_notifier_cb() has done. The clients will be notified |
| 1607 | * shortly. No cleanup necessary (reschedule the wakeup) as our and |
| 1608 | * their SSR handling will cover it |
| 1609 | */ |
| 1610 | if (unlikely(in_global_reset == 1)) { |
| 1611 | mutex_unlock(&wakeup_lock); |
| 1612 | return; |
| 1613 | } |
| 1614 | |
| 1615 | /* |
Jeff Hugo | c269614 | 2012-05-03 11:42:13 -0600 | [diff] [blame] | 1616 | * if someone is voting for UL before bam is inited (modem up first |
| 1617 | * time), set flag for init to kickoff ul wakeup once bam is inited |
| 1618 | */ |
| 1619 | mutex_lock(&delayed_ul_vote_lock); |
| 1620 | if (unlikely(!bam_mux_initialized)) { |
| 1621 | need_delayed_ul_vote = 1; |
| 1622 | mutex_unlock(&delayed_ul_vote_lock); |
| 1623 | mutex_unlock(&wakeup_lock); |
| 1624 | return; |
| 1625 | } |
| 1626 | mutex_unlock(&delayed_ul_vote_lock); |
| 1627 | |
Eric Holmberg | 006057d | 2012-01-11 10:10:42 -0700 | [diff] [blame] | 1628 | if (a2_pc_disabled) { |
| 1629 | /* |
| 1630 | * don't grab the wakelock the first time because it is |
| 1631 | * already grabbed when a2 powers on |
| 1632 | */ |
Jeff Hugo | 5f57ec9 | 2012-05-14 13:34:28 -0600 | [diff] [blame] | 1633 | if (likely(a2_pc_disabled_wakelock_skipped)) { |
Eric Holmberg | 006057d | 2012-01-11 10:10:42 -0700 | [diff] [blame] | 1634 | grab_wakelock(); |
Jeff Hugo | 5f57ec9 | 2012-05-14 13:34:28 -0600 | [diff] [blame] | 1635 | do_vote_dfab = 1; /* vote must occur after wait */ |
| 1636 | } else { |
Jeff Hugo | 583a6da | 2012-02-03 11:37:30 -0700 | [diff] [blame] | 1637 | a2_pc_disabled_wakelock_skipped = 1; |
Jeff Hugo | 5f57ec9 | 2012-05-14 13:34:28 -0600 | [diff] [blame] | 1638 | } |
Eric Holmberg | 006057d | 2012-01-11 10:10:42 -0700 | [diff] [blame] | 1639 | if (wait_for_dfab) { |
Jeff Hugo | 66f7f1e | 2012-01-16 14:30:42 -0700 | [diff] [blame] | 1640 | ret = wait_for_completion_timeout( |
Eric Holmberg | 006057d | 2012-01-11 10:10:42 -0700 | [diff] [blame] | 1641 | &dfab_unvote_completion, HZ); |
| 1642 | BUG_ON(ret == 0); |
| 1643 | } |
Jeff Hugo | 5f57ec9 | 2012-05-14 13:34:28 -0600 | [diff] [blame] | 1644 | if (likely(do_vote_dfab)) |
| 1645 | vote_dfab(); |
Eric Holmberg | 006057d | 2012-01-11 10:10:42 -0700 | [diff] [blame] | 1646 | schedule_delayed_work(&ul_timeout_work, |
| 1647 | msecs_to_jiffies(UL_TIMEOUT_DELAY)); |
| 1648 | bam_is_connected = 1; |
| 1649 | mutex_unlock(&wakeup_lock); |
| 1650 | return; |
| 1651 | } |
| 1652 | |
Jeff Hugo | f6c1c1e | 2011-12-01 17:43:49 -0700 | [diff] [blame] | 1653 | /* |
| 1654 | * must wait for the previous power down request to have been acked |
| 1655 | * chances are it already came in and this will just fall through |
| 1656 | * instead of waiting |
| 1657 | */ |
| 1658 | if (wait_for_ack) { |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 1659 | BAM_DMUX_LOG("%s waiting for previous ack\n", __func__); |
Jeff Hugo | 66f7f1e | 2012-01-16 14:30:42 -0700 | [diff] [blame] | 1660 | ret = wait_for_completion_timeout( |
Jeff Hugo | f6c1c1e | 2011-12-01 17:43:49 -0700 | [diff] [blame] | 1661 | &ul_wakeup_ack_completion, HZ); |
Eric Holmberg | 006057d | 2012-01-11 10:10:42 -0700 | [diff] [blame] | 1662 | wait_for_ack = 0; |
Jeff Hugo | 4838f41 | 2012-01-20 11:19:37 -0700 | [diff] [blame] | 1663 | if (unlikely(ret == 0) && ssrestart_check()) { |
| 1664 | mutex_unlock(&wakeup_lock); |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 1665 | BAM_DMUX_LOG("%s timeout previous ack\n", __func__); |
Jeff Hugo | 4838f41 | 2012-01-20 11:19:37 -0700 | [diff] [blame] | 1666 | return; |
| 1667 | } |
Jeff Hugo | f6c1c1e | 2011-12-01 17:43:49 -0700 | [diff] [blame] | 1668 | } |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 1669 | INIT_COMPLETION(ul_wakeup_ack_completion); |
Eric Holmberg | 878923a | 2012-01-10 14:28:19 -0700 | [diff] [blame] | 1670 | power_vote(1); |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 1671 | BAM_DMUX_LOG("%s waiting for wakeup ack\n", __func__); |
Jeff Hugo | 66f7f1e | 2012-01-16 14:30:42 -0700 | [diff] [blame] | 1672 | ret = wait_for_completion_timeout(&ul_wakeup_ack_completion, HZ); |
Jeff Hugo | 4838f41 | 2012-01-20 11:19:37 -0700 | [diff] [blame] | 1673 | if (unlikely(ret == 0) && ssrestart_check()) { |
| 1674 | mutex_unlock(&wakeup_lock); |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 1675 | BAM_DMUX_LOG("%s timeout wakeup ack\n", __func__); |
Jeff Hugo | 4838f41 | 2012-01-20 11:19:37 -0700 | [diff] [blame] | 1676 | return; |
| 1677 | } |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 1678 | BAM_DMUX_LOG("%s waiting completion\n", __func__); |
Jeff Hugo | 66f7f1e | 2012-01-16 14:30:42 -0700 | [diff] [blame] | 1679 | ret = wait_for_completion_timeout(&bam_connection_completion, HZ); |
Jeff Hugo | 4838f41 | 2012-01-20 11:19:37 -0700 | [diff] [blame] | 1680 | if (unlikely(ret == 0) && ssrestart_check()) { |
| 1681 | mutex_unlock(&wakeup_lock); |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 1682 | BAM_DMUX_LOG("%s timeout power on\n", __func__); |
Jeff Hugo | 4838f41 | 2012-01-20 11:19:37 -0700 | [diff] [blame] | 1683 | return; |
| 1684 | } |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 1685 | |
| 1686 | bam_is_connected = 1; |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 1687 | BAM_DMUX_LOG("%s complete\n", __func__); |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 1688 | schedule_delayed_work(&ul_timeout_work, |
| 1689 | msecs_to_jiffies(UL_TIMEOUT_DELAY)); |
| 1690 | mutex_unlock(&wakeup_lock); |
| 1691 | } |
| 1692 | |
| 1693 | static void reconnect_to_bam(void) |
| 1694 | { |
| 1695 | int i; |
| 1696 | |
Jeff Hugo | 6e7a92a | 2011-10-24 05:25:13 -0600 | [diff] [blame] | 1697 | in_global_reset = 0; |
Jeff Hugo | a82a95c | 2012-12-14 17:56:19 -0700 | [diff] [blame] | 1698 | in_ssr = 0; |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 1699 | vote_dfab(); |
Jeff Hugo | 18792a3 | 2012-06-20 15:25:55 -0600 | [diff] [blame] | 1700 | if (!power_management_only_mode) { |
Jeff Hugo | a82a95c | 2012-12-14 17:56:19 -0700 | [diff] [blame] | 1701 | if (ssr_skipped_disconnect) { |
| 1702 | /* delayed to here to prevent bus stall */ |
| 1703 | sps_disconnect(bam_tx_pipe); |
| 1704 | sps_disconnect(bam_rx_pipe); |
| 1705 | __memzero(rx_desc_mem_buf.base, rx_desc_mem_buf.size); |
| 1706 | __memzero(tx_desc_mem_buf.base, tx_desc_mem_buf.size); |
| 1707 | } |
| 1708 | ssr_skipped_disconnect = 0; |
Jeff Hugo | 18792a3 | 2012-06-20 15:25:55 -0600 | [diff] [blame] | 1709 | i = sps_device_reset(a2_device_handle); |
| 1710 | if (i) |
| 1711 | pr_err("%s: device reset failed rc = %d\n", __func__, |
| 1712 | i); |
| 1713 | i = sps_connect(bam_tx_pipe, &tx_connection); |
| 1714 | if (i) |
| 1715 | pr_err("%s: tx connection failed rc = %d\n", __func__, |
| 1716 | i); |
| 1717 | i = sps_connect(bam_rx_pipe, &rx_connection); |
| 1718 | if (i) |
| 1719 | pr_err("%s: rx connection failed rc = %d\n", __func__, |
| 1720 | i); |
| 1721 | i = sps_register_event(bam_tx_pipe, &tx_register_event); |
| 1722 | if (i) |
| 1723 | pr_err("%s: tx event reg failed rc = %d\n", __func__, |
| 1724 | i); |
| 1725 | i = sps_register_event(bam_rx_pipe, &rx_register_event); |
| 1726 | if (i) |
| 1727 | pr_err("%s: rx event reg failed rc = %d\n", __func__, |
| 1728 | i); |
| 1729 | } |
Eric Holmberg | 8df0cdb | 2012-01-04 17:40:46 -0700 | [diff] [blame] | 1730 | |
| 1731 | bam_connection_is_active = 1; |
| 1732 | |
| 1733 | if (polling_mode) |
| 1734 | rx_switch_to_interrupt_mode(); |
| 1735 | |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 1736 | toggle_apps_ack(); |
| 1737 | complete_all(&bam_connection_completion); |
Jeff Hugo | 18792a3 | 2012-06-20 15:25:55 -0600 | [diff] [blame] | 1738 | if (!power_management_only_mode) |
| 1739 | queue_rx(); |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 1740 | } |
| 1741 | |
| 1742 | static void disconnect_to_bam(void) |
| 1743 | { |
| 1744 | struct list_head *node; |
| 1745 | struct rx_pkt_info *info; |
Eric Holmberg | 454d9da | 2012-01-12 09:37:14 -0700 | [diff] [blame] | 1746 | unsigned long flags; |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 1747 | |
Jeff Hugo | 6e7a92a | 2011-10-24 05:25:13 -0600 | [diff] [blame] | 1748 | bam_connection_is_active = 0; |
Eric Holmberg | 454d9da | 2012-01-12 09:37:14 -0700 | [diff] [blame] | 1749 | |
| 1750 | /* handle disconnect during active UL */ |
| 1751 | write_lock_irqsave(&ul_wakeup_lock, flags); |
| 1752 | if (bam_is_connected) { |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 1753 | BAM_DMUX_LOG("%s: UL active - forcing powerdown\n", __func__); |
Eric Holmberg | 454d9da | 2012-01-12 09:37:14 -0700 | [diff] [blame] | 1754 | ul_powerdown(); |
| 1755 | } |
| 1756 | write_unlock_irqrestore(&ul_wakeup_lock, flags); |
| 1757 | ul_powerdown_finish(); |
| 1758 | |
| 1759 | /* tear down BAM connection */ |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 1760 | INIT_COMPLETION(bam_connection_completion); |
Jeff Hugo | a82a95c | 2012-12-14 17:56:19 -0700 | [diff] [blame] | 1761 | |
| 1762 | /* in_ssr documentation/assumptions found in restart_notifier_cb */ |
Jeff Hugo | 18792a3 | 2012-06-20 15:25:55 -0600 | [diff] [blame] | 1763 | if (!power_management_only_mode) { |
Jeff Hugo | a82a95c | 2012-12-14 17:56:19 -0700 | [diff] [blame] | 1764 | if (likely(!in_ssr)) { |
Jeff Hugo | f7ae7a6 | 2013-04-19 11:18:32 -0600 | [diff] [blame^] | 1765 | BAM_DMUX_LOG("%s: disconnect tx\n", __func__); |
Jeff Hugo | a82a95c | 2012-12-14 17:56:19 -0700 | [diff] [blame] | 1766 | sps_disconnect(bam_tx_pipe); |
Jeff Hugo | f7ae7a6 | 2013-04-19 11:18:32 -0600 | [diff] [blame^] | 1767 | BAM_DMUX_LOG("%s: disconnect rx\n", __func__); |
Jeff Hugo | a82a95c | 2012-12-14 17:56:19 -0700 | [diff] [blame] | 1768 | sps_disconnect(bam_rx_pipe); |
| 1769 | __memzero(rx_desc_mem_buf.base, rx_desc_mem_buf.size); |
| 1770 | __memzero(tx_desc_mem_buf.base, tx_desc_mem_buf.size); |
Jeff Hugo | f7ae7a6 | 2013-04-19 11:18:32 -0600 | [diff] [blame^] | 1771 | BAM_DMUX_LOG("%s: device reset\n", __func__); |
Jeff Hugo | a82a95c | 2012-12-14 17:56:19 -0700 | [diff] [blame] | 1772 | sps_device_reset(a2_device_handle); |
| 1773 | } else { |
| 1774 | ssr_skipped_disconnect = 1; |
| 1775 | } |
Jeff Hugo | 18792a3 | 2012-06-20 15:25:55 -0600 | [diff] [blame] | 1776 | } |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 1777 | unvote_dfab(); |
Eric Holmberg | 8df0cdb | 2012-01-04 17:40:46 -0700 | [diff] [blame] | 1778 | |
| 1779 | mutex_lock(&bam_rx_pool_mutexlock); |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 1780 | while (!list_empty(&bam_rx_pool)) { |
| 1781 | node = bam_rx_pool.next; |
| 1782 | list_del(node); |
| 1783 | info = container_of(node, struct rx_pkt_info, list_node); |
| 1784 | dma_unmap_single(NULL, info->dma_address, BUFFER_SIZE, |
| 1785 | DMA_FROM_DEVICE); |
| 1786 | dev_kfree_skb_any(info->skb); |
| 1787 | kfree(info); |
| 1788 | } |
Eric Holmberg | b5b08e5 | 2012-01-20 14:19:00 -0700 | [diff] [blame] | 1789 | bam_rx_pool_len = 0; |
Eric Holmberg | 8df0cdb | 2012-01-04 17:40:46 -0700 | [diff] [blame] | 1790 | mutex_unlock(&bam_rx_pool_mutexlock); |
Eric Holmberg | 878923a | 2012-01-10 14:28:19 -0700 | [diff] [blame] | 1791 | |
Jeff Hugo | 0b13a35 | 2012-03-17 23:18:30 -0600 | [diff] [blame] | 1792 | if (disconnect_ack) |
| 1793 | toggle_apps_ack(); |
| 1794 | |
Eric Holmberg | 878923a | 2012-01-10 14:28:19 -0700 | [diff] [blame] | 1795 | verify_tx_queue_is_empty(__func__); |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 1796 | } |
| 1797 | |
| 1798 | static void vote_dfab(void) |
| 1799 | { |
Jeff Hugo | ca0caa8 | 2011-12-05 16:05:23 -0700 | [diff] [blame] | 1800 | int rc; |
| 1801 | |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 1802 | BAM_DMUX_LOG("%s\n", __func__); |
Eric Holmberg | 006057d | 2012-01-11 10:10:42 -0700 | [diff] [blame] | 1803 | mutex_lock(&dfab_status_lock); |
| 1804 | if (dfab_is_on) { |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 1805 | BAM_DMUX_LOG("%s: dfab is already on\n", __func__); |
Eric Holmberg | 006057d | 2012-01-11 10:10:42 -0700 | [diff] [blame] | 1806 | mutex_unlock(&dfab_status_lock); |
| 1807 | return; |
| 1808 | } |
Jeff Hugo | d0befde | 2012-08-09 15:32:49 -0600 | [diff] [blame] | 1809 | if (dfab_clk) { |
| 1810 | rc = clk_prepare_enable(dfab_clk); |
| 1811 | if (rc) |
| 1812 | DMUX_LOG_KERR("bam_dmux vote for dfab failed rc = %d\n", |
| 1813 | rc); |
| 1814 | } |
| 1815 | if (xo_clk) { |
| 1816 | rc = clk_prepare_enable(xo_clk); |
| 1817 | if (rc) |
| 1818 | DMUX_LOG_KERR("bam_dmux vote for xo failed rc = %d\n", |
| 1819 | rc); |
| 1820 | } |
Eric Holmberg | 006057d | 2012-01-11 10:10:42 -0700 | [diff] [blame] | 1821 | dfab_is_on = 1; |
| 1822 | mutex_unlock(&dfab_status_lock); |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 1823 | } |
| 1824 | |
| 1825 | static void unvote_dfab(void) |
| 1826 | { |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 1827 | BAM_DMUX_LOG("%s\n", __func__); |
Eric Holmberg | 006057d | 2012-01-11 10:10:42 -0700 | [diff] [blame] | 1828 | mutex_lock(&dfab_status_lock); |
| 1829 | if (!dfab_is_on) { |
| 1830 | DMUX_LOG_KERR("%s: dfab is already off\n", __func__); |
| 1831 | dump_stack(); |
| 1832 | mutex_unlock(&dfab_status_lock); |
| 1833 | return; |
| 1834 | } |
Jeff Hugo | d0befde | 2012-08-09 15:32:49 -0600 | [diff] [blame] | 1835 | if (dfab_clk) |
| 1836 | clk_disable_unprepare(dfab_clk); |
| 1837 | if (xo_clk) |
| 1838 | clk_disable_unprepare(xo_clk); |
Eric Holmberg | 006057d | 2012-01-11 10:10:42 -0700 | [diff] [blame] | 1839 | dfab_is_on = 0; |
| 1840 | mutex_unlock(&dfab_status_lock); |
| 1841 | } |
| 1842 | |
| 1843 | /* reference counting wrapper around wakelock */ |
| 1844 | static void grab_wakelock(void) |
| 1845 | { |
| 1846 | unsigned long flags; |
| 1847 | |
| 1848 | spin_lock_irqsave(&wakelock_reference_lock, flags); |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 1849 | BAM_DMUX_LOG("%s: ref count = %d\n", __func__, |
Eric Holmberg | 006057d | 2012-01-11 10:10:42 -0700 | [diff] [blame] | 1850 | wakelock_reference_count); |
| 1851 | if (wakelock_reference_count == 0) |
| 1852 | wake_lock(&bam_wakelock); |
| 1853 | ++wakelock_reference_count; |
| 1854 | spin_unlock_irqrestore(&wakelock_reference_lock, flags); |
| 1855 | } |
| 1856 | |
| 1857 | static void release_wakelock(void) |
| 1858 | { |
| 1859 | unsigned long flags; |
| 1860 | |
| 1861 | spin_lock_irqsave(&wakelock_reference_lock, flags); |
| 1862 | if (wakelock_reference_count == 0) { |
| 1863 | DMUX_LOG_KERR("%s: bam_dmux wakelock not locked\n", __func__); |
| 1864 | dump_stack(); |
| 1865 | spin_unlock_irqrestore(&wakelock_reference_lock, flags); |
| 1866 | return; |
| 1867 | } |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 1868 | BAM_DMUX_LOG("%s: ref count = %d\n", __func__, |
Eric Holmberg | 006057d | 2012-01-11 10:10:42 -0700 | [diff] [blame] | 1869 | wakelock_reference_count); |
| 1870 | --wakelock_reference_count; |
| 1871 | if (wakelock_reference_count == 0) |
| 1872 | wake_unlock(&bam_wakelock); |
| 1873 | spin_unlock_irqrestore(&wakelock_reference_lock, flags); |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 1874 | } |
| 1875 | |
Jeff Hugo | 6e7a92a | 2011-10-24 05:25:13 -0600 | [diff] [blame] | 1876 | static int restart_notifier_cb(struct notifier_block *this, |
| 1877 | unsigned long code, |
| 1878 | void *data) |
| 1879 | { |
| 1880 | int i; |
| 1881 | struct list_head *node; |
| 1882 | struct tx_pkt_info *info; |
| 1883 | int temp_remote_status; |
Jeff Hugo | 626303bf | 2011-11-21 11:43:28 -0700 | [diff] [blame] | 1884 | unsigned long flags; |
Jeff Hugo | 6e7a92a | 2011-10-24 05:25:13 -0600 | [diff] [blame] | 1885 | |
Jeff Hugo | a82a95c | 2012-12-14 17:56:19 -0700 | [diff] [blame] | 1886 | /* |
| 1887 | * Bam_dmux counts on the fact that the BEFORE_SHUTDOWN level of |
| 1888 | * notifications are guarenteed to execute before the AFTER_SHUTDOWN |
| 1889 | * level of notifications, and that BEFORE_SHUTDOWN always occurs in |
| 1890 | * all SSR events, no matter what triggered the SSR. Also, bam_dmux |
| 1891 | * assumes that SMD does its SSR processing in the AFTER_SHUTDOWN level |
| 1892 | * thus bam_dmux is guarenteed to detect SSR before SMD, since the |
| 1893 | * callbacks for all the drivers within the AFTER_SHUTDOWN level could |
| 1894 | * occur in any order. Bam_dmux uses this knowledge to skip accessing |
| 1895 | * the bam hardware when disconnect_to_bam() is triggered by SMD's SSR |
| 1896 | * processing. We do not wat to access the bam hardware during SSR |
| 1897 | * because a watchdog crash from a bus stall would likely occur. |
| 1898 | */ |
Jeff Hugo | 199294b | 2013-02-25 13:46:56 -0700 | [diff] [blame] | 1899 | if (code == SUBSYS_BEFORE_SHUTDOWN) { |
| 1900 | in_global_reset = 1; |
Jeff Hugo | a82a95c | 2012-12-14 17:56:19 -0700 | [diff] [blame] | 1901 | in_ssr = 1; |
Zaheerulla Meer | f800bba | 2013-02-13 15:49:14 +0530 | [diff] [blame] | 1902 | BAM_DMUX_LOG("%s: begin\n", __func__); |
Jeff Hugo | 199294b | 2013-02-25 13:46:56 -0700 | [diff] [blame] | 1903 | flush_workqueue(bam_mux_rx_workqueue); |
| 1904 | } |
Jeff Hugo | 6e7a92a | 2011-10-24 05:25:13 -0600 | [diff] [blame] | 1905 | if (code != SUBSYS_AFTER_SHUTDOWN) |
| 1906 | return NOTIFY_DONE; |
| 1907 | |
Eric Holmberg | 454d9da | 2012-01-12 09:37:14 -0700 | [diff] [blame] | 1908 | /* Handle uplink Powerdown */ |
| 1909 | write_lock_irqsave(&ul_wakeup_lock, flags); |
| 1910 | if (bam_is_connected) { |
| 1911 | ul_powerdown(); |
| 1912 | wait_for_ack = 0; |
| 1913 | } |
Jeff Hugo | 4838f41 | 2012-01-20 11:19:37 -0700 | [diff] [blame] | 1914 | /* |
| 1915 | * if modem crash during ul_wakeup(), power_vote is 1, needs to be |
| 1916 | * reset to 0. harmless if bam_is_connected check above passes |
| 1917 | */ |
| 1918 | power_vote(0); |
Eric Holmberg | 454d9da | 2012-01-12 09:37:14 -0700 | [diff] [blame] | 1919 | write_unlock_irqrestore(&ul_wakeup_lock, flags); |
| 1920 | ul_powerdown_finish(); |
Eric Holmberg | 006057d | 2012-01-11 10:10:42 -0700 | [diff] [blame] | 1921 | a2_pc_disabled = 0; |
Jeff Hugo | 583a6da | 2012-02-03 11:37:30 -0700 | [diff] [blame] | 1922 | a2_pc_disabled_wakelock_skipped = 0; |
Jeff Hugo | f62029d | 2012-07-17 13:39:53 -0600 | [diff] [blame] | 1923 | disconnect_ack = 1; |
Eric Holmberg | 454d9da | 2012-01-12 09:37:14 -0700 | [diff] [blame] | 1924 | |
| 1925 | /* Cleanup Channel States */ |
Eric Holmberg | a623da8 | 2012-07-12 09:37:09 -0600 | [diff] [blame] | 1926 | mutex_lock(&bam_pdev_mutexlock); |
Jeff Hugo | 6e7a92a | 2011-10-24 05:25:13 -0600 | [diff] [blame] | 1927 | for (i = 0; i < BAM_DMUX_NUM_CHANNELS; ++i) { |
| 1928 | temp_remote_status = bam_ch_is_remote_open(i); |
| 1929 | bam_ch[i].status &= ~BAM_CH_REMOTE_OPEN; |
Karthikeyan Ramasubramanian | 7bf5ca8 | 2011-11-21 13:33:19 -0700 | [diff] [blame] | 1930 | bam_ch[i].num_tx_pkts = 0; |
Jeff Hugo | 6e7a92a | 2011-10-24 05:25:13 -0600 | [diff] [blame] | 1931 | if (bam_ch_is_local_open(i)) |
| 1932 | bam_ch[i].status |= BAM_CH_IN_RESET; |
| 1933 | if (temp_remote_status) { |
| 1934 | platform_device_unregister(bam_ch[i].pdev); |
| 1935 | bam_ch[i].pdev = platform_device_alloc( |
| 1936 | bam_ch[i].name, 2); |
| 1937 | } |
| 1938 | } |
Eric Holmberg | a623da8 | 2012-07-12 09:37:09 -0600 | [diff] [blame] | 1939 | mutex_unlock(&bam_pdev_mutexlock); |
Eric Holmberg | 454d9da | 2012-01-12 09:37:14 -0700 | [diff] [blame] | 1940 | |
| 1941 | /* Cleanup pending UL data */ |
Jeff Hugo | 626303bf | 2011-11-21 11:43:28 -0700 | [diff] [blame] | 1942 | spin_lock_irqsave(&bam_tx_pool_spinlock, flags); |
Jeff Hugo | 6e7a92a | 2011-10-24 05:25:13 -0600 | [diff] [blame] | 1943 | while (!list_empty(&bam_tx_pool)) { |
| 1944 | node = bam_tx_pool.next; |
| 1945 | list_del(node); |
| 1946 | info = container_of(node, struct tx_pkt_info, |
| 1947 | list_node); |
| 1948 | if (!info->is_cmd) { |
| 1949 | dma_unmap_single(NULL, info->dma_address, |
| 1950 | info->skb->len, |
| 1951 | DMA_TO_DEVICE); |
| 1952 | dev_kfree_skb_any(info->skb); |
| 1953 | } else { |
| 1954 | dma_unmap_single(NULL, info->dma_address, |
| 1955 | info->len, |
| 1956 | DMA_TO_DEVICE); |
| 1957 | kfree(info->skb); |
| 1958 | } |
| 1959 | kfree(info); |
| 1960 | } |
Jeff Hugo | 626303bf | 2011-11-21 11:43:28 -0700 | [diff] [blame] | 1961 | spin_unlock_irqrestore(&bam_tx_pool_spinlock, flags); |
Eric Holmberg | 454d9da | 2012-01-12 09:37:14 -0700 | [diff] [blame] | 1962 | |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 1963 | BAM_DMUX_LOG("%s: complete\n", __func__); |
Jeff Hugo | 6e7a92a | 2011-10-24 05:25:13 -0600 | [diff] [blame] | 1964 | return NOTIFY_DONE; |
| 1965 | } |
| 1966 | |
Jeff Hugo | 9dea05c | 2011-12-21 12:23:05 -0700 | [diff] [blame] | 1967 | static int bam_init(void) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1968 | { |
| 1969 | u32 h; |
| 1970 | dma_addr_t dma_addr; |
| 1971 | int ret; |
| 1972 | void *a2_virt_addr; |
Jeff Hugo | 4b2890d | 2012-01-16 16:14:21 -0700 | [diff] [blame] | 1973 | int skip_iounmap = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1974 | |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 1975 | vote_dfab(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1976 | /* init BAM */ |
Jeff Hugo | 3910ee1 | 2012-08-21 14:08:20 -0600 | [diff] [blame] | 1977 | a2_virt_addr = ioremap_nocache((unsigned long)(a2_phys_base), |
| 1978 | a2_phys_size); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1979 | if (!a2_virt_addr) { |
| 1980 | pr_err("%s: ioremap failed\n", __func__); |
| 1981 | ret = -ENOMEM; |
Jeff Hugo | 994a92d | 2012-01-05 13:25:21 -0700 | [diff] [blame] | 1982 | goto ioremap_failed; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1983 | } |
Jeff Hugo | 3910ee1 | 2012-08-21 14:08:20 -0600 | [diff] [blame] | 1984 | a2_props.phys_addr = (u32)(a2_phys_base); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1985 | a2_props.virt_addr = a2_virt_addr; |
Jeff Hugo | 3910ee1 | 2012-08-21 14:08:20 -0600 | [diff] [blame] | 1986 | a2_props.virt_size = a2_phys_size; |
| 1987 | a2_props.irq = a2_bam_irq; |
Jeff Hugo | 927cba6 | 2011-11-11 11:49:52 -0700 | [diff] [blame] | 1988 | a2_props.options = SPS_BAM_OPT_IRQ_WAKEUP; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1989 | a2_props.num_pipes = A2_NUM_PIPES; |
| 1990 | a2_props.summing_threshold = A2_SUMMING_THRESHOLD; |
Jeff Hugo | 75913c8 | 2011-12-05 15:59:01 -0700 | [diff] [blame] | 1991 | if (cpu_is_msm9615()) |
| 1992 | a2_props.manage = SPS_BAM_MGR_DEVICE_REMOTE; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1993 | /* need to free on tear down */ |
| 1994 | ret = sps_register_bam_device(&a2_props, &h); |
| 1995 | if (ret < 0) { |
| 1996 | pr_err("%s: register bam error %d\n", __func__, ret); |
| 1997 | goto register_bam_failed; |
| 1998 | } |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 1999 | a2_device_handle = h; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2000 | |
| 2001 | bam_tx_pipe = sps_alloc_endpoint(); |
| 2002 | if (bam_tx_pipe == NULL) { |
| 2003 | pr_err("%s: tx alloc endpoint failed\n", __func__); |
| 2004 | ret = -ENOMEM; |
Jeff Hugo | 8ff4a81 | 2012-01-17 11:03:13 -0700 | [diff] [blame] | 2005 | goto tx_alloc_endpoint_failed; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2006 | } |
| 2007 | ret = sps_get_config(bam_tx_pipe, &tx_connection); |
| 2008 | if (ret) { |
| 2009 | pr_err("%s: tx get config failed %d\n", __func__, ret); |
| 2010 | goto tx_get_config_failed; |
| 2011 | } |
| 2012 | |
| 2013 | tx_connection.source = SPS_DEV_HANDLE_MEM; |
| 2014 | tx_connection.src_pipe_index = 0; |
| 2015 | tx_connection.destination = h; |
| 2016 | tx_connection.dest_pipe_index = 4; |
| 2017 | tx_connection.mode = SPS_MODE_DEST; |
| 2018 | tx_connection.options = SPS_O_AUTO_ENABLE | SPS_O_EOT; |
| 2019 | tx_desc_mem_buf.size = 0x800; /* 2k */ |
| 2020 | tx_desc_mem_buf.base = dma_alloc_coherent(NULL, tx_desc_mem_buf.size, |
| 2021 | &dma_addr, 0); |
| 2022 | if (tx_desc_mem_buf.base == NULL) { |
| 2023 | pr_err("%s: tx memory alloc failed\n", __func__); |
| 2024 | ret = -ENOMEM; |
Jeff Hugo | 8ff4a81 | 2012-01-17 11:03:13 -0700 | [diff] [blame] | 2025 | goto tx_get_config_failed; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2026 | } |
| 2027 | tx_desc_mem_buf.phys_base = dma_addr; |
| 2028 | memset(tx_desc_mem_buf.base, 0x0, tx_desc_mem_buf.size); |
| 2029 | tx_connection.desc = tx_desc_mem_buf; |
| 2030 | tx_connection.event_thresh = 0x10; |
| 2031 | |
| 2032 | ret = sps_connect(bam_tx_pipe, &tx_connection); |
| 2033 | if (ret < 0) { |
| 2034 | pr_err("%s: tx connect error %d\n", __func__, ret); |
| 2035 | goto tx_connect_failed; |
| 2036 | } |
| 2037 | |
| 2038 | bam_rx_pipe = sps_alloc_endpoint(); |
| 2039 | if (bam_rx_pipe == NULL) { |
| 2040 | pr_err("%s: rx alloc endpoint failed\n", __func__); |
| 2041 | ret = -ENOMEM; |
Jeff Hugo | 8ff4a81 | 2012-01-17 11:03:13 -0700 | [diff] [blame] | 2042 | goto rx_alloc_endpoint_failed; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2043 | } |
| 2044 | ret = sps_get_config(bam_rx_pipe, &rx_connection); |
| 2045 | if (ret) { |
| 2046 | pr_err("%s: rx get config failed %d\n", __func__, ret); |
| 2047 | goto rx_get_config_failed; |
| 2048 | } |
| 2049 | |
| 2050 | rx_connection.source = h; |
| 2051 | rx_connection.src_pipe_index = 5; |
| 2052 | rx_connection.destination = SPS_DEV_HANDLE_MEM; |
| 2053 | rx_connection.dest_pipe_index = 1; |
| 2054 | rx_connection.mode = SPS_MODE_SRC; |
Jeff Hugo | 949080a | 2011-08-30 11:58:56 -0600 | [diff] [blame] | 2055 | rx_connection.options = SPS_O_AUTO_ENABLE | SPS_O_EOT | |
| 2056 | SPS_O_ACK_TRANSFERS; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2057 | rx_desc_mem_buf.size = 0x800; /* 2k */ |
| 2058 | rx_desc_mem_buf.base = dma_alloc_coherent(NULL, rx_desc_mem_buf.size, |
| 2059 | &dma_addr, 0); |
| 2060 | if (rx_desc_mem_buf.base == NULL) { |
| 2061 | pr_err("%s: rx memory alloc failed\n", __func__); |
| 2062 | ret = -ENOMEM; |
| 2063 | goto rx_mem_failed; |
| 2064 | } |
| 2065 | rx_desc_mem_buf.phys_base = dma_addr; |
| 2066 | memset(rx_desc_mem_buf.base, 0x0, rx_desc_mem_buf.size); |
| 2067 | rx_connection.desc = rx_desc_mem_buf; |
| 2068 | rx_connection.event_thresh = 0x10; |
| 2069 | |
| 2070 | ret = sps_connect(bam_rx_pipe, &rx_connection); |
| 2071 | if (ret < 0) { |
| 2072 | pr_err("%s: rx connect error %d\n", __func__, ret); |
| 2073 | goto rx_connect_failed; |
| 2074 | } |
| 2075 | |
| 2076 | tx_register_event.options = SPS_O_EOT; |
| 2077 | tx_register_event.mode = SPS_TRIGGER_CALLBACK; |
| 2078 | tx_register_event.xfer_done = NULL; |
| 2079 | tx_register_event.callback = bam_mux_tx_notify; |
| 2080 | tx_register_event.user = NULL; |
| 2081 | ret = sps_register_event(bam_tx_pipe, &tx_register_event); |
| 2082 | if (ret < 0) { |
| 2083 | pr_err("%s: tx register event error %d\n", __func__, ret); |
| 2084 | goto rx_event_reg_failed; |
| 2085 | } |
| 2086 | |
Jeff Hugo | 33dbc00 | 2011-08-25 15:52:53 -0600 | [diff] [blame] | 2087 | rx_register_event.options = SPS_O_EOT; |
| 2088 | rx_register_event.mode = SPS_TRIGGER_CALLBACK; |
| 2089 | rx_register_event.xfer_done = NULL; |
| 2090 | rx_register_event.callback = bam_mux_rx_notify; |
| 2091 | rx_register_event.user = NULL; |
| 2092 | ret = sps_register_event(bam_rx_pipe, &rx_register_event); |
| 2093 | if (ret < 0) { |
| 2094 | pr_err("%s: tx register event error %d\n", __func__, ret); |
| 2095 | goto rx_event_reg_failed; |
| 2096 | } |
| 2097 | |
Jeff Hugo | c269614 | 2012-05-03 11:42:13 -0600 | [diff] [blame] | 2098 | mutex_lock(&delayed_ul_vote_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2099 | bam_mux_initialized = 1; |
Jeff Hugo | c269614 | 2012-05-03 11:42:13 -0600 | [diff] [blame] | 2100 | if (need_delayed_ul_vote) { |
| 2101 | need_delayed_ul_vote = 0; |
| 2102 | msm_bam_dmux_kickoff_ul_wakeup(); |
| 2103 | } |
| 2104 | mutex_unlock(&delayed_ul_vote_lock); |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 2105 | toggle_apps_ack(); |
Jeff Hugo | 6e7a92a | 2011-10-24 05:25:13 -0600 | [diff] [blame] | 2106 | bam_connection_is_active = 1; |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 2107 | complete_all(&bam_connection_completion); |
Jeff Hugo | 2fb555e | 2012-03-14 16:33:47 -0600 | [diff] [blame] | 2108 | queue_rx(); |
Jeff Hugo | 9dea05c | 2011-12-21 12:23:05 -0700 | [diff] [blame] | 2109 | return 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2110 | |
| 2111 | rx_event_reg_failed: |
| 2112 | sps_disconnect(bam_rx_pipe); |
| 2113 | rx_connect_failed: |
| 2114 | dma_free_coherent(NULL, rx_desc_mem_buf.size, rx_desc_mem_buf.base, |
| 2115 | rx_desc_mem_buf.phys_base); |
| 2116 | rx_mem_failed: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2117 | rx_get_config_failed: |
| 2118 | sps_free_endpoint(bam_rx_pipe); |
Jeff Hugo | 8ff4a81 | 2012-01-17 11:03:13 -0700 | [diff] [blame] | 2119 | rx_alloc_endpoint_failed: |
| 2120 | sps_disconnect(bam_tx_pipe); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2121 | tx_connect_failed: |
| 2122 | dma_free_coherent(NULL, tx_desc_mem_buf.size, tx_desc_mem_buf.base, |
| 2123 | tx_desc_mem_buf.phys_base); |
| 2124 | tx_get_config_failed: |
| 2125 | sps_free_endpoint(bam_tx_pipe); |
Jeff Hugo | 8ff4a81 | 2012-01-17 11:03:13 -0700 | [diff] [blame] | 2126 | tx_alloc_endpoint_failed: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2127 | sps_deregister_bam_device(h); |
Jeff Hugo | 4b2890d | 2012-01-16 16:14:21 -0700 | [diff] [blame] | 2128 | /* |
| 2129 | * sps_deregister_bam_device() calls iounmap. calling iounmap on the |
| 2130 | * same handle below will cause a crash, so skip it if we've freed |
| 2131 | * the handle here. |
| 2132 | */ |
| 2133 | skip_iounmap = 1; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2134 | register_bam_failed: |
Jeff Hugo | 4b2890d | 2012-01-16 16:14:21 -0700 | [diff] [blame] | 2135 | if (!skip_iounmap) |
| 2136 | iounmap(a2_virt_addr); |
Jeff Hugo | 994a92d | 2012-01-05 13:25:21 -0700 | [diff] [blame] | 2137 | ioremap_failed: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2138 | /*destroy_workqueue(bam_mux_workqueue);*/ |
Jeff Hugo | 9dea05c | 2011-12-21 12:23:05 -0700 | [diff] [blame] | 2139 | return ret; |
| 2140 | } |
| 2141 | |
| 2142 | static int bam_init_fallback(void) |
| 2143 | { |
| 2144 | u32 h; |
| 2145 | int ret; |
| 2146 | void *a2_virt_addr; |
| 2147 | |
Jeff Hugo | 9dea05c | 2011-12-21 12:23:05 -0700 | [diff] [blame] | 2148 | /* init BAM */ |
Jeff Hugo | 3910ee1 | 2012-08-21 14:08:20 -0600 | [diff] [blame] | 2149 | a2_virt_addr = ioremap_nocache((unsigned long)(a2_phys_base), |
| 2150 | a2_phys_size); |
Jeff Hugo | 9dea05c | 2011-12-21 12:23:05 -0700 | [diff] [blame] | 2151 | if (!a2_virt_addr) { |
| 2152 | pr_err("%s: ioremap failed\n", __func__); |
| 2153 | ret = -ENOMEM; |
| 2154 | goto ioremap_failed; |
| 2155 | } |
Jeff Hugo | 3910ee1 | 2012-08-21 14:08:20 -0600 | [diff] [blame] | 2156 | a2_props.phys_addr = (u32)(a2_phys_base); |
Jeff Hugo | 9dea05c | 2011-12-21 12:23:05 -0700 | [diff] [blame] | 2157 | a2_props.virt_addr = a2_virt_addr; |
Jeff Hugo | 3910ee1 | 2012-08-21 14:08:20 -0600 | [diff] [blame] | 2158 | a2_props.virt_size = a2_phys_size; |
| 2159 | a2_props.irq = a2_bam_irq; |
Jeff Hugo | 9dea05c | 2011-12-21 12:23:05 -0700 | [diff] [blame] | 2160 | a2_props.options = SPS_BAM_OPT_IRQ_WAKEUP; |
| 2161 | a2_props.num_pipes = A2_NUM_PIPES; |
| 2162 | a2_props.summing_threshold = A2_SUMMING_THRESHOLD; |
| 2163 | if (cpu_is_msm9615()) |
| 2164 | a2_props.manage = SPS_BAM_MGR_DEVICE_REMOTE; |
| 2165 | ret = sps_register_bam_device(&a2_props, &h); |
| 2166 | if (ret < 0) { |
| 2167 | pr_err("%s: register bam error %d\n", __func__, ret); |
| 2168 | goto register_bam_failed; |
| 2169 | } |
| 2170 | a2_device_handle = h; |
Jeff Hugo | c269614 | 2012-05-03 11:42:13 -0600 | [diff] [blame] | 2171 | |
| 2172 | mutex_lock(&delayed_ul_vote_lock); |
| 2173 | bam_mux_initialized = 1; |
| 2174 | if (need_delayed_ul_vote) { |
| 2175 | need_delayed_ul_vote = 0; |
| 2176 | msm_bam_dmux_kickoff_ul_wakeup(); |
| 2177 | } |
| 2178 | mutex_unlock(&delayed_ul_vote_lock); |
Jeff Hugo | 2bec977 | 2012-04-05 12:25:16 -0600 | [diff] [blame] | 2179 | toggle_apps_ack(); |
Jeff Hugo | 9dea05c | 2011-12-21 12:23:05 -0700 | [diff] [blame] | 2180 | |
Jeff Hugo | 18792a3 | 2012-06-20 15:25:55 -0600 | [diff] [blame] | 2181 | power_management_only_mode = 1; |
| 2182 | bam_connection_is_active = 1; |
| 2183 | complete_all(&bam_connection_completion); |
| 2184 | |
Jeff Hugo | 9dea05c | 2011-12-21 12:23:05 -0700 | [diff] [blame] | 2185 | return 0; |
| 2186 | |
| 2187 | register_bam_failed: |
Jeff Hugo | 4b2890d | 2012-01-16 16:14:21 -0700 | [diff] [blame] | 2188 | iounmap(a2_virt_addr); |
Jeff Hugo | 9dea05c | 2011-12-21 12:23:05 -0700 | [diff] [blame] | 2189 | ioremap_failed: |
| 2190 | return ret; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2191 | } |
Jeff Hugo | ade1f84 | 2011-08-03 15:53:59 -0600 | [diff] [blame] | 2192 | |
Jeff Hugo | a670b76 | 2012-03-15 15:58:28 -0600 | [diff] [blame] | 2193 | static void msm9615_bam_init(void) |
Eric Holmberg | 604ab25 | 2012-01-15 00:01:18 -0700 | [diff] [blame] | 2194 | { |
| 2195 | int ret = 0; |
| 2196 | |
| 2197 | ret = bam_init(); |
| 2198 | if (ret) { |
| 2199 | ret = bam_init_fallback(); |
| 2200 | if (ret) |
| 2201 | pr_err("%s: bam init fallback failed: %d", |
| 2202 | __func__, ret); |
| 2203 | } |
| 2204 | } |
| 2205 | |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 2206 | static void toggle_apps_ack(void) |
| 2207 | { |
| 2208 | static unsigned int clear_bit; /* 0 = set the bit, else clear bit */ |
Eric Holmberg | 878923a | 2012-01-10 14:28:19 -0700 | [diff] [blame] | 2209 | |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 2210 | BAM_DMUX_LOG("%s: apps ack %d->%d\n", __func__, |
Eric Holmberg | 878923a | 2012-01-10 14:28:19 -0700 | [diff] [blame] | 2211 | clear_bit & 0x1, ~clear_bit & 0x1); |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 2212 | smsm_change_state(SMSM_APPS_STATE, |
| 2213 | clear_bit & SMSM_A2_POWER_CONTROL_ACK, |
| 2214 | ~clear_bit & SMSM_A2_POWER_CONTROL_ACK); |
| 2215 | clear_bit = ~clear_bit; |
Eric Holmberg | 1f1255d | 2012-02-22 13:37:21 -0700 | [diff] [blame] | 2216 | DBG_INC_ACK_OUT_CNT(); |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 2217 | } |
| 2218 | |
Jeff Hugo | ade1f84 | 2011-08-03 15:53:59 -0600 | [diff] [blame] | 2219 | static void bam_dmux_smsm_cb(void *priv, uint32_t old_state, uint32_t new_state) |
| 2220 | { |
Jeff Hugo | 4b7c7b3 | 2012-04-18 16:25:14 -0600 | [diff] [blame] | 2221 | static int last_processed_state; |
| 2222 | |
| 2223 | mutex_lock(&smsm_cb_lock); |
Eric Holmberg | 878923a | 2012-01-10 14:28:19 -0700 | [diff] [blame] | 2224 | bam_dmux_power_state = new_state & SMSM_A2_POWER_CONTROL ? 1 : 0; |
Eric Holmberg | 1f1255d | 2012-02-22 13:37:21 -0700 | [diff] [blame] | 2225 | DBG_INC_A2_POWER_CONTROL_IN_CNT(); |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 2226 | BAM_DMUX_LOG("%s: 0x%08x -> 0x%08x\n", __func__, old_state, |
Eric Holmberg | 878923a | 2012-01-10 14:28:19 -0700 | [diff] [blame] | 2227 | new_state); |
Jeff Hugo | 4b7c7b3 | 2012-04-18 16:25:14 -0600 | [diff] [blame] | 2228 | if (last_processed_state == (new_state & SMSM_A2_POWER_CONTROL)) { |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 2229 | BAM_DMUX_LOG("%s: already processed this state\n", __func__); |
Jeff Hugo | 4b7c7b3 | 2012-04-18 16:25:14 -0600 | [diff] [blame] | 2230 | mutex_unlock(&smsm_cb_lock); |
| 2231 | return; |
| 2232 | } |
| 2233 | |
| 2234 | last_processed_state = new_state & SMSM_A2_POWER_CONTROL; |
Eric Holmberg | 878923a | 2012-01-10 14:28:19 -0700 | [diff] [blame] | 2235 | |
Jeff Hugo | ae3a85e | 2011-12-02 17:10:18 -0700 | [diff] [blame] | 2236 | if (bam_mux_initialized && new_state & SMSM_A2_POWER_CONTROL) { |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 2237 | BAM_DMUX_LOG("%s: reconnect\n", __func__); |
Eric Holmberg | 006057d | 2012-01-11 10:10:42 -0700 | [diff] [blame] | 2238 | grab_wakelock(); |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 2239 | reconnect_to_bam(); |
Jeff Hugo | ae3a85e | 2011-12-02 17:10:18 -0700 | [diff] [blame] | 2240 | } else if (bam_mux_initialized && |
| 2241 | !(new_state & SMSM_A2_POWER_CONTROL)) { |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 2242 | BAM_DMUX_LOG("%s: disconnect\n", __func__); |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 2243 | disconnect_to_bam(); |
Eric Holmberg | 006057d | 2012-01-11 10:10:42 -0700 | [diff] [blame] | 2244 | release_wakelock(); |
Jeff Hugo | ae3a85e | 2011-12-02 17:10:18 -0700 | [diff] [blame] | 2245 | } else if (new_state & SMSM_A2_POWER_CONTROL) { |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 2246 | BAM_DMUX_LOG("%s: init\n", __func__); |
Eric Holmberg | 006057d | 2012-01-11 10:10:42 -0700 | [diff] [blame] | 2247 | grab_wakelock(); |
Jeff Hugo | a670b76 | 2012-03-15 15:58:28 -0600 | [diff] [blame] | 2248 | if (cpu_is_msm9615()) |
| 2249 | msm9615_bam_init(); |
| 2250 | else |
Eric Holmberg | 604ab25 | 2012-01-15 00:01:18 -0700 | [diff] [blame] | 2251 | bam_init(); |
Jeff Hugo | ae3a85e | 2011-12-02 17:10:18 -0700 | [diff] [blame] | 2252 | } else { |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 2253 | BAM_DMUX_LOG("%s: bad state change\n", __func__); |
Jeff Hugo | ade1f84 | 2011-08-03 15:53:59 -0600 | [diff] [blame] | 2254 | pr_err("%s: unsupported state change\n", __func__); |
Jeff Hugo | ae3a85e | 2011-12-02 17:10:18 -0700 | [diff] [blame] | 2255 | } |
Jeff Hugo | 4b7c7b3 | 2012-04-18 16:25:14 -0600 | [diff] [blame] | 2256 | mutex_unlock(&smsm_cb_lock); |
Jeff Hugo | ade1f84 | 2011-08-03 15:53:59 -0600 | [diff] [blame] | 2257 | |
| 2258 | } |
| 2259 | |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 2260 | static void bam_dmux_smsm_ack_cb(void *priv, uint32_t old_state, |
| 2261 | uint32_t new_state) |
| 2262 | { |
Eric Holmberg | 1f1255d | 2012-02-22 13:37:21 -0700 | [diff] [blame] | 2263 | DBG_INC_ACK_IN_CNT(); |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 2264 | BAM_DMUX_LOG("%s: 0x%08x -> 0x%08x\n", __func__, old_state, |
Eric Holmberg | 878923a | 2012-01-10 14:28:19 -0700 | [diff] [blame] | 2265 | new_state); |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 2266 | complete_all(&ul_wakeup_ack_completion); |
| 2267 | } |
| 2268 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2269 | static int bam_dmux_probe(struct platform_device *pdev) |
| 2270 | { |
| 2271 | int rc; |
Jeff Hugo | 3910ee1 | 2012-08-21 14:08:20 -0600 | [diff] [blame] | 2272 | struct resource *r; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2273 | |
| 2274 | DBG("%s probe called\n", __func__); |
| 2275 | if (bam_mux_initialized) |
| 2276 | return 0; |
| 2277 | |
Jeff Hugo | 3910ee1 | 2012-08-21 14:08:20 -0600 | [diff] [blame] | 2278 | if (pdev->dev.of_node) { |
| 2279 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 2280 | if (!r) { |
| 2281 | pr_err("%s: reg field missing\n", __func__); |
| 2282 | return -ENODEV; |
| 2283 | } |
| 2284 | a2_phys_base = (void *)(r->start); |
| 2285 | a2_phys_size = (uint32_t)(resource_size(r)); |
| 2286 | a2_bam_irq = platform_get_irq(pdev, 0); |
| 2287 | if (a2_bam_irq == -ENXIO) { |
| 2288 | pr_err("%s: irq field missing\n", __func__); |
| 2289 | return -ENODEV; |
| 2290 | } |
| 2291 | DBG("%s: base:%p size:%x irq:%d\n", __func__, |
| 2292 | a2_phys_base, |
| 2293 | a2_phys_size, |
| 2294 | a2_bam_irq); |
| 2295 | } else { /* fallback to default init data */ |
| 2296 | a2_phys_base = (void *)(A2_PHYS_BASE); |
| 2297 | a2_phys_size = A2_PHYS_SIZE; |
| 2298 | a2_bam_irq = A2_BAM_IRQ; |
| 2299 | } |
| 2300 | |
Stephen Boyd | 69d35e3 | 2012-02-14 15:33:30 -0800 | [diff] [blame] | 2301 | xo_clk = clk_get(&pdev->dev, "xo"); |
| 2302 | if (IS_ERR(xo_clk)) { |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 2303 | BAM_DMUX_LOG("%s: did not get xo clock\n", __func__); |
Jeff Hugo | d0befde | 2012-08-09 15:32:49 -0600 | [diff] [blame] | 2304 | xo_clk = NULL; |
Stephen Boyd | 69d35e3 | 2012-02-14 15:33:30 -0800 | [diff] [blame] | 2305 | } |
Stephen Boyd | 1c51a49 | 2011-10-26 12:11:47 -0700 | [diff] [blame] | 2306 | dfab_clk = clk_get(&pdev->dev, "bus_clk"); |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 2307 | if (IS_ERR(dfab_clk)) { |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 2308 | BAM_DMUX_LOG("%s: did not get dfab clock\n", __func__); |
Jeff Hugo | d0befde | 2012-08-09 15:32:49 -0600 | [diff] [blame] | 2309 | dfab_clk = NULL; |
| 2310 | } else { |
| 2311 | rc = clk_set_rate(dfab_clk, 64000000); |
| 2312 | if (rc) |
| 2313 | pr_err("%s: unable to set dfab clock rate\n", __func__); |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 2314 | } |
| 2315 | |
Jeff Hugo | fff43af9 | 2012-03-29 17:54:52 -0600 | [diff] [blame] | 2316 | /* |
| 2317 | * setup the workqueue so that it can be pinned to core 0 and not |
| 2318 | * block the watchdog pet function, so that netif_rx() in rmnet |
| 2319 | * only uses one queue. |
| 2320 | */ |
| 2321 | bam_mux_rx_workqueue = alloc_workqueue("bam_dmux_rx", |
| 2322 | WQ_MEM_RECLAIM | WQ_CPU_INTENSIVE, 1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2323 | if (!bam_mux_rx_workqueue) |
| 2324 | return -ENOMEM; |
| 2325 | |
| 2326 | bam_mux_tx_workqueue = create_singlethread_workqueue("bam_dmux_tx"); |
| 2327 | if (!bam_mux_tx_workqueue) { |
| 2328 | destroy_workqueue(bam_mux_rx_workqueue); |
| 2329 | return -ENOMEM; |
| 2330 | } |
| 2331 | |
Jeff Hugo | 7960abd | 2011-08-02 15:39:38 -0600 | [diff] [blame] | 2332 | for (rc = 0; rc < BAM_DMUX_NUM_CHANNELS; ++rc) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2333 | spin_lock_init(&bam_ch[rc].lock); |
Jeff Hugo | 7960abd | 2011-08-02 15:39:38 -0600 | [diff] [blame] | 2334 | scnprintf(bam_ch[rc].name, BAM_DMUX_CH_NAME_MAX_LEN, |
| 2335 | "bam_dmux_ch_%d", rc); |
| 2336 | /* bus 2, ie a2 stream 2 */ |
| 2337 | bam_ch[rc].pdev = platform_device_alloc(bam_ch[rc].name, 2); |
| 2338 | if (!bam_ch[rc].pdev) { |
| 2339 | pr_err("%s: platform device alloc failed\n", __func__); |
| 2340 | destroy_workqueue(bam_mux_rx_workqueue); |
| 2341 | destroy_workqueue(bam_mux_tx_workqueue); |
| 2342 | return -ENOMEM; |
| 2343 | } |
| 2344 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2345 | |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 2346 | init_completion(&ul_wakeup_ack_completion); |
| 2347 | init_completion(&bam_connection_completion); |
Eric Holmberg | 006057d | 2012-01-11 10:10:42 -0700 | [diff] [blame] | 2348 | init_completion(&dfab_unvote_completion); |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 2349 | INIT_DELAYED_WORK(&ul_timeout_work, ul_timeout); |
Jeff Hugo | 988e7ba | 2012-10-03 15:53:54 -0600 | [diff] [blame] | 2350 | INIT_DELAYED_WORK(&queue_rx_work, queue_rx_work_func); |
Jeff Hugo | ae3a85e | 2011-12-02 17:10:18 -0700 | [diff] [blame] | 2351 | wake_lock_init(&bam_wakelock, WAKE_LOCK_SUSPEND, "bam_dmux_wakelock"); |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 2352 | |
Jeff Hugo | ade1f84 | 2011-08-03 15:53:59 -0600 | [diff] [blame] | 2353 | rc = smsm_state_cb_register(SMSM_MODEM_STATE, SMSM_A2_POWER_CONTROL, |
| 2354 | bam_dmux_smsm_cb, NULL); |
| 2355 | |
| 2356 | if (rc) { |
| 2357 | destroy_workqueue(bam_mux_rx_workqueue); |
| 2358 | destroy_workqueue(bam_mux_tx_workqueue); |
| 2359 | pr_err("%s: smsm cb register failed, rc: %d\n", __func__, rc); |
| 2360 | return -ENOMEM; |
| 2361 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2362 | |
Jeff Hugo | aab7ebc | 2011-09-07 16:46:04 -0600 | [diff] [blame] | 2363 | rc = smsm_state_cb_register(SMSM_MODEM_STATE, SMSM_A2_POWER_CONTROL_ACK, |
| 2364 | bam_dmux_smsm_ack_cb, NULL); |
| 2365 | |
| 2366 | if (rc) { |
| 2367 | destroy_workqueue(bam_mux_rx_workqueue); |
| 2368 | destroy_workqueue(bam_mux_tx_workqueue); |
| 2369 | smsm_state_cb_deregister(SMSM_MODEM_STATE, |
| 2370 | SMSM_A2_POWER_CONTROL, |
| 2371 | bam_dmux_smsm_cb, NULL); |
| 2372 | pr_err("%s: smsm ack cb register failed, rc: %d\n", __func__, |
| 2373 | rc); |
| 2374 | for (rc = 0; rc < BAM_DMUX_NUM_CHANNELS; ++rc) |
| 2375 | platform_device_put(bam_ch[rc].pdev); |
| 2376 | return -ENOMEM; |
| 2377 | } |
| 2378 | |
Eric Holmberg | fd1e2ae | 2011-11-15 18:28:17 -0700 | [diff] [blame] | 2379 | if (smsm_get_state(SMSM_MODEM_STATE) & SMSM_A2_POWER_CONTROL) |
| 2380 | bam_dmux_smsm_cb(NULL, 0, smsm_get_state(SMSM_MODEM_STATE)); |
| 2381 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2382 | return 0; |
| 2383 | } |
| 2384 | |
Jeff Hugo | 3910ee1 | 2012-08-21 14:08:20 -0600 | [diff] [blame] | 2385 | static struct of_device_id msm_match_table[] = { |
| 2386 | {.compatible = "qcom,bam_dmux"}, |
| 2387 | {}, |
| 2388 | }; |
| 2389 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2390 | static struct platform_driver bam_dmux_driver = { |
| 2391 | .probe = bam_dmux_probe, |
| 2392 | .driver = { |
| 2393 | .name = "BAM_RMNT", |
| 2394 | .owner = THIS_MODULE, |
Jeff Hugo | 3910ee1 | 2012-08-21 14:08:20 -0600 | [diff] [blame] | 2395 | .of_match_table = msm_match_table, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2396 | }, |
| 2397 | }; |
| 2398 | |
| 2399 | static int __init bam_dmux_init(void) |
| 2400 | { |
| 2401 | #ifdef CONFIG_DEBUG_FS |
| 2402 | struct dentry *dent; |
| 2403 | |
| 2404 | dent = debugfs_create_dir("bam_dmux", 0); |
Eric Holmberg | 2fddbcd | 2011-11-28 18:25:57 -0700 | [diff] [blame] | 2405 | if (!IS_ERR(dent)) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2406 | debug_create("tbl", 0444, dent, debug_tbl); |
Eric Holmberg | 2fddbcd | 2011-11-28 18:25:57 -0700 | [diff] [blame] | 2407 | debug_create("ul_pkt_cnt", 0444, dent, debug_ul_pkt_cnt); |
| 2408 | debug_create("stats", 0444, dent, debug_stats); |
| 2409 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2410 | #endif |
Zaheerulla Meer | 6fbf32c | 2013-01-31 17:06:44 +0530 | [diff] [blame] | 2411 | |
| 2412 | bam_ipc_log_txt = ipc_log_context_create(BAM_IPC_LOG_PAGES, "bam_dmux"); |
| 2413 | if (!bam_ipc_log_txt) { |
| 2414 | pr_err("%s : unable to create IPC Logging Context", __func__); |
Eric Holmberg | 878923a | 2012-01-10 14:28:19 -0700 | [diff] [blame] | 2415 | } |
| 2416 | |
Anurag Singh | dcd8b4e | 2012-07-30 16:46:37 -0700 | [diff] [blame] | 2417 | rx_timer_interval = DEFAULT_POLLING_MIN_SLEEP; |
| 2418 | |
Jeff Hugo | 6e7a92a | 2011-10-24 05:25:13 -0600 | [diff] [blame] | 2419 | subsys_notif_register_notifier("modem", &restart_notifier); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2420 | return platform_driver_register(&bam_dmux_driver); |
| 2421 | } |
| 2422 | |
Jeff Hugo | ade1f84 | 2011-08-03 15:53:59 -0600 | [diff] [blame] | 2423 | late_initcall(bam_dmux_init); /* needs to init after SMD */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2424 | MODULE_DESCRIPTION("MSM BAM DMUX"); |
| 2425 | MODULE_LICENSE("GPL v2"); |