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