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> |
Hauke Mehrtens | a32be01 | 2015-09-19 12:47:20 +0200 | [diff] [blame^] | 18 | #include <linux/atomic.h> |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 19 | #include <linux/kernel.h> |
| 20 | #include <linux/kthread.h> |
| 21 | #include <linux/printk.h> |
| 22 | #include <linux/pci_ids.h> |
| 23 | #include <linux/netdevice.h> |
| 24 | #include <linux/interrupt.h> |
| 25 | #include <linux/sched.h> |
| 26 | #include <linux/mmc/sdio.h> |
Arend van Spriel | cb7cf7b | 2014-01-29 15:32:19 +0100 | [diff] [blame] | 27 | #include <linux/mmc/sdio_ids.h> |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 28 | #include <linux/mmc/sdio_func.h> |
| 29 | #include <linux/mmc/card.h> |
| 30 | #include <linux/semaphore.h> |
| 31 | #include <linux/firmware.h> |
Stephen Rothwell | b7a57e7 | 2011-10-12 21:35:07 +0200 | [diff] [blame] | 32 | #include <linux/module.h> |
Franky Lin | 99ba15c | 2011-11-04 22:23:42 +0100 | [diff] [blame] | 33 | #include <linux/bcma/bcma.h> |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 34 | #include <linux/debugfs.h> |
Arend van Spriel | 8dc0181 | 2012-06-21 11:33:32 +0200 | [diff] [blame] | 35 | #include <linux/vmalloc.h> |
Hante Meuleman | 668761a | 2013-04-12 10:55:55 +0200 | [diff] [blame] | 36 | #include <linux/platform_data/brcmfmac-sdio.h> |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 37 | #include <linux/moduleparam.h> |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 38 | #include <asm/unaligned.h> |
| 39 | #include <defs.h> |
| 40 | #include <brcmu_wifi.h> |
| 41 | #include <brcmu_utils.h> |
| 42 | #include <brcm_hw_ids.h> |
| 43 | #include <soc.h> |
Hante Meuleman | 888bf76e | 2014-10-28 14:56:17 +0100 | [diff] [blame] | 44 | #include "sdio.h" |
Arend van Spriel | 20c9c9b | 2014-01-29 15:32:15 +0100 | [diff] [blame] | 45 | #include "chip.h" |
Arend van Spriel | dabedab | 2014-05-27 12:56:17 +0200 | [diff] [blame] | 46 | #include "firmware.h" |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 47 | |
Hante Meuleman | 4dd8b26 | 2015-01-25 20:31:32 +0100 | [diff] [blame] | 48 | #define DCMD_RESP_TIMEOUT 2000 /* In milli second */ |
| 49 | #define CTL_DONE_TIMEOUT 2000 /* In milli second */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 50 | |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 51 | #ifdef DEBUG |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 52 | |
| 53 | #define BRCMF_TRAP_INFO_SIZE 80 |
| 54 | |
| 55 | #define CBUF_LEN (128) |
| 56 | |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 57 | /* Device console log buffer state */ |
| 58 | #define CONSOLE_BUFFER_MAX 2024 |
| 59 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 60 | struct rte_log_le { |
| 61 | __le32 buf; /* Can't be pointer on (64-bit) hosts */ |
| 62 | __le32 buf_size; |
| 63 | __le32 idx; |
| 64 | char *_buf_compat; /* Redundant pointer for backward compat. */ |
| 65 | }; |
| 66 | |
| 67 | struct rte_console { |
| 68 | /* Virtual UART |
| 69 | * When there is no UART (e.g. Quickturn), |
| 70 | * the host should write a complete |
| 71 | * input line directly into cbuf and then write |
| 72 | * the length into vcons_in. |
| 73 | * This may also be used when there is a real UART |
| 74 | * (at risk of conflicting with |
| 75 | * the real UART). vcons_out is currently unused. |
| 76 | */ |
| 77 | uint vcons_in; |
| 78 | uint vcons_out; |
| 79 | |
| 80 | /* Output (logging) buffer |
| 81 | * Console output is written to a ring buffer log_buf at index log_idx. |
| 82 | * The host may read the output when it sees log_idx advance. |
| 83 | * Output will be lost if the output wraps around faster than the host |
| 84 | * polls. |
| 85 | */ |
| 86 | struct rte_log_le log_le; |
| 87 | |
| 88 | /* Console input line buffer |
| 89 | * Characters are read one at a time into cbuf |
| 90 | * until <CR> is received, then |
| 91 | * the buffer is processed as a command line. |
| 92 | * Also used for virtual UART. |
| 93 | */ |
| 94 | uint cbuf_idx; |
| 95 | char cbuf[CBUF_LEN]; |
| 96 | }; |
| 97 | |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 98 | #endif /* DEBUG */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 99 | #include <chipcommon.h> |
| 100 | |
Hante Meuleman | d14f78b | 2014-10-28 14:56:14 +0100 | [diff] [blame] | 101 | #include "bus.h" |
Hante Meuleman | a8e8ed3 | 2014-10-28 14:56:13 +0100 | [diff] [blame] | 102 | #include "debug.h" |
Arend van Spriel | 40c1c24 | 2013-04-05 10:57:44 +0200 | [diff] [blame] | 103 | #include "tracepoint.h" |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 104 | |
| 105 | #define TXQLEN 2048 /* bulk tx queue length */ |
| 106 | #define TXHI (TXQLEN - 256) /* turn on flow control above TXHI */ |
| 107 | #define TXLOW (TXHI - 256) /* turn off flow control below TXLOW */ |
| 108 | #define PRIOMASK 7 |
| 109 | |
| 110 | #define TXRETRIES 2 /* # of retries for tx frames */ |
| 111 | |
| 112 | #define BRCMF_RXBOUND 50 /* Default for max rx frames in |
| 113 | one scheduling */ |
| 114 | |
| 115 | #define BRCMF_TXBOUND 20 /* Default for max tx frames in |
| 116 | one scheduling */ |
| 117 | |
| 118 | #define BRCMF_TXMINMAX 1 /* Max tx frames if rx still pending */ |
| 119 | |
| 120 | #define MEMBLOCK 2048 /* Block size used for downloading |
| 121 | of dongle image */ |
| 122 | #define MAX_DATA_BUF (32 * 1024) /* Must be large enough to hold |
| 123 | biggest possible glom */ |
| 124 | |
| 125 | #define BRCMF_FIRSTREAD (1 << 6) |
| 126 | |
Arend van Spriel | 9d6c1dc | 2015-08-26 22:15:01 +0200 | [diff] [blame] | 127 | #define BRCMF_CONSOLE 10 /* watchdog interval to poll console */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 128 | |
| 129 | /* SBSDIO_DEVICE_CTL */ |
| 130 | |
| 131 | /* 1: device will assert busy signal when receiving CMD53 */ |
| 132 | #define SBSDIO_DEVCTL_SETBUSY 0x01 |
| 133 | /* 1: assertion of sdio interrupt is synchronous to the sdio clock */ |
| 134 | #define SBSDIO_DEVCTL_SPI_INTR_SYNC 0x02 |
| 135 | /* 1: mask all interrupts to host except the chipActive (rev 8) */ |
| 136 | #define SBSDIO_DEVCTL_CA_INT_ONLY 0x04 |
| 137 | /* 1: isolate internal sdio signals, put external pads in tri-state; requires |
| 138 | * sdio bus power cycle to clear (rev 9) */ |
| 139 | #define SBSDIO_DEVCTL_PADS_ISO 0x08 |
| 140 | /* Force SD->SB reset mapping (rev 11) */ |
| 141 | #define SBSDIO_DEVCTL_SB_RST_CTL 0x30 |
| 142 | /* Determined by CoreControl bit */ |
| 143 | #define SBSDIO_DEVCTL_RST_CORECTL 0x00 |
| 144 | /* Force backplane reset */ |
| 145 | #define SBSDIO_DEVCTL_RST_BPRESET 0x10 |
| 146 | /* Force no backplane reset */ |
| 147 | #define SBSDIO_DEVCTL_RST_NOBPRESET 0x20 |
| 148 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 149 | /* direct(mapped) cis space */ |
| 150 | |
| 151 | /* MAPPED common CIS address */ |
| 152 | #define SBSDIO_CIS_BASE_COMMON 0x1000 |
| 153 | /* maximum bytes in one CIS */ |
| 154 | #define SBSDIO_CIS_SIZE_LIMIT 0x200 |
| 155 | /* cis offset addr is < 17 bits */ |
| 156 | #define SBSDIO_CIS_OFT_ADDR_MASK 0x1FFFF |
| 157 | |
| 158 | /* manfid tuple length, include tuple, link bytes */ |
| 159 | #define SBSDIO_CIS_MANFID_TUPLE_LEN 6 |
| 160 | |
Arend van Spriel | cb7cf7b | 2014-01-29 15:32:19 +0100 | [diff] [blame] | 161 | #define CORE_BUS_REG(base, field) \ |
| 162 | (base + offsetof(struct sdpcmd_regs, field)) |
| 163 | |
| 164 | /* SDIO function 1 register CHIPCLKCSR */ |
| 165 | /* Force ALP request to backplane */ |
| 166 | #define SBSDIO_FORCE_ALP 0x01 |
| 167 | /* Force HT request to backplane */ |
| 168 | #define SBSDIO_FORCE_HT 0x02 |
| 169 | /* Force ILP request to backplane */ |
| 170 | #define SBSDIO_FORCE_ILP 0x04 |
| 171 | /* Make ALP ready (power up xtal) */ |
| 172 | #define SBSDIO_ALP_AVAIL_REQ 0x08 |
| 173 | /* Make HT ready (power up PLL) */ |
| 174 | #define SBSDIO_HT_AVAIL_REQ 0x10 |
| 175 | /* Squelch clock requests from HW */ |
| 176 | #define SBSDIO_FORCE_HW_CLKREQ_OFF 0x20 |
| 177 | /* Status: ALP is ready */ |
| 178 | #define SBSDIO_ALP_AVAIL 0x40 |
| 179 | /* Status: HT is ready */ |
| 180 | #define SBSDIO_HT_AVAIL 0x80 |
Arend van Spriel | 8a385ba | 2014-03-15 17:18:20 +0100 | [diff] [blame] | 181 | #define SBSDIO_CSR_MASK 0x1F |
Arend van Spriel | cb7cf7b | 2014-01-29 15:32:19 +0100 | [diff] [blame] | 182 | #define SBSDIO_AVBITS (SBSDIO_HT_AVAIL | SBSDIO_ALP_AVAIL) |
| 183 | #define SBSDIO_ALPAV(regval) ((regval) & SBSDIO_AVBITS) |
| 184 | #define SBSDIO_HTAV(regval) (((regval) & SBSDIO_AVBITS) == SBSDIO_AVBITS) |
| 185 | #define SBSDIO_ALPONLY(regval) (SBSDIO_ALPAV(regval) && !SBSDIO_HTAV(regval)) |
| 186 | #define SBSDIO_CLKAV(regval, alponly) \ |
| 187 | (SBSDIO_ALPAV(regval) && (alponly ? 1 : SBSDIO_HTAV(regval))) |
| 188 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 189 | /* intstatus */ |
| 190 | #define I_SMB_SW0 (1 << 0) /* To SB Mail S/W interrupt 0 */ |
| 191 | #define I_SMB_SW1 (1 << 1) /* To SB Mail S/W interrupt 1 */ |
| 192 | #define I_SMB_SW2 (1 << 2) /* To SB Mail S/W interrupt 2 */ |
| 193 | #define I_SMB_SW3 (1 << 3) /* To SB Mail S/W interrupt 3 */ |
| 194 | #define I_SMB_SW_MASK 0x0000000f /* To SB Mail S/W interrupts mask */ |
| 195 | #define I_SMB_SW_SHIFT 0 /* To SB Mail S/W interrupts shift */ |
| 196 | #define I_HMB_SW0 (1 << 4) /* To Host Mail S/W interrupt 0 */ |
| 197 | #define I_HMB_SW1 (1 << 5) /* To Host Mail S/W interrupt 1 */ |
| 198 | #define I_HMB_SW2 (1 << 6) /* To Host Mail S/W interrupt 2 */ |
| 199 | #define I_HMB_SW3 (1 << 7) /* To Host Mail S/W interrupt 3 */ |
| 200 | #define I_HMB_SW_MASK 0x000000f0 /* To Host Mail S/W interrupts mask */ |
| 201 | #define I_HMB_SW_SHIFT 4 /* To Host Mail S/W interrupts shift */ |
| 202 | #define I_WR_OOSYNC (1 << 8) /* Write Frame Out Of Sync */ |
| 203 | #define I_RD_OOSYNC (1 << 9) /* Read Frame Out Of Sync */ |
| 204 | #define I_PC (1 << 10) /* descriptor error */ |
| 205 | #define I_PD (1 << 11) /* data error */ |
| 206 | #define I_DE (1 << 12) /* Descriptor protocol Error */ |
| 207 | #define I_RU (1 << 13) /* Receive descriptor Underflow */ |
| 208 | #define I_RO (1 << 14) /* Receive fifo Overflow */ |
| 209 | #define I_XU (1 << 15) /* Transmit fifo Underflow */ |
| 210 | #define I_RI (1 << 16) /* Receive Interrupt */ |
| 211 | #define I_BUSPWR (1 << 17) /* SDIO Bus Power Change (rev 9) */ |
| 212 | #define I_XMTDATA_AVAIL (1 << 23) /* bits in fifo */ |
| 213 | #define I_XI (1 << 24) /* Transmit Interrupt */ |
| 214 | #define I_RF_TERM (1 << 25) /* Read Frame Terminate */ |
| 215 | #define I_WF_TERM (1 << 26) /* Write Frame Terminate */ |
| 216 | #define I_PCMCIA_XU (1 << 27) /* PCMCIA Transmit FIFO Underflow */ |
| 217 | #define I_SBINT (1 << 28) /* sbintstatus Interrupt */ |
| 218 | #define I_CHIPACTIVE (1 << 29) /* chip from doze to active state */ |
| 219 | #define I_SRESET (1 << 30) /* CCCR RES interrupt */ |
| 220 | #define I_IOE2 (1U << 31) /* CCCR IOE2 Bit Changed */ |
| 221 | #define I_ERRORS (I_PC | I_PD | I_DE | I_RU | I_RO | I_XU) |
| 222 | #define I_DMA (I_RI | I_XI | I_ERRORS) |
| 223 | |
| 224 | /* corecontrol */ |
| 225 | #define CC_CISRDY (1 << 0) /* CIS Ready */ |
| 226 | #define CC_BPRESEN (1 << 1) /* CCCR RES signal */ |
| 227 | #define CC_F2RDY (1 << 2) /* set CCCR IOR2 bit */ |
| 228 | #define CC_CLRPADSISO (1 << 3) /* clear SDIO pads isolation */ |
| 229 | #define CC_XMTDATAAVAIL_MODE (1 << 4) |
| 230 | #define CC_XMTDATAAVAIL_CTRL (1 << 5) |
| 231 | |
| 232 | /* SDA_FRAMECTRL */ |
| 233 | #define SFC_RF_TERM (1 << 0) /* Read Frame Terminate */ |
| 234 | #define SFC_WF_TERM (1 << 1) /* Write Frame Terminate */ |
| 235 | #define SFC_CRC4WOOS (1 << 2) /* CRC error for write out of sync */ |
| 236 | #define SFC_ABORTALL (1 << 3) /* Abort all in-progress frames */ |
| 237 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 238 | /* |
| 239 | * Software allocation of To SB Mailbox resources |
| 240 | */ |
| 241 | |
| 242 | /* tosbmailbox bits corresponding to intstatus bits */ |
| 243 | #define SMB_NAK (1 << 0) /* Frame NAK */ |
| 244 | #define SMB_INT_ACK (1 << 1) /* Host Interrupt ACK */ |
| 245 | #define SMB_USE_OOB (1 << 2) /* Use OOB Wakeup */ |
| 246 | #define SMB_DEV_INT (1 << 3) /* Miscellaneous Interrupt */ |
| 247 | |
| 248 | /* tosbmailboxdata */ |
| 249 | #define SMB_DATA_VERSION_SHIFT 16 /* host protocol version */ |
| 250 | |
| 251 | /* |
| 252 | * Software allocation of To Host Mailbox resources |
| 253 | */ |
| 254 | |
| 255 | /* intstatus bits */ |
| 256 | #define I_HMB_FC_STATE I_HMB_SW0 /* Flow Control State */ |
| 257 | #define I_HMB_FC_CHANGE I_HMB_SW1 /* Flow Control State Changed */ |
| 258 | #define I_HMB_FRAME_IND I_HMB_SW2 /* Frame Indication */ |
| 259 | #define I_HMB_HOST_INT I_HMB_SW3 /* Miscellaneous Interrupt */ |
| 260 | |
| 261 | /* tohostmailboxdata */ |
| 262 | #define HMB_DATA_NAKHANDLED 1 /* retransmit NAK'd frame */ |
| 263 | #define HMB_DATA_DEVREADY 2 /* talk to host after enable */ |
| 264 | #define HMB_DATA_FC 4 /* per prio flowcontrol update flag */ |
| 265 | #define HMB_DATA_FWREADY 8 /* fw ready for protocol activity */ |
| 266 | |
| 267 | #define HMB_DATA_FCDATA_MASK 0xff000000 |
| 268 | #define HMB_DATA_FCDATA_SHIFT 24 |
| 269 | |
| 270 | #define HMB_DATA_VERSION_MASK 0x00ff0000 |
| 271 | #define HMB_DATA_VERSION_SHIFT 16 |
| 272 | |
| 273 | /* |
| 274 | * Software-defined protocol header |
| 275 | */ |
| 276 | |
| 277 | /* Current protocol version */ |
| 278 | #define SDPCM_PROT_VERSION 4 |
| 279 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 280 | /* |
| 281 | * Shared structure between dongle and the host. |
| 282 | * The structure contains pointers to trap or assert information. |
| 283 | */ |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 284 | #define SDPCM_SHARED_VERSION 0x0003 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 285 | #define SDPCM_SHARED_VERSION_MASK 0x00FF |
| 286 | #define SDPCM_SHARED_ASSERT_BUILT 0x0100 |
| 287 | #define SDPCM_SHARED_ASSERT 0x0200 |
| 288 | #define SDPCM_SHARED_TRAP 0x0400 |
| 289 | |
| 290 | /* Space for header read, limit for data packets */ |
| 291 | #define MAX_HDR_READ (1 << 6) |
| 292 | #define MAX_RX_DATASZ 2048 |
| 293 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 294 | /* Bump up limit on waiting for HT to account for first startup; |
| 295 | * if the image is doing a CRC calculation before programming the PMU |
| 296 | * for HT availability, it could take a couple hundred ms more, so |
| 297 | * max out at a 1 second (1000000us). |
| 298 | */ |
| 299 | #undef PMU_MAX_TRANSITION_DLY |
| 300 | #define PMU_MAX_TRANSITION_DLY 1000000 |
| 301 | |
| 302 | /* Value for ChipClockCSR during initial setup */ |
| 303 | #define BRCMF_INIT_CLKCTL1 (SBSDIO_FORCE_HW_CLKREQ_OFF | \ |
| 304 | SBSDIO_ALP_AVAIL_REQ) |
| 305 | |
| 306 | /* Flags for SDH calls */ |
| 307 | #define F2SYNC (SDIO_REQ_4BYTE | SDIO_REQ_FIXED) |
| 308 | |
Franky Lin | 382a9e0 | 2011-12-16 18:37:18 -0800 | [diff] [blame] | 309 | #define BRCMF_IDLE_ACTIVE 0 /* Do not request any SD clock change |
| 310 | * when idle |
| 311 | */ |
| 312 | #define BRCMF_IDLE_INTERVAL 1 |
| 313 | |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 314 | #define KSO_WAIT_US 50 |
| 315 | #define MAX_KSO_ATTEMPTS (PMU_MAX_TRANSITION_DLY/KSO_WAIT_US) |
| 316 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 317 | /* |
| 318 | * Conversion of 802.1D priority to precedence level |
| 319 | */ |
| 320 | static uint prio2prec(u32 prio) |
| 321 | { |
| 322 | return (prio == PRIO_8021D_NONE || prio == PRIO_8021D_BE) ? |
| 323 | (prio^2) : prio; |
| 324 | } |
| 325 | |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 326 | #ifdef DEBUG |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 327 | /* Device console log buffer state */ |
| 328 | struct brcmf_console { |
| 329 | uint count; /* Poll interval msec counter */ |
| 330 | uint log_addr; /* Log struct address (fixed) */ |
| 331 | struct rte_log_le log_le; /* Log struct (host copy) */ |
| 332 | uint bufsize; /* Size of log buffer */ |
| 333 | u8 *buf; /* Log buffer (host copy) */ |
| 334 | uint last; /* Last buffer read index */ |
| 335 | }; |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 336 | |
| 337 | struct brcmf_trap_info { |
| 338 | __le32 type; |
| 339 | __le32 epc; |
| 340 | __le32 cpsr; |
| 341 | __le32 spsr; |
| 342 | __le32 r0; /* a1 */ |
| 343 | __le32 r1; /* a2 */ |
| 344 | __le32 r2; /* a3 */ |
| 345 | __le32 r3; /* a4 */ |
| 346 | __le32 r4; /* v1 */ |
| 347 | __le32 r5; /* v2 */ |
| 348 | __le32 r6; /* v3 */ |
| 349 | __le32 r7; /* v4 */ |
| 350 | __le32 r8; /* v5 */ |
| 351 | __le32 r9; /* sb/v6 */ |
| 352 | __le32 r10; /* sl/v7 */ |
| 353 | __le32 r11; /* fp/v8 */ |
| 354 | __le32 r12; /* ip */ |
| 355 | __le32 r13; /* sp */ |
| 356 | __le32 r14; /* lr */ |
| 357 | __le32 pc; /* r15 */ |
| 358 | }; |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 359 | #endif /* DEBUG */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 360 | |
| 361 | struct sdpcm_shared { |
| 362 | u32 flags; |
| 363 | u32 trap_addr; |
| 364 | u32 assert_exp_addr; |
| 365 | u32 assert_file_addr; |
| 366 | u32 assert_line; |
| 367 | u32 console_addr; /* Address of struct rte_console */ |
| 368 | u32 msgtrace_addr; |
| 369 | u8 tag[32]; |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 370 | u32 brpt_addr; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 371 | }; |
| 372 | |
| 373 | struct sdpcm_shared_le { |
| 374 | __le32 flags; |
| 375 | __le32 trap_addr; |
| 376 | __le32 assert_exp_addr; |
| 377 | __le32 assert_file_addr; |
| 378 | __le32 assert_line; |
| 379 | __le32 console_addr; /* Address of struct rte_console */ |
| 380 | __le32 msgtrace_addr; |
| 381 | u8 tag[32]; |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 382 | __le32 brpt_addr; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 383 | }; |
| 384 | |
Franky Lin | 6bc5231 | 2013-08-10 12:27:28 +0200 | [diff] [blame] | 385 | /* dongle SDIO bus specific header info */ |
| 386 | struct brcmf_sdio_hdrinfo { |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 387 | u8 seq_num; |
| 388 | u8 channel; |
| 389 | u16 len; |
| 390 | u16 len_left; |
| 391 | u16 len_nxtfrm; |
| 392 | u8 dat_offset; |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 393 | bool lastfrm; |
| 394 | u16 tail_pad; |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 395 | }; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 396 | |
Arend van Spriel | 82d957e | 2014-07-12 08:49:36 +0200 | [diff] [blame] | 397 | /* |
| 398 | * hold counter variables |
| 399 | */ |
| 400 | struct brcmf_sdio_count { |
| 401 | uint intrcount; /* Count of device interrupt callbacks */ |
| 402 | uint lastintrs; /* Count as of last watchdog timer */ |
| 403 | uint pollcnt; /* Count of active polls */ |
| 404 | uint regfails; /* Count of R_REG failures */ |
| 405 | uint tx_sderrs; /* Count of tx attempts with sd errors */ |
| 406 | uint fcqueued; /* Tx packets that got queued */ |
| 407 | uint rxrtx; /* Count of rtx requests (NAK to dongle) */ |
| 408 | uint rx_toolong; /* Receive frames too long to receive */ |
| 409 | uint rxc_errors; /* SDIO errors when reading control frames */ |
| 410 | uint rx_hdrfail; /* SDIO errors on header reads */ |
| 411 | uint rx_badhdr; /* Bad received headers (roosync?) */ |
| 412 | uint rx_badseq; /* Mismatched rx sequence number */ |
| 413 | uint fc_rcvd; /* Number of flow-control events received */ |
| 414 | uint fc_xoff; /* Number which turned on flow-control */ |
| 415 | uint fc_xon; /* Number which turned off flow-control */ |
| 416 | uint rxglomfail; /* Failed deglom attempts */ |
| 417 | uint rxglomframes; /* Number of glom frames (superframes) */ |
| 418 | uint rxglompkts; /* Number of packets from glom frames */ |
| 419 | uint f2rxhdrs; /* Number of header reads */ |
| 420 | uint f2rxdata; /* Number of frame data reads */ |
| 421 | uint f2txdata; /* Number of f2 frame writes */ |
| 422 | uint f1regdata; /* Number of f1 register accesses */ |
| 423 | uint tickcnt; /* Number of watchdog been schedule */ |
| 424 | ulong tx_ctlerrs; /* Err of sending ctrl frames */ |
| 425 | ulong tx_ctlpkts; /* Ctrl frames sent to dongle */ |
| 426 | ulong rx_ctlerrs; /* Err of processing rx ctrl frames */ |
| 427 | ulong rx_ctlpkts; /* Ctrl frames processed from dongle */ |
| 428 | ulong rx_readahead_cnt; /* packets where header read-ahead was used */ |
| 429 | }; |
| 430 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 431 | /* misc chip info needed by some of the routines */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 432 | /* Private data for SDIO bus interaction */ |
Franky Lin | e92eedf | 2011-11-22 17:21:50 -0800 | [diff] [blame] | 433 | struct brcmf_sdio { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 434 | struct brcmf_sdio_dev *sdiodev; /* sdio device handler */ |
Arend van Spriel | 9cf218f | 2014-01-13 22:20:27 +0100 | [diff] [blame] | 435 | struct brcmf_chip *ci; /* Chip info struct */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 436 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 437 | u32 hostintmask; /* Copy of Host Interrupt Mask */ |
Franky Lin | 4531603 | 2012-09-13 21:12:03 +0200 | [diff] [blame] | 438 | atomic_t intstatus; /* Intstatus bits (events) pending */ |
| 439 | atomic_t fcstate; /* State of dongle flow-control */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 440 | |
| 441 | uint blocksize; /* Block size of SDIO transfers */ |
| 442 | uint roundup; /* Max roundup limit */ |
| 443 | |
| 444 | struct pktq txq; /* Queue length used for flow-control */ |
| 445 | u8 flowcontrol; /* per prio flow control bitmask */ |
| 446 | u8 tx_seq; /* Transmit sequence number (next) */ |
| 447 | u8 tx_max; /* Maximum transmit sequence allowed */ |
| 448 | |
Arend van Spriel | 9b2d2f2 | 2013-11-29 12:25:14 +0100 | [diff] [blame] | 449 | u8 *hdrbuf; /* buffer for handling rx frame */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 450 | u8 *rxhdr; /* Header of current rx frame (in hdrbuf) */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 451 | u8 rx_seq; /* Receive sequence number (expected) */ |
Franky Lin | 6bc5231 | 2013-08-10 12:27:28 +0200 | [diff] [blame] | 452 | struct brcmf_sdio_hdrinfo cur_read; |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 453 | /* info of current read frame */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 454 | bool rxskip; /* Skip receive (awaiting NAK ACK) */ |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 455 | bool rxpending; /* Data frame pending in dongle */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 456 | |
| 457 | uint rxbound; /* Rx frames to read before resched */ |
| 458 | uint txbound; /* Tx frames to send before resched */ |
| 459 | uint txminmax; |
| 460 | |
| 461 | struct sk_buff *glomd; /* Packet containing glomming descriptor */ |
Arend van Spriel | b83db86 | 2011-10-19 12:51:09 +0200 | [diff] [blame] | 462 | struct sk_buff_head glom; /* Packet list for glommed superframe */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 463 | uint glomerr; /* Glom packet read errors */ |
| 464 | |
| 465 | u8 *rxbuf; /* Buffer for receiving control packets */ |
| 466 | uint rxblen; /* Allocated length of rxbuf */ |
| 467 | u8 *rxctl; /* Aligned pointer into rxbuf */ |
Franky Lin | dd43a01 | 2012-11-05 16:22:22 -0800 | [diff] [blame] | 468 | u8 *rxctl_orig; /* pointer for freeing rxctl */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 469 | uint rxlen; /* Length of valid data in buffer */ |
Franky Lin | dd43a01 | 2012-11-05 16:22:22 -0800 | [diff] [blame] | 470 | spinlock_t rxctl_lock; /* protection lock for ctrl frame resources */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 471 | |
| 472 | u8 sdpcm_ver; /* Bus protocol reported by dongle */ |
| 473 | |
| 474 | bool intr; /* Use interrupts */ |
| 475 | bool poll; /* Use polling */ |
Franky Lin | 1d38227 | 2012-09-13 21:11:59 +0200 | [diff] [blame] | 476 | atomic_t ipend; /* Device interrupt is pending */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 477 | uint spurious; /* Count of spurious interrupts */ |
| 478 | uint pollrate; /* Ticks between device polls */ |
| 479 | uint polltick; /* Tick counter */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 480 | |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 481 | #ifdef DEBUG |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 482 | uint console_interval; |
| 483 | struct brcmf_console console; /* Console output polling support */ |
| 484 | uint console_addr; /* Console address from shared struct */ |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 485 | #endif /* DEBUG */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 486 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 487 | uint clkstate; /* State of sd and backplane clock(s) */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 488 | s32 idletime; /* Control for activity timeout */ |
Hante Meuleman | b441ba8 | 2015-03-06 18:40:39 +0100 | [diff] [blame] | 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; |
Hante Meuleman | 4dd8b26 | 2015-01-25 20:31:32 +0100 | [diff] [blame] | 498 | int ctrl_frame_err; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 499 | |
Hante Meuleman | fed7ec4 | 2014-03-15 17:18:18 +0100 | [diff] [blame] | 500 | spinlock_t txq_lock; /* protect bus->txq */ |
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; |
Hante Meuleman | 2c64e16 | 2015-03-18 13:25:22 +0100 | [diff] [blame] | 512 | bool dpc_triggered; |
| 513 | bool dpc_running; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 514 | |
Franky Lin | c8bf348 | 2011-12-16 18:37:08 -0800 | [diff] [blame] | 515 | bool txoff; /* Transmit flow-controlled */ |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 516 | struct brcmf_sdio_count sdcnt; |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 517 | bool sr_enabled; /* SaveRestore enabled */ |
Arend van Spriel | 9982464 | 2015-02-06 18:36:45 +0100 | [diff] [blame] | 518 | bool sleeping; |
Franky Lin | 706478c | 2013-08-10 12:27:29 +0200 | [diff] [blame] | 519 | |
| 520 | u8 tx_hdrlen; /* sdio bus header length for tx packet */ |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 521 | bool txglom; /* host tx glomming enable flag */ |
Arend van Spriel | e217d1c | 2013-11-29 12:25:13 +0100 | [diff] [blame] | 522 | u16 head_align; /* buffer pointer alignment */ |
| 523 | u16 sgentry_align; /* scatter-gather buffer alignment */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 524 | }; |
| 525 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 526 | /* clkstate */ |
| 527 | #define CLK_NONE 0 |
| 528 | #define CLK_SDONLY 1 |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 529 | #define CLK_PENDING 2 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 530 | #define CLK_AVAIL 3 |
| 531 | |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 532 | #ifdef DEBUG |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 533 | static int qcount[NUMPRIO]; |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 534 | #endif /* DEBUG */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 535 | |
Hante Meuleman | 668761a | 2013-04-12 10:55:55 +0200 | [diff] [blame] | 536 | #define DEFAULT_SDIO_DRIVE_STRENGTH 6 /* in milliamps */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 537 | |
| 538 | #define RETRYCHAN(chan) ((chan) == SDPCM_EVENT_CHANNEL) |
| 539 | |
| 540 | /* Retry count for register access failures */ |
| 541 | static const uint retry_limit = 2; |
| 542 | |
| 543 | /* Limit on rounding up frames */ |
| 544 | static const uint max_roundup = 512; |
| 545 | |
| 546 | #define ALIGNMENT 4 |
| 547 | |
Franky Lin | 9d7d6f9 | 2012-10-22 10:36:24 -0700 | [diff] [blame] | 548 | enum brcmf_sdio_frmtype { |
| 549 | BRCMF_SDIO_FT_NORMAL, |
| 550 | BRCMF_SDIO_FT_SUPER, |
| 551 | BRCMF_SDIO_FT_SUB, |
| 552 | }; |
| 553 | |
Arend van Spriel | 65d80d0 | 2014-01-29 15:32:14 +0100 | [diff] [blame] | 554 | #define SDIOD_DRVSTR_KEY(chip, pmu) (((chip) << 16) | (pmu)) |
| 555 | |
| 556 | /* SDIO Pad drive strength to select value mappings */ |
| 557 | struct sdiod_drive_str { |
| 558 | u8 strength; /* Pad Drive Strength in mA */ |
| 559 | u8 sel; /* Chip-specific select value */ |
| 560 | }; |
| 561 | |
| 562 | /* SDIO Drive Strength to sel value table for PMU Rev 11 (1.8V) */ |
| 563 | static const struct sdiod_drive_str sdiod_drvstr_tab1_1v8[] = { |
| 564 | {32, 0x6}, |
| 565 | {26, 0x7}, |
| 566 | {22, 0x4}, |
| 567 | {16, 0x5}, |
| 568 | {12, 0x2}, |
| 569 | {8, 0x3}, |
| 570 | {4, 0x0}, |
| 571 | {0, 0x1} |
| 572 | }; |
| 573 | |
| 574 | /* SDIO Drive Strength to sel value table for PMU Rev 13 (1.8v) */ |
| 575 | static const struct sdiod_drive_str sdiod_drive_strength_tab5_1v8[] = { |
| 576 | {6, 0x7}, |
| 577 | {5, 0x6}, |
| 578 | {4, 0x5}, |
| 579 | {3, 0x4}, |
| 580 | {2, 0x2}, |
| 581 | {1, 0x1}, |
| 582 | {0, 0x0} |
| 583 | }; |
| 584 | |
| 585 | /* SDIO Drive Strength to sel value table for PMU Rev 17 (1.8v) */ |
| 586 | static const struct sdiod_drive_str sdiod_drvstr_tab6_1v8[] = { |
| 587 | {3, 0x3}, |
| 588 | {2, 0x2}, |
| 589 | {1, 0x1}, |
| 590 | {0, 0x0} }; |
| 591 | |
| 592 | /* SDIO Drive Strength to sel value table for 43143 PMU Rev 17 (3.3V) */ |
| 593 | static const struct sdiod_drive_str sdiod_drvstr_tab2_3v3[] = { |
| 594 | {16, 0x7}, |
| 595 | {12, 0x5}, |
| 596 | {8, 0x3}, |
| 597 | {4, 0x1} |
| 598 | }; |
| 599 | |
Hante Meuleman | f2c44fe | 2013-09-25 13:05:45 +0200 | [diff] [blame] | 600 | #define BCM43143_FIRMWARE_NAME "brcm/brcmfmac43143-sdio.bin" |
| 601 | #define BCM43143_NVRAM_NAME "brcm/brcmfmac43143-sdio.txt" |
| 602 | #define BCM43241B0_FIRMWARE_NAME "brcm/brcmfmac43241b0-sdio.bin" |
| 603 | #define BCM43241B0_NVRAM_NAME "brcm/brcmfmac43241b0-sdio.txt" |
| 604 | #define BCM43241B4_FIRMWARE_NAME "brcm/brcmfmac43241b4-sdio.bin" |
| 605 | #define BCM43241B4_NVRAM_NAME "brcm/brcmfmac43241b4-sdio.txt" |
Arend van Spriel | ba5e866 | 2015-04-14 20:10:28 +0200 | [diff] [blame] | 606 | #define BCM43241B5_FIRMWARE_NAME "brcm/brcmfmac43241b5-sdio.bin" |
| 607 | #define BCM43241B5_NVRAM_NAME "brcm/brcmfmac43241b5-sdio.txt" |
Hante Meuleman | f2c44fe | 2013-09-25 13:05:45 +0200 | [diff] [blame] | 608 | #define BCM4329_FIRMWARE_NAME "brcm/brcmfmac4329-sdio.bin" |
| 609 | #define BCM4329_NVRAM_NAME "brcm/brcmfmac4329-sdio.txt" |
| 610 | #define BCM4330_FIRMWARE_NAME "brcm/brcmfmac4330-sdio.bin" |
| 611 | #define BCM4330_NVRAM_NAME "brcm/brcmfmac4330-sdio.txt" |
| 612 | #define BCM4334_FIRMWARE_NAME "brcm/brcmfmac4334-sdio.bin" |
| 613 | #define BCM4334_NVRAM_NAME "brcm/brcmfmac4334-sdio.txt" |
Arend van Spriel | 8b3a38d | 2014-12-23 19:04:23 +0100 | [diff] [blame] | 614 | #define BCM43340_FIRMWARE_NAME "brcm/brcmfmac43340-sdio.bin" |
| 615 | #define BCM43340_NVRAM_NAME "brcm/brcmfmac43340-sdio.txt" |
Hante Meuleman | f2c44fe | 2013-09-25 13:05:45 +0200 | [diff] [blame] | 616 | #define BCM4335_FIRMWARE_NAME "brcm/brcmfmac4335-sdio.bin" |
| 617 | #define BCM4335_NVRAM_NAME "brcm/brcmfmac4335-sdio.txt" |
Arend van Spriel | 11e69c3 | 2014-01-08 10:49:33 +0100 | [diff] [blame] | 618 | #define BCM43362_FIRMWARE_NAME "brcm/brcmfmac43362-sdio.bin" |
| 619 | #define BCM43362_NVRAM_NAME "brcm/brcmfmac43362-sdio.txt" |
Franky Lin | bed89b6 | 2013-11-29 12:25:09 +0100 | [diff] [blame] | 620 | #define BCM4339_FIRMWARE_NAME "brcm/brcmfmac4339-sdio.bin" |
| 621 | #define BCM4339_NVRAM_NAME "brcm/brcmfmac4339-sdio.txt" |
Arend van Spriel | 2591155 | 2015-03-18 13:25:26 +0100 | [diff] [blame] | 622 | #define BCM43430_FIRMWARE_NAME "brcm/brcmfmac43430-sdio.bin" |
| 623 | #define BCM43430_NVRAM_NAME "brcm/brcmfmac43430-sdio.txt" |
Arend van Spriel | 228a717 | 2015-03-18 13:25:27 +0100 | [diff] [blame] | 624 | #define BCM43455_FIRMWARE_NAME "brcm/brcmfmac43455-sdio.bin" |
| 625 | #define BCM43455_NVRAM_NAME "brcm/brcmfmac43455-sdio.txt" |
Franky Lin | a797ca1 | 2014-03-15 17:18:17 +0100 | [diff] [blame] | 626 | #define BCM4354_FIRMWARE_NAME "brcm/brcmfmac4354-sdio.bin" |
| 627 | #define BCM4354_NVRAM_NAME "brcm/brcmfmac4354-sdio.txt" |
Hante Meuleman | f2c44fe | 2013-09-25 13:05:45 +0200 | [diff] [blame] | 628 | |
| 629 | MODULE_FIRMWARE(BCM43143_FIRMWARE_NAME); |
| 630 | MODULE_FIRMWARE(BCM43143_NVRAM_NAME); |
| 631 | MODULE_FIRMWARE(BCM43241B0_FIRMWARE_NAME); |
| 632 | MODULE_FIRMWARE(BCM43241B0_NVRAM_NAME); |
| 633 | MODULE_FIRMWARE(BCM43241B4_FIRMWARE_NAME); |
| 634 | MODULE_FIRMWARE(BCM43241B4_NVRAM_NAME); |
Arend van Spriel | ba5e866 | 2015-04-14 20:10:28 +0200 | [diff] [blame] | 635 | MODULE_FIRMWARE(BCM43241B5_FIRMWARE_NAME); |
| 636 | MODULE_FIRMWARE(BCM43241B5_NVRAM_NAME); |
Hante Meuleman | f2c44fe | 2013-09-25 13:05:45 +0200 | [diff] [blame] | 637 | MODULE_FIRMWARE(BCM4329_FIRMWARE_NAME); |
| 638 | MODULE_FIRMWARE(BCM4329_NVRAM_NAME); |
| 639 | MODULE_FIRMWARE(BCM4330_FIRMWARE_NAME); |
| 640 | MODULE_FIRMWARE(BCM4330_NVRAM_NAME); |
| 641 | MODULE_FIRMWARE(BCM4334_FIRMWARE_NAME); |
| 642 | MODULE_FIRMWARE(BCM4334_NVRAM_NAME); |
Arend van Spriel | 8b3a38d | 2014-12-23 19:04:23 +0100 | [diff] [blame] | 643 | MODULE_FIRMWARE(BCM43340_FIRMWARE_NAME); |
| 644 | MODULE_FIRMWARE(BCM43340_NVRAM_NAME); |
Hante Meuleman | f2c44fe | 2013-09-25 13:05:45 +0200 | [diff] [blame] | 645 | MODULE_FIRMWARE(BCM4335_FIRMWARE_NAME); |
| 646 | MODULE_FIRMWARE(BCM4335_NVRAM_NAME); |
Arend van Spriel | 11e69c3 | 2014-01-08 10:49:33 +0100 | [diff] [blame] | 647 | MODULE_FIRMWARE(BCM43362_FIRMWARE_NAME); |
| 648 | MODULE_FIRMWARE(BCM43362_NVRAM_NAME); |
Franky Lin | bed89b6 | 2013-11-29 12:25:09 +0100 | [diff] [blame] | 649 | MODULE_FIRMWARE(BCM4339_FIRMWARE_NAME); |
| 650 | MODULE_FIRMWARE(BCM4339_NVRAM_NAME); |
Arend van Spriel | 2591155 | 2015-03-18 13:25:26 +0100 | [diff] [blame] | 651 | MODULE_FIRMWARE(BCM43430_FIRMWARE_NAME); |
| 652 | MODULE_FIRMWARE(BCM43430_NVRAM_NAME); |
Arend van Spriel | 228a717 | 2015-03-18 13:25:27 +0100 | [diff] [blame] | 653 | MODULE_FIRMWARE(BCM43455_FIRMWARE_NAME); |
| 654 | MODULE_FIRMWARE(BCM43455_NVRAM_NAME); |
Franky Lin | a797ca1 | 2014-03-15 17:18:17 +0100 | [diff] [blame] | 655 | MODULE_FIRMWARE(BCM4354_FIRMWARE_NAME); |
| 656 | MODULE_FIRMWARE(BCM4354_NVRAM_NAME); |
Hante Meuleman | f2c44fe | 2013-09-25 13:05:45 +0200 | [diff] [blame] | 657 | |
| 658 | struct brcmf_firmware_names { |
| 659 | u32 chipid; |
| 660 | u32 revmsk; |
| 661 | const char *bin; |
| 662 | const char *nv; |
| 663 | }; |
| 664 | |
| 665 | enum brcmf_firmware_type { |
| 666 | BRCMF_FIRMWARE_BIN, |
| 667 | BRCMF_FIRMWARE_NVRAM |
| 668 | }; |
| 669 | |
| 670 | #define BRCMF_FIRMWARE_NVRAM(name) \ |
| 671 | name ## _FIRMWARE_NAME, name ## _NVRAM_NAME |
| 672 | |
| 673 | static const struct brcmf_firmware_names brcmf_fwname_data[] = { |
Hante Meuleman | 5779ae6 | 2014-07-12 08:49:34 +0200 | [diff] [blame] | 674 | { BRCM_CC_43143_CHIP_ID, 0xFFFFFFFF, BRCMF_FIRMWARE_NVRAM(BCM43143) }, |
| 675 | { BRCM_CC_43241_CHIP_ID, 0x0000001F, BRCMF_FIRMWARE_NVRAM(BCM43241B0) }, |
Arend van Spriel | ba5e866 | 2015-04-14 20:10:28 +0200 | [diff] [blame] | 676 | { BRCM_CC_43241_CHIP_ID, 0x00000020, BRCMF_FIRMWARE_NVRAM(BCM43241B4) }, |
| 677 | { BRCM_CC_43241_CHIP_ID, 0xFFFFFFC0, BRCMF_FIRMWARE_NVRAM(BCM43241B5) }, |
Hante Meuleman | 5779ae6 | 2014-07-12 08:49:34 +0200 | [diff] [blame] | 678 | { BRCM_CC_4329_CHIP_ID, 0xFFFFFFFF, BRCMF_FIRMWARE_NVRAM(BCM4329) }, |
| 679 | { BRCM_CC_4330_CHIP_ID, 0xFFFFFFFF, BRCMF_FIRMWARE_NVRAM(BCM4330) }, |
| 680 | { BRCM_CC_4334_CHIP_ID, 0xFFFFFFFF, BRCMF_FIRMWARE_NVRAM(BCM4334) }, |
Arend van Spriel | 8b3a38d | 2014-12-23 19:04:23 +0100 | [diff] [blame] | 681 | { BRCM_CC_43340_CHIP_ID, 0xFFFFFFFF, BRCMF_FIRMWARE_NVRAM(BCM43340) }, |
Hante Meuleman | 5779ae6 | 2014-07-12 08:49:34 +0200 | [diff] [blame] | 682 | { BRCM_CC_4335_CHIP_ID, 0xFFFFFFFF, BRCMF_FIRMWARE_NVRAM(BCM4335) }, |
| 683 | { BRCM_CC_43362_CHIP_ID, 0xFFFFFFFE, BRCMF_FIRMWARE_NVRAM(BCM43362) }, |
| 684 | { BRCM_CC_4339_CHIP_ID, 0xFFFFFFFF, BRCMF_FIRMWARE_NVRAM(BCM4339) }, |
Arend van Spriel | 2591155 | 2015-03-18 13:25:26 +0100 | [diff] [blame] | 685 | { BRCM_CC_43430_CHIP_ID, 0xFFFFFFFF, BRCMF_FIRMWARE_NVRAM(BCM43430) }, |
Arend van Spriel | 228a717 | 2015-03-18 13:25:27 +0100 | [diff] [blame] | 686 | { BRCM_CC_4345_CHIP_ID, 0xFFFFFFC0, BRCMF_FIRMWARE_NVRAM(BCM43455) }, |
Hante Meuleman | 5779ae6 | 2014-07-12 08:49:34 +0200 | [diff] [blame] | 687 | { BRCM_CC_4354_CHIP_ID, 0xFFFFFFFF, BRCMF_FIRMWARE_NVRAM(BCM4354) } |
Hante Meuleman | f2c44fe | 2013-09-25 13:05:45 +0200 | [diff] [blame] | 688 | }; |
| 689 | |
Daniel Kim | c1b2053 | 2014-07-12 08:49:37 +0200 | [diff] [blame] | 690 | static int brcmf_sdio_get_fwnames(struct brcmf_chip *ci, |
| 691 | struct brcmf_sdio_dev *sdiodev) |
Hante Meuleman | f2c44fe | 2013-09-25 13:05:45 +0200 | [diff] [blame] | 692 | { |
Arend van Spriel | bd0e1b1 | 2014-05-27 12:56:22 +0200 | [diff] [blame] | 693 | int i; |
Daniel Kim | 46de068 | 2014-07-30 13:20:00 +0200 | [diff] [blame] | 694 | char end; |
Hante Meuleman | f2c44fe | 2013-09-25 13:05:45 +0200 | [diff] [blame] | 695 | |
| 696 | for (i = 0; i < ARRAY_SIZE(brcmf_fwname_data); i++) { |
Arend van Spriel | bd0e1b1 | 2014-05-27 12:56:22 +0200 | [diff] [blame] | 697 | if (brcmf_fwname_data[i].chipid == ci->chip && |
Daniel Kim | c1b2053 | 2014-07-12 08:49:37 +0200 | [diff] [blame] | 698 | brcmf_fwname_data[i].revmsk & BIT(ci->chiprev)) |
| 699 | break; |
Hante Meuleman | f2c44fe | 2013-09-25 13:05:45 +0200 | [diff] [blame] | 700 | } |
Daniel Kim | c1b2053 | 2014-07-12 08:49:37 +0200 | [diff] [blame] | 701 | |
| 702 | if (i == ARRAY_SIZE(brcmf_fwname_data)) { |
| 703 | brcmf_err("Unknown chipid %d [%d]\n", ci->chip, ci->chiprev); |
| 704 | return -ENODEV; |
| 705 | } |
| 706 | |
| 707 | /* check if firmware path is provided by module parameter */ |
| 708 | if (brcmf_firmware_path[0] != '\0') { |
Rickard Strandqvist | 59dfdd9 | 2014-10-12 13:42:14 +0200 | [diff] [blame] | 709 | strlcpy(sdiodev->fw_name, brcmf_firmware_path, |
| 710 | sizeof(sdiodev->fw_name)); |
| 711 | strlcpy(sdiodev->nvram_name, brcmf_firmware_path, |
| 712 | sizeof(sdiodev->nvram_name)); |
Daniel Kim | c1b2053 | 2014-07-12 08:49:37 +0200 | [diff] [blame] | 713 | |
Daniel Kim | 46de068 | 2014-07-30 13:20:00 +0200 | [diff] [blame] | 714 | end = brcmf_firmware_path[strlen(brcmf_firmware_path) - 1]; |
| 715 | if (end != '/') { |
Rickard Strandqvist | 59dfdd9 | 2014-10-12 13:42:14 +0200 | [diff] [blame] | 716 | strlcat(sdiodev->fw_name, "/", |
| 717 | sizeof(sdiodev->fw_name)); |
| 718 | strlcat(sdiodev->nvram_name, "/", |
| 719 | sizeof(sdiodev->nvram_name)); |
Daniel Kim | 46de068 | 2014-07-30 13:20:00 +0200 | [diff] [blame] | 720 | } |
Daniel Kim | c1b2053 | 2014-07-12 08:49:37 +0200 | [diff] [blame] | 721 | } |
Rickard Strandqvist | 59dfdd9 | 2014-10-12 13:42:14 +0200 | [diff] [blame] | 722 | strlcat(sdiodev->fw_name, brcmf_fwname_data[i].bin, |
| 723 | sizeof(sdiodev->fw_name)); |
| 724 | strlcat(sdiodev->nvram_name, brcmf_fwname_data[i].nv, |
| 725 | sizeof(sdiodev->nvram_name)); |
Daniel Kim | c1b2053 | 2014-07-12 08:49:37 +0200 | [diff] [blame] | 726 | |
| 727 | return 0; |
Hante Meuleman | f2c44fe | 2013-09-25 13:05:45 +0200 | [diff] [blame] | 728 | } |
| 729 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 730 | static void pkt_align(struct sk_buff *p, int len, int align) |
| 731 | { |
| 732 | uint datalign; |
| 733 | datalign = (unsigned long)(p->data); |
| 734 | datalign = roundup(datalign, (align)) - datalign; |
| 735 | if (datalign) |
| 736 | skb_pull(p, datalign); |
| 737 | __skb_trim(p, len); |
| 738 | } |
| 739 | |
| 740 | /* To check if there's window offered */ |
Franky Lin | e92eedf | 2011-11-22 17:21:50 -0800 | [diff] [blame] | 741 | static bool data_ok(struct brcmf_sdio *bus) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 742 | { |
| 743 | return (u8)(bus->tx_max - bus->tx_seq) != 0 && |
| 744 | ((u8)(bus->tx_max - bus->tx_seq) & 0x80) == 0; |
| 745 | } |
| 746 | |
| 747 | /* |
| 748 | * Reads a register in the SDIO hardware block. This block occupies a series of |
| 749 | * adresses on the 32 bit backplane bus. |
| 750 | */ |
Arend van Spriel | cb7cf7b | 2014-01-29 15:32:19 +0100 | [diff] [blame] | 751 | 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] | 752 | { |
Arend van Spriel | cb7cf7b | 2014-01-29 15:32:19 +0100 | [diff] [blame] | 753 | struct brcmf_core *core; |
Franky Lin | 79ae395 | 2012-05-04 18:27:34 -0700 | [diff] [blame] | 754 | int ret; |
Franky Lin | 5869275 | 2012-05-04 18:27:36 -0700 | [diff] [blame] | 755 | |
Arend van Spriel | cb7cf7b | 2014-01-29 15:32:19 +0100 | [diff] [blame] | 756 | core = brcmf_chip_get_core(bus->ci, BCMA_CORE_SDIO_DEV); |
| 757 | *regvar = brcmf_sdiod_regrl(bus->sdiodev, core->base + offset, &ret); |
Franky Lin | 5869275 | 2012-05-04 18:27:36 -0700 | [diff] [blame] | 758 | |
| 759 | return ret; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 760 | } |
| 761 | |
Arend van Spriel | cb7cf7b | 2014-01-29 15:32:19 +0100 | [diff] [blame] | 762 | 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] | 763 | { |
Arend van Spriel | cb7cf7b | 2014-01-29 15:32:19 +0100 | [diff] [blame] | 764 | struct brcmf_core *core; |
Franky Lin | e13ce26 | 2012-05-04 18:27:35 -0700 | [diff] [blame] | 765 | int ret; |
Franky Lin | 5869275 | 2012-05-04 18:27:36 -0700 | [diff] [blame] | 766 | |
Arend van Spriel | cb7cf7b | 2014-01-29 15:32:19 +0100 | [diff] [blame] | 767 | core = brcmf_chip_get_core(bus->ci, BCMA_CORE_SDIO_DEV); |
| 768 | brcmf_sdiod_regwl(bus->sdiodev, core->base + reg_offset, regval, &ret); |
Franky Lin | 5869275 | 2012-05-04 18:27:36 -0700 | [diff] [blame] | 769 | |
| 770 | return ret; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 771 | } |
| 772 | |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 773 | static int |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 774 | brcmf_sdio_kso_control(struct brcmf_sdio *bus, bool on) |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 775 | { |
| 776 | u8 wr_val = 0, rd_val, cmp_val, bmask; |
| 777 | int err = 0; |
| 778 | int try_cnt = 0; |
| 779 | |
Arend van Spriel | 8a385ba | 2014-03-15 17:18:20 +0100 | [diff] [blame] | 780 | brcmf_dbg(TRACE, "Enter: on=%d\n", on); |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 781 | |
| 782 | wr_val = (on << SBSDIO_FUNC1_SLEEPCSR_KSO_SHIFT); |
| 783 | /* 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] | 784 | brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, |
| 785 | wr_val, &err); |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 786 | |
| 787 | if (on) { |
| 788 | /* device WAKEUP through KSO: |
| 789 | * write bit 0 & read back until |
| 790 | * both bits 0 (kso bit) & 1 (dev on status) are set |
| 791 | */ |
| 792 | cmp_val = SBSDIO_FUNC1_SLEEPCSR_KSO_MASK | |
| 793 | SBSDIO_FUNC1_SLEEPCSR_DEVON_MASK; |
| 794 | bmask = cmp_val; |
| 795 | usleep_range(2000, 3000); |
| 796 | } else { |
| 797 | /* Put device to sleep, turn off KSO */ |
| 798 | cmp_val = 0; |
| 799 | /* only check for bit0, bit1(dev on status) may not |
| 800 | * get cleared right away |
| 801 | */ |
| 802 | bmask = SBSDIO_FUNC1_SLEEPCSR_KSO_MASK; |
| 803 | } |
| 804 | |
| 805 | do { |
| 806 | /* reliable KSO bit set/clr: |
| 807 | * the sdiod sleep write access is synced to PMU 32khz clk |
| 808 | * just one write attempt may fail, |
| 809 | * read it back until it matches written value |
| 810 | */ |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 811 | rd_val = brcmf_sdiod_regrb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, |
| 812 | &err); |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 813 | if (((rd_val & bmask) == cmp_val) && !err) |
| 814 | break; |
Arend van Spriel | 8a385ba | 2014-03-15 17:18:20 +0100 | [diff] [blame] | 815 | |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 816 | udelay(KSO_WAIT_US); |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 817 | brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, |
| 818 | wr_val, &err); |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 819 | } while (try_cnt++ < MAX_KSO_ATTEMPTS); |
| 820 | |
Arend van Spriel | 8a385ba | 2014-03-15 17:18:20 +0100 | [diff] [blame] | 821 | if (try_cnt > 2) |
| 822 | brcmf_dbg(SDIO, "try_cnt=%d rd_val=0x%x err=%d\n", try_cnt, |
| 823 | rd_val, err); |
| 824 | |
| 825 | if (try_cnt > MAX_KSO_ATTEMPTS) |
| 826 | brcmf_err("max tries: rd_val=0x%x err=%d\n", rd_val, err); |
| 827 | |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 828 | return err; |
| 829 | } |
| 830 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 831 | #define HOSTINTMASK (I_HMB_SW_MASK | I_CHIPACTIVE) |
| 832 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 833 | /* Turn backplane clock on or off */ |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 834 | 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] | 835 | { |
| 836 | int err; |
| 837 | u8 clkctl, clkreq, devctl; |
| 838 | unsigned long timeout; |
| 839 | |
Arend van Spriel | c320337 | 2013-04-03 12:40:44 +0200 | [diff] [blame] | 840 | brcmf_dbg(SDIO, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 841 | |
| 842 | clkctl = 0; |
| 843 | |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 844 | if (bus->sr_enabled) { |
| 845 | bus->clkstate = (on ? CLK_AVAIL : CLK_SDONLY); |
| 846 | return 0; |
| 847 | } |
| 848 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 849 | if (on) { |
| 850 | /* Request HT Avail */ |
| 851 | clkreq = |
| 852 | bus->alp_only ? SBSDIO_ALP_AVAIL_REQ : SBSDIO_HT_AVAIL_REQ; |
| 853 | |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 854 | brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, |
| 855 | clkreq, &err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 856 | if (err) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 857 | brcmf_err("HT Avail request error: %d\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 858 | return -EBADE; |
| 859 | } |
| 860 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 861 | /* Check current status */ |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 862 | clkctl = brcmf_sdiod_regrb(bus->sdiodev, |
| 863 | SBSDIO_FUNC1_CHIPCLKCSR, &err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 864 | if (err) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 865 | brcmf_err("HT Avail read error: %d\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 866 | return -EBADE; |
| 867 | } |
| 868 | |
| 869 | /* Go to pending and await interrupt if appropriate */ |
| 870 | if (!SBSDIO_CLKAV(clkctl, bus->alp_only) && pendok) { |
| 871 | /* Allow only clock-available interrupt */ |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 872 | devctl = brcmf_sdiod_regrb(bus->sdiodev, |
| 873 | SBSDIO_DEVICE_CTL, &err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 874 | if (err) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 875 | brcmf_err("Devctl error setting CA: %d\n", |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 876 | err); |
| 877 | return -EBADE; |
| 878 | } |
| 879 | |
| 880 | devctl |= SBSDIO_DEVCTL_CA_INT_ONLY; |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 881 | brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_DEVICE_CTL, |
| 882 | devctl, &err); |
Arend van Spriel | c320337 | 2013-04-03 12:40:44 +0200 | [diff] [blame] | 883 | brcmf_dbg(SDIO, "CLKCTL: set PENDING\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 884 | bus->clkstate = CLK_PENDING; |
| 885 | |
| 886 | return 0; |
| 887 | } else if (bus->clkstate == CLK_PENDING) { |
| 888 | /* Cancel CA-only interrupt filter */ |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 889 | devctl = brcmf_sdiod_regrb(bus->sdiodev, |
| 890 | SBSDIO_DEVICE_CTL, &err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 891 | devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY; |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 892 | brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_DEVICE_CTL, |
| 893 | devctl, &err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | /* Otherwise, wait here (polling) for HT Avail */ |
| 897 | timeout = jiffies + |
| 898 | msecs_to_jiffies(PMU_MAX_TRANSITION_DLY/1000); |
| 899 | while (!SBSDIO_CLKAV(clkctl, bus->alp_only)) { |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 900 | clkctl = brcmf_sdiod_regrb(bus->sdiodev, |
| 901 | SBSDIO_FUNC1_CHIPCLKCSR, |
| 902 | &err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 903 | if (time_after(jiffies, timeout)) |
| 904 | break; |
| 905 | else |
| 906 | usleep_range(5000, 10000); |
| 907 | } |
| 908 | if (err) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 909 | brcmf_err("HT Avail request error: %d\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 910 | return -EBADE; |
| 911 | } |
| 912 | if (!SBSDIO_CLKAV(clkctl, bus->alp_only)) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 913 | brcmf_err("HT Avail timeout (%d): clkctl 0x%02x\n", |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 914 | PMU_MAX_TRANSITION_DLY, clkctl); |
| 915 | return -EBADE; |
| 916 | } |
| 917 | |
| 918 | /* Mark clock available */ |
| 919 | bus->clkstate = CLK_AVAIL; |
Arend van Spriel | c320337 | 2013-04-03 12:40:44 +0200 | [diff] [blame] | 920 | brcmf_dbg(SDIO, "CLKCTL: turned ON\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 921 | |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 922 | #if defined(DEBUG) |
Joe Perches | 23677ce | 2012-02-09 11:17:23 +0000 | [diff] [blame] | 923 | if (!bus->alp_only) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 924 | if (SBSDIO_ALPONLY(clkctl)) |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 925 | brcmf_err("HT Clock should be on\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 926 | } |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 927 | #endif /* defined (DEBUG) */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 928 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 929 | } else { |
| 930 | clkreq = 0; |
| 931 | |
| 932 | if (bus->clkstate == CLK_PENDING) { |
| 933 | /* Cancel CA-only interrupt filter */ |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 934 | devctl = brcmf_sdiod_regrb(bus->sdiodev, |
| 935 | SBSDIO_DEVICE_CTL, &err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 936 | devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY; |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 937 | brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_DEVICE_CTL, |
| 938 | devctl, &err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | bus->clkstate = CLK_SDONLY; |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 942 | brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, |
| 943 | clkreq, &err); |
Arend van Spriel | c320337 | 2013-04-03 12:40:44 +0200 | [diff] [blame] | 944 | brcmf_dbg(SDIO, "CLKCTL: turned OFF\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 945 | if (err) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 946 | brcmf_err("Failed access turning clock off: %d\n", |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 947 | err); |
| 948 | return -EBADE; |
| 949 | } |
| 950 | } |
| 951 | return 0; |
| 952 | } |
| 953 | |
| 954 | /* Change idle/active SD state */ |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 955 | static int brcmf_sdio_sdclk(struct brcmf_sdio *bus, bool on) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 956 | { |
Arend van Spriel | c320337 | 2013-04-03 12:40:44 +0200 | [diff] [blame] | 957 | brcmf_dbg(SDIO, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 958 | |
| 959 | if (on) |
| 960 | bus->clkstate = CLK_SDONLY; |
| 961 | else |
| 962 | bus->clkstate = CLK_NONE; |
| 963 | |
| 964 | return 0; |
| 965 | } |
| 966 | |
| 967 | /* Transition SD and backplane clock readiness */ |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 968 | 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] | 969 | { |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 970 | #ifdef DEBUG |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 971 | uint oldstate = bus->clkstate; |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 972 | #endif /* DEBUG */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 973 | |
Arend van Spriel | c320337 | 2013-04-03 12:40:44 +0200 | [diff] [blame] | 974 | brcmf_dbg(SDIO, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 975 | |
| 976 | /* Early exit if we're already there */ |
Hante Meuleman | b441ba8 | 2015-03-06 18:40:39 +0100 | [diff] [blame] | 977 | if (bus->clkstate == target) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 978 | return 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 979 | |
| 980 | switch (target) { |
| 981 | case CLK_AVAIL: |
| 982 | /* Make sure SD clock is available */ |
| 983 | if (bus->clkstate == CLK_NONE) |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 984 | brcmf_sdio_sdclk(bus, true); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 985 | /* Now request HT Avail on the backplane */ |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 986 | brcmf_sdio_htclk(bus, true, pendok); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 987 | break; |
| 988 | |
| 989 | case CLK_SDONLY: |
| 990 | /* Remove HT request, or bring up SD clock */ |
| 991 | if (bus->clkstate == CLK_NONE) |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 992 | brcmf_sdio_sdclk(bus, true); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 993 | else if (bus->clkstate == CLK_AVAIL) |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 994 | brcmf_sdio_htclk(bus, false, false); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 995 | else |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 996 | brcmf_err("request for %d -> %d\n", |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 997 | bus->clkstate, target); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 998 | break; |
| 999 | |
| 1000 | case CLK_NONE: |
| 1001 | /* Make sure to remove HT request */ |
| 1002 | if (bus->clkstate == CLK_AVAIL) |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 1003 | brcmf_sdio_htclk(bus, false, false); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1004 | /* Now remove the SD clock */ |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 1005 | brcmf_sdio_sdclk(bus, false); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1006 | break; |
| 1007 | } |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 1008 | #ifdef DEBUG |
Arend van Spriel | c320337 | 2013-04-03 12:40:44 +0200 | [diff] [blame] | 1009 | brcmf_dbg(SDIO, "%d -> %d\n", oldstate, bus->clkstate); |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 1010 | #endif /* DEBUG */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1011 | |
| 1012 | return 0; |
| 1013 | } |
| 1014 | |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 1015 | static int |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 1016 | brcmf_sdio_bus_sleep(struct brcmf_sdio *bus, bool sleep, bool pendok) |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 1017 | { |
| 1018 | int err = 0; |
Arend van Spriel | 8a385ba | 2014-03-15 17:18:20 +0100 | [diff] [blame] | 1019 | u8 clkcsr; |
Arend van Spriel | 82030d6 | 2014-01-29 15:32:20 +0100 | [diff] [blame] | 1020 | |
| 1021 | brcmf_dbg(SDIO, "Enter: request %s currently %s\n", |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 1022 | (sleep ? "SLEEP" : "WAKE"), |
Arend van Spriel | 9982464 | 2015-02-06 18:36:45 +0100 | [diff] [blame] | 1023 | (bus->sleeping ? "SLEEP" : "WAKE")); |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 1024 | |
| 1025 | /* If SR is enabled control bus state with KSO */ |
| 1026 | if (bus->sr_enabled) { |
| 1027 | /* Done if we're already in the requested state */ |
Arend van Spriel | 9982464 | 2015-02-06 18:36:45 +0100 | [diff] [blame] | 1028 | if (sleep == bus->sleeping) |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 1029 | goto end; |
| 1030 | |
| 1031 | /* Going to sleep */ |
| 1032 | if (sleep) { |
Arend van Spriel | 8a385ba | 2014-03-15 17:18:20 +0100 | [diff] [blame] | 1033 | clkcsr = brcmf_sdiod_regrb(bus->sdiodev, |
| 1034 | SBSDIO_FUNC1_CHIPCLKCSR, |
| 1035 | &err); |
| 1036 | if ((clkcsr & SBSDIO_CSR_MASK) == 0) { |
| 1037 | brcmf_dbg(SDIO, "no clock, set ALP\n"); |
| 1038 | brcmf_sdiod_regwb(bus->sdiodev, |
| 1039 | SBSDIO_FUNC1_CHIPCLKCSR, |
| 1040 | SBSDIO_ALP_AVAIL_REQ, &err); |
| 1041 | } |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 1042 | err = brcmf_sdio_kso_control(bus, false); |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 1043 | } else { |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 1044 | err = brcmf_sdio_kso_control(bus, true); |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 1045 | } |
Arend van Spriel | 8982cd4 | 2015-01-25 20:31:34 +0100 | [diff] [blame] | 1046 | if (err) { |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 1047 | brcmf_err("error while changing bus sleep state %d\n", |
| 1048 | err); |
Arend van Spriel | 8a385ba | 2014-03-15 17:18:20 +0100 | [diff] [blame] | 1049 | goto done; |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 1050 | } |
| 1051 | } |
| 1052 | |
| 1053 | end: |
| 1054 | /* control clocks */ |
| 1055 | if (sleep) { |
| 1056 | if (!bus->sr_enabled) |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 1057 | brcmf_sdio_clkctl(bus, CLK_NONE, pendok); |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 1058 | } else { |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 1059 | brcmf_sdio_clkctl(bus, CLK_AVAIL, pendok); |
Arend van Spriel | cf45932 | 2015-03-11 16:11:33 +0100 | [diff] [blame] | 1060 | brcmf_sdio_wd_timer(bus, BRCMF_WD_POLL_MS); |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 1061 | } |
Arend van Spriel | 9982464 | 2015-02-06 18:36:45 +0100 | [diff] [blame] | 1062 | bus->sleeping = sleep; |
Arend van Spriel | 8982cd4 | 2015-01-25 20:31:34 +0100 | [diff] [blame] | 1063 | brcmf_dbg(SDIO, "new state %s\n", |
| 1064 | (sleep ? "SLEEP" : "WAKE")); |
Arend van Spriel | 8a385ba | 2014-03-15 17:18:20 +0100 | [diff] [blame] | 1065 | done: |
| 1066 | brcmf_dbg(SDIO, "Exit: err=%d\n", err); |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 1067 | return err; |
| 1068 | |
| 1069 | } |
| 1070 | |
Daniel Kim | 0801e6c | 2014-01-29 15:32:13 +0100 | [diff] [blame] | 1071 | #ifdef DEBUG |
| 1072 | static inline bool brcmf_sdio_valid_shared_address(u32 addr) |
| 1073 | { |
| 1074 | return !(addr == 0 || ((~addr >> 16) & 0xffff) == (addr & 0xffff)); |
| 1075 | } |
| 1076 | |
| 1077 | static int brcmf_sdio_readshared(struct brcmf_sdio *bus, |
| 1078 | struct sdpcm_shared *sh) |
| 1079 | { |
Arend van Spriel | 9819a90 | 2015-03-11 16:11:32 +0100 | [diff] [blame] | 1080 | u32 addr = 0; |
Daniel Kim | 0801e6c | 2014-01-29 15:32:13 +0100 | [diff] [blame] | 1081 | int rv; |
| 1082 | u32 shaddr = 0; |
| 1083 | struct sdpcm_shared_le sh_le; |
| 1084 | __le32 addr_le; |
| 1085 | |
Arend van Spriel | 9819a90 | 2015-03-11 16:11:32 +0100 | [diff] [blame] | 1086 | sdio_claim_host(bus->sdiodev->func[1]); |
| 1087 | brcmf_sdio_bus_sleep(bus, false, false); |
Daniel Kim | 0801e6c | 2014-01-29 15:32:13 +0100 | [diff] [blame] | 1088 | |
| 1089 | /* |
| 1090 | * Read last word in socram to determine |
| 1091 | * address of sdpcm_shared structure |
| 1092 | */ |
Arend van Spriel | 9819a90 | 2015-03-11 16:11:32 +0100 | [diff] [blame] | 1093 | shaddr = bus->ci->rambase + bus->ci->ramsize - 4; |
| 1094 | if (!bus->ci->rambase && brcmf_chip_sr_capable(bus->ci)) |
| 1095 | shaddr -= bus->ci->srsize; |
| 1096 | rv = brcmf_sdiod_ramrw(bus->sdiodev, false, shaddr, |
| 1097 | (u8 *)&addr_le, 4); |
Daniel Kim | 0801e6c | 2014-01-29 15:32:13 +0100 | [diff] [blame] | 1098 | if (rv < 0) |
Arend van Spriel | 9819a90 | 2015-03-11 16:11:32 +0100 | [diff] [blame] | 1099 | goto fail; |
Daniel Kim | 0801e6c | 2014-01-29 15:32:13 +0100 | [diff] [blame] | 1100 | |
| 1101 | /* |
| 1102 | * Check if addr is valid. |
| 1103 | * NVRAM length at the end of memory should have been overwritten. |
| 1104 | */ |
Arend van Spriel | 9819a90 | 2015-03-11 16:11:32 +0100 | [diff] [blame] | 1105 | addr = le32_to_cpu(addr_le); |
Daniel Kim | 0801e6c | 2014-01-29 15:32:13 +0100 | [diff] [blame] | 1106 | if (!brcmf_sdio_valid_shared_address(addr)) { |
Arend van Spriel | 9819a90 | 2015-03-11 16:11:32 +0100 | [diff] [blame] | 1107 | brcmf_err("invalid sdpcm_shared address 0x%08X\n", addr); |
| 1108 | rv = -EINVAL; |
| 1109 | goto fail; |
Daniel Kim | 0801e6c | 2014-01-29 15:32:13 +0100 | [diff] [blame] | 1110 | } |
| 1111 | |
Arend van Spriel | 9819a90 | 2015-03-11 16:11:32 +0100 | [diff] [blame] | 1112 | brcmf_dbg(INFO, "sdpcm_shared address 0x%08X\n", addr); |
| 1113 | |
Daniel Kim | 0801e6c | 2014-01-29 15:32:13 +0100 | [diff] [blame] | 1114 | /* Read hndrte_shared structure */ |
| 1115 | rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, (u8 *)&sh_le, |
| 1116 | sizeof(struct sdpcm_shared_le)); |
| 1117 | if (rv < 0) |
Arend van Spriel | 9819a90 | 2015-03-11 16:11:32 +0100 | [diff] [blame] | 1118 | goto fail; |
| 1119 | |
| 1120 | sdio_release_host(bus->sdiodev->func[1]); |
Daniel Kim | 0801e6c | 2014-01-29 15:32:13 +0100 | [diff] [blame] | 1121 | |
| 1122 | /* Endianness */ |
| 1123 | sh->flags = le32_to_cpu(sh_le.flags); |
| 1124 | sh->trap_addr = le32_to_cpu(sh_le.trap_addr); |
| 1125 | sh->assert_exp_addr = le32_to_cpu(sh_le.assert_exp_addr); |
| 1126 | sh->assert_file_addr = le32_to_cpu(sh_le.assert_file_addr); |
| 1127 | sh->assert_line = le32_to_cpu(sh_le.assert_line); |
| 1128 | sh->console_addr = le32_to_cpu(sh_le.console_addr); |
| 1129 | sh->msgtrace_addr = le32_to_cpu(sh_le.msgtrace_addr); |
| 1130 | |
| 1131 | if ((sh->flags & SDPCM_SHARED_VERSION_MASK) > SDPCM_SHARED_VERSION) { |
| 1132 | brcmf_err("sdpcm shared version unsupported: dhd %d dongle %d\n", |
| 1133 | SDPCM_SHARED_VERSION, |
| 1134 | sh->flags & SDPCM_SHARED_VERSION_MASK); |
| 1135 | return -EPROTO; |
| 1136 | } |
Daniel Kim | 0801e6c | 2014-01-29 15:32:13 +0100 | [diff] [blame] | 1137 | return 0; |
Arend van Spriel | 9819a90 | 2015-03-11 16:11:32 +0100 | [diff] [blame] | 1138 | |
| 1139 | fail: |
| 1140 | brcmf_err("unable to obtain sdpcm_shared info: rv=%d (addr=0x%x)\n", |
| 1141 | rv, addr); |
| 1142 | sdio_release_host(bus->sdiodev->func[1]); |
| 1143 | return rv; |
Daniel Kim | 0801e6c | 2014-01-29 15:32:13 +0100 | [diff] [blame] | 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 | 9b2d2f2 | 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 | 9b2d2f2 | 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 | 9b2d2f2 | 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 | 9b2d2f2 | 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 | a1ce7a0 | 2015-02-06 18:36:42 +0100 | [diff] [blame] | 1912 | !bus->rxskip && rxleft && bus->sdiodev->state == BRCMF_SDIOD_DATA; |
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 | 9b2d2f2 | 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 | 9b2d2f2 | 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; |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 2379 | if (bus->txglom) |
| 2380 | pkt_num = min_t(u8, bus->tx_max - bus->tx_seq, |
Arend van Spriel | af1fa21 | 2014-02-27 19:25:00 +0100 | [diff] [blame] | 2381 | bus->sdiodev->txglomsz); |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 2382 | pkt_num = min_t(u32, pkt_num, |
| 2383 | brcmu_pktq_mlen(&bus->txq, ~bus->flowcontrol)); |
Hante Meuleman | fed7ec4 | 2014-03-15 17:18:18 +0100 | [diff] [blame] | 2384 | __skb_queue_head_init(&pktq); |
| 2385 | spin_lock_bh(&bus->txq_lock); |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 2386 | for (i = 0; i < pkt_num; i++) { |
| 2387 | pkt = brcmu_pktq_mdeq(&bus->txq, tx_prec_map, |
| 2388 | &prec_out); |
| 2389 | if (pkt == NULL) |
| 2390 | break; |
| 2391 | __skb_queue_tail(&pktq, pkt); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2392 | } |
Hante Meuleman | fed7ec4 | 2014-03-15 17:18:18 +0100 | [diff] [blame] | 2393 | spin_unlock_bh(&bus->txq_lock); |
Hante Meuleman | 4dd8b26 | 2015-01-25 20:31:32 +0100 | [diff] [blame] | 2394 | if (i == 0) |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 2395 | break; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2396 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 2397 | ret = brcmf_sdio_txpkt(bus, &pktq, SDPCM_DATA_CHANNEL); |
Hante Meuleman | fed7ec4 | 2014-03-15 17:18:18 +0100 | [diff] [blame] | 2398 | |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 2399 | cnt += i; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2400 | |
| 2401 | /* In poll mode, need to check for other events */ |
Hante Meuleman | b6a8cf2 | 2014-02-25 20:30:33 +0100 | [diff] [blame] | 2402 | if (!bus->intr) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2403 | /* Check device status, signal pending interrupt */ |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 2404 | sdio_claim_host(bus->sdiodev->func[1]); |
Franky Lin | 5c15c23 | 2012-05-04 18:27:37 -0700 | [diff] [blame] | 2405 | ret = r_sdreg32(bus, &intstatus, |
| 2406 | offsetof(struct sdpcmd_regs, |
| 2407 | intstatus)); |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 2408 | sdio_release_host(bus->sdiodev->func[1]); |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 2409 | bus->sdcnt.f2txdata++; |
Franky Lin | 5c15c23 | 2012-05-04 18:27:37 -0700 | [diff] [blame] | 2410 | if (ret != 0) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2411 | break; |
| 2412 | if (intstatus & bus->hostintmask) |
Franky Lin | 1d38227 | 2012-09-13 21:11:59 +0200 | [diff] [blame] | 2413 | atomic_set(&bus->ipend, 1); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2414 | } |
| 2415 | } |
| 2416 | |
| 2417 | /* Deflow-control stack if needed */ |
Arend van Spriel | a1ce7a0 | 2015-02-06 18:36:42 +0100 | [diff] [blame] | 2418 | if ((bus->sdiodev->state == BRCMF_SDIOD_DATA) && |
Franky Lin | c8bf348 | 2011-12-16 18:37:08 -0800 | [diff] [blame] | 2419 | bus->txoff && (pktq_len(&bus->txq) < TXLOW)) { |
Hante Meuleman | 90d03ff | 2012-09-11 21:18:46 +0200 | [diff] [blame] | 2420 | bus->txoff = false; |
| 2421 | brcmf_txflowblock(bus->sdiodev->dev, false); |
Franky Lin | c8bf348 | 2011-12-16 18:37:08 -0800 | [diff] [blame] | 2422 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2423 | |
| 2424 | return cnt; |
| 2425 | } |
| 2426 | |
Hante Meuleman | fed7ec4 | 2014-03-15 17:18:18 +0100 | [diff] [blame] | 2427 | static int brcmf_sdio_tx_ctrlframe(struct brcmf_sdio *bus, u8 *frame, u16 len) |
| 2428 | { |
| 2429 | u8 doff; |
| 2430 | u16 pad; |
| 2431 | uint retries = 0; |
| 2432 | struct brcmf_sdio_hdrinfo hd_info = {0}; |
| 2433 | int ret; |
| 2434 | |
| 2435 | brcmf_dbg(TRACE, "Enter\n"); |
| 2436 | |
| 2437 | /* Back the pointer to make room for bus header */ |
| 2438 | frame -= bus->tx_hdrlen; |
| 2439 | len += bus->tx_hdrlen; |
| 2440 | |
| 2441 | /* Add alignment padding (optional for ctl frames) */ |
| 2442 | doff = ((unsigned long)frame % bus->head_align); |
| 2443 | if (doff) { |
| 2444 | frame -= doff; |
| 2445 | len += doff; |
| 2446 | memset(frame + bus->tx_hdrlen, 0, doff); |
| 2447 | } |
| 2448 | |
| 2449 | /* Round send length to next SDIO block */ |
| 2450 | pad = 0; |
| 2451 | if (bus->roundup && bus->blocksize && (len > bus->blocksize)) { |
| 2452 | pad = bus->blocksize - (len % bus->blocksize); |
| 2453 | if ((pad > bus->roundup) || (pad >= bus->blocksize)) |
| 2454 | pad = 0; |
| 2455 | } else if (len % bus->head_align) { |
| 2456 | pad = bus->head_align - (len % bus->head_align); |
| 2457 | } |
| 2458 | len += pad; |
| 2459 | |
| 2460 | hd_info.len = len - pad; |
| 2461 | hd_info.channel = SDPCM_CONTROL_CHANNEL; |
| 2462 | hd_info.dat_offset = doff + bus->tx_hdrlen; |
| 2463 | hd_info.seq_num = bus->tx_seq; |
| 2464 | hd_info.lastfrm = true; |
| 2465 | hd_info.tail_pad = pad; |
| 2466 | brcmf_sdio_hdpack(bus, frame, &hd_info); |
| 2467 | |
| 2468 | if (bus->txglom) |
| 2469 | brcmf_sdio_update_hwhdr(frame, len); |
| 2470 | |
| 2471 | brcmf_dbg_hex_dump(BRCMF_BYTES_ON() && BRCMF_CTL_ON(), |
| 2472 | frame, len, "Tx Frame:\n"); |
| 2473 | brcmf_dbg_hex_dump(!(BRCMF_BYTES_ON() && BRCMF_CTL_ON()) && |
| 2474 | BRCMF_HDRS_ON(), |
| 2475 | frame, min_t(u16, len, 16), "TxHdr:\n"); |
| 2476 | |
| 2477 | do { |
| 2478 | ret = brcmf_sdiod_send_buf(bus->sdiodev, frame, len); |
| 2479 | |
| 2480 | if (ret < 0) |
| 2481 | brcmf_sdio_txfail(bus); |
| 2482 | else |
| 2483 | bus->tx_seq = (bus->tx_seq + 1) % SDPCM_SEQ_WRAP; |
| 2484 | } while (ret < 0 && retries++ < TXRETRIES); |
| 2485 | |
| 2486 | return ret; |
| 2487 | } |
| 2488 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 2489 | static void brcmf_sdio_bus_stop(struct device *dev) |
Franky Lin | a9ffda8 | 2011-12-16 18:37:12 -0800 | [diff] [blame] | 2490 | { |
| 2491 | u32 local_hostintmask; |
| 2492 | u8 saveclk; |
Franky Lin | a9ffda8 | 2011-12-16 18:37:12 -0800 | [diff] [blame] | 2493 | int err; |
| 2494 | struct brcmf_bus *bus_if = dev_get_drvdata(dev); |
Arend van Spriel | 0a332e4 | 2012-02-09 21:09:02 +0100 | [diff] [blame] | 2495 | struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio; |
Franky Lin | a9ffda8 | 2011-12-16 18:37:12 -0800 | [diff] [blame] | 2496 | struct brcmf_sdio *bus = sdiodev->bus; |
| 2497 | |
| 2498 | brcmf_dbg(TRACE, "Enter\n"); |
| 2499 | |
| 2500 | if (bus->watchdog_tsk) { |
| 2501 | send_sig(SIGTERM, bus->watchdog_tsk, 1); |
| 2502 | kthread_stop(bus->watchdog_tsk); |
| 2503 | bus->watchdog_tsk = NULL; |
| 2504 | } |
| 2505 | |
Arend van Spriel | a1ce7a0 | 2015-02-06 18:36:42 +0100 | [diff] [blame] | 2506 | if (sdiodev->state != BRCMF_SDIOD_NOMEDIUM) { |
Arend van Spriel | bb35071 | 2014-01-13 22:20:29 +0100 | [diff] [blame] | 2507 | sdio_claim_host(sdiodev->func[1]); |
Franky Lin | a9ffda8 | 2011-12-16 18:37:12 -0800 | [diff] [blame] | 2508 | |
Arend van Spriel | bb35071 | 2014-01-13 22:20:29 +0100 | [diff] [blame] | 2509 | /* Enable clock for device interrupts */ |
| 2510 | brcmf_sdio_bus_sleep(bus, false, false); |
Franky Lin | a9ffda8 | 2011-12-16 18:37:12 -0800 | [diff] [blame] | 2511 | |
Arend van Spriel | bb35071 | 2014-01-13 22:20:29 +0100 | [diff] [blame] | 2512 | /* Disable and clear interrupts at the chip level also */ |
| 2513 | w_sdreg32(bus, 0, offsetof(struct sdpcmd_regs, hostintmask)); |
| 2514 | local_hostintmask = bus->hostintmask; |
| 2515 | bus->hostintmask = 0; |
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 | /* Force backplane clocks to assure F2 interrupt propagates */ |
| 2518 | saveclk = brcmf_sdiod_regrb(sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, |
| 2519 | &err); |
| 2520 | if (!err) |
| 2521 | brcmf_sdiod_regwb(sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, |
| 2522 | (saveclk | SBSDIO_FORCE_HT), &err); |
| 2523 | if (err) |
| 2524 | brcmf_err("Failed to force clock for F2: err %d\n", |
| 2525 | err); |
Franky Lin | a9ffda8 | 2011-12-16 18:37:12 -0800 | [diff] [blame] | 2526 | |
Arend van Spriel | bb35071 | 2014-01-13 22:20:29 +0100 | [diff] [blame] | 2527 | /* Turn off the bus (F2), free any pending packets */ |
| 2528 | brcmf_dbg(INTR, "disable SDIO interrupts\n"); |
| 2529 | sdio_disable_func(sdiodev->func[SDIO_FUNC_2]); |
| 2530 | |
| 2531 | /* Clear any pending interrupts now that F2 is disabled */ |
| 2532 | w_sdreg32(bus, local_hostintmask, |
| 2533 | offsetof(struct sdpcmd_regs, intstatus)); |
| 2534 | |
| 2535 | sdio_release_host(sdiodev->func[1]); |
Franky Lin | a9ffda8 | 2011-12-16 18:37:12 -0800 | [diff] [blame] | 2536 | } |
Franky Lin | a9ffda8 | 2011-12-16 18:37:12 -0800 | [diff] [blame] | 2537 | /* Clear the data packet queues */ |
| 2538 | brcmu_pktq_flush(&bus->txq, true, NULL, NULL); |
| 2539 | |
| 2540 | /* Clear any held glomming stuff */ |
Markus Elfring | 297540f | 2015-02-04 20:28:49 +0100 | [diff] [blame] | 2541 | brcmu_pkt_buf_free_skb(bus->glomd); |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 2542 | brcmf_sdio_free_glom(bus); |
Franky Lin | a9ffda8 | 2011-12-16 18:37:12 -0800 | [diff] [blame] | 2543 | |
| 2544 | /* Clear rx control and wake any waiters */ |
Franky Lin | dd43a01 | 2012-11-05 16:22:22 -0800 | [diff] [blame] | 2545 | spin_lock_bh(&bus->rxctl_lock); |
Franky Lin | a9ffda8 | 2011-12-16 18:37:12 -0800 | [diff] [blame] | 2546 | bus->rxlen = 0; |
Franky Lin | dd43a01 | 2012-11-05 16:22:22 -0800 | [diff] [blame] | 2547 | spin_unlock_bh(&bus->rxctl_lock); |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 2548 | brcmf_sdio_dcmd_resp_wake(bus); |
Franky Lin | a9ffda8 | 2011-12-16 18:37:12 -0800 | [diff] [blame] | 2549 | |
| 2550 | /* Reset some F2 state stuff */ |
| 2551 | bus->rxskip = false; |
| 2552 | bus->tx_seq = bus->rx_seq = 0; |
Franky Lin | a9ffda8 | 2011-12-16 18:37:12 -0800 | [diff] [blame] | 2553 | } |
| 2554 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 2555 | static inline void brcmf_sdio_clrintr(struct brcmf_sdio *bus) |
Franky Lin | ba89bf1 | 2012-04-27 18:56:59 -0700 | [diff] [blame] | 2556 | { |
| 2557 | unsigned long flags; |
| 2558 | |
Hante Meuleman | 668761a | 2013-04-12 10:55:55 +0200 | [diff] [blame] | 2559 | if (bus->sdiodev->oob_irq_requested) { |
| 2560 | spin_lock_irqsave(&bus->sdiodev->irq_en_lock, flags); |
| 2561 | if (!bus->sdiodev->irq_en && !atomic_read(&bus->ipend)) { |
| 2562 | enable_irq(bus->sdiodev->pdata->oob_irq_nr); |
| 2563 | bus->sdiodev->irq_en = true; |
| 2564 | } |
| 2565 | spin_unlock_irqrestore(&bus->sdiodev->irq_en_lock, flags); |
Franky Lin | ba89bf1 | 2012-04-27 18:56:59 -0700 | [diff] [blame] | 2566 | } |
Franky Lin | ba89bf1 | 2012-04-27 18:56:59 -0700 | [diff] [blame] | 2567 | } |
Franky Lin | ba89bf1 | 2012-04-27 18:56:59 -0700 | [diff] [blame] | 2568 | |
Franky Lin | 4531603 | 2012-09-13 21:12:03 +0200 | [diff] [blame] | 2569 | static int brcmf_sdio_intr_rstatus(struct brcmf_sdio *bus) |
| 2570 | { |
Arend van Spriel | cb7cf7b | 2014-01-29 15:32:19 +0100 | [diff] [blame] | 2571 | struct brcmf_core *buscore; |
Franky Lin | 4531603 | 2012-09-13 21:12:03 +0200 | [diff] [blame] | 2572 | u32 addr; |
| 2573 | unsigned long val; |
Hante Meuleman | 5cbb9c2 | 2014-03-06 10:16:12 +0100 | [diff] [blame] | 2574 | int ret; |
Franky Lin | 4531603 | 2012-09-13 21:12:03 +0200 | [diff] [blame] | 2575 | |
Arend van Spriel | cb7cf7b | 2014-01-29 15:32:19 +0100 | [diff] [blame] | 2576 | buscore = brcmf_chip_get_core(bus->ci, BCMA_CORE_SDIO_DEV); |
| 2577 | addr = buscore->base + offsetof(struct sdpcmd_regs, intstatus); |
Franky Lin | 4531603 | 2012-09-13 21:12:03 +0200 | [diff] [blame] | 2578 | |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 2579 | val = brcmf_sdiod_regrl(bus->sdiodev, addr, &ret); |
Franky Lin | 4531603 | 2012-09-13 21:12:03 +0200 | [diff] [blame] | 2580 | bus->sdcnt.f1regdata++; |
| 2581 | if (ret != 0) |
Hante Meuleman | 5cbb9c2 | 2014-03-06 10:16:12 +0100 | [diff] [blame] | 2582 | return ret; |
Franky Lin | 4531603 | 2012-09-13 21:12:03 +0200 | [diff] [blame] | 2583 | |
| 2584 | val &= bus->hostintmask; |
| 2585 | atomic_set(&bus->fcstate, !!(val & I_HMB_FC_STATE)); |
| 2586 | |
| 2587 | /* Clear interrupts */ |
| 2588 | if (val) { |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 2589 | brcmf_sdiod_regwl(bus->sdiodev, addr, val, &ret); |
Franky Lin | 4531603 | 2012-09-13 21:12:03 +0200 | [diff] [blame] | 2590 | bus->sdcnt.f1regdata++; |
Vineet Gupta | d3928d0 | 2015-07-09 13:43:18 +0530 | [diff] [blame] | 2591 | atomic_or(val, &bus->intstatus); |
Franky Lin | 4531603 | 2012-09-13 21:12:03 +0200 | [diff] [blame] | 2592 | } |
| 2593 | |
| 2594 | return ret; |
| 2595 | } |
| 2596 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 2597 | static void brcmf_sdio_dpc(struct brcmf_sdio *bus) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2598 | { |
Franky Lin | 4531603 | 2012-09-13 21:12:03 +0200 | [diff] [blame] | 2599 | u32 newstatus = 0; |
| 2600 | unsigned long intstatus; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2601 | uint txlimit = bus->txbound; /* Tx frames to send before resched */ |
Hante Meuleman | b6a8cf2 | 2014-02-25 20:30:33 +0100 | [diff] [blame] | 2602 | uint framecnt; /* Temporary counter of tx/rx frames */ |
Hante Meuleman | 5cbb9c2 | 2014-03-06 10:16:12 +0100 | [diff] [blame] | 2603 | int err = 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2604 | |
| 2605 | brcmf_dbg(TRACE, "Enter\n"); |
| 2606 | |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 2607 | sdio_claim_host(bus->sdiodev->func[1]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2608 | |
| 2609 | /* If waiting for HTAVAIL, check status */ |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 2610 | if (!bus->sr_enabled && bus->clkstate == CLK_PENDING) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2611 | u8 clkctl, devctl = 0; |
| 2612 | |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 2613 | #ifdef DEBUG |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2614 | /* Check for inconsistent device control */ |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 2615 | devctl = brcmf_sdiod_regrb(bus->sdiodev, |
| 2616 | SBSDIO_DEVICE_CTL, &err); |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 2617 | #endif /* DEBUG */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2618 | |
| 2619 | /* Read CSR, if clock on switch to AVAIL, else ignore */ |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 2620 | clkctl = brcmf_sdiod_regrb(bus->sdiodev, |
| 2621 | SBSDIO_FUNC1_CHIPCLKCSR, &err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2622 | |
Arend van Spriel | c320337 | 2013-04-03 12:40:44 +0200 | [diff] [blame] | 2623 | 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] | 2624 | devctl, clkctl); |
| 2625 | |
| 2626 | if (SBSDIO_HTAV(clkctl)) { |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 2627 | devctl = brcmf_sdiod_regrb(bus->sdiodev, |
| 2628 | SBSDIO_DEVICE_CTL, &err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2629 | devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY; |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 2630 | brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_DEVICE_CTL, |
| 2631 | devctl, &err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2632 | bus->clkstate = CLK_AVAIL; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2633 | } |
| 2634 | } |
| 2635 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2636 | /* Make sure backplane clock is on */ |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 2637 | brcmf_sdio_bus_sleep(bus, false, true); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2638 | |
| 2639 | /* Pending interrupt indicates new device status */ |
Franky Lin | 1d38227 | 2012-09-13 21:11:59 +0200 | [diff] [blame] | 2640 | if (atomic_read(&bus->ipend) > 0) { |
| 2641 | atomic_set(&bus->ipend, 0); |
Franky Lin | 4531603 | 2012-09-13 21:12:03 +0200 | [diff] [blame] | 2642 | err = brcmf_sdio_intr_rstatus(bus); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2643 | } |
| 2644 | |
Franky Lin | 4531603 | 2012-09-13 21:12:03 +0200 | [diff] [blame] | 2645 | /* Start with leftover status bits */ |
| 2646 | intstatus = atomic_xchg(&bus->intstatus, 0); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2647 | |
| 2648 | /* Handle flow-control change: read new state in case our ack |
| 2649 | * crossed another change interrupt. If change still set, assume |
| 2650 | * FC ON for safety, let next loop through do the debounce. |
| 2651 | */ |
| 2652 | if (intstatus & I_HMB_FC_CHANGE) { |
| 2653 | intstatus &= ~I_HMB_FC_CHANGE; |
Franky Lin | 5c15c23 | 2012-05-04 18:27:37 -0700 | [diff] [blame] | 2654 | err = w_sdreg32(bus, I_HMB_FC_CHANGE, |
| 2655 | offsetof(struct sdpcmd_regs, intstatus)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2656 | |
Franky Lin | 5c15c23 | 2012-05-04 18:27:37 -0700 | [diff] [blame] | 2657 | err = r_sdreg32(bus, &newstatus, |
| 2658 | offsetof(struct sdpcmd_regs, intstatus)); |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 2659 | bus->sdcnt.f1regdata += 2; |
Franky Lin | 4531603 | 2012-09-13 21:12:03 +0200 | [diff] [blame] | 2660 | atomic_set(&bus->fcstate, |
| 2661 | !!(newstatus & (I_HMB_FC_STATE | I_HMB_FC_CHANGE))); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2662 | intstatus |= (newstatus & bus->hostintmask); |
| 2663 | } |
| 2664 | |
| 2665 | /* Handle host mailbox indication */ |
| 2666 | if (intstatus & I_HMB_HOST_INT) { |
| 2667 | intstatus &= ~I_HMB_HOST_INT; |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 2668 | intstatus |= brcmf_sdio_hostmail(bus); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2669 | } |
| 2670 | |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 2671 | sdio_release_host(bus->sdiodev->func[1]); |
Franky Lin | 7cdf57d | 2012-11-05 16:22:23 -0800 | [diff] [blame] | 2672 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2673 | /* Generally don't ask for these, can get CRC errors... */ |
| 2674 | if (intstatus & I_WR_OOSYNC) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 2675 | brcmf_err("Dongle reports WR_OOSYNC\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2676 | intstatus &= ~I_WR_OOSYNC; |
| 2677 | } |
| 2678 | |
| 2679 | if (intstatus & I_RD_OOSYNC) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 2680 | brcmf_err("Dongle reports RD_OOSYNC\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2681 | intstatus &= ~I_RD_OOSYNC; |
| 2682 | } |
| 2683 | |
| 2684 | if (intstatus & I_SBINT) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 2685 | brcmf_err("Dongle reports SBINT\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2686 | intstatus &= ~I_SBINT; |
| 2687 | } |
| 2688 | |
| 2689 | /* Would be active due to wake-wlan in gSPI */ |
| 2690 | if (intstatus & I_CHIPACTIVE) { |
| 2691 | brcmf_dbg(INFO, "Dongle reports CHIPACTIVE\n"); |
| 2692 | intstatus &= ~I_CHIPACTIVE; |
| 2693 | } |
| 2694 | |
| 2695 | /* Ignore frame indications if rxskip is set */ |
| 2696 | if (bus->rxskip) |
| 2697 | intstatus &= ~I_HMB_FRAME_IND; |
| 2698 | |
| 2699 | /* On frame indication, read available frames */ |
Hante Meuleman | b6a8cf2 | 2014-02-25 20:30:33 +0100 | [diff] [blame] | 2700 | if ((intstatus & I_HMB_FRAME_IND) && (bus->clkstate == CLK_AVAIL)) { |
| 2701 | brcmf_sdio_readframes(bus, bus->rxbound); |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 2702 | if (!bus->rxpending) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2703 | intstatus &= ~I_HMB_FRAME_IND; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2704 | } |
| 2705 | |
| 2706 | /* Keep still-pending events for next scheduling */ |
Hante Meuleman | 5cbb9c2 | 2014-03-06 10:16:12 +0100 | [diff] [blame] | 2707 | if (intstatus) |
Vineet Gupta | d3928d0 | 2015-07-09 13:43:18 +0530 | [diff] [blame] | 2708 | atomic_or(intstatus, &bus->intstatus); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2709 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 2710 | brcmf_sdio_clrintr(bus); |
Franky Lin | ba89bf1 | 2012-04-27 18:56:59 -0700 | [diff] [blame] | 2711 | |
Hante Meuleman | fed7ec4 | 2014-03-15 17:18:18 +0100 | [diff] [blame] | 2712 | if (bus->ctrl_frame_stat && (bus->clkstate == CLK_AVAIL) && |
Hante Meuleman | 4dd8b26 | 2015-01-25 20:31:32 +0100 | [diff] [blame] | 2713 | data_ok(bus)) { |
| 2714 | sdio_claim_host(bus->sdiodev->func[1]); |
Hante Meuleman | 449e58b | 2015-03-06 18:40:40 +0100 | [diff] [blame] | 2715 | if (bus->ctrl_frame_stat) { |
| 2716 | err = brcmf_sdio_tx_ctrlframe(bus, bus->ctrl_frame_buf, |
| 2717 | bus->ctrl_frame_len); |
| 2718 | bus->ctrl_frame_err = err; |
Hante Meuleman | 2c64e16 | 2015-03-18 13:25:22 +0100 | [diff] [blame] | 2719 | wmb(); |
Hante Meuleman | 449e58b | 2015-03-06 18:40:40 +0100 | [diff] [blame] | 2720 | bus->ctrl_frame_stat = false; |
| 2721 | } |
Hante Meuleman | 4dd8b26 | 2015-01-25 20:31:32 +0100 | [diff] [blame] | 2722 | sdio_release_host(bus->sdiodev->func[1]); |
Hante Meuleman | 4dd8b26 | 2015-01-25 20:31:32 +0100 | [diff] [blame] | 2723 | brcmf_sdio_wait_event_wakeup(bus); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2724 | } |
| 2725 | /* Send queued frames (limit 1 if rx may still be pending) */ |
Hante Meuleman | fed7ec4 | 2014-03-15 17:18:18 +0100 | [diff] [blame] | 2726 | if ((bus->clkstate == CLK_AVAIL) && !atomic_read(&bus->fcstate) && |
| 2727 | brcmu_pktq_mlen(&bus->txq, ~bus->flowcontrol) && txlimit && |
| 2728 | data_ok(bus)) { |
Franky Lin | 4754fce | 2012-09-19 22:21:11 +0200 | [diff] [blame] | 2729 | framecnt = bus->rxpending ? min(txlimit, bus->txminmax) : |
| 2730 | txlimit; |
Hante Meuleman | b6a8cf2 | 2014-02-25 20:30:33 +0100 | [diff] [blame] | 2731 | brcmf_sdio_sendfromq(bus, framecnt); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2732 | } |
| 2733 | |
Arend van Spriel | a1ce7a0 | 2015-02-06 18:36:42 +0100 | [diff] [blame] | 2734 | if ((bus->sdiodev->state != BRCMF_SDIOD_DATA) || (err != 0)) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 2735 | brcmf_err("failed backplane access over SDIO, halting operation\n"); |
Franky Lin | 4531603 | 2012-09-13 21:12:03 +0200 | [diff] [blame] | 2736 | atomic_set(&bus->intstatus, 0); |
Hante Meuleman | de6878c | 2015-03-06 18:40:38 +0100 | [diff] [blame] | 2737 | if (bus->ctrl_frame_stat) { |
Hante Meuleman | 449e58b | 2015-03-06 18:40:40 +0100 | [diff] [blame] | 2738 | sdio_claim_host(bus->sdiodev->func[1]); |
| 2739 | if (bus->ctrl_frame_stat) { |
| 2740 | bus->ctrl_frame_err = -ENODEV; |
Hante Meuleman | 2c64e16 | 2015-03-18 13:25:22 +0100 | [diff] [blame] | 2741 | wmb(); |
Hante Meuleman | 449e58b | 2015-03-06 18:40:40 +0100 | [diff] [blame] | 2742 | bus->ctrl_frame_stat = false; |
| 2743 | brcmf_sdio_wait_event_wakeup(bus); |
| 2744 | } |
| 2745 | sdio_release_host(bus->sdiodev->func[1]); |
Hante Meuleman | de6878c | 2015-03-06 18:40:38 +0100 | [diff] [blame] | 2746 | } |
Franky Lin | 4531603 | 2012-09-13 21:12:03 +0200 | [diff] [blame] | 2747 | } else if (atomic_read(&bus->intstatus) || |
| 2748 | atomic_read(&bus->ipend) > 0 || |
| 2749 | (!atomic_read(&bus->fcstate) && |
| 2750 | brcmu_pktq_mlen(&bus->txq, ~bus->flowcontrol) && |
Hante Meuleman | b6a8cf2 | 2014-02-25 20:30:33 +0100 | [diff] [blame] | 2751 | data_ok(bus))) { |
Hante Meuleman | 2c64e16 | 2015-03-18 13:25:22 +0100 | [diff] [blame] | 2752 | bus->dpc_triggered = true; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2753 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2754 | } |
| 2755 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 2756 | static struct pktq *brcmf_sdio_bus_gettxq(struct device *dev) |
Arend van Spriel | e2432b6 | 2013-04-03 12:40:38 +0200 | [diff] [blame] | 2757 | { |
| 2758 | struct brcmf_bus *bus_if = dev_get_drvdata(dev); |
| 2759 | struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio; |
| 2760 | struct brcmf_sdio *bus = sdiodev->bus; |
| 2761 | |
| 2762 | return &bus->txq; |
| 2763 | } |
| 2764 | |
Hante Meuleman | 8493662 | 2014-10-28 14:56:19 +0100 | [diff] [blame] | 2765 | static bool brcmf_sdio_prec_enq(struct pktq *q, struct sk_buff *pkt, int prec) |
| 2766 | { |
| 2767 | struct sk_buff *p; |
| 2768 | int eprec = -1; /* precedence to evict from */ |
| 2769 | |
| 2770 | /* Fast case, precedence queue is not full and we are also not |
| 2771 | * exceeding total queue length |
| 2772 | */ |
| 2773 | if (!pktq_pfull(q, prec) && !pktq_full(q)) { |
| 2774 | brcmu_pktq_penq(q, prec, pkt); |
| 2775 | return true; |
| 2776 | } |
| 2777 | |
| 2778 | /* Determine precedence from which to evict packet, if any */ |
| 2779 | if (pktq_pfull(q, prec)) { |
| 2780 | eprec = prec; |
| 2781 | } else if (pktq_full(q)) { |
| 2782 | p = brcmu_pktq_peek_tail(q, &eprec); |
| 2783 | if (eprec > prec) |
| 2784 | return false; |
| 2785 | } |
| 2786 | |
| 2787 | /* Evict if needed */ |
| 2788 | if (eprec >= 0) { |
| 2789 | /* Detect queueing to unconfigured precedence */ |
| 2790 | if (eprec == prec) |
| 2791 | return false; /* refuse newer (incoming) packet */ |
| 2792 | /* Evict packet according to discard policy */ |
| 2793 | p = brcmu_pktq_pdeq_tail(q, eprec); |
| 2794 | if (p == NULL) |
| 2795 | brcmf_err("brcmu_pktq_pdeq_tail() failed\n"); |
| 2796 | brcmu_pkt_buf_free_skb(p); |
| 2797 | } |
| 2798 | |
| 2799 | /* Enqueue */ |
| 2800 | p = brcmu_pktq_penq(q, prec, pkt); |
| 2801 | if (p == NULL) |
| 2802 | brcmf_err("brcmu_pktq_penq() failed\n"); |
| 2803 | |
| 2804 | return p != NULL; |
| 2805 | } |
| 2806 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 2807 | 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] | 2808 | { |
| 2809 | int ret = -EBADE; |
Arend van Spriel | 44ff566 | 2014-02-25 20:30:28 +0100 | [diff] [blame] | 2810 | uint prec; |
Franky Lin | bf347bb | 2011-11-22 17:21:56 -0800 | [diff] [blame] | 2811 | struct brcmf_bus *bus_if = dev_get_drvdata(dev); |
Arend van Spriel | 0a332e4 | 2012-02-09 21:09:02 +0100 | [diff] [blame] | 2812 | struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio; |
Franky Lin | bf347bb | 2011-11-22 17:21:56 -0800 | [diff] [blame] | 2813 | struct brcmf_sdio *bus = sdiodev->bus; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2814 | |
Arend van Spriel | 44ff566 | 2014-02-25 20:30:28 +0100 | [diff] [blame] | 2815 | brcmf_dbg(TRACE, "Enter: pkt: data %p len %d\n", pkt->data, pkt->len); |
Arend van Spriel | 5768f31 | 2015-06-11 00:12:20 +0200 | [diff] [blame] | 2816 | if (sdiodev->state != BRCMF_SDIOD_DATA) |
| 2817 | return -EIO; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2818 | |
| 2819 | /* Add space for the header */ |
Franky Lin | 706478c | 2013-08-10 12:27:29 +0200 | [diff] [blame] | 2820 | skb_push(pkt, bus->tx_hdrlen); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2821 | /* precondition: IS_ALIGNED((unsigned long)(pkt->data), 2) */ |
| 2822 | |
| 2823 | prec = prio2prec((pkt->priority & PRIOMASK)); |
| 2824 | |
| 2825 | /* Check for existing queue, current flow-control, |
| 2826 | pending event, or pending clock */ |
| 2827 | 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] | 2828 | bus->sdcnt.fcqueued++; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2829 | |
| 2830 | /* Priority based enq */ |
Hante Meuleman | fed7ec4 | 2014-03-15 17:18:18 +0100 | [diff] [blame] | 2831 | spin_lock_bh(&bus->txq_lock); |
Arend van Spriel | 5aa9f0e | 2014-02-25 20:30:27 +0100 | [diff] [blame] | 2832 | /* reset bus_flags in packet cb */ |
| 2833 | *(u16 *)(pkt->cb) = 0; |
Hante Meuleman | 8493662 | 2014-10-28 14:56:19 +0100 | [diff] [blame] | 2834 | if (!brcmf_sdio_prec_enq(&bus->txq, pkt, prec)) { |
Franky Lin | 706478c | 2013-08-10 12:27:29 +0200 | [diff] [blame] | 2835 | skb_pull(pkt, bus->tx_hdrlen); |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 2836 | brcmf_err("out of bus->txq !!!\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2837 | ret = -ENOSR; |
| 2838 | } else { |
| 2839 | ret = 0; |
| 2840 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2841 | |
Franky Lin | c8bf348 | 2011-12-16 18:37:08 -0800 | [diff] [blame] | 2842 | if (pktq_len(&bus->txq) >= TXHI) { |
Hante Meuleman | 90d03ff | 2012-09-11 21:18:46 +0200 | [diff] [blame] | 2843 | bus->txoff = true; |
Hante Meuleman | 8493662 | 2014-10-28 14:56:19 +0100 | [diff] [blame] | 2844 | brcmf_txflowblock(dev, true); |
Franky Lin | c8bf348 | 2011-12-16 18:37:08 -0800 | [diff] [blame] | 2845 | } |
Hante Meuleman | fed7ec4 | 2014-03-15 17:18:18 +0100 | [diff] [blame] | 2846 | spin_unlock_bh(&bus->txq_lock); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2847 | |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 2848 | #ifdef DEBUG |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2849 | if (pktq_plen(&bus->txq, prec) > qcount[prec]) |
| 2850 | qcount[prec] = pktq_plen(&bus->txq, prec); |
| 2851 | #endif |
Franky Lin | f1e68c2 | 2012-09-13 21:12:00 +0200 | [diff] [blame] | 2852 | |
Arend van Spriel | 9982464 | 2015-02-06 18:36:45 +0100 | [diff] [blame] | 2853 | brcmf_sdio_trigger_dpc(bus); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2854 | return ret; |
| 2855 | } |
| 2856 | |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 2857 | #ifdef DEBUG |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2858 | #define CONSOLE_LINE_MAX 192 |
| 2859 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 2860 | static int brcmf_sdio_readconsole(struct brcmf_sdio *bus) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2861 | { |
| 2862 | struct brcmf_console *c = &bus->console; |
| 2863 | u8 line[CONSOLE_LINE_MAX], ch; |
| 2864 | u32 n, idx, addr; |
| 2865 | int rv; |
| 2866 | |
| 2867 | /* Don't do anything until FWREADY updates console address */ |
| 2868 | if (bus->console_addr == 0) |
| 2869 | return 0; |
| 2870 | |
| 2871 | /* Read console log struct */ |
| 2872 | addr = bus->console_addr + offsetof(struct rte_console, log_le); |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 2873 | rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, (u8 *)&c->log_le, |
| 2874 | sizeof(c->log_le)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2875 | if (rv < 0) |
| 2876 | return rv; |
| 2877 | |
| 2878 | /* Allocate console buffer (one time only) */ |
| 2879 | if (c->buf == NULL) { |
| 2880 | c->bufsize = le32_to_cpu(c->log_le.buf_size); |
| 2881 | c->buf = kmalloc(c->bufsize, GFP_ATOMIC); |
| 2882 | if (c->buf == NULL) |
| 2883 | return -ENOMEM; |
| 2884 | } |
| 2885 | |
| 2886 | idx = le32_to_cpu(c->log_le.idx); |
| 2887 | |
| 2888 | /* Protect against corrupt value */ |
| 2889 | if (idx > c->bufsize) |
| 2890 | return -EBADE; |
| 2891 | |
| 2892 | /* Skip reading the console buffer if the index pointer |
| 2893 | has not moved */ |
| 2894 | if (idx == c->last) |
| 2895 | return 0; |
| 2896 | |
| 2897 | /* Read the console buffer */ |
| 2898 | addr = le32_to_cpu(c->log_le.buf); |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 2899 | 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] | 2900 | if (rv < 0) |
| 2901 | return rv; |
| 2902 | |
| 2903 | while (c->last != idx) { |
| 2904 | for (n = 0; n < CONSOLE_LINE_MAX - 2; n++) { |
| 2905 | if (c->last == idx) { |
| 2906 | /* This would output a partial line. |
| 2907 | * Instead, back up |
| 2908 | * the buffer pointer and output this |
| 2909 | * line next time around. |
| 2910 | */ |
| 2911 | if (c->last >= n) |
| 2912 | c->last -= n; |
| 2913 | else |
| 2914 | c->last = c->bufsize - n; |
| 2915 | goto break2; |
| 2916 | } |
| 2917 | ch = c->buf[c->last]; |
| 2918 | c->last = (c->last + 1) % c->bufsize; |
| 2919 | if (ch == '\n') |
| 2920 | break; |
| 2921 | line[n] = ch; |
| 2922 | } |
| 2923 | |
| 2924 | if (n > 0) { |
| 2925 | if (line[n - 1] == '\r') |
| 2926 | n--; |
| 2927 | line[n] = 0; |
Joe Perches | 18aad4f | 2012-01-15 00:38:42 -0800 | [diff] [blame] | 2928 | pr_debug("CONSOLE: %s\n", line); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2929 | } |
| 2930 | } |
| 2931 | break2: |
| 2932 | |
| 2933 | return 0; |
| 2934 | } |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 2935 | #endif /* DEBUG */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2936 | |
Franky Lin | fcf094f | 2011-12-16 18:37:16 -0800 | [diff] [blame] | 2937 | static int |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 2938 | 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] | 2939 | { |
Franky Lin | 47a1ce7 | 2011-11-22 17:21:55 -0800 | [diff] [blame] | 2940 | struct brcmf_bus *bus_if = dev_get_drvdata(dev); |
Arend van Spriel | 0a332e4 | 2012-02-09 21:09:02 +0100 | [diff] [blame] | 2941 | struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio; |
Franky Lin | 47a1ce7 | 2011-11-22 17:21:55 -0800 | [diff] [blame] | 2942 | struct brcmf_sdio *bus = sdiodev->bus; |
Hante Meuleman | 4dd8b26 | 2015-01-25 20:31:32 +0100 | [diff] [blame] | 2943 | int ret; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2944 | |
| 2945 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 5768f31 | 2015-06-11 00:12:20 +0200 | [diff] [blame] | 2946 | if (sdiodev->state != BRCMF_SDIOD_DATA) |
| 2947 | return -EIO; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2948 | |
Hante Meuleman | 4dd8b26 | 2015-01-25 20:31:32 +0100 | [diff] [blame] | 2949 | /* Send from dpc */ |
| 2950 | bus->ctrl_frame_buf = msg; |
| 2951 | bus->ctrl_frame_len = msglen; |
Hante Meuleman | 2c64e16 | 2015-03-18 13:25:22 +0100 | [diff] [blame] | 2952 | wmb(); |
Hante Meuleman | 4dd8b26 | 2015-01-25 20:31:32 +0100 | [diff] [blame] | 2953 | bus->ctrl_frame_stat = true; |
Hante Meuleman | 4dd8b26 | 2015-01-25 20:31:32 +0100 | [diff] [blame] | 2954 | |
Arend van Spriel | 9982464 | 2015-02-06 18:36:45 +0100 | [diff] [blame] | 2955 | brcmf_sdio_trigger_dpc(bus); |
Hante Meuleman | 4dd8b26 | 2015-01-25 20:31:32 +0100 | [diff] [blame] | 2956 | wait_event_interruptible_timeout(bus->ctrl_wait, !bus->ctrl_frame_stat, |
| 2957 | msecs_to_jiffies(CTL_DONE_TIMEOUT)); |
Hante Meuleman | 449e58b | 2015-03-06 18:40:40 +0100 | [diff] [blame] | 2958 | ret = 0; |
| 2959 | if (bus->ctrl_frame_stat) { |
| 2960 | sdio_claim_host(bus->sdiodev->func[1]); |
| 2961 | if (bus->ctrl_frame_stat) { |
| 2962 | brcmf_dbg(SDIO, "ctrl_frame timeout\n"); |
| 2963 | bus->ctrl_frame_stat = false; |
| 2964 | ret = -ETIMEDOUT; |
| 2965 | } |
| 2966 | sdio_release_host(bus->sdiodev->func[1]); |
| 2967 | } |
| 2968 | if (!ret) { |
Hante Meuleman | 4dd8b26 | 2015-01-25 20:31:32 +0100 | [diff] [blame] | 2969 | brcmf_dbg(SDIO, "ctrl_frame complete, err=%d\n", |
| 2970 | bus->ctrl_frame_err); |
Hante Meuleman | 2c64e16 | 2015-03-18 13:25:22 +0100 | [diff] [blame] | 2971 | rmb(); |
Hante Meuleman | 4dd8b26 | 2015-01-25 20:31:32 +0100 | [diff] [blame] | 2972 | ret = bus->ctrl_frame_err; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2973 | } |
| 2974 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2975 | if (ret) |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 2976 | bus->sdcnt.tx_ctlerrs++; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2977 | else |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 2978 | bus->sdcnt.tx_ctlpkts++; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2979 | |
Hante Meuleman | 4dd8b26 | 2015-01-25 20:31:32 +0100 | [diff] [blame] | 2980 | return ret; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2981 | } |
| 2982 | |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 2983 | #ifdef DEBUG |
Arend van Spriel | 1b1e4e9 | 2014-07-12 08:49:35 +0200 | [diff] [blame] | 2984 | static int brcmf_sdio_dump_console(struct seq_file *seq, struct brcmf_sdio *bus, |
| 2985 | struct sdpcm_shared *sh) |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 2986 | { |
| 2987 | u32 addr, console_ptr, console_size, console_index; |
| 2988 | char *conbuf = NULL; |
| 2989 | __le32 sh_val; |
| 2990 | int rv; |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 2991 | |
| 2992 | /* obtain console information from device memory */ |
| 2993 | addr = sh->console_addr + offsetof(struct rte_console, log_le); |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 2994 | rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, |
| 2995 | (u8 *)&sh_val, sizeof(u32)); |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 2996 | if (rv < 0) |
| 2997 | return rv; |
| 2998 | console_ptr = le32_to_cpu(sh_val); |
| 2999 | |
| 3000 | 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] | 3001 | rv = brcmf_sdiod_ramrw(bus->sdiodev, false, addr, |
| 3002 | (u8 *)&sh_val, sizeof(u32)); |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3003 | if (rv < 0) |
| 3004 | return rv; |
| 3005 | console_size = le32_to_cpu(sh_val); |
| 3006 | |
| 3007 | addr = sh->console_addr + offsetof(struct rte_console, log_le.idx); |
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_index = le32_to_cpu(sh_val); |
| 3013 | |
| 3014 | /* allocate buffer for console data */ |
| 3015 | if (console_size <= CONSOLE_BUFFER_MAX) |
| 3016 | conbuf = vzalloc(console_size+1); |
| 3017 | |
| 3018 | if (!conbuf) |
| 3019 | return -ENOMEM; |
| 3020 | |
| 3021 | /* obtain the console data from device */ |
| 3022 | conbuf[console_size] = '\0'; |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 3023 | rv = brcmf_sdiod_ramrw(bus->sdiodev, false, console_ptr, (u8 *)conbuf, |
| 3024 | console_size); |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3025 | if (rv < 0) |
| 3026 | goto done; |
| 3027 | |
Arend van Spriel | 1b1e4e9 | 2014-07-12 08:49:35 +0200 | [diff] [blame] | 3028 | rv = seq_write(seq, conbuf + console_index, |
| 3029 | console_size - console_index); |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3030 | if (rv < 0) |
| 3031 | goto done; |
| 3032 | |
Arend van Spriel | 1b1e4e9 | 2014-07-12 08:49:35 +0200 | [diff] [blame] | 3033 | if (console_index > 0) |
| 3034 | rv = seq_write(seq, conbuf, console_index - 1); |
| 3035 | |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3036 | done: |
| 3037 | vfree(conbuf); |
| 3038 | return rv; |
| 3039 | } |
| 3040 | |
Arend van Spriel | 1b1e4e9 | 2014-07-12 08:49:35 +0200 | [diff] [blame] | 3041 | static int brcmf_sdio_trap_info(struct seq_file *seq, struct brcmf_sdio *bus, |
| 3042 | struct sdpcm_shared *sh) |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3043 | { |
Arend van Spriel | 1b1e4e9 | 2014-07-12 08:49:35 +0200 | [diff] [blame] | 3044 | int error; |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3045 | struct brcmf_trap_info tr; |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3046 | |
Piotr Haber | baa9e60 | 2013-04-05 10:57:42 +0200 | [diff] [blame] | 3047 | if ((sh->flags & SDPCM_SHARED_TRAP) == 0) { |
| 3048 | brcmf_dbg(INFO, "no trap in firmware\n"); |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3049 | return 0; |
Piotr Haber | baa9e60 | 2013-04-05 10:57:42 +0200 | [diff] [blame] | 3050 | } |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3051 | |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 3052 | error = brcmf_sdiod_ramrw(bus->sdiodev, false, sh->trap_addr, (u8 *)&tr, |
| 3053 | sizeof(struct brcmf_trap_info)); |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3054 | if (error < 0) |
| 3055 | return error; |
| 3056 | |
Arend van Spriel | 1b1e4e9 | 2014-07-12 08:49:35 +0200 | [diff] [blame] | 3057 | seq_printf(seq, |
| 3058 | "dongle trap info: type 0x%x @ epc 0x%08x\n" |
| 3059 | " cpsr 0x%08x spsr 0x%08x sp 0x%08x\n" |
| 3060 | " lr 0x%08x pc 0x%08x offset 0x%x\n" |
| 3061 | " r0 0x%08x r1 0x%08x r2 0x%08x r3 0x%08x\n" |
| 3062 | " r4 0x%08x r5 0x%08x r6 0x%08x r7 0x%08x\n", |
| 3063 | le32_to_cpu(tr.type), le32_to_cpu(tr.epc), |
| 3064 | le32_to_cpu(tr.cpsr), le32_to_cpu(tr.spsr), |
| 3065 | le32_to_cpu(tr.r13), le32_to_cpu(tr.r14), |
| 3066 | le32_to_cpu(tr.pc), sh->trap_addr, |
| 3067 | le32_to_cpu(tr.r0), le32_to_cpu(tr.r1), |
| 3068 | le32_to_cpu(tr.r2), le32_to_cpu(tr.r3), |
| 3069 | le32_to_cpu(tr.r4), le32_to_cpu(tr.r5), |
| 3070 | le32_to_cpu(tr.r6), le32_to_cpu(tr.r7)); |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3071 | |
Arend van Spriel | 1b1e4e9 | 2014-07-12 08:49:35 +0200 | [diff] [blame] | 3072 | return 0; |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3073 | } |
| 3074 | |
Arend van Spriel | 1b1e4e9 | 2014-07-12 08:49:35 +0200 | [diff] [blame] | 3075 | static int brcmf_sdio_assert_info(struct seq_file *seq, struct brcmf_sdio *bus, |
| 3076 | struct sdpcm_shared *sh) |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3077 | { |
| 3078 | int error = 0; |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3079 | char file[80] = "?"; |
| 3080 | char expr[80] = "<???>"; |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3081 | |
| 3082 | if ((sh->flags & SDPCM_SHARED_ASSERT_BUILT) == 0) { |
| 3083 | brcmf_dbg(INFO, "firmware not built with -assert\n"); |
| 3084 | return 0; |
| 3085 | } else if ((sh->flags & SDPCM_SHARED_ASSERT) == 0) { |
| 3086 | brcmf_dbg(INFO, "no assert in dongle\n"); |
| 3087 | return 0; |
| 3088 | } |
| 3089 | |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 3090 | sdio_claim_host(bus->sdiodev->func[1]); |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3091 | if (sh->assert_file_addr != 0) { |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 3092 | error = brcmf_sdiod_ramrw(bus->sdiodev, false, |
| 3093 | sh->assert_file_addr, (u8 *)file, 80); |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3094 | if (error < 0) |
| 3095 | return error; |
| 3096 | } |
| 3097 | if (sh->assert_exp_addr != 0) { |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 3098 | error = brcmf_sdiod_ramrw(bus->sdiodev, false, |
| 3099 | sh->assert_exp_addr, (u8 *)expr, 80); |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3100 | if (error < 0) |
| 3101 | return error; |
| 3102 | } |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 3103 | sdio_release_host(bus->sdiodev->func[1]); |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3104 | |
Arend van Spriel | 1b1e4e9 | 2014-07-12 08:49:35 +0200 | [diff] [blame] | 3105 | seq_printf(seq, "dongle assert: %s:%d: assert(%s)\n", |
| 3106 | file, sh->assert_line, expr); |
| 3107 | return 0; |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3108 | } |
| 3109 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3110 | static int brcmf_sdio_checkdied(struct brcmf_sdio *bus) |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3111 | { |
| 3112 | int error; |
| 3113 | struct sdpcm_shared sh; |
| 3114 | |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3115 | error = brcmf_sdio_readshared(bus, &sh); |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3116 | |
| 3117 | if (error < 0) |
| 3118 | return error; |
| 3119 | |
| 3120 | if ((sh.flags & SDPCM_SHARED_ASSERT_BUILT) == 0) |
| 3121 | brcmf_dbg(INFO, "firmware not built with -assert\n"); |
| 3122 | else if (sh.flags & SDPCM_SHARED_ASSERT) |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 3123 | brcmf_err("assertion in dongle\n"); |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3124 | |
| 3125 | if (sh.flags & SDPCM_SHARED_TRAP) |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 3126 | brcmf_err("firmware trap in dongle\n"); |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3127 | |
| 3128 | return 0; |
| 3129 | } |
| 3130 | |
Arend van Spriel | 1b1e4e9 | 2014-07-12 08:49:35 +0200 | [diff] [blame] | 3131 | 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] | 3132 | { |
| 3133 | int error = 0; |
| 3134 | struct sdpcm_shared sh; |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3135 | |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3136 | error = brcmf_sdio_readshared(bus, &sh); |
| 3137 | if (error < 0) |
| 3138 | goto done; |
| 3139 | |
Arend van Spriel | 1b1e4e9 | 2014-07-12 08:49:35 +0200 | [diff] [blame] | 3140 | error = brcmf_sdio_assert_info(seq, bus, &sh); |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3141 | if (error < 0) |
| 3142 | goto done; |
Piotr Haber | baa9e60 | 2013-04-05 10:57:42 +0200 | [diff] [blame] | 3143 | |
Arend van Spriel | 1b1e4e9 | 2014-07-12 08:49:35 +0200 | [diff] [blame] | 3144 | error = brcmf_sdio_trap_info(seq, bus, &sh); |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3145 | if (error < 0) |
| 3146 | goto done; |
| 3147 | |
Arend van Spriel | 1b1e4e9 | 2014-07-12 08:49:35 +0200 | [diff] [blame] | 3148 | error = brcmf_sdio_dump_console(seq, bus, &sh); |
Piotr Haber | baa9e60 | 2013-04-05 10:57:42 +0200 | [diff] [blame] | 3149 | |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3150 | done: |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3151 | return error; |
| 3152 | } |
| 3153 | |
Arend van Spriel | 1b1e4e9 | 2014-07-12 08:49:35 +0200 | [diff] [blame] | 3154 | 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] | 3155 | { |
Arend van Spriel | 82d957e | 2014-07-12 08:49:36 +0200 | [diff] [blame] | 3156 | struct brcmf_bus *bus_if = dev_get_drvdata(seq->private); |
| 3157 | struct brcmf_sdio *bus = bus_if->bus_priv.sdio->bus; |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3158 | |
Arend van Spriel | 1b1e4e9 | 2014-07-12 08:49:35 +0200 | [diff] [blame] | 3159 | return brcmf_sdio_died_dump(seq, bus); |
| 3160 | } |
| 3161 | |
Arend van Spriel | 82d957e | 2014-07-12 08:49:36 +0200 | [diff] [blame] | 3162 | 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] | 3163 | { |
Arend van Spriel | 82d957e | 2014-07-12 08:49:36 +0200 | [diff] [blame] | 3164 | struct brcmf_bus *bus_if = dev_get_drvdata(seq->private); |
| 3165 | struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio; |
| 3166 | struct brcmf_sdio_count *sdcnt = &sdiodev->bus->sdcnt; |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3167 | |
Arend van Spriel | 82d957e | 2014-07-12 08:49:36 +0200 | [diff] [blame] | 3168 | seq_printf(seq, |
| 3169 | "intrcount: %u\nlastintrs: %u\n" |
| 3170 | "pollcnt: %u\nregfails: %u\n" |
| 3171 | "tx_sderrs: %u\nfcqueued: %u\n" |
| 3172 | "rxrtx: %u\nrx_toolong: %u\n" |
| 3173 | "rxc_errors: %u\nrx_hdrfail: %u\n" |
| 3174 | "rx_badhdr: %u\nrx_badseq: %u\n" |
| 3175 | "fc_rcvd: %u\nfc_xoff: %u\n" |
| 3176 | "fc_xon: %u\nrxglomfail: %u\n" |
| 3177 | "rxglomframes: %u\nrxglompkts: %u\n" |
| 3178 | "f2rxhdrs: %u\nf2rxdata: %u\n" |
| 3179 | "f2txdata: %u\nf1regdata: %u\n" |
| 3180 | "tickcnt: %u\ntx_ctlerrs: %lu\n" |
| 3181 | "tx_ctlpkts: %lu\nrx_ctlerrs: %lu\n" |
| 3182 | "rx_ctlpkts: %lu\nrx_readahead: %lu\n", |
| 3183 | sdcnt->intrcount, sdcnt->lastintrs, |
| 3184 | sdcnt->pollcnt, sdcnt->regfails, |
| 3185 | sdcnt->tx_sderrs, sdcnt->fcqueued, |
| 3186 | sdcnt->rxrtx, sdcnt->rx_toolong, |
| 3187 | sdcnt->rxc_errors, sdcnt->rx_hdrfail, |
| 3188 | sdcnt->rx_badhdr, sdcnt->rx_badseq, |
| 3189 | sdcnt->fc_rcvd, sdcnt->fc_xoff, |
| 3190 | sdcnt->fc_xon, sdcnt->rxglomfail, |
| 3191 | sdcnt->rxglomframes, sdcnt->rxglompkts, |
| 3192 | sdcnt->f2rxhdrs, sdcnt->f2rxdata, |
| 3193 | sdcnt->f2txdata, sdcnt->f1regdata, |
| 3194 | sdcnt->tickcnt, sdcnt->tx_ctlerrs, |
| 3195 | sdcnt->tx_ctlpkts, sdcnt->rx_ctlerrs, |
| 3196 | sdcnt->rx_ctlpkts, sdcnt->rx_readahead_cnt); |
| 3197 | |
| 3198 | return 0; |
| 3199 | } |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3200 | |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 3201 | static void brcmf_sdio_debugfs_create(struct brcmf_sdio *bus) |
| 3202 | { |
| 3203 | struct brcmf_pub *drvr = bus->sdiodev->bus_if->drvr; |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3204 | struct dentry *dentry = brcmf_debugfs_get_devdir(drvr); |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 3205 | |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3206 | if (IS_ERR_OR_NULL(dentry)) |
| 3207 | return; |
| 3208 | |
Arend van Spriel | 9d6c1dc | 2015-08-26 22:15:01 +0200 | [diff] [blame] | 3209 | bus->console_interval = BRCMF_CONSOLE; |
| 3210 | |
Arend van Spriel | 82d957e | 2014-07-12 08:49:36 +0200 | [diff] [blame] | 3211 | brcmf_debugfs_add_entry(drvr, "forensics", brcmf_sdio_forensic_read); |
| 3212 | brcmf_debugfs_add_entry(drvr, "counters", |
| 3213 | brcmf_debugfs_sdio_count_read); |
Daniel Kim | 0801e6c | 2014-01-29 15:32:13 +0100 | [diff] [blame] | 3214 | debugfs_create_u32("console_interval", 0644, dentry, |
| 3215 | &bus->console_interval); |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 3216 | } |
| 3217 | #else |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3218 | static int brcmf_sdio_checkdied(struct brcmf_sdio *bus) |
Arend van Spriel | 4fc0d01 | 2012-06-14 12:16:57 +0200 | [diff] [blame] | 3219 | { |
| 3220 | return 0; |
| 3221 | } |
| 3222 | |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 3223 | static void brcmf_sdio_debugfs_create(struct brcmf_sdio *bus) |
| 3224 | { |
| 3225 | } |
| 3226 | #endif /* DEBUG */ |
| 3227 | |
Franky Lin | fcf094f | 2011-12-16 18:37:16 -0800 | [diff] [blame] | 3228 | static int |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3229 | 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] | 3230 | { |
| 3231 | int timeleft; |
| 3232 | uint rxlen = 0; |
| 3233 | bool pending; |
Franky Lin | dd43a01 | 2012-11-05 16:22:22 -0800 | [diff] [blame] | 3234 | u8 *buf; |
Franky Lin | 532cdd3 | 2011-11-22 17:21:54 -0800 | [diff] [blame] | 3235 | struct brcmf_bus *bus_if = dev_get_drvdata(dev); |
Arend van Spriel | 0a332e4 | 2012-02-09 21:09:02 +0100 | [diff] [blame] | 3236 | struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio; |
Franky Lin | 532cdd3 | 2011-11-22 17:21:54 -0800 | [diff] [blame] | 3237 | struct brcmf_sdio *bus = sdiodev->bus; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3238 | |
| 3239 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 5768f31 | 2015-06-11 00:12:20 +0200 | [diff] [blame] | 3240 | if (sdiodev->state != BRCMF_SDIOD_DATA) |
| 3241 | return -EIO; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3242 | |
| 3243 | /* Wait until control frame is available */ |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3244 | timeleft = brcmf_sdio_dcmd_resp_wait(bus, &bus->rxlen, &pending); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3245 | |
Franky Lin | dd43a01 | 2012-11-05 16:22:22 -0800 | [diff] [blame] | 3246 | spin_lock_bh(&bus->rxctl_lock); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3247 | rxlen = bus->rxlen; |
| 3248 | memcpy(msg, bus->rxctl, min(msglen, rxlen)); |
Franky Lin | dd43a01 | 2012-11-05 16:22:22 -0800 | [diff] [blame] | 3249 | bus->rxctl = NULL; |
| 3250 | buf = bus->rxctl_orig; |
| 3251 | bus->rxctl_orig = NULL; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3252 | bus->rxlen = 0; |
Franky Lin | dd43a01 | 2012-11-05 16:22:22 -0800 | [diff] [blame] | 3253 | spin_unlock_bh(&bus->rxctl_lock); |
| 3254 | vfree(buf); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3255 | |
| 3256 | if (rxlen) { |
| 3257 | brcmf_dbg(CTL, "resumed on rxctl frame, got %d expected %d\n", |
| 3258 | rxlen, msglen); |
| 3259 | } else if (timeleft == 0) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 3260 | brcmf_err("resumed on timeout\n"); |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3261 | brcmf_sdio_checkdied(bus); |
Joe Perches | 23677ce | 2012-02-09 11:17:23 +0000 | [diff] [blame] | 3262 | } else if (pending) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3263 | brcmf_dbg(CTL, "cancelled\n"); |
| 3264 | return -ERESTARTSYS; |
| 3265 | } else { |
| 3266 | brcmf_dbg(CTL, "resumed for unknown reason?\n"); |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3267 | brcmf_sdio_checkdied(bus); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3268 | } |
| 3269 | |
| 3270 | if (rxlen) |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 3271 | bus->sdcnt.rx_ctlpkts++; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3272 | else |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 3273 | bus->sdcnt.rx_ctlerrs++; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3274 | |
| 3275 | return rxlen ? (int)rxlen : -ETIMEDOUT; |
| 3276 | } |
| 3277 | |
Hante Meuleman | a74d036 | 2014-01-13 22:20:22 +0100 | [diff] [blame] | 3278 | #ifdef DEBUG |
| 3279 | static bool |
| 3280 | brcmf_sdio_verifymemory(struct brcmf_sdio_dev *sdiodev, u32 ram_addr, |
| 3281 | u8 *ram_data, uint ram_sz) |
| 3282 | { |
| 3283 | char *ram_cmp; |
| 3284 | int err; |
| 3285 | bool ret = true; |
| 3286 | int address; |
| 3287 | int offset; |
| 3288 | int len; |
| 3289 | |
| 3290 | /* read back and verify */ |
| 3291 | brcmf_dbg(INFO, "Compare RAM dl & ul at 0x%08x; size=%d\n", ram_addr, |
| 3292 | ram_sz); |
| 3293 | ram_cmp = kmalloc(MEMBLOCK, GFP_KERNEL); |
| 3294 | /* do not proceed while no memory but */ |
| 3295 | if (!ram_cmp) |
| 3296 | return true; |
| 3297 | |
| 3298 | address = ram_addr; |
| 3299 | offset = 0; |
| 3300 | while (offset < ram_sz) { |
| 3301 | len = ((offset + MEMBLOCK) < ram_sz) ? MEMBLOCK : |
| 3302 | ram_sz - offset; |
| 3303 | err = brcmf_sdiod_ramrw(sdiodev, false, address, ram_cmp, len); |
| 3304 | if (err) { |
| 3305 | brcmf_err("error %d on reading %d membytes at 0x%08x\n", |
| 3306 | err, len, address); |
| 3307 | ret = false; |
| 3308 | break; |
| 3309 | } else if (memcmp(ram_cmp, &ram_data[offset], len)) { |
| 3310 | brcmf_err("Downloaded RAM image is corrupted, block offset is %d, len is %d\n", |
| 3311 | offset, len); |
| 3312 | ret = false; |
| 3313 | break; |
| 3314 | } |
| 3315 | offset += len; |
| 3316 | address += len; |
| 3317 | } |
| 3318 | |
| 3319 | kfree(ram_cmp); |
| 3320 | |
| 3321 | return ret; |
| 3322 | } |
| 3323 | #else /* DEBUG */ |
| 3324 | static bool |
| 3325 | brcmf_sdio_verifymemory(struct brcmf_sdio_dev *sdiodev, u32 ram_addr, |
| 3326 | u8 *ram_data, uint ram_sz) |
| 3327 | { |
| 3328 | return true; |
| 3329 | } |
| 3330 | #endif /* DEBUG */ |
| 3331 | |
Arend van Spriel | 3355650 | 2014-01-13 22:20:25 +0100 | [diff] [blame] | 3332 | static int brcmf_sdio_download_code_file(struct brcmf_sdio *bus, |
| 3333 | const struct firmware *fw) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3334 | { |
Hante Meuleman | f2c44fe | 2013-09-25 13:05:45 +0200 | [diff] [blame] | 3335 | int err; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3336 | |
Hante Meuleman | a74d036 | 2014-01-13 22:20:22 +0100 | [diff] [blame] | 3337 | brcmf_dbg(TRACE, "Enter\n"); |
| 3338 | |
Hante Meuleman | f9951c1 | 2014-01-29 15:32:17 +0100 | [diff] [blame] | 3339 | err = brcmf_sdiod_ramrw(bus->sdiodev, true, bus->ci->rambase, |
| 3340 | (u8 *)fw->data, fw->size); |
| 3341 | if (err) |
| 3342 | brcmf_err("error %d on writing %d membytes at 0x%08x\n", |
| 3343 | err, (int)fw->size, bus->ci->rambase); |
| 3344 | else if (!brcmf_sdio_verifymemory(bus->sdiodev, bus->ci->rambase, |
| 3345 | (u8 *)fw->data, fw->size)) |
| 3346 | err = -EIO; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3347 | |
Hante Meuleman | f2c44fe | 2013-09-25 13:05:45 +0200 | [diff] [blame] | 3348 | return err; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3349 | } |
| 3350 | |
Arend van Spriel | 3355650 | 2014-01-13 22:20:25 +0100 | [diff] [blame] | 3351 | static int brcmf_sdio_download_nvram(struct brcmf_sdio *bus, |
Arend van Spriel | bd0e1b1 | 2014-05-27 12:56:22 +0200 | [diff] [blame] | 3352 | void *vars, u32 varsz) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3353 | { |
Hante Meuleman | a74d036 | 2014-01-13 22:20:22 +0100 | [diff] [blame] | 3354 | int address; |
| 3355 | int err; |
| 3356 | |
| 3357 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3358 | |
Hante Meuleman | a74d036 | 2014-01-13 22:20:22 +0100 | [diff] [blame] | 3359 | address = bus->ci->ramsize - varsz + bus->ci->rambase; |
| 3360 | err = brcmf_sdiod_ramrw(bus->sdiodev, true, address, vars, varsz); |
| 3361 | if (err) |
| 3362 | brcmf_err("error %d on writing %d nvram bytes at 0x%08x\n", |
| 3363 | err, varsz, address); |
| 3364 | else if (!brcmf_sdio_verifymemory(bus->sdiodev, address, vars, varsz)) |
| 3365 | err = -EIO; |
| 3366 | |
Hante Meuleman | a74d036 | 2014-01-13 22:20:22 +0100 | [diff] [blame] | 3367 | return err; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3368 | } |
| 3369 | |
Arend van Spriel | bd0e1b1 | 2014-05-27 12:56:22 +0200 | [diff] [blame] | 3370 | static int brcmf_sdio_download_firmware(struct brcmf_sdio *bus, |
| 3371 | const struct firmware *fw, |
| 3372 | void *nvram, u32 nvlen) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3373 | { |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3374 | int bcmerror = -EFAULT; |
Arend van Spriel | 3355650 | 2014-01-13 22:20:25 +0100 | [diff] [blame] | 3375 | u32 rstvec; |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3376 | |
| 3377 | sdio_claim_host(bus->sdiodev->func[1]); |
| 3378 | brcmf_sdio_clkctl(bus, CLK_AVAIL, false); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3379 | |
Arend van Spriel | 3355650 | 2014-01-13 22:20:25 +0100 | [diff] [blame] | 3380 | rstvec = get_unaligned_le32(fw->data); |
| 3381 | brcmf_dbg(SDIO, "firmware rstvec: %x\n", rstvec); |
| 3382 | |
| 3383 | bcmerror = brcmf_sdio_download_code_file(bus, fw); |
| 3384 | release_firmware(fw); |
| 3385 | if (bcmerror) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 3386 | brcmf_err("dongle image file download failed\n"); |
Arend van Spriel | bd0e1b1 | 2014-05-27 12:56:22 +0200 | [diff] [blame] | 3387 | brcmf_fw_nvram_free(nvram); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3388 | goto err; |
| 3389 | } |
| 3390 | |
Arend van Spriel | bd0e1b1 | 2014-05-27 12:56:22 +0200 | [diff] [blame] | 3391 | bcmerror = brcmf_sdio_download_nvram(bus, nvram, nvlen); |
| 3392 | brcmf_fw_nvram_free(nvram); |
Arend van Spriel | 3355650 | 2014-01-13 22:20:25 +0100 | [diff] [blame] | 3393 | if (bcmerror) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 3394 | brcmf_err("dongle nvram file download failed\n"); |
Franky Lin | 3eaa956 | 2013-04-02 21:06:20 +0200 | [diff] [blame] | 3395 | goto err; |
| 3396 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3397 | |
| 3398 | /* Take arm out of reset */ |
Arend van Spriel | d380ebc | 2015-03-11 16:11:29 +0100 | [diff] [blame] | 3399 | if (!brcmf_chip_set_active(bus->ci, rstvec)) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 3400 | brcmf_err("error getting out of ARM core reset\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3401 | goto err; |
| 3402 | } |
| 3403 | |
Hante Meuleman | a1cee86 | 2015-01-25 20:31:35 +0100 | [diff] [blame] | 3404 | /* Allow full data communication using DPC from now on. */ |
Arend van Spriel | a1ce7a0 | 2015-02-06 18:36:42 +0100 | [diff] [blame] | 3405 | brcmf_sdiod_change_state(bus->sdiodev, BRCMF_SDIOD_DATA); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3406 | bcmerror = 0; |
| 3407 | |
| 3408 | err: |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3409 | brcmf_sdio_clkctl(bus, CLK_SDONLY, false); |
| 3410 | sdio_release_host(bus->sdiodev->func[1]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3411 | return bcmerror; |
| 3412 | } |
| 3413 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3414 | static void brcmf_sdio_sr_init(struct brcmf_sdio *bus) |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 3415 | { |
| 3416 | int err = 0; |
| 3417 | u8 val; |
| 3418 | |
| 3419 | brcmf_dbg(TRACE, "Enter\n"); |
| 3420 | |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 3421 | val = brcmf_sdiod_regrb(bus->sdiodev, SBSDIO_FUNC1_WAKEUPCTRL, &err); |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 3422 | if (err) { |
| 3423 | brcmf_err("error reading SBSDIO_FUNC1_WAKEUPCTRL\n"); |
| 3424 | return; |
| 3425 | } |
| 3426 | |
| 3427 | val |= 1 << SBSDIO_FUNC1_WCTRL_HTWAIT_SHIFT; |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 3428 | brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_WAKEUPCTRL, val, &err); |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 3429 | if (err) { |
| 3430 | brcmf_err("error writing SBSDIO_FUNC1_WAKEUPCTRL\n"); |
| 3431 | return; |
| 3432 | } |
| 3433 | |
| 3434 | /* Add CMD14 Support */ |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 3435 | brcmf_sdiod_regwb(bus->sdiodev, SDIO_CCCR_BRCM_CARDCAP, |
| 3436 | (SDIO_CCCR_BRCM_CARDCAP_CMD14_SUPPORT | |
| 3437 | SDIO_CCCR_BRCM_CARDCAP_CMD14_EXT), |
| 3438 | &err); |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 3439 | if (err) { |
| 3440 | brcmf_err("error writing SDIO_CCCR_BRCM_CARDCAP\n"); |
| 3441 | return; |
| 3442 | } |
| 3443 | |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 3444 | brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, |
| 3445 | SBSDIO_FORCE_HT, &err); |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 3446 | if (err) { |
| 3447 | brcmf_err("error writing SBSDIO_FUNC1_CHIPCLKCSR\n"); |
| 3448 | return; |
| 3449 | } |
| 3450 | |
| 3451 | /* set flag */ |
| 3452 | bus->sr_enabled = true; |
| 3453 | brcmf_dbg(INFO, "SR enabled\n"); |
| 3454 | } |
| 3455 | |
| 3456 | /* enable KSO bit */ |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3457 | static int brcmf_sdio_kso_init(struct brcmf_sdio *bus) |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 3458 | { |
| 3459 | u8 val; |
| 3460 | int err = 0; |
| 3461 | |
| 3462 | brcmf_dbg(TRACE, "Enter\n"); |
| 3463 | |
| 3464 | /* KSO bit added in SDIO core rev 12 */ |
Arend van Spriel | cb7cf7b | 2014-01-29 15:32:19 +0100 | [diff] [blame] | 3465 | 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] | 3466 | return 0; |
| 3467 | |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 3468 | val = brcmf_sdiod_regrb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, &err); |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 3469 | if (err) { |
| 3470 | brcmf_err("error reading SBSDIO_FUNC1_SLEEPCSR\n"); |
| 3471 | return err; |
| 3472 | } |
| 3473 | |
| 3474 | if (!(val & SBSDIO_FUNC1_SLEEPCSR_KSO_MASK)) { |
| 3475 | val |= (SBSDIO_FUNC1_SLEEPCSR_KSO_EN << |
| 3476 | SBSDIO_FUNC1_SLEEPCSR_KSO_SHIFT); |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 3477 | brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR, |
| 3478 | val, &err); |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 3479 | if (err) { |
| 3480 | brcmf_err("error writing SBSDIO_FUNC1_SLEEPCSR\n"); |
| 3481 | return err; |
| 3482 | } |
| 3483 | } |
| 3484 | |
| 3485 | return 0; |
| 3486 | } |
| 3487 | |
| 3488 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3489 | static int brcmf_sdio_bus_preinit(struct device *dev) |
Arend van Spriel | cf45828 | 2013-11-29 11:48:15 +0100 | [diff] [blame] | 3490 | { |
| 3491 | struct brcmf_bus *bus_if = dev_get_drvdata(dev); |
| 3492 | struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio; |
| 3493 | struct brcmf_sdio *bus = sdiodev->bus; |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 3494 | uint pad_size; |
Arend van Spriel | cf45828 | 2013-11-29 11:48:15 +0100 | [diff] [blame] | 3495 | u32 value; |
Arend van Spriel | cf45828 | 2013-11-29 11:48:15 +0100 | [diff] [blame] | 3496 | int err; |
| 3497 | |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 3498 | /* the commands below use the terms tx and rx from |
| 3499 | * a device perspective, ie. bus:txglom affects the |
| 3500 | * bus transfers from device to host. |
| 3501 | */ |
Arend van Spriel | cb7cf7b | 2014-01-29 15:32:19 +0100 | [diff] [blame] | 3502 | 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] | 3503 | /* for sdio core rev < 12, disable txgloming */ |
| 3504 | value = 0; |
| 3505 | err = brcmf_iovar_data_set(dev, "bus:txglom", &value, |
| 3506 | sizeof(u32)); |
| 3507 | } else { |
| 3508 | /* otherwise, set txglomalign */ |
| 3509 | value = 4; |
| 3510 | if (sdiodev->pdata) |
| 3511 | value = sdiodev->pdata->sd_sgentry_align; |
| 3512 | /* SDIO ADMA requires at least 32 bit alignment */ |
| 3513 | value = max_t(u32, value, 4); |
| 3514 | err = brcmf_iovar_data_set(dev, "bus:txglomalign", &value, |
| 3515 | sizeof(u32)); |
| 3516 | } |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 3517 | |
| 3518 | if (err < 0) |
| 3519 | goto done; |
| 3520 | |
| 3521 | bus->tx_hdrlen = SDPCM_HWHDR_LEN + SDPCM_SWHDR_LEN; |
| 3522 | if (sdiodev->sg_support) { |
| 3523 | bus->txglom = false; |
| 3524 | value = 1; |
| 3525 | pad_size = bus->sdiodev->func[2]->cur_blksize << 1; |
Franky Lin | 8da9d2c | 2013-11-29 12:25:10 +0100 | [diff] [blame] | 3526 | err = brcmf_iovar_data_set(bus->sdiodev->dev, "bus:rxglom", |
| 3527 | &value, sizeof(u32)); |
| 3528 | if (err < 0) { |
| 3529 | /* bus:rxglom is allowed to fail */ |
| 3530 | err = 0; |
| 3531 | } else { |
| 3532 | bus->txglom = true; |
| 3533 | bus->tx_hdrlen += SDPCM_HWEXT_LEN; |
| 3534 | } |
| 3535 | } |
| 3536 | brcmf_bus_add_txhdrlen(bus->sdiodev->dev, bus->tx_hdrlen); |
| 3537 | |
| 3538 | done: |
Arend van Spriel | cf45828 | 2013-11-29 11:48:15 +0100 | [diff] [blame] | 3539 | return err; |
| 3540 | } |
| 3541 | |
Arend van Spriel | 9982464 | 2015-02-06 18:36:45 +0100 | [diff] [blame] | 3542 | void brcmf_sdio_trigger_dpc(struct brcmf_sdio *bus) |
| 3543 | { |
Hante Meuleman | 2c64e16 | 2015-03-18 13:25:22 +0100 | [diff] [blame] | 3544 | if (!bus->dpc_triggered) { |
| 3545 | bus->dpc_triggered = true; |
Arend van Spriel | 9982464 | 2015-02-06 18:36:45 +0100 | [diff] [blame] | 3546 | queue_work(bus->brcmf_wq, &bus->datawork); |
| 3547 | } |
| 3548 | } |
| 3549 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3550 | void brcmf_sdio_isr(struct brcmf_sdio *bus) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3551 | { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3552 | brcmf_dbg(TRACE, "Enter\n"); |
| 3553 | |
| 3554 | if (!bus) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 3555 | brcmf_err("bus is null pointer, exiting\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3556 | return; |
| 3557 | } |
| 3558 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3559 | /* Count the interrupt call */ |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 3560 | bus->sdcnt.intrcount++; |
Franky Lin | 4531603 | 2012-09-13 21:12:03 +0200 | [diff] [blame] | 3561 | if (in_interrupt()) |
| 3562 | atomic_set(&bus->ipend, 1); |
| 3563 | else |
| 3564 | if (brcmf_sdio_intr_rstatus(bus)) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 3565 | brcmf_err("failed backplane access\n"); |
Franky Lin | 4531603 | 2012-09-13 21:12:03 +0200 | [diff] [blame] | 3566 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3567 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3568 | /* Disable additional interrupts (is this needed now)? */ |
| 3569 | if (!bus->intr) |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 3570 | brcmf_err("isr w/o interrupt configured!\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3571 | |
Hante Meuleman | 2c64e16 | 2015-03-18 13:25:22 +0100 | [diff] [blame] | 3572 | bus->dpc_triggered = true; |
Franky Lin | f1e68c2 | 2012-09-13 21:12:00 +0200 | [diff] [blame] | 3573 | queue_work(bus->brcmf_wq, &bus->datawork); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3574 | } |
| 3575 | |
Hante Meuleman | b441ba8 | 2015-03-06 18:40:39 +0100 | [diff] [blame] | 3576 | static void brcmf_sdio_bus_watchdog(struct brcmf_sdio *bus) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3577 | { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3578 | brcmf_dbg(TIMER, "Enter\n"); |
| 3579 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3580 | /* Poll period: check device if appropriate. */ |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 3581 | if (!bus->sr_enabled && |
| 3582 | bus->poll && (++bus->polltick >= bus->pollrate)) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3583 | u32 intstatus = 0; |
| 3584 | |
| 3585 | /* Reset poll tick */ |
| 3586 | bus->polltick = 0; |
| 3587 | |
| 3588 | /* Check device if no interrupts */ |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 3589 | if (!bus->intr || |
| 3590 | (bus->sdcnt.intrcount == bus->sdcnt.lastintrs)) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3591 | |
Hante Meuleman | 2c64e16 | 2015-03-18 13:25:22 +0100 | [diff] [blame] | 3592 | if (!bus->dpc_triggered) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3593 | u8 devpend; |
Arend van Spriel | fccfe93 | 2013-06-18 13:29:26 +0200 | [diff] [blame] | 3594 | |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 3595 | sdio_claim_host(bus->sdiodev->func[1]); |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 3596 | devpend = brcmf_sdiod_regrb(bus->sdiodev, |
| 3597 | SDIO_CCCR_INTx, |
| 3598 | NULL); |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 3599 | sdio_release_host(bus->sdiodev->func[1]); |
Arend van Spriel | 9982464 | 2015-02-06 18:36:45 +0100 | [diff] [blame] | 3600 | intstatus = devpend & (INTR_STATUS_FUNC1 | |
| 3601 | INTR_STATUS_FUNC2); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3602 | } |
| 3603 | |
| 3604 | /* If there is something, make like the ISR and |
| 3605 | schedule the DPC */ |
| 3606 | if (intstatus) { |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 3607 | bus->sdcnt.pollcnt++; |
Franky Lin | 1d38227 | 2012-09-13 21:11:59 +0200 | [diff] [blame] | 3608 | atomic_set(&bus->ipend, 1); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3609 | |
Hante Meuleman | 2c64e16 | 2015-03-18 13:25:22 +0100 | [diff] [blame] | 3610 | bus->dpc_triggered = true; |
Franky Lin | f1e68c2 | 2012-09-13 21:12:00 +0200 | [diff] [blame] | 3611 | queue_work(bus->brcmf_wq, &bus->datawork); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3612 | } |
| 3613 | } |
| 3614 | |
| 3615 | /* Update interrupt tracking */ |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 3616 | bus->sdcnt.lastintrs = bus->sdcnt.intrcount; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3617 | } |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 3618 | #ifdef DEBUG |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3619 | /* Poll for console output periodically */ |
Arend van Spriel | 9d6c1dc | 2015-08-26 22:15:01 +0200 | [diff] [blame] | 3620 | if (bus->sdiodev->state == BRCMF_SDIOD_DATA && BRCMF_FWCON_ON() && |
Franky Lin | 8d169aa | 2011-11-22 17:21:52 -0800 | [diff] [blame] | 3621 | bus->console_interval != 0) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3622 | bus->console.count += BRCMF_WD_POLL_MS; |
| 3623 | if (bus->console.count >= bus->console_interval) { |
| 3624 | bus->console.count -= bus->console_interval; |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 3625 | sdio_claim_host(bus->sdiodev->func[1]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3626 | /* Make sure backplane clock is on */ |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3627 | brcmf_sdio_bus_sleep(bus, false, false); |
| 3628 | if (brcmf_sdio_readconsole(bus) < 0) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3629 | /* stop on error */ |
| 3630 | bus->console_interval = 0; |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 3631 | sdio_release_host(bus->sdiodev->func[1]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3632 | } |
| 3633 | } |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 3634 | #endif /* DEBUG */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3635 | |
| 3636 | /* On idle timeout clear activity flag and/or turn off clock */ |
Hante Meuleman | 2c64e16 | 2015-03-18 13:25:22 +0100 | [diff] [blame] | 3637 | if (!bus->dpc_triggered) { |
| 3638 | rmb(); |
| 3639 | if ((!bus->dpc_running) && (bus->idletime > 0) && |
| 3640 | (bus->clkstate == CLK_AVAIL)) { |
| 3641 | bus->idlecount++; |
| 3642 | if (bus->idlecount > bus->idletime) { |
| 3643 | brcmf_dbg(SDIO, "idle\n"); |
| 3644 | sdio_claim_host(bus->sdiodev->func[1]); |
| 3645 | brcmf_sdio_wd_timer(bus, 0); |
| 3646 | bus->idlecount = 0; |
| 3647 | brcmf_sdio_bus_sleep(bus, true, false); |
| 3648 | sdio_release_host(bus->sdiodev->func[1]); |
| 3649 | } |
| 3650 | } else { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3651 | bus->idlecount = 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3652 | } |
Hante Meuleman | b441ba8 | 2015-03-06 18:40:39 +0100 | [diff] [blame] | 3653 | } else { |
| 3654 | bus->idlecount = 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3655 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3656 | } |
| 3657 | |
Franky Lin | f1e68c2 | 2012-09-13 21:12:00 +0200 | [diff] [blame] | 3658 | static void brcmf_sdio_dataworker(struct work_struct *work) |
| 3659 | { |
| 3660 | struct brcmf_sdio *bus = container_of(work, struct brcmf_sdio, |
| 3661 | datawork); |
Franky Lin | f1e68c2 | 2012-09-13 21:12:00 +0200 | [diff] [blame] | 3662 | |
Hante Meuleman | 2c64e16 | 2015-03-18 13:25:22 +0100 | [diff] [blame] | 3663 | bus->dpc_running = true; |
| 3664 | wmb(); |
| 3665 | while (ACCESS_ONCE(bus->dpc_triggered)) { |
| 3666 | bus->dpc_triggered = false; |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3667 | brcmf_sdio_dpc(bus); |
Hante Meuleman | b441ba8 | 2015-03-06 18:40:39 +0100 | [diff] [blame] | 3668 | bus->idlecount = 0; |
Franky Lin | f1e68c2 | 2012-09-13 21:12:00 +0200 | [diff] [blame] | 3669 | } |
Hante Meuleman | 2c64e16 | 2015-03-18 13:25:22 +0100 | [diff] [blame] | 3670 | bus->dpc_running = false; |
Arend van Spriel | 9982464 | 2015-02-06 18:36:45 +0100 | [diff] [blame] | 3671 | if (brcmf_sdiod_freezing(bus->sdiodev)) { |
| 3672 | brcmf_sdiod_change_state(bus->sdiodev, BRCMF_SDIOD_DOWN); |
| 3673 | brcmf_sdiod_try_freeze(bus->sdiodev); |
| 3674 | brcmf_sdiod_change_state(bus->sdiodev, BRCMF_SDIOD_DATA); |
| 3675 | } |
Franky Lin | f1e68c2 | 2012-09-13 21:12:00 +0200 | [diff] [blame] | 3676 | } |
| 3677 | |
Arend van Spriel | 65d80d0 | 2014-01-29 15:32:14 +0100 | [diff] [blame] | 3678 | static void |
| 3679 | brcmf_sdio_drivestrengthinit(struct brcmf_sdio_dev *sdiodev, |
Arend van Spriel | cb7cf7b | 2014-01-29 15:32:19 +0100 | [diff] [blame] | 3680 | struct brcmf_chip *ci, u32 drivestrength) |
Arend van Spriel | 65d80d0 | 2014-01-29 15:32:14 +0100 | [diff] [blame] | 3681 | { |
| 3682 | const struct sdiod_drive_str *str_tab = NULL; |
| 3683 | u32 str_mask; |
| 3684 | u32 str_shift; |
Arend van Spriel | cb7cf7b | 2014-01-29 15:32:19 +0100 | [diff] [blame] | 3685 | u32 base; |
Arend van Spriel | 65d80d0 | 2014-01-29 15:32:14 +0100 | [diff] [blame] | 3686 | u32 i; |
| 3687 | u32 drivestrength_sel = 0; |
| 3688 | u32 cc_data_temp; |
| 3689 | u32 addr; |
| 3690 | |
Arend van Spriel | cb7cf7b | 2014-01-29 15:32:19 +0100 | [diff] [blame] | 3691 | if (!(ci->cc_caps & CC_CAP_PMU)) |
Arend van Spriel | 65d80d0 | 2014-01-29 15:32:14 +0100 | [diff] [blame] | 3692 | return; |
| 3693 | |
| 3694 | switch (SDIOD_DRVSTR_KEY(ci->chip, ci->pmurev)) { |
Hante Meuleman | 5779ae6 | 2014-07-12 08:49:34 +0200 | [diff] [blame] | 3695 | case SDIOD_DRVSTR_KEY(BRCM_CC_4330_CHIP_ID, 12): |
Arend van Spriel | 65d80d0 | 2014-01-29 15:32:14 +0100 | [diff] [blame] | 3696 | str_tab = sdiod_drvstr_tab1_1v8; |
| 3697 | str_mask = 0x00003800; |
| 3698 | str_shift = 11; |
| 3699 | break; |
Hante Meuleman | 5779ae6 | 2014-07-12 08:49:34 +0200 | [diff] [blame] | 3700 | case SDIOD_DRVSTR_KEY(BRCM_CC_4334_CHIP_ID, 17): |
Arend van Spriel | 65d80d0 | 2014-01-29 15:32:14 +0100 | [diff] [blame] | 3701 | str_tab = sdiod_drvstr_tab6_1v8; |
| 3702 | str_mask = 0x00001800; |
| 3703 | str_shift = 11; |
| 3704 | break; |
Hante Meuleman | 5779ae6 | 2014-07-12 08:49:34 +0200 | [diff] [blame] | 3705 | case SDIOD_DRVSTR_KEY(BRCM_CC_43143_CHIP_ID, 17): |
Arend van Spriel | 65d80d0 | 2014-01-29 15:32:14 +0100 | [diff] [blame] | 3706 | /* note: 43143 does not support tristate */ |
| 3707 | i = ARRAY_SIZE(sdiod_drvstr_tab2_3v3) - 1; |
| 3708 | if (drivestrength >= sdiod_drvstr_tab2_3v3[i].strength) { |
| 3709 | str_tab = sdiod_drvstr_tab2_3v3; |
| 3710 | str_mask = 0x00000007; |
| 3711 | str_shift = 0; |
| 3712 | } else |
| 3713 | 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] | 3714 | ci->name, drivestrength); |
Arend van Spriel | 65d80d0 | 2014-01-29 15:32:14 +0100 | [diff] [blame] | 3715 | break; |
Hante Meuleman | 5779ae6 | 2014-07-12 08:49:34 +0200 | [diff] [blame] | 3716 | case SDIOD_DRVSTR_KEY(BRCM_CC_43362_CHIP_ID, 13): |
Arend van Spriel | 65d80d0 | 2014-01-29 15:32:14 +0100 | [diff] [blame] | 3717 | str_tab = sdiod_drive_strength_tab5_1v8; |
| 3718 | str_mask = 0x00003800; |
| 3719 | str_shift = 11; |
| 3720 | break; |
| 3721 | default: |
| 3722 | 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] | 3723 | ci->name, ci->chiprev, ci->pmurev); |
Arend van Spriel | 65d80d0 | 2014-01-29 15:32:14 +0100 | [diff] [blame] | 3724 | break; |
| 3725 | } |
| 3726 | |
| 3727 | if (str_tab != NULL) { |
| 3728 | for (i = 0; str_tab[i].strength != 0; i++) { |
| 3729 | if (drivestrength >= str_tab[i].strength) { |
| 3730 | drivestrength_sel = str_tab[i].sel; |
| 3731 | break; |
| 3732 | } |
| 3733 | } |
Arend van Spriel | cb7cf7b | 2014-01-29 15:32:19 +0100 | [diff] [blame] | 3734 | base = brcmf_chip_get_chipcommon(ci)->base; |
Arend van Spriel | 65d80d0 | 2014-01-29 15:32:14 +0100 | [diff] [blame] | 3735 | addr = CORE_CC_REG(base, chipcontrol_addr); |
| 3736 | brcmf_sdiod_regwl(sdiodev, addr, 1, NULL); |
| 3737 | cc_data_temp = brcmf_sdiod_regrl(sdiodev, addr, NULL); |
| 3738 | cc_data_temp &= ~str_mask; |
| 3739 | drivestrength_sel <<= str_shift; |
| 3740 | cc_data_temp |= drivestrength_sel; |
| 3741 | brcmf_sdiod_regwl(sdiodev, addr, cc_data_temp, NULL); |
| 3742 | |
| 3743 | brcmf_dbg(INFO, "SDIO: %d mA (req=%d mA) drive strength selected, set to 0x%08x\n", |
| 3744 | str_tab[i].strength, drivestrength, cc_data_temp); |
| 3745 | } |
| 3746 | } |
| 3747 | |
Arend van Spriel | cb7cf7b | 2014-01-29 15:32:19 +0100 | [diff] [blame] | 3748 | static int brcmf_sdio_buscoreprep(void *ctx) |
Arend van Spriel | 65d80d0 | 2014-01-29 15:32:14 +0100 | [diff] [blame] | 3749 | { |
Arend van Spriel | cb7cf7b | 2014-01-29 15:32:19 +0100 | [diff] [blame] | 3750 | struct brcmf_sdio_dev *sdiodev = ctx; |
Arend van Spriel | 65d80d0 | 2014-01-29 15:32:14 +0100 | [diff] [blame] | 3751 | int err = 0; |
| 3752 | u8 clkval, clkset; |
| 3753 | |
| 3754 | /* Try forcing SDIO core to do ALPAvail request only */ |
| 3755 | clkset = SBSDIO_FORCE_HW_CLKREQ_OFF | SBSDIO_ALP_AVAIL_REQ; |
| 3756 | brcmf_sdiod_regwb(sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, clkset, &err); |
| 3757 | if (err) { |
| 3758 | brcmf_err("error writing for HT off\n"); |
| 3759 | return err; |
| 3760 | } |
| 3761 | |
| 3762 | /* If register supported, wait for ALPAvail and then force ALP */ |
| 3763 | /* This may take up to 15 milliseconds */ |
| 3764 | clkval = brcmf_sdiod_regrb(sdiodev, |
| 3765 | SBSDIO_FUNC1_CHIPCLKCSR, NULL); |
| 3766 | |
| 3767 | if ((clkval & ~SBSDIO_AVBITS) != clkset) { |
| 3768 | brcmf_err("ChipClkCSR access: wrote 0x%02x read 0x%02x\n", |
| 3769 | clkset, clkval); |
| 3770 | return -EACCES; |
| 3771 | } |
| 3772 | |
| 3773 | SPINWAIT(((clkval = brcmf_sdiod_regrb(sdiodev, |
| 3774 | SBSDIO_FUNC1_CHIPCLKCSR, NULL)), |
| 3775 | !SBSDIO_ALPAV(clkval)), |
| 3776 | PMU_MAX_TRANSITION_DLY); |
| 3777 | if (!SBSDIO_ALPAV(clkval)) { |
| 3778 | brcmf_err("timeout on ALPAV wait, clkval 0x%02x\n", |
| 3779 | clkval); |
| 3780 | return -EBUSY; |
| 3781 | } |
| 3782 | |
| 3783 | clkset = SBSDIO_FORCE_HW_CLKREQ_OFF | SBSDIO_FORCE_ALP; |
| 3784 | brcmf_sdiod_regwb(sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, clkset, &err); |
| 3785 | udelay(65); |
| 3786 | |
| 3787 | /* Also, disable the extra SDIO pull-ups */ |
| 3788 | brcmf_sdiod_regwb(sdiodev, SBSDIO_FUNC1_SDIOPULLUP, 0, NULL); |
| 3789 | |
| 3790 | return 0; |
| 3791 | } |
| 3792 | |
Arend van Spriel | d380ebc | 2015-03-11 16:11:29 +0100 | [diff] [blame] | 3793 | static void brcmf_sdio_buscore_activate(void *ctx, struct brcmf_chip *chip, |
| 3794 | u32 rstvec) |
Arend van Spriel | cb7cf7b | 2014-01-29 15:32:19 +0100 | [diff] [blame] | 3795 | { |
| 3796 | struct brcmf_sdio_dev *sdiodev = ctx; |
| 3797 | struct brcmf_core *core; |
| 3798 | u32 reg_addr; |
| 3799 | |
| 3800 | /* clear all interrupts */ |
| 3801 | core = brcmf_chip_get_core(chip, BCMA_CORE_SDIO_DEV); |
| 3802 | reg_addr = core->base + offsetof(struct sdpcmd_regs, intstatus); |
| 3803 | brcmf_sdiod_regwl(sdiodev, reg_addr, 0xFFFFFFFF, NULL); |
| 3804 | |
| 3805 | if (rstvec) |
| 3806 | /* Write reset vector to address 0 */ |
| 3807 | brcmf_sdiod_ramrw(sdiodev, true, 0, (void *)&rstvec, |
| 3808 | sizeof(rstvec)); |
| 3809 | } |
| 3810 | |
| 3811 | static u32 brcmf_sdio_buscore_read32(void *ctx, u32 addr) |
| 3812 | { |
| 3813 | struct brcmf_sdio_dev *sdiodev = ctx; |
| 3814 | u32 val, rev; |
| 3815 | |
| 3816 | val = brcmf_sdiod_regrl(sdiodev, addr, NULL); |
Arend van Spriel | 8bd61f8 | 2015-01-06 23:02:54 +0100 | [diff] [blame] | 3817 | if (sdiodev->func[0]->device == SDIO_DEVICE_ID_BROADCOM_4335_4339 && |
Arend van Spriel | cb7cf7b | 2014-01-29 15:32:19 +0100 | [diff] [blame] | 3818 | addr == CORE_CC_REG(SI_ENUM_BASE, chipid)) { |
| 3819 | rev = (val & CID_REV_MASK) >> CID_REV_SHIFT; |
| 3820 | if (rev >= 2) { |
| 3821 | val &= ~CID_ID_MASK; |
Hante Meuleman | 5779ae6 | 2014-07-12 08:49:34 +0200 | [diff] [blame] | 3822 | val |= BRCM_CC_4339_CHIP_ID; |
Arend van Spriel | cb7cf7b | 2014-01-29 15:32:19 +0100 | [diff] [blame] | 3823 | } |
| 3824 | } |
| 3825 | return val; |
| 3826 | } |
| 3827 | |
| 3828 | static void brcmf_sdio_buscore_write32(void *ctx, u32 addr, u32 val) |
| 3829 | { |
| 3830 | struct brcmf_sdio_dev *sdiodev = ctx; |
| 3831 | |
| 3832 | brcmf_sdiod_regwl(sdiodev, addr, val, NULL); |
| 3833 | } |
| 3834 | |
| 3835 | static const struct brcmf_buscore_ops brcmf_sdio_buscore_ops = { |
| 3836 | .prepare = brcmf_sdio_buscoreprep, |
Arend van Spriel | d380ebc | 2015-03-11 16:11:29 +0100 | [diff] [blame] | 3837 | .activate = brcmf_sdio_buscore_activate, |
Arend van Spriel | cb7cf7b | 2014-01-29 15:32:19 +0100 | [diff] [blame] | 3838 | .read32 = brcmf_sdio_buscore_read32, |
| 3839 | .write32 = brcmf_sdio_buscore_write32, |
| 3840 | }; |
| 3841 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3842 | static bool |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3843 | brcmf_sdio_probe_attach(struct brcmf_sdio *bus) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3844 | { |
| 3845 | u8 clkctl = 0; |
| 3846 | int err = 0; |
| 3847 | int reg_addr; |
| 3848 | u32 reg_val; |
Hante Meuleman | 668761a | 2013-04-12 10:55:55 +0200 | [diff] [blame] | 3849 | u32 drivestrength; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3850 | |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 3851 | sdio_claim_host(bus->sdiodev->func[1]); |
| 3852 | |
Joe Perches | 18aad4f | 2012-01-15 00:38:42 -0800 | [diff] [blame] | 3853 | pr_debug("F1 signature read @0x18000000=0x%4x\n", |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 3854 | brcmf_sdiod_regrl(bus->sdiodev, SI_ENUM_BASE, NULL)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3855 | |
| 3856 | /* |
Arend van Spriel | cb7cf7b | 2014-01-29 15:32:19 +0100 | [diff] [blame] | 3857 | * Force PLL off until brcmf_chip_attach() |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3858 | * programs PLL control regs |
| 3859 | */ |
| 3860 | |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 3861 | brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, |
| 3862 | BRCMF_INIT_CLKCTL1, &err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3863 | if (!err) |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 3864 | clkctl = brcmf_sdiod_regrb(bus->sdiodev, |
| 3865 | SBSDIO_FUNC1_CHIPCLKCSR, &err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3866 | |
| 3867 | if (err || ((clkctl & ~SBSDIO_AVBITS) != BRCMF_INIT_CLKCTL1)) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 3868 | 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] | 3869 | err, BRCMF_INIT_CLKCTL1, clkctl); |
| 3870 | goto fail; |
| 3871 | } |
| 3872 | |
Arend van Spriel | cb7cf7b | 2014-01-29 15:32:19 +0100 | [diff] [blame] | 3873 | bus->ci = brcmf_chip_attach(bus->sdiodev, &brcmf_sdio_buscore_ops); |
| 3874 | if (IS_ERR(bus->ci)) { |
| 3875 | brcmf_err("brcmf_chip_attach failed!\n"); |
| 3876 | bus->ci = NULL; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3877 | goto fail; |
| 3878 | } |
| 3879 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3880 | if (brcmf_sdio_kso_init(bus)) { |
Piotr Haber | 4a3da99 | 2013-04-11 13:28:46 +0200 | [diff] [blame] | 3881 | brcmf_err("error enabling KSO\n"); |
| 3882 | goto fail; |
| 3883 | } |
| 3884 | |
Hante Meuleman | 668761a | 2013-04-12 10:55:55 +0200 | [diff] [blame] | 3885 | if ((bus->sdiodev->pdata) && (bus->sdiodev->pdata->drive_strength)) |
| 3886 | drivestrength = bus->sdiodev->pdata->drive_strength; |
| 3887 | else |
| 3888 | drivestrength = DEFAULT_SDIO_DRIVE_STRENGTH; |
Arend van Spriel | 65d80d0 | 2014-01-29 15:32:14 +0100 | [diff] [blame] | 3889 | brcmf_sdio_drivestrengthinit(bus->sdiodev, bus->ci, drivestrength); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3890 | |
Piotr Haber | 1e9ab4d | 2013-04-11 13:28:52 +0200 | [diff] [blame] | 3891 | /* 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] | 3892 | reg_val = brcmf_sdiod_regrb(bus->sdiodev, |
| 3893 | SDIO_CCCR_BRCM_CARDCTRL, &err); |
Piotr Haber | 1e9ab4d | 2013-04-11 13:28:52 +0200 | [diff] [blame] | 3894 | if (err) |
| 3895 | goto fail; |
| 3896 | |
| 3897 | reg_val |= SDIO_CCCR_BRCM_CARDCTRL_WLANRESET; |
| 3898 | |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 3899 | brcmf_sdiod_regwb(bus->sdiodev, |
| 3900 | SDIO_CCCR_BRCM_CARDCTRL, reg_val, &err); |
Piotr Haber | 1e9ab4d | 2013-04-11 13:28:52 +0200 | [diff] [blame] | 3901 | if (err) |
| 3902 | goto fail; |
| 3903 | |
| 3904 | /* set PMUControl so a backplane reset does PMU state reload */ |
Arend van Spriel | cb7cf7b | 2014-01-29 15:32:19 +0100 | [diff] [blame] | 3905 | reg_addr = CORE_CC_REG(brcmf_chip_get_chipcommon(bus->ci)->base, |
Piotr Haber | 1e9ab4d | 2013-04-11 13:28:52 +0200 | [diff] [blame] | 3906 | pmucontrol); |
Arend van Spriel | cb7cf7b | 2014-01-29 15:32:19 +0100 | [diff] [blame] | 3907 | reg_val = brcmf_sdiod_regrl(bus->sdiodev, reg_addr, &err); |
Piotr Haber | 1e9ab4d | 2013-04-11 13:28:52 +0200 | [diff] [blame] | 3908 | if (err) |
| 3909 | goto fail; |
| 3910 | |
| 3911 | reg_val |= (BCMA_CC_PMU_CTL_RES_RELOAD << BCMA_CC_PMU_CTL_RES_SHIFT); |
| 3912 | |
Arend van Spriel | cb7cf7b | 2014-01-29 15:32:19 +0100 | [diff] [blame] | 3913 | brcmf_sdiod_regwl(bus->sdiodev, reg_addr, reg_val, &err); |
Piotr Haber | 1e9ab4d | 2013-04-11 13:28:52 +0200 | [diff] [blame] | 3914 | if (err) |
| 3915 | goto fail; |
| 3916 | |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 3917 | sdio_release_host(bus->sdiodev->func[1]); |
| 3918 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3919 | brcmu_pktq_init(&bus->txq, (PRIOMASK + 1), TXQLEN); |
| 3920 | |
Arend van Spriel | 9b2d2f2 | 2013-11-29 12:25:14 +0100 | [diff] [blame] | 3921 | /* allocate header buffer */ |
| 3922 | bus->hdrbuf = kzalloc(MAX_HDR_READ + bus->head_align, GFP_KERNEL); |
| 3923 | if (!bus->hdrbuf) |
| 3924 | return false; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3925 | /* Locate an appropriately-aligned portion of hdrbuf */ |
| 3926 | bus->rxhdr = (u8 *) roundup((unsigned long)&bus->hdrbuf[0], |
Arend van Spriel | 9b2d2f2 | 2013-11-29 12:25:14 +0100 | [diff] [blame] | 3927 | bus->head_align); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3928 | |
| 3929 | /* Set the poll and/or interrupt flags */ |
| 3930 | bus->intr = true; |
| 3931 | bus->poll = false; |
| 3932 | if (bus->poll) |
| 3933 | bus->pollrate = 1; |
| 3934 | |
| 3935 | return true; |
| 3936 | |
| 3937 | fail: |
Franky Lin | 38b0b0d | 2012-11-05 16:22:24 -0800 | [diff] [blame] | 3938 | sdio_release_host(bus->sdiodev->func[1]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3939 | return false; |
| 3940 | } |
| 3941 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3942 | static int |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3943 | brcmf_sdio_watchdog_thread(void *data) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3944 | { |
Franky Lin | e92eedf | 2011-11-22 17:21:50 -0800 | [diff] [blame] | 3945 | struct brcmf_sdio *bus = (struct brcmf_sdio *)data; |
Arend van Spriel | 9982464 | 2015-02-06 18:36:45 +0100 | [diff] [blame] | 3946 | int wait; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3947 | |
| 3948 | allow_signal(SIGTERM); |
| 3949 | /* Run until signal received */ |
Arend van Spriel | 9982464 | 2015-02-06 18:36:45 +0100 | [diff] [blame] | 3950 | brcmf_sdiod_freezer_count(bus->sdiodev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3951 | while (1) { |
| 3952 | if (kthread_should_stop()) |
| 3953 | break; |
Arend van Spriel | 9982464 | 2015-02-06 18:36:45 +0100 | [diff] [blame] | 3954 | brcmf_sdiod_freezer_uncount(bus->sdiodev); |
| 3955 | wait = wait_for_completion_interruptible(&bus->watchdog_wait); |
| 3956 | brcmf_sdiod_freezer_count(bus->sdiodev); |
| 3957 | brcmf_sdiod_try_freeze(bus->sdiodev); |
| 3958 | if (!wait) { |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3959 | brcmf_sdio_bus_watchdog(bus); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3960 | /* Count the tick for reference */ |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 3961 | bus->sdcnt.tickcnt++; |
Arend van Spriel | 58e9df4 | 2014-03-20 10:18:01 +0100 | [diff] [blame] | 3962 | reinit_completion(&bus->watchdog_wait); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3963 | } else |
| 3964 | break; |
| 3965 | } |
| 3966 | return 0; |
| 3967 | } |
| 3968 | |
| 3969 | static void |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3970 | brcmf_sdio_watchdog(unsigned long data) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3971 | { |
Franky Lin | e92eedf | 2011-11-22 17:21:50 -0800 | [diff] [blame] | 3972 | struct brcmf_sdio *bus = (struct brcmf_sdio *)data; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3973 | |
| 3974 | if (bus->watchdog_tsk) { |
| 3975 | complete(&bus->watchdog_wait); |
| 3976 | /* Reschedule the watchdog */ |
| 3977 | if (bus->wd_timer_valid) |
| 3978 | mod_timer(&bus->timer, |
Nicholas Mc Guire | 187d3c3 | 2015-02-06 05:26:45 -0500 | [diff] [blame] | 3979 | jiffies + msecs_to_jiffies(BRCMF_WD_POLL_MS)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3980 | } |
| 3981 | } |
| 3982 | |
Arend van Spriel | d9cb259 | 2012-12-05 15:25:54 +0100 | [diff] [blame] | 3983 | static struct brcmf_bus_ops brcmf_sdio_bus_ops = { |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3984 | .stop = brcmf_sdio_bus_stop, |
| 3985 | .preinit = brcmf_sdio_bus_preinit, |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 3986 | .txdata = brcmf_sdio_bus_txdata, |
| 3987 | .txctl = brcmf_sdio_bus_txctl, |
| 3988 | .rxctl = brcmf_sdio_bus_rxctl, |
| 3989 | .gettxq = brcmf_sdio_bus_gettxq, |
Hante Meuleman | 330b4e4 | 2014-10-28 14:56:05 +0100 | [diff] [blame] | 3990 | .wowl_config = brcmf_sdio_wowl_config |
Arend van Spriel | d9cb259 | 2012-12-05 15:25:54 +0100 | [diff] [blame] | 3991 | }; |
| 3992 | |
Arend van Spriel | bd0e1b1 | 2014-05-27 12:56:22 +0200 | [diff] [blame] | 3993 | static void brcmf_sdio_firmware_callback(struct device *dev, |
| 3994 | const struct firmware *code, |
| 3995 | void *nvram, u32 nvram_len) |
| 3996 | { |
| 3997 | struct brcmf_bus *bus_if = dev_get_drvdata(dev); |
| 3998 | struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio; |
| 3999 | struct brcmf_sdio *bus = sdiodev->bus; |
| 4000 | int err = 0; |
| 4001 | u8 saveclk; |
| 4002 | |
| 4003 | brcmf_dbg(TRACE, "Enter: dev=%s\n", dev_name(dev)); |
| 4004 | |
Arend van Spriel | bd0e1b1 | 2014-05-27 12:56:22 +0200 | [diff] [blame] | 4005 | if (!bus_if->drvr) |
| 4006 | return; |
| 4007 | |
Hante Meuleman | a1cee86 | 2015-01-25 20:31:35 +0100 | [diff] [blame] | 4008 | /* try to download image and nvram to the dongle */ |
| 4009 | bus->alp_only = true; |
| 4010 | err = brcmf_sdio_download_firmware(bus, code, nvram, nvram_len); |
| 4011 | if (err) |
| 4012 | goto fail; |
| 4013 | bus->alp_only = false; |
| 4014 | |
Arend van Spriel | bd0e1b1 | 2014-05-27 12:56:22 +0200 | [diff] [blame] | 4015 | /* Start the watchdog timer */ |
| 4016 | bus->sdcnt.tickcnt = 0; |
| 4017 | brcmf_sdio_wd_timer(bus, BRCMF_WD_POLL_MS); |
| 4018 | |
| 4019 | sdio_claim_host(sdiodev->func[1]); |
| 4020 | |
| 4021 | /* Make sure backplane clock is on, needed to generate F2 interrupt */ |
| 4022 | brcmf_sdio_clkctl(bus, CLK_AVAIL, false); |
| 4023 | if (bus->clkstate != CLK_AVAIL) |
| 4024 | goto release; |
| 4025 | |
| 4026 | /* Force clocks on backplane to be sure F2 interrupt propagates */ |
| 4027 | saveclk = brcmf_sdiod_regrb(sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, &err); |
| 4028 | if (!err) { |
| 4029 | brcmf_sdiod_regwb(sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, |
| 4030 | (saveclk | SBSDIO_FORCE_HT), &err); |
| 4031 | } |
| 4032 | if (err) { |
| 4033 | brcmf_err("Failed to force clock for F2: err %d\n", err); |
| 4034 | goto release; |
| 4035 | } |
| 4036 | |
| 4037 | /* Enable function 2 (frame transfers) */ |
| 4038 | w_sdreg32(bus, SDPCM_PROT_VERSION << SMB_DATA_VERSION_SHIFT, |
| 4039 | offsetof(struct sdpcmd_regs, tosbmailboxdata)); |
| 4040 | err = sdio_enable_func(sdiodev->func[SDIO_FUNC_2]); |
| 4041 | |
| 4042 | |
| 4043 | brcmf_dbg(INFO, "enable F2: err=%d\n", err); |
| 4044 | |
| 4045 | /* If F2 successfully enabled, set core and enable interrupts */ |
| 4046 | if (!err) { |
| 4047 | /* Set up the interrupt mask and enable interrupts */ |
| 4048 | bus->hostintmask = HOSTINTMASK; |
| 4049 | w_sdreg32(bus, bus->hostintmask, |
| 4050 | offsetof(struct sdpcmd_regs, hostintmask)); |
| 4051 | |
| 4052 | brcmf_sdiod_regwb(sdiodev, SBSDIO_WATERMARK, 8, &err); |
| 4053 | } else { |
| 4054 | /* Disable F2 again */ |
| 4055 | sdio_disable_func(sdiodev->func[SDIO_FUNC_2]); |
| 4056 | goto release; |
| 4057 | } |
| 4058 | |
| 4059 | if (brcmf_chip_sr_capable(bus->ci)) { |
| 4060 | brcmf_sdio_sr_init(bus); |
| 4061 | } else { |
| 4062 | /* Restore previous clock setting */ |
| 4063 | brcmf_sdiod_regwb(sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, |
| 4064 | saveclk, &err); |
| 4065 | } |
| 4066 | |
| 4067 | if (err == 0) { |
| 4068 | err = brcmf_sdiod_intr_register(sdiodev); |
| 4069 | if (err != 0) |
| 4070 | brcmf_err("intr register failed:%d\n", err); |
| 4071 | } |
| 4072 | |
| 4073 | /* If we didn't come up, turn off backplane clock */ |
| 4074 | if (err != 0) |
| 4075 | brcmf_sdio_clkctl(bus, CLK_NONE, false); |
| 4076 | |
| 4077 | sdio_release_host(sdiodev->func[1]); |
| 4078 | |
| 4079 | err = brcmf_bus_start(dev); |
| 4080 | if (err != 0) { |
| 4081 | brcmf_err("dongle is not responding\n"); |
| 4082 | goto fail; |
| 4083 | } |
| 4084 | return; |
| 4085 | |
| 4086 | release: |
| 4087 | sdio_release_host(sdiodev->func[1]); |
| 4088 | fail: |
| 4089 | brcmf_dbg(TRACE, "failed: dev=%s, err=%d\n", dev_name(dev), err); |
| 4090 | device_release_driver(dev); |
| 4091 | } |
| 4092 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 4093 | struct brcmf_sdio *brcmf_sdio_probe(struct brcmf_sdio_dev *sdiodev) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4094 | { |
| 4095 | int ret; |
Franky Lin | e92eedf | 2011-11-22 17:21:50 -0800 | [diff] [blame] | 4096 | struct brcmf_sdio *bus; |
Arend van Spriel | 9982464 | 2015-02-06 18:36:45 +0100 | [diff] [blame] | 4097 | struct workqueue_struct *wq; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4098 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4099 | brcmf_dbg(TRACE, "Enter\n"); |
| 4100 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4101 | /* Allocate private bus interface state */ |
Franky Lin | e92eedf | 2011-11-22 17:21:50 -0800 | [diff] [blame] | 4102 | bus = kzalloc(sizeof(struct brcmf_sdio), GFP_ATOMIC); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4103 | if (!bus) |
| 4104 | goto fail; |
| 4105 | |
| 4106 | bus->sdiodev = sdiodev; |
| 4107 | sdiodev->bus = bus; |
Arend van Spriel | b83db86 | 2011-10-19 12:51:09 +0200 | [diff] [blame] | 4108 | skb_queue_head_init(&bus->glom); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4109 | bus->txbound = BRCMF_TXBOUND; |
| 4110 | bus->rxbound = BRCMF_RXBOUND; |
| 4111 | bus->txminmax = BRCMF_TXMINMAX; |
Franky Lin | 6bc5231 | 2013-08-10 12:27:28 +0200 | [diff] [blame] | 4112 | bus->tx_seq = SDPCM_SEQ_WRAP - 1; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4113 | |
Arend van Spriel | e217d1c | 2013-11-29 12:25:13 +0100 | [diff] [blame] | 4114 | /* platform specific configuration: |
| 4115 | * alignments must be at least 4 bytes for ADMA |
Hante Meuleman | 888bf76e | 2014-10-28 14:56:17 +0100 | [diff] [blame] | 4116 | */ |
Arend van Spriel | e217d1c | 2013-11-29 12:25:13 +0100 | [diff] [blame] | 4117 | bus->head_align = ALIGNMENT; |
| 4118 | bus->sgentry_align = ALIGNMENT; |
| 4119 | if (sdiodev->pdata) { |
| 4120 | if (sdiodev->pdata->sd_head_align > ALIGNMENT) |
| 4121 | bus->head_align = sdiodev->pdata->sd_head_align; |
| 4122 | if (sdiodev->pdata->sd_sgentry_align > ALIGNMENT) |
| 4123 | bus->sgentry_align = sdiodev->pdata->sd_sgentry_align; |
| 4124 | } |
| 4125 | |
Arend van Spriel | 9982464 | 2015-02-06 18:36:45 +0100 | [diff] [blame] | 4126 | /* single-threaded workqueue */ |
| 4127 | wq = alloc_ordered_workqueue("brcmf_wq/%s", WQ_MEM_RECLAIM, |
| 4128 | dev_name(&sdiodev->func[1]->dev)); |
| 4129 | if (!wq) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 4130 | brcmf_err("insufficient memory to create txworkqueue\n"); |
Hante Meuleman | 37ac578 | 2012-11-14 18:46:18 -0800 | [diff] [blame] | 4131 | goto fail; |
| 4132 | } |
Arend van Spriel | 9982464 | 2015-02-06 18:36:45 +0100 | [diff] [blame] | 4133 | brcmf_sdiod_freezer_count(sdiodev); |
| 4134 | INIT_WORK(&bus->datawork, brcmf_sdio_dataworker); |
| 4135 | bus->brcmf_wq = wq; |
Hante Meuleman | 37ac578 | 2012-11-14 18:46:18 -0800 | [diff] [blame] | 4136 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4137 | /* attempt to attach to the dongle */ |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 4138 | if (!(brcmf_sdio_probe_attach(bus))) { |
| 4139 | brcmf_err("brcmf_sdio_probe_attach failed\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4140 | goto fail; |
| 4141 | } |
| 4142 | |
Franky Lin | dd43a01 | 2012-11-05 16:22:22 -0800 | [diff] [blame] | 4143 | spin_lock_init(&bus->rxctl_lock); |
Hante Meuleman | fed7ec4 | 2014-03-15 17:18:18 +0100 | [diff] [blame] | 4144 | spin_lock_init(&bus->txq_lock); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4145 | init_waitqueue_head(&bus->ctrl_wait); |
| 4146 | init_waitqueue_head(&bus->dcmd_resp_wait); |
| 4147 | |
| 4148 | /* Set up the watchdog timer */ |
| 4149 | init_timer(&bus->timer); |
| 4150 | bus->timer.data = (unsigned long)bus; |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 4151 | bus->timer.function = brcmf_sdio_watchdog; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4152 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4153 | /* Initialize watchdog thread */ |
| 4154 | init_completion(&bus->watchdog_wait); |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 4155 | bus->watchdog_tsk = kthread_run(brcmf_sdio_watchdog_thread, |
Arend van Spriel | 9982464 | 2015-02-06 18:36:45 +0100 | [diff] [blame] | 4156 | bus, "brcmf_wdog/%s", |
| 4157 | dev_name(&sdiodev->func[1]->dev)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4158 | if (IS_ERR(bus->watchdog_tsk)) { |
Joe Perches | 02f7719 | 2012-01-15 00:38:44 -0800 | [diff] [blame] | 4159 | pr_warn("brcmf_watchdog thread failed to start\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4160 | bus->watchdog_tsk = NULL; |
| 4161 | } |
| 4162 | /* Initialize DPC thread */ |
Hante Meuleman | 2c64e16 | 2015-03-18 13:25:22 +0100 | [diff] [blame] | 4163 | bus->dpc_triggered = false; |
| 4164 | bus->dpc_running = false; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4165 | |
Franky Lin | a9ffda8 | 2011-12-16 18:37:12 -0800 | [diff] [blame] | 4166 | /* Assign bus interface call back */ |
Arend van Spriel | d9cb259 | 2012-12-05 15:25:54 +0100 | [diff] [blame] | 4167 | bus->sdiodev->bus_if->dev = bus->sdiodev->dev; |
| 4168 | bus->sdiodev->bus_if->ops = &brcmf_sdio_bus_ops; |
Arend van Spriel | 75d907d | 2013-02-06 18:40:45 +0100 | [diff] [blame] | 4169 | bus->sdiodev->bus_if->chip = bus->ci->chip; |
| 4170 | bus->sdiodev->bus_if->chiprev = bus->ci->chiprev; |
Arend van Spriel | d9cb259 | 2012-12-05 15:25:54 +0100 | [diff] [blame] | 4171 | |
Franky Lin | 706478c | 2013-08-10 12:27:29 +0200 | [diff] [blame] | 4172 | /* default sdio bus header length for tx packet */ |
| 4173 | bus->tx_hdrlen = SDPCM_HWHDR_LEN + SDPCM_SWHDR_LEN; |
| 4174 | |
| 4175 | /* Attach to the common layer, reserve hdr space */ |
Arend van Spriel | 8dee77b | 2013-11-29 11:48:14 +0100 | [diff] [blame] | 4176 | ret = brcmf_attach(bus->sdiodev->dev); |
Franky Lin | 712ac5b | 2011-12-16 18:37:09 -0800 | [diff] [blame] | 4177 | if (ret != 0) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 4178 | brcmf_err("brcmf_attach failed\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4179 | goto fail; |
| 4180 | } |
| 4181 | |
Daniel Kim | 7dd3abc | 2014-05-27 12:56:26 +0200 | [diff] [blame] | 4182 | /* Query the F2 block size, set roundup accordingly */ |
| 4183 | bus->blocksize = bus->sdiodev->func[2]->cur_blksize; |
| 4184 | bus->roundup = min(max_roundup, bus->blocksize); |
| 4185 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4186 | /* Allocate buffers */ |
Arend van Spriel | fad1322 | 2014-01-06 12:40:40 +0100 | [diff] [blame] | 4187 | if (bus->sdiodev->bus_if->maxctl) { |
Daniel Kim | 7dd3abc | 2014-05-27 12:56:26 +0200 | [diff] [blame] | 4188 | bus->sdiodev->bus_if->maxctl += bus->roundup; |
Arend van Spriel | fad1322 | 2014-01-06 12:40:40 +0100 | [diff] [blame] | 4189 | bus->rxblen = |
| 4190 | roundup((bus->sdiodev->bus_if->maxctl + SDPCM_HDRLEN), |
| 4191 | ALIGNMENT) + bus->head_align; |
| 4192 | bus->rxbuf = kmalloc(bus->rxblen, GFP_ATOMIC); |
| 4193 | if (!(bus->rxbuf)) { |
| 4194 | brcmf_err("rxbuf allocation failed\n"); |
| 4195 | goto fail; |
| 4196 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4197 | } |
| 4198 | |
Arend van Spriel | fad1322 | 2014-01-06 12:40:40 +0100 | [diff] [blame] | 4199 | sdio_claim_host(bus->sdiodev->func[1]); |
| 4200 | |
| 4201 | /* Disable F2 to clear any intermediate frame state on the dongle */ |
| 4202 | sdio_disable_func(bus->sdiodev->func[SDIO_FUNC_2]); |
| 4203 | |
Arend van Spriel | fad1322 | 2014-01-06 12:40:40 +0100 | [diff] [blame] | 4204 | bus->rxflow = false; |
| 4205 | |
| 4206 | /* Done with backplane-dependent accesses, can drop clock... */ |
| 4207 | brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, 0, NULL); |
| 4208 | |
| 4209 | sdio_release_host(bus->sdiodev->func[1]); |
| 4210 | |
| 4211 | /* ...and initialize clock/power states */ |
| 4212 | bus->clkstate = CLK_SDONLY; |
| 4213 | bus->idletime = BRCMF_IDLE_INTERVAL; |
| 4214 | bus->idleclock = BRCMF_IDLE_ACTIVE; |
| 4215 | |
Arend van Spriel | fad1322 | 2014-01-06 12:40:40 +0100 | [diff] [blame] | 4216 | /* SR state */ |
Arend van Spriel | fad1322 | 2014-01-06 12:40:40 +0100 | [diff] [blame] | 4217 | bus->sr_enabled = false; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4218 | |
Arend van Spriel | 8096983 | 2012-06-09 22:51:44 +0200 | [diff] [blame] | 4219 | brcmf_sdio_debugfs_create(bus); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4220 | brcmf_dbg(INFO, "completed!!\n"); |
| 4221 | |
Daniel Kim | c1b2053 | 2014-07-12 08:49:37 +0200 | [diff] [blame] | 4222 | ret = brcmf_sdio_get_fwnames(bus->ci, sdiodev); |
| 4223 | if (ret) |
| 4224 | goto fail; |
| 4225 | |
Arend van Spriel | bd0e1b1 | 2014-05-27 12:56:22 +0200 | [diff] [blame] | 4226 | ret = brcmf_fw_get_firmwares(sdiodev->dev, BRCMF_FW_REQUEST_NVRAM, |
Daniel Kim | c1b2053 | 2014-07-12 08:49:37 +0200 | [diff] [blame] | 4227 | sdiodev->fw_name, sdiodev->nvram_name, |
Arend van Spriel | bd0e1b1 | 2014-05-27 12:56:22 +0200 | [diff] [blame] | 4228 | brcmf_sdio_firmware_callback); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4229 | if (ret != 0) { |
Arend van Spriel | bd0e1b1 | 2014-05-27 12:56:22 +0200 | [diff] [blame] | 4230 | brcmf_err("async firmware request failed: %d\n", ret); |
Hante Meuleman | 1799ddf | 2012-11-14 18:46:17 -0800 | [diff] [blame] | 4231 | goto fail; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4232 | } |
Franky Lin | 15d45b6 | 2011-10-21 16:16:32 +0200 | [diff] [blame] | 4233 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4234 | return bus; |
| 4235 | |
| 4236 | fail: |
Arend van Spriel | 9fbe2a6 | 2013-12-12 11:59:05 +0100 | [diff] [blame] | 4237 | brcmf_sdio_remove(bus); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4238 | return NULL; |
| 4239 | } |
| 4240 | |
Arend van Spriel | 9fbe2a6 | 2013-12-12 11:59:05 +0100 | [diff] [blame] | 4241 | /* Detach and free everything */ |
| 4242 | void brcmf_sdio_remove(struct brcmf_sdio *bus) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4243 | { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4244 | brcmf_dbg(TRACE, "Enter\n"); |
| 4245 | |
Arend van Spriel | 9fbe2a6 | 2013-12-12 11:59:05 +0100 | [diff] [blame] | 4246 | if (bus) { |
| 4247 | /* De-register interrupt handler */ |
| 4248 | brcmf_sdiod_intr_unregister(bus->sdiodev); |
| 4249 | |
Arend van Spriel | 4faf28b | 2014-05-27 12:56:18 +0200 | [diff] [blame] | 4250 | brcmf_detach(bus->sdiodev->dev); |
Arend van Spriel | bfad4a0 | 2014-01-06 12:40:39 +0100 | [diff] [blame] | 4251 | |
Hante Meuleman | e0c180ec | 2014-01-29 15:32:18 +0100 | [diff] [blame] | 4252 | cancel_work_sync(&bus->datawork); |
| 4253 | if (bus->brcmf_wq) |
| 4254 | destroy_workqueue(bus->brcmf_wq); |
| 4255 | |
Arend van Spriel | bfad4a0 | 2014-01-06 12:40:39 +0100 | [diff] [blame] | 4256 | if (bus->ci) { |
Arend van Spriel | a1ce7a0 | 2015-02-06 18:36:42 +0100 | [diff] [blame] | 4257 | if (bus->sdiodev->state != BRCMF_SDIOD_NOMEDIUM) { |
Arend van Spriel | bb35071 | 2014-01-13 22:20:29 +0100 | [diff] [blame] | 4258 | sdio_claim_host(bus->sdiodev->func[1]); |
Arend van Spriel | cf45932 | 2015-03-11 16:11:33 +0100 | [diff] [blame] | 4259 | brcmf_sdio_wd_timer(bus, 0); |
Arend van Spriel | bb35071 | 2014-01-13 22:20:29 +0100 | [diff] [blame] | 4260 | brcmf_sdio_clkctl(bus, CLK_AVAIL, false); |
| 4261 | /* Leave the device in state where it is |
Arend van Spriel | d380ebc | 2015-03-11 16:11:29 +0100 | [diff] [blame] | 4262 | * 'passive'. This is done by resetting all |
| 4263 | * necessary cores. |
Arend van Spriel | bb35071 | 2014-01-13 22:20:29 +0100 | [diff] [blame] | 4264 | */ |
| 4265 | msleep(20); |
Arend van Spriel | d380ebc | 2015-03-11 16:11:29 +0100 | [diff] [blame] | 4266 | brcmf_chip_set_passive(bus->ci); |
Arend van Spriel | bb35071 | 2014-01-13 22:20:29 +0100 | [diff] [blame] | 4267 | brcmf_sdio_clkctl(bus, CLK_NONE, false); |
| 4268 | sdio_release_host(bus->sdiodev->func[1]); |
| 4269 | } |
Arend van Spriel | cb7cf7b | 2014-01-29 15:32:19 +0100 | [diff] [blame] | 4270 | brcmf_chip_detach(bus->ci); |
Arend van Spriel | 9fbe2a6 | 2013-12-12 11:59:05 +0100 | [diff] [blame] | 4271 | } |
| 4272 | |
Arend van Spriel | bfad4a0 | 2014-01-06 12:40:39 +0100 | [diff] [blame] | 4273 | kfree(bus->rxbuf); |
Arend van Spriel | 9fbe2a6 | 2013-12-12 11:59:05 +0100 | [diff] [blame] | 4274 | kfree(bus->hdrbuf); |
| 4275 | kfree(bus); |
| 4276 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4277 | |
| 4278 | brcmf_dbg(TRACE, "Disconnected\n"); |
| 4279 | } |
| 4280 | |
Arend van Spriel | 82d7f3c | 2013-12-12 11:59:04 +0100 | [diff] [blame] | 4281 | void brcmf_sdio_wd_timer(struct brcmf_sdio *bus, uint wdtick) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4282 | { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4283 | /* Totally stop the timer */ |
Joe Perches | 23677ce | 2012-02-09 11:17:23 +0000 | [diff] [blame] | 4284 | if (!wdtick && bus->wd_timer_valid) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4285 | del_timer_sync(&bus->timer); |
| 4286 | bus->wd_timer_valid = false; |
| 4287 | bus->save_ms = wdtick; |
| 4288 | return; |
| 4289 | } |
| 4290 | |
Franky Lin | ece960e | 2011-10-21 16:16:19 +0200 | [diff] [blame] | 4291 | /* don't start the wd until fw is loaded */ |
Arend van Spriel | a1ce7a0 | 2015-02-06 18:36:42 +0100 | [diff] [blame] | 4292 | if (bus->sdiodev->state != BRCMF_SDIOD_DATA) |
Franky Lin | ece960e | 2011-10-21 16:16:19 +0200 | [diff] [blame] | 4293 | return; |
| 4294 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4295 | if (wdtick) { |
| 4296 | if (bus->save_ms != BRCMF_WD_POLL_MS) { |
Joe Perches | 23677ce | 2012-02-09 11:17:23 +0000 | [diff] [blame] | 4297 | if (bus->wd_timer_valid) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4298 | /* Stop timer and restart at new value */ |
| 4299 | del_timer_sync(&bus->timer); |
| 4300 | |
| 4301 | /* Create timer again when watchdog period is |
| 4302 | dynamically changed or in the first instance |
| 4303 | */ |
| 4304 | bus->timer.expires = |
Nicholas Mc Guire | 187d3c3 | 2015-02-06 05:26:45 -0500 | [diff] [blame] | 4305 | jiffies + msecs_to_jiffies(BRCMF_WD_POLL_MS); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4306 | add_timer(&bus->timer); |
| 4307 | |
| 4308 | } else { |
| 4309 | /* Re arm the timer, at last watchdog period */ |
| 4310 | mod_timer(&bus->timer, |
Nicholas Mc Guire | 187d3c3 | 2015-02-06 05:26:45 -0500 | [diff] [blame] | 4311 | jiffies + msecs_to_jiffies(BRCMF_WD_POLL_MS)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4312 | } |
| 4313 | |
| 4314 | bus->wd_timer_valid = true; |
| 4315 | bus->save_ms = wdtick; |
| 4316 | } |
| 4317 | } |
Arend van Spriel | 9982464 | 2015-02-06 18:36:45 +0100 | [diff] [blame] | 4318 | |
| 4319 | int brcmf_sdio_sleep(struct brcmf_sdio *bus, bool sleep) |
| 4320 | { |
| 4321 | int ret; |
| 4322 | |
| 4323 | sdio_claim_host(bus->sdiodev->func[1]); |
| 4324 | ret = brcmf_sdio_bus_sleep(bus, sleep, false); |
| 4325 | sdio_release_host(bus->sdiodev->func[1]); |
| 4326 | |
| 4327 | return ret; |
| 4328 | } |
| 4329 | |