Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2004-2011 Atheros Communications Inc. |
| 3 | * |
| 4 | * Permission to use, copy, modify, and/or distribute this software for any |
| 5 | * purpose with or without fee is hereby granted, provided that the above |
| 6 | * copyright notice and this permission notice appear in all copies. |
| 7 | * |
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | */ |
| 16 | |
| 17 | #include <linux/mmc/card.h> |
| 18 | #include <linux/mmc/mmc.h> |
| 19 | #include <linux/mmc/host.h> |
| 20 | #include <linux/mmc/sdio_func.h> |
| 21 | #include <linux/mmc/sdio_ids.h> |
| 22 | #include <linux/mmc/sdio.h> |
| 23 | #include <linux/mmc/sd.h> |
Kalle Valo | 2e1cb23 | 2011-10-05 12:23:49 +0300 | [diff] [blame] | 24 | #include "hif.h" |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 25 | #include "hif-ops.h" |
| 26 | #include "target.h" |
| 27 | #include "debug.h" |
Vivek Natarajan | 9df337a | 2011-09-15 20:30:43 +0530 | [diff] [blame] | 28 | #include "cfg80211.h" |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 29 | |
| 30 | struct ath6kl_sdio { |
| 31 | struct sdio_func *func; |
| 32 | |
| 33 | spinlock_t lock; |
| 34 | |
| 35 | /* free list */ |
| 36 | struct list_head bus_req_freeq; |
| 37 | |
| 38 | /* available bus requests */ |
| 39 | struct bus_request bus_req[BUS_REQUEST_MAX_NUM]; |
| 40 | |
| 41 | struct ath6kl *ar; |
Raja Mani | fdb2858 | 2011-11-21 12:26:51 +0530 | [diff] [blame] | 42 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 43 | u8 *dma_buffer; |
| 44 | |
Raja Mani | fdb2858 | 2011-11-21 12:26:51 +0530 | [diff] [blame] | 45 | /* protects access to dma_buffer */ |
| 46 | struct mutex dma_buffer_mutex; |
| 47 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 48 | /* scatter request list head */ |
| 49 | struct list_head scat_req; |
| 50 | |
| 51 | spinlock_t scat_lock; |
Kalle Valo | 32a07e4 | 2011-10-30 21:15:57 +0200 | [diff] [blame] | 52 | bool scatter_enabled; |
| 53 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 54 | bool is_disabled; |
| 55 | atomic_t irq_handling; |
| 56 | const struct sdio_device_id *id; |
| 57 | struct work_struct wr_async_work; |
| 58 | struct list_head wr_asyncq; |
| 59 | spinlock_t wr_async_lock; |
| 60 | }; |
| 61 | |
| 62 | #define CMD53_ARG_READ 0 |
| 63 | #define CMD53_ARG_WRITE 1 |
| 64 | #define CMD53_ARG_BLOCK_BASIS 1 |
| 65 | #define CMD53_ARG_FIXED_ADDRESS 0 |
| 66 | #define CMD53_ARG_INCR_ADDRESS 1 |
| 67 | |
| 68 | static inline struct ath6kl_sdio *ath6kl_sdio_priv(struct ath6kl *ar) |
| 69 | { |
| 70 | return ar->hif_priv; |
| 71 | } |
| 72 | |
| 73 | /* |
| 74 | * Macro to check if DMA buffer is WORD-aligned and DMA-able. |
| 75 | * Most host controllers assume the buffer is DMA'able and will |
| 76 | * bug-check otherwise (i.e. buffers on the stack). virt_addr_valid |
| 77 | * check fails on stack memory. |
| 78 | */ |
| 79 | static inline bool buf_needs_bounce(u8 *buf) |
| 80 | { |
| 81 | return ((unsigned long) buf & 0x3) || !virt_addr_valid(buf); |
| 82 | } |
| 83 | |
| 84 | static void ath6kl_sdio_set_mbox_info(struct ath6kl *ar) |
| 85 | { |
| 86 | struct ath6kl_mbox_info *mbox_info = &ar->mbox_info; |
| 87 | |
| 88 | /* EP1 has an extended range */ |
| 89 | mbox_info->htc_addr = HIF_MBOX_BASE_ADDR; |
| 90 | mbox_info->htc_ext_addr = HIF_MBOX0_EXT_BASE_ADDR; |
| 91 | mbox_info->htc_ext_sz = HIF_MBOX0_EXT_WIDTH; |
| 92 | mbox_info->block_size = HIF_MBOX_BLOCK_SIZE; |
| 93 | mbox_info->gmbox_addr = HIF_GMBOX_BASE_ADDR; |
| 94 | mbox_info->gmbox_sz = HIF_GMBOX_WIDTH; |
| 95 | } |
| 96 | |
| 97 | static inline void ath6kl_sdio_set_cmd53_arg(u32 *arg, u8 rw, u8 func, |
| 98 | u8 mode, u8 opcode, u32 addr, |
| 99 | u16 blksz) |
| 100 | { |
| 101 | *arg = (((rw & 1) << 31) | |
| 102 | ((func & 0x7) << 28) | |
| 103 | ((mode & 1) << 27) | |
| 104 | ((opcode & 1) << 26) | |
| 105 | ((addr & 0x1FFFF) << 9) | |
| 106 | (blksz & 0x1FF)); |
| 107 | } |
| 108 | |
| 109 | static inline void ath6kl_sdio_set_cmd52_arg(u32 *arg, u8 write, u8 raw, |
| 110 | unsigned int address, |
| 111 | unsigned char val) |
| 112 | { |
| 113 | const u8 func = 0; |
| 114 | |
| 115 | *arg = ((write & 1) << 31) | |
| 116 | ((func & 0x7) << 28) | |
| 117 | ((raw & 1) << 27) | |
| 118 | (1 << 26) | |
| 119 | ((address & 0x1FFFF) << 9) | |
| 120 | (1 << 8) | |
| 121 | (val & 0xFF); |
| 122 | } |
| 123 | |
| 124 | static int ath6kl_sdio_func0_cmd52_wr_byte(struct mmc_card *card, |
| 125 | unsigned int address, |
| 126 | unsigned char byte) |
| 127 | { |
| 128 | struct mmc_command io_cmd; |
| 129 | |
| 130 | memset(&io_cmd, 0, sizeof(io_cmd)); |
| 131 | ath6kl_sdio_set_cmd52_arg(&io_cmd.arg, 1, 0, address, byte); |
| 132 | io_cmd.opcode = SD_IO_RW_DIRECT; |
| 133 | io_cmd.flags = MMC_RSP_R5 | MMC_CMD_AC; |
| 134 | |
| 135 | return mmc_wait_for_cmd(card->host, &io_cmd, 0); |
| 136 | } |
| 137 | |
Vasanthakumar Thiagarajan | da22069 | 2011-07-16 20:29:16 +0530 | [diff] [blame] | 138 | static int ath6kl_sdio_io(struct sdio_func *func, u32 request, u32 addr, |
| 139 | u8 *buf, u32 len) |
| 140 | { |
| 141 | int ret = 0; |
| 142 | |
Vasanthakumar Thiagarajan | 861dd05 | 2011-09-30 21:46:59 +0530 | [diff] [blame] | 143 | sdio_claim_host(func); |
| 144 | |
Vasanthakumar Thiagarajan | da22069 | 2011-07-16 20:29:16 +0530 | [diff] [blame] | 145 | if (request & HIF_WRITE) { |
Kalle Valo | f7325b8 | 2011-09-27 14:30:58 +0300 | [diff] [blame] | 146 | /* FIXME: looks like ugly workaround for something */ |
Vasanthakumar Thiagarajan | da22069 | 2011-07-16 20:29:16 +0530 | [diff] [blame] | 147 | if (addr >= HIF_MBOX_BASE_ADDR && |
| 148 | addr <= HIF_MBOX_END_ADDR) |
| 149 | addr += (HIF_MBOX_WIDTH - len); |
| 150 | |
Kalle Valo | f7325b8 | 2011-09-27 14:30:58 +0300 | [diff] [blame] | 151 | /* FIXME: this also looks like ugly workaround */ |
Vasanthakumar Thiagarajan | da22069 | 2011-07-16 20:29:16 +0530 | [diff] [blame] | 152 | if (addr == HIF_MBOX0_EXT_BASE_ADDR) |
| 153 | addr += HIF_MBOX0_EXT_WIDTH - len; |
| 154 | |
| 155 | if (request & HIF_FIXED_ADDRESS) |
| 156 | ret = sdio_writesb(func, addr, buf, len); |
| 157 | else |
| 158 | ret = sdio_memcpy_toio(func, addr, buf, len); |
| 159 | } else { |
| 160 | if (request & HIF_FIXED_ADDRESS) |
| 161 | ret = sdio_readsb(func, buf, addr, len); |
| 162 | else |
| 163 | ret = sdio_memcpy_fromio(func, buf, addr, len); |
| 164 | } |
| 165 | |
Vasanthakumar Thiagarajan | 861dd05 | 2011-09-30 21:46:59 +0530 | [diff] [blame] | 166 | sdio_release_host(func); |
| 167 | |
Kalle Valo | f7325b8 | 2011-09-27 14:30:58 +0300 | [diff] [blame] | 168 | ath6kl_dbg(ATH6KL_DBG_SDIO, "%s addr 0x%x%s buf 0x%p len %d\n", |
| 169 | request & HIF_WRITE ? "wr" : "rd", addr, |
| 170 | request & HIF_FIXED_ADDRESS ? " (fixed)" : "", buf, len); |
| 171 | ath6kl_dbg_dump(ATH6KL_DBG_SDIO_DUMP, NULL, "sdio ", buf, len); |
| 172 | |
Vasanthakumar Thiagarajan | da22069 | 2011-07-16 20:29:16 +0530 | [diff] [blame] | 173 | return ret; |
| 174 | } |
| 175 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 176 | static struct bus_request *ath6kl_sdio_alloc_busreq(struct ath6kl_sdio *ar_sdio) |
| 177 | { |
| 178 | struct bus_request *bus_req; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 179 | |
Vasanthakumar Thiagarajan | 151bd30 | 2011-09-30 19:18:43 +0530 | [diff] [blame] | 180 | spin_lock_bh(&ar_sdio->lock); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 181 | |
| 182 | if (list_empty(&ar_sdio->bus_req_freeq)) { |
Vasanthakumar Thiagarajan | 151bd30 | 2011-09-30 19:18:43 +0530 | [diff] [blame] | 183 | spin_unlock_bh(&ar_sdio->lock); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 184 | return NULL; |
| 185 | } |
| 186 | |
| 187 | bus_req = list_first_entry(&ar_sdio->bus_req_freeq, |
| 188 | struct bus_request, list); |
| 189 | list_del(&bus_req->list); |
| 190 | |
Vasanthakumar Thiagarajan | 151bd30 | 2011-09-30 19:18:43 +0530 | [diff] [blame] | 191 | spin_unlock_bh(&ar_sdio->lock); |
Kalle Valo | f7325b8 | 2011-09-27 14:30:58 +0300 | [diff] [blame] | 192 | ath6kl_dbg(ATH6KL_DBG_SCATTER, "%s: bus request 0x%p\n", |
| 193 | __func__, bus_req); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 194 | |
| 195 | return bus_req; |
| 196 | } |
| 197 | |
| 198 | static void ath6kl_sdio_free_bus_req(struct ath6kl_sdio *ar_sdio, |
| 199 | struct bus_request *bus_req) |
| 200 | { |
Kalle Valo | f7325b8 | 2011-09-27 14:30:58 +0300 | [diff] [blame] | 201 | ath6kl_dbg(ATH6KL_DBG_SCATTER, "%s: bus request 0x%p\n", |
| 202 | __func__, bus_req); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 203 | |
Vasanthakumar Thiagarajan | 151bd30 | 2011-09-30 19:18:43 +0530 | [diff] [blame] | 204 | spin_lock_bh(&ar_sdio->lock); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 205 | list_add_tail(&bus_req->list, &ar_sdio->bus_req_freeq); |
Vasanthakumar Thiagarajan | 151bd30 | 2011-09-30 19:18:43 +0530 | [diff] [blame] | 206 | spin_unlock_bh(&ar_sdio->lock); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | static void ath6kl_sdio_setup_scat_data(struct hif_scatter_req *scat_req, |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 210 | struct mmc_data *data) |
| 211 | { |
| 212 | struct scatterlist *sg; |
| 213 | int i; |
| 214 | |
| 215 | data->blksz = HIF_MBOX_BLOCK_SIZE; |
| 216 | data->blocks = scat_req->len / HIF_MBOX_BLOCK_SIZE; |
| 217 | |
| 218 | ath6kl_dbg(ATH6KL_DBG_SCATTER, |
| 219 | "hif-scatter: (%s) addr: 0x%X, (block len: %d, block count: %d) , (tot:%d,sg:%d)\n", |
| 220 | (scat_req->req & HIF_WRITE) ? "WR" : "RD", scat_req->addr, |
| 221 | data->blksz, data->blocks, scat_req->len, |
| 222 | scat_req->scat_entries); |
| 223 | |
| 224 | data->flags = (scat_req->req & HIF_WRITE) ? MMC_DATA_WRITE : |
| 225 | MMC_DATA_READ; |
| 226 | |
| 227 | /* fill SG entries */ |
Vasanthakumar Thiagarajan | d4df789 | 2011-07-16 20:29:07 +0530 | [diff] [blame] | 228 | sg = scat_req->sgentries; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 229 | sg_init_table(sg, scat_req->scat_entries); |
| 230 | |
| 231 | /* assemble SG list */ |
| 232 | for (i = 0; i < scat_req->scat_entries; i++, sg++) { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 233 | ath6kl_dbg(ATH6KL_DBG_SCATTER, "%d: addr:0x%p, len:%d\n", |
| 234 | i, scat_req->scat_list[i].buf, |
| 235 | scat_req->scat_list[i].len); |
| 236 | |
| 237 | sg_set_buf(sg, scat_req->scat_list[i].buf, |
| 238 | scat_req->scat_list[i].len); |
| 239 | } |
| 240 | |
| 241 | /* set scatter-gather table for request */ |
Vasanthakumar Thiagarajan | d4df789 | 2011-07-16 20:29:07 +0530 | [diff] [blame] | 242 | data->sg = scat_req->sgentries; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 243 | data->sg_len = scat_req->scat_entries; |
| 244 | } |
| 245 | |
| 246 | static int ath6kl_sdio_scat_rw(struct ath6kl_sdio *ar_sdio, |
| 247 | struct bus_request *req) |
| 248 | { |
| 249 | struct mmc_request mmc_req; |
| 250 | struct mmc_command cmd; |
| 251 | struct mmc_data data; |
| 252 | struct hif_scatter_req *scat_req; |
| 253 | u8 opcode, rw; |
Vasanthakumar Thiagarajan | 348a8fb | 2011-07-16 20:29:17 +0530 | [diff] [blame] | 254 | int status, len; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 255 | |
| 256 | scat_req = req->scat_req; |
| 257 | |
Vasanthakumar Thiagarajan | 348a8fb | 2011-07-16 20:29:17 +0530 | [diff] [blame] | 258 | if (scat_req->virt_scat) { |
| 259 | len = scat_req->len; |
| 260 | if (scat_req->req & HIF_BLOCK_BASIS) |
| 261 | len = round_down(len, HIF_MBOX_BLOCK_SIZE); |
| 262 | |
| 263 | status = ath6kl_sdio_io(ar_sdio->func, scat_req->req, |
| 264 | scat_req->addr, scat_req->virt_dma_buf, |
| 265 | len); |
| 266 | goto scat_complete; |
| 267 | } |
| 268 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 269 | memset(&mmc_req, 0, sizeof(struct mmc_request)); |
| 270 | memset(&cmd, 0, sizeof(struct mmc_command)); |
| 271 | memset(&data, 0, sizeof(struct mmc_data)); |
| 272 | |
Vasanthakumar Thiagarajan | d4df789 | 2011-07-16 20:29:07 +0530 | [diff] [blame] | 273 | ath6kl_sdio_setup_scat_data(scat_req, &data); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 274 | |
| 275 | opcode = (scat_req->req & HIF_FIXED_ADDRESS) ? |
| 276 | CMD53_ARG_FIXED_ADDRESS : CMD53_ARG_INCR_ADDRESS; |
| 277 | |
| 278 | rw = (scat_req->req & HIF_WRITE) ? CMD53_ARG_WRITE : CMD53_ARG_READ; |
| 279 | |
| 280 | /* Fixup the address so that the last byte will fall on MBOX EOM */ |
| 281 | if (scat_req->req & HIF_WRITE) { |
| 282 | if (scat_req->addr == HIF_MBOX_BASE_ADDR) |
| 283 | scat_req->addr += HIF_MBOX_WIDTH - scat_req->len; |
| 284 | else |
| 285 | /* Uses extended address range */ |
| 286 | scat_req->addr += HIF_MBOX0_EXT_WIDTH - scat_req->len; |
| 287 | } |
| 288 | |
| 289 | /* set command argument */ |
| 290 | ath6kl_sdio_set_cmd53_arg(&cmd.arg, rw, ar_sdio->func->num, |
| 291 | CMD53_ARG_BLOCK_BASIS, opcode, scat_req->addr, |
| 292 | data.blocks); |
| 293 | |
| 294 | cmd.opcode = SD_IO_RW_EXTENDED; |
| 295 | cmd.flags = MMC_RSP_SPI_R5 | MMC_RSP_R5 | MMC_CMD_ADTC; |
| 296 | |
| 297 | mmc_req.cmd = &cmd; |
| 298 | mmc_req.data = &data; |
| 299 | |
Vasanthakumar Thiagarajan | 861dd05 | 2011-09-30 21:46:59 +0530 | [diff] [blame] | 300 | sdio_claim_host(ar_sdio->func); |
| 301 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 302 | mmc_set_data_timeout(&data, ar_sdio->func->card); |
| 303 | /* synchronous call to process request */ |
| 304 | mmc_wait_for_req(ar_sdio->func->card->host, &mmc_req); |
| 305 | |
Vasanthakumar Thiagarajan | 861dd05 | 2011-09-30 21:46:59 +0530 | [diff] [blame] | 306 | sdio_release_host(ar_sdio->func); |
| 307 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 308 | status = cmd.error ? cmd.error : data.error; |
Vasanthakumar Thiagarajan | 348a8fb | 2011-07-16 20:29:17 +0530 | [diff] [blame] | 309 | |
| 310 | scat_complete: |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 311 | scat_req->status = status; |
| 312 | |
| 313 | if (scat_req->status) |
| 314 | ath6kl_err("Scatter write request failed:%d\n", |
| 315 | scat_req->status); |
| 316 | |
| 317 | if (scat_req->req & HIF_ASYNCHRONOUS) |
Vasanthakumar Thiagarajan | e041c7f | 2011-07-16 20:29:09 +0530 | [diff] [blame] | 318 | scat_req->complete(ar_sdio->ar->htc_target, scat_req); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 319 | |
| 320 | return status; |
| 321 | } |
| 322 | |
Vasanthakumar Thiagarajan | 3df505a | 2011-07-16 20:29:10 +0530 | [diff] [blame] | 323 | static int ath6kl_sdio_alloc_prep_scat_req(struct ath6kl_sdio *ar_sdio, |
| 324 | int n_scat_entry, int n_scat_req, |
| 325 | bool virt_scat) |
| 326 | { |
| 327 | struct hif_scatter_req *s_req; |
| 328 | struct bus_request *bus_req; |
Vasanthakumar Thiagarajan | cfeab10 | 2011-07-16 20:29:14 +0530 | [diff] [blame] | 329 | int i, scat_req_sz, scat_list_sz, sg_sz, buf_sz; |
| 330 | u8 *virt_buf; |
Vasanthakumar Thiagarajan | 3df505a | 2011-07-16 20:29:10 +0530 | [diff] [blame] | 331 | |
| 332 | scat_list_sz = (n_scat_entry - 1) * sizeof(struct hif_scatter_item); |
| 333 | scat_req_sz = sizeof(*s_req) + scat_list_sz; |
| 334 | |
| 335 | if (!virt_scat) |
| 336 | sg_sz = sizeof(struct scatterlist) * n_scat_entry; |
Vasanthakumar Thiagarajan | cfeab10 | 2011-07-16 20:29:14 +0530 | [diff] [blame] | 337 | else |
| 338 | buf_sz = 2 * L1_CACHE_BYTES + |
| 339 | ATH6KL_MAX_TRANSFER_SIZE_PER_SCATTER; |
Vasanthakumar Thiagarajan | 3df505a | 2011-07-16 20:29:10 +0530 | [diff] [blame] | 340 | |
| 341 | for (i = 0; i < n_scat_req; i++) { |
| 342 | /* allocate the scatter request */ |
| 343 | s_req = kzalloc(scat_req_sz, GFP_KERNEL); |
| 344 | if (!s_req) |
| 345 | return -ENOMEM; |
| 346 | |
Vasanthakumar Thiagarajan | cfeab10 | 2011-07-16 20:29:14 +0530 | [diff] [blame] | 347 | if (virt_scat) { |
| 348 | virt_buf = kzalloc(buf_sz, GFP_KERNEL); |
| 349 | if (!virt_buf) { |
| 350 | kfree(s_req); |
| 351 | return -ENOMEM; |
| 352 | } |
| 353 | |
| 354 | s_req->virt_dma_buf = |
| 355 | (u8 *)L1_CACHE_ALIGN((unsigned long)virt_buf); |
| 356 | } else { |
Vasanthakumar Thiagarajan | 3df505a | 2011-07-16 20:29:10 +0530 | [diff] [blame] | 357 | /* allocate sglist */ |
| 358 | s_req->sgentries = kzalloc(sg_sz, GFP_KERNEL); |
| 359 | |
| 360 | if (!s_req->sgentries) { |
| 361 | kfree(s_req); |
| 362 | return -ENOMEM; |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | /* allocate a bus request for this scatter request */ |
| 367 | bus_req = ath6kl_sdio_alloc_busreq(ar_sdio); |
| 368 | if (!bus_req) { |
| 369 | kfree(s_req->sgentries); |
Vasanthakumar Thiagarajan | cfeab10 | 2011-07-16 20:29:14 +0530 | [diff] [blame] | 370 | kfree(s_req->virt_dma_buf); |
Vasanthakumar Thiagarajan | 3df505a | 2011-07-16 20:29:10 +0530 | [diff] [blame] | 371 | kfree(s_req); |
| 372 | return -ENOMEM; |
| 373 | } |
| 374 | |
| 375 | /* assign the scatter request to this bus request */ |
| 376 | bus_req->scat_req = s_req; |
| 377 | s_req->busrequest = bus_req; |
| 378 | |
Vasanthakumar Thiagarajan | 4a005c3 | 2011-07-16 20:29:15 +0530 | [diff] [blame] | 379 | s_req->virt_scat = virt_scat; |
| 380 | |
Vasanthakumar Thiagarajan | 3df505a | 2011-07-16 20:29:10 +0530 | [diff] [blame] | 381 | /* add it to the scatter pool */ |
| 382 | hif_scatter_req_add(ar_sdio->ar, s_req); |
| 383 | } |
| 384 | |
| 385 | return 0; |
| 386 | } |
| 387 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 388 | static int ath6kl_sdio_read_write_sync(struct ath6kl *ar, u32 addr, u8 *buf, |
| 389 | u32 len, u32 request) |
| 390 | { |
| 391 | struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar); |
| 392 | u8 *tbuf = NULL; |
| 393 | int ret; |
| 394 | bool bounced = false; |
| 395 | |
| 396 | if (request & HIF_BLOCK_BASIS) |
| 397 | len = round_down(len, HIF_MBOX_BLOCK_SIZE); |
| 398 | |
| 399 | if (buf_needs_bounce(buf)) { |
| 400 | if (!ar_sdio->dma_buffer) |
| 401 | return -ENOMEM; |
Raja Mani | fdb2858 | 2011-11-21 12:26:51 +0530 | [diff] [blame] | 402 | mutex_lock(&ar_sdio->dma_buffer_mutex); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 403 | tbuf = ar_sdio->dma_buffer; |
| 404 | memcpy(tbuf, buf, len); |
| 405 | bounced = true; |
| 406 | } else |
| 407 | tbuf = buf; |
| 408 | |
Vasanthakumar Thiagarajan | da22069 | 2011-07-16 20:29:16 +0530 | [diff] [blame] | 409 | ret = ath6kl_sdio_io(ar_sdio->func, request, addr, tbuf, len); |
| 410 | if ((request & HIF_READ) && bounced) |
| 411 | memcpy(buf, tbuf, len); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 412 | |
Raja Mani | fdb2858 | 2011-11-21 12:26:51 +0530 | [diff] [blame] | 413 | if (bounced) |
| 414 | mutex_unlock(&ar_sdio->dma_buffer_mutex); |
| 415 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 416 | return ret; |
| 417 | } |
| 418 | |
| 419 | static void __ath6kl_sdio_write_async(struct ath6kl_sdio *ar_sdio, |
| 420 | struct bus_request *req) |
| 421 | { |
| 422 | if (req->scat_req) |
| 423 | ath6kl_sdio_scat_rw(ar_sdio, req); |
| 424 | else { |
| 425 | void *context; |
| 426 | int status; |
| 427 | |
| 428 | status = ath6kl_sdio_read_write_sync(ar_sdio->ar, req->address, |
| 429 | req->buffer, req->length, |
| 430 | req->request); |
| 431 | context = req->packet; |
| 432 | ath6kl_sdio_free_bus_req(ar_sdio, req); |
Kalle Valo | 8e8ddb2 | 2011-10-05 12:23:33 +0300 | [diff] [blame] | 433 | ath6kl_hif_rw_comp_handler(context, status); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 434 | } |
| 435 | } |
| 436 | |
| 437 | static void ath6kl_sdio_write_async_work(struct work_struct *work) |
| 438 | { |
| 439 | struct ath6kl_sdio *ar_sdio; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 440 | struct bus_request *req, *tmp_req; |
| 441 | |
| 442 | ar_sdio = container_of(work, struct ath6kl_sdio, wr_async_work); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 443 | |
Vasanthakumar Thiagarajan | 151bd30 | 2011-09-30 19:18:43 +0530 | [diff] [blame] | 444 | spin_lock_bh(&ar_sdio->wr_async_lock); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 445 | list_for_each_entry_safe(req, tmp_req, &ar_sdio->wr_asyncq, list) { |
| 446 | list_del(&req->list); |
Vasanthakumar Thiagarajan | 151bd30 | 2011-09-30 19:18:43 +0530 | [diff] [blame] | 447 | spin_unlock_bh(&ar_sdio->wr_async_lock); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 448 | __ath6kl_sdio_write_async(ar_sdio, req); |
Vasanthakumar Thiagarajan | 151bd30 | 2011-09-30 19:18:43 +0530 | [diff] [blame] | 449 | spin_lock_bh(&ar_sdio->wr_async_lock); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 450 | } |
Vasanthakumar Thiagarajan | 151bd30 | 2011-09-30 19:18:43 +0530 | [diff] [blame] | 451 | spin_unlock_bh(&ar_sdio->wr_async_lock); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | static void ath6kl_sdio_irq_handler(struct sdio_func *func) |
| 455 | { |
| 456 | int status; |
| 457 | struct ath6kl_sdio *ar_sdio; |
| 458 | |
Kalle Valo | f7325b8 | 2011-09-27 14:30:58 +0300 | [diff] [blame] | 459 | ath6kl_dbg(ATH6KL_DBG_SDIO, "irq\n"); |
| 460 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 461 | ar_sdio = sdio_get_drvdata(func); |
| 462 | atomic_set(&ar_sdio->irq_handling, 1); |
| 463 | |
| 464 | /* |
| 465 | * Release the host during interrups so we can pick it back up when |
| 466 | * we process commands. |
| 467 | */ |
| 468 | sdio_release_host(ar_sdio->func); |
| 469 | |
Kalle Valo | 8e8ddb2 | 2011-10-05 12:23:33 +0300 | [diff] [blame] | 470 | status = ath6kl_hif_intr_bh_handler(ar_sdio->ar); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 471 | sdio_claim_host(ar_sdio->func); |
| 472 | atomic_set(&ar_sdio->irq_handling, 0); |
| 473 | WARN_ON(status && status != -ECANCELED); |
| 474 | } |
| 475 | |
Kalle Valo | b2e7569 | 2011-10-27 18:48:14 +0300 | [diff] [blame] | 476 | static int ath6kl_sdio_power_on(struct ath6kl *ar) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 477 | { |
Kalle Valo | b2e7569 | 2011-10-27 18:48:14 +0300 | [diff] [blame] | 478 | struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 479 | struct sdio_func *func = ar_sdio->func; |
| 480 | int ret = 0; |
| 481 | |
| 482 | if (!ar_sdio->is_disabled) |
| 483 | return 0; |
| 484 | |
Kalle Valo | 3ef987b | 2011-10-24 12:18:07 +0300 | [diff] [blame] | 485 | ath6kl_dbg(ATH6KL_DBG_BOOT, "sdio power on\n"); |
| 486 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 487 | sdio_claim_host(func); |
| 488 | |
| 489 | ret = sdio_enable_func(func); |
| 490 | if (ret) { |
| 491 | ath6kl_err("Unable to enable sdio func: %d)\n", ret); |
| 492 | sdio_release_host(func); |
| 493 | return ret; |
| 494 | } |
| 495 | |
| 496 | sdio_release_host(func); |
| 497 | |
| 498 | /* |
| 499 | * Wait for hardware to initialise. It should take a lot less than |
| 500 | * 10 ms but let's be conservative here. |
| 501 | */ |
| 502 | msleep(10); |
| 503 | |
| 504 | ar_sdio->is_disabled = false; |
| 505 | |
| 506 | return ret; |
| 507 | } |
| 508 | |
Kalle Valo | b2e7569 | 2011-10-27 18:48:14 +0300 | [diff] [blame] | 509 | static int ath6kl_sdio_power_off(struct ath6kl *ar) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 510 | { |
Kalle Valo | b2e7569 | 2011-10-27 18:48:14 +0300 | [diff] [blame] | 511 | struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 512 | int ret; |
| 513 | |
| 514 | if (ar_sdio->is_disabled) |
| 515 | return 0; |
| 516 | |
Kalle Valo | 3ef987b | 2011-10-24 12:18:07 +0300 | [diff] [blame] | 517 | ath6kl_dbg(ATH6KL_DBG_BOOT, "sdio power off\n"); |
| 518 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 519 | /* Disable the card */ |
| 520 | sdio_claim_host(ar_sdio->func); |
| 521 | ret = sdio_disable_func(ar_sdio->func); |
| 522 | sdio_release_host(ar_sdio->func); |
| 523 | |
| 524 | if (ret) |
| 525 | return ret; |
| 526 | |
| 527 | ar_sdio->is_disabled = true; |
| 528 | |
| 529 | return ret; |
| 530 | } |
| 531 | |
| 532 | static int ath6kl_sdio_write_async(struct ath6kl *ar, u32 address, u8 *buffer, |
| 533 | u32 length, u32 request, |
| 534 | struct htc_packet *packet) |
| 535 | { |
| 536 | struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar); |
| 537 | struct bus_request *bus_req; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 538 | |
| 539 | bus_req = ath6kl_sdio_alloc_busreq(ar_sdio); |
| 540 | |
| 541 | if (!bus_req) |
| 542 | return -ENOMEM; |
| 543 | |
| 544 | bus_req->address = address; |
| 545 | bus_req->buffer = buffer; |
| 546 | bus_req->length = length; |
| 547 | bus_req->request = request; |
| 548 | bus_req->packet = packet; |
| 549 | |
Vasanthakumar Thiagarajan | 151bd30 | 2011-09-30 19:18:43 +0530 | [diff] [blame] | 550 | spin_lock_bh(&ar_sdio->wr_async_lock); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 551 | list_add_tail(&bus_req->list, &ar_sdio->wr_asyncq); |
Vasanthakumar Thiagarajan | 151bd30 | 2011-09-30 19:18:43 +0530 | [diff] [blame] | 552 | spin_unlock_bh(&ar_sdio->wr_async_lock); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 553 | queue_work(ar->ath6kl_wq, &ar_sdio->wr_async_work); |
| 554 | |
| 555 | return 0; |
| 556 | } |
| 557 | |
| 558 | static void ath6kl_sdio_irq_enable(struct ath6kl *ar) |
| 559 | { |
| 560 | struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar); |
| 561 | int ret; |
| 562 | |
| 563 | sdio_claim_host(ar_sdio->func); |
| 564 | |
| 565 | /* Register the isr */ |
| 566 | ret = sdio_claim_irq(ar_sdio->func, ath6kl_sdio_irq_handler); |
| 567 | if (ret) |
| 568 | ath6kl_err("Failed to claim sdio irq: %d\n", ret); |
| 569 | |
| 570 | sdio_release_host(ar_sdio->func); |
| 571 | } |
| 572 | |
| 573 | static void ath6kl_sdio_irq_disable(struct ath6kl *ar) |
| 574 | { |
| 575 | struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar); |
| 576 | int ret; |
| 577 | |
| 578 | sdio_claim_host(ar_sdio->func); |
| 579 | |
| 580 | /* Mask our function IRQ */ |
| 581 | while (atomic_read(&ar_sdio->irq_handling)) { |
| 582 | sdio_release_host(ar_sdio->func); |
| 583 | schedule_timeout(HZ / 10); |
| 584 | sdio_claim_host(ar_sdio->func); |
| 585 | } |
| 586 | |
| 587 | ret = sdio_release_irq(ar_sdio->func); |
| 588 | if (ret) |
| 589 | ath6kl_err("Failed to release sdio irq: %d\n", ret); |
| 590 | |
| 591 | sdio_release_host(ar_sdio->func); |
| 592 | } |
| 593 | |
| 594 | static struct hif_scatter_req *ath6kl_sdio_scatter_req_get(struct ath6kl *ar) |
| 595 | { |
| 596 | struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar); |
| 597 | struct hif_scatter_req *node = NULL; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 598 | |
Vasanthakumar Thiagarajan | 151bd30 | 2011-09-30 19:18:43 +0530 | [diff] [blame] | 599 | spin_lock_bh(&ar_sdio->scat_lock); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 600 | |
| 601 | if (!list_empty(&ar_sdio->scat_req)) { |
| 602 | node = list_first_entry(&ar_sdio->scat_req, |
| 603 | struct hif_scatter_req, list); |
| 604 | list_del(&node->list); |
| 605 | } |
| 606 | |
Vasanthakumar Thiagarajan | 151bd30 | 2011-09-30 19:18:43 +0530 | [diff] [blame] | 607 | spin_unlock_bh(&ar_sdio->scat_lock); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 608 | |
| 609 | return node; |
| 610 | } |
| 611 | |
| 612 | static void ath6kl_sdio_scatter_req_add(struct ath6kl *ar, |
| 613 | struct hif_scatter_req *s_req) |
| 614 | { |
| 615 | struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 616 | |
Vasanthakumar Thiagarajan | 151bd30 | 2011-09-30 19:18:43 +0530 | [diff] [blame] | 617 | spin_lock_bh(&ar_sdio->scat_lock); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 618 | |
| 619 | list_add_tail(&s_req->list, &ar_sdio->scat_req); |
| 620 | |
Vasanthakumar Thiagarajan | 151bd30 | 2011-09-30 19:18:43 +0530 | [diff] [blame] | 621 | spin_unlock_bh(&ar_sdio->scat_lock); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 622 | |
| 623 | } |
| 624 | |
Vasanthakumar Thiagarajan | c630d18 | 2011-07-16 20:29:06 +0530 | [diff] [blame] | 625 | /* scatter gather read write request */ |
| 626 | static int ath6kl_sdio_async_rw_scatter(struct ath6kl *ar, |
| 627 | struct hif_scatter_req *scat_req) |
| 628 | { |
| 629 | struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar); |
Vasanthakumar Thiagarajan | c630d18 | 2011-07-16 20:29:06 +0530 | [diff] [blame] | 630 | u32 request = scat_req->req; |
| 631 | int status = 0; |
Vasanthakumar Thiagarajan | c630d18 | 2011-07-16 20:29:06 +0530 | [diff] [blame] | 632 | |
| 633 | if (!scat_req->len) |
| 634 | return -EINVAL; |
| 635 | |
| 636 | ath6kl_dbg(ATH6KL_DBG_SCATTER, |
| 637 | "hif-scatter: total len: %d scatter entries: %d\n", |
| 638 | scat_req->len, scat_req->scat_entries); |
| 639 | |
Vasanthakumar Thiagarajan | 861dd05 | 2011-09-30 21:46:59 +0530 | [diff] [blame] | 640 | if (request & HIF_SYNCHRONOUS) |
Vasanthakumar Thiagarajan | d4df789 | 2011-07-16 20:29:07 +0530 | [diff] [blame] | 641 | status = ath6kl_sdio_scat_rw(ar_sdio, scat_req->busrequest); |
Vasanthakumar Thiagarajan | 861dd05 | 2011-09-30 21:46:59 +0530 | [diff] [blame] | 642 | else { |
Vasanthakumar Thiagarajan | 151bd30 | 2011-09-30 19:18:43 +0530 | [diff] [blame] | 643 | spin_lock_bh(&ar_sdio->wr_async_lock); |
Vasanthakumar Thiagarajan | d4df789 | 2011-07-16 20:29:07 +0530 | [diff] [blame] | 644 | list_add_tail(&scat_req->busrequest->list, &ar_sdio->wr_asyncq); |
Vasanthakumar Thiagarajan | 151bd30 | 2011-09-30 19:18:43 +0530 | [diff] [blame] | 645 | spin_unlock_bh(&ar_sdio->wr_async_lock); |
Vasanthakumar Thiagarajan | c630d18 | 2011-07-16 20:29:06 +0530 | [diff] [blame] | 646 | queue_work(ar->ath6kl_wq, &ar_sdio->wr_async_work); |
| 647 | } |
| 648 | |
| 649 | return status; |
| 650 | } |
| 651 | |
Vasanthakumar Thiagarajan | 18a0f93 | 2011-07-16 20:29:13 +0530 | [diff] [blame] | 652 | /* clean up scatter support */ |
| 653 | static void ath6kl_sdio_cleanup_scatter(struct ath6kl *ar) |
| 654 | { |
| 655 | struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar); |
| 656 | struct hif_scatter_req *s_req, *tmp_req; |
Vasanthakumar Thiagarajan | 18a0f93 | 2011-07-16 20:29:13 +0530 | [diff] [blame] | 657 | |
| 658 | /* empty the free list */ |
Vasanthakumar Thiagarajan | 151bd30 | 2011-09-30 19:18:43 +0530 | [diff] [blame] | 659 | spin_lock_bh(&ar_sdio->scat_lock); |
Vasanthakumar Thiagarajan | 18a0f93 | 2011-07-16 20:29:13 +0530 | [diff] [blame] | 660 | list_for_each_entry_safe(s_req, tmp_req, &ar_sdio->scat_req, list) { |
| 661 | list_del(&s_req->list); |
Vasanthakumar Thiagarajan | 151bd30 | 2011-09-30 19:18:43 +0530 | [diff] [blame] | 662 | spin_unlock_bh(&ar_sdio->scat_lock); |
Vasanthakumar Thiagarajan | 18a0f93 | 2011-07-16 20:29:13 +0530 | [diff] [blame] | 663 | |
Kalle Valo | 32a07e4 | 2011-10-30 21:15:57 +0200 | [diff] [blame] | 664 | /* |
| 665 | * FIXME: should we also call completion handler with |
| 666 | * ath6kl_hif_rw_comp_handler() with status -ECANCELED so |
| 667 | * that the packet is properly freed? |
| 668 | */ |
Vasanthakumar Thiagarajan | 18a0f93 | 2011-07-16 20:29:13 +0530 | [diff] [blame] | 669 | if (s_req->busrequest) |
| 670 | ath6kl_sdio_free_bus_req(ar_sdio, s_req->busrequest); |
| 671 | kfree(s_req->virt_dma_buf); |
| 672 | kfree(s_req->sgentries); |
| 673 | kfree(s_req); |
| 674 | |
Vasanthakumar Thiagarajan | 151bd30 | 2011-09-30 19:18:43 +0530 | [diff] [blame] | 675 | spin_lock_bh(&ar_sdio->scat_lock); |
Vasanthakumar Thiagarajan | 18a0f93 | 2011-07-16 20:29:13 +0530 | [diff] [blame] | 676 | } |
Vasanthakumar Thiagarajan | 151bd30 | 2011-09-30 19:18:43 +0530 | [diff] [blame] | 677 | spin_unlock_bh(&ar_sdio->scat_lock); |
Vasanthakumar Thiagarajan | 18a0f93 | 2011-07-16 20:29:13 +0530 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | /* setup of HIF scatter resources */ |
Vasanthakumar Thiagarajan | 50745af | 2011-07-18 14:23:29 +0530 | [diff] [blame] | 681 | static int ath6kl_sdio_enable_scatter(struct ath6kl *ar) |
Vasanthakumar Thiagarajan | 18a0f93 | 2011-07-16 20:29:13 +0530 | [diff] [blame] | 682 | { |
| 683 | struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar); |
Vasanthakumar Thiagarajan | 50745af | 2011-07-18 14:23:29 +0530 | [diff] [blame] | 684 | struct htc_target *target = ar->htc_target; |
Vasanthakumar Thiagarajan | cfeab10 | 2011-07-16 20:29:14 +0530 | [diff] [blame] | 685 | int ret; |
| 686 | bool virt_scat = false; |
Vasanthakumar Thiagarajan | 18a0f93 | 2011-07-16 20:29:13 +0530 | [diff] [blame] | 687 | |
Kalle Valo | 32a07e4 | 2011-10-30 21:15:57 +0200 | [diff] [blame] | 688 | if (ar_sdio->scatter_enabled) |
| 689 | return 0; |
| 690 | |
| 691 | ar_sdio->scatter_enabled = true; |
| 692 | |
Vasanthakumar Thiagarajan | 18a0f93 | 2011-07-16 20:29:13 +0530 | [diff] [blame] | 693 | /* check if host supports scatter and it meets our requirements */ |
| 694 | if (ar_sdio->func->card->host->max_segs < MAX_SCATTER_ENTRIES_PER_REQ) { |
Vasanthakumar Thiagarajan | cfeab10 | 2011-07-16 20:29:14 +0530 | [diff] [blame] | 695 | ath6kl_err("host only supports scatter of :%d entries, need: %d\n", |
Vasanthakumar Thiagarajan | 18a0f93 | 2011-07-16 20:29:13 +0530 | [diff] [blame] | 696 | ar_sdio->func->card->host->max_segs, |
| 697 | MAX_SCATTER_ENTRIES_PER_REQ); |
Vasanthakumar Thiagarajan | cfeab10 | 2011-07-16 20:29:14 +0530 | [diff] [blame] | 698 | virt_scat = true; |
Vasanthakumar Thiagarajan | 18a0f93 | 2011-07-16 20:29:13 +0530 | [diff] [blame] | 699 | } |
| 700 | |
Vasanthakumar Thiagarajan | cfeab10 | 2011-07-16 20:29:14 +0530 | [diff] [blame] | 701 | if (!virt_scat) { |
| 702 | ret = ath6kl_sdio_alloc_prep_scat_req(ar_sdio, |
| 703 | MAX_SCATTER_ENTRIES_PER_REQ, |
| 704 | MAX_SCATTER_REQUESTS, virt_scat); |
Vasanthakumar Thiagarajan | 18a0f93 | 2011-07-16 20:29:13 +0530 | [diff] [blame] | 705 | |
Vasanthakumar Thiagarajan | cfeab10 | 2011-07-16 20:29:14 +0530 | [diff] [blame] | 706 | if (!ret) { |
Kalle Valo | 3ef987b | 2011-10-24 12:18:07 +0300 | [diff] [blame] | 707 | ath6kl_dbg(ATH6KL_DBG_BOOT, |
| 708 | "hif-scatter enabled requests %d entries %d\n", |
Vasanthakumar Thiagarajan | cfeab10 | 2011-07-16 20:29:14 +0530 | [diff] [blame] | 709 | MAX_SCATTER_REQUESTS, |
| 710 | MAX_SCATTER_ENTRIES_PER_REQ); |
| 711 | |
Vasanthakumar Thiagarajan | 50745af | 2011-07-18 14:23:29 +0530 | [diff] [blame] | 712 | target->max_scat_entries = MAX_SCATTER_ENTRIES_PER_REQ; |
| 713 | target->max_xfer_szper_scatreq = |
Vasanthakumar Thiagarajan | cfeab10 | 2011-07-16 20:29:14 +0530 | [diff] [blame] | 714 | MAX_SCATTER_REQ_TRANSFER_SIZE; |
| 715 | } else { |
| 716 | ath6kl_sdio_cleanup_scatter(ar); |
| 717 | ath6kl_warn("hif scatter resource setup failed, trying virtual scatter method\n"); |
| 718 | } |
Vasanthakumar Thiagarajan | 18a0f93 | 2011-07-16 20:29:13 +0530 | [diff] [blame] | 719 | } |
| 720 | |
Vasanthakumar Thiagarajan | cfeab10 | 2011-07-16 20:29:14 +0530 | [diff] [blame] | 721 | if (virt_scat || ret) { |
| 722 | ret = ath6kl_sdio_alloc_prep_scat_req(ar_sdio, |
| 723 | ATH6KL_SCATTER_ENTRIES_PER_REQ, |
| 724 | ATH6KL_SCATTER_REQS, virt_scat); |
| 725 | |
| 726 | if (ret) { |
| 727 | ath6kl_err("failed to alloc virtual scatter resources !\n"); |
| 728 | ath6kl_sdio_cleanup_scatter(ar); |
| 729 | return ret; |
| 730 | } |
| 731 | |
Kalle Valo | 3ef987b | 2011-10-24 12:18:07 +0300 | [diff] [blame] | 732 | ath6kl_dbg(ATH6KL_DBG_BOOT, |
| 733 | "virtual scatter enabled requests %d entries %d\n", |
Vasanthakumar Thiagarajan | cfeab10 | 2011-07-16 20:29:14 +0530 | [diff] [blame] | 734 | ATH6KL_SCATTER_REQS, ATH6KL_SCATTER_ENTRIES_PER_REQ); |
| 735 | |
Vasanthakumar Thiagarajan | 50745af | 2011-07-18 14:23:29 +0530 | [diff] [blame] | 736 | target->max_scat_entries = ATH6KL_SCATTER_ENTRIES_PER_REQ; |
| 737 | target->max_xfer_szper_scatreq = |
Vasanthakumar Thiagarajan | cfeab10 | 2011-07-16 20:29:14 +0530 | [diff] [blame] | 738 | ATH6KL_MAX_TRANSFER_SIZE_PER_SCATTER; |
| 739 | } |
| 740 | |
Vasanthakumar Thiagarajan | 18a0f93 | 2011-07-16 20:29:13 +0530 | [diff] [blame] | 741 | return 0; |
| 742 | } |
| 743 | |
Kalle Valo | e28e810 | 2011-11-01 08:44:36 +0200 | [diff] [blame] | 744 | static int ath6kl_sdio_config(struct ath6kl *ar) |
| 745 | { |
| 746 | struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar); |
| 747 | struct sdio_func *func = ar_sdio->func; |
| 748 | int ret; |
| 749 | |
| 750 | sdio_claim_host(func); |
| 751 | |
| 752 | if ((ar_sdio->id->device & MANUFACTURER_ID_ATH6KL_BASE_MASK) >= |
| 753 | MANUFACTURER_ID_AR6003_BASE) { |
| 754 | /* enable 4-bit ASYNC interrupt on AR6003 or later */ |
| 755 | ret = ath6kl_sdio_func0_cmd52_wr_byte(func->card, |
| 756 | CCCR_SDIO_IRQ_MODE_REG, |
| 757 | SDIO_IRQ_MODE_ASYNC_4BIT_IRQ); |
| 758 | if (ret) { |
| 759 | ath6kl_err("Failed to enable 4-bit async irq mode %d\n", |
| 760 | ret); |
| 761 | goto out; |
| 762 | } |
| 763 | |
| 764 | ath6kl_dbg(ATH6KL_DBG_BOOT, "4-bit async irq mode enabled\n"); |
| 765 | } |
| 766 | |
| 767 | /* give us some time to enable, in ms */ |
| 768 | func->enable_timeout = 100; |
| 769 | |
| 770 | ret = sdio_set_block_size(func, HIF_MBOX_BLOCK_SIZE); |
| 771 | if (ret) { |
| 772 | ath6kl_err("Set sdio block size %d failed: %d)\n", |
| 773 | HIF_MBOX_BLOCK_SIZE, ret); |
| 774 | sdio_release_host(func); |
| 775 | goto out; |
| 776 | } |
| 777 | |
| 778 | out: |
| 779 | sdio_release_host(func); |
| 780 | |
| 781 | return ret; |
| 782 | } |
| 783 | |
Raja Mani | 0f60e9f | 2011-11-07 22:52:45 +0200 | [diff] [blame] | 784 | static int ath6kl_sdio_suspend(struct ath6kl *ar, struct cfg80211_wowlan *wow) |
Kalle Valo | abcb344 | 2011-07-22 08:26:20 +0300 | [diff] [blame] | 785 | { |
| 786 | struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar); |
| 787 | struct sdio_func *func = ar_sdio->func; |
| 788 | mmc_pm_flag_t flags; |
| 789 | int ret; |
| 790 | |
| 791 | flags = sdio_get_host_pm_caps(func); |
| 792 | |
Kalle Valo | b4b2a0b | 2011-11-01 08:44:44 +0200 | [diff] [blame] | 793 | ath6kl_dbg(ATH6KL_DBG_SUSPEND, "sdio suspend pm_caps 0x%x\n", flags); |
| 794 | |
Kalle Valo | 8277de1 | 2011-11-03 12:18:31 +0200 | [diff] [blame] | 795 | if (!(flags & MMC_PM_KEEP_POWER) || |
| 796 | (ar->conf_flags & ATH6KL_CONF_SUSPEND_CUTPOWER)) { |
Kalle Valo | b4b2a0b | 2011-11-01 08:44:44 +0200 | [diff] [blame] | 797 | /* as host doesn't support keep power we need to cut power */ |
Raja Mani | 0f60e9f | 2011-11-07 22:52:45 +0200 | [diff] [blame] | 798 | return ath6kl_cfg80211_suspend(ar, ATH6KL_CFG_SUSPEND_CUTPOWER, |
| 799 | NULL); |
Sam Leffler | 1738085 | 2011-10-13 13:20:32 +0300 | [diff] [blame] | 800 | } |
Kalle Valo | abcb344 | 2011-07-22 08:26:20 +0300 | [diff] [blame] | 801 | |
| 802 | ret = sdio_set_host_pm_flags(func, MMC_PM_KEEP_POWER); |
| 803 | if (ret) { |
| 804 | printk(KERN_ERR "ath6kl: set sdio pm flags failed: %d\n", |
| 805 | ret); |
| 806 | return ret; |
| 807 | } |
| 808 | |
Raja Mani | d7c44e0 | 2011-11-07 22:52:46 +0200 | [diff] [blame] | 809 | if ((flags & MMC_PM_WAKE_SDIO_IRQ) && wow) { |
| 810 | /* |
| 811 | * The host sdio controller is capable of keep power and |
| 812 | * sdio irq wake up at this point. It's fine to continue |
| 813 | * wow suspend operation. |
| 814 | */ |
| 815 | ret = ath6kl_cfg80211_suspend(ar, ATH6KL_CFG_SUSPEND_WOW, wow); |
| 816 | if (ret) |
| 817 | return ret; |
| 818 | |
| 819 | ret = sdio_set_host_pm_flags(func, MMC_PM_WAKE_SDIO_IRQ); |
| 820 | if (ret) |
| 821 | ath6kl_err("set sdio wake irq flag failed: %d\n", ret); |
| 822 | |
| 823 | return ret; |
| 824 | } |
| 825 | |
Raja Mani | 0f60e9f | 2011-11-07 22:52:45 +0200 | [diff] [blame] | 826 | return ath6kl_cfg80211_suspend(ar, ATH6KL_CFG_SUSPEND_DEEPSLEEP, NULL); |
Kalle Valo | abcb344 | 2011-07-22 08:26:20 +0300 | [diff] [blame] | 827 | } |
| 828 | |
Chilam Ng | aa6cffc | 2011-10-05 10:12:52 +0300 | [diff] [blame] | 829 | static int ath6kl_sdio_resume(struct ath6kl *ar) |
| 830 | { |
Kalle Valo | b4b2a0b | 2011-11-01 08:44:44 +0200 | [diff] [blame] | 831 | switch (ar->state) { |
| 832 | case ATH6KL_STATE_OFF: |
| 833 | case ATH6KL_STATE_CUTPOWER: |
| 834 | ath6kl_dbg(ATH6KL_DBG_SUSPEND, |
| 835 | "sdio resume configuring sdio\n"); |
| 836 | |
| 837 | /* need to set sdio settings after power is cut from sdio */ |
| 838 | ath6kl_sdio_config(ar); |
| 839 | break; |
| 840 | |
| 841 | case ATH6KL_STATE_ON: |
Kalle Valo | b4b2a0b | 2011-11-01 08:44:44 +0200 | [diff] [blame] | 842 | break; |
| 843 | |
| 844 | case ATH6KL_STATE_DEEPSLEEP: |
| 845 | break; |
Raja Mani | d7c44e0 | 2011-11-07 22:52:46 +0200 | [diff] [blame] | 846 | |
| 847 | case ATH6KL_STATE_WOW: |
| 848 | break; |
Kalle Valo | b4b2a0b | 2011-11-01 08:44:44 +0200 | [diff] [blame] | 849 | } |
| 850 | |
Kalle Valo | 52d81a6 | 2011-11-01 08:44:21 +0200 | [diff] [blame] | 851 | ath6kl_cfg80211_resume(ar); |
Chilam Ng | aa6cffc | 2011-10-05 10:12:52 +0300 | [diff] [blame] | 852 | |
| 853 | return 0; |
| 854 | } |
| 855 | |
Kalle Valo | c711149 | 2011-11-11 12:17:51 +0200 | [diff] [blame] | 856 | /* set the window address register (using 4-byte register access ). */ |
| 857 | static int ath6kl_set_addrwin_reg(struct ath6kl *ar, u32 reg_addr, u32 addr) |
| 858 | { |
| 859 | int status; |
| 860 | u8 addr_val[4]; |
| 861 | s32 i; |
| 862 | |
| 863 | /* |
| 864 | * Write bytes 1,2,3 of the register to set the upper address bytes, |
| 865 | * the LSB is written last to initiate the access cycle |
| 866 | */ |
| 867 | |
| 868 | for (i = 1; i <= 3; i++) { |
| 869 | /* |
| 870 | * Fill the buffer with the address byte value we want to |
| 871 | * hit 4 times. |
| 872 | */ |
| 873 | memset(addr_val, ((u8 *)&addr)[i], 4); |
| 874 | |
| 875 | /* |
| 876 | * Hit each byte of the register address with a 4-byte |
| 877 | * write operation to the same address, this is a harmless |
| 878 | * operation. |
| 879 | */ |
| 880 | status = ath6kl_sdio_read_write_sync(ar, reg_addr + i, addr_val, |
| 881 | 4, HIF_WR_SYNC_BYTE_FIX); |
| 882 | if (status) |
| 883 | break; |
| 884 | } |
| 885 | |
| 886 | if (status) { |
| 887 | ath6kl_err("%s: failed to write initial bytes of 0x%x " |
| 888 | "to window reg: 0x%X\n", __func__, |
| 889 | addr, reg_addr); |
| 890 | return status; |
| 891 | } |
| 892 | |
| 893 | /* |
| 894 | * Write the address register again, this time write the whole |
| 895 | * 4-byte value. The effect here is that the LSB write causes the |
| 896 | * cycle to start, the extra 3 byte write to bytes 1,2,3 has no |
| 897 | * effect since we are writing the same values again |
| 898 | */ |
| 899 | status = ath6kl_sdio_read_write_sync(ar, reg_addr, (u8 *)(&addr), |
| 900 | 4, HIF_WR_SYNC_BYTE_INC); |
| 901 | |
| 902 | if (status) { |
| 903 | ath6kl_err("%s: failed to write 0x%x to window reg: 0x%X\n", |
| 904 | __func__, addr, reg_addr); |
| 905 | return status; |
| 906 | } |
| 907 | |
| 908 | return 0; |
| 909 | } |
| 910 | |
| 911 | static int ath6kl_sdio_diag_read32(struct ath6kl *ar, u32 address, u32 *data) |
| 912 | { |
| 913 | int status; |
| 914 | |
| 915 | /* set window register to start read cycle */ |
| 916 | status = ath6kl_set_addrwin_reg(ar, WINDOW_READ_ADDR_ADDRESS, |
| 917 | address); |
| 918 | |
| 919 | if (status) |
| 920 | return status; |
| 921 | |
| 922 | /* read the data */ |
| 923 | status = ath6kl_sdio_read_write_sync(ar, WINDOW_DATA_ADDRESS, |
| 924 | (u8 *)data, sizeof(u32), HIF_RD_SYNC_BYTE_INC); |
| 925 | if (status) { |
| 926 | ath6kl_err("%s: failed to read from window data addr\n", |
| 927 | __func__); |
| 928 | return status; |
| 929 | } |
| 930 | |
| 931 | return status; |
| 932 | } |
| 933 | |
| 934 | static int ath6kl_sdio_diag_write32(struct ath6kl *ar, u32 address, |
| 935 | __le32 data) |
| 936 | { |
| 937 | int status; |
| 938 | u32 val = (__force u32) data; |
| 939 | |
| 940 | /* set write data */ |
| 941 | status = ath6kl_sdio_read_write_sync(ar, WINDOW_DATA_ADDRESS, |
| 942 | (u8 *) &val, sizeof(u32), HIF_WR_SYNC_BYTE_INC); |
| 943 | if (status) { |
| 944 | ath6kl_err("%s: failed to write 0x%x to window data addr\n", |
| 945 | __func__, data); |
| 946 | return status; |
| 947 | } |
| 948 | |
| 949 | /* set window register, which starts the write cycle */ |
| 950 | return ath6kl_set_addrwin_reg(ar, WINDOW_WRITE_ADDR_ADDRESS, |
| 951 | address); |
| 952 | } |
| 953 | |
Kalle Valo | 66b693c | 2011-11-11 12:17:33 +0200 | [diff] [blame] | 954 | static int ath6kl_sdio_bmi_credits(struct ath6kl *ar) |
| 955 | { |
| 956 | u32 addr; |
| 957 | unsigned long timeout; |
| 958 | int ret; |
| 959 | |
| 960 | ar->bmi.cmd_credits = 0; |
| 961 | |
| 962 | /* Read the counter register to get the command credits */ |
| 963 | addr = COUNT_DEC_ADDRESS + (HTC_MAILBOX_NUM_MAX + ENDPOINT1) * 4; |
| 964 | |
| 965 | timeout = jiffies + msecs_to_jiffies(BMI_COMMUNICATION_TIMEOUT); |
| 966 | while (time_before(jiffies, timeout) && !ar->bmi.cmd_credits) { |
| 967 | |
| 968 | /* |
| 969 | * Hit the credit counter with a 4-byte access, the first byte |
| 970 | * read will hit the counter and cause a decrement, while the |
| 971 | * remaining 3 bytes has no effect. The rationale behind this |
| 972 | * is to make all HIF accesses 4-byte aligned. |
| 973 | */ |
| 974 | ret = ath6kl_sdio_read_write_sync(ar, addr, |
| 975 | (u8 *)&ar->bmi.cmd_credits, 4, |
| 976 | HIF_RD_SYNC_BYTE_INC); |
| 977 | if (ret) { |
| 978 | ath6kl_err("Unable to decrement the command credit " |
| 979 | "count register: %d\n", ret); |
| 980 | return ret; |
| 981 | } |
| 982 | |
| 983 | /* The counter is only 8 bits. |
| 984 | * Ignore anything in the upper 3 bytes |
| 985 | */ |
| 986 | ar->bmi.cmd_credits &= 0xFF; |
| 987 | } |
| 988 | |
| 989 | if (!ar->bmi.cmd_credits) { |
| 990 | ath6kl_err("bmi communication timeout\n"); |
| 991 | return -ETIMEDOUT; |
| 992 | } |
| 993 | |
| 994 | return 0; |
| 995 | } |
| 996 | |
| 997 | static int ath6kl_bmi_get_rx_lkahd(struct ath6kl *ar) |
| 998 | { |
| 999 | unsigned long timeout; |
| 1000 | u32 rx_word = 0; |
| 1001 | int ret = 0; |
| 1002 | |
| 1003 | timeout = jiffies + msecs_to_jiffies(BMI_COMMUNICATION_TIMEOUT); |
| 1004 | while ((time_before(jiffies, timeout)) && !rx_word) { |
| 1005 | ret = ath6kl_sdio_read_write_sync(ar, |
| 1006 | RX_LOOKAHEAD_VALID_ADDRESS, |
| 1007 | (u8 *)&rx_word, sizeof(rx_word), |
| 1008 | HIF_RD_SYNC_BYTE_INC); |
| 1009 | if (ret) { |
| 1010 | ath6kl_err("unable to read RX_LOOKAHEAD_VALID\n"); |
| 1011 | return ret; |
| 1012 | } |
| 1013 | |
| 1014 | /* all we really want is one bit */ |
| 1015 | rx_word &= (1 << ENDPOINT1); |
| 1016 | } |
| 1017 | |
| 1018 | if (!rx_word) { |
| 1019 | ath6kl_err("bmi_recv_buf FIFO empty\n"); |
| 1020 | return -EINVAL; |
| 1021 | } |
| 1022 | |
| 1023 | return ret; |
| 1024 | } |
| 1025 | |
| 1026 | static int ath6kl_sdio_bmi_write(struct ath6kl *ar, u8 *buf, u32 len) |
| 1027 | { |
| 1028 | int ret; |
| 1029 | u32 addr; |
| 1030 | |
| 1031 | ret = ath6kl_sdio_bmi_credits(ar); |
| 1032 | if (ret) |
| 1033 | return ret; |
| 1034 | |
| 1035 | addr = ar->mbox_info.htc_addr; |
| 1036 | |
| 1037 | ret = ath6kl_sdio_read_write_sync(ar, addr, buf, len, |
| 1038 | HIF_WR_SYNC_BYTE_INC); |
| 1039 | if (ret) |
| 1040 | ath6kl_err("unable to send the bmi data to the device\n"); |
| 1041 | |
| 1042 | return ret; |
| 1043 | } |
| 1044 | |
| 1045 | static int ath6kl_sdio_bmi_read(struct ath6kl *ar, u8 *buf, u32 len) |
| 1046 | { |
| 1047 | int ret; |
| 1048 | u32 addr; |
| 1049 | |
| 1050 | /* |
| 1051 | * During normal bootup, small reads may be required. |
| 1052 | * Rather than issue an HIF Read and then wait as the Target |
| 1053 | * adds successive bytes to the FIFO, we wait here until |
| 1054 | * we know that response data is available. |
| 1055 | * |
| 1056 | * This allows us to cleanly timeout on an unexpected |
| 1057 | * Target failure rather than risk problems at the HIF level. |
| 1058 | * In particular, this avoids SDIO timeouts and possibly garbage |
| 1059 | * data on some host controllers. And on an interconnect |
| 1060 | * such as Compact Flash (as well as some SDIO masters) which |
| 1061 | * does not provide any indication on data timeout, it avoids |
| 1062 | * a potential hang or garbage response. |
| 1063 | * |
| 1064 | * Synchronization is more difficult for reads larger than the |
| 1065 | * size of the MBOX FIFO (128B), because the Target is unable |
| 1066 | * to push the 129th byte of data until AFTER the Host posts an |
| 1067 | * HIF Read and removes some FIFO data. So for large reads the |
| 1068 | * Host proceeds to post an HIF Read BEFORE all the data is |
| 1069 | * actually available to read. Fortunately, large BMI reads do |
| 1070 | * not occur in practice -- they're supported for debug/development. |
| 1071 | * |
| 1072 | * So Host/Target BMI synchronization is divided into these cases: |
| 1073 | * CASE 1: length < 4 |
| 1074 | * Should not happen |
| 1075 | * |
| 1076 | * CASE 2: 4 <= length <= 128 |
| 1077 | * Wait for first 4 bytes to be in FIFO |
| 1078 | * If CONSERVATIVE_BMI_READ is enabled, also wait for |
| 1079 | * a BMI command credit, which indicates that the ENTIRE |
| 1080 | * response is available in the the FIFO |
| 1081 | * |
| 1082 | * CASE 3: length > 128 |
| 1083 | * Wait for the first 4 bytes to be in FIFO |
| 1084 | * |
| 1085 | * For most uses, a small timeout should be sufficient and we will |
| 1086 | * usually see a response quickly; but there may be some unusual |
| 1087 | * (debug) cases of BMI_EXECUTE where we want an larger timeout. |
| 1088 | * For now, we use an unbounded busy loop while waiting for |
| 1089 | * BMI_EXECUTE. |
| 1090 | * |
| 1091 | * If BMI_EXECUTE ever needs to support longer-latency execution, |
| 1092 | * especially in production, this code needs to be enhanced to sleep |
| 1093 | * and yield. Also note that BMI_COMMUNICATION_TIMEOUT is currently |
| 1094 | * a function of Host processor speed. |
| 1095 | */ |
| 1096 | if (len >= 4) { /* NB: Currently, always true */ |
| 1097 | ret = ath6kl_bmi_get_rx_lkahd(ar); |
| 1098 | if (ret) |
| 1099 | return ret; |
| 1100 | } |
| 1101 | |
| 1102 | addr = ar->mbox_info.htc_addr; |
| 1103 | ret = ath6kl_sdio_read_write_sync(ar, addr, buf, len, |
| 1104 | HIF_RD_SYNC_BYTE_INC); |
| 1105 | if (ret) { |
| 1106 | ath6kl_err("Unable to read the bmi data from the device: %d\n", |
| 1107 | ret); |
| 1108 | return ret; |
| 1109 | } |
| 1110 | |
| 1111 | return 0; |
| 1112 | } |
| 1113 | |
Kalle Valo | 32a07e4 | 2011-10-30 21:15:57 +0200 | [diff] [blame] | 1114 | static void ath6kl_sdio_stop(struct ath6kl *ar) |
| 1115 | { |
| 1116 | struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar); |
| 1117 | struct bus_request *req, *tmp_req; |
| 1118 | void *context; |
| 1119 | |
| 1120 | /* FIXME: make sure that wq is not queued again */ |
| 1121 | |
| 1122 | cancel_work_sync(&ar_sdio->wr_async_work); |
| 1123 | |
| 1124 | spin_lock_bh(&ar_sdio->wr_async_lock); |
| 1125 | |
| 1126 | list_for_each_entry_safe(req, tmp_req, &ar_sdio->wr_asyncq, list) { |
| 1127 | list_del(&req->list); |
| 1128 | |
| 1129 | if (req->scat_req) { |
| 1130 | /* this is a scatter gather request */ |
| 1131 | req->scat_req->status = -ECANCELED; |
| 1132 | req->scat_req->complete(ar_sdio->ar->htc_target, |
| 1133 | req->scat_req); |
| 1134 | } else { |
| 1135 | context = req->packet; |
| 1136 | ath6kl_sdio_free_bus_req(ar_sdio, req); |
| 1137 | ath6kl_hif_rw_comp_handler(context, -ECANCELED); |
| 1138 | } |
| 1139 | } |
| 1140 | |
| 1141 | spin_unlock_bh(&ar_sdio->wr_async_lock); |
| 1142 | |
| 1143 | WARN_ON(get_queue_depth(&ar_sdio->scat_req) != 4); |
| 1144 | } |
| 1145 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1146 | static const struct ath6kl_hif_ops ath6kl_sdio_ops = { |
| 1147 | .read_write_sync = ath6kl_sdio_read_write_sync, |
| 1148 | .write_async = ath6kl_sdio_write_async, |
| 1149 | .irq_enable = ath6kl_sdio_irq_enable, |
| 1150 | .irq_disable = ath6kl_sdio_irq_disable, |
| 1151 | .scatter_req_get = ath6kl_sdio_scatter_req_get, |
| 1152 | .scatter_req_add = ath6kl_sdio_scatter_req_add, |
| 1153 | .enable_scatter = ath6kl_sdio_enable_scatter, |
Vasanthakumar Thiagarajan | f74a736 | 2011-07-16 20:29:05 +0530 | [diff] [blame] | 1154 | .scat_req_rw = ath6kl_sdio_async_rw_scatter, |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1155 | .cleanup_scatter = ath6kl_sdio_cleanup_scatter, |
Kalle Valo | abcb344 | 2011-07-22 08:26:20 +0300 | [diff] [blame] | 1156 | .suspend = ath6kl_sdio_suspend, |
Chilam Ng | aa6cffc | 2011-10-05 10:12:52 +0300 | [diff] [blame] | 1157 | .resume = ath6kl_sdio_resume, |
Kalle Valo | c711149 | 2011-11-11 12:17:51 +0200 | [diff] [blame] | 1158 | .diag_read32 = ath6kl_sdio_diag_read32, |
| 1159 | .diag_write32 = ath6kl_sdio_diag_write32, |
Kalle Valo | 66b693c | 2011-11-11 12:17:33 +0200 | [diff] [blame] | 1160 | .bmi_read = ath6kl_sdio_bmi_read, |
| 1161 | .bmi_write = ath6kl_sdio_bmi_write, |
Kalle Valo | b2e7569 | 2011-10-27 18:48:14 +0300 | [diff] [blame] | 1162 | .power_on = ath6kl_sdio_power_on, |
| 1163 | .power_off = ath6kl_sdio_power_off, |
Kalle Valo | 32a07e4 | 2011-10-30 21:15:57 +0200 | [diff] [blame] | 1164 | .stop = ath6kl_sdio_stop, |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1165 | }; |
| 1166 | |
Kalle Valo | b4b2a0b | 2011-11-01 08:44:44 +0200 | [diff] [blame] | 1167 | #ifdef CONFIG_PM_SLEEP |
| 1168 | |
| 1169 | /* |
| 1170 | * Empty handlers so that mmc subsystem doesn't remove us entirely during |
| 1171 | * suspend. We instead follow cfg80211 suspend/resume handlers. |
| 1172 | */ |
| 1173 | static int ath6kl_sdio_pm_suspend(struct device *device) |
| 1174 | { |
| 1175 | ath6kl_dbg(ATH6KL_DBG_SUSPEND, "sdio pm suspend\n"); |
| 1176 | |
| 1177 | return 0; |
| 1178 | } |
| 1179 | |
| 1180 | static int ath6kl_sdio_pm_resume(struct device *device) |
| 1181 | { |
| 1182 | ath6kl_dbg(ATH6KL_DBG_SUSPEND, "sdio pm resume\n"); |
| 1183 | |
| 1184 | return 0; |
| 1185 | } |
| 1186 | |
| 1187 | static SIMPLE_DEV_PM_OPS(ath6kl_sdio_pm_ops, ath6kl_sdio_pm_suspend, |
| 1188 | ath6kl_sdio_pm_resume); |
| 1189 | |
| 1190 | #define ATH6KL_SDIO_PM_OPS (&ath6kl_sdio_pm_ops) |
| 1191 | |
| 1192 | #else |
| 1193 | |
| 1194 | #define ATH6KL_SDIO_PM_OPS NULL |
| 1195 | |
| 1196 | #endif /* CONFIG_PM_SLEEP */ |
| 1197 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1198 | static int ath6kl_sdio_probe(struct sdio_func *func, |
| 1199 | const struct sdio_device_id *id) |
| 1200 | { |
| 1201 | int ret; |
| 1202 | struct ath6kl_sdio *ar_sdio; |
| 1203 | struct ath6kl *ar; |
| 1204 | int count; |
| 1205 | |
Kalle Valo | 3ef987b | 2011-10-24 12:18:07 +0300 | [diff] [blame] | 1206 | ath6kl_dbg(ATH6KL_DBG_BOOT, |
| 1207 | "sdio new func %d vendor 0x%x device 0x%x block 0x%x/0x%x\n", |
Kalle Valo | f7325b8 | 2011-09-27 14:30:58 +0300 | [diff] [blame] | 1208 | func->num, func->vendor, func->device, |
| 1209 | func->max_blksize, func->cur_blksize); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1210 | |
| 1211 | ar_sdio = kzalloc(sizeof(struct ath6kl_sdio), GFP_KERNEL); |
| 1212 | if (!ar_sdio) |
| 1213 | return -ENOMEM; |
| 1214 | |
| 1215 | ar_sdio->dma_buffer = kzalloc(HIF_DMA_BUFFER_SIZE, GFP_KERNEL); |
| 1216 | if (!ar_sdio->dma_buffer) { |
| 1217 | ret = -ENOMEM; |
| 1218 | goto err_hif; |
| 1219 | } |
| 1220 | |
| 1221 | ar_sdio->func = func; |
| 1222 | sdio_set_drvdata(func, ar_sdio); |
| 1223 | |
| 1224 | ar_sdio->id = id; |
| 1225 | ar_sdio->is_disabled = true; |
| 1226 | |
| 1227 | spin_lock_init(&ar_sdio->lock); |
| 1228 | spin_lock_init(&ar_sdio->scat_lock); |
| 1229 | spin_lock_init(&ar_sdio->wr_async_lock); |
Raja Mani | fdb2858 | 2011-11-21 12:26:51 +0530 | [diff] [blame] | 1230 | mutex_init(&ar_sdio->dma_buffer_mutex); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1231 | |
| 1232 | INIT_LIST_HEAD(&ar_sdio->scat_req); |
| 1233 | INIT_LIST_HEAD(&ar_sdio->bus_req_freeq); |
| 1234 | INIT_LIST_HEAD(&ar_sdio->wr_asyncq); |
| 1235 | |
| 1236 | INIT_WORK(&ar_sdio->wr_async_work, ath6kl_sdio_write_async_work); |
| 1237 | |
| 1238 | for (count = 0; count < BUS_REQUEST_MAX_NUM; count++) |
| 1239 | ath6kl_sdio_free_bus_req(ar_sdio, &ar_sdio->bus_req[count]); |
| 1240 | |
| 1241 | ar = ath6kl_core_alloc(&ar_sdio->func->dev); |
| 1242 | if (!ar) { |
| 1243 | ath6kl_err("Failed to alloc ath6kl core\n"); |
| 1244 | ret = -ENOMEM; |
| 1245 | goto err_dma; |
| 1246 | } |
| 1247 | |
| 1248 | ar_sdio->ar = ar; |
Kalle Valo | 77eab1e | 2011-11-11 12:18:22 +0200 | [diff] [blame] | 1249 | ar->hif_type = ATH6KL_HIF_TYPE_SDIO; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1250 | ar->hif_priv = ar_sdio; |
| 1251 | ar->hif_ops = &ath6kl_sdio_ops; |
Kalle Valo | 1f4c894 | 2011-11-11 12:17:42 +0200 | [diff] [blame] | 1252 | ar->bmi.max_data_size = 256; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1253 | |
| 1254 | ath6kl_sdio_set_mbox_info(ar); |
| 1255 | |
Kalle Valo | e28e810 | 2011-11-01 08:44:36 +0200 | [diff] [blame] | 1256 | ret = ath6kl_sdio_config(ar); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1257 | if (ret) { |
Kalle Valo | e28e810 | 2011-11-01 08:44:36 +0200 | [diff] [blame] | 1258 | ath6kl_err("Failed to config sdio: %d\n", ret); |
| 1259 | goto err_core_alloc; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1260 | } |
| 1261 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1262 | ret = ath6kl_core_init(ar); |
| 1263 | if (ret) { |
| 1264 | ath6kl_err("Failed to init ath6kl core\n"); |
Kalle Valo | e28e810 | 2011-11-01 08:44:36 +0200 | [diff] [blame] | 1265 | goto err_core_alloc; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1266 | } |
| 1267 | |
| 1268 | return ret; |
| 1269 | |
Vasanthakumar Thiagarajan | 8dafb70 | 2011-10-25 19:33:58 +0530 | [diff] [blame] | 1270 | err_core_alloc: |
| 1271 | ath6kl_core_free(ar_sdio->ar); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1272 | err_dma: |
| 1273 | kfree(ar_sdio->dma_buffer); |
| 1274 | err_hif: |
| 1275 | kfree(ar_sdio); |
| 1276 | |
| 1277 | return ret; |
| 1278 | } |
| 1279 | |
| 1280 | static void ath6kl_sdio_remove(struct sdio_func *func) |
| 1281 | { |
| 1282 | struct ath6kl_sdio *ar_sdio; |
| 1283 | |
Kalle Valo | 3ef987b | 2011-10-24 12:18:07 +0300 | [diff] [blame] | 1284 | ath6kl_dbg(ATH6KL_DBG_BOOT, |
| 1285 | "sdio removed func %d vendor 0x%x device 0x%x\n", |
Kalle Valo | f7325b8 | 2011-09-27 14:30:58 +0300 | [diff] [blame] | 1286 | func->num, func->vendor, func->device); |
| 1287 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1288 | ar_sdio = sdio_get_drvdata(func); |
| 1289 | |
| 1290 | ath6kl_stop_txrx(ar_sdio->ar); |
| 1291 | cancel_work_sync(&ar_sdio->wr_async_work); |
| 1292 | |
Vasanthakumar Thiagarajan | 6db8fa5 | 2011-10-25 19:34:16 +0530 | [diff] [blame] | 1293 | ath6kl_core_cleanup(ar_sdio->ar); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1294 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1295 | kfree(ar_sdio->dma_buffer); |
| 1296 | kfree(ar_sdio); |
| 1297 | } |
| 1298 | |
| 1299 | static const struct sdio_device_id ath6kl_sdio_devices[] = { |
| 1300 | {SDIO_DEVICE(MANUFACTURER_CODE, (MANUFACTURER_ID_AR6003_BASE | 0x0))}, |
| 1301 | {SDIO_DEVICE(MANUFACTURER_CODE, (MANUFACTURER_ID_AR6003_BASE | 0x1))}, |
Naveen Gangadharan | d93e2c2 | 2011-11-11 12:18:14 +0200 | [diff] [blame] | 1302 | {SDIO_DEVICE(MANUFACTURER_CODE, (MANUFACTURER_ID_AR6004_BASE | 0x0))}, |
| 1303 | {SDIO_DEVICE(MANUFACTURER_CODE, (MANUFACTURER_ID_AR6004_BASE | 0x1))}, |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1304 | {}, |
| 1305 | }; |
| 1306 | |
| 1307 | MODULE_DEVICE_TABLE(sdio, ath6kl_sdio_devices); |
| 1308 | |
| 1309 | static struct sdio_driver ath6kl_sdio_driver = { |
Kalle Valo | fde5776 | 2011-11-11 12:18:45 +0200 | [diff] [blame] | 1310 | .name = "ath6kl_sdio", |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1311 | .id_table = ath6kl_sdio_devices, |
| 1312 | .probe = ath6kl_sdio_probe, |
| 1313 | .remove = ath6kl_sdio_remove, |
Kalle Valo | b4b2a0b | 2011-11-01 08:44:44 +0200 | [diff] [blame] | 1314 | .drv.pm = ATH6KL_SDIO_PM_OPS, |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1315 | }; |
| 1316 | |
| 1317 | static int __init ath6kl_sdio_init(void) |
| 1318 | { |
| 1319 | int ret; |
| 1320 | |
| 1321 | ret = sdio_register_driver(&ath6kl_sdio_driver); |
| 1322 | if (ret) |
| 1323 | ath6kl_err("sdio driver registration failed: %d\n", ret); |
| 1324 | |
| 1325 | return ret; |
| 1326 | } |
| 1327 | |
| 1328 | static void __exit ath6kl_sdio_exit(void) |
| 1329 | { |
| 1330 | sdio_unregister_driver(&ath6kl_sdio_driver); |
| 1331 | } |
| 1332 | |
| 1333 | module_init(ath6kl_sdio_init); |
| 1334 | module_exit(ath6kl_sdio_exit); |
| 1335 | |
| 1336 | MODULE_AUTHOR("Atheros Communications, Inc."); |
| 1337 | MODULE_DESCRIPTION("Driver support for Atheros AR600x SDIO devices"); |
| 1338 | MODULE_LICENSE("Dual BSD/GPL"); |
| 1339 | |
Kalle Valo | 0d0192b | 2011-11-14 19:31:07 +0200 | [diff] [blame] | 1340 | MODULE_FIRMWARE(AR6003_HW_2_0_OTP_FILE); |
| 1341 | MODULE_FIRMWARE(AR6003_HW_2_0_FIRMWARE_FILE); |
| 1342 | MODULE_FIRMWARE(AR6003_HW_2_0_PATCH_FILE); |
| 1343 | MODULE_FIRMWARE(AR6003_HW_2_0_BOARD_DATA_FILE); |
| 1344 | MODULE_FIRMWARE(AR6003_HW_2_0_DEFAULT_BOARD_DATA_FILE); |
| 1345 | MODULE_FIRMWARE(AR6003_HW_2_1_1_OTP_FILE); |
| 1346 | MODULE_FIRMWARE(AR6003_HW_2_1_1_FIRMWARE_FILE); |
| 1347 | MODULE_FIRMWARE(AR6003_HW_2_1_1_PATCH_FILE); |
| 1348 | MODULE_FIRMWARE(AR6003_HW_2_1_1_BOARD_DATA_FILE); |
| 1349 | MODULE_FIRMWARE(AR6003_HW_2_1_1_DEFAULT_BOARD_DATA_FILE); |
Kalle Valo | f0ea5d5 | 2011-11-14 19:31:15 +0200 | [diff] [blame] | 1350 | MODULE_FIRMWARE(AR6004_HW_1_0_FIRMWARE_FILE); |
| 1351 | MODULE_FIRMWARE(AR6004_HW_1_0_BOARD_DATA_FILE); |
| 1352 | MODULE_FIRMWARE(AR6004_HW_1_0_DEFAULT_BOARD_DATA_FILE); |
| 1353 | MODULE_FIRMWARE(AR6004_HW_1_1_FIRMWARE_FILE); |
| 1354 | MODULE_FIRMWARE(AR6004_HW_1_1_BOARD_DATA_FILE); |
| 1355 | MODULE_FIRMWARE(AR6004_HW_1_1_DEFAULT_BOARD_DATA_FILE); |