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