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