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