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> |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 19 | #include <linux/kthread.h> |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 20 | #include <linux/printk.h> |
Stanislav Fomichev | be1c09f | 2011-03-28 01:31:36 +0400 | [diff] [blame] | 21 | #include <linux/pci_ids.h> |
Brett Rudley | c6ac24e | 2010-10-26 11:55:23 -0700 | [diff] [blame] | 22 | #include <linux/netdevice.h> |
Franky Lin | 7c6100e | 2011-06-01 13:45:36 +0200 | [diff] [blame] | 23 | #include <linux/sched.h> |
Franky Lin | 0df4604 | 2011-06-01 13:45:40 +0200 | [diff] [blame] | 24 | #include <linux/mmc/sdio.h> |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 25 | #include <linux/mmc/sdio_func.h> |
Arend van Spriel | fb1d0aa | 2011-06-29 16:47:55 -0700 | [diff] [blame] | 26 | #include <linux/semaphore.h> |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 27 | #include <linux/firmware.h> |
Franky Lin | 7c6100e | 2011-06-01 13:45:36 +0200 | [diff] [blame] | 28 | #include <asm/unaligned.h> |
Roland Vossen | cc3cea5 | 2011-06-01 13:45:59 +0200 | [diff] [blame] | 29 | #include <defs.h> |
Roland Vossen | f97e956 | 2011-06-01 13:45:52 +0200 | [diff] [blame] | 30 | #include <brcmu_wifi.h> |
| 31 | #include <brcmu_utils.h> |
Roland Vossen | cc3cea5 | 2011-06-01 13:45:59 +0200 | [diff] [blame] | 32 | #include <brcm_hw_ids.h> |
Roland Vossen | cc3cea5 | 2011-06-01 13:45:59 +0200 | [diff] [blame] | 33 | #include <soc.h> |
Roland Vossen | c4daa84 | 2011-06-09 16:44:50 +0200 | [diff] [blame] | 34 | #include "sdio_host.h" |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 35 | #include "bcmsdbus.h" |
| 36 | #include "bcmsdh_sdmmc.h" |
Roland Vossen | 4489518 | 2011-06-01 13:45:55 +0200 | [diff] [blame] | 37 | |
| 38 | /* register access macros */ |
Roland Vossen | 4489518 | 2011-06-01 13:45:55 +0200 | [diff] [blame] | 39 | #ifndef __BIG_ENDIAN |
| 40 | #ifndef __mips__ |
Roland Vossen | b61a4be | 2011-06-01 13:45:56 +0200 | [diff] [blame] | 41 | #define R_REG(r) \ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 42 | brcmf_sdcard_reg_read(NULL, (unsigned long)(r), sizeof(*(r))) |
Roland Vossen | 4489518 | 2011-06-01 13:45:55 +0200 | [diff] [blame] | 43 | #else /* __mips__ */ |
Roland Vossen | b61a4be | 2011-06-01 13:45:56 +0200 | [diff] [blame] | 44 | #define R_REG(r) \ |
| 45 | ({ \ |
| 46 | __typeof(*(r)) __osl_v; \ |
| 47 | __asm__ __volatile__("sync"); \ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 48 | __osl_v = brcmf_sdcard_reg_read(NULL, (unsigned long)(r),\ |
Roland Vossen | 2503634 | 2011-06-01 13:45:57 +0200 | [diff] [blame] | 49 | sizeof(*(r))); \ |
Roland Vossen | b61a4be | 2011-06-01 13:45:56 +0200 | [diff] [blame] | 50 | __asm__ __volatile__("sync"); \ |
| 51 | __osl_v; \ |
| 52 | }) |
Roland Vossen | 4489518 | 2011-06-01 13:45:55 +0200 | [diff] [blame] | 53 | #endif /* __mips__ */ |
| 54 | |
| 55 | #define W_REG(r, v) do { \ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 56 | brcmf_sdcard_reg_write(NULL, (unsigned long)(r), sizeof(*(r)), \ |
| 57 | (v)); \ |
Roland Vossen | 4489518 | 2011-06-01 13:45:55 +0200 | [diff] [blame] | 58 | } while (0) |
| 59 | #else /* __BIG_ENDIAN */ |
Roland Vossen | b61a4be | 2011-06-01 13:45:56 +0200 | [diff] [blame] | 60 | #define R_REG(r) \ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 61 | brcmf_sdcard_reg_read(NULL, (unsigned long)(r), sizeof(*(r))) |
Roland Vossen | 4489518 | 2011-06-01 13:45:55 +0200 | [diff] [blame] | 62 | #define W_REG(r, v) do { \ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 63 | brcmf_sdcard_reg_write(NULL, (unsigned long)(r), sizeof(*(r)), \ |
| 64 | (v)); \ |
Roland Vossen | 4489518 | 2011-06-01 13:45:55 +0200 | [diff] [blame] | 65 | } while (0) |
| 66 | #endif /* __BIG_ENDIAN */ |
| 67 | |
Roland Vossen | 4489518 | 2011-06-01 13:45:55 +0200 | [diff] [blame] | 68 | #define AND_REG(r, v) W_REG((r), R_REG(r) & (v)) |
| 69 | #define OR_REG(r, v) W_REG((r), R_REG(r) | (v)) |
| 70 | |
| 71 | #define SET_REG(r, mask, val) \ |
| 72 | W_REG((r), ((R_REG(r) & ~(mask)) | (val))) |
| 73 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 74 | #ifdef BCMDBG |
Roland Vossen | f1c7a08 | 2011-06-01 13:45:09 +0200 | [diff] [blame] | 75 | |
| 76 | /* ARM trap handling */ |
| 77 | |
| 78 | /* Trap types defined by ARM (see arminc.h) */ |
| 79 | |
| 80 | /* Trap locations in lo memory */ |
| 81 | #define TRAP_STRIDE 4 |
| 82 | #define FIRST_TRAP TR_RST |
| 83 | #define LAST_TRAP (TR_FIQ * TRAP_STRIDE) |
| 84 | |
| 85 | #if defined(__ARM_ARCH_4T__) |
| 86 | #define MAX_TRAP_TYPE (TR_FIQ + 1) |
| 87 | #elif defined(__ARM_ARCH_7M__) |
| 88 | #define MAX_TRAP_TYPE (TR_ISR + ARMCM3_NUMINTS) |
| 89 | #endif /* __ARM_ARCH_7M__ */ |
| 90 | |
| 91 | /* The trap structure is defined here as offsets for assembly */ |
| 92 | #define TR_TYPE 0x00 |
| 93 | #define TR_EPC 0x04 |
| 94 | #define TR_CPSR 0x08 |
| 95 | #define TR_SPSR 0x0c |
| 96 | #define TR_REGS 0x10 |
| 97 | #define TR_REG(n) (TR_REGS + (n) * 4) |
| 98 | #define TR_SP TR_REG(13) |
| 99 | #define TR_LR TR_REG(14) |
| 100 | #define TR_PC TR_REG(15) |
| 101 | |
| 102 | #define TRAP_T_SIZE 80 |
| 103 | |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 104 | struct brcmf_trap { |
Roland Vossen | f1c7a08 | 2011-06-01 13:45:09 +0200 | [diff] [blame] | 105 | u32 type; |
| 106 | u32 epc; |
| 107 | u32 cpsr; |
| 108 | u32 spsr; |
| 109 | u32 r0; |
| 110 | u32 r1; |
| 111 | u32 r2; |
| 112 | u32 r3; |
| 113 | u32 r4; |
| 114 | u32 r5; |
| 115 | u32 r6; |
| 116 | u32 r7; |
| 117 | u32 r8; |
| 118 | u32 r9; |
| 119 | u32 r10; |
| 120 | u32 r11; |
| 121 | u32 r12; |
| 122 | u32 r13; |
| 123 | u32 r14; |
| 124 | u32 pc; |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 125 | }; |
Roland Vossen | f1c7a08 | 2011-06-01 13:45:09 +0200 | [diff] [blame] | 126 | |
Roland Vossen | f1c7a08 | 2011-06-01 13:45:09 +0200 | [diff] [blame] | 127 | #define CBUF_LEN (128) |
| 128 | |
| 129 | #define LOG_BUF_LEN 1024 |
| 130 | |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 131 | struct rte_log { |
Roland Vossen | f1c7a08 | 2011-06-01 13:45:09 +0200 | [diff] [blame] | 132 | u32 buf; /* Can't be pointer on (64-bit) hosts */ |
| 133 | uint buf_size; |
| 134 | uint idx; |
| 135 | char *_buf_compat; /* Redundant pointer for backward compat. */ |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 136 | }; |
Roland Vossen | f1c7a08 | 2011-06-01 13:45:09 +0200 | [diff] [blame] | 137 | |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 138 | struct rte_console { |
Roland Vossen | f1c7a08 | 2011-06-01 13:45:09 +0200 | [diff] [blame] | 139 | /* Virtual UART |
| 140 | * When there is no UART (e.g. Quickturn), |
| 141 | * the host should write a complete |
| 142 | * input line directly into cbuf and then write |
| 143 | * the length into vcons_in. |
| 144 | * This may also be used when there is a real UART |
| 145 | * (at risk of conflicting with |
| 146 | * the real UART). vcons_out is currently unused. |
| 147 | */ |
| 148 | volatile uint vcons_in; |
| 149 | volatile uint vcons_out; |
| 150 | |
| 151 | /* Output (logging) buffer |
| 152 | * Console output is written to a ring buffer log_buf at index log_idx. |
| 153 | * The host may read the output when it sees log_idx advance. |
| 154 | * Output will be lost if the output wraps around faster than the host |
| 155 | * polls. |
| 156 | */ |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 157 | struct rte_log log; |
Roland Vossen | f1c7a08 | 2011-06-01 13:45:09 +0200 | [diff] [blame] | 158 | |
| 159 | /* Console input line buffer |
| 160 | * Characters are read one at a time into cbuf |
| 161 | * until <CR> is received, then |
| 162 | * the buffer is processed as a command line. |
| 163 | * Also used for virtual UART. |
| 164 | */ |
| 165 | uint cbuf_idx; |
| 166 | char cbuf[CBUF_LEN]; |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 167 | }; |
Roland Vossen | f1c7a08 | 2011-06-01 13:45:09 +0200 | [diff] [blame] | 168 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 169 | #endif /* BCMDBG */ |
Roland Vossen | 745c9e6 | 2011-06-01 13:45:30 +0200 | [diff] [blame] | 170 | #include <chipcommon.h> |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 171 | |
Roland Vossen | c4daa84 | 2011-06-09 16:44:50 +0200 | [diff] [blame] | 172 | #include "sbsdio.h" |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 173 | |
Roland Vossen | c4daa84 | 2011-06-09 16:44:50 +0200 | [diff] [blame] | 174 | #include "dngl_stats.h" |
| 175 | #include "dhd.h" |
| 176 | #include "dhd_bus.h" |
| 177 | #include "dhd_proto.h" |
| 178 | #include "dhd_dbg.h" |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 179 | #include <sdiovar.h> |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 180 | #include <bcmchip.h> |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 181 | |
| 182 | #ifndef DHDSDIO_MEM_DUMP_FNAME |
| 183 | #define DHDSDIO_MEM_DUMP_FNAME "mem_dump" |
| 184 | #endif |
| 185 | |
Grant Grundler | 26a71a4 | 2011-03-09 10:41:25 -0800 | [diff] [blame] | 186 | #define TXQLEN 2048 /* bulk tx queue length */ |
| 187 | #define TXHI (TXQLEN - 256) /* turn on flow control above TXHI */ |
| 188 | #define TXLOW (TXHI - 256) /* turn off flow control below TXLOW */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 189 | #define PRIOMASK 7 |
| 190 | |
| 191 | #define TXRETRIES 2 /* # of retries for tx frames */ |
| 192 | |
| 193 | #if defined(CONFIG_MACH_SANDGATE2G) |
| 194 | #define DHD_RXBOUND 250 /* Default for max rx frames in |
| 195 | one scheduling */ |
| 196 | #else |
| 197 | #define DHD_RXBOUND 50 /* Default for max rx frames in |
| 198 | one scheduling */ |
| 199 | #endif /* defined(CONFIG_MACH_SANDGATE2G) */ |
| 200 | |
| 201 | #define DHD_TXBOUND 20 /* Default for max tx frames in |
| 202 | one scheduling */ |
| 203 | |
| 204 | #define DHD_TXMINMAX 1 /* Max tx frames if rx still pending */ |
| 205 | |
| 206 | #define MEMBLOCK 2048 /* Block size used for downloading |
| 207 | of dongle image */ |
| 208 | #define MAX_DATA_BUF (32 * 1024) /* Must be large enough to hold |
| 209 | biggest possible glom */ |
| 210 | |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 211 | #ifndef BRCMF_FIRSTREAD |
| 212 | #define BRCMF_FIRSTREAD 32 |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 213 | #endif |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 214 | #if !ISPOWEROF2(BRCMF_FIRSTREAD) |
| 215 | #error BRCMF_FIRSTREAD is not a power of 2! |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 216 | #endif |
| 217 | |
| 218 | /* Total length of frame header for dongle protocol */ |
| 219 | #define SDPCM_HDRLEN (SDPCM_FRAMETAG_LEN + SDPCM_SWHEADER_LEN) |
| 220 | #ifdef SDTEST |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 221 | #define SDPCM_RESERVE (SDPCM_HDRLEN + SDPCM_TEST_HDRLEN + BRCMF_SDALIGN) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 222 | #else |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 223 | #define SDPCM_RESERVE (SDPCM_HDRLEN + BRCMF_SDALIGN) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 224 | #endif |
| 225 | |
Franky Lin | b49b14d | 2011-06-01 13:45:37 +0200 | [diff] [blame] | 226 | /* |
| 227 | * Software allocation of To SB Mailbox resources |
| 228 | */ |
| 229 | |
| 230 | /* tosbmailbox bits corresponding to intstatus bits */ |
| 231 | #define SMB_NAK (1 << 0) /* Frame NAK */ |
| 232 | #define SMB_INT_ACK (1 << 1) /* Host Interrupt ACK */ |
| 233 | #define SMB_USE_OOB (1 << 2) /* Use OOB Wakeup */ |
| 234 | #define SMB_DEV_INT (1 << 3) /* Miscellaneous Interrupt */ |
| 235 | |
| 236 | /* tosbmailboxdata */ |
| 237 | #define SMB_DATA_VERSION_SHIFT 16 /* host protocol version */ |
| 238 | |
| 239 | /* |
| 240 | * Software allocation of To Host Mailbox resources |
| 241 | */ |
| 242 | |
| 243 | /* intstatus bits */ |
| 244 | #define I_HMB_FC_STATE I_HMB_SW0 /* Flow Control State */ |
| 245 | #define I_HMB_FC_CHANGE I_HMB_SW1 /* Flow Control State Changed */ |
| 246 | #define I_HMB_FRAME_IND I_HMB_SW2 /* Frame Indication */ |
| 247 | #define I_HMB_HOST_INT I_HMB_SW3 /* Miscellaneous Interrupt */ |
| 248 | |
| 249 | /* tohostmailboxdata */ |
| 250 | #define HMB_DATA_NAKHANDLED 1 /* retransmit NAK'd frame */ |
| 251 | #define HMB_DATA_DEVREADY 2 /* talk to host after enable */ |
| 252 | #define HMB_DATA_FC 4 /* per prio flowcontrol update flag */ |
| 253 | #define HMB_DATA_FWREADY 8 /* fw ready for protocol activity */ |
| 254 | |
| 255 | #define HMB_DATA_FCDATA_MASK 0xff000000 |
| 256 | #define HMB_DATA_FCDATA_SHIFT 24 |
| 257 | |
| 258 | #define HMB_DATA_VERSION_MASK 0x00ff0000 |
| 259 | #define HMB_DATA_VERSION_SHIFT 16 |
| 260 | |
| 261 | /* |
| 262 | * Software-defined protocol header |
| 263 | */ |
| 264 | |
| 265 | /* Current protocol version */ |
| 266 | #define SDPCM_PROT_VERSION 4 |
| 267 | |
| 268 | /* SW frame header */ |
| 269 | #define SDPCM_PACKET_SEQUENCE(p) (((u8 *)p)[0] & 0xff) |
| 270 | |
| 271 | #define SDPCM_CHANNEL_MASK 0x00000f00 |
| 272 | #define SDPCM_CHANNEL_SHIFT 8 |
| 273 | #define SDPCM_PACKET_CHANNEL(p) (((u8 *)p)[1] & 0x0f) |
| 274 | |
| 275 | #define SDPCM_NEXTLEN_OFFSET 2 |
| 276 | |
| 277 | /* Data Offset from SOF (HW Tag, SW Tag, Pad) */ |
| 278 | #define SDPCM_DOFFSET_OFFSET 3 /* Data Offset */ |
| 279 | #define SDPCM_DOFFSET_VALUE(p) (((u8 *)p)[SDPCM_DOFFSET_OFFSET] & 0xff) |
| 280 | #define SDPCM_DOFFSET_MASK 0xff000000 |
| 281 | #define SDPCM_DOFFSET_SHIFT 24 |
| 282 | #define SDPCM_FCMASK_OFFSET 4 /* Flow control */ |
| 283 | #define SDPCM_FCMASK_VALUE(p) (((u8 *)p)[SDPCM_FCMASK_OFFSET] & 0xff) |
| 284 | #define SDPCM_WINDOW_OFFSET 5 /* Credit based fc */ |
| 285 | #define SDPCM_WINDOW_VALUE(p) (((u8 *)p)[SDPCM_WINDOW_OFFSET] & 0xff) |
| 286 | |
| 287 | #define SDPCM_SWHEADER_LEN 8 /* SW header is 64 bits */ |
| 288 | |
| 289 | /* logical channel numbers */ |
| 290 | #define SDPCM_CONTROL_CHANNEL 0 /* Control channel Id */ |
| 291 | #define SDPCM_EVENT_CHANNEL 1 /* Asyc Event Indication Channel Id */ |
| 292 | #define SDPCM_DATA_CHANNEL 2 /* Data Xmit/Recv Channel Id */ |
| 293 | #define SDPCM_GLOM_CHANNEL 3 /* For coalesced packets */ |
| 294 | #define SDPCM_TEST_CHANNEL 15 /* Reserved for test/debug packets */ |
| 295 | |
| 296 | #define SDPCM_SEQUENCE_WRAP 256 /* wrap-around val for 8bit frame seq */ |
| 297 | |
| 298 | #define SDPCM_GLOMDESC(p) (((u8 *)p)[1] & 0x80) |
| 299 | |
| 300 | /* For TEST_CHANNEL packets, define another 4-byte header */ |
| 301 | #define SDPCM_TEST_HDRLEN 4 /* |
| 302 | * Generally: Cmd(1), Ext(1), Len(2); |
| 303 | * Semantics of Ext byte depend on |
| 304 | * command. Len is current or requested |
| 305 | * frame length, not including test |
| 306 | * header; sent little-endian. |
| 307 | */ |
| 308 | #define SDPCM_TEST_DISCARD 0x01 /* Receiver discards. Ext:pattern id. */ |
| 309 | #define SDPCM_TEST_ECHOREQ 0x02 /* Echo request. Ext:pattern id. */ |
| 310 | #define SDPCM_TEST_ECHORSP 0x03 /* Echo response. Ext:pattern id. */ |
| 311 | #define SDPCM_TEST_BURST 0x04 /* |
| 312 | * Receiver to send a burst. |
| 313 | * Ext is a frame count |
| 314 | */ |
| 315 | #define SDPCM_TEST_SEND 0x05 /* |
| 316 | * Receiver sets send mode. |
| 317 | * Ext is boolean on/off |
| 318 | */ |
| 319 | |
| 320 | /* Handy macro for filling in datagen packets with a pattern */ |
| 321 | #define SDPCM_TEST_FILL(byteno, id) ((u8)(id + byteno)) |
| 322 | |
| 323 | /* |
| 324 | * Shared structure between dongle and the host. |
| 325 | * The structure contains pointers to trap or assert information. |
| 326 | */ |
| 327 | #define SDPCM_SHARED_VERSION 0x0002 |
| 328 | #define SDPCM_SHARED_VERSION_MASK 0x00FF |
| 329 | #define SDPCM_SHARED_ASSERT_BUILT 0x0100 |
| 330 | #define SDPCM_SHARED_ASSERT 0x0200 |
| 331 | #define SDPCM_SHARED_TRAP 0x0400 |
| 332 | |
| 333 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 334 | /* Space for header read, limit for data packets */ |
| 335 | #ifndef MAX_HDR_READ |
| 336 | #define MAX_HDR_READ 32 |
| 337 | #endif |
| 338 | #if !ISPOWEROF2(MAX_HDR_READ) |
| 339 | #error MAX_HDR_READ is not a power of 2! |
| 340 | #endif |
| 341 | |
| 342 | #define MAX_RX_DATASZ 2048 |
| 343 | |
| 344 | /* Maximum milliseconds to wait for F2 to come up */ |
| 345 | #define DHD_WAIT_F2RDY 3000 |
| 346 | |
| 347 | /* Bump up limit on waiting for HT to account for first startup; |
| 348 | * if the image is doing a CRC calculation before programming the PMU |
| 349 | * for HT availability, it could take a couple hundred ms more, so |
| 350 | * max out at a 1 second (1000000us). |
| 351 | */ |
| 352 | #if (PMU_MAX_TRANSITION_DLY <= 1000000) |
| 353 | #undef PMU_MAX_TRANSITION_DLY |
| 354 | #define PMU_MAX_TRANSITION_DLY 1000000 |
| 355 | #endif |
| 356 | |
| 357 | /* Value for ChipClockCSR during initial setup */ |
| 358 | #define DHD_INIT_CLKCTL1 (SBSDIO_FORCE_HW_CLKREQ_OFF | \ |
| 359 | SBSDIO_ALP_AVAIL_REQ) |
| 360 | #define DHD_INIT_CLKCTL2 (SBSDIO_FORCE_HW_CLKREQ_OFF | SBSDIO_FORCE_ALP) |
| 361 | |
| 362 | /* Flags for SDH calls */ |
| 363 | #define F2SYNC (SDIO_REQ_4BYTE | SDIO_REQ_FIXED) |
| 364 | |
Roland Vossen | b6fe70c | 2011-06-01 13:45:19 +0200 | [diff] [blame] | 365 | /* sbimstate */ |
| 366 | #define SBIM_IBE 0x20000 /* inbanderror */ |
| 367 | #define SBIM_TO 0x40000 /* timeout */ |
| 368 | #define SBIM_BY 0x01800000 /* busy (sonics >= 2.3) */ |
| 369 | #define SBIM_RJ 0x02000000 /* reject (sonics >= 2.3) */ |
| 370 | |
| 371 | /* sbtmstatelow */ |
| 372 | #define SBTML_RESET 0x0001 /* reset */ |
| 373 | #define SBTML_REJ_MASK 0x0006 /* reject field */ |
| 374 | #define SBTML_REJ 0x0002 /* reject */ |
| 375 | #define SBTML_TMPREJ 0x0004 /* temporary reject, for error recovery */ |
| 376 | |
| 377 | #define SBTML_SICF_SHIFT 16 /* Shift to locate the SI control flags in sbtml */ |
| 378 | |
| 379 | /* sbtmstatehigh */ |
| 380 | #define SBTMH_SERR 0x0001 /* serror */ |
| 381 | #define SBTMH_INT 0x0002 /* interrupt */ |
| 382 | #define SBTMH_BUSY 0x0004 /* busy */ |
| 383 | #define SBTMH_TO 0x0020 /* timeout (sonics >= 2.3) */ |
| 384 | |
| 385 | #define SBTMH_SISF_SHIFT 16 /* Shift to locate the SI status flags in sbtmh */ |
| 386 | |
| 387 | /* sbidlow */ |
| 388 | #define SBIDL_INIT 0x80 /* initiator */ |
| 389 | |
| 390 | /* sbidhigh */ |
| 391 | #define SBIDH_RC_MASK 0x000f /* revision code */ |
| 392 | #define SBIDH_RCE_MASK 0x7000 /* revision code extension field */ |
| 393 | #define SBIDH_RCE_SHIFT 8 |
| 394 | #define SBCOREREV(sbidh) \ |
| 395 | ((((sbidh) & SBIDH_RCE_MASK) >> SBIDH_RCE_SHIFT) | ((sbidh) & SBIDH_RC_MASK)) |
| 396 | #define SBIDH_CC_MASK 0x8ff0 /* core code */ |
| 397 | #define SBIDH_CC_SHIFT 4 |
| 398 | #define SBIDH_VC_MASK 0xffff0000 /* vendor code */ |
| 399 | #define SBIDH_VC_SHIFT 16 |
| 400 | |
Arend van Spriel | 70dfb58 | 2011-02-25 16:39:17 +0100 | [diff] [blame] | 401 | /* |
| 402 | * Conversion of 802.1D priority to precedence level |
| 403 | */ |
| 404 | #define PRIO2PREC(prio) \ |
| 405 | (((prio) == PRIO_8021D_NONE || (prio) == PRIO_8021D_BE) ? \ |
| 406 | ((prio^2)) : (prio)) |
| 407 | |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 408 | BRCMF_SPINWAIT_SLEEP_INIT(sdioh_spinwait_sleep); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 409 | |
Roland Vossen | b6fe70c | 2011-06-01 13:45:19 +0200 | [diff] [blame] | 410 | /* Core reg address translation */ |
| 411 | #define CORE_CC_REG(base, field) (base + offsetof(chipcregs_t, field)) |
Franky Lin | 597600a | 2011-06-01 13:45:39 +0200 | [diff] [blame] | 412 | #define CORE_BUS_REG(base, field) \ |
| 413 | (base + offsetof(struct sdpcmd_regs, field)) |
Roland Vossen | b6fe70c | 2011-06-01 13:45:19 +0200 | [diff] [blame] | 414 | #define CORE_SB(base, field) \ |
| 415 | (base + SBCONFIGOFF + offsetof(sbconfig_t, field)) |
| 416 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 417 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 418 | /* Device console log buffer state */ |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 419 | struct dhd_console { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 420 | uint count; /* Poll interval msec counter */ |
| 421 | uint log_addr; /* Log struct address (fixed) */ |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 422 | struct rte_log log; /* Log struct (host copy) */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 423 | uint bufsize; /* Size of log buffer */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 424 | u8 *buf; /* Log buffer (host copy) */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 425 | uint last; /* Last buffer read index */ |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 426 | }; |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 427 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 428 | |
Franky Lin | b49b14d | 2011-06-01 13:45:37 +0200 | [diff] [blame] | 429 | struct sdpcm_shared { |
| 430 | u32 flags; |
| 431 | u32 trap_addr; |
| 432 | u32 assert_exp_addr; |
| 433 | u32 assert_file_addr; |
| 434 | u32 assert_line; |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 435 | u32 console_addr; /* Address of struct rte_console */ |
Franky Lin | b49b14d | 2011-06-01 13:45:37 +0200 | [diff] [blame] | 436 | u32 msgtrace_addr; |
| 437 | u8 tag[32]; |
| 438 | }; |
| 439 | |
| 440 | |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 441 | /* misc chip info needed by some of the routines */ |
| 442 | struct chip_info { |
| 443 | u32 chip; |
| 444 | u32 chiprev; |
| 445 | u32 cccorebase; |
| 446 | u32 ccrev; |
| 447 | u32 cccaps; |
| 448 | u32 buscorebase; |
| 449 | u32 buscorerev; |
| 450 | u32 buscoretype; |
| 451 | u32 ramcorebase; |
| 452 | u32 armcorebase; |
| 453 | u32 pmurev; |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 454 | u32 ramsize; |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 455 | }; |
| 456 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 457 | /* Private data for SDIO bus interaction */ |
| 458 | typedef struct dhd_bus { |
Arend van Spriel | fb1d0aa | 2011-06-29 16:47:55 -0700 | [diff] [blame] | 459 | struct brcmf_pub *dhd; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 460 | |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 461 | struct brcmf_sdio_card *card; /* Handle for sdio card calls */ |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 462 | struct chip_info *ci; /* Chip info struct */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 463 | char *vars; /* Variables (from CIS and/or other) */ |
| 464 | uint varsz; /* Size of variables buffer */ |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 465 | u32 sbaddr; /* Current SB window pointer (-1, invalid) */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 466 | |
Franky Lin | 597600a | 2011-06-01 13:45:39 +0200 | [diff] [blame] | 467 | struct sdpcmd_regs *regs; /* SDIO core */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 468 | uint sdpcmrev; /* SDIO core revision */ |
| 469 | uint armrev; /* CPU core revision */ |
| 470 | uint ramrev; /* SOCRAM core revision */ |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 471 | u32 ramsize; /* Size of RAM in SOCRAM (bytes) */ |
| 472 | u32 orig_ramsize; /* Size of RAM in SOCRAM (bytes) */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 473 | |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 474 | u32 bus; /* gSPI or SDIO bus */ |
| 475 | u32 hostintmask; /* Copy of Host Interrupt Mask */ |
| 476 | u32 intstatus; /* Intstatus bits (events) pending */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 477 | bool dpc_sched; /* Indicates DPC schedule (intrpt rcvd) */ |
| 478 | bool fcstate; /* State of dongle flow-control */ |
| 479 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 480 | u16 cl_devid; /* cached devid for brcmf_sdio_probe_attach() */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 481 | |
| 482 | uint blocksize; /* Block size of SDIO transfers */ |
| 483 | uint roundup; /* Max roundup limit */ |
| 484 | |
| 485 | struct pktq txq; /* Queue length used for flow-control */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 486 | u8 flowcontrol; /* per prio flow control bitmask */ |
| 487 | u8 tx_seq; /* Transmit sequence number (next) */ |
| 488 | u8 tx_max; /* Maximum transmit sequence allowed */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 489 | |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 490 | u8 hdrbuf[MAX_HDR_READ + BRCMF_SDALIGN]; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 491 | u8 *rxhdr; /* Header of current rx frame (in hdrbuf) */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 492 | u16 nextlen; /* Next Read Len from last header */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 493 | u8 rx_seq; /* Receive sequence number (expected) */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 494 | bool rxskip; /* Skip receive (awaiting NAK ACK) */ |
| 495 | |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 496 | struct sk_buff *glomd; /* Packet containing glomming descriptor */ |
| 497 | struct sk_buff *glom; /* Packet chain for glommed superframe */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 498 | uint glomerr; /* Glom packet read errors */ |
| 499 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 500 | u8 *rxbuf; /* Buffer for receiving control packets */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 501 | uint rxblen; /* Allocated length of rxbuf */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 502 | u8 *rxctl; /* Aligned pointer into rxbuf */ |
| 503 | u8 *databuf; /* Buffer for receiving big glom packet */ |
| 504 | u8 *dataptr; /* Aligned pointer into databuf */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 505 | uint rxlen; /* Length of valid data in buffer */ |
| 506 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 507 | u8 sdpcm_ver; /* Bus protocol reported by dongle */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 508 | |
| 509 | bool intr; /* Use interrupts */ |
| 510 | bool poll; /* Use polling */ |
| 511 | bool ipend; /* Device interrupt is pending */ |
| 512 | bool intdis; /* Interrupts disabled by isr */ |
| 513 | uint intrcount; /* Count of device interrupt callbacks */ |
| 514 | uint lastintrs; /* Count as of last watchdog timer */ |
| 515 | uint spurious; /* Count of spurious interrupts */ |
| 516 | uint pollrate; /* Ticks between device polls */ |
| 517 | uint polltick; /* Tick counter */ |
| 518 | uint pollcnt; /* Count of active polls */ |
| 519 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 520 | #ifdef BCMDBG |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 521 | struct dhd_console console; /* Console output polling support */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 522 | uint console_addr; /* Console address from shared struct */ |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 523 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 524 | |
| 525 | uint regfails; /* Count of R_REG/W_REG failures */ |
| 526 | |
| 527 | uint clkstate; /* State of sd and backplane clock(s) */ |
| 528 | bool activity; /* Activity flag for clock down */ |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 529 | s32 idletime; /* Control for activity timeout */ |
| 530 | s32 idlecount; /* Activity timeout counter */ |
| 531 | s32 idleclock; /* How to set bus driver when idle */ |
Roland Vossen | 62dd656 | 2011-07-05 22:05:57 +0200 | [diff] [blame] | 532 | s32 sd_rxchain; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 533 | bool use_rxchain; /* If dhd should use PKT chains */ |
| 534 | bool sleeping; /* Is SDIO bus sleeping? */ |
| 535 | bool rxflow_mode; /* Rx flow control mode */ |
| 536 | bool rxflow; /* Is rx flow control on */ |
| 537 | uint prev_rxlim_hit; /* Is prev rx limit exceeded |
| 538 | (per dpc schedule) */ |
| 539 | bool alp_only; /* Don't use HT clock (ALP only) */ |
| 540 | /* Field to decide if rx of control frames happen in rxbuf or lb-pool */ |
| 541 | bool usebufpool; |
| 542 | |
| 543 | #ifdef SDTEST |
| 544 | /* external loopback */ |
| 545 | bool ext_loop; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 546 | u8 loopid; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 547 | |
| 548 | /* pktgen configuration */ |
| 549 | uint pktgen_freq; /* Ticks between bursts */ |
| 550 | uint pktgen_count; /* Packets to send each burst */ |
| 551 | uint pktgen_print; /* Bursts between count displays */ |
| 552 | uint pktgen_total; /* Stop after this many */ |
| 553 | uint pktgen_minlen; /* Minimum packet data len */ |
| 554 | uint pktgen_maxlen; /* Maximum packet data len */ |
| 555 | uint pktgen_mode; /* Configured mode: tx, rx, or echo */ |
| 556 | uint pktgen_stop; /* Number of tx failures causing stop */ |
| 557 | |
| 558 | /* active pktgen fields */ |
| 559 | uint pktgen_tick; /* Tick counter for bursts */ |
| 560 | uint pktgen_ptick; /* Burst counter for printing */ |
| 561 | uint pktgen_sent; /* Number of test packets generated */ |
| 562 | uint pktgen_rcvd; /* Number of test packets received */ |
| 563 | uint pktgen_fail; /* Number of failed send attempts */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 564 | u16 pktgen_len; /* Length of next packet to send */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 565 | #endif /* SDTEST */ |
| 566 | |
| 567 | /* Some additional counters */ |
| 568 | uint tx_sderrs; /* Count of tx attempts with sd errors */ |
| 569 | uint fcqueued; /* Tx packets that got queued */ |
| 570 | uint rxrtx; /* Count of rtx requests (NAK to dongle) */ |
| 571 | uint rx_toolong; /* Receive frames too long to receive */ |
| 572 | uint rxc_errors; /* SDIO errors when reading control frames */ |
| 573 | uint rx_hdrfail; /* SDIO errors on header reads */ |
| 574 | uint rx_badhdr; /* Bad received headers (roosync?) */ |
| 575 | uint rx_badseq; /* Mismatched rx sequence number */ |
| 576 | uint fc_rcvd; /* Number of flow-control events received */ |
| 577 | uint fc_xoff; /* Number which turned on flow-control */ |
| 578 | uint fc_xon; /* Number which turned off flow-control */ |
| 579 | uint rxglomfail; /* Failed deglom attempts */ |
| 580 | uint rxglomframes; /* Number of glom frames (superframes) */ |
| 581 | uint rxglompkts; /* Number of packets from glom frames */ |
| 582 | uint f2rxhdrs; /* Number of header reads */ |
| 583 | uint f2rxdata; /* Number of frame data reads */ |
| 584 | uint f2txdata; /* Number of f2 frame writes */ |
| 585 | uint f1regdata; /* Number of f1 register accesses */ |
| 586 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 587 | u8 *ctrl_frame_buf; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 588 | u32 ctrl_frame_len; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 589 | bool ctrl_frame_stat; |
Franky Lin | 0f1a87c | 2011-06-29 16:46:32 -0700 | [diff] [blame] | 590 | |
| 591 | spinlock_t txqlock; |
Franky Lin | b7adfa7 | 2011-06-29 16:47:42 -0700 | [diff] [blame] | 592 | wait_queue_head_t ctrl_wait; |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 593 | |
| 594 | struct timer_list timer; |
| 595 | struct completion watchdog_wait; |
| 596 | struct task_struct *watchdog_tsk; |
| 597 | bool wd_timer_valid; |
Franky Lin | 0827888 | 2011-06-29 16:47:45 -0700 | [diff] [blame] | 598 | |
| 599 | struct tasklet_struct tasklet; |
| 600 | struct task_struct *dpc_tsk; |
| 601 | struct completion dpc_wait; |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 602 | |
| 603 | bool threads_only; |
| 604 | struct semaphore sdsem; |
| 605 | spinlock_t sdlock; |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 606 | |
| 607 | const char *fw_name; |
| 608 | const struct firmware *firmware; |
| 609 | const char *nv_name; |
| 610 | u32 fw_ptr; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 611 | } dhd_bus_t; |
| 612 | |
Roland Vossen | b6fe70c | 2011-06-01 13:45:19 +0200 | [diff] [blame] | 613 | typedef volatile struct _sbconfig { |
| 614 | u32 PAD[2]; |
| 615 | u32 sbipsflag; /* initiator port ocp slave flag */ |
| 616 | u32 PAD[3]; |
| 617 | u32 sbtpsflag; /* target port ocp slave flag */ |
| 618 | u32 PAD[11]; |
| 619 | u32 sbtmerrloga; /* (sonics >= 2.3) */ |
| 620 | u32 PAD; |
| 621 | u32 sbtmerrlog; /* (sonics >= 2.3) */ |
| 622 | u32 PAD[3]; |
| 623 | u32 sbadmatch3; /* address match3 */ |
| 624 | u32 PAD; |
| 625 | u32 sbadmatch2; /* address match2 */ |
| 626 | u32 PAD; |
| 627 | u32 sbadmatch1; /* address match1 */ |
| 628 | u32 PAD[7]; |
| 629 | u32 sbimstate; /* initiator agent state */ |
| 630 | u32 sbintvec; /* interrupt mask */ |
| 631 | u32 sbtmstatelow; /* target state */ |
| 632 | u32 sbtmstatehigh; /* target state */ |
| 633 | u32 sbbwa0; /* bandwidth allocation table0 */ |
| 634 | u32 PAD; |
| 635 | u32 sbimconfiglow; /* initiator configuration */ |
| 636 | u32 sbimconfighigh; /* initiator configuration */ |
| 637 | u32 sbadmatch0; /* address match0 */ |
| 638 | u32 PAD; |
| 639 | u32 sbtmconfiglow; /* target configuration */ |
| 640 | u32 sbtmconfighigh; /* target configuration */ |
| 641 | u32 sbbconfig; /* broadcast configuration */ |
| 642 | u32 PAD; |
| 643 | u32 sbbstate; /* broadcast state */ |
| 644 | u32 PAD[3]; |
| 645 | u32 sbactcnfg; /* activate configuration */ |
| 646 | u32 PAD[3]; |
| 647 | u32 sbflagst; /* current sbflags */ |
| 648 | u32 PAD[3]; |
| 649 | u32 sbidlow; /* identification */ |
| 650 | u32 sbidhigh; /* identification */ |
| 651 | } sbconfig_t; |
| 652 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 653 | /* clkstate */ |
| 654 | #define CLK_NONE 0 |
| 655 | #define CLK_SDONLY 1 |
| 656 | #define CLK_PENDING 2 /* Not used yet */ |
| 657 | #define CLK_AVAIL 3 |
| 658 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 659 | #define DHD_NOPMU(dhd) (false) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 660 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 661 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 662 | static int qcount[NUMPRIO]; |
| 663 | static int tx_packets[NUMPRIO]; |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 664 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 665 | |
| 666 | /* Deferred transmit */ |
Franky Lin | 0827888 | 2011-06-29 16:47:45 -0700 | [diff] [blame] | 667 | uint brcmf_deferred_tx = 1; |
| 668 | module_param(brcmf_deferred_tx, uint, 0); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 669 | |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 670 | /* Watchdog thread priority, -1 to use kernel timer */ |
| 671 | int brcmf_watchdog_prio = 97; |
| 672 | module_param(brcmf_watchdog_prio, int, 0); |
| 673 | |
| 674 | /* Watchdog interval */ |
| 675 | uint brcmf_watchdog_ms = 10; |
| 676 | module_param(brcmf_watchdog_ms, uint, 0); |
| 677 | |
Franky Lin | 0827888 | 2011-06-29 16:47:45 -0700 | [diff] [blame] | 678 | /* DPC thread priority, -1 to use tasklet */ |
| 679 | int brcmf_dpc_prio = 98; |
| 680 | module_param(brcmf_dpc_prio, int, 0); |
| 681 | |
Franky Lin | 913af5f | 2011-06-29 16:47:44 -0700 | [diff] [blame] | 682 | #ifdef BCMDBG |
| 683 | /* Console poll interval */ |
| 684 | uint brcmf_console_ms; |
| 685 | module_param(brcmf_console_ms, uint, 0); |
| 686 | #endif /* DHD_DEBUG */ |
| 687 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 688 | /* Tx/Rx bounds */ |
Arend van Spriel | 7af9d0c | 2011-06-29 16:47:19 -0700 | [diff] [blame] | 689 | uint brcmf_txbound; |
| 690 | uint brcmf_rxbound; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 691 | uint dhd_txminmax; |
| 692 | |
| 693 | /* override the RAM size if possible */ |
| 694 | #define DONGLE_MIN_MEMSIZE (128 * 1024) |
Arend van Spriel | 7af9d0c | 2011-06-29 16:47:19 -0700 | [diff] [blame] | 695 | int brcmf_dongle_memsize; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 696 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 697 | static bool dhd_alignctl; |
| 698 | |
| 699 | static bool sd1idle; |
| 700 | |
| 701 | static bool retrydata; |
| 702 | #define RETRYCHAN(chan) (((chan) == SDPCM_EVENT_CHANNEL) || retrydata) |
| 703 | |
| 704 | static const uint watermark = 8; |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 705 | static const uint firstread = BRCMF_FIRSTREAD; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 706 | |
| 707 | #define HDATLEN (firstread - (SDPCM_HDRLEN)) |
| 708 | |
| 709 | /* Retry count for register access failures */ |
| 710 | static const uint retry_limit = 2; |
| 711 | |
| 712 | /* Force even SD lengths (some host controllers mess up on odd bytes) */ |
| 713 | static bool forcealign; |
| 714 | |
| 715 | #define ALIGNMENT 4 |
| 716 | |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 717 | #define PKTALIGN(_p, _len, _align) \ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 718 | do { \ |
| 719 | uint datalign; \ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 720 | datalign = (unsigned long)((_p)->data); \ |
| 721 | datalign = roundup(datalign, (_align)) - datalign; \ |
| 722 | ASSERT(datalign < (_align)); \ |
| 723 | ASSERT((_p)->len >= ((_len) + datalign)); \ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 724 | if (datalign) \ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 725 | skb_pull((_p), datalign); \ |
| 726 | __skb_trim((_p), (_len)); \ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 727 | } while (0) |
| 728 | |
| 729 | /* Limit on rounding up frames */ |
| 730 | static const uint max_roundup = 512; |
| 731 | |
| 732 | /* Try doing readahead */ |
| 733 | static bool dhd_readahead; |
| 734 | |
| 735 | /* To check if there's window offered */ |
| 736 | #define DATAOK(bus) \ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 737 | (((u8)(bus->tx_max - bus->tx_seq) != 0) && \ |
| 738 | (((u8)(bus->tx_max - bus->tx_seq) & 0x80) == 0)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 739 | |
| 740 | /* Macros to get register read/write status */ |
| 741 | /* NOTE: these assume a local dhdsdio_bus_t *bus! */ |
| 742 | #define R_SDREG(regvar, regaddr, retryvar) \ |
| 743 | do { \ |
| 744 | retryvar = 0; \ |
| 745 | do { \ |
Arend van Spriel | ff31c54 | 2011-03-01 10:56:54 +0100 | [diff] [blame] | 746 | regvar = R_REG(regaddr); \ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 747 | } while (brcmf_sdcard_regfail(bus->card) && \ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 748 | (++retryvar <= retry_limit)); \ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 749 | if (retryvar) { \ |
| 750 | bus->regfails += (retryvar-1); \ |
| 751 | if (retryvar > retry_limit) { \ |
| 752 | DHD_ERROR(("%s: FAILED" #regvar "READ, LINE %d\n", \ |
| 753 | __func__, __LINE__)); \ |
| 754 | regvar = 0; \ |
| 755 | } \ |
| 756 | } \ |
| 757 | } while (0) |
| 758 | |
| 759 | #define W_SDREG(regval, regaddr, retryvar) \ |
| 760 | do { \ |
| 761 | retryvar = 0; \ |
| 762 | do { \ |
Arend van Spriel | ff31c54 | 2011-03-01 10:56:54 +0100 | [diff] [blame] | 763 | W_REG(regaddr, regval); \ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 764 | } while (brcmf_sdcard_regfail(bus->card) && \ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 765 | (++retryvar <= retry_limit)); \ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 766 | if (retryvar) { \ |
| 767 | bus->regfails += (retryvar-1); \ |
| 768 | if (retryvar > retry_limit) \ |
| 769 | DHD_ERROR(("%s: FAILED REGISTER WRITE, LINE %d\n", \ |
| 770 | __func__, __LINE__)); \ |
| 771 | } \ |
| 772 | } while (0) |
| 773 | |
| 774 | #define DHD_BUS SDIO_BUS |
| 775 | |
| 776 | #define PKT_AVAILABLE() (intstatus & I_HMB_FRAME_IND) |
| 777 | |
| 778 | #define HOSTINTMASK (I_HMB_SW_MASK | I_CHIPACTIVE) |
| 779 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 780 | #ifdef SDTEST |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 781 | static void brcmf_sdbrcm_checkdied(dhd_bus_t *bus, void *pkt, uint seq); |
| 782 | static void brcmf_sdbrcm_sdtest_set(dhd_bus_t *bus, bool start); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 783 | #endif |
| 784 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 785 | #ifdef BCMDBG |
Arend van Spriel | fb1d0aa | 2011-06-29 16:47:55 -0700 | [diff] [blame] | 786 | static int brcmf_sdbrcm_bus_console_in(struct brcmf_pub *drvr, |
| 787 | unsigned char *msg, uint msglen); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 788 | static int brcmf_sdbrcm_checkdied(dhd_bus_t *bus, u8 *data, uint size); |
| 789 | static int brcmf_sdbrcm_mem_dump(dhd_bus_t *bus); |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 790 | #endif /* BCMDBG */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 791 | static int brcmf_sdbrcm_download_state(dhd_bus_t *bus, bool enter); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 792 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 793 | static void brcmf_sdbrcm_release(dhd_bus_t *bus); |
| 794 | static void brcmf_sdbrcm_release_malloc(dhd_bus_t *bus); |
| 795 | static void brcmf_sdbrcm_disconnect(void *ptr); |
| 796 | static bool brcmf_sdbrcm_chipmatch(u16 chipid); |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 797 | static bool brcmf_sdbrcm_probe_attach(dhd_bus_t *bus, void *card, |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 798 | void *regsva, u16 devid); |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 799 | static bool brcmf_sdbrcm_probe_malloc(dhd_bus_t *bus, void *card); |
| 800 | static bool brcmf_sdbrcm_probe_init(dhd_bus_t *bus, void *card); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 801 | static void brcmf_sdbrcm_release_dongle(dhd_bus_t *bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 802 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 803 | static uint brcmf_process_nvram_vars(char *varbuf, uint len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 804 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 805 | static void brcmf_sdbrcm_setmemsize(struct dhd_bus *bus, int mem_size); |
| 806 | 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] | 807 | uint flags, u8 *buf, uint nbytes, |
Roland Vossen | 62dd656 | 2011-07-05 22:05:57 +0200 | [diff] [blame] | 808 | struct sk_buff *pkt, |
| 809 | brcmf_sdio_cmplt_fn_t complete, void *handle); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 810 | |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 811 | static bool brcmf_sdbrcm_download_firmware(struct dhd_bus *bus, void *card); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 812 | static int _brcmf_sdbrcm_download_firmware(struct dhd_bus *bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 813 | |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 814 | static int brcmf_sdbrcm_download_code_file(struct dhd_bus *bus); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 815 | static int brcmf_sdbrcm_download_nvram(struct dhd_bus *bus); |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 816 | |
| 817 | static void |
| 818 | brcmf_sdbrcm_chip_disablecore(struct brcmf_sdio_card *card, u32 corebase); |
| 819 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 820 | static int brcmf_sdbrcm_chip_attach(struct dhd_bus *bus, void *regs); |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 821 | |
| 822 | static void |
| 823 | brcmf_sdbrcm_chip_resetcore(struct brcmf_sdio_card *card, u32 corebase); |
| 824 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 825 | static void brcmf_sdbrcm_sdiod_drive_strength_init(struct dhd_bus *bus, |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 826 | u32 drivestrength); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 827 | static void brcmf_sdbrcm_chip_detach(struct dhd_bus *bus); |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 828 | static void brcmf_sdbrcm_wait_for_event(dhd_bus_t *bus, bool *lockvar); |
Franky Lin | b7adfa7 | 2011-06-29 16:47:42 -0700 | [diff] [blame] | 829 | static void brcmf_sdbrcm_wait_event_wakeup(dhd_bus_t *bus); |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 830 | static void brcmf_sdbrcm_watchdog(unsigned long data); |
| 831 | static int brcmf_sdbrcm_watchdog_thread(void *data); |
Franky Lin | 0827888 | 2011-06-29 16:47:45 -0700 | [diff] [blame] | 832 | static int brcmf_sdbrcm_dpc_thread(void *data); |
| 833 | static void brcmf_sdbrcm_dpc_tasklet(unsigned long data); |
| 834 | static void brcmf_sdbrcm_sched_dpc(dhd_bus_t *bus); |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 835 | static void brcmf_sdbrcm_sdlock(dhd_bus_t *bus); |
| 836 | static void brcmf_sdbrcm_sdunlock(dhd_bus_t *bus); |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 837 | static int brcmf_sdbrcm_get_image(char *buf, int len, struct dhd_bus *bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 838 | |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 839 | /* Packet free applicable unconditionally for sdio and sdspi. |
| 840 | * Conditional if bufpool was present for gspi bus. |
| 841 | */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 842 | 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] | 843 | { |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 844 | if ((bus->bus != SPI_BUS) || bus->usebufpool) |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 845 | brcmu_pkt_buf_free_skb(pkt); |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 846 | } |
| 847 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 848 | static void brcmf_sdbrcm_setmemsize(struct dhd_bus *bus, int mem_size) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 849 | { |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 850 | s32 min_size = DONGLE_MIN_MEMSIZE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 851 | /* Restrict the memsize to user specified limit */ |
| 852 | DHD_ERROR(("user: Restrict the dongle ram size to %d, min %d\n", |
Arend van Spriel | 7af9d0c | 2011-06-29 16:47:19 -0700 | [diff] [blame] | 853 | brcmf_dongle_memsize, min_size)); |
| 854 | if ((brcmf_dongle_memsize > min_size) && |
| 855 | (brcmf_dongle_memsize < (s32) bus->orig_ramsize)) |
| 856 | bus->ramsize = brcmf_dongle_memsize; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 857 | } |
| 858 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 859 | 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] | 860 | { |
| 861 | int err = 0; |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 862 | brcmf_sdcard_cfg_write(bus->card, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRLOW, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 863 | (address >> 8) & SBSDIO_SBADDRLOW_MASK, &err); |
| 864 | if (!err) |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 865 | brcmf_sdcard_cfg_write(bus->card, SDIO_FUNC_1, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 866 | SBSDIO_FUNC1_SBADDRMID, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 867 | (address >> 16) & SBSDIO_SBADDRMID_MASK, &err); |
| 868 | if (!err) |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 869 | brcmf_sdcard_cfg_write(bus->card, SDIO_FUNC_1, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 870 | SBSDIO_FUNC1_SBADDRHIGH, |
| 871 | (address >> 24) & SBSDIO_SBADDRHIGH_MASK, |
| 872 | &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 873 | return err; |
| 874 | } |
| 875 | |
| 876 | /* Turn backplane clock on or off */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 877 | 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] | 878 | { |
| 879 | int err; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 880 | u8 clkctl, clkreq, devctl; |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 881 | struct brcmf_sdio_card *card; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 882 | |
| 883 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 884 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 885 | clkctl = 0; |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 886 | card = bus->card; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 887 | |
| 888 | if (on) { |
| 889 | /* Request HT Avail */ |
| 890 | clkreq = |
| 891 | bus->alp_only ? SBSDIO_ALP_AVAIL_REQ : SBSDIO_HT_AVAIL_REQ; |
| 892 | |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 893 | if ((bus->ci->chip == BCM4329_CHIP_ID) |
| 894 | && (bus->ci->chiprev == 0)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 895 | clkreq |= SBSDIO_FORCE_ALP; |
| 896 | |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 897 | brcmf_sdcard_cfg_write(card, SDIO_FUNC_1, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 898 | SBSDIO_FUNC1_CHIPCLKCSR, clkreq, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 899 | if (err) { |
| 900 | DHD_ERROR(("%s: HT Avail request error: %d\n", |
| 901 | __func__, err)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 902 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 903 | } |
| 904 | |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 905 | if (pendok && ((bus->ci->buscoretype == PCMCIA_CORE_ID) |
| 906 | && (bus->ci->buscorerev == 9))) { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 907 | u32 dummy, retries; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 908 | R_SDREG(dummy, &bus->regs->clockctlstatus, retries); |
| 909 | } |
| 910 | |
| 911 | /* Check current status */ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 912 | clkctl = brcmf_sdcard_cfg_read(card, SDIO_FUNC_1, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 913 | SBSDIO_FUNC1_CHIPCLKCSR, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 914 | if (err) { |
| 915 | DHD_ERROR(("%s: HT Avail read error: %d\n", |
| 916 | __func__, err)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 917 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | /* Go to pending and await interrupt if appropriate */ |
| 921 | if (!SBSDIO_CLKAV(clkctl, bus->alp_only) && pendok) { |
| 922 | /* Allow only clock-available interrupt */ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 923 | devctl = brcmf_sdcard_cfg_read(card, SDIO_FUNC_1, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 924 | SBSDIO_DEVICE_CTL, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 925 | if (err) { |
| 926 | DHD_ERROR(("%s: Devctl error setting CA: %d\n", |
| 927 | __func__, err)); |
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 | devctl |= SBSDIO_DEVCTL_CA_INT_ONLY; |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 932 | brcmf_sdcard_cfg_write(card, SDIO_FUNC_1, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 933 | SBSDIO_DEVICE_CTL, devctl, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 934 | DHD_INFO(("CLKCTL: set PENDING\n")); |
| 935 | bus->clkstate = CLK_PENDING; |
| 936 | |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 937 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 938 | } else if (bus->clkstate == CLK_PENDING) { |
| 939 | /* Cancel CA-only interrupt filter */ |
| 940 | devctl = |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 941 | brcmf_sdcard_cfg_read(card, SDIO_FUNC_1, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 942 | SBSDIO_DEVICE_CTL, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 943 | devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY; |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 944 | brcmf_sdcard_cfg_write(card, SDIO_FUNC_1, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 945 | SBSDIO_DEVICE_CTL, devctl, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | /* Otherwise, wait here (polling) for HT Avail */ |
| 949 | if (!SBSDIO_CLKAV(clkctl, bus->alp_only)) { |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 950 | BRCMF_SPINWAIT_SLEEP(sdioh_spinwait_sleep, |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 951 | ((clkctl = |
| 952 | brcmf_sdcard_cfg_read(card, SDIO_FUNC_1, |
| 953 | SBSDIO_FUNC1_CHIPCLKCSR, |
| 954 | &err)), |
| 955 | !SBSDIO_CLKAV(clkctl, bus->alp_only)), |
| 956 | PMU_MAX_TRANSITION_DLY); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 957 | } |
| 958 | if (err) { |
| 959 | DHD_ERROR(("%s: HT Avail request error: %d\n", |
| 960 | __func__, err)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 961 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 962 | } |
| 963 | if (!SBSDIO_CLKAV(clkctl, bus->alp_only)) { |
| 964 | DHD_ERROR(("%s: HT Avail timeout (%d): clkctl 0x%02x\n", |
| 965 | __func__, PMU_MAX_TRANSITION_DLY, clkctl)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 966 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | /* Mark clock available */ |
| 970 | bus->clkstate = CLK_AVAIL; |
| 971 | DHD_INFO(("CLKCTL: turned ON\n")); |
| 972 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 973 | #if defined(BCMDBG) |
Arend van Spriel | f3341e7 | 2011-06-29 16:47:28 -0700 | [diff] [blame] | 974 | if (bus->alp_only != true) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 975 | if (SBSDIO_ALPONLY(clkctl)) { |
| 976 | DHD_ERROR(("%s: HT Clock should be on.\n", |
| 977 | __func__)); |
| 978 | } |
| 979 | } |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 980 | #endif /* defined (BCMDBG) */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 981 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 982 | bus->activity = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 983 | } else { |
| 984 | clkreq = 0; |
| 985 | |
| 986 | if (bus->clkstate == CLK_PENDING) { |
| 987 | /* Cancel CA-only interrupt filter */ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 988 | devctl = brcmf_sdcard_cfg_read(card, SDIO_FUNC_1, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 989 | SBSDIO_DEVICE_CTL, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 990 | devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY; |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 991 | brcmf_sdcard_cfg_write(card, SDIO_FUNC_1, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 992 | SBSDIO_DEVICE_CTL, devctl, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | bus->clkstate = CLK_SDONLY; |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 996 | brcmf_sdcard_cfg_write(card, SDIO_FUNC_1, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 997 | SBSDIO_FUNC1_CHIPCLKCSR, clkreq, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 998 | DHD_INFO(("CLKCTL: turned OFF\n")); |
| 999 | if (err) { |
| 1000 | DHD_ERROR(("%s: Failed access turning clock off: %d\n", |
| 1001 | __func__, err)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 1002 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1003 | } |
| 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 | /* Change idle/active SD state */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1009 | static int brcmf_sdbrcm_sdclk(dhd_bus_t *bus, bool on) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1010 | { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1011 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 1012 | |
Franky Lin | 602a8ab | 2011-06-01 13:45:04 +0200 | [diff] [blame] | 1013 | if (on) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1014 | bus->clkstate = CLK_SDONLY; |
Franky Lin | 602a8ab | 2011-06-01 13:45:04 +0200 | [diff] [blame] | 1015 | else |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1016 | bus->clkstate = CLK_NONE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1017 | |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 1018 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1019 | } |
| 1020 | |
| 1021 | /* Transition SD and backplane clock readiness */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1022 | 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] | 1023 | { |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1024 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1025 | uint oldstate = bus->clkstate; |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1026 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1027 | |
| 1028 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 1029 | |
| 1030 | /* Early exit if we're already there */ |
| 1031 | if (bus->clkstate == target) { |
| 1032 | if (target == CLK_AVAIL) { |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 1033 | brcmf_sdbrcm_wd_timer(bus, brcmf_watchdog_ms); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1034 | bus->activity = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1035 | } |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 1036 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1037 | } |
| 1038 | |
| 1039 | switch (target) { |
| 1040 | case CLK_AVAIL: |
| 1041 | /* Make sure SD clock is available */ |
| 1042 | if (bus->clkstate == CLK_NONE) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1043 | brcmf_sdbrcm_sdclk(bus, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1044 | /* Now request HT Avail on the backplane */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1045 | brcmf_sdbrcm_htclk(bus, true, pendok); |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 1046 | brcmf_sdbrcm_wd_timer(bus, brcmf_watchdog_ms); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1047 | bus->activity = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1048 | break; |
| 1049 | |
| 1050 | case CLK_SDONLY: |
| 1051 | /* Remove HT request, or bring up SD clock */ |
| 1052 | if (bus->clkstate == CLK_NONE) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1053 | brcmf_sdbrcm_sdclk(bus, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1054 | else if (bus->clkstate == CLK_AVAIL) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1055 | brcmf_sdbrcm_htclk(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1056 | else |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1057 | DHD_ERROR(("brcmf_sdbrcm_clkctl: request for %d -> %d" |
| 1058 | "\n", bus->clkstate, target)); |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 1059 | brcmf_sdbrcm_wd_timer(bus, brcmf_watchdog_ms); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1060 | break; |
| 1061 | |
| 1062 | case CLK_NONE: |
| 1063 | /* Make sure to remove HT request */ |
| 1064 | if (bus->clkstate == CLK_AVAIL) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1065 | brcmf_sdbrcm_htclk(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1066 | /* Now remove the SD clock */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1067 | brcmf_sdbrcm_sdclk(bus, false); |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 1068 | brcmf_sdbrcm_wd_timer(bus, 0); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1069 | break; |
| 1070 | } |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1071 | #ifdef BCMDBG |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1072 | DHD_INFO(("brcmf_sdbrcm_clkctl: %d -> %d\n", oldstate, bus->clkstate)); |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1073 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1074 | |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 1075 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1076 | } |
| 1077 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1078 | int brcmf_sdbrcm_bussleep(dhd_bus_t *bus, bool sleep) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1079 | { |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 1080 | struct brcmf_sdio_card *card = bus->card; |
Franky Lin | 597600a | 2011-06-01 13:45:39 +0200 | [diff] [blame] | 1081 | struct sdpcmd_regs *regs = bus->regs; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1082 | uint retries = 0; |
| 1083 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1084 | DHD_INFO(("brcmf_sdbrcm_bussleep: request %s (currently %s)\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1085 | (sleep ? "SLEEP" : "WAKE"), |
| 1086 | (bus->sleeping ? "SLEEP" : "WAKE"))); |
| 1087 | |
| 1088 | /* Done if we're already in the requested state */ |
| 1089 | if (sleep == bus->sleeping) |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 1090 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1091 | |
| 1092 | /* Going to sleep: set the alarm and turn off the lights... */ |
| 1093 | if (sleep) { |
| 1094 | /* Don't sleep if something is pending */ |
| 1095 | if (bus->dpc_sched || bus->rxskip || pktq_len(&bus->txq)) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 1096 | return -EBUSY; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1097 | |
| 1098 | /* Disable SDIO interrupts (no longer interested) */ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 1099 | brcmf_sdcard_intr_disable(bus->card); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1100 | |
| 1101 | /* Make sure the controller has the bus up */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1102 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1103 | |
| 1104 | /* Tell device to start using OOB wakeup */ |
| 1105 | W_SDREG(SMB_USE_OOB, ®s->tosbmailbox, retries); |
| 1106 | if (retries > retry_limit) |
| 1107 | DHD_ERROR(("CANNOT SIGNAL CHIP, WILL NOT WAKE UP!!\n")); |
| 1108 | |
| 1109 | /* Turn off our contribution to the HT clock request */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1110 | brcmf_sdbrcm_clkctl(bus, CLK_SDONLY, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1111 | |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 1112 | brcmf_sdcard_cfg_write(card, SDIO_FUNC_1, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1113 | SBSDIO_FUNC1_CHIPCLKCSR, |
| 1114 | SBSDIO_FORCE_HW_CLKREQ_OFF, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1115 | |
| 1116 | /* Isolate the bus */ |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 1117 | if (bus->ci->chip != BCM4329_CHIP_ID |
| 1118 | && bus->ci->chip != BCM4319_CHIP_ID) { |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 1119 | brcmf_sdcard_cfg_write(card, SDIO_FUNC_1, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1120 | SBSDIO_DEVICE_CTL, |
| 1121 | SBSDIO_DEVCTL_PADS_ISO, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | /* Change state */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1125 | bus->sleeping = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1126 | |
| 1127 | } else { |
| 1128 | /* Waking up: bus power up is ok, set local state */ |
| 1129 | |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 1130 | brcmf_sdcard_cfg_write(card, SDIO_FUNC_1, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1131 | SBSDIO_FUNC1_CHIPCLKCSR, 0, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1132 | |
| 1133 | /* Force pad isolation off if possible |
| 1134 | (in case power never toggled) */ |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 1135 | if ((bus->ci->buscoretype == PCMCIA_CORE_ID) |
| 1136 | && (bus->ci->buscorerev >= 10)) |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 1137 | brcmf_sdcard_cfg_write(card, SDIO_FUNC_1, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1138 | SBSDIO_DEVICE_CTL, 0, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1139 | |
| 1140 | /* Make sure the controller has the bus up */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1141 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1142 | |
| 1143 | /* Send misc interrupt to indicate OOB not needed */ |
| 1144 | W_SDREG(0, ®s->tosbmailboxdata, retries); |
| 1145 | if (retries <= retry_limit) |
| 1146 | W_SDREG(SMB_DEV_INT, ®s->tosbmailbox, retries); |
| 1147 | |
| 1148 | if (retries > retry_limit) |
| 1149 | DHD_ERROR(("CANNOT SIGNAL CHIP TO CLEAR OOB!!\n")); |
| 1150 | |
| 1151 | /* Make sure we have SD bus access */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1152 | brcmf_sdbrcm_clkctl(bus, CLK_SDONLY, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1153 | |
| 1154 | /* Change state */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1155 | bus->sleeping = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1156 | |
| 1157 | /* Enable interrupts again */ |
| 1158 | if (bus->intr && (bus->dhd->busstate == DHD_BUS_DATA)) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1159 | bus->intdis = false; |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 1160 | brcmf_sdcard_intr_enable(bus->card); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1161 | } |
| 1162 | } |
| 1163 | |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 1164 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1165 | } |
| 1166 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1167 | #define BUS_WAKE(bus) \ |
| 1168 | do { \ |
| 1169 | if ((bus)->sleeping) \ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1170 | brcmf_sdbrcm_bussleep((bus), false); \ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1171 | } while (0); |
| 1172 | |
| 1173 | /* Writes a HW/SW header into the packet and sends it. */ |
| 1174 | /* Assumes: (a) header space already there, (b) caller holds lock */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1175 | 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] | 1176 | bool free_pkt) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1177 | { |
| 1178 | int ret; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1179 | u8 *frame; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 1180 | u16 len, pad = 0; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1181 | u32 swheader; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1182 | uint retries = 0; |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 1183 | struct brcmf_sdio_card *card; |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 1184 | struct sk_buff *new; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1185 | int i; |
| 1186 | |
| 1187 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 1188 | |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 1189 | card = bus->card; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1190 | |
| 1191 | if (bus->dhd->dongle_reset) { |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 1192 | ret = -EPERM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1193 | goto done; |
| 1194 | } |
| 1195 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1196 | frame = (u8 *) (pkt->data); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1197 | |
| 1198 | /* Add alignment padding, allocate new packet if needed */ |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 1199 | pad = ((unsigned long)frame % BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1200 | if (pad) { |
Arend van Spriel | 3be727c | 2010-11-23 22:20:30 +0100 | [diff] [blame] | 1201 | if (skb_headroom(pkt) < pad) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1202 | DHD_INFO(("%s: insufficient headroom %d for %d pad\n", |
Arend van Spriel | 3be727c | 2010-11-23 22:20:30 +0100 | [diff] [blame] | 1203 | __func__, skb_headroom(pkt), pad)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1204 | bus->dhd->tx_realloc++; |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 1205 | new = brcmu_pkt_buf_get_skb(pkt->len + BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1206 | if (!new) { |
| 1207 | DHD_ERROR(("%s: couldn't allocate new %d-byte " |
| 1208 | "packet\n", |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 1209 | __func__, pkt->len + BRCMF_SDALIGN)); |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 1210 | ret = -ENOMEM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1211 | goto done; |
| 1212 | } |
| 1213 | |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 1214 | PKTALIGN(new, pkt->len, BRCMF_SDALIGN); |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 1215 | memcpy(new->data, pkt->data, pkt->len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1216 | if (free_pkt) |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1217 | brcmu_pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1218 | /* free the pkt if canned one is not used */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1219 | free_pkt = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1220 | pkt = new; |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1221 | frame = (u8 *) (pkt->data); |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 1222 | ASSERT(((unsigned long)frame % BRCMF_SDALIGN) == 0); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1223 | pad = 0; |
| 1224 | } else { |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 1225 | skb_push(pkt, pad); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1226 | frame = (u8 *) (pkt->data); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1227 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1228 | ASSERT((pad + SDPCM_HDRLEN) <= (int)(pkt->len)); |
Brett Rudley | 9249ede | 2010-11-30 20:09:49 -0800 | [diff] [blame] | 1229 | memset(frame, 0, pad + SDPCM_HDRLEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1230 | } |
| 1231 | } |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 1232 | ASSERT(pad < BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1233 | |
| 1234 | /* 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] | 1235 | len = (u16) (pkt->len); |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 1236 | *(u16 *) frame = cpu_to_le16(len); |
| 1237 | *(((u16 *) frame) + 1) = cpu_to_le16(~len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1238 | |
| 1239 | /* Software tag: channel, sequence number, data offset */ |
| 1240 | swheader = |
| 1241 | ((chan << SDPCM_CHANNEL_SHIFT) & SDPCM_CHANNEL_MASK) | bus->tx_seq | |
| 1242 | (((pad + |
| 1243 | SDPCM_HDRLEN) << SDPCM_DOFFSET_SHIFT) & SDPCM_DOFFSET_MASK); |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 1244 | |
| 1245 | put_unaligned_le32(swheader, frame + SDPCM_FRAMETAG_LEN); |
| 1246 | put_unaligned_le32(0, frame + SDPCM_FRAMETAG_LEN + sizeof(swheader)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1247 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1248 | #ifdef BCMDBG |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1249 | tx_packets[pkt->priority]++; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1250 | if (DHD_BYTES_ON() && |
| 1251 | (((DHD_CTL_ON() && (chan == SDPCM_CONTROL_CHANNEL)) || |
| 1252 | (DHD_DATA_ON() && (chan != SDPCM_CONTROL_CHANNEL))))) { |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 1253 | printk(KERN_DEBUG "Tx Frame:\n"); |
| 1254 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, frame, len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1255 | } else if (DHD_HDRS_ON()) { |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 1256 | printk(KERN_DEBUG "TxHdr:\n"); |
| 1257 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 1258 | frame, min_t(u16, len, 16)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1259 | } |
| 1260 | #endif |
| 1261 | |
| 1262 | /* Raise len to next SDIO block to eliminate tail command */ |
| 1263 | if (bus->roundup && bus->blocksize && (len > bus->blocksize)) { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 1264 | u16 pad = bus->blocksize - (len % bus->blocksize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1265 | if ((pad <= bus->roundup) && (pad < bus->blocksize)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1266 | len += pad; |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 1267 | } else if (len % BRCMF_SDALIGN) { |
| 1268 | len += BRCMF_SDALIGN - (len % BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1269 | } |
| 1270 | |
| 1271 | /* Some controllers have trouble with odd bytes -- round to even */ |
| 1272 | if (forcealign && (len & (ALIGNMENT - 1))) { |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 1273 | len = roundup(len, ALIGNMENT); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1274 | } |
| 1275 | |
| 1276 | do { |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 1277 | ret = brcmf_sdbrcm_send_buf(bus, brcmf_sdcard_cur_sbwad(card), |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1278 | SDIO_FUNC_2, F2SYNC, frame, len, pkt, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1279 | bus->f2txdata++; |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 1280 | ASSERT(ret != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1281 | |
| 1282 | if (ret < 0) { |
| 1283 | /* On failure, abort the command |
| 1284 | and terminate the frame */ |
| 1285 | DHD_INFO(("%s: sdio error %d, abort command and " |
| 1286 | "terminate frame.\n", __func__, ret)); |
| 1287 | bus->tx_sderrs++; |
| 1288 | |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 1289 | brcmf_sdcard_abort(card, SDIO_FUNC_2); |
| 1290 | brcmf_sdcard_cfg_write(card, SDIO_FUNC_1, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1291 | SBSDIO_FUNC1_FRAMECTRL, SFC_WF_TERM, |
| 1292 | NULL); |
| 1293 | bus->f1regdata++; |
| 1294 | |
| 1295 | for (i = 0; i < 3; i++) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1296 | u8 hi, lo; |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 1297 | hi = brcmf_sdcard_cfg_read(card, SDIO_FUNC_1, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1298 | SBSDIO_FUNC1_WFRAMEBCHI, |
| 1299 | NULL); |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 1300 | lo = brcmf_sdcard_cfg_read(card, SDIO_FUNC_1, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1301 | SBSDIO_FUNC1_WFRAMEBCLO, |
| 1302 | NULL); |
| 1303 | bus->f1regdata += 2; |
| 1304 | if ((hi == 0) && (lo == 0)) |
| 1305 | break; |
| 1306 | } |
| 1307 | |
| 1308 | } |
| 1309 | if (ret == 0) |
| 1310 | bus->tx_seq = (bus->tx_seq + 1) % SDPCM_SEQUENCE_WRAP; |
| 1311 | |
| 1312 | } while ((ret < 0) && retrydata && retries++ < TXRETRIES); |
| 1313 | |
| 1314 | done: |
| 1315 | /* restore pkt buffer pointer before calling tx complete routine */ |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 1316 | skb_pull(pkt, SDPCM_HDRLEN + pad); |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 1317 | brcmf_sdbrcm_sdunlock(bus); |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 1318 | brcmf_txcomplete(bus->dhd, pkt, ret != 0); |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 1319 | brcmf_sdbrcm_sdlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1320 | |
| 1321 | if (free_pkt) |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1322 | brcmu_pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1323 | |
| 1324 | return ret; |
| 1325 | } |
| 1326 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1327 | 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] | 1328 | { |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 1329 | int ret = -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1330 | uint datalen, prec; |
| 1331 | |
| 1332 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 1333 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1334 | datalen = pkt->len; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1335 | |
| 1336 | #ifdef SDTEST |
| 1337 | /* Push the test header if doing loopback */ |
| 1338 | if (bus->ext_loop) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1339 | u8 *data; |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 1340 | skb_push(pkt, SDPCM_TEST_HDRLEN); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1341 | data = pkt->data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1342 | *data++ = SDPCM_TEST_ECHOREQ; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1343 | *data++ = (u8) bus->loopid++; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1344 | *data++ = (datalen >> 0); |
| 1345 | *data++ = (datalen >> 8); |
| 1346 | datalen += SDPCM_TEST_HDRLEN; |
| 1347 | } |
| 1348 | #endif /* SDTEST */ |
| 1349 | |
| 1350 | /* Add space for the header */ |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 1351 | skb_push(pkt, SDPCM_HDRLEN); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1352 | ASSERT(IS_ALIGNED((unsigned long)(pkt->data), 2)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1353 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1354 | prec = PRIO2PREC((pkt->priority & PRIOMASK)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1355 | |
| 1356 | /* Check for existing queue, current flow-control, |
| 1357 | pending event, or pending clock */ |
Arend van Spriel | 7af9d0c | 2011-06-29 16:47:19 -0700 | [diff] [blame] | 1358 | if (brcmf_deferred_tx || bus->fcstate || pktq_len(&bus->txq) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1359 | || bus->dpc_sched || (!DATAOK(bus)) |
| 1360 | || (bus->flowcontrol & NBITVAL(prec)) |
| 1361 | || (bus->clkstate != CLK_AVAIL)) { |
| 1362 | DHD_TRACE(("%s: deferring pktq len %d\n", __func__, |
| 1363 | pktq_len(&bus->txq))); |
| 1364 | bus->fcqueued++; |
| 1365 | |
| 1366 | /* Priority based enq */ |
Franky Lin | 0f1a87c | 2011-06-29 16:46:32 -0700 | [diff] [blame] | 1367 | spin_lock_bh(&bus->txqlock); |
Arend van Spriel | aba5e0a | 2011-06-29 16:47:03 -0700 | [diff] [blame] | 1368 | 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] | 1369 | skb_pull(pkt, SDPCM_HDRLEN); |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 1370 | brcmf_txcomplete(bus->dhd, pkt, false); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1371 | brcmu_pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1372 | DHD_ERROR(("%s: out of bus->txq !!!\n", __func__)); |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 1373 | ret = -ENOSR; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1374 | } else { |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 1375 | ret = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1376 | } |
Franky Lin | 0f1a87c | 2011-06-29 16:46:32 -0700 | [diff] [blame] | 1377 | spin_unlock_bh(&bus->txqlock); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1378 | |
Grant Grundler | 7c31607 | 2011-03-09 15:04:15 -0800 | [diff] [blame] | 1379 | if (pktq_len(&bus->txq) >= TXHI) |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 1380 | brcmf_txflowcontrol(bus->dhd, 0, ON); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1381 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1382 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1383 | if (pktq_plen(&bus->txq, prec) > qcount[prec]) |
| 1384 | qcount[prec] = pktq_plen(&bus->txq, prec); |
| 1385 | #endif |
| 1386 | /* Schedule DPC if needed to send queued packet(s) */ |
Arend van Spriel | 7af9d0c | 2011-06-29 16:47:19 -0700 | [diff] [blame] | 1387 | if (brcmf_deferred_tx && !bus->dpc_sched) { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1388 | bus->dpc_sched = true; |
Franky Lin | 0827888 | 2011-06-29 16:47:45 -0700 | [diff] [blame] | 1389 | brcmf_sdbrcm_sched_dpc(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1390 | } |
| 1391 | } else { |
| 1392 | /* Lock: we're about to use shared data/code (and SDIO) */ |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 1393 | brcmf_sdbrcm_sdlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1394 | |
| 1395 | /* Otherwise, send it now */ |
| 1396 | BUS_WAKE(bus); |
| 1397 | /* Make sure back plane ht clk is on, no pending allowed */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1398 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1399 | |
| 1400 | #ifndef SDTEST |
| 1401 | DHD_TRACE(("%s: calling txpkt\n", __func__)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1402 | ret = brcmf_sdbrcm_txpkt(bus, pkt, SDPCM_DATA_CHANNEL, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1403 | #else |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1404 | ret = brcmf_sdbrcm_txpkt(bus, pkt, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1405 | (bus->ext_loop ? SDPCM_TEST_CHANNEL : |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1406 | SDPCM_DATA_CHANNEL), true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1407 | #endif |
| 1408 | if (ret) |
| 1409 | bus->dhd->tx_errors++; |
| 1410 | else |
| 1411 | bus->dhd->dstats.tx_bytes += datalen; |
| 1412 | |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 1413 | if (bus->idletime == BRCMF_IDLE_IMMEDIATE && |
| 1414 | !bus->dpc_sched) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1415 | bus->activity = false; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1416 | brcmf_sdbrcm_clkctl(bus, CLK_NONE, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1417 | } |
| 1418 | |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 1419 | brcmf_sdbrcm_sdunlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1420 | } |
| 1421 | |
| 1422 | return ret; |
| 1423 | } |
| 1424 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1425 | static uint brcmf_sdbrcm_sendfromq(dhd_bus_t *bus, uint maxframes) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1426 | { |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 1427 | struct sk_buff *pkt; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1428 | u32 intstatus = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1429 | uint retries = 0; |
| 1430 | int ret = 0, prec_out; |
| 1431 | uint cnt = 0; |
| 1432 | uint datalen; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1433 | u8 tx_prec_map; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1434 | |
Arend van Spriel | fb1d0aa | 2011-06-29 16:47:55 -0700 | [diff] [blame] | 1435 | struct brcmf_pub *dhd = bus->dhd; |
Franky Lin | 597600a | 2011-06-01 13:45:39 +0200 | [diff] [blame] | 1436 | struct sdpcmd_regs *regs = bus->regs; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1437 | |
| 1438 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 1439 | |
| 1440 | tx_prec_map = ~bus->flowcontrol; |
| 1441 | |
| 1442 | /* Send frames until the limit or some other event */ |
| 1443 | for (cnt = 0; (cnt < maxframes) && DATAOK(bus); cnt++) { |
Franky Lin | 0f1a87c | 2011-06-29 16:46:32 -0700 | [diff] [blame] | 1444 | spin_lock_bh(&bus->txqlock); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1445 | pkt = brcmu_pktq_mdeq(&bus->txq, tx_prec_map, &prec_out); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1446 | if (pkt == NULL) { |
Franky Lin | 0f1a87c | 2011-06-29 16:46:32 -0700 | [diff] [blame] | 1447 | spin_unlock_bh(&bus->txqlock); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1448 | break; |
| 1449 | } |
Franky Lin | 0f1a87c | 2011-06-29 16:46:32 -0700 | [diff] [blame] | 1450 | spin_unlock_bh(&bus->txqlock); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1451 | datalen = pkt->len - SDPCM_HDRLEN; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1452 | |
| 1453 | #ifndef SDTEST |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1454 | ret = brcmf_sdbrcm_txpkt(bus, pkt, SDPCM_DATA_CHANNEL, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1455 | #else |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1456 | ret = brcmf_sdbrcm_txpkt(bus, pkt, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1457 | (bus->ext_loop ? SDPCM_TEST_CHANNEL : |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1458 | SDPCM_DATA_CHANNEL), true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1459 | #endif |
| 1460 | if (ret) |
| 1461 | bus->dhd->tx_errors++; |
| 1462 | else |
| 1463 | bus->dhd->dstats.tx_bytes += datalen; |
| 1464 | |
| 1465 | /* In poll mode, need to check for other events */ |
| 1466 | if (!bus->intr && cnt) { |
| 1467 | /* Check device status, signal pending interrupt */ |
| 1468 | R_SDREG(intstatus, ®s->intstatus, retries); |
| 1469 | bus->f2txdata++; |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 1470 | if (brcmf_sdcard_regfail(bus->card)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1471 | break; |
| 1472 | if (intstatus & bus->hostintmask) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1473 | bus->ipend = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1474 | } |
| 1475 | } |
| 1476 | |
| 1477 | /* Deflow-control stack if needed */ |
Grant Grundler | 7c31607 | 2011-03-09 15:04:15 -0800 | [diff] [blame] | 1478 | if (dhd->up && (dhd->busstate == DHD_BUS_DATA) && |
Grant Grundler | 26a71a4 | 2011-03-09 10:41:25 -0800 | [diff] [blame] | 1479 | dhd->txoff && (pktq_len(&bus->txq) < TXLOW)) |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 1480 | brcmf_txflowcontrol(dhd, 0, OFF); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1481 | |
| 1482 | return cnt; |
| 1483 | } |
| 1484 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1485 | int |
| 1486 | 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] | 1487 | { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1488 | u8 *frame; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 1489 | u16 len; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1490 | u32 swheader; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1491 | uint retries = 0; |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 1492 | struct brcmf_sdio_card *card = bus->card; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1493 | u8 doff = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1494 | int ret = -1; |
| 1495 | int i; |
| 1496 | |
| 1497 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 1498 | |
| 1499 | if (bus->dhd->dongle_reset) |
| 1500 | return -EIO; |
| 1501 | |
| 1502 | /* Back the pointer to make a room for bus header */ |
| 1503 | frame = msg - SDPCM_HDRLEN; |
| 1504 | len = (msglen += SDPCM_HDRLEN); |
| 1505 | |
| 1506 | /* Add alignment padding (optional for ctl frames) */ |
| 1507 | if (dhd_alignctl) { |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 1508 | doff = ((unsigned long)frame % BRCMF_SDALIGN); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 1509 | if (doff) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1510 | frame -= doff; |
| 1511 | len += doff; |
| 1512 | msglen += doff; |
Brett Rudley | 9249ede | 2010-11-30 20:09:49 -0800 | [diff] [blame] | 1513 | memset(frame, 0, doff + SDPCM_HDRLEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1514 | } |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 1515 | ASSERT(doff < BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1516 | } |
| 1517 | doff += SDPCM_HDRLEN; |
| 1518 | |
| 1519 | /* Round send length to next SDIO block */ |
| 1520 | if (bus->roundup && bus->blocksize && (len > bus->blocksize)) { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 1521 | u16 pad = bus->blocksize - (len % bus->blocksize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1522 | if ((pad <= bus->roundup) && (pad < bus->blocksize)) |
| 1523 | len += pad; |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 1524 | } else if (len % BRCMF_SDALIGN) { |
| 1525 | len += BRCMF_SDALIGN - (len % BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1526 | } |
| 1527 | |
| 1528 | /* Satisfy length-alignment requirements */ |
| 1529 | if (forcealign && (len & (ALIGNMENT - 1))) |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 1530 | len = roundup(len, ALIGNMENT); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1531 | |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 1532 | ASSERT(IS_ALIGNED((unsigned long)frame, 2)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1533 | |
| 1534 | /* Need to lock here to protect txseq and SDIO tx calls */ |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 1535 | brcmf_sdbrcm_sdlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1536 | |
| 1537 | BUS_WAKE(bus); |
| 1538 | |
| 1539 | /* Make sure backplane clock is on */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1540 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1541 | |
| 1542 | /* 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] | 1543 | *(u16 *) frame = cpu_to_le16((u16) msglen); |
| 1544 | *(((u16 *) frame) + 1) = cpu_to_le16(~msglen); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1545 | |
| 1546 | /* Software tag: channel, sequence number, data offset */ |
| 1547 | swheader = |
| 1548 | ((SDPCM_CONTROL_CHANNEL << SDPCM_CHANNEL_SHIFT) & |
| 1549 | SDPCM_CHANNEL_MASK) |
| 1550 | | bus->tx_seq | ((doff << SDPCM_DOFFSET_SHIFT) & |
| 1551 | SDPCM_DOFFSET_MASK); |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 1552 | put_unaligned_le32(swheader, frame + SDPCM_FRAMETAG_LEN); |
| 1553 | put_unaligned_le32(0, frame + SDPCM_FRAMETAG_LEN + sizeof(swheader)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1554 | |
| 1555 | if (!DATAOK(bus)) { |
| 1556 | DHD_INFO(("%s: No bus credit bus->tx_max %d, bus->tx_seq %d\n", |
| 1557 | __func__, bus->tx_max, bus->tx_seq)); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1558 | bus->ctrl_frame_stat = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1559 | /* Send from dpc */ |
| 1560 | bus->ctrl_frame_buf = frame; |
| 1561 | bus->ctrl_frame_len = len; |
| 1562 | |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 1563 | brcmf_sdbrcm_wait_for_event(bus, &bus->ctrl_frame_stat); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1564 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1565 | if (bus->ctrl_frame_stat == false) { |
| 1566 | DHD_INFO(("%s: ctrl_frame_stat == false\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1567 | ret = 0; |
| 1568 | } else { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1569 | DHD_INFO(("%s: ctrl_frame_stat == true\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1570 | ret = -1; |
| 1571 | } |
| 1572 | } |
| 1573 | |
| 1574 | if (ret == -1) { |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1575 | #ifdef BCMDBG |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 1576 | if (DHD_BYTES_ON() && DHD_CTL_ON()) { |
| 1577 | printk(KERN_DEBUG "Tx Frame:\n"); |
| 1578 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 1579 | frame, len); |
| 1580 | } else if (DHD_HDRS_ON()) { |
| 1581 | printk(KERN_DEBUG "TxHdr:\n"); |
| 1582 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 1583 | frame, min_t(u16, len, 16)); |
| 1584 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1585 | #endif |
| 1586 | |
| 1587 | do { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1588 | bus->ctrl_frame_stat = false; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1589 | ret = brcmf_sdbrcm_send_buf(bus, |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 1590 | brcmf_sdcard_cur_sbwad(card), SDIO_FUNC_2, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1591 | F2SYNC, frame, len, NULL, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1592 | |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 1593 | ASSERT(ret != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1594 | |
| 1595 | if (ret < 0) { |
| 1596 | /* On failure, abort the command and |
| 1597 | terminate the frame */ |
| 1598 | DHD_INFO(("%s: sdio error %d, abort command and terminate frame.\n", |
| 1599 | __func__, ret)); |
| 1600 | bus->tx_sderrs++; |
| 1601 | |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 1602 | brcmf_sdcard_abort(card, SDIO_FUNC_2); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1603 | |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 1604 | brcmf_sdcard_cfg_write(card, SDIO_FUNC_1, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1605 | SBSDIO_FUNC1_FRAMECTRL, |
| 1606 | SFC_WF_TERM, NULL); |
| 1607 | bus->f1regdata++; |
| 1608 | |
| 1609 | for (i = 0; i < 3; i++) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1610 | u8 hi, lo; |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 1611 | hi = brcmf_sdcard_cfg_read(card, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1612 | SDIO_FUNC_1, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1613 | SBSDIO_FUNC1_WFRAMEBCHI, |
| 1614 | NULL); |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 1615 | lo = brcmf_sdcard_cfg_read(card, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1616 | SDIO_FUNC_1, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1617 | SBSDIO_FUNC1_WFRAMEBCLO, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1618 | NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1619 | bus->f1regdata += 2; |
| 1620 | if ((hi == 0) && (lo == 0)) |
| 1621 | break; |
| 1622 | } |
| 1623 | |
| 1624 | } |
| 1625 | if (ret == 0) { |
| 1626 | bus->tx_seq = |
| 1627 | (bus->tx_seq + 1) % SDPCM_SEQUENCE_WRAP; |
| 1628 | } |
| 1629 | } while ((ret < 0) && retries++ < TXRETRIES); |
| 1630 | } |
| 1631 | |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 1632 | if ((bus->idletime == BRCMF_IDLE_IMMEDIATE) && !bus->dpc_sched) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1633 | bus->activity = false; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1634 | brcmf_sdbrcm_clkctl(bus, CLK_NONE, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1635 | } |
| 1636 | |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 1637 | brcmf_sdbrcm_sdunlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1638 | |
| 1639 | if (ret) |
| 1640 | bus->dhd->tx_ctlerrs++; |
| 1641 | else |
| 1642 | bus->dhd->tx_ctlpkts++; |
| 1643 | |
| 1644 | return ret ? -EIO : 0; |
| 1645 | } |
| 1646 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1647 | 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] | 1648 | { |
| 1649 | int timeleft; |
| 1650 | uint rxlen = 0; |
| 1651 | bool pending; |
| 1652 | |
| 1653 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 1654 | |
| 1655 | if (bus->dhd->dongle_reset) |
| 1656 | return -EIO; |
| 1657 | |
| 1658 | /* Wait until control frame is available */ |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 1659 | timeleft = brcmf_os_ioctl_resp_wait(bus->dhd, &bus->rxlen, &pending); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1660 | |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 1661 | brcmf_sdbrcm_sdlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1662 | rxlen = bus->rxlen; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 1663 | memcpy(msg, bus->rxctl, min(msglen, rxlen)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1664 | bus->rxlen = 0; |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 1665 | brcmf_sdbrcm_sdunlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1666 | |
| 1667 | if (rxlen) { |
| 1668 | DHD_CTL(("%s: resumed on rxctl frame, got %d expected %d\n", |
| 1669 | __func__, rxlen, msglen)); |
| 1670 | } else if (timeleft == 0) { |
| 1671 | DHD_ERROR(("%s: resumed on timeout\n", __func__)); |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1672 | #ifdef BCMDBG |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 1673 | brcmf_sdbrcm_sdlock(bus); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1674 | brcmf_sdbrcm_checkdied(bus, NULL, 0); |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 1675 | brcmf_sdbrcm_sdunlock(bus); |
| 1676 | #endif /* DHD_DEBUG */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1677 | } else if (pending == true) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1678 | DHD_CTL(("%s: cancelled\n", __func__)); |
| 1679 | return -ERESTARTSYS; |
| 1680 | } else { |
| 1681 | DHD_CTL(("%s: resumed for unknown reason?\n", __func__)); |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1682 | #ifdef BCMDBG |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 1683 | brcmf_sdbrcm_sdlock(bus); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1684 | brcmf_sdbrcm_checkdied(bus, NULL, 0); |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 1685 | brcmf_sdbrcm_sdunlock(bus); |
| 1686 | #endif /* DHD_DEBUG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1687 | } |
| 1688 | |
| 1689 | if (rxlen) |
| 1690 | bus->dhd->rx_ctlpkts++; |
| 1691 | else |
| 1692 | bus->dhd->rx_ctlerrs++; |
| 1693 | |
Jason Cooper | e9887c9 | 2010-10-06 10:08:02 -0400 | [diff] [blame] | 1694 | return rxlen ? (int)rxlen : -ETIMEDOUT; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1695 | } |
| 1696 | |
| 1697 | /* IOVar table */ |
| 1698 | enum { |
| 1699 | IOV_INTR = 1, |
| 1700 | IOV_POLLRATE, |
| 1701 | IOV_SDREG, |
| 1702 | IOV_SBREG, |
| 1703 | IOV_SDCIS, |
| 1704 | IOV_MEMBYTES, |
| 1705 | IOV_MEMSIZE, |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1706 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1707 | IOV_CHECKDIED, |
Franky Lin | 913af5f | 2011-06-29 16:47:44 -0700 | [diff] [blame] | 1708 | IOV_CONS, |
| 1709 | IOV_DCONSOLE_POLL, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1710 | #endif |
| 1711 | IOV_DOWNLOAD, |
| 1712 | IOV_FORCEEVEN, |
| 1713 | IOV_SDIOD_DRIVE, |
| 1714 | IOV_READAHEAD, |
| 1715 | IOV_SDRXCHAIN, |
| 1716 | IOV_ALIGNCTL, |
| 1717 | IOV_SDALIGN, |
| 1718 | IOV_DEVRESET, |
| 1719 | IOV_CPU, |
| 1720 | #ifdef SDTEST |
| 1721 | IOV_PKTGEN, |
| 1722 | IOV_EXTLOOP, |
| 1723 | #endif /* SDTEST */ |
| 1724 | IOV_SPROM, |
| 1725 | IOV_TXBOUND, |
| 1726 | IOV_RXBOUND, |
| 1727 | IOV_TXMINMAX, |
| 1728 | IOV_IDLETIME, |
| 1729 | IOV_IDLECLOCK, |
| 1730 | IOV_SD1IDLE, |
| 1731 | IOV_SLEEP, |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 1732 | IOV_WDTICK, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1733 | IOV_VARS |
| 1734 | }; |
| 1735 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1736 | const struct brcmu_iovar dhdsdio_iovars[] = { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1737 | {"intr", IOV_INTR, 0, IOVT_BOOL, 0}, |
| 1738 | {"sleep", IOV_SLEEP, 0, IOVT_BOOL, 0}, |
| 1739 | {"pollrate", IOV_POLLRATE, 0, IOVT_UINT32, 0}, |
| 1740 | {"idletime", IOV_IDLETIME, 0, IOVT_INT32, 0}, |
| 1741 | {"idleclock", IOV_IDLECLOCK, 0, IOVT_INT32, 0}, |
| 1742 | {"sd1idle", IOV_SD1IDLE, 0, IOVT_BOOL, 0}, |
| 1743 | {"membytes", IOV_MEMBYTES, 0, IOVT_BUFFER, 2 * sizeof(int)}, |
| 1744 | {"memsize", IOV_MEMSIZE, 0, IOVT_UINT32, 0}, |
| 1745 | {"download", IOV_DOWNLOAD, 0, IOVT_BOOL, 0}, |
| 1746 | {"vars", IOV_VARS, 0, IOVT_BUFFER, 0}, |
| 1747 | {"sdiod_drive", IOV_SDIOD_DRIVE, 0, IOVT_UINT32, 0}, |
| 1748 | {"readahead", IOV_READAHEAD, 0, IOVT_BOOL, 0}, |
| 1749 | {"sdrxchain", IOV_SDRXCHAIN, 0, IOVT_BOOL, 0}, |
| 1750 | {"alignctl", IOV_ALIGNCTL, 0, IOVT_BOOL, 0}, |
| 1751 | {"sdalign", IOV_SDALIGN, 0, IOVT_BOOL, 0}, |
| 1752 | {"devreset", IOV_DEVRESET, 0, IOVT_BOOL, 0}, |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 1753 | {"wdtick", IOV_WDTICK, 0, IOVT_UINT32, 0}, |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1754 | #ifdef BCMDBG |
Franky Lin | 913af5f | 2011-06-29 16:47:44 -0700 | [diff] [blame] | 1755 | {"cons", IOV_CONS, 0, IOVT_BUFFER, 0} |
| 1756 | , |
| 1757 | {"dconpoll", IOV_DCONSOLE_POLL, 0, IOVT_UINT32, 0} |
| 1758 | , |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 1759 | {"sdreg", IOV_SDREG, 0, IOVT_BUFFER, sizeof(struct brcmf_sdreg)} |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1760 | , |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 1761 | {"sbreg", IOV_SBREG, 0, IOVT_BUFFER, sizeof(struct brcmf_sdreg)} |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1762 | , |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 1763 | {"sd_cis", IOV_SDCIS, 0, IOVT_BUFFER, BRCMF_IOCTL_MAXLEN} |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1764 | , |
| 1765 | {"forcealign", IOV_FORCEEVEN, 0, IOVT_BOOL, 0} |
| 1766 | , |
| 1767 | {"txbound", IOV_TXBOUND, 0, IOVT_UINT32, 0} |
| 1768 | , |
| 1769 | {"rxbound", IOV_RXBOUND, 0, IOVT_UINT32, 0} |
| 1770 | , |
| 1771 | {"txminmax", IOV_TXMINMAX, 0, IOVT_UINT32, 0} |
| 1772 | , |
| 1773 | {"cpu", IOV_CPU, 0, IOVT_BOOL, 0} |
| 1774 | , |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1775 | {"checkdied", IOV_CHECKDIED, 0, IOVT_BUFFER, 0} |
| 1776 | , |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1777 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1778 | #ifdef SDTEST |
| 1779 | {"extloop", IOV_EXTLOOP, 0, IOVT_BOOL, 0} |
| 1780 | , |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 1781 | {"pktgen", IOV_PKTGEN, 0, IOVT_BUFFER, sizeof(brcmf_pktgen_t)} |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1782 | , |
| 1783 | #endif /* SDTEST */ |
| 1784 | |
| 1785 | {NULL, 0, 0, 0, 0} |
| 1786 | }; |
| 1787 | |
| 1788 | static void |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1789 | 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] | 1790 | { |
| 1791 | uint q1, q2; |
| 1792 | |
| 1793 | if (!div) { |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1794 | brcmu_bprintf(strbuf, "%s N/A", desc); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1795 | } else { |
| 1796 | q1 = num / div; |
| 1797 | q2 = (100 * (num - (q1 * div))) / div; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1798 | brcmu_bprintf(strbuf, "%s %d.%02d", desc, q1, q2); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1799 | } |
| 1800 | } |
| 1801 | |
Arend van Spriel | fb1d0aa | 2011-06-29 16:47:55 -0700 | [diff] [blame] | 1802 | void brcmf_sdbrcm_bus_dump(struct brcmf_pub *dhdp, struct brcmu_strbuf *strbuf) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1803 | { |
| 1804 | dhd_bus_t *bus = dhdp->bus; |
| 1805 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1806 | brcmu_bprintf(strbuf, "Bus SDIO structure:\n"); |
| 1807 | brcmu_bprintf(strbuf, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1808 | "hostintmask 0x%08x intstatus 0x%08x sdpcm_ver %d\n", |
| 1809 | bus->hostintmask, bus->intstatus, bus->sdpcm_ver); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1810 | brcmu_bprintf(strbuf, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1811 | "fcstate %d qlen %d tx_seq %d, max %d, rxskip %d rxlen %d rx_seq %d\n", |
| 1812 | bus->fcstate, pktq_len(&bus->txq), bus->tx_seq, bus->tx_max, |
| 1813 | bus->rxskip, bus->rxlen, bus->rx_seq); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1814 | brcmu_bprintf(strbuf, "intr %d intrcount %d lastintrs %d spurious %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1815 | bus->intr, bus->intrcount, bus->lastintrs, bus->spurious); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1816 | brcmu_bprintf(strbuf, "pollrate %d pollcnt %d regfails %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1817 | bus->pollrate, bus->pollcnt, bus->regfails); |
| 1818 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1819 | brcmu_bprintf(strbuf, "\nAdditional counters:\n"); |
| 1820 | brcmu_bprintf(strbuf, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1821 | "tx_sderrs %d fcqueued %d rxrtx %d rx_toolong %d rxc_errors %d\n", |
| 1822 | bus->tx_sderrs, bus->fcqueued, bus->rxrtx, bus->rx_toolong, |
| 1823 | bus->rxc_errors); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1824 | brcmu_bprintf(strbuf, "rx_hdrfail %d badhdr %d badseq %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1825 | bus->rx_hdrfail, bus->rx_badhdr, bus->rx_badseq); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1826 | brcmu_bprintf(strbuf, "fc_rcvd %d, fc_xoff %d, fc_xon %d\n", |
| 1827 | bus->fc_rcvd, bus->fc_xoff, bus->fc_xon); |
| 1828 | brcmu_bprintf(strbuf, "rxglomfail %d, rxglomframes %d, rxglompkts %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1829 | bus->rxglomfail, bus->rxglomframes, bus->rxglompkts); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1830 | brcmu_bprintf(strbuf, "f2rx (hdrs/data) %d (%d/%d), f2tx %d f1regs" |
| 1831 | " %d\n", |
| 1832 | (bus->f2rxhdrs + bus->f2rxdata), bus->f2rxhdrs, |
| 1833 | bus->f2rxdata, bus->f2txdata, bus->f1regdata); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1834 | { |
| 1835 | dhd_dump_pct(strbuf, "\nRx: pkts/f2rd", bus->dhd->rx_packets, |
| 1836 | (bus->f2rxhdrs + bus->f2rxdata)); |
| 1837 | dhd_dump_pct(strbuf, ", pkts/f1sd", bus->dhd->rx_packets, |
| 1838 | bus->f1regdata); |
| 1839 | dhd_dump_pct(strbuf, ", pkts/sd", bus->dhd->rx_packets, |
| 1840 | (bus->f2rxhdrs + bus->f2rxdata + bus->f1regdata)); |
| 1841 | dhd_dump_pct(strbuf, ", pkts/int", bus->dhd->rx_packets, |
| 1842 | bus->intrcount); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1843 | brcmu_bprintf(strbuf, "\n"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1844 | |
| 1845 | dhd_dump_pct(strbuf, "Rx: glom pct", (100 * bus->rxglompkts), |
| 1846 | bus->dhd->rx_packets); |
| 1847 | dhd_dump_pct(strbuf, ", pkts/glom", bus->rxglompkts, |
| 1848 | bus->rxglomframes); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1849 | brcmu_bprintf(strbuf, "\n"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1850 | |
| 1851 | dhd_dump_pct(strbuf, "Tx: pkts/f2wr", bus->dhd->tx_packets, |
| 1852 | bus->f2txdata); |
| 1853 | dhd_dump_pct(strbuf, ", pkts/f1sd", bus->dhd->tx_packets, |
| 1854 | bus->f1regdata); |
| 1855 | dhd_dump_pct(strbuf, ", pkts/sd", bus->dhd->tx_packets, |
| 1856 | (bus->f2txdata + bus->f1regdata)); |
| 1857 | dhd_dump_pct(strbuf, ", pkts/int", bus->dhd->tx_packets, |
| 1858 | bus->intrcount); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1859 | brcmu_bprintf(strbuf, "\n"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1860 | |
| 1861 | dhd_dump_pct(strbuf, "Total: pkts/f2rw", |
| 1862 | (bus->dhd->tx_packets + bus->dhd->rx_packets), |
| 1863 | (bus->f2txdata + bus->f2rxhdrs + bus->f2rxdata)); |
| 1864 | dhd_dump_pct(strbuf, ", pkts/f1sd", |
| 1865 | (bus->dhd->tx_packets + bus->dhd->rx_packets), |
| 1866 | bus->f1regdata); |
| 1867 | dhd_dump_pct(strbuf, ", pkts/sd", |
| 1868 | (bus->dhd->tx_packets + bus->dhd->rx_packets), |
| 1869 | (bus->f2txdata + bus->f2rxhdrs + bus->f2rxdata + |
| 1870 | bus->f1regdata)); |
| 1871 | dhd_dump_pct(strbuf, ", pkts/int", |
| 1872 | (bus->dhd->tx_packets + bus->dhd->rx_packets), |
| 1873 | bus->intrcount); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1874 | brcmu_bprintf(strbuf, "\n\n"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1875 | } |
| 1876 | |
| 1877 | #ifdef SDTEST |
| 1878 | if (bus->pktgen_count) { |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1879 | brcmu_bprintf(strbuf, "pktgen config and count:\n"); |
| 1880 | brcmu_bprintf(strbuf, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1881 | "freq %d count %d print %d total %d min %d len %d\n", |
| 1882 | bus->pktgen_freq, bus->pktgen_count, |
| 1883 | bus->pktgen_print, bus->pktgen_total, |
| 1884 | bus->pktgen_minlen, bus->pktgen_maxlen); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1885 | brcmu_bprintf(strbuf, "send attempts %d rcvd %d fail %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1886 | bus->pktgen_sent, bus->pktgen_rcvd, |
| 1887 | bus->pktgen_fail); |
| 1888 | } |
| 1889 | #endif /* SDTEST */ |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1890 | #ifdef BCMDBG |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1891 | brcmu_bprintf(strbuf, "dpc_sched %d host interrupt%spending\n", |
Roland Vossen | 7d72d30 | 2011-07-05 22:05:59 +0200 | [diff] [blame^] | 1892 | bus->dpc_sched, " not "); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1893 | brcmu_bprintf(strbuf, "blocksize %d roundup %d\n", bus->blocksize, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1894 | bus->roundup); |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1895 | #endif /* BCMDBG */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1896 | brcmu_bprintf(strbuf, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1897 | "clkstate %d activity %d idletime %d idlecount %d sleeping %d\n", |
| 1898 | bus->clkstate, bus->activity, bus->idletime, bus->idlecount, |
| 1899 | bus->sleeping); |
| 1900 | } |
| 1901 | |
Arend van Spriel | fb1d0aa | 2011-06-29 16:47:55 -0700 | [diff] [blame] | 1902 | void dhd_bus_clearcounts(struct brcmf_pub *dhdp) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1903 | { |
| 1904 | dhd_bus_t *bus = (dhd_bus_t *) dhdp->bus; |
| 1905 | |
| 1906 | bus->intrcount = bus->lastintrs = bus->spurious = bus->regfails = 0; |
| 1907 | bus->rxrtx = bus->rx_toolong = bus->rxc_errors = 0; |
| 1908 | bus->rx_hdrfail = bus->rx_badhdr = bus->rx_badseq = 0; |
| 1909 | bus->tx_sderrs = bus->fc_rcvd = bus->fc_xoff = bus->fc_xon = 0; |
| 1910 | bus->rxglomfail = bus->rxglomframes = bus->rxglompkts = 0; |
| 1911 | bus->f2rxhdrs = bus->f2rxdata = bus->f2txdata = bus->f1regdata = 0; |
| 1912 | } |
| 1913 | |
| 1914 | #ifdef SDTEST |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1915 | static int brcmf_sdbrcm_pktgen_get(dhd_bus_t *bus, u8 *arg) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1916 | { |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 1917 | brcmf_pktgen_t pktgen; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1918 | |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 1919 | pktgen.version = BRCMF_PKTGEN_VERSION; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1920 | pktgen.freq = bus->pktgen_freq; |
| 1921 | pktgen.count = bus->pktgen_count; |
| 1922 | pktgen.print = bus->pktgen_print; |
| 1923 | pktgen.total = bus->pktgen_total; |
| 1924 | pktgen.minlen = bus->pktgen_minlen; |
| 1925 | pktgen.maxlen = bus->pktgen_maxlen; |
| 1926 | pktgen.numsent = bus->pktgen_sent; |
| 1927 | pktgen.numrcvd = bus->pktgen_rcvd; |
| 1928 | pktgen.numfail = bus->pktgen_fail; |
| 1929 | pktgen.mode = bus->pktgen_mode; |
| 1930 | pktgen.stop = bus->pktgen_stop; |
| 1931 | |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 1932 | memcpy(arg, &pktgen, sizeof(pktgen)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1933 | |
| 1934 | return 0; |
| 1935 | } |
| 1936 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1937 | static int brcmf_sdbrcm_pktgen_set(dhd_bus_t *bus, u8 *arg) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1938 | { |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 1939 | brcmf_pktgen_t pktgen; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1940 | uint oldcnt, oldmode; |
| 1941 | |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 1942 | memcpy(&pktgen, arg, sizeof(pktgen)); |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 1943 | if (pktgen.version != BRCMF_PKTGEN_VERSION) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 1944 | return -EINVAL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1945 | |
| 1946 | oldcnt = bus->pktgen_count; |
| 1947 | oldmode = bus->pktgen_mode; |
| 1948 | |
| 1949 | bus->pktgen_freq = pktgen.freq; |
| 1950 | bus->pktgen_count = pktgen.count; |
| 1951 | bus->pktgen_print = pktgen.print; |
| 1952 | bus->pktgen_total = pktgen.total; |
| 1953 | bus->pktgen_minlen = pktgen.minlen; |
| 1954 | bus->pktgen_maxlen = pktgen.maxlen; |
| 1955 | bus->pktgen_mode = pktgen.mode; |
| 1956 | bus->pktgen_stop = pktgen.stop; |
| 1957 | |
| 1958 | bus->pktgen_tick = bus->pktgen_ptick = 0; |
Greg Kroah-Hartman | 3ea2f4d | 2010-10-08 11:39:43 -0700 | [diff] [blame] | 1959 | bus->pktgen_len = max(bus->pktgen_len, bus->pktgen_minlen); |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 1960 | bus->pktgen_len = min(bus->pktgen_len, bus->pktgen_maxlen); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1961 | |
| 1962 | /* Clear counts for a new pktgen (mode change, or was stopped) */ |
| 1963 | if (bus->pktgen_count && (!oldcnt || oldmode != bus->pktgen_mode)) |
| 1964 | bus->pktgen_sent = bus->pktgen_rcvd = bus->pktgen_fail = 0; |
| 1965 | |
| 1966 | return 0; |
| 1967 | } |
| 1968 | #endif /* SDTEST */ |
| 1969 | |
| 1970 | static int |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1971 | 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] | 1972 | uint size) |
| 1973 | { |
| 1974 | int bcmerror = 0; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1975 | u32 sdaddr; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1976 | uint dsize; |
| 1977 | |
| 1978 | /* Determine initial transfer parameters */ |
| 1979 | sdaddr = address & SBSDIO_SB_OFT_ADDR_MASK; |
| 1980 | if ((sdaddr + size) & SBSDIO_SBWINDOW_MASK) |
| 1981 | dsize = (SBSDIO_SB_OFT_ADDR_LIMIT - sdaddr); |
| 1982 | else |
| 1983 | dsize = size; |
| 1984 | |
| 1985 | /* Set the backplane window to include the start address */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1986 | bcmerror = brcmf_sdbrcm_set_siaddr_window(bus, address); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1987 | if (bcmerror) { |
| 1988 | DHD_ERROR(("%s: window change failed\n", __func__)); |
| 1989 | goto xfer_done; |
| 1990 | } |
| 1991 | |
| 1992 | /* Do the transfer(s) */ |
| 1993 | while (size) { |
| 1994 | DHD_INFO(("%s: %s %d bytes at offset 0x%08x in window 0x%08x\n", |
| 1995 | __func__, (write ? "write" : "read"), dsize, |
| 1996 | sdaddr, (address & SBSDIO_SBWINDOW_MASK))); |
| 1997 | bcmerror = |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 1998 | brcmf_sdcard_rwdata(bus->card, write, sdaddr, data, dsize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1999 | if (bcmerror) { |
| 2000 | DHD_ERROR(("%s: membytes transfer failed\n", __func__)); |
| 2001 | break; |
| 2002 | } |
| 2003 | |
| 2004 | /* Adjust for next transfer (if any) */ |
| 2005 | size -= dsize; |
| 2006 | if (size) { |
| 2007 | data += dsize; |
| 2008 | address += dsize; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2009 | bcmerror = brcmf_sdbrcm_set_siaddr_window(bus, address); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2010 | if (bcmerror) { |
| 2011 | DHD_ERROR(("%s: window change failed\n", |
| 2012 | __func__)); |
| 2013 | break; |
| 2014 | } |
| 2015 | sdaddr = 0; |
Greg Kroah-Hartman | b61640d | 2010-10-08 12:37:39 -0700 | [diff] [blame] | 2016 | dsize = min_t(uint, SBSDIO_SB_OFT_ADDR_LIMIT, size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2017 | } |
| 2018 | } |
| 2019 | |
| 2020 | xfer_done: |
| 2021 | /* Return the window to backplane enumeration space for core access */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2022 | if (brcmf_sdbrcm_set_siaddr_window(bus, |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 2023 | brcmf_sdcard_cur_sbwad(bus->card))) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2024 | DHD_ERROR(("%s: FAILED to set window back to 0x%x\n", |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 2025 | __func__, brcmf_sdcard_cur_sbwad(bus->card))); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2026 | } |
| 2027 | |
| 2028 | return bcmerror; |
| 2029 | } |
| 2030 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 2031 | #ifdef BCMDBG |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2032 | 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] | 2033 | { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2034 | u32 addr; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2035 | int rv; |
| 2036 | |
| 2037 | /* Read last word in memory to determine address of |
| 2038 | sdpcm_shared structure */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2039 | rv = brcmf_sdbrcm_membytes(bus, false, bus->ramsize - 4, (u8 *)&addr, |
| 2040 | 4); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2041 | if (rv < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2042 | return rv; |
| 2043 | |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 2044 | addr = le32_to_cpu(addr); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2045 | |
| 2046 | DHD_INFO(("sdpcm_shared address 0x%08X\n", addr)); |
| 2047 | |
| 2048 | /* |
| 2049 | * Check if addr is valid. |
| 2050 | * NVRAM length at the end of memory should have been overwritten. |
| 2051 | */ |
| 2052 | if (addr == 0 || ((~addr >> 16) & 0xffff) == (addr & 0xffff)) { |
| 2053 | DHD_ERROR(("%s: address (0x%08x) of sdpcm_shared invalid\n", |
| 2054 | __func__, addr)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2055 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2056 | } |
| 2057 | |
Roland Vossen | 70963f9 | 2011-06-01 13:45:08 +0200 | [diff] [blame] | 2058 | /* Read rte_shared structure */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2059 | rv = brcmf_sdbrcm_membytes(bus, false, addr, (u8 *) sh, |
Franky Lin | b49b14d | 2011-06-01 13:45:37 +0200 | [diff] [blame] | 2060 | sizeof(struct sdpcm_shared)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2061 | if (rv < 0) |
| 2062 | return rv; |
| 2063 | |
| 2064 | /* Endianness */ |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 2065 | sh->flags = le32_to_cpu(sh->flags); |
| 2066 | sh->trap_addr = le32_to_cpu(sh->trap_addr); |
| 2067 | sh->assert_exp_addr = le32_to_cpu(sh->assert_exp_addr); |
| 2068 | sh->assert_file_addr = le32_to_cpu(sh->assert_file_addr); |
| 2069 | sh->assert_line = le32_to_cpu(sh->assert_line); |
| 2070 | sh->console_addr = le32_to_cpu(sh->console_addr); |
| 2071 | sh->msgtrace_addr = le32_to_cpu(sh->msgtrace_addr); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2072 | |
| 2073 | if ((sh->flags & SDPCM_SHARED_VERSION_MASK) != SDPCM_SHARED_VERSION) { |
| 2074 | DHD_ERROR(("%s: sdpcm_shared version %d in dhd " |
| 2075 | "is different than sdpcm_shared version %d in dongle\n", |
| 2076 | __func__, SDPCM_SHARED_VERSION, |
| 2077 | sh->flags & SDPCM_SHARED_VERSION_MASK)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2078 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2079 | } |
| 2080 | |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 2081 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2082 | } |
| 2083 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2084 | 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] | 2085 | { |
| 2086 | int bcmerror = 0; |
| 2087 | uint msize = 512; |
| 2088 | char *mbuffer = NULL; |
| 2089 | uint maxstrlen = 256; |
| 2090 | char *str = NULL; |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 2091 | struct brcmf_trap tr; |
Franky Lin | b49b14d | 2011-06-01 13:45:37 +0200 | [diff] [blame] | 2092 | struct sdpcm_shared sdpcm_shared; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2093 | struct brcmu_strbuf strbuf; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2094 | |
| 2095 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 2096 | |
| 2097 | if (data == NULL) { |
| 2098 | /* |
| 2099 | * Called after a rx ctrl timeout. "data" is NULL. |
| 2100 | * allocate memory to trace the trap or assert. |
| 2101 | */ |
| 2102 | size = msize; |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2103 | mbuffer = data = kmalloc(msize, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2104 | if (mbuffer == NULL) { |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2105 | DHD_ERROR(("%s: kmalloc(%d) failed\n", __func__, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2106 | msize)); |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2107 | bcmerror = -ENOMEM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2108 | goto done; |
| 2109 | } |
| 2110 | } |
| 2111 | |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2112 | str = kmalloc(maxstrlen, GFP_ATOMIC); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2113 | if (str == NULL) { |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2114 | DHD_ERROR(("%s: kmalloc(%d) failed\n", __func__, maxstrlen)); |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2115 | bcmerror = -ENOMEM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2116 | goto done; |
| 2117 | } |
| 2118 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2119 | bcmerror = brcmf_sdbrcm_readshared(bus, &sdpcm_shared); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2120 | if (bcmerror < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2121 | goto done; |
| 2122 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2123 | brcmu_binit(&strbuf, data, size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2124 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2125 | brcmu_bprintf(&strbuf, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2126 | "msgtrace address : 0x%08X\nconsole address : 0x%08X\n", |
| 2127 | sdpcm_shared.msgtrace_addr, sdpcm_shared.console_addr); |
| 2128 | |
| 2129 | if ((sdpcm_shared.flags & SDPCM_SHARED_ASSERT_BUILT) == 0) { |
| 2130 | /* NOTE: Misspelled assert is intentional - DO NOT FIX. |
| 2131 | * (Avoids conflict with real asserts for programmatic |
| 2132 | * parsing of output.) |
| 2133 | */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2134 | brcmu_bprintf(&strbuf, "Assrt not built in dongle\n"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2135 | } |
| 2136 | |
| 2137 | if ((sdpcm_shared.flags & (SDPCM_SHARED_ASSERT | SDPCM_SHARED_TRAP)) == |
| 2138 | 0) { |
| 2139 | /* NOTE: Misspelled assert is intentional - DO NOT FIX. |
| 2140 | * (Avoids conflict with real asserts for programmatic |
| 2141 | * parsing of output.) |
| 2142 | */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2143 | brcmu_bprintf(&strbuf, "No trap%s in dongle", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2144 | (sdpcm_shared.flags & SDPCM_SHARED_ASSERT_BUILT) |
| 2145 | ? "/assrt" : ""); |
| 2146 | } else { |
| 2147 | if (sdpcm_shared.flags & SDPCM_SHARED_ASSERT) { |
| 2148 | /* Download assert */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2149 | brcmu_bprintf(&strbuf, "Dongle assert"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2150 | if (sdpcm_shared.assert_exp_addr != 0) { |
| 2151 | str[0] = '\0'; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2152 | bcmerror = brcmf_sdbrcm_membytes(bus, false, |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2153 | sdpcm_shared.assert_exp_addr, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2154 | (u8 *) str, maxstrlen); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2155 | if (bcmerror < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2156 | goto done; |
| 2157 | |
| 2158 | str[maxstrlen - 1] = '\0'; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2159 | brcmu_bprintf(&strbuf, " expr \"%s\"", str); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2160 | } |
| 2161 | |
| 2162 | if (sdpcm_shared.assert_file_addr != 0) { |
| 2163 | str[0] = '\0'; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2164 | bcmerror = brcmf_sdbrcm_membytes(bus, false, |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2165 | sdpcm_shared.assert_file_addr, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2166 | (u8 *) str, maxstrlen); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2167 | if (bcmerror < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2168 | goto done; |
| 2169 | |
| 2170 | str[maxstrlen - 1] = '\0'; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2171 | brcmu_bprintf(&strbuf, " file \"%s\"", str); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2172 | } |
| 2173 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2174 | brcmu_bprintf(&strbuf, " line %d ", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2175 | sdpcm_shared.assert_line); |
| 2176 | } |
| 2177 | |
| 2178 | if (sdpcm_shared.flags & SDPCM_SHARED_TRAP) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2179 | bcmerror = brcmf_sdbrcm_membytes(bus, false, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2180 | sdpcm_shared.trap_addr, (u8 *)&tr, |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 2181 | sizeof(struct brcmf_trap)); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2182 | if (bcmerror < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2183 | goto done; |
| 2184 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2185 | brcmu_bprintf(&strbuf, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2186 | "Dongle trap type 0x%x @ epc 0x%x, cpsr 0x%x, spsr 0x%x, sp 0x%x," |
| 2187 | "lp 0x%x, rpc 0x%x Trap offset 0x%x, " |
| 2188 | "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", |
| 2189 | tr.type, tr.epc, tr.cpsr, tr.spsr, tr.r13, |
| 2190 | tr.r14, tr.pc, sdpcm_shared.trap_addr, |
| 2191 | tr.r0, tr.r1, tr.r2, tr.r3, tr.r4, tr.r5, |
| 2192 | tr.r6, tr.r7); |
| 2193 | } |
| 2194 | } |
| 2195 | |
| 2196 | if (sdpcm_shared.flags & (SDPCM_SHARED_ASSERT | SDPCM_SHARED_TRAP)) |
| 2197 | DHD_ERROR(("%s: %s\n", __func__, strbuf.origbuf)); |
| 2198 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 2199 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2200 | if (sdpcm_shared.flags & SDPCM_SHARED_TRAP) { |
| 2201 | /* Mem dump to a file on device */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2202 | brcmf_sdbrcm_mem_dump(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2203 | } |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 2204 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2205 | |
| 2206 | done: |
Ilia Mirkin | 46d994b | 2011-03-13 00:28:56 -0500 | [diff] [blame] | 2207 | kfree(mbuffer); |
| 2208 | kfree(str); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2209 | |
| 2210 | return bcmerror; |
| 2211 | } |
| 2212 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2213 | static int brcmf_sdbrcm_mem_dump(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2214 | { |
| 2215 | int ret = 0; |
| 2216 | int size; /* Full mem size */ |
| 2217 | int start = 0; /* Start address */ |
| 2218 | int read_size = 0; /* Read size of each iteration */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2219 | u8 *buf = NULL, *databuf = NULL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2220 | |
| 2221 | /* Get full mem size */ |
| 2222 | size = bus->ramsize; |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2223 | buf = kmalloc(size, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2224 | if (!buf) { |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 2225 | DHD_ERROR(("%s: Out of memory (%d bytes)\n", __func__, size)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2226 | return -1; |
| 2227 | } |
| 2228 | |
| 2229 | /* Read mem content */ |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 2230 | printk(KERN_DEBUG "Dump dongle memory"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2231 | databuf = buf; |
| 2232 | while (size) { |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 2233 | read_size = min(MEMBLOCK, size); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2234 | ret = brcmf_sdbrcm_membytes(bus, false, start, databuf, |
| 2235 | read_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2236 | if (ret) { |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 2237 | DHD_ERROR(("%s: Error membytes %d\n", __func__, ret)); |
Ilia Mirkin | 46d994b | 2011-03-13 00:28:56 -0500 | [diff] [blame] | 2238 | kfree(buf); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2239 | return -1; |
| 2240 | } |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 2241 | printk("."); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2242 | |
| 2243 | /* Decrement size and increment start address */ |
| 2244 | size -= read_size; |
| 2245 | start += read_size; |
| 2246 | databuf += read_size; |
| 2247 | } |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 2248 | printk(KERN_DEBUG "Done\n"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2249 | |
| 2250 | /* free buf before return !!! */ |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 2251 | if (brcmf_write_to_file(bus->dhd, buf, bus->ramsize)) { |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 2252 | DHD_ERROR(("%s: Error writing to files\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2253 | return -1; |
| 2254 | } |
| 2255 | |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 2256 | /* buf free handled in brcmf_write_to_file, not here */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2257 | return 0; |
| 2258 | } |
| 2259 | |
| 2260 | #define CONSOLE_LINE_MAX 192 |
| 2261 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2262 | static int brcmf_sdbrcm_readconsole(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2263 | { |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 2264 | struct dhd_console *c = &bus->console; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2265 | u8 line[CONSOLE_LINE_MAX], ch; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2266 | u32 n, idx, addr; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2267 | int rv; |
| 2268 | |
| 2269 | /* Don't do anything until FWREADY updates console address */ |
| 2270 | if (bus->console_addr == 0) |
| 2271 | return 0; |
| 2272 | |
| 2273 | /* Read console log struct */ |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 2274 | addr = bus->console_addr + offsetof(struct rte_console, log); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2275 | rv = brcmf_sdbrcm_membytes(bus, false, addr, (u8 *)&c->log, |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2276 | sizeof(c->log)); |
| 2277 | if (rv < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2278 | return rv; |
| 2279 | |
| 2280 | /* Allocate console buffer (one time only) */ |
| 2281 | if (c->buf == NULL) { |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 2282 | c->bufsize = le32_to_cpu(c->log.buf_size); |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2283 | c->buf = kmalloc(c->bufsize, GFP_ATOMIC); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2284 | if (c->buf == NULL) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2285 | return -ENOMEM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2286 | } |
| 2287 | |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 2288 | idx = le32_to_cpu(c->log.idx); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2289 | |
| 2290 | /* Protect against corrupt value */ |
| 2291 | if (idx > c->bufsize) |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2292 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2293 | |
| 2294 | /* Skip reading the console buffer if the index pointer |
| 2295 | has not moved */ |
| 2296 | if (idx == c->last) |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 2297 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2298 | |
| 2299 | /* Read the console buffer */ |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 2300 | addr = le32_to_cpu(c->log.buf); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2301 | rv = brcmf_sdbrcm_membytes(bus, false, addr, c->buf, c->bufsize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2302 | if (rv < 0) |
| 2303 | return rv; |
| 2304 | |
| 2305 | while (c->last != idx) { |
| 2306 | for (n = 0; n < CONSOLE_LINE_MAX - 2; n++) { |
| 2307 | if (c->last == idx) { |
| 2308 | /* This would output a partial line. |
| 2309 | * Instead, back up |
| 2310 | * the buffer pointer and output this |
| 2311 | * line next time around. |
| 2312 | */ |
| 2313 | if (c->last >= n) |
| 2314 | c->last -= n; |
| 2315 | else |
| 2316 | c->last = c->bufsize - n; |
| 2317 | goto break2; |
| 2318 | } |
| 2319 | ch = c->buf[c->last]; |
| 2320 | c->last = (c->last + 1) % c->bufsize; |
| 2321 | if (ch == '\n') |
| 2322 | break; |
| 2323 | line[n] = ch; |
| 2324 | } |
| 2325 | |
| 2326 | if (n > 0) { |
| 2327 | if (line[n - 1] == '\r') |
| 2328 | n--; |
| 2329 | line[n] = 0; |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 2330 | printk(KERN_DEBUG "CONSOLE: %s\n", line); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2331 | } |
| 2332 | } |
| 2333 | break2: |
| 2334 | |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 2335 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2336 | } |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 2337 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2338 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2339 | int brcmf_sdbrcm_downloadvars(dhd_bus_t *bus, void *arg, int len) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2340 | { |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 2341 | int bcmerror = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2342 | |
| 2343 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 2344 | |
| 2345 | /* Basic sanity checks */ |
| 2346 | if (bus->dhd->up) { |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2347 | bcmerror = -EISCONN; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2348 | goto err; |
| 2349 | } |
| 2350 | if (!len) { |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2351 | bcmerror = -EOVERFLOW; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2352 | goto err; |
| 2353 | } |
| 2354 | |
| 2355 | /* Free the old ones and replace with passed variables */ |
Ilia Mirkin | 46d994b | 2011-03-13 00:28:56 -0500 | [diff] [blame] | 2356 | kfree(bus->vars); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2357 | |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2358 | bus->vars = kmalloc(len, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2359 | bus->varsz = bus->vars ? len : 0; |
| 2360 | if (bus->vars == NULL) { |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2361 | bcmerror = -ENOMEM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2362 | goto err; |
| 2363 | } |
| 2364 | |
| 2365 | /* Copy the passed variables, which should include the |
| 2366 | terminating double-null */ |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2367 | memcpy(bus->vars, arg, bus->varsz); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2368 | err: |
| 2369 | return bcmerror; |
| 2370 | } |
| 2371 | |
| 2372 | static int |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2373 | 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] | 2374 | const char *name, void *params, int plen, void *arg, int len, |
| 2375 | int val_size) |
| 2376 | { |
| 2377 | int bcmerror = 0; |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2378 | s32 int_val = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2379 | bool bool_val = 0; |
| 2380 | |
| 2381 | DHD_TRACE(("%s: Enter, action %d name %s params %p plen %d arg %p " |
| 2382 | "len %d val_size %d\n", |
| 2383 | __func__, actionid, name, params, plen, arg, len, val_size)); |
| 2384 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2385 | bcmerror = brcmu_iovar_lencheck(vi, arg, len, IOV_ISSET(actionid)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2386 | if (bcmerror != 0) |
| 2387 | goto exit; |
| 2388 | |
| 2389 | if (plen >= (int)sizeof(int_val)) |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2390 | memcpy(&int_val, params, sizeof(int_val)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2391 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2392 | bool_val = (int_val != 0) ? true : false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2393 | |
| 2394 | /* Some ioctls use the bus */ |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 2395 | brcmf_sdbrcm_sdlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2396 | |
| 2397 | /* Check if dongle is in reset. If so, only allow DEVRESET iovars */ |
| 2398 | if (bus->dhd->dongle_reset && !(actionid == IOV_SVAL(IOV_DEVRESET) || |
| 2399 | actionid == IOV_GVAL(IOV_DEVRESET))) { |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2400 | bcmerror = -EPERM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2401 | goto exit; |
| 2402 | } |
| 2403 | |
| 2404 | /* Handle sleep stuff before any clock mucking */ |
| 2405 | if (vi->varid == IOV_SLEEP) { |
| 2406 | if (IOV_ISSET(actionid)) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2407 | bcmerror = brcmf_sdbrcm_bussleep(bus, bool_val); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2408 | } else { |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2409 | int_val = (s32) bus->sleeping; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2410 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2411 | } |
| 2412 | goto exit; |
| 2413 | } |
| 2414 | |
| 2415 | /* Request clock to allow SDIO accesses */ |
| 2416 | if (!bus->dhd->dongle_reset) { |
| 2417 | BUS_WAKE(bus); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2418 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2419 | } |
| 2420 | |
| 2421 | switch (actionid) { |
| 2422 | case IOV_GVAL(IOV_INTR): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2423 | int_val = (s32) bus->intr; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2424 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2425 | break; |
| 2426 | |
| 2427 | case IOV_SVAL(IOV_INTR): |
| 2428 | bus->intr = bool_val; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2429 | bus->intdis = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2430 | if (bus->dhd->up) { |
| 2431 | if (bus->intr) { |
| 2432 | DHD_INTR(("%s: enable SDIO device interrupts\n", |
| 2433 | __func__)); |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 2434 | brcmf_sdcard_intr_enable(bus->card); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2435 | } else { |
| 2436 | DHD_INTR(("%s: disable SDIO interrupts\n", |
| 2437 | __func__)); |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 2438 | brcmf_sdcard_intr_disable(bus->card); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2439 | } |
| 2440 | } |
| 2441 | break; |
| 2442 | |
| 2443 | case IOV_GVAL(IOV_POLLRATE): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2444 | int_val = (s32) bus->pollrate; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2445 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2446 | break; |
| 2447 | |
| 2448 | case IOV_SVAL(IOV_POLLRATE): |
| 2449 | bus->pollrate = (uint) int_val; |
| 2450 | bus->poll = (bus->pollrate != 0); |
| 2451 | break; |
| 2452 | |
| 2453 | case IOV_GVAL(IOV_IDLETIME): |
| 2454 | int_val = bus->idletime; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2455 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2456 | break; |
| 2457 | |
| 2458 | case IOV_SVAL(IOV_IDLETIME): |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 2459 | if ((int_val < 0) && (int_val != BRCMF_IDLE_IMMEDIATE)) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2460 | bcmerror = -EINVAL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2461 | else |
| 2462 | bus->idletime = int_val; |
| 2463 | break; |
| 2464 | |
| 2465 | case IOV_GVAL(IOV_IDLECLOCK): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2466 | int_val = (s32) bus->idleclock; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2467 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2468 | break; |
| 2469 | |
| 2470 | case IOV_SVAL(IOV_IDLECLOCK): |
| 2471 | bus->idleclock = int_val; |
| 2472 | break; |
| 2473 | |
| 2474 | case IOV_GVAL(IOV_SD1IDLE): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2475 | int_val = (s32) sd1idle; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2476 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2477 | break; |
| 2478 | |
| 2479 | case IOV_SVAL(IOV_SD1IDLE): |
| 2480 | sd1idle = bool_val; |
| 2481 | break; |
| 2482 | |
| 2483 | case IOV_SVAL(IOV_MEMBYTES): |
| 2484 | case IOV_GVAL(IOV_MEMBYTES): |
| 2485 | { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2486 | u32 address; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2487 | uint size, dsize; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2488 | u8 *data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2489 | |
| 2490 | bool set = (actionid == IOV_SVAL(IOV_MEMBYTES)); |
| 2491 | |
| 2492 | ASSERT(plen >= 2 * sizeof(int)); |
| 2493 | |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2494 | address = (u32) int_val; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2495 | memcpy(&int_val, (char *)params + sizeof(int_val), |
| 2496 | sizeof(int_val)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2497 | size = (uint) int_val; |
| 2498 | |
| 2499 | /* Do some validation */ |
| 2500 | dsize = set ? plen - (2 * sizeof(int)) : len; |
| 2501 | if (dsize < size) { |
| 2502 | DHD_ERROR(("%s: error on %s membytes, addr " |
| 2503 | "0x%08x size %d dsize %d\n", |
| 2504 | __func__, (set ? "set" : "get"), |
| 2505 | address, size, dsize)); |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2506 | bcmerror = -EINVAL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2507 | break; |
| 2508 | } |
| 2509 | |
| 2510 | DHD_INFO(("%s: Request to %s %d bytes at address " |
| 2511 | "0x%08x\n", |
| 2512 | __func__, (set ? "write" : "read"), size, address)); |
| 2513 | |
| 2514 | /* If we know about SOCRAM, check for a fit */ |
| 2515 | if ((bus->orig_ramsize) && |
| 2516 | ((address > bus->orig_ramsize) |
| 2517 | || (address + size > bus->orig_ramsize))) { |
| 2518 | DHD_ERROR(("%s: ramsize 0x%08x doesn't have %d " |
| 2519 | "bytes at 0x%08x\n", |
| 2520 | __func__, bus->orig_ramsize, size, address)); |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2521 | bcmerror = -EINVAL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2522 | break; |
| 2523 | } |
| 2524 | |
| 2525 | /* Generate the actual data pointer */ |
| 2526 | data = |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2527 | set ? (u8 *) params + |
| 2528 | 2 * sizeof(int) : (u8 *) arg; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2529 | |
| 2530 | /* Call to do the transfer */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2531 | bcmerror = brcmf_sdbrcm_membytes(bus, set, address, |
| 2532 | data, size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2533 | |
| 2534 | break; |
| 2535 | } |
| 2536 | |
| 2537 | case IOV_GVAL(IOV_MEMSIZE): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2538 | int_val = (s32) bus->ramsize; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2539 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2540 | break; |
| 2541 | |
| 2542 | case IOV_GVAL(IOV_SDIOD_DRIVE): |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 2543 | int_val = (s32) brcmf_sdiod_drive_strength; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2544 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2545 | break; |
| 2546 | |
| 2547 | case IOV_SVAL(IOV_SDIOD_DRIVE): |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 2548 | brcmf_sdiod_drive_strength = int_val; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2549 | brcmf_sdbrcm_sdiod_drive_strength_init(bus, |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 2550 | brcmf_sdiod_drive_strength); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2551 | break; |
| 2552 | |
| 2553 | case IOV_SVAL(IOV_DOWNLOAD): |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2554 | bcmerror = brcmf_sdbrcm_download_state(bus, bool_val); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2555 | break; |
| 2556 | |
| 2557 | case IOV_SVAL(IOV_VARS): |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2558 | bcmerror = brcmf_sdbrcm_downloadvars(bus, arg, len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2559 | break; |
| 2560 | |
| 2561 | case IOV_GVAL(IOV_READAHEAD): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2562 | int_val = (s32) dhd_readahead; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2563 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2564 | break; |
| 2565 | |
| 2566 | case IOV_SVAL(IOV_READAHEAD): |
| 2567 | if (bool_val && !dhd_readahead) |
| 2568 | bus->nextlen = 0; |
| 2569 | dhd_readahead = bool_val; |
| 2570 | break; |
| 2571 | |
| 2572 | case IOV_GVAL(IOV_SDRXCHAIN): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2573 | int_val = (s32) bus->use_rxchain; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2574 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2575 | break; |
| 2576 | |
| 2577 | case IOV_SVAL(IOV_SDRXCHAIN): |
| 2578 | if (bool_val && !bus->sd_rxchain) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2579 | bcmerror = -ENOTSUPP; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2580 | else |
| 2581 | bus->use_rxchain = bool_val; |
| 2582 | break; |
| 2583 | case IOV_GVAL(IOV_ALIGNCTL): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2584 | int_val = (s32) dhd_alignctl; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2585 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2586 | break; |
| 2587 | |
| 2588 | case IOV_SVAL(IOV_ALIGNCTL): |
| 2589 | dhd_alignctl = bool_val; |
| 2590 | break; |
| 2591 | |
| 2592 | case IOV_GVAL(IOV_SDALIGN): |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 2593 | int_val = BRCMF_SDALIGN; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2594 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2595 | break; |
| 2596 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 2597 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2598 | case IOV_GVAL(IOV_VARS): |
| 2599 | if (bus->varsz < (uint) len) |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2600 | memcpy(arg, bus->vars, bus->varsz); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2601 | else |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2602 | bcmerror = -EOVERFLOW; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2603 | break; |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 2604 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2605 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 2606 | #ifdef BCMDBG |
Franky Lin | 913af5f | 2011-06-29 16:47:44 -0700 | [diff] [blame] | 2607 | case IOV_GVAL(IOV_DCONSOLE_POLL): |
| 2608 | int_val = (s32) brcmf_console_ms; |
| 2609 | memcpy(arg, &int_val, val_size); |
| 2610 | break; |
| 2611 | |
| 2612 | case IOV_SVAL(IOV_DCONSOLE_POLL): |
| 2613 | brcmf_console_ms = (uint) int_val; |
| 2614 | break; |
| 2615 | |
| 2616 | case IOV_SVAL(IOV_CONS): |
| 2617 | if (len > 0) |
| 2618 | bcmerror = brcmf_sdbrcm_bus_console_in(bus->dhd, |
| 2619 | arg, len - 1); |
| 2620 | break; |
| 2621 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2622 | case IOV_GVAL(IOV_SDREG): |
| 2623 | { |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 2624 | struct brcmf_sdreg *sd_ptr; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2625 | u32 addr, size; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2626 | |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 2627 | sd_ptr = (struct brcmf_sdreg *) params; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2628 | |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 2629 | addr = (unsigned long)bus->regs + sd_ptr->offset; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2630 | size = sd_ptr->func; |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 2631 | int_val = (s32) brcmf_sdcard_reg_read(bus->card, addr, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2632 | size); |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 2633 | if (brcmf_sdcard_regfail(bus->card)) |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2634 | bcmerror = -EIO; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2635 | memcpy(arg, &int_val, sizeof(s32)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2636 | break; |
| 2637 | } |
| 2638 | |
| 2639 | case IOV_SVAL(IOV_SDREG): |
| 2640 | { |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 2641 | struct brcmf_sdreg *sd_ptr; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2642 | u32 addr, size; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2643 | |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 2644 | sd_ptr = (struct brcmf_sdreg *) params; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2645 | |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 2646 | addr = (unsigned long)bus->regs + sd_ptr->offset; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2647 | size = sd_ptr->func; |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 2648 | brcmf_sdcard_reg_write(bus->card, addr, size, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2649 | sd_ptr->value); |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 2650 | if (brcmf_sdcard_regfail(bus->card)) |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2651 | bcmerror = -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2652 | break; |
| 2653 | } |
| 2654 | |
| 2655 | /* Same as above, but offset is not backplane |
| 2656 | (not SDIO core) */ |
| 2657 | case IOV_GVAL(IOV_SBREG): |
| 2658 | { |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 2659 | struct brcmf_sdreg sdreg; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2660 | u32 addr, size; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2661 | |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2662 | memcpy(&sdreg, params, sizeof(sdreg)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2663 | |
| 2664 | addr = SI_ENUM_BASE + sdreg.offset; |
| 2665 | size = sdreg.func; |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 2666 | int_val = (s32) brcmf_sdcard_reg_read(bus->card, addr, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2667 | size); |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 2668 | if (brcmf_sdcard_regfail(bus->card)) |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2669 | bcmerror = -EIO; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2670 | memcpy(arg, &int_val, sizeof(s32)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2671 | break; |
| 2672 | } |
| 2673 | |
| 2674 | case IOV_SVAL(IOV_SBREG): |
| 2675 | { |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 2676 | struct brcmf_sdreg sdreg; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2677 | u32 addr, size; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2678 | |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2679 | memcpy(&sdreg, params, sizeof(sdreg)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2680 | |
| 2681 | addr = SI_ENUM_BASE + sdreg.offset; |
| 2682 | size = sdreg.func; |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 2683 | brcmf_sdcard_reg_write(bus->card, addr, size, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2684 | sdreg.value); |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 2685 | if (brcmf_sdcard_regfail(bus->card)) |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2686 | bcmerror = -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2687 | break; |
| 2688 | } |
| 2689 | |
| 2690 | case IOV_GVAL(IOV_SDCIS): |
| 2691 | { |
| 2692 | *(char *)arg = 0; |
| 2693 | |
nohee ko | ea3b8a2 | 2010-10-09 10:34:38 -0700 | [diff] [blame] | 2694 | strcat(arg, "\nFunc 0\n"); |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 2695 | brcmf_sdcard_cis_read(bus->card, 0x10, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2696 | (u8 *) arg + strlen(arg), |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2697 | SBSDIO_CIS_SIZE_LIMIT); |
nohee ko | ea3b8a2 | 2010-10-09 10:34:38 -0700 | [diff] [blame] | 2698 | strcat(arg, "\nFunc 1\n"); |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 2699 | brcmf_sdcard_cis_read(bus->card, 0x11, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2700 | (u8 *) arg + strlen(arg), |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2701 | SBSDIO_CIS_SIZE_LIMIT); |
nohee ko | ea3b8a2 | 2010-10-09 10:34:38 -0700 | [diff] [blame] | 2702 | strcat(arg, "\nFunc 2\n"); |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 2703 | brcmf_sdcard_cis_read(bus->card, 0x12, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2704 | (u8 *) arg + strlen(arg), |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2705 | SBSDIO_CIS_SIZE_LIMIT); |
| 2706 | break; |
| 2707 | } |
| 2708 | |
| 2709 | case IOV_GVAL(IOV_FORCEEVEN): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2710 | int_val = (s32) forcealign; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2711 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2712 | break; |
| 2713 | |
| 2714 | case IOV_SVAL(IOV_FORCEEVEN): |
| 2715 | forcealign = bool_val; |
| 2716 | break; |
| 2717 | |
| 2718 | case IOV_GVAL(IOV_TXBOUND): |
Arend van Spriel | 7af9d0c | 2011-06-29 16:47:19 -0700 | [diff] [blame] | 2719 | int_val = (s32) brcmf_txbound; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2720 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2721 | break; |
| 2722 | |
| 2723 | case IOV_SVAL(IOV_TXBOUND): |
Arend van Spriel | 7af9d0c | 2011-06-29 16:47:19 -0700 | [diff] [blame] | 2724 | brcmf_txbound = (uint) int_val; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2725 | break; |
| 2726 | |
| 2727 | case IOV_GVAL(IOV_RXBOUND): |
Arend van Spriel | 7af9d0c | 2011-06-29 16:47:19 -0700 | [diff] [blame] | 2728 | int_val = (s32) brcmf_rxbound; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2729 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2730 | break; |
| 2731 | |
| 2732 | case IOV_SVAL(IOV_RXBOUND): |
Arend van Spriel | 7af9d0c | 2011-06-29 16:47:19 -0700 | [diff] [blame] | 2733 | brcmf_rxbound = (uint) int_val; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2734 | break; |
| 2735 | |
| 2736 | case IOV_GVAL(IOV_TXMINMAX): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2737 | int_val = (s32) dhd_txminmax; |
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_TXMINMAX): |
| 2742 | dhd_txminmax = (uint) int_val; |
| 2743 | break; |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 2744 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2745 | |
| 2746 | #ifdef SDTEST |
| 2747 | case IOV_GVAL(IOV_EXTLOOP): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2748 | int_val = (s32) bus->ext_loop; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2749 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2750 | break; |
| 2751 | |
| 2752 | case IOV_SVAL(IOV_EXTLOOP): |
| 2753 | bus->ext_loop = bool_val; |
| 2754 | break; |
| 2755 | |
| 2756 | case IOV_GVAL(IOV_PKTGEN): |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2757 | bcmerror = brcmf_sdbrcm_pktgen_get(bus, arg); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2758 | break; |
| 2759 | |
| 2760 | case IOV_SVAL(IOV_PKTGEN): |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2761 | bcmerror = brcmf_sdbrcm_pktgen_set(bus, arg); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2762 | break; |
| 2763 | #endif /* SDTEST */ |
| 2764 | |
| 2765 | case IOV_SVAL(IOV_DEVRESET): |
| 2766 | DHD_TRACE(("%s: Called set IOV_DEVRESET=%d dongle_reset=%d " |
| 2767 | "busstate=%d\n", |
| 2768 | __func__, bool_val, bus->dhd->dongle_reset, |
| 2769 | bus->dhd->busstate)); |
| 2770 | |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 2771 | brcmf_bus_devreset(bus->dhd, (u8) bool_val); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2772 | |
| 2773 | break; |
| 2774 | |
| 2775 | case IOV_GVAL(IOV_DEVRESET): |
| 2776 | DHD_TRACE(("%s: Called get IOV_DEVRESET\n", __func__)); |
| 2777 | |
| 2778 | /* Get its status */ |
| 2779 | int_val = (bool) bus->dhd->dongle_reset; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2780 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2781 | |
| 2782 | break; |
| 2783 | |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 2784 | case IOV_GVAL(IOV_WDTICK): |
| 2785 | int_val = (s32) brcmf_watchdog_ms; |
| 2786 | memcpy(arg, &int_val, val_size); |
| 2787 | break; |
| 2788 | |
| 2789 | case IOV_SVAL(IOV_WDTICK): |
| 2790 | if (!bus->dhd->up) { |
| 2791 | bcmerror = -ENOLINK; |
| 2792 | break; |
| 2793 | } |
| 2794 | brcmf_sdbrcm_wd_timer(bus, (uint) int_val); |
| 2795 | break; |
| 2796 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2797 | default: |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2798 | bcmerror = -ENOTSUPP; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2799 | break; |
| 2800 | } |
| 2801 | |
| 2802 | exit: |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 2803 | if ((bus->idletime == BRCMF_IDLE_IMMEDIATE) && !bus->dpc_sched) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2804 | bus->activity = false; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2805 | brcmf_sdbrcm_clkctl(bus, CLK_NONE, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2806 | } |
| 2807 | |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 2808 | brcmf_sdbrcm_sdunlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2809 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2810 | if (actionid == IOV_SVAL(IOV_DEVRESET) && bool_val == false) |
Arend van Spriel | fb1d0aa | 2011-06-29 16:47:55 -0700 | [diff] [blame] | 2811 | brcmf_c_preinit_ioctls((struct brcmf_pub *) bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2812 | |
| 2813 | return bcmerror; |
| 2814 | } |
| 2815 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2816 | static int brcmf_sdbrcm_write_vars(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2817 | { |
| 2818 | int bcmerror = 0; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2819 | u32 varsize; |
| 2820 | u32 varaddr; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2821 | u8 *vbuffer; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2822 | u32 varsizew; |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 2823 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2824 | char *nvram_ularray; |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 2825 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2826 | |
| 2827 | /* Even if there are no vars are to be written, we still |
| 2828 | need to set the ramsize. */ |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 2829 | varsize = bus->varsz ? roundup(bus->varsz, 4) : 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2830 | varaddr = (bus->ramsize - 4) - varsize; |
| 2831 | |
| 2832 | if (bus->vars) { |
Alexander Beregalov | 12d0eb4 | 2011-03-09 03:53:35 +0300 | [diff] [blame] | 2833 | vbuffer = kzalloc(varsize, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2834 | if (!vbuffer) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2835 | return -ENOMEM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2836 | |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2837 | memcpy(vbuffer, bus->vars, bus->varsz); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2838 | |
| 2839 | /* Write the vars list */ |
| 2840 | bcmerror = |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2841 | brcmf_sdbrcm_membytes(bus, true, varaddr, vbuffer, varsize); |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 2842 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2843 | /* Verify NVRAM bytes */ |
| 2844 | DHD_INFO(("Compare NVRAM dl & ul; varsize=%d\n", varsize)); |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2845 | nvram_ularray = kmalloc(varsize, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2846 | if (!nvram_ularray) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2847 | return -ENOMEM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2848 | |
| 2849 | /* Upload image to verify downloaded contents. */ |
| 2850 | memset(nvram_ularray, 0xaa, varsize); |
| 2851 | |
| 2852 | /* Read the vars list to temp buffer for comparison */ |
| 2853 | bcmerror = |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2854 | brcmf_sdbrcm_membytes(bus, false, varaddr, nvram_ularray, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2855 | varsize); |
| 2856 | if (bcmerror) { |
| 2857 | DHD_ERROR(("%s: error %d on reading %d nvram bytes at " |
| 2858 | "0x%08x\n", __func__, bcmerror, varsize, varaddr)); |
| 2859 | } |
| 2860 | /* Compare the org NVRAM with the one read from RAM */ |
| 2861 | if (memcmp(vbuffer, nvram_ularray, varsize)) { |
| 2862 | DHD_ERROR(("%s: Downloaded NVRAM image is corrupted.\n", |
| 2863 | __func__)); |
| 2864 | } else |
| 2865 | DHD_ERROR(("%s: Download/Upload/Compare of NVRAM ok.\n", |
| 2866 | __func__)); |
| 2867 | |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 2868 | kfree(nvram_ularray); |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 2869 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2870 | |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 2871 | kfree(vbuffer); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2872 | } |
| 2873 | |
| 2874 | /* adjust to the user specified RAM */ |
| 2875 | DHD_INFO(("Physical memory size: %d, usable memory size: %d\n", |
| 2876 | bus->orig_ramsize, bus->ramsize)); |
| 2877 | DHD_INFO(("Vars are at %d, orig varsize is %d\n", varaddr, varsize)); |
| 2878 | varsize = ((bus->orig_ramsize - 4) - varaddr); |
| 2879 | |
| 2880 | /* |
| 2881 | * Determine the length token: |
| 2882 | * Varsize, converted to words, in lower 16-bits, checksum |
| 2883 | * in upper 16-bits. |
| 2884 | */ |
| 2885 | if (bcmerror) { |
| 2886 | varsizew = 0; |
| 2887 | } else { |
| 2888 | varsizew = varsize / 4; |
| 2889 | varsizew = (~varsizew << 16) | (varsizew & 0x0000FFFF); |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 2890 | varsizew = cpu_to_le32(varsizew); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2891 | } |
| 2892 | |
| 2893 | DHD_INFO(("New varsize is %d, length token=0x%08x\n", varsize, |
| 2894 | varsizew)); |
| 2895 | |
| 2896 | /* Write the length token to the last word */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2897 | bcmerror = brcmf_sdbrcm_membytes(bus, true, (bus->orig_ramsize - 4), |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2898 | (u8 *)&varsizew, 4); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2899 | |
| 2900 | return bcmerror; |
| 2901 | } |
| 2902 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2903 | static int brcmf_sdbrcm_download_state(dhd_bus_t *bus, bool enter) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2904 | { |
| 2905 | uint retries; |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 2906 | u32 regdata; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2907 | int bcmerror = 0; |
| 2908 | |
| 2909 | /* To enter download state, disable ARM and reset SOCRAM. |
| 2910 | * To exit download state, simply reset ARM (default is RAM boot). |
| 2911 | */ |
| 2912 | if (enter) { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2913 | bus->alp_only = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2914 | |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 2915 | brcmf_sdbrcm_chip_disablecore(bus->card, bus->ci->armcorebase); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2916 | |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 2917 | brcmf_sdbrcm_chip_resetcore(bus->card, bus->ci->ramcorebase); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2918 | |
| 2919 | /* Clear the top bit of memory */ |
| 2920 | if (bus->ramsize) { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2921 | u32 zeros = 0; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2922 | brcmf_sdbrcm_membytes(bus, true, bus->ramsize - 4, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2923 | (u8 *)&zeros, 4); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2924 | } |
| 2925 | } else { |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 2926 | regdata = brcmf_sdcard_reg_read(bus->card, |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 2927 | CORE_SB(bus->ci->ramcorebase, sbtmstatelow), 4); |
| 2928 | regdata &= (SBTML_RESET | SBTML_REJ_MASK | |
| 2929 | (SICF_CLOCK_EN << SBTML_SICF_SHIFT)); |
| 2930 | if ((SICF_CLOCK_EN << SBTML_SICF_SHIFT) != regdata) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2931 | DHD_ERROR(("%s: SOCRAM core is down after reset?\n", |
| 2932 | __func__)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2933 | bcmerror = -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2934 | goto fail; |
| 2935 | } |
| 2936 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2937 | bcmerror = brcmf_sdbrcm_write_vars(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2938 | if (bcmerror) { |
| 2939 | DHD_ERROR(("%s: no vars written to RAM\n", __func__)); |
| 2940 | bcmerror = 0; |
| 2941 | } |
| 2942 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2943 | W_SDREG(0xFFFFFFFF, &bus->regs->intstatus, retries); |
| 2944 | |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 2945 | brcmf_sdbrcm_chip_resetcore(bus->card, bus->ci->armcorebase); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2946 | |
| 2947 | /* Allow HT Clock now that the ARM is running. */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2948 | bus->alp_only = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2949 | |
| 2950 | bus->dhd->busstate = DHD_BUS_LOAD; |
| 2951 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2952 | fail: |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2953 | return bcmerror; |
| 2954 | } |
| 2955 | |
| 2956 | int |
Arend van Spriel | fb1d0aa | 2011-06-29 16:47:55 -0700 | [diff] [blame] | 2957 | brcmf_sdbrcm_bus_iovar_op(struct brcmf_pub *dhdp, const char *name, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2958 | void *params, int plen, void *arg, int len, bool set) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2959 | { |
| 2960 | dhd_bus_t *bus = dhdp->bus; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2961 | const struct brcmu_iovar *vi = NULL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2962 | int bcmerror = 0; |
| 2963 | int val_size; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2964 | u32 actionid; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2965 | |
| 2966 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 2967 | |
| 2968 | ASSERT(name); |
| 2969 | ASSERT(len >= 0); |
| 2970 | |
| 2971 | /* Get MUST have return space */ |
| 2972 | ASSERT(set || (arg && len)); |
| 2973 | |
| 2974 | /* Set does NOT take qualifiers */ |
| 2975 | ASSERT(!set || (!params && !plen)); |
| 2976 | |
| 2977 | /* Look up var locally; if not found pass to host driver */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2978 | vi = brcmu_iovar_lookup(dhdsdio_iovars, name); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2979 | if (vi == NULL) { |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 2980 | brcmf_sdbrcm_sdlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2981 | |
| 2982 | BUS_WAKE(bus); |
| 2983 | |
| 2984 | /* Turn on clock in case SD command needs backplane */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2985 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2986 | |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 2987 | bcmerror = brcmf_sdcard_iovar_op(bus->card, name, params, plen, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2988 | arg, len, set); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2989 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2990 | /* Similar check for blocksize change */ |
| 2991 | if (set && strcmp(name, "sd_blocksize") == 0) { |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2992 | s32 fnum = 2; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2993 | if (brcmf_sdcard_iovar_op |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 2994 | (bus->card, "sd_blocksize", &fnum, sizeof(s32), |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2995 | &bus->blocksize, sizeof(s32), |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 2996 | false) != 0) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2997 | bus->blocksize = 0; |
| 2998 | DHD_ERROR(("%s: fail on %s get\n", __func__, |
| 2999 | "sd_blocksize")); |
| 3000 | } else { |
| 3001 | DHD_INFO(("%s: noted %s update, value now %d\n", |
| 3002 | __func__, "sd_blocksize", |
| 3003 | bus->blocksize)); |
| 3004 | } |
| 3005 | } |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 3006 | bus->roundup = min(max_roundup, bus->blocksize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3007 | |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 3008 | if (bus->idletime == BRCMF_IDLE_IMMEDIATE && |
| 3009 | !bus->dpc_sched) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3010 | bus->activity = false; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3011 | brcmf_sdbrcm_clkctl(bus, CLK_NONE, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3012 | } |
| 3013 | |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 3014 | brcmf_sdbrcm_sdunlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3015 | goto exit; |
| 3016 | } |
| 3017 | |
| 3018 | DHD_CTL(("%s: %s %s, len %d plen %d\n", __func__, |
| 3019 | name, (set ? "set" : "get"), len, plen)); |
| 3020 | |
| 3021 | /* set up 'params' pointer in case this is a set command so that |
| 3022 | * the convenience int and bool code can be common to set and get |
| 3023 | */ |
| 3024 | if (params == NULL) { |
| 3025 | params = arg; |
| 3026 | plen = len; |
| 3027 | } |
| 3028 | |
| 3029 | if (vi->type == IOVT_VOID) |
| 3030 | val_size = 0; |
| 3031 | else if (vi->type == IOVT_BUFFER) |
| 3032 | val_size = len; |
| 3033 | else |
| 3034 | /* all other types are integer sized */ |
| 3035 | val_size = sizeof(int); |
| 3036 | |
| 3037 | actionid = set ? IOV_SVAL(vi->varid) : IOV_GVAL(vi->varid); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3038 | bcmerror = brcmf_sdbrcm_doiovar(bus, vi, actionid, name, params, plen, |
| 3039 | arg, len, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3040 | |
| 3041 | exit: |
| 3042 | return bcmerror; |
| 3043 | } |
| 3044 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3045 | void brcmf_sdbrcm_bus_stop(struct dhd_bus *bus, bool enforce_mutex) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3046 | { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 3047 | u32 local_hostintmask; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3048 | u8 saveclk; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3049 | uint retries; |
| 3050 | int err; |
| 3051 | |
| 3052 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 3053 | |
| 3054 | if (enforce_mutex) |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 3055 | brcmf_sdbrcm_sdlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3056 | |
| 3057 | BUS_WAKE(bus); |
| 3058 | |
| 3059 | /* Enable clock for device interrupts */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3060 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3061 | |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 3062 | if (bus->watchdog_tsk) { |
| 3063 | send_sig(SIGTERM, bus->watchdog_tsk, 1); |
| 3064 | kthread_stop(bus->watchdog_tsk); |
| 3065 | bus->watchdog_tsk = NULL; |
| 3066 | } |
| 3067 | |
Franky Lin | 0827888 | 2011-06-29 16:47:45 -0700 | [diff] [blame] | 3068 | if (bus->dpc_tsk) { |
| 3069 | send_sig(SIGTERM, bus->dpc_tsk, 1); |
| 3070 | kthread_stop(bus->dpc_tsk); |
| 3071 | bus->dpc_tsk = NULL; |
| 3072 | } else |
| 3073 | tasklet_kill(&bus->tasklet); |
| 3074 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3075 | /* Disable and clear interrupts at the chip level also */ |
| 3076 | W_SDREG(0, &bus->regs->hostintmask, retries); |
| 3077 | local_hostintmask = bus->hostintmask; |
| 3078 | bus->hostintmask = 0; |
| 3079 | |
| 3080 | /* Change our idea of bus state */ |
| 3081 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 3082 | |
| 3083 | /* Force clocks on backplane to be sure F2 interrupt propagates */ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 3084 | saveclk = brcmf_sdcard_cfg_read(bus->card, SDIO_FUNC_1, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3085 | SBSDIO_FUNC1_CHIPCLKCSR, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3086 | if (!err) { |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 3087 | brcmf_sdcard_cfg_write(bus->card, SDIO_FUNC_1, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3088 | SBSDIO_FUNC1_CHIPCLKCSR, |
| 3089 | (saveclk | SBSDIO_FORCE_HT), &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3090 | } |
| 3091 | if (err) { |
| 3092 | DHD_ERROR(("%s: Failed to force clock for F2: err %d\n", |
| 3093 | __func__, err)); |
| 3094 | } |
| 3095 | |
| 3096 | /* Turn off the bus (F2), free any pending packets */ |
| 3097 | DHD_INTR(("%s: disable SDIO interrupts\n", __func__)); |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 3098 | brcmf_sdcard_intr_disable(bus->card); |
| 3099 | brcmf_sdcard_cfg_write(bus->card, SDIO_FUNC_0, SDIO_CCCR_IOEx, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3100 | SDIO_FUNC_ENABLE_1, NULL); |
| 3101 | |
| 3102 | /* Clear any pending interrupts now that F2 is disabled */ |
| 3103 | W_SDREG(local_hostintmask, &bus->regs->intstatus, retries); |
| 3104 | |
| 3105 | /* Turn off the backplane clock (only) */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3106 | brcmf_sdbrcm_clkctl(bus, CLK_SDONLY, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3107 | |
| 3108 | /* Clear the data packet queues */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3109 | brcmu_pktq_flush(&bus->txq, true, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3110 | |
| 3111 | /* Clear any held glomming stuff */ |
| 3112 | if (bus->glomd) |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3113 | brcmu_pkt_buf_free_skb(bus->glomd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3114 | |
| 3115 | if (bus->glom) |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3116 | brcmu_pkt_buf_free_skb(bus->glom); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3117 | |
| 3118 | bus->glom = bus->glomd = NULL; |
| 3119 | |
| 3120 | /* Clear rx control and wake any waiters */ |
| 3121 | bus->rxlen = 0; |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 3122 | brcmf_os_ioctl_resp_wake(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3123 | |
| 3124 | /* Reset some F2 state stuff */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3125 | bus->rxskip = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3126 | bus->tx_seq = bus->rx_seq = 0; |
| 3127 | |
| 3128 | if (enforce_mutex) |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 3129 | brcmf_sdbrcm_sdunlock(bus); |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 3130 | |
| 3131 | #if defined(OOB_INTR_ONLY) |
| 3132 | brcmf_sdio_unregister_oob_intr(); |
| 3133 | #endif /* defined(OOB_INTR_ONLY) */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3134 | } |
| 3135 | |
Arend van Spriel | fb1d0aa | 2011-06-29 16:47:55 -0700 | [diff] [blame] | 3136 | int brcmf_sdbrcm_bus_init(struct brcmf_pub *dhdp, bool enforce_mutex) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3137 | { |
| 3138 | dhd_bus_t *bus = dhdp->bus; |
Arend van Spriel | bb26354 | 2011-06-29 16:47:53 -0700 | [diff] [blame] | 3139 | struct brcmf_timeout tmo; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3140 | uint retries = 0; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3141 | u8 ready, enable; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3142 | int err, ret = 0; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3143 | u8 saveclk; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3144 | |
| 3145 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 3146 | |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 3147 | /* try to download image and nvram to the dongle */ |
| 3148 | if (dhdp->busstate == DHD_BUS_DOWN) { |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 3149 | if (!(brcmf_sdbrcm_download_firmware(bus, bus->card))) |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 3150 | return -1; |
| 3151 | } |
| 3152 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3153 | ASSERT(bus->dhd); |
| 3154 | if (!bus->dhd) |
| 3155 | return 0; |
| 3156 | |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 3157 | /* Start the watchdog timer */ |
| 3158 | bus->dhd->tickcnt = 0; |
| 3159 | brcmf_sdbrcm_wd_timer(bus, brcmf_watchdog_ms); |
| 3160 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3161 | if (enforce_mutex) |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 3162 | brcmf_sdbrcm_sdlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3163 | |
| 3164 | /* Make sure backplane clock is on, needed to generate F2 interrupt */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3165 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3166 | if (bus->clkstate != CLK_AVAIL) |
| 3167 | goto exit; |
| 3168 | |
| 3169 | /* Force clocks on backplane to be sure F2 interrupt propagates */ |
| 3170 | saveclk = |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 3171 | brcmf_sdcard_cfg_read(bus->card, SDIO_FUNC_1, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3172 | SBSDIO_FUNC1_CHIPCLKCSR, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3173 | if (!err) { |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 3174 | brcmf_sdcard_cfg_write(bus->card, SDIO_FUNC_1, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3175 | SBSDIO_FUNC1_CHIPCLKCSR, |
| 3176 | (saveclk | SBSDIO_FORCE_HT), &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3177 | } |
| 3178 | if (err) { |
| 3179 | DHD_ERROR(("%s: Failed to force clock for F2: err %d\n", |
| 3180 | __func__, err)); |
| 3181 | goto exit; |
| 3182 | } |
| 3183 | |
| 3184 | /* Enable function 2 (frame transfers) */ |
| 3185 | W_SDREG((SDPCM_PROT_VERSION << SMB_DATA_VERSION_SHIFT), |
| 3186 | &bus->regs->tosbmailboxdata, retries); |
| 3187 | enable = (SDIO_FUNC_ENABLE_1 | SDIO_FUNC_ENABLE_2); |
| 3188 | |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 3189 | brcmf_sdcard_cfg_write(bus->card, SDIO_FUNC_0, SDIO_CCCR_IOEx, enable, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3190 | NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3191 | |
| 3192 | /* 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] | 3193 | brcmf_timeout_start(&tmo, DHD_WAIT_F2RDY * 1000); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3194 | |
| 3195 | ready = 0; |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 3196 | while (ready != enable && !brcmf_timeout_expired(&tmo)) |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 3197 | ready = brcmf_sdcard_cfg_read(bus->card, SDIO_FUNC_0, |
| 3198 | SDIO_CCCR_IORx, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3199 | |
| 3200 | DHD_INFO(("%s: enable 0x%02x, ready 0x%02x (waited %uus)\n", |
| 3201 | __func__, enable, ready, tmo.elapsed)); |
| 3202 | |
| 3203 | /* If F2 successfully enabled, set core and enable interrupts */ |
| 3204 | if (ready == enable) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3205 | /* Set up the interrupt mask and enable interrupts */ |
| 3206 | bus->hostintmask = HOSTINTMASK; |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 3207 | W_SDREG(bus->hostintmask, |
| 3208 | (unsigned int *)CORE_BUS_REG(bus->ci->buscorebase, |
| 3209 | hostintmask), retries); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3210 | |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 3211 | brcmf_sdcard_cfg_write(bus->card, SDIO_FUNC_1, SBSDIO_WATERMARK, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3212 | (u8) watermark, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3213 | |
| 3214 | /* Set bus state according to enable result */ |
| 3215 | dhdp->busstate = DHD_BUS_DATA; |
| 3216 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3217 | bus->intdis = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3218 | if (bus->intr) { |
| 3219 | DHD_INTR(("%s: enable SDIO device interrupts\n", |
| 3220 | __func__)); |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 3221 | brcmf_sdcard_intr_enable(bus->card); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3222 | } else { |
| 3223 | DHD_INTR(("%s: disable SDIO interrupts\n", __func__)); |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 3224 | brcmf_sdcard_intr_disable(bus->card); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3225 | } |
| 3226 | |
| 3227 | } |
| 3228 | |
| 3229 | else { |
| 3230 | /* Disable F2 again */ |
| 3231 | enable = SDIO_FUNC_ENABLE_1; |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 3232 | brcmf_sdcard_cfg_write(bus->card, SDIO_FUNC_0, SDIO_CCCR_IOEx, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3233 | enable, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3234 | } |
| 3235 | |
| 3236 | /* Restore previous clock setting */ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 3237 | brcmf_sdcard_cfg_write(bus->card, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3238 | saveclk, &err); |
| 3239 | |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 3240 | #if defined(OOB_INTR_ONLY) |
| 3241 | /* Host registration for OOB interrupt */ |
| 3242 | if (brcmf_sdio_register_oob_intr(bus->dhd)) { |
| 3243 | brcmf_sdbrcm_wd_timer(bus, 0); |
| 3244 | DHD_ERROR(("%s Host failed to resgister for OOB\n", __func__)); |
| 3245 | ret = -ENODEV; |
| 3246 | goto exit; |
| 3247 | } |
| 3248 | |
| 3249 | /* Enable oob at firmware */ |
| 3250 | brcmf_sdbrcm_enable_oob_intr(bus, true); |
| 3251 | #endif /* defined(OOB_INTR_ONLY) */ |
| 3252 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3253 | /* If we didn't come up, turn off backplane clock */ |
| 3254 | if (dhdp->busstate != DHD_BUS_DATA) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3255 | brcmf_sdbrcm_clkctl(bus, CLK_NONE, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3256 | |
| 3257 | exit: |
| 3258 | if (enforce_mutex) |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 3259 | brcmf_sdbrcm_sdunlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3260 | |
| 3261 | return ret; |
| 3262 | } |
| 3263 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3264 | 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] | 3265 | { |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 3266 | struct brcmf_sdio_card *card = bus->card; |
Franky Lin | 597600a | 2011-06-01 13:45:39 +0200 | [diff] [blame] | 3267 | struct sdpcmd_regs *regs = bus->regs; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3268 | uint retries = 0; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3269 | u16 lastrbc; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3270 | u8 hi, lo; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3271 | int err; |
| 3272 | |
| 3273 | DHD_ERROR(("%s: %sterminate frame%s\n", __func__, |
| 3274 | (abort ? "abort command, " : ""), |
| 3275 | (rtx ? ", send NAK" : ""))); |
| 3276 | |
| 3277 | if (abort) |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 3278 | brcmf_sdcard_abort(card, SDIO_FUNC_2); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3279 | |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 3280 | brcmf_sdcard_cfg_write(card, SDIO_FUNC_1, SBSDIO_FUNC1_FRAMECTRL, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3281 | SFC_RF_TERM, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3282 | bus->f1regdata++; |
| 3283 | |
| 3284 | /* Wait until the packet has been flushed (device/FIFO stable) */ |
| 3285 | for (lastrbc = retries = 0xffff; retries > 0; retries--) { |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 3286 | hi = brcmf_sdcard_cfg_read(card, SDIO_FUNC_1, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3287 | SBSDIO_FUNC1_RFRAMEBCHI, NULL); |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 3288 | lo = brcmf_sdcard_cfg_read(card, SDIO_FUNC_1, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3289 | SBSDIO_FUNC1_RFRAMEBCLO, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3290 | bus->f1regdata += 2; |
| 3291 | |
| 3292 | if ((hi == 0) && (lo == 0)) |
| 3293 | break; |
| 3294 | |
| 3295 | if ((hi > (lastrbc >> 8)) && (lo > (lastrbc & 0x00ff))) { |
| 3296 | DHD_ERROR(("%s: count growing: last 0x%04x now " |
| 3297 | "0x%04x\n", |
| 3298 | __func__, lastrbc, ((hi << 8) + lo))); |
| 3299 | } |
| 3300 | lastrbc = (hi << 8) + lo; |
| 3301 | } |
| 3302 | |
| 3303 | if (!retries) { |
| 3304 | DHD_ERROR(("%s: count never zeroed: last 0x%04x\n", |
| 3305 | __func__, lastrbc)); |
| 3306 | } else { |
| 3307 | DHD_INFO(("%s: flush took %d iterations\n", __func__, |
| 3308 | (0xffff - retries))); |
| 3309 | } |
| 3310 | |
| 3311 | if (rtx) { |
| 3312 | bus->rxrtx++; |
| 3313 | W_SDREG(SMB_NAK, ®s->tosbmailbox, retries); |
| 3314 | bus->f1regdata++; |
| 3315 | if (retries <= retry_limit) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3316 | bus->rxskip = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3317 | } |
| 3318 | |
| 3319 | /* Clear partial in any case */ |
| 3320 | bus->nextlen = 0; |
| 3321 | |
| 3322 | /* If we can't reach the device, signal failure */ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 3323 | if (err || brcmf_sdcard_regfail(card)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3324 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 3325 | } |
| 3326 | |
| 3327 | static void |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3328 | 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] | 3329 | { |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 3330 | struct brcmf_sdio_card *card = bus->card; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3331 | uint rdlen, pad; |
| 3332 | |
| 3333 | int sdret; |
| 3334 | |
| 3335 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 3336 | |
| 3337 | /* Control data already received in aligned rxctl */ |
| 3338 | if ((bus->bus == SPI_BUS) && (!bus->usebufpool)) |
| 3339 | goto gotpkt; |
| 3340 | |
| 3341 | ASSERT(bus->rxbuf); |
| 3342 | /* Set rxctl for frame (w/optional alignment) */ |
| 3343 | bus->rxctl = bus->rxbuf; |
| 3344 | if (dhd_alignctl) { |
| 3345 | bus->rxctl += firstread; |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 3346 | pad = ((unsigned long)bus->rxctl % BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3347 | if (pad) |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 3348 | bus->rxctl += (BRCMF_SDALIGN - pad); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3349 | bus->rxctl -= firstread; |
| 3350 | } |
| 3351 | ASSERT(bus->rxctl >= bus->rxbuf); |
| 3352 | |
| 3353 | /* Copy the already-read portion over */ |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 3354 | memcpy(bus->rxctl, hdr, firstread); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3355 | if (len <= firstread) |
| 3356 | goto gotpkt; |
| 3357 | |
| 3358 | /* Copy the full data pkt in gSPI case and process ioctl. */ |
| 3359 | if (bus->bus == SPI_BUS) { |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 3360 | memcpy(bus->rxctl, hdr, len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3361 | goto gotpkt; |
| 3362 | } |
| 3363 | |
| 3364 | /* Raise rdlen to next SDIO block to avoid tail command */ |
| 3365 | rdlen = len - firstread; |
| 3366 | if (bus->roundup && bus->blocksize && (rdlen > bus->blocksize)) { |
| 3367 | pad = bus->blocksize - (rdlen % bus->blocksize); |
| 3368 | if ((pad <= bus->roundup) && (pad < bus->blocksize) && |
| 3369 | ((len + pad) < bus->dhd->maxctl)) |
| 3370 | rdlen += pad; |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 3371 | } else if (rdlen % BRCMF_SDALIGN) { |
| 3372 | rdlen += BRCMF_SDALIGN - (rdlen % BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3373 | } |
| 3374 | |
| 3375 | /* Satisfy length-alignment requirements */ |
| 3376 | if (forcealign && (rdlen & (ALIGNMENT - 1))) |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 3377 | rdlen = roundup(rdlen, ALIGNMENT); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3378 | |
| 3379 | /* Drop if the read is too big or it exceeds our maximum */ |
| 3380 | if ((rdlen + firstread) > bus->dhd->maxctl) { |
| 3381 | DHD_ERROR(("%s: %d-byte control read exceeds %d-byte buffer\n", |
| 3382 | __func__, rdlen, bus->dhd->maxctl)); |
| 3383 | bus->dhd->rx_errors++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3384 | brcmf_sdbrcm_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3385 | goto done; |
| 3386 | } |
| 3387 | |
| 3388 | if ((len - doff) > bus->dhd->maxctl) { |
| 3389 | DHD_ERROR(("%s: %d-byte ctl frame (%d-byte ctl data) exceeds " |
| 3390 | "%d-byte limit\n", |
| 3391 | __func__, len, (len - doff), bus->dhd->maxctl)); |
| 3392 | bus->dhd->rx_errors++; |
| 3393 | bus->rx_toolong++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3394 | brcmf_sdbrcm_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3395 | goto done; |
| 3396 | } |
| 3397 | |
| 3398 | /* Read remainder of frame body into the rxctl buffer */ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 3399 | sdret = brcmf_sdcard_recv_buf(card, brcmf_sdcard_cur_sbwad(card), |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3400 | SDIO_FUNC_2, |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 3401 | F2SYNC, (bus->rxctl + firstread), rdlen, |
| 3402 | NULL, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3403 | bus->f2rxdata++; |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 3404 | ASSERT(sdret != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3405 | |
| 3406 | /* Control frame failures need retransmission */ |
| 3407 | if (sdret < 0) { |
| 3408 | DHD_ERROR(("%s: read %d control bytes failed: %d\n", |
| 3409 | __func__, rdlen, sdret)); |
| 3410 | bus->rxc_errors++; /* dhd.rx_ctlerrs is higher level */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3411 | brcmf_sdbrcm_rxfail(bus, true, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3412 | goto done; |
| 3413 | } |
| 3414 | |
| 3415 | gotpkt: |
| 3416 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 3417 | #ifdef BCMDBG |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 3418 | if (DHD_BYTES_ON() && DHD_CTL_ON()) { |
| 3419 | printk(KERN_DEBUG "RxCtrl:\n"); |
| 3420 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, bus->rxctl, len); |
| 3421 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3422 | #endif |
| 3423 | |
| 3424 | /* Point to valid data and indicate its length */ |
| 3425 | bus->rxctl += doff; |
| 3426 | bus->rxlen = len - doff; |
| 3427 | |
| 3428 | done: |
| 3429 | /* Awake any waiters */ |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 3430 | brcmf_os_ioctl_resp_wake(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3431 | } |
| 3432 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3433 | static u8 brcmf_sdbrcm_rxglom(dhd_bus_t *bus, u8 rxseq) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3434 | { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3435 | u16 dlen, totlen; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3436 | u8 *dptr, num = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3437 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3438 | u16 sublen, check; |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 3439 | struct sk_buff *pfirst, *plast, *pnext, *save_pfirst; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3440 | |
| 3441 | int errcode; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3442 | u8 chan, seq, doff, sfdoff; |
| 3443 | u8 txmax; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3444 | |
| 3445 | int ifidx = 0; |
| 3446 | bool usechain = bus->use_rxchain; |
| 3447 | |
| 3448 | /* If packets, issue read(s) and send up packet chain */ |
| 3449 | /* Return sequence numbers consumed? */ |
| 3450 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3451 | 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] | 3452 | bus->glom)); |
| 3453 | |
| 3454 | /* If there's a descriptor, generate the packet chain */ |
| 3455 | if (bus->glomd) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3456 | pfirst = plast = pnext = NULL; |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3457 | dlen = (u16) (bus->glomd->len); |
| 3458 | dptr = bus->glomd->data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3459 | if (!dlen || (dlen & 1)) { |
| 3460 | DHD_ERROR(("%s: bad glomd len(%d), ignore descriptor\n", |
| 3461 | __func__, dlen)); |
| 3462 | dlen = 0; |
| 3463 | } |
| 3464 | |
| 3465 | for (totlen = num = 0; dlen; num++) { |
| 3466 | /* Get (and move past) next length */ |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 3467 | sublen = get_unaligned_le16(dptr); |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3468 | dlen -= sizeof(u16); |
| 3469 | dptr += sizeof(u16); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3470 | if ((sublen < SDPCM_HDRLEN) || |
| 3471 | ((num == 0) && (sublen < (2 * SDPCM_HDRLEN)))) { |
| 3472 | DHD_ERROR(("%s: descriptor len %d bad: %d\n", |
| 3473 | __func__, num, sublen)); |
| 3474 | pnext = NULL; |
| 3475 | break; |
| 3476 | } |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 3477 | if (sublen % BRCMF_SDALIGN) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3478 | DHD_ERROR(("%s: sublen %d not multiple of %d\n", |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 3479 | __func__, sublen, BRCMF_SDALIGN)); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3480 | usechain = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3481 | } |
| 3482 | totlen += sublen; |
| 3483 | |
| 3484 | /* For last frame, adjust read len so total |
| 3485 | is a block multiple */ |
| 3486 | if (!dlen) { |
| 3487 | sublen += |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 3488 | (roundup(totlen, bus->blocksize) - totlen); |
| 3489 | totlen = roundup(totlen, bus->blocksize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3490 | } |
| 3491 | |
| 3492 | /* Allocate/chain packet for next subframe */ |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 3493 | pnext = brcmu_pkt_buf_get_skb(sublen + BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3494 | if (pnext == NULL) { |
Henry Ptasinski | b33f0e2 | 2011-05-10 22:25:29 +0200 | [diff] [blame] | 3495 | DHD_ERROR(("%s: bcm_pkt_buf_get_skb failed, " |
| 3496 | "num %d len %d\n", __func__, |
| 3497 | num, sublen)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3498 | break; |
| 3499 | } |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3500 | ASSERT(!(pnext->prev)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3501 | if (!pfirst) { |
| 3502 | ASSERT(!plast); |
| 3503 | pfirst = plast = pnext; |
| 3504 | } else { |
| 3505 | ASSERT(plast); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3506 | plast->next = pnext; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3507 | plast = pnext; |
| 3508 | } |
| 3509 | |
| 3510 | /* Adhere to start alignment requirements */ |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 3511 | PKTALIGN(pnext, sublen, BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3512 | } |
| 3513 | |
| 3514 | /* If all allocations succeeded, save packet chain |
| 3515 | in bus structure */ |
| 3516 | if (pnext) { |
| 3517 | DHD_GLOM(("%s: allocated %d-byte packet chain for %d " |
| 3518 | "subframes\n", __func__, totlen, num)); |
| 3519 | if (DHD_GLOM_ON() && bus->nextlen) { |
| 3520 | if (totlen != bus->nextlen) { |
| 3521 | DHD_GLOM(("%s: glomdesc mismatch: nextlen %d glomdesc %d " "rxseq %d\n", |
| 3522 | __func__, bus->nextlen, |
| 3523 | totlen, rxseq)); |
| 3524 | } |
| 3525 | } |
| 3526 | bus->glom = pfirst; |
| 3527 | pfirst = pnext = NULL; |
| 3528 | } else { |
| 3529 | if (pfirst) |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3530 | brcmu_pkt_buf_free_skb(pfirst); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3531 | bus->glom = NULL; |
| 3532 | num = 0; |
| 3533 | } |
| 3534 | |
| 3535 | /* Done with descriptor packet */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3536 | brcmu_pkt_buf_free_skb(bus->glomd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3537 | bus->glomd = NULL; |
| 3538 | bus->nextlen = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3539 | } |
| 3540 | |
| 3541 | /* Ok -- either we just generated a packet chain, |
| 3542 | or had one from before */ |
| 3543 | if (bus->glom) { |
| 3544 | if (DHD_GLOM_ON()) { |
| 3545 | DHD_GLOM(("%s: try superframe read, packet chain:\n", |
| 3546 | __func__)); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3547 | for (pnext = bus->glom; pnext; pnext = pnext->next) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3548 | DHD_GLOM((" %p: %p len 0x%04x (%d)\n", |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3549 | pnext, (u8 *) (pnext->data), |
| 3550 | pnext->len, pnext->len)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3551 | } |
| 3552 | } |
| 3553 | |
| 3554 | pfirst = bus->glom; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3555 | dlen = (u16) brcmu_pkttotlen(pfirst); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3556 | |
| 3557 | /* Do an SDIO read for the superframe. Configurable iovar to |
| 3558 | * read directly into the chained packet, or allocate a large |
| 3559 | * packet and and copy into the chain. |
| 3560 | */ |
| 3561 | if (usechain) { |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 3562 | errcode = brcmf_sdcard_recv_buf(bus->card, |
| 3563 | brcmf_sdcard_cur_sbwad(bus->card), |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3564 | SDIO_FUNC_2, |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 3565 | F2SYNC, (u8 *) pfirst->data, dlen, |
| 3566 | pfirst, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3567 | } else if (bus->dataptr) { |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 3568 | errcode = brcmf_sdcard_recv_buf(bus->card, |
| 3569 | brcmf_sdcard_cur_sbwad(bus->card), |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3570 | SDIO_FUNC_2, |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 3571 | F2SYNC, bus->dataptr, dlen, |
| 3572 | NULL, NULL, NULL); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3573 | sublen = (u16) brcmu_pktfrombuf(pfirst, 0, dlen, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3574 | bus->dataptr); |
| 3575 | if (sublen != dlen) { |
| 3576 | DHD_ERROR(("%s: FAILED TO COPY, dlen %d sublen %d\n", |
| 3577 | __func__, dlen, sublen)); |
| 3578 | errcode = -1; |
| 3579 | } |
| 3580 | pnext = NULL; |
| 3581 | } else { |
| 3582 | DHD_ERROR(("COULDN'T ALLOC %d-BYTE GLOM, FORCE FAILURE\n", |
| 3583 | dlen)); |
| 3584 | errcode = -1; |
| 3585 | } |
| 3586 | bus->f2rxdata++; |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 3587 | ASSERT(errcode != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3588 | |
| 3589 | /* On failure, kill the superframe, allow a couple retries */ |
| 3590 | if (errcode < 0) { |
| 3591 | DHD_ERROR(("%s: glom read of %d bytes failed: %d\n", |
| 3592 | __func__, dlen, errcode)); |
| 3593 | bus->dhd->rx_errors++; |
| 3594 | |
| 3595 | if (bus->glomerr++ < 3) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3596 | brcmf_sdbrcm_rxfail(bus, true, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3597 | } else { |
| 3598 | bus->glomerr = 0; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3599 | brcmf_sdbrcm_rxfail(bus, true, false); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3600 | brcmu_pkt_buf_free_skb(bus->glom); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3601 | bus->rxglomfail++; |
| 3602 | bus->glom = NULL; |
| 3603 | } |
| 3604 | return 0; |
| 3605 | } |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 3606 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3607 | if (DHD_GLOM_ON()) { |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 3608 | printk(KERN_DEBUG "SUPERFRAME:\n"); |
| 3609 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 3610 | pfirst->data, min_t(int, pfirst->len, 48)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3611 | } |
| 3612 | #endif |
| 3613 | |
| 3614 | /* Validate the superframe header */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3615 | dptr = (u8 *) (pfirst->data); |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 3616 | sublen = get_unaligned_le16(dptr); |
| 3617 | check = get_unaligned_le16(dptr + sizeof(u16)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3618 | |
| 3619 | chan = SDPCM_PACKET_CHANNEL(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3620 | seq = SDPCM_PACKET_SEQUENCE(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3621 | bus->nextlen = dptr[SDPCM_FRAMETAG_LEN + SDPCM_NEXTLEN_OFFSET]; |
| 3622 | if ((bus->nextlen << 4) > MAX_RX_DATASZ) { |
| 3623 | DHD_INFO(("%s: nextlen too large (%d) seq %d\n", |
| 3624 | __func__, bus->nextlen, seq)); |
| 3625 | bus->nextlen = 0; |
| 3626 | } |
| 3627 | doff = SDPCM_DOFFSET_VALUE(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3628 | txmax = SDPCM_WINDOW_VALUE(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3629 | |
| 3630 | errcode = 0; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3631 | if ((u16)~(sublen ^ check)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3632 | DHD_ERROR(("%s (superframe): HW hdr error: len/check " |
| 3633 | "0x%04x/0x%04x\n", __func__, sublen, check)); |
| 3634 | errcode = -1; |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 3635 | } else if (roundup(sublen, bus->blocksize) != dlen) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3636 | DHD_ERROR(("%s (superframe): len 0x%04x, rounded " |
| 3637 | "0x%04x, expect 0x%04x\n", |
| 3638 | __func__, sublen, |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 3639 | roundup(sublen, bus->blocksize), dlen)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3640 | errcode = -1; |
| 3641 | } else if (SDPCM_PACKET_CHANNEL(&dptr[SDPCM_FRAMETAG_LEN]) != |
| 3642 | SDPCM_GLOM_CHANNEL) { |
| 3643 | DHD_ERROR(("%s (superframe): bad channel %d\n", |
| 3644 | __func__, |
| 3645 | SDPCM_PACKET_CHANNEL(&dptr |
| 3646 | [SDPCM_FRAMETAG_LEN]))); |
| 3647 | errcode = -1; |
| 3648 | } else if (SDPCM_GLOMDESC(&dptr[SDPCM_FRAMETAG_LEN])) { |
| 3649 | DHD_ERROR(("%s (superframe): got second descriptor?\n", |
| 3650 | __func__)); |
| 3651 | errcode = -1; |
| 3652 | } else if ((doff < SDPCM_HDRLEN) || |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3653 | (doff > (pfirst->len - SDPCM_HDRLEN))) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3654 | DHD_ERROR(("%s (superframe): Bad data offset %d: HW %d " |
| 3655 | "pkt %d min %d\n", |
| 3656 | __func__, doff, sublen, |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3657 | pfirst->len, SDPCM_HDRLEN)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3658 | errcode = -1; |
| 3659 | } |
| 3660 | |
| 3661 | /* Check sequence number of superframe SW header */ |
| 3662 | if (rxseq != seq) { |
| 3663 | DHD_INFO(("%s: (superframe) rx_seq %d, expected %d\n", |
| 3664 | __func__, seq, rxseq)); |
| 3665 | bus->rx_badseq++; |
| 3666 | rxseq = seq; |
| 3667 | } |
| 3668 | |
| 3669 | /* Check window for sanity */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3670 | if ((u8) (txmax - bus->tx_seq) > 0x40) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3671 | DHD_ERROR(("%s: unlikely tx max %d with tx_seq %d\n", |
| 3672 | __func__, txmax, bus->tx_seq)); |
| 3673 | txmax = bus->tx_seq + 2; |
| 3674 | } |
| 3675 | bus->tx_max = txmax; |
| 3676 | |
| 3677 | /* Remove superframe header, remember offset */ |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 3678 | skb_pull(pfirst, doff); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3679 | sfdoff = doff; |
| 3680 | |
| 3681 | /* Validate all the subframe headers */ |
| 3682 | for (num = 0, pnext = pfirst; pnext && !errcode; |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3683 | num++, pnext = pnext->next) { |
| 3684 | dptr = (u8 *) (pnext->data); |
| 3685 | dlen = (u16) (pnext->len); |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 3686 | sublen = get_unaligned_le16(dptr); |
| 3687 | check = get_unaligned_le16(dptr + sizeof(u16)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3688 | chan = SDPCM_PACKET_CHANNEL(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3689 | doff = SDPCM_DOFFSET_VALUE(&dptr[SDPCM_FRAMETAG_LEN]); |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 3690 | #ifdef BCMDBG |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 3691 | if (DHD_GLOM_ON()) { |
| 3692 | printk(KERN_DEBUG "subframe:\n"); |
| 3693 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 3694 | dptr, 32); |
| 3695 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3696 | #endif |
| 3697 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3698 | if ((u16)~(sublen ^ check)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3699 | DHD_ERROR(("%s (subframe %d): HW hdr error: " |
| 3700 | "len/check 0x%04x/0x%04x\n", |
| 3701 | __func__, num, sublen, check)); |
| 3702 | errcode = -1; |
| 3703 | } else if ((sublen > dlen) || (sublen < SDPCM_HDRLEN)) { |
| 3704 | DHD_ERROR(("%s (subframe %d): length mismatch: " |
| 3705 | "len 0x%04x, expect 0x%04x\n", |
| 3706 | __func__, num, sublen, dlen)); |
| 3707 | errcode = -1; |
| 3708 | } else if ((chan != SDPCM_DATA_CHANNEL) && |
| 3709 | (chan != SDPCM_EVENT_CHANNEL)) { |
| 3710 | DHD_ERROR(("%s (subframe %d): bad channel %d\n", |
| 3711 | __func__, num, chan)); |
| 3712 | errcode = -1; |
| 3713 | } else if ((doff < SDPCM_HDRLEN) || (doff > sublen)) { |
| 3714 | DHD_ERROR(("%s (subframe %d): Bad data offset %d: HW %d min %d\n", |
| 3715 | __func__, num, doff, sublen, |
| 3716 | SDPCM_HDRLEN)); |
| 3717 | errcode = -1; |
| 3718 | } |
| 3719 | } |
| 3720 | |
| 3721 | if (errcode) { |
| 3722 | /* Terminate frame on error, request |
| 3723 | a couple retries */ |
| 3724 | if (bus->glomerr++ < 3) { |
| 3725 | /* Restore superframe header space */ |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 3726 | skb_push(pfirst, sfdoff); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3727 | brcmf_sdbrcm_rxfail(bus, true, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3728 | } else { |
| 3729 | bus->glomerr = 0; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3730 | brcmf_sdbrcm_rxfail(bus, true, false); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3731 | brcmu_pkt_buf_free_skb(bus->glom); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3732 | bus->rxglomfail++; |
| 3733 | bus->glom = NULL; |
| 3734 | } |
| 3735 | bus->nextlen = 0; |
| 3736 | return 0; |
| 3737 | } |
| 3738 | |
| 3739 | /* Basic SD framing looks ok - process each packet (header) */ |
| 3740 | save_pfirst = pfirst; |
| 3741 | bus->glom = NULL; |
| 3742 | plast = NULL; |
| 3743 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3744 | for (num = 0; pfirst; rxseq++, pfirst = pnext) { |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3745 | pnext = pfirst->next; |
| 3746 | pfirst->next = NULL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3747 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3748 | dptr = (u8 *) (pfirst->data); |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 3749 | sublen = get_unaligned_le16(dptr); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3750 | chan = SDPCM_PACKET_CHANNEL(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3751 | seq = SDPCM_PACKET_SEQUENCE(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3752 | doff = SDPCM_DOFFSET_VALUE(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3753 | |
| 3754 | DHD_GLOM(("%s: Get subframe %d, %p(%p/%d), sublen %d " |
| 3755 | "chan %d seq %d\n", |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3756 | __func__, num, pfirst, pfirst->data, |
| 3757 | pfirst->len, sublen, chan, seq)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3758 | |
| 3759 | ASSERT((chan == SDPCM_DATA_CHANNEL) |
| 3760 | || (chan == SDPCM_EVENT_CHANNEL)); |
| 3761 | |
| 3762 | if (rxseq != seq) { |
| 3763 | DHD_GLOM(("%s: rx_seq %d, expected %d\n", |
| 3764 | __func__, seq, rxseq)); |
| 3765 | bus->rx_badseq++; |
| 3766 | rxseq = seq; |
| 3767 | } |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 3768 | #ifdef BCMDBG |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 3769 | if (DHD_BYTES_ON() && DHD_DATA_ON()) { |
| 3770 | printk(KERN_DEBUG "Rx Subframe Data:\n"); |
| 3771 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 3772 | dptr, dlen); |
| 3773 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3774 | #endif |
| 3775 | |
Arend van Spriel | 2cb8ada | 2010-11-18 20:46:44 +0100 | [diff] [blame] | 3776 | __skb_trim(pfirst, sublen); |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 3777 | skb_pull(pfirst, doff); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3778 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3779 | if (pfirst->len == 0) { |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3780 | brcmu_pkt_buf_free_skb(pfirst); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3781 | if (plast) { |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3782 | plast->next = pnext; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3783 | } else { |
| 3784 | ASSERT(save_pfirst == pfirst); |
| 3785 | save_pfirst = pnext; |
| 3786 | } |
| 3787 | continue; |
Arend van Spriel | 0aa94b8 | 2011-06-29 16:47:13 -0700 | [diff] [blame] | 3788 | } else if (brcmf_proto_hdrpull(bus->dhd, &ifidx, pfirst) |
| 3789 | != 0) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3790 | DHD_ERROR(("%s: rx protocol error\n", |
| 3791 | __func__)); |
| 3792 | bus->dhd->rx_errors++; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3793 | brcmu_pkt_buf_free_skb(pfirst); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3794 | if (plast) { |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3795 | plast->next = pnext; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3796 | } else { |
| 3797 | ASSERT(save_pfirst == pfirst); |
| 3798 | save_pfirst = pnext; |
| 3799 | } |
| 3800 | continue; |
| 3801 | } |
| 3802 | |
| 3803 | /* this packet will go up, link back into |
| 3804 | chain and count it */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3805 | pfirst->next = pnext; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3806 | plast = pfirst; |
| 3807 | num++; |
| 3808 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 3809 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3810 | if (DHD_GLOM_ON()) { |
| 3811 | DHD_GLOM(("%s subframe %d to stack, %p(%p/%d) " |
| 3812 | "nxt/lnk %p/%p\n", |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3813 | __func__, num, pfirst, pfirst->data, |
| 3814 | pfirst->len, pfirst->next, |
| 3815 | pfirst->prev)); |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 3816 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 3817 | pfirst->data, |
| 3818 | min_t(int, pfirst->len, 32)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3819 | } |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 3820 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3821 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3822 | if (num) { |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 3823 | brcmf_sdbrcm_sdunlock(bus); |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 3824 | brcmf_rx_frame(bus->dhd, ifidx, save_pfirst, num); |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 3825 | brcmf_sdbrcm_sdlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3826 | } |
| 3827 | |
| 3828 | bus->rxglomframes++; |
| 3829 | bus->rxglompkts += num; |
| 3830 | } |
| 3831 | return num; |
| 3832 | } |
| 3833 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3834 | /* Return true if there may be more frames to read */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3835 | static uint |
| 3836 | brcmf_sdbrcm_readframes(dhd_bus_t *bus, uint maxframes, bool *finished) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3837 | { |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 3838 | struct brcmf_sdio_card *card = bus->card; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3839 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3840 | u16 len, check; /* Extracted hardware header fields */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3841 | u8 chan, seq, doff; /* Extracted software header fields */ |
| 3842 | u8 fcbits; /* Extracted fcbits from software header */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3843 | |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 3844 | struct sk_buff *pkt; /* Packet for event or data frames */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3845 | u16 pad; /* Number of pad bytes to read */ |
| 3846 | u16 rdlen; /* Total number of bytes to read */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3847 | u8 rxseq; /* Next sequence number to expect */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3848 | uint rxleft = 0; /* Remaining number of frames allowed */ |
Roland Vossen | 62dd656 | 2011-07-05 22:05:57 +0200 | [diff] [blame] | 3849 | int sdret; /* Return code from calls */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3850 | u8 txmax; /* Maximum tx sequence offered */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3851 | bool len_consistent; /* Result of comparing readahead len and |
| 3852 | len from hw-hdr */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3853 | u8 *rxbuf; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3854 | int ifidx = 0; |
| 3855 | uint rxcount = 0; /* Total frames read */ |
| 3856 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 3857 | #if defined(BCMDBG) || defined(SDTEST) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3858 | bool sdtest = false; /* To limit message spew from test mode */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3859 | #endif |
| 3860 | |
| 3861 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 3862 | |
| 3863 | ASSERT(maxframes); |
| 3864 | |
| 3865 | #ifdef SDTEST |
| 3866 | /* Allow pktgen to override maxframes */ |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 3867 | if (bus->pktgen_count && (bus->pktgen_mode == BRCMF_PKTGEN_RECV)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3868 | maxframes = bus->pktgen_count; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3869 | sdtest = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3870 | } |
| 3871 | #endif |
| 3872 | |
| 3873 | /* Not finished unless we encounter no more frames indication */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3874 | *finished = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3875 | |
| 3876 | for (rxseq = bus->rx_seq, rxleft = maxframes; |
| 3877 | !bus->rxskip && rxleft && bus->dhd->busstate != DHD_BUS_DOWN; |
| 3878 | rxseq++, rxleft--) { |
| 3879 | |
| 3880 | /* Handle glomming separately */ |
| 3881 | if (bus->glom || bus->glomd) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3882 | u8 cnt; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3883 | DHD_GLOM(("%s: calling rxglom: glomd %p, glom %p\n", |
| 3884 | __func__, bus->glomd, bus->glom)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3885 | cnt = brcmf_sdbrcm_rxglom(bus, rxseq); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3886 | DHD_GLOM(("%s: rxglom returned %d\n", __func__, cnt)); |
| 3887 | rxseq += cnt - 1; |
| 3888 | rxleft = (rxleft > cnt) ? (rxleft - cnt) : 1; |
| 3889 | continue; |
| 3890 | } |
| 3891 | |
| 3892 | /* Try doing single read if we can */ |
| 3893 | if (dhd_readahead && bus->nextlen) { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3894 | u16 nextlen = bus->nextlen; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3895 | bus->nextlen = 0; |
| 3896 | |
| 3897 | if (bus->bus == SPI_BUS) { |
| 3898 | rdlen = len = nextlen; |
| 3899 | } else { |
| 3900 | rdlen = len = nextlen << 4; |
| 3901 | |
| 3902 | /* Pad read to blocksize for efficiency */ |
| 3903 | if (bus->roundup && bus->blocksize |
| 3904 | && (rdlen > bus->blocksize)) { |
| 3905 | pad = |
| 3906 | bus->blocksize - |
| 3907 | (rdlen % bus->blocksize); |
| 3908 | if ((pad <= bus->roundup) |
| 3909 | && (pad < bus->blocksize) |
| 3910 | && ((rdlen + pad + firstread) < |
| 3911 | MAX_RX_DATASZ)) |
| 3912 | rdlen += pad; |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 3913 | } else if (rdlen % BRCMF_SDALIGN) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3914 | rdlen += |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 3915 | BRCMF_SDALIGN - (rdlen % BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3916 | } |
| 3917 | } |
| 3918 | |
| 3919 | /* We use bus->rxctl buffer in WinXP for initial |
| 3920 | * control pkt receives. |
| 3921 | * Later we use buffer-poll for data as well |
| 3922 | * as control packets. |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3923 | * This is required because dhd receives full |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3924 | * frame in gSPI unlike SDIO. |
| 3925 | * After the frame is received we have to |
| 3926 | * distinguish whether it is data |
| 3927 | * or non-data frame. |
| 3928 | */ |
| 3929 | /* Allocate a packet buffer */ |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 3930 | pkt = brcmu_pkt_buf_get_skb(rdlen + BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3931 | if (!pkt) { |
| 3932 | if (bus->bus == SPI_BUS) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3933 | bus->usebufpool = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3934 | bus->rxctl = bus->rxbuf; |
| 3935 | if (dhd_alignctl) { |
| 3936 | bus->rxctl += firstread; |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 3937 | pad = ((unsigned long)bus->rxctl % |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 3938 | BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3939 | if (pad) |
| 3940 | bus->rxctl += |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 3941 | (BRCMF_SDALIGN - pad); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3942 | bus->rxctl -= firstread; |
| 3943 | } |
| 3944 | ASSERT(bus->rxctl >= bus->rxbuf); |
| 3945 | rxbuf = bus->rxctl; |
| 3946 | /* Read the entire frame */ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 3947 | sdret = brcmf_sdcard_recv_buf(card, |
| 3948 | brcmf_sdcard_cur_sbwad(card), |
| 3949 | SDIO_FUNC_2, F2SYNC, |
| 3950 | rxbuf, rdlen, |
| 3951 | NULL, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3952 | bus->f2rxdata++; |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 3953 | ASSERT(sdret != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3954 | |
| 3955 | /* Control frame failures need |
| 3956 | retransmission */ |
| 3957 | if (sdret < 0) { |
| 3958 | DHD_ERROR(("%s: read %d control bytes failed: %d\n", |
| 3959 | __func__, |
| 3960 | rdlen, sdret)); |
| 3961 | /* dhd.rx_ctlerrs is higher */ |
| 3962 | bus->rxc_errors++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3963 | brcmf_sdbrcm_rxfail(bus, true, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3964 | (bus->bus == |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3965 | SPI_BUS) ? false |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3966 | : true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3967 | continue; |
| 3968 | } |
| 3969 | } else { |
| 3970 | /* Give up on data, |
| 3971 | request rtx of events */ |
Arend van Spriel | cda64a5 | 2011-05-10 22:25:33 +0200 | [diff] [blame] | 3972 | DHD_ERROR(("%s (nextlen): " |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3973 | "brcmu_pkt_buf_get_skb " |
| 3974 | "failed:" |
Arend van Spriel | cda64a5 | 2011-05-10 22:25:33 +0200 | [diff] [blame] | 3975 | " len %d rdlen %d expected" |
| 3976 | " rxseq %d\n", __func__, |
| 3977 | len, rdlen, rxseq)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3978 | continue; |
| 3979 | } |
| 3980 | } else { |
| 3981 | if (bus->bus == SPI_BUS) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3982 | bus->usebufpool = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3983 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3984 | ASSERT(!(pkt->prev)); |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 3985 | PKTALIGN(pkt, rdlen, BRCMF_SDALIGN); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3986 | rxbuf = (u8 *) (pkt->data); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3987 | /* Read the entire frame */ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 3988 | sdret = brcmf_sdcard_recv_buf(card, |
| 3989 | brcmf_sdcard_cur_sbwad(card), |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3990 | SDIO_FUNC_2, F2SYNC, |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 3991 | rxbuf, rdlen, |
| 3992 | pkt, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3993 | bus->f2rxdata++; |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 3994 | ASSERT(sdret != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3995 | |
| 3996 | if (sdret < 0) { |
| 3997 | DHD_ERROR(("%s (nextlen): read %d bytes failed: %d\n", |
| 3998 | __func__, rdlen, sdret)); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3999 | brcmu_pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4000 | bus->dhd->rx_errors++; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4001 | /* Force retry w/normal header read. |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4002 | * Don't attempt NAK for |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4003 | * gSPI |
| 4004 | */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4005 | brcmf_sdbrcm_rxfail(bus, true, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4006 | (bus->bus == |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4007 | SPI_BUS) ? false : |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4008 | true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4009 | continue; |
| 4010 | } |
| 4011 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4012 | |
| 4013 | /* Now check the header */ |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 4014 | memcpy(bus->rxhdr, rxbuf, SDPCM_HDRLEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4015 | |
| 4016 | /* Extract hardware header fields */ |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 4017 | len = get_unaligned_le16(bus->rxhdr); |
| 4018 | check = get_unaligned_le16(bus->rxhdr + sizeof(u16)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4019 | |
| 4020 | /* All zeros means readahead info was bad */ |
| 4021 | if (!(len | check)) { |
| 4022 | DHD_INFO(("%s (nextlen): read zeros in HW " |
| 4023 | "header???\n", __func__)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4024 | brcmf_sdbrcm_pktfree2(bus, pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4025 | continue; |
| 4026 | } |
| 4027 | |
| 4028 | /* Validate check bytes */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4029 | if ((u16)~(len ^ check)) { |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4030 | DHD_ERROR(("%s (nextlen): HW hdr error:" |
| 4031 | " nextlen/len/check" |
| 4032 | " 0x%04x/0x%04x/0x%04x\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4033 | __func__, nextlen, len, check)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4034 | bus->rx_badhdr++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4035 | brcmf_sdbrcm_rxfail(bus, false, false); |
| 4036 | brcmf_sdbrcm_pktfree2(bus, pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4037 | continue; |
| 4038 | } |
| 4039 | |
| 4040 | /* Validate frame length */ |
| 4041 | if (len < SDPCM_HDRLEN) { |
| 4042 | DHD_ERROR(("%s (nextlen): HW hdr length " |
| 4043 | "invalid: %d\n", __func__, len)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4044 | brcmf_sdbrcm_pktfree2(bus, pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4045 | continue; |
| 4046 | } |
| 4047 | |
| 4048 | /* Check for consistency withreadahead info */ |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 4049 | len_consistent = (nextlen != (roundup(len, 16) >> 4)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4050 | if (len_consistent) { |
| 4051 | /* Mismatch, force retry w/normal |
| 4052 | header (may be >4K) */ |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4053 | DHD_ERROR(("%s (nextlen): mismatch, " |
| 4054 | "nextlen %d len %d rnd %d; " |
| 4055 | "expected rxseq %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4056 | __func__, nextlen, |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 4057 | len, roundup(len, 16), rxseq)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4058 | brcmf_sdbrcm_rxfail(bus, true, |
| 4059 | bus->bus != SPI_BUS); |
| 4060 | brcmf_sdbrcm_pktfree2(bus, pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4061 | continue; |
| 4062 | } |
| 4063 | |
| 4064 | /* Extract software header fields */ |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4065 | chan = SDPCM_PACKET_CHANNEL( |
| 4066 | &bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 4067 | seq = SDPCM_PACKET_SEQUENCE( |
| 4068 | &bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 4069 | doff = SDPCM_DOFFSET_VALUE( |
| 4070 | &bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 4071 | txmax = SDPCM_WINDOW_VALUE( |
| 4072 | &bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4073 | |
| 4074 | bus->nextlen = |
| 4075 | bus->rxhdr[SDPCM_FRAMETAG_LEN + |
| 4076 | SDPCM_NEXTLEN_OFFSET]; |
| 4077 | if ((bus->nextlen << 4) > MAX_RX_DATASZ) { |
| 4078 | DHD_INFO(("%s (nextlen): got frame w/nextlen too large" " (%d), seq %d\n", |
| 4079 | __func__, bus->nextlen, seq)); |
| 4080 | bus->nextlen = 0; |
| 4081 | } |
| 4082 | |
| 4083 | bus->dhd->rx_readahead_cnt++; |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4084 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4085 | /* Handle Flow Control */ |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4086 | fcbits = SDPCM_FCMASK_VALUE( |
| 4087 | &bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4088 | |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4089 | if (bus->flowcontrol != fcbits) { |
| 4090 | if (~bus->flowcontrol & fcbits) |
| 4091 | bus->fc_xoff++; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4092 | |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4093 | if (bus->flowcontrol & ~fcbits) |
| 4094 | bus->fc_xon++; |
| 4095 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4096 | bus->fc_rcvd++; |
| 4097 | bus->flowcontrol = fcbits; |
| 4098 | } |
| 4099 | |
| 4100 | /* Check and update sequence number */ |
| 4101 | if (rxseq != seq) { |
| 4102 | DHD_INFO(("%s (nextlen): rx_seq %d, expected " |
| 4103 | "%d\n", __func__, seq, rxseq)); |
| 4104 | bus->rx_badseq++; |
| 4105 | rxseq = seq; |
| 4106 | } |
| 4107 | |
| 4108 | /* Check window for sanity */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4109 | if ((u8) (txmax - bus->tx_seq) > 0x40) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4110 | DHD_ERROR(("%s: got unlikely tx max %d with " |
| 4111 | "tx_seq %d\n", |
| 4112 | __func__, txmax, bus->tx_seq)); |
| 4113 | txmax = bus->tx_seq + 2; |
| 4114 | } |
| 4115 | bus->tx_max = txmax; |
| 4116 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 4117 | #ifdef BCMDBG |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 4118 | if (DHD_BYTES_ON() && DHD_DATA_ON()) { |
| 4119 | printk(KERN_DEBUG "Rx Data:\n"); |
| 4120 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 4121 | rxbuf, len); |
| 4122 | } else if (DHD_HDRS_ON()) { |
| 4123 | printk(KERN_DEBUG "RxHdr:\n"); |
| 4124 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 4125 | bus->rxhdr, SDPCM_HDRLEN); |
| 4126 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4127 | #endif |
| 4128 | |
| 4129 | if (chan == SDPCM_CONTROL_CHANNEL) { |
| 4130 | if (bus->bus == SPI_BUS) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4131 | brcmf_sdbrcm_read_control(bus, rxbuf, |
| 4132 | len, doff); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4133 | } else { |
| 4134 | DHD_ERROR(("%s (nextlen): readahead on control" " packet %d?\n", |
| 4135 | __func__, seq)); |
| 4136 | /* Force retry w/normal header read */ |
| 4137 | bus->nextlen = 0; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4138 | brcmf_sdbrcm_rxfail(bus, false, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4139 | } |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4140 | brcmf_sdbrcm_pktfree2(bus, pkt); |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4141 | continue; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4142 | } |
| 4143 | |
| 4144 | if ((bus->bus == SPI_BUS) && !bus->usebufpool) { |
| 4145 | DHD_ERROR(("Received %d bytes on %d channel. Running out of " "rx pktbuf's or not yet malloced.\n", |
| 4146 | len, chan)); |
| 4147 | continue; |
| 4148 | } |
| 4149 | |
| 4150 | /* Validate data offset */ |
| 4151 | if ((doff < SDPCM_HDRLEN) || (doff > len)) { |
| 4152 | DHD_ERROR(("%s (nextlen): bad data offset %d: HW len %d min %d\n", |
| 4153 | __func__, doff, len, SDPCM_HDRLEN)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4154 | brcmf_sdbrcm_rxfail(bus, false, false); |
| 4155 | brcmf_sdbrcm_pktfree2(bus, pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4156 | continue; |
| 4157 | } |
| 4158 | |
| 4159 | /* All done with this one -- now deliver the packet */ |
| 4160 | goto deliver; |
| 4161 | } |
| 4162 | /* gSPI frames should not be handled in fractions */ |
| 4163 | if (bus->bus == SPI_BUS) |
| 4164 | break; |
| 4165 | |
| 4166 | /* Read frame header (hardware and software) */ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 4167 | sdret = brcmf_sdcard_recv_buf(card, |
| 4168 | brcmf_sdcard_cur_sbwad(card), |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4169 | SDIO_FUNC_2, F2SYNC, bus->rxhdr, firstread, |
| 4170 | NULL, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4171 | bus->f2rxhdrs++; |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 4172 | ASSERT(sdret != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4173 | |
| 4174 | if (sdret < 0) { |
| 4175 | DHD_ERROR(("%s: RXHEADER FAILED: %d\n", __func__, |
| 4176 | sdret)); |
| 4177 | bus->rx_hdrfail++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4178 | brcmf_sdbrcm_rxfail(bus, true, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4179 | continue; |
| 4180 | } |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 4181 | #ifdef BCMDBG |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 4182 | if (DHD_BYTES_ON() || DHD_HDRS_ON()) { |
| 4183 | printk(KERN_DEBUG "RxHdr:\n"); |
| 4184 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 4185 | bus->rxhdr, SDPCM_HDRLEN); |
| 4186 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4187 | #endif |
| 4188 | |
| 4189 | /* Extract hardware header fields */ |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 4190 | len = get_unaligned_le16(bus->rxhdr); |
| 4191 | check = get_unaligned_le16(bus->rxhdr + sizeof(u16)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4192 | |
| 4193 | /* All zeros means no more frames */ |
| 4194 | if (!(len | check)) { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4195 | *finished = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4196 | break; |
| 4197 | } |
| 4198 | |
| 4199 | /* Validate check bytes */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4200 | if ((u16) ~(len ^ check)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4201 | DHD_ERROR(("%s: HW hdr err: len/check 0x%04x/0x%04x\n", |
| 4202 | __func__, len, check)); |
| 4203 | bus->rx_badhdr++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4204 | brcmf_sdbrcm_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4205 | continue; |
| 4206 | } |
| 4207 | |
| 4208 | /* Validate frame length */ |
| 4209 | if (len < SDPCM_HDRLEN) { |
| 4210 | DHD_ERROR(("%s: HW hdr length invalid: %d\n", |
| 4211 | __func__, len)); |
| 4212 | continue; |
| 4213 | } |
| 4214 | |
| 4215 | /* Extract software header fields */ |
| 4216 | chan = SDPCM_PACKET_CHANNEL(&bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 4217 | seq = SDPCM_PACKET_SEQUENCE(&bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 4218 | doff = SDPCM_DOFFSET_VALUE(&bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 4219 | txmax = SDPCM_WINDOW_VALUE(&bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 4220 | |
| 4221 | /* Validate data offset */ |
| 4222 | if ((doff < SDPCM_HDRLEN) || (doff > len)) { |
| 4223 | DHD_ERROR(("%s: Bad data offset %d: HW len %d, min %d " |
| 4224 | "seq %d\n", |
| 4225 | __func__, doff, len, SDPCM_HDRLEN, seq)); |
| 4226 | bus->rx_badhdr++; |
| 4227 | ASSERT(0); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4228 | brcmf_sdbrcm_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4229 | continue; |
| 4230 | } |
| 4231 | |
| 4232 | /* Save the readahead length if there is one */ |
| 4233 | bus->nextlen = |
| 4234 | bus->rxhdr[SDPCM_FRAMETAG_LEN + SDPCM_NEXTLEN_OFFSET]; |
| 4235 | if ((bus->nextlen << 4) > MAX_RX_DATASZ) { |
| 4236 | DHD_INFO(("%s (nextlen): got frame w/nextlen too large " |
| 4237 | "(%d), seq %d\n", |
| 4238 | __func__, bus->nextlen, seq)); |
| 4239 | bus->nextlen = 0; |
| 4240 | } |
| 4241 | |
| 4242 | /* Handle Flow Control */ |
| 4243 | fcbits = SDPCM_FCMASK_VALUE(&bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 4244 | |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4245 | if (bus->flowcontrol != fcbits) { |
| 4246 | if (~bus->flowcontrol & fcbits) |
| 4247 | bus->fc_xoff++; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4248 | |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4249 | if (bus->flowcontrol & ~fcbits) |
| 4250 | bus->fc_xon++; |
| 4251 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4252 | bus->fc_rcvd++; |
| 4253 | bus->flowcontrol = fcbits; |
| 4254 | } |
| 4255 | |
| 4256 | /* Check and update sequence number */ |
| 4257 | if (rxseq != seq) { |
| 4258 | DHD_INFO(("%s: rx_seq %d, expected %d\n", __func__, |
| 4259 | seq, rxseq)); |
| 4260 | bus->rx_badseq++; |
| 4261 | rxseq = seq; |
| 4262 | } |
| 4263 | |
| 4264 | /* Check window for sanity */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4265 | if ((u8) (txmax - bus->tx_seq) > 0x40) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4266 | DHD_ERROR(("%s: unlikely tx max %d with tx_seq %d\n", |
| 4267 | __func__, txmax, bus->tx_seq)); |
| 4268 | txmax = bus->tx_seq + 2; |
| 4269 | } |
| 4270 | bus->tx_max = txmax; |
| 4271 | |
| 4272 | /* Call a separate function for control frames */ |
| 4273 | if (chan == SDPCM_CONTROL_CHANNEL) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4274 | brcmf_sdbrcm_read_control(bus, bus->rxhdr, len, doff); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4275 | continue; |
| 4276 | } |
| 4277 | |
| 4278 | ASSERT((chan == SDPCM_DATA_CHANNEL) |
| 4279 | || (chan == SDPCM_EVENT_CHANNEL) |
| 4280 | || (chan == SDPCM_TEST_CHANNEL) |
| 4281 | || (chan == SDPCM_GLOM_CHANNEL)); |
| 4282 | |
| 4283 | /* Length to read */ |
| 4284 | rdlen = (len > firstread) ? (len - firstread) : 0; |
| 4285 | |
| 4286 | /* May pad read to blocksize for efficiency */ |
| 4287 | if (bus->roundup && bus->blocksize && |
| 4288 | (rdlen > bus->blocksize)) { |
| 4289 | pad = bus->blocksize - (rdlen % bus->blocksize); |
| 4290 | if ((pad <= bus->roundup) && (pad < bus->blocksize) && |
| 4291 | ((rdlen + pad + firstread) < MAX_RX_DATASZ)) |
| 4292 | rdlen += pad; |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 4293 | } else if (rdlen % BRCMF_SDALIGN) { |
| 4294 | rdlen += BRCMF_SDALIGN - (rdlen % BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4295 | } |
| 4296 | |
| 4297 | /* Satisfy length-alignment requirements */ |
| 4298 | if (forcealign && (rdlen & (ALIGNMENT - 1))) |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 4299 | rdlen = roundup(rdlen, ALIGNMENT); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4300 | |
| 4301 | if ((rdlen + firstread) > MAX_RX_DATASZ) { |
| 4302 | /* Too long -- skip this frame */ |
| 4303 | DHD_ERROR(("%s: too long: len %d rdlen %d\n", |
| 4304 | __func__, len, rdlen)); |
| 4305 | bus->dhd->rx_errors++; |
| 4306 | bus->rx_toolong++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4307 | brcmf_sdbrcm_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4308 | continue; |
| 4309 | } |
| 4310 | |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 4311 | pkt = brcmu_pkt_buf_get_skb(rdlen + firstread + BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4312 | if (!pkt) { |
| 4313 | /* Give up on data, request rtx of events */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4314 | DHD_ERROR(("%s: brcmu_pkt_buf_get_skb failed: rdlen %d" |
| 4315 | " chan %d\n", __func__, rdlen, chan)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4316 | bus->dhd->rx_dropped++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4317 | brcmf_sdbrcm_rxfail(bus, false, RETRYCHAN(chan)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4318 | continue; |
| 4319 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4320 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4321 | ASSERT(!(pkt->prev)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4322 | |
| 4323 | /* Leave room for what we already read, and align remainder */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4324 | ASSERT(firstread < pkt->len); |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 4325 | skb_pull(pkt, firstread); |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 4326 | PKTALIGN(pkt, rdlen, BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4327 | |
| 4328 | /* Read the remaining frame data */ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 4329 | sdret = brcmf_sdcard_recv_buf(card, |
| 4330 | brcmf_sdcard_cur_sbwad(card), |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4331 | SDIO_FUNC_2, F2SYNC, ((u8 *) (pkt->data)), |
| 4332 | rdlen, pkt, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4333 | bus->f2rxdata++; |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 4334 | ASSERT(sdret != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4335 | |
| 4336 | if (sdret < 0) { |
| 4337 | DHD_ERROR(("%s: read %d %s bytes failed: %d\n", |
| 4338 | __func__, rdlen, |
| 4339 | ((chan == |
| 4340 | SDPCM_EVENT_CHANNEL) ? "event" : ((chan == |
| 4341 | SDPCM_DATA_CHANNEL) |
| 4342 | ? "data" : "test")), |
| 4343 | sdret)); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4344 | brcmu_pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4345 | bus->dhd->rx_errors++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4346 | brcmf_sdbrcm_rxfail(bus, true, RETRYCHAN(chan)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4347 | continue; |
| 4348 | } |
| 4349 | |
| 4350 | /* Copy the already-read portion */ |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 4351 | skb_push(pkt, firstread); |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 4352 | memcpy(pkt->data, bus->rxhdr, firstread); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4353 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 4354 | #ifdef BCMDBG |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 4355 | if (DHD_BYTES_ON() && DHD_DATA_ON()) { |
| 4356 | printk(KERN_DEBUG "Rx Data:\n"); |
| 4357 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 4358 | pkt->data, len); |
| 4359 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4360 | #endif |
| 4361 | |
| 4362 | deliver: |
| 4363 | /* Save superframe descriptor and allocate packet frame */ |
| 4364 | if (chan == SDPCM_GLOM_CHANNEL) { |
| 4365 | if (SDPCM_GLOMDESC(&bus->rxhdr[SDPCM_FRAMETAG_LEN])) { |
| 4366 | DHD_GLOM(("%s: glom descriptor, %d bytes:\n", |
| 4367 | __func__, len)); |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 4368 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4369 | if (DHD_GLOM_ON()) { |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 4370 | printk(KERN_DEBUG "Glom Data:\n"); |
| 4371 | print_hex_dump_bytes("", |
| 4372 | DUMP_PREFIX_OFFSET, |
| 4373 | pkt->data, len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4374 | } |
| 4375 | #endif |
Arend van Spriel | 2cb8ada | 2010-11-18 20:46:44 +0100 | [diff] [blame] | 4376 | __skb_trim(pkt, len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4377 | ASSERT(doff == SDPCM_HDRLEN); |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 4378 | skb_pull(pkt, SDPCM_HDRLEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4379 | bus->glomd = pkt; |
| 4380 | } else { |
| 4381 | DHD_ERROR(("%s: glom superframe w/o " |
| 4382 | "descriptor!\n", __func__)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4383 | brcmf_sdbrcm_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4384 | } |
| 4385 | continue; |
| 4386 | } |
| 4387 | |
| 4388 | /* Fill in packet len and prio, deliver upward */ |
Arend van Spriel | 2cb8ada | 2010-11-18 20:46:44 +0100 | [diff] [blame] | 4389 | __skb_trim(pkt, len); |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 4390 | skb_pull(pkt, doff); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4391 | |
| 4392 | #ifdef SDTEST |
| 4393 | /* Test channel packets are processed separately */ |
| 4394 | if (chan == SDPCM_TEST_CHANNEL) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4395 | brcmf_sdbrcm_checkdied(bus, pkt, seq); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4396 | continue; |
| 4397 | } |
| 4398 | #endif /* SDTEST */ |
| 4399 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4400 | if (pkt->len == 0) { |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4401 | brcmu_pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4402 | continue; |
Arend van Spriel | 0aa94b8 | 2011-06-29 16:47:13 -0700 | [diff] [blame] | 4403 | } else if (brcmf_proto_hdrpull(bus->dhd, &ifidx, pkt) != 0) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4404 | DHD_ERROR(("%s: rx protocol error\n", __func__)); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4405 | brcmu_pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4406 | bus->dhd->rx_errors++; |
| 4407 | continue; |
| 4408 | } |
| 4409 | |
| 4410 | /* Unlock during rx call */ |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 4411 | brcmf_sdbrcm_sdunlock(bus); |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 4412 | brcmf_rx_frame(bus->dhd, ifidx, pkt, 1); |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 4413 | brcmf_sdbrcm_sdlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4414 | } |
| 4415 | rxcount = maxframes - rxleft; |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 4416 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4417 | /* Message if we hit the limit */ |
| 4418 | if (!rxleft && !sdtest) |
| 4419 | DHD_DATA(("%s: hit rx limit of %d frames\n", __func__, |
| 4420 | maxframes)); |
| 4421 | else |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 4422 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4423 | DHD_DATA(("%s: processed %d frames\n", __func__, rxcount)); |
| 4424 | /* Back off rxseq if awaiting rtx, update rx_seq */ |
| 4425 | if (bus->rxskip) |
| 4426 | rxseq--; |
| 4427 | bus->rx_seq = rxseq; |
| 4428 | |
| 4429 | return rxcount; |
| 4430 | } |
| 4431 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4432 | static u32 brcmf_sdbrcm_hostmail(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4433 | { |
Franky Lin | 597600a | 2011-06-01 13:45:39 +0200 | [diff] [blame] | 4434 | struct sdpcmd_regs *regs = bus->regs; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 4435 | u32 intstatus = 0; |
| 4436 | u32 hmb_data; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4437 | u8 fcbits; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4438 | uint retries = 0; |
| 4439 | |
| 4440 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 4441 | |
| 4442 | /* Read mailbox data and ack that we did so */ |
| 4443 | R_SDREG(hmb_data, ®s->tohostmailboxdata, retries); |
| 4444 | if (retries <= retry_limit) |
| 4445 | W_SDREG(SMB_INT_ACK, ®s->tosbmailbox, retries); |
| 4446 | bus->f1regdata += 2; |
| 4447 | |
| 4448 | /* Dongle recomposed rx frames, accept them again */ |
| 4449 | if (hmb_data & HMB_DATA_NAKHANDLED) { |
| 4450 | DHD_INFO(("Dongle reports NAK handled, expect rtx of %d\n", |
| 4451 | bus->rx_seq)); |
| 4452 | if (!bus->rxskip) |
| 4453 | DHD_ERROR(("%s: unexpected NAKHANDLED!\n", __func__)); |
| 4454 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4455 | bus->rxskip = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4456 | intstatus |= I_HMB_FRAME_IND; |
| 4457 | } |
| 4458 | |
| 4459 | /* |
| 4460 | * DEVREADY does not occur with gSPI. |
| 4461 | */ |
| 4462 | if (hmb_data & (HMB_DATA_DEVREADY | HMB_DATA_FWREADY)) { |
| 4463 | bus->sdpcm_ver = |
| 4464 | (hmb_data & HMB_DATA_VERSION_MASK) >> |
| 4465 | HMB_DATA_VERSION_SHIFT; |
| 4466 | if (bus->sdpcm_ver != SDPCM_PROT_VERSION) |
| 4467 | DHD_ERROR(("Version mismatch, dongle reports %d, " |
| 4468 | "expecting %d\n", |
| 4469 | bus->sdpcm_ver, SDPCM_PROT_VERSION)); |
| 4470 | else |
| 4471 | DHD_INFO(("Dongle ready, protocol version %d\n", |
| 4472 | bus->sdpcm_ver)); |
| 4473 | } |
| 4474 | |
| 4475 | /* |
| 4476 | * 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] | 4477 | * method isn't used any more. |
| 4478 | * remaining backward compatible with older dongles. |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4479 | */ |
| 4480 | if (hmb_data & HMB_DATA_FC) { |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4481 | fcbits = (hmb_data & HMB_DATA_FCDATA_MASK) >> |
| 4482 | HMB_DATA_FCDATA_SHIFT; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4483 | |
| 4484 | if (fcbits & ~bus->flowcontrol) |
| 4485 | bus->fc_xoff++; |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4486 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4487 | if (bus->flowcontrol & ~fcbits) |
| 4488 | bus->fc_xon++; |
| 4489 | |
| 4490 | bus->fc_rcvd++; |
| 4491 | bus->flowcontrol = fcbits; |
| 4492 | } |
| 4493 | |
| 4494 | /* Shouldn't be any others */ |
| 4495 | if (hmb_data & ~(HMB_DATA_DEVREADY | |
| 4496 | HMB_DATA_NAKHANDLED | |
| 4497 | HMB_DATA_FC | |
| 4498 | HMB_DATA_FWREADY | |
| 4499 | HMB_DATA_FCDATA_MASK | HMB_DATA_VERSION_MASK)) { |
| 4500 | DHD_ERROR(("Unknown mailbox data content: 0x%02x\n", hmb_data)); |
| 4501 | } |
| 4502 | |
| 4503 | return intstatus; |
| 4504 | } |
| 4505 | |
Franky Lin | 0827888 | 2011-06-29 16:47:45 -0700 | [diff] [blame] | 4506 | static bool brcmf_sdbrcm_dpc(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4507 | { |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 4508 | struct brcmf_sdio_card *card = bus->card; |
Franky Lin | 597600a | 2011-06-01 13:45:39 +0200 | [diff] [blame] | 4509 | struct sdpcmd_regs *regs = bus->regs; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 4510 | u32 intstatus, newstatus = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4511 | uint retries = 0; |
Arend van Spriel | 7af9d0c | 2011-06-29 16:47:19 -0700 | [diff] [blame] | 4512 | uint rxlimit = brcmf_rxbound; /* Rx frames to read before resched */ |
| 4513 | uint txlimit = brcmf_txbound; /* Tx frames to send before resched */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4514 | uint framecnt = 0; /* Temporary counter of tx/rx frames */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4515 | bool rxdone = true; /* Flag for no more read data */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4516 | bool resched = false; /* Flag indicating resched wanted */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4517 | |
| 4518 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 4519 | |
| 4520 | /* Start with leftover status bits */ |
| 4521 | intstatus = bus->intstatus; |
| 4522 | |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 4523 | brcmf_sdbrcm_sdlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4524 | |
| 4525 | /* If waiting for HTAVAIL, check status */ |
| 4526 | if (bus->clkstate == CLK_PENDING) { |
| 4527 | int err; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4528 | u8 clkctl, devctl = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4529 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 4530 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4531 | /* Check for inconsistent device control */ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 4532 | devctl = brcmf_sdcard_cfg_read(card, SDIO_FUNC_1, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4533 | SBSDIO_DEVICE_CTL, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4534 | if (err) { |
| 4535 | DHD_ERROR(("%s: error reading DEVCTL: %d\n", |
| 4536 | __func__, err)); |
| 4537 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 4538 | } else { |
| 4539 | ASSERT(devctl & SBSDIO_DEVCTL_CA_INT_ONLY); |
| 4540 | } |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 4541 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4542 | |
| 4543 | /* Read CSR, if clock on switch to AVAIL, else ignore */ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 4544 | clkctl = brcmf_sdcard_cfg_read(card, SDIO_FUNC_1, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4545 | SBSDIO_FUNC1_CHIPCLKCSR, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4546 | if (err) { |
| 4547 | DHD_ERROR(("%s: error reading CSR: %d\n", __func__, |
| 4548 | err)); |
| 4549 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 4550 | } |
| 4551 | |
| 4552 | DHD_INFO(("DPC: PENDING, devctl 0x%02x clkctl 0x%02x\n", devctl, |
| 4553 | clkctl)); |
| 4554 | |
| 4555 | if (SBSDIO_HTAV(clkctl)) { |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 4556 | devctl = brcmf_sdcard_cfg_read(card, SDIO_FUNC_1, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4557 | SBSDIO_DEVICE_CTL, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4558 | if (err) { |
| 4559 | DHD_ERROR(("%s: error reading DEVCTL: %d\n", |
| 4560 | __func__, err)); |
| 4561 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 4562 | } |
| 4563 | devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY; |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 4564 | brcmf_sdcard_cfg_write(card, SDIO_FUNC_1, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4565 | SBSDIO_DEVICE_CTL, devctl, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4566 | if (err) { |
| 4567 | DHD_ERROR(("%s: error writing DEVCTL: %d\n", |
| 4568 | __func__, err)); |
| 4569 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 4570 | } |
| 4571 | bus->clkstate = CLK_AVAIL; |
| 4572 | } else { |
| 4573 | goto clkwait; |
| 4574 | } |
| 4575 | } |
| 4576 | |
| 4577 | BUS_WAKE(bus); |
| 4578 | |
| 4579 | /* Make sure backplane clock is on */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4580 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4581 | if (bus->clkstate == CLK_PENDING) |
| 4582 | goto clkwait; |
| 4583 | |
| 4584 | /* Pending interrupt indicates new device status */ |
| 4585 | if (bus->ipend) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4586 | bus->ipend = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4587 | R_SDREG(newstatus, ®s->intstatus, retries); |
| 4588 | bus->f1regdata++; |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 4589 | if (brcmf_sdcard_regfail(bus->card)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4590 | newstatus = 0; |
| 4591 | newstatus &= bus->hostintmask; |
| 4592 | bus->fcstate = !!(newstatus & I_HMB_FC_STATE); |
| 4593 | if (newstatus) { |
| 4594 | W_SDREG(newstatus, ®s->intstatus, retries); |
| 4595 | bus->f1regdata++; |
| 4596 | } |
| 4597 | } |
| 4598 | |
| 4599 | /* Merge new bits with previous */ |
| 4600 | intstatus |= newstatus; |
| 4601 | bus->intstatus = 0; |
| 4602 | |
| 4603 | /* Handle flow-control change: read new state in case our ack |
| 4604 | * crossed another change interrupt. If change still set, assume |
| 4605 | * FC ON for safety, let next loop through do the debounce. |
| 4606 | */ |
| 4607 | if (intstatus & I_HMB_FC_CHANGE) { |
| 4608 | intstatus &= ~I_HMB_FC_CHANGE; |
| 4609 | W_SDREG(I_HMB_FC_CHANGE, ®s->intstatus, retries); |
| 4610 | R_SDREG(newstatus, ®s->intstatus, retries); |
| 4611 | bus->f1regdata += 2; |
| 4612 | bus->fcstate = |
| 4613 | !!(newstatus & (I_HMB_FC_STATE | I_HMB_FC_CHANGE)); |
| 4614 | intstatus |= (newstatus & bus->hostintmask); |
| 4615 | } |
| 4616 | |
| 4617 | /* Handle host mailbox indication */ |
| 4618 | if (intstatus & I_HMB_HOST_INT) { |
| 4619 | intstatus &= ~I_HMB_HOST_INT; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4620 | intstatus |= brcmf_sdbrcm_hostmail(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4621 | } |
| 4622 | |
| 4623 | /* Generally don't ask for these, can get CRC errors... */ |
| 4624 | if (intstatus & I_WR_OOSYNC) { |
| 4625 | DHD_ERROR(("Dongle reports WR_OOSYNC\n")); |
| 4626 | intstatus &= ~I_WR_OOSYNC; |
| 4627 | } |
| 4628 | |
| 4629 | if (intstatus & I_RD_OOSYNC) { |
| 4630 | DHD_ERROR(("Dongle reports RD_OOSYNC\n")); |
| 4631 | intstatus &= ~I_RD_OOSYNC; |
| 4632 | } |
| 4633 | |
| 4634 | if (intstatus & I_SBINT) { |
| 4635 | DHD_ERROR(("Dongle reports SBINT\n")); |
| 4636 | intstatus &= ~I_SBINT; |
| 4637 | } |
| 4638 | |
| 4639 | /* Would be active due to wake-wlan in gSPI */ |
| 4640 | if (intstatus & I_CHIPACTIVE) { |
| 4641 | DHD_INFO(("Dongle reports CHIPACTIVE\n")); |
| 4642 | intstatus &= ~I_CHIPACTIVE; |
| 4643 | } |
| 4644 | |
| 4645 | /* Ignore frame indications if rxskip is set */ |
| 4646 | if (bus->rxskip) |
| 4647 | intstatus &= ~I_HMB_FRAME_IND; |
| 4648 | |
| 4649 | /* On frame indication, read available frames */ |
| 4650 | if (PKT_AVAILABLE()) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4651 | framecnt = brcmf_sdbrcm_readframes(bus, rxlimit, &rxdone); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4652 | if (rxdone || bus->rxskip) |
| 4653 | intstatus &= ~I_HMB_FRAME_IND; |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 4654 | rxlimit -= min(framecnt, rxlimit); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4655 | } |
| 4656 | |
| 4657 | /* Keep still-pending events for next scheduling */ |
| 4658 | bus->intstatus = intstatus; |
| 4659 | |
| 4660 | clkwait: |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4661 | /* Re-enable interrupts to detect new device events (mailbox, rx frame) |
| 4662 | * or clock availability. (Allows tx loop to check ipend if desired.) |
| 4663 | * (Unless register access seems hosed, as we may not be able to ACK...) |
| 4664 | */ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 4665 | if (bus->intr && bus->intdis && !brcmf_sdcard_regfail(card)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4666 | DHD_INTR(("%s: enable SDIO interrupts, rxdone %d framecnt %d\n", |
| 4667 | __func__, rxdone, framecnt)); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4668 | bus->intdis = false; |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 4669 | brcmf_sdcard_intr_enable(card); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4670 | } |
| 4671 | |
| 4672 | if (DATAOK(bus) && bus->ctrl_frame_stat && |
| 4673 | (bus->clkstate == CLK_AVAIL)) { |
| 4674 | int ret, i; |
| 4675 | |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 4676 | ret = brcmf_sdbrcm_send_buf(bus, brcmf_sdcard_cur_sbwad(card), |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4677 | SDIO_FUNC_2, F2SYNC, (u8 *) bus->ctrl_frame_buf, |
| 4678 | (u32) bus->ctrl_frame_len, NULL, NULL, NULL); |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 4679 | ASSERT(ret != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4680 | |
| 4681 | if (ret < 0) { |
| 4682 | /* On failure, abort the command and |
| 4683 | terminate the frame */ |
| 4684 | DHD_INFO(("%s: sdio error %d, abort command and " |
| 4685 | "terminate frame.\n", __func__, ret)); |
| 4686 | bus->tx_sderrs++; |
| 4687 | |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 4688 | brcmf_sdcard_abort(card, SDIO_FUNC_2); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4689 | |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 4690 | brcmf_sdcard_cfg_write(card, SDIO_FUNC_1, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4691 | SBSDIO_FUNC1_FRAMECTRL, SFC_WF_TERM, |
| 4692 | NULL); |
| 4693 | bus->f1regdata++; |
| 4694 | |
| 4695 | for (i = 0; i < 3; i++) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4696 | u8 hi, lo; |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 4697 | hi = brcmf_sdcard_cfg_read(card, SDIO_FUNC_1, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4698 | SBSDIO_FUNC1_WFRAMEBCHI, |
| 4699 | NULL); |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 4700 | lo = brcmf_sdcard_cfg_read(card, SDIO_FUNC_1, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4701 | SBSDIO_FUNC1_WFRAMEBCLO, |
| 4702 | NULL); |
| 4703 | bus->f1regdata += 2; |
| 4704 | if ((hi == 0) && (lo == 0)) |
| 4705 | break; |
| 4706 | } |
| 4707 | |
| 4708 | } |
| 4709 | if (ret == 0) |
| 4710 | bus->tx_seq = (bus->tx_seq + 1) % SDPCM_SEQUENCE_WRAP; |
| 4711 | |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 4712 | DHD_INFO(("Return_dpc value is : %d\n", ret)); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4713 | bus->ctrl_frame_stat = false; |
Franky Lin | b7adfa7 | 2011-06-29 16:47:42 -0700 | [diff] [blame] | 4714 | brcmf_sdbrcm_wait_event_wakeup(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4715 | } |
| 4716 | /* Send queued frames (limit 1 if rx may still be pending) */ |
| 4717 | else if ((bus->clkstate == CLK_AVAIL) && !bus->fcstate && |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4718 | brcmu_pktq_mlen(&bus->txq, ~bus->flowcontrol) && txlimit |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4719 | && DATAOK(bus)) { |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 4720 | framecnt = rxdone ? txlimit : min(txlimit, dhd_txminmax); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4721 | framecnt = brcmf_sdbrcm_sendfromq(bus, framecnt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4722 | txlimit -= framecnt; |
| 4723 | } |
| 4724 | |
| 4725 | /* Resched if events or tx frames are pending, |
| 4726 | else await next interrupt */ |
| 4727 | /* On failed register access, all bets are off: |
| 4728 | no resched or interrupts */ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 4729 | if ((bus->dhd->busstate == DHD_BUS_DOWN) || |
| 4730 | brcmf_sdcard_regfail(card)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4731 | DHD_ERROR(("%s: failed backplane access over SDIO, halting " |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 4732 | "operation %d\n", __func__, |
| 4733 | brcmf_sdcard_regfail(card))); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4734 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 4735 | bus->intstatus = 0; |
| 4736 | } else if (bus->clkstate == CLK_PENDING) { |
| 4737 | DHD_INFO(("%s: rescheduled due to CLK_PENDING awaiting " |
| 4738 | "I_CHIPACTIVE interrupt\n", __func__)); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4739 | resched = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4740 | } else if (bus->intstatus || bus->ipend || |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4741 | (!bus->fcstate && brcmu_pktq_mlen(&bus->txq, ~bus->flowcontrol) |
| 4742 | && DATAOK(bus)) || PKT_AVAILABLE()) { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4743 | resched = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4744 | } |
| 4745 | |
| 4746 | bus->dpc_sched = resched; |
| 4747 | |
| 4748 | /* If we're done for now, turn off clock request. */ |
| 4749 | if ((bus->clkstate != CLK_PENDING) |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 4750 | && bus->idletime == BRCMF_IDLE_IMMEDIATE) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4751 | bus->activity = false; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4752 | brcmf_sdbrcm_clkctl(bus, CLK_NONE, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4753 | } |
| 4754 | |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 4755 | brcmf_sdbrcm_sdunlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4756 | |
| 4757 | return resched; |
| 4758 | } |
| 4759 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4760 | void brcmf_sdbrcm_isr(void *arg) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4761 | { |
| 4762 | dhd_bus_t *bus = (dhd_bus_t *) arg; |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 4763 | struct brcmf_sdio_card *card; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4764 | |
| 4765 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 4766 | |
| 4767 | if (!bus) { |
| 4768 | DHD_ERROR(("%s : bus is null pointer , exit\n", __func__)); |
| 4769 | return; |
| 4770 | } |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 4771 | card = bus->card; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4772 | |
| 4773 | if (bus->dhd->busstate == DHD_BUS_DOWN) { |
| 4774 | DHD_ERROR(("%s : bus is down. we have nothing to do\n", |
| 4775 | __func__)); |
| 4776 | return; |
| 4777 | } |
| 4778 | /* Count the interrupt call */ |
| 4779 | bus->intrcount++; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4780 | bus->ipend = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4781 | |
| 4782 | /* Shouldn't get this interrupt if we're sleeping? */ |
| 4783 | if (bus->sleeping) { |
| 4784 | DHD_ERROR(("INTERRUPT WHILE SLEEPING??\n")); |
| 4785 | return; |
| 4786 | } |
| 4787 | |
| 4788 | /* Disable additional interrupts (is this needed now)? */ |
| 4789 | if (bus->intr) |
| 4790 | DHD_INTR(("%s: disable SDIO interrupts\n", __func__)); |
| 4791 | else |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4792 | DHD_ERROR(("brcmf_sdbrcm_isr() w/o interrupt configured!\n")); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4793 | |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 4794 | brcmf_sdcard_intr_disable(card); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4795 | bus->intdis = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4796 | |
| 4797 | #if defined(SDIO_ISR_THREAD) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4798 | DHD_TRACE(("Calling brcmf_sdbrcm_dpc() from %s\n", __func__)); |
| 4799 | while (brcmf_sdbrcm_dpc(bus)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4800 | ; |
| 4801 | #else |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4802 | bus->dpc_sched = true; |
Franky Lin | 0827888 | 2011-06-29 16:47:45 -0700 | [diff] [blame] | 4803 | brcmf_sdbrcm_sched_dpc(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4804 | #endif |
| 4805 | |
| 4806 | } |
| 4807 | |
| 4808 | #ifdef SDTEST |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4809 | static void brcmf_sdbrcm_pktgen_init(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4810 | { |
| 4811 | /* Default to specified length, or full range */ |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 4812 | if (brcmf_pktgen_len) { |
| 4813 | bus->pktgen_maxlen = min(brcmf_pktgen_len, |
| 4814 | BRCMF_MAX_PKTGEN_LEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4815 | bus->pktgen_minlen = bus->pktgen_maxlen; |
| 4816 | } else { |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 4817 | bus->pktgen_maxlen = BRCMF_MAX_PKTGEN_LEN; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4818 | bus->pktgen_minlen = 0; |
| 4819 | } |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4820 | bus->pktgen_len = (u16) bus->pktgen_minlen; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4821 | |
| 4822 | /* Default to per-watchdog burst with 10s print time */ |
| 4823 | bus->pktgen_freq = 1; |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 4824 | bus->pktgen_print = 10000 / brcmf_watchdog_ms; |
| 4825 | bus->pktgen_count = (brcmf_pktgen * brcmf_watchdog_ms + 999) / 1000; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4826 | |
| 4827 | /* Default to echo mode */ |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 4828 | bus->pktgen_mode = BRCMF_PKTGEN_ECHO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4829 | bus->pktgen_stop = 1; |
| 4830 | } |
| 4831 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4832 | static void brcmf_sdbrcm_pktgen(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4833 | { |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 4834 | struct sk_buff *pkt; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4835 | u8 *data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4836 | uint pktcount; |
| 4837 | uint fillbyte; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4838 | u16 len; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4839 | |
| 4840 | /* Display current count if appropriate */ |
| 4841 | if (bus->pktgen_print && (++bus->pktgen_ptick >= bus->pktgen_print)) { |
| 4842 | bus->pktgen_ptick = 0; |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 4843 | printk(KERN_DEBUG "%s: send attempts %d rcvd %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4844 | __func__, bus->pktgen_sent, bus->pktgen_rcvd); |
| 4845 | } |
| 4846 | |
| 4847 | /* For recv mode, just make sure dongle has started sending */ |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 4848 | if (bus->pktgen_mode == BRCMF_PKTGEN_RECV) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4849 | if (!bus->pktgen_rcvd) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4850 | brcmf_sdbrcm_sdtest_set(bus, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4851 | return; |
| 4852 | } |
| 4853 | |
| 4854 | /* Otherwise, generate or request the specified number of packets */ |
| 4855 | for (pktcount = 0; pktcount < bus->pktgen_count; pktcount++) { |
| 4856 | /* Stop if total has been reached */ |
| 4857 | if (bus->pktgen_total |
| 4858 | && (bus->pktgen_sent >= bus->pktgen_total)) { |
| 4859 | bus->pktgen_count = 0; |
| 4860 | break; |
| 4861 | } |
| 4862 | |
| 4863 | /* Allocate an appropriate-sized packet */ |
| 4864 | len = bus->pktgen_len; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4865 | pkt = brcmu_pkt_buf_get_skb( |
Roland Vossen | 62dd656 | 2011-07-05 22:05:57 +0200 | [diff] [blame] | 4866 | len + SDPCM_HDRLEN + SDPCM_TEST_HDRLEN + BRCMF_SDALIGN, |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4867 | true); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 4868 | if (!pkt) { |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4869 | DHD_ERROR(("%s: brcmu_pkt_buf_get_skb failed!\n", |
| 4870 | __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4871 | break; |
| 4872 | } |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 4873 | PKTALIGN(pkt, (len + SDPCM_HDRLEN + SDPCM_TEST_HDRLEN), |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 4874 | BRCMF_SDALIGN); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4875 | data = (u8 *) (pkt->data) + SDPCM_HDRLEN; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4876 | |
| 4877 | /* Write test header cmd and extra based on mode */ |
| 4878 | switch (bus->pktgen_mode) { |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 4879 | case BRCMF_PKTGEN_ECHO: |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4880 | *data++ = SDPCM_TEST_ECHOREQ; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4881 | *data++ = (u8) bus->pktgen_sent; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4882 | break; |
| 4883 | |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 4884 | case BRCMF_PKTGEN_SEND: |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4885 | *data++ = SDPCM_TEST_DISCARD; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4886 | *data++ = (u8) bus->pktgen_sent; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4887 | break; |
| 4888 | |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 4889 | case BRCMF_PKTGEN_RXBURST: |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4890 | *data++ = SDPCM_TEST_BURST; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4891 | *data++ = (u8) bus->pktgen_count; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4892 | break; |
| 4893 | |
| 4894 | default: |
| 4895 | DHD_ERROR(("Unrecognized pktgen mode %d\n", |
| 4896 | bus->pktgen_mode)); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4897 | brcmu_pkt_buf_free_skb(pkt, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4898 | bus->pktgen_count = 0; |
| 4899 | return; |
| 4900 | } |
| 4901 | |
| 4902 | /* Write test header length field */ |
| 4903 | *data++ = (len >> 0); |
| 4904 | *data++ = (len >> 8); |
| 4905 | |
| 4906 | /* Then fill in the remainder -- N/A for burst, |
| 4907 | but who cares... */ |
| 4908 | for (fillbyte = 0; fillbyte < len; fillbyte++) |
| 4909 | *data++ = |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4910 | SDPCM_TEST_FILL(fillbyte, (u8) bus->pktgen_sent); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4911 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 4912 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4913 | if (DHD_BYTES_ON() && DHD_DATA_ON()) { |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4914 | data = (u8 *) (pkt->data) + SDPCM_HDRLEN; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4915 | printk(KERN_DEBUG "brcmf_sdbrcm_pktgen: Tx Data:\n"); |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 4916 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, data, |
| 4917 | pkt->len - SDPCM_HDRLEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4918 | } |
| 4919 | #endif |
| 4920 | |
| 4921 | /* Send it */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4922 | if (brcmf_sdbrcm_txpkt(bus, pkt, SDPCM_TEST_CHANNEL, true)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4923 | bus->pktgen_fail++; |
| 4924 | if (bus->pktgen_stop |
| 4925 | && bus->pktgen_stop == bus->pktgen_fail) |
| 4926 | bus->pktgen_count = 0; |
| 4927 | } |
| 4928 | bus->pktgen_sent++; |
| 4929 | |
| 4930 | /* Bump length if not fixed, wrap at max */ |
| 4931 | if (++bus->pktgen_len > bus->pktgen_maxlen) |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4932 | bus->pktgen_len = (u16) bus->pktgen_minlen; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4933 | |
| 4934 | /* Special case for burst mode: just send one request! */ |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 4935 | if (bus->pktgen_mode == BRCMF_PKTGEN_RXBURST) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4936 | break; |
| 4937 | } |
| 4938 | } |
| 4939 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4940 | static void brcmf_sdbrcm_sdtest_set(dhd_bus_t *bus, bool start) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4941 | { |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 4942 | struct sk_buff *pkt; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4943 | u8 *data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4944 | |
| 4945 | /* Allocate the packet */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4946 | pkt = brcmu_pkt_buf_get_skb(SDPCM_HDRLEN + SDPCM_TEST_HDRLEN + |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 4947 | BRCMF_SDALIGN, true); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 4948 | if (!pkt) { |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4949 | DHD_ERROR(("%s: brcmu_pkt_buf_get_skb failed!\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4950 | return; |
| 4951 | } |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 4952 | PKTALIGN(pkt, (SDPCM_HDRLEN + SDPCM_TEST_HDRLEN), BRCMF_SDALIGN); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4953 | data = (u8 *) (pkt->data) + SDPCM_HDRLEN; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4954 | |
| 4955 | /* Fill in the test header */ |
| 4956 | *data++ = SDPCM_TEST_SEND; |
| 4957 | *data++ = start; |
| 4958 | *data++ = (bus->pktgen_maxlen >> 0); |
| 4959 | *data++ = (bus->pktgen_maxlen >> 8); |
| 4960 | |
| 4961 | /* Send it */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4962 | if (brcmf_sdbrcm_txpkt(bus, pkt, SDPCM_TEST_CHANNEL, true)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4963 | bus->pktgen_fail++; |
| 4964 | } |
| 4965 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4966 | static void |
| 4967 | 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] | 4968 | { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4969 | u8 *data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4970 | uint pktlen; |
| 4971 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4972 | u8 cmd; |
| 4973 | u8 extra; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4974 | u16 len; |
| 4975 | u16 offset; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4976 | |
| 4977 | /* Check for min length */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4978 | pktlen = pkt->len; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4979 | if (pktlen < SDPCM_TEST_HDRLEN) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4980 | DHD_ERROR(("brcmf_sdbrcm_checkdied: toss runt frame, pktlen " |
| 4981 | "%d\n", pktlen)); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4982 | brcmu_pkt_buf_free_skb(pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4983 | return; |
| 4984 | } |
| 4985 | |
| 4986 | /* Extract header fields */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4987 | data = pkt->data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4988 | cmd = *data++; |
| 4989 | extra = *data++; |
| 4990 | len = *data++; |
| 4991 | len += *data++ << 8; |
| 4992 | |
| 4993 | /* Check length for relevant commands */ |
| 4994 | if (cmd == SDPCM_TEST_DISCARD || cmd == SDPCM_TEST_ECHOREQ |
| 4995 | || cmd == SDPCM_TEST_ECHORSP) { |
| 4996 | if (pktlen != len + SDPCM_TEST_HDRLEN) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4997 | DHD_ERROR(("brcmf_sdbrcm_checkdied: frame length " |
| 4998 | "mismatch, pktlen %d seq %d" " cmd %d extra %d " |
| 4999 | "len %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5000 | pktlen, seq, cmd, extra, len)); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 5001 | brcmu_pkt_buf_free_skb(pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5002 | return; |
| 5003 | } |
| 5004 | } |
| 5005 | |
| 5006 | /* Process as per command */ |
| 5007 | switch (cmd) { |
| 5008 | case SDPCM_TEST_ECHOREQ: |
| 5009 | /* Rx->Tx turnaround ok (even on NDIS w/current |
| 5010 | implementation) */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 5011 | *(u8 *) (pkt->data) = SDPCM_TEST_ECHORSP; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5012 | if (brcmf_sdbrcm_txpkt(bus, pkt, SDPCM_TEST_CHANNEL, true) == 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5013 | bus->pktgen_sent++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5014 | else { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5015 | bus->pktgen_fail++; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 5016 | brcmu_pkt_buf_free_skb(pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5017 | } |
| 5018 | bus->pktgen_rcvd++; |
| 5019 | break; |
| 5020 | |
| 5021 | case SDPCM_TEST_ECHORSP: |
| 5022 | if (bus->ext_loop) { |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 5023 | brcmu_pkt_buf_free_skb(pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5024 | bus->pktgen_rcvd++; |
| 5025 | break; |
| 5026 | } |
| 5027 | |
| 5028 | for (offset = 0; offset < len; offset++, data++) { |
| 5029 | if (*data != SDPCM_TEST_FILL(offset, extra)) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5030 | DHD_ERROR(("brcmf_sdbrcm_checkdied: echo data " |
| 5031 | "mismatch: " "offset %d (len %d) " |
| 5032 | "expect 0x%02x rcvd 0x%02x\n", |
| 5033 | offset, len, |
| 5034 | SDPCM_TEST_FILL(offset, extra), |
| 5035 | *data)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5036 | break; |
| 5037 | } |
| 5038 | } |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 5039 | brcmu_pkt_buf_free_skb(pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5040 | bus->pktgen_rcvd++; |
| 5041 | break; |
| 5042 | |
| 5043 | case SDPCM_TEST_DISCARD: |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 5044 | brcmu_pkt_buf_free_skb(pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5045 | bus->pktgen_rcvd++; |
| 5046 | break; |
| 5047 | |
| 5048 | case SDPCM_TEST_BURST: |
| 5049 | case SDPCM_TEST_SEND: |
| 5050 | default: |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5051 | DHD_INFO(("brcmf_sdbrcm_checkdied: unsupported or unknown " |
| 5052 | "command, pktlen %d seq %d" " cmd %d extra %d len %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5053 | pktlen, seq, cmd, extra, len)); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 5054 | brcmu_pkt_buf_free_skb(pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5055 | break; |
| 5056 | } |
| 5057 | |
| 5058 | /* For recv mode, stop at limie (and tell dongle to stop sending) */ |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 5059 | if (bus->pktgen_mode == BRCMF_PKTGEN_RECV) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5060 | if (bus->pktgen_total |
| 5061 | && (bus->pktgen_rcvd >= bus->pktgen_total)) { |
| 5062 | bus->pktgen_count = 0; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5063 | brcmf_sdbrcm_sdtest_set(bus, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5064 | } |
| 5065 | } |
| 5066 | } |
| 5067 | #endif /* SDTEST */ |
| 5068 | |
Arend van Spriel | fb1d0aa | 2011-06-29 16:47:55 -0700 | [diff] [blame] | 5069 | extern bool brcmf_sdbrcm_bus_watchdog(struct brcmf_pub *dhdp) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5070 | { |
| 5071 | dhd_bus_t *bus; |
| 5072 | |
| 5073 | DHD_TIMER(("%s: Enter\n", __func__)); |
| 5074 | |
| 5075 | bus = dhdp->bus; |
| 5076 | |
| 5077 | if (bus->dhd->dongle_reset) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5078 | return false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5079 | |
| 5080 | /* Ignore the timer if simulating bus down */ |
| 5081 | if (bus->sleeping) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5082 | return false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5083 | |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 5084 | brcmf_sdbrcm_sdlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5085 | |
| 5086 | /* Poll period: check device if appropriate. */ |
| 5087 | if (bus->poll && (++bus->polltick >= bus->pollrate)) { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 5088 | u32 intstatus = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5089 | |
| 5090 | /* Reset poll tick */ |
| 5091 | bus->polltick = 0; |
| 5092 | |
| 5093 | /* Check device if no interrupts */ |
| 5094 | if (!bus->intr || (bus->intrcount == bus->lastintrs)) { |
| 5095 | |
| 5096 | if (!bus->dpc_sched) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 5097 | u8 devpend; |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 5098 | devpend = brcmf_sdcard_cfg_read(bus->card, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5099 | SDIO_FUNC_0, SDIO_CCCR_INTx, |
| 5100 | NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5101 | intstatus = |
| 5102 | devpend & (INTR_STATUS_FUNC1 | |
| 5103 | INTR_STATUS_FUNC2); |
| 5104 | } |
| 5105 | |
| 5106 | /* If there is something, make like the ISR and |
| 5107 | schedule the DPC */ |
| 5108 | if (intstatus) { |
| 5109 | bus->pollcnt++; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5110 | bus->ipend = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5111 | if (bus->intr) |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 5112 | brcmf_sdcard_intr_disable(bus->card); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5113 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5114 | bus->dpc_sched = true; |
Franky Lin | 0827888 | 2011-06-29 16:47:45 -0700 | [diff] [blame] | 5115 | brcmf_sdbrcm_sched_dpc(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5116 | |
| 5117 | } |
| 5118 | } |
| 5119 | |
| 5120 | /* Update interrupt tracking */ |
| 5121 | bus->lastintrs = bus->intrcount; |
| 5122 | } |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 5123 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5124 | /* Poll for console output periodically */ |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 5125 | if (dhdp->busstate == DHD_BUS_DATA && brcmf_console_ms != 0) { |
| 5126 | bus->console.count += brcmf_watchdog_ms; |
| 5127 | if (bus->console.count >= brcmf_console_ms) { |
| 5128 | bus->console.count -= brcmf_console_ms; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5129 | /* Make sure backplane clock is on */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5130 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
| 5131 | if (brcmf_sdbrcm_readconsole(bus) < 0) |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 5132 | brcmf_console_ms = 0; /* On error, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5133 | stop trying */ |
| 5134 | } |
| 5135 | } |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 5136 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5137 | |
| 5138 | #ifdef SDTEST |
| 5139 | /* Generate packets if configured */ |
| 5140 | if (bus->pktgen_count && (++bus->pktgen_tick >= bus->pktgen_freq)) { |
| 5141 | /* Make sure backplane clock is on */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5142 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5143 | bus->pktgen_tick = 0; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5144 | brcmf_sdbrcm_pktgen(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5145 | } |
| 5146 | #endif |
| 5147 | |
| 5148 | /* On idle timeout clear activity flag and/or turn off clock */ |
| 5149 | if ((bus->idletime > 0) && (bus->clkstate == CLK_AVAIL)) { |
| 5150 | if (++bus->idlecount >= bus->idletime) { |
| 5151 | bus->idlecount = 0; |
| 5152 | if (bus->activity) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5153 | bus->activity = false; |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 5154 | brcmf_sdbrcm_wd_timer(bus, brcmf_watchdog_ms); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5155 | } else { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5156 | brcmf_sdbrcm_clkctl(bus, CLK_NONE, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5157 | } |
| 5158 | } |
| 5159 | } |
| 5160 | |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 5161 | brcmf_sdbrcm_sdunlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5162 | |
| 5163 | return bus->ipend; |
| 5164 | } |
| 5165 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 5166 | #ifdef BCMDBG |
Arend van Spriel | fb1d0aa | 2011-06-29 16:47:55 -0700 | [diff] [blame] | 5167 | static int brcmf_sdbrcm_bus_console_in(struct brcmf_pub *drvr, |
| 5168 | unsigned char *msg, uint msglen) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5169 | { |
Arend van Spriel | fb1d0aa | 2011-06-29 16:47:55 -0700 | [diff] [blame] | 5170 | dhd_bus_t *bus = drvr->bus; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 5171 | u32 addr, val; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5172 | int rv; |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 5173 | struct sk_buff *pkt; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5174 | |
| 5175 | /* Address could be zero if CONSOLE := 0 in dongle Makefile */ |
| 5176 | if (bus->console_addr == 0) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 5177 | return -ENOTSUPP; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5178 | |
| 5179 | /* Exclusive bus access */ |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 5180 | brcmf_sdbrcm_sdlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5181 | |
| 5182 | /* Don't allow input if dongle is in reset */ |
| 5183 | if (bus->dhd->dongle_reset) { |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 5184 | brcmf_sdbrcm_sdunlock(bus); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 5185 | return -EPERM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5186 | } |
| 5187 | |
| 5188 | /* Request clock to allow SDIO accesses */ |
| 5189 | BUS_WAKE(bus); |
| 5190 | /* 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] | 5191 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5192 | |
| 5193 | /* Zero cbuf_index */ |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 5194 | addr = bus->console_addr + offsetof(struct rte_console, cbuf_idx); |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 5195 | val = cpu_to_le32(0); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5196 | rv = brcmf_sdbrcm_membytes(bus, true, addr, (u8 *)&val, sizeof(val)); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5197 | if (rv < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5198 | goto done; |
| 5199 | |
| 5200 | /* Write message into cbuf */ |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 5201 | addr = bus->console_addr + offsetof(struct rte_console, cbuf); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5202 | rv = brcmf_sdbrcm_membytes(bus, true, addr, (u8 *)msg, msglen); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5203 | if (rv < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5204 | goto done; |
| 5205 | |
| 5206 | /* Write length into vcons_in */ |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 5207 | addr = bus->console_addr + offsetof(struct rte_console, vcons_in); |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 5208 | val = cpu_to_le32(msglen); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5209 | rv = brcmf_sdbrcm_membytes(bus, true, addr, (u8 *)&val, sizeof(val)); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5210 | if (rv < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5211 | goto done; |
| 5212 | |
| 5213 | /* Bump dongle by sending an empty event pkt. |
| 5214 | * sdpcm_sendup (RX) checks for virtual console input. |
| 5215 | */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 5216 | pkt = brcmu_pkt_buf_get_skb(4 + SDPCM_RESERVE); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5217 | if ((pkt != NULL) && bus->clkstate == CLK_AVAIL) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5218 | brcmf_sdbrcm_txpkt(bus, pkt, SDPCM_EVENT_CHANNEL, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5219 | |
| 5220 | done: |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 5221 | if ((bus->idletime == BRCMF_IDLE_IMMEDIATE) && !bus->dpc_sched) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5222 | bus->activity = false; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5223 | brcmf_sdbrcm_clkctl(bus, CLK_NONE, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5224 | } |
| 5225 | |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 5226 | brcmf_sdbrcm_sdunlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5227 | |
| 5228 | return rv; |
| 5229 | } |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 5230 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5231 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5232 | static bool brcmf_sdbrcm_chipmatch(u16 chipid) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5233 | { |
| 5234 | if (chipid == BCM4325_CHIP_ID) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5235 | return true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5236 | if (chipid == BCM4329_CHIP_ID) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5237 | return true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5238 | if (chipid == BCM4319_CHIP_ID) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5239 | return true; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5240 | return false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5241 | } |
| 5242 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5243 | 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] | 5244 | u16 slot, u16 func, uint bustype, void *regsva, |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 5245 | void *card) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5246 | { |
| 5247 | int ret; |
| 5248 | dhd_bus_t *bus; |
| 5249 | |
| 5250 | /* Init global variables at run-time, not as part of the declaration. |
| 5251 | * This is required to support init/de-init of the driver. |
| 5252 | * Initialization |
| 5253 | * of globals as part of the declaration results in non-deterministic |
| 5254 | * behavior since the value of the globals may be different on the |
| 5255 | * first time that the driver is initialized vs subsequent |
| 5256 | * initializations. |
| 5257 | */ |
Arend van Spriel | 7af9d0c | 2011-06-29 16:47:19 -0700 | [diff] [blame] | 5258 | brcmf_txbound = DHD_TXBOUND; |
| 5259 | brcmf_rxbound = DHD_RXBOUND; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5260 | dhd_alignctl = true; |
| 5261 | sd1idle = true; |
| 5262 | dhd_readahead = true; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5263 | retrydata = false; |
Arend van Spriel | 7af9d0c | 2011-06-29 16:47:19 -0700 | [diff] [blame] | 5264 | brcmf_dongle_memsize = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5265 | dhd_txminmax = DHD_TXMINMAX; |
| 5266 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5267 | forcealign = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5268 | |
Arend van Spriel | aba5e0a | 2011-06-29 16:47:03 -0700 | [diff] [blame] | 5269 | brcmf_c_init(); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5270 | |
| 5271 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5272 | DHD_INFO(("%s: venid 0x%04x devid 0x%04x\n", __func__, venid, devid)); |
| 5273 | |
| 5274 | /* We make assumptions about address window mappings */ |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 5275 | ASSERT((unsigned long)regsva == SI_ENUM_BASE); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5276 | |
Roland Vossen | 62dd656 | 2011-07-05 22:05:57 +0200 | [diff] [blame] | 5277 | /* SDIO car passes venid and devid based on CIS parsing -- but |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5278 | * low-power start |
| 5279 | * means early parse could fail, so here we should get either an ID |
| 5280 | * we recognize OR (-1) indicating we must request power first. |
| 5281 | */ |
| 5282 | /* Check the Vendor ID */ |
| 5283 | switch (venid) { |
| 5284 | case 0x0000: |
Stanislav Fomichev | be1c09f | 2011-03-28 01:31:36 +0400 | [diff] [blame] | 5285 | case PCI_VENDOR_ID_BROADCOM: |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5286 | break; |
| 5287 | default: |
| 5288 | DHD_ERROR(("%s: unknown vendor: 0x%04x\n", __func__, venid)); |
| 5289 | return NULL; |
| 5290 | } |
| 5291 | |
| 5292 | /* Check the Device ID and make sure it's one that we support */ |
| 5293 | switch (devid) { |
| 5294 | case BCM4325_D11DUAL_ID: /* 4325 802.11a/g id */ |
| 5295 | case BCM4325_D11G_ID: /* 4325 802.11g 2.4Ghz band id */ |
| 5296 | case BCM4325_D11A_ID: /* 4325 802.11a 5Ghz band id */ |
| 5297 | DHD_INFO(("%s: found 4325 Dongle\n", __func__)); |
| 5298 | break; |
| 5299 | case BCM4329_D11NDUAL_ID: /* 4329 802.11n dualband device */ |
| 5300 | case BCM4329_D11N2G_ID: /* 4329 802.11n 2.4G device */ |
| 5301 | case BCM4329_D11N5G_ID: /* 4329 802.11n 5G device */ |
| 5302 | case 0x4329: |
| 5303 | DHD_INFO(("%s: found 4329 Dongle\n", __func__)); |
| 5304 | break; |
| 5305 | case BCM4319_D11N_ID: /* 4319 802.11n id */ |
| 5306 | case BCM4319_D11N2G_ID: /* 4319 802.11n2g id */ |
| 5307 | case BCM4319_D11N5G_ID: /* 4319 802.11n5g id */ |
| 5308 | DHD_INFO(("%s: found 4319 Dongle\n", __func__)); |
| 5309 | break; |
| 5310 | case 0: |
| 5311 | DHD_INFO(("%s: allow device id 0, will check chip internals\n", |
| 5312 | __func__)); |
| 5313 | break; |
| 5314 | |
| 5315 | default: |
| 5316 | DHD_ERROR(("%s: skipping 0x%04x/0x%04x, not a dongle\n", |
| 5317 | __func__, venid, devid)); |
| 5318 | return NULL; |
| 5319 | } |
| 5320 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5321 | /* Allocate private bus interface state */ |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5322 | bus = kzalloc(sizeof(dhd_bus_t), GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5323 | if (!bus) { |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5324 | DHD_ERROR(("%s: kmalloc of dhd_bus_t failed\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5325 | goto fail; |
| 5326 | } |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 5327 | bus->card = card; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5328 | bus->cl_devid = (u16) devid; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5329 | bus->bus = DHD_BUS; |
| 5330 | bus->tx_seq = SDPCM_SEQUENCE_WRAP - 1; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5331 | bus->usebufpool = false; /* Use bufpool if allocated, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5332 | else use locally malloced rxbuf */ |
| 5333 | |
| 5334 | /* attempt to attach to the dongle */ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 5335 | if (!(brcmf_sdbrcm_probe_attach(bus, card, regsva, devid))) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5336 | DHD_ERROR(("%s: brcmf_sdbrcm_probe_attach failed\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5337 | goto fail; |
| 5338 | } |
| 5339 | |
Franky Lin | 0f1a87c | 2011-06-29 16:46:32 -0700 | [diff] [blame] | 5340 | spin_lock_init(&bus->txqlock); |
Franky Lin | b7adfa7 | 2011-06-29 16:47:42 -0700 | [diff] [blame] | 5341 | init_waitqueue_head(&bus->ctrl_wait); |
Franky Lin | 0f1a87c | 2011-06-29 16:46:32 -0700 | [diff] [blame] | 5342 | |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 5343 | /* Set up the watchdog timer */ |
| 5344 | init_timer(&bus->timer); |
| 5345 | bus->timer.data = (unsigned long)bus; |
| 5346 | bus->timer.function = brcmf_sdbrcm_watchdog; |
| 5347 | |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 5348 | /* Initialize thread based operation and lock */ |
| 5349 | if ((brcmf_watchdog_prio >= 0) && (brcmf_dpc_prio >= 0)) { |
| 5350 | bus->threads_only = true; |
| 5351 | sema_init(&bus->sdsem, 1); |
| 5352 | } else { |
| 5353 | bus->threads_only = false; |
| 5354 | spin_lock_init(&bus->sdlock); |
| 5355 | } |
| 5356 | |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 5357 | if (brcmf_dpc_prio >= 0) { |
| 5358 | /* Initialize watchdog thread */ |
| 5359 | init_completion(&bus->watchdog_wait); |
| 5360 | bus->watchdog_tsk = kthread_run(brcmf_sdbrcm_watchdog_thread, |
| 5361 | bus, "brcmf_watchdog"); |
| 5362 | if (IS_ERR(bus->watchdog_tsk)) { |
| 5363 | printk(KERN_WARNING |
| 5364 | "brcmf_watchdog thread failed to start\n"); |
| 5365 | bus->watchdog_tsk = NULL; |
| 5366 | } |
| 5367 | } else |
| 5368 | bus->watchdog_tsk = NULL; |
| 5369 | |
Franky Lin | 0827888 | 2011-06-29 16:47:45 -0700 | [diff] [blame] | 5370 | /* Set up the bottom half handler */ |
| 5371 | if (brcmf_dpc_prio >= 0) { |
| 5372 | /* Initialize DPC thread */ |
| 5373 | init_completion(&bus->dpc_wait); |
| 5374 | bus->dpc_tsk = kthread_run(brcmf_sdbrcm_dpc_thread, |
| 5375 | bus, "dhd_dpc"); |
| 5376 | if (IS_ERR(bus->dpc_tsk)) { |
| 5377 | printk(KERN_WARNING |
| 5378 | "dhd_dpc thread failed to start\n"); |
| 5379 | bus->dpc_tsk = NULL; |
| 5380 | } |
| 5381 | } else { |
| 5382 | tasklet_init(&bus->tasklet, brcmf_sdbrcm_dpc_tasklet, |
| 5383 | (unsigned long)bus); |
| 5384 | bus->dpc_tsk = NULL; |
| 5385 | } |
| 5386 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5387 | /* Attach to the dhd/OS/network interface */ |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 5388 | bus->dhd = brcmf_attach(bus, SDPCM_RESERVE); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5389 | if (!bus->dhd) { |
| 5390 | DHD_ERROR(("%s: dhd_attach failed\n", __func__)); |
| 5391 | goto fail; |
| 5392 | } |
| 5393 | |
| 5394 | /* Allocate buffers */ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 5395 | if (!(brcmf_sdbrcm_probe_malloc(bus, card))) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5396 | DHD_ERROR(("%s: brcmf_sdbrcm_probe_malloc failed\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5397 | goto fail; |
| 5398 | } |
| 5399 | |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 5400 | if (!(brcmf_sdbrcm_probe_init(bus, card))) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5401 | DHD_ERROR(("%s: brcmf_sdbrcm_probe_init failed\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5402 | goto fail; |
| 5403 | } |
| 5404 | |
| 5405 | /* Register interrupt callback, but mask it (not operational yet). */ |
| 5406 | DHD_INTR(("%s: disable SDIO interrupts (not interested yet)\n", |
| 5407 | __func__)); |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 5408 | brcmf_sdcard_intr_disable(card); |
| 5409 | ret = brcmf_sdcard_intr_reg(card, brcmf_sdbrcm_isr, bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5410 | if (ret != 0) { |
Roland Vossen | 62dd656 | 2011-07-05 22:05:57 +0200 | [diff] [blame] | 5411 | DHD_ERROR(("%s: FAILED: sdcard_intr_reg returned %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5412 | __func__, ret)); |
| 5413 | goto fail; |
| 5414 | } |
| 5415 | DHD_INTR(("%s: registered SDIO interrupt function ok\n", __func__)); |
| 5416 | |
| 5417 | DHD_INFO(("%s: completed!!\n", __func__)); |
| 5418 | |
| 5419 | /* if firmware path present try to download and bring up bus */ |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 5420 | ret = brcmf_bus_start(bus->dhd); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5421 | if (ret != 0) { |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 5422 | if (ret == -ENOLINK) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5423 | DHD_ERROR(("%s: dongle is not responding\n", __func__)); |
| 5424 | goto fail; |
| 5425 | } |
| 5426 | } |
| 5427 | /* 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] | 5428 | if (brcmf_net_attach(bus->dhd, 0) != 0) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5429 | DHD_ERROR(("%s: Net attach failed!!\n", __func__)); |
| 5430 | goto fail; |
| 5431 | } |
| 5432 | |
| 5433 | return bus; |
| 5434 | |
| 5435 | fail: |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5436 | brcmf_sdbrcm_release(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5437 | return NULL; |
| 5438 | } |
| 5439 | |
| 5440 | static bool |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 5441 | brcmf_sdbrcm_probe_attach(struct dhd_bus *bus, void *card, void *regsva, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5442 | u16 devid) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5443 | { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 5444 | u8 clkctl = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5445 | int err = 0; |
| 5446 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5447 | bus->alp_only = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5448 | |
| 5449 | /* Return the window to backplane enumeration space for core access */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5450 | if (brcmf_sdbrcm_set_siaddr_window(bus, SI_ENUM_BASE)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5451 | DHD_ERROR(("%s: FAILED to return to SI_ENUM_BASE\n", __func__)); |
| 5452 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 5453 | #ifdef BCMDBG |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 5454 | printk(KERN_DEBUG "F1 signature read @0x18000000=0x%4x\n", |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 5455 | brcmf_sdcard_reg_read(bus->card, SI_ENUM_BASE, 4)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5456 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 5457 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5458 | |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 5459 | /* |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5460 | * Force PLL off until brcmf_sdbrcm_chip_attach() |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 5461 | * programs PLL control regs |
| 5462 | */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5463 | |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 5464 | brcmf_sdcard_cfg_write(card, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5465 | DHD_INIT_CLKCTL1, &err); |
| 5466 | if (!err) |
| 5467 | clkctl = |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 5468 | brcmf_sdcard_cfg_read(card, SDIO_FUNC_1, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5469 | SBSDIO_FUNC1_CHIPCLKCSR, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5470 | |
| 5471 | if (err || ((clkctl & ~SBSDIO_AVBITS) != DHD_INIT_CLKCTL1)) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5472 | DHD_ERROR(("brcmf_sdbrcm_probe: ChipClkCSR access: err %d wrote" |
| 5473 | " 0x%02x read 0x%02x\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5474 | err, DHD_INIT_CLKCTL1, clkctl)); |
| 5475 | goto fail; |
| 5476 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5477 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5478 | if (brcmf_sdbrcm_chip_attach(bus, regsva)) { |
| 5479 | DHD_ERROR(("%s: brcmf_sdbrcm_chip_attach failed!\n", __func__)); |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 5480 | goto fail; |
| 5481 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5482 | |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 5483 | brcmf_sdcard_chipinfo(card, bus->ci->chip, bus->ci->chiprev); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5484 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5485 | if (!brcmf_sdbrcm_chipmatch((u16) bus->ci->chip)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5486 | DHD_ERROR(("%s: unsupported chip: 0x%04x\n", |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 5487 | __func__, bus->ci->chip)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5488 | goto fail; |
| 5489 | } |
| 5490 | |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 5491 | brcmf_sdbrcm_sdiod_drive_strength_init(bus, brcmf_sdiod_drive_strength); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5492 | |
| 5493 | /* Get info on the ARM and SOCRAM cores... */ |
| 5494 | if (!DHD_NOPMU(bus)) { |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 5495 | bus->armrev = SBCOREREV(brcmf_sdcard_reg_read(bus->card, |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 5496 | CORE_SB(bus->ci->armcorebase, sbidhigh), 4)); |
| 5497 | bus->orig_ramsize = bus->ci->ramsize; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5498 | if (!(bus->orig_ramsize)) { |
| 5499 | DHD_ERROR(("%s: failed to find SOCRAM memory!\n", |
| 5500 | __func__)); |
| 5501 | goto fail; |
| 5502 | } |
| 5503 | bus->ramsize = bus->orig_ramsize; |
Arend van Spriel | 7af9d0c | 2011-06-29 16:47:19 -0700 | [diff] [blame] | 5504 | if (brcmf_dongle_memsize) |
| 5505 | brcmf_sdbrcm_setmemsize(bus, brcmf_dongle_memsize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5506 | |
| 5507 | DHD_ERROR(("DHD: dongle ram size is set to %d(orig %d)\n", |
| 5508 | bus->ramsize, bus->orig_ramsize)); |
| 5509 | } |
| 5510 | |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 5511 | bus->regs = (void *)bus->ci->buscorebase; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5512 | |
| 5513 | /* Set core control so an SDIO reset does a backplane reset */ |
Arend van Spriel | ff31c54 | 2011-03-01 10:56:54 +0100 | [diff] [blame] | 5514 | OR_REG(&bus->regs->corecontrol, CC_BPRESEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5515 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 5516 | brcmu_pktq_init(&bus->txq, (PRIOMASK + 1), TXQLEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5517 | |
| 5518 | /* Locate an appropriately-aligned portion of hdrbuf */ |
Roland Vossen | 62dd656 | 2011-07-05 22:05:57 +0200 | [diff] [blame] | 5519 | bus->rxhdr = (u8 *) roundup((unsigned long)&bus->hdrbuf[0], |
| 5520 | BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5521 | |
| 5522 | /* Set the poll and/or interrupt flags */ |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 5523 | bus->intr = (bool) brcmf_intr; |
| 5524 | bus->poll = (bool) brcmf_poll; |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5525 | if (bus->poll) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5526 | bus->pollrate = 1; |
| 5527 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5528 | return true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5529 | |
| 5530 | fail: |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5531 | return false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5532 | } |
| 5533 | |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 5534 | static bool brcmf_sdbrcm_probe_malloc(dhd_bus_t *bus, void *card) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5535 | { |
| 5536 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5537 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5538 | if (bus->dhd->maxctl) { |
| 5539 | bus->rxblen = |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 5540 | roundup((bus->dhd->maxctl + SDPCM_HDRLEN), |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 5541 | ALIGNMENT) + BRCMF_SDALIGN; |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5542 | bus->rxbuf = kmalloc(bus->rxblen, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5543 | if (!(bus->rxbuf)) { |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5544 | DHD_ERROR(("%s: kmalloc of %d-byte rxbuf failed\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5545 | __func__, bus->rxblen)); |
| 5546 | goto fail; |
| 5547 | } |
| 5548 | } |
| 5549 | |
| 5550 | /* Allocate buffer to receive glomed packet */ |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5551 | bus->databuf = kmalloc(MAX_DATA_BUF, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5552 | if (!(bus->databuf)) { |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5553 | DHD_ERROR(("%s: kmalloc of %d-byte databuf failed\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5554 | __func__, MAX_DATA_BUF)); |
| 5555 | /* release rxbuf which was already located as above */ |
| 5556 | if (!bus->rxblen) |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 5557 | kfree(bus->rxbuf); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5558 | goto fail; |
| 5559 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5560 | |
| 5561 | /* Align the buffer */ |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 5562 | if ((unsigned long)bus->databuf % BRCMF_SDALIGN) |
Roland Vossen | 62dd656 | 2011-07-05 22:05:57 +0200 | [diff] [blame] | 5563 | bus->dataptr = bus->databuf + (BRCMF_SDALIGN - |
| 5564 | ((unsigned long)bus->databuf % BRCMF_SDALIGN)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5565 | else |
| 5566 | bus->dataptr = bus->databuf; |
| 5567 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5568 | return true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5569 | |
| 5570 | fail: |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5571 | return false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5572 | } |
| 5573 | |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 5574 | static bool brcmf_sdbrcm_probe_init(dhd_bus_t *bus, void *card) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5575 | { |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 5576 | s32 fnum; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5577 | |
| 5578 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5579 | |
| 5580 | #ifdef SDTEST |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5581 | brcmf_sdbrcm_pktgen_init(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5582 | #endif /* SDTEST */ |
| 5583 | |
| 5584 | /* Disable F2 to clear any intermediate frame state on the dongle */ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 5585 | brcmf_sdcard_cfg_write(card, SDIO_FUNC_0, SDIO_CCCR_IOEx, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5586 | SDIO_FUNC_ENABLE_1, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5587 | |
| 5588 | bus->dhd->busstate = DHD_BUS_DOWN; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5589 | bus->sleeping = false; |
| 5590 | bus->rxflow = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5591 | bus->prev_rxlim_hit = 0; |
| 5592 | |
| 5593 | /* Done with backplane-dependent accesses, can drop clock... */ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 5594 | brcmf_sdcard_cfg_write(card, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, 0, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5595 | NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5596 | |
| 5597 | /* ...and initialize clock/power states */ |
| 5598 | bus->clkstate = CLK_SDONLY; |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 5599 | bus->idletime = (s32) brcmf_idletime; |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 5600 | bus->idleclock = BRCMF_IDLE_ACTIVE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5601 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5602 | /* Query the F2 block size, set roundup accordingly */ |
| 5603 | fnum = 2; |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 5604 | if (brcmf_sdcard_iovar_op(card, "sd_blocksize", &fnum, sizeof(s32), |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 5605 | &bus->blocksize, sizeof(s32), false) != 0) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5606 | bus->blocksize = 0; |
| 5607 | DHD_ERROR(("%s: fail on %s get\n", __func__, "sd_blocksize")); |
| 5608 | } else { |
| 5609 | DHD_INFO(("%s: Initial value for %s is %d\n", |
| 5610 | __func__, "sd_blocksize", bus->blocksize)); |
| 5611 | } |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 5612 | bus->roundup = min(max_roundup, bus->blocksize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5613 | |
| 5614 | /* Query if bus module supports packet chaining, |
| 5615 | default to use if supported */ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 5616 | if (brcmf_sdcard_iovar_op(card, "sd_rxchain", NULL, 0, |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 5617 | &bus->sd_rxchain, sizeof(s32), |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 5618 | false) != 0) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5619 | bus->sd_rxchain = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5620 | } else { |
Roland Vossen | 62dd656 | 2011-07-05 22:05:57 +0200 | [diff] [blame] | 5621 | DHD_INFO(("%s: bus module (through sdiocard API) %s chaining\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5622 | __func__, |
| 5623 | (bus->sd_rxchain ? "supports" : "does not support"))); |
| 5624 | } |
| 5625 | bus->use_rxchain = (bool) bus->sd_rxchain; |
| 5626 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5627 | return true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5628 | } |
| 5629 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5630 | static bool |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 5631 | brcmf_sdbrcm_download_firmware(struct dhd_bus *bus, void *card) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5632 | { |
| 5633 | bool ret; |
| 5634 | |
| 5635 | /* Download the firmware */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5636 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5637 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5638 | ret = _brcmf_sdbrcm_download_firmware(bus) == 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5639 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5640 | brcmf_sdbrcm_clkctl(bus, CLK_SDONLY, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5641 | |
| 5642 | return ret; |
| 5643 | } |
| 5644 | |
| 5645 | /* Detach and free everything */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5646 | static void brcmf_sdbrcm_release(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5647 | { |
| 5648 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5649 | |
| 5650 | if (bus) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5651 | /* De-register interrupt handler */ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 5652 | brcmf_sdcard_intr_disable(bus->card); |
| 5653 | brcmf_sdcard_intr_dereg(bus->card); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5654 | |
| 5655 | if (bus->dhd) { |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 5656 | brcmf_detach(bus->dhd); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5657 | brcmf_sdbrcm_release_dongle(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5658 | bus->dhd = NULL; |
| 5659 | } |
| 5660 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5661 | brcmf_sdbrcm_release_malloc(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5662 | |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 5663 | kfree(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5664 | } |
| 5665 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5666 | DHD_TRACE(("%s: Disconnected\n", __func__)); |
| 5667 | } |
| 5668 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5669 | static void brcmf_sdbrcm_release_malloc(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5670 | { |
| 5671 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5672 | |
| 5673 | if (bus->dhd && bus->dhd->dongle_reset) |
| 5674 | return; |
| 5675 | |
Henry Ptasinski | 521223a | 2011-06-29 16:46:55 -0700 | [diff] [blame] | 5676 | kfree(bus->rxbuf); |
| 5677 | bus->rxctl = bus->rxbuf = NULL; |
| 5678 | bus->rxlen = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5679 | |
Ilia Mirkin | 46d994b | 2011-03-13 00:28:56 -0500 | [diff] [blame] | 5680 | kfree(bus->databuf); |
| 5681 | bus->databuf = NULL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5682 | } |
| 5683 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5684 | static void brcmf_sdbrcm_release_dongle(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5685 | { |
| 5686 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5687 | |
| 5688 | if (bus->dhd && bus->dhd->dongle_reset) |
| 5689 | return; |
| 5690 | |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 5691 | if (bus->ci) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5692 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
| 5693 | brcmf_sdbrcm_clkctl(bus, CLK_NONE, false); |
| 5694 | brcmf_sdbrcm_chip_detach(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5695 | if (bus->vars && bus->varsz) |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 5696 | kfree(bus->vars); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5697 | bus->vars = NULL; |
| 5698 | } |
| 5699 | |
| 5700 | DHD_TRACE(("%s: Disconnected\n", __func__)); |
| 5701 | } |
| 5702 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5703 | static void brcmf_sdbrcm_disconnect(void *ptr) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5704 | { |
| 5705 | dhd_bus_t *bus = (dhd_bus_t *)ptr; |
| 5706 | |
| 5707 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5708 | |
| 5709 | if (bus) { |
| 5710 | ASSERT(bus->dhd); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5711 | brcmf_sdbrcm_release(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5712 | } |
| 5713 | |
| 5714 | DHD_TRACE(("%s: Disconnected\n", __func__)); |
| 5715 | } |
| 5716 | |
| 5717 | /* Register/Unregister functions are called by the main DHD entry |
| 5718 | * point (e.g. module insertion) to link with the bus driver, in |
| 5719 | * order to look for or await the device. |
| 5720 | */ |
| 5721 | |
Roland Vossen | 8965004 | 2011-06-29 16:47:22 -0700 | [diff] [blame] | 5722 | static struct brcmf_sdioh_driver dhd_sdio = { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5723 | brcmf_sdbrcm_probe, |
| 5724 | brcmf_sdbrcm_disconnect |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5725 | }; |
| 5726 | |
| 5727 | int dhd_bus_register(void) |
| 5728 | { |
| 5729 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5730 | |
Franky Lin | 0827888 | 2011-06-29 16:47:45 -0700 | [diff] [blame] | 5731 | /* Sanity check on the module parameters */ |
| 5732 | do { |
| 5733 | /* Both watchdog and DPC as tasklets are ok */ |
| 5734 | if ((brcmf_watchdog_prio < 0) && (brcmf_dpc_prio < 0)) |
| 5735 | break; |
| 5736 | |
| 5737 | /* If both watchdog and DPC are threads, TX must be deferred */ |
| 5738 | if ((brcmf_watchdog_prio >= 0) && (brcmf_dpc_prio >= 0) |
| 5739 | && brcmf_deferred_tx) |
| 5740 | break; |
| 5741 | |
| 5742 | DHD_ERROR(("Invalid module parameters.\n")); |
| 5743 | return -EINVAL; |
| 5744 | } while (0); |
| 5745 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5746 | return brcmf_sdio_register(&dhd_sdio); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5747 | } |
| 5748 | |
| 5749 | void dhd_bus_unregister(void) |
| 5750 | { |
| 5751 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5752 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5753 | brcmf_sdio_unregister(); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5754 | } |
| 5755 | |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 5756 | static int brcmf_sdbrcm_download_code_file(struct dhd_bus *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5757 | { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5758 | int offset = 0; |
| 5759 | uint len; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 5760 | u8 *memblock = NULL, *memptr; |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 5761 | int ret; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5762 | |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 5763 | DHD_INFO(("%s: Enter\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5764 | |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 5765 | bus->fw_name = BCM4329_FW_NAME; |
| 5766 | ret = request_firmware(&bus->firmware, bus->fw_name, |
| 5767 | &gInstance->func[2]->dev); |
| 5768 | if (ret) { |
| 5769 | DHD_ERROR(("%s: Fail to request firmware %d\n", __func__, ret)); |
| 5770 | return ret; |
| 5771 | } |
| 5772 | bus->fw_ptr = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5773 | |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 5774 | memptr = memblock = kmalloc(MEMBLOCK + BRCMF_SDALIGN, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5775 | if (memblock == NULL) { |
| 5776 | DHD_ERROR(("%s: Failed to allocate memory %d bytes\n", |
| 5777 | __func__, MEMBLOCK)); |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 5778 | ret = -ENOMEM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5779 | goto err; |
| 5780 | } |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 5781 | if ((u32)(unsigned long)memblock % BRCMF_SDALIGN) |
Roland Vossen | 62dd656 | 2011-07-05 22:05:57 +0200 | [diff] [blame] | 5782 | memptr += (BRCMF_SDALIGN - |
| 5783 | ((u32)(unsigned long)memblock % BRCMF_SDALIGN)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5784 | |
| 5785 | /* Download image */ |
| 5786 | while ((len = |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 5787 | brcmf_sdbrcm_get_image((char *)memptr, MEMBLOCK, bus))) { |
| 5788 | ret = brcmf_sdbrcm_membytes(bus, true, offset, memptr, len); |
| 5789 | if (ret) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5790 | DHD_ERROR(("%s: error %d on writing %d membytes at " |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 5791 | "0x%08x\n", __func__, ret, MEMBLOCK, offset)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5792 | goto err; |
| 5793 | } |
| 5794 | |
| 5795 | offset += MEMBLOCK; |
| 5796 | } |
| 5797 | |
| 5798 | err: |
Ilia Mirkin | 46d994b | 2011-03-13 00:28:56 -0500 | [diff] [blame] | 5799 | kfree(memblock); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5800 | |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 5801 | release_firmware(bus->firmware); |
| 5802 | bus->fw_ptr = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5803 | |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 5804 | return ret; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5805 | } |
| 5806 | |
| 5807 | /* |
| 5808 | * ProcessVars:Takes a buffer of "<var>=<value>\n" lines read from a file |
| 5809 | * and ending in a NUL. |
| 5810 | * Removes carriage returns, empty lines, comment lines, and converts |
| 5811 | * newlines to NULs. |
| 5812 | * Shortens buffer as needed and pads with NULs. End of buffer is marked |
| 5813 | * by two NULs. |
| 5814 | */ |
| 5815 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5816 | static uint brcmf_process_nvram_vars(char *varbuf, uint len) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5817 | { |
| 5818 | char *dp; |
| 5819 | bool findNewline; |
| 5820 | int column; |
| 5821 | uint buf_len, n; |
| 5822 | |
| 5823 | dp = varbuf; |
| 5824 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5825 | findNewline = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5826 | column = 0; |
| 5827 | |
| 5828 | for (n = 0; n < len; n++) { |
| 5829 | if (varbuf[n] == 0) |
| 5830 | break; |
| 5831 | if (varbuf[n] == '\r') |
| 5832 | continue; |
| 5833 | if (findNewline && varbuf[n] != '\n') |
| 5834 | continue; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5835 | findNewline = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5836 | if (varbuf[n] == '#') { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5837 | findNewline = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5838 | continue; |
| 5839 | } |
| 5840 | if (varbuf[n] == '\n') { |
| 5841 | if (column == 0) |
| 5842 | continue; |
| 5843 | *dp++ = 0; |
| 5844 | column = 0; |
| 5845 | continue; |
| 5846 | } |
| 5847 | *dp++ = varbuf[n]; |
| 5848 | column++; |
| 5849 | } |
| 5850 | buf_len = dp - varbuf; |
| 5851 | |
| 5852 | while (dp < varbuf + n) |
| 5853 | *dp++ = 0; |
| 5854 | |
| 5855 | return buf_len; |
| 5856 | } |
| 5857 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5858 | static int brcmf_sdbrcm_download_nvram(struct dhd_bus *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5859 | { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5860 | uint len; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5861 | char *memblock = NULL; |
| 5862 | char *bufp; |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 5863 | int ret; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5864 | |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 5865 | bus->nv_name = BCM4329_NV_NAME; |
| 5866 | ret = request_firmware(&bus->firmware, bus->nv_name, |
| 5867 | &gInstance->func[2]->dev); |
| 5868 | if (ret) { |
| 5869 | DHD_ERROR(("%s: Fail to request nvram %d\n", __func__, ret)); |
| 5870 | return ret; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5871 | } |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 5872 | bus->fw_ptr = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5873 | |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5874 | memblock = kmalloc(MEMBLOCK, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5875 | if (memblock == NULL) { |
| 5876 | DHD_ERROR(("%s: Failed to allocate memory %d bytes\n", |
| 5877 | __func__, MEMBLOCK)); |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 5878 | ret = -ENOMEM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5879 | goto err; |
| 5880 | } |
| 5881 | |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 5882 | len = brcmf_sdbrcm_get_image(memblock, MEMBLOCK, bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5883 | |
| 5884 | if (len > 0 && len < MEMBLOCK) { |
| 5885 | bufp = (char *)memblock; |
| 5886 | bufp[len] = 0; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5887 | len = brcmf_process_nvram_vars(bufp, len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5888 | bufp += len; |
| 5889 | *bufp++ = 0; |
| 5890 | if (len) |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 5891 | ret = brcmf_sdbrcm_downloadvars(bus, memblock, len + 1); |
| 5892 | if (ret) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5893 | DHD_ERROR(("%s: error downloading vars: %d\n", |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 5894 | __func__, ret)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5895 | } else { |
| 5896 | DHD_ERROR(("%s: error reading nvram file: %d\n", |
| 5897 | __func__, len)); |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 5898 | ret = -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5899 | } |
| 5900 | |
| 5901 | err: |
Ilia Mirkin | 46d994b | 2011-03-13 00:28:56 -0500 | [diff] [blame] | 5902 | kfree(memblock); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5903 | |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 5904 | release_firmware(bus->firmware); |
| 5905 | bus->fw_ptr = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5906 | |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 5907 | return ret; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5908 | } |
| 5909 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5910 | static int _brcmf_sdbrcm_download_firmware(struct dhd_bus *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5911 | { |
| 5912 | int bcmerror = -1; |
| 5913 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5914 | /* Keep arm in reset */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5915 | if (brcmf_sdbrcm_download_state(bus, true)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5916 | DHD_ERROR(("%s: error placing ARM core in reset\n", __func__)); |
| 5917 | goto err; |
| 5918 | } |
| 5919 | |
| 5920 | /* External image takes precedence if specified */ |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 5921 | if (brcmf_sdbrcm_download_code_file(bus)) { |
| 5922 | DHD_ERROR(("%s: dongle image file download failed\n", |
| 5923 | __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5924 | goto err; |
| 5925 | } |
| 5926 | |
| 5927 | /* EXAMPLE: nvram_array */ |
| 5928 | /* If a valid nvram_arry is specified as above, it can be passed |
| 5929 | down to dongle */ |
| 5930 | /* dhd_bus_set_nvram_params(bus, (char *)&nvram_array); */ |
| 5931 | |
| 5932 | /* External nvram takes precedence if specified */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5933 | if (brcmf_sdbrcm_download_nvram(bus)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5934 | DHD_ERROR(("%s: dongle nvram file download failed\n", |
| 5935 | __func__)); |
| 5936 | } |
| 5937 | |
| 5938 | /* Take arm out of reset */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5939 | if (brcmf_sdbrcm_download_state(bus, false)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5940 | DHD_ERROR(("%s: error getting out of ARM core reset\n", |
| 5941 | __func__)); |
| 5942 | goto err; |
| 5943 | } |
| 5944 | |
| 5945 | bcmerror = 0; |
| 5946 | |
| 5947 | err: |
| 5948 | return bcmerror; |
| 5949 | } |
| 5950 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5951 | |
| 5952 | static int |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5953 | 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] | 5954 | u8 *buf, uint nbytes, struct sk_buff *pkt, |
Roland Vossen | 62dd656 | 2011-07-05 22:05:57 +0200 | [diff] [blame] | 5955 | brcmf_sdio_cmplt_fn_t complete, void *handle) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5956 | { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5957 | return brcmf_sdcard_send_buf |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 5958 | (bus->card, addr, fn, flags, buf, nbytes, pkt, complete, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5959 | handle); |
| 5960 | } |
| 5961 | |
| 5962 | uint dhd_bus_chip(struct dhd_bus *bus) |
| 5963 | { |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 5964 | ASSERT(bus->ci != NULL); |
| 5965 | return bus->ci->chip; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5966 | } |
| 5967 | |
| 5968 | void *dhd_bus_pub(struct dhd_bus *bus) |
| 5969 | { |
| 5970 | return bus->dhd; |
| 5971 | } |
| 5972 | |
| 5973 | void *dhd_bus_txq(struct dhd_bus *bus) |
| 5974 | { |
| 5975 | return &bus->txq; |
| 5976 | } |
| 5977 | |
| 5978 | uint dhd_bus_hdrlen(struct dhd_bus *bus) |
| 5979 | { |
| 5980 | return SDPCM_HDRLEN; |
| 5981 | } |
| 5982 | |
Arend van Spriel | fb1d0aa | 2011-06-29 16:47:55 -0700 | [diff] [blame] | 5983 | int brcmf_bus_devreset(struct brcmf_pub *dhdp, u8 flag) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5984 | { |
| 5985 | int bcmerror = 0; |
| 5986 | dhd_bus_t *bus; |
| 5987 | |
| 5988 | bus = dhdp->bus; |
| 5989 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5990 | if (flag == true) { |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 5991 | brcmf_sdbrcm_wd_timer(bus, 0); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5992 | if (!bus->dhd->dongle_reset) { |
| 5993 | /* Expect app to have torn down any |
| 5994 | connection before calling */ |
| 5995 | /* Stop the bus, disable F2 */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5996 | brcmf_sdbrcm_bus_stop(bus, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5997 | |
| 5998 | /* Clean tx/rx buffer pointers, |
| 5999 | detach from the dongle */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6000 | brcmf_sdbrcm_release_dongle(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6001 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 6002 | bus->dhd->dongle_reset = true; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 6003 | bus->dhd->up = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6004 | |
| 6005 | DHD_TRACE(("%s: WLAN OFF DONE\n", __func__)); |
| 6006 | /* App can now remove power from device */ |
| 6007 | } else |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 6008 | bcmerror = -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6009 | } else { |
| 6010 | /* App must have restored power to device before calling */ |
| 6011 | |
| 6012 | DHD_TRACE(("\n\n%s: == WLAN ON ==\n", __func__)); |
| 6013 | |
| 6014 | if (bus->dhd->dongle_reset) { |
| 6015 | /* Turn on WLAN */ |
| 6016 | /* Reset SD client */ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6017 | brcmf_sdcard_reset(bus->card); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6018 | |
| 6019 | /* Attempt to re-attach & download */ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6020 | if (brcmf_sdbrcm_probe_attach(bus, bus->card, |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 6021 | (u32 *) SI_ENUM_BASE, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6022 | bus->cl_devid)) { |
| 6023 | /* Attempt to download binary to the dongle */ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6024 | if (brcmf_sdbrcm_probe_init(bus, bus->card)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6025 | /* Re-init bus, enable F2 transfer */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6026 | brcmf_sdbrcm_bus_init( |
Arend van Spriel | fb1d0aa | 2011-06-29 16:47:55 -0700 | [diff] [blame] | 6027 | (struct brcmf_pub *) bus->dhd, |
| 6028 | false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6029 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 6030 | bus->dhd->dongle_reset = false; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 6031 | bus->dhd->up = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6032 | |
| 6033 | DHD_TRACE(("%s: WLAN ON DONE\n", |
| 6034 | __func__)); |
| 6035 | } else |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 6036 | bcmerror = -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6037 | } else |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 6038 | bcmerror = -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6039 | } else { |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 6040 | bcmerror = -EISCONN; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 6041 | DHD_ERROR(("%s: Set DEVRESET=false invoked when device " |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6042 | "is on\n", __func__)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 6043 | bcmerror = -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6044 | } |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 6045 | brcmf_sdbrcm_wd_timer(bus, brcmf_watchdog_ms); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6046 | } |
| 6047 | return bcmerror; |
| 6048 | } |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6049 | |
| 6050 | static int |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6051 | brcmf_sdbrcm_chip_recognition(struct brcmf_sdio_card *card, |
| 6052 | struct chip_info *ci, void *regs) |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6053 | { |
| 6054 | u32 regdata; |
| 6055 | |
| 6056 | /* |
| 6057 | * Get CC core rev |
| 6058 | * Chipid is assume to be at offset 0 from regs arg |
| 6059 | * For different chiptypes or old sdio hosts w/o chipcommon, |
| 6060 | * other ways of recognition should be added here. |
| 6061 | */ |
| 6062 | ci->cccorebase = (u32)regs; |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6063 | regdata = brcmf_sdcard_reg_read(card, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6064 | CORE_CC_REG(ci->cccorebase, chipid), 4); |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6065 | ci->chip = regdata & CID_ID_MASK; |
| 6066 | ci->chiprev = (regdata & CID_REV_MASK) >> CID_REV_SHIFT; |
| 6067 | |
| 6068 | DHD_INFO(("%s: chipid=0x%x chiprev=%d\n", |
| 6069 | __func__, ci->chip, ci->chiprev)); |
| 6070 | |
| 6071 | /* Address of cores for new chips should be added here */ |
| 6072 | switch (ci->chip) { |
| 6073 | case BCM4329_CHIP_ID: |
| 6074 | ci->buscorebase = BCM4329_CORE_BUS_BASE; |
| 6075 | ci->ramcorebase = BCM4329_CORE_SOCRAM_BASE; |
| 6076 | ci->armcorebase = BCM4329_CORE_ARM_BASE; |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 6077 | ci->ramsize = BCM4329_RAMSIZE; |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6078 | break; |
| 6079 | default: |
| 6080 | DHD_ERROR(("%s: chipid 0x%x is not supported\n", |
| 6081 | __func__, ci->chip)); |
| 6082 | return -ENODEV; |
| 6083 | } |
| 6084 | |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6085 | regdata = brcmf_sdcard_reg_read(card, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6086 | CORE_SB(ci->cccorebase, sbidhigh), 4); |
| 6087 | ci->ccrev = SBCOREREV(regdata); |
| 6088 | |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6089 | regdata = brcmf_sdcard_reg_read(card, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6090 | CORE_CC_REG(ci->cccorebase, pmucapabilities), 4); |
| 6091 | ci->pmurev = regdata & PCAP_REV_MASK; |
| 6092 | |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6093 | regdata = brcmf_sdcard_reg_read(card, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6094 | CORE_SB(ci->buscorebase, sbidhigh), 4); |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6095 | ci->buscorerev = SBCOREREV(regdata); |
| 6096 | ci->buscoretype = (regdata & SBIDH_CC_MASK) >> SBIDH_CC_SHIFT; |
| 6097 | |
| 6098 | DHD_INFO(("%s: ccrev=%d, pmurev=%d, buscore rev/type=%d/0x%x\n", |
| 6099 | __func__, ci->ccrev, ci->pmurev, |
| 6100 | ci->buscorerev, ci->buscoretype)); |
| 6101 | |
| 6102 | /* get chipcommon capabilites */ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6103 | ci->cccaps = brcmf_sdcard_reg_read(card, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6104 | CORE_CC_REG(ci->cccorebase, capabilities), 4); |
| 6105 | |
| 6106 | return 0; |
| 6107 | } |
| 6108 | |
| 6109 | static void |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6110 | brcmf_sdbrcm_chip_disablecore(struct brcmf_sdio_card *card, u32 corebase) |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6111 | { |
| 6112 | u32 regdata; |
| 6113 | |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6114 | regdata = brcmf_sdcard_reg_read(card, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6115 | CORE_SB(corebase, sbtmstatelow), 4); |
| 6116 | if (regdata & SBTML_RESET) |
| 6117 | return; |
| 6118 | |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6119 | regdata = brcmf_sdcard_reg_read(card, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6120 | CORE_SB(corebase, sbtmstatelow), 4); |
| 6121 | if ((regdata & (SICF_CLOCK_EN << SBTML_SICF_SHIFT)) != 0) { |
| 6122 | /* |
| 6123 | * set target reject and spin until busy is clear |
| 6124 | * (preserve core-specific bits) |
| 6125 | */ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6126 | regdata = brcmf_sdcard_reg_read(card, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6127 | CORE_SB(corebase, sbtmstatelow), 4); |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6128 | brcmf_sdcard_reg_write(card, CORE_SB(corebase, sbtmstatelow), 4, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6129 | regdata | SBTML_REJ); |
| 6130 | |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6131 | regdata = brcmf_sdcard_reg_read(card, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6132 | CORE_SB(corebase, sbtmstatelow), 4); |
| 6133 | udelay(1); |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6134 | SPINWAIT((brcmf_sdcard_reg_read(card, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6135 | CORE_SB(corebase, sbtmstatehigh), 4) & |
| 6136 | SBTMH_BUSY), 100000); |
| 6137 | |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6138 | regdata = brcmf_sdcard_reg_read(card, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6139 | CORE_SB(corebase, sbtmstatehigh), 4); |
| 6140 | if (regdata & SBTMH_BUSY) |
| 6141 | DHD_ERROR(("%s: ARM core still busy\n", __func__)); |
| 6142 | |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6143 | regdata = brcmf_sdcard_reg_read(card, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6144 | CORE_SB(corebase, sbidlow), 4); |
| 6145 | if (regdata & SBIDL_INIT) { |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6146 | regdata = brcmf_sdcard_reg_read(card, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6147 | CORE_SB(corebase, sbimstate), 4) | |
| 6148 | SBIM_RJ; |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6149 | brcmf_sdcard_reg_write(card, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6150 | CORE_SB(corebase, sbimstate), 4, |
| 6151 | regdata); |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6152 | regdata = brcmf_sdcard_reg_read(card, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6153 | CORE_SB(corebase, sbimstate), 4); |
| 6154 | udelay(1); |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6155 | SPINWAIT((brcmf_sdcard_reg_read(card, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6156 | CORE_SB(corebase, sbimstate), 4) & |
| 6157 | SBIM_BY), 100000); |
| 6158 | } |
| 6159 | |
| 6160 | /* set reset and reject while enabling the clocks */ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6161 | brcmf_sdcard_reg_write(card, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6162 | CORE_SB(corebase, sbtmstatelow), 4, |
| 6163 | (((SICF_FGC | SICF_CLOCK_EN) << SBTML_SICF_SHIFT) | |
| 6164 | SBTML_REJ | SBTML_RESET)); |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6165 | regdata = brcmf_sdcard_reg_read(card, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6166 | CORE_SB(corebase, sbtmstatelow), 4); |
| 6167 | udelay(10); |
| 6168 | |
| 6169 | /* clear the initiator reject bit */ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6170 | regdata = brcmf_sdcard_reg_read(card, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6171 | CORE_SB(corebase, sbidlow), 4); |
| 6172 | if (regdata & SBIDL_INIT) { |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6173 | regdata = brcmf_sdcard_reg_read(card, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6174 | CORE_SB(corebase, sbimstate), 4) & |
| 6175 | ~SBIM_RJ; |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6176 | brcmf_sdcard_reg_write(card, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6177 | CORE_SB(corebase, sbimstate), 4, |
| 6178 | regdata); |
| 6179 | } |
| 6180 | } |
| 6181 | |
| 6182 | /* leave reset and reject asserted */ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6183 | brcmf_sdcard_reg_write(card, CORE_SB(corebase, sbtmstatelow), 4, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6184 | (SBTML_REJ | SBTML_RESET)); |
| 6185 | udelay(1); |
| 6186 | } |
| 6187 | |
| 6188 | static int |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6189 | brcmf_sdbrcm_chip_attach(struct dhd_bus *bus, void *regs) |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6190 | { |
| 6191 | struct chip_info *ci; |
| 6192 | int err; |
| 6193 | u8 clkval, clkset; |
| 6194 | |
| 6195 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 6196 | |
| 6197 | /* alloc chip_info_t */ |
| 6198 | ci = kmalloc(sizeof(struct chip_info), GFP_ATOMIC); |
| 6199 | if (NULL == ci) { |
| 6200 | DHD_ERROR(("%s: malloc failed!\n", __func__)); |
| 6201 | return -ENOMEM; |
| 6202 | } |
| 6203 | |
| 6204 | memset((unsigned char *)ci, 0, sizeof(struct chip_info)); |
| 6205 | |
| 6206 | /* bus/core/clk setup for register access */ |
| 6207 | /* Try forcing SDIO core to do ALPAvail request only */ |
| 6208 | clkset = SBSDIO_FORCE_HW_CLKREQ_OFF | SBSDIO_ALP_AVAIL_REQ; |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6209 | brcmf_sdcard_cfg_write(bus->card, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6210 | clkset, &err); |
| 6211 | if (err) { |
| 6212 | DHD_ERROR(("%s: error writing for HT off\n", __func__)); |
| 6213 | goto fail; |
| 6214 | } |
| 6215 | |
| 6216 | /* If register supported, wait for ALPAvail and then force ALP */ |
| 6217 | /* This may take up to 15 milliseconds */ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6218 | clkval = brcmf_sdcard_cfg_read(bus->card, SDIO_FUNC_1, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6219 | SBSDIO_FUNC1_CHIPCLKCSR, NULL); |
| 6220 | if ((clkval & ~SBSDIO_AVBITS) == clkset) { |
| 6221 | SPINWAIT(((clkval = |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6222 | brcmf_sdcard_cfg_read(bus->card, SDIO_FUNC_1, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6223 | SBSDIO_FUNC1_CHIPCLKCSR, |
| 6224 | NULL)), |
| 6225 | !SBSDIO_ALPAV(clkval)), |
| 6226 | PMU_MAX_TRANSITION_DLY); |
| 6227 | if (!SBSDIO_ALPAV(clkval)) { |
| 6228 | DHD_ERROR(("%s: timeout on ALPAV wait, clkval 0x%02x\n", |
| 6229 | __func__, clkval)); |
| 6230 | err = -EBUSY; |
| 6231 | goto fail; |
| 6232 | } |
| 6233 | clkset = SBSDIO_FORCE_HW_CLKREQ_OFF | |
| 6234 | SBSDIO_FORCE_ALP; |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6235 | brcmf_sdcard_cfg_write(bus->card, SDIO_FUNC_1, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6236 | SBSDIO_FUNC1_CHIPCLKCSR, |
| 6237 | clkset, &err); |
| 6238 | udelay(65); |
| 6239 | } else { |
| 6240 | DHD_ERROR(("%s: ChipClkCSR access: wrote 0x%02x read 0x%02x\n", |
| 6241 | __func__, clkset, clkval)); |
| 6242 | err = -EACCES; |
| 6243 | goto fail; |
| 6244 | } |
| 6245 | |
| 6246 | /* Also, disable the extra SDIO pull-ups */ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6247 | brcmf_sdcard_cfg_write(bus->card, SDIO_FUNC_1, SBSDIO_FUNC1_SDIOPULLUP, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6248 | 0, NULL); |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6249 | |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6250 | err = brcmf_sdbrcm_chip_recognition(bus->card, ci, regs); |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6251 | if (err) |
| 6252 | goto fail; |
| 6253 | |
| 6254 | /* |
| 6255 | * Make sure any on-chip ARM is off (in case strapping is wrong), |
| 6256 | * or downloaded code was already running. |
| 6257 | */ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6258 | brcmf_sdbrcm_chip_disablecore(bus->card, ci->armcorebase); |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6259 | |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6260 | brcmf_sdcard_reg_write(bus->card, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6261 | CORE_CC_REG(ci->cccorebase, gpiopullup), 4, 0); |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6262 | brcmf_sdcard_reg_write(bus->card, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6263 | CORE_CC_REG(ci->cccorebase, gpiopulldown), 4, 0); |
| 6264 | |
| 6265 | /* Disable F2 to clear any intermediate frame state on the dongle */ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6266 | brcmf_sdcard_cfg_write(bus->card, SDIO_FUNC_0, SDIO_CCCR_IOEx, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6267 | SDIO_FUNC_ENABLE_1, NULL); |
| 6268 | |
| 6269 | /* WAR: cmd52 backplane read so core HW will drop ALPReq */ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6270 | clkval = brcmf_sdcard_cfg_read(bus->card, SDIO_FUNC_1, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6271 | 0, NULL); |
| 6272 | |
| 6273 | /* Done with backplane-dependent accesses, can drop clock... */ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6274 | brcmf_sdcard_cfg_write(bus->card, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6275 | 0, NULL); |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6276 | |
| 6277 | bus->ci = ci; |
| 6278 | return 0; |
| 6279 | fail: |
| 6280 | bus->ci = NULL; |
| 6281 | kfree(ci); |
| 6282 | return err; |
| 6283 | } |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6284 | |
| 6285 | static void |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6286 | brcmf_sdbrcm_chip_resetcore(struct brcmf_sdio_card *card, u32 corebase) |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6287 | { |
| 6288 | u32 regdata; |
| 6289 | |
| 6290 | /* |
| 6291 | * Must do the disable sequence first to work for |
| 6292 | * arbitrary current core state. |
| 6293 | */ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6294 | brcmf_sdbrcm_chip_disablecore(card, corebase); |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6295 | |
| 6296 | /* |
| 6297 | * Now do the initialization sequence. |
| 6298 | * set reset while enabling the clock and |
| 6299 | * forcing them on throughout the core |
| 6300 | */ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6301 | brcmf_sdcard_reg_write(card, CORE_SB(corebase, sbtmstatelow), 4, |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6302 | ((SICF_FGC | SICF_CLOCK_EN) << SBTML_SICF_SHIFT) | |
| 6303 | SBTML_RESET); |
| 6304 | udelay(1); |
| 6305 | |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6306 | regdata = brcmf_sdcard_reg_read(card, CORE_SB(corebase, sbtmstatehigh), |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6307 | 4); |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6308 | if (regdata & SBTMH_SERR) |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6309 | brcmf_sdcard_reg_write(card, CORE_SB(corebase, sbtmstatehigh), |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6310 | 4, 0); |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6311 | |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6312 | regdata = brcmf_sdcard_reg_read(card, CORE_SB(corebase, sbimstate), 4); |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6313 | if (regdata & (SBIM_IBE | SBIM_TO)) |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6314 | brcmf_sdcard_reg_write(card, CORE_SB(corebase, sbimstate), 4, |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6315 | regdata & ~(SBIM_IBE | SBIM_TO)); |
| 6316 | |
| 6317 | /* clear reset and allow it to propagate throughout the core */ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6318 | brcmf_sdcard_reg_write(card, CORE_SB(corebase, sbtmstatelow), 4, |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6319 | (SICF_FGC << SBTML_SICF_SHIFT) | |
| 6320 | (SICF_CLOCK_EN << SBTML_SICF_SHIFT)); |
| 6321 | udelay(1); |
| 6322 | |
| 6323 | /* leave clock enabled */ |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6324 | brcmf_sdcard_reg_write(card, CORE_SB(corebase, sbtmstatelow), 4, |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6325 | (SICF_CLOCK_EN << SBTML_SICF_SHIFT)); |
| 6326 | udelay(1); |
| 6327 | } |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 6328 | |
| 6329 | /* SDIO Pad drive strength to select value mappings */ |
| 6330 | struct sdiod_drive_str { |
| 6331 | u8 strength; /* Pad Drive Strength in mA */ |
| 6332 | u8 sel; /* Chip-specific select value */ |
| 6333 | }; |
| 6334 | |
| 6335 | /* SDIO Drive Strength to sel value table for PMU Rev 1 */ |
| 6336 | static const struct sdiod_drive_str sdiod_drive_strength_tab1[] = { |
| 6337 | { |
| 6338 | 4, 0x2}, { |
| 6339 | 2, 0x3}, { |
| 6340 | 1, 0x0}, { |
| 6341 | 0, 0x0} |
| 6342 | }; |
| 6343 | |
| 6344 | /* SDIO Drive Strength to sel value table for PMU Rev 2, 3 */ |
| 6345 | static const struct sdiod_drive_str sdiod_drive_strength_tab2[] = { |
| 6346 | { |
| 6347 | 12, 0x7}, { |
| 6348 | 10, 0x6}, { |
| 6349 | 8, 0x5}, { |
| 6350 | 6, 0x4}, { |
| 6351 | 4, 0x2}, { |
| 6352 | 2, 0x1}, { |
| 6353 | 0, 0x0} |
| 6354 | }; |
| 6355 | |
| 6356 | /* SDIO Drive Strength to sel value table for PMU Rev 8 (1.8V) */ |
| 6357 | static const struct sdiod_drive_str sdiod_drive_strength_tab3[] = { |
| 6358 | { |
| 6359 | 32, 0x7}, { |
| 6360 | 26, 0x6}, { |
| 6361 | 22, 0x5}, { |
| 6362 | 16, 0x4}, { |
| 6363 | 12, 0x3}, { |
| 6364 | 8, 0x2}, { |
| 6365 | 4, 0x1}, { |
| 6366 | 0, 0x0} |
| 6367 | }; |
| 6368 | |
| 6369 | #define SDIOD_DRVSTR_KEY(chip, pmu) (((chip) << 16) | (pmu)) |
| 6370 | |
| 6371 | static void |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6372 | brcmf_sdbrcm_sdiod_drive_strength_init(struct dhd_bus *bus, u32 drivestrength) { |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 6373 | struct sdiod_drive_str *str_tab = NULL; |
| 6374 | u32 str_mask = 0; |
| 6375 | u32 str_shift = 0; |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 6376 | char chn[8]; |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 6377 | |
| 6378 | if (!(bus->ci->cccaps & CC_CAP_PMU)) |
| 6379 | return; |
| 6380 | |
| 6381 | switch (SDIOD_DRVSTR_KEY(bus->ci->chip, bus->ci->pmurev)) { |
| 6382 | case SDIOD_DRVSTR_KEY(BCM4325_CHIP_ID, 1): |
| 6383 | str_tab = (struct sdiod_drive_str *)&sdiod_drive_strength_tab1; |
| 6384 | str_mask = 0x30000000; |
| 6385 | str_shift = 28; |
| 6386 | break; |
| 6387 | case SDIOD_DRVSTR_KEY(BCM4325_CHIP_ID, 2): |
| 6388 | case SDIOD_DRVSTR_KEY(BCM4325_CHIP_ID, 3): |
| 6389 | str_tab = (struct sdiod_drive_str *)&sdiod_drive_strength_tab2; |
| 6390 | str_mask = 0x00003800; |
| 6391 | str_shift = 11; |
| 6392 | break; |
| 6393 | case SDIOD_DRVSTR_KEY(BCM4336_CHIP_ID, 8): |
| 6394 | str_tab = (struct sdiod_drive_str *)&sdiod_drive_strength_tab3; |
| 6395 | str_mask = 0x00003800; |
| 6396 | str_shift = 11; |
| 6397 | break; |
| 6398 | default: |
| 6399 | DHD_ERROR(("No SDIO Drive strength init" |
| 6400 | "done for chip %s rev %d pmurev %d\n", |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 6401 | brcmu_chipname(bus->ci->chip, chn, 8), |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 6402 | bus->ci->chiprev, bus->ci->pmurev)); |
| 6403 | break; |
| 6404 | } |
| 6405 | |
| 6406 | if (str_tab != NULL) { |
| 6407 | u32 drivestrength_sel = 0; |
| 6408 | u32 cc_data_temp; |
| 6409 | int i; |
| 6410 | |
| 6411 | for (i = 0; str_tab[i].strength != 0; i++) { |
| 6412 | if (drivestrength >= str_tab[i].strength) { |
| 6413 | drivestrength_sel = str_tab[i].sel; |
| 6414 | break; |
| 6415 | } |
| 6416 | } |
| 6417 | |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6418 | brcmf_sdcard_reg_write(bus->card, |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 6419 | CORE_CC_REG(bus->ci->cccorebase, chipcontrol_addr), |
| 6420 | 4, 1); |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6421 | cc_data_temp = brcmf_sdcard_reg_read(bus->card, |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 6422 | CORE_CC_REG(bus->ci->cccorebase, chipcontrol_addr), 4); |
| 6423 | cc_data_temp &= ~str_mask; |
| 6424 | drivestrength_sel <<= str_shift; |
| 6425 | cc_data_temp |= drivestrength_sel; |
Roland Vossen | 127aa5c | 2011-07-05 22:05:58 +0200 | [diff] [blame] | 6426 | brcmf_sdcard_reg_write(bus->card, |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 6427 | CORE_CC_REG(bus->ci->cccorebase, chipcontrol_addr), |
| 6428 | 4, cc_data_temp); |
| 6429 | |
| 6430 | DHD_INFO(("SDIO: %dmA drive strength selected, set to 0x%08x\n", |
| 6431 | drivestrength, cc_data_temp)); |
| 6432 | } |
| 6433 | } |
Franky Lin | cee3cf4 | 2011-04-25 19:34:06 -0700 | [diff] [blame] | 6434 | |
| 6435 | static void |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6436 | brcmf_sdbrcm_chip_detach(struct dhd_bus *bus) |
Franky Lin | cee3cf4 | 2011-04-25 19:34:06 -0700 | [diff] [blame] | 6437 | { |
| 6438 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 6439 | |
| 6440 | kfree(bus->ci); |
| 6441 | bus->ci = NULL; |
| 6442 | } |
Franky Lin | b7adfa7 | 2011-06-29 16:47:42 -0700 | [diff] [blame] | 6443 | |
| 6444 | static void |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 6445 | brcmf_sdbrcm_wait_for_event(dhd_bus_t *bus, bool *lockvar) |
Franky Lin | b7adfa7 | 2011-06-29 16:47:42 -0700 | [diff] [blame] | 6446 | { |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 6447 | brcmf_sdbrcm_sdunlock(bus); |
| 6448 | wait_event_interruptible_timeout(bus->ctrl_wait, |
Franky Lin | b7adfa7 | 2011-06-29 16:47:42 -0700 | [diff] [blame] | 6449 | (*lockvar == false), HZ * 2); |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 6450 | brcmf_sdbrcm_sdlock(bus); |
Franky Lin | b7adfa7 | 2011-06-29 16:47:42 -0700 | [diff] [blame] | 6451 | return; |
| 6452 | } |
| 6453 | |
| 6454 | static void |
| 6455 | brcmf_sdbrcm_wait_event_wakeup(dhd_bus_t *bus) |
| 6456 | { |
| 6457 | if (waitqueue_active(&bus->ctrl_wait)) |
| 6458 | wake_up_interruptible(&bus->ctrl_wait); |
| 6459 | return; |
| 6460 | } |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 6461 | |
| 6462 | static int |
| 6463 | brcmf_sdbrcm_watchdog_thread(void *data) |
| 6464 | { |
| 6465 | dhd_bus_t *bus = (dhd_bus_t *)data; |
| 6466 | |
| 6467 | /* This thread doesn't need any user-level access, |
| 6468 | * so get rid of all our resources |
| 6469 | */ |
| 6470 | if (brcmf_watchdog_prio > 0) { |
| 6471 | struct sched_param param; |
| 6472 | param.sched_priority = (brcmf_watchdog_prio < MAX_RT_PRIO) ? |
| 6473 | brcmf_watchdog_prio : (MAX_RT_PRIO - 1); |
| 6474 | sched_setscheduler(current, SCHED_FIFO, ¶m); |
| 6475 | } |
| 6476 | |
| 6477 | allow_signal(SIGTERM); |
| 6478 | /* Run until signal received */ |
| 6479 | while (1) { |
| 6480 | if (kthread_should_stop()) |
| 6481 | break; |
| 6482 | if (!wait_for_completion_interruptible(&bus->watchdog_wait)) { |
| 6483 | if (bus->dhd->dongle_reset == false) |
| 6484 | brcmf_sdbrcm_bus_watchdog(bus->dhd); |
| 6485 | /* Count the tick for reference */ |
| 6486 | bus->dhd->tickcnt++; |
| 6487 | } else |
| 6488 | break; |
| 6489 | } |
| 6490 | return 0; |
| 6491 | } |
| 6492 | |
| 6493 | static void |
| 6494 | brcmf_sdbrcm_watchdog(unsigned long data) |
| 6495 | { |
| 6496 | dhd_bus_t *bus = (dhd_bus_t *)data; |
| 6497 | |
| 6498 | if (brcmf_watchdog_prio >= 0) { |
| 6499 | if (bus->watchdog_tsk) |
| 6500 | complete(&bus->watchdog_wait); |
| 6501 | else |
| 6502 | return; |
| 6503 | } else { |
| 6504 | brcmf_sdbrcm_bus_watchdog(bus->dhd); |
| 6505 | |
| 6506 | /* Count the tick for reference */ |
| 6507 | bus->dhd->tickcnt++; |
| 6508 | } |
| 6509 | |
| 6510 | /* Reschedule the watchdog */ |
| 6511 | if (bus->wd_timer_valid) |
| 6512 | mod_timer(&bus->timer, jiffies + brcmf_watchdog_ms * HZ / 1000); |
| 6513 | } |
| 6514 | |
| 6515 | void |
| 6516 | brcmf_sdbrcm_wd_timer(struct dhd_bus *bus, uint wdtick) |
| 6517 | { |
| 6518 | static uint save_ms; |
| 6519 | |
| 6520 | /* don't start the wd until fw is loaded */ |
| 6521 | if (bus->dhd->busstate == DHD_BUS_DOWN) |
| 6522 | return; |
| 6523 | |
| 6524 | /* Totally stop the timer */ |
| 6525 | if (!wdtick && bus->wd_timer_valid == true) { |
| 6526 | del_timer_sync(&bus->timer); |
| 6527 | bus->wd_timer_valid = false; |
| 6528 | save_ms = wdtick; |
| 6529 | return; |
| 6530 | } |
| 6531 | |
| 6532 | if (wdtick) { |
| 6533 | brcmf_watchdog_ms = (uint) wdtick; |
| 6534 | |
| 6535 | if (save_ms != brcmf_watchdog_ms) { |
| 6536 | if (bus->wd_timer_valid == true) |
| 6537 | /* Stop timer and restart at new value */ |
| 6538 | del_timer_sync(&bus->timer); |
| 6539 | |
| 6540 | /* Create timer again when watchdog period is |
| 6541 | dynamically changed or in the first instance |
| 6542 | */ |
| 6543 | bus->timer.expires = |
| 6544 | jiffies + brcmf_watchdog_ms * HZ / 1000; |
| 6545 | add_timer(&bus->timer); |
| 6546 | |
| 6547 | } else { |
| 6548 | /* Re arm the timer, at last watchdog period */ |
| 6549 | mod_timer(&bus->timer, |
| 6550 | jiffies + brcmf_watchdog_ms * HZ / 1000); |
| 6551 | } |
| 6552 | |
| 6553 | bus->wd_timer_valid = true; |
| 6554 | save_ms = wdtick; |
| 6555 | } |
| 6556 | } |
Franky Lin | 0827888 | 2011-06-29 16:47:45 -0700 | [diff] [blame] | 6557 | |
| 6558 | static int brcmf_sdbrcm_dpc_thread(void *data) |
| 6559 | { |
| 6560 | dhd_bus_t *bus = (dhd_bus_t *) data; |
| 6561 | |
| 6562 | /* This thread doesn't need any user-level access, |
| 6563 | * so get rid of all our resources |
| 6564 | */ |
| 6565 | if (brcmf_dpc_prio > 0) { |
| 6566 | struct sched_param param; |
| 6567 | param.sched_priority = (brcmf_dpc_prio < MAX_RT_PRIO) ? |
| 6568 | brcmf_dpc_prio : (MAX_RT_PRIO - 1); |
| 6569 | sched_setscheduler(current, SCHED_FIFO, ¶m); |
| 6570 | } |
| 6571 | |
| 6572 | allow_signal(SIGTERM); |
| 6573 | /* Run until signal received */ |
| 6574 | while (1) { |
| 6575 | if (kthread_should_stop()) |
| 6576 | break; |
| 6577 | if (!wait_for_completion_interruptible(&bus->dpc_wait)) { |
| 6578 | /* Call bus dpc unless it indicated down |
| 6579 | (then clean stop) */ |
| 6580 | if (bus->dhd->busstate != DHD_BUS_DOWN) { |
| 6581 | if (brcmf_sdbrcm_dpc(bus)) |
| 6582 | complete(&bus->dpc_wait); |
| 6583 | } else { |
| 6584 | brcmf_sdbrcm_bus_stop(bus, true); |
| 6585 | } |
| 6586 | } else |
| 6587 | break; |
| 6588 | } |
| 6589 | return 0; |
| 6590 | } |
| 6591 | |
| 6592 | static void brcmf_sdbrcm_dpc_tasklet(unsigned long data) |
| 6593 | { |
| 6594 | dhd_bus_t *bus = (dhd_bus_t *) data; |
| 6595 | |
| 6596 | /* Call bus dpc unless it indicated down (then clean stop) */ |
| 6597 | if (bus->dhd->busstate != DHD_BUS_DOWN) { |
| 6598 | if (brcmf_sdbrcm_dpc(bus)) |
| 6599 | tasklet_schedule(&bus->tasklet); |
| 6600 | } else |
| 6601 | brcmf_sdbrcm_bus_stop(bus, true); |
| 6602 | } |
| 6603 | |
| 6604 | static void brcmf_sdbrcm_sched_dpc(dhd_bus_t *bus) |
| 6605 | { |
| 6606 | if (bus->dpc_tsk) { |
| 6607 | complete(&bus->dpc_wait); |
| 6608 | return; |
| 6609 | } |
| 6610 | |
| 6611 | tasklet_schedule(&bus->tasklet); |
| 6612 | } |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 6613 | |
| 6614 | static void brcmf_sdbrcm_sdlock(dhd_bus_t *bus) |
| 6615 | { |
| 6616 | if (bus->threads_only) |
| 6617 | down(&bus->sdsem); |
| 6618 | else |
| 6619 | spin_lock_bh(&bus->sdlock); |
| 6620 | } |
| 6621 | |
| 6622 | static void brcmf_sdbrcm_sdunlock(dhd_bus_t *bus) |
| 6623 | { |
| 6624 | if (bus->threads_only) |
| 6625 | up(&bus->sdsem); |
| 6626 | else |
| 6627 | spin_unlock_bh(&bus->sdlock); |
| 6628 | } |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 6629 | |
| 6630 | static int brcmf_sdbrcm_get_image(char *buf, int len, struct dhd_bus *bus) |
| 6631 | { |
| 6632 | if (bus->firmware->size < bus->fw_ptr + len) |
| 6633 | len = bus->firmware->size - bus->fw_ptr; |
| 6634 | |
| 6635 | memcpy(buf, &bus->firmware->data[bus->fw_ptr], len); |
| 6636 | bus->fw_ptr += len; |
| 6637 | return len; |
| 6638 | } |
| 6639 | |
| 6640 | MODULE_FIRMWARE(BCM4329_FW_NAME); |
| 6641 | MODULE_FIRMWARE(BCM4329_NV_NAME); |