Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2010 Broadcom Corporation |
| 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 ANY |
| 11 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
| 13 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 14 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | */ |
| 16 | |
| 17 | #include <linux/types.h> |
| 18 | #include <linux/kernel.h> |
| 19 | #include <linux/kthread.h> |
| 20 | #include <linux/printk.h> |
| 21 | #include <linux/pci_ids.h> |
| 22 | #include <linux/netdevice.h> |
| 23 | #include <linux/interrupt.h> |
| 24 | #include <linux/sched.h> |
| 25 | #include <linux/mmc/sdio.h> |
| 26 | #include <linux/mmc/sdio_func.h> |
| 27 | #include <linux/mmc/card.h> |
| 28 | #include <linux/semaphore.h> |
| 29 | #include <linux/firmware.h> |
Stephen Rothwell | b7a57e7 | 2011-10-12 21:35:07 +0200 | [diff] [blame] | 30 | #include <linux/module.h> |
Franky Lin | 99ba15c | 2011-11-04 22:23:42 +0100 | [diff] [blame] | 31 | #include <linux/bcma/bcma.h> |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 32 | #include <linux/debugfs.h> |
Arend van Spriel | 8dc0181 | 2012-06-21 11:33:32 +0200 | [diff] [blame] | 33 | #include <linux/vmalloc.h> |
Hante Meuleman | 668761a | 2013-04-12 10:55:55 +0200 | [diff] [blame] | 34 | #include <linux/platform_data/brcmfmac-sdio.h> |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 35 | #include <linux/moduleparam.h> |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 36 | #include <asm/unaligned.h> |
| 37 | #include <defs.h> |
| 38 | #include <brcmu_wifi.h> |
| 39 | #include <brcmu_utils.h> |
| 40 | #include <brcm_hw_ids.h> |
| 41 | #include <soc.h> |
| 42 | #include "sdio_host.h" |
Franky Lin | a83369b | 2011-11-04 22:23:28 +0100 | [diff] [blame] | 43 | #include "sdio_chip.h" |
Hante Meuleman | a74d036 | 2014-01-13 22:20:22 +0100 | [diff] [blame] | 44 | #include "nvram.h" |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 45 | |
| 46 | #define DCMD_RESP_TIMEOUT 2000 /* In milli second */ |
| 47 | |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 48 | #ifdef DEBUG |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 49 | |
| 50 | #define BRCMF_TRAP_INFO_SIZE 80 |
| 51 | |
| 52 | #define CBUF_LEN (128) |
| 53 | |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 54 | /* Device console log buffer state */ |
| 55 | #define CONSOLE_BUFFER_MAX 2024 |
| 56 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 57 | struct rte_log_le { |
| 58 | __le32 buf; /* Can't be pointer on (64-bit) hosts */ |
| 59 | __le32 buf_size; |
| 60 | __le32 idx; |
| 61 | char *_buf_compat; /* Redundant pointer for backward compat. */ |
| 62 | }; |
| 63 | |
| 64 | struct rte_console { |
| 65 | /* Virtual UART |
| 66 | * When there is no UART (e.g. Quickturn), |
| 67 | * the host should write a complete |
| 68 | * input line directly into cbuf and then write |
| 69 | * the length into vcons_in. |
| 70 | * This may also be used when there is a real UART |
| 71 | * (at risk of conflicting with |
| 72 | * the real UART). vcons_out is currently unused. |
| 73 | */ |
| 74 | uint vcons_in; |
| 75 | uint vcons_out; |
| 76 | |
| 77 | /* Output (logging) buffer |
| 78 | * Console output is written to a ring buffer log_buf at index log_idx. |
| 79 | * The host may read the output when it sees log_idx advance. |
| 80 | * Output will be lost if the output wraps around faster than the host |
| 81 | * polls. |
| 82 | */ |
| 83 | struct rte_log_le log_le; |
| 84 | |
| 85 | /* Console input line buffer |
| 86 | * Characters are read one at a time into cbuf |
| 87 | * until <CR> is received, then |
| 88 | * the buffer is processed as a command line. |
| 89 | * Also used for virtual UART. |
| 90 | */ |
| 91 | uint cbuf_idx; |
| 92 | char cbuf[CBUF_LEN]; |
| 93 | }; |
| 94 | |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 95 | #endif /* DEBUG */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 96 | #include <chipcommon.h> |
| 97 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 98 | #include "dhd_bus.h" |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 99 | #include "dhd_dbg.h" |
Arend van Spriel | 40c1c24 | 2013-04-05 10:57:44 +0200 | [diff] [blame] | 100 | #include "tracepoint.h" |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 101 | |
| 102 | #define TXQLEN 2048 /* bulk tx queue length */ |
| 103 | #define TXHI (TXQLEN - 256) /* turn on flow control above TXHI */ |
| 104 | #define TXLOW (TXHI - 256) /* turn off flow control below TXLOW */ |
| 105 | #define PRIOMASK 7 |
| 106 | |
| 107 | #define TXRETRIES 2 /* # of retries for tx frames */ |
| 108 | |
| 109 | #define BRCMF_RXBOUND 50 /* Default for max rx frames in |
| 110 | one scheduling */ |
| 111 | |
| 112 | #define BRCMF_TXBOUND 20 /* Default for max tx frames in |
| 113 | one scheduling */ |
| 114 | |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 115 | #define BRCMF_DEFAULT_TXGLOM_SIZE 32 /* max tx frames in glom chain */ |
| 116 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 117 | #define BRCMF_TXMINMAX 1 /* Max tx frames if rx still pending */ |
| 118 | |
| 119 | #define MEMBLOCK 2048 /* Block size used for downloading |
| 120 | of dongle image */ |
| 121 | #define MAX_DATA_BUF (32 * 1024) /* Must be large enough to hold |
| 122 | biggest possible glom */ |
| 123 | |
| 124 | #define BRCMF_FIRSTREAD (1 << 6) |
| 125 | |
| 126 | |
| 127 | /* SBSDIO_DEVICE_CTL */ |
| 128 | |
| 129 | /* 1: device will assert busy signal when receiving CMD53 */ |
| 130 | #define SBSDIO_DEVCTL_SETBUSY 0x01 |
| 131 | /* 1: assertion of sdio interrupt is synchronous to the sdio clock */ |
| 132 | #define SBSDIO_DEVCTL_SPI_INTR_SYNC 0x02 |
| 133 | /* 1: mask all interrupts to host except the chipActive (rev 8) */ |
| 134 | #define SBSDIO_DEVCTL_CA_INT_ONLY 0x04 |
| 135 | /* 1: isolate internal sdio signals, put external pads in tri-state; requires |
| 136 | * sdio bus power cycle to clear (rev 9) */ |
| 137 | #define SBSDIO_DEVCTL_PADS_ISO 0x08 |
| 138 | /* Force SD->SB reset mapping (rev 11) */ |
| 139 | #define SBSDIO_DEVCTL_SB_RST_CTL 0x30 |
| 140 | /* Determined by CoreControl bit */ |
| 141 | #define SBSDIO_DEVCTL_RST_CORECTL 0x00 |
| 142 | /* Force backplane reset */ |
| 143 | #define SBSDIO_DEVCTL_RST_BPRESET 0x10 |
| 144 | /* Force no backplane reset */ |
| 145 | #define SBSDIO_DEVCTL_RST_NOBPRESET 0x20 |
| 146 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 147 | /* direct(mapped) cis space */ |
| 148 | |
| 149 | /* MAPPED common CIS address */ |
| 150 | #define SBSDIO_CIS_BASE_COMMON 0x1000 |
| 151 | /* maximum bytes in one CIS */ |
| 152 | #define SBSDIO_CIS_SIZE_LIMIT 0x200 |
| 153 | /* cis offset addr is < 17 bits */ |
| 154 | #define SBSDIO_CIS_OFT_ADDR_MASK 0x1FFFF |
| 155 | |
| 156 | /* manfid tuple length, include tuple, link bytes */ |
| 157 | #define SBSDIO_CIS_MANFID_TUPLE_LEN 6 |
| 158 | |
| 159 | /* intstatus */ |
| 160 | #define I_SMB_SW0 (1 << 0) /* To SB Mail S/W interrupt 0 */ |
| 161 | #define I_SMB_SW1 (1 << 1) /* To SB Mail S/W interrupt 1 */ |
| 162 | #define I_SMB_SW2 (1 << 2) /* To SB Mail S/W interrupt 2 */ |
| 163 | #define I_SMB_SW3 (1 << 3) /* To SB Mail S/W interrupt 3 */ |
| 164 | #define I_SMB_SW_MASK 0x0000000f /* To SB Mail S/W interrupts mask */ |
| 165 | #define I_SMB_SW_SHIFT 0 /* To SB Mail S/W interrupts shift */ |
| 166 | #define I_HMB_SW0 (1 << 4) /* To Host Mail S/W interrupt 0 */ |
| 167 | #define I_HMB_SW1 (1 << 5) /* To Host Mail S/W interrupt 1 */ |
| 168 | #define I_HMB_SW2 (1 << 6) /* To Host Mail S/W interrupt 2 */ |
| 169 | #define I_HMB_SW3 (1 << 7) /* To Host Mail S/W interrupt 3 */ |
| 170 | #define I_HMB_SW_MASK 0x000000f0 /* To Host Mail S/W interrupts mask */ |
| 171 | #define I_HMB_SW_SHIFT 4 /* To Host Mail S/W interrupts shift */ |
| 172 | #define I_WR_OOSYNC (1 << 8) /* Write Frame Out Of Sync */ |
| 173 | #define I_RD_OOSYNC (1 << 9) /* Read Frame Out Of Sync */ |
| 174 | #define I_PC (1 << 10) /* descriptor error */ |
| 175 | #define I_PD (1 << 11) /* data error */ |
| 176 | #define I_DE (1 << 12) /* Descriptor protocol Error */ |
| 177 | #define I_RU (1 << 13) /* Receive descriptor Underflow */ |
| 178 | #define I_RO (1 << 14) /* Receive fifo Overflow */ |
| 179 | #define I_XU (1 << 15) /* Transmit fifo Underflow */ |
| 180 | #define I_RI (1 << 16) /* Receive Interrupt */ |
| 181 | #define I_BUSPWR (1 << 17) /* SDIO Bus Power Change (rev 9) */ |
| 182 | #define I_XMTDATA_AVAIL (1 << 23) /* bits in fifo */ |
| 183 | #define I_XI (1 << 24) /* Transmit Interrupt */ |
| 184 | #define I_RF_TERM (1 << 25) /* Read Frame Terminate */ |
| 185 | #define I_WF_TERM (1 << 26) /* Write Frame Terminate */ |
| 186 | #define I_PCMCIA_XU (1 << 27) /* PCMCIA Transmit FIFO Underflow */ |
| 187 | #define I_SBINT (1 << 28) /* sbintstatus Interrupt */ |
| 188 | #define I_CHIPACTIVE (1 << 29) /* chip from doze to active state */ |
| 189 | #define I_SRESET (1 << 30) /* CCCR RES interrupt */ |
| 190 | #define I_IOE2 (1U << 31) /* CCCR IOE2 Bit Changed */ |
| 191 | #define I_ERRORS (I_PC | I_PD | I_DE | I_RU | I_RO | I_XU) |
| 192 | #define I_DMA (I_RI | I_XI | I_ERRORS) |
| 193 | |
| 194 | /* corecontrol */ |
| 195 | #define CC_CISRDY (1 << 0) /* CIS Ready */ |
| 196 | #define CC_BPRESEN (1 << 1) /* CCCR RES signal */ |
| 197 | #define CC_F2RDY (1 << 2) /* set CCCR IOR2 bit */ |
| 198 | #define CC_CLRPADSISO (1 << 3) /* clear SDIO pads isolation */ |
| 199 | #define CC_XMTDATAAVAIL_MODE (1 << 4) |
| 200 | #define CC_XMTDATAAVAIL_CTRL (1 << 5) |
| 201 | |
| 202 | /* SDA_FRAMECTRL */ |
| 203 | #define SFC_RF_TERM (1 << 0) /* Read Frame Terminate */ |
| 204 | #define SFC_WF_TERM (1 << 1) /* Write Frame Terminate */ |
| 205 | #define SFC_CRC4WOOS (1 << 2) /* CRC error for write out of sync */ |
| 206 | #define SFC_ABORTALL (1 << 3) /* Abort all in-progress frames */ |
| 207 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 208 | /* |
| 209 | * Software allocation of To SB Mailbox resources |
| 210 | */ |
| 211 | |
| 212 | /* tosbmailbox bits corresponding to intstatus bits */ |
| 213 | #define SMB_NAK (1 << 0) /* Frame NAK */ |
| 214 | #define SMB_INT_ACK (1 << 1) /* Host Interrupt ACK */ |
| 215 | #define SMB_USE_OOB (1 << 2) /* Use OOB Wakeup */ |
| 216 | #define SMB_DEV_INT (1 << 3) /* Miscellaneous Interrupt */ |
| 217 | |
| 218 | /* tosbmailboxdata */ |
| 219 | #define SMB_DATA_VERSION_SHIFT 16 /* host protocol version */ |
| 220 | |
| 221 | /* |
| 222 | * Software allocation of To Host Mailbox resources |
| 223 | */ |
| 224 | |
| 225 | /* intstatus bits */ |
| 226 | #define I_HMB_FC_STATE I_HMB_SW0 /* Flow Control State */ |
| 227 | #define I_HMB_FC_CHANGE I_HMB_SW1 /* Flow Control State Changed */ |
| 228 | #define I_HMB_FRAME_IND I_HMB_SW2 /* Frame Indication */ |
| 229 | #define I_HMB_HOST_INT I_HMB_SW3 /* Miscellaneous Interrupt */ |
| 230 | |
| 231 | /* tohostmailboxdata */ |
| 232 | #define HMB_DATA_NAKHANDLED 1 /* retransmit NAK'd frame */ |
| 233 | #define HMB_DATA_DEVREADY 2 /* talk to host after enable */ |
| 234 | #define HMB_DATA_FC 4 /* per prio flowcontrol update flag */ |
| 235 | #define HMB_DATA_FWREADY 8 /* fw ready for protocol activity */ |
| 236 | |
| 237 | #define HMB_DATA_FCDATA_MASK 0xff000000 |
| 238 | #define HMB_DATA_FCDATA_SHIFT 24 |
| 239 | |
| 240 | #define HMB_DATA_VERSION_MASK 0x00ff0000 |
| 241 | #define HMB_DATA_VERSION_SHIFT 16 |
| 242 | |
| 243 | /* |
| 244 | * Software-defined protocol header |
| 245 | */ |
| 246 | |
| 247 | /* Current protocol version */ |
| 248 | #define SDPCM_PROT_VERSION 4 |
| 249 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 250 | /* |
| 251 | * Shared structure between dongle and the host. |
| 252 | * The structure contains pointers to trap or assert information. |
| 253 | */ |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 254 | #define SDPCM_SHARED_VERSION 0x0003 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 255 | #define SDPCM_SHARED_VERSION_MASK 0x00FF |
| 256 | #define SDPCM_SHARED_ASSERT_BUILT 0x0100 |
| 257 | #define SDPCM_SHARED_ASSERT 0x0200 |
| 258 | #define SDPCM_SHARED_TRAP 0x0400 |
| 259 | |
| 260 | /* Space for header read, limit for data packets */ |
| 261 | #define MAX_HDR_READ (1 << 6) |
| 262 | #define MAX_RX_DATASZ 2048 |
| 263 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 264 | /* Bump up limit on waiting for HT to account for first startup; |
| 265 | * if the image is doing a CRC calculation before programming the PMU |
| 266 | * for HT availability, it could take a couple hundred ms more, so |
| 267 | * max out at a 1 second (1000000us). |
| 268 | */ |
| 269 | #undef PMU_MAX_TRANSITION_DLY |
| 270 | #define PMU_MAX_TRANSITION_DLY 1000000 |
| 271 | |
| 272 | /* Value for ChipClockCSR during initial setup */ |
| 273 | #define BRCMF_INIT_CLKCTL1 (SBSDIO_FORCE_HW_CLKREQ_OFF | \ |
| 274 | SBSDIO_ALP_AVAIL_REQ) |
| 275 | |
| 276 | /* Flags for SDH calls */ |
| 277 | #define F2SYNC (SDIO_REQ_4BYTE | SDIO_REQ_FIXED) |
| 278 | |
Franky Lin | 382a9e0 | 2011-12-16 18:37:18 -0800 | [diff] [blame] | 279 | #define BRCMF_IDLE_IMMEDIATE (-1) /* Enter idle immediately */ |
| 280 | #define BRCMF_IDLE_ACTIVE 0 /* Do not request any SD clock change |
| 281 | * when idle |
| 282 | */ |
| 283 | #define BRCMF_IDLE_INTERVAL 1 |
| 284 | |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 285 | #define KSO_WAIT_US 50 |
| 286 | #define MAX_KSO_ATTEMPTS (PMU_MAX_TRANSITION_DLY/KSO_WAIT_US) |
| 287 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 288 | /* |
| 289 | * Conversion of 802.1D priority to precedence level |
| 290 | */ |
| 291 | static uint prio2prec(u32 prio) |
| 292 | { |
| 293 | return (prio == PRIO_8021D_NONE || prio == PRIO_8021D_BE) ? |
| 294 | (prio^2) : prio; |
| 295 | } |
| 296 | |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 297 | #ifdef DEBUG |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 298 | /* Device console log buffer state */ |
| 299 | struct brcmf_console { |
| 300 | uint count; /* Poll interval msec counter */ |
| 301 | uint log_addr; /* Log struct address (fixed) */ |
| 302 | struct rte_log_le log_le; /* Log struct (host copy) */ |
| 303 | uint bufsize; /* Size of log buffer */ |
| 304 | u8 *buf; /* Log buffer (host copy) */ |
| 305 | uint last; /* Last buffer read index */ |
| 306 | }; |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 307 | |
| 308 | struct brcmf_trap_info { |
| 309 | __le32 type; |
| 310 | __le32 epc; |
| 311 | __le32 cpsr; |
| 312 | __le32 spsr; |
| 313 | __le32 r0; /* a1 */ |
| 314 | __le32 r1; /* a2 */ |
| 315 | __le32 r2; /* a3 */ |
| 316 | __le32 r3; /* a4 */ |
| 317 | __le32 r4; /* v1 */ |
| 318 | __le32 r5; /* v2 */ |
| 319 | __le32 r6; /* v3 */ |
| 320 | __le32 r7; /* v4 */ |
| 321 | __le32 r8; /* v5 */ |
| 322 | __le32 r9; /* sb/v6 */ |
| 323 | __le32 r10; /* sl/v7 */ |
| 324 | __le32 r11; /* fp/v8 */ |
| 325 | __le32 r12; /* ip */ |
| 326 | __le32 r13; /* sp */ |
| 327 | __le32 r14; /* lr */ |
| 328 | __le32 pc; /* r15 */ |
| 329 | }; |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 330 | #endif /* DEBUG */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 331 | |
| 332 | struct sdpcm_shared { |
| 333 | u32 flags; |
| 334 | u32 trap_addr; |
| 335 | u32 assert_exp_addr; |
| 336 | u32 assert_file_addr; |
| 337 | u32 assert_line; |
| 338 | u32 console_addr; /* Address of struct rte_console */ |
| 339 | u32 msgtrace_addr; |
| 340 | u8 tag[32]; |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 341 | u32 brpt_addr; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 342 | }; |
| 343 | |
| 344 | struct sdpcm_shared_le { |
| 345 | __le32 flags; |
| 346 | __le32 trap_addr; |
| 347 | __le32 assert_exp_addr; |
| 348 | __le32 assert_file_addr; |
| 349 | __le32 assert_line; |
| 350 | __le32 console_addr; /* Address of struct rte_console */ |
| 351 | __le32 msgtrace_addr; |
| 352 | u8 tag[32]; |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 353 | __le32 brpt_addr; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 354 | }; |
| 355 | |
Franky Lin | 6bc5231 | 2013-08-10 12:27:28 +0200 | [diff] [blame] | 356 | /* dongle SDIO bus specific header info */ |
| 357 | struct brcmf_sdio_hdrinfo { |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 358 | u8 seq_num; |
| 359 | u8 channel; |
| 360 | u16 len; |
| 361 | u16 len_left; |
| 362 | u16 len_nxtfrm; |
| 363 | u8 dat_offset; |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 364 | bool lastfrm; |
| 365 | u16 tail_pad; |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 366 | }; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 367 | |
| 368 | /* misc chip info needed by some of the routines */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 369 | /* Private data for SDIO bus interaction */ |
Franky Lin | e92eedf | 2011-11-22 17:21:50 -0800 | [diff] [blame] | 370 | struct brcmf_sdio { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 371 | struct brcmf_sdio_dev *sdiodev; /* sdio device handler */ |
| 372 | struct chip_info *ci; /* Chip info struct */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 373 | |
| 374 | u32 ramsize; /* Size of RAM in SOCRAM (bytes) */ |
| 375 | |
| 376 | u32 hostintmask; /* Copy of Host Interrupt Mask */ |
Franky Lin | 4531603 | 2012-09-13 21:12:03 +0200 | [diff] [blame] | 377 | atomic_t intstatus; /* Intstatus bits (events) pending */ |
| 378 | atomic_t fcstate; /* State of dongle flow-control */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 379 | |
| 380 | uint blocksize; /* Block size of SDIO transfers */ |
| 381 | uint roundup; /* Max roundup limit */ |
| 382 | |
| 383 | struct pktq txq; /* Queue length used for flow-control */ |
| 384 | u8 flowcontrol; /* per prio flow control bitmask */ |
| 385 | u8 tx_seq; /* Transmit sequence number (next) */ |
| 386 | u8 tx_max; /* Maximum transmit sequence allowed */ |
| 387 | |
Arend van Spriel | 9b2d2f2 | 2013-11-29 12:25:14 +0100 | [diff] [blame] | 388 | u8 *hdrbuf; /* buffer for handling rx frame */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 389 | u8 *rxhdr; /* Header of current rx frame (in hdrbuf) */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 390 | u8 rx_seq; /* Receive sequence number (expected) */ |
Franky Lin | 6bc5231 | 2013-08-10 12:27:28 +0200 | [diff] [blame] | 391 | struct brcmf_sdio_hdrinfo cur_read; |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 392 | /* info of current read frame */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 393 | bool rxskip; /* Skip receive (awaiting NAK ACK) */ |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 394 | bool rxpending; /* Data frame pending in dongle */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 395 | |
| 396 | uint rxbound; /* Rx frames to read before resched */ |
| 397 | uint txbound; /* Tx frames to send before resched */ |
| 398 | uint txminmax; |
| 399 | |
| 400 | struct sk_buff *glomd; /* Packet containing glomming descriptor */ |
Arend van Spriel | b83db86 | 2011-10-19 12:51:09 +0200 | [diff] [blame] | 401 | struct sk_buff_head glom; /* Packet list for glommed superframe */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 402 | uint glomerr; /* Glom packet read errors */ |
| 403 | |
| 404 | u8 *rxbuf; /* Buffer for receiving control packets */ |
| 405 | uint rxblen; /* Allocated length of rxbuf */ |
| 406 | u8 *rxctl; /* Aligned pointer into rxbuf */ |
Franky Lin | dd43a01 | 2012-11-05 16:22:22 -0800 | [diff] [blame] | 407 | u8 *rxctl_orig; /* pointer for freeing rxctl */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 408 | uint rxlen; /* Length of valid data in buffer */ |
Franky Lin | dd43a01 | 2012-11-05 16:22:22 -0800 | [diff] [blame] | 409 | spinlock_t rxctl_lock; /* protection lock for ctrl frame resources */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 410 | |
| 411 | u8 sdpcm_ver; /* Bus protocol reported by dongle */ |
| 412 | |
| 413 | bool intr; /* Use interrupts */ |
| 414 | bool poll; /* Use polling */ |
Franky Lin | 1d38227 | 2012-09-13 21:11:59 +0200 | [diff] [blame] | 415 | atomic_t ipend; /* Device interrupt is pending */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 416 | uint spurious; /* Count of spurious interrupts */ |
| 417 | uint pollrate; /* Ticks between device polls */ |
| 418 | uint polltick; /* Tick counter */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 419 | |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 420 | #ifdef DEBUG |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 421 | uint console_interval; |
| 422 | struct brcmf_console console; /* Console output polling support */ |
| 423 | uint console_addr; /* Console address from shared struct */ |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 424 | #endif /* DEBUG */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 425 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 426 | uint clkstate; /* State of sd and backplane clock(s) */ |
| 427 | bool activity; /* Activity flag for clock down */ |
| 428 | s32 idletime; /* Control for activity timeout */ |
| 429 | s32 idlecount; /* Activity timeout counter */ |
| 430 | s32 idleclock; /* How to set bus driver when idle */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 431 | bool rxflow_mode; /* Rx flow control mode */ |
| 432 | bool rxflow; /* Is rx flow control on */ |
| 433 | bool alp_only; /* Don't use HT clock (ALP only) */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 434 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 435 | u8 *ctrl_frame_buf; |
| 436 | u32 ctrl_frame_len; |
| 437 | bool ctrl_frame_stat; |
| 438 | |
| 439 | spinlock_t txqlock; |
| 440 | wait_queue_head_t ctrl_wait; |
| 441 | wait_queue_head_t dcmd_resp_wait; |
| 442 | |
| 443 | struct timer_list timer; |
| 444 | struct completion watchdog_wait; |
| 445 | struct task_struct *watchdog_tsk; |
| 446 | bool wd_timer_valid; |
| 447 | uint save_ms; |
| 448 | |
Franky Lin | f1e68c2 | 2012-09-13 21:12:00 +0200 | [diff] [blame] | 449 | struct workqueue_struct *brcmf_wq; |
| 450 | struct work_struct datawork; |
Arend van Spriel | fccfe93 | 2013-06-18 13:29:26 +0200 | [diff] [blame] | 451 | atomic_t dpc_tskcnt; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 452 | |
Franky Lin | c8bf348 | 2011-12-16 18:37:08 -0800 | [diff] [blame] | 453 | bool txoff; /* Transmit flow-controlled */ |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 454 | struct brcmf_sdio_count sdcnt; |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 455 | bool sr_enabled; /* SaveRestore enabled */ |
| 456 | bool sleeping; /* SDIO bus sleeping */ |
Franky Lin | 706478c | 2013-08-10 12:27:29 +0200 | [diff] [blame] | 457 | |
| 458 | u8 tx_hdrlen; /* sdio bus header length for tx packet */ |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 459 | bool txglom; /* host tx glomming enable flag */ |
| 460 | struct sk_buff *txglom_sgpad; /* scatter-gather padding buffer */ |
Arend van Spriel | e217d1c | 2013-11-29 12:25:13 +0100 | [diff] [blame] | 461 | u16 head_align; /* buffer pointer alignment */ |
| 462 | u16 sgentry_align; /* scatter-gather buffer alignment */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 463 | }; |
| 464 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 465 | /* clkstate */ |
| 466 | #define CLK_NONE 0 |
| 467 | #define CLK_SDONLY 1 |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 468 | #define CLK_PENDING 2 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 469 | #define CLK_AVAIL 3 |
| 470 | |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 471 | #ifdef DEBUG |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 472 | static int qcount[NUMPRIO]; |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 473 | #endif /* DEBUG */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 474 | |
Hante Meuleman | 668761a | 2013-04-12 10:55:55 +0200 | [diff] [blame] | 475 | #define DEFAULT_SDIO_DRIVE_STRENGTH 6 /* in milliamps */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 476 | |
| 477 | #define RETRYCHAN(chan) ((chan) == SDPCM_EVENT_CHANNEL) |
| 478 | |
| 479 | /* Retry count for register access failures */ |
| 480 | static const uint retry_limit = 2; |
| 481 | |
| 482 | /* Limit on rounding up frames */ |
| 483 | static const uint max_roundup = 512; |
| 484 | |
| 485 | #define ALIGNMENT 4 |
| 486 | |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 487 | static int brcmf_sdio_txglomsz = BRCMF_DEFAULT_TXGLOM_SIZE; |
| 488 | module_param_named(txglomsz, brcmf_sdio_txglomsz, int, 0); |
| 489 | MODULE_PARM_DESC(txglomsz, "maximum tx packet chain size [SDIO]"); |
| 490 | |
Franky Lin | 9d7d6f9 | 2012-10-22 10:36:24 -0700 | [diff] [blame] | 491 | enum brcmf_sdio_frmtype { |
| 492 | BRCMF_SDIO_FT_NORMAL, |
| 493 | BRCMF_SDIO_FT_SUPER, |
| 494 | BRCMF_SDIO_FT_SUB, |
| 495 | }; |
| 496 | |
Hante Meuleman | f2c44fe | 2013-09-25 13:05:45 +0200 | [diff] [blame] | 497 | #define BCM43143_FIRMWARE_NAME "brcm/brcmfmac43143-sdio.bin" |
| 498 | #define BCM43143_NVRAM_NAME "brcm/brcmfmac43143-sdio.txt" |
| 499 | #define BCM43241B0_FIRMWARE_NAME "brcm/brcmfmac43241b0-sdio.bin" |
| 500 | #define BCM43241B0_NVRAM_NAME "brcm/brcmfmac43241b0-sdio.txt" |
| 501 | #define BCM43241B4_FIRMWARE_NAME "brcm/brcmfmac43241b4-sdio.bin" |
| 502 | #define BCM43241B4_NVRAM_NAME "brcm/brcmfmac43241b4-sdio.txt" |
| 503 | #define BCM4329_FIRMWARE_NAME "brcm/brcmfmac4329-sdio.bin" |
| 504 | #define BCM4329_NVRAM_NAME "brcm/brcmfmac4329-sdio.txt" |
| 505 | #define BCM4330_FIRMWARE_NAME "brcm/brcmfmac4330-sdio.bin" |
| 506 | #define BCM4330_NVRAM_NAME "brcm/brcmfmac4330-sdio.txt" |
| 507 | #define BCM4334_FIRMWARE_NAME "brcm/brcmfmac4334-sdio.bin" |
| 508 | #define BCM4334_NVRAM_NAME "brcm/brcmfmac4334-sdio.txt" |
| 509 | #define BCM4335_FIRMWARE_NAME "brcm/brcmfmac4335-sdio.bin" |
| 510 | #define BCM4335_NVRAM_NAME "brcm/brcmfmac4335-sdio.txt" |
Arend van Spriel | 11e69c3 | 2014-01-08 10:49:33 +0100 | [diff] [blame] | 511 | #define BCM43362_FIRMWARE_NAME "brcm/brcmfmac43362-sdio.bin" |
| 512 | #define BCM43362_NVRAM_NAME "brcm/brcmfmac43362-sdio.txt" |
Franky Lin | bed89b6 | 2013-11-29 12:25:09 +0100 | [diff] [blame] | 513 | #define BCM4339_FIRMWARE_NAME "brcm/brcmfmac4339-sdio.bin" |
| 514 | #define BCM4339_NVRAM_NAME "brcm/brcmfmac4339-sdio.txt" |
Hante Meuleman | f2c44fe | 2013-09-25 13:05:45 +0200 | [diff] [blame] | 515 | |
| 516 | MODULE_FIRMWARE(BCM43143_FIRMWARE_NAME); |
| 517 | MODULE_FIRMWARE(BCM43143_NVRAM_NAME); |
| 518 | MODULE_FIRMWARE(BCM43241B0_FIRMWARE_NAME); |
| 519 | MODULE_FIRMWARE(BCM43241B0_NVRAM_NAME); |
| 520 | MODULE_FIRMWARE(BCM43241B4_FIRMWARE_NAME); |
| 521 | MODULE_FIRMWARE(BCM43241B4_NVRAM_NAME); |
| 522 | MODULE_FIRMWARE(BCM4329_FIRMWARE_NAME); |
| 523 | MODULE_FIRMWARE(BCM4329_NVRAM_NAME); |
| 524 | MODULE_FIRMWARE(BCM4330_FIRMWARE_NAME); |
| 525 | MODULE_FIRMWARE(BCM4330_NVRAM_NAME); |
| 526 | MODULE_FIRMWARE(BCM4334_FIRMWARE_NAME); |
| 527 | MODULE_FIRMWARE(BCM4334_NVRAM_NAME); |
| 528 | MODULE_FIRMWARE(BCM4335_FIRMWARE_NAME); |
| 529 | MODULE_FIRMWARE(BCM4335_NVRAM_NAME); |
Arend van Spriel | 11e69c3 | 2014-01-08 10:49:33 +0100 | [diff] [blame] | 530 | MODULE_FIRMWARE(BCM43362_FIRMWARE_NAME); |
| 531 | MODULE_FIRMWARE(BCM43362_NVRAM_NAME); |
Franky Lin | bed89b6 | 2013-11-29 12:25:09 +0100 | [diff] [blame] | 532 | MODULE_FIRMWARE(BCM4339_FIRMWARE_NAME); |
| 533 | MODULE_FIRMWARE(BCM4339_NVRAM_NAME); |
Hante Meuleman | f2c44fe | 2013-09-25 13:05:45 +0200 | [diff] [blame] | 534 | |
| 535 | struct brcmf_firmware_names { |
| 536 | u32 chipid; |
| 537 | u32 revmsk; |
| 538 | const char *bin; |
| 539 | const char *nv; |
| 540 | }; |
| 541 | |
| 542 | enum brcmf_firmware_type { |
| 543 | BRCMF_FIRMWARE_BIN, |
| 544 | BRCMF_FIRMWARE_NVRAM |
| 545 | }; |
| 546 | |
| 547 | #define BRCMF_FIRMWARE_NVRAM(name) \ |
| 548 | name ## _FIRMWARE_NAME, name ## _NVRAM_NAME |
| 549 | |
| 550 | static const struct brcmf_firmware_names brcmf_fwname_data[] = { |
| 551 | { BCM43143_CHIP_ID, 0xFFFFFFFF, BRCMF_FIRMWARE_NVRAM(BCM43143) }, |
| 552 | { BCM43241_CHIP_ID, 0x0000001F, BRCMF_FIRMWARE_NVRAM(BCM43241B0) }, |
| 553 | { BCM43241_CHIP_ID, 0xFFFFFFE0, BRCMF_FIRMWARE_NVRAM(BCM43241B4) }, |
| 554 | { BCM4329_CHIP_ID, 0xFFFFFFFF, BRCMF_FIRMWARE_NVRAM(BCM4329) }, |
| 555 | { BCM4330_CHIP_ID, 0xFFFFFFFF, BRCMF_FIRMWARE_NVRAM(BCM4330) }, |
| 556 | { BCM4334_CHIP_ID, 0xFFFFFFFF, BRCMF_FIRMWARE_NVRAM(BCM4334) }, |
Franky Lin | bed89b6 | 2013-11-29 12:25:09 +0100 | [diff] [blame] | 557 | { BCM4335_CHIP_ID, 0xFFFFFFFF, BRCMF_FIRMWARE_NVRAM(BCM4335) }, |
Arend van Spriel | 11e69c3 | 2014-01-08 10:49:33 +0100 | [diff] [blame] | 558 | { BCM43362_CHIP_ID, 0xFFFFFFFE, BRCMF_FIRMWARE_NVRAM(BCM43362) }, |
Franky Lin | bed89b6 | 2013-11-29 12:25:09 +0100 | [diff] [blame] | 559 | { BCM4339_CHIP_ID, 0xFFFFFFFF, BRCMF_FIRMWARE_NVRAM(BCM4339) } |
Hante Meuleman | f2c44fe | 2013-09-25 13:05:45 +0200 | [diff] [blame] | 560 | }; |
| 561 | |
| 562 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 563 | static const struct firmware *brcmf_sdio_get_fw(struct brcmf_sdio *bus, |
Hante Meuleman | f2c44fe | 2013-09-25 13:05:45 +0200 | [diff] [blame] | 564 | enum brcmf_firmware_type type) |
| 565 | { |
| 566 | const struct firmware *fw; |
| 567 | const char *name; |
| 568 | int err, i; |
| 569 | |
| 570 | for (i = 0; i < ARRAY_SIZE(brcmf_fwname_data); i++) { |
| 571 | if (brcmf_fwname_data[i].chipid == bus->ci->chip && |
| 572 | brcmf_fwname_data[i].revmsk & BIT(bus->ci->chiprev)) { |
| 573 | switch (type) { |
| 574 | case BRCMF_FIRMWARE_BIN: |
| 575 | name = brcmf_fwname_data[i].bin; |
| 576 | break; |
| 577 | case BRCMF_FIRMWARE_NVRAM: |
| 578 | name = brcmf_fwname_data[i].nv; |
| 579 | break; |
| 580 | default: |
| 581 | brcmf_err("invalid firmware type (%d)\n", type); |
| 582 | return NULL; |
| 583 | } |
| 584 | goto found; |
| 585 | } |
| 586 | } |
| 587 | brcmf_err("Unknown chipid %d [%d]\n", |
| 588 | bus->ci->chip, bus->ci->chiprev); |
| 589 | return NULL; |
| 590 | |
| 591 | found: |
| 592 | err = request_firmware(&fw, name, &bus->sdiodev->func[2]->dev); |
| 593 | if ((err) || (!fw)) { |
| 594 | brcmf_err("fail to request firmware %s (%d)\n", name, err); |
| 595 | return NULL; |
| 596 | } |
| 597 | |
| 598 | return fw; |
| 599 | } |
| 600 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 601 | static void pkt_align(struct sk_buff *p, int len, int align) |
| 602 | { |
| 603 | uint datalign; |
| 604 | datalign = (unsigned long)(p->data); |
| 605 | datalign = roundup(datalign, (align)) - datalign; |
| 606 | if (datalign) |
| 607 | skb_pull(p, datalign); |
| 608 | __skb_trim(p, len); |
| 609 | } |
| 610 | |
| 611 | /* To check if there's window offered */ |
Franky Lin | e92eedf | 2011-11-22 17:21:50 -0800 | [diff] [blame] | 612 | static bool data_ok(struct brcmf_sdio *bus) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 613 | { |
| 614 | return (u8)(bus->tx_max - bus->tx_seq) != 0 && |
| 615 | ((u8)(bus->tx_max - bus->tx_seq) & 0x80) == 0; |
| 616 | } |
| 617 | |
| 618 | /* |
| 619 | * Reads a register in the SDIO hardware block. This block occupies a series of |
| 620 | * adresses on the 32 bit backplane bus. |
| 621 | */ |
Franky Lin | 5869275 | 2012-05-04 18:27:36 -0700 | [diff] [blame] | 622 | static int |
| 623 | r_sdreg32(struct brcmf_sdio *bus, u32 *regvar, u32 offset) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 624 | { |
Franky Lin | 99ba15c | 2011-11-04 22:23:42 +0100 | [diff] [blame] | 625 | u8 idx = brcmf_sdio_chip_getinfidx(bus->ci, BCMA_CORE_SDIO_DEV); |
Franky Lin | 79ae395 | 2012-05-04 18:27:34 -0700 | [diff] [blame] | 626 | int ret; |
Franky Lin | 5869275 | 2012-05-04 18:27:36 -0700 | [diff] [blame] | 627 | |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 628 | *regvar = brcmf_sdiod_regrl(bus->sdiodev, |
| 629 | bus->ci->c_inf[idx].base + offset, &ret); |
Franky Lin | 5869275 | 2012-05-04 18:27:36 -0700 | [diff] [blame] | 630 | |
| 631 | return ret; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 632 | } |
| 633 | |
Franky Lin | 5869275 | 2012-05-04 18:27:36 -0700 | [diff] [blame] | 634 | static int |
| 635 | w_sdreg32(struct brcmf_sdio *bus, u32 regval, u32 reg_offset) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 636 | { |
Franky Lin | 99ba15c | 2011-11-04 22:23:42 +0100 | [diff] [blame] | 637 | u8 idx = brcmf_sdio_chip_getinfidx(bus->ci, BCMA_CORE_SDIO_DEV); |
Franky Lin | e13ce26 | 2012-05-04 18:27:35 -0700 | [diff] [blame] | 638 | int ret; |
Franky Lin | 5869275 | 2012-05-04 18:27:36 -0700 | [diff] [blame] | 639 | |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 640 | brcmf_sdiod_regwl(bus->sdiodev, |
| 641 | bus->ci->c_inf[idx].base + reg_offset, |
| 642 | regval, &ret); |
Franky Lin | 5869275 | 2012-05-04 18:27:36 -0700 | [diff] [blame] | 643 | |
| 644 | return ret; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 645 | } |
| 646 | |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 647 | static int |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 648 | brcmf_sdio_kso_control(struct brcmf_sdio *bus, bool on) |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 649 | { |
| 650 | u8 wr_val = 0, rd_val, cmp_val, bmask; |
| 651 | int err = 0; |
| 652 | int try_cnt = 0; |
| 653 | |
| 654 | brcmf_dbg(TRACE, "Enter\n"); |
| 655 | |
| 656 | wr_val = (on << SBSDIO_FUNC1_SLEEPCSR_KSO_SHIFT); |
| 657 | /* 1st KSO write goes to AOS wake up core if device is asleep */ |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 658 | brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, |
| 659 | wr_val, &err); |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 660 | if (err) { |
| 661 | brcmf_err("SDIO_AOS KSO write error: %d\n", err); |
| 662 | return err; |
| 663 | } |
| 664 | |
| 665 | if (on) { |
| 666 | /* device WAKEUP through KSO: |
| 667 | * write bit 0 & read back until |
| 668 | * both bits 0 (kso bit) & 1 (dev on status) are set |
| 669 | */ |
| 670 | cmp_val = SBSDIO_FUNC1_SLEEPCSR_KSO_MASK | |
| 671 | SBSDIO_FUNC1_SLEEPCSR_DEVON_MASK; |
| 672 | bmask = cmp_val; |
| 673 | usleep_range(2000, 3000); |
| 674 | } else { |
| 675 | /* Put device to sleep, turn off KSO */ |
| 676 | cmp_val = 0; |
| 677 | /* only check for bit0, bit1(dev on status) may not |
| 678 | * get cleared right away |
| 679 | */ |
| 680 | bmask = SBSDIO_FUNC1_SLEEPCSR_KSO_MASK; |
| 681 | } |
| 682 | |
| 683 | do { |
| 684 | /* reliable KSO bit set/clr: |
| 685 | * the sdiod sleep write access is synced to PMU 32khz clk |
| 686 | * just one write attempt may fail, |
| 687 | * read it back until it matches written value |
| 688 | */ |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 689 | rd_val = brcmf_sdiod_regrb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, |
| 690 | &err); |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 691 | if (((rd_val & bmask) == cmp_val) && !err) |
| 692 | break; |
| 693 | brcmf_dbg(SDIO, "KSO wr/rd retry:%d (max: %d) ERR:%x\n", |
| 694 | try_cnt, MAX_KSO_ATTEMPTS, err); |
| 695 | udelay(KSO_WAIT_US); |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 696 | brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, |
| 697 | wr_val, &err); |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 698 | } while (try_cnt++ < MAX_KSO_ATTEMPTS); |
| 699 | |
| 700 | return err; |
| 701 | } |
| 702 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 703 | #define PKT_AVAILABLE() (intstatus & I_HMB_FRAME_IND) |
| 704 | |
| 705 | #define HOSTINTMASK (I_HMB_SW_MASK | I_CHIPACTIVE) |
| 706 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 707 | /* Turn backplane clock on or off */ |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 708 | static int brcmf_sdio_htclk(struct brcmf_sdio *bus, bool on, bool pendok) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 709 | { |
| 710 | int err; |
| 711 | u8 clkctl, clkreq, devctl; |
| 712 | unsigned long timeout; |
| 713 | |
Arend van Spriel | c320337 | 2013-04-03 12:40:44 +0200 | [diff] [blame] | 714 | brcmf_dbg(SDIO, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 715 | |
| 716 | clkctl = 0; |
| 717 | |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 718 | if (bus->sr_enabled) { |
| 719 | bus->clkstate = (on ? CLK_AVAIL : CLK_SDONLY); |
| 720 | return 0; |
| 721 | } |
| 722 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 723 | if (on) { |
| 724 | /* Request HT Avail */ |
| 725 | clkreq = |
| 726 | bus->alp_only ? SBSDIO_ALP_AVAIL_REQ : SBSDIO_HT_AVAIL_REQ; |
| 727 | |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 728 | brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, |
| 729 | clkreq, &err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 730 | if (err) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 731 | brcmf_err("HT Avail request error: %d\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 732 | return -EBADE; |
| 733 | } |
| 734 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 735 | /* Check current status */ |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 736 | clkctl = brcmf_sdiod_regrb(bus->sdiodev, |
| 737 | SBSDIO_FUNC1_CHIPCLKCSR, &err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 738 | if (err) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 739 | brcmf_err("HT Avail read error: %d\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 740 | return -EBADE; |
| 741 | } |
| 742 | |
| 743 | /* Go to pending and await interrupt if appropriate */ |
| 744 | if (!SBSDIO_CLKAV(clkctl, bus->alp_only) && pendok) { |
| 745 | /* Allow only clock-available interrupt */ |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 746 | devctl = brcmf_sdiod_regrb(bus->sdiodev, |
| 747 | SBSDIO_DEVICE_CTL, &err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 748 | if (err) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 749 | brcmf_err("Devctl error setting CA: %d\n", |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 750 | err); |
| 751 | return -EBADE; |
| 752 | } |
| 753 | |
| 754 | devctl |= SBSDIO_DEVCTL_CA_INT_ONLY; |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 755 | brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_DEVICE_CTL, |
| 756 | devctl, &err); |
Arend van Spriel | c320337 | 2013-04-03 12:40:44 +0200 | [diff] [blame] | 757 | brcmf_dbg(SDIO, "CLKCTL: set PENDING\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 758 | bus->clkstate = CLK_PENDING; |
| 759 | |
| 760 | return 0; |
| 761 | } else if (bus->clkstate == CLK_PENDING) { |
| 762 | /* Cancel CA-only interrupt filter */ |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 763 | devctl = brcmf_sdiod_regrb(bus->sdiodev, |
| 764 | SBSDIO_DEVICE_CTL, &err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 765 | devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY; |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 766 | brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_DEVICE_CTL, |
| 767 | devctl, &err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | /* Otherwise, wait here (polling) for HT Avail */ |
| 771 | timeout = jiffies + |
| 772 | msecs_to_jiffies(PMU_MAX_TRANSITION_DLY/1000); |
| 773 | while (!SBSDIO_CLKAV(clkctl, bus->alp_only)) { |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 774 | clkctl = brcmf_sdiod_regrb(bus->sdiodev, |
| 775 | SBSDIO_FUNC1_CHIPCLKCSR, |
| 776 | &err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 777 | if (time_after(jiffies, timeout)) |
| 778 | break; |
| 779 | else |
| 780 | usleep_range(5000, 10000); |
| 781 | } |
| 782 | if (err) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 783 | brcmf_err("HT Avail request error: %d\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 784 | return -EBADE; |
| 785 | } |
| 786 | if (!SBSDIO_CLKAV(clkctl, bus->alp_only)) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 787 | brcmf_err("HT Avail timeout (%d): clkctl 0x%02x\n", |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 788 | PMU_MAX_TRANSITION_DLY, clkctl); |
| 789 | return -EBADE; |
| 790 | } |
| 791 | |
| 792 | /* Mark clock available */ |
| 793 | bus->clkstate = CLK_AVAIL; |
Arend van Spriel | c320337 | 2013-04-03 12:40:44 +0200 | [diff] [blame] | 794 | brcmf_dbg(SDIO, "CLKCTL: turned ON\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 795 | |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 796 | #if defined(DEBUG) |
Joe Perches | 23677ce | 2012-02-09 11:17:23 +0000 | [diff] [blame] | 797 | if (!bus->alp_only) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 798 | if (SBSDIO_ALPONLY(clkctl)) |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 799 | brcmf_err("HT Clock should be on\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 800 | } |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 801 | #endif /* defined (DEBUG) */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 802 | |
| 803 | bus->activity = true; |
| 804 | } else { |
| 805 | clkreq = 0; |
| 806 | |
| 807 | if (bus->clkstate == CLK_PENDING) { |
| 808 | /* Cancel CA-only interrupt filter */ |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 809 | devctl = brcmf_sdiod_regrb(bus->sdiodev, |
| 810 | SBSDIO_DEVICE_CTL, &err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 811 | devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY; |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 812 | brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_DEVICE_CTL, |
| 813 | devctl, &err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | bus->clkstate = CLK_SDONLY; |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 817 | brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, |
| 818 | clkreq, &err); |
Arend van Spriel | c320337 | 2013-04-03 12:40:44 +0200 | [diff] [blame] | 819 | brcmf_dbg(SDIO, "CLKCTL: turned OFF\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 820 | if (err) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 821 | brcmf_err("Failed access turning clock off: %d\n", |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 822 | err); |
| 823 | return -EBADE; |
| 824 | } |
| 825 | } |
| 826 | return 0; |
| 827 | } |
| 828 | |
| 829 | /* Change idle/active SD state */ |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 830 | static int brcmf_sdio_sdclk(struct brcmf_sdio *bus, bool on) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 831 | { |
Arend van Spriel | c320337 | 2013-04-03 12:40:44 +0200 | [diff] [blame] | 832 | brcmf_dbg(SDIO, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 833 | |
| 834 | if (on) |
| 835 | bus->clkstate = CLK_SDONLY; |
| 836 | else |
| 837 | bus->clkstate = CLK_NONE; |
| 838 | |
| 839 | return 0; |
| 840 | } |
| 841 | |
| 842 | /* Transition SD and backplane clock readiness */ |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 843 | static int brcmf_sdio_clkctl(struct brcmf_sdio *bus, uint target, bool pendok) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 844 | { |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 845 | #ifdef DEBUG |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 846 | uint oldstate = bus->clkstate; |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 847 | #endif /* DEBUG */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 848 | |
Arend van Spriel | c320337 | 2013-04-03 12:40:44 +0200 | [diff] [blame] | 849 | brcmf_dbg(SDIO, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 850 | |
| 851 | /* Early exit if we're already there */ |
| 852 | if (bus->clkstate == target) { |
| 853 | if (target == CLK_AVAIL) { |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 854 | brcmf_sdio_wd_timer(bus, BRCMF_WD_POLL_MS); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 855 | bus->activity = true; |
| 856 | } |
| 857 | return 0; |
| 858 | } |
| 859 | |
| 860 | switch (target) { |
| 861 | case CLK_AVAIL: |
| 862 | /* Make sure SD clock is available */ |
| 863 | if (bus->clkstate == CLK_NONE) |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 864 | brcmf_sdio_sdclk(bus, true); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 865 | /* Now request HT Avail on the backplane */ |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 866 | brcmf_sdio_htclk(bus, true, pendok); |
| 867 | brcmf_sdio_wd_timer(bus, BRCMF_WD_POLL_MS); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 868 | bus->activity = true; |
| 869 | break; |
| 870 | |
| 871 | case CLK_SDONLY: |
| 872 | /* Remove HT request, or bring up SD clock */ |
| 873 | if (bus->clkstate == CLK_NONE) |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 874 | brcmf_sdio_sdclk(bus, true); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 875 | else if (bus->clkstate == CLK_AVAIL) |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 876 | brcmf_sdio_htclk(bus, false, false); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 877 | else |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 878 | brcmf_err("request for %d -> %d\n", |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 879 | bus->clkstate, target); |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 880 | brcmf_sdio_wd_timer(bus, BRCMF_WD_POLL_MS); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 881 | break; |
| 882 | |
| 883 | case CLK_NONE: |
| 884 | /* Make sure to remove HT request */ |
| 885 | if (bus->clkstate == CLK_AVAIL) |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 886 | brcmf_sdio_htclk(bus, false, false); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 887 | /* Now remove the SD clock */ |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 888 | brcmf_sdio_sdclk(bus, false); |
| 889 | brcmf_sdio_wd_timer(bus, 0); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 890 | break; |
| 891 | } |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 892 | #ifdef DEBUG |
Arend van Spriel | c320337 | 2013-04-03 12:40:44 +0200 | [diff] [blame] | 893 | brcmf_dbg(SDIO, "%d -> %d\n", oldstate, bus->clkstate); |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 894 | #endif /* DEBUG */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 895 | |
| 896 | return 0; |
| 897 | } |
| 898 | |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 899 | static int |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 900 | brcmf_sdio_bus_sleep(struct brcmf_sdio *bus, bool sleep, bool pendok) |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 901 | { |
| 902 | int err = 0; |
| 903 | brcmf_dbg(TRACE, "Enter\n"); |
| 904 | brcmf_dbg(SDIO, "request %s currently %s\n", |
| 905 | (sleep ? "SLEEP" : "WAKE"), |
| 906 | (bus->sleeping ? "SLEEP" : "WAKE")); |
| 907 | |
| 908 | /* If SR is enabled control bus state with KSO */ |
| 909 | if (bus->sr_enabled) { |
| 910 | /* Done if we're already in the requested state */ |
| 911 | if (sleep == bus->sleeping) |
| 912 | goto end; |
| 913 | |
| 914 | /* Going to sleep */ |
| 915 | if (sleep) { |
| 916 | /* Don't sleep if something is pending */ |
| 917 | if (atomic_read(&bus->intstatus) || |
| 918 | atomic_read(&bus->ipend) > 0 || |
| 919 | (!atomic_read(&bus->fcstate) && |
| 920 | brcmu_pktq_mlen(&bus->txq, ~bus->flowcontrol) && |
| 921 | data_ok(bus))) |
| 922 | return -EBUSY; |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 923 | err = brcmf_sdio_kso_control(bus, false); |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 924 | /* disable watchdog */ |
| 925 | if (!err) |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 926 | brcmf_sdio_wd_timer(bus, 0); |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 927 | } else { |
| 928 | bus->idlecount = 0; |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 929 | err = brcmf_sdio_kso_control(bus, true); |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 930 | } |
| 931 | if (!err) { |
| 932 | /* Change state */ |
| 933 | bus->sleeping = sleep; |
| 934 | brcmf_dbg(SDIO, "new state %s\n", |
| 935 | (sleep ? "SLEEP" : "WAKE")); |
| 936 | } else { |
| 937 | brcmf_err("error while changing bus sleep state %d\n", |
| 938 | err); |
| 939 | return err; |
| 940 | } |
| 941 | } |
| 942 | |
| 943 | end: |
| 944 | /* control clocks */ |
| 945 | if (sleep) { |
| 946 | if (!bus->sr_enabled) |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 947 | brcmf_sdio_clkctl(bus, CLK_NONE, pendok); |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 948 | } else { |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 949 | brcmf_sdio_clkctl(bus, CLK_AVAIL, pendok); |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | return err; |
| 953 | |
| 954 | } |
| 955 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 956 | static u32 brcmf_sdio_hostmail(struct brcmf_sdio *bus) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 957 | { |
| 958 | u32 intstatus = 0; |
| 959 | u32 hmb_data; |
| 960 | u8 fcbits; |
Franky Lin | 5869275 | 2012-05-04 18:27:36 -0700 | [diff] [blame] | 961 | int ret; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 962 | |
Arend van Spriel | c320337 | 2013-04-03 12:40:44 +0200 | [diff] [blame] | 963 | brcmf_dbg(SDIO, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 964 | |
| 965 | /* Read mailbox data and ack that we did so */ |
Franky Lin | 5869275 | 2012-05-04 18:27:36 -0700 | [diff] [blame] | 966 | ret = r_sdreg32(bus, &hmb_data, |
| 967 | offsetof(struct sdpcmd_regs, tohostmailboxdata)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 968 | |
Franky Lin | 5869275 | 2012-05-04 18:27:36 -0700 | [diff] [blame] | 969 | if (ret == 0) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 970 | w_sdreg32(bus, SMB_INT_ACK, |
Franky Lin | 5869275 | 2012-05-04 18:27:36 -0700 | [diff] [blame] | 971 | offsetof(struct sdpcmd_regs, tosbmailbox)); |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 972 | bus->sdcnt.f1regdata += 2; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 973 | |
| 974 | /* Dongle recomposed rx frames, accept them again */ |
| 975 | if (hmb_data & HMB_DATA_NAKHANDLED) { |
Arend van Spriel | c320337 | 2013-04-03 12:40:44 +0200 | [diff] [blame] | 976 | brcmf_dbg(SDIO, "Dongle reports NAK handled, expect rtx of %d\n", |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 977 | bus->rx_seq); |
| 978 | if (!bus->rxskip) |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 979 | brcmf_err("unexpected NAKHANDLED!\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 980 | |
| 981 | bus->rxskip = false; |
| 982 | intstatus |= I_HMB_FRAME_IND; |
| 983 | } |
| 984 | |
| 985 | /* |
| 986 | * DEVREADY does not occur with gSPI. |
| 987 | */ |
| 988 | if (hmb_data & (HMB_DATA_DEVREADY | HMB_DATA_FWREADY)) { |
| 989 | bus->sdpcm_ver = |
| 990 | (hmb_data & HMB_DATA_VERSION_MASK) >> |
| 991 | HMB_DATA_VERSION_SHIFT; |
| 992 | if (bus->sdpcm_ver != SDPCM_PROT_VERSION) |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 993 | brcmf_err("Version mismatch, dongle reports %d, " |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 994 | "expecting %d\n", |
| 995 | bus->sdpcm_ver, SDPCM_PROT_VERSION); |
| 996 | else |
Arend van Spriel | c320337 | 2013-04-03 12:40:44 +0200 | [diff] [blame] | 997 | brcmf_dbg(SDIO, "Dongle ready, protocol version %d\n", |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 998 | bus->sdpcm_ver); |
| 999 | } |
| 1000 | |
| 1001 | /* |
| 1002 | * Flow Control has been moved into the RX headers and this out of band |
| 1003 | * method isn't used any more. |
| 1004 | * remaining backward compatible with older dongles. |
| 1005 | */ |
| 1006 | if (hmb_data & HMB_DATA_FC) { |
| 1007 | fcbits = (hmb_data & HMB_DATA_FCDATA_MASK) >> |
| 1008 | HMB_DATA_FCDATA_SHIFT; |
| 1009 | |
| 1010 | if (fcbits & ~bus->flowcontrol) |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 1011 | bus->sdcnt.fc_xoff++; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1012 | |
| 1013 | if (bus->flowcontrol & ~fcbits) |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 1014 | bus->sdcnt.fc_xon++; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1015 | |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 1016 | bus->sdcnt.fc_rcvd++; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1017 | bus->flowcontrol = fcbits; |
| 1018 | } |
| 1019 | |
| 1020 | /* Shouldn't be any others */ |
| 1021 | if (hmb_data & ~(HMB_DATA_DEVREADY | |
| 1022 | HMB_DATA_NAKHANDLED | |
| 1023 | HMB_DATA_FC | |
| 1024 | HMB_DATA_FWREADY | |
| 1025 | HMB_DATA_FCDATA_MASK | HMB_DATA_VERSION_MASK)) |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 1026 | brcmf_err("Unknown mailbox data content: 0x%02x\n", |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1027 | hmb_data); |
| 1028 | |
| 1029 | return intstatus; |
| 1030 | } |
| 1031 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 1032 | static void brcmf_sdio_rxfail(struct brcmf_sdio *bus, bool abort, bool rtx) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1033 | { |
| 1034 | uint retries = 0; |
| 1035 | u16 lastrbc; |
| 1036 | u8 hi, lo; |
| 1037 | int err; |
| 1038 | |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 1039 | brcmf_err("%sterminate frame%s\n", |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1040 | abort ? "abort command, " : "", |
| 1041 | rtx ? ", send NAK" : ""); |
| 1042 | |
| 1043 | if (abort) |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 1044 | brcmf_sdiod_abort(bus->sdiodev, SDIO_FUNC_2); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1045 | |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 1046 | brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_FRAMECTRL, |
| 1047 | SFC_RF_TERM, &err); |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 1048 | bus->sdcnt.f1regdata++; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1049 | |
| 1050 | /* Wait until the packet has been flushed (device/FIFO stable) */ |
| 1051 | for (lastrbc = retries = 0xffff; retries > 0; retries--) { |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 1052 | hi = brcmf_sdiod_regrb(bus->sdiodev, |
| 1053 | SBSDIO_FUNC1_RFRAMEBCHI, &err); |
| 1054 | lo = brcmf_sdiod_regrb(bus->sdiodev, |
| 1055 | SBSDIO_FUNC1_RFRAMEBCLO, &err); |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 1056 | bus->sdcnt.f1regdata += 2; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1057 | |
| 1058 | if ((hi == 0) && (lo == 0)) |
| 1059 | break; |
| 1060 | |
| 1061 | if ((hi > (lastrbc >> 8)) && (lo > (lastrbc & 0x00ff))) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 1062 | brcmf_err("count growing: last 0x%04x now 0x%04x\n", |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1063 | lastrbc, (hi << 8) + lo); |
| 1064 | } |
| 1065 | lastrbc = (hi << 8) + lo; |
| 1066 | } |
| 1067 | |
| 1068 | if (!retries) |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 1069 | brcmf_err("count never zeroed: last 0x%04x\n", lastrbc); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1070 | else |
Arend van Spriel | c320337 | 2013-04-03 12:40:44 +0200 | [diff] [blame] | 1071 | brcmf_dbg(SDIO, "flush took %d iterations\n", 0xffff - retries); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1072 | |
| 1073 | if (rtx) { |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 1074 | bus->sdcnt.rxrtx++; |
Franky Lin | 5869275 | 2012-05-04 18:27:36 -0700 | [diff] [blame] | 1075 | err = w_sdreg32(bus, SMB_NAK, |
| 1076 | offsetof(struct sdpcmd_regs, tosbmailbox)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1077 | |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 1078 | bus->sdcnt.f1regdata++; |
Franky Lin | 5869275 | 2012-05-04 18:27:36 -0700 | [diff] [blame] | 1079 | if (err == 0) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1080 | bus->rxskip = true; |
| 1081 | } |
| 1082 | |
| 1083 | /* Clear partial in any case */ |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1084 | bus->cur_read.len = 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1085 | |
| 1086 | /* If we can't reach the device, signal failure */ |
Franky Lin | 5c15c23 | 2012-05-04 18:27:37 -0700 | [diff] [blame] | 1087 | if (err) |
Franky Lin | 712ac5b | 2011-12-16 18:37:09 -0800 | [diff] [blame] | 1088 | bus->sdiodev->bus_if->state = BRCMF_BUS_DOWN; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1089 | } |
| 1090 | |
Arend van Spriel | 9a95e60 | 2011-11-10 20:30:29 +0100 | [diff] [blame] | 1091 | /* return total length of buffer chain */ |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 1092 | static uint brcmf_sdio_glom_len(struct brcmf_sdio *bus) |
Arend van Spriel | 9a95e60 | 2011-11-10 20:30:29 +0100 | [diff] [blame] | 1093 | { |
| 1094 | struct sk_buff *p; |
| 1095 | uint total; |
| 1096 | |
| 1097 | total = 0; |
| 1098 | skb_queue_walk(&bus->glom, p) |
| 1099 | total += p->len; |
| 1100 | return total; |
| 1101 | } |
| 1102 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 1103 | static void brcmf_sdio_free_glom(struct brcmf_sdio *bus) |
Arend van Spriel | 046808d | 2011-11-10 20:30:31 +0100 | [diff] [blame] | 1104 | { |
| 1105 | struct sk_buff *cur, *next; |
| 1106 | |
| 1107 | skb_queue_walk_safe(&bus->glom, cur, next) { |
| 1108 | skb_unlink(cur, &bus->glom); |
| 1109 | brcmu_pkt_buf_free_skb(cur); |
| 1110 | } |
| 1111 | } |
| 1112 | |
Franky Lin | 6bc5231 | 2013-08-10 12:27:28 +0200 | [diff] [blame] | 1113 | /** |
| 1114 | * brcmfmac sdio bus specific header |
| 1115 | * This is the lowest layer header wrapped on the packets transmitted between |
| 1116 | * host and WiFi dongle which contains information needed for SDIO core and |
| 1117 | * firmware |
| 1118 | * |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 1119 | * It consists of 3 parts: hardware header, hardware extension header and |
| 1120 | * software header |
Franky Lin | 6bc5231 | 2013-08-10 12:27:28 +0200 | [diff] [blame] | 1121 | * hardware header (frame tag) - 4 bytes |
| 1122 | * Byte 0~1: Frame length |
| 1123 | * Byte 2~3: Checksum, bit-wise inverse of frame length |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 1124 | * hardware extension header - 8 bytes |
| 1125 | * Tx glom mode only, N/A for Rx or normal Tx |
| 1126 | * Byte 0~1: Packet length excluding hw frame tag |
| 1127 | * Byte 2: Reserved |
| 1128 | * Byte 3: Frame flags, bit 0: last frame indication |
| 1129 | * Byte 4~5: Reserved |
| 1130 | * Byte 6~7: Tail padding length |
Franky Lin | 6bc5231 | 2013-08-10 12:27:28 +0200 | [diff] [blame] | 1131 | * software header - 8 bytes |
| 1132 | * Byte 0: Rx/Tx sequence number |
| 1133 | * Byte 1: 4 MSB Channel number, 4 LSB arbitrary flag |
| 1134 | * Byte 2: Length of next data frame, reserved for Tx |
| 1135 | * Byte 3: Data offset |
| 1136 | * Byte 4: Flow control bits, reserved for Tx |
| 1137 | * Byte 5: Maximum Sequence number allowed by firmware for Tx, N/A for Tx packet |
| 1138 | * Byte 6~7: Reserved |
| 1139 | */ |
| 1140 | #define SDPCM_HWHDR_LEN 4 |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 1141 | #define SDPCM_HWEXT_LEN 8 |
Franky Lin | 6bc5231 | 2013-08-10 12:27:28 +0200 | [diff] [blame] | 1142 | #define SDPCM_SWHDR_LEN 8 |
| 1143 | #define SDPCM_HDRLEN (SDPCM_HWHDR_LEN + SDPCM_SWHDR_LEN) |
Franky Lin | 6bc5231 | 2013-08-10 12:27:28 +0200 | [diff] [blame] | 1144 | /* software header */ |
| 1145 | #define SDPCM_SEQ_MASK 0x000000ff |
| 1146 | #define SDPCM_SEQ_WRAP 256 |
| 1147 | #define SDPCM_CHANNEL_MASK 0x00000f00 |
| 1148 | #define SDPCM_CHANNEL_SHIFT 8 |
| 1149 | #define SDPCM_CONTROL_CHANNEL 0 /* Control */ |
| 1150 | #define SDPCM_EVENT_CHANNEL 1 /* Asyc Event Indication */ |
| 1151 | #define SDPCM_DATA_CHANNEL 2 /* Data Xmit/Recv */ |
| 1152 | #define SDPCM_GLOM_CHANNEL 3 /* Coalesced packets */ |
| 1153 | #define SDPCM_TEST_CHANNEL 15 /* Test/debug packets */ |
| 1154 | #define SDPCM_GLOMDESC(p) (((u8 *)p)[1] & 0x80) |
| 1155 | #define SDPCM_NEXTLEN_MASK 0x00ff0000 |
| 1156 | #define SDPCM_NEXTLEN_SHIFT 16 |
| 1157 | #define SDPCM_DOFFSET_MASK 0xff000000 |
| 1158 | #define SDPCM_DOFFSET_SHIFT 24 |
| 1159 | #define SDPCM_FCMASK_MASK 0x000000ff |
| 1160 | #define SDPCM_WINDOW_MASK 0x0000ff00 |
| 1161 | #define SDPCM_WINDOW_SHIFT 8 |
| 1162 | |
| 1163 | static inline u8 brcmf_sdio_getdatoffset(u8 *swheader) |
| 1164 | { |
| 1165 | u32 hdrvalue; |
| 1166 | hdrvalue = *(u32 *)swheader; |
| 1167 | return (u8)((hdrvalue & SDPCM_DOFFSET_MASK) >> SDPCM_DOFFSET_SHIFT); |
| 1168 | } |
| 1169 | |
| 1170 | static int brcmf_sdio_hdparse(struct brcmf_sdio *bus, u8 *header, |
| 1171 | struct brcmf_sdio_hdrinfo *rd, |
| 1172 | enum brcmf_sdio_frmtype type) |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1173 | { |
| 1174 | u16 len, checksum; |
| 1175 | u8 rx_seq, fc, tx_seq_max; |
Franky Lin | 6bc5231 | 2013-08-10 12:27:28 +0200 | [diff] [blame] | 1176 | u32 swheader; |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1177 | |
Arend van Spriel | 4b77696 | 2013-11-29 12:25:06 +0100 | [diff] [blame] | 1178 | trace_brcmf_sdpcm_hdr(SDPCM_RX, header); |
Arend van Spriel | 76584ec | 2013-10-15 15:44:47 +0200 | [diff] [blame] | 1179 | |
Franky Lin | 6bc5231 | 2013-08-10 12:27:28 +0200 | [diff] [blame] | 1180 | /* hw header */ |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1181 | len = get_unaligned_le16(header); |
| 1182 | checksum = get_unaligned_le16(header + sizeof(u16)); |
| 1183 | /* All zero means no more to read */ |
| 1184 | if (!(len | checksum)) { |
| 1185 | bus->rxpending = false; |
Franky Lin | 1051058 | 2012-11-05 16:22:26 -0800 | [diff] [blame] | 1186 | return -ENODATA; |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1187 | } |
| 1188 | if ((u16)(~(len ^ checksum))) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 1189 | brcmf_err("HW header checksum error\n"); |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1190 | bus->sdcnt.rx_badhdr++; |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 1191 | brcmf_sdio_rxfail(bus, false, false); |
Franky Lin | 1051058 | 2012-11-05 16:22:26 -0800 | [diff] [blame] | 1192 | return -EIO; |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1193 | } |
| 1194 | if (len < SDPCM_HDRLEN) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 1195 | brcmf_err("HW header length error\n"); |
Franky Lin | 1051058 | 2012-11-05 16:22:26 -0800 | [diff] [blame] | 1196 | return -EPROTO; |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1197 | } |
Franky Lin | 9d7d6f9 | 2012-10-22 10:36:24 -0700 | [diff] [blame] | 1198 | if (type == BRCMF_SDIO_FT_SUPER && |
| 1199 | (roundup(len, bus->blocksize) != rd->len)) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 1200 | brcmf_err("HW superframe header length error\n"); |
Franky Lin | 1051058 | 2012-11-05 16:22:26 -0800 | [diff] [blame] | 1201 | return -EPROTO; |
Franky Lin | 9d7d6f9 | 2012-10-22 10:36:24 -0700 | [diff] [blame] | 1202 | } |
| 1203 | if (type == BRCMF_SDIO_FT_SUB && len > rd->len) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 1204 | brcmf_err("HW subframe header length error\n"); |
Franky Lin | 1051058 | 2012-11-05 16:22:26 -0800 | [diff] [blame] | 1205 | return -EPROTO; |
Franky Lin | 9d7d6f9 | 2012-10-22 10:36:24 -0700 | [diff] [blame] | 1206 | } |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1207 | rd->len = len; |
| 1208 | |
Franky Lin | 6bc5231 | 2013-08-10 12:27:28 +0200 | [diff] [blame] | 1209 | /* software header */ |
| 1210 | header += SDPCM_HWHDR_LEN; |
| 1211 | swheader = le32_to_cpu(*(__le32 *)header); |
| 1212 | if (type == BRCMF_SDIO_FT_SUPER && SDPCM_GLOMDESC(header)) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 1213 | brcmf_err("Glom descriptor found in superframe head\n"); |
Franky Lin | 9d7d6f9 | 2012-10-22 10:36:24 -0700 | [diff] [blame] | 1214 | rd->len = 0; |
Franky Lin | 1051058 | 2012-11-05 16:22:26 -0800 | [diff] [blame] | 1215 | return -EINVAL; |
Franky Lin | 9d7d6f9 | 2012-10-22 10:36:24 -0700 | [diff] [blame] | 1216 | } |
Franky Lin | 6bc5231 | 2013-08-10 12:27:28 +0200 | [diff] [blame] | 1217 | rx_seq = (u8)(swheader & SDPCM_SEQ_MASK); |
| 1218 | rd->channel = (swheader & SDPCM_CHANNEL_MASK) >> SDPCM_CHANNEL_SHIFT; |
Franky Lin | 9d7d6f9 | 2012-10-22 10:36:24 -0700 | [diff] [blame] | 1219 | if (len > MAX_RX_DATASZ && rd->channel != SDPCM_CONTROL_CHANNEL && |
| 1220 | type != BRCMF_SDIO_FT_SUPER) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 1221 | brcmf_err("HW header length too long\n"); |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1222 | bus->sdcnt.rx_toolong++; |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 1223 | brcmf_sdio_rxfail(bus, false, false); |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1224 | rd->len = 0; |
Franky Lin | 1051058 | 2012-11-05 16:22:26 -0800 | [diff] [blame] | 1225 | return -EPROTO; |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1226 | } |
Franky Lin | 9d7d6f9 | 2012-10-22 10:36:24 -0700 | [diff] [blame] | 1227 | if (type == BRCMF_SDIO_FT_SUPER && rd->channel != SDPCM_GLOM_CHANNEL) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 1228 | brcmf_err("Wrong channel for superframe\n"); |
Franky Lin | 9d7d6f9 | 2012-10-22 10:36:24 -0700 | [diff] [blame] | 1229 | rd->len = 0; |
Franky Lin | 1051058 | 2012-11-05 16:22:26 -0800 | [diff] [blame] | 1230 | return -EINVAL; |
Franky Lin | 9d7d6f9 | 2012-10-22 10:36:24 -0700 | [diff] [blame] | 1231 | } |
| 1232 | if (type == BRCMF_SDIO_FT_SUB && rd->channel != SDPCM_DATA_CHANNEL && |
| 1233 | rd->channel != SDPCM_EVENT_CHANNEL) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 1234 | brcmf_err("Wrong channel for subframe\n"); |
Franky Lin | 9d7d6f9 | 2012-10-22 10:36:24 -0700 | [diff] [blame] | 1235 | rd->len = 0; |
Franky Lin | 1051058 | 2012-11-05 16:22:26 -0800 | [diff] [blame] | 1236 | return -EINVAL; |
Franky Lin | 9d7d6f9 | 2012-10-22 10:36:24 -0700 | [diff] [blame] | 1237 | } |
Franky Lin | 6bc5231 | 2013-08-10 12:27:28 +0200 | [diff] [blame] | 1238 | rd->dat_offset = brcmf_sdio_getdatoffset(header); |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1239 | if (rd->dat_offset < SDPCM_HDRLEN || rd->dat_offset > rd->len) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 1240 | brcmf_err("seq %d: bad data offset\n", rx_seq); |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1241 | bus->sdcnt.rx_badhdr++; |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 1242 | brcmf_sdio_rxfail(bus, false, false); |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1243 | rd->len = 0; |
Franky Lin | 1051058 | 2012-11-05 16:22:26 -0800 | [diff] [blame] | 1244 | return -ENXIO; |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1245 | } |
| 1246 | if (rd->seq_num != rx_seq) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 1247 | brcmf_err("seq %d: sequence number error, expect %d\n", |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1248 | rx_seq, rd->seq_num); |
| 1249 | bus->sdcnt.rx_badseq++; |
| 1250 | rd->seq_num = rx_seq; |
| 1251 | } |
Franky Lin | 9d7d6f9 | 2012-10-22 10:36:24 -0700 | [diff] [blame] | 1252 | /* no need to check the reset for subframe */ |
| 1253 | if (type == BRCMF_SDIO_FT_SUB) |
Franky Lin | 1051058 | 2012-11-05 16:22:26 -0800 | [diff] [blame] | 1254 | return 0; |
Franky Lin | 6bc5231 | 2013-08-10 12:27:28 +0200 | [diff] [blame] | 1255 | rd->len_nxtfrm = (swheader & SDPCM_NEXTLEN_MASK) >> SDPCM_NEXTLEN_SHIFT; |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1256 | if (rd->len_nxtfrm << 4 > MAX_RX_DATASZ) { |
| 1257 | /* only warm for NON glom packet */ |
| 1258 | if (rd->channel != SDPCM_GLOM_CHANNEL) |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 1259 | brcmf_err("seq %d: next length error\n", rx_seq); |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1260 | rd->len_nxtfrm = 0; |
| 1261 | } |
Franky Lin | 6bc5231 | 2013-08-10 12:27:28 +0200 | [diff] [blame] | 1262 | swheader = le32_to_cpu(*(__le32 *)(header + 4)); |
| 1263 | fc = swheader & SDPCM_FCMASK_MASK; |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1264 | if (bus->flowcontrol != fc) { |
| 1265 | if (~bus->flowcontrol & fc) |
| 1266 | bus->sdcnt.fc_xoff++; |
| 1267 | if (bus->flowcontrol & ~fc) |
| 1268 | bus->sdcnt.fc_xon++; |
| 1269 | bus->sdcnt.fc_rcvd++; |
| 1270 | bus->flowcontrol = fc; |
| 1271 | } |
Franky Lin | 6bc5231 | 2013-08-10 12:27:28 +0200 | [diff] [blame] | 1272 | tx_seq_max = (swheader & SDPCM_WINDOW_MASK) >> SDPCM_WINDOW_SHIFT; |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1273 | if ((u8)(tx_seq_max - bus->tx_seq) > 0x40) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 1274 | brcmf_err("seq %d: max tx seq number error\n", rx_seq); |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1275 | tx_seq_max = bus->tx_seq + 2; |
| 1276 | } |
| 1277 | bus->tx_max = tx_seq_max; |
| 1278 | |
Franky Lin | 1051058 | 2012-11-05 16:22:26 -0800 | [diff] [blame] | 1279 | return 0; |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1280 | } |
| 1281 | |
Franky Lin | 6bc5231 | 2013-08-10 12:27:28 +0200 | [diff] [blame] | 1282 | static inline void brcmf_sdio_update_hwhdr(u8 *header, u16 frm_length) |
| 1283 | { |
| 1284 | *(__le16 *)header = cpu_to_le16(frm_length); |
| 1285 | *(((__le16 *)header) + 1) = cpu_to_le16(~frm_length); |
| 1286 | } |
| 1287 | |
| 1288 | static void brcmf_sdio_hdpack(struct brcmf_sdio *bus, u8 *header, |
| 1289 | struct brcmf_sdio_hdrinfo *hd_info) |
| 1290 | { |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 1291 | u32 hdrval; |
| 1292 | u8 hdr_offset; |
Franky Lin | 6bc5231 | 2013-08-10 12:27:28 +0200 | [diff] [blame] | 1293 | |
| 1294 | brcmf_sdio_update_hwhdr(header, hd_info->len); |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 1295 | hdr_offset = SDPCM_HWHDR_LEN; |
Franky Lin | 6bc5231 | 2013-08-10 12:27:28 +0200 | [diff] [blame] | 1296 | |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 1297 | if (bus->txglom) { |
| 1298 | hdrval = (hd_info->len - hdr_offset) | (hd_info->lastfrm << 24); |
| 1299 | *((__le32 *)(header + hdr_offset)) = cpu_to_le32(hdrval); |
| 1300 | hdrval = (u16)hd_info->tail_pad << 16; |
| 1301 | *(((__le32 *)(header + hdr_offset)) + 1) = cpu_to_le32(hdrval); |
| 1302 | hdr_offset += SDPCM_HWEXT_LEN; |
| 1303 | } |
| 1304 | |
| 1305 | hdrval = hd_info->seq_num; |
| 1306 | hdrval |= (hd_info->channel << SDPCM_CHANNEL_SHIFT) & |
| 1307 | SDPCM_CHANNEL_MASK; |
| 1308 | hdrval |= (hd_info->dat_offset << SDPCM_DOFFSET_SHIFT) & |
| 1309 | SDPCM_DOFFSET_MASK; |
| 1310 | *((__le32 *)(header + hdr_offset)) = cpu_to_le32(hdrval); |
| 1311 | *(((__le32 *)(header + hdr_offset)) + 1) = 0; |
| 1312 | trace_brcmf_sdpcm_hdr(SDPCM_TX + !!(bus->txglom), header); |
Franky Lin | 6bc5231 | 2013-08-10 12:27:28 +0200 | [diff] [blame] | 1313 | } |
| 1314 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 1315 | static u8 brcmf_sdio_rxglom(struct brcmf_sdio *bus, u8 rxseq) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1316 | { |
| 1317 | u16 dlen, totlen; |
| 1318 | u8 *dptr, num = 0; |
Franky Lin | 9d7d6f9 | 2012-10-22 10:36:24 -0700 | [diff] [blame] | 1319 | u16 sublen; |
Arend van Spriel | 0b45bf7 | 2011-11-22 17:21:36 -0800 | [diff] [blame] | 1320 | struct sk_buff *pfirst, *pnext; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1321 | |
| 1322 | int errcode; |
Franky Lin | 9d7d6f9 | 2012-10-22 10:36:24 -0700 | [diff] [blame] | 1323 | u8 doff, sfdoff; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1324 | |
Franky Lin | 6bc5231 | 2013-08-10 12:27:28 +0200 | [diff] [blame] | 1325 | struct brcmf_sdio_hdrinfo rd_new; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1326 | |
| 1327 | /* If packets, issue read(s) and send up packet chain */ |
| 1328 | /* Return sequence numbers consumed? */ |
| 1329 | |
Arend van Spriel | c320337 | 2013-04-03 12:40:44 +0200 | [diff] [blame] | 1330 | brcmf_dbg(SDIO, "start: glomd %p glom %p\n", |
Arend van Spriel | b83db86 | 2011-10-19 12:51:09 +0200 | [diff] [blame] | 1331 | bus->glomd, skb_peek(&bus->glom)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1332 | |
| 1333 | /* If there's a descriptor, generate the packet chain */ |
| 1334 | if (bus->glomd) { |
Arend van Spriel | 0b45bf7 | 2011-11-22 17:21:36 -0800 | [diff] [blame] | 1335 | pfirst = pnext = NULL; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1336 | dlen = (u16) (bus->glomd->len); |
| 1337 | dptr = bus->glomd->data; |
| 1338 | if (!dlen || (dlen & 1)) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 1339 | brcmf_err("bad glomd len(%d), ignore descriptor\n", |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1340 | dlen); |
| 1341 | dlen = 0; |
| 1342 | } |
| 1343 | |
| 1344 | for (totlen = num = 0; dlen; num++) { |
| 1345 | /* Get (and move past) next length */ |
| 1346 | sublen = get_unaligned_le16(dptr); |
| 1347 | dlen -= sizeof(u16); |
| 1348 | dptr += sizeof(u16); |
| 1349 | if ((sublen < SDPCM_HDRLEN) || |
| 1350 | ((num == 0) && (sublen < (2 * SDPCM_HDRLEN)))) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 1351 | brcmf_err("descriptor len %d bad: %d\n", |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1352 | num, sublen); |
| 1353 | pnext = NULL; |
| 1354 | break; |
| 1355 | } |
Arend van Spriel | e217d1c | 2013-11-29 12:25:13 +0100 | [diff] [blame] | 1356 | if (sublen % bus->sgentry_align) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 1357 | brcmf_err("sublen %d not multiple of %d\n", |
Arend van Spriel | e217d1c | 2013-11-29 12:25:13 +0100 | [diff] [blame] | 1358 | sublen, bus->sgentry_align); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1359 | } |
| 1360 | totlen += sublen; |
| 1361 | |
| 1362 | /* For last frame, adjust read len so total |
| 1363 | is a block multiple */ |
| 1364 | if (!dlen) { |
| 1365 | sublen += |
| 1366 | (roundup(totlen, bus->blocksize) - totlen); |
| 1367 | totlen = roundup(totlen, bus->blocksize); |
| 1368 | } |
| 1369 | |
| 1370 | /* Allocate/chain packet for next subframe */ |
Arend van Spriel | e217d1c | 2013-11-29 12:25:13 +0100 | [diff] [blame] | 1371 | pnext = brcmu_pkt_buf_get_skb(sublen + bus->sgentry_align); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1372 | if (pnext == NULL) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 1373 | brcmf_err("bcm_pkt_buf_get_skb failed, num %d len %d\n", |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1374 | num, sublen); |
| 1375 | break; |
| 1376 | } |
Arend van Spriel | b83db86 | 2011-10-19 12:51:09 +0200 | [diff] [blame] | 1377 | skb_queue_tail(&bus->glom, pnext); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1378 | |
| 1379 | /* Adhere to start alignment requirements */ |
Arend van Spriel | e217d1c | 2013-11-29 12:25:13 +0100 | [diff] [blame] | 1380 | pkt_align(pnext, sublen, bus->sgentry_align); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1381 | } |
| 1382 | |
| 1383 | /* If all allocations succeeded, save packet chain |
| 1384 | in bus structure */ |
| 1385 | if (pnext) { |
| 1386 | brcmf_dbg(GLOM, "allocated %d-byte packet chain for %d subframes\n", |
| 1387 | totlen, num); |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1388 | if (BRCMF_GLOM_ON() && bus->cur_read.len && |
| 1389 | totlen != bus->cur_read.len) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1390 | brcmf_dbg(GLOM, "glomdesc mismatch: nextlen %d glomdesc %d rxseq %d\n", |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1391 | bus->cur_read.len, totlen, rxseq); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1392 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1393 | pfirst = pnext = NULL; |
| 1394 | } else { |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 1395 | brcmf_sdio_free_glom(bus); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1396 | num = 0; |
| 1397 | } |
| 1398 | |
| 1399 | /* Done with descriptor packet */ |
| 1400 | brcmu_pkt_buf_free_skb(bus->glomd); |
| 1401 | bus->glomd = NULL; |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1402 | bus->cur_read.len = 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1403 | } |
| 1404 | |
| 1405 | /* Ok -- either we just generated a packet chain, |
| 1406 | or had one from before */ |
Arend van Spriel | b83db86 | 2011-10-19 12:51:09 +0200 | [diff] [blame] | 1407 | if (!skb_queue_empty(&bus->glom)) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1408 | if (BRCMF_GLOM_ON()) { |
| 1409 | brcmf_dbg(GLOM, "try superframe read, packet chain:\n"); |
Arend van Spriel | b83db86 | 2011-10-19 12:51:09 +0200 | [diff] [blame] | 1410 | skb_queue_walk(&bus->glom, pnext) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1411 | brcmf_dbg(GLOM, " %p: %p len 0x%04x (%d)\n", |
| 1412 | pnext, (u8 *) (pnext->data), |
| 1413 | pnext->len, pnext->len); |
| 1414 | } |
| 1415 | } |
| 1416 | |
Arend van Spriel | b83db86 | 2011-10-19 12:51:09 +0200 | [diff] [blame] | 1417 | pfirst = skb_peek(&bus->glom); |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 1418 | dlen = (u16) brcmf_sdio_glom_len(bus); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1419 | |
| 1420 | /* Do an SDIO read for the superframe. Configurable iovar to |
| 1421 | * read directly into the chained packet, or allocate a large |
| 1422 | * packet and and copy into the chain. |
| 1423 | */ |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 1424 | sdio_claim_host(bus->sdiodev->func[1]); |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 1425 | errcode = brcmf_sdiod_recv_chain(bus->sdiodev, |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 1426 | &bus->glom, dlen); |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 1427 | sdio_release_host(bus->sdiodev->func[1]); |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 1428 | bus->sdcnt.f2rxdata++; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1429 | |
| 1430 | /* On failure, kill the superframe, allow a couple retries */ |
| 1431 | if (errcode < 0) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 1432 | brcmf_err("glom read of %d bytes failed: %d\n", |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1433 | dlen, errcode); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1434 | |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 1435 | sdio_claim_host(bus->sdiodev->func[1]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1436 | if (bus->glomerr++ < 3) { |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 1437 | brcmf_sdio_rxfail(bus, true, true); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1438 | } else { |
| 1439 | bus->glomerr = 0; |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 1440 | brcmf_sdio_rxfail(bus, true, false); |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 1441 | bus->sdcnt.rxglomfail++; |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 1442 | brcmf_sdio_free_glom(bus); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1443 | } |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 1444 | sdio_release_host(bus->sdiodev->func[1]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1445 | return 0; |
| 1446 | } |
Joe Perches | 1e02382 | 2012-01-15 00:38:40 -0800 | [diff] [blame] | 1447 | |
| 1448 | brcmf_dbg_hex_dump(BRCMF_GLOM_ON(), |
| 1449 | pfirst->data, min_t(int, pfirst->len, 48), |
| 1450 | "SUPERFRAME:\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1451 | |
Franky Lin | 9d7d6f9 | 2012-10-22 10:36:24 -0700 | [diff] [blame] | 1452 | rd_new.seq_num = rxseq; |
| 1453 | rd_new.len = dlen; |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 1454 | sdio_claim_host(bus->sdiodev->func[1]); |
Franky Lin | 6bc5231 | 2013-08-10 12:27:28 +0200 | [diff] [blame] | 1455 | errcode = brcmf_sdio_hdparse(bus, pfirst->data, &rd_new, |
| 1456 | BRCMF_SDIO_FT_SUPER); |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 1457 | sdio_release_host(bus->sdiodev->func[1]); |
Franky Lin | 9d7d6f9 | 2012-10-22 10:36:24 -0700 | [diff] [blame] | 1458 | bus->cur_read.len = rd_new.len_nxtfrm << 4; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1459 | |
| 1460 | /* Remove superframe header, remember offset */ |
Franky Lin | 9d7d6f9 | 2012-10-22 10:36:24 -0700 | [diff] [blame] | 1461 | skb_pull(pfirst, rd_new.dat_offset); |
| 1462 | sfdoff = rd_new.dat_offset; |
Arend van Spriel | 0b45bf7 | 2011-11-22 17:21:36 -0800 | [diff] [blame] | 1463 | num = 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1464 | |
| 1465 | /* Validate all the subframe headers */ |
Arend van Spriel | 0b45bf7 | 2011-11-22 17:21:36 -0800 | [diff] [blame] | 1466 | skb_queue_walk(&bus->glom, pnext) { |
| 1467 | /* leave when invalid subframe is found */ |
| 1468 | if (errcode) |
| 1469 | break; |
| 1470 | |
Franky Lin | 9d7d6f9 | 2012-10-22 10:36:24 -0700 | [diff] [blame] | 1471 | rd_new.len = pnext->len; |
| 1472 | rd_new.seq_num = rxseq++; |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 1473 | sdio_claim_host(bus->sdiodev->func[1]); |
Franky Lin | 6bc5231 | 2013-08-10 12:27:28 +0200 | [diff] [blame] | 1474 | errcode = brcmf_sdio_hdparse(bus, pnext->data, &rd_new, |
| 1475 | BRCMF_SDIO_FT_SUB); |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 1476 | sdio_release_host(bus->sdiodev->func[1]); |
Joe Perches | 1e02382 | 2012-01-15 00:38:40 -0800 | [diff] [blame] | 1477 | brcmf_dbg_hex_dump(BRCMF_GLOM_ON(), |
Franky Lin | 9d7d6f9 | 2012-10-22 10:36:24 -0700 | [diff] [blame] | 1478 | pnext->data, 32, "subframe:\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1479 | |
Arend van Spriel | 0b45bf7 | 2011-11-22 17:21:36 -0800 | [diff] [blame] | 1480 | num++; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1481 | } |
| 1482 | |
| 1483 | if (errcode) { |
| 1484 | /* Terminate frame on error, request |
| 1485 | a couple retries */ |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 1486 | sdio_claim_host(bus->sdiodev->func[1]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1487 | if (bus->glomerr++ < 3) { |
| 1488 | /* Restore superframe header space */ |
| 1489 | skb_push(pfirst, sfdoff); |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 1490 | brcmf_sdio_rxfail(bus, true, true); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1491 | } else { |
| 1492 | bus->glomerr = 0; |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 1493 | brcmf_sdio_rxfail(bus, true, false); |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 1494 | bus->sdcnt.rxglomfail++; |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 1495 | brcmf_sdio_free_glom(bus); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1496 | } |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 1497 | sdio_release_host(bus->sdiodev->func[1]); |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1498 | bus->cur_read.len = 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1499 | return 0; |
| 1500 | } |
| 1501 | |
| 1502 | /* Basic SD framing looks ok - process each packet (header) */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1503 | |
Arend van Spriel | 0b45bf7 | 2011-11-22 17:21:36 -0800 | [diff] [blame] | 1504 | skb_queue_walk_safe(&bus->glom, pfirst, pnext) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1505 | dptr = (u8 *) (pfirst->data); |
| 1506 | sublen = get_unaligned_le16(dptr); |
Franky Lin | 6bc5231 | 2013-08-10 12:27:28 +0200 | [diff] [blame] | 1507 | doff = brcmf_sdio_getdatoffset(&dptr[SDPCM_HWHDR_LEN]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1508 | |
Joe Perches | 1e02382 | 2012-01-15 00:38:40 -0800 | [diff] [blame] | 1509 | brcmf_dbg_hex_dump(BRCMF_BYTES_ON() && BRCMF_DATA_ON(), |
Franky Lin | 9d7d6f9 | 2012-10-22 10:36:24 -0700 | [diff] [blame] | 1510 | dptr, pfirst->len, |
| 1511 | "Rx Subframe Data:\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1512 | |
| 1513 | __skb_trim(pfirst, sublen); |
| 1514 | skb_pull(pfirst, doff); |
| 1515 | |
| 1516 | if (pfirst->len == 0) { |
Arend van Spriel | 0b45bf7 | 2011-11-22 17:21:36 -0800 | [diff] [blame] | 1517 | skb_unlink(pfirst, &bus->glom); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1518 | brcmu_pkt_buf_free_skb(pfirst); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1519 | continue; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1520 | } |
| 1521 | |
Joe Perches | 1e02382 | 2012-01-15 00:38:40 -0800 | [diff] [blame] | 1522 | brcmf_dbg_hex_dump(BRCMF_GLOM_ON(), |
| 1523 | pfirst->data, |
| 1524 | min_t(int, pfirst->len, 32), |
| 1525 | "subframe %d to stack, %p (%p/%d) nxt/lnk %p/%p\n", |
| 1526 | bus->glom.qlen, pfirst, pfirst->data, |
| 1527 | pfirst->len, pfirst->next, |
| 1528 | pfirst->prev); |
Arend van Spriel | 05f3820 | 2013-09-25 13:05:46 +0200 | [diff] [blame] | 1529 | skb_unlink(pfirst, &bus->glom); |
| 1530 | brcmf_rx_frame(bus->sdiodev->dev, pfirst); |
| 1531 | bus->sdcnt.rxglompkts++; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1532 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1533 | |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 1534 | bus->sdcnt.rxglomframes++; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1535 | } |
| 1536 | return num; |
| 1537 | } |
| 1538 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 1539 | static int brcmf_sdio_dcmd_resp_wait(struct brcmf_sdio *bus, uint *condition, |
| 1540 | bool *pending) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1541 | { |
| 1542 | DECLARE_WAITQUEUE(wait, current); |
| 1543 | int timeout = msecs_to_jiffies(DCMD_RESP_TIMEOUT); |
| 1544 | |
| 1545 | /* Wait until control frame is available */ |
| 1546 | add_wait_queue(&bus->dcmd_resp_wait, &wait); |
| 1547 | set_current_state(TASK_INTERRUPTIBLE); |
| 1548 | |
| 1549 | while (!(*condition) && (!signal_pending(current) && timeout)) |
| 1550 | timeout = schedule_timeout(timeout); |
| 1551 | |
| 1552 | if (signal_pending(current)) |
| 1553 | *pending = true; |
| 1554 | |
| 1555 | set_current_state(TASK_RUNNING); |
| 1556 | remove_wait_queue(&bus->dcmd_resp_wait, &wait); |
| 1557 | |
| 1558 | return timeout; |
| 1559 | } |
| 1560 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 1561 | static int brcmf_sdio_dcmd_resp_wake(struct brcmf_sdio *bus) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1562 | { |
| 1563 | if (waitqueue_active(&bus->dcmd_resp_wait)) |
| 1564 | wake_up_interruptible(&bus->dcmd_resp_wait); |
| 1565 | |
| 1566 | return 0; |
| 1567 | } |
| 1568 | static void |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 1569 | brcmf_sdio_read_control(struct brcmf_sdio *bus, u8 *hdr, uint len, uint doff) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1570 | { |
| 1571 | uint rdlen, pad; |
Franky Lin | dd43a01 | 2012-11-05 16:22:22 -0800 | [diff] [blame] | 1572 | u8 *buf = NULL, *rbuf; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1573 | int sdret; |
| 1574 | |
| 1575 | brcmf_dbg(TRACE, "Enter\n"); |
| 1576 | |
Franky Lin | dd43a01 | 2012-11-05 16:22:22 -0800 | [diff] [blame] | 1577 | if (bus->rxblen) |
| 1578 | buf = vzalloc(bus->rxblen); |
Joe Perches | 14f8dc4 | 2013-02-07 11:46:27 +0000 | [diff] [blame] | 1579 | if (!buf) |
Franky Lin | dd43a01 | 2012-11-05 16:22:22 -0800 | [diff] [blame] | 1580 | goto done; |
Joe Perches | 14f8dc4 | 2013-02-07 11:46:27 +0000 | [diff] [blame] | 1581 | |
Franky Lin | dd43a01 | 2012-11-05 16:22:22 -0800 | [diff] [blame] | 1582 | rbuf = bus->rxbuf; |
Arend van Spriel | 9b2d2f2 | 2013-11-29 12:25:14 +0100 | [diff] [blame] | 1583 | pad = ((unsigned long)rbuf % bus->head_align); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1584 | if (pad) |
Arend van Spriel | 9b2d2f2 | 2013-11-29 12:25:14 +0100 | [diff] [blame] | 1585 | rbuf += (bus->head_align - pad); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1586 | |
| 1587 | /* Copy the already-read portion over */ |
Franky Lin | dd43a01 | 2012-11-05 16:22:22 -0800 | [diff] [blame] | 1588 | memcpy(buf, hdr, BRCMF_FIRSTREAD); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1589 | if (len <= BRCMF_FIRSTREAD) |
| 1590 | goto gotpkt; |
| 1591 | |
| 1592 | /* Raise rdlen to next SDIO block to avoid tail command */ |
| 1593 | rdlen = len - BRCMF_FIRSTREAD; |
| 1594 | if (bus->roundup && bus->blocksize && (rdlen > bus->blocksize)) { |
| 1595 | pad = bus->blocksize - (rdlen % bus->blocksize); |
| 1596 | if ((pad <= bus->roundup) && (pad < bus->blocksize) && |
Franky Lin | b01a6b3 | 2011-12-16 18:37:03 -0800 | [diff] [blame] | 1597 | ((len + pad) < bus->sdiodev->bus_if->maxctl)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1598 | rdlen += pad; |
Arend van Spriel | 9b2d2f2 | 2013-11-29 12:25:14 +0100 | [diff] [blame] | 1599 | } else if (rdlen % bus->head_align) { |
| 1600 | rdlen += bus->head_align - (rdlen % bus->head_align); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1601 | } |
| 1602 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1603 | /* Drop if the read is too big or it exceeds our maximum */ |
Franky Lin | b01a6b3 | 2011-12-16 18:37:03 -0800 | [diff] [blame] | 1604 | if ((rdlen + BRCMF_FIRSTREAD) > bus->sdiodev->bus_if->maxctl) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 1605 | brcmf_err("%d-byte control read exceeds %d-byte buffer\n", |
Franky Lin | b01a6b3 | 2011-12-16 18:37:03 -0800 | [diff] [blame] | 1606 | rdlen, bus->sdiodev->bus_if->maxctl); |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 1607 | brcmf_sdio_rxfail(bus, false, false); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1608 | goto done; |
| 1609 | } |
| 1610 | |
Franky Lin | b01a6b3 | 2011-12-16 18:37:03 -0800 | [diff] [blame] | 1611 | if ((len - doff) > bus->sdiodev->bus_if->maxctl) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 1612 | brcmf_err("%d-byte ctl frame (%d-byte ctl data) exceeds %d-byte limit\n", |
Franky Lin | b01a6b3 | 2011-12-16 18:37:03 -0800 | [diff] [blame] | 1613 | len, len - doff, bus->sdiodev->bus_if->maxctl); |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 1614 | bus->sdcnt.rx_toolong++; |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 1615 | brcmf_sdio_rxfail(bus, false, false); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1616 | goto done; |
| 1617 | } |
| 1618 | |
Franky Lin | dd43a01 | 2012-11-05 16:22:22 -0800 | [diff] [blame] | 1619 | /* Read remain of frame body */ |
Arend van Spriel | a7cdd82 | 2013-12-12 11:58:59 +0100 | [diff] [blame] | 1620 | sdret = brcmf_sdiod_recv_buf(bus->sdiodev, rbuf, rdlen); |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 1621 | bus->sdcnt.f2rxdata++; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1622 | |
| 1623 | /* Control frame failures need retransmission */ |
| 1624 | if (sdret < 0) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 1625 | brcmf_err("read %d control bytes failed: %d\n", |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1626 | rdlen, sdret); |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 1627 | bus->sdcnt.rxc_errors++; |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 1628 | brcmf_sdio_rxfail(bus, true, true); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1629 | goto done; |
Franky Lin | dd43a01 | 2012-11-05 16:22:22 -0800 | [diff] [blame] | 1630 | } else |
| 1631 | memcpy(buf + BRCMF_FIRSTREAD, rbuf, rdlen); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1632 | |
| 1633 | gotpkt: |
| 1634 | |
Joe Perches | 1e02382 | 2012-01-15 00:38:40 -0800 | [diff] [blame] | 1635 | brcmf_dbg_hex_dump(BRCMF_BYTES_ON() && BRCMF_CTL_ON(), |
Franky Lin | dd43a01 | 2012-11-05 16:22:22 -0800 | [diff] [blame] | 1636 | buf, len, "RxCtrl:\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1637 | |
| 1638 | /* Point to valid data and indicate its length */ |
Franky Lin | dd43a01 | 2012-11-05 16:22:22 -0800 | [diff] [blame] | 1639 | spin_lock_bh(&bus->rxctl_lock); |
| 1640 | if (bus->rxctl) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 1641 | brcmf_err("last control frame is being processed.\n"); |
Franky Lin | dd43a01 | 2012-11-05 16:22:22 -0800 | [diff] [blame] | 1642 | spin_unlock_bh(&bus->rxctl_lock); |
| 1643 | vfree(buf); |
| 1644 | goto done; |
| 1645 | } |
| 1646 | bus->rxctl = buf + doff; |
| 1647 | bus->rxctl_orig = buf; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1648 | bus->rxlen = len - doff; |
Franky Lin | dd43a01 | 2012-11-05 16:22:22 -0800 | [diff] [blame] | 1649 | spin_unlock_bh(&bus->rxctl_lock); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1650 | |
| 1651 | done: |
| 1652 | /* Awake any waiters */ |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 1653 | brcmf_sdio_dcmd_resp_wake(bus); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1654 | } |
| 1655 | |
| 1656 | /* Pad read to blocksize for efficiency */ |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 1657 | static void brcmf_sdio_pad(struct brcmf_sdio *bus, u16 *pad, u16 *rdlen) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1658 | { |
| 1659 | if (bus->roundup && bus->blocksize && *rdlen > bus->blocksize) { |
| 1660 | *pad = bus->blocksize - (*rdlen % bus->blocksize); |
| 1661 | if (*pad <= bus->roundup && *pad < bus->blocksize && |
| 1662 | *rdlen + *pad + BRCMF_FIRSTREAD < MAX_RX_DATASZ) |
| 1663 | *rdlen += *pad; |
Arend van Spriel | 9b2d2f2 | 2013-11-29 12:25:14 +0100 | [diff] [blame] | 1664 | } else if (*rdlen % bus->head_align) { |
| 1665 | *rdlen += bus->head_align - (*rdlen % bus->head_align); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1666 | } |
| 1667 | } |
| 1668 | |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1669 | static uint brcmf_sdio_readframes(struct brcmf_sdio *bus, uint maxframes) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1670 | { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1671 | struct sk_buff *pkt; /* Packet for event or data frames */ |
| 1672 | u16 pad; /* Number of pad bytes to read */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1673 | uint rxleft = 0; /* Remaining number of frames allowed */ |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 1674 | int ret; /* Return code from calls */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1675 | uint rxcount = 0; /* Total frames read */ |
Franky Lin | 6bc5231 | 2013-08-10 12:27:28 +0200 | [diff] [blame] | 1676 | struct brcmf_sdio_hdrinfo *rd = &bus->cur_read, rd_new; |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1677 | u8 head_read = 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1678 | |
| 1679 | brcmf_dbg(TRACE, "Enter\n"); |
| 1680 | |
| 1681 | /* Not finished unless we encounter no more frames indication */ |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1682 | bus->rxpending = true; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1683 | |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1684 | for (rd->seq_num = bus->rx_seq, rxleft = maxframes; |
Franky Lin | 8d169aa | 2011-11-22 17:21:52 -0800 | [diff] [blame] | 1685 | !bus->rxskip && rxleft && |
Franky Lin | 712ac5b | 2011-12-16 18:37:09 -0800 | [diff] [blame] | 1686 | bus->sdiodev->bus_if->state != BRCMF_BUS_DOWN; |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1687 | rd->seq_num++, rxleft--) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1688 | |
| 1689 | /* Handle glomming separately */ |
Arend van Spriel | b83db86 | 2011-10-19 12:51:09 +0200 | [diff] [blame] | 1690 | if (bus->glomd || !skb_queue_empty(&bus->glom)) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1691 | u8 cnt; |
| 1692 | brcmf_dbg(GLOM, "calling rxglom: glomd %p, glom %p\n", |
Arend van Spriel | b83db86 | 2011-10-19 12:51:09 +0200 | [diff] [blame] | 1693 | bus->glomd, skb_peek(&bus->glom)); |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 1694 | cnt = brcmf_sdio_rxglom(bus, rd->seq_num); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1695 | brcmf_dbg(GLOM, "rxglom returned %d\n", cnt); |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1696 | rd->seq_num += cnt - 1; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1697 | rxleft = (rxleft > cnt) ? (rxleft - cnt) : 1; |
| 1698 | continue; |
| 1699 | } |
| 1700 | |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1701 | rd->len_left = rd->len; |
| 1702 | /* read header first for unknow frame length */ |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 1703 | sdio_claim_host(bus->sdiodev->func[1]); |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1704 | if (!rd->len) { |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 1705 | ret = brcmf_sdiod_recv_buf(bus->sdiodev, |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 1706 | bus->rxhdr, BRCMF_FIRSTREAD); |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1707 | bus->sdcnt.f2rxhdrs++; |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 1708 | if (ret < 0) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 1709 | brcmf_err("RXHEADER FAILED: %d\n", |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 1710 | ret); |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1711 | bus->sdcnt.rx_hdrfail++; |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 1712 | brcmf_sdio_rxfail(bus, true, true); |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 1713 | sdio_release_host(bus->sdiodev->func[1]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1714 | continue; |
| 1715 | } |
| 1716 | |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1717 | brcmf_dbg_hex_dump(BRCMF_BYTES_ON() || BRCMF_HDRS_ON(), |
| 1718 | bus->rxhdr, SDPCM_HDRLEN, |
| 1719 | "RxHdr:\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1720 | |
Franky Lin | 6bc5231 | 2013-08-10 12:27:28 +0200 | [diff] [blame] | 1721 | if (brcmf_sdio_hdparse(bus, bus->rxhdr, rd, |
| 1722 | BRCMF_SDIO_FT_NORMAL)) { |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 1723 | sdio_release_host(bus->sdiodev->func[1]); |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1724 | if (!bus->rxpending) |
| 1725 | break; |
| 1726 | else |
| 1727 | continue; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1728 | } |
| 1729 | |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1730 | if (rd->channel == SDPCM_CONTROL_CHANNEL) { |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 1731 | brcmf_sdio_read_control(bus, bus->rxhdr, |
| 1732 | rd->len, |
| 1733 | rd->dat_offset); |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1734 | /* prepare the descriptor for the next read */ |
| 1735 | rd->len = rd->len_nxtfrm << 4; |
| 1736 | rd->len_nxtfrm = 0; |
| 1737 | /* treat all packet as event if we don't know */ |
| 1738 | rd->channel = SDPCM_EVENT_CHANNEL; |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 1739 | sdio_release_host(bus->sdiodev->func[1]); |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1740 | continue; |
| 1741 | } |
| 1742 | rd->len_left = rd->len > BRCMF_FIRSTREAD ? |
| 1743 | rd->len - BRCMF_FIRSTREAD : 0; |
| 1744 | head_read = BRCMF_FIRSTREAD; |
| 1745 | } |
| 1746 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 1747 | brcmf_sdio_pad(bus, &pad, &rd->len_left); |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1748 | |
| 1749 | pkt = brcmu_pkt_buf_get_skb(rd->len_left + head_read + |
Arend van Spriel | 9b2d2f2 | 2013-11-29 12:25:14 +0100 | [diff] [blame] | 1750 | bus->head_align); |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1751 | if (!pkt) { |
| 1752 | /* Give up on data, request rtx of events */ |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 1753 | brcmf_err("brcmu_pkt_buf_get_skb failed\n"); |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 1754 | brcmf_sdio_rxfail(bus, false, |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1755 | RETRYCHAN(rd->channel)); |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 1756 | sdio_release_host(bus->sdiodev->func[1]); |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1757 | continue; |
| 1758 | } |
| 1759 | skb_pull(pkt, head_read); |
Arend van Spriel | 9b2d2f2 | 2013-11-29 12:25:14 +0100 | [diff] [blame] | 1760 | pkt_align(pkt, rd->len_left, bus->head_align); |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1761 | |
Arend van Spriel | a7cdd82 | 2013-12-12 11:58:59 +0100 | [diff] [blame] | 1762 | ret = brcmf_sdiod_recv_pkt(bus->sdiodev, pkt); |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1763 | bus->sdcnt.f2rxdata++; |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 1764 | sdio_release_host(bus->sdiodev->func[1]); |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1765 | |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 1766 | if (ret < 0) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 1767 | brcmf_err("read %d bytes from channel %d failed: %d\n", |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 1768 | rd->len, rd->channel, ret); |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1769 | brcmu_pkt_buf_free_skb(pkt); |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 1770 | sdio_claim_host(bus->sdiodev->func[1]); |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 1771 | brcmf_sdio_rxfail(bus, true, |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1772 | RETRYCHAN(rd->channel)); |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 1773 | sdio_release_host(bus->sdiodev->func[1]); |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1774 | continue; |
| 1775 | } |
| 1776 | |
| 1777 | if (head_read) { |
| 1778 | skb_push(pkt, head_read); |
| 1779 | memcpy(pkt->data, bus->rxhdr, head_read); |
| 1780 | head_read = 0; |
| 1781 | } else { |
| 1782 | memcpy(bus->rxhdr, pkt->data, SDPCM_HDRLEN); |
| 1783 | rd_new.seq_num = rd->seq_num; |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 1784 | sdio_claim_host(bus->sdiodev->func[1]); |
Franky Lin | 6bc5231 | 2013-08-10 12:27:28 +0200 | [diff] [blame] | 1785 | if (brcmf_sdio_hdparse(bus, bus->rxhdr, &rd_new, |
| 1786 | BRCMF_SDIO_FT_NORMAL)) { |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1787 | rd->len = 0; |
| 1788 | brcmu_pkt_buf_free_skb(pkt); |
| 1789 | } |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 1790 | bus->sdcnt.rx_readahead_cnt++; |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1791 | if (rd->len != roundup(rd_new.len, 16)) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 1792 | brcmf_err("frame length mismatch:read %d, should be %d\n", |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1793 | rd->len, |
| 1794 | roundup(rd_new.len, 16) >> 4); |
| 1795 | rd->len = 0; |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 1796 | brcmf_sdio_rxfail(bus, true, true); |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 1797 | sdio_release_host(bus->sdiodev->func[1]); |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1798 | brcmu_pkt_buf_free_skb(pkt); |
| 1799 | continue; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1800 | } |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 1801 | sdio_release_host(bus->sdiodev->func[1]); |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1802 | rd->len_nxtfrm = rd_new.len_nxtfrm; |
| 1803 | rd->channel = rd_new.channel; |
| 1804 | rd->dat_offset = rd_new.dat_offset; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1805 | |
Joe Perches | 1e02382 | 2012-01-15 00:38:40 -0800 | [diff] [blame] | 1806 | brcmf_dbg_hex_dump(!(BRCMF_BYTES_ON() && |
| 1807 | BRCMF_DATA_ON()) && |
| 1808 | BRCMF_HDRS_ON(), |
| 1809 | bus->rxhdr, SDPCM_HDRLEN, |
| 1810 | "RxHdr:\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1811 | |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1812 | if (rd_new.channel == SDPCM_CONTROL_CHANNEL) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 1813 | brcmf_err("readahead on control packet %d?\n", |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1814 | rd_new.seq_num); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1815 | /* Force retry w/normal header read */ |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1816 | rd->len = 0; |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 1817 | sdio_claim_host(bus->sdiodev->func[1]); |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 1818 | brcmf_sdio_rxfail(bus, false, true); |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 1819 | sdio_release_host(bus->sdiodev->func[1]); |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1820 | brcmu_pkt_buf_free_skb(pkt); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1821 | continue; |
| 1822 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1823 | } |
| 1824 | |
Joe Perches | 1e02382 | 2012-01-15 00:38:40 -0800 | [diff] [blame] | 1825 | brcmf_dbg_hex_dump(BRCMF_BYTES_ON() && BRCMF_DATA_ON(), |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1826 | pkt->data, rd->len, "Rx Data:\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1827 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1828 | /* Save superframe descriptor and allocate packet frame */ |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1829 | if (rd->channel == SDPCM_GLOM_CHANNEL) { |
Franky Lin | 6bc5231 | 2013-08-10 12:27:28 +0200 | [diff] [blame] | 1830 | if (SDPCM_GLOMDESC(&bus->rxhdr[SDPCM_HWHDR_LEN])) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1831 | brcmf_dbg(GLOM, "glom descriptor, %d bytes:\n", |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1832 | rd->len); |
Joe Perches | 1e02382 | 2012-01-15 00:38:40 -0800 | [diff] [blame] | 1833 | brcmf_dbg_hex_dump(BRCMF_GLOM_ON(), |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1834 | pkt->data, rd->len, |
Joe Perches | 1e02382 | 2012-01-15 00:38:40 -0800 | [diff] [blame] | 1835 | "Glom Data:\n"); |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1836 | __skb_trim(pkt, rd->len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1837 | skb_pull(pkt, SDPCM_HDRLEN); |
| 1838 | bus->glomd = pkt; |
| 1839 | } else { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 1840 | brcmf_err("%s: glom superframe w/o " |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1841 | "descriptor!\n", __func__); |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 1842 | sdio_claim_host(bus->sdiodev->func[1]); |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 1843 | brcmf_sdio_rxfail(bus, false, false); |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 1844 | sdio_release_host(bus->sdiodev->func[1]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1845 | } |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1846 | /* prepare the descriptor for the next read */ |
| 1847 | rd->len = rd->len_nxtfrm << 4; |
| 1848 | rd->len_nxtfrm = 0; |
| 1849 | /* treat all packet as event if we don't know */ |
| 1850 | rd->channel = SDPCM_EVENT_CHANNEL; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1851 | continue; |
| 1852 | } |
| 1853 | |
| 1854 | /* Fill in packet len and prio, deliver upward */ |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1855 | __skb_trim(pkt, rd->len); |
| 1856 | skb_pull(pkt, rd->dat_offset); |
| 1857 | |
| 1858 | /* prepare the descriptor for the next read */ |
| 1859 | rd->len = rd->len_nxtfrm << 4; |
| 1860 | rd->len_nxtfrm = 0; |
| 1861 | /* treat all packet as event if we don't know */ |
| 1862 | rd->channel = SDPCM_EVENT_CHANNEL; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1863 | |
| 1864 | if (pkt->len == 0) { |
| 1865 | brcmu_pkt_buf_free_skb(pkt); |
| 1866 | continue; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1867 | } |
| 1868 | |
Arend van Spriel | 05f3820 | 2013-09-25 13:05:46 +0200 | [diff] [blame] | 1869 | brcmf_rx_frame(bus->sdiodev->dev, pkt); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1870 | } |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1871 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1872 | rxcount = maxframes - rxleft; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1873 | /* Message if we hit the limit */ |
| 1874 | if (!rxleft) |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1875 | brcmf_dbg(DATA, "hit rx limit of %d frames\n", maxframes); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1876 | else |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1877 | brcmf_dbg(DATA, "processed %d frames\n", rxcount); |
| 1878 | /* Back off rxseq if awaiting rtx, update rx_seq */ |
| 1879 | if (bus->rxskip) |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 1880 | rd->seq_num--; |
| 1881 | bus->rx_seq = rd->seq_num; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1882 | |
| 1883 | return rxcount; |
| 1884 | } |
| 1885 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1886 | static void |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 1887 | brcmf_sdio_wait_event_wakeup(struct brcmf_sdio *bus) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1888 | { |
| 1889 | if (waitqueue_active(&bus->ctrl_wait)) |
| 1890 | wake_up_interruptible(&bus->ctrl_wait); |
| 1891 | return; |
| 1892 | } |
| 1893 | |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 1894 | static int brcmf_sdio_txpkt_hdalign(struct brcmf_sdio *bus, struct sk_buff *pkt) |
| 1895 | { |
Arend van Spriel | e217d1c | 2013-11-29 12:25:13 +0100 | [diff] [blame] | 1896 | u16 head_pad; |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 1897 | u8 *dat_buf; |
| 1898 | |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 1899 | dat_buf = (u8 *)(pkt->data); |
| 1900 | |
| 1901 | /* Check head padding */ |
Arend van Spriel | e217d1c | 2013-11-29 12:25:13 +0100 | [diff] [blame] | 1902 | head_pad = ((unsigned long)dat_buf % bus->head_align); |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 1903 | if (head_pad) { |
| 1904 | if (skb_headroom(pkt) < head_pad) { |
| 1905 | bus->sdiodev->bus_if->tx_realloc++; |
| 1906 | head_pad = 0; |
| 1907 | if (skb_cow(pkt, head_pad)) |
| 1908 | return -ENOMEM; |
| 1909 | } |
| 1910 | skb_push(pkt, head_pad); |
| 1911 | dat_buf = (u8 *)(pkt->data); |
| 1912 | memset(dat_buf, 0, head_pad + bus->tx_hdrlen); |
| 1913 | } |
| 1914 | return head_pad; |
| 1915 | } |
| 1916 | |
Franky Lin | 5491c11 | 2013-09-25 13:05:43 +0200 | [diff] [blame] | 1917 | /** |
| 1918 | * struct brcmf_skbuff_cb reserves first two bytes in sk_buff::cb for |
| 1919 | * bus layer usage. |
| 1920 | */ |
Franky Lin | b05e925 | 2013-08-10 12:27:26 +0200 | [diff] [blame] | 1921 | /* flag marking a dummy skb added for DMA alignment requirement */ |
Franky Lin | 5491c11 | 2013-09-25 13:05:43 +0200 | [diff] [blame] | 1922 | #define ALIGN_SKB_FLAG 0x8000 |
Franky Lin | b05e925 | 2013-08-10 12:27:26 +0200 | [diff] [blame] | 1923 | /* bit mask of data length chopped from the previous packet */ |
Franky Lin | 5491c11 | 2013-09-25 13:05:43 +0200 | [diff] [blame] | 1924 | #define ALIGN_SKB_CHOP_LEN_MASK 0x7fff |
| 1925 | |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 1926 | static int brcmf_sdio_txpkt_prep_sg(struct brcmf_sdio *bus, |
Arend van Spriel | a64304f | 2013-10-15 15:44:56 +0200 | [diff] [blame] | 1927 | struct sk_buff_head *pktq, |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 1928 | struct sk_buff *pkt, u16 total_len) |
Arend van Spriel | a64304f | 2013-10-15 15:44:56 +0200 | [diff] [blame] | 1929 | { |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 1930 | struct brcmf_sdio_dev *sdiodev; |
Arend van Spriel | a64304f | 2013-10-15 15:44:56 +0200 | [diff] [blame] | 1931 | struct sk_buff *pkt_pad; |
Arend van Spriel | e217d1c | 2013-11-29 12:25:13 +0100 | [diff] [blame] | 1932 | u16 tail_pad, tail_chop, chain_pad; |
Arend van Spriel | a64304f | 2013-10-15 15:44:56 +0200 | [diff] [blame] | 1933 | unsigned int blksize; |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 1934 | bool lastfrm; |
| 1935 | int ntail, ret; |
Arend van Spriel | a64304f | 2013-10-15 15:44:56 +0200 | [diff] [blame] | 1936 | |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 1937 | sdiodev = bus->sdiodev; |
Arend van Spriel | a64304f | 2013-10-15 15:44:56 +0200 | [diff] [blame] | 1938 | blksize = sdiodev->func[SDIO_FUNC_2]->cur_blksize; |
Arend van Spriel | a64304f | 2013-10-15 15:44:56 +0200 | [diff] [blame] | 1939 | /* sg entry alignment should be a divisor of block size */ |
Arend van Spriel | e217d1c | 2013-11-29 12:25:13 +0100 | [diff] [blame] | 1940 | WARN_ON(blksize % bus->sgentry_align); |
Arend van Spriel | a64304f | 2013-10-15 15:44:56 +0200 | [diff] [blame] | 1941 | |
| 1942 | /* Check tail padding */ |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 1943 | lastfrm = skb_queue_is_last(pktq, pkt); |
| 1944 | tail_pad = 0; |
Arend van Spriel | e217d1c | 2013-11-29 12:25:13 +0100 | [diff] [blame] | 1945 | tail_chop = pkt->len % bus->sgentry_align; |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 1946 | if (tail_chop) |
Arend van Spriel | e217d1c | 2013-11-29 12:25:13 +0100 | [diff] [blame] | 1947 | tail_pad = bus->sgentry_align - tail_chop; |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 1948 | chain_pad = (total_len + tail_pad) % blksize; |
| 1949 | if (lastfrm && chain_pad) |
| 1950 | tail_pad += blksize - chain_pad; |
Arend van Spriel | a64304f | 2013-10-15 15:44:56 +0200 | [diff] [blame] | 1951 | if (skb_tailroom(pkt) < tail_pad && pkt->len > blksize) { |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 1952 | pkt_pad = bus->txglom_sgpad; |
| 1953 | if (pkt_pad == NULL) |
| 1954 | brcmu_pkt_buf_get_skb(tail_pad + tail_chop); |
Arend van Spriel | a64304f | 2013-10-15 15:44:56 +0200 | [diff] [blame] | 1955 | if (pkt_pad == NULL) |
| 1956 | return -ENOMEM; |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 1957 | ret = brcmf_sdio_txpkt_hdalign(bus, pkt_pad); |
| 1958 | if (unlikely(ret < 0)) |
| 1959 | return ret; |
Arend van Spriel | a64304f | 2013-10-15 15:44:56 +0200 | [diff] [blame] | 1960 | memcpy(pkt_pad->data, |
| 1961 | pkt->data + pkt->len - tail_chop, |
| 1962 | tail_chop); |
| 1963 | *(u32 *)(pkt_pad->cb) = ALIGN_SKB_FLAG + tail_chop; |
| 1964 | skb_trim(pkt, pkt->len - tail_chop); |
| 1965 | __skb_queue_after(pktq, pkt, pkt_pad); |
| 1966 | } else { |
| 1967 | ntail = pkt->data_len + tail_pad - |
| 1968 | (pkt->end - pkt->tail); |
| 1969 | if (skb_cloned(pkt) || ntail > 0) |
| 1970 | if (pskb_expand_head(pkt, 0, ntail, GFP_ATOMIC)) |
| 1971 | return -ENOMEM; |
| 1972 | if (skb_linearize(pkt)) |
| 1973 | return -ENOMEM; |
Arend van Spriel | a64304f | 2013-10-15 15:44:56 +0200 | [diff] [blame] | 1974 | __skb_put(pkt, tail_pad); |
| 1975 | } |
| 1976 | |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 1977 | return tail_pad; |
Arend van Spriel | a64304f | 2013-10-15 15:44:56 +0200 | [diff] [blame] | 1978 | } |
| 1979 | |
Franky Lin | b05e925 | 2013-08-10 12:27:26 +0200 | [diff] [blame] | 1980 | /** |
| 1981 | * brcmf_sdio_txpkt_prep - packet preparation for transmit |
| 1982 | * @bus: brcmf_sdio structure pointer |
| 1983 | * @pktq: packet list pointer |
| 1984 | * @chan: virtual channel to transmit the packet |
| 1985 | * |
| 1986 | * Processes to be applied to the packet |
| 1987 | * - Align data buffer pointer |
| 1988 | * - Align data buffer length |
| 1989 | * - Prepare header |
| 1990 | * Return: negative value if there is error |
| 1991 | */ |
| 1992 | static int |
| 1993 | brcmf_sdio_txpkt_prep(struct brcmf_sdio *bus, struct sk_buff_head *pktq, |
| 1994 | uint chan) |
| 1995 | { |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 1996 | u16 head_pad, total_len; |
Arend van Spriel | a64304f | 2013-10-15 15:44:56 +0200 | [diff] [blame] | 1997 | struct sk_buff *pkt_next; |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 1998 | u8 txseq; |
| 1999 | int ret; |
Franky Lin | 6bc5231 | 2013-08-10 12:27:28 +0200 | [diff] [blame] | 2000 | struct brcmf_sdio_hdrinfo hd_info = {0}; |
Franky Lin | b05e925 | 2013-08-10 12:27:26 +0200 | [diff] [blame] | 2001 | |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 2002 | txseq = bus->tx_seq; |
| 2003 | total_len = 0; |
| 2004 | skb_queue_walk(pktq, pkt_next) { |
| 2005 | /* alignment packet inserted in previous |
| 2006 | * loop cycle can be skipped as it is |
| 2007 | * already properly aligned and does not |
| 2008 | * need an sdpcm header. |
| 2009 | */ |
| 2010 | if (*(u32 *)(pkt_next->cb) & ALIGN_SKB_FLAG) |
| 2011 | continue; |
Franky Lin | b05e925 | 2013-08-10 12:27:26 +0200 | [diff] [blame] | 2012 | |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 2013 | /* align packet data pointer */ |
| 2014 | ret = brcmf_sdio_txpkt_hdalign(bus, pkt_next); |
| 2015 | if (ret < 0) |
| 2016 | return ret; |
| 2017 | head_pad = (u16)ret; |
| 2018 | if (head_pad) |
| 2019 | memset(pkt_next->data, 0, head_pad + bus->tx_hdrlen); |
Franky Lin | b05e925 | 2013-08-10 12:27:26 +0200 | [diff] [blame] | 2020 | |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 2021 | total_len += pkt_next->len; |
Franky Lin | b05e925 | 2013-08-10 12:27:26 +0200 | [diff] [blame] | 2022 | |
Arend van Spriel | a64304f | 2013-10-15 15:44:56 +0200 | [diff] [blame] | 2023 | hd_info.len = pkt_next->len; |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 2024 | hd_info.lastfrm = skb_queue_is_last(pktq, pkt_next); |
| 2025 | if (bus->txglom && pktq->qlen > 1) { |
| 2026 | ret = brcmf_sdio_txpkt_prep_sg(bus, pktq, |
| 2027 | pkt_next, total_len); |
| 2028 | if (ret < 0) |
| 2029 | return ret; |
| 2030 | hd_info.tail_pad = (u16)ret; |
| 2031 | total_len += (u16)ret; |
| 2032 | } |
| 2033 | |
| 2034 | hd_info.channel = chan; |
| 2035 | hd_info.dat_offset = head_pad + bus->tx_hdrlen; |
| 2036 | hd_info.seq_num = txseq++; |
| 2037 | |
| 2038 | /* Now fill the header */ |
| 2039 | brcmf_sdio_hdpack(bus, pkt_next->data, &hd_info); |
| 2040 | |
| 2041 | if (BRCMF_BYTES_ON() && |
| 2042 | ((BRCMF_CTL_ON() && chan == SDPCM_CONTROL_CHANNEL) || |
| 2043 | (BRCMF_DATA_ON() && chan != SDPCM_CONTROL_CHANNEL))) |
| 2044 | brcmf_dbg_hex_dump(true, pkt_next, hd_info.len, |
| 2045 | "Tx Frame:\n"); |
| 2046 | else if (BRCMF_HDRS_ON()) |
| 2047 | brcmf_dbg_hex_dump(true, pkt_next, |
| 2048 | head_pad + bus->tx_hdrlen, |
| 2049 | "Tx Header:\n"); |
Franky Lin | b05e925 | 2013-08-10 12:27:26 +0200 | [diff] [blame] | 2050 | } |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 2051 | /* Hardware length tag of the first packet should be total |
| 2052 | * length of the chain (including padding) |
| 2053 | */ |
| 2054 | if (bus->txglom) |
| 2055 | brcmf_sdio_update_hwhdr(pktq->next->data, total_len); |
Franky Lin | b05e925 | 2013-08-10 12:27:26 +0200 | [diff] [blame] | 2056 | return 0; |
| 2057 | } |
| 2058 | |
| 2059 | /** |
| 2060 | * brcmf_sdio_txpkt_postp - packet post processing for transmit |
| 2061 | * @bus: brcmf_sdio structure pointer |
| 2062 | * @pktq: packet list pointer |
| 2063 | * |
| 2064 | * Processes to be applied to the packet |
| 2065 | * - Remove head padding |
| 2066 | * - Remove tail padding |
| 2067 | */ |
| 2068 | static void |
| 2069 | brcmf_sdio_txpkt_postp(struct brcmf_sdio *bus, struct sk_buff_head *pktq) |
| 2070 | { |
| 2071 | u8 *hdr; |
| 2072 | u32 dat_offset; |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 2073 | u16 tail_pad; |
Franky Lin | b05e925 | 2013-08-10 12:27:26 +0200 | [diff] [blame] | 2074 | u32 dummy_flags, chop_len; |
| 2075 | struct sk_buff *pkt_next, *tmp, *pkt_prev; |
| 2076 | |
| 2077 | skb_queue_walk_safe(pktq, pkt_next, tmp) { |
| 2078 | dummy_flags = *(u32 *)(pkt_next->cb); |
Franky Lin | 5491c11 | 2013-09-25 13:05:43 +0200 | [diff] [blame] | 2079 | if (dummy_flags & ALIGN_SKB_FLAG) { |
| 2080 | chop_len = dummy_flags & ALIGN_SKB_CHOP_LEN_MASK; |
Franky Lin | b05e925 | 2013-08-10 12:27:26 +0200 | [diff] [blame] | 2081 | if (chop_len) { |
| 2082 | pkt_prev = pkt_next->prev; |
Franky Lin | b05e925 | 2013-08-10 12:27:26 +0200 | [diff] [blame] | 2083 | skb_put(pkt_prev, chop_len); |
| 2084 | } |
| 2085 | __skb_unlink(pkt_next, pktq); |
| 2086 | brcmu_pkt_buf_free_skb(pkt_next); |
| 2087 | } else { |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 2088 | hdr = pkt_next->data + bus->tx_hdrlen - SDPCM_SWHDR_LEN; |
Franky Lin | b05e925 | 2013-08-10 12:27:26 +0200 | [diff] [blame] | 2089 | dat_offset = le32_to_cpu(*(__le32 *)hdr); |
| 2090 | dat_offset = (dat_offset & SDPCM_DOFFSET_MASK) >> |
| 2091 | SDPCM_DOFFSET_SHIFT; |
| 2092 | skb_pull(pkt_next, dat_offset); |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 2093 | if (bus->txglom) { |
| 2094 | tail_pad = le16_to_cpu(*(__le16 *)(hdr - 2)); |
| 2095 | skb_trim(pkt_next, pkt_next->len - tail_pad); |
| 2096 | } |
Franky Lin | b05e925 | 2013-08-10 12:27:26 +0200 | [diff] [blame] | 2097 | } |
| 2098 | } |
| 2099 | } |
| 2100 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2101 | /* Writes a HW/SW header into the packet and sends it. */ |
| 2102 | /* Assumes: (a) header space already there, (b) caller holds lock */ |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 2103 | static int brcmf_sdio_txpkt(struct brcmf_sdio *bus, struct sk_buff_head *pktq, |
| 2104 | uint chan) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2105 | { |
| 2106 | int ret; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2107 | int i; |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 2108 | struct sk_buff *pkt_next, *tmp; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2109 | |
| 2110 | brcmf_dbg(TRACE, "Enter\n"); |
| 2111 | |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 2112 | ret = brcmf_sdio_txpkt_prep(bus, pktq, chan); |
Franky Lin | b05e925 | 2013-08-10 12:27:26 +0200 | [diff] [blame] | 2113 | if (ret) |
| 2114 | goto done; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2115 | |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 2116 | sdio_claim_host(bus->sdiodev->func[1]); |
Arend van Spriel | a7cdd82 | 2013-12-12 11:58:59 +0100 | [diff] [blame] | 2117 | ret = brcmf_sdiod_send_pkt(bus->sdiodev, pktq); |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 2118 | bus->sdcnt.f2txdata++; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2119 | |
| 2120 | if (ret < 0) { |
| 2121 | /* On failure, abort the command and terminate the frame */ |
| 2122 | brcmf_dbg(INFO, "sdio error %d, abort command and terminate frame\n", |
| 2123 | ret); |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 2124 | bus->sdcnt.tx_sderrs++; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2125 | |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 2126 | brcmf_sdiod_abort(bus->sdiodev, SDIO_FUNC_2); |
| 2127 | brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_FRAMECTRL, |
| 2128 | SFC_WF_TERM, NULL); |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 2129 | bus->sdcnt.f1regdata++; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2130 | |
| 2131 | for (i = 0; i < 3; i++) { |
| 2132 | u8 hi, lo; |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 2133 | hi = brcmf_sdiod_regrb(bus->sdiodev, |
| 2134 | SBSDIO_FUNC1_WFRAMEBCHI, NULL); |
| 2135 | lo = brcmf_sdiod_regrb(bus->sdiodev, |
| 2136 | SBSDIO_FUNC1_WFRAMEBCLO, NULL); |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 2137 | bus->sdcnt.f1regdata += 2; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2138 | if ((hi == 0) && (lo == 0)) |
| 2139 | break; |
| 2140 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2141 | } |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 2142 | sdio_release_host(bus->sdiodev->func[1]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2143 | |
| 2144 | done: |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 2145 | brcmf_sdio_txpkt_postp(bus, pktq); |
| 2146 | if (ret == 0) |
| 2147 | bus->tx_seq = (bus->tx_seq + pktq->qlen) % SDPCM_SEQ_WRAP; |
| 2148 | skb_queue_walk_safe(pktq, pkt_next, tmp) { |
| 2149 | __skb_unlink(pkt_next, pktq); |
| 2150 | brcmf_txcomplete(bus->sdiodev->dev, pkt_next, ret == 0); |
| 2151 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2152 | return ret; |
| 2153 | } |
| 2154 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 2155 | static uint brcmf_sdio_sendfromq(struct brcmf_sdio *bus, uint maxframes) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2156 | { |
| 2157 | struct sk_buff *pkt; |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 2158 | struct sk_buff_head pktq; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2159 | u32 intstatus = 0; |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 2160 | int ret = 0, prec_out, i; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2161 | uint cnt = 0; |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 2162 | u8 tx_prec_map, pkt_num; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2163 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2164 | brcmf_dbg(TRACE, "Enter\n"); |
| 2165 | |
| 2166 | tx_prec_map = ~bus->flowcontrol; |
| 2167 | |
| 2168 | /* Send frames until the limit or some other event */ |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 2169 | for (cnt = 0; (cnt < maxframes) && data_ok(bus);) { |
| 2170 | pkt_num = 1; |
| 2171 | __skb_queue_head_init(&pktq); |
| 2172 | if (bus->txglom) |
| 2173 | pkt_num = min_t(u8, bus->tx_max - bus->tx_seq, |
| 2174 | brcmf_sdio_txglomsz); |
| 2175 | pkt_num = min_t(u32, pkt_num, |
| 2176 | brcmu_pktq_mlen(&bus->txq, ~bus->flowcontrol)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2177 | spin_lock_bh(&bus->txqlock); |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 2178 | for (i = 0; i < pkt_num; i++) { |
| 2179 | pkt = brcmu_pktq_mdeq(&bus->txq, tx_prec_map, |
| 2180 | &prec_out); |
| 2181 | if (pkt == NULL) |
| 2182 | break; |
| 2183 | __skb_queue_tail(&pktq, pkt); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2184 | } |
| 2185 | spin_unlock_bh(&bus->txqlock); |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 2186 | if (i == 0) |
| 2187 | break; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2188 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 2189 | ret = brcmf_sdio_txpkt(bus, &pktq, SDPCM_DATA_CHANNEL); |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 2190 | cnt += i; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2191 | |
| 2192 | /* In poll mode, need to check for other events */ |
| 2193 | if (!bus->intr && cnt) { |
| 2194 | /* Check device status, signal pending interrupt */ |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 2195 | sdio_claim_host(bus->sdiodev->func[1]); |
Franky Lin | 5c15c23 | 2012-05-04 18:27:37 -0700 | [diff] [blame] | 2196 | ret = r_sdreg32(bus, &intstatus, |
| 2197 | offsetof(struct sdpcmd_regs, |
| 2198 | intstatus)); |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 2199 | sdio_release_host(bus->sdiodev->func[1]); |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 2200 | bus->sdcnt.f2txdata++; |
Franky Lin | 5c15c23 | 2012-05-04 18:27:37 -0700 | [diff] [blame] | 2201 | if (ret != 0) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2202 | break; |
| 2203 | if (intstatus & bus->hostintmask) |
Franky Lin | 1d38227 | 2012-09-13 21:11:59 +0200 | [diff] [blame] | 2204 | atomic_set(&bus->ipend, 1); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2205 | } |
| 2206 | } |
| 2207 | |
| 2208 | /* Deflow-control stack if needed */ |
Hante Meuleman | 05dde97 | 2013-02-06 18:40:36 +0100 | [diff] [blame] | 2209 | if ((bus->sdiodev->bus_if->state == BRCMF_BUS_DATA) && |
Franky Lin | c8bf348 | 2011-12-16 18:37:08 -0800 | [diff] [blame] | 2210 | bus->txoff && (pktq_len(&bus->txq) < TXLOW)) { |
Hante Meuleman | 90d03ff | 2012-09-11 21:18:46 +0200 | [diff] [blame] | 2211 | bus->txoff = false; |
| 2212 | brcmf_txflowblock(bus->sdiodev->dev, false); |
Franky Lin | c8bf348 | 2011-12-16 18:37:08 -0800 | [diff] [blame] | 2213 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2214 | |
| 2215 | return cnt; |
| 2216 | } |
| 2217 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 2218 | static void brcmf_sdio_bus_stop(struct device *dev) |
Franky Lin | a9ffda8 | 2011-12-16 18:37:12 -0800 | [diff] [blame] | 2219 | { |
| 2220 | u32 local_hostintmask; |
| 2221 | u8 saveclk; |
Franky Lin | a9ffda8 | 2011-12-16 18:37:12 -0800 | [diff] [blame] | 2222 | int err; |
| 2223 | struct brcmf_bus *bus_if = dev_get_drvdata(dev); |
Arend van Spriel | 0a332e4 | 2012-02-09 21:09:02 +0100 | [diff] [blame] | 2224 | struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio; |
Franky Lin | a9ffda8 | 2011-12-16 18:37:12 -0800 | [diff] [blame] | 2225 | struct brcmf_sdio *bus = sdiodev->bus; |
| 2226 | |
| 2227 | brcmf_dbg(TRACE, "Enter\n"); |
| 2228 | |
| 2229 | if (bus->watchdog_tsk) { |
| 2230 | send_sig(SIGTERM, bus->watchdog_tsk, 1); |
| 2231 | kthread_stop(bus->watchdog_tsk); |
| 2232 | bus->watchdog_tsk = NULL; |
| 2233 | } |
| 2234 | |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 2235 | sdio_claim_host(bus->sdiodev->func[1]); |
Franky Lin | a9ffda8 | 2011-12-16 18:37:12 -0800 | [diff] [blame] | 2236 | |
Franky Lin | a9ffda8 | 2011-12-16 18:37:12 -0800 | [diff] [blame] | 2237 | /* Enable clock for device interrupts */ |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 2238 | brcmf_sdio_bus_sleep(bus, false, false); |
Franky Lin | a9ffda8 | 2011-12-16 18:37:12 -0800 | [diff] [blame] | 2239 | |
| 2240 | /* Disable and clear interrupts at the chip level also */ |
Franky Lin | 5869275 | 2012-05-04 18:27:36 -0700 | [diff] [blame] | 2241 | w_sdreg32(bus, 0, offsetof(struct sdpcmd_regs, hostintmask)); |
Franky Lin | a9ffda8 | 2011-12-16 18:37:12 -0800 | [diff] [blame] | 2242 | local_hostintmask = bus->hostintmask; |
| 2243 | bus->hostintmask = 0; |
| 2244 | |
| 2245 | /* Change our idea of bus state */ |
| 2246 | bus->sdiodev->bus_if->state = BRCMF_BUS_DOWN; |
| 2247 | |
| 2248 | /* Force clocks on backplane to be sure F2 interrupt propagates */ |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 2249 | saveclk = brcmf_sdiod_regrb(bus->sdiodev, |
| 2250 | SBSDIO_FUNC1_CHIPCLKCSR, &err); |
Franky Lin | a9ffda8 | 2011-12-16 18:37:12 -0800 | [diff] [blame] | 2251 | if (!err) { |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 2252 | brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, |
| 2253 | (saveclk | SBSDIO_FORCE_HT), &err); |
Franky Lin | a9ffda8 | 2011-12-16 18:37:12 -0800 | [diff] [blame] | 2254 | } |
| 2255 | if (err) |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 2256 | brcmf_err("Failed to force clock for F2: err %d\n", err); |
Franky Lin | a9ffda8 | 2011-12-16 18:37:12 -0800 | [diff] [blame] | 2257 | |
| 2258 | /* Turn off the bus (F2), free any pending packets */ |
| 2259 | brcmf_dbg(INTR, "disable SDIO interrupts\n"); |
Arend van Spriel | 71370eb | 2013-12-12 11:58:53 +0100 | [diff] [blame] | 2260 | sdio_disable_func(bus->sdiodev->func[SDIO_FUNC_2]); |
Franky Lin | a9ffda8 | 2011-12-16 18:37:12 -0800 | [diff] [blame] | 2261 | |
| 2262 | /* Clear any pending interrupts now that F2 is disabled */ |
| 2263 | w_sdreg32(bus, local_hostintmask, |
Franky Lin | 5869275 | 2012-05-04 18:27:36 -0700 | [diff] [blame] | 2264 | offsetof(struct sdpcmd_regs, intstatus)); |
Franky Lin | a9ffda8 | 2011-12-16 18:37:12 -0800 | [diff] [blame] | 2265 | |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 2266 | sdio_release_host(bus->sdiodev->func[1]); |
Franky Lin | a9ffda8 | 2011-12-16 18:37:12 -0800 | [diff] [blame] | 2267 | |
| 2268 | /* Clear the data packet queues */ |
| 2269 | brcmu_pktq_flush(&bus->txq, true, NULL, NULL); |
| 2270 | |
| 2271 | /* Clear any held glomming stuff */ |
| 2272 | if (bus->glomd) |
| 2273 | brcmu_pkt_buf_free_skb(bus->glomd); |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 2274 | brcmf_sdio_free_glom(bus); |
Franky Lin | a9ffda8 | 2011-12-16 18:37:12 -0800 | [diff] [blame] | 2275 | |
| 2276 | /* Clear rx control and wake any waiters */ |
Franky Lin | dd43a01 | 2012-11-05 16:22:22 -0800 | [diff] [blame] | 2277 | spin_lock_bh(&bus->rxctl_lock); |
Franky Lin | a9ffda8 | 2011-12-16 18:37:12 -0800 | [diff] [blame] | 2278 | bus->rxlen = 0; |
Franky Lin | dd43a01 | 2012-11-05 16:22:22 -0800 | [diff] [blame] | 2279 | spin_unlock_bh(&bus->rxctl_lock); |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 2280 | brcmf_sdio_dcmd_resp_wake(bus); |
Franky Lin | a9ffda8 | 2011-12-16 18:37:12 -0800 | [diff] [blame] | 2281 | |
| 2282 | /* Reset some F2 state stuff */ |
| 2283 | bus->rxskip = false; |
| 2284 | bus->tx_seq = bus->rx_seq = 0; |
Franky Lin | a9ffda8 | 2011-12-16 18:37:12 -0800 | [diff] [blame] | 2285 | } |
| 2286 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 2287 | static inline void brcmf_sdio_clrintr(struct brcmf_sdio *bus) |
Franky Lin | ba89bf1 | 2012-04-27 18:56:59 -0700 | [diff] [blame] | 2288 | { |
| 2289 | unsigned long flags; |
| 2290 | |
Hante Meuleman | 668761a | 2013-04-12 10:55:55 +0200 | [diff] [blame] | 2291 | if (bus->sdiodev->oob_irq_requested) { |
| 2292 | spin_lock_irqsave(&bus->sdiodev->irq_en_lock, flags); |
| 2293 | if (!bus->sdiodev->irq_en && !atomic_read(&bus->ipend)) { |
| 2294 | enable_irq(bus->sdiodev->pdata->oob_irq_nr); |
| 2295 | bus->sdiodev->irq_en = true; |
| 2296 | } |
| 2297 | spin_unlock_irqrestore(&bus->sdiodev->irq_en_lock, flags); |
Franky Lin | ba89bf1 | 2012-04-27 18:56:59 -0700 | [diff] [blame] | 2298 | } |
Franky Lin | ba89bf1 | 2012-04-27 18:56:59 -0700 | [diff] [blame] | 2299 | } |
Franky Lin | ba89bf1 | 2012-04-27 18:56:59 -0700 | [diff] [blame] | 2300 | |
Franky Lin | 4531603 | 2012-09-13 21:12:03 +0200 | [diff] [blame] | 2301 | static int brcmf_sdio_intr_rstatus(struct brcmf_sdio *bus) |
| 2302 | { |
| 2303 | u8 idx; |
| 2304 | u32 addr; |
| 2305 | unsigned long val; |
| 2306 | int n, ret; |
| 2307 | |
| 2308 | idx = brcmf_sdio_chip_getinfidx(bus->ci, BCMA_CORE_SDIO_DEV); |
| 2309 | addr = bus->ci->c_inf[idx].base + |
| 2310 | offsetof(struct sdpcmd_regs, intstatus); |
| 2311 | |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 2312 | val = brcmf_sdiod_regrl(bus->sdiodev, addr, &ret); |
Franky Lin | 4531603 | 2012-09-13 21:12:03 +0200 | [diff] [blame] | 2313 | bus->sdcnt.f1regdata++; |
| 2314 | if (ret != 0) |
| 2315 | val = 0; |
| 2316 | |
| 2317 | val &= bus->hostintmask; |
| 2318 | atomic_set(&bus->fcstate, !!(val & I_HMB_FC_STATE)); |
| 2319 | |
| 2320 | /* Clear interrupts */ |
| 2321 | if (val) { |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 2322 | brcmf_sdiod_regwl(bus->sdiodev, addr, val, &ret); |
Franky Lin | 4531603 | 2012-09-13 21:12:03 +0200 | [diff] [blame] | 2323 | bus->sdcnt.f1regdata++; |
| 2324 | } |
| 2325 | |
| 2326 | if (ret) { |
| 2327 | atomic_set(&bus->intstatus, 0); |
| 2328 | } else if (val) { |
| 2329 | for_each_set_bit(n, &val, 32) |
| 2330 | set_bit(n, (unsigned long *)&bus->intstatus.counter); |
| 2331 | } |
| 2332 | |
| 2333 | return ret; |
| 2334 | } |
| 2335 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 2336 | static void brcmf_sdio_dpc(struct brcmf_sdio *bus) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2337 | { |
Franky Lin | 4531603 | 2012-09-13 21:12:03 +0200 | [diff] [blame] | 2338 | u32 newstatus = 0; |
| 2339 | unsigned long intstatus; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2340 | uint rxlimit = bus->rxbound; /* Rx frames to read before resched */ |
| 2341 | uint txlimit = bus->txbound; /* Tx frames to send before resched */ |
| 2342 | uint framecnt = 0; /* Temporary counter of tx/rx frames */ |
Franky Lin | 4531603 | 2012-09-13 21:12:03 +0200 | [diff] [blame] | 2343 | int err = 0, n; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2344 | |
| 2345 | brcmf_dbg(TRACE, "Enter\n"); |
| 2346 | |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 2347 | sdio_claim_host(bus->sdiodev->func[1]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2348 | |
| 2349 | /* If waiting for HTAVAIL, check status */ |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 2350 | if (!bus->sr_enabled && bus->clkstate == CLK_PENDING) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2351 | u8 clkctl, devctl = 0; |
| 2352 | |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 2353 | #ifdef DEBUG |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2354 | /* Check for inconsistent device control */ |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 2355 | devctl = brcmf_sdiod_regrb(bus->sdiodev, |
| 2356 | SBSDIO_DEVICE_CTL, &err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2357 | if (err) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 2358 | brcmf_err("error reading DEVCTL: %d\n", err); |
Franky Lin | 712ac5b | 2011-12-16 18:37:09 -0800 | [diff] [blame] | 2359 | bus->sdiodev->bus_if->state = BRCMF_BUS_DOWN; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2360 | } |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 2361 | #endif /* DEBUG */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2362 | |
| 2363 | /* Read CSR, if clock on switch to AVAIL, else ignore */ |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 2364 | clkctl = brcmf_sdiod_regrb(bus->sdiodev, |
| 2365 | SBSDIO_FUNC1_CHIPCLKCSR, &err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2366 | if (err) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 2367 | brcmf_err("error reading CSR: %d\n", |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2368 | err); |
Franky Lin | 712ac5b | 2011-12-16 18:37:09 -0800 | [diff] [blame] | 2369 | bus->sdiodev->bus_if->state = BRCMF_BUS_DOWN; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2370 | } |
| 2371 | |
Arend van Spriel | c320337 | 2013-04-03 12:40:44 +0200 | [diff] [blame] | 2372 | brcmf_dbg(SDIO, "DPC: PENDING, devctl 0x%02x clkctl 0x%02x\n", |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2373 | devctl, clkctl); |
| 2374 | |
| 2375 | if (SBSDIO_HTAV(clkctl)) { |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 2376 | devctl = brcmf_sdiod_regrb(bus->sdiodev, |
| 2377 | SBSDIO_DEVICE_CTL, &err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2378 | if (err) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 2379 | brcmf_err("error reading DEVCTL: %d\n", |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2380 | err); |
Franky Lin | 712ac5b | 2011-12-16 18:37:09 -0800 | [diff] [blame] | 2381 | bus->sdiodev->bus_if->state = BRCMF_BUS_DOWN; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2382 | } |
| 2383 | devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY; |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 2384 | brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_DEVICE_CTL, |
| 2385 | devctl, &err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2386 | if (err) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 2387 | brcmf_err("error writing DEVCTL: %d\n", |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2388 | err); |
Franky Lin | 712ac5b | 2011-12-16 18:37:09 -0800 | [diff] [blame] | 2389 | bus->sdiodev->bus_if->state = BRCMF_BUS_DOWN; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2390 | } |
| 2391 | bus->clkstate = CLK_AVAIL; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2392 | } |
| 2393 | } |
| 2394 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2395 | /* Make sure backplane clock is on */ |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 2396 | brcmf_sdio_bus_sleep(bus, false, true); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2397 | |
| 2398 | /* Pending interrupt indicates new device status */ |
Franky Lin | 1d38227 | 2012-09-13 21:11:59 +0200 | [diff] [blame] | 2399 | if (atomic_read(&bus->ipend) > 0) { |
| 2400 | atomic_set(&bus->ipend, 0); |
Franky Lin | 4531603 | 2012-09-13 21:12:03 +0200 | [diff] [blame] | 2401 | err = brcmf_sdio_intr_rstatus(bus); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2402 | } |
| 2403 | |
Franky Lin | 4531603 | 2012-09-13 21:12:03 +0200 | [diff] [blame] | 2404 | /* Start with leftover status bits */ |
| 2405 | intstatus = atomic_xchg(&bus->intstatus, 0); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2406 | |
| 2407 | /* Handle flow-control change: read new state in case our ack |
| 2408 | * crossed another change interrupt. If change still set, assume |
| 2409 | * FC ON for safety, let next loop through do the debounce. |
| 2410 | */ |
| 2411 | if (intstatus & I_HMB_FC_CHANGE) { |
| 2412 | intstatus &= ~I_HMB_FC_CHANGE; |
Franky Lin | 5c15c23 | 2012-05-04 18:27:37 -0700 | [diff] [blame] | 2413 | err = w_sdreg32(bus, I_HMB_FC_CHANGE, |
| 2414 | offsetof(struct sdpcmd_regs, intstatus)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2415 | |
Franky Lin | 5c15c23 | 2012-05-04 18:27:37 -0700 | [diff] [blame] | 2416 | err = r_sdreg32(bus, &newstatus, |
| 2417 | offsetof(struct sdpcmd_regs, intstatus)); |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 2418 | bus->sdcnt.f1regdata += 2; |
Franky Lin | 4531603 | 2012-09-13 21:12:03 +0200 | [diff] [blame] | 2419 | atomic_set(&bus->fcstate, |
| 2420 | !!(newstatus & (I_HMB_FC_STATE | I_HMB_FC_CHANGE))); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2421 | intstatus |= (newstatus & bus->hostintmask); |
| 2422 | } |
| 2423 | |
| 2424 | /* Handle host mailbox indication */ |
| 2425 | if (intstatus & I_HMB_HOST_INT) { |
| 2426 | intstatus &= ~I_HMB_HOST_INT; |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 2427 | intstatus |= brcmf_sdio_hostmail(bus); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2428 | } |
| 2429 | |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 2430 | sdio_release_host(bus->sdiodev->func[1]); |
Franky Lin | 7cdf57d | 2012-11-05 16:22:23 -0800 | [diff] [blame] | 2431 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2432 | /* Generally don't ask for these, can get CRC errors... */ |
| 2433 | if (intstatus & I_WR_OOSYNC) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 2434 | brcmf_err("Dongle reports WR_OOSYNC\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2435 | intstatus &= ~I_WR_OOSYNC; |
| 2436 | } |
| 2437 | |
| 2438 | if (intstatus & I_RD_OOSYNC) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 2439 | brcmf_err("Dongle reports RD_OOSYNC\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2440 | intstatus &= ~I_RD_OOSYNC; |
| 2441 | } |
| 2442 | |
| 2443 | if (intstatus & I_SBINT) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 2444 | brcmf_err("Dongle reports SBINT\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2445 | intstatus &= ~I_SBINT; |
| 2446 | } |
| 2447 | |
| 2448 | /* Would be active due to wake-wlan in gSPI */ |
| 2449 | if (intstatus & I_CHIPACTIVE) { |
| 2450 | brcmf_dbg(INFO, "Dongle reports CHIPACTIVE\n"); |
| 2451 | intstatus &= ~I_CHIPACTIVE; |
| 2452 | } |
| 2453 | |
| 2454 | /* Ignore frame indications if rxskip is set */ |
| 2455 | if (bus->rxskip) |
| 2456 | intstatus &= ~I_HMB_FRAME_IND; |
| 2457 | |
| 2458 | /* On frame indication, read available frames */ |
Franky Lin | 03d5c36 | 2012-09-13 21:12:01 +0200 | [diff] [blame] | 2459 | if (PKT_AVAILABLE() && bus->clkstate == CLK_AVAIL) { |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 2460 | framecnt = brcmf_sdio_readframes(bus, rxlimit); |
| 2461 | if (!bus->rxpending) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2462 | intstatus &= ~I_HMB_FRAME_IND; |
| 2463 | rxlimit -= min(framecnt, rxlimit); |
| 2464 | } |
| 2465 | |
| 2466 | /* Keep still-pending events for next scheduling */ |
Franky Lin | 4531603 | 2012-09-13 21:12:03 +0200 | [diff] [blame] | 2467 | if (intstatus) { |
| 2468 | for_each_set_bit(n, &intstatus, 32) |
| 2469 | set_bit(n, (unsigned long *)&bus->intstatus.counter); |
| 2470 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2471 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 2472 | brcmf_sdio_clrintr(bus); |
Franky Lin | ba89bf1 | 2012-04-27 18:56:59 -0700 | [diff] [blame] | 2473 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2474 | if (data_ok(bus) && bus->ctrl_frame_stat && |
| 2475 | (bus->clkstate == CLK_AVAIL)) { |
Franky Lin | 03d5c36 | 2012-09-13 21:12:01 +0200 | [diff] [blame] | 2476 | int i; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2477 | |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 2478 | sdio_claim_host(bus->sdiodev->func[1]); |
Arend van Spriel | a7cdd82 | 2013-12-12 11:58:59 +0100 | [diff] [blame] | 2479 | err = brcmf_sdiod_send_buf(bus->sdiodev, bus->ctrl_frame_buf, |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 2480 | (u32)bus->ctrl_frame_len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2481 | |
Franky Lin | 03d5c36 | 2012-09-13 21:12:01 +0200 | [diff] [blame] | 2482 | if (err < 0) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2483 | /* On failure, abort the command and |
| 2484 | terminate the frame */ |
| 2485 | brcmf_dbg(INFO, "sdio error %d, abort command and terminate frame\n", |
Franky Lin | 03d5c36 | 2012-09-13 21:12:01 +0200 | [diff] [blame] | 2486 | err); |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 2487 | bus->sdcnt.tx_sderrs++; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2488 | |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 2489 | brcmf_sdiod_abort(bus->sdiodev, SDIO_FUNC_2); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2490 | |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 2491 | brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_FRAMECTRL, |
| 2492 | SFC_WF_TERM, &err); |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 2493 | bus->sdcnt.f1regdata++; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2494 | |
| 2495 | for (i = 0; i < 3; i++) { |
| 2496 | u8 hi, lo; |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 2497 | hi = brcmf_sdiod_regrb(bus->sdiodev, |
| 2498 | SBSDIO_FUNC1_WFRAMEBCHI, |
| 2499 | &err); |
| 2500 | lo = brcmf_sdiod_regrb(bus->sdiodev, |
| 2501 | SBSDIO_FUNC1_WFRAMEBCLO, |
| 2502 | &err); |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 2503 | bus->sdcnt.f1regdata += 2; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2504 | if ((hi == 0) && (lo == 0)) |
| 2505 | break; |
| 2506 | } |
| 2507 | |
Franky Lin | 03d5c36 | 2012-09-13 21:12:01 +0200 | [diff] [blame] | 2508 | } else { |
Franky Lin | 6bc5231 | 2013-08-10 12:27:28 +0200 | [diff] [blame] | 2509 | bus->tx_seq = (bus->tx_seq + 1) % SDPCM_SEQ_WRAP; |
Franky Lin | 03d5c36 | 2012-09-13 21:12:01 +0200 | [diff] [blame] | 2510 | } |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 2511 | sdio_release_host(bus->sdiodev->func[1]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2512 | bus->ctrl_frame_stat = false; |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 2513 | brcmf_sdio_wait_event_wakeup(bus); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2514 | } |
| 2515 | /* Send queued frames (limit 1 if rx may still be pending) */ |
Franky Lin | 4531603 | 2012-09-13 21:12:03 +0200 | [diff] [blame] | 2516 | else if ((bus->clkstate == CLK_AVAIL) && !atomic_read(&bus->fcstate) && |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2517 | brcmu_pktq_mlen(&bus->txq, ~bus->flowcontrol) && txlimit |
| 2518 | && data_ok(bus)) { |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 2519 | framecnt = bus->rxpending ? min(txlimit, bus->txminmax) : |
| 2520 | txlimit; |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 2521 | framecnt = brcmf_sdio_sendfromq(bus, framecnt); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2522 | txlimit -= framecnt; |
| 2523 | } |
| 2524 | |
Franky Lin | 5c15c23 | 2012-05-04 18:27:37 -0700 | [diff] [blame] | 2525 | if ((bus->sdiodev->bus_if->state == BRCMF_BUS_DOWN) || (err != 0)) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 2526 | brcmf_err("failed backplane access over SDIO, halting operation\n"); |
Franky Lin | 712ac5b | 2011-12-16 18:37:09 -0800 | [diff] [blame] | 2527 | bus->sdiodev->bus_if->state = BRCMF_BUS_DOWN; |
Franky Lin | 4531603 | 2012-09-13 21:12:03 +0200 | [diff] [blame] | 2528 | atomic_set(&bus->intstatus, 0); |
| 2529 | } else if (atomic_read(&bus->intstatus) || |
| 2530 | atomic_read(&bus->ipend) > 0 || |
| 2531 | (!atomic_read(&bus->fcstate) && |
| 2532 | brcmu_pktq_mlen(&bus->txq, ~bus->flowcontrol) && |
| 2533 | data_ok(bus)) || PKT_AVAILABLE()) { |
Arend van Spriel | fccfe93 | 2013-06-18 13:29:26 +0200 | [diff] [blame] | 2534 | atomic_inc(&bus->dpc_tskcnt); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2535 | } |
| 2536 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2537 | /* If we're done for now, turn off clock request. */ |
| 2538 | if ((bus->clkstate != CLK_PENDING) |
| 2539 | && bus->idletime == BRCMF_IDLE_IMMEDIATE) { |
| 2540 | bus->activity = false; |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 2541 | brcmf_dbg(SDIO, "idle state\n"); |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 2542 | sdio_claim_host(bus->sdiodev->func[1]); |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 2543 | brcmf_sdio_bus_sleep(bus, true, false); |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 2544 | sdio_release_host(bus->sdiodev->func[1]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2545 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2546 | } |
| 2547 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 2548 | static struct pktq *brcmf_sdio_bus_gettxq(struct device *dev) |
Arend van Spriel | e2432b6 | 2013-04-03 12:40:38 +0200 | [diff] [blame] | 2549 | { |
| 2550 | struct brcmf_bus *bus_if = dev_get_drvdata(dev); |
| 2551 | struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio; |
| 2552 | struct brcmf_sdio *bus = sdiodev->bus; |
| 2553 | |
| 2554 | return &bus->txq; |
| 2555 | } |
| 2556 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 2557 | static int brcmf_sdio_bus_txdata(struct device *dev, struct sk_buff *pkt) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2558 | { |
| 2559 | int ret = -EBADE; |
| 2560 | uint datalen, prec; |
Franky Lin | bf347bb | 2011-11-22 17:21:56 -0800 | [diff] [blame] | 2561 | struct brcmf_bus *bus_if = dev_get_drvdata(dev); |
Arend van Spriel | 0a332e4 | 2012-02-09 21:09:02 +0100 | [diff] [blame] | 2562 | struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio; |
Franky Lin | bf347bb | 2011-11-22 17:21:56 -0800 | [diff] [blame] | 2563 | struct brcmf_sdio *bus = sdiodev->bus; |
Arend van Spriel | 4061f89 | 2013-08-10 12:27:19 +0200 | [diff] [blame] | 2564 | ulong flags; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2565 | |
| 2566 | brcmf_dbg(TRACE, "Enter\n"); |
| 2567 | |
| 2568 | datalen = pkt->len; |
| 2569 | |
| 2570 | /* Add space for the header */ |
Franky Lin | 706478c | 2013-08-10 12:27:29 +0200 | [diff] [blame] | 2571 | skb_push(pkt, bus->tx_hdrlen); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2572 | /* precondition: IS_ALIGNED((unsigned long)(pkt->data), 2) */ |
| 2573 | |
| 2574 | prec = prio2prec((pkt->priority & PRIOMASK)); |
| 2575 | |
| 2576 | /* Check for existing queue, current flow-control, |
| 2577 | pending event, or pending clock */ |
| 2578 | brcmf_dbg(TRACE, "deferring pktq len %d\n", pktq_len(&bus->txq)); |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 2579 | bus->sdcnt.fcqueued++; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2580 | |
| 2581 | /* Priority based enq */ |
Arend van Spriel | 4061f89 | 2013-08-10 12:27:19 +0200 | [diff] [blame] | 2582 | spin_lock_irqsave(&bus->txqlock, flags); |
Joe Perches | 23677ce | 2012-02-09 11:17:23 +0000 | [diff] [blame] | 2583 | if (!brcmf_c_prec_enq(bus->sdiodev->dev, &bus->txq, pkt, prec)) { |
Franky Lin | 706478c | 2013-08-10 12:27:29 +0200 | [diff] [blame] | 2584 | skb_pull(pkt, bus->tx_hdrlen); |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 2585 | brcmf_err("out of bus->txq !!!\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2586 | ret = -ENOSR; |
| 2587 | } else { |
| 2588 | ret = 0; |
| 2589 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2590 | |
Franky Lin | c8bf348 | 2011-12-16 18:37:08 -0800 | [diff] [blame] | 2591 | if (pktq_len(&bus->txq) >= TXHI) { |
Hante Meuleman | 90d03ff | 2012-09-11 21:18:46 +0200 | [diff] [blame] | 2592 | bus->txoff = true; |
| 2593 | brcmf_txflowblock(bus->sdiodev->dev, true); |
Franky Lin | c8bf348 | 2011-12-16 18:37:08 -0800 | [diff] [blame] | 2594 | } |
Arend van Spriel | 4061f89 | 2013-08-10 12:27:19 +0200 | [diff] [blame] | 2595 | spin_unlock_irqrestore(&bus->txqlock, flags); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2596 | |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 2597 | #ifdef DEBUG |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2598 | if (pktq_plen(&bus->txq, prec) > qcount[prec]) |
| 2599 | qcount[prec] = pktq_plen(&bus->txq, prec); |
| 2600 | #endif |
Franky Lin | f1e68c2 | 2012-09-13 21:12:00 +0200 | [diff] [blame] | 2601 | |
Arend van Spriel | fccfe93 | 2013-06-18 13:29:26 +0200 | [diff] [blame] | 2602 | if (atomic_read(&bus->dpc_tskcnt) == 0) { |
| 2603 | atomic_inc(&bus->dpc_tskcnt); |
Franky Lin | f1e68c2 | 2012-09-13 21:12:00 +0200 | [diff] [blame] | 2604 | queue_work(bus->brcmf_wq, &bus->datawork); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2605 | } |
| 2606 | |
| 2607 | return ret; |
| 2608 | } |
| 2609 | |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 2610 | #ifdef DEBUG |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2611 | #define CONSOLE_LINE_MAX 192 |
| 2612 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 2613 | static int brcmf_sdio_readconsole(struct brcmf_sdio *bus) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2614 | { |
| 2615 | struct brcmf_console *c = &bus->console; |
| 2616 | u8 line[CONSOLE_LINE_MAX], ch; |
| 2617 | u32 n, idx, addr; |
| 2618 | int rv; |
| 2619 | |
| 2620 | /* Don't do anything until FWREADY updates console address */ |
| 2621 | if (bus->console_addr == 0) |
| 2622 | return 0; |
| 2623 | |
| 2624 | /* Read console log struct */ |
| 2625 | addr = bus->console_addr + offsetof(struct rte_console, log_le); |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 2626 | rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, (u8 *)&c->log_le, |
| 2627 | sizeof(c->log_le)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2628 | if (rv < 0) |
| 2629 | return rv; |
| 2630 | |
| 2631 | /* Allocate console buffer (one time only) */ |
| 2632 | if (c->buf == NULL) { |
| 2633 | c->bufsize = le32_to_cpu(c->log_le.buf_size); |
| 2634 | c->buf = kmalloc(c->bufsize, GFP_ATOMIC); |
| 2635 | if (c->buf == NULL) |
| 2636 | return -ENOMEM; |
| 2637 | } |
| 2638 | |
| 2639 | idx = le32_to_cpu(c->log_le.idx); |
| 2640 | |
| 2641 | /* Protect against corrupt value */ |
| 2642 | if (idx > c->bufsize) |
| 2643 | return -EBADE; |
| 2644 | |
| 2645 | /* Skip reading the console buffer if the index pointer |
| 2646 | has not moved */ |
| 2647 | if (idx == c->last) |
| 2648 | return 0; |
| 2649 | |
| 2650 | /* Read the console buffer */ |
| 2651 | addr = le32_to_cpu(c->log_le.buf); |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 2652 | rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, c->buf, c->bufsize); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2653 | if (rv < 0) |
| 2654 | return rv; |
| 2655 | |
| 2656 | while (c->last != idx) { |
| 2657 | for (n = 0; n < CONSOLE_LINE_MAX - 2; n++) { |
| 2658 | if (c->last == idx) { |
| 2659 | /* This would output a partial line. |
| 2660 | * Instead, back up |
| 2661 | * the buffer pointer and output this |
| 2662 | * line next time around. |
| 2663 | */ |
| 2664 | if (c->last >= n) |
| 2665 | c->last -= n; |
| 2666 | else |
| 2667 | c->last = c->bufsize - n; |
| 2668 | goto break2; |
| 2669 | } |
| 2670 | ch = c->buf[c->last]; |
| 2671 | c->last = (c->last + 1) % c->bufsize; |
| 2672 | if (ch == '\n') |
| 2673 | break; |
| 2674 | line[n] = ch; |
| 2675 | } |
| 2676 | |
| 2677 | if (n > 0) { |
| 2678 | if (line[n - 1] == '\r') |
| 2679 | n--; |
| 2680 | line[n] = 0; |
Joe Perches | 18aad4f | 2012-01-15 00:38:42 -0800 | [diff] [blame] | 2681 | pr_debug("CONSOLE: %s\n", line); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2682 | } |
| 2683 | } |
| 2684 | break2: |
| 2685 | |
| 2686 | return 0; |
| 2687 | } |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 2688 | #endif /* DEBUG */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2689 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 2690 | static int brcmf_sdio_tx_frame(struct brcmf_sdio *bus, u8 *frame, u16 len) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2691 | { |
| 2692 | int i; |
| 2693 | int ret; |
| 2694 | |
| 2695 | bus->ctrl_frame_stat = false; |
Arend van Spriel | a7cdd82 | 2013-12-12 11:58:59 +0100 | [diff] [blame] | 2696 | ret = brcmf_sdiod_send_buf(bus->sdiodev, frame, len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2697 | |
| 2698 | if (ret < 0) { |
| 2699 | /* On failure, abort the command and terminate the frame */ |
| 2700 | brcmf_dbg(INFO, "sdio error %d, abort command and terminate frame\n", |
| 2701 | ret); |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 2702 | bus->sdcnt.tx_sderrs++; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2703 | |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 2704 | brcmf_sdiod_abort(bus->sdiodev, SDIO_FUNC_2); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2705 | |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 2706 | brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_FRAMECTRL, |
| 2707 | SFC_WF_TERM, NULL); |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 2708 | bus->sdcnt.f1regdata++; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2709 | |
| 2710 | for (i = 0; i < 3; i++) { |
| 2711 | u8 hi, lo; |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 2712 | hi = brcmf_sdiod_regrb(bus->sdiodev, |
| 2713 | SBSDIO_FUNC1_WFRAMEBCHI, NULL); |
| 2714 | lo = brcmf_sdiod_regrb(bus->sdiodev, |
| 2715 | SBSDIO_FUNC1_WFRAMEBCLO, NULL); |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 2716 | bus->sdcnt.f1regdata += 2; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2717 | if (hi == 0 && lo == 0) |
| 2718 | break; |
| 2719 | } |
| 2720 | return ret; |
| 2721 | } |
| 2722 | |
Franky Lin | 6bc5231 | 2013-08-10 12:27:28 +0200 | [diff] [blame] | 2723 | bus->tx_seq = (bus->tx_seq + 1) % SDPCM_SEQ_WRAP; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2724 | |
| 2725 | return ret; |
| 2726 | } |
| 2727 | |
Franky Lin | fcf094f | 2011-12-16 18:37:16 -0800 | [diff] [blame] | 2728 | static int |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 2729 | brcmf_sdio_bus_txctl(struct device *dev, unsigned char *msg, uint msglen) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2730 | { |
| 2731 | u8 *frame; |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 2732 | u16 len, pad; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2733 | uint retries = 0; |
| 2734 | u8 doff = 0; |
| 2735 | int ret = -1; |
Franky Lin | 47a1ce7 | 2011-11-22 17:21:55 -0800 | [diff] [blame] | 2736 | struct brcmf_bus *bus_if = dev_get_drvdata(dev); |
Arend van Spriel | 0a332e4 | 2012-02-09 21:09:02 +0100 | [diff] [blame] | 2737 | struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio; |
Franky Lin | 47a1ce7 | 2011-11-22 17:21:55 -0800 | [diff] [blame] | 2738 | struct brcmf_sdio *bus = sdiodev->bus; |
Franky Lin | 6bc5231 | 2013-08-10 12:27:28 +0200 | [diff] [blame] | 2739 | struct brcmf_sdio_hdrinfo hd_info = {0}; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2740 | |
| 2741 | brcmf_dbg(TRACE, "Enter\n"); |
| 2742 | |
| 2743 | /* Back the pointer to make a room for bus header */ |
Franky Lin | 706478c | 2013-08-10 12:27:29 +0200 | [diff] [blame] | 2744 | frame = msg - bus->tx_hdrlen; |
| 2745 | len = (msglen += bus->tx_hdrlen); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2746 | |
| 2747 | /* Add alignment padding (optional for ctl frames) */ |
Arend van Spriel | 9b2d2f2 | 2013-11-29 12:25:14 +0100 | [diff] [blame] | 2748 | doff = ((unsigned long)frame % bus->head_align); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2749 | if (doff) { |
| 2750 | frame -= doff; |
| 2751 | len += doff; |
| 2752 | msglen += doff; |
Franky Lin | 706478c | 2013-08-10 12:27:29 +0200 | [diff] [blame] | 2753 | memset(frame, 0, doff + bus->tx_hdrlen); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2754 | } |
Arend van Spriel | 9b2d2f2 | 2013-11-29 12:25:14 +0100 | [diff] [blame] | 2755 | /* precondition: doff < bus->head_align */ |
Franky Lin | 706478c | 2013-08-10 12:27:29 +0200 | [diff] [blame] | 2756 | doff += bus->tx_hdrlen; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2757 | |
| 2758 | /* Round send length to next SDIO block */ |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 2759 | pad = 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2760 | if (bus->roundup && bus->blocksize && (len > bus->blocksize)) { |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 2761 | pad = bus->blocksize - (len % bus->blocksize); |
| 2762 | if ((pad > bus->roundup) || (pad >= bus->blocksize)) |
| 2763 | pad = 0; |
Arend van Spriel | 9b2d2f2 | 2013-11-29 12:25:14 +0100 | [diff] [blame] | 2764 | } else if (len % bus->head_align) { |
| 2765 | pad = bus->head_align - (len % bus->head_align); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2766 | } |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 2767 | len += pad; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2768 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2769 | /* precondition: IS_ALIGNED((unsigned long)frame, 2) */ |
| 2770 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2771 | /* Make sure backplane clock is on */ |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 2772 | sdio_claim_host(bus->sdiodev->func[1]); |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 2773 | brcmf_sdio_bus_sleep(bus, false, false); |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 2774 | sdio_release_host(bus->sdiodev->func[1]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2775 | |
Franky Lin | 6bc5231 | 2013-08-10 12:27:28 +0200 | [diff] [blame] | 2776 | hd_info.len = (u16)msglen; |
| 2777 | hd_info.channel = SDPCM_CONTROL_CHANNEL; |
| 2778 | hd_info.dat_offset = doff; |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 2779 | hd_info.seq_num = bus->tx_seq; |
Arend van Spriel | 9b2d2f2 | 2013-11-29 12:25:14 +0100 | [diff] [blame] | 2780 | hd_info.lastfrm = true; |
| 2781 | hd_info.tail_pad = pad; |
Franky Lin | 6bc5231 | 2013-08-10 12:27:28 +0200 | [diff] [blame] | 2782 | brcmf_sdio_hdpack(bus, frame, &hd_info); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2783 | |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 2784 | if (bus->txglom) |
| 2785 | brcmf_sdio_update_hwhdr(frame, len); |
| 2786 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2787 | if (!data_ok(bus)) { |
| 2788 | brcmf_dbg(INFO, "No bus credit bus->tx_max %d, bus->tx_seq %d\n", |
| 2789 | bus->tx_max, bus->tx_seq); |
| 2790 | bus->ctrl_frame_stat = true; |
| 2791 | /* Send from dpc */ |
| 2792 | bus->ctrl_frame_buf = frame; |
| 2793 | bus->ctrl_frame_len = len; |
| 2794 | |
Franky Lin | fd67dc8 | 2012-11-05 16:22:25 -0800 | [diff] [blame] | 2795 | wait_event_interruptible_timeout(bus->ctrl_wait, |
| 2796 | !bus->ctrl_frame_stat, |
| 2797 | msecs_to_jiffies(2000)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2798 | |
Joe Perches | 23677ce | 2012-02-09 11:17:23 +0000 | [diff] [blame] | 2799 | if (!bus->ctrl_frame_stat) { |
Arend van Spriel | c320337 | 2013-04-03 12:40:44 +0200 | [diff] [blame] | 2800 | brcmf_dbg(SDIO, "ctrl_frame_stat == false\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2801 | ret = 0; |
| 2802 | } else { |
Arend van Spriel | c320337 | 2013-04-03 12:40:44 +0200 | [diff] [blame] | 2803 | brcmf_dbg(SDIO, "ctrl_frame_stat == true\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2804 | ret = -1; |
| 2805 | } |
| 2806 | } |
| 2807 | |
| 2808 | if (ret == -1) { |
Joe Perches | 1e02382 | 2012-01-15 00:38:40 -0800 | [diff] [blame] | 2809 | brcmf_dbg_hex_dump(BRCMF_BYTES_ON() && BRCMF_CTL_ON(), |
| 2810 | frame, len, "Tx Frame:\n"); |
| 2811 | brcmf_dbg_hex_dump(!(BRCMF_BYTES_ON() && BRCMF_CTL_ON()) && |
| 2812 | BRCMF_HDRS_ON(), |
| 2813 | frame, min_t(u16, len, 16), "TxHdr:\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2814 | |
| 2815 | do { |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 2816 | sdio_claim_host(bus->sdiodev->func[1]); |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 2817 | ret = brcmf_sdio_tx_frame(bus, frame, len); |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 2818 | sdio_release_host(bus->sdiodev->func[1]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2819 | } while (ret < 0 && retries++ < TXRETRIES); |
| 2820 | } |
| 2821 | |
Franky Lin | f1e68c2 | 2012-09-13 21:12:00 +0200 | [diff] [blame] | 2822 | if ((bus->idletime == BRCMF_IDLE_IMMEDIATE) && |
Arend van Spriel | fccfe93 | 2013-06-18 13:29:26 +0200 | [diff] [blame] | 2823 | atomic_read(&bus->dpc_tskcnt) == 0) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2824 | bus->activity = false; |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 2825 | sdio_claim_host(bus->sdiodev->func[1]); |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 2826 | brcmf_dbg(INFO, "idle\n"); |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 2827 | brcmf_sdio_clkctl(bus, CLK_NONE, true); |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 2828 | sdio_release_host(bus->sdiodev->func[1]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2829 | } |
| 2830 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2831 | if (ret) |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 2832 | bus->sdcnt.tx_ctlerrs++; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2833 | else |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 2834 | bus->sdcnt.tx_ctlpkts++; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2835 | |
| 2836 | return ret ? -EIO : 0; |
| 2837 | } |
| 2838 | |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 2839 | #ifdef DEBUG |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 2840 | static inline bool brcmf_sdio_valid_shared_address(u32 addr) |
| 2841 | { |
| 2842 | return !(addr == 0 || ((~addr >> 16) & 0xffff) == (addr & 0xffff)); |
| 2843 | } |
| 2844 | |
| 2845 | static int brcmf_sdio_readshared(struct brcmf_sdio *bus, |
| 2846 | struct sdpcm_shared *sh) |
| 2847 | { |
| 2848 | u32 addr; |
| 2849 | int rv; |
| 2850 | u32 shaddr = 0; |
| 2851 | struct sdpcm_shared_le sh_le; |
| 2852 | __le32 addr_le; |
| 2853 | |
Franky Lin | 1640f28 | 2013-04-11 13:28:51 +0200 | [diff] [blame] | 2854 | shaddr = bus->ci->rambase + bus->ramsize - 4; |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 2855 | |
| 2856 | /* |
| 2857 | * Read last word in socram to determine |
| 2858 | * address of sdpcm_shared structure |
| 2859 | */ |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 2860 | sdio_claim_host(bus->sdiodev->func[1]); |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 2861 | brcmf_sdio_bus_sleep(bus, false, false); |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 2862 | rv = brcmf_sdiod_ramrw(bus->sdiodev, false, shaddr, (u8 *)&addr_le, 4); |
Piotr Haber | b55de97 | 2013-02-08 12:06:33 +0100 | [diff] [blame] | 2863 | sdio_release_host(bus->sdiodev->func[1]); |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 2864 | if (rv < 0) |
| 2865 | return rv; |
| 2866 | |
| 2867 | addr = le32_to_cpu(addr_le); |
| 2868 | |
Arend van Spriel | c320337 | 2013-04-03 12:40:44 +0200 | [diff] [blame] | 2869 | brcmf_dbg(SDIO, "sdpcm_shared address 0x%08X\n", addr); |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 2870 | |
| 2871 | /* |
| 2872 | * Check if addr is valid. |
| 2873 | * NVRAM length at the end of memory should have been overwritten. |
| 2874 | */ |
| 2875 | if (!brcmf_sdio_valid_shared_address(addr)) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 2876 | brcmf_err("invalid sdpcm_shared address 0x%08X\n", |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 2877 | addr); |
| 2878 | return -EINVAL; |
| 2879 | } |
| 2880 | |
| 2881 | /* Read hndrte_shared structure */ |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 2882 | rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, (u8 *)&sh_le, |
| 2883 | sizeof(struct sdpcm_shared_le)); |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 2884 | if (rv < 0) |
| 2885 | return rv; |
| 2886 | |
| 2887 | /* Endianness */ |
| 2888 | sh->flags = le32_to_cpu(sh_le.flags); |
| 2889 | sh->trap_addr = le32_to_cpu(sh_le.trap_addr); |
| 2890 | sh->assert_exp_addr = le32_to_cpu(sh_le.assert_exp_addr); |
| 2891 | sh->assert_file_addr = le32_to_cpu(sh_le.assert_file_addr); |
| 2892 | sh->assert_line = le32_to_cpu(sh_le.assert_line); |
| 2893 | sh->console_addr = le32_to_cpu(sh_le.console_addr); |
| 2894 | sh->msgtrace_addr = le32_to_cpu(sh_le.msgtrace_addr); |
| 2895 | |
Piotr Haber | 86dcd93 | 2013-04-05 10:57:43 +0200 | [diff] [blame] | 2896 | if ((sh->flags & SDPCM_SHARED_VERSION_MASK) > SDPCM_SHARED_VERSION) { |
| 2897 | brcmf_err("sdpcm shared version unsupported: dhd %d dongle %d\n", |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 2898 | SDPCM_SHARED_VERSION, |
| 2899 | sh->flags & SDPCM_SHARED_VERSION_MASK); |
| 2900 | return -EPROTO; |
| 2901 | } |
| 2902 | |
| 2903 | return 0; |
| 2904 | } |
| 2905 | |
| 2906 | static int brcmf_sdio_dump_console(struct brcmf_sdio *bus, |
| 2907 | struct sdpcm_shared *sh, char __user *data, |
| 2908 | size_t count) |
| 2909 | { |
| 2910 | u32 addr, console_ptr, console_size, console_index; |
| 2911 | char *conbuf = NULL; |
| 2912 | __le32 sh_val; |
| 2913 | int rv; |
| 2914 | loff_t pos = 0; |
| 2915 | int nbytes = 0; |
| 2916 | |
| 2917 | /* obtain console information from device memory */ |
| 2918 | addr = sh->console_addr + offsetof(struct rte_console, log_le); |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 2919 | rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, |
| 2920 | (u8 *)&sh_val, sizeof(u32)); |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 2921 | if (rv < 0) |
| 2922 | return rv; |
| 2923 | console_ptr = le32_to_cpu(sh_val); |
| 2924 | |
| 2925 | addr = sh->console_addr + offsetof(struct rte_console, log_le.buf_size); |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 2926 | rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, |
| 2927 | (u8 *)&sh_val, sizeof(u32)); |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 2928 | if (rv < 0) |
| 2929 | return rv; |
| 2930 | console_size = le32_to_cpu(sh_val); |
| 2931 | |
| 2932 | addr = sh->console_addr + offsetof(struct rte_console, log_le.idx); |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 2933 | rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, |
| 2934 | (u8 *)&sh_val, sizeof(u32)); |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 2935 | if (rv < 0) |
| 2936 | return rv; |
| 2937 | console_index = le32_to_cpu(sh_val); |
| 2938 | |
| 2939 | /* allocate buffer for console data */ |
| 2940 | if (console_size <= CONSOLE_BUFFER_MAX) |
| 2941 | conbuf = vzalloc(console_size+1); |
| 2942 | |
| 2943 | if (!conbuf) |
| 2944 | return -ENOMEM; |
| 2945 | |
| 2946 | /* obtain the console data from device */ |
| 2947 | conbuf[console_size] = '\0'; |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 2948 | rv = brcmf_sdiod_ramrw(bus->sdiodev, false, console_ptr, (u8 *)conbuf, |
| 2949 | console_size); |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 2950 | if (rv < 0) |
| 2951 | goto done; |
| 2952 | |
| 2953 | rv = simple_read_from_buffer(data, count, &pos, |
| 2954 | conbuf + console_index, |
| 2955 | console_size - console_index); |
| 2956 | if (rv < 0) |
| 2957 | goto done; |
| 2958 | |
| 2959 | nbytes = rv; |
| 2960 | if (console_index > 0) { |
| 2961 | pos = 0; |
| 2962 | rv = simple_read_from_buffer(data+nbytes, count, &pos, |
| 2963 | conbuf, console_index - 1); |
| 2964 | if (rv < 0) |
| 2965 | goto done; |
| 2966 | rv += nbytes; |
| 2967 | } |
| 2968 | done: |
| 2969 | vfree(conbuf); |
| 2970 | return rv; |
| 2971 | } |
| 2972 | |
| 2973 | static int brcmf_sdio_trap_info(struct brcmf_sdio *bus, struct sdpcm_shared *sh, |
| 2974 | char __user *data, size_t count) |
| 2975 | { |
| 2976 | int error, res; |
| 2977 | char buf[350]; |
| 2978 | struct brcmf_trap_info tr; |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 2979 | loff_t pos = 0; |
| 2980 | |
Piotr Haber | baa9e60 | 2013-04-05 10:57:42 +0200 | [diff] [blame] | 2981 | if ((sh->flags & SDPCM_SHARED_TRAP) == 0) { |
| 2982 | brcmf_dbg(INFO, "no trap in firmware\n"); |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 2983 | return 0; |
Piotr Haber | baa9e60 | 2013-04-05 10:57:42 +0200 | [diff] [blame] | 2984 | } |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 2985 | |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 2986 | error = brcmf_sdiod_ramrw(bus->sdiodev, false, sh->trap_addr, (u8 *)&tr, |
| 2987 | sizeof(struct brcmf_trap_info)); |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 2988 | if (error < 0) |
| 2989 | return error; |
| 2990 | |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 2991 | res = scnprintf(buf, sizeof(buf), |
| 2992 | "dongle trap info: type 0x%x @ epc 0x%08x\n" |
| 2993 | " cpsr 0x%08x spsr 0x%08x sp 0x%08x\n" |
| 2994 | " lr 0x%08x pc 0x%08x offset 0x%x\n" |
| 2995 | " r0 0x%08x r1 0x%08x r2 0x%08x r3 0x%08x\n" |
| 2996 | " r4 0x%08x r5 0x%08x r6 0x%08x r7 0x%08x\n", |
| 2997 | le32_to_cpu(tr.type), le32_to_cpu(tr.epc), |
| 2998 | le32_to_cpu(tr.cpsr), le32_to_cpu(tr.spsr), |
| 2999 | le32_to_cpu(tr.r13), le32_to_cpu(tr.r14), |
Arend van Spriel | 9bd02c6 | 2012-06-26 21:26:40 +0200 | [diff] [blame] | 3000 | le32_to_cpu(tr.pc), sh->trap_addr, |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3001 | le32_to_cpu(tr.r0), le32_to_cpu(tr.r1), |
| 3002 | le32_to_cpu(tr.r2), le32_to_cpu(tr.r3), |
| 3003 | le32_to_cpu(tr.r4), le32_to_cpu(tr.r5), |
| 3004 | le32_to_cpu(tr.r6), le32_to_cpu(tr.r7)); |
| 3005 | |
Piotr Haber | baa9e60 | 2013-04-05 10:57:42 +0200 | [diff] [blame] | 3006 | return simple_read_from_buffer(data, count, &pos, buf, res); |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3007 | } |
| 3008 | |
| 3009 | static int brcmf_sdio_assert_info(struct brcmf_sdio *bus, |
| 3010 | struct sdpcm_shared *sh, char __user *data, |
| 3011 | size_t count) |
| 3012 | { |
| 3013 | int error = 0; |
| 3014 | char buf[200]; |
| 3015 | char file[80] = "?"; |
| 3016 | char expr[80] = "<???>"; |
| 3017 | int res; |
| 3018 | loff_t pos = 0; |
| 3019 | |
| 3020 | if ((sh->flags & SDPCM_SHARED_ASSERT_BUILT) == 0) { |
| 3021 | brcmf_dbg(INFO, "firmware not built with -assert\n"); |
| 3022 | return 0; |
| 3023 | } else if ((sh->flags & SDPCM_SHARED_ASSERT) == 0) { |
| 3024 | brcmf_dbg(INFO, "no assert in dongle\n"); |
| 3025 | return 0; |
| 3026 | } |
| 3027 | |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 3028 | sdio_claim_host(bus->sdiodev->func[1]); |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3029 | if (sh->assert_file_addr != 0) { |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 3030 | error = brcmf_sdiod_ramrw(bus->sdiodev, false, |
| 3031 | sh->assert_file_addr, (u8 *)file, 80); |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3032 | if (error < 0) |
| 3033 | return error; |
| 3034 | } |
| 3035 | if (sh->assert_exp_addr != 0) { |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 3036 | error = brcmf_sdiod_ramrw(bus->sdiodev, false, |
| 3037 | sh->assert_exp_addr, (u8 *)expr, 80); |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3038 | if (error < 0) |
| 3039 | return error; |
| 3040 | } |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 3041 | sdio_release_host(bus->sdiodev->func[1]); |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3042 | |
| 3043 | res = scnprintf(buf, sizeof(buf), |
| 3044 | "dongle assert: %s:%d: assert(%s)\n", |
| 3045 | file, sh->assert_line, expr); |
| 3046 | return simple_read_from_buffer(data, count, &pos, buf, res); |
| 3047 | } |
| 3048 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3049 | static int brcmf_sdio_checkdied(struct brcmf_sdio *bus) |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3050 | { |
| 3051 | int error; |
| 3052 | struct sdpcm_shared sh; |
| 3053 | |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3054 | error = brcmf_sdio_readshared(bus, &sh); |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3055 | |
| 3056 | if (error < 0) |
| 3057 | return error; |
| 3058 | |
| 3059 | if ((sh.flags & SDPCM_SHARED_ASSERT_BUILT) == 0) |
| 3060 | brcmf_dbg(INFO, "firmware not built with -assert\n"); |
| 3061 | else if (sh.flags & SDPCM_SHARED_ASSERT) |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 3062 | brcmf_err("assertion in dongle\n"); |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3063 | |
| 3064 | if (sh.flags & SDPCM_SHARED_TRAP) |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 3065 | brcmf_err("firmware trap in dongle\n"); |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3066 | |
| 3067 | return 0; |
| 3068 | } |
| 3069 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3070 | static int brcmf_sdio_died_dump(struct brcmf_sdio *bus, char __user *data, |
| 3071 | size_t count, loff_t *ppos) |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3072 | { |
| 3073 | int error = 0; |
| 3074 | struct sdpcm_shared sh; |
| 3075 | int nbytes = 0; |
| 3076 | loff_t pos = *ppos; |
| 3077 | |
| 3078 | if (pos != 0) |
| 3079 | return 0; |
| 3080 | |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3081 | error = brcmf_sdio_readshared(bus, &sh); |
| 3082 | if (error < 0) |
| 3083 | goto done; |
| 3084 | |
| 3085 | error = brcmf_sdio_assert_info(bus, &sh, data, count); |
| 3086 | if (error < 0) |
| 3087 | goto done; |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3088 | nbytes = error; |
Piotr Haber | baa9e60 | 2013-04-05 10:57:42 +0200 | [diff] [blame] | 3089 | |
| 3090 | error = brcmf_sdio_trap_info(bus, &sh, data+nbytes, count); |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3091 | if (error < 0) |
| 3092 | goto done; |
Piotr Haber | baa9e60 | 2013-04-05 10:57:42 +0200 | [diff] [blame] | 3093 | nbytes += error; |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3094 | |
Piotr Haber | baa9e60 | 2013-04-05 10:57:42 +0200 | [diff] [blame] | 3095 | error = brcmf_sdio_dump_console(bus, &sh, data+nbytes, count); |
| 3096 | if (error < 0) |
| 3097 | goto done; |
| 3098 | nbytes += error; |
| 3099 | |
| 3100 | error = nbytes; |
| 3101 | *ppos += nbytes; |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3102 | done: |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3103 | return error; |
| 3104 | } |
| 3105 | |
| 3106 | static ssize_t brcmf_sdio_forensic_read(struct file *f, char __user *data, |
| 3107 | size_t count, loff_t *ppos) |
| 3108 | { |
| 3109 | struct brcmf_sdio *bus = f->private_data; |
| 3110 | int res; |
| 3111 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3112 | res = brcmf_sdio_died_dump(bus, data, count, ppos); |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3113 | if (res > 0) |
| 3114 | *ppos += res; |
| 3115 | return (ssize_t)res; |
| 3116 | } |
| 3117 | |
| 3118 | static const struct file_operations brcmf_sdio_forensic_ops = { |
| 3119 | .owner = THIS_MODULE, |
| 3120 | .open = simple_open, |
| 3121 | .read = brcmf_sdio_forensic_read |
| 3122 | }; |
| 3123 | |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 3124 | static void brcmf_sdio_debugfs_create(struct brcmf_sdio *bus) |
| 3125 | { |
| 3126 | struct brcmf_pub *drvr = bus->sdiodev->bus_if->drvr; |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3127 | struct dentry *dentry = brcmf_debugfs_get_devdir(drvr); |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 3128 | |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3129 | if (IS_ERR_OR_NULL(dentry)) |
| 3130 | return; |
| 3131 | |
| 3132 | debugfs_create_file("forensics", S_IRUGO, dentry, bus, |
| 3133 | &brcmf_sdio_forensic_ops); |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 3134 | brcmf_debugfs_create_sdio_count(drvr, &bus->sdcnt); |
| 3135 | } |
| 3136 | #else |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3137 | static int brcmf_sdio_checkdied(struct brcmf_sdio *bus) |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3138 | { |
| 3139 | return 0; |
| 3140 | } |
| 3141 | |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 3142 | static void brcmf_sdio_debugfs_create(struct brcmf_sdio *bus) |
| 3143 | { |
| 3144 | } |
| 3145 | #endif /* DEBUG */ |
| 3146 | |
Franky Lin | fcf094f | 2011-12-16 18:37:16 -0800 | [diff] [blame] | 3147 | static int |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3148 | brcmf_sdio_bus_rxctl(struct device *dev, unsigned char *msg, uint msglen) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3149 | { |
| 3150 | int timeleft; |
| 3151 | uint rxlen = 0; |
| 3152 | bool pending; |
Franky Lin | dd43a01 | 2012-11-05 16:22:22 -0800 | [diff] [blame] | 3153 | u8 *buf; |
Franky Lin | 532cdd3 | 2011-11-22 17:21:54 -0800 | [diff] [blame] | 3154 | struct brcmf_bus *bus_if = dev_get_drvdata(dev); |
Arend van Spriel | 0a332e4 | 2012-02-09 21:09:02 +0100 | [diff] [blame] | 3155 | struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio; |
Franky Lin | 532cdd3 | 2011-11-22 17:21:54 -0800 | [diff] [blame] | 3156 | struct brcmf_sdio *bus = sdiodev->bus; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3157 | |
| 3158 | brcmf_dbg(TRACE, "Enter\n"); |
| 3159 | |
| 3160 | /* Wait until control frame is available */ |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3161 | timeleft = brcmf_sdio_dcmd_resp_wait(bus, &bus->rxlen, &pending); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3162 | |
Franky Lin | dd43a01 | 2012-11-05 16:22:22 -0800 | [diff] [blame] | 3163 | spin_lock_bh(&bus->rxctl_lock); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3164 | rxlen = bus->rxlen; |
| 3165 | memcpy(msg, bus->rxctl, min(msglen, rxlen)); |
Franky Lin | dd43a01 | 2012-11-05 16:22:22 -0800 | [diff] [blame] | 3166 | bus->rxctl = NULL; |
| 3167 | buf = bus->rxctl_orig; |
| 3168 | bus->rxctl_orig = NULL; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3169 | bus->rxlen = 0; |
Franky Lin | dd43a01 | 2012-11-05 16:22:22 -0800 | [diff] [blame] | 3170 | spin_unlock_bh(&bus->rxctl_lock); |
| 3171 | vfree(buf); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3172 | |
| 3173 | if (rxlen) { |
| 3174 | brcmf_dbg(CTL, "resumed on rxctl frame, got %d expected %d\n", |
| 3175 | rxlen, msglen); |
| 3176 | } else if (timeleft == 0) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 3177 | brcmf_err("resumed on timeout\n"); |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3178 | brcmf_sdio_checkdied(bus); |
Joe Perches | 23677ce | 2012-02-09 11:17:23 +0000 | [diff] [blame] | 3179 | } else if (pending) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3180 | brcmf_dbg(CTL, "cancelled\n"); |
| 3181 | return -ERESTARTSYS; |
| 3182 | } else { |
| 3183 | brcmf_dbg(CTL, "resumed for unknown reason?\n"); |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3184 | brcmf_sdio_checkdied(bus); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3185 | } |
| 3186 | |
| 3187 | if (rxlen) |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 3188 | bus->sdcnt.rx_ctlpkts++; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3189 | else |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 3190 | bus->sdcnt.rx_ctlerrs++; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3191 | |
| 3192 | return rxlen ? (int)rxlen : -ETIMEDOUT; |
| 3193 | } |
| 3194 | |
Hante Meuleman | a74d036 | 2014-01-13 22:20:22 +0100 | [diff] [blame] | 3195 | #ifdef DEBUG |
| 3196 | static bool |
| 3197 | brcmf_sdio_verifymemory(struct brcmf_sdio_dev *sdiodev, u32 ram_addr, |
| 3198 | u8 *ram_data, uint ram_sz) |
| 3199 | { |
| 3200 | char *ram_cmp; |
| 3201 | int err; |
| 3202 | bool ret = true; |
| 3203 | int address; |
| 3204 | int offset; |
| 3205 | int len; |
| 3206 | |
| 3207 | /* read back and verify */ |
| 3208 | brcmf_dbg(INFO, "Compare RAM dl & ul at 0x%08x; size=%d\n", ram_addr, |
| 3209 | ram_sz); |
| 3210 | ram_cmp = kmalloc(MEMBLOCK, GFP_KERNEL); |
| 3211 | /* do not proceed while no memory but */ |
| 3212 | if (!ram_cmp) |
| 3213 | return true; |
| 3214 | |
| 3215 | address = ram_addr; |
| 3216 | offset = 0; |
| 3217 | while (offset < ram_sz) { |
| 3218 | len = ((offset + MEMBLOCK) < ram_sz) ? MEMBLOCK : |
| 3219 | ram_sz - offset; |
| 3220 | err = brcmf_sdiod_ramrw(sdiodev, false, address, ram_cmp, len); |
| 3221 | if (err) { |
| 3222 | brcmf_err("error %d on reading %d membytes at 0x%08x\n", |
| 3223 | err, len, address); |
| 3224 | ret = false; |
| 3225 | break; |
| 3226 | } else if (memcmp(ram_cmp, &ram_data[offset], len)) { |
| 3227 | brcmf_err("Downloaded RAM image is corrupted, block offset is %d, len is %d\n", |
| 3228 | offset, len); |
| 3229 | ret = false; |
| 3230 | break; |
| 3231 | } |
| 3232 | offset += len; |
| 3233 | address += len; |
| 3234 | } |
| 3235 | |
| 3236 | kfree(ram_cmp); |
| 3237 | |
| 3238 | return ret; |
| 3239 | } |
| 3240 | #else /* DEBUG */ |
| 3241 | static bool |
| 3242 | brcmf_sdio_verifymemory(struct brcmf_sdio_dev *sdiodev, u32 ram_addr, |
| 3243 | u8 *ram_data, uint ram_sz) |
| 3244 | { |
| 3245 | return true; |
| 3246 | } |
| 3247 | #endif /* DEBUG */ |
| 3248 | |
Arend van Spriel | 3355650 | 2014-01-13 22:20:25 +0100 | [diff] [blame^] | 3249 | static int brcmf_sdio_download_code_file(struct brcmf_sdio *bus, |
| 3250 | const struct firmware *fw) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3251 | { |
Hante Meuleman | f2c44fe | 2013-09-25 13:05:45 +0200 | [diff] [blame] | 3252 | int err; |
Franky Lin | 1640f28 | 2013-04-11 13:28:51 +0200 | [diff] [blame] | 3253 | int offset; |
Hante Meuleman | f2c44fe | 2013-09-25 13:05:45 +0200 | [diff] [blame] | 3254 | int address; |
| 3255 | int len; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3256 | |
Hante Meuleman | a74d036 | 2014-01-13 22:20:22 +0100 | [diff] [blame] | 3257 | brcmf_dbg(TRACE, "Enter\n"); |
| 3258 | |
Hante Meuleman | f2c44fe | 2013-09-25 13:05:45 +0200 | [diff] [blame] | 3259 | err = 0; |
| 3260 | offset = 0; |
| 3261 | address = bus->ci->rambase; |
| 3262 | while (offset < fw->size) { |
| 3263 | len = ((offset + MEMBLOCK) < fw->size) ? MEMBLOCK : |
| 3264 | fw->size - offset; |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 3265 | err = brcmf_sdiod_ramrw(bus->sdiodev, true, address, |
| 3266 | (u8 *)&fw->data[offset], len); |
Hante Meuleman | f2c44fe | 2013-09-25 13:05:45 +0200 | [diff] [blame] | 3267 | if (err) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 3268 | brcmf_err("error %d on writing %d membytes at 0x%08x\n", |
Hante Meuleman | f2c44fe | 2013-09-25 13:05:45 +0200 | [diff] [blame] | 3269 | err, len, address); |
Arend van Spriel | 3355650 | 2014-01-13 22:20:25 +0100 | [diff] [blame^] | 3270 | return err; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3271 | } |
Hante Meuleman | f2c44fe | 2013-09-25 13:05:45 +0200 | [diff] [blame] | 3272 | offset += len; |
| 3273 | address += len; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3274 | } |
Hante Meuleman | a74d036 | 2014-01-13 22:20:22 +0100 | [diff] [blame] | 3275 | if (!err) |
| 3276 | if (!brcmf_sdio_verifymemory(bus->sdiodev, bus->ci->rambase, |
| 3277 | (u8 *)fw->data, fw->size)) |
| 3278 | err = -EIO; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3279 | |
Hante Meuleman | f2c44fe | 2013-09-25 13:05:45 +0200 | [diff] [blame] | 3280 | return err; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3281 | } |
| 3282 | |
Arend van Spriel | 3355650 | 2014-01-13 22:20:25 +0100 | [diff] [blame^] | 3283 | static int brcmf_sdio_download_nvram(struct brcmf_sdio *bus, |
| 3284 | const struct firmware *nv) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3285 | { |
Hante Meuleman | a74d036 | 2014-01-13 22:20:22 +0100 | [diff] [blame] | 3286 | void *vars; |
| 3287 | u32 varsz; |
| 3288 | int address; |
| 3289 | int err; |
| 3290 | |
| 3291 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3292 | |
Hante Meuleman | a74d036 | 2014-01-13 22:20:22 +0100 | [diff] [blame] | 3293 | vars = brcmf_nvram_strip(nv, &varsz); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3294 | |
Hante Meuleman | a74d036 | 2014-01-13 22:20:22 +0100 | [diff] [blame] | 3295 | if (vars == NULL) |
| 3296 | return -EINVAL; |
| 3297 | |
| 3298 | address = bus->ci->ramsize - varsz + bus->ci->rambase; |
| 3299 | err = brcmf_sdiod_ramrw(bus->sdiodev, true, address, vars, varsz); |
| 3300 | if (err) |
| 3301 | brcmf_err("error %d on writing %d nvram bytes at 0x%08x\n", |
| 3302 | err, varsz, address); |
| 3303 | else if (!brcmf_sdio_verifymemory(bus->sdiodev, address, vars, varsz)) |
| 3304 | err = -EIO; |
| 3305 | |
| 3306 | brcmf_nvram_free(vars); |
| 3307 | |
| 3308 | return err; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3309 | } |
| 3310 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3311 | static int brcmf_sdio_download_firmware(struct brcmf_sdio *bus) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3312 | { |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3313 | int bcmerror = -EFAULT; |
Arend van Spriel | 3355650 | 2014-01-13 22:20:25 +0100 | [diff] [blame^] | 3314 | const struct firmware *fw; |
| 3315 | u32 rstvec; |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3316 | |
| 3317 | sdio_claim_host(bus->sdiodev->func[1]); |
| 3318 | brcmf_sdio_clkctl(bus, CLK_AVAIL, false); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3319 | |
| 3320 | /* Keep arm in reset */ |
Arend van Spriel | 3355650 | 2014-01-13 22:20:25 +0100 | [diff] [blame^] | 3321 | brcmf_sdio_chip_enter_download(bus->sdiodev, bus->ci); |
| 3322 | |
| 3323 | fw = brcmf_sdio_get_fw(bus, BRCMF_FIRMWARE_BIN); |
| 3324 | if (fw == NULL) { |
| 3325 | bcmerror = -ENOENT; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3326 | goto err; |
| 3327 | } |
| 3328 | |
Arend van Spriel | 3355650 | 2014-01-13 22:20:25 +0100 | [diff] [blame^] | 3329 | rstvec = get_unaligned_le32(fw->data); |
| 3330 | brcmf_dbg(SDIO, "firmware rstvec: %x\n", rstvec); |
| 3331 | |
| 3332 | bcmerror = brcmf_sdio_download_code_file(bus, fw); |
| 3333 | release_firmware(fw); |
| 3334 | if (bcmerror) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 3335 | brcmf_err("dongle image file download failed\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3336 | goto err; |
| 3337 | } |
| 3338 | |
Arend van Spriel | 3355650 | 2014-01-13 22:20:25 +0100 | [diff] [blame^] | 3339 | fw = brcmf_sdio_get_fw(bus, BRCMF_FIRMWARE_NVRAM); |
| 3340 | if (fw == NULL) { |
| 3341 | bcmerror = -ENOENT; |
| 3342 | goto err; |
| 3343 | } |
| 3344 | |
| 3345 | bcmerror = brcmf_sdio_download_nvram(bus, fw); |
| 3346 | release_firmware(fw); |
| 3347 | if (bcmerror) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 3348 | brcmf_err("dongle nvram file download failed\n"); |
Franky Lin | 3eaa956 | 2013-04-02 21:06:20 +0200 | [diff] [blame] | 3349 | goto err; |
| 3350 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3351 | |
| 3352 | /* Take arm out of reset */ |
Arend van Spriel | 3355650 | 2014-01-13 22:20:25 +0100 | [diff] [blame^] | 3353 | if (!brcmf_sdio_chip_exit_download(bus->sdiodev, bus->ci, rstvec)) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 3354 | brcmf_err("error getting out of ARM core reset\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3355 | goto err; |
| 3356 | } |
| 3357 | |
Arend van Spriel | 3355650 | 2014-01-13 22:20:25 +0100 | [diff] [blame^] | 3358 | /* Allow HT Clock now that the ARM is running. */ |
| 3359 | bus->sdiodev->bus_if->state = BRCMF_BUS_LOAD; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3360 | bcmerror = 0; |
| 3361 | |
| 3362 | err: |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3363 | brcmf_sdio_clkctl(bus, CLK_SDONLY, false); |
| 3364 | sdio_release_host(bus->sdiodev->func[1]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3365 | return bcmerror; |
| 3366 | } |
| 3367 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3368 | static bool brcmf_sdio_sr_capable(struct brcmf_sdio *bus) |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 3369 | { |
Arend van Spriel | 3bd44d9 | 2014-01-06 12:40:43 +0100 | [diff] [blame] | 3370 | u32 addr, reg, pmu_cc3_mask = ~0; |
| 3371 | int err; |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 3372 | |
| 3373 | brcmf_dbg(TRACE, "Enter\n"); |
| 3374 | |
| 3375 | /* old chips with PMU version less than 17 don't support save restore */ |
| 3376 | if (bus->ci->pmurev < 17) |
| 3377 | return false; |
| 3378 | |
Arend van Spriel | 3bd44d9 | 2014-01-06 12:40:43 +0100 | [diff] [blame] | 3379 | switch (bus->ci->chip) { |
| 3380 | case BCM43241_CHIP_ID: |
| 3381 | case BCM4335_CHIP_ID: |
| 3382 | case BCM4339_CHIP_ID: |
| 3383 | /* read PMU chipcontrol register 3 */ |
| 3384 | addr = CORE_CC_REG(bus->ci->c_inf[0].base, chipcontrol_addr); |
| 3385 | brcmf_sdiod_regwl(bus->sdiodev, addr, 3, NULL); |
| 3386 | addr = CORE_CC_REG(bus->ci->c_inf[0].base, chipcontrol_data); |
| 3387 | reg = brcmf_sdiod_regrl(bus->sdiodev, addr, NULL); |
| 3388 | return (reg & pmu_cc3_mask) != 0; |
| 3389 | default: |
| 3390 | addr = CORE_CC_REG(bus->ci->c_inf[0].base, pmucapabilities_ext); |
| 3391 | reg = brcmf_sdiod_regrl(bus->sdiodev, addr, &err); |
| 3392 | if ((reg & PCAPEXT_SR_SUPPORTED_MASK) == 0) |
| 3393 | return false; |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 3394 | |
Arend van Spriel | 3bd44d9 | 2014-01-06 12:40:43 +0100 | [diff] [blame] | 3395 | addr = CORE_CC_REG(bus->ci->c_inf[0].base, retention_ctl); |
| 3396 | reg = brcmf_sdiod_regrl(bus->sdiodev, addr, NULL); |
| 3397 | return (reg & (PMU_RCTL_MACPHY_DISABLE_MASK | |
| 3398 | PMU_RCTL_LOGIC_DISABLE_MASK)) == 0; |
| 3399 | } |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 3400 | } |
| 3401 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3402 | static void brcmf_sdio_sr_init(struct brcmf_sdio *bus) |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 3403 | { |
| 3404 | int err = 0; |
| 3405 | u8 val; |
| 3406 | |
| 3407 | brcmf_dbg(TRACE, "Enter\n"); |
| 3408 | |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 3409 | val = brcmf_sdiod_regrb(bus->sdiodev, SBSDIO_FUNC1_WAKEUPCTRL, &err); |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 3410 | if (err) { |
| 3411 | brcmf_err("error reading SBSDIO_FUNC1_WAKEUPCTRL\n"); |
| 3412 | return; |
| 3413 | } |
| 3414 | |
| 3415 | val |= 1 << SBSDIO_FUNC1_WCTRL_HTWAIT_SHIFT; |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 3416 | brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_WAKEUPCTRL, val, &err); |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 3417 | if (err) { |
| 3418 | brcmf_err("error writing SBSDIO_FUNC1_WAKEUPCTRL\n"); |
| 3419 | return; |
| 3420 | } |
| 3421 | |
| 3422 | /* Add CMD14 Support */ |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 3423 | brcmf_sdiod_regwb(bus->sdiodev, SDIO_CCCR_BRCM_CARDCAP, |
| 3424 | (SDIO_CCCR_BRCM_CARDCAP_CMD14_SUPPORT | |
| 3425 | SDIO_CCCR_BRCM_CARDCAP_CMD14_EXT), |
| 3426 | &err); |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 3427 | if (err) { |
| 3428 | brcmf_err("error writing SDIO_CCCR_BRCM_CARDCAP\n"); |
| 3429 | return; |
| 3430 | } |
| 3431 | |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 3432 | brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, |
| 3433 | SBSDIO_FORCE_HT, &err); |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 3434 | if (err) { |
| 3435 | brcmf_err("error writing SBSDIO_FUNC1_CHIPCLKCSR\n"); |
| 3436 | return; |
| 3437 | } |
| 3438 | |
| 3439 | /* set flag */ |
| 3440 | bus->sr_enabled = true; |
| 3441 | brcmf_dbg(INFO, "SR enabled\n"); |
| 3442 | } |
| 3443 | |
| 3444 | /* enable KSO bit */ |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3445 | static int brcmf_sdio_kso_init(struct brcmf_sdio *bus) |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 3446 | { |
| 3447 | u8 val; |
| 3448 | int err = 0; |
| 3449 | |
| 3450 | brcmf_dbg(TRACE, "Enter\n"); |
| 3451 | |
| 3452 | /* KSO bit added in SDIO core rev 12 */ |
| 3453 | if (bus->ci->c_inf[1].rev < 12) |
| 3454 | return 0; |
| 3455 | |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 3456 | val = brcmf_sdiod_regrb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, &err); |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 3457 | if (err) { |
| 3458 | brcmf_err("error reading SBSDIO_FUNC1_SLEEPCSR\n"); |
| 3459 | return err; |
| 3460 | } |
| 3461 | |
| 3462 | if (!(val & SBSDIO_FUNC1_SLEEPCSR_KSO_MASK)) { |
| 3463 | val |= (SBSDIO_FUNC1_SLEEPCSR_KSO_EN << |
| 3464 | SBSDIO_FUNC1_SLEEPCSR_KSO_SHIFT); |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 3465 | brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, |
| 3466 | val, &err); |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 3467 | if (err) { |
| 3468 | brcmf_err("error writing SBSDIO_FUNC1_SLEEPCSR\n"); |
| 3469 | return err; |
| 3470 | } |
| 3471 | } |
| 3472 | |
| 3473 | return 0; |
| 3474 | } |
| 3475 | |
| 3476 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3477 | static int brcmf_sdio_bus_preinit(struct device *dev) |
Arend van Spriel | cf45828 | 2013-11-29 11:48:15 +0100 | [diff] [blame] | 3478 | { |
| 3479 | struct brcmf_bus *bus_if = dev_get_drvdata(dev); |
| 3480 | struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio; |
| 3481 | struct brcmf_sdio *bus = sdiodev->bus; |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 3482 | uint pad_size; |
Arend van Spriel | cf45828 | 2013-11-29 11:48:15 +0100 | [diff] [blame] | 3483 | u32 value; |
| 3484 | u8 idx; |
| 3485 | int err; |
| 3486 | |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 3487 | /* the commands below use the terms tx and rx from |
| 3488 | * a device perspective, ie. bus:txglom affects the |
| 3489 | * bus transfers from device to host. |
| 3490 | */ |
Arend van Spriel | cf45828 | 2013-11-29 11:48:15 +0100 | [diff] [blame] | 3491 | idx = brcmf_sdio_chip_getinfidx(bus->ci, BCMA_CORE_SDIO_DEV); |
| 3492 | if (bus->ci->c_inf[idx].rev < 12) { |
| 3493 | /* for sdio core rev < 12, disable txgloming */ |
| 3494 | value = 0; |
| 3495 | err = brcmf_iovar_data_set(dev, "bus:txglom", &value, |
| 3496 | sizeof(u32)); |
| 3497 | } else { |
| 3498 | /* otherwise, set txglomalign */ |
| 3499 | value = 4; |
| 3500 | if (sdiodev->pdata) |
| 3501 | value = sdiodev->pdata->sd_sgentry_align; |
| 3502 | /* SDIO ADMA requires at least 32 bit alignment */ |
| 3503 | value = max_t(u32, value, 4); |
| 3504 | err = brcmf_iovar_data_set(dev, "bus:txglomalign", &value, |
| 3505 | sizeof(u32)); |
| 3506 | } |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 3507 | |
| 3508 | if (err < 0) |
| 3509 | goto done; |
| 3510 | |
| 3511 | bus->tx_hdrlen = SDPCM_HWHDR_LEN + SDPCM_SWHDR_LEN; |
| 3512 | if (sdiodev->sg_support) { |
| 3513 | bus->txglom = false; |
| 3514 | value = 1; |
| 3515 | pad_size = bus->sdiodev->func[2]->cur_blksize << 1; |
| 3516 | bus->txglom_sgpad = brcmu_pkt_buf_get_skb(pad_size); |
| 3517 | if (!bus->txglom_sgpad) |
| 3518 | brcmf_err("allocating txglom padding skb failed, reduced performance\n"); |
| 3519 | |
| 3520 | err = brcmf_iovar_data_set(bus->sdiodev->dev, "bus:rxglom", |
| 3521 | &value, sizeof(u32)); |
| 3522 | if (err < 0) { |
| 3523 | /* bus:rxglom is allowed to fail */ |
| 3524 | err = 0; |
| 3525 | } else { |
| 3526 | bus->txglom = true; |
| 3527 | bus->tx_hdrlen += SDPCM_HWEXT_LEN; |
| 3528 | } |
| 3529 | } |
| 3530 | brcmf_bus_add_txhdrlen(bus->sdiodev->dev, bus->tx_hdrlen); |
| 3531 | |
| 3532 | done: |
Arend van Spriel | cf45828 | 2013-11-29 11:48:15 +0100 | [diff] [blame] | 3533 | return err; |
| 3534 | } |
| 3535 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3536 | static int brcmf_sdio_bus_init(struct device *dev) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3537 | { |
Franky Lin | fa20b91 | 2011-11-22 17:21:57 -0800 | [diff] [blame] | 3538 | struct brcmf_bus *bus_if = dev_get_drvdata(dev); |
Arend van Spriel | 0a332e4 | 2012-02-09 21:09:02 +0100 | [diff] [blame] | 3539 | struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio; |
Franky Lin | fa20b91 | 2011-11-22 17:21:57 -0800 | [diff] [blame] | 3540 | struct brcmf_sdio *bus = sdiodev->bus; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3541 | int err, ret = 0; |
| 3542 | u8 saveclk; |
| 3543 | |
| 3544 | brcmf_dbg(TRACE, "Enter\n"); |
| 3545 | |
| 3546 | /* try to download image and nvram to the dongle */ |
Franky Lin | fa20b91 | 2011-11-22 17:21:57 -0800 | [diff] [blame] | 3547 | if (bus_if->state == BRCMF_BUS_DOWN) { |
Arend van Spriel | 3355650 | 2014-01-13 22:20:25 +0100 | [diff] [blame^] | 3548 | bus->alp_only = true; |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3549 | err = brcmf_sdio_download_firmware(bus); |
| 3550 | if (err) |
| 3551 | return err; |
Arend van Spriel | 3355650 | 2014-01-13 22:20:25 +0100 | [diff] [blame^] | 3552 | bus->alp_only = false; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3553 | } |
| 3554 | |
Franky Lin | 712ac5b | 2011-12-16 18:37:09 -0800 | [diff] [blame] | 3555 | if (!bus->sdiodev->bus_if->drvr) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3556 | return 0; |
| 3557 | |
| 3558 | /* Start the watchdog timer */ |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 3559 | bus->sdcnt.tickcnt = 0; |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3560 | brcmf_sdio_wd_timer(bus, BRCMF_WD_POLL_MS); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3561 | |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 3562 | sdio_claim_host(bus->sdiodev->func[1]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3563 | |
| 3564 | /* Make sure backplane clock is on, needed to generate F2 interrupt */ |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3565 | brcmf_sdio_clkctl(bus, CLK_AVAIL, false); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3566 | if (bus->clkstate != CLK_AVAIL) |
| 3567 | goto exit; |
| 3568 | |
| 3569 | /* Force clocks on backplane to be sure F2 interrupt propagates */ |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 3570 | saveclk = brcmf_sdiod_regrb(bus->sdiodev, |
| 3571 | SBSDIO_FUNC1_CHIPCLKCSR, &err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3572 | if (!err) { |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 3573 | brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, |
| 3574 | (saveclk | SBSDIO_FORCE_HT), &err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3575 | } |
| 3576 | if (err) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 3577 | brcmf_err("Failed to force clock for F2: err %d\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3578 | goto exit; |
| 3579 | } |
| 3580 | |
| 3581 | /* Enable function 2 (frame transfers) */ |
| 3582 | w_sdreg32(bus, SDPCM_PROT_VERSION << SMB_DATA_VERSION_SHIFT, |
Franky Lin | 5869275 | 2012-05-04 18:27:36 -0700 | [diff] [blame] | 3583 | offsetof(struct sdpcmd_regs, tosbmailboxdata)); |
Arend van Spriel | 71370eb | 2013-12-12 11:58:53 +0100 | [diff] [blame] | 3584 | err = sdio_enable_func(bus->sdiodev->func[SDIO_FUNC_2]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3585 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3586 | |
Arend van Spriel | 71370eb | 2013-12-12 11:58:53 +0100 | [diff] [blame] | 3587 | brcmf_dbg(INFO, "enable F2: err=%d\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3588 | |
| 3589 | /* If F2 successfully enabled, set core and enable interrupts */ |
Arend van Spriel | 71370eb | 2013-12-12 11:58:53 +0100 | [diff] [blame] | 3590 | if (!err) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3591 | /* Set up the interrupt mask and enable interrupts */ |
| 3592 | bus->hostintmask = HOSTINTMASK; |
| 3593 | w_sdreg32(bus, bus->hostintmask, |
Franky Lin | 5869275 | 2012-05-04 18:27:36 -0700 | [diff] [blame] | 3594 | offsetof(struct sdpcmd_regs, hostintmask)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3595 | |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 3596 | brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_WATERMARK, 8, &err); |
Arend van Spriel | c0e89f0 | 2012-02-09 21:09:04 +0100 | [diff] [blame] | 3597 | } else { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3598 | /* Disable F2 again */ |
Arend van Spriel | 71370eb | 2013-12-12 11:58:53 +0100 | [diff] [blame] | 3599 | sdio_disable_func(bus->sdiodev->func[SDIO_FUNC_2]); |
Arend van Spriel | c0e89f0 | 2012-02-09 21:09:04 +0100 | [diff] [blame] | 3600 | ret = -ENODEV; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3601 | } |
| 3602 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3603 | if (brcmf_sdio_sr_capable(bus)) { |
| 3604 | brcmf_sdio_sr_init(bus); |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 3605 | } else { |
| 3606 | /* Restore previous clock setting */ |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 3607 | brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, |
| 3608 | saveclk, &err); |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 3609 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3610 | |
Franky Lin | e2f93cc | 2012-04-27 18:56:58 -0700 | [diff] [blame] | 3611 | if (ret == 0) { |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 3612 | ret = brcmf_sdiod_intr_register(bus->sdiodev); |
Franky Lin | e2f93cc | 2012-04-27 18:56:58 -0700 | [diff] [blame] | 3613 | if (ret != 0) |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 3614 | brcmf_err("intr register failed:%d\n", ret); |
Franky Lin | e2f93cc | 2012-04-27 18:56:58 -0700 | [diff] [blame] | 3615 | } |
| 3616 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3617 | /* If we didn't come up, turn off backplane clock */ |
Arend van Spriel | 76a4c68 | 2014-01-06 12:40:45 +0100 | [diff] [blame] | 3618 | if (ret != 0) |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3619 | brcmf_sdio_clkctl(bus, CLK_NONE, false); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3620 | |
| 3621 | exit: |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 3622 | sdio_release_host(bus->sdiodev->func[1]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3623 | |
| 3624 | return ret; |
| 3625 | } |
| 3626 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3627 | void brcmf_sdio_isr(struct brcmf_sdio *bus) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3628 | { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3629 | brcmf_dbg(TRACE, "Enter\n"); |
| 3630 | |
| 3631 | if (!bus) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 3632 | brcmf_err("bus is null pointer, exiting\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3633 | return; |
| 3634 | } |
| 3635 | |
Franky Lin | 712ac5b | 2011-12-16 18:37:09 -0800 | [diff] [blame] | 3636 | if (bus->sdiodev->bus_if->state == BRCMF_BUS_DOWN) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 3637 | brcmf_err("bus is down. we have nothing to do\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3638 | return; |
| 3639 | } |
| 3640 | /* Count the interrupt call */ |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 3641 | bus->sdcnt.intrcount++; |
Franky Lin | 4531603 | 2012-09-13 21:12:03 +0200 | [diff] [blame] | 3642 | if (in_interrupt()) |
| 3643 | atomic_set(&bus->ipend, 1); |
| 3644 | else |
| 3645 | if (brcmf_sdio_intr_rstatus(bus)) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 3646 | brcmf_err("failed backplane access\n"); |
Franky Lin | 4531603 | 2012-09-13 21:12:03 +0200 | [diff] [blame] | 3647 | bus->sdiodev->bus_if->state = BRCMF_BUS_DOWN; |
| 3648 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3649 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3650 | /* Disable additional interrupts (is this needed now)? */ |
| 3651 | if (!bus->intr) |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 3652 | brcmf_err("isr w/o interrupt configured!\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3653 | |
Arend van Spriel | fccfe93 | 2013-06-18 13:29:26 +0200 | [diff] [blame] | 3654 | atomic_inc(&bus->dpc_tskcnt); |
Franky Lin | f1e68c2 | 2012-09-13 21:12:00 +0200 | [diff] [blame] | 3655 | queue_work(bus->brcmf_wq, &bus->datawork); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3656 | } |
| 3657 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3658 | static bool brcmf_sdio_bus_watchdog(struct brcmf_sdio *bus) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3659 | { |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 3660 | #ifdef DEBUG |
Franky Lin | cad2b26 | 2011-11-22 17:21:53 -0800 | [diff] [blame] | 3661 | struct brcmf_bus *bus_if = dev_get_drvdata(bus->sdiodev->dev); |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 3662 | #endif /* DEBUG */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3663 | |
| 3664 | brcmf_dbg(TIMER, "Enter\n"); |
| 3665 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3666 | /* Poll period: check device if appropriate. */ |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 3667 | if (!bus->sr_enabled && |
| 3668 | bus->poll && (++bus->polltick >= bus->pollrate)) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3669 | u32 intstatus = 0; |
| 3670 | |
| 3671 | /* Reset poll tick */ |
| 3672 | bus->polltick = 0; |
| 3673 | |
| 3674 | /* Check device if no interrupts */ |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 3675 | if (!bus->intr || |
| 3676 | (bus->sdcnt.intrcount == bus->sdcnt.lastintrs)) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3677 | |
Arend van Spriel | fccfe93 | 2013-06-18 13:29:26 +0200 | [diff] [blame] | 3678 | if (atomic_read(&bus->dpc_tskcnt) == 0) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3679 | u8 devpend; |
Arend van Spriel | fccfe93 | 2013-06-18 13:29:26 +0200 | [diff] [blame] | 3680 | |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 3681 | sdio_claim_host(bus->sdiodev->func[1]); |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 3682 | devpend = brcmf_sdiod_regrb(bus->sdiodev, |
| 3683 | SDIO_CCCR_INTx, |
| 3684 | NULL); |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 3685 | sdio_release_host(bus->sdiodev->func[1]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3686 | intstatus = |
| 3687 | devpend & (INTR_STATUS_FUNC1 | |
| 3688 | INTR_STATUS_FUNC2); |
| 3689 | } |
| 3690 | |
| 3691 | /* If there is something, make like the ISR and |
| 3692 | schedule the DPC */ |
| 3693 | if (intstatus) { |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 3694 | bus->sdcnt.pollcnt++; |
Franky Lin | 1d38227 | 2012-09-13 21:11:59 +0200 | [diff] [blame] | 3695 | atomic_set(&bus->ipend, 1); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3696 | |
Arend van Spriel | fccfe93 | 2013-06-18 13:29:26 +0200 | [diff] [blame] | 3697 | atomic_inc(&bus->dpc_tskcnt); |
Franky Lin | f1e68c2 | 2012-09-13 21:12:00 +0200 | [diff] [blame] | 3698 | queue_work(bus->brcmf_wq, &bus->datawork); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3699 | } |
| 3700 | } |
| 3701 | |
| 3702 | /* Update interrupt tracking */ |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 3703 | bus->sdcnt.lastintrs = bus->sdcnt.intrcount; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3704 | } |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 3705 | #ifdef DEBUG |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3706 | /* Poll for console output periodically */ |
Hante Meuleman | 2def5c1 | 2012-11-14 18:46:19 -0800 | [diff] [blame] | 3707 | if (bus_if && bus_if->state == BRCMF_BUS_DATA && |
Franky Lin | 8d169aa | 2011-11-22 17:21:52 -0800 | [diff] [blame] | 3708 | bus->console_interval != 0) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3709 | bus->console.count += BRCMF_WD_POLL_MS; |
| 3710 | if (bus->console.count >= bus->console_interval) { |
| 3711 | bus->console.count -= bus->console_interval; |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 3712 | sdio_claim_host(bus->sdiodev->func[1]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3713 | /* Make sure backplane clock is on */ |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3714 | brcmf_sdio_bus_sleep(bus, false, false); |
| 3715 | if (brcmf_sdio_readconsole(bus) < 0) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3716 | /* stop on error */ |
| 3717 | bus->console_interval = 0; |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 3718 | sdio_release_host(bus->sdiodev->func[1]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3719 | } |
| 3720 | } |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 3721 | #endif /* DEBUG */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3722 | |
| 3723 | /* On idle timeout clear activity flag and/or turn off clock */ |
| 3724 | if ((bus->idletime > 0) && (bus->clkstate == CLK_AVAIL)) { |
| 3725 | if (++bus->idlecount >= bus->idletime) { |
| 3726 | bus->idlecount = 0; |
| 3727 | if (bus->activity) { |
| 3728 | bus->activity = false; |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3729 | brcmf_sdio_wd_timer(bus, BRCMF_WD_POLL_MS); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3730 | } else { |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 3731 | brcmf_dbg(SDIO, "idle\n"); |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 3732 | sdio_claim_host(bus->sdiodev->func[1]); |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3733 | brcmf_sdio_bus_sleep(bus, true, false); |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 3734 | sdio_release_host(bus->sdiodev->func[1]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3735 | } |
| 3736 | } |
| 3737 | } |
| 3738 | |
Franky Lin | 1d38227 | 2012-09-13 21:11:59 +0200 | [diff] [blame] | 3739 | return (atomic_read(&bus->ipend) > 0); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3740 | } |
| 3741 | |
Franky Lin | f1e68c2 | 2012-09-13 21:12:00 +0200 | [diff] [blame] | 3742 | static void brcmf_sdio_dataworker(struct work_struct *work) |
| 3743 | { |
| 3744 | struct brcmf_sdio *bus = container_of(work, struct brcmf_sdio, |
| 3745 | datawork); |
Franky Lin | f1e68c2 | 2012-09-13 21:12:00 +0200 | [diff] [blame] | 3746 | |
Arend van Spriel | fccfe93 | 2013-06-18 13:29:26 +0200 | [diff] [blame] | 3747 | while (atomic_read(&bus->dpc_tskcnt)) { |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3748 | brcmf_sdio_dpc(bus); |
Arend van Spriel | fccfe93 | 2013-06-18 13:29:26 +0200 | [diff] [blame] | 3749 | atomic_dec(&bus->dpc_tskcnt); |
Franky Lin | f1e68c2 | 2012-09-13 21:12:00 +0200 | [diff] [blame] | 3750 | } |
Franky Lin | f1e68c2 | 2012-09-13 21:12:00 +0200 | [diff] [blame] | 3751 | } |
| 3752 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3753 | static bool |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3754 | brcmf_sdio_probe_attach(struct brcmf_sdio *bus) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3755 | { |
| 3756 | u8 clkctl = 0; |
| 3757 | int err = 0; |
| 3758 | int reg_addr; |
| 3759 | u32 reg_val; |
Hante Meuleman | 668761a | 2013-04-12 10:55:55 +0200 | [diff] [blame] | 3760 | u32 drivestrength; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3761 | |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 3762 | sdio_claim_host(bus->sdiodev->func[1]); |
| 3763 | |
Joe Perches | 18aad4f | 2012-01-15 00:38:42 -0800 | [diff] [blame] | 3764 | pr_debug("F1 signature read @0x18000000=0x%4x\n", |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 3765 | brcmf_sdiod_regrl(bus->sdiodev, SI_ENUM_BASE, NULL)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3766 | |
| 3767 | /* |
Franky Lin | a97e4fc | 2011-11-04 22:23:35 +0100 | [diff] [blame] | 3768 | * Force PLL off until brcmf_sdio_chip_attach() |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3769 | * programs PLL control regs |
| 3770 | */ |
| 3771 | |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 3772 | brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, |
| 3773 | BRCMF_INIT_CLKCTL1, &err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3774 | if (!err) |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 3775 | clkctl = brcmf_sdiod_regrb(bus->sdiodev, |
| 3776 | SBSDIO_FUNC1_CHIPCLKCSR, &err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3777 | |
| 3778 | if (err || ((clkctl & ~SBSDIO_AVBITS) != BRCMF_INIT_CLKCTL1)) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 3779 | brcmf_err("ChipClkCSR access: err %d wrote 0x%02x read 0x%02x\n", |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3780 | err, BRCMF_INIT_CLKCTL1, clkctl); |
| 3781 | goto fail; |
| 3782 | } |
| 3783 | |
Arend van Spriel | 4744d16 | 2013-12-12 11:58:55 +0100 | [diff] [blame] | 3784 | if (brcmf_sdio_chip_attach(bus->sdiodev, &bus->ci)) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 3785 | brcmf_err("brcmf_sdio_chip_attach failed!\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3786 | goto fail; |
| 3787 | } |
| 3788 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3789 | if (brcmf_sdio_kso_init(bus)) { |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 3790 | brcmf_err("error enabling KSO\n"); |
| 3791 | goto fail; |
| 3792 | } |
| 3793 | |
Hante Meuleman | 668761a | 2013-04-12 10:55:55 +0200 | [diff] [blame] | 3794 | if ((bus->sdiodev->pdata) && (bus->sdiodev->pdata->drive_strength)) |
| 3795 | drivestrength = bus->sdiodev->pdata->drive_strength; |
| 3796 | else |
| 3797 | drivestrength = DEFAULT_SDIO_DRIVE_STRENGTH; |
| 3798 | brcmf_sdio_chip_drivestrengthinit(bus->sdiodev, bus->ci, drivestrength); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3799 | |
Franky Lin | 454d2a8 | 2011-11-04 22:23:37 +0100 | [diff] [blame] | 3800 | /* Get info on the SOCRAM cores... */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3801 | bus->ramsize = bus->ci->ramsize; |
| 3802 | if (!(bus->ramsize)) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 3803 | brcmf_err("failed to find SOCRAM memory!\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3804 | goto fail; |
| 3805 | } |
| 3806 | |
Piotr Haber | 1e9ab4d | 2013-04-11 13:28:52 +0200 | [diff] [blame] | 3807 | /* Set card control so an SDIO card reset does a WLAN backplane reset */ |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 3808 | reg_val = brcmf_sdiod_regrb(bus->sdiodev, |
| 3809 | SDIO_CCCR_BRCM_CARDCTRL, &err); |
Piotr Haber | 1e9ab4d | 2013-04-11 13:28:52 +0200 | [diff] [blame] | 3810 | if (err) |
| 3811 | goto fail; |
| 3812 | |
| 3813 | reg_val |= SDIO_CCCR_BRCM_CARDCTRL_WLANRESET; |
| 3814 | |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 3815 | brcmf_sdiod_regwb(bus->sdiodev, |
| 3816 | SDIO_CCCR_BRCM_CARDCTRL, reg_val, &err); |
Piotr Haber | 1e9ab4d | 2013-04-11 13:28:52 +0200 | [diff] [blame] | 3817 | if (err) |
| 3818 | goto fail; |
| 3819 | |
| 3820 | /* set PMUControl so a backplane reset does PMU state reload */ |
| 3821 | reg_addr = CORE_CC_REG(bus->ci->c_inf[0].base, |
| 3822 | pmucontrol); |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 3823 | reg_val = brcmf_sdiod_regrl(bus->sdiodev, |
| 3824 | reg_addr, |
| 3825 | &err); |
Piotr Haber | 1e9ab4d | 2013-04-11 13:28:52 +0200 | [diff] [blame] | 3826 | if (err) |
| 3827 | goto fail; |
| 3828 | |
| 3829 | reg_val |= (BCMA_CC_PMU_CTL_RES_RELOAD << BCMA_CC_PMU_CTL_RES_SHIFT); |
| 3830 | |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 3831 | brcmf_sdiod_regwl(bus->sdiodev, |
| 3832 | reg_addr, |
| 3833 | reg_val, |
| 3834 | &err); |
Piotr Haber | 1e9ab4d | 2013-04-11 13:28:52 +0200 | [diff] [blame] | 3835 | if (err) |
| 3836 | goto fail; |
| 3837 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3838 | |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 3839 | sdio_release_host(bus->sdiodev->func[1]); |
| 3840 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3841 | brcmu_pktq_init(&bus->txq, (PRIOMASK + 1), TXQLEN); |
| 3842 | |
Arend van Spriel | 9b2d2f2 | 2013-11-29 12:25:14 +0100 | [diff] [blame] | 3843 | /* allocate header buffer */ |
| 3844 | bus->hdrbuf = kzalloc(MAX_HDR_READ + bus->head_align, GFP_KERNEL); |
| 3845 | if (!bus->hdrbuf) |
| 3846 | return false; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3847 | /* Locate an appropriately-aligned portion of hdrbuf */ |
| 3848 | bus->rxhdr = (u8 *) roundup((unsigned long)&bus->hdrbuf[0], |
Arend van Spriel | 9b2d2f2 | 2013-11-29 12:25:14 +0100 | [diff] [blame] | 3849 | bus->head_align); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3850 | |
| 3851 | /* Set the poll and/or interrupt flags */ |
| 3852 | bus->intr = true; |
| 3853 | bus->poll = false; |
| 3854 | if (bus->poll) |
| 3855 | bus->pollrate = 1; |
| 3856 | |
| 3857 | return true; |
| 3858 | |
| 3859 | fail: |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 3860 | sdio_release_host(bus->sdiodev->func[1]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3861 | return false; |
| 3862 | } |
| 3863 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3864 | static int |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3865 | brcmf_sdio_watchdog_thread(void *data) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3866 | { |
Franky Lin | e92eedf | 2011-11-22 17:21:50 -0800 | [diff] [blame] | 3867 | struct brcmf_sdio *bus = (struct brcmf_sdio *)data; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3868 | |
| 3869 | allow_signal(SIGTERM); |
| 3870 | /* Run until signal received */ |
| 3871 | while (1) { |
| 3872 | if (kthread_should_stop()) |
| 3873 | break; |
| 3874 | if (!wait_for_completion_interruptible(&bus->watchdog_wait)) { |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3875 | brcmf_sdio_bus_watchdog(bus); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3876 | /* Count the tick for reference */ |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 3877 | bus->sdcnt.tickcnt++; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3878 | } else |
| 3879 | break; |
| 3880 | } |
| 3881 | return 0; |
| 3882 | } |
| 3883 | |
| 3884 | static void |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3885 | brcmf_sdio_watchdog(unsigned long data) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3886 | { |
Franky Lin | e92eedf | 2011-11-22 17:21:50 -0800 | [diff] [blame] | 3887 | struct brcmf_sdio *bus = (struct brcmf_sdio *)data; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3888 | |
| 3889 | if (bus->watchdog_tsk) { |
| 3890 | complete(&bus->watchdog_wait); |
| 3891 | /* Reschedule the watchdog */ |
| 3892 | if (bus->wd_timer_valid) |
| 3893 | mod_timer(&bus->timer, |
| 3894 | jiffies + BRCMF_WD_POLL_MS * HZ / 1000); |
| 3895 | } |
| 3896 | } |
| 3897 | |
Arend van Spriel | d9cb259 | 2012-12-05 15:25:54 +0100 | [diff] [blame] | 3898 | static struct brcmf_bus_ops brcmf_sdio_bus_ops = { |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3899 | .stop = brcmf_sdio_bus_stop, |
| 3900 | .preinit = brcmf_sdio_bus_preinit, |
| 3901 | .init = brcmf_sdio_bus_init, |
| 3902 | .txdata = brcmf_sdio_bus_txdata, |
| 3903 | .txctl = brcmf_sdio_bus_txctl, |
| 3904 | .rxctl = brcmf_sdio_bus_rxctl, |
| 3905 | .gettxq = brcmf_sdio_bus_gettxq, |
Arend van Spriel | d9cb259 | 2012-12-05 15:25:54 +0100 | [diff] [blame] | 3906 | }; |
| 3907 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3908 | struct brcmf_sdio *brcmf_sdio_probe(struct brcmf_sdio_dev *sdiodev) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3909 | { |
| 3910 | int ret; |
Franky Lin | e92eedf | 2011-11-22 17:21:50 -0800 | [diff] [blame] | 3911 | struct brcmf_sdio *bus; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3912 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3913 | brcmf_dbg(TRACE, "Enter\n"); |
| 3914 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3915 | /* Allocate private bus interface state */ |
Franky Lin | e92eedf | 2011-11-22 17:21:50 -0800 | [diff] [blame] | 3916 | bus = kzalloc(sizeof(struct brcmf_sdio), GFP_ATOMIC); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3917 | if (!bus) |
| 3918 | goto fail; |
| 3919 | |
| 3920 | bus->sdiodev = sdiodev; |
| 3921 | sdiodev->bus = bus; |
Arend van Spriel | b83db86 | 2011-10-19 12:51:09 +0200 | [diff] [blame] | 3922 | skb_queue_head_init(&bus->glom); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3923 | bus->txbound = BRCMF_TXBOUND; |
| 3924 | bus->rxbound = BRCMF_RXBOUND; |
| 3925 | bus->txminmax = BRCMF_TXMINMAX; |
Franky Lin | 6bc5231 | 2013-08-10 12:27:28 +0200 | [diff] [blame] | 3926 | bus->tx_seq = SDPCM_SEQ_WRAP - 1; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3927 | |
Arend van Spriel | e217d1c | 2013-11-29 12:25:13 +0100 | [diff] [blame] | 3928 | /* platform specific configuration: |
| 3929 | * alignments must be at least 4 bytes for ADMA |
| 3930 | */ |
| 3931 | bus->head_align = ALIGNMENT; |
| 3932 | bus->sgentry_align = ALIGNMENT; |
| 3933 | if (sdiodev->pdata) { |
| 3934 | if (sdiodev->pdata->sd_head_align > ALIGNMENT) |
| 3935 | bus->head_align = sdiodev->pdata->sd_head_align; |
| 3936 | if (sdiodev->pdata->sd_sgentry_align > ALIGNMENT) |
| 3937 | bus->sgentry_align = sdiodev->pdata->sd_sgentry_align; |
| 3938 | } |
| 3939 | |
Hante Meuleman | 37ac578 | 2012-11-14 18:46:18 -0800 | [diff] [blame] | 3940 | INIT_WORK(&bus->datawork, brcmf_sdio_dataworker); |
| 3941 | bus->brcmf_wq = create_singlethread_workqueue("brcmf_wq"); |
| 3942 | if (bus->brcmf_wq == NULL) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 3943 | brcmf_err("insufficient memory to create txworkqueue\n"); |
Hante Meuleman | 37ac578 | 2012-11-14 18:46:18 -0800 | [diff] [blame] | 3944 | goto fail; |
| 3945 | } |
| 3946 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3947 | /* attempt to attach to the dongle */ |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3948 | if (!(brcmf_sdio_probe_attach(bus))) { |
| 3949 | brcmf_err("brcmf_sdio_probe_attach failed\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3950 | goto fail; |
| 3951 | } |
| 3952 | |
Franky Lin | dd43a01 | 2012-11-05 16:22:22 -0800 | [diff] [blame] | 3953 | spin_lock_init(&bus->rxctl_lock); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3954 | spin_lock_init(&bus->txqlock); |
| 3955 | init_waitqueue_head(&bus->ctrl_wait); |
| 3956 | init_waitqueue_head(&bus->dcmd_resp_wait); |
| 3957 | |
| 3958 | /* Set up the watchdog timer */ |
| 3959 | init_timer(&bus->timer); |
| 3960 | bus->timer.data = (unsigned long)bus; |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3961 | bus->timer.function = brcmf_sdio_watchdog; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3962 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3963 | /* Initialize watchdog thread */ |
| 3964 | init_completion(&bus->watchdog_wait); |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3965 | bus->watchdog_tsk = kthread_run(brcmf_sdio_watchdog_thread, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3966 | bus, "brcmf_watchdog"); |
| 3967 | if (IS_ERR(bus->watchdog_tsk)) { |
Joe Perches | 02f7719 | 2012-01-15 00:38:44 -0800 | [diff] [blame] | 3968 | pr_warn("brcmf_watchdog thread failed to start\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3969 | bus->watchdog_tsk = NULL; |
| 3970 | } |
| 3971 | /* Initialize DPC thread */ |
Arend van Spriel | fccfe93 | 2013-06-18 13:29:26 +0200 | [diff] [blame] | 3972 | atomic_set(&bus->dpc_tskcnt, 0); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3973 | |
Franky Lin | a9ffda8 | 2011-12-16 18:37:12 -0800 | [diff] [blame] | 3974 | /* Assign bus interface call back */ |
Arend van Spriel | d9cb259 | 2012-12-05 15:25:54 +0100 | [diff] [blame] | 3975 | bus->sdiodev->bus_if->dev = bus->sdiodev->dev; |
| 3976 | bus->sdiodev->bus_if->ops = &brcmf_sdio_bus_ops; |
Arend van Spriel | 75d907d | 2013-02-06 18:40:45 +0100 | [diff] [blame] | 3977 | bus->sdiodev->bus_if->chip = bus->ci->chip; |
| 3978 | bus->sdiodev->bus_if->chiprev = bus->ci->chiprev; |
Arend van Spriel | d9cb259 | 2012-12-05 15:25:54 +0100 | [diff] [blame] | 3979 | |
Franky Lin | 706478c | 2013-08-10 12:27:29 +0200 | [diff] [blame] | 3980 | /* default sdio bus header length for tx packet */ |
| 3981 | bus->tx_hdrlen = SDPCM_HWHDR_LEN + SDPCM_SWHDR_LEN; |
| 3982 | |
| 3983 | /* Attach to the common layer, reserve hdr space */ |
Arend van Spriel | 8dee77b | 2013-11-29 11:48:14 +0100 | [diff] [blame] | 3984 | ret = brcmf_attach(bus->sdiodev->dev); |
Franky Lin | 712ac5b | 2011-12-16 18:37:09 -0800 | [diff] [blame] | 3985 | if (ret != 0) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 3986 | brcmf_err("brcmf_attach failed\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3987 | goto fail; |
| 3988 | } |
| 3989 | |
| 3990 | /* Allocate buffers */ |
Arend van Spriel | fad1322 | 2014-01-06 12:40:40 +0100 | [diff] [blame] | 3991 | if (bus->sdiodev->bus_if->maxctl) { |
| 3992 | bus->rxblen = |
| 3993 | roundup((bus->sdiodev->bus_if->maxctl + SDPCM_HDRLEN), |
| 3994 | ALIGNMENT) + bus->head_align; |
| 3995 | bus->rxbuf = kmalloc(bus->rxblen, GFP_ATOMIC); |
| 3996 | if (!(bus->rxbuf)) { |
| 3997 | brcmf_err("rxbuf allocation failed\n"); |
| 3998 | goto fail; |
| 3999 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4000 | } |
| 4001 | |
Arend van Spriel | fad1322 | 2014-01-06 12:40:40 +0100 | [diff] [blame] | 4002 | sdio_claim_host(bus->sdiodev->func[1]); |
| 4003 | |
| 4004 | /* Disable F2 to clear any intermediate frame state on the dongle */ |
| 4005 | sdio_disable_func(bus->sdiodev->func[SDIO_FUNC_2]); |
| 4006 | |
| 4007 | bus->sdiodev->bus_if->state = BRCMF_BUS_DOWN; |
| 4008 | bus->rxflow = false; |
| 4009 | |
| 4010 | /* Done with backplane-dependent accesses, can drop clock... */ |
| 4011 | brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, 0, NULL); |
| 4012 | |
| 4013 | sdio_release_host(bus->sdiodev->func[1]); |
| 4014 | |
| 4015 | /* ...and initialize clock/power states */ |
| 4016 | bus->clkstate = CLK_SDONLY; |
| 4017 | bus->idletime = BRCMF_IDLE_INTERVAL; |
| 4018 | bus->idleclock = BRCMF_IDLE_ACTIVE; |
| 4019 | |
| 4020 | /* Query the F2 block size, set roundup accordingly */ |
| 4021 | bus->blocksize = bus->sdiodev->func[2]->cur_blksize; |
| 4022 | bus->roundup = min(max_roundup, bus->blocksize); |
| 4023 | |
| 4024 | /* SR state */ |
| 4025 | bus->sleeping = false; |
| 4026 | bus->sr_enabled = false; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4027 | |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 4028 | brcmf_sdio_debugfs_create(bus); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4029 | brcmf_dbg(INFO, "completed!!\n"); |
| 4030 | |
| 4031 | /* if firmware path present try to download and bring up bus */ |
Franky Lin | ed683c9 | 2011-12-16 18:36:55 -0800 | [diff] [blame] | 4032 | ret = brcmf_bus_start(bus->sdiodev->dev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4033 | if (ret != 0) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 4034 | brcmf_err("dongle is not responding\n"); |
Hante Meuleman | 1799ddf | 2012-11-14 18:46:17 -0800 | [diff] [blame] | 4035 | goto fail; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4036 | } |
Franky Lin | 15d45b6 | 2011-10-21 16:16:32 +0200 | [diff] [blame] | 4037 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4038 | return bus; |
| 4039 | |
| 4040 | fail: |
Arend van Spriel | 9fbe2a6 | 2013-12-12 11:59:05 +0100 | [diff] [blame] | 4041 | brcmf_sdio_remove(bus); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4042 | return NULL; |
| 4043 | } |
| 4044 | |
Arend van Spriel | 9fbe2a6 | 2013-12-12 11:59:05 +0100 | [diff] [blame] | 4045 | /* Detach and free everything */ |
| 4046 | void brcmf_sdio_remove(struct brcmf_sdio *bus) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4047 | { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4048 | brcmf_dbg(TRACE, "Enter\n"); |
| 4049 | |
Arend van Spriel | 9fbe2a6 | 2013-12-12 11:59:05 +0100 | [diff] [blame] | 4050 | if (bus) { |
| 4051 | /* De-register interrupt handler */ |
| 4052 | brcmf_sdiod_intr_unregister(bus->sdiodev); |
| 4053 | |
| 4054 | cancel_work_sync(&bus->datawork); |
| 4055 | if (bus->brcmf_wq) |
| 4056 | destroy_workqueue(bus->brcmf_wq); |
| 4057 | |
| 4058 | if (bus->sdiodev->bus_if->drvr) { |
| 4059 | brcmf_detach(bus->sdiodev->dev); |
Arend van Spriel | bfad4a0 | 2014-01-06 12:40:39 +0100 | [diff] [blame] | 4060 | } |
| 4061 | |
| 4062 | if (bus->ci) { |
| 4063 | sdio_claim_host(bus->sdiodev->func[1]); |
| 4064 | brcmf_sdio_clkctl(bus, CLK_AVAIL, false); |
Hante Meuleman | 5303626 | 2014-01-13 22:20:23 +0100 | [diff] [blame] | 4065 | /* Leave the device in state where it is 'quiet'. This |
| 4066 | * is done by putting it in download_state which |
| 4067 | * essentially resets all necessary cores |
| 4068 | */ |
| 4069 | msleep(20); |
Arend van Spriel | 3355650 | 2014-01-13 22:20:25 +0100 | [diff] [blame^] | 4070 | brcmf_sdio_chip_enter_download(bus->sdiodev, bus->ci); |
Arend van Spriel | bfad4a0 | 2014-01-06 12:40:39 +0100 | [diff] [blame] | 4071 | brcmf_sdio_clkctl(bus, CLK_NONE, false); |
| 4072 | sdio_release_host(bus->sdiodev->func[1]); |
| 4073 | brcmf_sdio_chip_detach(&bus->ci); |
Arend van Spriel | 9fbe2a6 | 2013-12-12 11:59:05 +0100 | [diff] [blame] | 4074 | } |
| 4075 | |
| 4076 | brcmu_pkt_buf_free_skb(bus->txglom_sgpad); |
Arend van Spriel | bfad4a0 | 2014-01-06 12:40:39 +0100 | [diff] [blame] | 4077 | kfree(bus->rxbuf); |
Arend van Spriel | 9fbe2a6 | 2013-12-12 11:59:05 +0100 | [diff] [blame] | 4078 | kfree(bus->hdrbuf); |
| 4079 | kfree(bus); |
| 4080 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4081 | |
| 4082 | brcmf_dbg(TRACE, "Disconnected\n"); |
| 4083 | } |
| 4084 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 4085 | void brcmf_sdio_wd_timer(struct brcmf_sdio *bus, uint wdtick) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4086 | { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4087 | /* Totally stop the timer */ |
Joe Perches | 23677ce | 2012-02-09 11:17:23 +0000 | [diff] [blame] | 4088 | if (!wdtick && bus->wd_timer_valid) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4089 | del_timer_sync(&bus->timer); |
| 4090 | bus->wd_timer_valid = false; |
| 4091 | bus->save_ms = wdtick; |
| 4092 | return; |
| 4093 | } |
| 4094 | |
Franky Lin | ece960e | 2011-10-21 16:16:19 +0200 | [diff] [blame] | 4095 | /* don't start the wd until fw is loaded */ |
Arend van Spriel | d6ae2c5 | 2014-01-06 12:40:44 +0100 | [diff] [blame] | 4096 | if (bus->sdiodev->bus_if->state != BRCMF_BUS_DATA) |
Franky Lin | ece960e | 2011-10-21 16:16:19 +0200 | [diff] [blame] | 4097 | return; |
| 4098 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4099 | if (wdtick) { |
| 4100 | if (bus->save_ms != BRCMF_WD_POLL_MS) { |
Joe Perches | 23677ce | 2012-02-09 11:17:23 +0000 | [diff] [blame] | 4101 | if (bus->wd_timer_valid) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4102 | /* Stop timer and restart at new value */ |
| 4103 | del_timer_sync(&bus->timer); |
| 4104 | |
| 4105 | /* Create timer again when watchdog period is |
| 4106 | dynamically changed or in the first instance |
| 4107 | */ |
| 4108 | bus->timer.expires = |
| 4109 | jiffies + BRCMF_WD_POLL_MS * HZ / 1000; |
| 4110 | add_timer(&bus->timer); |
| 4111 | |
| 4112 | } else { |
| 4113 | /* Re arm the timer, at last watchdog period */ |
| 4114 | mod_timer(&bus->timer, |
| 4115 | jiffies + BRCMF_WD_POLL_MS * HZ / 1000); |
| 4116 | } |
| 4117 | |
| 4118 | bus->wd_timer_valid = true; |
| 4119 | bus->save_ms = wdtick; |
| 4120 | } |
| 4121 | } |