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