Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [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 | |
Greg Kroah-Hartman | a1c16ed | 2010-10-21 11:17:44 -0700 | [diff] [blame] | 17 | #include <linux/types.h> |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 18 | #include <linux/kernel.h> |
| 19 | #include <linux/printk.h> |
Stanislav Fomichev | be1c09f | 2011-03-28 01:31:36 +0400 | [diff] [blame] | 20 | #include <linux/pci_ids.h> |
Brett Rudley | c6ac24e | 2010-10-26 11:55:23 -0700 | [diff] [blame] | 21 | #include <linux/netdevice.h> |
Franky Lin | 7c6100e | 2011-06-01 13:45:36 +0200 | [diff] [blame] | 22 | #include <linux/sched.h> |
Franky Lin | 0df4604 | 2011-06-01 13:45:40 +0200 | [diff] [blame] | 23 | #include <linux/mmc/sdio.h> |
Franky Lin | 7c6100e | 2011-06-01 13:45:36 +0200 | [diff] [blame] | 24 | #include <asm/unaligned.h> |
Roland Vossen | cc3cea5 | 2011-06-01 13:45:59 +0200 | [diff] [blame] | 25 | #include <defs.h> |
Roland Vossen | f97e956 | 2011-06-01 13:45:52 +0200 | [diff] [blame] | 26 | #include <brcmu_wifi.h> |
| 27 | #include <brcmu_utils.h> |
Roland Vossen | cc3cea5 | 2011-06-01 13:45:59 +0200 | [diff] [blame] | 28 | #include <brcm_hw_ids.h> |
Roland Vossen | cc3cea5 | 2011-06-01 13:45:59 +0200 | [diff] [blame] | 29 | #include <soc.h> |
Roland Vossen | c4daa84 | 2011-06-09 16:44:50 +0200 | [diff] [blame] | 30 | #include "sdio_host.h" |
Roland Vossen | 4489518 | 2011-06-01 13:45:55 +0200 | [diff] [blame] | 31 | |
| 32 | /* register access macros */ |
Roland Vossen | 4489518 | 2011-06-01 13:45:55 +0200 | [diff] [blame] | 33 | #ifndef __BIG_ENDIAN |
| 34 | #ifndef __mips__ |
Roland Vossen | b61a4be | 2011-06-01 13:45:56 +0200 | [diff] [blame] | 35 | #define R_REG(r) \ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 36 | brcmf_sdcard_reg_read(NULL, (unsigned long)(r), sizeof(*(r))) |
Roland Vossen | 4489518 | 2011-06-01 13:45:55 +0200 | [diff] [blame] | 37 | #else /* __mips__ */ |
Roland Vossen | b61a4be | 2011-06-01 13:45:56 +0200 | [diff] [blame] | 38 | #define R_REG(r) \ |
| 39 | ({ \ |
| 40 | __typeof(*(r)) __osl_v; \ |
| 41 | __asm__ __volatile__("sync"); \ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 42 | __osl_v = brcmf_sdcard_reg_read(NULL, (unsigned long)(r),\ |
Roland Vossen | 2503634 | 2011-06-01 13:45:57 +0200 | [diff] [blame] | 43 | sizeof(*(r))); \ |
Roland Vossen | b61a4be | 2011-06-01 13:45:56 +0200 | [diff] [blame] | 44 | __asm__ __volatile__("sync"); \ |
| 45 | __osl_v; \ |
| 46 | }) |
Roland Vossen | 4489518 | 2011-06-01 13:45:55 +0200 | [diff] [blame] | 47 | #endif /* __mips__ */ |
| 48 | |
| 49 | #define W_REG(r, v) do { \ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 50 | brcmf_sdcard_reg_write(NULL, (unsigned long)(r), sizeof(*(r)), \ |
| 51 | (v)); \ |
Roland Vossen | 4489518 | 2011-06-01 13:45:55 +0200 | [diff] [blame] | 52 | } while (0) |
| 53 | #else /* __BIG_ENDIAN */ |
Roland Vossen | b61a4be | 2011-06-01 13:45:56 +0200 | [diff] [blame] | 54 | #define R_REG(r) \ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 55 | brcmf_sdcard_reg_read(NULL, (unsigned long)(r), sizeof(*(r))) |
Roland Vossen | 4489518 | 2011-06-01 13:45:55 +0200 | [diff] [blame] | 56 | #define W_REG(r, v) do { \ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 57 | brcmf_sdcard_reg_write(NULL, (unsigned long)(r), sizeof(*(r)), \ |
| 58 | (v)); \ |
Roland Vossen | 4489518 | 2011-06-01 13:45:55 +0200 | [diff] [blame] | 59 | } while (0) |
| 60 | #endif /* __BIG_ENDIAN */ |
| 61 | |
Roland Vossen | 4489518 | 2011-06-01 13:45:55 +0200 | [diff] [blame] | 62 | #define AND_REG(r, v) W_REG((r), R_REG(r) & (v)) |
| 63 | #define OR_REG(r, v) W_REG((r), R_REG(r) | (v)) |
| 64 | |
| 65 | #define SET_REG(r, mask, val) \ |
| 66 | W_REG((r), ((R_REG(r) & ~(mask)) | (val))) |
| 67 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 68 | #ifdef DHD_DEBUG |
Roland Vossen | f1c7a08 | 2011-06-01 13:45:09 +0200 | [diff] [blame] | 69 | |
| 70 | /* ARM trap handling */ |
| 71 | |
| 72 | /* Trap types defined by ARM (see arminc.h) */ |
| 73 | |
| 74 | /* Trap locations in lo memory */ |
| 75 | #define TRAP_STRIDE 4 |
| 76 | #define FIRST_TRAP TR_RST |
| 77 | #define LAST_TRAP (TR_FIQ * TRAP_STRIDE) |
| 78 | |
| 79 | #if defined(__ARM_ARCH_4T__) |
| 80 | #define MAX_TRAP_TYPE (TR_FIQ + 1) |
| 81 | #elif defined(__ARM_ARCH_7M__) |
| 82 | #define MAX_TRAP_TYPE (TR_ISR + ARMCM3_NUMINTS) |
| 83 | #endif /* __ARM_ARCH_7M__ */ |
| 84 | |
| 85 | /* The trap structure is defined here as offsets for assembly */ |
| 86 | #define TR_TYPE 0x00 |
| 87 | #define TR_EPC 0x04 |
| 88 | #define TR_CPSR 0x08 |
| 89 | #define TR_SPSR 0x0c |
| 90 | #define TR_REGS 0x10 |
| 91 | #define TR_REG(n) (TR_REGS + (n) * 4) |
| 92 | #define TR_SP TR_REG(13) |
| 93 | #define TR_LR TR_REG(14) |
| 94 | #define TR_PC TR_REG(15) |
| 95 | |
| 96 | #define TRAP_T_SIZE 80 |
| 97 | |
Roland Vossen | f1c7a08 | 2011-06-01 13:45:09 +0200 | [diff] [blame] | 98 | typedef struct _trap_struct { |
| 99 | u32 type; |
| 100 | u32 epc; |
| 101 | u32 cpsr; |
| 102 | u32 spsr; |
| 103 | u32 r0; |
| 104 | u32 r1; |
| 105 | u32 r2; |
| 106 | u32 r3; |
| 107 | u32 r4; |
| 108 | u32 r5; |
| 109 | u32 r6; |
| 110 | u32 r7; |
| 111 | u32 r8; |
| 112 | u32 r9; |
| 113 | u32 r10; |
| 114 | u32 r11; |
| 115 | u32 r12; |
| 116 | u32 r13; |
| 117 | u32 r14; |
| 118 | u32 pc; |
| 119 | } trap_t; |
| 120 | |
Roland Vossen | f1c7a08 | 2011-06-01 13:45:09 +0200 | [diff] [blame] | 121 | #define CBUF_LEN (128) |
| 122 | |
| 123 | #define LOG_BUF_LEN 1024 |
| 124 | |
| 125 | typedef struct { |
| 126 | u32 buf; /* Can't be pointer on (64-bit) hosts */ |
| 127 | uint buf_size; |
| 128 | uint idx; |
| 129 | char *_buf_compat; /* Redundant pointer for backward compat. */ |
| 130 | } rte_log_t; |
| 131 | |
| 132 | typedef struct { |
| 133 | /* Virtual UART |
| 134 | * When there is no UART (e.g. Quickturn), |
| 135 | * the host should write a complete |
| 136 | * input line directly into cbuf and then write |
| 137 | * the length into vcons_in. |
| 138 | * This may also be used when there is a real UART |
| 139 | * (at risk of conflicting with |
| 140 | * the real UART). vcons_out is currently unused. |
| 141 | */ |
| 142 | volatile uint vcons_in; |
| 143 | volatile uint vcons_out; |
| 144 | |
| 145 | /* Output (logging) buffer |
| 146 | * Console output is written to a ring buffer log_buf at index log_idx. |
| 147 | * The host may read the output when it sees log_idx advance. |
| 148 | * Output will be lost if the output wraps around faster than the host |
| 149 | * polls. |
| 150 | */ |
| 151 | rte_log_t log; |
| 152 | |
| 153 | /* Console input line buffer |
| 154 | * Characters are read one at a time into cbuf |
| 155 | * until <CR> is received, then |
| 156 | * the buffer is processed as a command line. |
| 157 | * Also used for virtual UART. |
| 158 | */ |
| 159 | uint cbuf_idx; |
| 160 | char cbuf[CBUF_LEN]; |
| 161 | } rte_cons_t; |
| 162 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 163 | #endif /* DHD_DEBUG */ |
Roland Vossen | 745c9e6 | 2011-06-01 13:45:30 +0200 | [diff] [blame] | 164 | #include <chipcommon.h> |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 165 | |
Roland Vossen | c4daa84 | 2011-06-09 16:44:50 +0200 | [diff] [blame] | 166 | #include "sbsdio.h" |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 167 | |
Roland Vossen | c4daa84 | 2011-06-09 16:44:50 +0200 | [diff] [blame] | 168 | #include "dngl_stats.h" |
| 169 | #include "dhd.h" |
| 170 | #include "dhd_bus.h" |
| 171 | #include "dhd_proto.h" |
| 172 | #include "dhd_dbg.h" |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 173 | #include <sdiovar.h> |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 174 | #include <bcmchip.h> |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 175 | |
| 176 | #ifndef DHDSDIO_MEM_DUMP_FNAME |
| 177 | #define DHDSDIO_MEM_DUMP_FNAME "mem_dump" |
| 178 | #endif |
| 179 | |
Grant Grundler | 26a71a4 | 2011-03-09 10:41:25 -0800 | [diff] [blame] | 180 | #define TXQLEN 2048 /* bulk tx queue length */ |
| 181 | #define TXHI (TXQLEN - 256) /* turn on flow control above TXHI */ |
| 182 | #define TXLOW (TXHI - 256) /* turn off flow control below TXLOW */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 183 | #define PRIOMASK 7 |
| 184 | |
| 185 | #define TXRETRIES 2 /* # of retries for tx frames */ |
| 186 | |
| 187 | #if defined(CONFIG_MACH_SANDGATE2G) |
| 188 | #define DHD_RXBOUND 250 /* Default for max rx frames in |
| 189 | one scheduling */ |
| 190 | #else |
| 191 | #define DHD_RXBOUND 50 /* Default for max rx frames in |
| 192 | one scheduling */ |
| 193 | #endif /* defined(CONFIG_MACH_SANDGATE2G) */ |
| 194 | |
| 195 | #define DHD_TXBOUND 20 /* Default for max tx frames in |
| 196 | one scheduling */ |
| 197 | |
| 198 | #define DHD_TXMINMAX 1 /* Max tx frames if rx still pending */ |
| 199 | |
| 200 | #define MEMBLOCK 2048 /* Block size used for downloading |
| 201 | of dongle image */ |
| 202 | #define MAX_DATA_BUF (32 * 1024) /* Must be large enough to hold |
| 203 | biggest possible glom */ |
| 204 | |
| 205 | /* Packet alignment for most efficient SDIO (can change based on platform) */ |
| 206 | #ifndef DHD_SDALIGN |
| 207 | #define DHD_SDALIGN 32 |
| 208 | #endif |
| 209 | #if !ISPOWEROF2(DHD_SDALIGN) |
| 210 | #error DHD_SDALIGN is not a power of 2! |
| 211 | #endif |
| 212 | |
| 213 | #ifndef DHD_FIRSTREAD |
| 214 | #define DHD_FIRSTREAD 32 |
| 215 | #endif |
| 216 | #if !ISPOWEROF2(DHD_FIRSTREAD) |
| 217 | #error DHD_FIRSTREAD is not a power of 2! |
| 218 | #endif |
| 219 | |
| 220 | /* Total length of frame header for dongle protocol */ |
| 221 | #define SDPCM_HDRLEN (SDPCM_FRAMETAG_LEN + SDPCM_SWHEADER_LEN) |
| 222 | #ifdef SDTEST |
| 223 | #define SDPCM_RESERVE (SDPCM_HDRLEN + SDPCM_TEST_HDRLEN + DHD_SDALIGN) |
| 224 | #else |
| 225 | #define SDPCM_RESERVE (SDPCM_HDRLEN + DHD_SDALIGN) |
| 226 | #endif |
| 227 | |
Franky Lin | b49b14d | 2011-06-01 13:45:37 +0200 | [diff] [blame] | 228 | /* |
| 229 | * Software allocation of To SB Mailbox resources |
| 230 | */ |
| 231 | |
| 232 | /* tosbmailbox bits corresponding to intstatus bits */ |
| 233 | #define SMB_NAK (1 << 0) /* Frame NAK */ |
| 234 | #define SMB_INT_ACK (1 << 1) /* Host Interrupt ACK */ |
| 235 | #define SMB_USE_OOB (1 << 2) /* Use OOB Wakeup */ |
| 236 | #define SMB_DEV_INT (1 << 3) /* Miscellaneous Interrupt */ |
| 237 | |
| 238 | /* tosbmailboxdata */ |
| 239 | #define SMB_DATA_VERSION_SHIFT 16 /* host protocol version */ |
| 240 | |
| 241 | /* |
| 242 | * Software allocation of To Host Mailbox resources |
| 243 | */ |
| 244 | |
| 245 | /* intstatus bits */ |
| 246 | #define I_HMB_FC_STATE I_HMB_SW0 /* Flow Control State */ |
| 247 | #define I_HMB_FC_CHANGE I_HMB_SW1 /* Flow Control State Changed */ |
| 248 | #define I_HMB_FRAME_IND I_HMB_SW2 /* Frame Indication */ |
| 249 | #define I_HMB_HOST_INT I_HMB_SW3 /* Miscellaneous Interrupt */ |
| 250 | |
| 251 | /* tohostmailboxdata */ |
| 252 | #define HMB_DATA_NAKHANDLED 1 /* retransmit NAK'd frame */ |
| 253 | #define HMB_DATA_DEVREADY 2 /* talk to host after enable */ |
| 254 | #define HMB_DATA_FC 4 /* per prio flowcontrol update flag */ |
| 255 | #define HMB_DATA_FWREADY 8 /* fw ready for protocol activity */ |
| 256 | |
| 257 | #define HMB_DATA_FCDATA_MASK 0xff000000 |
| 258 | #define HMB_DATA_FCDATA_SHIFT 24 |
| 259 | |
| 260 | #define HMB_DATA_VERSION_MASK 0x00ff0000 |
| 261 | #define HMB_DATA_VERSION_SHIFT 16 |
| 262 | |
| 263 | /* |
| 264 | * Software-defined protocol header |
| 265 | */ |
| 266 | |
| 267 | /* Current protocol version */ |
| 268 | #define SDPCM_PROT_VERSION 4 |
| 269 | |
| 270 | /* SW frame header */ |
| 271 | #define SDPCM_PACKET_SEQUENCE(p) (((u8 *)p)[0] & 0xff) |
| 272 | |
| 273 | #define SDPCM_CHANNEL_MASK 0x00000f00 |
| 274 | #define SDPCM_CHANNEL_SHIFT 8 |
| 275 | #define SDPCM_PACKET_CHANNEL(p) (((u8 *)p)[1] & 0x0f) |
| 276 | |
| 277 | #define SDPCM_NEXTLEN_OFFSET 2 |
| 278 | |
| 279 | /* Data Offset from SOF (HW Tag, SW Tag, Pad) */ |
| 280 | #define SDPCM_DOFFSET_OFFSET 3 /* Data Offset */ |
| 281 | #define SDPCM_DOFFSET_VALUE(p) (((u8 *)p)[SDPCM_DOFFSET_OFFSET] & 0xff) |
| 282 | #define SDPCM_DOFFSET_MASK 0xff000000 |
| 283 | #define SDPCM_DOFFSET_SHIFT 24 |
| 284 | #define SDPCM_FCMASK_OFFSET 4 /* Flow control */ |
| 285 | #define SDPCM_FCMASK_VALUE(p) (((u8 *)p)[SDPCM_FCMASK_OFFSET] & 0xff) |
| 286 | #define SDPCM_WINDOW_OFFSET 5 /* Credit based fc */ |
| 287 | #define SDPCM_WINDOW_VALUE(p) (((u8 *)p)[SDPCM_WINDOW_OFFSET] & 0xff) |
| 288 | |
| 289 | #define SDPCM_SWHEADER_LEN 8 /* SW header is 64 bits */ |
| 290 | |
| 291 | /* logical channel numbers */ |
| 292 | #define SDPCM_CONTROL_CHANNEL 0 /* Control channel Id */ |
| 293 | #define SDPCM_EVENT_CHANNEL 1 /* Asyc Event Indication Channel Id */ |
| 294 | #define SDPCM_DATA_CHANNEL 2 /* Data Xmit/Recv Channel Id */ |
| 295 | #define SDPCM_GLOM_CHANNEL 3 /* For coalesced packets */ |
| 296 | #define SDPCM_TEST_CHANNEL 15 /* Reserved for test/debug packets */ |
| 297 | |
| 298 | #define SDPCM_SEQUENCE_WRAP 256 /* wrap-around val for 8bit frame seq */ |
| 299 | |
| 300 | #define SDPCM_GLOMDESC(p) (((u8 *)p)[1] & 0x80) |
| 301 | |
| 302 | /* For TEST_CHANNEL packets, define another 4-byte header */ |
| 303 | #define SDPCM_TEST_HDRLEN 4 /* |
| 304 | * Generally: Cmd(1), Ext(1), Len(2); |
| 305 | * Semantics of Ext byte depend on |
| 306 | * command. Len is current or requested |
| 307 | * frame length, not including test |
| 308 | * header; sent little-endian. |
| 309 | */ |
| 310 | #define SDPCM_TEST_DISCARD 0x01 /* Receiver discards. Ext:pattern id. */ |
| 311 | #define SDPCM_TEST_ECHOREQ 0x02 /* Echo request. Ext:pattern id. */ |
| 312 | #define SDPCM_TEST_ECHORSP 0x03 /* Echo response. Ext:pattern id. */ |
| 313 | #define SDPCM_TEST_BURST 0x04 /* |
| 314 | * Receiver to send a burst. |
| 315 | * Ext is a frame count |
| 316 | */ |
| 317 | #define SDPCM_TEST_SEND 0x05 /* |
| 318 | * Receiver sets send mode. |
| 319 | * Ext is boolean on/off |
| 320 | */ |
| 321 | |
| 322 | /* Handy macro for filling in datagen packets with a pattern */ |
| 323 | #define SDPCM_TEST_FILL(byteno, id) ((u8)(id + byteno)) |
| 324 | |
| 325 | /* |
| 326 | * Shared structure between dongle and the host. |
| 327 | * The structure contains pointers to trap or assert information. |
| 328 | */ |
| 329 | #define SDPCM_SHARED_VERSION 0x0002 |
| 330 | #define SDPCM_SHARED_VERSION_MASK 0x00FF |
| 331 | #define SDPCM_SHARED_ASSERT_BUILT 0x0100 |
| 332 | #define SDPCM_SHARED_ASSERT 0x0200 |
| 333 | #define SDPCM_SHARED_TRAP 0x0400 |
| 334 | |
| 335 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 336 | /* Space for header read, limit for data packets */ |
| 337 | #ifndef MAX_HDR_READ |
| 338 | #define MAX_HDR_READ 32 |
| 339 | #endif |
| 340 | #if !ISPOWEROF2(MAX_HDR_READ) |
| 341 | #error MAX_HDR_READ is not a power of 2! |
| 342 | #endif |
| 343 | |
| 344 | #define MAX_RX_DATASZ 2048 |
| 345 | |
| 346 | /* Maximum milliseconds to wait for F2 to come up */ |
| 347 | #define DHD_WAIT_F2RDY 3000 |
| 348 | |
| 349 | /* Bump up limit on waiting for HT to account for first startup; |
| 350 | * if the image is doing a CRC calculation before programming the PMU |
| 351 | * for HT availability, it could take a couple hundred ms more, so |
| 352 | * max out at a 1 second (1000000us). |
| 353 | */ |
| 354 | #if (PMU_MAX_TRANSITION_DLY <= 1000000) |
| 355 | #undef PMU_MAX_TRANSITION_DLY |
| 356 | #define PMU_MAX_TRANSITION_DLY 1000000 |
| 357 | #endif |
| 358 | |
| 359 | /* Value for ChipClockCSR during initial setup */ |
| 360 | #define DHD_INIT_CLKCTL1 (SBSDIO_FORCE_HW_CLKREQ_OFF | \ |
| 361 | SBSDIO_ALP_AVAIL_REQ) |
| 362 | #define DHD_INIT_CLKCTL2 (SBSDIO_FORCE_HW_CLKREQ_OFF | SBSDIO_FORCE_ALP) |
| 363 | |
| 364 | /* Flags for SDH calls */ |
| 365 | #define F2SYNC (SDIO_REQ_4BYTE | SDIO_REQ_FIXED) |
| 366 | |
Roland Vossen | b6fe70c | 2011-06-01 13:45:19 +0200 | [diff] [blame] | 367 | /* sbimstate */ |
| 368 | #define SBIM_IBE 0x20000 /* inbanderror */ |
| 369 | #define SBIM_TO 0x40000 /* timeout */ |
| 370 | #define SBIM_BY 0x01800000 /* busy (sonics >= 2.3) */ |
| 371 | #define SBIM_RJ 0x02000000 /* reject (sonics >= 2.3) */ |
| 372 | |
| 373 | /* sbtmstatelow */ |
| 374 | #define SBTML_RESET 0x0001 /* reset */ |
| 375 | #define SBTML_REJ_MASK 0x0006 /* reject field */ |
| 376 | #define SBTML_REJ 0x0002 /* reject */ |
| 377 | #define SBTML_TMPREJ 0x0004 /* temporary reject, for error recovery */ |
| 378 | |
| 379 | #define SBTML_SICF_SHIFT 16 /* Shift to locate the SI control flags in sbtml */ |
| 380 | |
| 381 | /* sbtmstatehigh */ |
| 382 | #define SBTMH_SERR 0x0001 /* serror */ |
| 383 | #define SBTMH_INT 0x0002 /* interrupt */ |
| 384 | #define SBTMH_BUSY 0x0004 /* busy */ |
| 385 | #define SBTMH_TO 0x0020 /* timeout (sonics >= 2.3) */ |
| 386 | |
| 387 | #define SBTMH_SISF_SHIFT 16 /* Shift to locate the SI status flags in sbtmh */ |
| 388 | |
| 389 | /* sbidlow */ |
| 390 | #define SBIDL_INIT 0x80 /* initiator */ |
| 391 | |
| 392 | /* sbidhigh */ |
| 393 | #define SBIDH_RC_MASK 0x000f /* revision code */ |
| 394 | #define SBIDH_RCE_MASK 0x7000 /* revision code extension field */ |
| 395 | #define SBIDH_RCE_SHIFT 8 |
| 396 | #define SBCOREREV(sbidh) \ |
| 397 | ((((sbidh) & SBIDH_RCE_MASK) >> SBIDH_RCE_SHIFT) | ((sbidh) & SBIDH_RC_MASK)) |
| 398 | #define SBIDH_CC_MASK 0x8ff0 /* core code */ |
| 399 | #define SBIDH_CC_SHIFT 4 |
| 400 | #define SBIDH_VC_MASK 0xffff0000 /* vendor code */ |
| 401 | #define SBIDH_VC_SHIFT 16 |
| 402 | |
Arend van Spriel | 70dfb58 | 2011-02-25 16:39:17 +0100 | [diff] [blame] | 403 | /* |
| 404 | * Conversion of 802.1D priority to precedence level |
| 405 | */ |
| 406 | #define PRIO2PREC(prio) \ |
| 407 | (((prio) == PRIO_8021D_NONE || (prio) == PRIO_8021D_BE) ? \ |
| 408 | ((prio^2)) : (prio)) |
| 409 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 410 | DHD_SPINWAIT_SLEEP_INIT(sdioh_spinwait_sleep); |
| 411 | extern int dhdcdc_set_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf, |
| 412 | uint len); |
| 413 | |
Roland Vossen | b6fe70c | 2011-06-01 13:45:19 +0200 | [diff] [blame] | 414 | /* Core reg address translation */ |
| 415 | #define CORE_CC_REG(base, field) (base + offsetof(chipcregs_t, field)) |
Franky Lin | 597600a | 2011-06-01 13:45:39 +0200 | [diff] [blame] | 416 | #define CORE_BUS_REG(base, field) \ |
| 417 | (base + offsetof(struct sdpcmd_regs, field)) |
Roland Vossen | b6fe70c | 2011-06-01 13:45:19 +0200 | [diff] [blame] | 418 | #define CORE_SB(base, field) \ |
| 419 | (base + SBCONFIGOFF + offsetof(sbconfig_t, field)) |
| 420 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 421 | #ifdef DHD_DEBUG |
| 422 | /* Device console log buffer state */ |
| 423 | typedef struct dhd_console { |
| 424 | uint count; /* Poll interval msec counter */ |
| 425 | uint log_addr; /* Log struct address (fixed) */ |
Roland Vossen | 70963f9 | 2011-06-01 13:45:08 +0200 | [diff] [blame] | 426 | rte_log_t log; /* Log struct (host copy) */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 427 | uint bufsize; /* Size of log buffer */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 428 | u8 *buf; /* Log buffer (host copy) */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 429 | uint last; /* Last buffer read index */ |
| 430 | } dhd_console_t; |
| 431 | #endif /* DHD_DEBUG */ |
| 432 | |
Franky Lin | b49b14d | 2011-06-01 13:45:37 +0200 | [diff] [blame] | 433 | struct sdpcm_shared { |
| 434 | u32 flags; |
| 435 | u32 trap_addr; |
| 436 | u32 assert_exp_addr; |
| 437 | u32 assert_file_addr; |
| 438 | u32 assert_line; |
| 439 | u32 console_addr; /* Address of rte_cons_t */ |
| 440 | u32 msgtrace_addr; |
| 441 | u8 tag[32]; |
| 442 | }; |
| 443 | |
| 444 | |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 445 | /* misc chip info needed by some of the routines */ |
| 446 | struct chip_info { |
| 447 | u32 chip; |
| 448 | u32 chiprev; |
| 449 | u32 cccorebase; |
| 450 | u32 ccrev; |
| 451 | u32 cccaps; |
| 452 | u32 buscorebase; |
| 453 | u32 buscorerev; |
| 454 | u32 buscoretype; |
| 455 | u32 ramcorebase; |
| 456 | u32 armcorebase; |
| 457 | u32 pmurev; |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 458 | u32 ramsize; |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 459 | }; |
| 460 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 461 | /* Private data for SDIO bus interaction */ |
| 462 | typedef struct dhd_bus { |
| 463 | dhd_pub_t *dhd; |
| 464 | |
| 465 | bcmsdh_info_t *sdh; /* Handle for BCMSDH calls */ |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 466 | struct chip_info *ci; /* Chip info struct */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 467 | char *vars; /* Variables (from CIS and/or other) */ |
| 468 | uint varsz; /* Size of variables buffer */ |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 469 | u32 sbaddr; /* Current SB window pointer (-1, invalid) */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 470 | |
Franky Lin | 597600a | 2011-06-01 13:45:39 +0200 | [diff] [blame] | 471 | struct sdpcmd_regs *regs; /* SDIO core */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 472 | uint sdpcmrev; /* SDIO core revision */ |
| 473 | uint armrev; /* CPU core revision */ |
| 474 | uint ramrev; /* SOCRAM core revision */ |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 475 | u32 ramsize; /* Size of RAM in SOCRAM (bytes) */ |
| 476 | u32 orig_ramsize; /* Size of RAM in SOCRAM (bytes) */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 477 | |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 478 | u32 bus; /* gSPI or SDIO bus */ |
| 479 | u32 hostintmask; /* Copy of Host Interrupt Mask */ |
| 480 | u32 intstatus; /* Intstatus bits (events) pending */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 481 | bool dpc_sched; /* Indicates DPC schedule (intrpt rcvd) */ |
| 482 | bool fcstate; /* State of dongle flow-control */ |
| 483 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 484 | u16 cl_devid; /* cached devid for brcmf_sdio_probe_attach() */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 485 | char *fw_path; /* module_param: path to firmware image */ |
| 486 | char *nv_path; /* module_param: path to nvram vars file */ |
| 487 | const char *nvram_params; /* user specified nvram params. */ |
| 488 | |
| 489 | uint blocksize; /* Block size of SDIO transfers */ |
| 490 | uint roundup; /* Max roundup limit */ |
| 491 | |
| 492 | struct pktq txq; /* Queue length used for flow-control */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 493 | u8 flowcontrol; /* per prio flow control bitmask */ |
| 494 | u8 tx_seq; /* Transmit sequence number (next) */ |
| 495 | u8 tx_max; /* Maximum transmit sequence allowed */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 496 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 497 | u8 hdrbuf[MAX_HDR_READ + DHD_SDALIGN]; |
| 498 | u8 *rxhdr; /* Header of current rx frame (in hdrbuf) */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 499 | u16 nextlen; /* Next Read Len from last header */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 500 | u8 rx_seq; /* Receive sequence number (expected) */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 501 | bool rxskip; /* Skip receive (awaiting NAK ACK) */ |
| 502 | |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 503 | struct sk_buff *glomd; /* Packet containing glomming descriptor */ |
| 504 | struct sk_buff *glom; /* Packet chain for glommed superframe */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 505 | uint glomerr; /* Glom packet read errors */ |
| 506 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 507 | u8 *rxbuf; /* Buffer for receiving control packets */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 508 | uint rxblen; /* Allocated length of rxbuf */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 509 | u8 *rxctl; /* Aligned pointer into rxbuf */ |
| 510 | u8 *databuf; /* Buffer for receiving big glom packet */ |
| 511 | u8 *dataptr; /* Aligned pointer into databuf */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 512 | uint rxlen; /* Length of valid data in buffer */ |
| 513 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 514 | u8 sdpcm_ver; /* Bus protocol reported by dongle */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 515 | |
| 516 | bool intr; /* Use interrupts */ |
| 517 | bool poll; /* Use polling */ |
| 518 | bool ipend; /* Device interrupt is pending */ |
| 519 | bool intdis; /* Interrupts disabled by isr */ |
| 520 | uint intrcount; /* Count of device interrupt callbacks */ |
| 521 | uint lastintrs; /* Count as of last watchdog timer */ |
| 522 | uint spurious; /* Count of spurious interrupts */ |
| 523 | uint pollrate; /* Ticks between device polls */ |
| 524 | uint polltick; /* Tick counter */ |
| 525 | uint pollcnt; /* Count of active polls */ |
| 526 | |
| 527 | #ifdef DHD_DEBUG |
| 528 | dhd_console_t console; /* Console output polling support */ |
| 529 | uint console_addr; /* Console address from shared struct */ |
| 530 | #endif /* DHD_DEBUG */ |
| 531 | |
| 532 | uint regfails; /* Count of R_REG/W_REG failures */ |
| 533 | |
| 534 | uint clkstate; /* State of sd and backplane clock(s) */ |
| 535 | bool activity; /* Activity flag for clock down */ |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 536 | s32 idletime; /* Control for activity timeout */ |
| 537 | s32 idlecount; /* Activity timeout counter */ |
| 538 | s32 idleclock; /* How to set bus driver when idle */ |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 539 | s32 sd_rxchain; /* If bcmsdh api accepts PKT chains */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 540 | bool use_rxchain; /* If dhd should use PKT chains */ |
| 541 | bool sleeping; /* Is SDIO bus sleeping? */ |
| 542 | bool rxflow_mode; /* Rx flow control mode */ |
| 543 | bool rxflow; /* Is rx flow control on */ |
| 544 | uint prev_rxlim_hit; /* Is prev rx limit exceeded |
| 545 | (per dpc schedule) */ |
| 546 | bool alp_only; /* Don't use HT clock (ALP only) */ |
| 547 | /* Field to decide if rx of control frames happen in rxbuf or lb-pool */ |
| 548 | bool usebufpool; |
| 549 | |
| 550 | #ifdef SDTEST |
| 551 | /* external loopback */ |
| 552 | bool ext_loop; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 553 | u8 loopid; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 554 | |
| 555 | /* pktgen configuration */ |
| 556 | uint pktgen_freq; /* Ticks between bursts */ |
| 557 | uint pktgen_count; /* Packets to send each burst */ |
| 558 | uint pktgen_print; /* Bursts between count displays */ |
| 559 | uint pktgen_total; /* Stop after this many */ |
| 560 | uint pktgen_minlen; /* Minimum packet data len */ |
| 561 | uint pktgen_maxlen; /* Maximum packet data len */ |
| 562 | uint pktgen_mode; /* Configured mode: tx, rx, or echo */ |
| 563 | uint pktgen_stop; /* Number of tx failures causing stop */ |
| 564 | |
| 565 | /* active pktgen fields */ |
| 566 | uint pktgen_tick; /* Tick counter for bursts */ |
| 567 | uint pktgen_ptick; /* Burst counter for printing */ |
| 568 | uint pktgen_sent; /* Number of test packets generated */ |
| 569 | uint pktgen_rcvd; /* Number of test packets received */ |
| 570 | uint pktgen_fail; /* Number of failed send attempts */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 571 | u16 pktgen_len; /* Length of next packet to send */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 572 | #endif /* SDTEST */ |
| 573 | |
| 574 | /* Some additional counters */ |
| 575 | uint tx_sderrs; /* Count of tx attempts with sd errors */ |
| 576 | uint fcqueued; /* Tx packets that got queued */ |
| 577 | uint rxrtx; /* Count of rtx requests (NAK to dongle) */ |
| 578 | uint rx_toolong; /* Receive frames too long to receive */ |
| 579 | uint rxc_errors; /* SDIO errors when reading control frames */ |
| 580 | uint rx_hdrfail; /* SDIO errors on header reads */ |
| 581 | uint rx_badhdr; /* Bad received headers (roosync?) */ |
| 582 | uint rx_badseq; /* Mismatched rx sequence number */ |
| 583 | uint fc_rcvd; /* Number of flow-control events received */ |
| 584 | uint fc_xoff; /* Number which turned on flow-control */ |
| 585 | uint fc_xon; /* Number which turned off flow-control */ |
| 586 | uint rxglomfail; /* Failed deglom attempts */ |
| 587 | uint rxglomframes; /* Number of glom frames (superframes) */ |
| 588 | uint rxglompkts; /* Number of packets from glom frames */ |
| 589 | uint f2rxhdrs; /* Number of header reads */ |
| 590 | uint f2rxdata; /* Number of frame data reads */ |
| 591 | uint f2txdata; /* Number of f2 frame writes */ |
| 592 | uint f1regdata; /* Number of f1 register accesses */ |
| 593 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 594 | u8 *ctrl_frame_buf; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 595 | u32 ctrl_frame_len; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 596 | bool ctrl_frame_stat; |
Franky Lin | 0f1a87c | 2011-06-29 16:46:32 -0700 | [diff] [blame] | 597 | |
| 598 | spinlock_t txqlock; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 599 | } dhd_bus_t; |
| 600 | |
Roland Vossen | b6fe70c | 2011-06-01 13:45:19 +0200 | [diff] [blame] | 601 | typedef volatile struct _sbconfig { |
| 602 | u32 PAD[2]; |
| 603 | u32 sbipsflag; /* initiator port ocp slave flag */ |
| 604 | u32 PAD[3]; |
| 605 | u32 sbtpsflag; /* target port ocp slave flag */ |
| 606 | u32 PAD[11]; |
| 607 | u32 sbtmerrloga; /* (sonics >= 2.3) */ |
| 608 | u32 PAD; |
| 609 | u32 sbtmerrlog; /* (sonics >= 2.3) */ |
| 610 | u32 PAD[3]; |
| 611 | u32 sbadmatch3; /* address match3 */ |
| 612 | u32 PAD; |
| 613 | u32 sbadmatch2; /* address match2 */ |
| 614 | u32 PAD; |
| 615 | u32 sbadmatch1; /* address match1 */ |
| 616 | u32 PAD[7]; |
| 617 | u32 sbimstate; /* initiator agent state */ |
| 618 | u32 sbintvec; /* interrupt mask */ |
| 619 | u32 sbtmstatelow; /* target state */ |
| 620 | u32 sbtmstatehigh; /* target state */ |
| 621 | u32 sbbwa0; /* bandwidth allocation table0 */ |
| 622 | u32 PAD; |
| 623 | u32 sbimconfiglow; /* initiator configuration */ |
| 624 | u32 sbimconfighigh; /* initiator configuration */ |
| 625 | u32 sbadmatch0; /* address match0 */ |
| 626 | u32 PAD; |
| 627 | u32 sbtmconfiglow; /* target configuration */ |
| 628 | u32 sbtmconfighigh; /* target configuration */ |
| 629 | u32 sbbconfig; /* broadcast configuration */ |
| 630 | u32 PAD; |
| 631 | u32 sbbstate; /* broadcast state */ |
| 632 | u32 PAD[3]; |
| 633 | u32 sbactcnfg; /* activate configuration */ |
| 634 | u32 PAD[3]; |
| 635 | u32 sbflagst; /* current sbflags */ |
| 636 | u32 PAD[3]; |
| 637 | u32 sbidlow; /* identification */ |
| 638 | u32 sbidhigh; /* identification */ |
| 639 | } sbconfig_t; |
| 640 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 641 | /* clkstate */ |
| 642 | #define CLK_NONE 0 |
| 643 | #define CLK_SDONLY 1 |
| 644 | #define CLK_PENDING 2 /* Not used yet */ |
| 645 | #define CLK_AVAIL 3 |
| 646 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 647 | #define DHD_NOPMU(dhd) (false) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 648 | |
| 649 | #ifdef DHD_DEBUG |
| 650 | static int qcount[NUMPRIO]; |
| 651 | static int tx_packets[NUMPRIO]; |
| 652 | #endif /* DHD_DEBUG */ |
| 653 | |
| 654 | /* Deferred transmit */ |
| 655 | const uint dhd_deferred_tx = 1; |
| 656 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 657 | /* Tx/Rx bounds */ |
| 658 | uint dhd_txbound; |
| 659 | uint dhd_rxbound; |
| 660 | uint dhd_txminmax; |
| 661 | |
| 662 | /* override the RAM size if possible */ |
| 663 | #define DONGLE_MIN_MEMSIZE (128 * 1024) |
| 664 | int dhd_dongle_memsize; |
| 665 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 666 | static bool dhd_alignctl; |
| 667 | |
| 668 | static bool sd1idle; |
| 669 | |
| 670 | static bool retrydata; |
| 671 | #define RETRYCHAN(chan) (((chan) == SDPCM_EVENT_CHANNEL) || retrydata) |
| 672 | |
| 673 | static const uint watermark = 8; |
| 674 | static const uint firstread = DHD_FIRSTREAD; |
| 675 | |
| 676 | #define HDATLEN (firstread - (SDPCM_HDRLEN)) |
| 677 | |
| 678 | /* Retry count for register access failures */ |
| 679 | static const uint retry_limit = 2; |
| 680 | |
| 681 | /* Force even SD lengths (some host controllers mess up on odd bytes) */ |
| 682 | static bool forcealign; |
| 683 | |
| 684 | #define ALIGNMENT 4 |
| 685 | |
| 686 | #if defined(OOB_INTR_ONLY) && defined(HW_OOB) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 687 | extern void brcmf_sdcard_enable_hw_oob_intr(void *sdh, bool enable); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 688 | #endif |
| 689 | |
| 690 | #if defined(OOB_INTR_ONLY) && defined(SDIO_ISR_THREAD) |
| 691 | #error OOB_INTR_ONLY is NOT working with SDIO_ISR_THREAD |
| 692 | #endif /* defined(OOB_INTR_ONLY) && defined(SDIO_ISR_THREAD) */ |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 693 | #define PKTALIGN(_p, _len, _align) \ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 694 | do { \ |
| 695 | uint datalign; \ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 696 | datalign = (unsigned long)((_p)->data); \ |
| 697 | datalign = roundup(datalign, (_align)) - datalign; \ |
| 698 | ASSERT(datalign < (_align)); \ |
| 699 | ASSERT((_p)->len >= ((_len) + datalign)); \ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 700 | if (datalign) \ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 701 | skb_pull((_p), datalign); \ |
| 702 | __skb_trim((_p), (_len)); \ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 703 | } while (0) |
| 704 | |
| 705 | /* Limit on rounding up frames */ |
| 706 | static const uint max_roundup = 512; |
| 707 | |
| 708 | /* Try doing readahead */ |
| 709 | static bool dhd_readahead; |
| 710 | |
| 711 | /* To check if there's window offered */ |
| 712 | #define DATAOK(bus) \ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 713 | (((u8)(bus->tx_max - bus->tx_seq) != 0) && \ |
| 714 | (((u8)(bus->tx_max - bus->tx_seq) & 0x80) == 0)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 715 | |
| 716 | /* Macros to get register read/write status */ |
| 717 | /* NOTE: these assume a local dhdsdio_bus_t *bus! */ |
| 718 | #define R_SDREG(regvar, regaddr, retryvar) \ |
| 719 | do { \ |
| 720 | retryvar = 0; \ |
| 721 | do { \ |
Arend van Spriel | ff31c54 | 2011-03-01 10:56:54 +0100 | [diff] [blame] | 722 | regvar = R_REG(regaddr); \ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 723 | } while (brcmf_sdcard_regfail(bus->sdh) && \ |
| 724 | (++retryvar <= retry_limit)); \ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 725 | if (retryvar) { \ |
| 726 | bus->regfails += (retryvar-1); \ |
| 727 | if (retryvar > retry_limit) { \ |
| 728 | DHD_ERROR(("%s: FAILED" #regvar "READ, LINE %d\n", \ |
| 729 | __func__, __LINE__)); \ |
| 730 | regvar = 0; \ |
| 731 | } \ |
| 732 | } \ |
| 733 | } while (0) |
| 734 | |
| 735 | #define W_SDREG(regval, regaddr, retryvar) \ |
| 736 | do { \ |
| 737 | retryvar = 0; \ |
| 738 | do { \ |
Arend van Spriel | ff31c54 | 2011-03-01 10:56:54 +0100 | [diff] [blame] | 739 | W_REG(regaddr, regval); \ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 740 | } while (brcmf_sdcard_regfail(bus->sdh) && \ |
| 741 | (++retryvar <= retry_limit)); \ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 742 | if (retryvar) { \ |
| 743 | bus->regfails += (retryvar-1); \ |
| 744 | if (retryvar > retry_limit) \ |
| 745 | DHD_ERROR(("%s: FAILED REGISTER WRITE, LINE %d\n", \ |
| 746 | __func__, __LINE__)); \ |
| 747 | } \ |
| 748 | } while (0) |
| 749 | |
| 750 | #define DHD_BUS SDIO_BUS |
| 751 | |
| 752 | #define PKT_AVAILABLE() (intstatus & I_HMB_FRAME_IND) |
| 753 | |
| 754 | #define HOSTINTMASK (I_HMB_SW_MASK | I_CHIPACTIVE) |
| 755 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 756 | #ifdef SDTEST |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 757 | static void brcmf_sdbrcm_checkdied(dhd_bus_t *bus, void *pkt, uint seq); |
| 758 | static void brcmf_sdbrcm_sdtest_set(dhd_bus_t *bus, bool start); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 759 | #endif |
| 760 | |
| 761 | #ifdef DHD_DEBUG |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 762 | static int brcmf_sdbrcm_checkdied(dhd_bus_t *bus, u8 *data, uint size); |
| 763 | static int brcmf_sdbrcm_mem_dump(dhd_bus_t *bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 764 | #endif /* DHD_DEBUG */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 765 | static int brcmf_sdbrcm_download_state(dhd_bus_t *bus, bool enter); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 766 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 767 | static void brcmf_sdbrcm_release(dhd_bus_t *bus); |
| 768 | static void brcmf_sdbrcm_release_malloc(dhd_bus_t *bus); |
| 769 | static void brcmf_sdbrcm_disconnect(void *ptr); |
| 770 | static bool brcmf_sdbrcm_chipmatch(u16 chipid); |
| 771 | static bool brcmf_sdbrcm_probe_attach(dhd_bus_t *bus, void *sdh, |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 772 | void *regsva, u16 devid); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 773 | static bool brcmf_sdbrcm_probe_malloc(dhd_bus_t *bus, void *sdh); |
| 774 | static bool brcmf_sdbrcm_probe_init(dhd_bus_t *bus, void *sdh); |
| 775 | static void brcmf_sdbrcm_release_dongle(dhd_bus_t *bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 776 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 777 | static uint brcmf_process_nvram_vars(char *varbuf, uint len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 778 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 779 | static void brcmf_sdbrcm_setmemsize(struct dhd_bus *bus, int mem_size); |
| 780 | static int brcmf_sdbrcm_send_buf(dhd_bus_t *bus, u32 addr, uint fn, |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 781 | uint flags, u8 *buf, uint nbytes, |
| 782 | struct sk_buff *pkt, bcmsdh_cmplt_fn_t complete, |
| 783 | void *handle); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 784 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 785 | static bool brcmf_sdbrcm_download_firmware(struct dhd_bus *bus, void *sdh); |
| 786 | static int _brcmf_sdbrcm_download_firmware(struct dhd_bus *bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 787 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 788 | static int |
| 789 | brcmf_sdbrcm_download_code_file(struct dhd_bus *bus, char *image_path); |
| 790 | static int brcmf_sdbrcm_download_nvram(struct dhd_bus *bus); |
| 791 | static void brcmf_sdbrcm_chip_disablecore(bcmsdh_info_t *sdh, u32 corebase); |
| 792 | static int brcmf_sdbrcm_chip_attach(struct dhd_bus *bus, void *regs); |
| 793 | static void brcmf_sdbrcm_chip_resetcore(bcmsdh_info_t *sdh, u32 corebase); |
| 794 | static void brcmf_sdbrcm_sdiod_drive_strength_init(struct dhd_bus *bus, |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 795 | u32 drivestrength); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 796 | static void brcmf_sdbrcm_chip_detach(struct dhd_bus *bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 797 | |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 798 | /* Packet free applicable unconditionally for sdio and sdspi. |
| 799 | * Conditional if bufpool was present for gspi bus. |
| 800 | */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 801 | static void brcmf_sdbrcm_pktfree2(dhd_bus_t *bus, struct sk_buff *pkt) |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 802 | { |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 803 | if ((bus->bus != SPI_BUS) || bus->usebufpool) |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 804 | brcmu_pkt_buf_free_skb(pkt); |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 805 | } |
| 806 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 807 | static void brcmf_sdbrcm_setmemsize(struct dhd_bus *bus, int mem_size) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 808 | { |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 809 | s32 min_size = DONGLE_MIN_MEMSIZE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 810 | /* Restrict the memsize to user specified limit */ |
| 811 | DHD_ERROR(("user: Restrict the dongle ram size to %d, min %d\n", |
| 812 | dhd_dongle_memsize, min_size)); |
| 813 | if ((dhd_dongle_memsize > min_size) && |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 814 | (dhd_dongle_memsize < (s32) bus->orig_ramsize)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 815 | bus->ramsize = dhd_dongle_memsize; |
| 816 | } |
| 817 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 818 | static int brcmf_sdbrcm_set_siaddr_window(dhd_bus_t *bus, u32 address) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 819 | { |
| 820 | int err = 0; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 821 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRLOW, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 822 | (address >> 8) & SBSDIO_SBADDRLOW_MASK, &err); |
| 823 | if (!err) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 824 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_1, |
| 825 | SBSDIO_FUNC1_SBADDRMID, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 826 | (address >> 16) & SBSDIO_SBADDRMID_MASK, &err); |
| 827 | if (!err) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 828 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_1, |
| 829 | SBSDIO_FUNC1_SBADDRHIGH, |
| 830 | (address >> 24) & SBSDIO_SBADDRHIGH_MASK, |
| 831 | &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 832 | return err; |
| 833 | } |
| 834 | |
| 835 | /* Turn backplane clock on or off */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 836 | static int brcmf_sdbrcm_htclk(dhd_bus_t *bus, bool on, bool pendok) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 837 | { |
| 838 | int err; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 839 | u8 clkctl, clkreq, devctl; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 840 | bcmsdh_info_t *sdh; |
| 841 | |
| 842 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 843 | |
| 844 | #if defined(OOB_INTR_ONLY) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 845 | pendok = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 846 | #endif |
| 847 | clkctl = 0; |
| 848 | sdh = bus->sdh; |
| 849 | |
| 850 | if (on) { |
| 851 | /* Request HT Avail */ |
| 852 | clkreq = |
| 853 | bus->alp_only ? SBSDIO_ALP_AVAIL_REQ : SBSDIO_HT_AVAIL_REQ; |
| 854 | |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 855 | if ((bus->ci->chip == BCM4329_CHIP_ID) |
| 856 | && (bus->ci->chiprev == 0)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 857 | clkreq |= SBSDIO_FORCE_ALP; |
| 858 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 859 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, |
| 860 | SBSDIO_FUNC1_CHIPCLKCSR, clkreq, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 861 | if (err) { |
| 862 | DHD_ERROR(("%s: HT Avail request error: %d\n", |
| 863 | __func__, err)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 864 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 865 | } |
| 866 | |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 867 | if (pendok && ((bus->ci->buscoretype == PCMCIA_CORE_ID) |
| 868 | && (bus->ci->buscorerev == 9))) { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 869 | u32 dummy, retries; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 870 | R_SDREG(dummy, &bus->regs->clockctlstatus, retries); |
| 871 | } |
| 872 | |
| 873 | /* Check current status */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 874 | clkctl = brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
| 875 | SBSDIO_FUNC1_CHIPCLKCSR, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 876 | if (err) { |
| 877 | DHD_ERROR(("%s: HT Avail read error: %d\n", |
| 878 | __func__, err)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 879 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | /* Go to pending and await interrupt if appropriate */ |
| 883 | if (!SBSDIO_CLKAV(clkctl, bus->alp_only) && pendok) { |
| 884 | /* Allow only clock-available interrupt */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 885 | devctl = brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
| 886 | SBSDIO_DEVICE_CTL, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 887 | if (err) { |
| 888 | DHD_ERROR(("%s: Devctl error setting CA: %d\n", |
| 889 | __func__, err)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 890 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | devctl |= SBSDIO_DEVCTL_CA_INT_ONLY; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 894 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, |
| 895 | SBSDIO_DEVICE_CTL, devctl, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 896 | DHD_INFO(("CLKCTL: set PENDING\n")); |
| 897 | bus->clkstate = CLK_PENDING; |
| 898 | |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 899 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 900 | } else if (bus->clkstate == CLK_PENDING) { |
| 901 | /* Cancel CA-only interrupt filter */ |
| 902 | devctl = |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 903 | brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
| 904 | SBSDIO_DEVICE_CTL, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 905 | devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 906 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, |
| 907 | SBSDIO_DEVICE_CTL, devctl, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | /* Otherwise, wait here (polling) for HT Avail */ |
| 911 | if (!SBSDIO_CLKAV(clkctl, bus->alp_only)) { |
| 912 | SPINWAIT_SLEEP(sdioh_spinwait_sleep, |
| 913 | ((clkctl = |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 914 | brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 915 | SBSDIO_FUNC1_CHIPCLKCSR, |
| 916 | &err)), |
| 917 | !SBSDIO_CLKAV(clkctl, bus->alp_only)), |
| 918 | PMU_MAX_TRANSITION_DLY); |
| 919 | } |
| 920 | if (err) { |
| 921 | DHD_ERROR(("%s: HT Avail request error: %d\n", |
| 922 | __func__, err)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 923 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 924 | } |
| 925 | if (!SBSDIO_CLKAV(clkctl, bus->alp_only)) { |
| 926 | DHD_ERROR(("%s: HT Avail timeout (%d): clkctl 0x%02x\n", |
| 927 | __func__, PMU_MAX_TRANSITION_DLY, clkctl)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 928 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 929 | } |
| 930 | |
| 931 | /* Mark clock available */ |
| 932 | bus->clkstate = CLK_AVAIL; |
| 933 | DHD_INFO(("CLKCTL: turned ON\n")); |
| 934 | |
| 935 | #if defined(DHD_DEBUG) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 936 | if (bus->alp_only == true) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 937 | #if !defined(BCMLXSDMMC) |
| 938 | if (!SBSDIO_ALPONLY(clkctl)) { |
| 939 | DHD_ERROR(("%s: HT Clock, when ALP Only\n", |
| 940 | __func__)); |
| 941 | } |
| 942 | #endif /* !defined(BCMLXSDMMC) */ |
| 943 | } else { |
| 944 | if (SBSDIO_ALPONLY(clkctl)) { |
| 945 | DHD_ERROR(("%s: HT Clock should be on.\n", |
| 946 | __func__)); |
| 947 | } |
| 948 | } |
| 949 | #endif /* defined (DHD_DEBUG) */ |
| 950 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 951 | bus->activity = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 952 | } else { |
| 953 | clkreq = 0; |
| 954 | |
| 955 | if (bus->clkstate == CLK_PENDING) { |
| 956 | /* Cancel CA-only interrupt filter */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 957 | devctl = brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
| 958 | SBSDIO_DEVICE_CTL, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 959 | devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 960 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, |
| 961 | SBSDIO_DEVICE_CTL, devctl, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 962 | } |
| 963 | |
| 964 | bus->clkstate = CLK_SDONLY; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 965 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, |
| 966 | SBSDIO_FUNC1_CHIPCLKCSR, clkreq, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 967 | DHD_INFO(("CLKCTL: turned OFF\n")); |
| 968 | if (err) { |
| 969 | DHD_ERROR(("%s: Failed access turning clock off: %d\n", |
| 970 | __func__, err)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 971 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 972 | } |
| 973 | } |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 974 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 975 | } |
| 976 | |
| 977 | /* Change idle/active SD state */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 978 | static int brcmf_sdbrcm_sdclk(dhd_bus_t *bus, bool on) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 979 | { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 980 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 981 | |
Franky Lin | 602a8ab | 2011-06-01 13:45:04 +0200 | [diff] [blame] | 982 | if (on) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 983 | bus->clkstate = CLK_SDONLY; |
Franky Lin | 602a8ab | 2011-06-01 13:45:04 +0200 | [diff] [blame] | 984 | else |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 985 | bus->clkstate = CLK_NONE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 986 | |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 987 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 988 | } |
| 989 | |
| 990 | /* Transition SD and backplane clock readiness */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 991 | static int brcmf_sdbrcm_clkctl(dhd_bus_t *bus, uint target, bool pendok) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 992 | { |
| 993 | #ifdef DHD_DEBUG |
| 994 | uint oldstate = bus->clkstate; |
| 995 | #endif /* DHD_DEBUG */ |
| 996 | |
| 997 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 998 | |
| 999 | /* Early exit if we're already there */ |
| 1000 | if (bus->clkstate == target) { |
| 1001 | if (target == CLK_AVAIL) { |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 1002 | brcmf_os_wd_timer(bus->dhd, brcmf_watchdog_ms); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1003 | bus->activity = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1004 | } |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 1005 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | switch (target) { |
| 1009 | case CLK_AVAIL: |
| 1010 | /* Make sure SD clock is available */ |
| 1011 | if (bus->clkstate == CLK_NONE) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1012 | brcmf_sdbrcm_sdclk(bus, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1013 | /* Now request HT Avail on the backplane */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1014 | brcmf_sdbrcm_htclk(bus, true, pendok); |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 1015 | brcmf_os_wd_timer(bus->dhd, brcmf_watchdog_ms); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1016 | bus->activity = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1017 | break; |
| 1018 | |
| 1019 | case CLK_SDONLY: |
| 1020 | /* Remove HT request, or bring up SD clock */ |
| 1021 | if (bus->clkstate == CLK_NONE) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1022 | brcmf_sdbrcm_sdclk(bus, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1023 | else if (bus->clkstate == CLK_AVAIL) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1024 | brcmf_sdbrcm_htclk(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1025 | else |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1026 | DHD_ERROR(("brcmf_sdbrcm_clkctl: request for %d -> %d" |
| 1027 | "\n", bus->clkstate, target)); |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 1028 | brcmf_os_wd_timer(bus->dhd, brcmf_watchdog_ms); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1029 | break; |
| 1030 | |
| 1031 | case CLK_NONE: |
| 1032 | /* Make sure to remove HT request */ |
| 1033 | if (bus->clkstate == CLK_AVAIL) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1034 | brcmf_sdbrcm_htclk(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1035 | /* Now remove the SD clock */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1036 | brcmf_sdbrcm_sdclk(bus, false); |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 1037 | brcmf_os_wd_timer(bus->dhd, 0); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1038 | break; |
| 1039 | } |
| 1040 | #ifdef DHD_DEBUG |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1041 | DHD_INFO(("brcmf_sdbrcm_clkctl: %d -> %d\n", oldstate, bus->clkstate)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1042 | #endif /* DHD_DEBUG */ |
| 1043 | |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 1044 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1045 | } |
| 1046 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1047 | int brcmf_sdbrcm_bussleep(dhd_bus_t *bus, bool sleep) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1048 | { |
| 1049 | bcmsdh_info_t *sdh = bus->sdh; |
Franky Lin | 597600a | 2011-06-01 13:45:39 +0200 | [diff] [blame] | 1050 | struct sdpcmd_regs *regs = bus->regs; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1051 | uint retries = 0; |
| 1052 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1053 | DHD_INFO(("brcmf_sdbrcm_bussleep: request %s (currently %s)\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1054 | (sleep ? "SLEEP" : "WAKE"), |
| 1055 | (bus->sleeping ? "SLEEP" : "WAKE"))); |
| 1056 | |
| 1057 | /* Done if we're already in the requested state */ |
| 1058 | if (sleep == bus->sleeping) |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 1059 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1060 | |
| 1061 | /* Going to sleep: set the alarm and turn off the lights... */ |
| 1062 | if (sleep) { |
| 1063 | /* Don't sleep if something is pending */ |
| 1064 | if (bus->dpc_sched || bus->rxskip || pktq_len(&bus->txq)) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 1065 | return -EBUSY; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1066 | |
| 1067 | /* Disable SDIO interrupts (no longer interested) */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1068 | brcmf_sdcard_intr_disable(bus->sdh); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1069 | |
| 1070 | /* Make sure the controller has the bus up */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1071 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1072 | |
| 1073 | /* Tell device to start using OOB wakeup */ |
| 1074 | W_SDREG(SMB_USE_OOB, ®s->tosbmailbox, retries); |
| 1075 | if (retries > retry_limit) |
| 1076 | DHD_ERROR(("CANNOT SIGNAL CHIP, WILL NOT WAKE UP!!\n")); |
| 1077 | |
| 1078 | /* Turn off our contribution to the HT clock request */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1079 | brcmf_sdbrcm_clkctl(bus, CLK_SDONLY, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1080 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1081 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, |
| 1082 | SBSDIO_FUNC1_CHIPCLKCSR, |
| 1083 | SBSDIO_FORCE_HW_CLKREQ_OFF, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1084 | |
| 1085 | /* Isolate the bus */ |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 1086 | if (bus->ci->chip != BCM4329_CHIP_ID |
| 1087 | && bus->ci->chip != BCM4319_CHIP_ID) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1088 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, |
| 1089 | SBSDIO_DEVICE_CTL, |
| 1090 | SBSDIO_DEVCTL_PADS_ISO, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1091 | } |
| 1092 | |
| 1093 | /* Change state */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1094 | bus->sleeping = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1095 | |
| 1096 | } else { |
| 1097 | /* Waking up: bus power up is ok, set local state */ |
| 1098 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1099 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, |
| 1100 | SBSDIO_FUNC1_CHIPCLKCSR, 0, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1101 | |
| 1102 | /* Force pad isolation off if possible |
| 1103 | (in case power never toggled) */ |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 1104 | if ((bus->ci->buscoretype == PCMCIA_CORE_ID) |
| 1105 | && (bus->ci->buscorerev >= 10)) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1106 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, |
| 1107 | SBSDIO_DEVICE_CTL, 0, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1108 | |
| 1109 | /* Make sure the controller has the bus up */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1110 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1111 | |
| 1112 | /* Send misc interrupt to indicate OOB not needed */ |
| 1113 | W_SDREG(0, ®s->tosbmailboxdata, retries); |
| 1114 | if (retries <= retry_limit) |
| 1115 | W_SDREG(SMB_DEV_INT, ®s->tosbmailbox, retries); |
| 1116 | |
| 1117 | if (retries > retry_limit) |
| 1118 | DHD_ERROR(("CANNOT SIGNAL CHIP TO CLEAR OOB!!\n")); |
| 1119 | |
| 1120 | /* Make sure we have SD bus access */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1121 | brcmf_sdbrcm_clkctl(bus, CLK_SDONLY, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1122 | |
| 1123 | /* Change state */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1124 | bus->sleeping = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1125 | |
| 1126 | /* Enable interrupts again */ |
| 1127 | if (bus->intr && (bus->dhd->busstate == DHD_BUS_DATA)) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1128 | bus->intdis = false; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1129 | brcmf_sdcard_intr_enable(bus->sdh); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1130 | } |
| 1131 | } |
| 1132 | |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 1133 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1134 | } |
| 1135 | |
| 1136 | #if defined(OOB_INTR_ONLY) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1137 | void brcmf_sdbrcm_enable_oob_intr(struct dhd_bus *bus, bool enable) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1138 | { |
| 1139 | #if defined(HW_OOB) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1140 | brcmf_sdcard_enable_hw_oob_intr(bus->sdh, enable); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1141 | #else |
| 1142 | sdpcmd_regs_t *regs = bus->regs; |
| 1143 | uint retries = 0; |
| 1144 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1145 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1146 | if (enable == true) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1147 | |
| 1148 | /* Tell device to start using OOB wakeup */ |
| 1149 | W_SDREG(SMB_USE_OOB, ®s->tosbmailbox, retries); |
| 1150 | if (retries > retry_limit) |
| 1151 | DHD_ERROR(("CANNOT SIGNAL CHIP, WILL NOT WAKE UP!!\n")); |
| 1152 | |
| 1153 | } else { |
| 1154 | /* Send misc interrupt to indicate OOB not needed */ |
| 1155 | W_SDREG(0, ®s->tosbmailboxdata, retries); |
| 1156 | if (retries <= retry_limit) |
| 1157 | W_SDREG(SMB_DEV_INT, ®s->tosbmailbox, retries); |
| 1158 | } |
| 1159 | |
| 1160 | /* Turn off our contribution to the HT clock request */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1161 | brcmf_sdbrcm_clkctl(bus, CLK_SDONLY, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1162 | #endif /* !defined(HW_OOB) */ |
| 1163 | } |
| 1164 | #endif /* defined(OOB_INTR_ONLY) */ |
| 1165 | |
| 1166 | #define BUS_WAKE(bus) \ |
| 1167 | do { \ |
| 1168 | if ((bus)->sleeping) \ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1169 | brcmf_sdbrcm_bussleep((bus), false); \ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1170 | } while (0); |
| 1171 | |
| 1172 | /* Writes a HW/SW header into the packet and sends it. */ |
| 1173 | /* Assumes: (a) header space already there, (b) caller holds lock */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1174 | static int brcmf_sdbrcm_txpkt(dhd_bus_t *bus, struct sk_buff *pkt, uint chan, |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 1175 | bool free_pkt) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1176 | { |
| 1177 | int ret; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1178 | u8 *frame; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 1179 | u16 len, pad = 0; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1180 | u32 swheader; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1181 | uint retries = 0; |
| 1182 | bcmsdh_info_t *sdh; |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 1183 | struct sk_buff *new; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1184 | int i; |
| 1185 | |
| 1186 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 1187 | |
| 1188 | sdh = bus->sdh; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1189 | |
| 1190 | if (bus->dhd->dongle_reset) { |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 1191 | ret = -EPERM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1192 | goto done; |
| 1193 | } |
| 1194 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1195 | frame = (u8 *) (pkt->data); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1196 | |
| 1197 | /* Add alignment padding, allocate new packet if needed */ |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 1198 | pad = ((unsigned long)frame % DHD_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1199 | if (pad) { |
Arend van Spriel | 3be727c | 2010-11-23 22:20:30 +0100 | [diff] [blame] | 1200 | if (skb_headroom(pkt) < pad) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1201 | DHD_INFO(("%s: insufficient headroom %d for %d pad\n", |
Arend van Spriel | 3be727c | 2010-11-23 22:20:30 +0100 | [diff] [blame] | 1202 | __func__, skb_headroom(pkt), pad)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1203 | bus->dhd->tx_realloc++; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1204 | new = brcmu_pkt_buf_get_skb(pkt->len + DHD_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1205 | if (!new) { |
| 1206 | DHD_ERROR(("%s: couldn't allocate new %d-byte " |
| 1207 | "packet\n", |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1208 | __func__, pkt->len + DHD_SDALIGN)); |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 1209 | ret = -ENOMEM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1210 | goto done; |
| 1211 | } |
| 1212 | |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 1213 | PKTALIGN(new, pkt->len, DHD_SDALIGN); |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 1214 | memcpy(new->data, pkt->data, pkt->len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1215 | if (free_pkt) |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1216 | brcmu_pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1217 | /* free the pkt if canned one is not used */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1218 | free_pkt = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1219 | pkt = new; |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1220 | frame = (u8 *) (pkt->data); |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 1221 | ASSERT(((unsigned long)frame % DHD_SDALIGN) == 0); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1222 | pad = 0; |
| 1223 | } else { |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 1224 | skb_push(pkt, pad); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1225 | frame = (u8 *) (pkt->data); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1226 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1227 | ASSERT((pad + SDPCM_HDRLEN) <= (int)(pkt->len)); |
Brett Rudley | 9249ede | 2010-11-30 20:09:49 -0800 | [diff] [blame] | 1228 | memset(frame, 0, pad + SDPCM_HDRLEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1229 | } |
| 1230 | } |
| 1231 | ASSERT(pad < DHD_SDALIGN); |
| 1232 | |
| 1233 | /* Hardware tag: 2 byte len followed by 2 byte ~len check (all LE) */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1234 | len = (u16) (pkt->len); |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 1235 | *(u16 *) frame = cpu_to_le16(len); |
| 1236 | *(((u16 *) frame) + 1) = cpu_to_le16(~len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1237 | |
| 1238 | /* Software tag: channel, sequence number, data offset */ |
| 1239 | swheader = |
| 1240 | ((chan << SDPCM_CHANNEL_SHIFT) & SDPCM_CHANNEL_MASK) | bus->tx_seq | |
| 1241 | (((pad + |
| 1242 | SDPCM_HDRLEN) << SDPCM_DOFFSET_SHIFT) & SDPCM_DOFFSET_MASK); |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 1243 | |
| 1244 | put_unaligned_le32(swheader, frame + SDPCM_FRAMETAG_LEN); |
| 1245 | put_unaligned_le32(0, frame + SDPCM_FRAMETAG_LEN + sizeof(swheader)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1246 | |
| 1247 | #ifdef DHD_DEBUG |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1248 | tx_packets[pkt->priority]++; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1249 | if (DHD_BYTES_ON() && |
| 1250 | (((DHD_CTL_ON() && (chan == SDPCM_CONTROL_CHANNEL)) || |
| 1251 | (DHD_DATA_ON() && (chan != SDPCM_CONTROL_CHANNEL))))) { |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 1252 | printk(KERN_DEBUG "Tx Frame:\n"); |
| 1253 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, frame, len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1254 | } else if (DHD_HDRS_ON()) { |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 1255 | printk(KERN_DEBUG "TxHdr:\n"); |
| 1256 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 1257 | frame, min_t(u16, len, 16)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1258 | } |
| 1259 | #endif |
| 1260 | |
| 1261 | /* Raise len to next SDIO block to eliminate tail command */ |
| 1262 | if (bus->roundup && bus->blocksize && (len > bus->blocksize)) { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 1263 | u16 pad = bus->blocksize - (len % bus->blocksize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1264 | if ((pad <= bus->roundup) && (pad < bus->blocksize)) |
| 1265 | #ifdef NOTUSED |
Arend van Spriel | 3be727c | 2010-11-23 22:20:30 +0100 | [diff] [blame] | 1266 | if (pad <= skb_tailroom(pkt)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1267 | #endif /* NOTUSED */ |
| 1268 | len += pad; |
| 1269 | } else if (len % DHD_SDALIGN) { |
| 1270 | len += DHD_SDALIGN - (len % DHD_SDALIGN); |
| 1271 | } |
| 1272 | |
| 1273 | /* Some controllers have trouble with odd bytes -- round to even */ |
| 1274 | if (forcealign && (len & (ALIGNMENT - 1))) { |
| 1275 | #ifdef NOTUSED |
Arend van Spriel | 3be727c | 2010-11-23 22:20:30 +0100 | [diff] [blame] | 1276 | if (skb_tailroom(pkt)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1277 | #endif |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 1278 | len = roundup(len, ALIGNMENT); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1279 | #ifdef NOTUSED |
| 1280 | else |
| 1281 | DHD_ERROR(("%s: sending unrounded %d-byte packet\n", |
| 1282 | __func__, len)); |
| 1283 | #endif |
| 1284 | } |
| 1285 | |
| 1286 | do { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1287 | ret = brcmf_sdbrcm_send_buf(bus, brcmf_sdcard_cur_sbwad(sdh), |
| 1288 | SDIO_FUNC_2, F2SYNC, frame, len, pkt, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1289 | bus->f2txdata++; |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 1290 | ASSERT(ret != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1291 | |
| 1292 | if (ret < 0) { |
| 1293 | /* On failure, abort the command |
| 1294 | and terminate the frame */ |
| 1295 | DHD_INFO(("%s: sdio error %d, abort command and " |
| 1296 | "terminate frame.\n", __func__, ret)); |
| 1297 | bus->tx_sderrs++; |
| 1298 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1299 | brcmf_sdcard_abort(sdh, SDIO_FUNC_2); |
| 1300 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1301 | SBSDIO_FUNC1_FRAMECTRL, SFC_WF_TERM, |
| 1302 | NULL); |
| 1303 | bus->f1regdata++; |
| 1304 | |
| 1305 | for (i = 0; i < 3; i++) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1306 | u8 hi, lo; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1307 | hi = brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1308 | SBSDIO_FUNC1_WFRAMEBCHI, |
| 1309 | NULL); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1310 | lo = brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1311 | SBSDIO_FUNC1_WFRAMEBCLO, |
| 1312 | NULL); |
| 1313 | bus->f1regdata += 2; |
| 1314 | if ((hi == 0) && (lo == 0)) |
| 1315 | break; |
| 1316 | } |
| 1317 | |
| 1318 | } |
| 1319 | if (ret == 0) |
| 1320 | bus->tx_seq = (bus->tx_seq + 1) % SDPCM_SEQUENCE_WRAP; |
| 1321 | |
| 1322 | } while ((ret < 0) && retrydata && retries++ < TXRETRIES); |
| 1323 | |
| 1324 | done: |
| 1325 | /* restore pkt buffer pointer before calling tx complete routine */ |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 1326 | skb_pull(pkt, SDPCM_HDRLEN + pad); |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 1327 | brcmf_os_sdunlock(bus->dhd); |
| 1328 | brcmf_txcomplete(bus->dhd, pkt, ret != 0); |
| 1329 | brcmf_os_sdlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1330 | |
| 1331 | if (free_pkt) |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1332 | brcmu_pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1333 | |
| 1334 | return ret; |
| 1335 | } |
| 1336 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1337 | int brcmf_sdbrcm_bus_txdata(struct dhd_bus *bus, struct sk_buff *pkt) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1338 | { |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 1339 | int ret = -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1340 | uint datalen, prec; |
| 1341 | |
| 1342 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 1343 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1344 | datalen = pkt->len; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1345 | |
| 1346 | #ifdef SDTEST |
| 1347 | /* Push the test header if doing loopback */ |
| 1348 | if (bus->ext_loop) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1349 | u8 *data; |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 1350 | skb_push(pkt, SDPCM_TEST_HDRLEN); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1351 | data = pkt->data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1352 | *data++ = SDPCM_TEST_ECHOREQ; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1353 | *data++ = (u8) bus->loopid++; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1354 | *data++ = (datalen >> 0); |
| 1355 | *data++ = (datalen >> 8); |
| 1356 | datalen += SDPCM_TEST_HDRLEN; |
| 1357 | } |
| 1358 | #endif /* SDTEST */ |
| 1359 | |
| 1360 | /* Add space for the header */ |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 1361 | skb_push(pkt, SDPCM_HDRLEN); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1362 | ASSERT(IS_ALIGNED((unsigned long)(pkt->data), 2)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1363 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1364 | prec = PRIO2PREC((pkt->priority & PRIOMASK)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1365 | |
| 1366 | /* Check for existing queue, current flow-control, |
| 1367 | pending event, or pending clock */ |
| 1368 | if (dhd_deferred_tx || bus->fcstate || pktq_len(&bus->txq) |
| 1369 | || bus->dpc_sched || (!DATAOK(bus)) |
| 1370 | || (bus->flowcontrol & NBITVAL(prec)) |
| 1371 | || (bus->clkstate != CLK_AVAIL)) { |
| 1372 | DHD_TRACE(("%s: deferring pktq len %d\n", __func__, |
| 1373 | pktq_len(&bus->txq))); |
| 1374 | bus->fcqueued++; |
| 1375 | |
| 1376 | /* Priority based enq */ |
Franky Lin | 0f1a87c | 2011-06-29 16:46:32 -0700 | [diff] [blame] | 1377 | spin_lock_bh(&bus->txqlock); |
Arend van Spriel | aba5e0a | 2011-06-29 16:47:03 -0700 | [diff] [blame] | 1378 | if (brcmf_c_prec_enq(bus->dhd, &bus->txq, pkt, prec) == false) { |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 1379 | skb_pull(pkt, SDPCM_HDRLEN); |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 1380 | brcmf_txcomplete(bus->dhd, pkt, false); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1381 | brcmu_pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1382 | DHD_ERROR(("%s: out of bus->txq !!!\n", __func__)); |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 1383 | ret = -ENOSR; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1384 | } else { |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 1385 | ret = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1386 | } |
Franky Lin | 0f1a87c | 2011-06-29 16:46:32 -0700 | [diff] [blame] | 1387 | spin_unlock_bh(&bus->txqlock); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1388 | |
Grant Grundler | 7c31607 | 2011-03-09 15:04:15 -0800 | [diff] [blame] | 1389 | if (pktq_len(&bus->txq) >= TXHI) |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 1390 | brcmf_txflowcontrol(bus->dhd, 0, ON); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1391 | |
| 1392 | #ifdef DHD_DEBUG |
| 1393 | if (pktq_plen(&bus->txq, prec) > qcount[prec]) |
| 1394 | qcount[prec] = pktq_plen(&bus->txq, prec); |
| 1395 | #endif |
| 1396 | /* Schedule DPC if needed to send queued packet(s) */ |
| 1397 | if (dhd_deferred_tx && !bus->dpc_sched) { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1398 | bus->dpc_sched = true; |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 1399 | brcmf_sched_dpc(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1400 | } |
| 1401 | } else { |
| 1402 | /* Lock: we're about to use shared data/code (and SDIO) */ |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 1403 | brcmf_os_sdlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1404 | |
| 1405 | /* Otherwise, send it now */ |
| 1406 | BUS_WAKE(bus); |
| 1407 | /* Make sure back plane ht clk is on, no pending allowed */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1408 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1409 | |
| 1410 | #ifndef SDTEST |
| 1411 | DHD_TRACE(("%s: calling txpkt\n", __func__)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1412 | ret = brcmf_sdbrcm_txpkt(bus, pkt, SDPCM_DATA_CHANNEL, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1413 | #else |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1414 | ret = brcmf_sdbrcm_txpkt(bus, pkt, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1415 | (bus->ext_loop ? SDPCM_TEST_CHANNEL : |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1416 | SDPCM_DATA_CHANNEL), true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1417 | #endif |
| 1418 | if (ret) |
| 1419 | bus->dhd->tx_errors++; |
| 1420 | else |
| 1421 | bus->dhd->dstats.tx_bytes += datalen; |
| 1422 | |
| 1423 | if ((bus->idletime == DHD_IDLE_IMMEDIATE) && !bus->dpc_sched) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1424 | bus->activity = false; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1425 | brcmf_sdbrcm_clkctl(bus, CLK_NONE, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1426 | } |
| 1427 | |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 1428 | brcmf_os_sdunlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1429 | } |
| 1430 | |
| 1431 | return ret; |
| 1432 | } |
| 1433 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1434 | static uint brcmf_sdbrcm_sendfromq(dhd_bus_t *bus, uint maxframes) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1435 | { |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 1436 | struct sk_buff *pkt; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1437 | u32 intstatus = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1438 | uint retries = 0; |
| 1439 | int ret = 0, prec_out; |
| 1440 | uint cnt = 0; |
| 1441 | uint datalen; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1442 | u8 tx_prec_map; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1443 | |
| 1444 | dhd_pub_t *dhd = bus->dhd; |
Franky Lin | 597600a | 2011-06-01 13:45:39 +0200 | [diff] [blame] | 1445 | struct sdpcmd_regs *regs = bus->regs; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1446 | |
| 1447 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 1448 | |
| 1449 | tx_prec_map = ~bus->flowcontrol; |
| 1450 | |
| 1451 | /* Send frames until the limit or some other event */ |
| 1452 | for (cnt = 0; (cnt < maxframes) && DATAOK(bus); cnt++) { |
Franky Lin | 0f1a87c | 2011-06-29 16:46:32 -0700 | [diff] [blame] | 1453 | spin_lock_bh(&bus->txqlock); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1454 | pkt = brcmu_pktq_mdeq(&bus->txq, tx_prec_map, &prec_out); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1455 | if (pkt == NULL) { |
Franky Lin | 0f1a87c | 2011-06-29 16:46:32 -0700 | [diff] [blame] | 1456 | spin_unlock_bh(&bus->txqlock); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1457 | break; |
| 1458 | } |
Franky Lin | 0f1a87c | 2011-06-29 16:46:32 -0700 | [diff] [blame] | 1459 | spin_unlock_bh(&bus->txqlock); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1460 | datalen = pkt->len - SDPCM_HDRLEN; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1461 | |
| 1462 | #ifndef SDTEST |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1463 | ret = brcmf_sdbrcm_txpkt(bus, pkt, SDPCM_DATA_CHANNEL, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1464 | #else |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1465 | ret = brcmf_sdbrcm_txpkt(bus, pkt, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1466 | (bus->ext_loop ? SDPCM_TEST_CHANNEL : |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1467 | SDPCM_DATA_CHANNEL), true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1468 | #endif |
| 1469 | if (ret) |
| 1470 | bus->dhd->tx_errors++; |
| 1471 | else |
| 1472 | bus->dhd->dstats.tx_bytes += datalen; |
| 1473 | |
| 1474 | /* In poll mode, need to check for other events */ |
| 1475 | if (!bus->intr && cnt) { |
| 1476 | /* Check device status, signal pending interrupt */ |
| 1477 | R_SDREG(intstatus, ®s->intstatus, retries); |
| 1478 | bus->f2txdata++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1479 | if (brcmf_sdcard_regfail(bus->sdh)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1480 | break; |
| 1481 | if (intstatus & bus->hostintmask) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1482 | bus->ipend = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1483 | } |
| 1484 | } |
| 1485 | |
| 1486 | /* Deflow-control stack if needed */ |
Grant Grundler | 7c31607 | 2011-03-09 15:04:15 -0800 | [diff] [blame] | 1487 | if (dhd->up && (dhd->busstate == DHD_BUS_DATA) && |
Grant Grundler | 26a71a4 | 2011-03-09 10:41:25 -0800 | [diff] [blame] | 1488 | dhd->txoff && (pktq_len(&bus->txq) < TXLOW)) |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 1489 | brcmf_txflowcontrol(dhd, 0, OFF); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1490 | |
| 1491 | return cnt; |
| 1492 | } |
| 1493 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1494 | int |
| 1495 | brcmf_sdbrcm_bus_txctl(struct dhd_bus *bus, unsigned char *msg, uint msglen) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1496 | { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1497 | u8 *frame; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 1498 | u16 len; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1499 | u32 swheader; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1500 | uint retries = 0; |
| 1501 | bcmsdh_info_t *sdh = bus->sdh; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1502 | u8 doff = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1503 | int ret = -1; |
| 1504 | int i; |
| 1505 | |
| 1506 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 1507 | |
| 1508 | if (bus->dhd->dongle_reset) |
| 1509 | return -EIO; |
| 1510 | |
| 1511 | /* Back the pointer to make a room for bus header */ |
| 1512 | frame = msg - SDPCM_HDRLEN; |
| 1513 | len = (msglen += SDPCM_HDRLEN); |
| 1514 | |
| 1515 | /* Add alignment padding (optional for ctl frames) */ |
| 1516 | if (dhd_alignctl) { |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 1517 | doff = ((unsigned long)frame % DHD_SDALIGN); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 1518 | if (doff) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1519 | frame -= doff; |
| 1520 | len += doff; |
| 1521 | msglen += doff; |
Brett Rudley | 9249ede | 2010-11-30 20:09:49 -0800 | [diff] [blame] | 1522 | memset(frame, 0, doff + SDPCM_HDRLEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1523 | } |
| 1524 | ASSERT(doff < DHD_SDALIGN); |
| 1525 | } |
| 1526 | doff += SDPCM_HDRLEN; |
| 1527 | |
| 1528 | /* Round send length to next SDIO block */ |
| 1529 | if (bus->roundup && bus->blocksize && (len > bus->blocksize)) { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 1530 | u16 pad = bus->blocksize - (len % bus->blocksize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1531 | if ((pad <= bus->roundup) && (pad < bus->blocksize)) |
| 1532 | len += pad; |
| 1533 | } else if (len % DHD_SDALIGN) { |
| 1534 | len += DHD_SDALIGN - (len % DHD_SDALIGN); |
| 1535 | } |
| 1536 | |
| 1537 | /* Satisfy length-alignment requirements */ |
| 1538 | if (forcealign && (len & (ALIGNMENT - 1))) |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 1539 | len = roundup(len, ALIGNMENT); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1540 | |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 1541 | ASSERT(IS_ALIGNED((unsigned long)frame, 2)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1542 | |
| 1543 | /* Need to lock here to protect txseq and SDIO tx calls */ |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 1544 | brcmf_os_sdlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1545 | |
| 1546 | BUS_WAKE(bus); |
| 1547 | |
| 1548 | /* Make sure backplane clock is on */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1549 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1550 | |
| 1551 | /* Hardware tag: 2 byte len followed by 2 byte ~len check (all LE) */ |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 1552 | *(u16 *) frame = cpu_to_le16((u16) msglen); |
| 1553 | *(((u16 *) frame) + 1) = cpu_to_le16(~msglen); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1554 | |
| 1555 | /* Software tag: channel, sequence number, data offset */ |
| 1556 | swheader = |
| 1557 | ((SDPCM_CONTROL_CHANNEL << SDPCM_CHANNEL_SHIFT) & |
| 1558 | SDPCM_CHANNEL_MASK) |
| 1559 | | bus->tx_seq | ((doff << SDPCM_DOFFSET_SHIFT) & |
| 1560 | SDPCM_DOFFSET_MASK); |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 1561 | put_unaligned_le32(swheader, frame + SDPCM_FRAMETAG_LEN); |
| 1562 | put_unaligned_le32(0, frame + SDPCM_FRAMETAG_LEN + sizeof(swheader)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1563 | |
| 1564 | if (!DATAOK(bus)) { |
| 1565 | DHD_INFO(("%s: No bus credit bus->tx_max %d, bus->tx_seq %d\n", |
| 1566 | __func__, bus->tx_max, bus->tx_seq)); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1567 | bus->ctrl_frame_stat = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1568 | /* Send from dpc */ |
| 1569 | bus->ctrl_frame_buf = frame; |
| 1570 | bus->ctrl_frame_len = len; |
| 1571 | |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 1572 | brcmf_wait_for_event(bus->dhd, &bus->ctrl_frame_stat); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1573 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1574 | if (bus->ctrl_frame_stat == false) { |
| 1575 | DHD_INFO(("%s: ctrl_frame_stat == false\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1576 | ret = 0; |
| 1577 | } else { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1578 | DHD_INFO(("%s: ctrl_frame_stat == true\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1579 | ret = -1; |
| 1580 | } |
| 1581 | } |
| 1582 | |
| 1583 | if (ret == -1) { |
| 1584 | #ifdef DHD_DEBUG |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 1585 | if (DHD_BYTES_ON() && DHD_CTL_ON()) { |
| 1586 | printk(KERN_DEBUG "Tx Frame:\n"); |
| 1587 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 1588 | frame, len); |
| 1589 | } else if (DHD_HDRS_ON()) { |
| 1590 | printk(KERN_DEBUG "TxHdr:\n"); |
| 1591 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 1592 | frame, min_t(u16, len, 16)); |
| 1593 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1594 | #endif |
| 1595 | |
| 1596 | do { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1597 | bus->ctrl_frame_stat = false; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1598 | ret = brcmf_sdbrcm_send_buf(bus, |
| 1599 | brcmf_sdcard_cur_sbwad(sdh), SDIO_FUNC_2, |
| 1600 | F2SYNC, frame, len, NULL, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1601 | |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 1602 | ASSERT(ret != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1603 | |
| 1604 | if (ret < 0) { |
| 1605 | /* On failure, abort the command and |
| 1606 | terminate the frame */ |
| 1607 | DHD_INFO(("%s: sdio error %d, abort command and terminate frame.\n", |
| 1608 | __func__, ret)); |
| 1609 | bus->tx_sderrs++; |
| 1610 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1611 | brcmf_sdcard_abort(sdh, SDIO_FUNC_2); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1612 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1613 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1614 | SBSDIO_FUNC1_FRAMECTRL, |
| 1615 | SFC_WF_TERM, NULL); |
| 1616 | bus->f1regdata++; |
| 1617 | |
| 1618 | for (i = 0; i < 3; i++) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1619 | u8 hi, lo; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1620 | hi = brcmf_sdcard_cfg_read(sdh, |
| 1621 | SDIO_FUNC_1, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1622 | SBSDIO_FUNC1_WFRAMEBCHI, |
| 1623 | NULL); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1624 | lo = brcmf_sdcard_cfg_read(sdh, |
| 1625 | SDIO_FUNC_1, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1626 | SBSDIO_FUNC1_WFRAMEBCLO, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1627 | NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1628 | bus->f1regdata += 2; |
| 1629 | if ((hi == 0) && (lo == 0)) |
| 1630 | break; |
| 1631 | } |
| 1632 | |
| 1633 | } |
| 1634 | if (ret == 0) { |
| 1635 | bus->tx_seq = |
| 1636 | (bus->tx_seq + 1) % SDPCM_SEQUENCE_WRAP; |
| 1637 | } |
| 1638 | } while ((ret < 0) && retries++ < TXRETRIES); |
| 1639 | } |
| 1640 | |
| 1641 | if ((bus->idletime == DHD_IDLE_IMMEDIATE) && !bus->dpc_sched) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1642 | bus->activity = false; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1643 | brcmf_sdbrcm_clkctl(bus, CLK_NONE, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1644 | } |
| 1645 | |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 1646 | brcmf_os_sdunlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1647 | |
| 1648 | if (ret) |
| 1649 | bus->dhd->tx_ctlerrs++; |
| 1650 | else |
| 1651 | bus->dhd->tx_ctlpkts++; |
| 1652 | |
| 1653 | return ret ? -EIO : 0; |
| 1654 | } |
| 1655 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1656 | int brcmf_sdbrcm_bus_rxctl(struct dhd_bus *bus, unsigned char *msg, uint msglen) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1657 | { |
| 1658 | int timeleft; |
| 1659 | uint rxlen = 0; |
| 1660 | bool pending; |
| 1661 | |
| 1662 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 1663 | |
| 1664 | if (bus->dhd->dongle_reset) |
| 1665 | return -EIO; |
| 1666 | |
| 1667 | /* Wait until control frame is available */ |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 1668 | timeleft = brcmf_os_ioctl_resp_wait(bus->dhd, &bus->rxlen, &pending); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1669 | |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 1670 | brcmf_os_sdlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1671 | rxlen = bus->rxlen; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 1672 | memcpy(msg, bus->rxctl, min(msglen, rxlen)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1673 | bus->rxlen = 0; |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 1674 | brcmf_os_sdunlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1675 | |
| 1676 | if (rxlen) { |
| 1677 | DHD_CTL(("%s: resumed on rxctl frame, got %d expected %d\n", |
| 1678 | __func__, rxlen, msglen)); |
| 1679 | } else if (timeleft == 0) { |
| 1680 | DHD_ERROR(("%s: resumed on timeout\n", __func__)); |
| 1681 | #ifdef DHD_DEBUG |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 1682 | brcmf_os_sdlock(bus->dhd); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1683 | brcmf_sdbrcm_checkdied(bus, NULL, 0); |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 1684 | brcmf_os_sdunlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1685 | #endif /* DHD_DEBUG */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1686 | } else if (pending == true) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1687 | DHD_CTL(("%s: cancelled\n", __func__)); |
| 1688 | return -ERESTARTSYS; |
| 1689 | } else { |
| 1690 | DHD_CTL(("%s: resumed for unknown reason?\n", __func__)); |
| 1691 | #ifdef DHD_DEBUG |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 1692 | brcmf_os_sdlock(bus->dhd); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1693 | brcmf_sdbrcm_checkdied(bus, NULL, 0); |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 1694 | brcmf_os_sdunlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1695 | #endif /* DHD_DEBUG */ |
| 1696 | } |
| 1697 | |
| 1698 | if (rxlen) |
| 1699 | bus->dhd->rx_ctlpkts++; |
| 1700 | else |
| 1701 | bus->dhd->rx_ctlerrs++; |
| 1702 | |
Jason Cooper | e9887c9 | 2010-10-06 10:08:02 -0400 | [diff] [blame] | 1703 | return rxlen ? (int)rxlen : -ETIMEDOUT; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1704 | } |
| 1705 | |
| 1706 | /* IOVar table */ |
| 1707 | enum { |
| 1708 | IOV_INTR = 1, |
| 1709 | IOV_POLLRATE, |
| 1710 | IOV_SDREG, |
| 1711 | IOV_SBREG, |
| 1712 | IOV_SDCIS, |
| 1713 | IOV_MEMBYTES, |
| 1714 | IOV_MEMSIZE, |
| 1715 | #ifdef DHD_DEBUG |
| 1716 | IOV_CHECKDIED, |
| 1717 | #endif |
| 1718 | IOV_DOWNLOAD, |
| 1719 | IOV_FORCEEVEN, |
| 1720 | IOV_SDIOD_DRIVE, |
| 1721 | IOV_READAHEAD, |
| 1722 | IOV_SDRXCHAIN, |
| 1723 | IOV_ALIGNCTL, |
| 1724 | IOV_SDALIGN, |
| 1725 | IOV_DEVRESET, |
| 1726 | IOV_CPU, |
| 1727 | #ifdef SDTEST |
| 1728 | IOV_PKTGEN, |
| 1729 | IOV_EXTLOOP, |
| 1730 | #endif /* SDTEST */ |
| 1731 | IOV_SPROM, |
| 1732 | IOV_TXBOUND, |
| 1733 | IOV_RXBOUND, |
| 1734 | IOV_TXMINMAX, |
| 1735 | IOV_IDLETIME, |
| 1736 | IOV_IDLECLOCK, |
| 1737 | IOV_SD1IDLE, |
| 1738 | IOV_SLEEP, |
| 1739 | IOV_VARS |
| 1740 | }; |
| 1741 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1742 | const struct brcmu_iovar dhdsdio_iovars[] = { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1743 | {"intr", IOV_INTR, 0, IOVT_BOOL, 0}, |
| 1744 | {"sleep", IOV_SLEEP, 0, IOVT_BOOL, 0}, |
| 1745 | {"pollrate", IOV_POLLRATE, 0, IOVT_UINT32, 0}, |
| 1746 | {"idletime", IOV_IDLETIME, 0, IOVT_INT32, 0}, |
| 1747 | {"idleclock", IOV_IDLECLOCK, 0, IOVT_INT32, 0}, |
| 1748 | {"sd1idle", IOV_SD1IDLE, 0, IOVT_BOOL, 0}, |
| 1749 | {"membytes", IOV_MEMBYTES, 0, IOVT_BUFFER, 2 * sizeof(int)}, |
| 1750 | {"memsize", IOV_MEMSIZE, 0, IOVT_UINT32, 0}, |
| 1751 | {"download", IOV_DOWNLOAD, 0, IOVT_BOOL, 0}, |
| 1752 | {"vars", IOV_VARS, 0, IOVT_BUFFER, 0}, |
| 1753 | {"sdiod_drive", IOV_SDIOD_DRIVE, 0, IOVT_UINT32, 0}, |
| 1754 | {"readahead", IOV_READAHEAD, 0, IOVT_BOOL, 0}, |
| 1755 | {"sdrxchain", IOV_SDRXCHAIN, 0, IOVT_BOOL, 0}, |
| 1756 | {"alignctl", IOV_ALIGNCTL, 0, IOVT_BOOL, 0}, |
| 1757 | {"sdalign", IOV_SDALIGN, 0, IOVT_BOOL, 0}, |
| 1758 | {"devreset", IOV_DEVRESET, 0, IOVT_BOOL, 0}, |
| 1759 | #ifdef DHD_DEBUG |
| 1760 | {"sdreg", IOV_SDREG, 0, IOVT_BUFFER, sizeof(sdreg_t)} |
| 1761 | , |
| 1762 | {"sbreg", IOV_SBREG, 0, IOVT_BUFFER, sizeof(sdreg_t)} |
| 1763 | , |
| 1764 | {"sd_cis", IOV_SDCIS, 0, IOVT_BUFFER, DHD_IOCTL_MAXLEN} |
| 1765 | , |
| 1766 | {"forcealign", IOV_FORCEEVEN, 0, IOVT_BOOL, 0} |
| 1767 | , |
| 1768 | {"txbound", IOV_TXBOUND, 0, IOVT_UINT32, 0} |
| 1769 | , |
| 1770 | {"rxbound", IOV_RXBOUND, 0, IOVT_UINT32, 0} |
| 1771 | , |
| 1772 | {"txminmax", IOV_TXMINMAX, 0, IOVT_UINT32, 0} |
| 1773 | , |
| 1774 | {"cpu", IOV_CPU, 0, IOVT_BOOL, 0} |
| 1775 | , |
| 1776 | #ifdef DHD_DEBUG |
| 1777 | {"checkdied", IOV_CHECKDIED, 0, IOVT_BUFFER, 0} |
| 1778 | , |
| 1779 | #endif /* DHD_DEBUG */ |
| 1780 | #endif /* DHD_DEBUG */ |
| 1781 | #ifdef SDTEST |
| 1782 | {"extloop", IOV_EXTLOOP, 0, IOVT_BOOL, 0} |
| 1783 | , |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 1784 | {"pktgen", IOV_PKTGEN, 0, IOVT_BUFFER, sizeof(brcmf_pktgen_t)} |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1785 | , |
| 1786 | #endif /* SDTEST */ |
| 1787 | |
| 1788 | {NULL, 0, 0, 0, 0} |
| 1789 | }; |
| 1790 | |
| 1791 | static void |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1792 | dhd_dump_pct(struct brcmu_strbuf *strbuf, char *desc, uint num, uint div) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1793 | { |
| 1794 | uint q1, q2; |
| 1795 | |
| 1796 | if (!div) { |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1797 | brcmu_bprintf(strbuf, "%s N/A", desc); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1798 | } else { |
| 1799 | q1 = num / div; |
| 1800 | q2 = (100 * (num - (q1 * div))) / div; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1801 | brcmu_bprintf(strbuf, "%s %d.%02d", desc, q1, q2); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1802 | } |
| 1803 | } |
| 1804 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1805 | void brcmf_sdbrcm_bus_dump(dhd_pub_t *dhdp, struct brcmu_strbuf *strbuf) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1806 | { |
| 1807 | dhd_bus_t *bus = dhdp->bus; |
| 1808 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1809 | brcmu_bprintf(strbuf, "Bus SDIO structure:\n"); |
| 1810 | brcmu_bprintf(strbuf, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1811 | "hostintmask 0x%08x intstatus 0x%08x sdpcm_ver %d\n", |
| 1812 | bus->hostintmask, bus->intstatus, bus->sdpcm_ver); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1813 | brcmu_bprintf(strbuf, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1814 | "fcstate %d qlen %d tx_seq %d, max %d, rxskip %d rxlen %d rx_seq %d\n", |
| 1815 | bus->fcstate, pktq_len(&bus->txq), bus->tx_seq, bus->tx_max, |
| 1816 | bus->rxskip, bus->rxlen, bus->rx_seq); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1817 | brcmu_bprintf(strbuf, "intr %d intrcount %d lastintrs %d spurious %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1818 | bus->intr, bus->intrcount, bus->lastintrs, bus->spurious); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1819 | brcmu_bprintf(strbuf, "pollrate %d pollcnt %d regfails %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1820 | bus->pollrate, bus->pollcnt, bus->regfails); |
| 1821 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1822 | brcmu_bprintf(strbuf, "\nAdditional counters:\n"); |
| 1823 | brcmu_bprintf(strbuf, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1824 | "tx_sderrs %d fcqueued %d rxrtx %d rx_toolong %d rxc_errors %d\n", |
| 1825 | bus->tx_sderrs, bus->fcqueued, bus->rxrtx, bus->rx_toolong, |
| 1826 | bus->rxc_errors); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1827 | brcmu_bprintf(strbuf, "rx_hdrfail %d badhdr %d badseq %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1828 | bus->rx_hdrfail, bus->rx_badhdr, bus->rx_badseq); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1829 | brcmu_bprintf(strbuf, "fc_rcvd %d, fc_xoff %d, fc_xon %d\n", |
| 1830 | bus->fc_rcvd, bus->fc_xoff, bus->fc_xon); |
| 1831 | brcmu_bprintf(strbuf, "rxglomfail %d, rxglomframes %d, rxglompkts %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1832 | bus->rxglomfail, bus->rxglomframes, bus->rxglompkts); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1833 | brcmu_bprintf(strbuf, "f2rx (hdrs/data) %d (%d/%d), f2tx %d f1regs" |
| 1834 | " %d\n", |
| 1835 | (bus->f2rxhdrs + bus->f2rxdata), bus->f2rxhdrs, |
| 1836 | bus->f2rxdata, bus->f2txdata, bus->f1regdata); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1837 | { |
| 1838 | dhd_dump_pct(strbuf, "\nRx: pkts/f2rd", bus->dhd->rx_packets, |
| 1839 | (bus->f2rxhdrs + bus->f2rxdata)); |
| 1840 | dhd_dump_pct(strbuf, ", pkts/f1sd", bus->dhd->rx_packets, |
| 1841 | bus->f1regdata); |
| 1842 | dhd_dump_pct(strbuf, ", pkts/sd", bus->dhd->rx_packets, |
| 1843 | (bus->f2rxhdrs + bus->f2rxdata + bus->f1regdata)); |
| 1844 | dhd_dump_pct(strbuf, ", pkts/int", bus->dhd->rx_packets, |
| 1845 | bus->intrcount); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1846 | brcmu_bprintf(strbuf, "\n"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1847 | |
| 1848 | dhd_dump_pct(strbuf, "Rx: glom pct", (100 * bus->rxglompkts), |
| 1849 | bus->dhd->rx_packets); |
| 1850 | dhd_dump_pct(strbuf, ", pkts/glom", bus->rxglompkts, |
| 1851 | bus->rxglomframes); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1852 | brcmu_bprintf(strbuf, "\n"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1853 | |
| 1854 | dhd_dump_pct(strbuf, "Tx: pkts/f2wr", bus->dhd->tx_packets, |
| 1855 | bus->f2txdata); |
| 1856 | dhd_dump_pct(strbuf, ", pkts/f1sd", bus->dhd->tx_packets, |
| 1857 | bus->f1regdata); |
| 1858 | dhd_dump_pct(strbuf, ", pkts/sd", bus->dhd->tx_packets, |
| 1859 | (bus->f2txdata + bus->f1regdata)); |
| 1860 | dhd_dump_pct(strbuf, ", pkts/int", bus->dhd->tx_packets, |
| 1861 | bus->intrcount); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1862 | brcmu_bprintf(strbuf, "\n"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1863 | |
| 1864 | dhd_dump_pct(strbuf, "Total: pkts/f2rw", |
| 1865 | (bus->dhd->tx_packets + bus->dhd->rx_packets), |
| 1866 | (bus->f2txdata + bus->f2rxhdrs + bus->f2rxdata)); |
| 1867 | dhd_dump_pct(strbuf, ", pkts/f1sd", |
| 1868 | (bus->dhd->tx_packets + bus->dhd->rx_packets), |
| 1869 | bus->f1regdata); |
| 1870 | dhd_dump_pct(strbuf, ", pkts/sd", |
| 1871 | (bus->dhd->tx_packets + bus->dhd->rx_packets), |
| 1872 | (bus->f2txdata + bus->f2rxhdrs + bus->f2rxdata + |
| 1873 | bus->f1regdata)); |
| 1874 | dhd_dump_pct(strbuf, ", pkts/int", |
| 1875 | (bus->dhd->tx_packets + bus->dhd->rx_packets), |
| 1876 | bus->intrcount); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1877 | brcmu_bprintf(strbuf, "\n\n"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1878 | } |
| 1879 | |
| 1880 | #ifdef SDTEST |
| 1881 | if (bus->pktgen_count) { |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1882 | brcmu_bprintf(strbuf, "pktgen config and count:\n"); |
| 1883 | brcmu_bprintf(strbuf, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1884 | "freq %d count %d print %d total %d min %d len %d\n", |
| 1885 | bus->pktgen_freq, bus->pktgen_count, |
| 1886 | bus->pktgen_print, bus->pktgen_total, |
| 1887 | bus->pktgen_minlen, bus->pktgen_maxlen); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1888 | brcmu_bprintf(strbuf, "send attempts %d rcvd %d fail %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1889 | bus->pktgen_sent, bus->pktgen_rcvd, |
| 1890 | bus->pktgen_fail); |
| 1891 | } |
| 1892 | #endif /* SDTEST */ |
| 1893 | #ifdef DHD_DEBUG |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1894 | brcmu_bprintf(strbuf, "dpc_sched %d host interrupt%spending\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1895 | bus->dpc_sched, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1896 | (brcmf_sdcard_intr_pending(bus->sdh) ? " " : " not ")); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1897 | brcmu_bprintf(strbuf, "blocksize %d roundup %d\n", bus->blocksize, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1898 | bus->roundup); |
| 1899 | #endif /* DHD_DEBUG */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1900 | brcmu_bprintf(strbuf, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1901 | "clkstate %d activity %d idletime %d idlecount %d sleeping %d\n", |
| 1902 | bus->clkstate, bus->activity, bus->idletime, bus->idlecount, |
| 1903 | bus->sleeping); |
| 1904 | } |
| 1905 | |
| 1906 | void dhd_bus_clearcounts(dhd_pub_t *dhdp) |
| 1907 | { |
| 1908 | dhd_bus_t *bus = (dhd_bus_t *) dhdp->bus; |
| 1909 | |
| 1910 | bus->intrcount = bus->lastintrs = bus->spurious = bus->regfails = 0; |
| 1911 | bus->rxrtx = bus->rx_toolong = bus->rxc_errors = 0; |
| 1912 | bus->rx_hdrfail = bus->rx_badhdr = bus->rx_badseq = 0; |
| 1913 | bus->tx_sderrs = bus->fc_rcvd = bus->fc_xoff = bus->fc_xon = 0; |
| 1914 | bus->rxglomfail = bus->rxglomframes = bus->rxglompkts = 0; |
| 1915 | bus->f2rxhdrs = bus->f2rxdata = bus->f2txdata = bus->f1regdata = 0; |
| 1916 | } |
| 1917 | |
| 1918 | #ifdef SDTEST |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1919 | static int brcmf_sdbrcm_pktgen_get(dhd_bus_t *bus, u8 *arg) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1920 | { |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 1921 | brcmf_pktgen_t pktgen; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1922 | |
| 1923 | pktgen.version = DHD_PKTGEN_VERSION; |
| 1924 | pktgen.freq = bus->pktgen_freq; |
| 1925 | pktgen.count = bus->pktgen_count; |
| 1926 | pktgen.print = bus->pktgen_print; |
| 1927 | pktgen.total = bus->pktgen_total; |
| 1928 | pktgen.minlen = bus->pktgen_minlen; |
| 1929 | pktgen.maxlen = bus->pktgen_maxlen; |
| 1930 | pktgen.numsent = bus->pktgen_sent; |
| 1931 | pktgen.numrcvd = bus->pktgen_rcvd; |
| 1932 | pktgen.numfail = bus->pktgen_fail; |
| 1933 | pktgen.mode = bus->pktgen_mode; |
| 1934 | pktgen.stop = bus->pktgen_stop; |
| 1935 | |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 1936 | memcpy(arg, &pktgen, sizeof(pktgen)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1937 | |
| 1938 | return 0; |
| 1939 | } |
| 1940 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1941 | static int brcmf_sdbrcm_pktgen_set(dhd_bus_t *bus, u8 *arg) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1942 | { |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 1943 | brcmf_pktgen_t pktgen; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1944 | uint oldcnt, oldmode; |
| 1945 | |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 1946 | memcpy(&pktgen, arg, sizeof(pktgen)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1947 | if (pktgen.version != DHD_PKTGEN_VERSION) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 1948 | return -EINVAL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1949 | |
| 1950 | oldcnt = bus->pktgen_count; |
| 1951 | oldmode = bus->pktgen_mode; |
| 1952 | |
| 1953 | bus->pktgen_freq = pktgen.freq; |
| 1954 | bus->pktgen_count = pktgen.count; |
| 1955 | bus->pktgen_print = pktgen.print; |
| 1956 | bus->pktgen_total = pktgen.total; |
| 1957 | bus->pktgen_minlen = pktgen.minlen; |
| 1958 | bus->pktgen_maxlen = pktgen.maxlen; |
| 1959 | bus->pktgen_mode = pktgen.mode; |
| 1960 | bus->pktgen_stop = pktgen.stop; |
| 1961 | |
| 1962 | bus->pktgen_tick = bus->pktgen_ptick = 0; |
Greg Kroah-Hartman | 3ea2f4d | 2010-10-08 11:39:43 -0700 | [diff] [blame] | 1963 | bus->pktgen_len = max(bus->pktgen_len, bus->pktgen_minlen); |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 1964 | bus->pktgen_len = min(bus->pktgen_len, bus->pktgen_maxlen); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1965 | |
| 1966 | /* Clear counts for a new pktgen (mode change, or was stopped) */ |
| 1967 | if (bus->pktgen_count && (!oldcnt || oldmode != bus->pktgen_mode)) |
| 1968 | bus->pktgen_sent = bus->pktgen_rcvd = bus->pktgen_fail = 0; |
| 1969 | |
| 1970 | return 0; |
| 1971 | } |
| 1972 | #endif /* SDTEST */ |
| 1973 | |
| 1974 | static int |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1975 | brcmf_sdbrcm_membytes(dhd_bus_t *bus, bool write, u32 address, u8 *data, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1976 | uint size) |
| 1977 | { |
| 1978 | int bcmerror = 0; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1979 | u32 sdaddr; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1980 | uint dsize; |
| 1981 | |
| 1982 | /* Determine initial transfer parameters */ |
| 1983 | sdaddr = address & SBSDIO_SB_OFT_ADDR_MASK; |
| 1984 | if ((sdaddr + size) & SBSDIO_SBWINDOW_MASK) |
| 1985 | dsize = (SBSDIO_SB_OFT_ADDR_LIMIT - sdaddr); |
| 1986 | else |
| 1987 | dsize = size; |
| 1988 | |
| 1989 | /* Set the backplane window to include the start address */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1990 | bcmerror = brcmf_sdbrcm_set_siaddr_window(bus, address); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1991 | if (bcmerror) { |
| 1992 | DHD_ERROR(("%s: window change failed\n", __func__)); |
| 1993 | goto xfer_done; |
| 1994 | } |
| 1995 | |
| 1996 | /* Do the transfer(s) */ |
| 1997 | while (size) { |
| 1998 | DHD_INFO(("%s: %s %d bytes at offset 0x%08x in window 0x%08x\n", |
| 1999 | __func__, (write ? "write" : "read"), dsize, |
| 2000 | sdaddr, (address & SBSDIO_SBWINDOW_MASK))); |
| 2001 | bcmerror = |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2002 | brcmf_sdcard_rwdata(bus->sdh, write, sdaddr, data, dsize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2003 | if (bcmerror) { |
| 2004 | DHD_ERROR(("%s: membytes transfer failed\n", __func__)); |
| 2005 | break; |
| 2006 | } |
| 2007 | |
| 2008 | /* Adjust for next transfer (if any) */ |
| 2009 | size -= dsize; |
| 2010 | if (size) { |
| 2011 | data += dsize; |
| 2012 | address += dsize; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2013 | bcmerror = brcmf_sdbrcm_set_siaddr_window(bus, address); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2014 | if (bcmerror) { |
| 2015 | DHD_ERROR(("%s: window change failed\n", |
| 2016 | __func__)); |
| 2017 | break; |
| 2018 | } |
| 2019 | sdaddr = 0; |
Greg Kroah-Hartman | b61640d | 2010-10-08 12:37:39 -0700 | [diff] [blame] | 2020 | dsize = min_t(uint, SBSDIO_SB_OFT_ADDR_LIMIT, size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2021 | } |
| 2022 | } |
| 2023 | |
| 2024 | xfer_done: |
| 2025 | /* Return the window to backplane enumeration space for core access */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2026 | if (brcmf_sdbrcm_set_siaddr_window(bus, |
| 2027 | brcmf_sdcard_cur_sbwad(bus->sdh))) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2028 | DHD_ERROR(("%s: FAILED to set window back to 0x%x\n", |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2029 | __func__, brcmf_sdcard_cur_sbwad(bus->sdh))); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2030 | } |
| 2031 | |
| 2032 | return bcmerror; |
| 2033 | } |
| 2034 | |
| 2035 | #ifdef DHD_DEBUG |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2036 | static int brcmf_sdbrcm_readshared(dhd_bus_t *bus, struct sdpcm_shared *sh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2037 | { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2038 | u32 addr; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2039 | int rv; |
| 2040 | |
| 2041 | /* Read last word in memory to determine address of |
| 2042 | sdpcm_shared structure */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2043 | rv = brcmf_sdbrcm_membytes(bus, false, bus->ramsize - 4, (u8 *)&addr, |
| 2044 | 4); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2045 | if (rv < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2046 | return rv; |
| 2047 | |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 2048 | addr = le32_to_cpu(addr); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2049 | |
| 2050 | DHD_INFO(("sdpcm_shared address 0x%08X\n", addr)); |
| 2051 | |
| 2052 | /* |
| 2053 | * Check if addr is valid. |
| 2054 | * NVRAM length at the end of memory should have been overwritten. |
| 2055 | */ |
| 2056 | if (addr == 0 || ((~addr >> 16) & 0xffff) == (addr & 0xffff)) { |
| 2057 | DHD_ERROR(("%s: address (0x%08x) of sdpcm_shared invalid\n", |
| 2058 | __func__, addr)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2059 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2060 | } |
| 2061 | |
Roland Vossen | 70963f9 | 2011-06-01 13:45:08 +0200 | [diff] [blame] | 2062 | /* Read rte_shared structure */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2063 | rv = brcmf_sdbrcm_membytes(bus, false, addr, (u8 *) sh, |
Franky Lin | b49b14d | 2011-06-01 13:45:37 +0200 | [diff] [blame] | 2064 | sizeof(struct sdpcm_shared)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2065 | if (rv < 0) |
| 2066 | return rv; |
| 2067 | |
| 2068 | /* Endianness */ |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 2069 | sh->flags = le32_to_cpu(sh->flags); |
| 2070 | sh->trap_addr = le32_to_cpu(sh->trap_addr); |
| 2071 | sh->assert_exp_addr = le32_to_cpu(sh->assert_exp_addr); |
| 2072 | sh->assert_file_addr = le32_to_cpu(sh->assert_file_addr); |
| 2073 | sh->assert_line = le32_to_cpu(sh->assert_line); |
| 2074 | sh->console_addr = le32_to_cpu(sh->console_addr); |
| 2075 | sh->msgtrace_addr = le32_to_cpu(sh->msgtrace_addr); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2076 | |
| 2077 | if ((sh->flags & SDPCM_SHARED_VERSION_MASK) != SDPCM_SHARED_VERSION) { |
| 2078 | DHD_ERROR(("%s: sdpcm_shared version %d in dhd " |
| 2079 | "is different than sdpcm_shared version %d in dongle\n", |
| 2080 | __func__, SDPCM_SHARED_VERSION, |
| 2081 | sh->flags & SDPCM_SHARED_VERSION_MASK)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2082 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2083 | } |
| 2084 | |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 2085 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2086 | } |
| 2087 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2088 | static int brcmf_sdbrcm_checkdied(dhd_bus_t *bus, u8 *data, uint size) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2089 | { |
| 2090 | int bcmerror = 0; |
| 2091 | uint msize = 512; |
| 2092 | char *mbuffer = NULL; |
| 2093 | uint maxstrlen = 256; |
| 2094 | char *str = NULL; |
| 2095 | trap_t tr; |
Franky Lin | b49b14d | 2011-06-01 13:45:37 +0200 | [diff] [blame] | 2096 | struct sdpcm_shared sdpcm_shared; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2097 | struct brcmu_strbuf strbuf; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2098 | |
| 2099 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 2100 | |
| 2101 | if (data == NULL) { |
| 2102 | /* |
| 2103 | * Called after a rx ctrl timeout. "data" is NULL. |
| 2104 | * allocate memory to trace the trap or assert. |
| 2105 | */ |
| 2106 | size = msize; |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2107 | mbuffer = data = kmalloc(msize, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2108 | if (mbuffer == NULL) { |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2109 | DHD_ERROR(("%s: kmalloc(%d) failed\n", __func__, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2110 | msize)); |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2111 | bcmerror = -ENOMEM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2112 | goto done; |
| 2113 | } |
| 2114 | } |
| 2115 | |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2116 | str = kmalloc(maxstrlen, GFP_ATOMIC); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2117 | if (str == NULL) { |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2118 | DHD_ERROR(("%s: kmalloc(%d) failed\n", __func__, maxstrlen)); |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2119 | bcmerror = -ENOMEM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2120 | goto done; |
| 2121 | } |
| 2122 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2123 | bcmerror = brcmf_sdbrcm_readshared(bus, &sdpcm_shared); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2124 | if (bcmerror < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2125 | goto done; |
| 2126 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2127 | brcmu_binit(&strbuf, data, size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2128 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2129 | brcmu_bprintf(&strbuf, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2130 | "msgtrace address : 0x%08X\nconsole address : 0x%08X\n", |
| 2131 | sdpcm_shared.msgtrace_addr, sdpcm_shared.console_addr); |
| 2132 | |
| 2133 | if ((sdpcm_shared.flags & SDPCM_SHARED_ASSERT_BUILT) == 0) { |
| 2134 | /* NOTE: Misspelled assert is intentional - DO NOT FIX. |
| 2135 | * (Avoids conflict with real asserts for programmatic |
| 2136 | * parsing of output.) |
| 2137 | */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2138 | brcmu_bprintf(&strbuf, "Assrt not built in dongle\n"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2139 | } |
| 2140 | |
| 2141 | if ((sdpcm_shared.flags & (SDPCM_SHARED_ASSERT | SDPCM_SHARED_TRAP)) == |
| 2142 | 0) { |
| 2143 | /* NOTE: Misspelled assert is intentional - DO NOT FIX. |
| 2144 | * (Avoids conflict with real asserts for programmatic |
| 2145 | * parsing of output.) |
| 2146 | */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2147 | brcmu_bprintf(&strbuf, "No trap%s in dongle", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2148 | (sdpcm_shared.flags & SDPCM_SHARED_ASSERT_BUILT) |
| 2149 | ? "/assrt" : ""); |
| 2150 | } else { |
| 2151 | if (sdpcm_shared.flags & SDPCM_SHARED_ASSERT) { |
| 2152 | /* Download assert */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2153 | brcmu_bprintf(&strbuf, "Dongle assert"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2154 | if (sdpcm_shared.assert_exp_addr != 0) { |
| 2155 | str[0] = '\0'; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2156 | bcmerror = brcmf_sdbrcm_membytes(bus, false, |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2157 | sdpcm_shared.assert_exp_addr, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2158 | (u8 *) str, maxstrlen); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2159 | if (bcmerror < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2160 | goto done; |
| 2161 | |
| 2162 | str[maxstrlen - 1] = '\0'; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2163 | brcmu_bprintf(&strbuf, " expr \"%s\"", str); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2164 | } |
| 2165 | |
| 2166 | if (sdpcm_shared.assert_file_addr != 0) { |
| 2167 | str[0] = '\0'; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2168 | bcmerror = brcmf_sdbrcm_membytes(bus, false, |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2169 | sdpcm_shared.assert_file_addr, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2170 | (u8 *) str, maxstrlen); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2171 | if (bcmerror < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2172 | goto done; |
| 2173 | |
| 2174 | str[maxstrlen - 1] = '\0'; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2175 | brcmu_bprintf(&strbuf, " file \"%s\"", str); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2176 | } |
| 2177 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2178 | brcmu_bprintf(&strbuf, " line %d ", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2179 | sdpcm_shared.assert_line); |
| 2180 | } |
| 2181 | |
| 2182 | if (sdpcm_shared.flags & SDPCM_SHARED_TRAP) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2183 | bcmerror = brcmf_sdbrcm_membytes(bus, false, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2184 | sdpcm_shared.trap_addr, (u8 *)&tr, |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2185 | sizeof(trap_t)); |
| 2186 | if (bcmerror < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2187 | goto done; |
| 2188 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2189 | brcmu_bprintf(&strbuf, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2190 | "Dongle trap type 0x%x @ epc 0x%x, cpsr 0x%x, spsr 0x%x, sp 0x%x," |
| 2191 | "lp 0x%x, rpc 0x%x Trap offset 0x%x, " |
| 2192 | "r0 0x%x, r1 0x%x, r2 0x%x, r3 0x%x, r4 0x%x, r5 0x%x, r6 0x%x, r7 0x%x\n", |
| 2193 | tr.type, tr.epc, tr.cpsr, tr.spsr, tr.r13, |
| 2194 | tr.r14, tr.pc, sdpcm_shared.trap_addr, |
| 2195 | tr.r0, tr.r1, tr.r2, tr.r3, tr.r4, tr.r5, |
| 2196 | tr.r6, tr.r7); |
| 2197 | } |
| 2198 | } |
| 2199 | |
| 2200 | if (sdpcm_shared.flags & (SDPCM_SHARED_ASSERT | SDPCM_SHARED_TRAP)) |
| 2201 | DHD_ERROR(("%s: %s\n", __func__, strbuf.origbuf)); |
| 2202 | |
| 2203 | #ifdef DHD_DEBUG |
| 2204 | if (sdpcm_shared.flags & SDPCM_SHARED_TRAP) { |
| 2205 | /* Mem dump to a file on device */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2206 | brcmf_sdbrcm_mem_dump(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2207 | } |
| 2208 | #endif /* DHD_DEBUG */ |
| 2209 | |
| 2210 | done: |
Ilia Mirkin | 46d994b | 2011-03-13 00:28:56 -0500 | [diff] [blame] | 2211 | kfree(mbuffer); |
| 2212 | kfree(str); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2213 | |
| 2214 | return bcmerror; |
| 2215 | } |
| 2216 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2217 | static int brcmf_sdbrcm_mem_dump(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2218 | { |
| 2219 | int ret = 0; |
| 2220 | int size; /* Full mem size */ |
| 2221 | int start = 0; /* Start address */ |
| 2222 | int read_size = 0; /* Read size of each iteration */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2223 | u8 *buf = NULL, *databuf = NULL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2224 | |
| 2225 | /* Get full mem size */ |
| 2226 | size = bus->ramsize; |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2227 | buf = kmalloc(size, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2228 | if (!buf) { |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 2229 | DHD_ERROR(("%s: Out of memory (%d bytes)\n", __func__, size)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2230 | return -1; |
| 2231 | } |
| 2232 | |
| 2233 | /* Read mem content */ |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 2234 | printk(KERN_DEBUG "Dump dongle memory"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2235 | databuf = buf; |
| 2236 | while (size) { |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 2237 | read_size = min(MEMBLOCK, size); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2238 | ret = brcmf_sdbrcm_membytes(bus, false, start, databuf, |
| 2239 | read_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2240 | if (ret) { |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 2241 | DHD_ERROR(("%s: Error membytes %d\n", __func__, ret)); |
Ilia Mirkin | 46d994b | 2011-03-13 00:28:56 -0500 | [diff] [blame] | 2242 | kfree(buf); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2243 | return -1; |
| 2244 | } |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 2245 | printk("."); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2246 | |
| 2247 | /* Decrement size and increment start address */ |
| 2248 | size -= read_size; |
| 2249 | start += read_size; |
| 2250 | databuf += read_size; |
| 2251 | } |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 2252 | printk(KERN_DEBUG "Done\n"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2253 | |
| 2254 | /* free buf before return !!! */ |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 2255 | if (brcmf_write_to_file(bus->dhd, buf, bus->ramsize)) { |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 2256 | DHD_ERROR(("%s: Error writing to files\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2257 | return -1; |
| 2258 | } |
| 2259 | |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 2260 | /* buf free handled in brcmf_write_to_file, not here */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2261 | return 0; |
| 2262 | } |
| 2263 | |
| 2264 | #define CONSOLE_LINE_MAX 192 |
| 2265 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2266 | static int brcmf_sdbrcm_readconsole(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2267 | { |
| 2268 | dhd_console_t *c = &bus->console; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2269 | u8 line[CONSOLE_LINE_MAX], ch; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2270 | u32 n, idx, addr; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2271 | int rv; |
| 2272 | |
| 2273 | /* Don't do anything until FWREADY updates console address */ |
| 2274 | if (bus->console_addr == 0) |
| 2275 | return 0; |
| 2276 | |
| 2277 | /* Read console log struct */ |
Roland Vossen | 70963f9 | 2011-06-01 13:45:08 +0200 | [diff] [blame] | 2278 | addr = bus->console_addr + offsetof(rte_cons_t, log); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2279 | rv = brcmf_sdbrcm_membytes(bus, false, addr, (u8 *)&c->log, |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2280 | sizeof(c->log)); |
| 2281 | if (rv < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2282 | return rv; |
| 2283 | |
| 2284 | /* Allocate console buffer (one time only) */ |
| 2285 | if (c->buf == NULL) { |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 2286 | c->bufsize = le32_to_cpu(c->log.buf_size); |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2287 | c->buf = kmalloc(c->bufsize, GFP_ATOMIC); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2288 | if (c->buf == NULL) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2289 | return -ENOMEM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2290 | } |
| 2291 | |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 2292 | idx = le32_to_cpu(c->log.idx); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2293 | |
| 2294 | /* Protect against corrupt value */ |
| 2295 | if (idx > c->bufsize) |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2296 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2297 | |
| 2298 | /* Skip reading the console buffer if the index pointer |
| 2299 | has not moved */ |
| 2300 | if (idx == c->last) |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 2301 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2302 | |
| 2303 | /* Read the console buffer */ |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 2304 | addr = le32_to_cpu(c->log.buf); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2305 | rv = brcmf_sdbrcm_membytes(bus, false, addr, c->buf, c->bufsize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2306 | if (rv < 0) |
| 2307 | return rv; |
| 2308 | |
| 2309 | while (c->last != idx) { |
| 2310 | for (n = 0; n < CONSOLE_LINE_MAX - 2; n++) { |
| 2311 | if (c->last == idx) { |
| 2312 | /* This would output a partial line. |
| 2313 | * Instead, back up |
| 2314 | * the buffer pointer and output this |
| 2315 | * line next time around. |
| 2316 | */ |
| 2317 | if (c->last >= n) |
| 2318 | c->last -= n; |
| 2319 | else |
| 2320 | c->last = c->bufsize - n; |
| 2321 | goto break2; |
| 2322 | } |
| 2323 | ch = c->buf[c->last]; |
| 2324 | c->last = (c->last + 1) % c->bufsize; |
| 2325 | if (ch == '\n') |
| 2326 | break; |
| 2327 | line[n] = ch; |
| 2328 | } |
| 2329 | |
| 2330 | if (n > 0) { |
| 2331 | if (line[n - 1] == '\r') |
| 2332 | n--; |
| 2333 | line[n] = 0; |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 2334 | printk(KERN_DEBUG "CONSOLE: %s\n", line); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2335 | } |
| 2336 | } |
| 2337 | break2: |
| 2338 | |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 2339 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2340 | } |
| 2341 | #endif /* DHD_DEBUG */ |
| 2342 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2343 | int brcmf_sdbrcm_downloadvars(dhd_bus_t *bus, void *arg, int len) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2344 | { |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 2345 | int bcmerror = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2346 | |
| 2347 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 2348 | |
| 2349 | /* Basic sanity checks */ |
| 2350 | if (bus->dhd->up) { |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2351 | bcmerror = -EISCONN; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2352 | goto err; |
| 2353 | } |
| 2354 | if (!len) { |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2355 | bcmerror = -EOVERFLOW; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2356 | goto err; |
| 2357 | } |
| 2358 | |
| 2359 | /* Free the old ones and replace with passed variables */ |
Ilia Mirkin | 46d994b | 2011-03-13 00:28:56 -0500 | [diff] [blame] | 2360 | kfree(bus->vars); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2361 | |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2362 | bus->vars = kmalloc(len, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2363 | bus->varsz = bus->vars ? len : 0; |
| 2364 | if (bus->vars == NULL) { |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2365 | bcmerror = -ENOMEM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2366 | goto err; |
| 2367 | } |
| 2368 | |
| 2369 | /* Copy the passed variables, which should include the |
| 2370 | terminating double-null */ |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2371 | memcpy(bus->vars, arg, bus->varsz); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2372 | err: |
| 2373 | return bcmerror; |
| 2374 | } |
| 2375 | |
| 2376 | static int |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2377 | brcmf_sdbrcm_doiovar(dhd_bus_t *bus, const struct brcmu_iovar *vi, u32 actionid, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2378 | const char *name, void *params, int plen, void *arg, int len, |
| 2379 | int val_size) |
| 2380 | { |
| 2381 | int bcmerror = 0; |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2382 | s32 int_val = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2383 | bool bool_val = 0; |
| 2384 | |
| 2385 | DHD_TRACE(("%s: Enter, action %d name %s params %p plen %d arg %p " |
| 2386 | "len %d val_size %d\n", |
| 2387 | __func__, actionid, name, params, plen, arg, len, val_size)); |
| 2388 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2389 | bcmerror = brcmu_iovar_lencheck(vi, arg, len, IOV_ISSET(actionid)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2390 | if (bcmerror != 0) |
| 2391 | goto exit; |
| 2392 | |
| 2393 | if (plen >= (int)sizeof(int_val)) |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2394 | memcpy(&int_val, params, sizeof(int_val)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2395 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2396 | bool_val = (int_val != 0) ? true : false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2397 | |
| 2398 | /* Some ioctls use the bus */ |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 2399 | brcmf_os_sdlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2400 | |
| 2401 | /* Check if dongle is in reset. If so, only allow DEVRESET iovars */ |
| 2402 | if (bus->dhd->dongle_reset && !(actionid == IOV_SVAL(IOV_DEVRESET) || |
| 2403 | actionid == IOV_GVAL(IOV_DEVRESET))) { |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2404 | bcmerror = -EPERM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2405 | goto exit; |
| 2406 | } |
| 2407 | |
| 2408 | /* Handle sleep stuff before any clock mucking */ |
| 2409 | if (vi->varid == IOV_SLEEP) { |
| 2410 | if (IOV_ISSET(actionid)) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2411 | bcmerror = brcmf_sdbrcm_bussleep(bus, bool_val); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2412 | } else { |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2413 | int_val = (s32) bus->sleeping; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2414 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2415 | } |
| 2416 | goto exit; |
| 2417 | } |
| 2418 | |
| 2419 | /* Request clock to allow SDIO accesses */ |
| 2420 | if (!bus->dhd->dongle_reset) { |
| 2421 | BUS_WAKE(bus); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2422 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2423 | } |
| 2424 | |
| 2425 | switch (actionid) { |
| 2426 | case IOV_GVAL(IOV_INTR): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2427 | int_val = (s32) bus->intr; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2428 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2429 | break; |
| 2430 | |
| 2431 | case IOV_SVAL(IOV_INTR): |
| 2432 | bus->intr = bool_val; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2433 | bus->intdis = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2434 | if (bus->dhd->up) { |
| 2435 | if (bus->intr) { |
| 2436 | DHD_INTR(("%s: enable SDIO device interrupts\n", |
| 2437 | __func__)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2438 | brcmf_sdcard_intr_enable(bus->sdh); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2439 | } else { |
| 2440 | DHD_INTR(("%s: disable SDIO interrupts\n", |
| 2441 | __func__)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2442 | brcmf_sdcard_intr_disable(bus->sdh); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2443 | } |
| 2444 | } |
| 2445 | break; |
| 2446 | |
| 2447 | case IOV_GVAL(IOV_POLLRATE): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2448 | int_val = (s32) bus->pollrate; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2449 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2450 | break; |
| 2451 | |
| 2452 | case IOV_SVAL(IOV_POLLRATE): |
| 2453 | bus->pollrate = (uint) int_val; |
| 2454 | bus->poll = (bus->pollrate != 0); |
| 2455 | break; |
| 2456 | |
| 2457 | case IOV_GVAL(IOV_IDLETIME): |
| 2458 | int_val = bus->idletime; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2459 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2460 | break; |
| 2461 | |
| 2462 | case IOV_SVAL(IOV_IDLETIME): |
| 2463 | if ((int_val < 0) && (int_val != DHD_IDLE_IMMEDIATE)) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2464 | bcmerror = -EINVAL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2465 | else |
| 2466 | bus->idletime = int_val; |
| 2467 | break; |
| 2468 | |
| 2469 | case IOV_GVAL(IOV_IDLECLOCK): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2470 | int_val = (s32) bus->idleclock; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2471 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2472 | break; |
| 2473 | |
| 2474 | case IOV_SVAL(IOV_IDLECLOCK): |
| 2475 | bus->idleclock = int_val; |
| 2476 | break; |
| 2477 | |
| 2478 | case IOV_GVAL(IOV_SD1IDLE): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2479 | int_val = (s32) sd1idle; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2480 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2481 | break; |
| 2482 | |
| 2483 | case IOV_SVAL(IOV_SD1IDLE): |
| 2484 | sd1idle = bool_val; |
| 2485 | break; |
| 2486 | |
| 2487 | case IOV_SVAL(IOV_MEMBYTES): |
| 2488 | case IOV_GVAL(IOV_MEMBYTES): |
| 2489 | { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2490 | u32 address; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2491 | uint size, dsize; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2492 | u8 *data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2493 | |
| 2494 | bool set = (actionid == IOV_SVAL(IOV_MEMBYTES)); |
| 2495 | |
| 2496 | ASSERT(plen >= 2 * sizeof(int)); |
| 2497 | |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2498 | address = (u32) int_val; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2499 | memcpy(&int_val, (char *)params + sizeof(int_val), |
| 2500 | sizeof(int_val)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2501 | size = (uint) int_val; |
| 2502 | |
| 2503 | /* Do some validation */ |
| 2504 | dsize = set ? plen - (2 * sizeof(int)) : len; |
| 2505 | if (dsize < size) { |
| 2506 | DHD_ERROR(("%s: error on %s membytes, addr " |
| 2507 | "0x%08x size %d dsize %d\n", |
| 2508 | __func__, (set ? "set" : "get"), |
| 2509 | address, size, dsize)); |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2510 | bcmerror = -EINVAL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2511 | break; |
| 2512 | } |
| 2513 | |
| 2514 | DHD_INFO(("%s: Request to %s %d bytes at address " |
| 2515 | "0x%08x\n", |
| 2516 | __func__, (set ? "write" : "read"), size, address)); |
| 2517 | |
| 2518 | /* If we know about SOCRAM, check for a fit */ |
| 2519 | if ((bus->orig_ramsize) && |
| 2520 | ((address > bus->orig_ramsize) |
| 2521 | || (address + size > bus->orig_ramsize))) { |
| 2522 | DHD_ERROR(("%s: ramsize 0x%08x doesn't have %d " |
| 2523 | "bytes at 0x%08x\n", |
| 2524 | __func__, bus->orig_ramsize, size, address)); |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2525 | bcmerror = -EINVAL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2526 | break; |
| 2527 | } |
| 2528 | |
| 2529 | /* Generate the actual data pointer */ |
| 2530 | data = |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2531 | set ? (u8 *) params + |
| 2532 | 2 * sizeof(int) : (u8 *) arg; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2533 | |
| 2534 | /* Call to do the transfer */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2535 | bcmerror = brcmf_sdbrcm_membytes(bus, set, address, |
| 2536 | data, size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2537 | |
| 2538 | break; |
| 2539 | } |
| 2540 | |
| 2541 | case IOV_GVAL(IOV_MEMSIZE): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2542 | int_val = (s32) bus->ramsize; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2543 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2544 | break; |
| 2545 | |
| 2546 | case IOV_GVAL(IOV_SDIOD_DRIVE): |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 2547 | int_val = (s32) brcmf_sdiod_drive_strength; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2548 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2549 | break; |
| 2550 | |
| 2551 | case IOV_SVAL(IOV_SDIOD_DRIVE): |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 2552 | brcmf_sdiod_drive_strength = int_val; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2553 | brcmf_sdbrcm_sdiod_drive_strength_init(bus, |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 2554 | brcmf_sdiod_drive_strength); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2555 | break; |
| 2556 | |
| 2557 | case IOV_SVAL(IOV_DOWNLOAD): |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2558 | bcmerror = brcmf_sdbrcm_download_state(bus, bool_val); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2559 | break; |
| 2560 | |
| 2561 | case IOV_SVAL(IOV_VARS): |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2562 | bcmerror = brcmf_sdbrcm_downloadvars(bus, arg, len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2563 | break; |
| 2564 | |
| 2565 | case IOV_GVAL(IOV_READAHEAD): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2566 | int_val = (s32) dhd_readahead; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2567 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2568 | break; |
| 2569 | |
| 2570 | case IOV_SVAL(IOV_READAHEAD): |
| 2571 | if (bool_val && !dhd_readahead) |
| 2572 | bus->nextlen = 0; |
| 2573 | dhd_readahead = bool_val; |
| 2574 | break; |
| 2575 | |
| 2576 | case IOV_GVAL(IOV_SDRXCHAIN): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2577 | int_val = (s32) bus->use_rxchain; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2578 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2579 | break; |
| 2580 | |
| 2581 | case IOV_SVAL(IOV_SDRXCHAIN): |
| 2582 | if (bool_val && !bus->sd_rxchain) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2583 | bcmerror = -ENOTSUPP; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2584 | else |
| 2585 | bus->use_rxchain = bool_val; |
| 2586 | break; |
| 2587 | case IOV_GVAL(IOV_ALIGNCTL): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2588 | int_val = (s32) dhd_alignctl; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2589 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2590 | break; |
| 2591 | |
| 2592 | case IOV_SVAL(IOV_ALIGNCTL): |
| 2593 | dhd_alignctl = bool_val; |
| 2594 | break; |
| 2595 | |
| 2596 | case IOV_GVAL(IOV_SDALIGN): |
| 2597 | int_val = DHD_SDALIGN; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2598 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2599 | break; |
| 2600 | |
| 2601 | #ifdef DHD_DEBUG |
| 2602 | case IOV_GVAL(IOV_VARS): |
| 2603 | if (bus->varsz < (uint) len) |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2604 | memcpy(arg, bus->vars, bus->varsz); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2605 | else |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2606 | bcmerror = -EOVERFLOW; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2607 | break; |
| 2608 | #endif /* DHD_DEBUG */ |
| 2609 | |
| 2610 | #ifdef DHD_DEBUG |
| 2611 | case IOV_GVAL(IOV_SDREG): |
| 2612 | { |
| 2613 | sdreg_t *sd_ptr; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2614 | u32 addr, size; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2615 | |
| 2616 | sd_ptr = (sdreg_t *) params; |
| 2617 | |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 2618 | addr = (unsigned long)bus->regs + sd_ptr->offset; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2619 | size = sd_ptr->func; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2620 | int_val = (s32) brcmf_sdcard_reg_read(bus->sdh, addr, |
| 2621 | size); |
| 2622 | if (brcmf_sdcard_regfail(bus->sdh)) |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2623 | bcmerror = -EIO; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2624 | memcpy(arg, &int_val, sizeof(s32)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2625 | break; |
| 2626 | } |
| 2627 | |
| 2628 | case IOV_SVAL(IOV_SDREG): |
| 2629 | { |
| 2630 | sdreg_t *sd_ptr; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2631 | u32 addr, size; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2632 | |
| 2633 | sd_ptr = (sdreg_t *) params; |
| 2634 | |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 2635 | addr = (unsigned long)bus->regs + sd_ptr->offset; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2636 | size = sd_ptr->func; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2637 | brcmf_sdcard_reg_write(bus->sdh, addr, size, |
| 2638 | sd_ptr->value); |
| 2639 | if (brcmf_sdcard_regfail(bus->sdh)) |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2640 | bcmerror = -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2641 | break; |
| 2642 | } |
| 2643 | |
| 2644 | /* Same as above, but offset is not backplane |
| 2645 | (not SDIO core) */ |
| 2646 | case IOV_GVAL(IOV_SBREG): |
| 2647 | { |
| 2648 | sdreg_t sdreg; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2649 | u32 addr, size; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2650 | |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2651 | memcpy(&sdreg, params, sizeof(sdreg)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2652 | |
| 2653 | addr = SI_ENUM_BASE + sdreg.offset; |
| 2654 | size = sdreg.func; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2655 | int_val = (s32) brcmf_sdcard_reg_read(bus->sdh, addr, |
| 2656 | size); |
| 2657 | if (brcmf_sdcard_regfail(bus->sdh)) |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2658 | bcmerror = -EIO; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2659 | memcpy(arg, &int_val, sizeof(s32)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2660 | break; |
| 2661 | } |
| 2662 | |
| 2663 | case IOV_SVAL(IOV_SBREG): |
| 2664 | { |
| 2665 | sdreg_t sdreg; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2666 | u32 addr, size; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2667 | |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2668 | memcpy(&sdreg, params, sizeof(sdreg)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2669 | |
| 2670 | addr = SI_ENUM_BASE + sdreg.offset; |
| 2671 | size = sdreg.func; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2672 | brcmf_sdcard_reg_write(bus->sdh, addr, size, |
| 2673 | sdreg.value); |
| 2674 | if (brcmf_sdcard_regfail(bus->sdh)) |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2675 | bcmerror = -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2676 | break; |
| 2677 | } |
| 2678 | |
| 2679 | case IOV_GVAL(IOV_SDCIS): |
| 2680 | { |
| 2681 | *(char *)arg = 0; |
| 2682 | |
nohee ko | ea3b8a2 | 2010-10-09 10:34:38 -0700 | [diff] [blame] | 2683 | strcat(arg, "\nFunc 0\n"); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2684 | brcmf_sdcard_cis_read(bus->sdh, 0x10, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2685 | (u8 *) arg + strlen(arg), |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2686 | SBSDIO_CIS_SIZE_LIMIT); |
nohee ko | ea3b8a2 | 2010-10-09 10:34:38 -0700 | [diff] [blame] | 2687 | strcat(arg, "\nFunc 1\n"); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2688 | brcmf_sdcard_cis_read(bus->sdh, 0x11, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2689 | (u8 *) arg + strlen(arg), |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2690 | SBSDIO_CIS_SIZE_LIMIT); |
nohee ko | ea3b8a2 | 2010-10-09 10:34:38 -0700 | [diff] [blame] | 2691 | strcat(arg, "\nFunc 2\n"); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2692 | brcmf_sdcard_cis_read(bus->sdh, 0x12, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2693 | (u8 *) arg + strlen(arg), |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2694 | SBSDIO_CIS_SIZE_LIMIT); |
| 2695 | break; |
| 2696 | } |
| 2697 | |
| 2698 | case IOV_GVAL(IOV_FORCEEVEN): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2699 | int_val = (s32) forcealign; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2700 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2701 | break; |
| 2702 | |
| 2703 | case IOV_SVAL(IOV_FORCEEVEN): |
| 2704 | forcealign = bool_val; |
| 2705 | break; |
| 2706 | |
| 2707 | case IOV_GVAL(IOV_TXBOUND): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2708 | int_val = (s32) dhd_txbound; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2709 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2710 | break; |
| 2711 | |
| 2712 | case IOV_SVAL(IOV_TXBOUND): |
| 2713 | dhd_txbound = (uint) int_val; |
| 2714 | break; |
| 2715 | |
| 2716 | case IOV_GVAL(IOV_RXBOUND): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2717 | int_val = (s32) dhd_rxbound; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2718 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2719 | break; |
| 2720 | |
| 2721 | case IOV_SVAL(IOV_RXBOUND): |
| 2722 | dhd_rxbound = (uint) int_val; |
| 2723 | break; |
| 2724 | |
| 2725 | case IOV_GVAL(IOV_TXMINMAX): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2726 | int_val = (s32) dhd_txminmax; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2727 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2728 | break; |
| 2729 | |
| 2730 | case IOV_SVAL(IOV_TXMINMAX): |
| 2731 | dhd_txminmax = (uint) int_val; |
| 2732 | break; |
| 2733 | #endif /* DHD_DEBUG */ |
| 2734 | |
| 2735 | #ifdef SDTEST |
| 2736 | case IOV_GVAL(IOV_EXTLOOP): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2737 | int_val = (s32) bus->ext_loop; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2738 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2739 | break; |
| 2740 | |
| 2741 | case IOV_SVAL(IOV_EXTLOOP): |
| 2742 | bus->ext_loop = bool_val; |
| 2743 | break; |
| 2744 | |
| 2745 | case IOV_GVAL(IOV_PKTGEN): |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2746 | bcmerror = brcmf_sdbrcm_pktgen_get(bus, arg); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2747 | break; |
| 2748 | |
| 2749 | case IOV_SVAL(IOV_PKTGEN): |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2750 | bcmerror = brcmf_sdbrcm_pktgen_set(bus, arg); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2751 | break; |
| 2752 | #endif /* SDTEST */ |
| 2753 | |
| 2754 | case IOV_SVAL(IOV_DEVRESET): |
| 2755 | DHD_TRACE(("%s: Called set IOV_DEVRESET=%d dongle_reset=%d " |
| 2756 | "busstate=%d\n", |
| 2757 | __func__, bool_val, bus->dhd->dongle_reset, |
| 2758 | bus->dhd->busstate)); |
| 2759 | |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 2760 | brcmf_bus_devreset(bus->dhd, (u8) bool_val); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2761 | |
| 2762 | break; |
| 2763 | |
| 2764 | case IOV_GVAL(IOV_DEVRESET): |
| 2765 | DHD_TRACE(("%s: Called get IOV_DEVRESET\n", __func__)); |
| 2766 | |
| 2767 | /* Get its status */ |
| 2768 | int_val = (bool) bus->dhd->dongle_reset; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2769 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2770 | |
| 2771 | break; |
| 2772 | |
| 2773 | default: |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2774 | bcmerror = -ENOTSUPP; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2775 | break; |
| 2776 | } |
| 2777 | |
| 2778 | exit: |
| 2779 | if ((bus->idletime == DHD_IDLE_IMMEDIATE) && !bus->dpc_sched) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2780 | bus->activity = false; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2781 | brcmf_sdbrcm_clkctl(bus, CLK_NONE, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2782 | } |
| 2783 | |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 2784 | brcmf_os_sdunlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2785 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2786 | if (actionid == IOV_SVAL(IOV_DEVRESET) && bool_val == false) |
Arend van Spriel | aba5e0a | 2011-06-29 16:47:03 -0700 | [diff] [blame] | 2787 | brcmf_c_preinit_ioctls((dhd_pub_t *) bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2788 | |
| 2789 | return bcmerror; |
| 2790 | } |
| 2791 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2792 | static int brcmf_sdbrcm_write_vars(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2793 | { |
| 2794 | int bcmerror = 0; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2795 | u32 varsize; |
| 2796 | u32 varaddr; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2797 | u8 *vbuffer; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2798 | u32 varsizew; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2799 | #ifdef DHD_DEBUG |
| 2800 | char *nvram_ularray; |
| 2801 | #endif /* DHD_DEBUG */ |
| 2802 | |
| 2803 | /* Even if there are no vars are to be written, we still |
| 2804 | need to set the ramsize. */ |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 2805 | varsize = bus->varsz ? roundup(bus->varsz, 4) : 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2806 | varaddr = (bus->ramsize - 4) - varsize; |
| 2807 | |
| 2808 | if (bus->vars) { |
Alexander Beregalov | 12d0eb4 | 2011-03-09 03:53:35 +0300 | [diff] [blame] | 2809 | vbuffer = kzalloc(varsize, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2810 | if (!vbuffer) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2811 | return -ENOMEM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2812 | |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2813 | memcpy(vbuffer, bus->vars, bus->varsz); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2814 | |
| 2815 | /* Write the vars list */ |
| 2816 | bcmerror = |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2817 | brcmf_sdbrcm_membytes(bus, true, varaddr, vbuffer, varsize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2818 | #ifdef DHD_DEBUG |
| 2819 | /* Verify NVRAM bytes */ |
| 2820 | DHD_INFO(("Compare NVRAM dl & ul; varsize=%d\n", varsize)); |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2821 | nvram_ularray = kmalloc(varsize, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2822 | if (!nvram_ularray) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2823 | return -ENOMEM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2824 | |
| 2825 | /* Upload image to verify downloaded contents. */ |
| 2826 | memset(nvram_ularray, 0xaa, varsize); |
| 2827 | |
| 2828 | /* Read the vars list to temp buffer for comparison */ |
| 2829 | bcmerror = |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2830 | brcmf_sdbrcm_membytes(bus, false, varaddr, nvram_ularray, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2831 | varsize); |
| 2832 | if (bcmerror) { |
| 2833 | DHD_ERROR(("%s: error %d on reading %d nvram bytes at " |
| 2834 | "0x%08x\n", __func__, bcmerror, varsize, varaddr)); |
| 2835 | } |
| 2836 | /* Compare the org NVRAM with the one read from RAM */ |
| 2837 | if (memcmp(vbuffer, nvram_ularray, varsize)) { |
| 2838 | DHD_ERROR(("%s: Downloaded NVRAM image is corrupted.\n", |
| 2839 | __func__)); |
| 2840 | } else |
| 2841 | DHD_ERROR(("%s: Download/Upload/Compare of NVRAM ok.\n", |
| 2842 | __func__)); |
| 2843 | |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 2844 | kfree(nvram_ularray); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2845 | #endif /* DHD_DEBUG */ |
| 2846 | |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 2847 | kfree(vbuffer); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2848 | } |
| 2849 | |
| 2850 | /* adjust to the user specified RAM */ |
| 2851 | DHD_INFO(("Physical memory size: %d, usable memory size: %d\n", |
| 2852 | bus->orig_ramsize, bus->ramsize)); |
| 2853 | DHD_INFO(("Vars are at %d, orig varsize is %d\n", varaddr, varsize)); |
| 2854 | varsize = ((bus->orig_ramsize - 4) - varaddr); |
| 2855 | |
| 2856 | /* |
| 2857 | * Determine the length token: |
| 2858 | * Varsize, converted to words, in lower 16-bits, checksum |
| 2859 | * in upper 16-bits. |
| 2860 | */ |
| 2861 | if (bcmerror) { |
| 2862 | varsizew = 0; |
| 2863 | } else { |
| 2864 | varsizew = varsize / 4; |
| 2865 | varsizew = (~varsizew << 16) | (varsizew & 0x0000FFFF); |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 2866 | varsizew = cpu_to_le32(varsizew); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2867 | } |
| 2868 | |
| 2869 | DHD_INFO(("New varsize is %d, length token=0x%08x\n", varsize, |
| 2870 | varsizew)); |
| 2871 | |
| 2872 | /* Write the length token to the last word */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2873 | bcmerror = brcmf_sdbrcm_membytes(bus, true, (bus->orig_ramsize - 4), |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2874 | (u8 *)&varsizew, 4); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2875 | |
| 2876 | return bcmerror; |
| 2877 | } |
| 2878 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2879 | static int brcmf_sdbrcm_download_state(dhd_bus_t *bus, bool enter) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2880 | { |
| 2881 | uint retries; |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 2882 | u32 regdata; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2883 | int bcmerror = 0; |
| 2884 | |
| 2885 | /* To enter download state, disable ARM and reset SOCRAM. |
| 2886 | * To exit download state, simply reset ARM (default is RAM boot). |
| 2887 | */ |
| 2888 | if (enter) { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2889 | bus->alp_only = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2890 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2891 | brcmf_sdbrcm_chip_disablecore(bus->sdh, bus->ci->armcorebase); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2892 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2893 | brcmf_sdbrcm_chip_resetcore(bus->sdh, bus->ci->ramcorebase); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2894 | |
| 2895 | /* Clear the top bit of memory */ |
| 2896 | if (bus->ramsize) { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2897 | u32 zeros = 0; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2898 | brcmf_sdbrcm_membytes(bus, true, bus->ramsize - 4, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2899 | (u8 *)&zeros, 4); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2900 | } |
| 2901 | } else { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2902 | regdata = brcmf_sdcard_reg_read(bus->sdh, |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 2903 | CORE_SB(bus->ci->ramcorebase, sbtmstatelow), 4); |
| 2904 | regdata &= (SBTML_RESET | SBTML_REJ_MASK | |
| 2905 | (SICF_CLOCK_EN << SBTML_SICF_SHIFT)); |
| 2906 | if ((SICF_CLOCK_EN << SBTML_SICF_SHIFT) != regdata) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2907 | DHD_ERROR(("%s: SOCRAM core is down after reset?\n", |
| 2908 | __func__)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2909 | bcmerror = -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2910 | goto fail; |
| 2911 | } |
| 2912 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2913 | bcmerror = brcmf_sdbrcm_write_vars(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2914 | if (bcmerror) { |
| 2915 | DHD_ERROR(("%s: no vars written to RAM\n", __func__)); |
| 2916 | bcmerror = 0; |
| 2917 | } |
| 2918 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2919 | W_SDREG(0xFFFFFFFF, &bus->regs->intstatus, retries); |
| 2920 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2921 | brcmf_sdbrcm_chip_resetcore(bus->sdh, bus->ci->armcorebase); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2922 | |
| 2923 | /* Allow HT Clock now that the ARM is running. */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2924 | bus->alp_only = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2925 | |
| 2926 | bus->dhd->busstate = DHD_BUS_LOAD; |
| 2927 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2928 | fail: |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2929 | return bcmerror; |
| 2930 | } |
| 2931 | |
| 2932 | int |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2933 | brcmf_sdbrcm_bus_iovar_op(dhd_pub_t *dhdp, const char *name, |
| 2934 | void *params, int plen, void *arg, int len, bool set) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2935 | { |
| 2936 | dhd_bus_t *bus = dhdp->bus; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2937 | const struct brcmu_iovar *vi = NULL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2938 | int bcmerror = 0; |
| 2939 | int val_size; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2940 | u32 actionid; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2941 | |
| 2942 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 2943 | |
| 2944 | ASSERT(name); |
| 2945 | ASSERT(len >= 0); |
| 2946 | |
| 2947 | /* Get MUST have return space */ |
| 2948 | ASSERT(set || (arg && len)); |
| 2949 | |
| 2950 | /* Set does NOT take qualifiers */ |
| 2951 | ASSERT(!set || (!params && !plen)); |
| 2952 | |
| 2953 | /* Look up var locally; if not found pass to host driver */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2954 | vi = brcmu_iovar_lookup(dhdsdio_iovars, name); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2955 | if (vi == NULL) { |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 2956 | brcmf_os_sdlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2957 | |
| 2958 | BUS_WAKE(bus); |
| 2959 | |
| 2960 | /* Turn on clock in case SD command needs backplane */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2961 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2962 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2963 | bcmerror = brcmf_sdcard_iovar_op(bus->sdh, name, params, plen, |
| 2964 | arg, len, set); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2965 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2966 | /* Similar check for blocksize change */ |
| 2967 | if (set && strcmp(name, "sd_blocksize") == 0) { |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2968 | s32 fnum = 2; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2969 | if (brcmf_sdcard_iovar_op |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2970 | (bus->sdh, "sd_blocksize", &fnum, sizeof(s32), |
| 2971 | &bus->blocksize, sizeof(s32), |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 2972 | false) != 0) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2973 | bus->blocksize = 0; |
| 2974 | DHD_ERROR(("%s: fail on %s get\n", __func__, |
| 2975 | "sd_blocksize")); |
| 2976 | } else { |
| 2977 | DHD_INFO(("%s: noted %s update, value now %d\n", |
| 2978 | __func__, "sd_blocksize", |
| 2979 | bus->blocksize)); |
| 2980 | } |
| 2981 | } |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 2982 | bus->roundup = min(max_roundup, bus->blocksize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2983 | |
| 2984 | if ((bus->idletime == DHD_IDLE_IMMEDIATE) && !bus->dpc_sched) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2985 | bus->activity = false; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2986 | brcmf_sdbrcm_clkctl(bus, CLK_NONE, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2987 | } |
| 2988 | |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 2989 | brcmf_os_sdunlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2990 | goto exit; |
| 2991 | } |
| 2992 | |
| 2993 | DHD_CTL(("%s: %s %s, len %d plen %d\n", __func__, |
| 2994 | name, (set ? "set" : "get"), len, plen)); |
| 2995 | |
| 2996 | /* set up 'params' pointer in case this is a set command so that |
| 2997 | * the convenience int and bool code can be common to set and get |
| 2998 | */ |
| 2999 | if (params == NULL) { |
| 3000 | params = arg; |
| 3001 | plen = len; |
| 3002 | } |
| 3003 | |
| 3004 | if (vi->type == IOVT_VOID) |
| 3005 | val_size = 0; |
| 3006 | else if (vi->type == IOVT_BUFFER) |
| 3007 | val_size = len; |
| 3008 | else |
| 3009 | /* all other types are integer sized */ |
| 3010 | val_size = sizeof(int); |
| 3011 | |
| 3012 | actionid = set ? IOV_SVAL(vi->varid) : IOV_GVAL(vi->varid); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3013 | bcmerror = brcmf_sdbrcm_doiovar(bus, vi, actionid, name, params, plen, |
| 3014 | arg, len, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3015 | |
| 3016 | exit: |
| 3017 | return bcmerror; |
| 3018 | } |
| 3019 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3020 | void brcmf_sdbrcm_bus_stop(struct dhd_bus *bus, bool enforce_mutex) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3021 | { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 3022 | u32 local_hostintmask; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3023 | u8 saveclk; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3024 | uint retries; |
| 3025 | int err; |
| 3026 | |
| 3027 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 3028 | |
| 3029 | if (enforce_mutex) |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 3030 | brcmf_os_sdlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3031 | |
| 3032 | BUS_WAKE(bus); |
| 3033 | |
| 3034 | /* Enable clock for device interrupts */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3035 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3036 | |
| 3037 | /* Disable and clear interrupts at the chip level also */ |
| 3038 | W_SDREG(0, &bus->regs->hostintmask, retries); |
| 3039 | local_hostintmask = bus->hostintmask; |
| 3040 | bus->hostintmask = 0; |
| 3041 | |
| 3042 | /* Change our idea of bus state */ |
| 3043 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 3044 | |
| 3045 | /* Force clocks on backplane to be sure F2 interrupt propagates */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3046 | saveclk = brcmf_sdcard_cfg_read(bus->sdh, SDIO_FUNC_1, |
| 3047 | SBSDIO_FUNC1_CHIPCLKCSR, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3048 | if (!err) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3049 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_1, |
| 3050 | SBSDIO_FUNC1_CHIPCLKCSR, |
| 3051 | (saveclk | SBSDIO_FORCE_HT), &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3052 | } |
| 3053 | if (err) { |
| 3054 | DHD_ERROR(("%s: Failed to force clock for F2: err %d\n", |
| 3055 | __func__, err)); |
| 3056 | } |
| 3057 | |
| 3058 | /* Turn off the bus (F2), free any pending packets */ |
| 3059 | DHD_INTR(("%s: disable SDIO interrupts\n", __func__)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3060 | brcmf_sdcard_intr_disable(bus->sdh); |
| 3061 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_0, SDIO_CCCR_IOEx, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3062 | SDIO_FUNC_ENABLE_1, NULL); |
| 3063 | |
| 3064 | /* Clear any pending interrupts now that F2 is disabled */ |
| 3065 | W_SDREG(local_hostintmask, &bus->regs->intstatus, retries); |
| 3066 | |
| 3067 | /* Turn off the backplane clock (only) */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3068 | brcmf_sdbrcm_clkctl(bus, CLK_SDONLY, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3069 | |
| 3070 | /* Clear the data packet queues */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3071 | brcmu_pktq_flush(&bus->txq, true, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3072 | |
| 3073 | /* Clear any held glomming stuff */ |
| 3074 | if (bus->glomd) |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3075 | brcmu_pkt_buf_free_skb(bus->glomd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3076 | |
| 3077 | if (bus->glom) |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3078 | brcmu_pkt_buf_free_skb(bus->glom); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3079 | |
| 3080 | bus->glom = bus->glomd = NULL; |
| 3081 | |
| 3082 | /* Clear rx control and wake any waiters */ |
| 3083 | bus->rxlen = 0; |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 3084 | brcmf_os_ioctl_resp_wake(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3085 | |
| 3086 | /* Reset some F2 state stuff */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3087 | bus->rxskip = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3088 | bus->tx_seq = bus->rx_seq = 0; |
| 3089 | |
| 3090 | if (enforce_mutex) |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 3091 | brcmf_os_sdunlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3092 | } |
| 3093 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3094 | int brcmf_sdbrcm_bus_init(dhd_pub_t *dhdp, bool enforce_mutex) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3095 | { |
| 3096 | dhd_bus_t *bus = dhdp->bus; |
| 3097 | dhd_timeout_t tmo; |
| 3098 | uint retries = 0; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3099 | u8 ready, enable; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3100 | int err, ret = 0; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3101 | u8 saveclk; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3102 | |
| 3103 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 3104 | |
| 3105 | ASSERT(bus->dhd); |
| 3106 | if (!bus->dhd) |
| 3107 | return 0; |
| 3108 | |
| 3109 | if (enforce_mutex) |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 3110 | brcmf_os_sdlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3111 | |
| 3112 | /* Make sure backplane clock is on, needed to generate F2 interrupt */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3113 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3114 | if (bus->clkstate != CLK_AVAIL) |
| 3115 | goto exit; |
| 3116 | |
| 3117 | /* Force clocks on backplane to be sure F2 interrupt propagates */ |
| 3118 | saveclk = |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3119 | brcmf_sdcard_cfg_read(bus->sdh, SDIO_FUNC_1, |
| 3120 | SBSDIO_FUNC1_CHIPCLKCSR, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3121 | if (!err) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3122 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_1, |
| 3123 | SBSDIO_FUNC1_CHIPCLKCSR, |
| 3124 | (saveclk | SBSDIO_FORCE_HT), &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3125 | } |
| 3126 | if (err) { |
| 3127 | DHD_ERROR(("%s: Failed to force clock for F2: err %d\n", |
| 3128 | __func__, err)); |
| 3129 | goto exit; |
| 3130 | } |
| 3131 | |
| 3132 | /* Enable function 2 (frame transfers) */ |
| 3133 | W_SDREG((SDPCM_PROT_VERSION << SMB_DATA_VERSION_SHIFT), |
| 3134 | &bus->regs->tosbmailboxdata, retries); |
| 3135 | enable = (SDIO_FUNC_ENABLE_1 | SDIO_FUNC_ENABLE_2); |
| 3136 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3137 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_0, SDIO_CCCR_IOEx, enable, |
| 3138 | NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3139 | |
| 3140 | /* Give the dongle some time to do its thing and set IOR2 */ |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 3141 | brcmf_timeout_start(&tmo, DHD_WAIT_F2RDY * 1000); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3142 | |
| 3143 | ready = 0; |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 3144 | while (ready != enable && !brcmf_timeout_expired(&tmo)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3145 | ready = |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3146 | brcmf_sdcard_cfg_read(bus->sdh, SDIO_FUNC_0, SDIO_CCCR_IORx, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3147 | NULL); |
| 3148 | |
| 3149 | DHD_INFO(("%s: enable 0x%02x, ready 0x%02x (waited %uus)\n", |
| 3150 | __func__, enable, ready, tmo.elapsed)); |
| 3151 | |
| 3152 | /* If F2 successfully enabled, set core and enable interrupts */ |
| 3153 | if (ready == enable) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3154 | /* Set up the interrupt mask and enable interrupts */ |
| 3155 | bus->hostintmask = HOSTINTMASK; |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 3156 | W_SDREG(bus->hostintmask, |
| 3157 | (unsigned int *)CORE_BUS_REG(bus->ci->buscorebase, |
| 3158 | hostintmask), retries); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3159 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3160 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_WATERMARK, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3161 | (u8) watermark, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3162 | |
| 3163 | /* Set bus state according to enable result */ |
| 3164 | dhdp->busstate = DHD_BUS_DATA; |
| 3165 | |
| 3166 | /* bcmsdh_intr_unmask(bus->sdh); */ |
| 3167 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3168 | bus->intdis = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3169 | if (bus->intr) { |
| 3170 | DHD_INTR(("%s: enable SDIO device interrupts\n", |
| 3171 | __func__)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3172 | brcmf_sdcard_intr_enable(bus->sdh); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3173 | } else { |
| 3174 | DHD_INTR(("%s: disable SDIO interrupts\n", __func__)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3175 | brcmf_sdcard_intr_disable(bus->sdh); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3176 | } |
| 3177 | |
| 3178 | } |
| 3179 | |
| 3180 | else { |
| 3181 | /* Disable F2 again */ |
| 3182 | enable = SDIO_FUNC_ENABLE_1; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3183 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_0, SDIO_CCCR_IOEx, |
| 3184 | enable, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3185 | } |
| 3186 | |
| 3187 | /* Restore previous clock setting */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3188 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3189 | saveclk, &err); |
| 3190 | |
| 3191 | /* If we didn't come up, turn off backplane clock */ |
| 3192 | if (dhdp->busstate != DHD_BUS_DATA) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3193 | brcmf_sdbrcm_clkctl(bus, CLK_NONE, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3194 | |
| 3195 | exit: |
| 3196 | if (enforce_mutex) |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 3197 | brcmf_os_sdunlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3198 | |
| 3199 | return ret; |
| 3200 | } |
| 3201 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3202 | static void brcmf_sdbrcm_rxfail(dhd_bus_t *bus, bool abort, bool rtx) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3203 | { |
| 3204 | bcmsdh_info_t *sdh = bus->sdh; |
Franky Lin | 597600a | 2011-06-01 13:45:39 +0200 | [diff] [blame] | 3205 | struct sdpcmd_regs *regs = bus->regs; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3206 | uint retries = 0; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3207 | u16 lastrbc; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3208 | u8 hi, lo; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3209 | int err; |
| 3210 | |
| 3211 | DHD_ERROR(("%s: %sterminate frame%s\n", __func__, |
| 3212 | (abort ? "abort command, " : ""), |
| 3213 | (rtx ? ", send NAK" : ""))); |
| 3214 | |
| 3215 | if (abort) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3216 | brcmf_sdcard_abort(sdh, SDIO_FUNC_2); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3217 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3218 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_FRAMECTRL, |
| 3219 | SFC_RF_TERM, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3220 | bus->f1regdata++; |
| 3221 | |
| 3222 | /* Wait until the packet has been flushed (device/FIFO stable) */ |
| 3223 | for (lastrbc = retries = 0xffff; retries > 0; retries--) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3224 | hi = brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
| 3225 | SBSDIO_FUNC1_RFRAMEBCHI, NULL); |
| 3226 | lo = brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
| 3227 | SBSDIO_FUNC1_RFRAMEBCLO, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3228 | bus->f1regdata += 2; |
| 3229 | |
| 3230 | if ((hi == 0) && (lo == 0)) |
| 3231 | break; |
| 3232 | |
| 3233 | if ((hi > (lastrbc >> 8)) && (lo > (lastrbc & 0x00ff))) { |
| 3234 | DHD_ERROR(("%s: count growing: last 0x%04x now " |
| 3235 | "0x%04x\n", |
| 3236 | __func__, lastrbc, ((hi << 8) + lo))); |
| 3237 | } |
| 3238 | lastrbc = (hi << 8) + lo; |
| 3239 | } |
| 3240 | |
| 3241 | if (!retries) { |
| 3242 | DHD_ERROR(("%s: count never zeroed: last 0x%04x\n", |
| 3243 | __func__, lastrbc)); |
| 3244 | } else { |
| 3245 | DHD_INFO(("%s: flush took %d iterations\n", __func__, |
| 3246 | (0xffff - retries))); |
| 3247 | } |
| 3248 | |
| 3249 | if (rtx) { |
| 3250 | bus->rxrtx++; |
| 3251 | W_SDREG(SMB_NAK, ®s->tosbmailbox, retries); |
| 3252 | bus->f1regdata++; |
| 3253 | if (retries <= retry_limit) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3254 | bus->rxskip = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3255 | } |
| 3256 | |
| 3257 | /* Clear partial in any case */ |
| 3258 | bus->nextlen = 0; |
| 3259 | |
| 3260 | /* If we can't reach the device, signal failure */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3261 | if (err || brcmf_sdcard_regfail(sdh)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3262 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 3263 | } |
| 3264 | |
| 3265 | static void |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3266 | brcmf_sdbrcm_read_control(dhd_bus_t *bus, u8 *hdr, uint len, uint doff) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3267 | { |
| 3268 | bcmsdh_info_t *sdh = bus->sdh; |
| 3269 | uint rdlen, pad; |
| 3270 | |
| 3271 | int sdret; |
| 3272 | |
| 3273 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 3274 | |
| 3275 | /* Control data already received in aligned rxctl */ |
| 3276 | if ((bus->bus == SPI_BUS) && (!bus->usebufpool)) |
| 3277 | goto gotpkt; |
| 3278 | |
| 3279 | ASSERT(bus->rxbuf); |
| 3280 | /* Set rxctl for frame (w/optional alignment) */ |
| 3281 | bus->rxctl = bus->rxbuf; |
| 3282 | if (dhd_alignctl) { |
| 3283 | bus->rxctl += firstread; |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 3284 | pad = ((unsigned long)bus->rxctl % DHD_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3285 | if (pad) |
| 3286 | bus->rxctl += (DHD_SDALIGN - pad); |
| 3287 | bus->rxctl -= firstread; |
| 3288 | } |
| 3289 | ASSERT(bus->rxctl >= bus->rxbuf); |
| 3290 | |
| 3291 | /* Copy the already-read portion over */ |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 3292 | memcpy(bus->rxctl, hdr, firstread); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3293 | if (len <= firstread) |
| 3294 | goto gotpkt; |
| 3295 | |
| 3296 | /* Copy the full data pkt in gSPI case and process ioctl. */ |
| 3297 | if (bus->bus == SPI_BUS) { |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 3298 | memcpy(bus->rxctl, hdr, len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3299 | goto gotpkt; |
| 3300 | } |
| 3301 | |
| 3302 | /* Raise rdlen to next SDIO block to avoid tail command */ |
| 3303 | rdlen = len - firstread; |
| 3304 | if (bus->roundup && bus->blocksize && (rdlen > bus->blocksize)) { |
| 3305 | pad = bus->blocksize - (rdlen % bus->blocksize); |
| 3306 | if ((pad <= bus->roundup) && (pad < bus->blocksize) && |
| 3307 | ((len + pad) < bus->dhd->maxctl)) |
| 3308 | rdlen += pad; |
| 3309 | } else if (rdlen % DHD_SDALIGN) { |
| 3310 | rdlen += DHD_SDALIGN - (rdlen % DHD_SDALIGN); |
| 3311 | } |
| 3312 | |
| 3313 | /* Satisfy length-alignment requirements */ |
| 3314 | if (forcealign && (rdlen & (ALIGNMENT - 1))) |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 3315 | rdlen = roundup(rdlen, ALIGNMENT); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3316 | |
| 3317 | /* Drop if the read is too big or it exceeds our maximum */ |
| 3318 | if ((rdlen + firstread) > bus->dhd->maxctl) { |
| 3319 | DHD_ERROR(("%s: %d-byte control read exceeds %d-byte buffer\n", |
| 3320 | __func__, rdlen, bus->dhd->maxctl)); |
| 3321 | bus->dhd->rx_errors++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3322 | brcmf_sdbrcm_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3323 | goto done; |
| 3324 | } |
| 3325 | |
| 3326 | if ((len - doff) > bus->dhd->maxctl) { |
| 3327 | DHD_ERROR(("%s: %d-byte ctl frame (%d-byte ctl data) exceeds " |
| 3328 | "%d-byte limit\n", |
| 3329 | __func__, len, (len - doff), bus->dhd->maxctl)); |
| 3330 | bus->dhd->rx_errors++; |
| 3331 | bus->rx_toolong++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3332 | brcmf_sdbrcm_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3333 | goto done; |
| 3334 | } |
| 3335 | |
| 3336 | /* Read remainder of frame body into the rxctl buffer */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3337 | sdret = brcmf_sdcard_recv_buf(sdh, brcmf_sdcard_cur_sbwad(sdh), |
| 3338 | SDIO_FUNC_2, |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 3339 | F2SYNC, (bus->rxctl + firstread), rdlen, |
| 3340 | NULL, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3341 | bus->f2rxdata++; |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 3342 | ASSERT(sdret != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3343 | |
| 3344 | /* Control frame failures need retransmission */ |
| 3345 | if (sdret < 0) { |
| 3346 | DHD_ERROR(("%s: read %d control bytes failed: %d\n", |
| 3347 | __func__, rdlen, sdret)); |
| 3348 | bus->rxc_errors++; /* dhd.rx_ctlerrs is higher level */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3349 | brcmf_sdbrcm_rxfail(bus, true, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3350 | goto done; |
| 3351 | } |
| 3352 | |
| 3353 | gotpkt: |
| 3354 | |
| 3355 | #ifdef DHD_DEBUG |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 3356 | if (DHD_BYTES_ON() && DHD_CTL_ON()) { |
| 3357 | printk(KERN_DEBUG "RxCtrl:\n"); |
| 3358 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, bus->rxctl, len); |
| 3359 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3360 | #endif |
| 3361 | |
| 3362 | /* Point to valid data and indicate its length */ |
| 3363 | bus->rxctl += doff; |
| 3364 | bus->rxlen = len - doff; |
| 3365 | |
| 3366 | done: |
| 3367 | /* Awake any waiters */ |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 3368 | brcmf_os_ioctl_resp_wake(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3369 | } |
| 3370 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3371 | static u8 brcmf_sdbrcm_rxglom(dhd_bus_t *bus, u8 rxseq) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3372 | { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3373 | u16 dlen, totlen; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3374 | u8 *dptr, num = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3375 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3376 | u16 sublen, check; |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 3377 | struct sk_buff *pfirst, *plast, *pnext, *save_pfirst; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3378 | |
| 3379 | int errcode; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3380 | u8 chan, seq, doff, sfdoff; |
| 3381 | u8 txmax; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3382 | |
| 3383 | int ifidx = 0; |
| 3384 | bool usechain = bus->use_rxchain; |
| 3385 | |
| 3386 | /* If packets, issue read(s) and send up packet chain */ |
| 3387 | /* Return sequence numbers consumed? */ |
| 3388 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3389 | DHD_TRACE(("brcmf_sdbrcm_rxglom: start: glomd %p glom %p\n", bus->glomd, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3390 | bus->glom)); |
| 3391 | |
| 3392 | /* If there's a descriptor, generate the packet chain */ |
| 3393 | if (bus->glomd) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3394 | pfirst = plast = pnext = NULL; |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3395 | dlen = (u16) (bus->glomd->len); |
| 3396 | dptr = bus->glomd->data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3397 | if (!dlen || (dlen & 1)) { |
| 3398 | DHD_ERROR(("%s: bad glomd len(%d), ignore descriptor\n", |
| 3399 | __func__, dlen)); |
| 3400 | dlen = 0; |
| 3401 | } |
| 3402 | |
| 3403 | for (totlen = num = 0; dlen; num++) { |
| 3404 | /* Get (and move past) next length */ |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 3405 | sublen = get_unaligned_le16(dptr); |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3406 | dlen -= sizeof(u16); |
| 3407 | dptr += sizeof(u16); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3408 | if ((sublen < SDPCM_HDRLEN) || |
| 3409 | ((num == 0) && (sublen < (2 * SDPCM_HDRLEN)))) { |
| 3410 | DHD_ERROR(("%s: descriptor len %d bad: %d\n", |
| 3411 | __func__, num, sublen)); |
| 3412 | pnext = NULL; |
| 3413 | break; |
| 3414 | } |
| 3415 | if (sublen % DHD_SDALIGN) { |
| 3416 | DHD_ERROR(("%s: sublen %d not multiple of %d\n", |
| 3417 | __func__, sublen, DHD_SDALIGN)); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3418 | usechain = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3419 | } |
| 3420 | totlen += sublen; |
| 3421 | |
| 3422 | /* For last frame, adjust read len so total |
| 3423 | is a block multiple */ |
| 3424 | if (!dlen) { |
| 3425 | sublen += |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 3426 | (roundup(totlen, bus->blocksize) - totlen); |
| 3427 | totlen = roundup(totlen, bus->blocksize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3428 | } |
| 3429 | |
| 3430 | /* Allocate/chain packet for next subframe */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3431 | pnext = brcmu_pkt_buf_get_skb(sublen + DHD_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3432 | if (pnext == NULL) { |
Henry Ptasinski | b33f0e2 | 2011-05-10 22:25:29 +0200 | [diff] [blame] | 3433 | DHD_ERROR(("%s: bcm_pkt_buf_get_skb failed, " |
| 3434 | "num %d len %d\n", __func__, |
| 3435 | num, sublen)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3436 | break; |
| 3437 | } |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3438 | ASSERT(!(pnext->prev)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3439 | if (!pfirst) { |
| 3440 | ASSERT(!plast); |
| 3441 | pfirst = plast = pnext; |
| 3442 | } else { |
| 3443 | ASSERT(plast); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3444 | plast->next = pnext; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3445 | plast = pnext; |
| 3446 | } |
| 3447 | |
| 3448 | /* Adhere to start alignment requirements */ |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 3449 | PKTALIGN(pnext, sublen, DHD_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3450 | } |
| 3451 | |
| 3452 | /* If all allocations succeeded, save packet chain |
| 3453 | in bus structure */ |
| 3454 | if (pnext) { |
| 3455 | DHD_GLOM(("%s: allocated %d-byte packet chain for %d " |
| 3456 | "subframes\n", __func__, totlen, num)); |
| 3457 | if (DHD_GLOM_ON() && bus->nextlen) { |
| 3458 | if (totlen != bus->nextlen) { |
| 3459 | DHD_GLOM(("%s: glomdesc mismatch: nextlen %d glomdesc %d " "rxseq %d\n", |
| 3460 | __func__, bus->nextlen, |
| 3461 | totlen, rxseq)); |
| 3462 | } |
| 3463 | } |
| 3464 | bus->glom = pfirst; |
| 3465 | pfirst = pnext = NULL; |
| 3466 | } else { |
| 3467 | if (pfirst) |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3468 | brcmu_pkt_buf_free_skb(pfirst); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3469 | bus->glom = NULL; |
| 3470 | num = 0; |
| 3471 | } |
| 3472 | |
| 3473 | /* Done with descriptor packet */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3474 | brcmu_pkt_buf_free_skb(bus->glomd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3475 | bus->glomd = NULL; |
| 3476 | bus->nextlen = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3477 | } |
| 3478 | |
| 3479 | /* Ok -- either we just generated a packet chain, |
| 3480 | or had one from before */ |
| 3481 | if (bus->glom) { |
| 3482 | if (DHD_GLOM_ON()) { |
| 3483 | DHD_GLOM(("%s: try superframe read, packet chain:\n", |
| 3484 | __func__)); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3485 | for (pnext = bus->glom; pnext; pnext = pnext->next) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3486 | DHD_GLOM((" %p: %p len 0x%04x (%d)\n", |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3487 | pnext, (u8 *) (pnext->data), |
| 3488 | pnext->len, pnext->len)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3489 | } |
| 3490 | } |
| 3491 | |
| 3492 | pfirst = bus->glom; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3493 | dlen = (u16) brcmu_pkttotlen(pfirst); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3494 | |
| 3495 | /* Do an SDIO read for the superframe. Configurable iovar to |
| 3496 | * read directly into the chained packet, or allocate a large |
| 3497 | * packet and and copy into the chain. |
| 3498 | */ |
| 3499 | if (usechain) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3500 | errcode = brcmf_sdcard_recv_buf(bus->sdh, |
| 3501 | brcmf_sdcard_cur_sbwad(bus->sdh), |
| 3502 | SDIO_FUNC_2, |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 3503 | F2SYNC, (u8 *) pfirst->data, dlen, |
| 3504 | pfirst, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3505 | } else if (bus->dataptr) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3506 | errcode = brcmf_sdcard_recv_buf(bus->sdh, |
| 3507 | brcmf_sdcard_cur_sbwad(bus->sdh), |
| 3508 | SDIO_FUNC_2, |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 3509 | F2SYNC, bus->dataptr, dlen, |
| 3510 | NULL, NULL, NULL); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3511 | sublen = (u16) brcmu_pktfrombuf(pfirst, 0, dlen, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3512 | bus->dataptr); |
| 3513 | if (sublen != dlen) { |
| 3514 | DHD_ERROR(("%s: FAILED TO COPY, dlen %d sublen %d\n", |
| 3515 | __func__, dlen, sublen)); |
| 3516 | errcode = -1; |
| 3517 | } |
| 3518 | pnext = NULL; |
| 3519 | } else { |
| 3520 | DHD_ERROR(("COULDN'T ALLOC %d-BYTE GLOM, FORCE FAILURE\n", |
| 3521 | dlen)); |
| 3522 | errcode = -1; |
| 3523 | } |
| 3524 | bus->f2rxdata++; |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 3525 | ASSERT(errcode != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3526 | |
| 3527 | /* On failure, kill the superframe, allow a couple retries */ |
| 3528 | if (errcode < 0) { |
| 3529 | DHD_ERROR(("%s: glom read of %d bytes failed: %d\n", |
| 3530 | __func__, dlen, errcode)); |
| 3531 | bus->dhd->rx_errors++; |
| 3532 | |
| 3533 | if (bus->glomerr++ < 3) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3534 | brcmf_sdbrcm_rxfail(bus, true, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3535 | } else { |
| 3536 | bus->glomerr = 0; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3537 | brcmf_sdbrcm_rxfail(bus, true, false); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3538 | brcmu_pkt_buf_free_skb(bus->glom); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3539 | bus->rxglomfail++; |
| 3540 | bus->glom = NULL; |
| 3541 | } |
| 3542 | return 0; |
| 3543 | } |
| 3544 | #ifdef DHD_DEBUG |
| 3545 | if (DHD_GLOM_ON()) { |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 3546 | printk(KERN_DEBUG "SUPERFRAME:\n"); |
| 3547 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 3548 | pfirst->data, min_t(int, pfirst->len, 48)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3549 | } |
| 3550 | #endif |
| 3551 | |
| 3552 | /* Validate the superframe header */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3553 | dptr = (u8 *) (pfirst->data); |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 3554 | sublen = get_unaligned_le16(dptr); |
| 3555 | check = get_unaligned_le16(dptr + sizeof(u16)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3556 | |
| 3557 | chan = SDPCM_PACKET_CHANNEL(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3558 | seq = SDPCM_PACKET_SEQUENCE(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3559 | bus->nextlen = dptr[SDPCM_FRAMETAG_LEN + SDPCM_NEXTLEN_OFFSET]; |
| 3560 | if ((bus->nextlen << 4) > MAX_RX_DATASZ) { |
| 3561 | DHD_INFO(("%s: nextlen too large (%d) seq %d\n", |
| 3562 | __func__, bus->nextlen, seq)); |
| 3563 | bus->nextlen = 0; |
| 3564 | } |
| 3565 | doff = SDPCM_DOFFSET_VALUE(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3566 | txmax = SDPCM_WINDOW_VALUE(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3567 | |
| 3568 | errcode = 0; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3569 | if ((u16)~(sublen ^ check)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3570 | DHD_ERROR(("%s (superframe): HW hdr error: len/check " |
| 3571 | "0x%04x/0x%04x\n", __func__, sublen, check)); |
| 3572 | errcode = -1; |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 3573 | } else if (roundup(sublen, bus->blocksize) != dlen) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3574 | DHD_ERROR(("%s (superframe): len 0x%04x, rounded " |
| 3575 | "0x%04x, expect 0x%04x\n", |
| 3576 | __func__, sublen, |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 3577 | roundup(sublen, bus->blocksize), dlen)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3578 | errcode = -1; |
| 3579 | } else if (SDPCM_PACKET_CHANNEL(&dptr[SDPCM_FRAMETAG_LEN]) != |
| 3580 | SDPCM_GLOM_CHANNEL) { |
| 3581 | DHD_ERROR(("%s (superframe): bad channel %d\n", |
| 3582 | __func__, |
| 3583 | SDPCM_PACKET_CHANNEL(&dptr |
| 3584 | [SDPCM_FRAMETAG_LEN]))); |
| 3585 | errcode = -1; |
| 3586 | } else if (SDPCM_GLOMDESC(&dptr[SDPCM_FRAMETAG_LEN])) { |
| 3587 | DHD_ERROR(("%s (superframe): got second descriptor?\n", |
| 3588 | __func__)); |
| 3589 | errcode = -1; |
| 3590 | } else if ((doff < SDPCM_HDRLEN) || |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3591 | (doff > (pfirst->len - SDPCM_HDRLEN))) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3592 | DHD_ERROR(("%s (superframe): Bad data offset %d: HW %d " |
| 3593 | "pkt %d min %d\n", |
| 3594 | __func__, doff, sublen, |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3595 | pfirst->len, SDPCM_HDRLEN)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3596 | errcode = -1; |
| 3597 | } |
| 3598 | |
| 3599 | /* Check sequence number of superframe SW header */ |
| 3600 | if (rxseq != seq) { |
| 3601 | DHD_INFO(("%s: (superframe) rx_seq %d, expected %d\n", |
| 3602 | __func__, seq, rxseq)); |
| 3603 | bus->rx_badseq++; |
| 3604 | rxseq = seq; |
| 3605 | } |
| 3606 | |
| 3607 | /* Check window for sanity */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3608 | if ((u8) (txmax - bus->tx_seq) > 0x40) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3609 | DHD_ERROR(("%s: unlikely tx max %d with tx_seq %d\n", |
| 3610 | __func__, txmax, bus->tx_seq)); |
| 3611 | txmax = bus->tx_seq + 2; |
| 3612 | } |
| 3613 | bus->tx_max = txmax; |
| 3614 | |
| 3615 | /* Remove superframe header, remember offset */ |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 3616 | skb_pull(pfirst, doff); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3617 | sfdoff = doff; |
| 3618 | |
| 3619 | /* Validate all the subframe headers */ |
| 3620 | for (num = 0, pnext = pfirst; pnext && !errcode; |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3621 | num++, pnext = pnext->next) { |
| 3622 | dptr = (u8 *) (pnext->data); |
| 3623 | dlen = (u16) (pnext->len); |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 3624 | sublen = get_unaligned_le16(dptr); |
| 3625 | check = get_unaligned_le16(dptr + sizeof(u16)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3626 | chan = SDPCM_PACKET_CHANNEL(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3627 | doff = SDPCM_DOFFSET_VALUE(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3628 | #ifdef DHD_DEBUG |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 3629 | if (DHD_GLOM_ON()) { |
| 3630 | printk(KERN_DEBUG "subframe:\n"); |
| 3631 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 3632 | dptr, 32); |
| 3633 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3634 | #endif |
| 3635 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3636 | if ((u16)~(sublen ^ check)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3637 | DHD_ERROR(("%s (subframe %d): HW hdr error: " |
| 3638 | "len/check 0x%04x/0x%04x\n", |
| 3639 | __func__, num, sublen, check)); |
| 3640 | errcode = -1; |
| 3641 | } else if ((sublen > dlen) || (sublen < SDPCM_HDRLEN)) { |
| 3642 | DHD_ERROR(("%s (subframe %d): length mismatch: " |
| 3643 | "len 0x%04x, expect 0x%04x\n", |
| 3644 | __func__, num, sublen, dlen)); |
| 3645 | errcode = -1; |
| 3646 | } else if ((chan != SDPCM_DATA_CHANNEL) && |
| 3647 | (chan != SDPCM_EVENT_CHANNEL)) { |
| 3648 | DHD_ERROR(("%s (subframe %d): bad channel %d\n", |
| 3649 | __func__, num, chan)); |
| 3650 | errcode = -1; |
| 3651 | } else if ((doff < SDPCM_HDRLEN) || (doff > sublen)) { |
| 3652 | DHD_ERROR(("%s (subframe %d): Bad data offset %d: HW %d min %d\n", |
| 3653 | __func__, num, doff, sublen, |
| 3654 | SDPCM_HDRLEN)); |
| 3655 | errcode = -1; |
| 3656 | } |
| 3657 | } |
| 3658 | |
| 3659 | if (errcode) { |
| 3660 | /* Terminate frame on error, request |
| 3661 | a couple retries */ |
| 3662 | if (bus->glomerr++ < 3) { |
| 3663 | /* Restore superframe header space */ |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 3664 | skb_push(pfirst, sfdoff); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3665 | brcmf_sdbrcm_rxfail(bus, true, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3666 | } else { |
| 3667 | bus->glomerr = 0; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3668 | brcmf_sdbrcm_rxfail(bus, true, false); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3669 | brcmu_pkt_buf_free_skb(bus->glom); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3670 | bus->rxglomfail++; |
| 3671 | bus->glom = NULL; |
| 3672 | } |
| 3673 | bus->nextlen = 0; |
| 3674 | return 0; |
| 3675 | } |
| 3676 | |
| 3677 | /* Basic SD framing looks ok - process each packet (header) */ |
| 3678 | save_pfirst = pfirst; |
| 3679 | bus->glom = NULL; |
| 3680 | plast = NULL; |
| 3681 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3682 | for (num = 0; pfirst; rxseq++, pfirst = pnext) { |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3683 | pnext = pfirst->next; |
| 3684 | pfirst->next = NULL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3685 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3686 | dptr = (u8 *) (pfirst->data); |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 3687 | sublen = get_unaligned_le16(dptr); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3688 | chan = SDPCM_PACKET_CHANNEL(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3689 | seq = SDPCM_PACKET_SEQUENCE(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3690 | doff = SDPCM_DOFFSET_VALUE(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3691 | |
| 3692 | DHD_GLOM(("%s: Get subframe %d, %p(%p/%d), sublen %d " |
| 3693 | "chan %d seq %d\n", |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3694 | __func__, num, pfirst, pfirst->data, |
| 3695 | pfirst->len, sublen, chan, seq)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3696 | |
| 3697 | ASSERT((chan == SDPCM_DATA_CHANNEL) |
| 3698 | || (chan == SDPCM_EVENT_CHANNEL)); |
| 3699 | |
| 3700 | if (rxseq != seq) { |
| 3701 | DHD_GLOM(("%s: rx_seq %d, expected %d\n", |
| 3702 | __func__, seq, rxseq)); |
| 3703 | bus->rx_badseq++; |
| 3704 | rxseq = seq; |
| 3705 | } |
| 3706 | #ifdef DHD_DEBUG |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 3707 | if (DHD_BYTES_ON() && DHD_DATA_ON()) { |
| 3708 | printk(KERN_DEBUG "Rx Subframe Data:\n"); |
| 3709 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 3710 | dptr, dlen); |
| 3711 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3712 | #endif |
| 3713 | |
Arend van Spriel | 2cb8ada | 2010-11-18 20:46:44 +0100 | [diff] [blame] | 3714 | __skb_trim(pfirst, sublen); |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 3715 | skb_pull(pfirst, doff); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3716 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3717 | if (pfirst->len == 0) { |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3718 | brcmu_pkt_buf_free_skb(pfirst); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3719 | if (plast) { |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3720 | plast->next = pnext; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3721 | } else { |
| 3722 | ASSERT(save_pfirst == pfirst); |
| 3723 | save_pfirst = pnext; |
| 3724 | } |
| 3725 | continue; |
| 3726 | } else if (dhd_prot_hdrpull(bus->dhd, &ifidx, pfirst) != |
| 3727 | 0) { |
| 3728 | DHD_ERROR(("%s: rx protocol error\n", |
| 3729 | __func__)); |
| 3730 | bus->dhd->rx_errors++; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3731 | brcmu_pkt_buf_free_skb(pfirst); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3732 | if (plast) { |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3733 | plast->next = pnext; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3734 | } else { |
| 3735 | ASSERT(save_pfirst == pfirst); |
| 3736 | save_pfirst = pnext; |
| 3737 | } |
| 3738 | continue; |
| 3739 | } |
| 3740 | |
| 3741 | /* this packet will go up, link back into |
| 3742 | chain and count it */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3743 | pfirst->next = pnext; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3744 | plast = pfirst; |
| 3745 | num++; |
| 3746 | |
| 3747 | #ifdef DHD_DEBUG |
| 3748 | if (DHD_GLOM_ON()) { |
| 3749 | DHD_GLOM(("%s subframe %d to stack, %p(%p/%d) " |
| 3750 | "nxt/lnk %p/%p\n", |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3751 | __func__, num, pfirst, pfirst->data, |
| 3752 | pfirst->len, pfirst->next, |
| 3753 | pfirst->prev)); |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 3754 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 3755 | pfirst->data, |
| 3756 | min_t(int, pfirst->len, 32)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3757 | } |
| 3758 | #endif /* DHD_DEBUG */ |
| 3759 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3760 | if (num) { |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 3761 | brcmf_os_sdunlock(bus->dhd); |
| 3762 | brcmf_rx_frame(bus->dhd, ifidx, save_pfirst, num); |
| 3763 | brcmf_os_sdlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3764 | } |
| 3765 | |
| 3766 | bus->rxglomframes++; |
| 3767 | bus->rxglompkts += num; |
| 3768 | } |
| 3769 | return num; |
| 3770 | } |
| 3771 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3772 | /* Return true if there may be more frames to read */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3773 | static uint |
| 3774 | brcmf_sdbrcm_readframes(dhd_bus_t *bus, uint maxframes, bool *finished) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3775 | { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3776 | bcmsdh_info_t *sdh = bus->sdh; |
| 3777 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3778 | u16 len, check; /* Extracted hardware header fields */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3779 | u8 chan, seq, doff; /* Extracted software header fields */ |
| 3780 | u8 fcbits; /* Extracted fcbits from software header */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3781 | |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 3782 | struct sk_buff *pkt; /* Packet for event or data frames */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3783 | u16 pad; /* Number of pad bytes to read */ |
| 3784 | u16 rdlen; /* Total number of bytes to read */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3785 | u8 rxseq; /* Next sequence number to expect */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3786 | uint rxleft = 0; /* Remaining number of frames allowed */ |
| 3787 | int sdret; /* Return code from bcmsdh calls */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3788 | u8 txmax; /* Maximum tx sequence offered */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3789 | bool len_consistent; /* Result of comparing readahead len and |
| 3790 | len from hw-hdr */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3791 | u8 *rxbuf; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3792 | int ifidx = 0; |
| 3793 | uint rxcount = 0; /* Total frames read */ |
| 3794 | |
| 3795 | #if defined(DHD_DEBUG) || defined(SDTEST) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3796 | bool sdtest = false; /* To limit message spew from test mode */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3797 | #endif |
| 3798 | |
| 3799 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 3800 | |
| 3801 | ASSERT(maxframes); |
| 3802 | |
| 3803 | #ifdef SDTEST |
| 3804 | /* Allow pktgen to override maxframes */ |
| 3805 | if (bus->pktgen_count && (bus->pktgen_mode == DHD_PKTGEN_RECV)) { |
| 3806 | maxframes = bus->pktgen_count; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3807 | sdtest = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3808 | } |
| 3809 | #endif |
| 3810 | |
| 3811 | /* Not finished unless we encounter no more frames indication */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3812 | *finished = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3813 | |
| 3814 | for (rxseq = bus->rx_seq, rxleft = maxframes; |
| 3815 | !bus->rxskip && rxleft && bus->dhd->busstate != DHD_BUS_DOWN; |
| 3816 | rxseq++, rxleft--) { |
| 3817 | |
| 3818 | /* Handle glomming separately */ |
| 3819 | if (bus->glom || bus->glomd) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3820 | u8 cnt; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3821 | DHD_GLOM(("%s: calling rxglom: glomd %p, glom %p\n", |
| 3822 | __func__, bus->glomd, bus->glom)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3823 | cnt = brcmf_sdbrcm_rxglom(bus, rxseq); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3824 | DHD_GLOM(("%s: rxglom returned %d\n", __func__, cnt)); |
| 3825 | rxseq += cnt - 1; |
| 3826 | rxleft = (rxleft > cnt) ? (rxleft - cnt) : 1; |
| 3827 | continue; |
| 3828 | } |
| 3829 | |
| 3830 | /* Try doing single read if we can */ |
| 3831 | if (dhd_readahead && bus->nextlen) { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3832 | u16 nextlen = bus->nextlen; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3833 | bus->nextlen = 0; |
| 3834 | |
| 3835 | if (bus->bus == SPI_BUS) { |
| 3836 | rdlen = len = nextlen; |
| 3837 | } else { |
| 3838 | rdlen = len = nextlen << 4; |
| 3839 | |
| 3840 | /* Pad read to blocksize for efficiency */ |
| 3841 | if (bus->roundup && bus->blocksize |
| 3842 | && (rdlen > bus->blocksize)) { |
| 3843 | pad = |
| 3844 | bus->blocksize - |
| 3845 | (rdlen % bus->blocksize); |
| 3846 | if ((pad <= bus->roundup) |
| 3847 | && (pad < bus->blocksize) |
| 3848 | && ((rdlen + pad + firstread) < |
| 3849 | MAX_RX_DATASZ)) |
| 3850 | rdlen += pad; |
| 3851 | } else if (rdlen % DHD_SDALIGN) { |
| 3852 | rdlen += |
| 3853 | DHD_SDALIGN - (rdlen % DHD_SDALIGN); |
| 3854 | } |
| 3855 | } |
| 3856 | |
| 3857 | /* We use bus->rxctl buffer in WinXP for initial |
| 3858 | * control pkt receives. |
| 3859 | * Later we use buffer-poll for data as well |
| 3860 | * as control packets. |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3861 | * This is required because dhd receives full |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3862 | * frame in gSPI unlike SDIO. |
| 3863 | * After the frame is received we have to |
| 3864 | * distinguish whether it is data |
| 3865 | * or non-data frame. |
| 3866 | */ |
| 3867 | /* Allocate a packet buffer */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3868 | pkt = brcmu_pkt_buf_get_skb(rdlen + DHD_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3869 | if (!pkt) { |
| 3870 | if (bus->bus == SPI_BUS) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3871 | bus->usebufpool = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3872 | bus->rxctl = bus->rxbuf; |
| 3873 | if (dhd_alignctl) { |
| 3874 | bus->rxctl += firstread; |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 3875 | pad = ((unsigned long)bus->rxctl % |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3876 | DHD_SDALIGN); |
| 3877 | if (pad) |
| 3878 | bus->rxctl += |
| 3879 | (DHD_SDALIGN - pad); |
| 3880 | bus->rxctl -= firstread; |
| 3881 | } |
| 3882 | ASSERT(bus->rxctl >= bus->rxbuf); |
| 3883 | rxbuf = bus->rxctl; |
| 3884 | /* Read the entire frame */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3885 | sdret = brcmf_sdcard_recv_buf(sdh, |
| 3886 | brcmf_sdcard_cur_sbwad(sdh), |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 3887 | SDIO_FUNC_2, F2SYNC, |
| 3888 | rxbuf, rdlen, |
| 3889 | NULL, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3890 | bus->f2rxdata++; |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 3891 | ASSERT(sdret != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3892 | |
| 3893 | /* Control frame failures need |
| 3894 | retransmission */ |
| 3895 | if (sdret < 0) { |
| 3896 | DHD_ERROR(("%s: read %d control bytes failed: %d\n", |
| 3897 | __func__, |
| 3898 | rdlen, sdret)); |
| 3899 | /* dhd.rx_ctlerrs is higher */ |
| 3900 | bus->rxc_errors++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3901 | brcmf_sdbrcm_rxfail(bus, true, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3902 | (bus->bus == |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3903 | SPI_BUS) ? false |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3904 | : true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3905 | continue; |
| 3906 | } |
| 3907 | } else { |
| 3908 | /* Give up on data, |
| 3909 | request rtx of events */ |
Arend van Spriel | cda64a5 | 2011-05-10 22:25:33 +0200 | [diff] [blame] | 3910 | DHD_ERROR(("%s (nextlen): " |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3911 | "brcmu_pkt_buf_get_skb " |
| 3912 | "failed:" |
Arend van Spriel | cda64a5 | 2011-05-10 22:25:33 +0200 | [diff] [blame] | 3913 | " len %d rdlen %d expected" |
| 3914 | " rxseq %d\n", __func__, |
| 3915 | len, rdlen, rxseq)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3916 | continue; |
| 3917 | } |
| 3918 | } else { |
| 3919 | if (bus->bus == SPI_BUS) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3920 | bus->usebufpool = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3921 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3922 | ASSERT(!(pkt->prev)); |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 3923 | PKTALIGN(pkt, rdlen, DHD_SDALIGN); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3924 | rxbuf = (u8 *) (pkt->data); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3925 | /* Read the entire frame */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3926 | sdret = brcmf_sdcard_recv_buf(sdh, |
| 3927 | brcmf_sdcard_cur_sbwad(sdh), |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3928 | SDIO_FUNC_2, F2SYNC, |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 3929 | rxbuf, rdlen, |
| 3930 | pkt, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3931 | bus->f2rxdata++; |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 3932 | ASSERT(sdret != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3933 | |
| 3934 | if (sdret < 0) { |
| 3935 | DHD_ERROR(("%s (nextlen): read %d bytes failed: %d\n", |
| 3936 | __func__, rdlen, sdret)); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3937 | brcmu_pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3938 | bus->dhd->rx_errors++; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3939 | /* Force retry w/normal header read. |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3940 | * Don't attempt NAK for |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3941 | * gSPI |
| 3942 | */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3943 | brcmf_sdbrcm_rxfail(bus, true, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3944 | (bus->bus == |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3945 | SPI_BUS) ? false : |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3946 | true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3947 | continue; |
| 3948 | } |
| 3949 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3950 | |
| 3951 | /* Now check the header */ |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 3952 | memcpy(bus->rxhdr, rxbuf, SDPCM_HDRLEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3953 | |
| 3954 | /* Extract hardware header fields */ |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 3955 | len = get_unaligned_le16(bus->rxhdr); |
| 3956 | check = get_unaligned_le16(bus->rxhdr + sizeof(u16)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3957 | |
| 3958 | /* All zeros means readahead info was bad */ |
| 3959 | if (!(len | check)) { |
| 3960 | DHD_INFO(("%s (nextlen): read zeros in HW " |
| 3961 | "header???\n", __func__)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3962 | brcmf_sdbrcm_pktfree2(bus, pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3963 | continue; |
| 3964 | } |
| 3965 | |
| 3966 | /* Validate check bytes */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3967 | if ((u16)~(len ^ check)) { |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 3968 | DHD_ERROR(("%s (nextlen): HW hdr error:" |
| 3969 | " nextlen/len/check" |
| 3970 | " 0x%04x/0x%04x/0x%04x\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3971 | __func__, nextlen, len, check)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3972 | bus->rx_badhdr++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3973 | brcmf_sdbrcm_rxfail(bus, false, false); |
| 3974 | brcmf_sdbrcm_pktfree2(bus, pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3975 | continue; |
| 3976 | } |
| 3977 | |
| 3978 | /* Validate frame length */ |
| 3979 | if (len < SDPCM_HDRLEN) { |
| 3980 | DHD_ERROR(("%s (nextlen): HW hdr length " |
| 3981 | "invalid: %d\n", __func__, len)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3982 | brcmf_sdbrcm_pktfree2(bus, pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3983 | continue; |
| 3984 | } |
| 3985 | |
| 3986 | /* Check for consistency withreadahead info */ |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 3987 | len_consistent = (nextlen != (roundup(len, 16) >> 4)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3988 | if (len_consistent) { |
| 3989 | /* Mismatch, force retry w/normal |
| 3990 | header (may be >4K) */ |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 3991 | DHD_ERROR(("%s (nextlen): mismatch, " |
| 3992 | "nextlen %d len %d rnd %d; " |
| 3993 | "expected rxseq %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3994 | __func__, nextlen, |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 3995 | len, roundup(len, 16), rxseq)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3996 | brcmf_sdbrcm_rxfail(bus, true, |
| 3997 | bus->bus != SPI_BUS); |
| 3998 | brcmf_sdbrcm_pktfree2(bus, pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3999 | continue; |
| 4000 | } |
| 4001 | |
| 4002 | /* Extract software header fields */ |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4003 | chan = SDPCM_PACKET_CHANNEL( |
| 4004 | &bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 4005 | seq = SDPCM_PACKET_SEQUENCE( |
| 4006 | &bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 4007 | doff = SDPCM_DOFFSET_VALUE( |
| 4008 | &bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 4009 | txmax = SDPCM_WINDOW_VALUE( |
| 4010 | &bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4011 | |
| 4012 | bus->nextlen = |
| 4013 | bus->rxhdr[SDPCM_FRAMETAG_LEN + |
| 4014 | SDPCM_NEXTLEN_OFFSET]; |
| 4015 | if ((bus->nextlen << 4) > MAX_RX_DATASZ) { |
| 4016 | DHD_INFO(("%s (nextlen): got frame w/nextlen too large" " (%d), seq %d\n", |
| 4017 | __func__, bus->nextlen, seq)); |
| 4018 | bus->nextlen = 0; |
| 4019 | } |
| 4020 | |
| 4021 | bus->dhd->rx_readahead_cnt++; |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4022 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4023 | /* Handle Flow Control */ |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4024 | fcbits = SDPCM_FCMASK_VALUE( |
| 4025 | &bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4026 | |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4027 | if (bus->flowcontrol != fcbits) { |
| 4028 | if (~bus->flowcontrol & fcbits) |
| 4029 | bus->fc_xoff++; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4030 | |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4031 | if (bus->flowcontrol & ~fcbits) |
| 4032 | bus->fc_xon++; |
| 4033 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4034 | bus->fc_rcvd++; |
| 4035 | bus->flowcontrol = fcbits; |
| 4036 | } |
| 4037 | |
| 4038 | /* Check and update sequence number */ |
| 4039 | if (rxseq != seq) { |
| 4040 | DHD_INFO(("%s (nextlen): rx_seq %d, expected " |
| 4041 | "%d\n", __func__, seq, rxseq)); |
| 4042 | bus->rx_badseq++; |
| 4043 | rxseq = seq; |
| 4044 | } |
| 4045 | |
| 4046 | /* Check window for sanity */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4047 | if ((u8) (txmax - bus->tx_seq) > 0x40) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4048 | DHD_ERROR(("%s: got unlikely tx max %d with " |
| 4049 | "tx_seq %d\n", |
| 4050 | __func__, txmax, bus->tx_seq)); |
| 4051 | txmax = bus->tx_seq + 2; |
| 4052 | } |
| 4053 | bus->tx_max = txmax; |
| 4054 | |
| 4055 | #ifdef DHD_DEBUG |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 4056 | if (DHD_BYTES_ON() && DHD_DATA_ON()) { |
| 4057 | printk(KERN_DEBUG "Rx Data:\n"); |
| 4058 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 4059 | rxbuf, len); |
| 4060 | } else if (DHD_HDRS_ON()) { |
| 4061 | printk(KERN_DEBUG "RxHdr:\n"); |
| 4062 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 4063 | bus->rxhdr, SDPCM_HDRLEN); |
| 4064 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4065 | #endif |
| 4066 | |
| 4067 | if (chan == SDPCM_CONTROL_CHANNEL) { |
| 4068 | if (bus->bus == SPI_BUS) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4069 | brcmf_sdbrcm_read_control(bus, rxbuf, |
| 4070 | len, doff); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4071 | } else { |
| 4072 | DHD_ERROR(("%s (nextlen): readahead on control" " packet %d?\n", |
| 4073 | __func__, seq)); |
| 4074 | /* Force retry w/normal header read */ |
| 4075 | bus->nextlen = 0; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4076 | brcmf_sdbrcm_rxfail(bus, false, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4077 | } |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4078 | brcmf_sdbrcm_pktfree2(bus, pkt); |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4079 | continue; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4080 | } |
| 4081 | |
| 4082 | if ((bus->bus == SPI_BUS) && !bus->usebufpool) { |
| 4083 | DHD_ERROR(("Received %d bytes on %d channel. Running out of " "rx pktbuf's or not yet malloced.\n", |
| 4084 | len, chan)); |
| 4085 | continue; |
| 4086 | } |
| 4087 | |
| 4088 | /* Validate data offset */ |
| 4089 | if ((doff < SDPCM_HDRLEN) || (doff > len)) { |
| 4090 | DHD_ERROR(("%s (nextlen): bad data offset %d: HW len %d min %d\n", |
| 4091 | __func__, doff, len, SDPCM_HDRLEN)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4092 | brcmf_sdbrcm_rxfail(bus, false, false); |
| 4093 | brcmf_sdbrcm_pktfree2(bus, pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4094 | continue; |
| 4095 | } |
| 4096 | |
| 4097 | /* All done with this one -- now deliver the packet */ |
| 4098 | goto deliver; |
| 4099 | } |
| 4100 | /* gSPI frames should not be handled in fractions */ |
| 4101 | if (bus->bus == SPI_BUS) |
| 4102 | break; |
| 4103 | |
| 4104 | /* Read frame header (hardware and software) */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4105 | sdret = brcmf_sdcard_recv_buf(sdh, brcmf_sdcard_cur_sbwad(sdh), |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4106 | SDIO_FUNC_2, F2SYNC, bus->rxhdr, firstread, |
| 4107 | NULL, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4108 | bus->f2rxhdrs++; |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 4109 | ASSERT(sdret != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4110 | |
| 4111 | if (sdret < 0) { |
| 4112 | DHD_ERROR(("%s: RXHEADER FAILED: %d\n", __func__, |
| 4113 | sdret)); |
| 4114 | bus->rx_hdrfail++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4115 | brcmf_sdbrcm_rxfail(bus, true, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4116 | continue; |
| 4117 | } |
| 4118 | #ifdef DHD_DEBUG |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 4119 | if (DHD_BYTES_ON() || DHD_HDRS_ON()) { |
| 4120 | printk(KERN_DEBUG "RxHdr:\n"); |
| 4121 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 4122 | bus->rxhdr, SDPCM_HDRLEN); |
| 4123 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4124 | #endif |
| 4125 | |
| 4126 | /* Extract hardware header fields */ |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 4127 | len = get_unaligned_le16(bus->rxhdr); |
| 4128 | check = get_unaligned_le16(bus->rxhdr + sizeof(u16)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4129 | |
| 4130 | /* All zeros means no more frames */ |
| 4131 | if (!(len | check)) { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4132 | *finished = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4133 | break; |
| 4134 | } |
| 4135 | |
| 4136 | /* Validate check bytes */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4137 | if ((u16) ~(len ^ check)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4138 | DHD_ERROR(("%s: HW hdr err: len/check 0x%04x/0x%04x\n", |
| 4139 | __func__, len, check)); |
| 4140 | bus->rx_badhdr++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4141 | brcmf_sdbrcm_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4142 | continue; |
| 4143 | } |
| 4144 | |
| 4145 | /* Validate frame length */ |
| 4146 | if (len < SDPCM_HDRLEN) { |
| 4147 | DHD_ERROR(("%s: HW hdr length invalid: %d\n", |
| 4148 | __func__, len)); |
| 4149 | continue; |
| 4150 | } |
| 4151 | |
| 4152 | /* Extract software header fields */ |
| 4153 | chan = SDPCM_PACKET_CHANNEL(&bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 4154 | seq = SDPCM_PACKET_SEQUENCE(&bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 4155 | doff = SDPCM_DOFFSET_VALUE(&bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 4156 | txmax = SDPCM_WINDOW_VALUE(&bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 4157 | |
| 4158 | /* Validate data offset */ |
| 4159 | if ((doff < SDPCM_HDRLEN) || (doff > len)) { |
| 4160 | DHD_ERROR(("%s: Bad data offset %d: HW len %d, min %d " |
| 4161 | "seq %d\n", |
| 4162 | __func__, doff, len, SDPCM_HDRLEN, seq)); |
| 4163 | bus->rx_badhdr++; |
| 4164 | ASSERT(0); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4165 | brcmf_sdbrcm_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4166 | continue; |
| 4167 | } |
| 4168 | |
| 4169 | /* Save the readahead length if there is one */ |
| 4170 | bus->nextlen = |
| 4171 | bus->rxhdr[SDPCM_FRAMETAG_LEN + SDPCM_NEXTLEN_OFFSET]; |
| 4172 | if ((bus->nextlen << 4) > MAX_RX_DATASZ) { |
| 4173 | DHD_INFO(("%s (nextlen): got frame w/nextlen too large " |
| 4174 | "(%d), seq %d\n", |
| 4175 | __func__, bus->nextlen, seq)); |
| 4176 | bus->nextlen = 0; |
| 4177 | } |
| 4178 | |
| 4179 | /* Handle Flow Control */ |
| 4180 | fcbits = SDPCM_FCMASK_VALUE(&bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 4181 | |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4182 | if (bus->flowcontrol != fcbits) { |
| 4183 | if (~bus->flowcontrol & fcbits) |
| 4184 | bus->fc_xoff++; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4185 | |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4186 | if (bus->flowcontrol & ~fcbits) |
| 4187 | bus->fc_xon++; |
| 4188 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4189 | bus->fc_rcvd++; |
| 4190 | bus->flowcontrol = fcbits; |
| 4191 | } |
| 4192 | |
| 4193 | /* Check and update sequence number */ |
| 4194 | if (rxseq != seq) { |
| 4195 | DHD_INFO(("%s: rx_seq %d, expected %d\n", __func__, |
| 4196 | seq, rxseq)); |
| 4197 | bus->rx_badseq++; |
| 4198 | rxseq = seq; |
| 4199 | } |
| 4200 | |
| 4201 | /* Check window for sanity */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4202 | if ((u8) (txmax - bus->tx_seq) > 0x40) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4203 | DHD_ERROR(("%s: unlikely tx max %d with tx_seq %d\n", |
| 4204 | __func__, txmax, bus->tx_seq)); |
| 4205 | txmax = bus->tx_seq + 2; |
| 4206 | } |
| 4207 | bus->tx_max = txmax; |
| 4208 | |
| 4209 | /* Call a separate function for control frames */ |
| 4210 | if (chan == SDPCM_CONTROL_CHANNEL) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4211 | brcmf_sdbrcm_read_control(bus, bus->rxhdr, len, doff); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4212 | continue; |
| 4213 | } |
| 4214 | |
| 4215 | ASSERT((chan == SDPCM_DATA_CHANNEL) |
| 4216 | || (chan == SDPCM_EVENT_CHANNEL) |
| 4217 | || (chan == SDPCM_TEST_CHANNEL) |
| 4218 | || (chan == SDPCM_GLOM_CHANNEL)); |
| 4219 | |
| 4220 | /* Length to read */ |
| 4221 | rdlen = (len > firstread) ? (len - firstread) : 0; |
| 4222 | |
| 4223 | /* May pad read to blocksize for efficiency */ |
| 4224 | if (bus->roundup && bus->blocksize && |
| 4225 | (rdlen > bus->blocksize)) { |
| 4226 | pad = bus->blocksize - (rdlen % bus->blocksize); |
| 4227 | if ((pad <= bus->roundup) && (pad < bus->blocksize) && |
| 4228 | ((rdlen + pad + firstread) < MAX_RX_DATASZ)) |
| 4229 | rdlen += pad; |
| 4230 | } else if (rdlen % DHD_SDALIGN) { |
| 4231 | rdlen += DHD_SDALIGN - (rdlen % DHD_SDALIGN); |
| 4232 | } |
| 4233 | |
| 4234 | /* Satisfy length-alignment requirements */ |
| 4235 | if (forcealign && (rdlen & (ALIGNMENT - 1))) |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 4236 | rdlen = roundup(rdlen, ALIGNMENT); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4237 | |
| 4238 | if ((rdlen + firstread) > MAX_RX_DATASZ) { |
| 4239 | /* Too long -- skip this frame */ |
| 4240 | DHD_ERROR(("%s: too long: len %d rdlen %d\n", |
| 4241 | __func__, len, rdlen)); |
| 4242 | bus->dhd->rx_errors++; |
| 4243 | bus->rx_toolong++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4244 | brcmf_sdbrcm_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4245 | continue; |
| 4246 | } |
| 4247 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4248 | pkt = brcmu_pkt_buf_get_skb(rdlen + firstread + DHD_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4249 | if (!pkt) { |
| 4250 | /* Give up on data, request rtx of events */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4251 | DHD_ERROR(("%s: brcmu_pkt_buf_get_skb failed: rdlen %d" |
| 4252 | " chan %d\n", __func__, rdlen, chan)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4253 | bus->dhd->rx_dropped++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4254 | brcmf_sdbrcm_rxfail(bus, false, RETRYCHAN(chan)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4255 | continue; |
| 4256 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4257 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4258 | ASSERT(!(pkt->prev)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4259 | |
| 4260 | /* Leave room for what we already read, and align remainder */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4261 | ASSERT(firstread < pkt->len); |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 4262 | skb_pull(pkt, firstread); |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 4263 | PKTALIGN(pkt, rdlen, DHD_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4264 | |
| 4265 | /* Read the remaining frame data */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4266 | sdret = brcmf_sdcard_recv_buf(sdh, brcmf_sdcard_cur_sbwad(sdh), |
| 4267 | SDIO_FUNC_2, F2SYNC, ((u8 *) (pkt->data)), |
| 4268 | rdlen, pkt, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4269 | bus->f2rxdata++; |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 4270 | ASSERT(sdret != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4271 | |
| 4272 | if (sdret < 0) { |
| 4273 | DHD_ERROR(("%s: read %d %s bytes failed: %d\n", |
| 4274 | __func__, rdlen, |
| 4275 | ((chan == |
| 4276 | SDPCM_EVENT_CHANNEL) ? "event" : ((chan == |
| 4277 | SDPCM_DATA_CHANNEL) |
| 4278 | ? "data" : "test")), |
| 4279 | sdret)); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4280 | brcmu_pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4281 | bus->dhd->rx_errors++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4282 | brcmf_sdbrcm_rxfail(bus, true, RETRYCHAN(chan)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4283 | continue; |
| 4284 | } |
| 4285 | |
| 4286 | /* Copy the already-read portion */ |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 4287 | skb_push(pkt, firstread); |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 4288 | memcpy(pkt->data, bus->rxhdr, firstread); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4289 | |
| 4290 | #ifdef DHD_DEBUG |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 4291 | if (DHD_BYTES_ON() && DHD_DATA_ON()) { |
| 4292 | printk(KERN_DEBUG "Rx Data:\n"); |
| 4293 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 4294 | pkt->data, len); |
| 4295 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4296 | #endif |
| 4297 | |
| 4298 | deliver: |
| 4299 | /* Save superframe descriptor and allocate packet frame */ |
| 4300 | if (chan == SDPCM_GLOM_CHANNEL) { |
| 4301 | if (SDPCM_GLOMDESC(&bus->rxhdr[SDPCM_FRAMETAG_LEN])) { |
| 4302 | DHD_GLOM(("%s: glom descriptor, %d bytes:\n", |
| 4303 | __func__, len)); |
| 4304 | #ifdef DHD_DEBUG |
| 4305 | if (DHD_GLOM_ON()) { |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 4306 | printk(KERN_DEBUG "Glom Data:\n"); |
| 4307 | print_hex_dump_bytes("", |
| 4308 | DUMP_PREFIX_OFFSET, |
| 4309 | pkt->data, len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4310 | } |
| 4311 | #endif |
Arend van Spriel | 2cb8ada | 2010-11-18 20:46:44 +0100 | [diff] [blame] | 4312 | __skb_trim(pkt, len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4313 | ASSERT(doff == SDPCM_HDRLEN); |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 4314 | skb_pull(pkt, SDPCM_HDRLEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4315 | bus->glomd = pkt; |
| 4316 | } else { |
| 4317 | DHD_ERROR(("%s: glom superframe w/o " |
| 4318 | "descriptor!\n", __func__)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4319 | brcmf_sdbrcm_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4320 | } |
| 4321 | continue; |
| 4322 | } |
| 4323 | |
| 4324 | /* Fill in packet len and prio, deliver upward */ |
Arend van Spriel | 2cb8ada | 2010-11-18 20:46:44 +0100 | [diff] [blame] | 4325 | __skb_trim(pkt, len); |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 4326 | skb_pull(pkt, doff); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4327 | |
| 4328 | #ifdef SDTEST |
| 4329 | /* Test channel packets are processed separately */ |
| 4330 | if (chan == SDPCM_TEST_CHANNEL) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4331 | brcmf_sdbrcm_checkdied(bus, pkt, seq); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4332 | continue; |
| 4333 | } |
| 4334 | #endif /* SDTEST */ |
| 4335 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4336 | if (pkt->len == 0) { |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4337 | brcmu_pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4338 | continue; |
| 4339 | } else if (dhd_prot_hdrpull(bus->dhd, &ifidx, pkt) != 0) { |
| 4340 | DHD_ERROR(("%s: rx protocol error\n", __func__)); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4341 | brcmu_pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4342 | bus->dhd->rx_errors++; |
| 4343 | continue; |
| 4344 | } |
| 4345 | |
| 4346 | /* Unlock during rx call */ |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 4347 | brcmf_os_sdunlock(bus->dhd); |
| 4348 | brcmf_rx_frame(bus->dhd, ifidx, pkt, 1); |
| 4349 | brcmf_os_sdlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4350 | } |
| 4351 | rxcount = maxframes - rxleft; |
| 4352 | #ifdef DHD_DEBUG |
| 4353 | /* Message if we hit the limit */ |
| 4354 | if (!rxleft && !sdtest) |
| 4355 | DHD_DATA(("%s: hit rx limit of %d frames\n", __func__, |
| 4356 | maxframes)); |
| 4357 | else |
| 4358 | #endif /* DHD_DEBUG */ |
| 4359 | DHD_DATA(("%s: processed %d frames\n", __func__, rxcount)); |
| 4360 | /* Back off rxseq if awaiting rtx, update rx_seq */ |
| 4361 | if (bus->rxskip) |
| 4362 | rxseq--; |
| 4363 | bus->rx_seq = rxseq; |
| 4364 | |
| 4365 | return rxcount; |
| 4366 | } |
| 4367 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4368 | static u32 brcmf_sdbrcm_hostmail(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4369 | { |
Franky Lin | 597600a | 2011-06-01 13:45:39 +0200 | [diff] [blame] | 4370 | struct sdpcmd_regs *regs = bus->regs; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 4371 | u32 intstatus = 0; |
| 4372 | u32 hmb_data; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4373 | u8 fcbits; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4374 | uint retries = 0; |
| 4375 | |
| 4376 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 4377 | |
| 4378 | /* Read mailbox data and ack that we did so */ |
| 4379 | R_SDREG(hmb_data, ®s->tohostmailboxdata, retries); |
| 4380 | if (retries <= retry_limit) |
| 4381 | W_SDREG(SMB_INT_ACK, ®s->tosbmailbox, retries); |
| 4382 | bus->f1regdata += 2; |
| 4383 | |
| 4384 | /* Dongle recomposed rx frames, accept them again */ |
| 4385 | if (hmb_data & HMB_DATA_NAKHANDLED) { |
| 4386 | DHD_INFO(("Dongle reports NAK handled, expect rtx of %d\n", |
| 4387 | bus->rx_seq)); |
| 4388 | if (!bus->rxskip) |
| 4389 | DHD_ERROR(("%s: unexpected NAKHANDLED!\n", __func__)); |
| 4390 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4391 | bus->rxskip = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4392 | intstatus |= I_HMB_FRAME_IND; |
| 4393 | } |
| 4394 | |
| 4395 | /* |
| 4396 | * DEVREADY does not occur with gSPI. |
| 4397 | */ |
| 4398 | if (hmb_data & (HMB_DATA_DEVREADY | HMB_DATA_FWREADY)) { |
| 4399 | bus->sdpcm_ver = |
| 4400 | (hmb_data & HMB_DATA_VERSION_MASK) >> |
| 4401 | HMB_DATA_VERSION_SHIFT; |
| 4402 | if (bus->sdpcm_ver != SDPCM_PROT_VERSION) |
| 4403 | DHD_ERROR(("Version mismatch, dongle reports %d, " |
| 4404 | "expecting %d\n", |
| 4405 | bus->sdpcm_ver, SDPCM_PROT_VERSION)); |
| 4406 | else |
| 4407 | DHD_INFO(("Dongle ready, protocol version %d\n", |
| 4408 | bus->sdpcm_ver)); |
| 4409 | } |
| 4410 | |
| 4411 | /* |
| 4412 | * Flow Control has been moved into the RX headers and this out of band |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4413 | * method isn't used any more. |
| 4414 | * remaining backward compatible with older dongles. |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4415 | */ |
| 4416 | if (hmb_data & HMB_DATA_FC) { |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4417 | fcbits = (hmb_data & HMB_DATA_FCDATA_MASK) >> |
| 4418 | HMB_DATA_FCDATA_SHIFT; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4419 | |
| 4420 | if (fcbits & ~bus->flowcontrol) |
| 4421 | bus->fc_xoff++; |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4422 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4423 | if (bus->flowcontrol & ~fcbits) |
| 4424 | bus->fc_xon++; |
| 4425 | |
| 4426 | bus->fc_rcvd++; |
| 4427 | bus->flowcontrol = fcbits; |
| 4428 | } |
| 4429 | |
| 4430 | /* Shouldn't be any others */ |
| 4431 | if (hmb_data & ~(HMB_DATA_DEVREADY | |
| 4432 | HMB_DATA_NAKHANDLED | |
| 4433 | HMB_DATA_FC | |
| 4434 | HMB_DATA_FWREADY | |
| 4435 | HMB_DATA_FCDATA_MASK | HMB_DATA_VERSION_MASK)) { |
| 4436 | DHD_ERROR(("Unknown mailbox data content: 0x%02x\n", hmb_data)); |
| 4437 | } |
| 4438 | |
| 4439 | return intstatus; |
| 4440 | } |
| 4441 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4442 | bool brcmf_sdbrcm_dpc(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4443 | { |
| 4444 | bcmsdh_info_t *sdh = bus->sdh; |
Franky Lin | 597600a | 2011-06-01 13:45:39 +0200 | [diff] [blame] | 4445 | struct sdpcmd_regs *regs = bus->regs; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 4446 | u32 intstatus, newstatus = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4447 | uint retries = 0; |
| 4448 | uint rxlimit = dhd_rxbound; /* Rx frames to read before resched */ |
| 4449 | uint txlimit = dhd_txbound; /* Tx frames to send before resched */ |
| 4450 | uint framecnt = 0; /* Temporary counter of tx/rx frames */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4451 | bool rxdone = true; /* Flag for no more read data */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4452 | bool resched = false; /* Flag indicating resched wanted */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4453 | |
| 4454 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 4455 | |
| 4456 | /* Start with leftover status bits */ |
| 4457 | intstatus = bus->intstatus; |
| 4458 | |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 4459 | brcmf_os_sdlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4460 | |
| 4461 | /* If waiting for HTAVAIL, check status */ |
| 4462 | if (bus->clkstate == CLK_PENDING) { |
| 4463 | int err; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4464 | u8 clkctl, devctl = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4465 | |
| 4466 | #ifdef DHD_DEBUG |
| 4467 | /* Check for inconsistent device control */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4468 | devctl = brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
| 4469 | SBSDIO_DEVICE_CTL, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4470 | if (err) { |
| 4471 | DHD_ERROR(("%s: error reading DEVCTL: %d\n", |
| 4472 | __func__, err)); |
| 4473 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 4474 | } else { |
| 4475 | ASSERT(devctl & SBSDIO_DEVCTL_CA_INT_ONLY); |
| 4476 | } |
| 4477 | #endif /* DHD_DEBUG */ |
| 4478 | |
| 4479 | /* Read CSR, if clock on switch to AVAIL, else ignore */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4480 | clkctl = brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
| 4481 | SBSDIO_FUNC1_CHIPCLKCSR, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4482 | if (err) { |
| 4483 | DHD_ERROR(("%s: error reading CSR: %d\n", __func__, |
| 4484 | err)); |
| 4485 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 4486 | } |
| 4487 | |
| 4488 | DHD_INFO(("DPC: PENDING, devctl 0x%02x clkctl 0x%02x\n", devctl, |
| 4489 | clkctl)); |
| 4490 | |
| 4491 | if (SBSDIO_HTAV(clkctl)) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4492 | devctl = brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
| 4493 | SBSDIO_DEVICE_CTL, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4494 | if (err) { |
| 4495 | DHD_ERROR(("%s: error reading DEVCTL: %d\n", |
| 4496 | __func__, err)); |
| 4497 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 4498 | } |
| 4499 | devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4500 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, |
| 4501 | SBSDIO_DEVICE_CTL, devctl, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4502 | if (err) { |
| 4503 | DHD_ERROR(("%s: error writing DEVCTL: %d\n", |
| 4504 | __func__, err)); |
| 4505 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 4506 | } |
| 4507 | bus->clkstate = CLK_AVAIL; |
| 4508 | } else { |
| 4509 | goto clkwait; |
| 4510 | } |
| 4511 | } |
| 4512 | |
| 4513 | BUS_WAKE(bus); |
| 4514 | |
| 4515 | /* Make sure backplane clock is on */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4516 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4517 | if (bus->clkstate == CLK_PENDING) |
| 4518 | goto clkwait; |
| 4519 | |
| 4520 | /* Pending interrupt indicates new device status */ |
| 4521 | if (bus->ipend) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4522 | bus->ipend = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4523 | R_SDREG(newstatus, ®s->intstatus, retries); |
| 4524 | bus->f1regdata++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4525 | if (brcmf_sdcard_regfail(bus->sdh)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4526 | newstatus = 0; |
| 4527 | newstatus &= bus->hostintmask; |
| 4528 | bus->fcstate = !!(newstatus & I_HMB_FC_STATE); |
| 4529 | if (newstatus) { |
| 4530 | W_SDREG(newstatus, ®s->intstatus, retries); |
| 4531 | bus->f1regdata++; |
| 4532 | } |
| 4533 | } |
| 4534 | |
| 4535 | /* Merge new bits with previous */ |
| 4536 | intstatus |= newstatus; |
| 4537 | bus->intstatus = 0; |
| 4538 | |
| 4539 | /* Handle flow-control change: read new state in case our ack |
| 4540 | * crossed another change interrupt. If change still set, assume |
| 4541 | * FC ON for safety, let next loop through do the debounce. |
| 4542 | */ |
| 4543 | if (intstatus & I_HMB_FC_CHANGE) { |
| 4544 | intstatus &= ~I_HMB_FC_CHANGE; |
| 4545 | W_SDREG(I_HMB_FC_CHANGE, ®s->intstatus, retries); |
| 4546 | R_SDREG(newstatus, ®s->intstatus, retries); |
| 4547 | bus->f1regdata += 2; |
| 4548 | bus->fcstate = |
| 4549 | !!(newstatus & (I_HMB_FC_STATE | I_HMB_FC_CHANGE)); |
| 4550 | intstatus |= (newstatus & bus->hostintmask); |
| 4551 | } |
| 4552 | |
| 4553 | /* Handle host mailbox indication */ |
| 4554 | if (intstatus & I_HMB_HOST_INT) { |
| 4555 | intstatus &= ~I_HMB_HOST_INT; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4556 | intstatus |= brcmf_sdbrcm_hostmail(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4557 | } |
| 4558 | |
| 4559 | /* Generally don't ask for these, can get CRC errors... */ |
| 4560 | if (intstatus & I_WR_OOSYNC) { |
| 4561 | DHD_ERROR(("Dongle reports WR_OOSYNC\n")); |
| 4562 | intstatus &= ~I_WR_OOSYNC; |
| 4563 | } |
| 4564 | |
| 4565 | if (intstatus & I_RD_OOSYNC) { |
| 4566 | DHD_ERROR(("Dongle reports RD_OOSYNC\n")); |
| 4567 | intstatus &= ~I_RD_OOSYNC; |
| 4568 | } |
| 4569 | |
| 4570 | if (intstatus & I_SBINT) { |
| 4571 | DHD_ERROR(("Dongle reports SBINT\n")); |
| 4572 | intstatus &= ~I_SBINT; |
| 4573 | } |
| 4574 | |
| 4575 | /* Would be active due to wake-wlan in gSPI */ |
| 4576 | if (intstatus & I_CHIPACTIVE) { |
| 4577 | DHD_INFO(("Dongle reports CHIPACTIVE\n")); |
| 4578 | intstatus &= ~I_CHIPACTIVE; |
| 4579 | } |
| 4580 | |
| 4581 | /* Ignore frame indications if rxskip is set */ |
| 4582 | if (bus->rxskip) |
| 4583 | intstatus &= ~I_HMB_FRAME_IND; |
| 4584 | |
| 4585 | /* On frame indication, read available frames */ |
| 4586 | if (PKT_AVAILABLE()) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4587 | framecnt = brcmf_sdbrcm_readframes(bus, rxlimit, &rxdone); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4588 | if (rxdone || bus->rxskip) |
| 4589 | intstatus &= ~I_HMB_FRAME_IND; |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 4590 | rxlimit -= min(framecnt, rxlimit); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4591 | } |
| 4592 | |
| 4593 | /* Keep still-pending events for next scheduling */ |
| 4594 | bus->intstatus = intstatus; |
| 4595 | |
| 4596 | clkwait: |
| 4597 | #if defined(OOB_INTR_ONLY) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4598 | brcmf_sdio_oob_intr_set(1); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4599 | #endif /* (OOB_INTR_ONLY) */ |
| 4600 | /* Re-enable interrupts to detect new device events (mailbox, rx frame) |
| 4601 | * or clock availability. (Allows tx loop to check ipend if desired.) |
| 4602 | * (Unless register access seems hosed, as we may not be able to ACK...) |
| 4603 | */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4604 | if (bus->intr && bus->intdis && !brcmf_sdcard_regfail(sdh)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4605 | DHD_INTR(("%s: enable SDIO interrupts, rxdone %d framecnt %d\n", |
| 4606 | __func__, rxdone, framecnt)); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4607 | bus->intdis = false; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4608 | brcmf_sdcard_intr_enable(sdh); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4609 | } |
| 4610 | |
| 4611 | if (DATAOK(bus) && bus->ctrl_frame_stat && |
| 4612 | (bus->clkstate == CLK_AVAIL)) { |
| 4613 | int ret, i; |
| 4614 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4615 | ret = brcmf_sdbrcm_send_buf(bus, brcmf_sdcard_cur_sbwad(sdh), |
| 4616 | SDIO_FUNC_2, F2SYNC, (u8 *) bus->ctrl_frame_buf, |
| 4617 | (u32) bus->ctrl_frame_len, NULL, NULL, NULL); |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 4618 | ASSERT(ret != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4619 | |
| 4620 | if (ret < 0) { |
| 4621 | /* On failure, abort the command and |
| 4622 | terminate the frame */ |
| 4623 | DHD_INFO(("%s: sdio error %d, abort command and " |
| 4624 | "terminate frame.\n", __func__, ret)); |
| 4625 | bus->tx_sderrs++; |
| 4626 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4627 | brcmf_sdcard_abort(sdh, SDIO_FUNC_2); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4628 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4629 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4630 | SBSDIO_FUNC1_FRAMECTRL, SFC_WF_TERM, |
| 4631 | NULL); |
| 4632 | bus->f1regdata++; |
| 4633 | |
| 4634 | for (i = 0; i < 3; i++) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4635 | u8 hi, lo; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4636 | hi = brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4637 | SBSDIO_FUNC1_WFRAMEBCHI, |
| 4638 | NULL); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4639 | lo = brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4640 | SBSDIO_FUNC1_WFRAMEBCLO, |
| 4641 | NULL); |
| 4642 | bus->f1regdata += 2; |
| 4643 | if ((hi == 0) && (lo == 0)) |
| 4644 | break; |
| 4645 | } |
| 4646 | |
| 4647 | } |
| 4648 | if (ret == 0) |
| 4649 | bus->tx_seq = (bus->tx_seq + 1) % SDPCM_SEQUENCE_WRAP; |
| 4650 | |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 4651 | DHD_INFO(("Return_dpc value is : %d\n", ret)); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4652 | bus->ctrl_frame_stat = false; |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 4653 | brcmf_wait_event_wakeup(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4654 | } |
| 4655 | /* Send queued frames (limit 1 if rx may still be pending) */ |
| 4656 | else if ((bus->clkstate == CLK_AVAIL) && !bus->fcstate && |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4657 | brcmu_pktq_mlen(&bus->txq, ~bus->flowcontrol) && txlimit |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4658 | && DATAOK(bus)) { |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 4659 | framecnt = rxdone ? txlimit : min(txlimit, dhd_txminmax); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4660 | framecnt = brcmf_sdbrcm_sendfromq(bus, framecnt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4661 | txlimit -= framecnt; |
| 4662 | } |
| 4663 | |
| 4664 | /* Resched if events or tx frames are pending, |
| 4665 | else await next interrupt */ |
| 4666 | /* On failed register access, all bets are off: |
| 4667 | no resched or interrupts */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4668 | if ((bus->dhd->busstate == DHD_BUS_DOWN) || brcmf_sdcard_regfail(sdh)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4669 | DHD_ERROR(("%s: failed backplane access over SDIO, halting " |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4670 | "operation %d\n", __func__, brcmf_sdcard_regfail(sdh))); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4671 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 4672 | bus->intstatus = 0; |
| 4673 | } else if (bus->clkstate == CLK_PENDING) { |
| 4674 | DHD_INFO(("%s: rescheduled due to CLK_PENDING awaiting " |
| 4675 | "I_CHIPACTIVE interrupt\n", __func__)); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4676 | resched = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4677 | } else if (bus->intstatus || bus->ipend || |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4678 | (!bus->fcstate && brcmu_pktq_mlen(&bus->txq, ~bus->flowcontrol) |
| 4679 | && DATAOK(bus)) || PKT_AVAILABLE()) { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4680 | resched = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4681 | } |
| 4682 | |
| 4683 | bus->dpc_sched = resched; |
| 4684 | |
| 4685 | /* If we're done for now, turn off clock request. */ |
| 4686 | if ((bus->clkstate != CLK_PENDING) |
| 4687 | && bus->idletime == DHD_IDLE_IMMEDIATE) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4688 | bus->activity = false; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4689 | brcmf_sdbrcm_clkctl(bus, CLK_NONE, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4690 | } |
| 4691 | |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 4692 | brcmf_os_sdunlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4693 | |
| 4694 | return resched; |
| 4695 | } |
| 4696 | |
| 4697 | bool dhd_bus_dpc(struct dhd_bus *bus) |
| 4698 | { |
| 4699 | bool resched; |
| 4700 | |
| 4701 | /* Call the DPC directly. */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4702 | DHD_TRACE(("Calling brcmf_sdbrcm_dpc() from %s\n", __func__)); |
| 4703 | resched = brcmf_sdbrcm_dpc(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4704 | |
| 4705 | return resched; |
| 4706 | } |
| 4707 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4708 | void brcmf_sdbrcm_isr(void *arg) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4709 | { |
| 4710 | dhd_bus_t *bus = (dhd_bus_t *) arg; |
| 4711 | bcmsdh_info_t *sdh; |
| 4712 | |
| 4713 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 4714 | |
| 4715 | if (!bus) { |
| 4716 | DHD_ERROR(("%s : bus is null pointer , exit\n", __func__)); |
| 4717 | return; |
| 4718 | } |
| 4719 | sdh = bus->sdh; |
| 4720 | |
| 4721 | if (bus->dhd->busstate == DHD_BUS_DOWN) { |
| 4722 | DHD_ERROR(("%s : bus is down. we have nothing to do\n", |
| 4723 | __func__)); |
| 4724 | return; |
| 4725 | } |
| 4726 | /* Count the interrupt call */ |
| 4727 | bus->intrcount++; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4728 | bus->ipend = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4729 | |
| 4730 | /* Shouldn't get this interrupt if we're sleeping? */ |
| 4731 | if (bus->sleeping) { |
| 4732 | DHD_ERROR(("INTERRUPT WHILE SLEEPING??\n")); |
| 4733 | return; |
| 4734 | } |
| 4735 | |
| 4736 | /* Disable additional interrupts (is this needed now)? */ |
| 4737 | if (bus->intr) |
| 4738 | DHD_INTR(("%s: disable SDIO interrupts\n", __func__)); |
| 4739 | else |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4740 | DHD_ERROR(("brcmf_sdbrcm_isr() w/o interrupt configured!\n")); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4741 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4742 | brcmf_sdcard_intr_disable(sdh); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4743 | bus->intdis = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4744 | |
| 4745 | #if defined(SDIO_ISR_THREAD) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4746 | DHD_TRACE(("Calling brcmf_sdbrcm_dpc() from %s\n", __func__)); |
| 4747 | while (brcmf_sdbrcm_dpc(bus)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4748 | ; |
| 4749 | #else |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4750 | bus->dpc_sched = true; |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 4751 | brcmf_sched_dpc(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4752 | #endif |
| 4753 | |
| 4754 | } |
| 4755 | |
| 4756 | #ifdef SDTEST |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4757 | static void brcmf_sdbrcm_pktgen_init(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4758 | { |
| 4759 | /* Default to specified length, or full range */ |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 4760 | if (brcmf_pktgen_len) { |
| 4761 | bus->pktgen_maxlen = min(brcmf_pktgen_len, |
| 4762 | BRCMF_MAX_PKTGEN_LEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4763 | bus->pktgen_minlen = bus->pktgen_maxlen; |
| 4764 | } else { |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 4765 | bus->pktgen_maxlen = BRCMF_MAX_PKTGEN_LEN; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4766 | bus->pktgen_minlen = 0; |
| 4767 | } |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4768 | bus->pktgen_len = (u16) bus->pktgen_minlen; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4769 | |
| 4770 | /* Default to per-watchdog burst with 10s print time */ |
| 4771 | bus->pktgen_freq = 1; |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 4772 | bus->pktgen_print = 10000 / brcmf_watchdog_ms; |
| 4773 | bus->pktgen_count = (brcmf_pktgen * brcmf_watchdog_ms + 999) / 1000; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4774 | |
| 4775 | /* Default to echo mode */ |
| 4776 | bus->pktgen_mode = DHD_PKTGEN_ECHO; |
| 4777 | bus->pktgen_stop = 1; |
| 4778 | } |
| 4779 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4780 | static void brcmf_sdbrcm_pktgen(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4781 | { |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 4782 | struct sk_buff *pkt; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4783 | u8 *data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4784 | uint pktcount; |
| 4785 | uint fillbyte; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4786 | u16 len; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4787 | |
| 4788 | /* Display current count if appropriate */ |
| 4789 | if (bus->pktgen_print && (++bus->pktgen_ptick >= bus->pktgen_print)) { |
| 4790 | bus->pktgen_ptick = 0; |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 4791 | printk(KERN_DEBUG "%s: send attempts %d rcvd %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4792 | __func__, bus->pktgen_sent, bus->pktgen_rcvd); |
| 4793 | } |
| 4794 | |
| 4795 | /* For recv mode, just make sure dongle has started sending */ |
| 4796 | if (bus->pktgen_mode == DHD_PKTGEN_RECV) { |
| 4797 | if (!bus->pktgen_rcvd) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4798 | brcmf_sdbrcm_sdtest_set(bus, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4799 | return; |
| 4800 | } |
| 4801 | |
| 4802 | /* Otherwise, generate or request the specified number of packets */ |
| 4803 | for (pktcount = 0; pktcount < bus->pktgen_count; pktcount++) { |
| 4804 | /* Stop if total has been reached */ |
| 4805 | if (bus->pktgen_total |
| 4806 | && (bus->pktgen_sent >= bus->pktgen_total)) { |
| 4807 | bus->pktgen_count = 0; |
| 4808 | break; |
| 4809 | } |
| 4810 | |
| 4811 | /* Allocate an appropriate-sized packet */ |
| 4812 | len = bus->pktgen_len; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4813 | pkt = brcmu_pkt_buf_get_skb( |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 4814 | (len + SDPCM_HDRLEN + SDPCM_TEST_HDRLEN + DHD_SDALIGN), |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4815 | true); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 4816 | if (!pkt) { |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4817 | DHD_ERROR(("%s: brcmu_pkt_buf_get_skb failed!\n", |
| 4818 | __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4819 | break; |
| 4820 | } |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 4821 | PKTALIGN(pkt, (len + SDPCM_HDRLEN + SDPCM_TEST_HDRLEN), |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4822 | DHD_SDALIGN); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4823 | data = (u8 *) (pkt->data) + SDPCM_HDRLEN; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4824 | |
| 4825 | /* Write test header cmd and extra based on mode */ |
| 4826 | switch (bus->pktgen_mode) { |
| 4827 | case DHD_PKTGEN_ECHO: |
| 4828 | *data++ = SDPCM_TEST_ECHOREQ; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4829 | *data++ = (u8) bus->pktgen_sent; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4830 | break; |
| 4831 | |
| 4832 | case DHD_PKTGEN_SEND: |
| 4833 | *data++ = SDPCM_TEST_DISCARD; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4834 | *data++ = (u8) bus->pktgen_sent; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4835 | break; |
| 4836 | |
| 4837 | case DHD_PKTGEN_RXBURST: |
| 4838 | *data++ = SDPCM_TEST_BURST; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4839 | *data++ = (u8) bus->pktgen_count; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4840 | break; |
| 4841 | |
| 4842 | default: |
| 4843 | DHD_ERROR(("Unrecognized pktgen mode %d\n", |
| 4844 | bus->pktgen_mode)); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4845 | brcmu_pkt_buf_free_skb(pkt, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4846 | bus->pktgen_count = 0; |
| 4847 | return; |
| 4848 | } |
| 4849 | |
| 4850 | /* Write test header length field */ |
| 4851 | *data++ = (len >> 0); |
| 4852 | *data++ = (len >> 8); |
| 4853 | |
| 4854 | /* Then fill in the remainder -- N/A for burst, |
| 4855 | but who cares... */ |
| 4856 | for (fillbyte = 0; fillbyte < len; fillbyte++) |
| 4857 | *data++ = |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4858 | SDPCM_TEST_FILL(fillbyte, (u8) bus->pktgen_sent); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4859 | |
| 4860 | #ifdef DHD_DEBUG |
| 4861 | if (DHD_BYTES_ON() && DHD_DATA_ON()) { |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4862 | data = (u8 *) (pkt->data) + SDPCM_HDRLEN; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4863 | printk(KERN_DEBUG "brcmf_sdbrcm_pktgen: Tx Data:\n"); |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 4864 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, data, |
| 4865 | pkt->len - SDPCM_HDRLEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4866 | } |
| 4867 | #endif |
| 4868 | |
| 4869 | /* Send it */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4870 | if (brcmf_sdbrcm_txpkt(bus, pkt, SDPCM_TEST_CHANNEL, true)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4871 | bus->pktgen_fail++; |
| 4872 | if (bus->pktgen_stop |
| 4873 | && bus->pktgen_stop == bus->pktgen_fail) |
| 4874 | bus->pktgen_count = 0; |
| 4875 | } |
| 4876 | bus->pktgen_sent++; |
| 4877 | |
| 4878 | /* Bump length if not fixed, wrap at max */ |
| 4879 | if (++bus->pktgen_len > bus->pktgen_maxlen) |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4880 | bus->pktgen_len = (u16) bus->pktgen_minlen; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4881 | |
| 4882 | /* Special case for burst mode: just send one request! */ |
| 4883 | if (bus->pktgen_mode == DHD_PKTGEN_RXBURST) |
| 4884 | break; |
| 4885 | } |
| 4886 | } |
| 4887 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4888 | static void brcmf_sdbrcm_sdtest_set(dhd_bus_t *bus, bool start) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4889 | { |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 4890 | struct sk_buff *pkt; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4891 | u8 *data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4892 | |
| 4893 | /* Allocate the packet */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4894 | pkt = brcmu_pkt_buf_get_skb(SDPCM_HDRLEN + SDPCM_TEST_HDRLEN + |
Henry Ptasinski | b33f0e2 | 2011-05-10 22:25:29 +0200 | [diff] [blame] | 4895 | DHD_SDALIGN, true); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 4896 | if (!pkt) { |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4897 | DHD_ERROR(("%s: brcmu_pkt_buf_get_skb failed!\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4898 | return; |
| 4899 | } |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 4900 | PKTALIGN(pkt, (SDPCM_HDRLEN + SDPCM_TEST_HDRLEN), DHD_SDALIGN); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4901 | data = (u8 *) (pkt->data) + SDPCM_HDRLEN; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4902 | |
| 4903 | /* Fill in the test header */ |
| 4904 | *data++ = SDPCM_TEST_SEND; |
| 4905 | *data++ = start; |
| 4906 | *data++ = (bus->pktgen_maxlen >> 0); |
| 4907 | *data++ = (bus->pktgen_maxlen >> 8); |
| 4908 | |
| 4909 | /* Send it */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4910 | if (brcmf_sdbrcm_txpkt(bus, pkt, SDPCM_TEST_CHANNEL, true)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4911 | bus->pktgen_fail++; |
| 4912 | } |
| 4913 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4914 | static void |
| 4915 | brcmf_sdbrcm_checkdied(dhd_bus_t *bus, struct sk_buff *pkt, uint seq) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4916 | { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4917 | u8 *data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4918 | uint pktlen; |
| 4919 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4920 | u8 cmd; |
| 4921 | u8 extra; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4922 | u16 len; |
| 4923 | u16 offset; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4924 | |
| 4925 | /* Check for min length */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4926 | pktlen = pkt->len; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4927 | if (pktlen < SDPCM_TEST_HDRLEN) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4928 | DHD_ERROR(("brcmf_sdbrcm_checkdied: toss runt frame, pktlen " |
| 4929 | "%d\n", pktlen)); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4930 | brcmu_pkt_buf_free_skb(pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4931 | return; |
| 4932 | } |
| 4933 | |
| 4934 | /* Extract header fields */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4935 | data = pkt->data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4936 | cmd = *data++; |
| 4937 | extra = *data++; |
| 4938 | len = *data++; |
| 4939 | len += *data++ << 8; |
| 4940 | |
| 4941 | /* Check length for relevant commands */ |
| 4942 | if (cmd == SDPCM_TEST_DISCARD || cmd == SDPCM_TEST_ECHOREQ |
| 4943 | || cmd == SDPCM_TEST_ECHORSP) { |
| 4944 | if (pktlen != len + SDPCM_TEST_HDRLEN) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4945 | DHD_ERROR(("brcmf_sdbrcm_checkdied: frame length " |
| 4946 | "mismatch, pktlen %d seq %d" " cmd %d extra %d " |
| 4947 | "len %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4948 | pktlen, seq, cmd, extra, len)); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4949 | brcmu_pkt_buf_free_skb(pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4950 | return; |
| 4951 | } |
| 4952 | } |
| 4953 | |
| 4954 | /* Process as per command */ |
| 4955 | switch (cmd) { |
| 4956 | case SDPCM_TEST_ECHOREQ: |
| 4957 | /* Rx->Tx turnaround ok (even on NDIS w/current |
| 4958 | implementation) */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4959 | *(u8 *) (pkt->data) = SDPCM_TEST_ECHORSP; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4960 | if (brcmf_sdbrcm_txpkt(bus, pkt, SDPCM_TEST_CHANNEL, true) == 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4961 | bus->pktgen_sent++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4962 | else { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4963 | bus->pktgen_fail++; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4964 | brcmu_pkt_buf_free_skb(pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4965 | } |
| 4966 | bus->pktgen_rcvd++; |
| 4967 | break; |
| 4968 | |
| 4969 | case SDPCM_TEST_ECHORSP: |
| 4970 | if (bus->ext_loop) { |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4971 | brcmu_pkt_buf_free_skb(pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4972 | bus->pktgen_rcvd++; |
| 4973 | break; |
| 4974 | } |
| 4975 | |
| 4976 | for (offset = 0; offset < len; offset++, data++) { |
| 4977 | if (*data != SDPCM_TEST_FILL(offset, extra)) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4978 | DHD_ERROR(("brcmf_sdbrcm_checkdied: echo data " |
| 4979 | "mismatch: " "offset %d (len %d) " |
| 4980 | "expect 0x%02x rcvd 0x%02x\n", |
| 4981 | offset, len, |
| 4982 | SDPCM_TEST_FILL(offset, extra), |
| 4983 | *data)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4984 | break; |
| 4985 | } |
| 4986 | } |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4987 | brcmu_pkt_buf_free_skb(pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4988 | bus->pktgen_rcvd++; |
| 4989 | break; |
| 4990 | |
| 4991 | case SDPCM_TEST_DISCARD: |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4992 | brcmu_pkt_buf_free_skb(pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4993 | bus->pktgen_rcvd++; |
| 4994 | break; |
| 4995 | |
| 4996 | case SDPCM_TEST_BURST: |
| 4997 | case SDPCM_TEST_SEND: |
| 4998 | default: |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4999 | DHD_INFO(("brcmf_sdbrcm_checkdied: unsupported or unknown " |
| 5000 | "command, pktlen %d seq %d" " cmd %d extra %d len %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5001 | pktlen, seq, cmd, extra, len)); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 5002 | brcmu_pkt_buf_free_skb(pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5003 | break; |
| 5004 | } |
| 5005 | |
| 5006 | /* For recv mode, stop at limie (and tell dongle to stop sending) */ |
| 5007 | if (bus->pktgen_mode == DHD_PKTGEN_RECV) { |
| 5008 | if (bus->pktgen_total |
| 5009 | && (bus->pktgen_rcvd >= bus->pktgen_total)) { |
| 5010 | bus->pktgen_count = 0; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5011 | brcmf_sdbrcm_sdtest_set(bus, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5012 | } |
| 5013 | } |
| 5014 | } |
| 5015 | #endif /* SDTEST */ |
| 5016 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5017 | extern bool brcmf_sdbrcm_bus_watchdog(dhd_pub_t *dhdp) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5018 | { |
| 5019 | dhd_bus_t *bus; |
| 5020 | |
| 5021 | DHD_TIMER(("%s: Enter\n", __func__)); |
| 5022 | |
| 5023 | bus = dhdp->bus; |
| 5024 | |
| 5025 | if (bus->dhd->dongle_reset) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5026 | return false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5027 | |
| 5028 | /* Ignore the timer if simulating bus down */ |
| 5029 | if (bus->sleeping) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5030 | return false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5031 | |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 5032 | brcmf_os_sdlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5033 | |
| 5034 | /* Poll period: check device if appropriate. */ |
| 5035 | if (bus->poll && (++bus->polltick >= bus->pollrate)) { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 5036 | u32 intstatus = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5037 | |
| 5038 | /* Reset poll tick */ |
| 5039 | bus->polltick = 0; |
| 5040 | |
| 5041 | /* Check device if no interrupts */ |
| 5042 | if (!bus->intr || (bus->intrcount == bus->lastintrs)) { |
| 5043 | |
| 5044 | if (!bus->dpc_sched) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 5045 | u8 devpend; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5046 | devpend = brcmf_sdcard_cfg_read(bus->sdh, |
| 5047 | SDIO_FUNC_0, SDIO_CCCR_INTx, |
| 5048 | NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5049 | intstatus = |
| 5050 | devpend & (INTR_STATUS_FUNC1 | |
| 5051 | INTR_STATUS_FUNC2); |
| 5052 | } |
| 5053 | |
| 5054 | /* If there is something, make like the ISR and |
| 5055 | schedule the DPC */ |
| 5056 | if (intstatus) { |
| 5057 | bus->pollcnt++; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5058 | bus->ipend = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5059 | if (bus->intr) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5060 | brcmf_sdcard_intr_disable(bus->sdh); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5061 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5062 | bus->dpc_sched = true; |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 5063 | brcmf_sched_dpc(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5064 | |
| 5065 | } |
| 5066 | } |
| 5067 | |
| 5068 | /* Update interrupt tracking */ |
| 5069 | bus->lastintrs = bus->intrcount; |
| 5070 | } |
| 5071 | #ifdef DHD_DEBUG |
| 5072 | /* Poll for console output periodically */ |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 5073 | if (dhdp->busstate == DHD_BUS_DATA && brcmf_console_ms != 0) { |
| 5074 | bus->console.count += brcmf_watchdog_ms; |
| 5075 | if (bus->console.count >= brcmf_console_ms) { |
| 5076 | bus->console.count -= brcmf_console_ms; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5077 | /* Make sure backplane clock is on */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5078 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
| 5079 | if (brcmf_sdbrcm_readconsole(bus) < 0) |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 5080 | brcmf_console_ms = 0; /* On error, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5081 | stop trying */ |
| 5082 | } |
| 5083 | } |
| 5084 | #endif /* DHD_DEBUG */ |
| 5085 | |
| 5086 | #ifdef SDTEST |
| 5087 | /* Generate packets if configured */ |
| 5088 | if (bus->pktgen_count && (++bus->pktgen_tick >= bus->pktgen_freq)) { |
| 5089 | /* Make sure backplane clock is on */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5090 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5091 | bus->pktgen_tick = 0; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5092 | brcmf_sdbrcm_pktgen(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5093 | } |
| 5094 | #endif |
| 5095 | |
| 5096 | /* On idle timeout clear activity flag and/or turn off clock */ |
| 5097 | if ((bus->idletime > 0) && (bus->clkstate == CLK_AVAIL)) { |
| 5098 | if (++bus->idlecount >= bus->idletime) { |
| 5099 | bus->idlecount = 0; |
| 5100 | if (bus->activity) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5101 | bus->activity = false; |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 5102 | brcmf_os_wd_timer(bus->dhd, brcmf_watchdog_ms); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5103 | } else { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5104 | brcmf_sdbrcm_clkctl(bus, CLK_NONE, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5105 | } |
| 5106 | } |
| 5107 | } |
| 5108 | |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 5109 | brcmf_os_sdunlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5110 | |
| 5111 | return bus->ipend; |
| 5112 | } |
| 5113 | |
| 5114 | #ifdef DHD_DEBUG |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5115 | extern int brcmf_sdbrcm_bus_console_in(dhd_pub_t *dhdp, unsigned char *msg, |
| 5116 | uint msglen) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5117 | { |
| 5118 | dhd_bus_t *bus = dhdp->bus; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 5119 | u32 addr, val; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5120 | int rv; |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 5121 | struct sk_buff *pkt; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5122 | |
| 5123 | /* Address could be zero if CONSOLE := 0 in dongle Makefile */ |
| 5124 | if (bus->console_addr == 0) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 5125 | return -ENOTSUPP; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5126 | |
| 5127 | /* Exclusive bus access */ |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 5128 | brcmf_os_sdlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5129 | |
| 5130 | /* Don't allow input if dongle is in reset */ |
| 5131 | if (bus->dhd->dongle_reset) { |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 5132 | brcmf_os_sdunlock(bus->dhd); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 5133 | return -EPERM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5134 | } |
| 5135 | |
| 5136 | /* Request clock to allow SDIO accesses */ |
| 5137 | BUS_WAKE(bus); |
| 5138 | /* No pend allowed since txpkt is called later, ht clk has to be on */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5139 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5140 | |
| 5141 | /* Zero cbuf_index */ |
Roland Vossen | 70963f9 | 2011-06-01 13:45:08 +0200 | [diff] [blame] | 5142 | addr = bus->console_addr + offsetof(rte_cons_t, cbuf_idx); |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 5143 | val = cpu_to_le32(0); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5144 | rv = brcmf_sdbrcm_membytes(bus, true, addr, (u8 *)&val, sizeof(val)); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5145 | if (rv < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5146 | goto done; |
| 5147 | |
| 5148 | /* Write message into cbuf */ |
Roland Vossen | 70963f9 | 2011-06-01 13:45:08 +0200 | [diff] [blame] | 5149 | addr = bus->console_addr + offsetof(rte_cons_t, cbuf); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5150 | rv = brcmf_sdbrcm_membytes(bus, true, addr, (u8 *)msg, msglen); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5151 | if (rv < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5152 | goto done; |
| 5153 | |
| 5154 | /* Write length into vcons_in */ |
Roland Vossen | 70963f9 | 2011-06-01 13:45:08 +0200 | [diff] [blame] | 5155 | addr = bus->console_addr + offsetof(rte_cons_t, vcons_in); |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 5156 | val = cpu_to_le32(msglen); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5157 | rv = brcmf_sdbrcm_membytes(bus, true, addr, (u8 *)&val, sizeof(val)); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5158 | if (rv < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5159 | goto done; |
| 5160 | |
| 5161 | /* Bump dongle by sending an empty event pkt. |
| 5162 | * sdpcm_sendup (RX) checks for virtual console input. |
| 5163 | */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 5164 | pkt = brcmu_pkt_buf_get_skb(4 + SDPCM_RESERVE); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5165 | if ((pkt != NULL) && bus->clkstate == CLK_AVAIL) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5166 | brcmf_sdbrcm_txpkt(bus, pkt, SDPCM_EVENT_CHANNEL, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5167 | |
| 5168 | done: |
| 5169 | if ((bus->idletime == DHD_IDLE_IMMEDIATE) && !bus->dpc_sched) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5170 | bus->activity = false; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5171 | brcmf_sdbrcm_clkctl(bus, CLK_NONE, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5172 | } |
| 5173 | |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 5174 | brcmf_os_sdunlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5175 | |
| 5176 | return rv; |
| 5177 | } |
| 5178 | #endif /* DHD_DEBUG */ |
| 5179 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5180 | static bool brcmf_sdbrcm_chipmatch(u16 chipid) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5181 | { |
| 5182 | if (chipid == BCM4325_CHIP_ID) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5183 | return true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5184 | if (chipid == BCM4329_CHIP_ID) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5185 | return true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5186 | if (chipid == BCM4319_CHIP_ID) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5187 | return true; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5188 | return false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5189 | } |
| 5190 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5191 | static void *brcmf_sdbrcm_probe(u16 venid, u16 devid, u16 bus_no, |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5192 | u16 slot, u16 func, uint bustype, void *regsva, |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 5193 | void *sdh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5194 | { |
| 5195 | int ret; |
| 5196 | dhd_bus_t *bus; |
| 5197 | |
| 5198 | /* Init global variables at run-time, not as part of the declaration. |
| 5199 | * This is required to support init/de-init of the driver. |
| 5200 | * Initialization |
| 5201 | * of globals as part of the declaration results in non-deterministic |
| 5202 | * behavior since the value of the globals may be different on the |
| 5203 | * first time that the driver is initialized vs subsequent |
| 5204 | * initializations. |
| 5205 | */ |
| 5206 | dhd_txbound = DHD_TXBOUND; |
| 5207 | dhd_rxbound = DHD_RXBOUND; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5208 | dhd_alignctl = true; |
| 5209 | sd1idle = true; |
| 5210 | dhd_readahead = true; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5211 | retrydata = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5212 | dhd_dongle_memsize = 0; |
| 5213 | dhd_txminmax = DHD_TXMINMAX; |
| 5214 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5215 | forcealign = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5216 | |
Arend van Spriel | aba5e0a | 2011-06-29 16:47:03 -0700 | [diff] [blame] | 5217 | brcmf_c_init(); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5218 | |
| 5219 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5220 | DHD_INFO(("%s: venid 0x%04x devid 0x%04x\n", __func__, venid, devid)); |
| 5221 | |
| 5222 | /* We make assumptions about address window mappings */ |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 5223 | ASSERT((unsigned long)regsva == SI_ENUM_BASE); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5224 | |
| 5225 | /* BCMSDH passes venid and devid based on CIS parsing -- but |
| 5226 | * low-power start |
| 5227 | * means early parse could fail, so here we should get either an ID |
| 5228 | * we recognize OR (-1) indicating we must request power first. |
| 5229 | */ |
| 5230 | /* Check the Vendor ID */ |
| 5231 | switch (venid) { |
| 5232 | case 0x0000: |
Stanislav Fomichev | be1c09f | 2011-03-28 01:31:36 +0400 | [diff] [blame] | 5233 | case PCI_VENDOR_ID_BROADCOM: |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5234 | break; |
| 5235 | default: |
| 5236 | DHD_ERROR(("%s: unknown vendor: 0x%04x\n", __func__, venid)); |
| 5237 | return NULL; |
| 5238 | } |
| 5239 | |
| 5240 | /* Check the Device ID and make sure it's one that we support */ |
| 5241 | switch (devid) { |
| 5242 | case BCM4325_D11DUAL_ID: /* 4325 802.11a/g id */ |
| 5243 | case BCM4325_D11G_ID: /* 4325 802.11g 2.4Ghz band id */ |
| 5244 | case BCM4325_D11A_ID: /* 4325 802.11a 5Ghz band id */ |
| 5245 | DHD_INFO(("%s: found 4325 Dongle\n", __func__)); |
| 5246 | break; |
| 5247 | case BCM4329_D11NDUAL_ID: /* 4329 802.11n dualband device */ |
| 5248 | case BCM4329_D11N2G_ID: /* 4329 802.11n 2.4G device */ |
| 5249 | case BCM4329_D11N5G_ID: /* 4329 802.11n 5G device */ |
| 5250 | case 0x4329: |
| 5251 | DHD_INFO(("%s: found 4329 Dongle\n", __func__)); |
| 5252 | break; |
| 5253 | case BCM4319_D11N_ID: /* 4319 802.11n id */ |
| 5254 | case BCM4319_D11N2G_ID: /* 4319 802.11n2g id */ |
| 5255 | case BCM4319_D11N5G_ID: /* 4319 802.11n5g id */ |
| 5256 | DHD_INFO(("%s: found 4319 Dongle\n", __func__)); |
| 5257 | break; |
| 5258 | case 0: |
| 5259 | DHD_INFO(("%s: allow device id 0, will check chip internals\n", |
| 5260 | __func__)); |
| 5261 | break; |
| 5262 | |
| 5263 | default: |
| 5264 | DHD_ERROR(("%s: skipping 0x%04x/0x%04x, not a dongle\n", |
| 5265 | __func__, venid, devid)); |
| 5266 | return NULL; |
| 5267 | } |
| 5268 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5269 | /* Allocate private bus interface state */ |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5270 | bus = kzalloc(sizeof(dhd_bus_t), GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5271 | if (!bus) { |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5272 | DHD_ERROR(("%s: kmalloc of dhd_bus_t failed\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5273 | goto fail; |
| 5274 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5275 | bus->sdh = sdh; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5276 | bus->cl_devid = (u16) devid; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5277 | bus->bus = DHD_BUS; |
| 5278 | bus->tx_seq = SDPCM_SEQUENCE_WRAP - 1; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5279 | bus->usebufpool = false; /* Use bufpool if allocated, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5280 | else use locally malloced rxbuf */ |
| 5281 | |
| 5282 | /* attempt to attach to the dongle */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5283 | if (!(brcmf_sdbrcm_probe_attach(bus, sdh, regsva, devid))) { |
| 5284 | DHD_ERROR(("%s: brcmf_sdbrcm_probe_attach failed\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5285 | goto fail; |
| 5286 | } |
| 5287 | |
Franky Lin | 0f1a87c | 2011-06-29 16:46:32 -0700 | [diff] [blame] | 5288 | spin_lock_init(&bus->txqlock); |
| 5289 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5290 | /* Attach to the dhd/OS/network interface */ |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 5291 | bus->dhd = brcmf_attach(bus, SDPCM_RESERVE); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5292 | if (!bus->dhd) { |
| 5293 | DHD_ERROR(("%s: dhd_attach failed\n", __func__)); |
| 5294 | goto fail; |
| 5295 | } |
| 5296 | |
| 5297 | /* Allocate buffers */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5298 | if (!(brcmf_sdbrcm_probe_malloc(bus, sdh))) { |
| 5299 | DHD_ERROR(("%s: brcmf_sdbrcm_probe_malloc failed\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5300 | goto fail; |
| 5301 | } |
| 5302 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5303 | if (!(brcmf_sdbrcm_probe_init(bus, sdh))) { |
| 5304 | DHD_ERROR(("%s: brcmf_sdbrcm_probe_init failed\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5305 | goto fail; |
| 5306 | } |
| 5307 | |
| 5308 | /* Register interrupt callback, but mask it (not operational yet). */ |
| 5309 | DHD_INTR(("%s: disable SDIO interrupts (not interested yet)\n", |
| 5310 | __func__)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5311 | brcmf_sdcard_intr_disable(sdh); |
| 5312 | ret = brcmf_sdcard_intr_reg(sdh, brcmf_sdbrcm_isr, bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5313 | if (ret != 0) { |
| 5314 | DHD_ERROR(("%s: FAILED: bcmsdh_intr_reg returned %d\n", |
| 5315 | __func__, ret)); |
| 5316 | goto fail; |
| 5317 | } |
| 5318 | DHD_INTR(("%s: registered SDIO interrupt function ok\n", __func__)); |
| 5319 | |
| 5320 | DHD_INFO(("%s: completed!!\n", __func__)); |
| 5321 | |
| 5322 | /* if firmware path present try to download and bring up bus */ |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 5323 | ret = brcmf_bus_start(bus->dhd); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5324 | if (ret != 0) { |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 5325 | if (ret == -ENOLINK) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5326 | DHD_ERROR(("%s: dongle is not responding\n", __func__)); |
| 5327 | goto fail; |
| 5328 | } |
| 5329 | } |
| 5330 | /* Ok, have the per-port tell the stack we're open for business */ |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 5331 | if (brcmf_net_attach(bus->dhd, 0) != 0) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5332 | DHD_ERROR(("%s: Net attach failed!!\n", __func__)); |
| 5333 | goto fail; |
| 5334 | } |
| 5335 | |
| 5336 | return bus; |
| 5337 | |
| 5338 | fail: |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5339 | brcmf_sdbrcm_release(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5340 | return NULL; |
| 5341 | } |
| 5342 | |
| 5343 | static bool |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5344 | brcmf_sdbrcm_probe_attach(struct dhd_bus *bus, void *sdh, void *regsva, |
| 5345 | u16 devid) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5346 | { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 5347 | u8 clkctl = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5348 | int err = 0; |
| 5349 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5350 | bus->alp_only = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5351 | |
| 5352 | /* Return the window to backplane enumeration space for core access */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5353 | if (brcmf_sdbrcm_set_siaddr_window(bus, SI_ENUM_BASE)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5354 | DHD_ERROR(("%s: FAILED to return to SI_ENUM_BASE\n", __func__)); |
| 5355 | |
| 5356 | #ifdef DHD_DEBUG |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 5357 | printk(KERN_DEBUG "F1 signature read @0x18000000=0x%4x\n", |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5358 | brcmf_sdcard_reg_read(bus->sdh, SI_ENUM_BASE, 4)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5359 | |
| 5360 | #endif /* DHD_DEBUG */ |
| 5361 | |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 5362 | /* |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5363 | * Force PLL off until brcmf_sdbrcm_chip_attach() |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 5364 | * programs PLL control regs |
| 5365 | */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5366 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5367 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5368 | DHD_INIT_CLKCTL1, &err); |
| 5369 | if (!err) |
| 5370 | clkctl = |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5371 | brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
| 5372 | SBSDIO_FUNC1_CHIPCLKCSR, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5373 | |
| 5374 | if (err || ((clkctl & ~SBSDIO_AVBITS) != DHD_INIT_CLKCTL1)) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5375 | DHD_ERROR(("brcmf_sdbrcm_probe: ChipClkCSR access: err %d wrote" |
| 5376 | " 0x%02x read 0x%02x\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5377 | err, DHD_INIT_CLKCTL1, clkctl)); |
| 5378 | goto fail; |
| 5379 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5380 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5381 | if (brcmf_sdbrcm_chip_attach(bus, regsva)) { |
| 5382 | DHD_ERROR(("%s: brcmf_sdbrcm_chip_attach failed!\n", __func__)); |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 5383 | goto fail; |
| 5384 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5385 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5386 | brcmf_sdcard_chipinfo(sdh, bus->ci->chip, bus->ci->chiprev); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5387 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5388 | if (!brcmf_sdbrcm_chipmatch((u16) bus->ci->chip)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5389 | DHD_ERROR(("%s: unsupported chip: 0x%04x\n", |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 5390 | __func__, bus->ci->chip)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5391 | goto fail; |
| 5392 | } |
| 5393 | |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 5394 | brcmf_sdbrcm_sdiod_drive_strength_init(bus, brcmf_sdiod_drive_strength); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5395 | |
| 5396 | /* Get info on the ARM and SOCRAM cores... */ |
| 5397 | if (!DHD_NOPMU(bus)) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5398 | bus->armrev = SBCOREREV(brcmf_sdcard_reg_read(bus->sdh, |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 5399 | CORE_SB(bus->ci->armcorebase, sbidhigh), 4)); |
| 5400 | bus->orig_ramsize = bus->ci->ramsize; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5401 | if (!(bus->orig_ramsize)) { |
| 5402 | DHD_ERROR(("%s: failed to find SOCRAM memory!\n", |
| 5403 | __func__)); |
| 5404 | goto fail; |
| 5405 | } |
| 5406 | bus->ramsize = bus->orig_ramsize; |
| 5407 | if (dhd_dongle_memsize) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5408 | brcmf_sdbrcm_setmemsize(bus, dhd_dongle_memsize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5409 | |
| 5410 | DHD_ERROR(("DHD: dongle ram size is set to %d(orig %d)\n", |
| 5411 | bus->ramsize, bus->orig_ramsize)); |
| 5412 | } |
| 5413 | |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 5414 | bus->regs = (void *)bus->ci->buscorebase; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5415 | |
| 5416 | /* Set core control so an SDIO reset does a backplane reset */ |
Arend van Spriel | ff31c54 | 2011-03-01 10:56:54 +0100 | [diff] [blame] | 5417 | OR_REG(&bus->regs->corecontrol, CC_BPRESEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5418 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 5419 | brcmu_pktq_init(&bus->txq, (PRIOMASK + 1), TXQLEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5420 | |
| 5421 | /* Locate an appropriately-aligned portion of hdrbuf */ |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 5422 | bus->rxhdr = (u8 *) roundup((unsigned long)&bus->hdrbuf[0], DHD_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5423 | |
| 5424 | /* Set the poll and/or interrupt flags */ |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 5425 | bus->intr = (bool) brcmf_intr; |
| 5426 | bus->poll = (bool) brcmf_poll; |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5427 | if (bus->poll) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5428 | bus->pollrate = 1; |
| 5429 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5430 | return true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5431 | |
| 5432 | fail: |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5433 | return false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5434 | } |
| 5435 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5436 | static bool brcmf_sdbrcm_probe_malloc(dhd_bus_t *bus, void *sdh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5437 | { |
| 5438 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5439 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5440 | if (bus->dhd->maxctl) { |
| 5441 | bus->rxblen = |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 5442 | roundup((bus->dhd->maxctl + SDPCM_HDRLEN), |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5443 | ALIGNMENT) + DHD_SDALIGN; |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5444 | bus->rxbuf = kmalloc(bus->rxblen, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5445 | if (!(bus->rxbuf)) { |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5446 | DHD_ERROR(("%s: kmalloc of %d-byte rxbuf failed\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5447 | __func__, bus->rxblen)); |
| 5448 | goto fail; |
| 5449 | } |
| 5450 | } |
| 5451 | |
| 5452 | /* Allocate buffer to receive glomed packet */ |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5453 | bus->databuf = kmalloc(MAX_DATA_BUF, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5454 | if (!(bus->databuf)) { |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5455 | DHD_ERROR(("%s: kmalloc of %d-byte databuf failed\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5456 | __func__, MAX_DATA_BUF)); |
| 5457 | /* release rxbuf which was already located as above */ |
| 5458 | if (!bus->rxblen) |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 5459 | kfree(bus->rxbuf); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5460 | goto fail; |
| 5461 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5462 | |
| 5463 | /* Align the buffer */ |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 5464 | if ((unsigned long)bus->databuf % DHD_SDALIGN) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5465 | bus->dataptr = |
| 5466 | bus->databuf + (DHD_SDALIGN - |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 5467 | ((unsigned long)bus->databuf % DHD_SDALIGN)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5468 | else |
| 5469 | bus->dataptr = bus->databuf; |
| 5470 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5471 | return true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5472 | |
| 5473 | fail: |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5474 | return false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5475 | } |
| 5476 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5477 | static bool brcmf_sdbrcm_probe_init(dhd_bus_t *bus, void *sdh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5478 | { |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 5479 | s32 fnum; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5480 | |
| 5481 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5482 | |
| 5483 | #ifdef SDTEST |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5484 | brcmf_sdbrcm_pktgen_init(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5485 | #endif /* SDTEST */ |
| 5486 | |
| 5487 | /* Disable F2 to clear any intermediate frame state on the dongle */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5488 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_0, SDIO_CCCR_IOEx, |
| 5489 | SDIO_FUNC_ENABLE_1, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5490 | |
| 5491 | bus->dhd->busstate = DHD_BUS_DOWN; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5492 | bus->sleeping = false; |
| 5493 | bus->rxflow = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5494 | bus->prev_rxlim_hit = 0; |
| 5495 | |
| 5496 | /* Done with backplane-dependent accesses, can drop clock... */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5497 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, 0, |
| 5498 | NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5499 | |
| 5500 | /* ...and initialize clock/power states */ |
| 5501 | bus->clkstate = CLK_SDONLY; |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 5502 | bus->idletime = (s32) brcmf_idletime; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5503 | bus->idleclock = DHD_IDLE_ACTIVE; |
| 5504 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5505 | /* Query the F2 block size, set roundup accordingly */ |
| 5506 | fnum = 2; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5507 | if (brcmf_sdcard_iovar_op(sdh, "sd_blocksize", &fnum, sizeof(s32), |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 5508 | &bus->blocksize, sizeof(s32), false) != 0) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5509 | bus->blocksize = 0; |
| 5510 | DHD_ERROR(("%s: fail on %s get\n", __func__, "sd_blocksize")); |
| 5511 | } else { |
| 5512 | DHD_INFO(("%s: Initial value for %s is %d\n", |
| 5513 | __func__, "sd_blocksize", bus->blocksize)); |
| 5514 | } |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 5515 | bus->roundup = min(max_roundup, bus->blocksize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5516 | |
| 5517 | /* Query if bus module supports packet chaining, |
| 5518 | default to use if supported */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5519 | if (brcmf_sdcard_iovar_op(sdh, "sd_rxchain", NULL, 0, |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 5520 | &bus->sd_rxchain, sizeof(s32), |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 5521 | false) != 0) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5522 | bus->sd_rxchain = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5523 | } else { |
| 5524 | DHD_INFO(("%s: bus module (through bcmsdh API) %s chaining\n", |
| 5525 | __func__, |
| 5526 | (bus->sd_rxchain ? "supports" : "does not support"))); |
| 5527 | } |
| 5528 | bus->use_rxchain = (bool) bus->sd_rxchain; |
| 5529 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5530 | return true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5531 | } |
| 5532 | |
| 5533 | bool |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 5534 | dhd_bus_download_firmware(struct dhd_bus *bus, char *fw_path, char *nv_path) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5535 | { |
| 5536 | bool ret; |
| 5537 | bus->fw_path = fw_path; |
| 5538 | bus->nv_path = nv_path; |
| 5539 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5540 | ret = brcmf_sdbrcm_download_firmware(bus, bus->sdh); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5541 | |
| 5542 | return ret; |
| 5543 | } |
| 5544 | |
| 5545 | static bool |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5546 | brcmf_sdbrcm_download_firmware(struct dhd_bus *bus, void *sdh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5547 | { |
| 5548 | bool ret; |
| 5549 | |
| 5550 | /* Download the firmware */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5551 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5552 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5553 | ret = _brcmf_sdbrcm_download_firmware(bus) == 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5554 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5555 | brcmf_sdbrcm_clkctl(bus, CLK_SDONLY, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5556 | |
| 5557 | return ret; |
| 5558 | } |
| 5559 | |
| 5560 | /* Detach and free everything */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5561 | static void brcmf_sdbrcm_release(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5562 | { |
| 5563 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5564 | |
| 5565 | if (bus) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5566 | /* De-register interrupt handler */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5567 | brcmf_sdcard_intr_disable(bus->sdh); |
| 5568 | brcmf_sdcard_intr_dereg(bus->sdh); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5569 | |
| 5570 | if (bus->dhd) { |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 5571 | brcmf_detach(bus->dhd); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5572 | brcmf_sdbrcm_release_dongle(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5573 | bus->dhd = NULL; |
| 5574 | } |
| 5575 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5576 | brcmf_sdbrcm_release_malloc(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5577 | |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 5578 | kfree(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5579 | } |
| 5580 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5581 | DHD_TRACE(("%s: Disconnected\n", __func__)); |
| 5582 | } |
| 5583 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5584 | static void brcmf_sdbrcm_release_malloc(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5585 | { |
| 5586 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5587 | |
| 5588 | if (bus->dhd && bus->dhd->dongle_reset) |
| 5589 | return; |
| 5590 | |
Henry Ptasinski | 521223a | 2011-06-29 16:46:55 -0700 | [diff] [blame] | 5591 | kfree(bus->rxbuf); |
| 5592 | bus->rxctl = bus->rxbuf = NULL; |
| 5593 | bus->rxlen = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5594 | |
Ilia Mirkin | 46d994b | 2011-03-13 00:28:56 -0500 | [diff] [blame] | 5595 | kfree(bus->databuf); |
| 5596 | bus->databuf = NULL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5597 | } |
| 5598 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5599 | static void brcmf_sdbrcm_release_dongle(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5600 | { |
| 5601 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5602 | |
| 5603 | if (bus->dhd && bus->dhd->dongle_reset) |
| 5604 | return; |
| 5605 | |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 5606 | if (bus->ci) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5607 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
| 5608 | brcmf_sdbrcm_clkctl(bus, CLK_NONE, false); |
| 5609 | brcmf_sdbrcm_chip_detach(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5610 | if (bus->vars && bus->varsz) |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 5611 | kfree(bus->vars); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5612 | bus->vars = NULL; |
| 5613 | } |
| 5614 | |
| 5615 | DHD_TRACE(("%s: Disconnected\n", __func__)); |
| 5616 | } |
| 5617 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5618 | static void brcmf_sdbrcm_disconnect(void *ptr) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5619 | { |
| 5620 | dhd_bus_t *bus = (dhd_bus_t *)ptr; |
| 5621 | |
| 5622 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5623 | |
| 5624 | if (bus) { |
| 5625 | ASSERT(bus->dhd); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5626 | brcmf_sdbrcm_release(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5627 | } |
| 5628 | |
| 5629 | DHD_TRACE(("%s: Disconnected\n", __func__)); |
| 5630 | } |
| 5631 | |
| 5632 | /* Register/Unregister functions are called by the main DHD entry |
| 5633 | * point (e.g. module insertion) to link with the bus driver, in |
| 5634 | * order to look for or await the device. |
| 5635 | */ |
| 5636 | |
| 5637 | static bcmsdh_driver_t dhd_sdio = { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5638 | brcmf_sdbrcm_probe, |
| 5639 | brcmf_sdbrcm_disconnect |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5640 | }; |
| 5641 | |
| 5642 | int dhd_bus_register(void) |
| 5643 | { |
| 5644 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5645 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5646 | return brcmf_sdio_register(&dhd_sdio); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5647 | } |
| 5648 | |
| 5649 | void dhd_bus_unregister(void) |
| 5650 | { |
| 5651 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5652 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5653 | brcmf_sdio_unregister(); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5654 | } |
| 5655 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5656 | static int brcmf_sdbrcm_download_code_file(struct dhd_bus *bus, char *fw_path) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5657 | { |
| 5658 | int bcmerror = -1; |
| 5659 | int offset = 0; |
| 5660 | uint len; |
| 5661 | void *image = NULL; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 5662 | u8 *memblock = NULL, *memptr; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5663 | |
Arend van Spriel | aba5e0a | 2011-06-29 16:47:03 -0700 | [diff] [blame] | 5664 | DHD_INFO(("%s: download firmware %s\n", __func__, brcmf_fw_path)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5665 | |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 5666 | image = brcmf_os_open_image(fw_path); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5667 | if (image == NULL) |
| 5668 | goto err; |
| 5669 | |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5670 | memptr = memblock = kmalloc(MEMBLOCK + DHD_SDALIGN, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5671 | if (memblock == NULL) { |
| 5672 | DHD_ERROR(("%s: Failed to allocate memory %d bytes\n", |
| 5673 | __func__, MEMBLOCK)); |
| 5674 | goto err; |
| 5675 | } |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 5676 | if ((u32)(unsigned long)memblock % DHD_SDALIGN) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5677 | memptr += |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 5678 | (DHD_SDALIGN - ((u32)(unsigned long)memblock % DHD_SDALIGN)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5679 | |
| 5680 | /* Download image */ |
| 5681 | while ((len = |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 5682 | brcmf_os_get_image_block((char *)memptr, MEMBLOCK, image))) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5683 | bcmerror = brcmf_sdbrcm_membytes(bus, true, offset, memptr, |
| 5684 | len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5685 | if (bcmerror) { |
| 5686 | DHD_ERROR(("%s: error %d on writing %d membytes at " |
| 5687 | "0x%08x\n", __func__, bcmerror, MEMBLOCK, offset)); |
| 5688 | goto err; |
| 5689 | } |
| 5690 | |
| 5691 | offset += MEMBLOCK; |
| 5692 | } |
| 5693 | |
| 5694 | err: |
Ilia Mirkin | 46d994b | 2011-03-13 00:28:56 -0500 | [diff] [blame] | 5695 | kfree(memblock); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5696 | |
| 5697 | if (image) |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 5698 | brcmf_os_close_image(image); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5699 | |
| 5700 | return bcmerror; |
| 5701 | } |
| 5702 | |
| 5703 | /* |
| 5704 | * ProcessVars:Takes a buffer of "<var>=<value>\n" lines read from a file |
| 5705 | * and ending in a NUL. |
| 5706 | * Removes carriage returns, empty lines, comment lines, and converts |
| 5707 | * newlines to NULs. |
| 5708 | * Shortens buffer as needed and pads with NULs. End of buffer is marked |
| 5709 | * by two NULs. |
| 5710 | */ |
| 5711 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5712 | static uint brcmf_process_nvram_vars(char *varbuf, uint len) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5713 | { |
| 5714 | char *dp; |
| 5715 | bool findNewline; |
| 5716 | int column; |
| 5717 | uint buf_len, n; |
| 5718 | |
| 5719 | dp = varbuf; |
| 5720 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5721 | findNewline = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5722 | column = 0; |
| 5723 | |
| 5724 | for (n = 0; n < len; n++) { |
| 5725 | if (varbuf[n] == 0) |
| 5726 | break; |
| 5727 | if (varbuf[n] == '\r') |
| 5728 | continue; |
| 5729 | if (findNewline && varbuf[n] != '\n') |
| 5730 | continue; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5731 | findNewline = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5732 | if (varbuf[n] == '#') { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5733 | findNewline = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5734 | continue; |
| 5735 | } |
| 5736 | if (varbuf[n] == '\n') { |
| 5737 | if (column == 0) |
| 5738 | continue; |
| 5739 | *dp++ = 0; |
| 5740 | column = 0; |
| 5741 | continue; |
| 5742 | } |
| 5743 | *dp++ = varbuf[n]; |
| 5744 | column++; |
| 5745 | } |
| 5746 | buf_len = dp - varbuf; |
| 5747 | |
| 5748 | while (dp < varbuf + n) |
| 5749 | *dp++ = 0; |
| 5750 | |
| 5751 | return buf_len; |
| 5752 | } |
| 5753 | |
| 5754 | /* |
| 5755 | EXAMPLE: nvram_array |
| 5756 | nvram_arry format: |
| 5757 | name=value |
| 5758 | Use carriage return at the end of each assignment, |
| 5759 | and an empty string with |
| 5760 | carriage return at the end of array. |
| 5761 | |
| 5762 | For example: |
| 5763 | unsigned char nvram_array[] = {"name1=value1\n", |
| 5764 | "name2=value2\n", "\n"}; |
| 5765 | Hex values start with 0x, and mac addr format: xx:xx:xx:xx:xx:xx. |
| 5766 | |
| 5767 | Search "EXAMPLE: nvram_array" to see how the array is activated. |
| 5768 | */ |
| 5769 | |
| 5770 | void dhd_bus_set_nvram_params(struct dhd_bus *bus, const char *nvram_params) |
| 5771 | { |
| 5772 | bus->nvram_params = nvram_params; |
| 5773 | } |
| 5774 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5775 | static int brcmf_sdbrcm_download_nvram(struct dhd_bus *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5776 | { |
| 5777 | int bcmerror = -1; |
| 5778 | uint len; |
| 5779 | void *image = NULL; |
| 5780 | char *memblock = NULL; |
| 5781 | char *bufp; |
| 5782 | char *nv_path; |
| 5783 | bool nvram_file_exists; |
| 5784 | |
| 5785 | nv_path = bus->nv_path; |
| 5786 | |
| 5787 | nvram_file_exists = ((nv_path != NULL) && (nv_path[0] != '\0')); |
| 5788 | if (!nvram_file_exists && (bus->nvram_params == NULL)) |
| 5789 | return 0; |
| 5790 | |
| 5791 | if (nvram_file_exists) { |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 5792 | image = brcmf_os_open_image(nv_path); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5793 | if (image == NULL) |
| 5794 | goto err; |
| 5795 | } |
| 5796 | |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5797 | memblock = kmalloc(MEMBLOCK, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5798 | if (memblock == NULL) { |
| 5799 | DHD_ERROR(("%s: Failed to allocate memory %d bytes\n", |
| 5800 | __func__, MEMBLOCK)); |
| 5801 | goto err; |
| 5802 | } |
| 5803 | |
| 5804 | /* Download variables */ |
| 5805 | if (nvram_file_exists) { |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 5806 | len = brcmf_os_get_image_block(memblock, MEMBLOCK, image); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5807 | } else { |
| 5808 | len = strlen(bus->nvram_params); |
| 5809 | ASSERT(len <= MEMBLOCK); |
| 5810 | if (len > MEMBLOCK) |
| 5811 | len = MEMBLOCK; |
| 5812 | memcpy(memblock, bus->nvram_params, len); |
| 5813 | } |
| 5814 | |
| 5815 | if (len > 0 && len < MEMBLOCK) { |
| 5816 | bufp = (char *)memblock; |
| 5817 | bufp[len] = 0; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5818 | len = brcmf_process_nvram_vars(bufp, len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5819 | bufp += len; |
| 5820 | *bufp++ = 0; |
| 5821 | if (len) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5822 | bcmerror = brcmf_sdbrcm_downloadvars(bus, memblock, |
| 5823 | len + 1); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5824 | if (bcmerror) { |
| 5825 | DHD_ERROR(("%s: error downloading vars: %d\n", |
| 5826 | __func__, bcmerror)); |
| 5827 | } |
| 5828 | } else { |
| 5829 | DHD_ERROR(("%s: error reading nvram file: %d\n", |
| 5830 | __func__, len)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 5831 | bcmerror = -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5832 | } |
| 5833 | |
| 5834 | err: |
Ilia Mirkin | 46d994b | 2011-03-13 00:28:56 -0500 | [diff] [blame] | 5835 | kfree(memblock); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5836 | |
| 5837 | if (image) |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 5838 | brcmf_os_close_image(image); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5839 | |
| 5840 | return bcmerror; |
| 5841 | } |
| 5842 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5843 | static int _brcmf_sdbrcm_download_firmware(struct dhd_bus *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5844 | { |
| 5845 | int bcmerror = -1; |
| 5846 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5847 | bool embed = false; /* download embedded firmware */ |
| 5848 | bool dlok = false; /* download firmware succeeded */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5849 | |
| 5850 | /* Out immediately if no image to download */ |
Franky Lin | a4181fb | 2011-06-01 13:45:34 +0200 | [diff] [blame] | 5851 | if ((bus->fw_path == NULL) || (bus->fw_path[0] == '\0')) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5852 | return bcmerror; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5853 | |
| 5854 | /* Keep arm in reset */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5855 | if (brcmf_sdbrcm_download_state(bus, true)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5856 | DHD_ERROR(("%s: error placing ARM core in reset\n", __func__)); |
| 5857 | goto err; |
| 5858 | } |
| 5859 | |
| 5860 | /* External image takes precedence if specified */ |
| 5861 | if ((bus->fw_path != NULL) && (bus->fw_path[0] != '\0')) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5862 | if (brcmf_sdbrcm_download_code_file(bus, bus->fw_path)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5863 | DHD_ERROR(("%s: dongle image file download failed\n", |
| 5864 | __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5865 | goto err; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5866 | } else { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5867 | embed = false; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5868 | dlok = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5869 | } |
| 5870 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5871 | if (!dlok) { |
| 5872 | DHD_ERROR(("%s: dongle image download failed\n", __func__)); |
| 5873 | goto err; |
| 5874 | } |
| 5875 | |
| 5876 | /* EXAMPLE: nvram_array */ |
| 5877 | /* If a valid nvram_arry is specified as above, it can be passed |
| 5878 | down to dongle */ |
| 5879 | /* dhd_bus_set_nvram_params(bus, (char *)&nvram_array); */ |
| 5880 | |
| 5881 | /* External nvram takes precedence if specified */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5882 | if (brcmf_sdbrcm_download_nvram(bus)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5883 | DHD_ERROR(("%s: dongle nvram file download failed\n", |
| 5884 | __func__)); |
| 5885 | } |
| 5886 | |
| 5887 | /* Take arm out of reset */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5888 | if (brcmf_sdbrcm_download_state(bus, false)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5889 | DHD_ERROR(("%s: error getting out of ARM core reset\n", |
| 5890 | __func__)); |
| 5891 | goto err; |
| 5892 | } |
| 5893 | |
| 5894 | bcmerror = 0; |
| 5895 | |
| 5896 | err: |
| 5897 | return bcmerror; |
| 5898 | } |
| 5899 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5900 | |
| 5901 | static int |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5902 | brcmf_sdbrcm_send_buf(dhd_bus_t *bus, u32 addr, uint fn, uint flags, |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 5903 | u8 *buf, uint nbytes, struct sk_buff *pkt, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5904 | bcmsdh_cmplt_fn_t complete, void *handle) |
| 5905 | { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5906 | return brcmf_sdcard_send_buf |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5907 | (bus->sdh, addr, fn, flags, buf, nbytes, pkt, complete, |
| 5908 | handle); |
| 5909 | } |
| 5910 | |
| 5911 | uint dhd_bus_chip(struct dhd_bus *bus) |
| 5912 | { |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 5913 | ASSERT(bus->ci != NULL); |
| 5914 | return bus->ci->chip; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5915 | } |
| 5916 | |
| 5917 | void *dhd_bus_pub(struct dhd_bus *bus) |
| 5918 | { |
| 5919 | return bus->dhd; |
| 5920 | } |
| 5921 | |
| 5922 | void *dhd_bus_txq(struct dhd_bus *bus) |
| 5923 | { |
| 5924 | return &bus->txq; |
| 5925 | } |
| 5926 | |
| 5927 | uint dhd_bus_hdrlen(struct dhd_bus *bus) |
| 5928 | { |
| 5929 | return SDPCM_HDRLEN; |
| 5930 | } |
| 5931 | |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame^] | 5932 | int brcmf_bus_devreset(dhd_pub_t *dhdp, u8 flag) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5933 | { |
| 5934 | int bcmerror = 0; |
| 5935 | dhd_bus_t *bus; |
| 5936 | |
| 5937 | bus = dhdp->bus; |
| 5938 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5939 | if (flag == true) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5940 | if (!bus->dhd->dongle_reset) { |
| 5941 | /* Expect app to have torn down any |
| 5942 | connection before calling */ |
| 5943 | /* Stop the bus, disable F2 */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5944 | brcmf_sdbrcm_bus_stop(bus, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5945 | |
| 5946 | /* Clean tx/rx buffer pointers, |
| 5947 | detach from the dongle */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5948 | brcmf_sdbrcm_release_dongle(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5949 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5950 | bus->dhd->dongle_reset = true; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5951 | bus->dhd->up = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5952 | |
| 5953 | DHD_TRACE(("%s: WLAN OFF DONE\n", __func__)); |
| 5954 | /* App can now remove power from device */ |
| 5955 | } else |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 5956 | bcmerror = -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5957 | } else { |
| 5958 | /* App must have restored power to device before calling */ |
| 5959 | |
| 5960 | DHD_TRACE(("\n\n%s: == WLAN ON ==\n", __func__)); |
| 5961 | |
| 5962 | if (bus->dhd->dongle_reset) { |
| 5963 | /* Turn on WLAN */ |
| 5964 | /* Reset SD client */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5965 | brcmf_sdcard_reset(bus->sdh); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5966 | |
| 5967 | /* Attempt to re-attach & download */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5968 | if (brcmf_sdbrcm_probe_attach(bus, bus->sdh, |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 5969 | (u32 *) SI_ENUM_BASE, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5970 | bus->cl_devid)) { |
| 5971 | /* Attempt to download binary to the dongle */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5972 | if (brcmf_sdbrcm_probe_init |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 5973 | (bus, bus->sdh) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5974 | && brcmf_sdbrcm_download_firmware(bus, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5975 | bus->sdh)) { |
| 5976 | |
| 5977 | /* Re-init bus, enable F2 transfer */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5978 | brcmf_sdbrcm_bus_init( |
| 5979 | (dhd_pub_t *) bus->dhd, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5980 | |
| 5981 | #if defined(OOB_INTR_ONLY) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5982 | brcmf_sdbrcm_enable_oob_intr(bus, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5983 | #endif /* defined(OOB_INTR_ONLY) */ |
| 5984 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5985 | bus->dhd->dongle_reset = false; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5986 | bus->dhd->up = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5987 | |
| 5988 | DHD_TRACE(("%s: WLAN ON DONE\n", |
| 5989 | __func__)); |
| 5990 | } else |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 5991 | bcmerror = -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5992 | } else |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 5993 | bcmerror = -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5994 | } else { |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 5995 | bcmerror = -EISCONN; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5996 | DHD_ERROR(("%s: Set DEVRESET=false invoked when device " |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5997 | "is on\n", __func__)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 5998 | bcmerror = -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5999 | } |
| 6000 | } |
| 6001 | return bcmerror; |
| 6002 | } |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6003 | |
| 6004 | static int |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6005 | brcmf_sdbrcm_chip_recognition(bcmsdh_info_t *sdh, struct chip_info *ci, |
| 6006 | void *regs) |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6007 | { |
| 6008 | u32 regdata; |
| 6009 | |
| 6010 | /* |
| 6011 | * Get CC core rev |
| 6012 | * Chipid is assume to be at offset 0 from regs arg |
| 6013 | * For different chiptypes or old sdio hosts w/o chipcommon, |
| 6014 | * other ways of recognition should be added here. |
| 6015 | */ |
| 6016 | ci->cccorebase = (u32)regs; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6017 | regdata = brcmf_sdcard_reg_read(sdh, |
| 6018 | CORE_CC_REG(ci->cccorebase, chipid), 4); |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6019 | ci->chip = regdata & CID_ID_MASK; |
| 6020 | ci->chiprev = (regdata & CID_REV_MASK) >> CID_REV_SHIFT; |
| 6021 | |
| 6022 | DHD_INFO(("%s: chipid=0x%x chiprev=%d\n", |
| 6023 | __func__, ci->chip, ci->chiprev)); |
| 6024 | |
| 6025 | /* Address of cores for new chips should be added here */ |
| 6026 | switch (ci->chip) { |
| 6027 | case BCM4329_CHIP_ID: |
| 6028 | ci->buscorebase = BCM4329_CORE_BUS_BASE; |
| 6029 | ci->ramcorebase = BCM4329_CORE_SOCRAM_BASE; |
| 6030 | ci->armcorebase = BCM4329_CORE_ARM_BASE; |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 6031 | ci->ramsize = BCM4329_RAMSIZE; |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6032 | break; |
| 6033 | default: |
| 6034 | DHD_ERROR(("%s: chipid 0x%x is not supported\n", |
| 6035 | __func__, ci->chip)); |
| 6036 | return -ENODEV; |
| 6037 | } |
| 6038 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6039 | regdata = brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6040 | CORE_SB(ci->cccorebase, sbidhigh), 4); |
| 6041 | ci->ccrev = SBCOREREV(regdata); |
| 6042 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6043 | regdata = brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6044 | CORE_CC_REG(ci->cccorebase, pmucapabilities), 4); |
| 6045 | ci->pmurev = regdata & PCAP_REV_MASK; |
| 6046 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6047 | regdata = brcmf_sdcard_reg_read(sdh, |
| 6048 | CORE_SB(ci->buscorebase, sbidhigh), 4); |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6049 | ci->buscorerev = SBCOREREV(regdata); |
| 6050 | ci->buscoretype = (regdata & SBIDH_CC_MASK) >> SBIDH_CC_SHIFT; |
| 6051 | |
| 6052 | DHD_INFO(("%s: ccrev=%d, pmurev=%d, buscore rev/type=%d/0x%x\n", |
| 6053 | __func__, ci->ccrev, ci->pmurev, |
| 6054 | ci->buscorerev, ci->buscoretype)); |
| 6055 | |
| 6056 | /* get chipcommon capabilites */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6057 | ci->cccaps = brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6058 | CORE_CC_REG(ci->cccorebase, capabilities), 4); |
| 6059 | |
| 6060 | return 0; |
| 6061 | } |
| 6062 | |
| 6063 | static void |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6064 | brcmf_sdbrcm_chip_disablecore(bcmsdh_info_t *sdh, u32 corebase) |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6065 | { |
| 6066 | u32 regdata; |
| 6067 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6068 | regdata = brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6069 | CORE_SB(corebase, sbtmstatelow), 4); |
| 6070 | if (regdata & SBTML_RESET) |
| 6071 | return; |
| 6072 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6073 | regdata = brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6074 | CORE_SB(corebase, sbtmstatelow), 4); |
| 6075 | if ((regdata & (SICF_CLOCK_EN << SBTML_SICF_SHIFT)) != 0) { |
| 6076 | /* |
| 6077 | * set target reject and spin until busy is clear |
| 6078 | * (preserve core-specific bits) |
| 6079 | */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6080 | regdata = brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6081 | CORE_SB(corebase, sbtmstatelow), 4); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6082 | brcmf_sdcard_reg_write(sdh, CORE_SB(corebase, sbtmstatelow), 4, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6083 | regdata | SBTML_REJ); |
| 6084 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6085 | regdata = brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6086 | CORE_SB(corebase, sbtmstatelow), 4); |
| 6087 | udelay(1); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6088 | SPINWAIT((brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6089 | CORE_SB(corebase, sbtmstatehigh), 4) & |
| 6090 | SBTMH_BUSY), 100000); |
| 6091 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6092 | regdata = brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6093 | CORE_SB(corebase, sbtmstatehigh), 4); |
| 6094 | if (regdata & SBTMH_BUSY) |
| 6095 | DHD_ERROR(("%s: ARM core still busy\n", __func__)); |
| 6096 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6097 | regdata = brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6098 | CORE_SB(corebase, sbidlow), 4); |
| 6099 | if (regdata & SBIDL_INIT) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6100 | regdata = brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6101 | CORE_SB(corebase, sbimstate), 4) | |
| 6102 | SBIM_RJ; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6103 | brcmf_sdcard_reg_write(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6104 | CORE_SB(corebase, sbimstate), 4, |
| 6105 | regdata); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6106 | regdata = brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6107 | CORE_SB(corebase, sbimstate), 4); |
| 6108 | udelay(1); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6109 | SPINWAIT((brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6110 | CORE_SB(corebase, sbimstate), 4) & |
| 6111 | SBIM_BY), 100000); |
| 6112 | } |
| 6113 | |
| 6114 | /* set reset and reject while enabling the clocks */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6115 | brcmf_sdcard_reg_write(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6116 | CORE_SB(corebase, sbtmstatelow), 4, |
| 6117 | (((SICF_FGC | SICF_CLOCK_EN) << SBTML_SICF_SHIFT) | |
| 6118 | SBTML_REJ | SBTML_RESET)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6119 | regdata = brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6120 | CORE_SB(corebase, sbtmstatelow), 4); |
| 6121 | udelay(10); |
| 6122 | |
| 6123 | /* clear the initiator reject bit */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6124 | regdata = brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6125 | CORE_SB(corebase, sbidlow), 4); |
| 6126 | if (regdata & SBIDL_INIT) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6127 | regdata = brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6128 | CORE_SB(corebase, sbimstate), 4) & |
| 6129 | ~SBIM_RJ; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6130 | brcmf_sdcard_reg_write(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6131 | CORE_SB(corebase, sbimstate), 4, |
| 6132 | regdata); |
| 6133 | } |
| 6134 | } |
| 6135 | |
| 6136 | /* leave reset and reject asserted */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6137 | brcmf_sdcard_reg_write(sdh, CORE_SB(corebase, sbtmstatelow), 4, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6138 | (SBTML_REJ | SBTML_RESET)); |
| 6139 | udelay(1); |
| 6140 | } |
| 6141 | |
| 6142 | static int |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6143 | brcmf_sdbrcm_chip_attach(struct dhd_bus *bus, void *regs) |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6144 | { |
| 6145 | struct chip_info *ci; |
| 6146 | int err; |
| 6147 | u8 clkval, clkset; |
| 6148 | |
| 6149 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 6150 | |
| 6151 | /* alloc chip_info_t */ |
| 6152 | ci = kmalloc(sizeof(struct chip_info), GFP_ATOMIC); |
| 6153 | if (NULL == ci) { |
| 6154 | DHD_ERROR(("%s: malloc failed!\n", __func__)); |
| 6155 | return -ENOMEM; |
| 6156 | } |
| 6157 | |
| 6158 | memset((unsigned char *)ci, 0, sizeof(struct chip_info)); |
| 6159 | |
| 6160 | /* bus/core/clk setup for register access */ |
| 6161 | /* Try forcing SDIO core to do ALPAvail request only */ |
| 6162 | clkset = SBSDIO_FORCE_HW_CLKREQ_OFF | SBSDIO_ALP_AVAIL_REQ; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6163 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6164 | clkset, &err); |
| 6165 | if (err) { |
| 6166 | DHD_ERROR(("%s: error writing for HT off\n", __func__)); |
| 6167 | goto fail; |
| 6168 | } |
| 6169 | |
| 6170 | /* If register supported, wait for ALPAvail and then force ALP */ |
| 6171 | /* This may take up to 15 milliseconds */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6172 | clkval = brcmf_sdcard_cfg_read(bus->sdh, SDIO_FUNC_1, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6173 | SBSDIO_FUNC1_CHIPCLKCSR, NULL); |
| 6174 | if ((clkval & ~SBSDIO_AVBITS) == clkset) { |
| 6175 | SPINWAIT(((clkval = |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6176 | brcmf_sdcard_cfg_read(bus->sdh, SDIO_FUNC_1, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6177 | SBSDIO_FUNC1_CHIPCLKCSR, |
| 6178 | NULL)), |
| 6179 | !SBSDIO_ALPAV(clkval)), |
| 6180 | PMU_MAX_TRANSITION_DLY); |
| 6181 | if (!SBSDIO_ALPAV(clkval)) { |
| 6182 | DHD_ERROR(("%s: timeout on ALPAV wait, clkval 0x%02x\n", |
| 6183 | __func__, clkval)); |
| 6184 | err = -EBUSY; |
| 6185 | goto fail; |
| 6186 | } |
| 6187 | clkset = SBSDIO_FORCE_HW_CLKREQ_OFF | |
| 6188 | SBSDIO_FORCE_ALP; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6189 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_1, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6190 | SBSDIO_FUNC1_CHIPCLKCSR, |
| 6191 | clkset, &err); |
| 6192 | udelay(65); |
| 6193 | } else { |
| 6194 | DHD_ERROR(("%s: ChipClkCSR access: wrote 0x%02x read 0x%02x\n", |
| 6195 | __func__, clkset, clkval)); |
| 6196 | err = -EACCES; |
| 6197 | goto fail; |
| 6198 | } |
| 6199 | |
| 6200 | /* Also, disable the extra SDIO pull-ups */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6201 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_SDIOPULLUP, |
| 6202 | 0, NULL); |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6203 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6204 | err = brcmf_sdbrcm_chip_recognition(bus->sdh, ci, regs); |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6205 | if (err) |
| 6206 | goto fail; |
| 6207 | |
| 6208 | /* |
| 6209 | * Make sure any on-chip ARM is off (in case strapping is wrong), |
| 6210 | * or downloaded code was already running. |
| 6211 | */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6212 | brcmf_sdbrcm_chip_disablecore(bus->sdh, ci->armcorebase); |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6213 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6214 | brcmf_sdcard_reg_write(bus->sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6215 | CORE_CC_REG(ci->cccorebase, gpiopullup), 4, 0); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6216 | brcmf_sdcard_reg_write(bus->sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6217 | CORE_CC_REG(ci->cccorebase, gpiopulldown), 4, 0); |
| 6218 | |
| 6219 | /* Disable F2 to clear any intermediate frame state on the dongle */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6220 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_0, SDIO_CCCR_IOEx, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6221 | SDIO_FUNC_ENABLE_1, NULL); |
| 6222 | |
| 6223 | /* WAR: cmd52 backplane read so core HW will drop ALPReq */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6224 | clkval = brcmf_sdcard_cfg_read(bus->sdh, SDIO_FUNC_1, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6225 | 0, NULL); |
| 6226 | |
| 6227 | /* Done with backplane-dependent accesses, can drop clock... */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6228 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 6229 | 0, NULL); |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6230 | |
| 6231 | bus->ci = ci; |
| 6232 | return 0; |
| 6233 | fail: |
| 6234 | bus->ci = NULL; |
| 6235 | kfree(ci); |
| 6236 | return err; |
| 6237 | } |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6238 | |
| 6239 | static void |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6240 | brcmf_sdbrcm_chip_resetcore(bcmsdh_info_t *sdh, u32 corebase) |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6241 | { |
| 6242 | u32 regdata; |
| 6243 | |
| 6244 | /* |
| 6245 | * Must do the disable sequence first to work for |
| 6246 | * arbitrary current core state. |
| 6247 | */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6248 | brcmf_sdbrcm_chip_disablecore(sdh, corebase); |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6249 | |
| 6250 | /* |
| 6251 | * Now do the initialization sequence. |
| 6252 | * set reset while enabling the clock and |
| 6253 | * forcing them on throughout the core |
| 6254 | */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6255 | brcmf_sdcard_reg_write(sdh, CORE_SB(corebase, sbtmstatelow), 4, |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6256 | ((SICF_FGC | SICF_CLOCK_EN) << SBTML_SICF_SHIFT) | |
| 6257 | SBTML_RESET); |
| 6258 | udelay(1); |
| 6259 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6260 | regdata = brcmf_sdcard_reg_read(sdh, CORE_SB(corebase, sbtmstatehigh), |
| 6261 | 4); |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6262 | if (regdata & SBTMH_SERR) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6263 | brcmf_sdcard_reg_write(sdh, CORE_SB(corebase, sbtmstatehigh), |
| 6264 | 4, 0); |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6265 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6266 | regdata = brcmf_sdcard_reg_read(sdh, CORE_SB(corebase, sbimstate), 4); |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6267 | if (regdata & (SBIM_IBE | SBIM_TO)) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6268 | brcmf_sdcard_reg_write(sdh, CORE_SB(corebase, sbimstate), 4, |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6269 | regdata & ~(SBIM_IBE | SBIM_TO)); |
| 6270 | |
| 6271 | /* clear reset and allow it to propagate throughout the core */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6272 | brcmf_sdcard_reg_write(sdh, CORE_SB(corebase, sbtmstatelow), 4, |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6273 | (SICF_FGC << SBTML_SICF_SHIFT) | |
| 6274 | (SICF_CLOCK_EN << SBTML_SICF_SHIFT)); |
| 6275 | udelay(1); |
| 6276 | |
| 6277 | /* leave clock enabled */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6278 | brcmf_sdcard_reg_write(sdh, CORE_SB(corebase, sbtmstatelow), 4, |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6279 | (SICF_CLOCK_EN << SBTML_SICF_SHIFT)); |
| 6280 | udelay(1); |
| 6281 | } |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 6282 | |
| 6283 | /* SDIO Pad drive strength to select value mappings */ |
| 6284 | struct sdiod_drive_str { |
| 6285 | u8 strength; /* Pad Drive Strength in mA */ |
| 6286 | u8 sel; /* Chip-specific select value */ |
| 6287 | }; |
| 6288 | |
| 6289 | /* SDIO Drive Strength to sel value table for PMU Rev 1 */ |
| 6290 | static const struct sdiod_drive_str sdiod_drive_strength_tab1[] = { |
| 6291 | { |
| 6292 | 4, 0x2}, { |
| 6293 | 2, 0x3}, { |
| 6294 | 1, 0x0}, { |
| 6295 | 0, 0x0} |
| 6296 | }; |
| 6297 | |
| 6298 | /* SDIO Drive Strength to sel value table for PMU Rev 2, 3 */ |
| 6299 | static const struct sdiod_drive_str sdiod_drive_strength_tab2[] = { |
| 6300 | { |
| 6301 | 12, 0x7}, { |
| 6302 | 10, 0x6}, { |
| 6303 | 8, 0x5}, { |
| 6304 | 6, 0x4}, { |
| 6305 | 4, 0x2}, { |
| 6306 | 2, 0x1}, { |
| 6307 | 0, 0x0} |
| 6308 | }; |
| 6309 | |
| 6310 | /* SDIO Drive Strength to sel value table for PMU Rev 8 (1.8V) */ |
| 6311 | static const struct sdiod_drive_str sdiod_drive_strength_tab3[] = { |
| 6312 | { |
| 6313 | 32, 0x7}, { |
| 6314 | 26, 0x6}, { |
| 6315 | 22, 0x5}, { |
| 6316 | 16, 0x4}, { |
| 6317 | 12, 0x3}, { |
| 6318 | 8, 0x2}, { |
| 6319 | 4, 0x1}, { |
| 6320 | 0, 0x0} |
| 6321 | }; |
| 6322 | |
| 6323 | #define SDIOD_DRVSTR_KEY(chip, pmu) (((chip) << 16) | (pmu)) |
| 6324 | |
| 6325 | static void |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6326 | brcmf_sdbrcm_sdiod_drive_strength_init(struct dhd_bus *bus, u32 drivestrength) { |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 6327 | struct sdiod_drive_str *str_tab = NULL; |
| 6328 | u32 str_mask = 0; |
| 6329 | u32 str_shift = 0; |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 6330 | char chn[8]; |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 6331 | |
| 6332 | if (!(bus->ci->cccaps & CC_CAP_PMU)) |
| 6333 | return; |
| 6334 | |
| 6335 | switch (SDIOD_DRVSTR_KEY(bus->ci->chip, bus->ci->pmurev)) { |
| 6336 | case SDIOD_DRVSTR_KEY(BCM4325_CHIP_ID, 1): |
| 6337 | str_tab = (struct sdiod_drive_str *)&sdiod_drive_strength_tab1; |
| 6338 | str_mask = 0x30000000; |
| 6339 | str_shift = 28; |
| 6340 | break; |
| 6341 | case SDIOD_DRVSTR_KEY(BCM4325_CHIP_ID, 2): |
| 6342 | case SDIOD_DRVSTR_KEY(BCM4325_CHIP_ID, 3): |
| 6343 | str_tab = (struct sdiod_drive_str *)&sdiod_drive_strength_tab2; |
| 6344 | str_mask = 0x00003800; |
| 6345 | str_shift = 11; |
| 6346 | break; |
| 6347 | case SDIOD_DRVSTR_KEY(BCM4336_CHIP_ID, 8): |
| 6348 | str_tab = (struct sdiod_drive_str *)&sdiod_drive_strength_tab3; |
| 6349 | str_mask = 0x00003800; |
| 6350 | str_shift = 11; |
| 6351 | break; |
| 6352 | default: |
| 6353 | DHD_ERROR(("No SDIO Drive strength init" |
| 6354 | "done for chip %s rev %d pmurev %d\n", |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 6355 | brcmu_chipname(bus->ci->chip, chn, 8), |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 6356 | bus->ci->chiprev, bus->ci->pmurev)); |
| 6357 | break; |
| 6358 | } |
| 6359 | |
| 6360 | if (str_tab != NULL) { |
| 6361 | u32 drivestrength_sel = 0; |
| 6362 | u32 cc_data_temp; |
| 6363 | int i; |
| 6364 | |
| 6365 | for (i = 0; str_tab[i].strength != 0; i++) { |
| 6366 | if (drivestrength >= str_tab[i].strength) { |
| 6367 | drivestrength_sel = str_tab[i].sel; |
| 6368 | break; |
| 6369 | } |
| 6370 | } |
| 6371 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6372 | brcmf_sdcard_reg_write(bus->sdh, |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 6373 | CORE_CC_REG(bus->ci->cccorebase, chipcontrol_addr), |
| 6374 | 4, 1); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6375 | cc_data_temp = brcmf_sdcard_reg_read(bus->sdh, |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 6376 | CORE_CC_REG(bus->ci->cccorebase, chipcontrol_addr), 4); |
| 6377 | cc_data_temp &= ~str_mask; |
| 6378 | drivestrength_sel <<= str_shift; |
| 6379 | cc_data_temp |= drivestrength_sel; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6380 | brcmf_sdcard_reg_write(bus->sdh, |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 6381 | CORE_CC_REG(bus->ci->cccorebase, chipcontrol_addr), |
| 6382 | 4, cc_data_temp); |
| 6383 | |
| 6384 | DHD_INFO(("SDIO: %dmA drive strength selected, set to 0x%08x\n", |
| 6385 | drivestrength, cc_data_temp)); |
| 6386 | } |
| 6387 | } |
Franky Lin | cee3cf4 | 2011-04-25 19:34:06 -0700 | [diff] [blame] | 6388 | |
| 6389 | static void |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6390 | brcmf_sdbrcm_chip_detach(struct dhd_bus *bus) |
Franky Lin | cee3cf4 | 2011-04-25 19:34:06 -0700 | [diff] [blame] | 6391 | { |
| 6392 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 6393 | |
| 6394 | kfree(bus->ci); |
| 6395 | bus->ci = NULL; |
| 6396 | } |