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 | 7c6100e | 2011-06-01 13:45:36 +0200 | [diff] [blame] | 25 | #include <asm/unaligned.h> |
Roland Vossen | cc3cea5 | 2011-06-01 13:45:59 +0200 | [diff] [blame] | 26 | #include <defs.h> |
Roland Vossen | f97e956 | 2011-06-01 13:45:52 +0200 | [diff] [blame] | 27 | #include <brcmu_wifi.h> |
| 28 | #include <brcmu_utils.h> |
Roland Vossen | cc3cea5 | 2011-06-01 13:45:59 +0200 | [diff] [blame] | 29 | #include <brcm_hw_ids.h> |
Roland Vossen | cc3cea5 | 2011-06-01 13:45:59 +0200 | [diff] [blame] | 30 | #include <soc.h> |
Roland Vossen | c4daa84 | 2011-06-09 16:44:50 +0200 | [diff] [blame] | 31 | #include "sdio_host.h" |
Roland Vossen | 4489518 | 2011-06-01 13:45:55 +0200 | [diff] [blame] | 32 | |
| 33 | /* register access macros */ |
Roland Vossen | 4489518 | 2011-06-01 13:45:55 +0200 | [diff] [blame] | 34 | #ifndef __BIG_ENDIAN |
| 35 | #ifndef __mips__ |
Roland Vossen | b61a4be | 2011-06-01 13:45:56 +0200 | [diff] [blame] | 36 | #define R_REG(r) \ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 37 | brcmf_sdcard_reg_read(NULL, (unsigned long)(r), sizeof(*(r))) |
Roland Vossen | 4489518 | 2011-06-01 13:45:55 +0200 | [diff] [blame] | 38 | #else /* __mips__ */ |
Roland Vossen | b61a4be | 2011-06-01 13:45:56 +0200 | [diff] [blame] | 39 | #define R_REG(r) \ |
| 40 | ({ \ |
| 41 | __typeof(*(r)) __osl_v; \ |
| 42 | __asm__ __volatile__("sync"); \ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 43 | __osl_v = brcmf_sdcard_reg_read(NULL, (unsigned long)(r),\ |
Roland Vossen | 2503634 | 2011-06-01 13:45:57 +0200 | [diff] [blame] | 44 | sizeof(*(r))); \ |
Roland Vossen | b61a4be | 2011-06-01 13:45:56 +0200 | [diff] [blame] | 45 | __asm__ __volatile__("sync"); \ |
| 46 | __osl_v; \ |
| 47 | }) |
Roland Vossen | 4489518 | 2011-06-01 13:45:55 +0200 | [diff] [blame] | 48 | #endif /* __mips__ */ |
| 49 | |
| 50 | #define W_REG(r, v) do { \ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 51 | brcmf_sdcard_reg_write(NULL, (unsigned long)(r), sizeof(*(r)), \ |
| 52 | (v)); \ |
Roland Vossen | 4489518 | 2011-06-01 13:45:55 +0200 | [diff] [blame] | 53 | } while (0) |
| 54 | #else /* __BIG_ENDIAN */ |
Roland Vossen | b61a4be | 2011-06-01 13:45:56 +0200 | [diff] [blame] | 55 | #define R_REG(r) \ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 56 | brcmf_sdcard_reg_read(NULL, (unsigned long)(r), sizeof(*(r))) |
Roland Vossen | 4489518 | 2011-06-01 13:45:55 +0200 | [diff] [blame] | 57 | #define W_REG(r, v) do { \ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 58 | brcmf_sdcard_reg_write(NULL, (unsigned long)(r), sizeof(*(r)), \ |
| 59 | (v)); \ |
Roland Vossen | 4489518 | 2011-06-01 13:45:55 +0200 | [diff] [blame] | 60 | } while (0) |
| 61 | #endif /* __BIG_ENDIAN */ |
| 62 | |
Roland Vossen | 4489518 | 2011-06-01 13:45:55 +0200 | [diff] [blame] | 63 | #define AND_REG(r, v) W_REG((r), R_REG(r) & (v)) |
| 64 | #define OR_REG(r, v) W_REG((r), R_REG(r) | (v)) |
| 65 | |
| 66 | #define SET_REG(r, mask, val) \ |
| 67 | W_REG((r), ((R_REG(r) & ~(mask)) | (val))) |
| 68 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 69 | #ifdef BCMDBG |
Roland Vossen | f1c7a08 | 2011-06-01 13:45:09 +0200 | [diff] [blame] | 70 | |
| 71 | /* ARM trap handling */ |
| 72 | |
| 73 | /* Trap types defined by ARM (see arminc.h) */ |
| 74 | |
| 75 | /* Trap locations in lo memory */ |
| 76 | #define TRAP_STRIDE 4 |
| 77 | #define FIRST_TRAP TR_RST |
| 78 | #define LAST_TRAP (TR_FIQ * TRAP_STRIDE) |
| 79 | |
| 80 | #if defined(__ARM_ARCH_4T__) |
| 81 | #define MAX_TRAP_TYPE (TR_FIQ + 1) |
| 82 | #elif defined(__ARM_ARCH_7M__) |
| 83 | #define MAX_TRAP_TYPE (TR_ISR + ARMCM3_NUMINTS) |
| 84 | #endif /* __ARM_ARCH_7M__ */ |
| 85 | |
| 86 | /* The trap structure is defined here as offsets for assembly */ |
| 87 | #define TR_TYPE 0x00 |
| 88 | #define TR_EPC 0x04 |
| 89 | #define TR_CPSR 0x08 |
| 90 | #define TR_SPSR 0x0c |
| 91 | #define TR_REGS 0x10 |
| 92 | #define TR_REG(n) (TR_REGS + (n) * 4) |
| 93 | #define TR_SP TR_REG(13) |
| 94 | #define TR_LR TR_REG(14) |
| 95 | #define TR_PC TR_REG(15) |
| 96 | |
| 97 | #define TRAP_T_SIZE 80 |
| 98 | |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 99 | struct brcmf_trap { |
Roland Vossen | f1c7a08 | 2011-06-01 13:45:09 +0200 | [diff] [blame] | 100 | u32 type; |
| 101 | u32 epc; |
| 102 | u32 cpsr; |
| 103 | u32 spsr; |
| 104 | u32 r0; |
| 105 | u32 r1; |
| 106 | u32 r2; |
| 107 | u32 r3; |
| 108 | u32 r4; |
| 109 | u32 r5; |
| 110 | u32 r6; |
| 111 | u32 r7; |
| 112 | u32 r8; |
| 113 | u32 r9; |
| 114 | u32 r10; |
| 115 | u32 r11; |
| 116 | u32 r12; |
| 117 | u32 r13; |
| 118 | u32 r14; |
| 119 | u32 pc; |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 120 | }; |
Roland Vossen | f1c7a08 | 2011-06-01 13:45:09 +0200 | [diff] [blame] | 121 | |
Roland Vossen | f1c7a08 | 2011-06-01 13:45:09 +0200 | [diff] [blame] | 122 | #define CBUF_LEN (128) |
| 123 | |
| 124 | #define LOG_BUF_LEN 1024 |
| 125 | |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 126 | struct rte_log { |
Roland Vossen | f1c7a08 | 2011-06-01 13:45:09 +0200 | [diff] [blame] | 127 | u32 buf; /* Can't be pointer on (64-bit) hosts */ |
| 128 | uint buf_size; |
| 129 | uint idx; |
| 130 | char *_buf_compat; /* Redundant pointer for backward compat. */ |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 131 | }; |
Roland Vossen | f1c7a08 | 2011-06-01 13:45:09 +0200 | [diff] [blame] | 132 | |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 133 | struct rte_console { |
Roland Vossen | f1c7a08 | 2011-06-01 13:45:09 +0200 | [diff] [blame] | 134 | /* Virtual UART |
| 135 | * When there is no UART (e.g. Quickturn), |
| 136 | * the host should write a complete |
| 137 | * input line directly into cbuf and then write |
| 138 | * the length into vcons_in. |
| 139 | * This may also be used when there is a real UART |
| 140 | * (at risk of conflicting with |
| 141 | * the real UART). vcons_out is currently unused. |
| 142 | */ |
| 143 | volatile uint vcons_in; |
| 144 | volatile uint vcons_out; |
| 145 | |
| 146 | /* Output (logging) buffer |
| 147 | * Console output is written to a ring buffer log_buf at index log_idx. |
| 148 | * The host may read the output when it sees log_idx advance. |
| 149 | * Output will be lost if the output wraps around faster than the host |
| 150 | * polls. |
| 151 | */ |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 152 | struct rte_log log; |
Roland Vossen | f1c7a08 | 2011-06-01 13:45:09 +0200 | [diff] [blame] | 153 | |
| 154 | /* Console input line buffer |
| 155 | * Characters are read one at a time into cbuf |
| 156 | * until <CR> is received, then |
| 157 | * the buffer is processed as a command line. |
| 158 | * Also used for virtual UART. |
| 159 | */ |
| 160 | uint cbuf_idx; |
| 161 | char cbuf[CBUF_LEN]; |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 162 | }; |
Roland Vossen | f1c7a08 | 2011-06-01 13:45:09 +0200 | [diff] [blame] | 163 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 164 | #endif /* BCMDBG */ |
Roland Vossen | 745c9e6 | 2011-06-01 13:45:30 +0200 | [diff] [blame] | 165 | #include <chipcommon.h> |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 166 | |
Roland Vossen | c4daa84 | 2011-06-09 16:44:50 +0200 | [diff] [blame] | 167 | #include "sbsdio.h" |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 168 | |
Roland Vossen | c4daa84 | 2011-06-09 16:44:50 +0200 | [diff] [blame] | 169 | #include "dngl_stats.h" |
| 170 | #include "dhd.h" |
| 171 | #include "dhd_bus.h" |
| 172 | #include "dhd_proto.h" |
| 173 | #include "dhd_dbg.h" |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 174 | #include <sdiovar.h> |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 175 | #include <bcmchip.h> |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 176 | |
| 177 | #ifndef DHDSDIO_MEM_DUMP_FNAME |
| 178 | #define DHDSDIO_MEM_DUMP_FNAME "mem_dump" |
| 179 | #endif |
| 180 | |
Grant Grundler | 26a71a4 | 2011-03-09 10:41:25 -0800 | [diff] [blame] | 181 | #define TXQLEN 2048 /* bulk tx queue length */ |
| 182 | #define TXHI (TXQLEN - 256) /* turn on flow control above TXHI */ |
| 183 | #define TXLOW (TXHI - 256) /* turn off flow control below TXLOW */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 184 | #define PRIOMASK 7 |
| 185 | |
| 186 | #define TXRETRIES 2 /* # of retries for tx frames */ |
| 187 | |
| 188 | #if defined(CONFIG_MACH_SANDGATE2G) |
| 189 | #define DHD_RXBOUND 250 /* Default for max rx frames in |
| 190 | one scheduling */ |
| 191 | #else |
| 192 | #define DHD_RXBOUND 50 /* Default for max rx frames in |
| 193 | one scheduling */ |
| 194 | #endif /* defined(CONFIG_MACH_SANDGATE2G) */ |
| 195 | |
| 196 | #define DHD_TXBOUND 20 /* Default for max tx frames in |
| 197 | one scheduling */ |
| 198 | |
| 199 | #define DHD_TXMINMAX 1 /* Max tx frames if rx still pending */ |
| 200 | |
| 201 | #define MEMBLOCK 2048 /* Block size used for downloading |
| 202 | of dongle image */ |
| 203 | #define MAX_DATA_BUF (32 * 1024) /* Must be large enough to hold |
| 204 | biggest possible glom */ |
| 205 | |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 206 | #ifndef BRCMF_FIRSTREAD |
| 207 | #define BRCMF_FIRSTREAD 32 |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 208 | #endif |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 209 | #if !ISPOWEROF2(BRCMF_FIRSTREAD) |
| 210 | #error BRCMF_FIRSTREAD is not a power of 2! |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 211 | #endif |
| 212 | |
| 213 | /* Total length of frame header for dongle protocol */ |
| 214 | #define SDPCM_HDRLEN (SDPCM_FRAMETAG_LEN + SDPCM_SWHEADER_LEN) |
| 215 | #ifdef SDTEST |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 216 | #define SDPCM_RESERVE (SDPCM_HDRLEN + SDPCM_TEST_HDRLEN + BRCMF_SDALIGN) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 217 | #else |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 218 | #define SDPCM_RESERVE (SDPCM_HDRLEN + BRCMF_SDALIGN) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 219 | #endif |
| 220 | |
Franky Lin | b49b14d | 2011-06-01 13:45:37 +0200 | [diff] [blame] | 221 | /* |
| 222 | * Software allocation of To SB Mailbox resources |
| 223 | */ |
| 224 | |
| 225 | /* tosbmailbox bits corresponding to intstatus bits */ |
| 226 | #define SMB_NAK (1 << 0) /* Frame NAK */ |
| 227 | #define SMB_INT_ACK (1 << 1) /* Host Interrupt ACK */ |
| 228 | #define SMB_USE_OOB (1 << 2) /* Use OOB Wakeup */ |
| 229 | #define SMB_DEV_INT (1 << 3) /* Miscellaneous Interrupt */ |
| 230 | |
| 231 | /* tosbmailboxdata */ |
| 232 | #define SMB_DATA_VERSION_SHIFT 16 /* host protocol version */ |
| 233 | |
| 234 | /* |
| 235 | * Software allocation of To Host Mailbox resources |
| 236 | */ |
| 237 | |
| 238 | /* intstatus bits */ |
| 239 | #define I_HMB_FC_STATE I_HMB_SW0 /* Flow Control State */ |
| 240 | #define I_HMB_FC_CHANGE I_HMB_SW1 /* Flow Control State Changed */ |
| 241 | #define I_HMB_FRAME_IND I_HMB_SW2 /* Frame Indication */ |
| 242 | #define I_HMB_HOST_INT I_HMB_SW3 /* Miscellaneous Interrupt */ |
| 243 | |
| 244 | /* tohostmailboxdata */ |
| 245 | #define HMB_DATA_NAKHANDLED 1 /* retransmit NAK'd frame */ |
| 246 | #define HMB_DATA_DEVREADY 2 /* talk to host after enable */ |
| 247 | #define HMB_DATA_FC 4 /* per prio flowcontrol update flag */ |
| 248 | #define HMB_DATA_FWREADY 8 /* fw ready for protocol activity */ |
| 249 | |
| 250 | #define HMB_DATA_FCDATA_MASK 0xff000000 |
| 251 | #define HMB_DATA_FCDATA_SHIFT 24 |
| 252 | |
| 253 | #define HMB_DATA_VERSION_MASK 0x00ff0000 |
| 254 | #define HMB_DATA_VERSION_SHIFT 16 |
| 255 | |
| 256 | /* |
| 257 | * Software-defined protocol header |
| 258 | */ |
| 259 | |
| 260 | /* Current protocol version */ |
| 261 | #define SDPCM_PROT_VERSION 4 |
| 262 | |
| 263 | /* SW frame header */ |
| 264 | #define SDPCM_PACKET_SEQUENCE(p) (((u8 *)p)[0] & 0xff) |
| 265 | |
| 266 | #define SDPCM_CHANNEL_MASK 0x00000f00 |
| 267 | #define SDPCM_CHANNEL_SHIFT 8 |
| 268 | #define SDPCM_PACKET_CHANNEL(p) (((u8 *)p)[1] & 0x0f) |
| 269 | |
| 270 | #define SDPCM_NEXTLEN_OFFSET 2 |
| 271 | |
| 272 | /* Data Offset from SOF (HW Tag, SW Tag, Pad) */ |
| 273 | #define SDPCM_DOFFSET_OFFSET 3 /* Data Offset */ |
| 274 | #define SDPCM_DOFFSET_VALUE(p) (((u8 *)p)[SDPCM_DOFFSET_OFFSET] & 0xff) |
| 275 | #define SDPCM_DOFFSET_MASK 0xff000000 |
| 276 | #define SDPCM_DOFFSET_SHIFT 24 |
| 277 | #define SDPCM_FCMASK_OFFSET 4 /* Flow control */ |
| 278 | #define SDPCM_FCMASK_VALUE(p) (((u8 *)p)[SDPCM_FCMASK_OFFSET] & 0xff) |
| 279 | #define SDPCM_WINDOW_OFFSET 5 /* Credit based fc */ |
| 280 | #define SDPCM_WINDOW_VALUE(p) (((u8 *)p)[SDPCM_WINDOW_OFFSET] & 0xff) |
| 281 | |
| 282 | #define SDPCM_SWHEADER_LEN 8 /* SW header is 64 bits */ |
| 283 | |
| 284 | /* logical channel numbers */ |
| 285 | #define SDPCM_CONTROL_CHANNEL 0 /* Control channel Id */ |
| 286 | #define SDPCM_EVENT_CHANNEL 1 /* Asyc Event Indication Channel Id */ |
| 287 | #define SDPCM_DATA_CHANNEL 2 /* Data Xmit/Recv Channel Id */ |
| 288 | #define SDPCM_GLOM_CHANNEL 3 /* For coalesced packets */ |
| 289 | #define SDPCM_TEST_CHANNEL 15 /* Reserved for test/debug packets */ |
| 290 | |
| 291 | #define SDPCM_SEQUENCE_WRAP 256 /* wrap-around val for 8bit frame seq */ |
| 292 | |
| 293 | #define SDPCM_GLOMDESC(p) (((u8 *)p)[1] & 0x80) |
| 294 | |
| 295 | /* For TEST_CHANNEL packets, define another 4-byte header */ |
| 296 | #define SDPCM_TEST_HDRLEN 4 /* |
| 297 | * Generally: Cmd(1), Ext(1), Len(2); |
| 298 | * Semantics of Ext byte depend on |
| 299 | * command. Len is current or requested |
| 300 | * frame length, not including test |
| 301 | * header; sent little-endian. |
| 302 | */ |
| 303 | #define SDPCM_TEST_DISCARD 0x01 /* Receiver discards. Ext:pattern id. */ |
| 304 | #define SDPCM_TEST_ECHOREQ 0x02 /* Echo request. Ext:pattern id. */ |
| 305 | #define SDPCM_TEST_ECHORSP 0x03 /* Echo response. Ext:pattern id. */ |
| 306 | #define SDPCM_TEST_BURST 0x04 /* |
| 307 | * Receiver to send a burst. |
| 308 | * Ext is a frame count |
| 309 | */ |
| 310 | #define SDPCM_TEST_SEND 0x05 /* |
| 311 | * Receiver sets send mode. |
| 312 | * Ext is boolean on/off |
| 313 | */ |
| 314 | |
| 315 | /* Handy macro for filling in datagen packets with a pattern */ |
| 316 | #define SDPCM_TEST_FILL(byteno, id) ((u8)(id + byteno)) |
| 317 | |
| 318 | /* |
| 319 | * Shared structure between dongle and the host. |
| 320 | * The structure contains pointers to trap or assert information. |
| 321 | */ |
| 322 | #define SDPCM_SHARED_VERSION 0x0002 |
| 323 | #define SDPCM_SHARED_VERSION_MASK 0x00FF |
| 324 | #define SDPCM_SHARED_ASSERT_BUILT 0x0100 |
| 325 | #define SDPCM_SHARED_ASSERT 0x0200 |
| 326 | #define SDPCM_SHARED_TRAP 0x0400 |
| 327 | |
| 328 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 329 | /* Space for header read, limit for data packets */ |
| 330 | #ifndef MAX_HDR_READ |
| 331 | #define MAX_HDR_READ 32 |
| 332 | #endif |
| 333 | #if !ISPOWEROF2(MAX_HDR_READ) |
| 334 | #error MAX_HDR_READ is not a power of 2! |
| 335 | #endif |
| 336 | |
| 337 | #define MAX_RX_DATASZ 2048 |
| 338 | |
| 339 | /* Maximum milliseconds to wait for F2 to come up */ |
| 340 | #define DHD_WAIT_F2RDY 3000 |
| 341 | |
| 342 | /* Bump up limit on waiting for HT to account for first startup; |
| 343 | * if the image is doing a CRC calculation before programming the PMU |
| 344 | * for HT availability, it could take a couple hundred ms more, so |
| 345 | * max out at a 1 second (1000000us). |
| 346 | */ |
| 347 | #if (PMU_MAX_TRANSITION_DLY <= 1000000) |
| 348 | #undef PMU_MAX_TRANSITION_DLY |
| 349 | #define PMU_MAX_TRANSITION_DLY 1000000 |
| 350 | #endif |
| 351 | |
| 352 | /* Value for ChipClockCSR during initial setup */ |
| 353 | #define DHD_INIT_CLKCTL1 (SBSDIO_FORCE_HW_CLKREQ_OFF | \ |
| 354 | SBSDIO_ALP_AVAIL_REQ) |
| 355 | #define DHD_INIT_CLKCTL2 (SBSDIO_FORCE_HW_CLKREQ_OFF | SBSDIO_FORCE_ALP) |
| 356 | |
| 357 | /* Flags for SDH calls */ |
| 358 | #define F2SYNC (SDIO_REQ_4BYTE | SDIO_REQ_FIXED) |
| 359 | |
Roland Vossen | b6fe70c | 2011-06-01 13:45:19 +0200 | [diff] [blame] | 360 | /* sbimstate */ |
| 361 | #define SBIM_IBE 0x20000 /* inbanderror */ |
| 362 | #define SBIM_TO 0x40000 /* timeout */ |
| 363 | #define SBIM_BY 0x01800000 /* busy (sonics >= 2.3) */ |
| 364 | #define SBIM_RJ 0x02000000 /* reject (sonics >= 2.3) */ |
| 365 | |
| 366 | /* sbtmstatelow */ |
| 367 | #define SBTML_RESET 0x0001 /* reset */ |
| 368 | #define SBTML_REJ_MASK 0x0006 /* reject field */ |
| 369 | #define SBTML_REJ 0x0002 /* reject */ |
| 370 | #define SBTML_TMPREJ 0x0004 /* temporary reject, for error recovery */ |
| 371 | |
| 372 | #define SBTML_SICF_SHIFT 16 /* Shift to locate the SI control flags in sbtml */ |
| 373 | |
| 374 | /* sbtmstatehigh */ |
| 375 | #define SBTMH_SERR 0x0001 /* serror */ |
| 376 | #define SBTMH_INT 0x0002 /* interrupt */ |
| 377 | #define SBTMH_BUSY 0x0004 /* busy */ |
| 378 | #define SBTMH_TO 0x0020 /* timeout (sonics >= 2.3) */ |
| 379 | |
| 380 | #define SBTMH_SISF_SHIFT 16 /* Shift to locate the SI status flags in sbtmh */ |
| 381 | |
| 382 | /* sbidlow */ |
| 383 | #define SBIDL_INIT 0x80 /* initiator */ |
| 384 | |
| 385 | /* sbidhigh */ |
| 386 | #define SBIDH_RC_MASK 0x000f /* revision code */ |
| 387 | #define SBIDH_RCE_MASK 0x7000 /* revision code extension field */ |
| 388 | #define SBIDH_RCE_SHIFT 8 |
| 389 | #define SBCOREREV(sbidh) \ |
| 390 | ((((sbidh) & SBIDH_RCE_MASK) >> SBIDH_RCE_SHIFT) | ((sbidh) & SBIDH_RC_MASK)) |
| 391 | #define SBIDH_CC_MASK 0x8ff0 /* core code */ |
| 392 | #define SBIDH_CC_SHIFT 4 |
| 393 | #define SBIDH_VC_MASK 0xffff0000 /* vendor code */ |
| 394 | #define SBIDH_VC_SHIFT 16 |
| 395 | |
Arend van Spriel | 70dfb58 | 2011-02-25 16:39:17 +0100 | [diff] [blame] | 396 | /* |
| 397 | * Conversion of 802.1D priority to precedence level |
| 398 | */ |
| 399 | #define PRIO2PREC(prio) \ |
| 400 | (((prio) == PRIO_8021D_NONE || (prio) == PRIO_8021D_BE) ? \ |
| 401 | ((prio^2)) : (prio)) |
| 402 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 403 | DHD_SPINWAIT_SLEEP_INIT(sdioh_spinwait_sleep); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 404 | |
Roland Vossen | b6fe70c | 2011-06-01 13:45:19 +0200 | [diff] [blame] | 405 | /* Core reg address translation */ |
| 406 | #define CORE_CC_REG(base, field) (base + offsetof(chipcregs_t, field)) |
Franky Lin | 597600a | 2011-06-01 13:45:39 +0200 | [diff] [blame] | 407 | #define CORE_BUS_REG(base, field) \ |
| 408 | (base + offsetof(struct sdpcmd_regs, field)) |
Roland Vossen | b6fe70c | 2011-06-01 13:45:19 +0200 | [diff] [blame] | 409 | #define CORE_SB(base, field) \ |
| 410 | (base + SBCONFIGOFF + offsetof(sbconfig_t, field)) |
| 411 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 412 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 413 | /* Device console log buffer state */ |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 414 | struct dhd_console { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 415 | uint count; /* Poll interval msec counter */ |
| 416 | uint log_addr; /* Log struct address (fixed) */ |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 417 | struct rte_log log; /* Log struct (host copy) */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 418 | uint bufsize; /* Size of log buffer */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 419 | u8 *buf; /* Log buffer (host copy) */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 420 | uint last; /* Last buffer read index */ |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 421 | }; |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 422 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 423 | |
Franky Lin | b49b14d | 2011-06-01 13:45:37 +0200 | [diff] [blame] | 424 | struct sdpcm_shared { |
| 425 | u32 flags; |
| 426 | u32 trap_addr; |
| 427 | u32 assert_exp_addr; |
| 428 | u32 assert_file_addr; |
| 429 | u32 assert_line; |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 430 | u32 console_addr; /* Address of struct rte_console */ |
Franky Lin | b49b14d | 2011-06-01 13:45:37 +0200 | [diff] [blame] | 431 | u32 msgtrace_addr; |
| 432 | u8 tag[32]; |
| 433 | }; |
| 434 | |
| 435 | |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 436 | /* misc chip info needed by some of the routines */ |
| 437 | struct chip_info { |
| 438 | u32 chip; |
| 439 | u32 chiprev; |
| 440 | u32 cccorebase; |
| 441 | u32 ccrev; |
| 442 | u32 cccaps; |
| 443 | u32 buscorebase; |
| 444 | u32 buscorerev; |
| 445 | u32 buscoretype; |
| 446 | u32 ramcorebase; |
| 447 | u32 armcorebase; |
| 448 | u32 pmurev; |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 449 | u32 ramsize; |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 450 | }; |
| 451 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 452 | /* Private data for SDIO bus interaction */ |
| 453 | typedef struct dhd_bus { |
| 454 | dhd_pub_t *dhd; |
| 455 | |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 456 | struct brcmf_sdio *sdh; /* Handle for BCMSDH calls */ |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 457 | struct chip_info *ci; /* Chip info struct */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 458 | char *vars; /* Variables (from CIS and/or other) */ |
| 459 | uint varsz; /* Size of variables buffer */ |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 460 | u32 sbaddr; /* Current SB window pointer (-1, invalid) */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 461 | |
Franky Lin | 597600a | 2011-06-01 13:45:39 +0200 | [diff] [blame] | 462 | struct sdpcmd_regs *regs; /* SDIO core */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 463 | uint sdpcmrev; /* SDIO core revision */ |
| 464 | uint armrev; /* CPU core revision */ |
| 465 | uint ramrev; /* SOCRAM core revision */ |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 466 | u32 ramsize; /* Size of RAM in SOCRAM (bytes) */ |
| 467 | u32 orig_ramsize; /* Size of RAM in SOCRAM (bytes) */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 468 | |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 469 | u32 bus; /* gSPI or SDIO bus */ |
| 470 | u32 hostintmask; /* Copy of Host Interrupt Mask */ |
| 471 | u32 intstatus; /* Intstatus bits (events) pending */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 472 | bool dpc_sched; /* Indicates DPC schedule (intrpt rcvd) */ |
| 473 | bool fcstate; /* State of dongle flow-control */ |
| 474 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 475 | u16 cl_devid; /* cached devid for brcmf_sdio_probe_attach() */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 476 | char *fw_path; /* module_param: path to firmware image */ |
| 477 | char *nv_path; /* module_param: path to nvram vars file */ |
| 478 | const char *nvram_params; /* user specified nvram params. */ |
| 479 | |
| 480 | uint blocksize; /* Block size of SDIO transfers */ |
| 481 | uint roundup; /* Max roundup limit */ |
| 482 | |
| 483 | struct pktq txq; /* Queue length used for flow-control */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 484 | u8 flowcontrol; /* per prio flow control bitmask */ |
| 485 | u8 tx_seq; /* Transmit sequence number (next) */ |
| 486 | u8 tx_max; /* Maximum transmit sequence allowed */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 487 | |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 488 | u8 hdrbuf[MAX_HDR_READ + BRCMF_SDALIGN]; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 489 | u8 *rxhdr; /* Header of current rx frame (in hdrbuf) */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 490 | u16 nextlen; /* Next Read Len from last header */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 491 | u8 rx_seq; /* Receive sequence number (expected) */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 492 | bool rxskip; /* Skip receive (awaiting NAK ACK) */ |
| 493 | |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 494 | struct sk_buff *glomd; /* Packet containing glomming descriptor */ |
| 495 | struct sk_buff *glom; /* Packet chain for glommed superframe */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 496 | uint glomerr; /* Glom packet read errors */ |
| 497 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 498 | u8 *rxbuf; /* Buffer for receiving control packets */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 499 | uint rxblen; /* Allocated length of rxbuf */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 500 | u8 *rxctl; /* Aligned pointer into rxbuf */ |
| 501 | u8 *databuf; /* Buffer for receiving big glom packet */ |
| 502 | u8 *dataptr; /* Aligned pointer into databuf */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 503 | uint rxlen; /* Length of valid data in buffer */ |
| 504 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 505 | u8 sdpcm_ver; /* Bus protocol reported by dongle */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 506 | |
| 507 | bool intr; /* Use interrupts */ |
| 508 | bool poll; /* Use polling */ |
| 509 | bool ipend; /* Device interrupt is pending */ |
| 510 | bool intdis; /* Interrupts disabled by isr */ |
| 511 | uint intrcount; /* Count of device interrupt callbacks */ |
| 512 | uint lastintrs; /* Count as of last watchdog timer */ |
| 513 | uint spurious; /* Count of spurious interrupts */ |
| 514 | uint pollrate; /* Ticks between device polls */ |
| 515 | uint polltick; /* Tick counter */ |
| 516 | uint pollcnt; /* Count of active polls */ |
| 517 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 518 | #ifdef BCMDBG |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 519 | struct dhd_console console; /* Console output polling support */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 520 | uint console_addr; /* Console address from shared struct */ |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 521 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 522 | |
| 523 | uint regfails; /* Count of R_REG/W_REG failures */ |
| 524 | |
| 525 | uint clkstate; /* State of sd and backplane clock(s) */ |
| 526 | bool activity; /* Activity flag for clock down */ |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 527 | s32 idletime; /* Control for activity timeout */ |
| 528 | s32 idlecount; /* Activity timeout counter */ |
| 529 | s32 idleclock; /* How to set bus driver when idle */ |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 530 | s32 sd_rxchain; /* If bcmsdh api accepts PKT chains */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 531 | bool use_rxchain; /* If dhd should use PKT chains */ |
| 532 | bool sleeping; /* Is SDIO bus sleeping? */ |
| 533 | bool rxflow_mode; /* Rx flow control mode */ |
| 534 | bool rxflow; /* Is rx flow control on */ |
| 535 | uint prev_rxlim_hit; /* Is prev rx limit exceeded |
| 536 | (per dpc schedule) */ |
| 537 | bool alp_only; /* Don't use HT clock (ALP only) */ |
| 538 | /* Field to decide if rx of control frames happen in rxbuf or lb-pool */ |
| 539 | bool usebufpool; |
| 540 | |
| 541 | #ifdef SDTEST |
| 542 | /* external loopback */ |
| 543 | bool ext_loop; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 544 | u8 loopid; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 545 | |
| 546 | /* pktgen configuration */ |
| 547 | uint pktgen_freq; /* Ticks between bursts */ |
| 548 | uint pktgen_count; /* Packets to send each burst */ |
| 549 | uint pktgen_print; /* Bursts between count displays */ |
| 550 | uint pktgen_total; /* Stop after this many */ |
| 551 | uint pktgen_minlen; /* Minimum packet data len */ |
| 552 | uint pktgen_maxlen; /* Maximum packet data len */ |
| 553 | uint pktgen_mode; /* Configured mode: tx, rx, or echo */ |
| 554 | uint pktgen_stop; /* Number of tx failures causing stop */ |
| 555 | |
| 556 | /* active pktgen fields */ |
| 557 | uint pktgen_tick; /* Tick counter for bursts */ |
| 558 | uint pktgen_ptick; /* Burst counter for printing */ |
| 559 | uint pktgen_sent; /* Number of test packets generated */ |
| 560 | uint pktgen_rcvd; /* Number of test packets received */ |
| 561 | uint pktgen_fail; /* Number of failed send attempts */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 562 | u16 pktgen_len; /* Length of next packet to send */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 563 | #endif /* SDTEST */ |
| 564 | |
| 565 | /* Some additional counters */ |
| 566 | uint tx_sderrs; /* Count of tx attempts with sd errors */ |
| 567 | uint fcqueued; /* Tx packets that got queued */ |
| 568 | uint rxrtx; /* Count of rtx requests (NAK to dongle) */ |
| 569 | uint rx_toolong; /* Receive frames too long to receive */ |
| 570 | uint rxc_errors; /* SDIO errors when reading control frames */ |
| 571 | uint rx_hdrfail; /* SDIO errors on header reads */ |
| 572 | uint rx_badhdr; /* Bad received headers (roosync?) */ |
| 573 | uint rx_badseq; /* Mismatched rx sequence number */ |
| 574 | uint fc_rcvd; /* Number of flow-control events received */ |
| 575 | uint fc_xoff; /* Number which turned on flow-control */ |
| 576 | uint fc_xon; /* Number which turned off flow-control */ |
| 577 | uint rxglomfail; /* Failed deglom attempts */ |
| 578 | uint rxglomframes; /* Number of glom frames (superframes) */ |
| 579 | uint rxglompkts; /* Number of packets from glom frames */ |
| 580 | uint f2rxhdrs; /* Number of header reads */ |
| 581 | uint f2rxdata; /* Number of frame data reads */ |
| 582 | uint f2txdata; /* Number of f2 frame writes */ |
| 583 | uint f1regdata; /* Number of f1 register accesses */ |
| 584 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 585 | u8 *ctrl_frame_buf; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 586 | u32 ctrl_frame_len; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 587 | bool ctrl_frame_stat; |
Franky Lin | 0f1a87c | 2011-06-29 16:46:32 -0700 | [diff] [blame] | 588 | |
| 589 | spinlock_t txqlock; |
Franky Lin | b7adfa7 | 2011-06-29 16:47:42 -0700 | [diff] [blame] | 590 | wait_queue_head_t ctrl_wait; |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 591 | |
| 592 | struct timer_list timer; |
| 593 | struct completion watchdog_wait; |
| 594 | struct task_struct *watchdog_tsk; |
| 595 | bool wd_timer_valid; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 596 | } dhd_bus_t; |
| 597 | |
Roland Vossen | b6fe70c | 2011-06-01 13:45:19 +0200 | [diff] [blame] | 598 | typedef volatile struct _sbconfig { |
| 599 | u32 PAD[2]; |
| 600 | u32 sbipsflag; /* initiator port ocp slave flag */ |
| 601 | u32 PAD[3]; |
| 602 | u32 sbtpsflag; /* target port ocp slave flag */ |
| 603 | u32 PAD[11]; |
| 604 | u32 sbtmerrloga; /* (sonics >= 2.3) */ |
| 605 | u32 PAD; |
| 606 | u32 sbtmerrlog; /* (sonics >= 2.3) */ |
| 607 | u32 PAD[3]; |
| 608 | u32 sbadmatch3; /* address match3 */ |
| 609 | u32 PAD; |
| 610 | u32 sbadmatch2; /* address match2 */ |
| 611 | u32 PAD; |
| 612 | u32 sbadmatch1; /* address match1 */ |
| 613 | u32 PAD[7]; |
| 614 | u32 sbimstate; /* initiator agent state */ |
| 615 | u32 sbintvec; /* interrupt mask */ |
| 616 | u32 sbtmstatelow; /* target state */ |
| 617 | u32 sbtmstatehigh; /* target state */ |
| 618 | u32 sbbwa0; /* bandwidth allocation table0 */ |
| 619 | u32 PAD; |
| 620 | u32 sbimconfiglow; /* initiator configuration */ |
| 621 | u32 sbimconfighigh; /* initiator configuration */ |
| 622 | u32 sbadmatch0; /* address match0 */ |
| 623 | u32 PAD; |
| 624 | u32 sbtmconfiglow; /* target configuration */ |
| 625 | u32 sbtmconfighigh; /* target configuration */ |
| 626 | u32 sbbconfig; /* broadcast configuration */ |
| 627 | u32 PAD; |
| 628 | u32 sbbstate; /* broadcast state */ |
| 629 | u32 PAD[3]; |
| 630 | u32 sbactcnfg; /* activate configuration */ |
| 631 | u32 PAD[3]; |
| 632 | u32 sbflagst; /* current sbflags */ |
| 633 | u32 PAD[3]; |
| 634 | u32 sbidlow; /* identification */ |
| 635 | u32 sbidhigh; /* identification */ |
| 636 | } sbconfig_t; |
| 637 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 638 | /* clkstate */ |
| 639 | #define CLK_NONE 0 |
| 640 | #define CLK_SDONLY 1 |
| 641 | #define CLK_PENDING 2 /* Not used yet */ |
| 642 | #define CLK_AVAIL 3 |
| 643 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 644 | #define DHD_NOPMU(dhd) (false) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 645 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 646 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 647 | static int qcount[NUMPRIO]; |
| 648 | static int tx_packets[NUMPRIO]; |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 649 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 650 | |
| 651 | /* Deferred transmit */ |
Arend van Spriel | 7af9d0c | 2011-06-29 16:47:19 -0700 | [diff] [blame] | 652 | const uint brcmf_deferred_tx = 1; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 653 | |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 654 | /* Watchdog thread priority, -1 to use kernel timer */ |
| 655 | int brcmf_watchdog_prio = 97; |
| 656 | module_param(brcmf_watchdog_prio, int, 0); |
| 657 | |
| 658 | /* Watchdog interval */ |
| 659 | uint brcmf_watchdog_ms = 10; |
| 660 | module_param(brcmf_watchdog_ms, uint, 0); |
| 661 | |
Franky Lin | 913af5f | 2011-06-29 16:47:44 -0700 | [diff] [blame^] | 662 | #ifdef BCMDBG |
| 663 | /* Console poll interval */ |
| 664 | uint brcmf_console_ms; |
| 665 | module_param(brcmf_console_ms, uint, 0); |
| 666 | #endif /* DHD_DEBUG */ |
| 667 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 668 | /* Tx/Rx bounds */ |
Arend van Spriel | 7af9d0c | 2011-06-29 16:47:19 -0700 | [diff] [blame] | 669 | uint brcmf_txbound; |
| 670 | uint brcmf_rxbound; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 671 | uint dhd_txminmax; |
| 672 | |
| 673 | /* override the RAM size if possible */ |
| 674 | #define DONGLE_MIN_MEMSIZE (128 * 1024) |
Arend van Spriel | 7af9d0c | 2011-06-29 16:47:19 -0700 | [diff] [blame] | 675 | int brcmf_dongle_memsize; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 676 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 677 | static bool dhd_alignctl; |
| 678 | |
| 679 | static bool sd1idle; |
| 680 | |
| 681 | static bool retrydata; |
| 682 | #define RETRYCHAN(chan) (((chan) == SDPCM_EVENT_CHANNEL) || retrydata) |
| 683 | |
| 684 | static const uint watermark = 8; |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 685 | static const uint firstread = BRCMF_FIRSTREAD; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 686 | |
| 687 | #define HDATLEN (firstread - (SDPCM_HDRLEN)) |
| 688 | |
| 689 | /* Retry count for register access failures */ |
| 690 | static const uint retry_limit = 2; |
| 691 | |
| 692 | /* Force even SD lengths (some host controllers mess up on odd bytes) */ |
| 693 | static bool forcealign; |
| 694 | |
| 695 | #define ALIGNMENT 4 |
| 696 | |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 697 | #define PKTALIGN(_p, _len, _align) \ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 698 | do { \ |
| 699 | uint datalign; \ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 700 | datalign = (unsigned long)((_p)->data); \ |
| 701 | datalign = roundup(datalign, (_align)) - datalign; \ |
| 702 | ASSERT(datalign < (_align)); \ |
| 703 | ASSERT((_p)->len >= ((_len) + datalign)); \ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 704 | if (datalign) \ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 705 | skb_pull((_p), datalign); \ |
| 706 | __skb_trim((_p), (_len)); \ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 707 | } while (0) |
| 708 | |
| 709 | /* Limit on rounding up frames */ |
| 710 | static const uint max_roundup = 512; |
| 711 | |
| 712 | /* Try doing readahead */ |
| 713 | static bool dhd_readahead; |
| 714 | |
| 715 | /* To check if there's window offered */ |
| 716 | #define DATAOK(bus) \ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 717 | (((u8)(bus->tx_max - bus->tx_seq) != 0) && \ |
| 718 | (((u8)(bus->tx_max - bus->tx_seq) & 0x80) == 0)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 719 | |
| 720 | /* Macros to get register read/write status */ |
| 721 | /* NOTE: these assume a local dhdsdio_bus_t *bus! */ |
| 722 | #define R_SDREG(regvar, regaddr, retryvar) \ |
| 723 | do { \ |
| 724 | retryvar = 0; \ |
| 725 | do { \ |
Arend van Spriel | ff31c54 | 2011-03-01 10:56:54 +0100 | [diff] [blame] | 726 | regvar = R_REG(regaddr); \ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 727 | } while (brcmf_sdcard_regfail(bus->sdh) && \ |
| 728 | (++retryvar <= retry_limit)); \ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 729 | if (retryvar) { \ |
| 730 | bus->regfails += (retryvar-1); \ |
| 731 | if (retryvar > retry_limit) { \ |
| 732 | DHD_ERROR(("%s: FAILED" #regvar "READ, LINE %d\n", \ |
| 733 | __func__, __LINE__)); \ |
| 734 | regvar = 0; \ |
| 735 | } \ |
| 736 | } \ |
| 737 | } while (0) |
| 738 | |
| 739 | #define W_SDREG(regval, regaddr, retryvar) \ |
| 740 | do { \ |
| 741 | retryvar = 0; \ |
| 742 | do { \ |
Arend van Spriel | ff31c54 | 2011-03-01 10:56:54 +0100 | [diff] [blame] | 743 | W_REG(regaddr, regval); \ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 744 | } while (brcmf_sdcard_regfail(bus->sdh) && \ |
| 745 | (++retryvar <= retry_limit)); \ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 746 | if (retryvar) { \ |
| 747 | bus->regfails += (retryvar-1); \ |
| 748 | if (retryvar > retry_limit) \ |
| 749 | DHD_ERROR(("%s: FAILED REGISTER WRITE, LINE %d\n", \ |
| 750 | __func__, __LINE__)); \ |
| 751 | } \ |
| 752 | } while (0) |
| 753 | |
| 754 | #define DHD_BUS SDIO_BUS |
| 755 | |
| 756 | #define PKT_AVAILABLE() (intstatus & I_HMB_FRAME_IND) |
| 757 | |
| 758 | #define HOSTINTMASK (I_HMB_SW_MASK | I_CHIPACTIVE) |
| 759 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 760 | #ifdef SDTEST |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 761 | static void brcmf_sdbrcm_checkdied(dhd_bus_t *bus, void *pkt, uint seq); |
| 762 | static void brcmf_sdbrcm_sdtest_set(dhd_bus_t *bus, bool start); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 763 | #endif |
| 764 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 765 | #ifdef BCMDBG |
Franky Lin | 913af5f | 2011-06-29 16:47:44 -0700 | [diff] [blame^] | 766 | static int brcmf_sdbrcm_bus_console_in(dhd_pub_t *dhdp, unsigned char *msg, |
| 767 | uint msglen); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 768 | static int brcmf_sdbrcm_checkdied(dhd_bus_t *bus, u8 *data, uint size); |
| 769 | static int brcmf_sdbrcm_mem_dump(dhd_bus_t *bus); |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 770 | #endif /* BCMDBG */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 771 | static int brcmf_sdbrcm_download_state(dhd_bus_t *bus, bool enter); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 772 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 773 | static void brcmf_sdbrcm_release(dhd_bus_t *bus); |
| 774 | static void brcmf_sdbrcm_release_malloc(dhd_bus_t *bus); |
| 775 | static void brcmf_sdbrcm_disconnect(void *ptr); |
| 776 | static bool brcmf_sdbrcm_chipmatch(u16 chipid); |
| 777 | static bool brcmf_sdbrcm_probe_attach(dhd_bus_t *bus, void *sdh, |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 778 | void *regsva, u16 devid); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 779 | static bool brcmf_sdbrcm_probe_malloc(dhd_bus_t *bus, void *sdh); |
| 780 | static bool brcmf_sdbrcm_probe_init(dhd_bus_t *bus, void *sdh); |
| 781 | static void brcmf_sdbrcm_release_dongle(dhd_bus_t *bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 782 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 783 | static uint brcmf_process_nvram_vars(char *varbuf, uint len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 784 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 785 | static void brcmf_sdbrcm_setmemsize(struct dhd_bus *bus, int mem_size); |
| 786 | 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] | 787 | uint flags, u8 *buf, uint nbytes, |
| 788 | struct sk_buff *pkt, bcmsdh_cmplt_fn_t complete, |
| 789 | void *handle); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 790 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 791 | static bool brcmf_sdbrcm_download_firmware(struct dhd_bus *bus, void *sdh); |
| 792 | static int _brcmf_sdbrcm_download_firmware(struct dhd_bus *bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 793 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 794 | static int |
| 795 | brcmf_sdbrcm_download_code_file(struct dhd_bus *bus, char *image_path); |
| 796 | static int brcmf_sdbrcm_download_nvram(struct dhd_bus *bus); |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 797 | static void brcmf_sdbrcm_chip_disablecore(struct brcmf_sdio *sdh, u32 corebase); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 798 | static int brcmf_sdbrcm_chip_attach(struct dhd_bus *bus, void *regs); |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 799 | static void brcmf_sdbrcm_chip_resetcore(struct brcmf_sdio *sdh, u32 corebase); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 800 | static void brcmf_sdbrcm_sdiod_drive_strength_init(struct dhd_bus *bus, |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 801 | u32 drivestrength); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 802 | static void brcmf_sdbrcm_chip_detach(struct dhd_bus *bus); |
Franky Lin | b7adfa7 | 2011-06-29 16:47:42 -0700 | [diff] [blame] | 803 | static void brcmf_sdbrcm_wait_for_event(dhd_pub_t *dhd, bool *lockvar); |
| 804 | static void brcmf_sdbrcm_wait_event_wakeup(dhd_bus_t *bus); |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 805 | static void brcmf_sdbrcm_watchdog(unsigned long data); |
| 806 | static int brcmf_sdbrcm_watchdog_thread(void *data); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 807 | |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 808 | /* Packet free applicable unconditionally for sdio and sdspi. |
| 809 | * Conditional if bufpool was present for gspi bus. |
| 810 | */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 811 | 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] | 812 | { |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 813 | if ((bus->bus != SPI_BUS) || bus->usebufpool) |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 814 | brcmu_pkt_buf_free_skb(pkt); |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 815 | } |
| 816 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 817 | static void brcmf_sdbrcm_setmemsize(struct dhd_bus *bus, int mem_size) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 818 | { |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 819 | s32 min_size = DONGLE_MIN_MEMSIZE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 820 | /* Restrict the memsize to user specified limit */ |
| 821 | 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] | 822 | brcmf_dongle_memsize, min_size)); |
| 823 | if ((brcmf_dongle_memsize > min_size) && |
| 824 | (brcmf_dongle_memsize < (s32) bus->orig_ramsize)) |
| 825 | bus->ramsize = brcmf_dongle_memsize; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 826 | } |
| 827 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 828 | 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] | 829 | { |
| 830 | int err = 0; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 831 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRLOW, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 832 | (address >> 8) & SBSDIO_SBADDRLOW_MASK, &err); |
| 833 | if (!err) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 834 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_1, |
| 835 | SBSDIO_FUNC1_SBADDRMID, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 836 | (address >> 16) & SBSDIO_SBADDRMID_MASK, &err); |
| 837 | if (!err) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 838 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_1, |
| 839 | SBSDIO_FUNC1_SBADDRHIGH, |
| 840 | (address >> 24) & SBSDIO_SBADDRHIGH_MASK, |
| 841 | &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 842 | return err; |
| 843 | } |
| 844 | |
| 845 | /* Turn backplane clock on or off */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 846 | 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] | 847 | { |
| 848 | int err; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 849 | u8 clkctl, clkreq, devctl; |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 850 | struct brcmf_sdio *sdh; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 851 | |
| 852 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 853 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 854 | clkctl = 0; |
| 855 | sdh = bus->sdh; |
| 856 | |
| 857 | if (on) { |
| 858 | /* Request HT Avail */ |
| 859 | clkreq = |
| 860 | bus->alp_only ? SBSDIO_ALP_AVAIL_REQ : SBSDIO_HT_AVAIL_REQ; |
| 861 | |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 862 | if ((bus->ci->chip == BCM4329_CHIP_ID) |
| 863 | && (bus->ci->chiprev == 0)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 864 | clkreq |= SBSDIO_FORCE_ALP; |
| 865 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 866 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, |
| 867 | SBSDIO_FUNC1_CHIPCLKCSR, clkreq, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 868 | if (err) { |
| 869 | DHD_ERROR(("%s: HT Avail request error: %d\n", |
| 870 | __func__, err)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 871 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 872 | } |
| 873 | |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 874 | if (pendok && ((bus->ci->buscoretype == PCMCIA_CORE_ID) |
| 875 | && (bus->ci->buscorerev == 9))) { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 876 | u32 dummy, retries; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 877 | R_SDREG(dummy, &bus->regs->clockctlstatus, retries); |
| 878 | } |
| 879 | |
| 880 | /* Check current status */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 881 | clkctl = brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
| 882 | SBSDIO_FUNC1_CHIPCLKCSR, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 883 | if (err) { |
| 884 | DHD_ERROR(("%s: HT Avail read error: %d\n", |
| 885 | __func__, err)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 886 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | /* Go to pending and await interrupt if appropriate */ |
| 890 | if (!SBSDIO_CLKAV(clkctl, bus->alp_only) && pendok) { |
| 891 | /* Allow only clock-available interrupt */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 892 | devctl = brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
| 893 | SBSDIO_DEVICE_CTL, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 894 | if (err) { |
| 895 | DHD_ERROR(("%s: Devctl error setting CA: %d\n", |
| 896 | __func__, err)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 897 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 898 | } |
| 899 | |
| 900 | devctl |= SBSDIO_DEVCTL_CA_INT_ONLY; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 901 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, |
| 902 | SBSDIO_DEVICE_CTL, devctl, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 903 | DHD_INFO(("CLKCTL: set PENDING\n")); |
| 904 | bus->clkstate = CLK_PENDING; |
| 905 | |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 906 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 907 | } else if (bus->clkstate == CLK_PENDING) { |
| 908 | /* Cancel CA-only interrupt filter */ |
| 909 | devctl = |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 910 | brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
| 911 | SBSDIO_DEVICE_CTL, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 912 | devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 913 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, |
| 914 | SBSDIO_DEVICE_CTL, devctl, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | /* Otherwise, wait here (polling) for HT Avail */ |
| 918 | if (!SBSDIO_CLKAV(clkctl, bus->alp_only)) { |
| 919 | SPINWAIT_SLEEP(sdioh_spinwait_sleep, |
| 920 | ((clkctl = |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 921 | brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 922 | SBSDIO_FUNC1_CHIPCLKCSR, |
| 923 | &err)), |
| 924 | !SBSDIO_CLKAV(clkctl, bus->alp_only)), |
| 925 | PMU_MAX_TRANSITION_DLY); |
| 926 | } |
| 927 | if (err) { |
| 928 | DHD_ERROR(("%s: HT Avail request error: %d\n", |
| 929 | __func__, err)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 930 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 931 | } |
| 932 | if (!SBSDIO_CLKAV(clkctl, bus->alp_only)) { |
| 933 | DHD_ERROR(("%s: HT Avail timeout (%d): clkctl 0x%02x\n", |
| 934 | __func__, PMU_MAX_TRANSITION_DLY, clkctl)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 935 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | /* Mark clock available */ |
| 939 | bus->clkstate = CLK_AVAIL; |
| 940 | DHD_INFO(("CLKCTL: turned ON\n")); |
| 941 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 942 | #if defined(BCMDBG) |
Arend van Spriel | f3341e7 | 2011-06-29 16:47:28 -0700 | [diff] [blame] | 943 | if (bus->alp_only != true) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 944 | if (SBSDIO_ALPONLY(clkctl)) { |
| 945 | DHD_ERROR(("%s: HT Clock should be on.\n", |
| 946 | __func__)); |
| 947 | } |
| 948 | } |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 949 | #endif /* defined (BCMDBG) */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 950 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 951 | bus->activity = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 952 | } else { |
| 953 | clkreq = 0; |
| 954 | |
| 955 | if (bus->clkstate == CLK_PENDING) { |
| 956 | /* Cancel CA-only interrupt filter */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 957 | devctl = brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
| 958 | SBSDIO_DEVICE_CTL, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 959 | devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 960 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, |
| 961 | SBSDIO_DEVICE_CTL, devctl, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 962 | } |
| 963 | |
| 964 | bus->clkstate = CLK_SDONLY; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 965 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, |
| 966 | SBSDIO_FUNC1_CHIPCLKCSR, clkreq, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 967 | DHD_INFO(("CLKCTL: turned OFF\n")); |
| 968 | if (err) { |
| 969 | DHD_ERROR(("%s: Failed access turning clock off: %d\n", |
| 970 | __func__, err)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 971 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 972 | } |
| 973 | } |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 974 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 975 | } |
| 976 | |
| 977 | /* Change idle/active SD state */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 978 | static int brcmf_sdbrcm_sdclk(dhd_bus_t *bus, bool on) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 979 | { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 980 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 981 | |
Franky Lin | 602a8ab | 2011-06-01 13:45:04 +0200 | [diff] [blame] | 982 | if (on) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 983 | bus->clkstate = CLK_SDONLY; |
Franky Lin | 602a8ab | 2011-06-01 13:45:04 +0200 | [diff] [blame] | 984 | else |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 985 | bus->clkstate = CLK_NONE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 986 | |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 987 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 988 | } |
| 989 | |
| 990 | /* Transition SD and backplane clock readiness */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 991 | static int brcmf_sdbrcm_clkctl(dhd_bus_t *bus, uint target, bool pendok) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 992 | { |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 993 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 994 | uint oldstate = bus->clkstate; |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 995 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 996 | |
| 997 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 998 | |
| 999 | /* Early exit if we're already there */ |
| 1000 | if (bus->clkstate == target) { |
| 1001 | if (target == CLK_AVAIL) { |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 1002 | brcmf_sdbrcm_wd_timer(bus, brcmf_watchdog_ms); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1003 | bus->activity = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1004 | } |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 1005 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | switch (target) { |
| 1009 | case CLK_AVAIL: |
| 1010 | /* Make sure SD clock is available */ |
| 1011 | if (bus->clkstate == CLK_NONE) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1012 | brcmf_sdbrcm_sdclk(bus, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1013 | /* Now request HT Avail on the backplane */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1014 | brcmf_sdbrcm_htclk(bus, true, pendok); |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 1015 | brcmf_sdbrcm_wd_timer(bus, brcmf_watchdog_ms); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1016 | bus->activity = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1017 | break; |
| 1018 | |
| 1019 | case CLK_SDONLY: |
| 1020 | /* Remove HT request, or bring up SD clock */ |
| 1021 | if (bus->clkstate == CLK_NONE) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1022 | brcmf_sdbrcm_sdclk(bus, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1023 | else if (bus->clkstate == CLK_AVAIL) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1024 | brcmf_sdbrcm_htclk(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1025 | else |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1026 | DHD_ERROR(("brcmf_sdbrcm_clkctl: request for %d -> %d" |
| 1027 | "\n", bus->clkstate, target)); |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 1028 | brcmf_sdbrcm_wd_timer(bus, brcmf_watchdog_ms); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1029 | break; |
| 1030 | |
| 1031 | case CLK_NONE: |
| 1032 | /* Make sure to remove HT request */ |
| 1033 | if (bus->clkstate == CLK_AVAIL) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1034 | brcmf_sdbrcm_htclk(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1035 | /* Now remove the SD clock */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1036 | brcmf_sdbrcm_sdclk(bus, false); |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 1037 | brcmf_sdbrcm_wd_timer(bus, 0); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1038 | break; |
| 1039 | } |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1040 | #ifdef BCMDBG |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1041 | DHD_INFO(("brcmf_sdbrcm_clkctl: %d -> %d\n", oldstate, bus->clkstate)); |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1042 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1043 | |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 1044 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1045 | } |
| 1046 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1047 | int brcmf_sdbrcm_bussleep(dhd_bus_t *bus, bool sleep) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1048 | { |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 1049 | struct brcmf_sdio *sdh = bus->sdh; |
Franky Lin | 597600a | 2011-06-01 13:45:39 +0200 | [diff] [blame] | 1050 | struct sdpcmd_regs *regs = bus->regs; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1051 | uint retries = 0; |
| 1052 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1053 | DHD_INFO(("brcmf_sdbrcm_bussleep: request %s (currently %s)\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1054 | (sleep ? "SLEEP" : "WAKE"), |
| 1055 | (bus->sleeping ? "SLEEP" : "WAKE"))); |
| 1056 | |
| 1057 | /* Done if we're already in the requested state */ |
| 1058 | if (sleep == bus->sleeping) |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 1059 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1060 | |
| 1061 | /* Going to sleep: set the alarm and turn off the lights... */ |
| 1062 | if (sleep) { |
| 1063 | /* Don't sleep if something is pending */ |
| 1064 | if (bus->dpc_sched || bus->rxskip || pktq_len(&bus->txq)) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 1065 | return -EBUSY; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1066 | |
| 1067 | /* Disable SDIO interrupts (no longer interested) */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1068 | brcmf_sdcard_intr_disable(bus->sdh); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1069 | |
| 1070 | /* Make sure the controller has the bus up */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1071 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1072 | |
| 1073 | /* Tell device to start using OOB wakeup */ |
| 1074 | W_SDREG(SMB_USE_OOB, ®s->tosbmailbox, retries); |
| 1075 | if (retries > retry_limit) |
| 1076 | DHD_ERROR(("CANNOT SIGNAL CHIP, WILL NOT WAKE UP!!\n")); |
| 1077 | |
| 1078 | /* Turn off our contribution to the HT clock request */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1079 | brcmf_sdbrcm_clkctl(bus, CLK_SDONLY, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1080 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1081 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, |
| 1082 | SBSDIO_FUNC1_CHIPCLKCSR, |
| 1083 | SBSDIO_FORCE_HW_CLKREQ_OFF, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1084 | |
| 1085 | /* Isolate the bus */ |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 1086 | if (bus->ci->chip != BCM4329_CHIP_ID |
| 1087 | && bus->ci->chip != BCM4319_CHIP_ID) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1088 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, |
| 1089 | SBSDIO_DEVICE_CTL, |
| 1090 | SBSDIO_DEVCTL_PADS_ISO, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1091 | } |
| 1092 | |
| 1093 | /* Change state */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1094 | bus->sleeping = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1095 | |
| 1096 | } else { |
| 1097 | /* Waking up: bus power up is ok, set local state */ |
| 1098 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1099 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, |
| 1100 | SBSDIO_FUNC1_CHIPCLKCSR, 0, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1101 | |
| 1102 | /* Force pad isolation off if possible |
| 1103 | (in case power never toggled) */ |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 1104 | if ((bus->ci->buscoretype == PCMCIA_CORE_ID) |
| 1105 | && (bus->ci->buscorerev >= 10)) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1106 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, |
| 1107 | SBSDIO_DEVICE_CTL, 0, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1108 | |
| 1109 | /* Make sure the controller has the bus up */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1110 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1111 | |
| 1112 | /* Send misc interrupt to indicate OOB not needed */ |
| 1113 | W_SDREG(0, ®s->tosbmailboxdata, retries); |
| 1114 | if (retries <= retry_limit) |
| 1115 | W_SDREG(SMB_DEV_INT, ®s->tosbmailbox, retries); |
| 1116 | |
| 1117 | if (retries > retry_limit) |
| 1118 | DHD_ERROR(("CANNOT SIGNAL CHIP TO CLEAR OOB!!\n")); |
| 1119 | |
| 1120 | /* Make sure we have SD bus access */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1121 | brcmf_sdbrcm_clkctl(bus, CLK_SDONLY, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1122 | |
| 1123 | /* Change state */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1124 | bus->sleeping = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1125 | |
| 1126 | /* Enable interrupts again */ |
| 1127 | if (bus->intr && (bus->dhd->busstate == DHD_BUS_DATA)) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1128 | bus->intdis = false; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1129 | brcmf_sdcard_intr_enable(bus->sdh); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1130 | } |
| 1131 | } |
| 1132 | |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 1133 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1134 | } |
| 1135 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1136 | #define BUS_WAKE(bus) \ |
| 1137 | do { \ |
| 1138 | if ((bus)->sleeping) \ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1139 | brcmf_sdbrcm_bussleep((bus), false); \ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1140 | } while (0); |
| 1141 | |
| 1142 | /* Writes a HW/SW header into the packet and sends it. */ |
| 1143 | /* Assumes: (a) header space already there, (b) caller holds lock */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1144 | 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] | 1145 | bool free_pkt) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1146 | { |
| 1147 | int ret; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1148 | u8 *frame; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 1149 | u16 len, pad = 0; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1150 | u32 swheader; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1151 | uint retries = 0; |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 1152 | struct brcmf_sdio *sdh; |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 1153 | struct sk_buff *new; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1154 | int i; |
| 1155 | |
| 1156 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 1157 | |
| 1158 | sdh = bus->sdh; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1159 | |
| 1160 | if (bus->dhd->dongle_reset) { |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 1161 | ret = -EPERM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1162 | goto done; |
| 1163 | } |
| 1164 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1165 | frame = (u8 *) (pkt->data); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1166 | |
| 1167 | /* Add alignment padding, allocate new packet if needed */ |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 1168 | pad = ((unsigned long)frame % BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1169 | if (pad) { |
Arend van Spriel | 3be727c | 2010-11-23 22:20:30 +0100 | [diff] [blame] | 1170 | if (skb_headroom(pkt) < pad) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1171 | DHD_INFO(("%s: insufficient headroom %d for %d pad\n", |
Arend van Spriel | 3be727c | 2010-11-23 22:20:30 +0100 | [diff] [blame] | 1172 | __func__, skb_headroom(pkt), pad)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1173 | bus->dhd->tx_realloc++; |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 1174 | new = brcmu_pkt_buf_get_skb(pkt->len + BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1175 | if (!new) { |
| 1176 | DHD_ERROR(("%s: couldn't allocate new %d-byte " |
| 1177 | "packet\n", |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 1178 | __func__, pkt->len + BRCMF_SDALIGN)); |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 1179 | ret = -ENOMEM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1180 | goto done; |
| 1181 | } |
| 1182 | |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 1183 | PKTALIGN(new, pkt->len, BRCMF_SDALIGN); |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 1184 | memcpy(new->data, pkt->data, pkt->len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1185 | if (free_pkt) |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1186 | brcmu_pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1187 | /* free the pkt if canned one is not used */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1188 | free_pkt = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1189 | pkt = new; |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1190 | frame = (u8 *) (pkt->data); |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 1191 | ASSERT(((unsigned long)frame % BRCMF_SDALIGN) == 0); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1192 | pad = 0; |
| 1193 | } else { |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 1194 | skb_push(pkt, pad); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1195 | frame = (u8 *) (pkt->data); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1196 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1197 | ASSERT((pad + SDPCM_HDRLEN) <= (int)(pkt->len)); |
Brett Rudley | 9249ede | 2010-11-30 20:09:49 -0800 | [diff] [blame] | 1198 | memset(frame, 0, pad + SDPCM_HDRLEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1199 | } |
| 1200 | } |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 1201 | ASSERT(pad < BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1202 | |
| 1203 | /* 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] | 1204 | len = (u16) (pkt->len); |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 1205 | *(u16 *) frame = cpu_to_le16(len); |
| 1206 | *(((u16 *) frame) + 1) = cpu_to_le16(~len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1207 | |
| 1208 | /* Software tag: channel, sequence number, data offset */ |
| 1209 | swheader = |
| 1210 | ((chan << SDPCM_CHANNEL_SHIFT) & SDPCM_CHANNEL_MASK) | bus->tx_seq | |
| 1211 | (((pad + |
| 1212 | SDPCM_HDRLEN) << SDPCM_DOFFSET_SHIFT) & SDPCM_DOFFSET_MASK); |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 1213 | |
| 1214 | put_unaligned_le32(swheader, frame + SDPCM_FRAMETAG_LEN); |
| 1215 | put_unaligned_le32(0, frame + SDPCM_FRAMETAG_LEN + sizeof(swheader)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1216 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1217 | #ifdef BCMDBG |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1218 | tx_packets[pkt->priority]++; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1219 | if (DHD_BYTES_ON() && |
| 1220 | (((DHD_CTL_ON() && (chan == SDPCM_CONTROL_CHANNEL)) || |
| 1221 | (DHD_DATA_ON() && (chan != SDPCM_CONTROL_CHANNEL))))) { |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 1222 | printk(KERN_DEBUG "Tx Frame:\n"); |
| 1223 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, frame, len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1224 | } else if (DHD_HDRS_ON()) { |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 1225 | printk(KERN_DEBUG "TxHdr:\n"); |
| 1226 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 1227 | frame, min_t(u16, len, 16)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1228 | } |
| 1229 | #endif |
| 1230 | |
| 1231 | /* Raise len to next SDIO block to eliminate tail command */ |
| 1232 | if (bus->roundup && bus->blocksize && (len > bus->blocksize)) { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 1233 | u16 pad = bus->blocksize - (len % bus->blocksize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1234 | if ((pad <= bus->roundup) && (pad < bus->blocksize)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1235 | len += pad; |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 1236 | } else if (len % BRCMF_SDALIGN) { |
| 1237 | len += BRCMF_SDALIGN - (len % BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1238 | } |
| 1239 | |
| 1240 | /* Some controllers have trouble with odd bytes -- round to even */ |
| 1241 | if (forcealign && (len & (ALIGNMENT - 1))) { |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 1242 | len = roundup(len, ALIGNMENT); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1243 | } |
| 1244 | |
| 1245 | do { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1246 | ret = brcmf_sdbrcm_send_buf(bus, brcmf_sdcard_cur_sbwad(sdh), |
| 1247 | SDIO_FUNC_2, F2SYNC, frame, len, pkt, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1248 | bus->f2txdata++; |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 1249 | ASSERT(ret != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1250 | |
| 1251 | if (ret < 0) { |
| 1252 | /* On failure, abort the command |
| 1253 | and terminate the frame */ |
| 1254 | DHD_INFO(("%s: sdio error %d, abort command and " |
| 1255 | "terminate frame.\n", __func__, ret)); |
| 1256 | bus->tx_sderrs++; |
| 1257 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1258 | brcmf_sdcard_abort(sdh, SDIO_FUNC_2); |
| 1259 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1260 | SBSDIO_FUNC1_FRAMECTRL, SFC_WF_TERM, |
| 1261 | NULL); |
| 1262 | bus->f1regdata++; |
| 1263 | |
| 1264 | for (i = 0; i < 3; i++) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1265 | u8 hi, lo; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1266 | hi = brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1267 | SBSDIO_FUNC1_WFRAMEBCHI, |
| 1268 | NULL); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1269 | lo = brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1270 | SBSDIO_FUNC1_WFRAMEBCLO, |
| 1271 | NULL); |
| 1272 | bus->f1regdata += 2; |
| 1273 | if ((hi == 0) && (lo == 0)) |
| 1274 | break; |
| 1275 | } |
| 1276 | |
| 1277 | } |
| 1278 | if (ret == 0) |
| 1279 | bus->tx_seq = (bus->tx_seq + 1) % SDPCM_SEQUENCE_WRAP; |
| 1280 | |
| 1281 | } while ((ret < 0) && retrydata && retries++ < TXRETRIES); |
| 1282 | |
| 1283 | done: |
| 1284 | /* restore pkt buffer pointer before calling tx complete routine */ |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 1285 | skb_pull(pkt, SDPCM_HDRLEN + pad); |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 1286 | brcmf_os_sdunlock(bus->dhd); |
| 1287 | brcmf_txcomplete(bus->dhd, pkt, ret != 0); |
| 1288 | brcmf_os_sdlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1289 | |
| 1290 | if (free_pkt) |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1291 | brcmu_pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1292 | |
| 1293 | return ret; |
| 1294 | } |
| 1295 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1296 | 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] | 1297 | { |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 1298 | int ret = -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1299 | uint datalen, prec; |
| 1300 | |
| 1301 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 1302 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1303 | datalen = pkt->len; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1304 | |
| 1305 | #ifdef SDTEST |
| 1306 | /* Push the test header if doing loopback */ |
| 1307 | if (bus->ext_loop) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1308 | u8 *data; |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 1309 | skb_push(pkt, SDPCM_TEST_HDRLEN); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1310 | data = pkt->data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1311 | *data++ = SDPCM_TEST_ECHOREQ; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1312 | *data++ = (u8) bus->loopid++; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1313 | *data++ = (datalen >> 0); |
| 1314 | *data++ = (datalen >> 8); |
| 1315 | datalen += SDPCM_TEST_HDRLEN; |
| 1316 | } |
| 1317 | #endif /* SDTEST */ |
| 1318 | |
| 1319 | /* Add space for the header */ |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 1320 | skb_push(pkt, SDPCM_HDRLEN); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1321 | ASSERT(IS_ALIGNED((unsigned long)(pkt->data), 2)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1322 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1323 | prec = PRIO2PREC((pkt->priority & PRIOMASK)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1324 | |
| 1325 | /* Check for existing queue, current flow-control, |
| 1326 | pending event, or pending clock */ |
Arend van Spriel | 7af9d0c | 2011-06-29 16:47:19 -0700 | [diff] [blame] | 1327 | if (brcmf_deferred_tx || bus->fcstate || pktq_len(&bus->txq) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1328 | || bus->dpc_sched || (!DATAOK(bus)) |
| 1329 | || (bus->flowcontrol & NBITVAL(prec)) |
| 1330 | || (bus->clkstate != CLK_AVAIL)) { |
| 1331 | DHD_TRACE(("%s: deferring pktq len %d\n", __func__, |
| 1332 | pktq_len(&bus->txq))); |
| 1333 | bus->fcqueued++; |
| 1334 | |
| 1335 | /* Priority based enq */ |
Franky Lin | 0f1a87c | 2011-06-29 16:46:32 -0700 | [diff] [blame] | 1336 | spin_lock_bh(&bus->txqlock); |
Arend van Spriel | aba5e0a | 2011-06-29 16:47:03 -0700 | [diff] [blame] | 1337 | 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] | 1338 | skb_pull(pkt, SDPCM_HDRLEN); |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 1339 | brcmf_txcomplete(bus->dhd, pkt, false); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1340 | brcmu_pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1341 | DHD_ERROR(("%s: out of bus->txq !!!\n", __func__)); |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 1342 | ret = -ENOSR; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1343 | } else { |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 1344 | ret = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1345 | } |
Franky Lin | 0f1a87c | 2011-06-29 16:46:32 -0700 | [diff] [blame] | 1346 | spin_unlock_bh(&bus->txqlock); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1347 | |
Grant Grundler | 7c31607 | 2011-03-09 15:04:15 -0800 | [diff] [blame] | 1348 | if (pktq_len(&bus->txq) >= TXHI) |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 1349 | brcmf_txflowcontrol(bus->dhd, 0, ON); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1350 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1351 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1352 | if (pktq_plen(&bus->txq, prec) > qcount[prec]) |
| 1353 | qcount[prec] = pktq_plen(&bus->txq, prec); |
| 1354 | #endif |
| 1355 | /* Schedule DPC if needed to send queued packet(s) */ |
Arend van Spriel | 7af9d0c | 2011-06-29 16:47:19 -0700 | [diff] [blame] | 1356 | if (brcmf_deferred_tx && !bus->dpc_sched) { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1357 | bus->dpc_sched = true; |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 1358 | brcmf_sched_dpc(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1359 | } |
| 1360 | } else { |
| 1361 | /* Lock: we're about to use shared data/code (and SDIO) */ |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 1362 | brcmf_os_sdlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1363 | |
| 1364 | /* Otherwise, send it now */ |
| 1365 | BUS_WAKE(bus); |
| 1366 | /* Make sure back plane ht clk is on, no pending allowed */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1367 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1368 | |
| 1369 | #ifndef SDTEST |
| 1370 | DHD_TRACE(("%s: calling txpkt\n", __func__)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1371 | ret = brcmf_sdbrcm_txpkt(bus, pkt, SDPCM_DATA_CHANNEL, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1372 | #else |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1373 | ret = brcmf_sdbrcm_txpkt(bus, pkt, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1374 | (bus->ext_loop ? SDPCM_TEST_CHANNEL : |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1375 | SDPCM_DATA_CHANNEL), true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1376 | #endif |
| 1377 | if (ret) |
| 1378 | bus->dhd->tx_errors++; |
| 1379 | else |
| 1380 | bus->dhd->dstats.tx_bytes += datalen; |
| 1381 | |
| 1382 | if ((bus->idletime == DHD_IDLE_IMMEDIATE) && !bus->dpc_sched) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1383 | bus->activity = false; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1384 | brcmf_sdbrcm_clkctl(bus, CLK_NONE, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1385 | } |
| 1386 | |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 1387 | brcmf_os_sdunlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | return ret; |
| 1391 | } |
| 1392 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1393 | static uint brcmf_sdbrcm_sendfromq(dhd_bus_t *bus, uint maxframes) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1394 | { |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 1395 | struct sk_buff *pkt; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1396 | u32 intstatus = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1397 | uint retries = 0; |
| 1398 | int ret = 0, prec_out; |
| 1399 | uint cnt = 0; |
| 1400 | uint datalen; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1401 | u8 tx_prec_map; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1402 | |
| 1403 | dhd_pub_t *dhd = bus->dhd; |
Franky Lin | 597600a | 2011-06-01 13:45:39 +0200 | [diff] [blame] | 1404 | struct sdpcmd_regs *regs = bus->regs; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1405 | |
| 1406 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 1407 | |
| 1408 | tx_prec_map = ~bus->flowcontrol; |
| 1409 | |
| 1410 | /* Send frames until the limit or some other event */ |
| 1411 | for (cnt = 0; (cnt < maxframes) && DATAOK(bus); cnt++) { |
Franky Lin | 0f1a87c | 2011-06-29 16:46:32 -0700 | [diff] [blame] | 1412 | spin_lock_bh(&bus->txqlock); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1413 | pkt = brcmu_pktq_mdeq(&bus->txq, tx_prec_map, &prec_out); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1414 | if (pkt == NULL) { |
Franky Lin | 0f1a87c | 2011-06-29 16:46:32 -0700 | [diff] [blame] | 1415 | spin_unlock_bh(&bus->txqlock); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1416 | break; |
| 1417 | } |
Franky Lin | 0f1a87c | 2011-06-29 16:46:32 -0700 | [diff] [blame] | 1418 | spin_unlock_bh(&bus->txqlock); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1419 | datalen = pkt->len - SDPCM_HDRLEN; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1420 | |
| 1421 | #ifndef SDTEST |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1422 | ret = brcmf_sdbrcm_txpkt(bus, pkt, SDPCM_DATA_CHANNEL, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1423 | #else |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1424 | ret = brcmf_sdbrcm_txpkt(bus, pkt, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1425 | (bus->ext_loop ? SDPCM_TEST_CHANNEL : |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1426 | SDPCM_DATA_CHANNEL), true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1427 | #endif |
| 1428 | if (ret) |
| 1429 | bus->dhd->tx_errors++; |
| 1430 | else |
| 1431 | bus->dhd->dstats.tx_bytes += datalen; |
| 1432 | |
| 1433 | /* In poll mode, need to check for other events */ |
| 1434 | if (!bus->intr && cnt) { |
| 1435 | /* Check device status, signal pending interrupt */ |
| 1436 | R_SDREG(intstatus, ®s->intstatus, retries); |
| 1437 | bus->f2txdata++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1438 | if (brcmf_sdcard_regfail(bus->sdh)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1439 | break; |
| 1440 | if (intstatus & bus->hostintmask) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1441 | bus->ipend = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1442 | } |
| 1443 | } |
| 1444 | |
| 1445 | /* Deflow-control stack if needed */ |
Grant Grundler | 7c31607 | 2011-03-09 15:04:15 -0800 | [diff] [blame] | 1446 | if (dhd->up && (dhd->busstate == DHD_BUS_DATA) && |
Grant Grundler | 26a71a4 | 2011-03-09 10:41:25 -0800 | [diff] [blame] | 1447 | dhd->txoff && (pktq_len(&bus->txq) < TXLOW)) |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 1448 | brcmf_txflowcontrol(dhd, 0, OFF); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1449 | |
| 1450 | return cnt; |
| 1451 | } |
| 1452 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1453 | int |
| 1454 | 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] | 1455 | { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1456 | u8 *frame; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 1457 | u16 len; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1458 | u32 swheader; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1459 | uint retries = 0; |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 1460 | struct brcmf_sdio *sdh = bus->sdh; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1461 | u8 doff = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1462 | int ret = -1; |
| 1463 | int i; |
| 1464 | |
| 1465 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 1466 | |
| 1467 | if (bus->dhd->dongle_reset) |
| 1468 | return -EIO; |
| 1469 | |
| 1470 | /* Back the pointer to make a room for bus header */ |
| 1471 | frame = msg - SDPCM_HDRLEN; |
| 1472 | len = (msglen += SDPCM_HDRLEN); |
| 1473 | |
| 1474 | /* Add alignment padding (optional for ctl frames) */ |
| 1475 | if (dhd_alignctl) { |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 1476 | doff = ((unsigned long)frame % BRCMF_SDALIGN); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 1477 | if (doff) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1478 | frame -= doff; |
| 1479 | len += doff; |
| 1480 | msglen += doff; |
Brett Rudley | 9249ede | 2010-11-30 20:09:49 -0800 | [diff] [blame] | 1481 | memset(frame, 0, doff + SDPCM_HDRLEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1482 | } |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 1483 | ASSERT(doff < BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1484 | } |
| 1485 | doff += SDPCM_HDRLEN; |
| 1486 | |
| 1487 | /* Round send length to next SDIO block */ |
| 1488 | if (bus->roundup && bus->blocksize && (len > bus->blocksize)) { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 1489 | u16 pad = bus->blocksize - (len % bus->blocksize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1490 | if ((pad <= bus->roundup) && (pad < bus->blocksize)) |
| 1491 | len += pad; |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 1492 | } else if (len % BRCMF_SDALIGN) { |
| 1493 | len += BRCMF_SDALIGN - (len % BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1494 | } |
| 1495 | |
| 1496 | /* Satisfy length-alignment requirements */ |
| 1497 | if (forcealign && (len & (ALIGNMENT - 1))) |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 1498 | len = roundup(len, ALIGNMENT); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1499 | |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 1500 | ASSERT(IS_ALIGNED((unsigned long)frame, 2)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1501 | |
| 1502 | /* Need to lock here to protect txseq and SDIO tx calls */ |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 1503 | brcmf_os_sdlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1504 | |
| 1505 | BUS_WAKE(bus); |
| 1506 | |
| 1507 | /* Make sure backplane clock is on */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1508 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1509 | |
| 1510 | /* 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] | 1511 | *(u16 *) frame = cpu_to_le16((u16) msglen); |
| 1512 | *(((u16 *) frame) + 1) = cpu_to_le16(~msglen); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1513 | |
| 1514 | /* Software tag: channel, sequence number, data offset */ |
| 1515 | swheader = |
| 1516 | ((SDPCM_CONTROL_CHANNEL << SDPCM_CHANNEL_SHIFT) & |
| 1517 | SDPCM_CHANNEL_MASK) |
| 1518 | | bus->tx_seq | ((doff << SDPCM_DOFFSET_SHIFT) & |
| 1519 | SDPCM_DOFFSET_MASK); |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 1520 | put_unaligned_le32(swheader, frame + SDPCM_FRAMETAG_LEN); |
| 1521 | put_unaligned_le32(0, frame + SDPCM_FRAMETAG_LEN + sizeof(swheader)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1522 | |
| 1523 | if (!DATAOK(bus)) { |
| 1524 | DHD_INFO(("%s: No bus credit bus->tx_max %d, bus->tx_seq %d\n", |
| 1525 | __func__, bus->tx_max, bus->tx_seq)); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1526 | bus->ctrl_frame_stat = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1527 | /* Send from dpc */ |
| 1528 | bus->ctrl_frame_buf = frame; |
| 1529 | bus->ctrl_frame_len = len; |
| 1530 | |
Franky Lin | b7adfa7 | 2011-06-29 16:47:42 -0700 | [diff] [blame] | 1531 | brcmf_sdbrcm_wait_for_event(bus->dhd, &bus->ctrl_frame_stat); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1532 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1533 | if (bus->ctrl_frame_stat == false) { |
| 1534 | DHD_INFO(("%s: ctrl_frame_stat == false\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1535 | ret = 0; |
| 1536 | } else { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1537 | DHD_INFO(("%s: ctrl_frame_stat == true\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1538 | ret = -1; |
| 1539 | } |
| 1540 | } |
| 1541 | |
| 1542 | if (ret == -1) { |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1543 | #ifdef BCMDBG |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 1544 | if (DHD_BYTES_ON() && DHD_CTL_ON()) { |
| 1545 | printk(KERN_DEBUG "Tx Frame:\n"); |
| 1546 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 1547 | frame, len); |
| 1548 | } else if (DHD_HDRS_ON()) { |
| 1549 | printk(KERN_DEBUG "TxHdr:\n"); |
| 1550 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 1551 | frame, min_t(u16, len, 16)); |
| 1552 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1553 | #endif |
| 1554 | |
| 1555 | do { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1556 | bus->ctrl_frame_stat = false; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1557 | ret = brcmf_sdbrcm_send_buf(bus, |
| 1558 | brcmf_sdcard_cur_sbwad(sdh), SDIO_FUNC_2, |
| 1559 | F2SYNC, frame, len, NULL, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1560 | |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 1561 | ASSERT(ret != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1562 | |
| 1563 | if (ret < 0) { |
| 1564 | /* On failure, abort the command and |
| 1565 | terminate the frame */ |
| 1566 | DHD_INFO(("%s: sdio error %d, abort command and terminate frame.\n", |
| 1567 | __func__, ret)); |
| 1568 | bus->tx_sderrs++; |
| 1569 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1570 | brcmf_sdcard_abort(sdh, SDIO_FUNC_2); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1571 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1572 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1573 | SBSDIO_FUNC1_FRAMECTRL, |
| 1574 | SFC_WF_TERM, NULL); |
| 1575 | bus->f1regdata++; |
| 1576 | |
| 1577 | for (i = 0; i < 3; i++) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1578 | u8 hi, lo; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1579 | hi = brcmf_sdcard_cfg_read(sdh, |
| 1580 | SDIO_FUNC_1, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1581 | SBSDIO_FUNC1_WFRAMEBCHI, |
| 1582 | NULL); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1583 | lo = brcmf_sdcard_cfg_read(sdh, |
| 1584 | SDIO_FUNC_1, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1585 | SBSDIO_FUNC1_WFRAMEBCLO, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1586 | NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1587 | bus->f1regdata += 2; |
| 1588 | if ((hi == 0) && (lo == 0)) |
| 1589 | break; |
| 1590 | } |
| 1591 | |
| 1592 | } |
| 1593 | if (ret == 0) { |
| 1594 | bus->tx_seq = |
| 1595 | (bus->tx_seq + 1) % SDPCM_SEQUENCE_WRAP; |
| 1596 | } |
| 1597 | } while ((ret < 0) && retries++ < TXRETRIES); |
| 1598 | } |
| 1599 | |
| 1600 | if ((bus->idletime == DHD_IDLE_IMMEDIATE) && !bus->dpc_sched) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1601 | bus->activity = false; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1602 | brcmf_sdbrcm_clkctl(bus, CLK_NONE, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1603 | } |
| 1604 | |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 1605 | brcmf_os_sdunlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1606 | |
| 1607 | if (ret) |
| 1608 | bus->dhd->tx_ctlerrs++; |
| 1609 | else |
| 1610 | bus->dhd->tx_ctlpkts++; |
| 1611 | |
| 1612 | return ret ? -EIO : 0; |
| 1613 | } |
| 1614 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1615 | 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] | 1616 | { |
| 1617 | int timeleft; |
| 1618 | uint rxlen = 0; |
| 1619 | bool pending; |
| 1620 | |
| 1621 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 1622 | |
| 1623 | if (bus->dhd->dongle_reset) |
| 1624 | return -EIO; |
| 1625 | |
| 1626 | /* Wait until control frame is available */ |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 1627 | timeleft = brcmf_os_ioctl_resp_wait(bus->dhd, &bus->rxlen, &pending); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1628 | |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 1629 | brcmf_os_sdlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1630 | rxlen = bus->rxlen; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 1631 | memcpy(msg, bus->rxctl, min(msglen, rxlen)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1632 | bus->rxlen = 0; |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 1633 | brcmf_os_sdunlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1634 | |
| 1635 | if (rxlen) { |
| 1636 | DHD_CTL(("%s: resumed on rxctl frame, got %d expected %d\n", |
| 1637 | __func__, rxlen, msglen)); |
| 1638 | } else if (timeleft == 0) { |
| 1639 | DHD_ERROR(("%s: resumed on timeout\n", __func__)); |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1640 | #ifdef BCMDBG |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 1641 | brcmf_os_sdlock(bus->dhd); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1642 | brcmf_sdbrcm_checkdied(bus, NULL, 0); |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 1643 | brcmf_os_sdunlock(bus->dhd); |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1644 | #endif /* BCMDBG */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1645 | } else if (pending == true) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1646 | DHD_CTL(("%s: cancelled\n", __func__)); |
| 1647 | return -ERESTARTSYS; |
| 1648 | } else { |
| 1649 | DHD_CTL(("%s: resumed for unknown reason?\n", __func__)); |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1650 | #ifdef BCMDBG |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 1651 | brcmf_os_sdlock(bus->dhd); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1652 | brcmf_sdbrcm_checkdied(bus, NULL, 0); |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 1653 | brcmf_os_sdunlock(bus->dhd); |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1654 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1655 | } |
| 1656 | |
| 1657 | if (rxlen) |
| 1658 | bus->dhd->rx_ctlpkts++; |
| 1659 | else |
| 1660 | bus->dhd->rx_ctlerrs++; |
| 1661 | |
Jason Cooper | e9887c9 | 2010-10-06 10:08:02 -0400 | [diff] [blame] | 1662 | return rxlen ? (int)rxlen : -ETIMEDOUT; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1663 | } |
| 1664 | |
| 1665 | /* IOVar table */ |
| 1666 | enum { |
| 1667 | IOV_INTR = 1, |
| 1668 | IOV_POLLRATE, |
| 1669 | IOV_SDREG, |
| 1670 | IOV_SBREG, |
| 1671 | IOV_SDCIS, |
| 1672 | IOV_MEMBYTES, |
| 1673 | IOV_MEMSIZE, |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1674 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1675 | IOV_CHECKDIED, |
Franky Lin | 913af5f | 2011-06-29 16:47:44 -0700 | [diff] [blame^] | 1676 | IOV_CONS, |
| 1677 | IOV_DCONSOLE_POLL, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1678 | #endif |
| 1679 | IOV_DOWNLOAD, |
| 1680 | IOV_FORCEEVEN, |
| 1681 | IOV_SDIOD_DRIVE, |
| 1682 | IOV_READAHEAD, |
| 1683 | IOV_SDRXCHAIN, |
| 1684 | IOV_ALIGNCTL, |
| 1685 | IOV_SDALIGN, |
| 1686 | IOV_DEVRESET, |
| 1687 | IOV_CPU, |
| 1688 | #ifdef SDTEST |
| 1689 | IOV_PKTGEN, |
| 1690 | IOV_EXTLOOP, |
| 1691 | #endif /* SDTEST */ |
| 1692 | IOV_SPROM, |
| 1693 | IOV_TXBOUND, |
| 1694 | IOV_RXBOUND, |
| 1695 | IOV_TXMINMAX, |
| 1696 | IOV_IDLETIME, |
| 1697 | IOV_IDLECLOCK, |
| 1698 | IOV_SD1IDLE, |
| 1699 | IOV_SLEEP, |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 1700 | IOV_WDTICK, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1701 | IOV_VARS |
| 1702 | }; |
| 1703 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1704 | const struct brcmu_iovar dhdsdio_iovars[] = { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1705 | {"intr", IOV_INTR, 0, IOVT_BOOL, 0}, |
| 1706 | {"sleep", IOV_SLEEP, 0, IOVT_BOOL, 0}, |
| 1707 | {"pollrate", IOV_POLLRATE, 0, IOVT_UINT32, 0}, |
| 1708 | {"idletime", IOV_IDLETIME, 0, IOVT_INT32, 0}, |
| 1709 | {"idleclock", IOV_IDLECLOCK, 0, IOVT_INT32, 0}, |
| 1710 | {"sd1idle", IOV_SD1IDLE, 0, IOVT_BOOL, 0}, |
| 1711 | {"membytes", IOV_MEMBYTES, 0, IOVT_BUFFER, 2 * sizeof(int)}, |
| 1712 | {"memsize", IOV_MEMSIZE, 0, IOVT_UINT32, 0}, |
| 1713 | {"download", IOV_DOWNLOAD, 0, IOVT_BOOL, 0}, |
| 1714 | {"vars", IOV_VARS, 0, IOVT_BUFFER, 0}, |
| 1715 | {"sdiod_drive", IOV_SDIOD_DRIVE, 0, IOVT_UINT32, 0}, |
| 1716 | {"readahead", IOV_READAHEAD, 0, IOVT_BOOL, 0}, |
| 1717 | {"sdrxchain", IOV_SDRXCHAIN, 0, IOVT_BOOL, 0}, |
| 1718 | {"alignctl", IOV_ALIGNCTL, 0, IOVT_BOOL, 0}, |
| 1719 | {"sdalign", IOV_SDALIGN, 0, IOVT_BOOL, 0}, |
| 1720 | {"devreset", IOV_DEVRESET, 0, IOVT_BOOL, 0}, |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 1721 | {"wdtick", IOV_WDTICK, 0, IOVT_UINT32, 0}, |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1722 | #ifdef BCMDBG |
Franky Lin | 913af5f | 2011-06-29 16:47:44 -0700 | [diff] [blame^] | 1723 | {"cons", IOV_CONS, 0, IOVT_BUFFER, 0} |
| 1724 | , |
| 1725 | {"dconpoll", IOV_DCONSOLE_POLL, 0, IOVT_UINT32, 0} |
| 1726 | , |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 1727 | {"sdreg", IOV_SDREG, 0, IOVT_BUFFER, sizeof(struct brcmf_sdreg)} |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1728 | , |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 1729 | {"sbreg", IOV_SBREG, 0, IOVT_BUFFER, sizeof(struct brcmf_sdreg)} |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1730 | , |
| 1731 | {"sd_cis", IOV_SDCIS, 0, IOVT_BUFFER, DHD_IOCTL_MAXLEN} |
| 1732 | , |
| 1733 | {"forcealign", IOV_FORCEEVEN, 0, IOVT_BOOL, 0} |
| 1734 | , |
| 1735 | {"txbound", IOV_TXBOUND, 0, IOVT_UINT32, 0} |
| 1736 | , |
| 1737 | {"rxbound", IOV_RXBOUND, 0, IOVT_UINT32, 0} |
| 1738 | , |
| 1739 | {"txminmax", IOV_TXMINMAX, 0, IOVT_UINT32, 0} |
| 1740 | , |
| 1741 | {"cpu", IOV_CPU, 0, IOVT_BOOL, 0} |
| 1742 | , |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1743 | {"checkdied", IOV_CHECKDIED, 0, IOVT_BUFFER, 0} |
| 1744 | , |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1745 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1746 | #ifdef SDTEST |
| 1747 | {"extloop", IOV_EXTLOOP, 0, IOVT_BOOL, 0} |
| 1748 | , |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 1749 | {"pktgen", IOV_PKTGEN, 0, IOVT_BUFFER, sizeof(brcmf_pktgen_t)} |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1750 | , |
| 1751 | #endif /* SDTEST */ |
| 1752 | |
| 1753 | {NULL, 0, 0, 0, 0} |
| 1754 | }; |
| 1755 | |
| 1756 | static void |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1757 | 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] | 1758 | { |
| 1759 | uint q1, q2; |
| 1760 | |
| 1761 | if (!div) { |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1762 | brcmu_bprintf(strbuf, "%s N/A", desc); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1763 | } else { |
| 1764 | q1 = num / div; |
| 1765 | q2 = (100 * (num - (q1 * div))) / div; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1766 | brcmu_bprintf(strbuf, "%s %d.%02d", desc, q1, q2); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1767 | } |
| 1768 | } |
| 1769 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1770 | void brcmf_sdbrcm_bus_dump(dhd_pub_t *dhdp, struct brcmu_strbuf *strbuf) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1771 | { |
| 1772 | dhd_bus_t *bus = dhdp->bus; |
| 1773 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1774 | brcmu_bprintf(strbuf, "Bus SDIO structure:\n"); |
| 1775 | brcmu_bprintf(strbuf, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1776 | "hostintmask 0x%08x intstatus 0x%08x sdpcm_ver %d\n", |
| 1777 | bus->hostintmask, bus->intstatus, bus->sdpcm_ver); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1778 | brcmu_bprintf(strbuf, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1779 | "fcstate %d qlen %d tx_seq %d, max %d, rxskip %d rxlen %d rx_seq %d\n", |
| 1780 | bus->fcstate, pktq_len(&bus->txq), bus->tx_seq, bus->tx_max, |
| 1781 | bus->rxskip, bus->rxlen, bus->rx_seq); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1782 | brcmu_bprintf(strbuf, "intr %d intrcount %d lastintrs %d spurious %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1783 | bus->intr, bus->intrcount, bus->lastintrs, bus->spurious); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1784 | brcmu_bprintf(strbuf, "pollrate %d pollcnt %d regfails %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1785 | bus->pollrate, bus->pollcnt, bus->regfails); |
| 1786 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1787 | brcmu_bprintf(strbuf, "\nAdditional counters:\n"); |
| 1788 | brcmu_bprintf(strbuf, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1789 | "tx_sderrs %d fcqueued %d rxrtx %d rx_toolong %d rxc_errors %d\n", |
| 1790 | bus->tx_sderrs, bus->fcqueued, bus->rxrtx, bus->rx_toolong, |
| 1791 | bus->rxc_errors); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1792 | brcmu_bprintf(strbuf, "rx_hdrfail %d badhdr %d badseq %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1793 | bus->rx_hdrfail, bus->rx_badhdr, bus->rx_badseq); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1794 | brcmu_bprintf(strbuf, "fc_rcvd %d, fc_xoff %d, fc_xon %d\n", |
| 1795 | bus->fc_rcvd, bus->fc_xoff, bus->fc_xon); |
| 1796 | brcmu_bprintf(strbuf, "rxglomfail %d, rxglomframes %d, rxglompkts %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1797 | bus->rxglomfail, bus->rxglomframes, bus->rxglompkts); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1798 | brcmu_bprintf(strbuf, "f2rx (hdrs/data) %d (%d/%d), f2tx %d f1regs" |
| 1799 | " %d\n", |
| 1800 | (bus->f2rxhdrs + bus->f2rxdata), bus->f2rxhdrs, |
| 1801 | bus->f2rxdata, bus->f2txdata, bus->f1regdata); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1802 | { |
| 1803 | dhd_dump_pct(strbuf, "\nRx: pkts/f2rd", bus->dhd->rx_packets, |
| 1804 | (bus->f2rxhdrs + bus->f2rxdata)); |
| 1805 | dhd_dump_pct(strbuf, ", pkts/f1sd", bus->dhd->rx_packets, |
| 1806 | bus->f1regdata); |
| 1807 | dhd_dump_pct(strbuf, ", pkts/sd", bus->dhd->rx_packets, |
| 1808 | (bus->f2rxhdrs + bus->f2rxdata + bus->f1regdata)); |
| 1809 | dhd_dump_pct(strbuf, ", pkts/int", bus->dhd->rx_packets, |
| 1810 | bus->intrcount); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1811 | brcmu_bprintf(strbuf, "\n"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1812 | |
| 1813 | dhd_dump_pct(strbuf, "Rx: glom pct", (100 * bus->rxglompkts), |
| 1814 | bus->dhd->rx_packets); |
| 1815 | dhd_dump_pct(strbuf, ", pkts/glom", bus->rxglompkts, |
| 1816 | bus->rxglomframes); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1817 | brcmu_bprintf(strbuf, "\n"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1818 | |
| 1819 | dhd_dump_pct(strbuf, "Tx: pkts/f2wr", bus->dhd->tx_packets, |
| 1820 | bus->f2txdata); |
| 1821 | dhd_dump_pct(strbuf, ", pkts/f1sd", bus->dhd->tx_packets, |
| 1822 | bus->f1regdata); |
| 1823 | dhd_dump_pct(strbuf, ", pkts/sd", bus->dhd->tx_packets, |
| 1824 | (bus->f2txdata + bus->f1regdata)); |
| 1825 | dhd_dump_pct(strbuf, ", pkts/int", bus->dhd->tx_packets, |
| 1826 | bus->intrcount); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1827 | brcmu_bprintf(strbuf, "\n"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1828 | |
| 1829 | dhd_dump_pct(strbuf, "Total: pkts/f2rw", |
| 1830 | (bus->dhd->tx_packets + bus->dhd->rx_packets), |
| 1831 | (bus->f2txdata + bus->f2rxhdrs + bus->f2rxdata)); |
| 1832 | dhd_dump_pct(strbuf, ", pkts/f1sd", |
| 1833 | (bus->dhd->tx_packets + bus->dhd->rx_packets), |
| 1834 | bus->f1regdata); |
| 1835 | dhd_dump_pct(strbuf, ", pkts/sd", |
| 1836 | (bus->dhd->tx_packets + bus->dhd->rx_packets), |
| 1837 | (bus->f2txdata + bus->f2rxhdrs + bus->f2rxdata + |
| 1838 | bus->f1regdata)); |
| 1839 | dhd_dump_pct(strbuf, ", pkts/int", |
| 1840 | (bus->dhd->tx_packets + bus->dhd->rx_packets), |
| 1841 | bus->intrcount); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1842 | brcmu_bprintf(strbuf, "\n\n"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1843 | } |
| 1844 | |
| 1845 | #ifdef SDTEST |
| 1846 | if (bus->pktgen_count) { |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1847 | brcmu_bprintf(strbuf, "pktgen config and count:\n"); |
| 1848 | brcmu_bprintf(strbuf, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1849 | "freq %d count %d print %d total %d min %d len %d\n", |
| 1850 | bus->pktgen_freq, bus->pktgen_count, |
| 1851 | bus->pktgen_print, bus->pktgen_total, |
| 1852 | bus->pktgen_minlen, bus->pktgen_maxlen); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1853 | brcmu_bprintf(strbuf, "send attempts %d rcvd %d fail %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1854 | bus->pktgen_sent, bus->pktgen_rcvd, |
| 1855 | bus->pktgen_fail); |
| 1856 | } |
| 1857 | #endif /* SDTEST */ |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1858 | #ifdef BCMDBG |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1859 | brcmu_bprintf(strbuf, "dpc_sched %d host interrupt%spending\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1860 | bus->dpc_sched, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1861 | (brcmf_sdcard_intr_pending(bus->sdh) ? " " : " not ")); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1862 | brcmu_bprintf(strbuf, "blocksize %d roundup %d\n", bus->blocksize, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1863 | bus->roundup); |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1864 | #endif /* BCMDBG */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1865 | brcmu_bprintf(strbuf, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1866 | "clkstate %d activity %d idletime %d idlecount %d sleeping %d\n", |
| 1867 | bus->clkstate, bus->activity, bus->idletime, bus->idlecount, |
| 1868 | bus->sleeping); |
| 1869 | } |
| 1870 | |
| 1871 | void dhd_bus_clearcounts(dhd_pub_t *dhdp) |
| 1872 | { |
| 1873 | dhd_bus_t *bus = (dhd_bus_t *) dhdp->bus; |
| 1874 | |
| 1875 | bus->intrcount = bus->lastintrs = bus->spurious = bus->regfails = 0; |
| 1876 | bus->rxrtx = bus->rx_toolong = bus->rxc_errors = 0; |
| 1877 | bus->rx_hdrfail = bus->rx_badhdr = bus->rx_badseq = 0; |
| 1878 | bus->tx_sderrs = bus->fc_rcvd = bus->fc_xoff = bus->fc_xon = 0; |
| 1879 | bus->rxglomfail = bus->rxglomframes = bus->rxglompkts = 0; |
| 1880 | bus->f2rxhdrs = bus->f2rxdata = bus->f2txdata = bus->f1regdata = 0; |
| 1881 | } |
| 1882 | |
| 1883 | #ifdef SDTEST |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1884 | static int brcmf_sdbrcm_pktgen_get(dhd_bus_t *bus, u8 *arg) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1885 | { |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 1886 | brcmf_pktgen_t pktgen; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1887 | |
| 1888 | pktgen.version = DHD_PKTGEN_VERSION; |
| 1889 | pktgen.freq = bus->pktgen_freq; |
| 1890 | pktgen.count = bus->pktgen_count; |
| 1891 | pktgen.print = bus->pktgen_print; |
| 1892 | pktgen.total = bus->pktgen_total; |
| 1893 | pktgen.minlen = bus->pktgen_minlen; |
| 1894 | pktgen.maxlen = bus->pktgen_maxlen; |
| 1895 | pktgen.numsent = bus->pktgen_sent; |
| 1896 | pktgen.numrcvd = bus->pktgen_rcvd; |
| 1897 | pktgen.numfail = bus->pktgen_fail; |
| 1898 | pktgen.mode = bus->pktgen_mode; |
| 1899 | pktgen.stop = bus->pktgen_stop; |
| 1900 | |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 1901 | memcpy(arg, &pktgen, sizeof(pktgen)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1902 | |
| 1903 | return 0; |
| 1904 | } |
| 1905 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1906 | static int brcmf_sdbrcm_pktgen_set(dhd_bus_t *bus, u8 *arg) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1907 | { |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 1908 | brcmf_pktgen_t pktgen; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1909 | uint oldcnt, oldmode; |
| 1910 | |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 1911 | memcpy(&pktgen, arg, sizeof(pktgen)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1912 | if (pktgen.version != DHD_PKTGEN_VERSION) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 1913 | return -EINVAL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1914 | |
| 1915 | oldcnt = bus->pktgen_count; |
| 1916 | oldmode = bus->pktgen_mode; |
| 1917 | |
| 1918 | bus->pktgen_freq = pktgen.freq; |
| 1919 | bus->pktgen_count = pktgen.count; |
| 1920 | bus->pktgen_print = pktgen.print; |
| 1921 | bus->pktgen_total = pktgen.total; |
| 1922 | bus->pktgen_minlen = pktgen.minlen; |
| 1923 | bus->pktgen_maxlen = pktgen.maxlen; |
| 1924 | bus->pktgen_mode = pktgen.mode; |
| 1925 | bus->pktgen_stop = pktgen.stop; |
| 1926 | |
| 1927 | bus->pktgen_tick = bus->pktgen_ptick = 0; |
Greg Kroah-Hartman | 3ea2f4d | 2010-10-08 11:39:43 -0700 | [diff] [blame] | 1928 | bus->pktgen_len = max(bus->pktgen_len, bus->pktgen_minlen); |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 1929 | bus->pktgen_len = min(bus->pktgen_len, bus->pktgen_maxlen); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1930 | |
| 1931 | /* Clear counts for a new pktgen (mode change, or was stopped) */ |
| 1932 | if (bus->pktgen_count && (!oldcnt || oldmode != bus->pktgen_mode)) |
| 1933 | bus->pktgen_sent = bus->pktgen_rcvd = bus->pktgen_fail = 0; |
| 1934 | |
| 1935 | return 0; |
| 1936 | } |
| 1937 | #endif /* SDTEST */ |
| 1938 | |
| 1939 | static int |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1940 | 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] | 1941 | uint size) |
| 1942 | { |
| 1943 | int bcmerror = 0; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1944 | u32 sdaddr; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1945 | uint dsize; |
| 1946 | |
| 1947 | /* Determine initial transfer parameters */ |
| 1948 | sdaddr = address & SBSDIO_SB_OFT_ADDR_MASK; |
| 1949 | if ((sdaddr + size) & SBSDIO_SBWINDOW_MASK) |
| 1950 | dsize = (SBSDIO_SB_OFT_ADDR_LIMIT - sdaddr); |
| 1951 | else |
| 1952 | dsize = size; |
| 1953 | |
| 1954 | /* Set the backplane window to include the start address */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1955 | bcmerror = brcmf_sdbrcm_set_siaddr_window(bus, address); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1956 | if (bcmerror) { |
| 1957 | DHD_ERROR(("%s: window change failed\n", __func__)); |
| 1958 | goto xfer_done; |
| 1959 | } |
| 1960 | |
| 1961 | /* Do the transfer(s) */ |
| 1962 | while (size) { |
| 1963 | DHD_INFO(("%s: %s %d bytes at offset 0x%08x in window 0x%08x\n", |
| 1964 | __func__, (write ? "write" : "read"), dsize, |
| 1965 | sdaddr, (address & SBSDIO_SBWINDOW_MASK))); |
| 1966 | bcmerror = |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1967 | brcmf_sdcard_rwdata(bus->sdh, write, sdaddr, data, dsize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1968 | if (bcmerror) { |
| 1969 | DHD_ERROR(("%s: membytes transfer failed\n", __func__)); |
| 1970 | break; |
| 1971 | } |
| 1972 | |
| 1973 | /* Adjust for next transfer (if any) */ |
| 1974 | size -= dsize; |
| 1975 | if (size) { |
| 1976 | data += dsize; |
| 1977 | address += dsize; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1978 | bcmerror = brcmf_sdbrcm_set_siaddr_window(bus, address); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1979 | if (bcmerror) { |
| 1980 | DHD_ERROR(("%s: window change failed\n", |
| 1981 | __func__)); |
| 1982 | break; |
| 1983 | } |
| 1984 | sdaddr = 0; |
Greg Kroah-Hartman | b61640d | 2010-10-08 12:37:39 -0700 | [diff] [blame] | 1985 | dsize = min_t(uint, SBSDIO_SB_OFT_ADDR_LIMIT, size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1986 | } |
| 1987 | } |
| 1988 | |
| 1989 | xfer_done: |
| 1990 | /* Return the window to backplane enumeration space for core access */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1991 | if (brcmf_sdbrcm_set_siaddr_window(bus, |
| 1992 | brcmf_sdcard_cur_sbwad(bus->sdh))) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1993 | DHD_ERROR(("%s: FAILED to set window back to 0x%x\n", |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1994 | __func__, brcmf_sdcard_cur_sbwad(bus->sdh))); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1995 | } |
| 1996 | |
| 1997 | return bcmerror; |
| 1998 | } |
| 1999 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 2000 | #ifdef BCMDBG |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2001 | 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] | 2002 | { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2003 | u32 addr; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2004 | int rv; |
| 2005 | |
| 2006 | /* Read last word in memory to determine address of |
| 2007 | sdpcm_shared structure */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2008 | rv = brcmf_sdbrcm_membytes(bus, false, bus->ramsize - 4, (u8 *)&addr, |
| 2009 | 4); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2010 | if (rv < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2011 | return rv; |
| 2012 | |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 2013 | addr = le32_to_cpu(addr); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2014 | |
| 2015 | DHD_INFO(("sdpcm_shared address 0x%08X\n", addr)); |
| 2016 | |
| 2017 | /* |
| 2018 | * Check if addr is valid. |
| 2019 | * NVRAM length at the end of memory should have been overwritten. |
| 2020 | */ |
| 2021 | if (addr == 0 || ((~addr >> 16) & 0xffff) == (addr & 0xffff)) { |
| 2022 | DHD_ERROR(("%s: address (0x%08x) of sdpcm_shared invalid\n", |
| 2023 | __func__, addr)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2024 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2025 | } |
| 2026 | |
Roland Vossen | 70963f9 | 2011-06-01 13:45:08 +0200 | [diff] [blame] | 2027 | /* Read rte_shared structure */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2028 | rv = brcmf_sdbrcm_membytes(bus, false, addr, (u8 *) sh, |
Franky Lin | b49b14d | 2011-06-01 13:45:37 +0200 | [diff] [blame] | 2029 | sizeof(struct sdpcm_shared)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2030 | if (rv < 0) |
| 2031 | return rv; |
| 2032 | |
| 2033 | /* Endianness */ |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 2034 | sh->flags = le32_to_cpu(sh->flags); |
| 2035 | sh->trap_addr = le32_to_cpu(sh->trap_addr); |
| 2036 | sh->assert_exp_addr = le32_to_cpu(sh->assert_exp_addr); |
| 2037 | sh->assert_file_addr = le32_to_cpu(sh->assert_file_addr); |
| 2038 | sh->assert_line = le32_to_cpu(sh->assert_line); |
| 2039 | sh->console_addr = le32_to_cpu(sh->console_addr); |
| 2040 | sh->msgtrace_addr = le32_to_cpu(sh->msgtrace_addr); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2041 | |
| 2042 | if ((sh->flags & SDPCM_SHARED_VERSION_MASK) != SDPCM_SHARED_VERSION) { |
| 2043 | DHD_ERROR(("%s: sdpcm_shared version %d in dhd " |
| 2044 | "is different than sdpcm_shared version %d in dongle\n", |
| 2045 | __func__, SDPCM_SHARED_VERSION, |
| 2046 | sh->flags & SDPCM_SHARED_VERSION_MASK)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2047 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2048 | } |
| 2049 | |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 2050 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2051 | } |
| 2052 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2053 | 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] | 2054 | { |
| 2055 | int bcmerror = 0; |
| 2056 | uint msize = 512; |
| 2057 | char *mbuffer = NULL; |
| 2058 | uint maxstrlen = 256; |
| 2059 | char *str = NULL; |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 2060 | struct brcmf_trap tr; |
Franky Lin | b49b14d | 2011-06-01 13:45:37 +0200 | [diff] [blame] | 2061 | struct sdpcm_shared sdpcm_shared; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2062 | struct brcmu_strbuf strbuf; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2063 | |
| 2064 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 2065 | |
| 2066 | if (data == NULL) { |
| 2067 | /* |
| 2068 | * Called after a rx ctrl timeout. "data" is NULL. |
| 2069 | * allocate memory to trace the trap or assert. |
| 2070 | */ |
| 2071 | size = msize; |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2072 | mbuffer = data = kmalloc(msize, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2073 | if (mbuffer == NULL) { |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2074 | DHD_ERROR(("%s: kmalloc(%d) failed\n", __func__, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2075 | msize)); |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2076 | bcmerror = -ENOMEM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2077 | goto done; |
| 2078 | } |
| 2079 | } |
| 2080 | |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2081 | str = kmalloc(maxstrlen, GFP_ATOMIC); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2082 | if (str == NULL) { |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2083 | DHD_ERROR(("%s: kmalloc(%d) failed\n", __func__, maxstrlen)); |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2084 | bcmerror = -ENOMEM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2085 | goto done; |
| 2086 | } |
| 2087 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2088 | bcmerror = brcmf_sdbrcm_readshared(bus, &sdpcm_shared); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2089 | if (bcmerror < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2090 | goto done; |
| 2091 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2092 | brcmu_binit(&strbuf, data, size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2093 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2094 | brcmu_bprintf(&strbuf, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2095 | "msgtrace address : 0x%08X\nconsole address : 0x%08X\n", |
| 2096 | sdpcm_shared.msgtrace_addr, sdpcm_shared.console_addr); |
| 2097 | |
| 2098 | if ((sdpcm_shared.flags & SDPCM_SHARED_ASSERT_BUILT) == 0) { |
| 2099 | /* NOTE: Misspelled assert is intentional - DO NOT FIX. |
| 2100 | * (Avoids conflict with real asserts for programmatic |
| 2101 | * parsing of output.) |
| 2102 | */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2103 | brcmu_bprintf(&strbuf, "Assrt not built in dongle\n"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2104 | } |
| 2105 | |
| 2106 | if ((sdpcm_shared.flags & (SDPCM_SHARED_ASSERT | SDPCM_SHARED_TRAP)) == |
| 2107 | 0) { |
| 2108 | /* NOTE: Misspelled assert is intentional - DO NOT FIX. |
| 2109 | * (Avoids conflict with real asserts for programmatic |
| 2110 | * parsing of output.) |
| 2111 | */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2112 | brcmu_bprintf(&strbuf, "No trap%s in dongle", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2113 | (sdpcm_shared.flags & SDPCM_SHARED_ASSERT_BUILT) |
| 2114 | ? "/assrt" : ""); |
| 2115 | } else { |
| 2116 | if (sdpcm_shared.flags & SDPCM_SHARED_ASSERT) { |
| 2117 | /* Download assert */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2118 | brcmu_bprintf(&strbuf, "Dongle assert"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2119 | if (sdpcm_shared.assert_exp_addr != 0) { |
| 2120 | str[0] = '\0'; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2121 | bcmerror = brcmf_sdbrcm_membytes(bus, false, |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2122 | sdpcm_shared.assert_exp_addr, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2123 | (u8 *) str, maxstrlen); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2124 | if (bcmerror < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2125 | goto done; |
| 2126 | |
| 2127 | str[maxstrlen - 1] = '\0'; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2128 | brcmu_bprintf(&strbuf, " expr \"%s\"", str); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2129 | } |
| 2130 | |
| 2131 | if (sdpcm_shared.assert_file_addr != 0) { |
| 2132 | str[0] = '\0'; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2133 | bcmerror = brcmf_sdbrcm_membytes(bus, false, |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2134 | sdpcm_shared.assert_file_addr, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2135 | (u8 *) str, maxstrlen); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2136 | if (bcmerror < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2137 | goto done; |
| 2138 | |
| 2139 | str[maxstrlen - 1] = '\0'; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2140 | brcmu_bprintf(&strbuf, " file \"%s\"", str); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2141 | } |
| 2142 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2143 | brcmu_bprintf(&strbuf, " line %d ", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2144 | sdpcm_shared.assert_line); |
| 2145 | } |
| 2146 | |
| 2147 | if (sdpcm_shared.flags & SDPCM_SHARED_TRAP) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2148 | bcmerror = brcmf_sdbrcm_membytes(bus, false, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2149 | sdpcm_shared.trap_addr, (u8 *)&tr, |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 2150 | sizeof(struct brcmf_trap)); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2151 | if (bcmerror < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2152 | goto done; |
| 2153 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2154 | brcmu_bprintf(&strbuf, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2155 | "Dongle trap type 0x%x @ epc 0x%x, cpsr 0x%x, spsr 0x%x, sp 0x%x," |
| 2156 | "lp 0x%x, rpc 0x%x Trap offset 0x%x, " |
| 2157 | "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", |
| 2158 | tr.type, tr.epc, tr.cpsr, tr.spsr, tr.r13, |
| 2159 | tr.r14, tr.pc, sdpcm_shared.trap_addr, |
| 2160 | tr.r0, tr.r1, tr.r2, tr.r3, tr.r4, tr.r5, |
| 2161 | tr.r6, tr.r7); |
| 2162 | } |
| 2163 | } |
| 2164 | |
| 2165 | if (sdpcm_shared.flags & (SDPCM_SHARED_ASSERT | SDPCM_SHARED_TRAP)) |
| 2166 | DHD_ERROR(("%s: %s\n", __func__, strbuf.origbuf)); |
| 2167 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 2168 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2169 | if (sdpcm_shared.flags & SDPCM_SHARED_TRAP) { |
| 2170 | /* Mem dump to a file on device */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2171 | brcmf_sdbrcm_mem_dump(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2172 | } |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 2173 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2174 | |
| 2175 | done: |
Ilia Mirkin | 46d994b | 2011-03-13 00:28:56 -0500 | [diff] [blame] | 2176 | kfree(mbuffer); |
| 2177 | kfree(str); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2178 | |
| 2179 | return bcmerror; |
| 2180 | } |
| 2181 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2182 | static int brcmf_sdbrcm_mem_dump(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2183 | { |
| 2184 | int ret = 0; |
| 2185 | int size; /* Full mem size */ |
| 2186 | int start = 0; /* Start address */ |
| 2187 | int read_size = 0; /* Read size of each iteration */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2188 | u8 *buf = NULL, *databuf = NULL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2189 | |
| 2190 | /* Get full mem size */ |
| 2191 | size = bus->ramsize; |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2192 | buf = kmalloc(size, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2193 | if (!buf) { |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 2194 | DHD_ERROR(("%s: Out of memory (%d bytes)\n", __func__, size)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2195 | return -1; |
| 2196 | } |
| 2197 | |
| 2198 | /* Read mem content */ |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 2199 | printk(KERN_DEBUG "Dump dongle memory"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2200 | databuf = buf; |
| 2201 | while (size) { |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 2202 | read_size = min(MEMBLOCK, size); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2203 | ret = brcmf_sdbrcm_membytes(bus, false, start, databuf, |
| 2204 | read_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2205 | if (ret) { |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 2206 | DHD_ERROR(("%s: Error membytes %d\n", __func__, ret)); |
Ilia Mirkin | 46d994b | 2011-03-13 00:28:56 -0500 | [diff] [blame] | 2207 | kfree(buf); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2208 | return -1; |
| 2209 | } |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 2210 | printk("."); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2211 | |
| 2212 | /* Decrement size and increment start address */ |
| 2213 | size -= read_size; |
| 2214 | start += read_size; |
| 2215 | databuf += read_size; |
| 2216 | } |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 2217 | printk(KERN_DEBUG "Done\n"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2218 | |
| 2219 | /* free buf before return !!! */ |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 2220 | if (brcmf_write_to_file(bus->dhd, buf, bus->ramsize)) { |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 2221 | DHD_ERROR(("%s: Error writing to files\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2222 | return -1; |
| 2223 | } |
| 2224 | |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 2225 | /* buf free handled in brcmf_write_to_file, not here */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2226 | return 0; |
| 2227 | } |
| 2228 | |
| 2229 | #define CONSOLE_LINE_MAX 192 |
| 2230 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2231 | static int brcmf_sdbrcm_readconsole(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2232 | { |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 2233 | struct dhd_console *c = &bus->console; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2234 | u8 line[CONSOLE_LINE_MAX], ch; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2235 | u32 n, idx, addr; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2236 | int rv; |
| 2237 | |
| 2238 | /* Don't do anything until FWREADY updates console address */ |
| 2239 | if (bus->console_addr == 0) |
| 2240 | return 0; |
| 2241 | |
| 2242 | /* Read console log struct */ |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 2243 | addr = bus->console_addr + offsetof(struct rte_console, log); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2244 | rv = brcmf_sdbrcm_membytes(bus, false, addr, (u8 *)&c->log, |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2245 | sizeof(c->log)); |
| 2246 | if (rv < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2247 | return rv; |
| 2248 | |
| 2249 | /* Allocate console buffer (one time only) */ |
| 2250 | if (c->buf == NULL) { |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 2251 | c->bufsize = le32_to_cpu(c->log.buf_size); |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2252 | c->buf = kmalloc(c->bufsize, GFP_ATOMIC); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2253 | if (c->buf == NULL) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2254 | return -ENOMEM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2255 | } |
| 2256 | |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 2257 | idx = le32_to_cpu(c->log.idx); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2258 | |
| 2259 | /* Protect against corrupt value */ |
| 2260 | if (idx > c->bufsize) |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2261 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2262 | |
| 2263 | /* Skip reading the console buffer if the index pointer |
| 2264 | has not moved */ |
| 2265 | if (idx == c->last) |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 2266 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2267 | |
| 2268 | /* Read the console buffer */ |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 2269 | addr = le32_to_cpu(c->log.buf); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2270 | rv = brcmf_sdbrcm_membytes(bus, false, addr, c->buf, c->bufsize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2271 | if (rv < 0) |
| 2272 | return rv; |
| 2273 | |
| 2274 | while (c->last != idx) { |
| 2275 | for (n = 0; n < CONSOLE_LINE_MAX - 2; n++) { |
| 2276 | if (c->last == idx) { |
| 2277 | /* This would output a partial line. |
| 2278 | * Instead, back up |
| 2279 | * the buffer pointer and output this |
| 2280 | * line next time around. |
| 2281 | */ |
| 2282 | if (c->last >= n) |
| 2283 | c->last -= n; |
| 2284 | else |
| 2285 | c->last = c->bufsize - n; |
| 2286 | goto break2; |
| 2287 | } |
| 2288 | ch = c->buf[c->last]; |
| 2289 | c->last = (c->last + 1) % c->bufsize; |
| 2290 | if (ch == '\n') |
| 2291 | break; |
| 2292 | line[n] = ch; |
| 2293 | } |
| 2294 | |
| 2295 | if (n > 0) { |
| 2296 | if (line[n - 1] == '\r') |
| 2297 | n--; |
| 2298 | line[n] = 0; |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 2299 | printk(KERN_DEBUG "CONSOLE: %s\n", line); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2300 | } |
| 2301 | } |
| 2302 | break2: |
| 2303 | |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 2304 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2305 | } |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 2306 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2307 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2308 | int brcmf_sdbrcm_downloadvars(dhd_bus_t *bus, void *arg, int len) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2309 | { |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 2310 | int bcmerror = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2311 | |
| 2312 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 2313 | |
| 2314 | /* Basic sanity checks */ |
| 2315 | if (bus->dhd->up) { |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2316 | bcmerror = -EISCONN; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2317 | goto err; |
| 2318 | } |
| 2319 | if (!len) { |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2320 | bcmerror = -EOVERFLOW; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2321 | goto err; |
| 2322 | } |
| 2323 | |
| 2324 | /* Free the old ones and replace with passed variables */ |
Ilia Mirkin | 46d994b | 2011-03-13 00:28:56 -0500 | [diff] [blame] | 2325 | kfree(bus->vars); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2326 | |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2327 | bus->vars = kmalloc(len, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2328 | bus->varsz = bus->vars ? len : 0; |
| 2329 | if (bus->vars == NULL) { |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2330 | bcmerror = -ENOMEM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2331 | goto err; |
| 2332 | } |
| 2333 | |
| 2334 | /* Copy the passed variables, which should include the |
| 2335 | terminating double-null */ |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2336 | memcpy(bus->vars, arg, bus->varsz); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2337 | err: |
| 2338 | return bcmerror; |
| 2339 | } |
| 2340 | |
| 2341 | static int |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2342 | 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] | 2343 | const char *name, void *params, int plen, void *arg, int len, |
| 2344 | int val_size) |
| 2345 | { |
| 2346 | int bcmerror = 0; |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2347 | s32 int_val = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2348 | bool bool_val = 0; |
| 2349 | |
| 2350 | DHD_TRACE(("%s: Enter, action %d name %s params %p plen %d arg %p " |
| 2351 | "len %d val_size %d\n", |
| 2352 | __func__, actionid, name, params, plen, arg, len, val_size)); |
| 2353 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2354 | bcmerror = brcmu_iovar_lencheck(vi, arg, len, IOV_ISSET(actionid)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2355 | if (bcmerror != 0) |
| 2356 | goto exit; |
| 2357 | |
| 2358 | if (plen >= (int)sizeof(int_val)) |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2359 | memcpy(&int_val, params, sizeof(int_val)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2360 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2361 | bool_val = (int_val != 0) ? true : false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2362 | |
| 2363 | /* Some ioctls use the bus */ |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 2364 | brcmf_os_sdlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2365 | |
| 2366 | /* Check if dongle is in reset. If so, only allow DEVRESET iovars */ |
| 2367 | if (bus->dhd->dongle_reset && !(actionid == IOV_SVAL(IOV_DEVRESET) || |
| 2368 | actionid == IOV_GVAL(IOV_DEVRESET))) { |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2369 | bcmerror = -EPERM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2370 | goto exit; |
| 2371 | } |
| 2372 | |
| 2373 | /* Handle sleep stuff before any clock mucking */ |
| 2374 | if (vi->varid == IOV_SLEEP) { |
| 2375 | if (IOV_ISSET(actionid)) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2376 | bcmerror = brcmf_sdbrcm_bussleep(bus, bool_val); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2377 | } else { |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2378 | int_val = (s32) bus->sleeping; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2379 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2380 | } |
| 2381 | goto exit; |
| 2382 | } |
| 2383 | |
| 2384 | /* Request clock to allow SDIO accesses */ |
| 2385 | if (!bus->dhd->dongle_reset) { |
| 2386 | BUS_WAKE(bus); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2387 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2388 | } |
| 2389 | |
| 2390 | switch (actionid) { |
| 2391 | case IOV_GVAL(IOV_INTR): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2392 | int_val = (s32) bus->intr; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2393 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2394 | break; |
| 2395 | |
| 2396 | case IOV_SVAL(IOV_INTR): |
| 2397 | bus->intr = bool_val; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2398 | bus->intdis = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2399 | if (bus->dhd->up) { |
| 2400 | if (bus->intr) { |
| 2401 | DHD_INTR(("%s: enable SDIO device interrupts\n", |
| 2402 | __func__)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2403 | brcmf_sdcard_intr_enable(bus->sdh); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2404 | } else { |
| 2405 | DHD_INTR(("%s: disable SDIO interrupts\n", |
| 2406 | __func__)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2407 | brcmf_sdcard_intr_disable(bus->sdh); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2408 | } |
| 2409 | } |
| 2410 | break; |
| 2411 | |
| 2412 | case IOV_GVAL(IOV_POLLRATE): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2413 | int_val = (s32) bus->pollrate; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2414 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2415 | break; |
| 2416 | |
| 2417 | case IOV_SVAL(IOV_POLLRATE): |
| 2418 | bus->pollrate = (uint) int_val; |
| 2419 | bus->poll = (bus->pollrate != 0); |
| 2420 | break; |
| 2421 | |
| 2422 | case IOV_GVAL(IOV_IDLETIME): |
| 2423 | int_val = bus->idletime; |
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_IDLETIME): |
| 2428 | if ((int_val < 0) && (int_val != DHD_IDLE_IMMEDIATE)) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2429 | bcmerror = -EINVAL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2430 | else |
| 2431 | bus->idletime = int_val; |
| 2432 | break; |
| 2433 | |
| 2434 | case IOV_GVAL(IOV_IDLECLOCK): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2435 | int_val = (s32) bus->idleclock; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2436 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2437 | break; |
| 2438 | |
| 2439 | case IOV_SVAL(IOV_IDLECLOCK): |
| 2440 | bus->idleclock = int_val; |
| 2441 | break; |
| 2442 | |
| 2443 | case IOV_GVAL(IOV_SD1IDLE): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2444 | int_val = (s32) sd1idle; |
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_SD1IDLE): |
| 2449 | sd1idle = bool_val; |
| 2450 | break; |
| 2451 | |
| 2452 | case IOV_SVAL(IOV_MEMBYTES): |
| 2453 | case IOV_GVAL(IOV_MEMBYTES): |
| 2454 | { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2455 | u32 address; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2456 | uint size, dsize; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2457 | u8 *data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2458 | |
| 2459 | bool set = (actionid == IOV_SVAL(IOV_MEMBYTES)); |
| 2460 | |
| 2461 | ASSERT(plen >= 2 * sizeof(int)); |
| 2462 | |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2463 | address = (u32) int_val; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2464 | memcpy(&int_val, (char *)params + sizeof(int_val), |
| 2465 | sizeof(int_val)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2466 | size = (uint) int_val; |
| 2467 | |
| 2468 | /* Do some validation */ |
| 2469 | dsize = set ? plen - (2 * sizeof(int)) : len; |
| 2470 | if (dsize < size) { |
| 2471 | DHD_ERROR(("%s: error on %s membytes, addr " |
| 2472 | "0x%08x size %d dsize %d\n", |
| 2473 | __func__, (set ? "set" : "get"), |
| 2474 | address, size, dsize)); |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2475 | bcmerror = -EINVAL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2476 | break; |
| 2477 | } |
| 2478 | |
| 2479 | DHD_INFO(("%s: Request to %s %d bytes at address " |
| 2480 | "0x%08x\n", |
| 2481 | __func__, (set ? "write" : "read"), size, address)); |
| 2482 | |
| 2483 | /* If we know about SOCRAM, check for a fit */ |
| 2484 | if ((bus->orig_ramsize) && |
| 2485 | ((address > bus->orig_ramsize) |
| 2486 | || (address + size > bus->orig_ramsize))) { |
| 2487 | DHD_ERROR(("%s: ramsize 0x%08x doesn't have %d " |
| 2488 | "bytes at 0x%08x\n", |
| 2489 | __func__, bus->orig_ramsize, size, address)); |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2490 | bcmerror = -EINVAL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2491 | break; |
| 2492 | } |
| 2493 | |
| 2494 | /* Generate the actual data pointer */ |
| 2495 | data = |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2496 | set ? (u8 *) params + |
| 2497 | 2 * sizeof(int) : (u8 *) arg; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2498 | |
| 2499 | /* Call to do the transfer */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2500 | bcmerror = brcmf_sdbrcm_membytes(bus, set, address, |
| 2501 | data, size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2502 | |
| 2503 | break; |
| 2504 | } |
| 2505 | |
| 2506 | case IOV_GVAL(IOV_MEMSIZE): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2507 | int_val = (s32) bus->ramsize; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2508 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2509 | break; |
| 2510 | |
| 2511 | case IOV_GVAL(IOV_SDIOD_DRIVE): |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 2512 | int_val = (s32) brcmf_sdiod_drive_strength; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2513 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2514 | break; |
| 2515 | |
| 2516 | case IOV_SVAL(IOV_SDIOD_DRIVE): |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 2517 | brcmf_sdiod_drive_strength = int_val; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2518 | brcmf_sdbrcm_sdiod_drive_strength_init(bus, |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 2519 | brcmf_sdiod_drive_strength); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2520 | break; |
| 2521 | |
| 2522 | case IOV_SVAL(IOV_DOWNLOAD): |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2523 | bcmerror = brcmf_sdbrcm_download_state(bus, bool_val); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2524 | break; |
| 2525 | |
| 2526 | case IOV_SVAL(IOV_VARS): |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2527 | bcmerror = brcmf_sdbrcm_downloadvars(bus, arg, len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2528 | break; |
| 2529 | |
| 2530 | case IOV_GVAL(IOV_READAHEAD): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2531 | int_val = (s32) dhd_readahead; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2532 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2533 | break; |
| 2534 | |
| 2535 | case IOV_SVAL(IOV_READAHEAD): |
| 2536 | if (bool_val && !dhd_readahead) |
| 2537 | bus->nextlen = 0; |
| 2538 | dhd_readahead = bool_val; |
| 2539 | break; |
| 2540 | |
| 2541 | case IOV_GVAL(IOV_SDRXCHAIN): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2542 | int_val = (s32) bus->use_rxchain; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2543 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2544 | break; |
| 2545 | |
| 2546 | case IOV_SVAL(IOV_SDRXCHAIN): |
| 2547 | if (bool_val && !bus->sd_rxchain) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2548 | bcmerror = -ENOTSUPP; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2549 | else |
| 2550 | bus->use_rxchain = bool_val; |
| 2551 | break; |
| 2552 | case IOV_GVAL(IOV_ALIGNCTL): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2553 | int_val = (s32) dhd_alignctl; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2554 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2555 | break; |
| 2556 | |
| 2557 | case IOV_SVAL(IOV_ALIGNCTL): |
| 2558 | dhd_alignctl = bool_val; |
| 2559 | break; |
| 2560 | |
| 2561 | case IOV_GVAL(IOV_SDALIGN): |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 2562 | int_val = BRCMF_SDALIGN; |
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 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 2566 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2567 | case IOV_GVAL(IOV_VARS): |
| 2568 | if (bus->varsz < (uint) len) |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2569 | memcpy(arg, bus->vars, bus->varsz); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2570 | else |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2571 | bcmerror = -EOVERFLOW; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2572 | break; |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 2573 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2574 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 2575 | #ifdef BCMDBG |
Franky Lin | 913af5f | 2011-06-29 16:47:44 -0700 | [diff] [blame^] | 2576 | case IOV_GVAL(IOV_DCONSOLE_POLL): |
| 2577 | int_val = (s32) brcmf_console_ms; |
| 2578 | memcpy(arg, &int_val, val_size); |
| 2579 | break; |
| 2580 | |
| 2581 | case IOV_SVAL(IOV_DCONSOLE_POLL): |
| 2582 | brcmf_console_ms = (uint) int_val; |
| 2583 | break; |
| 2584 | |
| 2585 | case IOV_SVAL(IOV_CONS): |
| 2586 | if (len > 0) |
| 2587 | bcmerror = brcmf_sdbrcm_bus_console_in(bus->dhd, |
| 2588 | arg, len - 1); |
| 2589 | break; |
| 2590 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2591 | case IOV_GVAL(IOV_SDREG): |
| 2592 | { |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 2593 | struct brcmf_sdreg *sd_ptr; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2594 | u32 addr, size; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2595 | |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 2596 | sd_ptr = (struct brcmf_sdreg *) params; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2597 | |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 2598 | addr = (unsigned long)bus->regs + sd_ptr->offset; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2599 | size = sd_ptr->func; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2600 | int_val = (s32) brcmf_sdcard_reg_read(bus->sdh, addr, |
| 2601 | size); |
| 2602 | if (brcmf_sdcard_regfail(bus->sdh)) |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2603 | bcmerror = -EIO; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2604 | memcpy(arg, &int_val, sizeof(s32)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2605 | break; |
| 2606 | } |
| 2607 | |
| 2608 | case IOV_SVAL(IOV_SDREG): |
| 2609 | { |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 2610 | struct brcmf_sdreg *sd_ptr; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2611 | u32 addr, size; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2612 | |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 2613 | sd_ptr = (struct brcmf_sdreg *) params; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2614 | |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 2615 | addr = (unsigned long)bus->regs + sd_ptr->offset; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2616 | size = sd_ptr->func; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2617 | brcmf_sdcard_reg_write(bus->sdh, addr, size, |
| 2618 | sd_ptr->value); |
| 2619 | if (brcmf_sdcard_regfail(bus->sdh)) |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2620 | bcmerror = -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2621 | break; |
| 2622 | } |
| 2623 | |
| 2624 | /* Same as above, but offset is not backplane |
| 2625 | (not SDIO core) */ |
| 2626 | case IOV_GVAL(IOV_SBREG): |
| 2627 | { |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 2628 | struct brcmf_sdreg sdreg; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2629 | u32 addr, size; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2630 | |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2631 | memcpy(&sdreg, params, sizeof(sdreg)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2632 | |
| 2633 | addr = SI_ENUM_BASE + sdreg.offset; |
| 2634 | size = sdreg.func; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2635 | int_val = (s32) brcmf_sdcard_reg_read(bus->sdh, addr, |
| 2636 | size); |
| 2637 | if (brcmf_sdcard_regfail(bus->sdh)) |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2638 | bcmerror = -EIO; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2639 | memcpy(arg, &int_val, sizeof(s32)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2640 | break; |
| 2641 | } |
| 2642 | |
| 2643 | case IOV_SVAL(IOV_SBREG): |
| 2644 | { |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 2645 | struct brcmf_sdreg sdreg; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2646 | u32 addr, size; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2647 | |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2648 | memcpy(&sdreg, params, sizeof(sdreg)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2649 | |
| 2650 | addr = SI_ENUM_BASE + sdreg.offset; |
| 2651 | size = sdreg.func; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2652 | brcmf_sdcard_reg_write(bus->sdh, addr, size, |
| 2653 | sdreg.value); |
| 2654 | if (brcmf_sdcard_regfail(bus->sdh)) |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2655 | bcmerror = -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2656 | break; |
| 2657 | } |
| 2658 | |
| 2659 | case IOV_GVAL(IOV_SDCIS): |
| 2660 | { |
| 2661 | *(char *)arg = 0; |
| 2662 | |
nohee ko | ea3b8a2 | 2010-10-09 10:34:38 -0700 | [diff] [blame] | 2663 | strcat(arg, "\nFunc 0\n"); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2664 | brcmf_sdcard_cis_read(bus->sdh, 0x10, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2665 | (u8 *) arg + strlen(arg), |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2666 | SBSDIO_CIS_SIZE_LIMIT); |
nohee ko | ea3b8a2 | 2010-10-09 10:34:38 -0700 | [diff] [blame] | 2667 | strcat(arg, "\nFunc 1\n"); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2668 | brcmf_sdcard_cis_read(bus->sdh, 0x11, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2669 | (u8 *) arg + strlen(arg), |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2670 | SBSDIO_CIS_SIZE_LIMIT); |
nohee ko | ea3b8a2 | 2010-10-09 10:34:38 -0700 | [diff] [blame] | 2671 | strcat(arg, "\nFunc 2\n"); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2672 | brcmf_sdcard_cis_read(bus->sdh, 0x12, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2673 | (u8 *) arg + strlen(arg), |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2674 | SBSDIO_CIS_SIZE_LIMIT); |
| 2675 | break; |
| 2676 | } |
| 2677 | |
| 2678 | case IOV_GVAL(IOV_FORCEEVEN): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2679 | int_val = (s32) forcealign; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2680 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2681 | break; |
| 2682 | |
| 2683 | case IOV_SVAL(IOV_FORCEEVEN): |
| 2684 | forcealign = bool_val; |
| 2685 | break; |
| 2686 | |
| 2687 | case IOV_GVAL(IOV_TXBOUND): |
Arend van Spriel | 7af9d0c | 2011-06-29 16:47:19 -0700 | [diff] [blame] | 2688 | int_val = (s32) brcmf_txbound; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2689 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2690 | break; |
| 2691 | |
| 2692 | case IOV_SVAL(IOV_TXBOUND): |
Arend van Spriel | 7af9d0c | 2011-06-29 16:47:19 -0700 | [diff] [blame] | 2693 | brcmf_txbound = (uint) int_val; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2694 | break; |
| 2695 | |
| 2696 | case IOV_GVAL(IOV_RXBOUND): |
Arend van Spriel | 7af9d0c | 2011-06-29 16:47:19 -0700 | [diff] [blame] | 2697 | int_val = (s32) brcmf_rxbound; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2698 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2699 | break; |
| 2700 | |
| 2701 | case IOV_SVAL(IOV_RXBOUND): |
Arend van Spriel | 7af9d0c | 2011-06-29 16:47:19 -0700 | [diff] [blame] | 2702 | brcmf_rxbound = (uint) int_val; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2703 | break; |
| 2704 | |
| 2705 | case IOV_GVAL(IOV_TXMINMAX): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2706 | int_val = (s32) dhd_txminmax; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2707 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2708 | break; |
| 2709 | |
| 2710 | case IOV_SVAL(IOV_TXMINMAX): |
| 2711 | dhd_txminmax = (uint) int_val; |
| 2712 | break; |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 2713 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2714 | |
| 2715 | #ifdef SDTEST |
| 2716 | case IOV_GVAL(IOV_EXTLOOP): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2717 | int_val = (s32) bus->ext_loop; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2718 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2719 | break; |
| 2720 | |
| 2721 | case IOV_SVAL(IOV_EXTLOOP): |
| 2722 | bus->ext_loop = bool_val; |
| 2723 | break; |
| 2724 | |
| 2725 | case IOV_GVAL(IOV_PKTGEN): |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2726 | bcmerror = brcmf_sdbrcm_pktgen_get(bus, arg); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2727 | break; |
| 2728 | |
| 2729 | case IOV_SVAL(IOV_PKTGEN): |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2730 | bcmerror = brcmf_sdbrcm_pktgen_set(bus, arg); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2731 | break; |
| 2732 | #endif /* SDTEST */ |
| 2733 | |
| 2734 | case IOV_SVAL(IOV_DEVRESET): |
| 2735 | DHD_TRACE(("%s: Called set IOV_DEVRESET=%d dongle_reset=%d " |
| 2736 | "busstate=%d\n", |
| 2737 | __func__, bool_val, bus->dhd->dongle_reset, |
| 2738 | bus->dhd->busstate)); |
| 2739 | |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 2740 | brcmf_bus_devreset(bus->dhd, (u8) bool_val); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2741 | |
| 2742 | break; |
| 2743 | |
| 2744 | case IOV_GVAL(IOV_DEVRESET): |
| 2745 | DHD_TRACE(("%s: Called get IOV_DEVRESET\n", __func__)); |
| 2746 | |
| 2747 | /* Get its status */ |
| 2748 | int_val = (bool) bus->dhd->dongle_reset; |
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 | |
| 2751 | break; |
| 2752 | |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 2753 | case IOV_GVAL(IOV_WDTICK): |
| 2754 | int_val = (s32) brcmf_watchdog_ms; |
| 2755 | memcpy(arg, &int_val, val_size); |
| 2756 | break; |
| 2757 | |
| 2758 | case IOV_SVAL(IOV_WDTICK): |
| 2759 | if (!bus->dhd->up) { |
| 2760 | bcmerror = -ENOLINK; |
| 2761 | break; |
| 2762 | } |
| 2763 | brcmf_sdbrcm_wd_timer(bus, (uint) int_val); |
| 2764 | break; |
| 2765 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2766 | default: |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2767 | bcmerror = -ENOTSUPP; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2768 | break; |
| 2769 | } |
| 2770 | |
| 2771 | exit: |
| 2772 | if ((bus->idletime == DHD_IDLE_IMMEDIATE) && !bus->dpc_sched) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2773 | bus->activity = false; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2774 | brcmf_sdbrcm_clkctl(bus, CLK_NONE, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2775 | } |
| 2776 | |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 2777 | brcmf_os_sdunlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2778 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2779 | if (actionid == IOV_SVAL(IOV_DEVRESET) && bool_val == false) |
Arend van Spriel | aba5e0a | 2011-06-29 16:47:03 -0700 | [diff] [blame] | 2780 | brcmf_c_preinit_ioctls((dhd_pub_t *) bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2781 | |
| 2782 | return bcmerror; |
| 2783 | } |
| 2784 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2785 | static int brcmf_sdbrcm_write_vars(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2786 | { |
| 2787 | int bcmerror = 0; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2788 | u32 varsize; |
| 2789 | u32 varaddr; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2790 | u8 *vbuffer; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2791 | u32 varsizew; |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 2792 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2793 | char *nvram_ularray; |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 2794 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2795 | |
| 2796 | /* Even if there are no vars are to be written, we still |
| 2797 | need to set the ramsize. */ |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 2798 | varsize = bus->varsz ? roundup(bus->varsz, 4) : 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2799 | varaddr = (bus->ramsize - 4) - varsize; |
| 2800 | |
| 2801 | if (bus->vars) { |
Alexander Beregalov | 12d0eb4 | 2011-03-09 03:53:35 +0300 | [diff] [blame] | 2802 | vbuffer = kzalloc(varsize, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2803 | if (!vbuffer) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2804 | return -ENOMEM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2805 | |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2806 | memcpy(vbuffer, bus->vars, bus->varsz); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2807 | |
| 2808 | /* Write the vars list */ |
| 2809 | bcmerror = |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2810 | brcmf_sdbrcm_membytes(bus, true, varaddr, vbuffer, varsize); |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 2811 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2812 | /* Verify NVRAM bytes */ |
| 2813 | DHD_INFO(("Compare NVRAM dl & ul; varsize=%d\n", varsize)); |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2814 | nvram_ularray = kmalloc(varsize, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2815 | if (!nvram_ularray) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2816 | return -ENOMEM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2817 | |
| 2818 | /* Upload image to verify downloaded contents. */ |
| 2819 | memset(nvram_ularray, 0xaa, varsize); |
| 2820 | |
| 2821 | /* Read the vars list to temp buffer for comparison */ |
| 2822 | bcmerror = |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2823 | brcmf_sdbrcm_membytes(bus, false, varaddr, nvram_ularray, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2824 | varsize); |
| 2825 | if (bcmerror) { |
| 2826 | DHD_ERROR(("%s: error %d on reading %d nvram bytes at " |
| 2827 | "0x%08x\n", __func__, bcmerror, varsize, varaddr)); |
| 2828 | } |
| 2829 | /* Compare the org NVRAM with the one read from RAM */ |
| 2830 | if (memcmp(vbuffer, nvram_ularray, varsize)) { |
| 2831 | DHD_ERROR(("%s: Downloaded NVRAM image is corrupted.\n", |
| 2832 | __func__)); |
| 2833 | } else |
| 2834 | DHD_ERROR(("%s: Download/Upload/Compare of NVRAM ok.\n", |
| 2835 | __func__)); |
| 2836 | |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 2837 | kfree(nvram_ularray); |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 2838 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2839 | |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 2840 | kfree(vbuffer); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2841 | } |
| 2842 | |
| 2843 | /* adjust to the user specified RAM */ |
| 2844 | DHD_INFO(("Physical memory size: %d, usable memory size: %d\n", |
| 2845 | bus->orig_ramsize, bus->ramsize)); |
| 2846 | DHD_INFO(("Vars are at %d, orig varsize is %d\n", varaddr, varsize)); |
| 2847 | varsize = ((bus->orig_ramsize - 4) - varaddr); |
| 2848 | |
| 2849 | /* |
| 2850 | * Determine the length token: |
| 2851 | * Varsize, converted to words, in lower 16-bits, checksum |
| 2852 | * in upper 16-bits. |
| 2853 | */ |
| 2854 | if (bcmerror) { |
| 2855 | varsizew = 0; |
| 2856 | } else { |
| 2857 | varsizew = varsize / 4; |
| 2858 | varsizew = (~varsizew << 16) | (varsizew & 0x0000FFFF); |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 2859 | varsizew = cpu_to_le32(varsizew); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2860 | } |
| 2861 | |
| 2862 | DHD_INFO(("New varsize is %d, length token=0x%08x\n", varsize, |
| 2863 | varsizew)); |
| 2864 | |
| 2865 | /* Write the length token to the last word */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2866 | bcmerror = brcmf_sdbrcm_membytes(bus, true, (bus->orig_ramsize - 4), |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2867 | (u8 *)&varsizew, 4); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2868 | |
| 2869 | return bcmerror; |
| 2870 | } |
| 2871 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2872 | static int brcmf_sdbrcm_download_state(dhd_bus_t *bus, bool enter) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2873 | { |
| 2874 | uint retries; |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 2875 | u32 regdata; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2876 | int bcmerror = 0; |
| 2877 | |
| 2878 | /* To enter download state, disable ARM and reset SOCRAM. |
| 2879 | * To exit download state, simply reset ARM (default is RAM boot). |
| 2880 | */ |
| 2881 | if (enter) { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2882 | bus->alp_only = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2883 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2884 | brcmf_sdbrcm_chip_disablecore(bus->sdh, bus->ci->armcorebase); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2885 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2886 | brcmf_sdbrcm_chip_resetcore(bus->sdh, bus->ci->ramcorebase); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2887 | |
| 2888 | /* Clear the top bit of memory */ |
| 2889 | if (bus->ramsize) { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2890 | u32 zeros = 0; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2891 | brcmf_sdbrcm_membytes(bus, true, bus->ramsize - 4, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2892 | (u8 *)&zeros, 4); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2893 | } |
| 2894 | } else { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2895 | regdata = brcmf_sdcard_reg_read(bus->sdh, |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 2896 | CORE_SB(bus->ci->ramcorebase, sbtmstatelow), 4); |
| 2897 | regdata &= (SBTML_RESET | SBTML_REJ_MASK | |
| 2898 | (SICF_CLOCK_EN << SBTML_SICF_SHIFT)); |
| 2899 | if ((SICF_CLOCK_EN << SBTML_SICF_SHIFT) != regdata) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2900 | DHD_ERROR(("%s: SOCRAM core is down after reset?\n", |
| 2901 | __func__)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2902 | bcmerror = -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2903 | goto fail; |
| 2904 | } |
| 2905 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2906 | bcmerror = brcmf_sdbrcm_write_vars(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2907 | if (bcmerror) { |
| 2908 | DHD_ERROR(("%s: no vars written to RAM\n", __func__)); |
| 2909 | bcmerror = 0; |
| 2910 | } |
| 2911 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2912 | W_SDREG(0xFFFFFFFF, &bus->regs->intstatus, retries); |
| 2913 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2914 | brcmf_sdbrcm_chip_resetcore(bus->sdh, bus->ci->armcorebase); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2915 | |
| 2916 | /* Allow HT Clock now that the ARM is running. */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2917 | bus->alp_only = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2918 | |
| 2919 | bus->dhd->busstate = DHD_BUS_LOAD; |
| 2920 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2921 | fail: |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2922 | return bcmerror; |
| 2923 | } |
| 2924 | |
| 2925 | int |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2926 | brcmf_sdbrcm_bus_iovar_op(dhd_pub_t *dhdp, const char *name, |
| 2927 | void *params, int plen, void *arg, int len, bool set) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2928 | { |
| 2929 | dhd_bus_t *bus = dhdp->bus; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2930 | const struct brcmu_iovar *vi = NULL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2931 | int bcmerror = 0; |
| 2932 | int val_size; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2933 | u32 actionid; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2934 | |
| 2935 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 2936 | |
| 2937 | ASSERT(name); |
| 2938 | ASSERT(len >= 0); |
| 2939 | |
| 2940 | /* Get MUST have return space */ |
| 2941 | ASSERT(set || (arg && len)); |
| 2942 | |
| 2943 | /* Set does NOT take qualifiers */ |
| 2944 | ASSERT(!set || (!params && !plen)); |
| 2945 | |
| 2946 | /* Look up var locally; if not found pass to host driver */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2947 | vi = brcmu_iovar_lookup(dhdsdio_iovars, name); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2948 | if (vi == NULL) { |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 2949 | brcmf_os_sdlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2950 | |
| 2951 | BUS_WAKE(bus); |
| 2952 | |
| 2953 | /* Turn on clock in case SD command needs backplane */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2954 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2955 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2956 | bcmerror = brcmf_sdcard_iovar_op(bus->sdh, name, params, plen, |
| 2957 | arg, len, set); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2958 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2959 | /* Similar check for blocksize change */ |
| 2960 | if (set && strcmp(name, "sd_blocksize") == 0) { |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2961 | s32 fnum = 2; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2962 | if (brcmf_sdcard_iovar_op |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2963 | (bus->sdh, "sd_blocksize", &fnum, sizeof(s32), |
| 2964 | &bus->blocksize, sizeof(s32), |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 2965 | false) != 0) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2966 | bus->blocksize = 0; |
| 2967 | DHD_ERROR(("%s: fail on %s get\n", __func__, |
| 2968 | "sd_blocksize")); |
| 2969 | } else { |
| 2970 | DHD_INFO(("%s: noted %s update, value now %d\n", |
| 2971 | __func__, "sd_blocksize", |
| 2972 | bus->blocksize)); |
| 2973 | } |
| 2974 | } |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 2975 | bus->roundup = min(max_roundup, bus->blocksize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2976 | |
| 2977 | if ((bus->idletime == DHD_IDLE_IMMEDIATE) && !bus->dpc_sched) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2978 | bus->activity = false; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2979 | brcmf_sdbrcm_clkctl(bus, CLK_NONE, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2980 | } |
| 2981 | |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 2982 | brcmf_os_sdunlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2983 | goto exit; |
| 2984 | } |
| 2985 | |
| 2986 | DHD_CTL(("%s: %s %s, len %d plen %d\n", __func__, |
| 2987 | name, (set ? "set" : "get"), len, plen)); |
| 2988 | |
| 2989 | /* set up 'params' pointer in case this is a set command so that |
| 2990 | * the convenience int and bool code can be common to set and get |
| 2991 | */ |
| 2992 | if (params == NULL) { |
| 2993 | params = arg; |
| 2994 | plen = len; |
| 2995 | } |
| 2996 | |
| 2997 | if (vi->type == IOVT_VOID) |
| 2998 | val_size = 0; |
| 2999 | else if (vi->type == IOVT_BUFFER) |
| 3000 | val_size = len; |
| 3001 | else |
| 3002 | /* all other types are integer sized */ |
| 3003 | val_size = sizeof(int); |
| 3004 | |
| 3005 | actionid = set ? IOV_SVAL(vi->varid) : IOV_GVAL(vi->varid); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3006 | bcmerror = brcmf_sdbrcm_doiovar(bus, vi, actionid, name, params, plen, |
| 3007 | arg, len, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3008 | |
| 3009 | exit: |
| 3010 | return bcmerror; |
| 3011 | } |
| 3012 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3013 | void brcmf_sdbrcm_bus_stop(struct dhd_bus *bus, bool enforce_mutex) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3014 | { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 3015 | u32 local_hostintmask; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3016 | u8 saveclk; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3017 | uint retries; |
| 3018 | int err; |
| 3019 | |
| 3020 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 3021 | |
| 3022 | if (enforce_mutex) |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 3023 | brcmf_os_sdlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3024 | |
| 3025 | BUS_WAKE(bus); |
| 3026 | |
| 3027 | /* Enable clock for device interrupts */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3028 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3029 | |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 3030 | if (bus->watchdog_tsk) { |
| 3031 | send_sig(SIGTERM, bus->watchdog_tsk, 1); |
| 3032 | kthread_stop(bus->watchdog_tsk); |
| 3033 | bus->watchdog_tsk = NULL; |
| 3034 | } |
| 3035 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3036 | /* Disable and clear interrupts at the chip level also */ |
| 3037 | W_SDREG(0, &bus->regs->hostintmask, retries); |
| 3038 | local_hostintmask = bus->hostintmask; |
| 3039 | bus->hostintmask = 0; |
| 3040 | |
| 3041 | /* Change our idea of bus state */ |
| 3042 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 3043 | |
| 3044 | /* Force clocks on backplane to be sure F2 interrupt propagates */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3045 | saveclk = brcmf_sdcard_cfg_read(bus->sdh, SDIO_FUNC_1, |
| 3046 | SBSDIO_FUNC1_CHIPCLKCSR, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3047 | if (!err) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3048 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_1, |
| 3049 | SBSDIO_FUNC1_CHIPCLKCSR, |
| 3050 | (saveclk | SBSDIO_FORCE_HT), &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3051 | } |
| 3052 | if (err) { |
| 3053 | DHD_ERROR(("%s: Failed to force clock for F2: err %d\n", |
| 3054 | __func__, err)); |
| 3055 | } |
| 3056 | |
| 3057 | /* Turn off the bus (F2), free any pending packets */ |
| 3058 | DHD_INTR(("%s: disable SDIO interrupts\n", __func__)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3059 | brcmf_sdcard_intr_disable(bus->sdh); |
| 3060 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_0, SDIO_CCCR_IOEx, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3061 | SDIO_FUNC_ENABLE_1, NULL); |
| 3062 | |
| 3063 | /* Clear any pending interrupts now that F2 is disabled */ |
| 3064 | W_SDREG(local_hostintmask, &bus->regs->intstatus, retries); |
| 3065 | |
| 3066 | /* Turn off the backplane clock (only) */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3067 | brcmf_sdbrcm_clkctl(bus, CLK_SDONLY, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3068 | |
| 3069 | /* Clear the data packet queues */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3070 | brcmu_pktq_flush(&bus->txq, true, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3071 | |
| 3072 | /* Clear any held glomming stuff */ |
| 3073 | if (bus->glomd) |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3074 | brcmu_pkt_buf_free_skb(bus->glomd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3075 | |
| 3076 | if (bus->glom) |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3077 | brcmu_pkt_buf_free_skb(bus->glom); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3078 | |
| 3079 | bus->glom = bus->glomd = NULL; |
| 3080 | |
| 3081 | /* Clear rx control and wake any waiters */ |
| 3082 | bus->rxlen = 0; |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 3083 | brcmf_os_ioctl_resp_wake(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3084 | |
| 3085 | /* Reset some F2 state stuff */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3086 | bus->rxskip = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3087 | bus->tx_seq = bus->rx_seq = 0; |
| 3088 | |
| 3089 | if (enforce_mutex) |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 3090 | brcmf_os_sdunlock(bus->dhd); |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 3091 | |
| 3092 | #if defined(OOB_INTR_ONLY) |
| 3093 | brcmf_sdio_unregister_oob_intr(); |
| 3094 | #endif /* defined(OOB_INTR_ONLY) */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3095 | } |
| 3096 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3097 | int brcmf_sdbrcm_bus_init(dhd_pub_t *dhdp, bool enforce_mutex) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3098 | { |
| 3099 | dhd_bus_t *bus = dhdp->bus; |
| 3100 | dhd_timeout_t tmo; |
| 3101 | uint retries = 0; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3102 | u8 ready, enable; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3103 | int err, ret = 0; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3104 | u8 saveclk; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3105 | |
| 3106 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 3107 | |
| 3108 | ASSERT(bus->dhd); |
| 3109 | if (!bus->dhd) |
| 3110 | return 0; |
| 3111 | |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 3112 | /* Start the watchdog timer */ |
| 3113 | bus->dhd->tickcnt = 0; |
| 3114 | brcmf_sdbrcm_wd_timer(bus, brcmf_watchdog_ms); |
| 3115 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3116 | if (enforce_mutex) |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 3117 | brcmf_os_sdlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3118 | |
| 3119 | /* Make sure backplane clock is on, needed to generate F2 interrupt */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3120 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3121 | if (bus->clkstate != CLK_AVAIL) |
| 3122 | goto exit; |
| 3123 | |
| 3124 | /* Force clocks on backplane to be sure F2 interrupt propagates */ |
| 3125 | saveclk = |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3126 | brcmf_sdcard_cfg_read(bus->sdh, SDIO_FUNC_1, |
| 3127 | SBSDIO_FUNC1_CHIPCLKCSR, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3128 | if (!err) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3129 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_1, |
| 3130 | SBSDIO_FUNC1_CHIPCLKCSR, |
| 3131 | (saveclk | SBSDIO_FORCE_HT), &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3132 | } |
| 3133 | if (err) { |
| 3134 | DHD_ERROR(("%s: Failed to force clock for F2: err %d\n", |
| 3135 | __func__, err)); |
| 3136 | goto exit; |
| 3137 | } |
| 3138 | |
| 3139 | /* Enable function 2 (frame transfers) */ |
| 3140 | W_SDREG((SDPCM_PROT_VERSION << SMB_DATA_VERSION_SHIFT), |
| 3141 | &bus->regs->tosbmailboxdata, retries); |
| 3142 | enable = (SDIO_FUNC_ENABLE_1 | SDIO_FUNC_ENABLE_2); |
| 3143 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3144 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_0, SDIO_CCCR_IOEx, enable, |
| 3145 | NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3146 | |
| 3147 | /* 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] | 3148 | brcmf_timeout_start(&tmo, DHD_WAIT_F2RDY * 1000); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3149 | |
| 3150 | ready = 0; |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 3151 | while (ready != enable && !brcmf_timeout_expired(&tmo)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3152 | ready = |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3153 | brcmf_sdcard_cfg_read(bus->sdh, SDIO_FUNC_0, SDIO_CCCR_IORx, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3154 | NULL); |
| 3155 | |
| 3156 | DHD_INFO(("%s: enable 0x%02x, ready 0x%02x (waited %uus)\n", |
| 3157 | __func__, enable, ready, tmo.elapsed)); |
| 3158 | |
| 3159 | /* If F2 successfully enabled, set core and enable interrupts */ |
| 3160 | if (ready == enable) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3161 | /* Set up the interrupt mask and enable interrupts */ |
| 3162 | bus->hostintmask = HOSTINTMASK; |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 3163 | W_SDREG(bus->hostintmask, |
| 3164 | (unsigned int *)CORE_BUS_REG(bus->ci->buscorebase, |
| 3165 | hostintmask), retries); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3166 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3167 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_WATERMARK, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3168 | (u8) watermark, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3169 | |
| 3170 | /* Set bus state according to enable result */ |
| 3171 | dhdp->busstate = DHD_BUS_DATA; |
| 3172 | |
| 3173 | /* bcmsdh_intr_unmask(bus->sdh); */ |
| 3174 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3175 | bus->intdis = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3176 | if (bus->intr) { |
| 3177 | DHD_INTR(("%s: enable SDIO device interrupts\n", |
| 3178 | __func__)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3179 | brcmf_sdcard_intr_enable(bus->sdh); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3180 | } else { |
| 3181 | DHD_INTR(("%s: disable SDIO interrupts\n", __func__)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3182 | brcmf_sdcard_intr_disable(bus->sdh); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3183 | } |
| 3184 | |
| 3185 | } |
| 3186 | |
| 3187 | else { |
| 3188 | /* Disable F2 again */ |
| 3189 | enable = SDIO_FUNC_ENABLE_1; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3190 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_0, SDIO_CCCR_IOEx, |
| 3191 | enable, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3192 | } |
| 3193 | |
| 3194 | /* Restore previous clock setting */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3195 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3196 | saveclk, &err); |
| 3197 | |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 3198 | #if defined(OOB_INTR_ONLY) |
| 3199 | /* Host registration for OOB interrupt */ |
| 3200 | if (brcmf_sdio_register_oob_intr(bus->dhd)) { |
| 3201 | brcmf_sdbrcm_wd_timer(bus, 0); |
| 3202 | DHD_ERROR(("%s Host failed to resgister for OOB\n", __func__)); |
| 3203 | ret = -ENODEV; |
| 3204 | goto exit; |
| 3205 | } |
| 3206 | |
| 3207 | /* Enable oob at firmware */ |
| 3208 | brcmf_sdbrcm_enable_oob_intr(bus, true); |
| 3209 | #endif /* defined(OOB_INTR_ONLY) */ |
| 3210 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3211 | /* If we didn't come up, turn off backplane clock */ |
| 3212 | if (dhdp->busstate != DHD_BUS_DATA) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3213 | brcmf_sdbrcm_clkctl(bus, CLK_NONE, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3214 | |
| 3215 | exit: |
| 3216 | if (enforce_mutex) |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 3217 | brcmf_os_sdunlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3218 | |
| 3219 | return ret; |
| 3220 | } |
| 3221 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3222 | 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] | 3223 | { |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 3224 | struct brcmf_sdio *sdh = bus->sdh; |
Franky Lin | 597600a | 2011-06-01 13:45:39 +0200 | [diff] [blame] | 3225 | struct sdpcmd_regs *regs = bus->regs; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3226 | uint retries = 0; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3227 | u16 lastrbc; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3228 | u8 hi, lo; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3229 | int err; |
| 3230 | |
| 3231 | DHD_ERROR(("%s: %sterminate frame%s\n", __func__, |
| 3232 | (abort ? "abort command, " : ""), |
| 3233 | (rtx ? ", send NAK" : ""))); |
| 3234 | |
| 3235 | if (abort) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3236 | brcmf_sdcard_abort(sdh, SDIO_FUNC_2); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3237 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3238 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_FRAMECTRL, |
| 3239 | SFC_RF_TERM, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3240 | bus->f1regdata++; |
| 3241 | |
| 3242 | /* Wait until the packet has been flushed (device/FIFO stable) */ |
| 3243 | for (lastrbc = retries = 0xffff; retries > 0; retries--) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3244 | hi = brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
| 3245 | SBSDIO_FUNC1_RFRAMEBCHI, NULL); |
| 3246 | lo = brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
| 3247 | SBSDIO_FUNC1_RFRAMEBCLO, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3248 | bus->f1regdata += 2; |
| 3249 | |
| 3250 | if ((hi == 0) && (lo == 0)) |
| 3251 | break; |
| 3252 | |
| 3253 | if ((hi > (lastrbc >> 8)) && (lo > (lastrbc & 0x00ff))) { |
| 3254 | DHD_ERROR(("%s: count growing: last 0x%04x now " |
| 3255 | "0x%04x\n", |
| 3256 | __func__, lastrbc, ((hi << 8) + lo))); |
| 3257 | } |
| 3258 | lastrbc = (hi << 8) + lo; |
| 3259 | } |
| 3260 | |
| 3261 | if (!retries) { |
| 3262 | DHD_ERROR(("%s: count never zeroed: last 0x%04x\n", |
| 3263 | __func__, lastrbc)); |
| 3264 | } else { |
| 3265 | DHD_INFO(("%s: flush took %d iterations\n", __func__, |
| 3266 | (0xffff - retries))); |
| 3267 | } |
| 3268 | |
| 3269 | if (rtx) { |
| 3270 | bus->rxrtx++; |
| 3271 | W_SDREG(SMB_NAK, ®s->tosbmailbox, retries); |
| 3272 | bus->f1regdata++; |
| 3273 | if (retries <= retry_limit) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3274 | bus->rxskip = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3275 | } |
| 3276 | |
| 3277 | /* Clear partial in any case */ |
| 3278 | bus->nextlen = 0; |
| 3279 | |
| 3280 | /* If we can't reach the device, signal failure */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3281 | if (err || brcmf_sdcard_regfail(sdh)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3282 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 3283 | } |
| 3284 | |
| 3285 | static void |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3286 | 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] | 3287 | { |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 3288 | struct brcmf_sdio *sdh = bus->sdh; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3289 | uint rdlen, pad; |
| 3290 | |
| 3291 | int sdret; |
| 3292 | |
| 3293 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 3294 | |
| 3295 | /* Control data already received in aligned rxctl */ |
| 3296 | if ((bus->bus == SPI_BUS) && (!bus->usebufpool)) |
| 3297 | goto gotpkt; |
| 3298 | |
| 3299 | ASSERT(bus->rxbuf); |
| 3300 | /* Set rxctl for frame (w/optional alignment) */ |
| 3301 | bus->rxctl = bus->rxbuf; |
| 3302 | if (dhd_alignctl) { |
| 3303 | bus->rxctl += firstread; |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 3304 | pad = ((unsigned long)bus->rxctl % BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3305 | if (pad) |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 3306 | bus->rxctl += (BRCMF_SDALIGN - pad); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3307 | bus->rxctl -= firstread; |
| 3308 | } |
| 3309 | ASSERT(bus->rxctl >= bus->rxbuf); |
| 3310 | |
| 3311 | /* Copy the already-read portion over */ |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 3312 | memcpy(bus->rxctl, hdr, firstread); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3313 | if (len <= firstread) |
| 3314 | goto gotpkt; |
| 3315 | |
| 3316 | /* Copy the full data pkt in gSPI case and process ioctl. */ |
| 3317 | if (bus->bus == SPI_BUS) { |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 3318 | memcpy(bus->rxctl, hdr, len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3319 | goto gotpkt; |
| 3320 | } |
| 3321 | |
| 3322 | /* Raise rdlen to next SDIO block to avoid tail command */ |
| 3323 | rdlen = len - firstread; |
| 3324 | if (bus->roundup && bus->blocksize && (rdlen > bus->blocksize)) { |
| 3325 | pad = bus->blocksize - (rdlen % bus->blocksize); |
| 3326 | if ((pad <= bus->roundup) && (pad < bus->blocksize) && |
| 3327 | ((len + pad) < bus->dhd->maxctl)) |
| 3328 | rdlen += pad; |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 3329 | } else if (rdlen % BRCMF_SDALIGN) { |
| 3330 | rdlen += BRCMF_SDALIGN - (rdlen % BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3331 | } |
| 3332 | |
| 3333 | /* Satisfy length-alignment requirements */ |
| 3334 | if (forcealign && (rdlen & (ALIGNMENT - 1))) |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 3335 | rdlen = roundup(rdlen, ALIGNMENT); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3336 | |
| 3337 | /* Drop if the read is too big or it exceeds our maximum */ |
| 3338 | if ((rdlen + firstread) > bus->dhd->maxctl) { |
| 3339 | DHD_ERROR(("%s: %d-byte control read exceeds %d-byte buffer\n", |
| 3340 | __func__, rdlen, bus->dhd->maxctl)); |
| 3341 | bus->dhd->rx_errors++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3342 | brcmf_sdbrcm_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3343 | goto done; |
| 3344 | } |
| 3345 | |
| 3346 | if ((len - doff) > bus->dhd->maxctl) { |
| 3347 | DHD_ERROR(("%s: %d-byte ctl frame (%d-byte ctl data) exceeds " |
| 3348 | "%d-byte limit\n", |
| 3349 | __func__, len, (len - doff), bus->dhd->maxctl)); |
| 3350 | bus->dhd->rx_errors++; |
| 3351 | bus->rx_toolong++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3352 | brcmf_sdbrcm_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3353 | goto done; |
| 3354 | } |
| 3355 | |
| 3356 | /* Read remainder of frame body into the rxctl buffer */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3357 | sdret = brcmf_sdcard_recv_buf(sdh, brcmf_sdcard_cur_sbwad(sdh), |
| 3358 | SDIO_FUNC_2, |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 3359 | F2SYNC, (bus->rxctl + firstread), rdlen, |
| 3360 | NULL, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3361 | bus->f2rxdata++; |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 3362 | ASSERT(sdret != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3363 | |
| 3364 | /* Control frame failures need retransmission */ |
| 3365 | if (sdret < 0) { |
| 3366 | DHD_ERROR(("%s: read %d control bytes failed: %d\n", |
| 3367 | __func__, rdlen, sdret)); |
| 3368 | bus->rxc_errors++; /* dhd.rx_ctlerrs is higher level */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3369 | brcmf_sdbrcm_rxfail(bus, true, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3370 | goto done; |
| 3371 | } |
| 3372 | |
| 3373 | gotpkt: |
| 3374 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 3375 | #ifdef BCMDBG |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 3376 | if (DHD_BYTES_ON() && DHD_CTL_ON()) { |
| 3377 | printk(KERN_DEBUG "RxCtrl:\n"); |
| 3378 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, bus->rxctl, len); |
| 3379 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3380 | #endif |
| 3381 | |
| 3382 | /* Point to valid data and indicate its length */ |
| 3383 | bus->rxctl += doff; |
| 3384 | bus->rxlen = len - doff; |
| 3385 | |
| 3386 | done: |
| 3387 | /* Awake any waiters */ |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 3388 | brcmf_os_ioctl_resp_wake(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3389 | } |
| 3390 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3391 | static u8 brcmf_sdbrcm_rxglom(dhd_bus_t *bus, u8 rxseq) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3392 | { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3393 | u16 dlen, totlen; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3394 | u8 *dptr, num = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3395 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3396 | u16 sublen, check; |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 3397 | struct sk_buff *pfirst, *plast, *pnext, *save_pfirst; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3398 | |
| 3399 | int errcode; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3400 | u8 chan, seq, doff, sfdoff; |
| 3401 | u8 txmax; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3402 | |
| 3403 | int ifidx = 0; |
| 3404 | bool usechain = bus->use_rxchain; |
| 3405 | |
| 3406 | /* If packets, issue read(s) and send up packet chain */ |
| 3407 | /* Return sequence numbers consumed? */ |
| 3408 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3409 | 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] | 3410 | bus->glom)); |
| 3411 | |
| 3412 | /* If there's a descriptor, generate the packet chain */ |
| 3413 | if (bus->glomd) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3414 | pfirst = plast = pnext = NULL; |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3415 | dlen = (u16) (bus->glomd->len); |
| 3416 | dptr = bus->glomd->data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3417 | if (!dlen || (dlen & 1)) { |
| 3418 | DHD_ERROR(("%s: bad glomd len(%d), ignore descriptor\n", |
| 3419 | __func__, dlen)); |
| 3420 | dlen = 0; |
| 3421 | } |
| 3422 | |
| 3423 | for (totlen = num = 0; dlen; num++) { |
| 3424 | /* Get (and move past) next length */ |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 3425 | sublen = get_unaligned_le16(dptr); |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3426 | dlen -= sizeof(u16); |
| 3427 | dptr += sizeof(u16); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3428 | if ((sublen < SDPCM_HDRLEN) || |
| 3429 | ((num == 0) && (sublen < (2 * SDPCM_HDRLEN)))) { |
| 3430 | DHD_ERROR(("%s: descriptor len %d bad: %d\n", |
| 3431 | __func__, num, sublen)); |
| 3432 | pnext = NULL; |
| 3433 | break; |
| 3434 | } |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 3435 | if (sublen % BRCMF_SDALIGN) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3436 | DHD_ERROR(("%s: sublen %d not multiple of %d\n", |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 3437 | __func__, sublen, BRCMF_SDALIGN)); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3438 | usechain = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3439 | } |
| 3440 | totlen += sublen; |
| 3441 | |
| 3442 | /* For last frame, adjust read len so total |
| 3443 | is a block multiple */ |
| 3444 | if (!dlen) { |
| 3445 | sublen += |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 3446 | (roundup(totlen, bus->blocksize) - totlen); |
| 3447 | totlen = roundup(totlen, bus->blocksize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3448 | } |
| 3449 | |
| 3450 | /* Allocate/chain packet for next subframe */ |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 3451 | pnext = brcmu_pkt_buf_get_skb(sublen + BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3452 | if (pnext == NULL) { |
Henry Ptasinski | b33f0e2 | 2011-05-10 22:25:29 +0200 | [diff] [blame] | 3453 | DHD_ERROR(("%s: bcm_pkt_buf_get_skb failed, " |
| 3454 | "num %d len %d\n", __func__, |
| 3455 | num, sublen)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3456 | break; |
| 3457 | } |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3458 | ASSERT(!(pnext->prev)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3459 | if (!pfirst) { |
| 3460 | ASSERT(!plast); |
| 3461 | pfirst = plast = pnext; |
| 3462 | } else { |
| 3463 | ASSERT(plast); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3464 | plast->next = pnext; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3465 | plast = pnext; |
| 3466 | } |
| 3467 | |
| 3468 | /* Adhere to start alignment requirements */ |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 3469 | PKTALIGN(pnext, sublen, BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3470 | } |
| 3471 | |
| 3472 | /* If all allocations succeeded, save packet chain |
| 3473 | in bus structure */ |
| 3474 | if (pnext) { |
| 3475 | DHD_GLOM(("%s: allocated %d-byte packet chain for %d " |
| 3476 | "subframes\n", __func__, totlen, num)); |
| 3477 | if (DHD_GLOM_ON() && bus->nextlen) { |
| 3478 | if (totlen != bus->nextlen) { |
| 3479 | DHD_GLOM(("%s: glomdesc mismatch: nextlen %d glomdesc %d " "rxseq %d\n", |
| 3480 | __func__, bus->nextlen, |
| 3481 | totlen, rxseq)); |
| 3482 | } |
| 3483 | } |
| 3484 | bus->glom = pfirst; |
| 3485 | pfirst = pnext = NULL; |
| 3486 | } else { |
| 3487 | if (pfirst) |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3488 | brcmu_pkt_buf_free_skb(pfirst); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3489 | bus->glom = NULL; |
| 3490 | num = 0; |
| 3491 | } |
| 3492 | |
| 3493 | /* Done with descriptor packet */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3494 | brcmu_pkt_buf_free_skb(bus->glomd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3495 | bus->glomd = NULL; |
| 3496 | bus->nextlen = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3497 | } |
| 3498 | |
| 3499 | /* Ok -- either we just generated a packet chain, |
| 3500 | or had one from before */ |
| 3501 | if (bus->glom) { |
| 3502 | if (DHD_GLOM_ON()) { |
| 3503 | DHD_GLOM(("%s: try superframe read, packet chain:\n", |
| 3504 | __func__)); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3505 | for (pnext = bus->glom; pnext; pnext = pnext->next) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3506 | DHD_GLOM((" %p: %p len 0x%04x (%d)\n", |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3507 | pnext, (u8 *) (pnext->data), |
| 3508 | pnext->len, pnext->len)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3509 | } |
| 3510 | } |
| 3511 | |
| 3512 | pfirst = bus->glom; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3513 | dlen = (u16) brcmu_pkttotlen(pfirst); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3514 | |
| 3515 | /* Do an SDIO read for the superframe. Configurable iovar to |
| 3516 | * read directly into the chained packet, or allocate a large |
| 3517 | * packet and and copy into the chain. |
| 3518 | */ |
| 3519 | if (usechain) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3520 | errcode = brcmf_sdcard_recv_buf(bus->sdh, |
| 3521 | brcmf_sdcard_cur_sbwad(bus->sdh), |
| 3522 | SDIO_FUNC_2, |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 3523 | F2SYNC, (u8 *) pfirst->data, dlen, |
| 3524 | pfirst, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3525 | } else if (bus->dataptr) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3526 | errcode = brcmf_sdcard_recv_buf(bus->sdh, |
| 3527 | brcmf_sdcard_cur_sbwad(bus->sdh), |
| 3528 | SDIO_FUNC_2, |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 3529 | F2SYNC, bus->dataptr, dlen, |
| 3530 | NULL, NULL, NULL); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3531 | sublen = (u16) brcmu_pktfrombuf(pfirst, 0, dlen, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3532 | bus->dataptr); |
| 3533 | if (sublen != dlen) { |
| 3534 | DHD_ERROR(("%s: FAILED TO COPY, dlen %d sublen %d\n", |
| 3535 | __func__, dlen, sublen)); |
| 3536 | errcode = -1; |
| 3537 | } |
| 3538 | pnext = NULL; |
| 3539 | } else { |
| 3540 | DHD_ERROR(("COULDN'T ALLOC %d-BYTE GLOM, FORCE FAILURE\n", |
| 3541 | dlen)); |
| 3542 | errcode = -1; |
| 3543 | } |
| 3544 | bus->f2rxdata++; |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 3545 | ASSERT(errcode != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3546 | |
| 3547 | /* On failure, kill the superframe, allow a couple retries */ |
| 3548 | if (errcode < 0) { |
| 3549 | DHD_ERROR(("%s: glom read of %d bytes failed: %d\n", |
| 3550 | __func__, dlen, errcode)); |
| 3551 | bus->dhd->rx_errors++; |
| 3552 | |
| 3553 | if (bus->glomerr++ < 3) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3554 | brcmf_sdbrcm_rxfail(bus, true, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3555 | } else { |
| 3556 | bus->glomerr = 0; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3557 | brcmf_sdbrcm_rxfail(bus, true, false); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3558 | brcmu_pkt_buf_free_skb(bus->glom); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3559 | bus->rxglomfail++; |
| 3560 | bus->glom = NULL; |
| 3561 | } |
| 3562 | return 0; |
| 3563 | } |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 3564 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3565 | if (DHD_GLOM_ON()) { |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 3566 | printk(KERN_DEBUG "SUPERFRAME:\n"); |
| 3567 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 3568 | pfirst->data, min_t(int, pfirst->len, 48)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3569 | } |
| 3570 | #endif |
| 3571 | |
| 3572 | /* Validate the superframe header */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3573 | dptr = (u8 *) (pfirst->data); |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 3574 | sublen = get_unaligned_le16(dptr); |
| 3575 | check = get_unaligned_le16(dptr + sizeof(u16)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3576 | |
| 3577 | chan = SDPCM_PACKET_CHANNEL(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3578 | seq = SDPCM_PACKET_SEQUENCE(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3579 | bus->nextlen = dptr[SDPCM_FRAMETAG_LEN + SDPCM_NEXTLEN_OFFSET]; |
| 3580 | if ((bus->nextlen << 4) > MAX_RX_DATASZ) { |
| 3581 | DHD_INFO(("%s: nextlen too large (%d) seq %d\n", |
| 3582 | __func__, bus->nextlen, seq)); |
| 3583 | bus->nextlen = 0; |
| 3584 | } |
| 3585 | doff = SDPCM_DOFFSET_VALUE(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3586 | txmax = SDPCM_WINDOW_VALUE(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3587 | |
| 3588 | errcode = 0; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3589 | if ((u16)~(sublen ^ check)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3590 | DHD_ERROR(("%s (superframe): HW hdr error: len/check " |
| 3591 | "0x%04x/0x%04x\n", __func__, sublen, check)); |
| 3592 | errcode = -1; |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 3593 | } else if (roundup(sublen, bus->blocksize) != dlen) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3594 | DHD_ERROR(("%s (superframe): len 0x%04x, rounded " |
| 3595 | "0x%04x, expect 0x%04x\n", |
| 3596 | __func__, sublen, |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 3597 | roundup(sublen, bus->blocksize), dlen)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3598 | errcode = -1; |
| 3599 | } else if (SDPCM_PACKET_CHANNEL(&dptr[SDPCM_FRAMETAG_LEN]) != |
| 3600 | SDPCM_GLOM_CHANNEL) { |
| 3601 | DHD_ERROR(("%s (superframe): bad channel %d\n", |
| 3602 | __func__, |
| 3603 | SDPCM_PACKET_CHANNEL(&dptr |
| 3604 | [SDPCM_FRAMETAG_LEN]))); |
| 3605 | errcode = -1; |
| 3606 | } else if (SDPCM_GLOMDESC(&dptr[SDPCM_FRAMETAG_LEN])) { |
| 3607 | DHD_ERROR(("%s (superframe): got second descriptor?\n", |
| 3608 | __func__)); |
| 3609 | errcode = -1; |
| 3610 | } else if ((doff < SDPCM_HDRLEN) || |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3611 | (doff > (pfirst->len - SDPCM_HDRLEN))) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3612 | DHD_ERROR(("%s (superframe): Bad data offset %d: HW %d " |
| 3613 | "pkt %d min %d\n", |
| 3614 | __func__, doff, sublen, |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3615 | pfirst->len, SDPCM_HDRLEN)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3616 | errcode = -1; |
| 3617 | } |
| 3618 | |
| 3619 | /* Check sequence number of superframe SW header */ |
| 3620 | if (rxseq != seq) { |
| 3621 | DHD_INFO(("%s: (superframe) rx_seq %d, expected %d\n", |
| 3622 | __func__, seq, rxseq)); |
| 3623 | bus->rx_badseq++; |
| 3624 | rxseq = seq; |
| 3625 | } |
| 3626 | |
| 3627 | /* Check window for sanity */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3628 | if ((u8) (txmax - bus->tx_seq) > 0x40) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3629 | DHD_ERROR(("%s: unlikely tx max %d with tx_seq %d\n", |
| 3630 | __func__, txmax, bus->tx_seq)); |
| 3631 | txmax = bus->tx_seq + 2; |
| 3632 | } |
| 3633 | bus->tx_max = txmax; |
| 3634 | |
| 3635 | /* Remove superframe header, remember offset */ |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 3636 | skb_pull(pfirst, doff); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3637 | sfdoff = doff; |
| 3638 | |
| 3639 | /* Validate all the subframe headers */ |
| 3640 | for (num = 0, pnext = pfirst; pnext && !errcode; |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3641 | num++, pnext = pnext->next) { |
| 3642 | dptr = (u8 *) (pnext->data); |
| 3643 | dlen = (u16) (pnext->len); |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 3644 | sublen = get_unaligned_le16(dptr); |
| 3645 | check = get_unaligned_le16(dptr + sizeof(u16)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3646 | chan = SDPCM_PACKET_CHANNEL(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3647 | doff = SDPCM_DOFFSET_VALUE(&dptr[SDPCM_FRAMETAG_LEN]); |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 3648 | #ifdef BCMDBG |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 3649 | if (DHD_GLOM_ON()) { |
| 3650 | printk(KERN_DEBUG "subframe:\n"); |
| 3651 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 3652 | dptr, 32); |
| 3653 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3654 | #endif |
| 3655 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3656 | if ((u16)~(sublen ^ check)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3657 | DHD_ERROR(("%s (subframe %d): HW hdr error: " |
| 3658 | "len/check 0x%04x/0x%04x\n", |
| 3659 | __func__, num, sublen, check)); |
| 3660 | errcode = -1; |
| 3661 | } else if ((sublen > dlen) || (sublen < SDPCM_HDRLEN)) { |
| 3662 | DHD_ERROR(("%s (subframe %d): length mismatch: " |
| 3663 | "len 0x%04x, expect 0x%04x\n", |
| 3664 | __func__, num, sublen, dlen)); |
| 3665 | errcode = -1; |
| 3666 | } else if ((chan != SDPCM_DATA_CHANNEL) && |
| 3667 | (chan != SDPCM_EVENT_CHANNEL)) { |
| 3668 | DHD_ERROR(("%s (subframe %d): bad channel %d\n", |
| 3669 | __func__, num, chan)); |
| 3670 | errcode = -1; |
| 3671 | } else if ((doff < SDPCM_HDRLEN) || (doff > sublen)) { |
| 3672 | DHD_ERROR(("%s (subframe %d): Bad data offset %d: HW %d min %d\n", |
| 3673 | __func__, num, doff, sublen, |
| 3674 | SDPCM_HDRLEN)); |
| 3675 | errcode = -1; |
| 3676 | } |
| 3677 | } |
| 3678 | |
| 3679 | if (errcode) { |
| 3680 | /* Terminate frame on error, request |
| 3681 | a couple retries */ |
| 3682 | if (bus->glomerr++ < 3) { |
| 3683 | /* Restore superframe header space */ |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 3684 | skb_push(pfirst, sfdoff); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3685 | brcmf_sdbrcm_rxfail(bus, true, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3686 | } else { |
| 3687 | bus->glomerr = 0; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3688 | brcmf_sdbrcm_rxfail(bus, true, false); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3689 | brcmu_pkt_buf_free_skb(bus->glom); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3690 | bus->rxglomfail++; |
| 3691 | bus->glom = NULL; |
| 3692 | } |
| 3693 | bus->nextlen = 0; |
| 3694 | return 0; |
| 3695 | } |
| 3696 | |
| 3697 | /* Basic SD framing looks ok - process each packet (header) */ |
| 3698 | save_pfirst = pfirst; |
| 3699 | bus->glom = NULL; |
| 3700 | plast = NULL; |
| 3701 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3702 | for (num = 0; pfirst; rxseq++, pfirst = pnext) { |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3703 | pnext = pfirst->next; |
| 3704 | pfirst->next = NULL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3705 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3706 | dptr = (u8 *) (pfirst->data); |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 3707 | sublen = get_unaligned_le16(dptr); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3708 | chan = SDPCM_PACKET_CHANNEL(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3709 | seq = SDPCM_PACKET_SEQUENCE(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3710 | doff = SDPCM_DOFFSET_VALUE(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3711 | |
| 3712 | DHD_GLOM(("%s: Get subframe %d, %p(%p/%d), sublen %d " |
| 3713 | "chan %d seq %d\n", |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3714 | __func__, num, pfirst, pfirst->data, |
| 3715 | pfirst->len, sublen, chan, seq)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3716 | |
| 3717 | ASSERT((chan == SDPCM_DATA_CHANNEL) |
| 3718 | || (chan == SDPCM_EVENT_CHANNEL)); |
| 3719 | |
| 3720 | if (rxseq != seq) { |
| 3721 | DHD_GLOM(("%s: rx_seq %d, expected %d\n", |
| 3722 | __func__, seq, rxseq)); |
| 3723 | bus->rx_badseq++; |
| 3724 | rxseq = seq; |
| 3725 | } |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 3726 | #ifdef BCMDBG |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 3727 | if (DHD_BYTES_ON() && DHD_DATA_ON()) { |
| 3728 | printk(KERN_DEBUG "Rx Subframe Data:\n"); |
| 3729 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 3730 | dptr, dlen); |
| 3731 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3732 | #endif |
| 3733 | |
Arend van Spriel | 2cb8ada | 2010-11-18 20:46:44 +0100 | [diff] [blame] | 3734 | __skb_trim(pfirst, sublen); |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 3735 | skb_pull(pfirst, doff); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3736 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3737 | if (pfirst->len == 0) { |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3738 | brcmu_pkt_buf_free_skb(pfirst); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3739 | if (plast) { |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3740 | plast->next = pnext; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3741 | } else { |
| 3742 | ASSERT(save_pfirst == pfirst); |
| 3743 | save_pfirst = pnext; |
| 3744 | } |
| 3745 | continue; |
Arend van Spriel | 0aa94b8 | 2011-06-29 16:47:13 -0700 | [diff] [blame] | 3746 | } else if (brcmf_proto_hdrpull(bus->dhd, &ifidx, pfirst) |
| 3747 | != 0) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3748 | DHD_ERROR(("%s: rx protocol error\n", |
| 3749 | __func__)); |
| 3750 | bus->dhd->rx_errors++; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3751 | brcmu_pkt_buf_free_skb(pfirst); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3752 | if (plast) { |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3753 | plast->next = pnext; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3754 | } else { |
| 3755 | ASSERT(save_pfirst == pfirst); |
| 3756 | save_pfirst = pnext; |
| 3757 | } |
| 3758 | continue; |
| 3759 | } |
| 3760 | |
| 3761 | /* this packet will go up, link back into |
| 3762 | chain and count it */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3763 | pfirst->next = pnext; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3764 | plast = pfirst; |
| 3765 | num++; |
| 3766 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 3767 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3768 | if (DHD_GLOM_ON()) { |
| 3769 | DHD_GLOM(("%s subframe %d to stack, %p(%p/%d) " |
| 3770 | "nxt/lnk %p/%p\n", |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3771 | __func__, num, pfirst, pfirst->data, |
| 3772 | pfirst->len, pfirst->next, |
| 3773 | pfirst->prev)); |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 3774 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 3775 | pfirst->data, |
| 3776 | min_t(int, pfirst->len, 32)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3777 | } |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 3778 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3779 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3780 | if (num) { |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 3781 | brcmf_os_sdunlock(bus->dhd); |
| 3782 | brcmf_rx_frame(bus->dhd, ifidx, save_pfirst, num); |
| 3783 | brcmf_os_sdlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3784 | } |
| 3785 | |
| 3786 | bus->rxglomframes++; |
| 3787 | bus->rxglompkts += num; |
| 3788 | } |
| 3789 | return num; |
| 3790 | } |
| 3791 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3792 | /* Return true if there may be more frames to read */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3793 | static uint |
| 3794 | brcmf_sdbrcm_readframes(dhd_bus_t *bus, uint maxframes, bool *finished) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3795 | { |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 3796 | struct brcmf_sdio *sdh = bus->sdh; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3797 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3798 | u16 len, check; /* Extracted hardware header fields */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3799 | u8 chan, seq, doff; /* Extracted software header fields */ |
| 3800 | u8 fcbits; /* Extracted fcbits from software header */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3801 | |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 3802 | struct sk_buff *pkt; /* Packet for event or data frames */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3803 | u16 pad; /* Number of pad bytes to read */ |
| 3804 | u16 rdlen; /* Total number of bytes to read */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3805 | u8 rxseq; /* Next sequence number to expect */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3806 | uint rxleft = 0; /* Remaining number of frames allowed */ |
| 3807 | int sdret; /* Return code from bcmsdh calls */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3808 | u8 txmax; /* Maximum tx sequence offered */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3809 | bool len_consistent; /* Result of comparing readahead len and |
| 3810 | len from hw-hdr */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3811 | u8 *rxbuf; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3812 | int ifidx = 0; |
| 3813 | uint rxcount = 0; /* Total frames read */ |
| 3814 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 3815 | #if defined(BCMDBG) || defined(SDTEST) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3816 | bool sdtest = false; /* To limit message spew from test mode */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3817 | #endif |
| 3818 | |
| 3819 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 3820 | |
| 3821 | ASSERT(maxframes); |
| 3822 | |
| 3823 | #ifdef SDTEST |
| 3824 | /* Allow pktgen to override maxframes */ |
| 3825 | if (bus->pktgen_count && (bus->pktgen_mode == DHD_PKTGEN_RECV)) { |
| 3826 | maxframes = bus->pktgen_count; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3827 | sdtest = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3828 | } |
| 3829 | #endif |
| 3830 | |
| 3831 | /* Not finished unless we encounter no more frames indication */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3832 | *finished = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3833 | |
| 3834 | for (rxseq = bus->rx_seq, rxleft = maxframes; |
| 3835 | !bus->rxskip && rxleft && bus->dhd->busstate != DHD_BUS_DOWN; |
| 3836 | rxseq++, rxleft--) { |
| 3837 | |
| 3838 | /* Handle glomming separately */ |
| 3839 | if (bus->glom || bus->glomd) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3840 | u8 cnt; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3841 | DHD_GLOM(("%s: calling rxglom: glomd %p, glom %p\n", |
| 3842 | __func__, bus->glomd, bus->glom)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3843 | cnt = brcmf_sdbrcm_rxglom(bus, rxseq); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3844 | DHD_GLOM(("%s: rxglom returned %d\n", __func__, cnt)); |
| 3845 | rxseq += cnt - 1; |
| 3846 | rxleft = (rxleft > cnt) ? (rxleft - cnt) : 1; |
| 3847 | continue; |
| 3848 | } |
| 3849 | |
| 3850 | /* Try doing single read if we can */ |
| 3851 | if (dhd_readahead && bus->nextlen) { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3852 | u16 nextlen = bus->nextlen; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3853 | bus->nextlen = 0; |
| 3854 | |
| 3855 | if (bus->bus == SPI_BUS) { |
| 3856 | rdlen = len = nextlen; |
| 3857 | } else { |
| 3858 | rdlen = len = nextlen << 4; |
| 3859 | |
| 3860 | /* Pad read to blocksize for efficiency */ |
| 3861 | if (bus->roundup && bus->blocksize |
| 3862 | && (rdlen > bus->blocksize)) { |
| 3863 | pad = |
| 3864 | bus->blocksize - |
| 3865 | (rdlen % bus->blocksize); |
| 3866 | if ((pad <= bus->roundup) |
| 3867 | && (pad < bus->blocksize) |
| 3868 | && ((rdlen + pad + firstread) < |
| 3869 | MAX_RX_DATASZ)) |
| 3870 | rdlen += pad; |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 3871 | } else if (rdlen % BRCMF_SDALIGN) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3872 | rdlen += |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 3873 | BRCMF_SDALIGN - (rdlen % BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3874 | } |
| 3875 | } |
| 3876 | |
| 3877 | /* We use bus->rxctl buffer in WinXP for initial |
| 3878 | * control pkt receives. |
| 3879 | * Later we use buffer-poll for data as well |
| 3880 | * as control packets. |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3881 | * This is required because dhd receives full |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3882 | * frame in gSPI unlike SDIO. |
| 3883 | * After the frame is received we have to |
| 3884 | * distinguish whether it is data |
| 3885 | * or non-data frame. |
| 3886 | */ |
| 3887 | /* Allocate a packet buffer */ |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 3888 | pkt = brcmu_pkt_buf_get_skb(rdlen + BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3889 | if (!pkt) { |
| 3890 | if (bus->bus == SPI_BUS) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3891 | bus->usebufpool = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3892 | bus->rxctl = bus->rxbuf; |
| 3893 | if (dhd_alignctl) { |
| 3894 | bus->rxctl += firstread; |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 3895 | pad = ((unsigned long)bus->rxctl % |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 3896 | BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3897 | if (pad) |
| 3898 | bus->rxctl += |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 3899 | (BRCMF_SDALIGN - pad); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3900 | bus->rxctl -= firstread; |
| 3901 | } |
| 3902 | ASSERT(bus->rxctl >= bus->rxbuf); |
| 3903 | rxbuf = bus->rxctl; |
| 3904 | /* Read the entire frame */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3905 | sdret = brcmf_sdcard_recv_buf(sdh, |
| 3906 | brcmf_sdcard_cur_sbwad(sdh), |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 3907 | SDIO_FUNC_2, F2SYNC, |
| 3908 | rxbuf, rdlen, |
| 3909 | NULL, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3910 | bus->f2rxdata++; |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 3911 | ASSERT(sdret != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3912 | |
| 3913 | /* Control frame failures need |
| 3914 | retransmission */ |
| 3915 | if (sdret < 0) { |
| 3916 | DHD_ERROR(("%s: read %d control bytes failed: %d\n", |
| 3917 | __func__, |
| 3918 | rdlen, sdret)); |
| 3919 | /* dhd.rx_ctlerrs is higher */ |
| 3920 | bus->rxc_errors++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3921 | brcmf_sdbrcm_rxfail(bus, true, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3922 | (bus->bus == |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3923 | SPI_BUS) ? false |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3924 | : true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3925 | continue; |
| 3926 | } |
| 3927 | } else { |
| 3928 | /* Give up on data, |
| 3929 | request rtx of events */ |
Arend van Spriel | cda64a5 | 2011-05-10 22:25:33 +0200 | [diff] [blame] | 3930 | DHD_ERROR(("%s (nextlen): " |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3931 | "brcmu_pkt_buf_get_skb " |
| 3932 | "failed:" |
Arend van Spriel | cda64a5 | 2011-05-10 22:25:33 +0200 | [diff] [blame] | 3933 | " len %d rdlen %d expected" |
| 3934 | " rxseq %d\n", __func__, |
| 3935 | len, rdlen, rxseq)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3936 | continue; |
| 3937 | } |
| 3938 | } else { |
| 3939 | if (bus->bus == SPI_BUS) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3940 | bus->usebufpool = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3941 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3942 | ASSERT(!(pkt->prev)); |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 3943 | PKTALIGN(pkt, rdlen, BRCMF_SDALIGN); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3944 | rxbuf = (u8 *) (pkt->data); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3945 | /* Read the entire frame */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3946 | sdret = brcmf_sdcard_recv_buf(sdh, |
| 3947 | brcmf_sdcard_cur_sbwad(sdh), |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3948 | SDIO_FUNC_2, F2SYNC, |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 3949 | rxbuf, rdlen, |
| 3950 | pkt, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3951 | bus->f2rxdata++; |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 3952 | ASSERT(sdret != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3953 | |
| 3954 | if (sdret < 0) { |
| 3955 | DHD_ERROR(("%s (nextlen): read %d bytes failed: %d\n", |
| 3956 | __func__, rdlen, sdret)); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3957 | brcmu_pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3958 | bus->dhd->rx_errors++; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3959 | /* Force retry w/normal header read. |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3960 | * Don't attempt NAK for |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3961 | * gSPI |
| 3962 | */ |
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 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3970 | |
| 3971 | /* Now check the header */ |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 3972 | memcpy(bus->rxhdr, rxbuf, SDPCM_HDRLEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3973 | |
| 3974 | /* Extract hardware header fields */ |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 3975 | len = get_unaligned_le16(bus->rxhdr); |
| 3976 | check = get_unaligned_le16(bus->rxhdr + sizeof(u16)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3977 | |
| 3978 | /* All zeros means readahead info was bad */ |
| 3979 | if (!(len | check)) { |
| 3980 | DHD_INFO(("%s (nextlen): read zeros in HW " |
| 3981 | "header???\n", __func__)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3982 | brcmf_sdbrcm_pktfree2(bus, pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3983 | continue; |
| 3984 | } |
| 3985 | |
| 3986 | /* Validate check bytes */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3987 | if ((u16)~(len ^ check)) { |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 3988 | DHD_ERROR(("%s (nextlen): HW hdr error:" |
| 3989 | " nextlen/len/check" |
| 3990 | " 0x%04x/0x%04x/0x%04x\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3991 | __func__, nextlen, len, check)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3992 | bus->rx_badhdr++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3993 | brcmf_sdbrcm_rxfail(bus, false, false); |
| 3994 | brcmf_sdbrcm_pktfree2(bus, pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3995 | continue; |
| 3996 | } |
| 3997 | |
| 3998 | /* Validate frame length */ |
| 3999 | if (len < SDPCM_HDRLEN) { |
| 4000 | DHD_ERROR(("%s (nextlen): HW hdr length " |
| 4001 | "invalid: %d\n", __func__, len)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4002 | brcmf_sdbrcm_pktfree2(bus, pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4003 | continue; |
| 4004 | } |
| 4005 | |
| 4006 | /* Check for consistency withreadahead info */ |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 4007 | len_consistent = (nextlen != (roundup(len, 16) >> 4)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4008 | if (len_consistent) { |
| 4009 | /* Mismatch, force retry w/normal |
| 4010 | header (may be >4K) */ |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4011 | DHD_ERROR(("%s (nextlen): mismatch, " |
| 4012 | "nextlen %d len %d rnd %d; " |
| 4013 | "expected rxseq %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4014 | __func__, nextlen, |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 4015 | len, roundup(len, 16), rxseq)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4016 | brcmf_sdbrcm_rxfail(bus, true, |
| 4017 | bus->bus != SPI_BUS); |
| 4018 | brcmf_sdbrcm_pktfree2(bus, pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4019 | continue; |
| 4020 | } |
| 4021 | |
| 4022 | /* Extract software header fields */ |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4023 | chan = SDPCM_PACKET_CHANNEL( |
| 4024 | &bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 4025 | seq = SDPCM_PACKET_SEQUENCE( |
| 4026 | &bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 4027 | doff = SDPCM_DOFFSET_VALUE( |
| 4028 | &bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 4029 | txmax = SDPCM_WINDOW_VALUE( |
| 4030 | &bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4031 | |
| 4032 | bus->nextlen = |
| 4033 | bus->rxhdr[SDPCM_FRAMETAG_LEN + |
| 4034 | SDPCM_NEXTLEN_OFFSET]; |
| 4035 | if ((bus->nextlen << 4) > MAX_RX_DATASZ) { |
| 4036 | DHD_INFO(("%s (nextlen): got frame w/nextlen too large" " (%d), seq %d\n", |
| 4037 | __func__, bus->nextlen, seq)); |
| 4038 | bus->nextlen = 0; |
| 4039 | } |
| 4040 | |
| 4041 | bus->dhd->rx_readahead_cnt++; |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4042 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4043 | /* Handle Flow Control */ |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4044 | fcbits = SDPCM_FCMASK_VALUE( |
| 4045 | &bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4046 | |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4047 | if (bus->flowcontrol != fcbits) { |
| 4048 | if (~bus->flowcontrol & fcbits) |
| 4049 | bus->fc_xoff++; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4050 | |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4051 | if (bus->flowcontrol & ~fcbits) |
| 4052 | bus->fc_xon++; |
| 4053 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4054 | bus->fc_rcvd++; |
| 4055 | bus->flowcontrol = fcbits; |
| 4056 | } |
| 4057 | |
| 4058 | /* Check and update sequence number */ |
| 4059 | if (rxseq != seq) { |
| 4060 | DHD_INFO(("%s (nextlen): rx_seq %d, expected " |
| 4061 | "%d\n", __func__, seq, rxseq)); |
| 4062 | bus->rx_badseq++; |
| 4063 | rxseq = seq; |
| 4064 | } |
| 4065 | |
| 4066 | /* Check window for sanity */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4067 | if ((u8) (txmax - bus->tx_seq) > 0x40) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4068 | DHD_ERROR(("%s: got unlikely tx max %d with " |
| 4069 | "tx_seq %d\n", |
| 4070 | __func__, txmax, bus->tx_seq)); |
| 4071 | txmax = bus->tx_seq + 2; |
| 4072 | } |
| 4073 | bus->tx_max = txmax; |
| 4074 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 4075 | #ifdef BCMDBG |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 4076 | if (DHD_BYTES_ON() && DHD_DATA_ON()) { |
| 4077 | printk(KERN_DEBUG "Rx Data:\n"); |
| 4078 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 4079 | rxbuf, len); |
| 4080 | } else if (DHD_HDRS_ON()) { |
| 4081 | printk(KERN_DEBUG "RxHdr:\n"); |
| 4082 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 4083 | bus->rxhdr, SDPCM_HDRLEN); |
| 4084 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4085 | #endif |
| 4086 | |
| 4087 | if (chan == SDPCM_CONTROL_CHANNEL) { |
| 4088 | if (bus->bus == SPI_BUS) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4089 | brcmf_sdbrcm_read_control(bus, rxbuf, |
| 4090 | len, doff); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4091 | } else { |
| 4092 | DHD_ERROR(("%s (nextlen): readahead on control" " packet %d?\n", |
| 4093 | __func__, seq)); |
| 4094 | /* Force retry w/normal header read */ |
| 4095 | bus->nextlen = 0; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4096 | brcmf_sdbrcm_rxfail(bus, false, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4097 | } |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4098 | brcmf_sdbrcm_pktfree2(bus, pkt); |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4099 | continue; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4100 | } |
| 4101 | |
| 4102 | if ((bus->bus == SPI_BUS) && !bus->usebufpool) { |
| 4103 | DHD_ERROR(("Received %d bytes on %d channel. Running out of " "rx pktbuf's or not yet malloced.\n", |
| 4104 | len, chan)); |
| 4105 | continue; |
| 4106 | } |
| 4107 | |
| 4108 | /* Validate data offset */ |
| 4109 | if ((doff < SDPCM_HDRLEN) || (doff > len)) { |
| 4110 | DHD_ERROR(("%s (nextlen): bad data offset %d: HW len %d min %d\n", |
| 4111 | __func__, doff, len, SDPCM_HDRLEN)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4112 | brcmf_sdbrcm_rxfail(bus, false, false); |
| 4113 | brcmf_sdbrcm_pktfree2(bus, pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4114 | continue; |
| 4115 | } |
| 4116 | |
| 4117 | /* All done with this one -- now deliver the packet */ |
| 4118 | goto deliver; |
| 4119 | } |
| 4120 | /* gSPI frames should not be handled in fractions */ |
| 4121 | if (bus->bus == SPI_BUS) |
| 4122 | break; |
| 4123 | |
| 4124 | /* Read frame header (hardware and software) */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4125 | sdret = brcmf_sdcard_recv_buf(sdh, brcmf_sdcard_cur_sbwad(sdh), |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4126 | SDIO_FUNC_2, F2SYNC, bus->rxhdr, firstread, |
| 4127 | NULL, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4128 | bus->f2rxhdrs++; |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 4129 | ASSERT(sdret != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4130 | |
| 4131 | if (sdret < 0) { |
| 4132 | DHD_ERROR(("%s: RXHEADER FAILED: %d\n", __func__, |
| 4133 | sdret)); |
| 4134 | bus->rx_hdrfail++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4135 | brcmf_sdbrcm_rxfail(bus, true, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4136 | continue; |
| 4137 | } |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 4138 | #ifdef BCMDBG |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 4139 | if (DHD_BYTES_ON() || DHD_HDRS_ON()) { |
| 4140 | printk(KERN_DEBUG "RxHdr:\n"); |
| 4141 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 4142 | bus->rxhdr, SDPCM_HDRLEN); |
| 4143 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4144 | #endif |
| 4145 | |
| 4146 | /* Extract hardware header fields */ |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 4147 | len = get_unaligned_le16(bus->rxhdr); |
| 4148 | check = get_unaligned_le16(bus->rxhdr + sizeof(u16)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4149 | |
| 4150 | /* All zeros means no more frames */ |
| 4151 | if (!(len | check)) { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4152 | *finished = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4153 | break; |
| 4154 | } |
| 4155 | |
| 4156 | /* Validate check bytes */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4157 | if ((u16) ~(len ^ check)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4158 | DHD_ERROR(("%s: HW hdr err: len/check 0x%04x/0x%04x\n", |
| 4159 | __func__, len, check)); |
| 4160 | bus->rx_badhdr++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4161 | brcmf_sdbrcm_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4162 | continue; |
| 4163 | } |
| 4164 | |
| 4165 | /* Validate frame length */ |
| 4166 | if (len < SDPCM_HDRLEN) { |
| 4167 | DHD_ERROR(("%s: HW hdr length invalid: %d\n", |
| 4168 | __func__, len)); |
| 4169 | continue; |
| 4170 | } |
| 4171 | |
| 4172 | /* Extract software header fields */ |
| 4173 | chan = SDPCM_PACKET_CHANNEL(&bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 4174 | seq = SDPCM_PACKET_SEQUENCE(&bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 4175 | doff = SDPCM_DOFFSET_VALUE(&bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 4176 | txmax = SDPCM_WINDOW_VALUE(&bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 4177 | |
| 4178 | /* Validate data offset */ |
| 4179 | if ((doff < SDPCM_HDRLEN) || (doff > len)) { |
| 4180 | DHD_ERROR(("%s: Bad data offset %d: HW len %d, min %d " |
| 4181 | "seq %d\n", |
| 4182 | __func__, doff, len, SDPCM_HDRLEN, seq)); |
| 4183 | bus->rx_badhdr++; |
| 4184 | ASSERT(0); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4185 | brcmf_sdbrcm_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4186 | continue; |
| 4187 | } |
| 4188 | |
| 4189 | /* Save the readahead length if there is one */ |
| 4190 | bus->nextlen = |
| 4191 | bus->rxhdr[SDPCM_FRAMETAG_LEN + SDPCM_NEXTLEN_OFFSET]; |
| 4192 | if ((bus->nextlen << 4) > MAX_RX_DATASZ) { |
| 4193 | DHD_INFO(("%s (nextlen): got frame w/nextlen too large " |
| 4194 | "(%d), seq %d\n", |
| 4195 | __func__, bus->nextlen, seq)); |
| 4196 | bus->nextlen = 0; |
| 4197 | } |
| 4198 | |
| 4199 | /* Handle Flow Control */ |
| 4200 | fcbits = SDPCM_FCMASK_VALUE(&bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 4201 | |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4202 | if (bus->flowcontrol != fcbits) { |
| 4203 | if (~bus->flowcontrol & fcbits) |
| 4204 | bus->fc_xoff++; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4205 | |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4206 | if (bus->flowcontrol & ~fcbits) |
| 4207 | bus->fc_xon++; |
| 4208 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4209 | bus->fc_rcvd++; |
| 4210 | bus->flowcontrol = fcbits; |
| 4211 | } |
| 4212 | |
| 4213 | /* Check and update sequence number */ |
| 4214 | if (rxseq != seq) { |
| 4215 | DHD_INFO(("%s: rx_seq %d, expected %d\n", __func__, |
| 4216 | seq, rxseq)); |
| 4217 | bus->rx_badseq++; |
| 4218 | rxseq = seq; |
| 4219 | } |
| 4220 | |
| 4221 | /* Check window for sanity */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4222 | if ((u8) (txmax - bus->tx_seq) > 0x40) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4223 | DHD_ERROR(("%s: unlikely tx max %d with tx_seq %d\n", |
| 4224 | __func__, txmax, bus->tx_seq)); |
| 4225 | txmax = bus->tx_seq + 2; |
| 4226 | } |
| 4227 | bus->tx_max = txmax; |
| 4228 | |
| 4229 | /* Call a separate function for control frames */ |
| 4230 | if (chan == SDPCM_CONTROL_CHANNEL) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4231 | brcmf_sdbrcm_read_control(bus, bus->rxhdr, len, doff); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4232 | continue; |
| 4233 | } |
| 4234 | |
| 4235 | ASSERT((chan == SDPCM_DATA_CHANNEL) |
| 4236 | || (chan == SDPCM_EVENT_CHANNEL) |
| 4237 | || (chan == SDPCM_TEST_CHANNEL) |
| 4238 | || (chan == SDPCM_GLOM_CHANNEL)); |
| 4239 | |
| 4240 | /* Length to read */ |
| 4241 | rdlen = (len > firstread) ? (len - firstread) : 0; |
| 4242 | |
| 4243 | /* May pad read to blocksize for efficiency */ |
| 4244 | if (bus->roundup && bus->blocksize && |
| 4245 | (rdlen > bus->blocksize)) { |
| 4246 | pad = bus->blocksize - (rdlen % bus->blocksize); |
| 4247 | if ((pad <= bus->roundup) && (pad < bus->blocksize) && |
| 4248 | ((rdlen + pad + firstread) < MAX_RX_DATASZ)) |
| 4249 | rdlen += pad; |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 4250 | } else if (rdlen % BRCMF_SDALIGN) { |
| 4251 | rdlen += BRCMF_SDALIGN - (rdlen % BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4252 | } |
| 4253 | |
| 4254 | /* Satisfy length-alignment requirements */ |
| 4255 | if (forcealign && (rdlen & (ALIGNMENT - 1))) |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 4256 | rdlen = roundup(rdlen, ALIGNMENT); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4257 | |
| 4258 | if ((rdlen + firstread) > MAX_RX_DATASZ) { |
| 4259 | /* Too long -- skip this frame */ |
| 4260 | DHD_ERROR(("%s: too long: len %d rdlen %d\n", |
| 4261 | __func__, len, rdlen)); |
| 4262 | bus->dhd->rx_errors++; |
| 4263 | bus->rx_toolong++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4264 | brcmf_sdbrcm_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4265 | continue; |
| 4266 | } |
| 4267 | |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 4268 | pkt = brcmu_pkt_buf_get_skb(rdlen + firstread + BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4269 | if (!pkt) { |
| 4270 | /* Give up on data, request rtx of events */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4271 | DHD_ERROR(("%s: brcmu_pkt_buf_get_skb failed: rdlen %d" |
| 4272 | " chan %d\n", __func__, rdlen, chan)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4273 | bus->dhd->rx_dropped++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4274 | brcmf_sdbrcm_rxfail(bus, false, RETRYCHAN(chan)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4275 | continue; |
| 4276 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4277 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4278 | ASSERT(!(pkt->prev)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4279 | |
| 4280 | /* Leave room for what we already read, and align remainder */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4281 | ASSERT(firstread < pkt->len); |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 4282 | skb_pull(pkt, firstread); |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 4283 | PKTALIGN(pkt, rdlen, BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4284 | |
| 4285 | /* Read the remaining frame data */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4286 | sdret = brcmf_sdcard_recv_buf(sdh, brcmf_sdcard_cur_sbwad(sdh), |
| 4287 | SDIO_FUNC_2, F2SYNC, ((u8 *) (pkt->data)), |
| 4288 | rdlen, pkt, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4289 | bus->f2rxdata++; |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 4290 | ASSERT(sdret != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4291 | |
| 4292 | if (sdret < 0) { |
| 4293 | DHD_ERROR(("%s: read %d %s bytes failed: %d\n", |
| 4294 | __func__, rdlen, |
| 4295 | ((chan == |
| 4296 | SDPCM_EVENT_CHANNEL) ? "event" : ((chan == |
| 4297 | SDPCM_DATA_CHANNEL) |
| 4298 | ? "data" : "test")), |
| 4299 | sdret)); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4300 | brcmu_pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4301 | bus->dhd->rx_errors++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4302 | brcmf_sdbrcm_rxfail(bus, true, RETRYCHAN(chan)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4303 | continue; |
| 4304 | } |
| 4305 | |
| 4306 | /* Copy the already-read portion */ |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 4307 | skb_push(pkt, firstread); |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 4308 | memcpy(pkt->data, bus->rxhdr, firstread); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4309 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 4310 | #ifdef BCMDBG |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 4311 | if (DHD_BYTES_ON() && DHD_DATA_ON()) { |
| 4312 | printk(KERN_DEBUG "Rx Data:\n"); |
| 4313 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 4314 | pkt->data, len); |
| 4315 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4316 | #endif |
| 4317 | |
| 4318 | deliver: |
| 4319 | /* Save superframe descriptor and allocate packet frame */ |
| 4320 | if (chan == SDPCM_GLOM_CHANNEL) { |
| 4321 | if (SDPCM_GLOMDESC(&bus->rxhdr[SDPCM_FRAMETAG_LEN])) { |
| 4322 | DHD_GLOM(("%s: glom descriptor, %d bytes:\n", |
| 4323 | __func__, len)); |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 4324 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4325 | if (DHD_GLOM_ON()) { |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 4326 | printk(KERN_DEBUG "Glom Data:\n"); |
| 4327 | print_hex_dump_bytes("", |
| 4328 | DUMP_PREFIX_OFFSET, |
| 4329 | pkt->data, len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4330 | } |
| 4331 | #endif |
Arend van Spriel | 2cb8ada | 2010-11-18 20:46:44 +0100 | [diff] [blame] | 4332 | __skb_trim(pkt, len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4333 | ASSERT(doff == SDPCM_HDRLEN); |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 4334 | skb_pull(pkt, SDPCM_HDRLEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4335 | bus->glomd = pkt; |
| 4336 | } else { |
| 4337 | DHD_ERROR(("%s: glom superframe w/o " |
| 4338 | "descriptor!\n", __func__)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4339 | brcmf_sdbrcm_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4340 | } |
| 4341 | continue; |
| 4342 | } |
| 4343 | |
| 4344 | /* Fill in packet len and prio, deliver upward */ |
Arend van Spriel | 2cb8ada | 2010-11-18 20:46:44 +0100 | [diff] [blame] | 4345 | __skb_trim(pkt, len); |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 4346 | skb_pull(pkt, doff); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4347 | |
| 4348 | #ifdef SDTEST |
| 4349 | /* Test channel packets are processed separately */ |
| 4350 | if (chan == SDPCM_TEST_CHANNEL) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4351 | brcmf_sdbrcm_checkdied(bus, pkt, seq); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4352 | continue; |
| 4353 | } |
| 4354 | #endif /* SDTEST */ |
| 4355 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4356 | if (pkt->len == 0) { |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4357 | brcmu_pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4358 | continue; |
Arend van Spriel | 0aa94b8 | 2011-06-29 16:47:13 -0700 | [diff] [blame] | 4359 | } else if (brcmf_proto_hdrpull(bus->dhd, &ifidx, pkt) != 0) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4360 | DHD_ERROR(("%s: rx protocol error\n", __func__)); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4361 | brcmu_pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4362 | bus->dhd->rx_errors++; |
| 4363 | continue; |
| 4364 | } |
| 4365 | |
| 4366 | /* Unlock during rx call */ |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 4367 | brcmf_os_sdunlock(bus->dhd); |
| 4368 | brcmf_rx_frame(bus->dhd, ifidx, pkt, 1); |
| 4369 | brcmf_os_sdlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4370 | } |
| 4371 | rxcount = maxframes - rxleft; |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 4372 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4373 | /* Message if we hit the limit */ |
| 4374 | if (!rxleft && !sdtest) |
| 4375 | DHD_DATA(("%s: hit rx limit of %d frames\n", __func__, |
| 4376 | maxframes)); |
| 4377 | else |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 4378 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4379 | DHD_DATA(("%s: processed %d frames\n", __func__, rxcount)); |
| 4380 | /* Back off rxseq if awaiting rtx, update rx_seq */ |
| 4381 | if (bus->rxskip) |
| 4382 | rxseq--; |
| 4383 | bus->rx_seq = rxseq; |
| 4384 | |
| 4385 | return rxcount; |
| 4386 | } |
| 4387 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4388 | static u32 brcmf_sdbrcm_hostmail(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4389 | { |
Franky Lin | 597600a | 2011-06-01 13:45:39 +0200 | [diff] [blame] | 4390 | struct sdpcmd_regs *regs = bus->regs; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 4391 | u32 intstatus = 0; |
| 4392 | u32 hmb_data; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4393 | u8 fcbits; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4394 | uint retries = 0; |
| 4395 | |
| 4396 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 4397 | |
| 4398 | /* Read mailbox data and ack that we did so */ |
| 4399 | R_SDREG(hmb_data, ®s->tohostmailboxdata, retries); |
| 4400 | if (retries <= retry_limit) |
| 4401 | W_SDREG(SMB_INT_ACK, ®s->tosbmailbox, retries); |
| 4402 | bus->f1regdata += 2; |
| 4403 | |
| 4404 | /* Dongle recomposed rx frames, accept them again */ |
| 4405 | if (hmb_data & HMB_DATA_NAKHANDLED) { |
| 4406 | DHD_INFO(("Dongle reports NAK handled, expect rtx of %d\n", |
| 4407 | bus->rx_seq)); |
| 4408 | if (!bus->rxskip) |
| 4409 | DHD_ERROR(("%s: unexpected NAKHANDLED!\n", __func__)); |
| 4410 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4411 | bus->rxskip = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4412 | intstatus |= I_HMB_FRAME_IND; |
| 4413 | } |
| 4414 | |
| 4415 | /* |
| 4416 | * DEVREADY does not occur with gSPI. |
| 4417 | */ |
| 4418 | if (hmb_data & (HMB_DATA_DEVREADY | HMB_DATA_FWREADY)) { |
| 4419 | bus->sdpcm_ver = |
| 4420 | (hmb_data & HMB_DATA_VERSION_MASK) >> |
| 4421 | HMB_DATA_VERSION_SHIFT; |
| 4422 | if (bus->sdpcm_ver != SDPCM_PROT_VERSION) |
| 4423 | DHD_ERROR(("Version mismatch, dongle reports %d, " |
| 4424 | "expecting %d\n", |
| 4425 | bus->sdpcm_ver, SDPCM_PROT_VERSION)); |
| 4426 | else |
| 4427 | DHD_INFO(("Dongle ready, protocol version %d\n", |
| 4428 | bus->sdpcm_ver)); |
| 4429 | } |
| 4430 | |
| 4431 | /* |
| 4432 | * 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] | 4433 | * method isn't used any more. |
| 4434 | * remaining backward compatible with older dongles. |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4435 | */ |
| 4436 | if (hmb_data & HMB_DATA_FC) { |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4437 | fcbits = (hmb_data & HMB_DATA_FCDATA_MASK) >> |
| 4438 | HMB_DATA_FCDATA_SHIFT; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4439 | |
| 4440 | if (fcbits & ~bus->flowcontrol) |
| 4441 | bus->fc_xoff++; |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4442 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4443 | if (bus->flowcontrol & ~fcbits) |
| 4444 | bus->fc_xon++; |
| 4445 | |
| 4446 | bus->fc_rcvd++; |
| 4447 | bus->flowcontrol = fcbits; |
| 4448 | } |
| 4449 | |
| 4450 | /* Shouldn't be any others */ |
| 4451 | if (hmb_data & ~(HMB_DATA_DEVREADY | |
| 4452 | HMB_DATA_NAKHANDLED | |
| 4453 | HMB_DATA_FC | |
| 4454 | HMB_DATA_FWREADY | |
| 4455 | HMB_DATA_FCDATA_MASK | HMB_DATA_VERSION_MASK)) { |
| 4456 | DHD_ERROR(("Unknown mailbox data content: 0x%02x\n", hmb_data)); |
| 4457 | } |
| 4458 | |
| 4459 | return intstatus; |
| 4460 | } |
| 4461 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4462 | bool brcmf_sdbrcm_dpc(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4463 | { |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 4464 | struct brcmf_sdio *sdh = bus->sdh; |
Franky Lin | 597600a | 2011-06-01 13:45:39 +0200 | [diff] [blame] | 4465 | struct sdpcmd_regs *regs = bus->regs; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 4466 | u32 intstatus, newstatus = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4467 | uint retries = 0; |
Arend van Spriel | 7af9d0c | 2011-06-29 16:47:19 -0700 | [diff] [blame] | 4468 | uint rxlimit = brcmf_rxbound; /* Rx frames to read before resched */ |
| 4469 | uint txlimit = brcmf_txbound; /* Tx frames to send before resched */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4470 | uint framecnt = 0; /* Temporary counter of tx/rx frames */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4471 | bool rxdone = true; /* Flag for no more read data */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4472 | bool resched = false; /* Flag indicating resched wanted */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4473 | |
| 4474 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 4475 | |
| 4476 | /* Start with leftover status bits */ |
| 4477 | intstatus = bus->intstatus; |
| 4478 | |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 4479 | brcmf_os_sdlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4480 | |
| 4481 | /* If waiting for HTAVAIL, check status */ |
| 4482 | if (bus->clkstate == CLK_PENDING) { |
| 4483 | int err; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4484 | u8 clkctl, devctl = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4485 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 4486 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4487 | /* Check for inconsistent device control */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4488 | devctl = brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
| 4489 | SBSDIO_DEVICE_CTL, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4490 | if (err) { |
| 4491 | DHD_ERROR(("%s: error reading DEVCTL: %d\n", |
| 4492 | __func__, err)); |
| 4493 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 4494 | } else { |
| 4495 | ASSERT(devctl & SBSDIO_DEVCTL_CA_INT_ONLY); |
| 4496 | } |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 4497 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4498 | |
| 4499 | /* Read CSR, if clock on switch to AVAIL, else ignore */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4500 | clkctl = brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
| 4501 | SBSDIO_FUNC1_CHIPCLKCSR, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4502 | if (err) { |
| 4503 | DHD_ERROR(("%s: error reading CSR: %d\n", __func__, |
| 4504 | err)); |
| 4505 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 4506 | } |
| 4507 | |
| 4508 | DHD_INFO(("DPC: PENDING, devctl 0x%02x clkctl 0x%02x\n", devctl, |
| 4509 | clkctl)); |
| 4510 | |
| 4511 | if (SBSDIO_HTAV(clkctl)) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4512 | devctl = brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
| 4513 | SBSDIO_DEVICE_CTL, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4514 | if (err) { |
| 4515 | DHD_ERROR(("%s: error reading DEVCTL: %d\n", |
| 4516 | __func__, err)); |
| 4517 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 4518 | } |
| 4519 | devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4520 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, |
| 4521 | SBSDIO_DEVICE_CTL, devctl, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4522 | if (err) { |
| 4523 | DHD_ERROR(("%s: error writing DEVCTL: %d\n", |
| 4524 | __func__, err)); |
| 4525 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 4526 | } |
| 4527 | bus->clkstate = CLK_AVAIL; |
| 4528 | } else { |
| 4529 | goto clkwait; |
| 4530 | } |
| 4531 | } |
| 4532 | |
| 4533 | BUS_WAKE(bus); |
| 4534 | |
| 4535 | /* Make sure backplane clock is on */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4536 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4537 | if (bus->clkstate == CLK_PENDING) |
| 4538 | goto clkwait; |
| 4539 | |
| 4540 | /* Pending interrupt indicates new device status */ |
| 4541 | if (bus->ipend) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4542 | bus->ipend = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4543 | R_SDREG(newstatus, ®s->intstatus, retries); |
| 4544 | bus->f1regdata++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4545 | if (brcmf_sdcard_regfail(bus->sdh)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4546 | newstatus = 0; |
| 4547 | newstatus &= bus->hostintmask; |
| 4548 | bus->fcstate = !!(newstatus & I_HMB_FC_STATE); |
| 4549 | if (newstatus) { |
| 4550 | W_SDREG(newstatus, ®s->intstatus, retries); |
| 4551 | bus->f1regdata++; |
| 4552 | } |
| 4553 | } |
| 4554 | |
| 4555 | /* Merge new bits with previous */ |
| 4556 | intstatus |= newstatus; |
| 4557 | bus->intstatus = 0; |
| 4558 | |
| 4559 | /* Handle flow-control change: read new state in case our ack |
| 4560 | * crossed another change interrupt. If change still set, assume |
| 4561 | * FC ON for safety, let next loop through do the debounce. |
| 4562 | */ |
| 4563 | if (intstatus & I_HMB_FC_CHANGE) { |
| 4564 | intstatus &= ~I_HMB_FC_CHANGE; |
| 4565 | W_SDREG(I_HMB_FC_CHANGE, ®s->intstatus, retries); |
| 4566 | R_SDREG(newstatus, ®s->intstatus, retries); |
| 4567 | bus->f1regdata += 2; |
| 4568 | bus->fcstate = |
| 4569 | !!(newstatus & (I_HMB_FC_STATE | I_HMB_FC_CHANGE)); |
| 4570 | intstatus |= (newstatus & bus->hostintmask); |
| 4571 | } |
| 4572 | |
| 4573 | /* Handle host mailbox indication */ |
| 4574 | if (intstatus & I_HMB_HOST_INT) { |
| 4575 | intstatus &= ~I_HMB_HOST_INT; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4576 | intstatus |= brcmf_sdbrcm_hostmail(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4577 | } |
| 4578 | |
| 4579 | /* Generally don't ask for these, can get CRC errors... */ |
| 4580 | if (intstatus & I_WR_OOSYNC) { |
| 4581 | DHD_ERROR(("Dongle reports WR_OOSYNC\n")); |
| 4582 | intstatus &= ~I_WR_OOSYNC; |
| 4583 | } |
| 4584 | |
| 4585 | if (intstatus & I_RD_OOSYNC) { |
| 4586 | DHD_ERROR(("Dongle reports RD_OOSYNC\n")); |
| 4587 | intstatus &= ~I_RD_OOSYNC; |
| 4588 | } |
| 4589 | |
| 4590 | if (intstatus & I_SBINT) { |
| 4591 | DHD_ERROR(("Dongle reports SBINT\n")); |
| 4592 | intstatus &= ~I_SBINT; |
| 4593 | } |
| 4594 | |
| 4595 | /* Would be active due to wake-wlan in gSPI */ |
| 4596 | if (intstatus & I_CHIPACTIVE) { |
| 4597 | DHD_INFO(("Dongle reports CHIPACTIVE\n")); |
| 4598 | intstatus &= ~I_CHIPACTIVE; |
| 4599 | } |
| 4600 | |
| 4601 | /* Ignore frame indications if rxskip is set */ |
| 4602 | if (bus->rxskip) |
| 4603 | intstatus &= ~I_HMB_FRAME_IND; |
| 4604 | |
| 4605 | /* On frame indication, read available frames */ |
| 4606 | if (PKT_AVAILABLE()) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4607 | framecnt = brcmf_sdbrcm_readframes(bus, rxlimit, &rxdone); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4608 | if (rxdone || bus->rxskip) |
| 4609 | intstatus &= ~I_HMB_FRAME_IND; |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 4610 | rxlimit -= min(framecnt, rxlimit); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4611 | } |
| 4612 | |
| 4613 | /* Keep still-pending events for next scheduling */ |
| 4614 | bus->intstatus = intstatus; |
| 4615 | |
| 4616 | clkwait: |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4617 | /* Re-enable interrupts to detect new device events (mailbox, rx frame) |
| 4618 | * or clock availability. (Allows tx loop to check ipend if desired.) |
| 4619 | * (Unless register access seems hosed, as we may not be able to ACK...) |
| 4620 | */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4621 | if (bus->intr && bus->intdis && !brcmf_sdcard_regfail(sdh)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4622 | DHD_INTR(("%s: enable SDIO interrupts, rxdone %d framecnt %d\n", |
| 4623 | __func__, rxdone, framecnt)); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4624 | bus->intdis = false; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4625 | brcmf_sdcard_intr_enable(sdh); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4626 | } |
| 4627 | |
| 4628 | if (DATAOK(bus) && bus->ctrl_frame_stat && |
| 4629 | (bus->clkstate == CLK_AVAIL)) { |
| 4630 | int ret, i; |
| 4631 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4632 | ret = brcmf_sdbrcm_send_buf(bus, brcmf_sdcard_cur_sbwad(sdh), |
| 4633 | SDIO_FUNC_2, F2SYNC, (u8 *) bus->ctrl_frame_buf, |
| 4634 | (u32) bus->ctrl_frame_len, NULL, NULL, NULL); |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 4635 | ASSERT(ret != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4636 | |
| 4637 | if (ret < 0) { |
| 4638 | /* On failure, abort the command and |
| 4639 | terminate the frame */ |
| 4640 | DHD_INFO(("%s: sdio error %d, abort command and " |
| 4641 | "terminate frame.\n", __func__, ret)); |
| 4642 | bus->tx_sderrs++; |
| 4643 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4644 | brcmf_sdcard_abort(sdh, SDIO_FUNC_2); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4645 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4646 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4647 | SBSDIO_FUNC1_FRAMECTRL, SFC_WF_TERM, |
| 4648 | NULL); |
| 4649 | bus->f1regdata++; |
| 4650 | |
| 4651 | for (i = 0; i < 3; i++) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4652 | u8 hi, lo; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4653 | hi = brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4654 | SBSDIO_FUNC1_WFRAMEBCHI, |
| 4655 | NULL); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4656 | lo = brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4657 | SBSDIO_FUNC1_WFRAMEBCLO, |
| 4658 | NULL); |
| 4659 | bus->f1regdata += 2; |
| 4660 | if ((hi == 0) && (lo == 0)) |
| 4661 | break; |
| 4662 | } |
| 4663 | |
| 4664 | } |
| 4665 | if (ret == 0) |
| 4666 | bus->tx_seq = (bus->tx_seq + 1) % SDPCM_SEQUENCE_WRAP; |
| 4667 | |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 4668 | DHD_INFO(("Return_dpc value is : %d\n", ret)); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4669 | bus->ctrl_frame_stat = false; |
Franky Lin | b7adfa7 | 2011-06-29 16:47:42 -0700 | [diff] [blame] | 4670 | brcmf_sdbrcm_wait_event_wakeup(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4671 | } |
| 4672 | /* Send queued frames (limit 1 if rx may still be pending) */ |
| 4673 | else if ((bus->clkstate == CLK_AVAIL) && !bus->fcstate && |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4674 | brcmu_pktq_mlen(&bus->txq, ~bus->flowcontrol) && txlimit |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4675 | && DATAOK(bus)) { |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 4676 | framecnt = rxdone ? txlimit : min(txlimit, dhd_txminmax); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4677 | framecnt = brcmf_sdbrcm_sendfromq(bus, framecnt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4678 | txlimit -= framecnt; |
| 4679 | } |
| 4680 | |
| 4681 | /* Resched if events or tx frames are pending, |
| 4682 | else await next interrupt */ |
| 4683 | /* On failed register access, all bets are off: |
| 4684 | no resched or interrupts */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4685 | if ((bus->dhd->busstate == DHD_BUS_DOWN) || brcmf_sdcard_regfail(sdh)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4686 | DHD_ERROR(("%s: failed backplane access over SDIO, halting " |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4687 | "operation %d\n", __func__, brcmf_sdcard_regfail(sdh))); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4688 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 4689 | bus->intstatus = 0; |
| 4690 | } else if (bus->clkstate == CLK_PENDING) { |
| 4691 | DHD_INFO(("%s: rescheduled due to CLK_PENDING awaiting " |
| 4692 | "I_CHIPACTIVE interrupt\n", __func__)); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4693 | resched = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4694 | } else if (bus->intstatus || bus->ipend || |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4695 | (!bus->fcstate && brcmu_pktq_mlen(&bus->txq, ~bus->flowcontrol) |
| 4696 | && DATAOK(bus)) || PKT_AVAILABLE()) { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4697 | resched = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4698 | } |
| 4699 | |
| 4700 | bus->dpc_sched = resched; |
| 4701 | |
| 4702 | /* If we're done for now, turn off clock request. */ |
| 4703 | if ((bus->clkstate != CLK_PENDING) |
| 4704 | && bus->idletime == DHD_IDLE_IMMEDIATE) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4705 | bus->activity = false; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4706 | brcmf_sdbrcm_clkctl(bus, CLK_NONE, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4707 | } |
| 4708 | |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 4709 | brcmf_os_sdunlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4710 | |
| 4711 | return resched; |
| 4712 | } |
| 4713 | |
| 4714 | bool dhd_bus_dpc(struct dhd_bus *bus) |
| 4715 | { |
| 4716 | bool resched; |
| 4717 | |
| 4718 | /* Call the DPC directly. */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4719 | DHD_TRACE(("Calling brcmf_sdbrcm_dpc() from %s\n", __func__)); |
| 4720 | resched = brcmf_sdbrcm_dpc(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4721 | |
| 4722 | return resched; |
| 4723 | } |
| 4724 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4725 | void brcmf_sdbrcm_isr(void *arg) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4726 | { |
| 4727 | dhd_bus_t *bus = (dhd_bus_t *) arg; |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 4728 | struct brcmf_sdio *sdh; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4729 | |
| 4730 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 4731 | |
| 4732 | if (!bus) { |
| 4733 | DHD_ERROR(("%s : bus is null pointer , exit\n", __func__)); |
| 4734 | return; |
| 4735 | } |
| 4736 | sdh = bus->sdh; |
| 4737 | |
| 4738 | if (bus->dhd->busstate == DHD_BUS_DOWN) { |
| 4739 | DHD_ERROR(("%s : bus is down. we have nothing to do\n", |
| 4740 | __func__)); |
| 4741 | return; |
| 4742 | } |
| 4743 | /* Count the interrupt call */ |
| 4744 | bus->intrcount++; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4745 | bus->ipend = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4746 | |
| 4747 | /* Shouldn't get this interrupt if we're sleeping? */ |
| 4748 | if (bus->sleeping) { |
| 4749 | DHD_ERROR(("INTERRUPT WHILE SLEEPING??\n")); |
| 4750 | return; |
| 4751 | } |
| 4752 | |
| 4753 | /* Disable additional interrupts (is this needed now)? */ |
| 4754 | if (bus->intr) |
| 4755 | DHD_INTR(("%s: disable SDIO interrupts\n", __func__)); |
| 4756 | else |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4757 | DHD_ERROR(("brcmf_sdbrcm_isr() w/o interrupt configured!\n")); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4758 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4759 | brcmf_sdcard_intr_disable(sdh); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4760 | bus->intdis = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4761 | |
| 4762 | #if defined(SDIO_ISR_THREAD) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4763 | DHD_TRACE(("Calling brcmf_sdbrcm_dpc() from %s\n", __func__)); |
| 4764 | while (brcmf_sdbrcm_dpc(bus)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4765 | ; |
| 4766 | #else |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4767 | bus->dpc_sched = true; |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 4768 | brcmf_sched_dpc(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4769 | #endif |
| 4770 | |
| 4771 | } |
| 4772 | |
| 4773 | #ifdef SDTEST |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4774 | static void brcmf_sdbrcm_pktgen_init(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4775 | { |
| 4776 | /* Default to specified length, or full range */ |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 4777 | if (brcmf_pktgen_len) { |
| 4778 | bus->pktgen_maxlen = min(brcmf_pktgen_len, |
| 4779 | BRCMF_MAX_PKTGEN_LEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4780 | bus->pktgen_minlen = bus->pktgen_maxlen; |
| 4781 | } else { |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 4782 | bus->pktgen_maxlen = BRCMF_MAX_PKTGEN_LEN; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4783 | bus->pktgen_minlen = 0; |
| 4784 | } |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4785 | bus->pktgen_len = (u16) bus->pktgen_minlen; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4786 | |
| 4787 | /* Default to per-watchdog burst with 10s print time */ |
| 4788 | bus->pktgen_freq = 1; |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 4789 | bus->pktgen_print = 10000 / brcmf_watchdog_ms; |
| 4790 | bus->pktgen_count = (brcmf_pktgen * brcmf_watchdog_ms + 999) / 1000; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4791 | |
| 4792 | /* Default to echo mode */ |
| 4793 | bus->pktgen_mode = DHD_PKTGEN_ECHO; |
| 4794 | bus->pktgen_stop = 1; |
| 4795 | } |
| 4796 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4797 | static void brcmf_sdbrcm_pktgen(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4798 | { |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 4799 | struct sk_buff *pkt; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4800 | u8 *data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4801 | uint pktcount; |
| 4802 | uint fillbyte; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4803 | u16 len; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4804 | |
| 4805 | /* Display current count if appropriate */ |
| 4806 | if (bus->pktgen_print && (++bus->pktgen_ptick >= bus->pktgen_print)) { |
| 4807 | bus->pktgen_ptick = 0; |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 4808 | printk(KERN_DEBUG "%s: send attempts %d rcvd %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4809 | __func__, bus->pktgen_sent, bus->pktgen_rcvd); |
| 4810 | } |
| 4811 | |
| 4812 | /* For recv mode, just make sure dongle has started sending */ |
| 4813 | if (bus->pktgen_mode == DHD_PKTGEN_RECV) { |
| 4814 | if (!bus->pktgen_rcvd) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4815 | brcmf_sdbrcm_sdtest_set(bus, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4816 | return; |
| 4817 | } |
| 4818 | |
| 4819 | /* Otherwise, generate or request the specified number of packets */ |
| 4820 | for (pktcount = 0; pktcount < bus->pktgen_count; pktcount++) { |
| 4821 | /* Stop if total has been reached */ |
| 4822 | if (bus->pktgen_total |
| 4823 | && (bus->pktgen_sent >= bus->pktgen_total)) { |
| 4824 | bus->pktgen_count = 0; |
| 4825 | break; |
| 4826 | } |
| 4827 | |
| 4828 | /* Allocate an appropriate-sized packet */ |
| 4829 | len = bus->pktgen_len; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4830 | pkt = brcmu_pkt_buf_get_skb( |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 4831 | (len + SDPCM_HDRLEN + SDPCM_TEST_HDRLEN + BRCMF_SDALIGN), |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4832 | true); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 4833 | if (!pkt) { |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4834 | DHD_ERROR(("%s: brcmu_pkt_buf_get_skb failed!\n", |
| 4835 | __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4836 | break; |
| 4837 | } |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 4838 | PKTALIGN(pkt, (len + SDPCM_HDRLEN + SDPCM_TEST_HDRLEN), |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 4839 | BRCMF_SDALIGN); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4840 | data = (u8 *) (pkt->data) + SDPCM_HDRLEN; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4841 | |
| 4842 | /* Write test header cmd and extra based on mode */ |
| 4843 | switch (bus->pktgen_mode) { |
| 4844 | case DHD_PKTGEN_ECHO: |
| 4845 | *data++ = SDPCM_TEST_ECHOREQ; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4846 | *data++ = (u8) bus->pktgen_sent; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4847 | break; |
| 4848 | |
| 4849 | case DHD_PKTGEN_SEND: |
| 4850 | *data++ = SDPCM_TEST_DISCARD; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4851 | *data++ = (u8) bus->pktgen_sent; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4852 | break; |
| 4853 | |
| 4854 | case DHD_PKTGEN_RXBURST: |
| 4855 | *data++ = SDPCM_TEST_BURST; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4856 | *data++ = (u8) bus->pktgen_count; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4857 | break; |
| 4858 | |
| 4859 | default: |
| 4860 | DHD_ERROR(("Unrecognized pktgen mode %d\n", |
| 4861 | bus->pktgen_mode)); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4862 | brcmu_pkt_buf_free_skb(pkt, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4863 | bus->pktgen_count = 0; |
| 4864 | return; |
| 4865 | } |
| 4866 | |
| 4867 | /* Write test header length field */ |
| 4868 | *data++ = (len >> 0); |
| 4869 | *data++ = (len >> 8); |
| 4870 | |
| 4871 | /* Then fill in the remainder -- N/A for burst, |
| 4872 | but who cares... */ |
| 4873 | for (fillbyte = 0; fillbyte < len; fillbyte++) |
| 4874 | *data++ = |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4875 | SDPCM_TEST_FILL(fillbyte, (u8) bus->pktgen_sent); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4876 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 4877 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4878 | if (DHD_BYTES_ON() && DHD_DATA_ON()) { |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4879 | data = (u8 *) (pkt->data) + SDPCM_HDRLEN; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4880 | printk(KERN_DEBUG "brcmf_sdbrcm_pktgen: Tx Data:\n"); |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 4881 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, data, |
| 4882 | pkt->len - SDPCM_HDRLEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4883 | } |
| 4884 | #endif |
| 4885 | |
| 4886 | /* Send it */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4887 | if (brcmf_sdbrcm_txpkt(bus, pkt, SDPCM_TEST_CHANNEL, true)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4888 | bus->pktgen_fail++; |
| 4889 | if (bus->pktgen_stop |
| 4890 | && bus->pktgen_stop == bus->pktgen_fail) |
| 4891 | bus->pktgen_count = 0; |
| 4892 | } |
| 4893 | bus->pktgen_sent++; |
| 4894 | |
| 4895 | /* Bump length if not fixed, wrap at max */ |
| 4896 | if (++bus->pktgen_len > bus->pktgen_maxlen) |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4897 | bus->pktgen_len = (u16) bus->pktgen_minlen; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4898 | |
| 4899 | /* Special case for burst mode: just send one request! */ |
| 4900 | if (bus->pktgen_mode == DHD_PKTGEN_RXBURST) |
| 4901 | break; |
| 4902 | } |
| 4903 | } |
| 4904 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4905 | static void brcmf_sdbrcm_sdtest_set(dhd_bus_t *bus, bool start) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4906 | { |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 4907 | struct sk_buff *pkt; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4908 | u8 *data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4909 | |
| 4910 | /* Allocate the packet */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4911 | pkt = brcmu_pkt_buf_get_skb(SDPCM_HDRLEN + SDPCM_TEST_HDRLEN + |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 4912 | BRCMF_SDALIGN, true); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 4913 | if (!pkt) { |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4914 | DHD_ERROR(("%s: brcmu_pkt_buf_get_skb failed!\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4915 | return; |
| 4916 | } |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 4917 | PKTALIGN(pkt, (SDPCM_HDRLEN + SDPCM_TEST_HDRLEN), BRCMF_SDALIGN); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4918 | data = (u8 *) (pkt->data) + SDPCM_HDRLEN; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4919 | |
| 4920 | /* Fill in the test header */ |
| 4921 | *data++ = SDPCM_TEST_SEND; |
| 4922 | *data++ = start; |
| 4923 | *data++ = (bus->pktgen_maxlen >> 0); |
| 4924 | *data++ = (bus->pktgen_maxlen >> 8); |
| 4925 | |
| 4926 | /* Send it */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4927 | if (brcmf_sdbrcm_txpkt(bus, pkt, SDPCM_TEST_CHANNEL, true)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4928 | bus->pktgen_fail++; |
| 4929 | } |
| 4930 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4931 | static void |
| 4932 | 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] | 4933 | { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4934 | u8 *data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4935 | uint pktlen; |
| 4936 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4937 | u8 cmd; |
| 4938 | u8 extra; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4939 | u16 len; |
| 4940 | u16 offset; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4941 | |
| 4942 | /* Check for min length */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4943 | pktlen = pkt->len; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4944 | if (pktlen < SDPCM_TEST_HDRLEN) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4945 | DHD_ERROR(("brcmf_sdbrcm_checkdied: toss runt frame, pktlen " |
| 4946 | "%d\n", pktlen)); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4947 | brcmu_pkt_buf_free_skb(pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4948 | return; |
| 4949 | } |
| 4950 | |
| 4951 | /* Extract header fields */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4952 | data = pkt->data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4953 | cmd = *data++; |
| 4954 | extra = *data++; |
| 4955 | len = *data++; |
| 4956 | len += *data++ << 8; |
| 4957 | |
| 4958 | /* Check length for relevant commands */ |
| 4959 | if (cmd == SDPCM_TEST_DISCARD || cmd == SDPCM_TEST_ECHOREQ |
| 4960 | || cmd == SDPCM_TEST_ECHORSP) { |
| 4961 | if (pktlen != len + SDPCM_TEST_HDRLEN) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4962 | DHD_ERROR(("brcmf_sdbrcm_checkdied: frame length " |
| 4963 | "mismatch, pktlen %d seq %d" " cmd %d extra %d " |
| 4964 | "len %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4965 | pktlen, seq, cmd, extra, len)); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4966 | brcmu_pkt_buf_free_skb(pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4967 | return; |
| 4968 | } |
| 4969 | } |
| 4970 | |
| 4971 | /* Process as per command */ |
| 4972 | switch (cmd) { |
| 4973 | case SDPCM_TEST_ECHOREQ: |
| 4974 | /* Rx->Tx turnaround ok (even on NDIS w/current |
| 4975 | implementation) */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4976 | *(u8 *) (pkt->data) = SDPCM_TEST_ECHORSP; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4977 | if (brcmf_sdbrcm_txpkt(bus, pkt, SDPCM_TEST_CHANNEL, true) == 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4978 | bus->pktgen_sent++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4979 | else { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4980 | bus->pktgen_fail++; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4981 | brcmu_pkt_buf_free_skb(pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4982 | } |
| 4983 | bus->pktgen_rcvd++; |
| 4984 | break; |
| 4985 | |
| 4986 | case SDPCM_TEST_ECHORSP: |
| 4987 | if (bus->ext_loop) { |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4988 | brcmu_pkt_buf_free_skb(pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4989 | bus->pktgen_rcvd++; |
| 4990 | break; |
| 4991 | } |
| 4992 | |
| 4993 | for (offset = 0; offset < len; offset++, data++) { |
| 4994 | if (*data != SDPCM_TEST_FILL(offset, extra)) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4995 | DHD_ERROR(("brcmf_sdbrcm_checkdied: echo data " |
| 4996 | "mismatch: " "offset %d (len %d) " |
| 4997 | "expect 0x%02x rcvd 0x%02x\n", |
| 4998 | offset, len, |
| 4999 | SDPCM_TEST_FILL(offset, extra), |
| 5000 | *data)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5001 | break; |
| 5002 | } |
| 5003 | } |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 5004 | brcmu_pkt_buf_free_skb(pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5005 | bus->pktgen_rcvd++; |
| 5006 | break; |
| 5007 | |
| 5008 | case SDPCM_TEST_DISCARD: |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 5009 | brcmu_pkt_buf_free_skb(pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5010 | bus->pktgen_rcvd++; |
| 5011 | break; |
| 5012 | |
| 5013 | case SDPCM_TEST_BURST: |
| 5014 | case SDPCM_TEST_SEND: |
| 5015 | default: |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5016 | DHD_INFO(("brcmf_sdbrcm_checkdied: unsupported or unknown " |
| 5017 | "command, pktlen %d seq %d" " cmd %d extra %d len %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5018 | pktlen, seq, cmd, extra, len)); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 5019 | brcmu_pkt_buf_free_skb(pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5020 | break; |
| 5021 | } |
| 5022 | |
| 5023 | /* For recv mode, stop at limie (and tell dongle to stop sending) */ |
| 5024 | if (bus->pktgen_mode == DHD_PKTGEN_RECV) { |
| 5025 | if (bus->pktgen_total |
| 5026 | && (bus->pktgen_rcvd >= bus->pktgen_total)) { |
| 5027 | bus->pktgen_count = 0; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5028 | brcmf_sdbrcm_sdtest_set(bus, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5029 | } |
| 5030 | } |
| 5031 | } |
| 5032 | #endif /* SDTEST */ |
| 5033 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5034 | extern bool brcmf_sdbrcm_bus_watchdog(dhd_pub_t *dhdp) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5035 | { |
| 5036 | dhd_bus_t *bus; |
| 5037 | |
| 5038 | DHD_TIMER(("%s: Enter\n", __func__)); |
| 5039 | |
| 5040 | bus = dhdp->bus; |
| 5041 | |
| 5042 | if (bus->dhd->dongle_reset) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5043 | return false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5044 | |
| 5045 | /* Ignore the timer if simulating bus down */ |
| 5046 | if (bus->sleeping) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5047 | return false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5048 | |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 5049 | brcmf_os_sdlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5050 | |
| 5051 | /* Poll period: check device if appropriate. */ |
| 5052 | if (bus->poll && (++bus->polltick >= bus->pollrate)) { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 5053 | u32 intstatus = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5054 | |
| 5055 | /* Reset poll tick */ |
| 5056 | bus->polltick = 0; |
| 5057 | |
| 5058 | /* Check device if no interrupts */ |
| 5059 | if (!bus->intr || (bus->intrcount == bus->lastintrs)) { |
| 5060 | |
| 5061 | if (!bus->dpc_sched) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 5062 | u8 devpend; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5063 | devpend = brcmf_sdcard_cfg_read(bus->sdh, |
| 5064 | SDIO_FUNC_0, SDIO_CCCR_INTx, |
| 5065 | NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5066 | intstatus = |
| 5067 | devpend & (INTR_STATUS_FUNC1 | |
| 5068 | INTR_STATUS_FUNC2); |
| 5069 | } |
| 5070 | |
| 5071 | /* If there is something, make like the ISR and |
| 5072 | schedule the DPC */ |
| 5073 | if (intstatus) { |
| 5074 | bus->pollcnt++; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5075 | bus->ipend = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5076 | if (bus->intr) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5077 | brcmf_sdcard_intr_disable(bus->sdh); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5078 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5079 | bus->dpc_sched = true; |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 5080 | brcmf_sched_dpc(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5081 | |
| 5082 | } |
| 5083 | } |
| 5084 | |
| 5085 | /* Update interrupt tracking */ |
| 5086 | bus->lastintrs = bus->intrcount; |
| 5087 | } |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 5088 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5089 | /* Poll for console output periodically */ |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 5090 | if (dhdp->busstate == DHD_BUS_DATA && brcmf_console_ms != 0) { |
| 5091 | bus->console.count += brcmf_watchdog_ms; |
| 5092 | if (bus->console.count >= brcmf_console_ms) { |
| 5093 | bus->console.count -= brcmf_console_ms; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5094 | /* Make sure backplane clock is on */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5095 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
| 5096 | if (brcmf_sdbrcm_readconsole(bus) < 0) |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 5097 | brcmf_console_ms = 0; /* On error, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5098 | stop trying */ |
| 5099 | } |
| 5100 | } |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 5101 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5102 | |
| 5103 | #ifdef SDTEST |
| 5104 | /* Generate packets if configured */ |
| 5105 | if (bus->pktgen_count && (++bus->pktgen_tick >= bus->pktgen_freq)) { |
| 5106 | /* Make sure backplane clock is on */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5107 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5108 | bus->pktgen_tick = 0; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5109 | brcmf_sdbrcm_pktgen(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5110 | } |
| 5111 | #endif |
| 5112 | |
| 5113 | /* On idle timeout clear activity flag and/or turn off clock */ |
| 5114 | if ((bus->idletime > 0) && (bus->clkstate == CLK_AVAIL)) { |
| 5115 | if (++bus->idlecount >= bus->idletime) { |
| 5116 | bus->idlecount = 0; |
| 5117 | if (bus->activity) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5118 | bus->activity = false; |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 5119 | brcmf_sdbrcm_wd_timer(bus, brcmf_watchdog_ms); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5120 | } else { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5121 | brcmf_sdbrcm_clkctl(bus, CLK_NONE, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5122 | } |
| 5123 | } |
| 5124 | } |
| 5125 | |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 5126 | brcmf_os_sdunlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5127 | |
| 5128 | return bus->ipend; |
| 5129 | } |
| 5130 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 5131 | #ifdef BCMDBG |
Franky Lin | 913af5f | 2011-06-29 16:47:44 -0700 | [diff] [blame^] | 5132 | static int brcmf_sdbrcm_bus_console_in(dhd_pub_t *dhdp, unsigned char *msg, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5133 | uint msglen) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5134 | { |
| 5135 | dhd_bus_t *bus = dhdp->bus; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 5136 | u32 addr, val; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5137 | int rv; |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 5138 | struct sk_buff *pkt; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5139 | |
| 5140 | /* Address could be zero if CONSOLE := 0 in dongle Makefile */ |
| 5141 | if (bus->console_addr == 0) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 5142 | return -ENOTSUPP; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5143 | |
| 5144 | /* Exclusive bus access */ |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 5145 | brcmf_os_sdlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5146 | |
| 5147 | /* Don't allow input if dongle is in reset */ |
| 5148 | if (bus->dhd->dongle_reset) { |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 5149 | brcmf_os_sdunlock(bus->dhd); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 5150 | return -EPERM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5151 | } |
| 5152 | |
| 5153 | /* Request clock to allow SDIO accesses */ |
| 5154 | BUS_WAKE(bus); |
| 5155 | /* 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] | 5156 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5157 | |
| 5158 | /* Zero cbuf_index */ |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 5159 | addr = bus->console_addr + offsetof(struct rte_console, cbuf_idx); |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 5160 | val = cpu_to_le32(0); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5161 | rv = brcmf_sdbrcm_membytes(bus, true, addr, (u8 *)&val, sizeof(val)); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5162 | if (rv < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5163 | goto done; |
| 5164 | |
| 5165 | /* Write message into cbuf */ |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 5166 | addr = bus->console_addr + offsetof(struct rte_console, cbuf); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5167 | rv = brcmf_sdbrcm_membytes(bus, true, addr, (u8 *)msg, msglen); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5168 | if (rv < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5169 | goto done; |
| 5170 | |
| 5171 | /* Write length into vcons_in */ |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 5172 | addr = bus->console_addr + offsetof(struct rte_console, vcons_in); |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 5173 | val = cpu_to_le32(msglen); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5174 | rv = brcmf_sdbrcm_membytes(bus, true, addr, (u8 *)&val, sizeof(val)); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5175 | if (rv < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5176 | goto done; |
| 5177 | |
| 5178 | /* Bump dongle by sending an empty event pkt. |
| 5179 | * sdpcm_sendup (RX) checks for virtual console input. |
| 5180 | */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 5181 | pkt = brcmu_pkt_buf_get_skb(4 + SDPCM_RESERVE); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5182 | if ((pkt != NULL) && bus->clkstate == CLK_AVAIL) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5183 | brcmf_sdbrcm_txpkt(bus, pkt, SDPCM_EVENT_CHANNEL, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5184 | |
| 5185 | done: |
| 5186 | if ((bus->idletime == DHD_IDLE_IMMEDIATE) && !bus->dpc_sched) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5187 | bus->activity = false; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5188 | brcmf_sdbrcm_clkctl(bus, CLK_NONE, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5189 | } |
| 5190 | |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 5191 | brcmf_os_sdunlock(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5192 | |
| 5193 | return rv; |
| 5194 | } |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 5195 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5196 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5197 | static bool brcmf_sdbrcm_chipmatch(u16 chipid) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5198 | { |
| 5199 | if (chipid == BCM4325_CHIP_ID) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5200 | return true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5201 | if (chipid == BCM4329_CHIP_ID) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5202 | return true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5203 | if (chipid == BCM4319_CHIP_ID) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5204 | return true; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5205 | return false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5206 | } |
| 5207 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5208 | 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] | 5209 | u16 slot, u16 func, uint bustype, void *regsva, |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 5210 | void *sdh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5211 | { |
| 5212 | int ret; |
| 5213 | dhd_bus_t *bus; |
| 5214 | |
| 5215 | /* Init global variables at run-time, not as part of the declaration. |
| 5216 | * This is required to support init/de-init of the driver. |
| 5217 | * Initialization |
| 5218 | * of globals as part of the declaration results in non-deterministic |
| 5219 | * behavior since the value of the globals may be different on the |
| 5220 | * first time that the driver is initialized vs subsequent |
| 5221 | * initializations. |
| 5222 | */ |
Arend van Spriel | 7af9d0c | 2011-06-29 16:47:19 -0700 | [diff] [blame] | 5223 | brcmf_txbound = DHD_TXBOUND; |
| 5224 | brcmf_rxbound = DHD_RXBOUND; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5225 | dhd_alignctl = true; |
| 5226 | sd1idle = true; |
| 5227 | dhd_readahead = true; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5228 | retrydata = false; |
Arend van Spriel | 7af9d0c | 2011-06-29 16:47:19 -0700 | [diff] [blame] | 5229 | brcmf_dongle_memsize = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5230 | dhd_txminmax = DHD_TXMINMAX; |
| 5231 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5232 | forcealign = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5233 | |
Arend van Spriel | aba5e0a | 2011-06-29 16:47:03 -0700 | [diff] [blame] | 5234 | brcmf_c_init(); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5235 | |
| 5236 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5237 | DHD_INFO(("%s: venid 0x%04x devid 0x%04x\n", __func__, venid, devid)); |
| 5238 | |
| 5239 | /* We make assumptions about address window mappings */ |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 5240 | ASSERT((unsigned long)regsva == SI_ENUM_BASE); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5241 | |
| 5242 | /* BCMSDH passes venid and devid based on CIS parsing -- but |
| 5243 | * low-power start |
| 5244 | * means early parse could fail, so here we should get either an ID |
| 5245 | * we recognize OR (-1) indicating we must request power first. |
| 5246 | */ |
| 5247 | /* Check the Vendor ID */ |
| 5248 | switch (venid) { |
| 5249 | case 0x0000: |
Stanislav Fomichev | be1c09f | 2011-03-28 01:31:36 +0400 | [diff] [blame] | 5250 | case PCI_VENDOR_ID_BROADCOM: |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5251 | break; |
| 5252 | default: |
| 5253 | DHD_ERROR(("%s: unknown vendor: 0x%04x\n", __func__, venid)); |
| 5254 | return NULL; |
| 5255 | } |
| 5256 | |
| 5257 | /* Check the Device ID and make sure it's one that we support */ |
| 5258 | switch (devid) { |
| 5259 | case BCM4325_D11DUAL_ID: /* 4325 802.11a/g id */ |
| 5260 | case BCM4325_D11G_ID: /* 4325 802.11g 2.4Ghz band id */ |
| 5261 | case BCM4325_D11A_ID: /* 4325 802.11a 5Ghz band id */ |
| 5262 | DHD_INFO(("%s: found 4325 Dongle\n", __func__)); |
| 5263 | break; |
| 5264 | case BCM4329_D11NDUAL_ID: /* 4329 802.11n dualband device */ |
| 5265 | case BCM4329_D11N2G_ID: /* 4329 802.11n 2.4G device */ |
| 5266 | case BCM4329_D11N5G_ID: /* 4329 802.11n 5G device */ |
| 5267 | case 0x4329: |
| 5268 | DHD_INFO(("%s: found 4329 Dongle\n", __func__)); |
| 5269 | break; |
| 5270 | case BCM4319_D11N_ID: /* 4319 802.11n id */ |
| 5271 | case BCM4319_D11N2G_ID: /* 4319 802.11n2g id */ |
| 5272 | case BCM4319_D11N5G_ID: /* 4319 802.11n5g id */ |
| 5273 | DHD_INFO(("%s: found 4319 Dongle\n", __func__)); |
| 5274 | break; |
| 5275 | case 0: |
| 5276 | DHD_INFO(("%s: allow device id 0, will check chip internals\n", |
| 5277 | __func__)); |
| 5278 | break; |
| 5279 | |
| 5280 | default: |
| 5281 | DHD_ERROR(("%s: skipping 0x%04x/0x%04x, not a dongle\n", |
| 5282 | __func__, venid, devid)); |
| 5283 | return NULL; |
| 5284 | } |
| 5285 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5286 | /* Allocate private bus interface state */ |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5287 | bus = kzalloc(sizeof(dhd_bus_t), GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5288 | if (!bus) { |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5289 | DHD_ERROR(("%s: kmalloc of dhd_bus_t failed\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5290 | goto fail; |
| 5291 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5292 | bus->sdh = sdh; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5293 | bus->cl_devid = (u16) devid; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5294 | bus->bus = DHD_BUS; |
| 5295 | bus->tx_seq = SDPCM_SEQUENCE_WRAP - 1; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5296 | bus->usebufpool = false; /* Use bufpool if allocated, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5297 | else use locally malloced rxbuf */ |
| 5298 | |
| 5299 | /* attempt to attach to the dongle */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5300 | if (!(brcmf_sdbrcm_probe_attach(bus, sdh, regsva, devid))) { |
| 5301 | DHD_ERROR(("%s: brcmf_sdbrcm_probe_attach failed\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5302 | goto fail; |
| 5303 | } |
| 5304 | |
Franky Lin | 0f1a87c | 2011-06-29 16:46:32 -0700 | [diff] [blame] | 5305 | spin_lock_init(&bus->txqlock); |
Franky Lin | b7adfa7 | 2011-06-29 16:47:42 -0700 | [diff] [blame] | 5306 | init_waitqueue_head(&bus->ctrl_wait); |
Franky Lin | 0f1a87c | 2011-06-29 16:46:32 -0700 | [diff] [blame] | 5307 | |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 5308 | /* Set up the watchdog timer */ |
| 5309 | init_timer(&bus->timer); |
| 5310 | bus->timer.data = (unsigned long)bus; |
| 5311 | bus->timer.function = brcmf_sdbrcm_watchdog; |
| 5312 | |
| 5313 | if (brcmf_dpc_prio >= 0) { |
| 5314 | /* Initialize watchdog thread */ |
| 5315 | init_completion(&bus->watchdog_wait); |
| 5316 | bus->watchdog_tsk = kthread_run(brcmf_sdbrcm_watchdog_thread, |
| 5317 | bus, "brcmf_watchdog"); |
| 5318 | if (IS_ERR(bus->watchdog_tsk)) { |
| 5319 | printk(KERN_WARNING |
| 5320 | "brcmf_watchdog thread failed to start\n"); |
| 5321 | bus->watchdog_tsk = NULL; |
| 5322 | } |
| 5323 | } else |
| 5324 | bus->watchdog_tsk = NULL; |
| 5325 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5326 | /* Attach to the dhd/OS/network interface */ |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 5327 | bus->dhd = brcmf_attach(bus, SDPCM_RESERVE); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5328 | if (!bus->dhd) { |
| 5329 | DHD_ERROR(("%s: dhd_attach failed\n", __func__)); |
| 5330 | goto fail; |
| 5331 | } |
| 5332 | |
| 5333 | /* Allocate buffers */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5334 | if (!(brcmf_sdbrcm_probe_malloc(bus, sdh))) { |
| 5335 | DHD_ERROR(("%s: brcmf_sdbrcm_probe_malloc failed\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5336 | goto fail; |
| 5337 | } |
| 5338 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5339 | if (!(brcmf_sdbrcm_probe_init(bus, sdh))) { |
| 5340 | DHD_ERROR(("%s: brcmf_sdbrcm_probe_init failed\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5341 | goto fail; |
| 5342 | } |
| 5343 | |
| 5344 | /* Register interrupt callback, but mask it (not operational yet). */ |
| 5345 | DHD_INTR(("%s: disable SDIO interrupts (not interested yet)\n", |
| 5346 | __func__)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5347 | brcmf_sdcard_intr_disable(sdh); |
| 5348 | ret = brcmf_sdcard_intr_reg(sdh, brcmf_sdbrcm_isr, bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5349 | if (ret != 0) { |
| 5350 | DHD_ERROR(("%s: FAILED: bcmsdh_intr_reg returned %d\n", |
| 5351 | __func__, ret)); |
| 5352 | goto fail; |
| 5353 | } |
| 5354 | DHD_INTR(("%s: registered SDIO interrupt function ok\n", __func__)); |
| 5355 | |
| 5356 | DHD_INFO(("%s: completed!!\n", __func__)); |
| 5357 | |
| 5358 | /* if firmware path present try to download and bring up bus */ |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 5359 | ret = brcmf_bus_start(bus->dhd); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5360 | if (ret != 0) { |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 5361 | if (ret == -ENOLINK) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5362 | DHD_ERROR(("%s: dongle is not responding\n", __func__)); |
| 5363 | goto fail; |
| 5364 | } |
| 5365 | } |
| 5366 | /* 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] | 5367 | if (brcmf_net_attach(bus->dhd, 0) != 0) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5368 | DHD_ERROR(("%s: Net attach failed!!\n", __func__)); |
| 5369 | goto fail; |
| 5370 | } |
| 5371 | |
| 5372 | return bus; |
| 5373 | |
| 5374 | fail: |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5375 | brcmf_sdbrcm_release(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5376 | return NULL; |
| 5377 | } |
| 5378 | |
| 5379 | static bool |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5380 | brcmf_sdbrcm_probe_attach(struct dhd_bus *bus, void *sdh, void *regsva, |
| 5381 | u16 devid) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5382 | { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 5383 | u8 clkctl = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5384 | int err = 0; |
| 5385 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5386 | bus->alp_only = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5387 | |
| 5388 | /* Return the window to backplane enumeration space for core access */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5389 | if (brcmf_sdbrcm_set_siaddr_window(bus, SI_ENUM_BASE)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5390 | DHD_ERROR(("%s: FAILED to return to SI_ENUM_BASE\n", __func__)); |
| 5391 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 5392 | #ifdef BCMDBG |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 5393 | printk(KERN_DEBUG "F1 signature read @0x18000000=0x%4x\n", |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5394 | brcmf_sdcard_reg_read(bus->sdh, SI_ENUM_BASE, 4)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5395 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 5396 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5397 | |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 5398 | /* |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5399 | * Force PLL off until brcmf_sdbrcm_chip_attach() |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 5400 | * programs PLL control regs |
| 5401 | */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5402 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5403 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5404 | DHD_INIT_CLKCTL1, &err); |
| 5405 | if (!err) |
| 5406 | clkctl = |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5407 | brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
| 5408 | SBSDIO_FUNC1_CHIPCLKCSR, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5409 | |
| 5410 | if (err || ((clkctl & ~SBSDIO_AVBITS) != DHD_INIT_CLKCTL1)) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5411 | DHD_ERROR(("brcmf_sdbrcm_probe: ChipClkCSR access: err %d wrote" |
| 5412 | " 0x%02x read 0x%02x\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5413 | err, DHD_INIT_CLKCTL1, clkctl)); |
| 5414 | goto fail; |
| 5415 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5416 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5417 | if (brcmf_sdbrcm_chip_attach(bus, regsva)) { |
| 5418 | DHD_ERROR(("%s: brcmf_sdbrcm_chip_attach failed!\n", __func__)); |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 5419 | goto fail; |
| 5420 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5421 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5422 | brcmf_sdcard_chipinfo(sdh, bus->ci->chip, bus->ci->chiprev); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5423 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5424 | if (!brcmf_sdbrcm_chipmatch((u16) bus->ci->chip)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5425 | DHD_ERROR(("%s: unsupported chip: 0x%04x\n", |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 5426 | __func__, bus->ci->chip)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5427 | goto fail; |
| 5428 | } |
| 5429 | |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 5430 | brcmf_sdbrcm_sdiod_drive_strength_init(bus, brcmf_sdiod_drive_strength); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5431 | |
| 5432 | /* Get info on the ARM and SOCRAM cores... */ |
| 5433 | if (!DHD_NOPMU(bus)) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5434 | bus->armrev = SBCOREREV(brcmf_sdcard_reg_read(bus->sdh, |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 5435 | CORE_SB(bus->ci->armcorebase, sbidhigh), 4)); |
| 5436 | bus->orig_ramsize = bus->ci->ramsize; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5437 | if (!(bus->orig_ramsize)) { |
| 5438 | DHD_ERROR(("%s: failed to find SOCRAM memory!\n", |
| 5439 | __func__)); |
| 5440 | goto fail; |
| 5441 | } |
| 5442 | bus->ramsize = bus->orig_ramsize; |
Arend van Spriel | 7af9d0c | 2011-06-29 16:47:19 -0700 | [diff] [blame] | 5443 | if (brcmf_dongle_memsize) |
| 5444 | brcmf_sdbrcm_setmemsize(bus, brcmf_dongle_memsize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5445 | |
| 5446 | DHD_ERROR(("DHD: dongle ram size is set to %d(orig %d)\n", |
| 5447 | bus->ramsize, bus->orig_ramsize)); |
| 5448 | } |
| 5449 | |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 5450 | bus->regs = (void *)bus->ci->buscorebase; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5451 | |
| 5452 | /* Set core control so an SDIO reset does a backplane reset */ |
Arend van Spriel | ff31c54 | 2011-03-01 10:56:54 +0100 | [diff] [blame] | 5453 | OR_REG(&bus->regs->corecontrol, CC_BPRESEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5454 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 5455 | brcmu_pktq_init(&bus->txq, (PRIOMASK + 1), TXQLEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5456 | |
| 5457 | /* Locate an appropriately-aligned portion of hdrbuf */ |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 5458 | bus->rxhdr = (u8 *) roundup((unsigned long)&bus->hdrbuf[0], BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5459 | |
| 5460 | /* Set the poll and/or interrupt flags */ |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 5461 | bus->intr = (bool) brcmf_intr; |
| 5462 | bus->poll = (bool) brcmf_poll; |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5463 | if (bus->poll) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5464 | bus->pollrate = 1; |
| 5465 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5466 | return true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5467 | |
| 5468 | fail: |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5469 | return false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5470 | } |
| 5471 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5472 | static bool brcmf_sdbrcm_probe_malloc(dhd_bus_t *bus, void *sdh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5473 | { |
| 5474 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5475 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5476 | if (bus->dhd->maxctl) { |
| 5477 | bus->rxblen = |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 5478 | roundup((bus->dhd->maxctl + SDPCM_HDRLEN), |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 5479 | ALIGNMENT) + BRCMF_SDALIGN; |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5480 | bus->rxbuf = kmalloc(bus->rxblen, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5481 | if (!(bus->rxbuf)) { |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5482 | DHD_ERROR(("%s: kmalloc of %d-byte rxbuf failed\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5483 | __func__, bus->rxblen)); |
| 5484 | goto fail; |
| 5485 | } |
| 5486 | } |
| 5487 | |
| 5488 | /* Allocate buffer to receive glomed packet */ |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5489 | bus->databuf = kmalloc(MAX_DATA_BUF, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5490 | if (!(bus->databuf)) { |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5491 | DHD_ERROR(("%s: kmalloc of %d-byte databuf failed\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5492 | __func__, MAX_DATA_BUF)); |
| 5493 | /* release rxbuf which was already located as above */ |
| 5494 | if (!bus->rxblen) |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 5495 | kfree(bus->rxbuf); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5496 | goto fail; |
| 5497 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5498 | |
| 5499 | /* Align the buffer */ |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 5500 | if ((unsigned long)bus->databuf % BRCMF_SDALIGN) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5501 | bus->dataptr = |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 5502 | bus->databuf + (BRCMF_SDALIGN - |
| 5503 | ((unsigned long)bus->databuf % BRCMF_SDALIGN)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5504 | else |
| 5505 | bus->dataptr = bus->databuf; |
| 5506 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5507 | return true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5508 | |
| 5509 | fail: |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5510 | return false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5511 | } |
| 5512 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5513 | static bool brcmf_sdbrcm_probe_init(dhd_bus_t *bus, void *sdh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5514 | { |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 5515 | s32 fnum; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5516 | |
| 5517 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5518 | |
| 5519 | #ifdef SDTEST |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5520 | brcmf_sdbrcm_pktgen_init(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5521 | #endif /* SDTEST */ |
| 5522 | |
| 5523 | /* Disable F2 to clear any intermediate frame state on the dongle */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5524 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_0, SDIO_CCCR_IOEx, |
| 5525 | SDIO_FUNC_ENABLE_1, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5526 | |
| 5527 | bus->dhd->busstate = DHD_BUS_DOWN; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5528 | bus->sleeping = false; |
| 5529 | bus->rxflow = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5530 | bus->prev_rxlim_hit = 0; |
| 5531 | |
| 5532 | /* Done with backplane-dependent accesses, can drop clock... */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5533 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, 0, |
| 5534 | NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5535 | |
| 5536 | /* ...and initialize clock/power states */ |
| 5537 | bus->clkstate = CLK_SDONLY; |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 5538 | bus->idletime = (s32) brcmf_idletime; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5539 | bus->idleclock = DHD_IDLE_ACTIVE; |
| 5540 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5541 | /* Query the F2 block size, set roundup accordingly */ |
| 5542 | fnum = 2; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5543 | if (brcmf_sdcard_iovar_op(sdh, "sd_blocksize", &fnum, sizeof(s32), |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 5544 | &bus->blocksize, sizeof(s32), false) != 0) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5545 | bus->blocksize = 0; |
| 5546 | DHD_ERROR(("%s: fail on %s get\n", __func__, "sd_blocksize")); |
| 5547 | } else { |
| 5548 | DHD_INFO(("%s: Initial value for %s is %d\n", |
| 5549 | __func__, "sd_blocksize", bus->blocksize)); |
| 5550 | } |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 5551 | bus->roundup = min(max_roundup, bus->blocksize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5552 | |
| 5553 | /* Query if bus module supports packet chaining, |
| 5554 | default to use if supported */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5555 | if (brcmf_sdcard_iovar_op(sdh, "sd_rxchain", NULL, 0, |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 5556 | &bus->sd_rxchain, sizeof(s32), |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 5557 | false) != 0) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5558 | bus->sd_rxchain = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5559 | } else { |
| 5560 | DHD_INFO(("%s: bus module (through bcmsdh API) %s chaining\n", |
| 5561 | __func__, |
| 5562 | (bus->sd_rxchain ? "supports" : "does not support"))); |
| 5563 | } |
| 5564 | bus->use_rxchain = (bool) bus->sd_rxchain; |
| 5565 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5566 | return true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5567 | } |
| 5568 | |
| 5569 | bool |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 5570 | dhd_bus_download_firmware(struct dhd_bus *bus, char *fw_path, char *nv_path) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5571 | { |
| 5572 | bool ret; |
| 5573 | bus->fw_path = fw_path; |
| 5574 | bus->nv_path = nv_path; |
| 5575 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5576 | ret = brcmf_sdbrcm_download_firmware(bus, bus->sdh); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5577 | |
| 5578 | return ret; |
| 5579 | } |
| 5580 | |
| 5581 | static bool |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5582 | brcmf_sdbrcm_download_firmware(struct dhd_bus *bus, void *sdh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5583 | { |
| 5584 | bool ret; |
| 5585 | |
| 5586 | /* Download the firmware */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5587 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5588 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5589 | ret = _brcmf_sdbrcm_download_firmware(bus) == 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5590 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5591 | brcmf_sdbrcm_clkctl(bus, CLK_SDONLY, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5592 | |
| 5593 | return ret; |
| 5594 | } |
| 5595 | |
| 5596 | /* Detach and free everything */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5597 | static void brcmf_sdbrcm_release(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5598 | { |
| 5599 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5600 | |
| 5601 | if (bus) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5602 | /* De-register interrupt handler */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5603 | brcmf_sdcard_intr_disable(bus->sdh); |
| 5604 | brcmf_sdcard_intr_dereg(bus->sdh); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5605 | |
| 5606 | if (bus->dhd) { |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 5607 | brcmf_detach(bus->dhd); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5608 | brcmf_sdbrcm_release_dongle(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5609 | bus->dhd = NULL; |
| 5610 | } |
| 5611 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5612 | brcmf_sdbrcm_release_malloc(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5613 | |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 5614 | kfree(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5615 | } |
| 5616 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5617 | DHD_TRACE(("%s: Disconnected\n", __func__)); |
| 5618 | } |
| 5619 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5620 | static void brcmf_sdbrcm_release_malloc(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5621 | { |
| 5622 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5623 | |
| 5624 | if (bus->dhd && bus->dhd->dongle_reset) |
| 5625 | return; |
| 5626 | |
Henry Ptasinski | 521223a | 2011-06-29 16:46:55 -0700 | [diff] [blame] | 5627 | kfree(bus->rxbuf); |
| 5628 | bus->rxctl = bus->rxbuf = NULL; |
| 5629 | bus->rxlen = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5630 | |
Ilia Mirkin | 46d994b | 2011-03-13 00:28:56 -0500 | [diff] [blame] | 5631 | kfree(bus->databuf); |
| 5632 | bus->databuf = NULL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5633 | } |
| 5634 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5635 | static void brcmf_sdbrcm_release_dongle(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5636 | { |
| 5637 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5638 | |
| 5639 | if (bus->dhd && bus->dhd->dongle_reset) |
| 5640 | return; |
| 5641 | |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 5642 | if (bus->ci) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5643 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
| 5644 | brcmf_sdbrcm_clkctl(bus, CLK_NONE, false); |
| 5645 | brcmf_sdbrcm_chip_detach(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5646 | if (bus->vars && bus->varsz) |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 5647 | kfree(bus->vars); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5648 | bus->vars = NULL; |
| 5649 | } |
| 5650 | |
| 5651 | DHD_TRACE(("%s: Disconnected\n", __func__)); |
| 5652 | } |
| 5653 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5654 | static void brcmf_sdbrcm_disconnect(void *ptr) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5655 | { |
| 5656 | dhd_bus_t *bus = (dhd_bus_t *)ptr; |
| 5657 | |
| 5658 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5659 | |
| 5660 | if (bus) { |
| 5661 | ASSERT(bus->dhd); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5662 | brcmf_sdbrcm_release(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5663 | } |
| 5664 | |
| 5665 | DHD_TRACE(("%s: Disconnected\n", __func__)); |
| 5666 | } |
| 5667 | |
| 5668 | /* Register/Unregister functions are called by the main DHD entry |
| 5669 | * point (e.g. module insertion) to link with the bus driver, in |
| 5670 | * order to look for or await the device. |
| 5671 | */ |
| 5672 | |
Roland Vossen | 8965004 | 2011-06-29 16:47:22 -0700 | [diff] [blame] | 5673 | static struct brcmf_sdioh_driver dhd_sdio = { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5674 | brcmf_sdbrcm_probe, |
| 5675 | brcmf_sdbrcm_disconnect |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5676 | }; |
| 5677 | |
| 5678 | int dhd_bus_register(void) |
| 5679 | { |
| 5680 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5681 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5682 | return brcmf_sdio_register(&dhd_sdio); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5683 | } |
| 5684 | |
| 5685 | void dhd_bus_unregister(void) |
| 5686 | { |
| 5687 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5688 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5689 | brcmf_sdio_unregister(); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5690 | } |
| 5691 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5692 | static int brcmf_sdbrcm_download_code_file(struct dhd_bus *bus, char *fw_path) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5693 | { |
| 5694 | int bcmerror = -1; |
| 5695 | int offset = 0; |
| 5696 | uint len; |
| 5697 | void *image = NULL; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 5698 | u8 *memblock = NULL, *memptr; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5699 | |
Arend van Spriel | aba5e0a | 2011-06-29 16:47:03 -0700 | [diff] [blame] | 5700 | DHD_INFO(("%s: download firmware %s\n", __func__, brcmf_fw_path)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5701 | |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 5702 | image = brcmf_os_open_image(fw_path); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5703 | if (image == NULL) |
| 5704 | goto err; |
| 5705 | |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 5706 | memptr = memblock = kmalloc(MEMBLOCK + BRCMF_SDALIGN, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5707 | if (memblock == NULL) { |
| 5708 | DHD_ERROR(("%s: Failed to allocate memory %d bytes\n", |
| 5709 | __func__, MEMBLOCK)); |
| 5710 | goto err; |
| 5711 | } |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 5712 | if ((u32)(unsigned long)memblock % BRCMF_SDALIGN) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5713 | memptr += |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 5714 | (BRCMF_SDALIGN - ((u32)(unsigned long)memblock % BRCMF_SDALIGN)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5715 | |
| 5716 | /* Download image */ |
| 5717 | while ((len = |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 5718 | brcmf_os_get_image_block((char *)memptr, MEMBLOCK, image))) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5719 | bcmerror = brcmf_sdbrcm_membytes(bus, true, offset, memptr, |
| 5720 | len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5721 | if (bcmerror) { |
| 5722 | DHD_ERROR(("%s: error %d on writing %d membytes at " |
| 5723 | "0x%08x\n", __func__, bcmerror, MEMBLOCK, offset)); |
| 5724 | goto err; |
| 5725 | } |
| 5726 | |
| 5727 | offset += MEMBLOCK; |
| 5728 | } |
| 5729 | |
| 5730 | err: |
Ilia Mirkin | 46d994b | 2011-03-13 00:28:56 -0500 | [diff] [blame] | 5731 | kfree(memblock); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5732 | |
| 5733 | if (image) |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 5734 | brcmf_os_close_image(image); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5735 | |
| 5736 | return bcmerror; |
| 5737 | } |
| 5738 | |
| 5739 | /* |
| 5740 | * ProcessVars:Takes a buffer of "<var>=<value>\n" lines read from a file |
| 5741 | * and ending in a NUL. |
| 5742 | * Removes carriage returns, empty lines, comment lines, and converts |
| 5743 | * newlines to NULs. |
| 5744 | * Shortens buffer as needed and pads with NULs. End of buffer is marked |
| 5745 | * by two NULs. |
| 5746 | */ |
| 5747 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5748 | static uint brcmf_process_nvram_vars(char *varbuf, uint len) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5749 | { |
| 5750 | char *dp; |
| 5751 | bool findNewline; |
| 5752 | int column; |
| 5753 | uint buf_len, n; |
| 5754 | |
| 5755 | dp = varbuf; |
| 5756 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5757 | findNewline = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5758 | column = 0; |
| 5759 | |
| 5760 | for (n = 0; n < len; n++) { |
| 5761 | if (varbuf[n] == 0) |
| 5762 | break; |
| 5763 | if (varbuf[n] == '\r') |
| 5764 | continue; |
| 5765 | if (findNewline && varbuf[n] != '\n') |
| 5766 | continue; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5767 | findNewline = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5768 | if (varbuf[n] == '#') { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5769 | findNewline = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5770 | continue; |
| 5771 | } |
| 5772 | if (varbuf[n] == '\n') { |
| 5773 | if (column == 0) |
| 5774 | continue; |
| 5775 | *dp++ = 0; |
| 5776 | column = 0; |
| 5777 | continue; |
| 5778 | } |
| 5779 | *dp++ = varbuf[n]; |
| 5780 | column++; |
| 5781 | } |
| 5782 | buf_len = dp - varbuf; |
| 5783 | |
| 5784 | while (dp < varbuf + n) |
| 5785 | *dp++ = 0; |
| 5786 | |
| 5787 | return buf_len; |
| 5788 | } |
| 5789 | |
| 5790 | /* |
| 5791 | EXAMPLE: nvram_array |
| 5792 | nvram_arry format: |
| 5793 | name=value |
| 5794 | Use carriage return at the end of each assignment, |
| 5795 | and an empty string with |
| 5796 | carriage return at the end of array. |
| 5797 | |
| 5798 | For example: |
| 5799 | unsigned char nvram_array[] = {"name1=value1\n", |
| 5800 | "name2=value2\n", "\n"}; |
| 5801 | Hex values start with 0x, and mac addr format: xx:xx:xx:xx:xx:xx. |
| 5802 | |
| 5803 | Search "EXAMPLE: nvram_array" to see how the array is activated. |
| 5804 | */ |
| 5805 | |
| 5806 | void dhd_bus_set_nvram_params(struct dhd_bus *bus, const char *nvram_params) |
| 5807 | { |
| 5808 | bus->nvram_params = nvram_params; |
| 5809 | } |
| 5810 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5811 | static int brcmf_sdbrcm_download_nvram(struct dhd_bus *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5812 | { |
| 5813 | int bcmerror = -1; |
| 5814 | uint len; |
| 5815 | void *image = NULL; |
| 5816 | char *memblock = NULL; |
| 5817 | char *bufp; |
| 5818 | char *nv_path; |
| 5819 | bool nvram_file_exists; |
| 5820 | |
| 5821 | nv_path = bus->nv_path; |
| 5822 | |
| 5823 | nvram_file_exists = ((nv_path != NULL) && (nv_path[0] != '\0')); |
| 5824 | if (!nvram_file_exists && (bus->nvram_params == NULL)) |
| 5825 | return 0; |
| 5826 | |
| 5827 | if (nvram_file_exists) { |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 5828 | image = brcmf_os_open_image(nv_path); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5829 | if (image == NULL) |
| 5830 | goto err; |
| 5831 | } |
| 5832 | |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5833 | memblock = kmalloc(MEMBLOCK, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5834 | if (memblock == NULL) { |
| 5835 | DHD_ERROR(("%s: Failed to allocate memory %d bytes\n", |
| 5836 | __func__, MEMBLOCK)); |
| 5837 | goto err; |
| 5838 | } |
| 5839 | |
| 5840 | /* Download variables */ |
| 5841 | if (nvram_file_exists) { |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 5842 | len = brcmf_os_get_image_block(memblock, MEMBLOCK, image); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5843 | } else { |
| 5844 | len = strlen(bus->nvram_params); |
| 5845 | ASSERT(len <= MEMBLOCK); |
| 5846 | if (len > MEMBLOCK) |
| 5847 | len = MEMBLOCK; |
| 5848 | memcpy(memblock, bus->nvram_params, len); |
| 5849 | } |
| 5850 | |
| 5851 | if (len > 0 && len < MEMBLOCK) { |
| 5852 | bufp = (char *)memblock; |
| 5853 | bufp[len] = 0; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5854 | len = brcmf_process_nvram_vars(bufp, len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5855 | bufp += len; |
| 5856 | *bufp++ = 0; |
| 5857 | if (len) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5858 | bcmerror = brcmf_sdbrcm_downloadvars(bus, memblock, |
| 5859 | len + 1); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5860 | if (bcmerror) { |
| 5861 | DHD_ERROR(("%s: error downloading vars: %d\n", |
| 5862 | __func__, bcmerror)); |
| 5863 | } |
| 5864 | } else { |
| 5865 | DHD_ERROR(("%s: error reading nvram file: %d\n", |
| 5866 | __func__, len)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 5867 | bcmerror = -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5868 | } |
| 5869 | |
| 5870 | err: |
Ilia Mirkin | 46d994b | 2011-03-13 00:28:56 -0500 | [diff] [blame] | 5871 | kfree(memblock); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5872 | |
| 5873 | if (image) |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 5874 | brcmf_os_close_image(image); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5875 | |
| 5876 | return bcmerror; |
| 5877 | } |
| 5878 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5879 | static int _brcmf_sdbrcm_download_firmware(struct dhd_bus *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5880 | { |
| 5881 | int bcmerror = -1; |
| 5882 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5883 | bool embed = false; /* download embedded firmware */ |
| 5884 | bool dlok = false; /* download firmware succeeded */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5885 | |
| 5886 | /* Out immediately if no image to download */ |
Franky Lin | a4181fb | 2011-06-01 13:45:34 +0200 | [diff] [blame] | 5887 | if ((bus->fw_path == NULL) || (bus->fw_path[0] == '\0')) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5888 | return bcmerror; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5889 | |
| 5890 | /* Keep arm in reset */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5891 | if (brcmf_sdbrcm_download_state(bus, true)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5892 | DHD_ERROR(("%s: error placing ARM core in reset\n", __func__)); |
| 5893 | goto err; |
| 5894 | } |
| 5895 | |
| 5896 | /* External image takes precedence if specified */ |
| 5897 | if ((bus->fw_path != NULL) && (bus->fw_path[0] != '\0')) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5898 | if (brcmf_sdbrcm_download_code_file(bus, bus->fw_path)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5899 | DHD_ERROR(("%s: dongle image file download failed\n", |
| 5900 | __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5901 | goto err; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5902 | } else { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5903 | embed = false; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5904 | dlok = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5905 | } |
| 5906 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5907 | if (!dlok) { |
| 5908 | DHD_ERROR(("%s: dongle image download failed\n", __func__)); |
| 5909 | goto err; |
| 5910 | } |
| 5911 | |
| 5912 | /* EXAMPLE: nvram_array */ |
| 5913 | /* If a valid nvram_arry is specified as above, it can be passed |
| 5914 | down to dongle */ |
| 5915 | /* dhd_bus_set_nvram_params(bus, (char *)&nvram_array); */ |
| 5916 | |
| 5917 | /* External nvram takes precedence if specified */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5918 | if (brcmf_sdbrcm_download_nvram(bus)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5919 | DHD_ERROR(("%s: dongle nvram file download failed\n", |
| 5920 | __func__)); |
| 5921 | } |
| 5922 | |
| 5923 | /* Take arm out of reset */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5924 | if (brcmf_sdbrcm_download_state(bus, false)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5925 | DHD_ERROR(("%s: error getting out of ARM core reset\n", |
| 5926 | __func__)); |
| 5927 | goto err; |
| 5928 | } |
| 5929 | |
| 5930 | bcmerror = 0; |
| 5931 | |
| 5932 | err: |
| 5933 | return bcmerror; |
| 5934 | } |
| 5935 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5936 | |
| 5937 | static int |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5938 | 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] | 5939 | u8 *buf, uint nbytes, struct sk_buff *pkt, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5940 | bcmsdh_cmplt_fn_t complete, void *handle) |
| 5941 | { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5942 | return brcmf_sdcard_send_buf |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5943 | (bus->sdh, addr, fn, flags, buf, nbytes, pkt, complete, |
| 5944 | handle); |
| 5945 | } |
| 5946 | |
| 5947 | uint dhd_bus_chip(struct dhd_bus *bus) |
| 5948 | { |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 5949 | ASSERT(bus->ci != NULL); |
| 5950 | return bus->ci->chip; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5951 | } |
| 5952 | |
| 5953 | void *dhd_bus_pub(struct dhd_bus *bus) |
| 5954 | { |
| 5955 | return bus->dhd; |
| 5956 | } |
| 5957 | |
| 5958 | void *dhd_bus_txq(struct dhd_bus *bus) |
| 5959 | { |
| 5960 | return &bus->txq; |
| 5961 | } |
| 5962 | |
| 5963 | uint dhd_bus_hdrlen(struct dhd_bus *bus) |
| 5964 | { |
| 5965 | return SDPCM_HDRLEN; |
| 5966 | } |
| 5967 | |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 5968 | int brcmf_bus_devreset(dhd_pub_t *dhdp, u8 flag) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5969 | { |
| 5970 | int bcmerror = 0; |
| 5971 | dhd_bus_t *bus; |
| 5972 | |
| 5973 | bus = dhdp->bus; |
| 5974 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5975 | if (flag == true) { |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 5976 | brcmf_sdbrcm_wd_timer(bus, 0); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5977 | if (!bus->dhd->dongle_reset) { |
| 5978 | /* Expect app to have torn down any |
| 5979 | connection before calling */ |
| 5980 | /* Stop the bus, disable F2 */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5981 | brcmf_sdbrcm_bus_stop(bus, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5982 | |
| 5983 | /* Clean tx/rx buffer pointers, |
| 5984 | detach from the dongle */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5985 | brcmf_sdbrcm_release_dongle(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5986 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5987 | bus->dhd->dongle_reset = true; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5988 | bus->dhd->up = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5989 | |
| 5990 | DHD_TRACE(("%s: WLAN OFF DONE\n", __func__)); |
| 5991 | /* App can now remove power from device */ |
| 5992 | } else |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 5993 | bcmerror = -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5994 | } else { |
| 5995 | /* App must have restored power to device before calling */ |
| 5996 | |
| 5997 | DHD_TRACE(("\n\n%s: == WLAN ON ==\n", __func__)); |
| 5998 | |
| 5999 | if (bus->dhd->dongle_reset) { |
| 6000 | /* Turn on WLAN */ |
| 6001 | /* Reset SD client */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6002 | brcmf_sdcard_reset(bus->sdh); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6003 | |
| 6004 | /* Attempt to re-attach & download */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6005 | if (brcmf_sdbrcm_probe_attach(bus, bus->sdh, |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 6006 | (u32 *) SI_ENUM_BASE, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6007 | bus->cl_devid)) { |
| 6008 | /* Attempt to download binary to the dongle */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6009 | if (brcmf_sdbrcm_probe_init |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 6010 | (bus, bus->sdh) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6011 | && brcmf_sdbrcm_download_firmware(bus, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6012 | bus->sdh)) { |
| 6013 | |
| 6014 | /* Re-init bus, enable F2 transfer */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6015 | brcmf_sdbrcm_bus_init( |
| 6016 | (dhd_pub_t *) bus->dhd, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6017 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 6018 | bus->dhd->dongle_reset = false; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 6019 | bus->dhd->up = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6020 | |
| 6021 | DHD_TRACE(("%s: WLAN ON DONE\n", |
| 6022 | __func__)); |
| 6023 | } else |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 6024 | bcmerror = -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6025 | } else |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 6026 | bcmerror = -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6027 | } else { |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 6028 | bcmerror = -EISCONN; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 6029 | DHD_ERROR(("%s: Set DEVRESET=false invoked when device " |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6030 | "is on\n", __func__)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 6031 | bcmerror = -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6032 | } |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 6033 | brcmf_sdbrcm_wd_timer(bus, brcmf_watchdog_ms); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6034 | } |
| 6035 | return bcmerror; |
| 6036 | } |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6037 | |
| 6038 | static int |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 6039 | brcmf_sdbrcm_chip_recognition(struct brcmf_sdio *sdh, struct chip_info *ci, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6040 | void *regs) |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6041 | { |
| 6042 | u32 regdata; |
| 6043 | |
| 6044 | /* |
| 6045 | * Get CC core rev |
| 6046 | * Chipid is assume to be at offset 0 from regs arg |
| 6047 | * For different chiptypes or old sdio hosts w/o chipcommon, |
| 6048 | * other ways of recognition should be added here. |
| 6049 | */ |
| 6050 | ci->cccorebase = (u32)regs; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6051 | regdata = brcmf_sdcard_reg_read(sdh, |
| 6052 | CORE_CC_REG(ci->cccorebase, chipid), 4); |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6053 | ci->chip = regdata & CID_ID_MASK; |
| 6054 | ci->chiprev = (regdata & CID_REV_MASK) >> CID_REV_SHIFT; |
| 6055 | |
| 6056 | DHD_INFO(("%s: chipid=0x%x chiprev=%d\n", |
| 6057 | __func__, ci->chip, ci->chiprev)); |
| 6058 | |
| 6059 | /* Address of cores for new chips should be added here */ |
| 6060 | switch (ci->chip) { |
| 6061 | case BCM4329_CHIP_ID: |
| 6062 | ci->buscorebase = BCM4329_CORE_BUS_BASE; |
| 6063 | ci->ramcorebase = BCM4329_CORE_SOCRAM_BASE; |
| 6064 | ci->armcorebase = BCM4329_CORE_ARM_BASE; |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 6065 | ci->ramsize = BCM4329_RAMSIZE; |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6066 | break; |
| 6067 | default: |
| 6068 | DHD_ERROR(("%s: chipid 0x%x is not supported\n", |
| 6069 | __func__, ci->chip)); |
| 6070 | return -ENODEV; |
| 6071 | } |
| 6072 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6073 | regdata = brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6074 | CORE_SB(ci->cccorebase, sbidhigh), 4); |
| 6075 | ci->ccrev = SBCOREREV(regdata); |
| 6076 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6077 | regdata = brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6078 | CORE_CC_REG(ci->cccorebase, pmucapabilities), 4); |
| 6079 | ci->pmurev = regdata & PCAP_REV_MASK; |
| 6080 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6081 | regdata = brcmf_sdcard_reg_read(sdh, |
| 6082 | CORE_SB(ci->buscorebase, sbidhigh), 4); |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6083 | ci->buscorerev = SBCOREREV(regdata); |
| 6084 | ci->buscoretype = (regdata & SBIDH_CC_MASK) >> SBIDH_CC_SHIFT; |
| 6085 | |
| 6086 | DHD_INFO(("%s: ccrev=%d, pmurev=%d, buscore rev/type=%d/0x%x\n", |
| 6087 | __func__, ci->ccrev, ci->pmurev, |
| 6088 | ci->buscorerev, ci->buscoretype)); |
| 6089 | |
| 6090 | /* get chipcommon capabilites */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6091 | ci->cccaps = brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6092 | CORE_CC_REG(ci->cccorebase, capabilities), 4); |
| 6093 | |
| 6094 | return 0; |
| 6095 | } |
| 6096 | |
| 6097 | static void |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 6098 | brcmf_sdbrcm_chip_disablecore(struct brcmf_sdio *sdh, u32 corebase) |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6099 | { |
| 6100 | u32 regdata; |
| 6101 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6102 | regdata = brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6103 | CORE_SB(corebase, sbtmstatelow), 4); |
| 6104 | if (regdata & SBTML_RESET) |
| 6105 | return; |
| 6106 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6107 | regdata = brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6108 | CORE_SB(corebase, sbtmstatelow), 4); |
| 6109 | if ((regdata & (SICF_CLOCK_EN << SBTML_SICF_SHIFT)) != 0) { |
| 6110 | /* |
| 6111 | * set target reject and spin until busy is clear |
| 6112 | * (preserve core-specific bits) |
| 6113 | */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6114 | regdata = brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6115 | CORE_SB(corebase, sbtmstatelow), 4); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6116 | brcmf_sdcard_reg_write(sdh, CORE_SB(corebase, sbtmstatelow), 4, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6117 | regdata | SBTML_REJ); |
| 6118 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6119 | regdata = brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6120 | CORE_SB(corebase, sbtmstatelow), 4); |
| 6121 | udelay(1); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6122 | SPINWAIT((brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6123 | CORE_SB(corebase, sbtmstatehigh), 4) & |
| 6124 | SBTMH_BUSY), 100000); |
| 6125 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6126 | regdata = brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6127 | CORE_SB(corebase, sbtmstatehigh), 4); |
| 6128 | if (regdata & SBTMH_BUSY) |
| 6129 | DHD_ERROR(("%s: ARM core still busy\n", __func__)); |
| 6130 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6131 | regdata = brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6132 | CORE_SB(corebase, sbidlow), 4); |
| 6133 | if (regdata & SBIDL_INIT) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6134 | regdata = brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6135 | CORE_SB(corebase, sbimstate), 4) | |
| 6136 | SBIM_RJ; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6137 | brcmf_sdcard_reg_write(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6138 | CORE_SB(corebase, sbimstate), 4, |
| 6139 | regdata); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6140 | regdata = brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6141 | CORE_SB(corebase, sbimstate), 4); |
| 6142 | udelay(1); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6143 | SPINWAIT((brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6144 | CORE_SB(corebase, sbimstate), 4) & |
| 6145 | SBIM_BY), 100000); |
| 6146 | } |
| 6147 | |
| 6148 | /* set reset and reject while enabling the clocks */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6149 | brcmf_sdcard_reg_write(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6150 | CORE_SB(corebase, sbtmstatelow), 4, |
| 6151 | (((SICF_FGC | SICF_CLOCK_EN) << SBTML_SICF_SHIFT) | |
| 6152 | SBTML_REJ | SBTML_RESET)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6153 | regdata = brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6154 | CORE_SB(corebase, sbtmstatelow), 4); |
| 6155 | udelay(10); |
| 6156 | |
| 6157 | /* clear the initiator reject bit */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6158 | regdata = brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6159 | CORE_SB(corebase, sbidlow), 4); |
| 6160 | if (regdata & SBIDL_INIT) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6161 | regdata = brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6162 | CORE_SB(corebase, sbimstate), 4) & |
| 6163 | ~SBIM_RJ; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6164 | brcmf_sdcard_reg_write(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6165 | CORE_SB(corebase, sbimstate), 4, |
| 6166 | regdata); |
| 6167 | } |
| 6168 | } |
| 6169 | |
| 6170 | /* leave reset and reject asserted */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6171 | brcmf_sdcard_reg_write(sdh, CORE_SB(corebase, sbtmstatelow), 4, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6172 | (SBTML_REJ | SBTML_RESET)); |
| 6173 | udelay(1); |
| 6174 | } |
| 6175 | |
| 6176 | static int |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6177 | brcmf_sdbrcm_chip_attach(struct dhd_bus *bus, void *regs) |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6178 | { |
| 6179 | struct chip_info *ci; |
| 6180 | int err; |
| 6181 | u8 clkval, clkset; |
| 6182 | |
| 6183 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 6184 | |
| 6185 | /* alloc chip_info_t */ |
| 6186 | ci = kmalloc(sizeof(struct chip_info), GFP_ATOMIC); |
| 6187 | if (NULL == ci) { |
| 6188 | DHD_ERROR(("%s: malloc failed!\n", __func__)); |
| 6189 | return -ENOMEM; |
| 6190 | } |
| 6191 | |
| 6192 | memset((unsigned char *)ci, 0, sizeof(struct chip_info)); |
| 6193 | |
| 6194 | /* bus/core/clk setup for register access */ |
| 6195 | /* Try forcing SDIO core to do ALPAvail request only */ |
| 6196 | clkset = SBSDIO_FORCE_HW_CLKREQ_OFF | SBSDIO_ALP_AVAIL_REQ; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6197 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6198 | clkset, &err); |
| 6199 | if (err) { |
| 6200 | DHD_ERROR(("%s: error writing for HT off\n", __func__)); |
| 6201 | goto fail; |
| 6202 | } |
| 6203 | |
| 6204 | /* If register supported, wait for ALPAvail and then force ALP */ |
| 6205 | /* This may take up to 15 milliseconds */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6206 | clkval = brcmf_sdcard_cfg_read(bus->sdh, SDIO_FUNC_1, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6207 | SBSDIO_FUNC1_CHIPCLKCSR, NULL); |
| 6208 | if ((clkval & ~SBSDIO_AVBITS) == clkset) { |
| 6209 | SPINWAIT(((clkval = |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6210 | brcmf_sdcard_cfg_read(bus->sdh, SDIO_FUNC_1, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6211 | SBSDIO_FUNC1_CHIPCLKCSR, |
| 6212 | NULL)), |
| 6213 | !SBSDIO_ALPAV(clkval)), |
| 6214 | PMU_MAX_TRANSITION_DLY); |
| 6215 | if (!SBSDIO_ALPAV(clkval)) { |
| 6216 | DHD_ERROR(("%s: timeout on ALPAV wait, clkval 0x%02x\n", |
| 6217 | __func__, clkval)); |
| 6218 | err = -EBUSY; |
| 6219 | goto fail; |
| 6220 | } |
| 6221 | clkset = SBSDIO_FORCE_HW_CLKREQ_OFF | |
| 6222 | SBSDIO_FORCE_ALP; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6223 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_1, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6224 | SBSDIO_FUNC1_CHIPCLKCSR, |
| 6225 | clkset, &err); |
| 6226 | udelay(65); |
| 6227 | } else { |
| 6228 | DHD_ERROR(("%s: ChipClkCSR access: wrote 0x%02x read 0x%02x\n", |
| 6229 | __func__, clkset, clkval)); |
| 6230 | err = -EACCES; |
| 6231 | goto fail; |
| 6232 | } |
| 6233 | |
| 6234 | /* Also, disable the extra SDIO pull-ups */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6235 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_SDIOPULLUP, |
| 6236 | 0, NULL); |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6237 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6238 | err = brcmf_sdbrcm_chip_recognition(bus->sdh, ci, regs); |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6239 | if (err) |
| 6240 | goto fail; |
| 6241 | |
| 6242 | /* |
| 6243 | * Make sure any on-chip ARM is off (in case strapping is wrong), |
| 6244 | * or downloaded code was already running. |
| 6245 | */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6246 | brcmf_sdbrcm_chip_disablecore(bus->sdh, ci->armcorebase); |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6247 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6248 | brcmf_sdcard_reg_write(bus->sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6249 | CORE_CC_REG(ci->cccorebase, gpiopullup), 4, 0); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6250 | brcmf_sdcard_reg_write(bus->sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6251 | CORE_CC_REG(ci->cccorebase, gpiopulldown), 4, 0); |
| 6252 | |
| 6253 | /* Disable F2 to clear any intermediate frame state on the dongle */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6254 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_0, SDIO_CCCR_IOEx, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6255 | SDIO_FUNC_ENABLE_1, NULL); |
| 6256 | |
| 6257 | /* WAR: cmd52 backplane read so core HW will drop ALPReq */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6258 | clkval = brcmf_sdcard_cfg_read(bus->sdh, SDIO_FUNC_1, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6259 | 0, NULL); |
| 6260 | |
| 6261 | /* Done with backplane-dependent accesses, can drop clock... */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6262 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 6263 | 0, NULL); |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6264 | |
| 6265 | bus->ci = ci; |
| 6266 | return 0; |
| 6267 | fail: |
| 6268 | bus->ci = NULL; |
| 6269 | kfree(ci); |
| 6270 | return err; |
| 6271 | } |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6272 | |
| 6273 | static void |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 6274 | brcmf_sdbrcm_chip_resetcore(struct brcmf_sdio *sdh, u32 corebase) |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6275 | { |
| 6276 | u32 regdata; |
| 6277 | |
| 6278 | /* |
| 6279 | * Must do the disable sequence first to work for |
| 6280 | * arbitrary current core state. |
| 6281 | */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6282 | brcmf_sdbrcm_chip_disablecore(sdh, corebase); |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6283 | |
| 6284 | /* |
| 6285 | * Now do the initialization sequence. |
| 6286 | * set reset while enabling the clock and |
| 6287 | * forcing them on throughout the core |
| 6288 | */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6289 | brcmf_sdcard_reg_write(sdh, CORE_SB(corebase, sbtmstatelow), 4, |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6290 | ((SICF_FGC | SICF_CLOCK_EN) << SBTML_SICF_SHIFT) | |
| 6291 | SBTML_RESET); |
| 6292 | udelay(1); |
| 6293 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6294 | regdata = brcmf_sdcard_reg_read(sdh, CORE_SB(corebase, sbtmstatehigh), |
| 6295 | 4); |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6296 | if (regdata & SBTMH_SERR) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6297 | brcmf_sdcard_reg_write(sdh, CORE_SB(corebase, sbtmstatehigh), |
| 6298 | 4, 0); |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6299 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6300 | regdata = brcmf_sdcard_reg_read(sdh, CORE_SB(corebase, sbimstate), 4); |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6301 | if (regdata & (SBIM_IBE | SBIM_TO)) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6302 | brcmf_sdcard_reg_write(sdh, CORE_SB(corebase, sbimstate), 4, |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6303 | regdata & ~(SBIM_IBE | SBIM_TO)); |
| 6304 | |
| 6305 | /* clear reset and allow it to propagate throughout the core */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6306 | brcmf_sdcard_reg_write(sdh, CORE_SB(corebase, sbtmstatelow), 4, |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6307 | (SICF_FGC << SBTML_SICF_SHIFT) | |
| 6308 | (SICF_CLOCK_EN << SBTML_SICF_SHIFT)); |
| 6309 | udelay(1); |
| 6310 | |
| 6311 | /* leave clock enabled */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6312 | brcmf_sdcard_reg_write(sdh, CORE_SB(corebase, sbtmstatelow), 4, |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6313 | (SICF_CLOCK_EN << SBTML_SICF_SHIFT)); |
| 6314 | udelay(1); |
| 6315 | } |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 6316 | |
| 6317 | /* SDIO Pad drive strength to select value mappings */ |
| 6318 | struct sdiod_drive_str { |
| 6319 | u8 strength; /* Pad Drive Strength in mA */ |
| 6320 | u8 sel; /* Chip-specific select value */ |
| 6321 | }; |
| 6322 | |
| 6323 | /* SDIO Drive Strength to sel value table for PMU Rev 1 */ |
| 6324 | static const struct sdiod_drive_str sdiod_drive_strength_tab1[] = { |
| 6325 | { |
| 6326 | 4, 0x2}, { |
| 6327 | 2, 0x3}, { |
| 6328 | 1, 0x0}, { |
| 6329 | 0, 0x0} |
| 6330 | }; |
| 6331 | |
| 6332 | /* SDIO Drive Strength to sel value table for PMU Rev 2, 3 */ |
| 6333 | static const struct sdiod_drive_str sdiod_drive_strength_tab2[] = { |
| 6334 | { |
| 6335 | 12, 0x7}, { |
| 6336 | 10, 0x6}, { |
| 6337 | 8, 0x5}, { |
| 6338 | 6, 0x4}, { |
| 6339 | 4, 0x2}, { |
| 6340 | 2, 0x1}, { |
| 6341 | 0, 0x0} |
| 6342 | }; |
| 6343 | |
| 6344 | /* SDIO Drive Strength to sel value table for PMU Rev 8 (1.8V) */ |
| 6345 | static const struct sdiod_drive_str sdiod_drive_strength_tab3[] = { |
| 6346 | { |
| 6347 | 32, 0x7}, { |
| 6348 | 26, 0x6}, { |
| 6349 | 22, 0x5}, { |
| 6350 | 16, 0x4}, { |
| 6351 | 12, 0x3}, { |
| 6352 | 8, 0x2}, { |
| 6353 | 4, 0x1}, { |
| 6354 | 0, 0x0} |
| 6355 | }; |
| 6356 | |
| 6357 | #define SDIOD_DRVSTR_KEY(chip, pmu) (((chip) << 16) | (pmu)) |
| 6358 | |
| 6359 | static void |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6360 | brcmf_sdbrcm_sdiod_drive_strength_init(struct dhd_bus *bus, u32 drivestrength) { |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 6361 | struct sdiod_drive_str *str_tab = NULL; |
| 6362 | u32 str_mask = 0; |
| 6363 | u32 str_shift = 0; |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 6364 | char chn[8]; |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 6365 | |
| 6366 | if (!(bus->ci->cccaps & CC_CAP_PMU)) |
| 6367 | return; |
| 6368 | |
| 6369 | switch (SDIOD_DRVSTR_KEY(bus->ci->chip, bus->ci->pmurev)) { |
| 6370 | case SDIOD_DRVSTR_KEY(BCM4325_CHIP_ID, 1): |
| 6371 | str_tab = (struct sdiod_drive_str *)&sdiod_drive_strength_tab1; |
| 6372 | str_mask = 0x30000000; |
| 6373 | str_shift = 28; |
| 6374 | break; |
| 6375 | case SDIOD_DRVSTR_KEY(BCM4325_CHIP_ID, 2): |
| 6376 | case SDIOD_DRVSTR_KEY(BCM4325_CHIP_ID, 3): |
| 6377 | str_tab = (struct sdiod_drive_str *)&sdiod_drive_strength_tab2; |
| 6378 | str_mask = 0x00003800; |
| 6379 | str_shift = 11; |
| 6380 | break; |
| 6381 | case SDIOD_DRVSTR_KEY(BCM4336_CHIP_ID, 8): |
| 6382 | str_tab = (struct sdiod_drive_str *)&sdiod_drive_strength_tab3; |
| 6383 | str_mask = 0x00003800; |
| 6384 | str_shift = 11; |
| 6385 | break; |
| 6386 | default: |
| 6387 | DHD_ERROR(("No SDIO Drive strength init" |
| 6388 | "done for chip %s rev %d pmurev %d\n", |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 6389 | brcmu_chipname(bus->ci->chip, chn, 8), |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 6390 | bus->ci->chiprev, bus->ci->pmurev)); |
| 6391 | break; |
| 6392 | } |
| 6393 | |
| 6394 | if (str_tab != NULL) { |
| 6395 | u32 drivestrength_sel = 0; |
| 6396 | u32 cc_data_temp; |
| 6397 | int i; |
| 6398 | |
| 6399 | for (i = 0; str_tab[i].strength != 0; i++) { |
| 6400 | if (drivestrength >= str_tab[i].strength) { |
| 6401 | drivestrength_sel = str_tab[i].sel; |
| 6402 | break; |
| 6403 | } |
| 6404 | } |
| 6405 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6406 | brcmf_sdcard_reg_write(bus->sdh, |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 6407 | CORE_CC_REG(bus->ci->cccorebase, chipcontrol_addr), |
| 6408 | 4, 1); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6409 | cc_data_temp = brcmf_sdcard_reg_read(bus->sdh, |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 6410 | CORE_CC_REG(bus->ci->cccorebase, chipcontrol_addr), 4); |
| 6411 | cc_data_temp &= ~str_mask; |
| 6412 | drivestrength_sel <<= str_shift; |
| 6413 | cc_data_temp |= drivestrength_sel; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6414 | brcmf_sdcard_reg_write(bus->sdh, |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 6415 | CORE_CC_REG(bus->ci->cccorebase, chipcontrol_addr), |
| 6416 | 4, cc_data_temp); |
| 6417 | |
| 6418 | DHD_INFO(("SDIO: %dmA drive strength selected, set to 0x%08x\n", |
| 6419 | drivestrength, cc_data_temp)); |
| 6420 | } |
| 6421 | } |
Franky Lin | cee3cf4 | 2011-04-25 19:34:06 -0700 | [diff] [blame] | 6422 | |
| 6423 | static void |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6424 | brcmf_sdbrcm_chip_detach(struct dhd_bus *bus) |
Franky Lin | cee3cf4 | 2011-04-25 19:34:06 -0700 | [diff] [blame] | 6425 | { |
| 6426 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 6427 | |
| 6428 | kfree(bus->ci); |
| 6429 | bus->ci = NULL; |
| 6430 | } |
Franky Lin | b7adfa7 | 2011-06-29 16:47:42 -0700 | [diff] [blame] | 6431 | |
| 6432 | static void |
| 6433 | brcmf_sdbrcm_wait_for_event(dhd_pub_t *dhd, bool *lockvar) |
| 6434 | { |
| 6435 | brcmf_os_sdunlock(dhd); |
| 6436 | wait_event_interruptible_timeout(dhd->bus->ctrl_wait, |
| 6437 | (*lockvar == false), HZ * 2); |
| 6438 | brcmf_os_sdlock(dhd); |
| 6439 | return; |
| 6440 | } |
| 6441 | |
| 6442 | static void |
| 6443 | brcmf_sdbrcm_wait_event_wakeup(dhd_bus_t *bus) |
| 6444 | { |
| 6445 | if (waitqueue_active(&bus->ctrl_wait)) |
| 6446 | wake_up_interruptible(&bus->ctrl_wait); |
| 6447 | return; |
| 6448 | } |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 6449 | |
| 6450 | static int |
| 6451 | brcmf_sdbrcm_watchdog_thread(void *data) |
| 6452 | { |
| 6453 | dhd_bus_t *bus = (dhd_bus_t *)data; |
| 6454 | |
| 6455 | /* This thread doesn't need any user-level access, |
| 6456 | * so get rid of all our resources |
| 6457 | */ |
| 6458 | if (brcmf_watchdog_prio > 0) { |
| 6459 | struct sched_param param; |
| 6460 | param.sched_priority = (brcmf_watchdog_prio < MAX_RT_PRIO) ? |
| 6461 | brcmf_watchdog_prio : (MAX_RT_PRIO - 1); |
| 6462 | sched_setscheduler(current, SCHED_FIFO, ¶m); |
| 6463 | } |
| 6464 | |
| 6465 | allow_signal(SIGTERM); |
| 6466 | /* Run until signal received */ |
| 6467 | while (1) { |
| 6468 | if (kthread_should_stop()) |
| 6469 | break; |
| 6470 | if (!wait_for_completion_interruptible(&bus->watchdog_wait)) { |
| 6471 | if (bus->dhd->dongle_reset == false) |
| 6472 | brcmf_sdbrcm_bus_watchdog(bus->dhd); |
| 6473 | /* Count the tick for reference */ |
| 6474 | bus->dhd->tickcnt++; |
| 6475 | } else |
| 6476 | break; |
| 6477 | } |
| 6478 | return 0; |
| 6479 | } |
| 6480 | |
| 6481 | static void |
| 6482 | brcmf_sdbrcm_watchdog(unsigned long data) |
| 6483 | { |
| 6484 | dhd_bus_t *bus = (dhd_bus_t *)data; |
| 6485 | |
| 6486 | if (brcmf_watchdog_prio >= 0) { |
| 6487 | if (bus->watchdog_tsk) |
| 6488 | complete(&bus->watchdog_wait); |
| 6489 | else |
| 6490 | return; |
| 6491 | } else { |
| 6492 | brcmf_sdbrcm_bus_watchdog(bus->dhd); |
| 6493 | |
| 6494 | /* Count the tick for reference */ |
| 6495 | bus->dhd->tickcnt++; |
| 6496 | } |
| 6497 | |
| 6498 | /* Reschedule the watchdog */ |
| 6499 | if (bus->wd_timer_valid) |
| 6500 | mod_timer(&bus->timer, jiffies + brcmf_watchdog_ms * HZ / 1000); |
| 6501 | } |
| 6502 | |
| 6503 | void |
| 6504 | brcmf_sdbrcm_wd_timer(struct dhd_bus *bus, uint wdtick) |
| 6505 | { |
| 6506 | static uint save_ms; |
| 6507 | |
| 6508 | /* don't start the wd until fw is loaded */ |
| 6509 | if (bus->dhd->busstate == DHD_BUS_DOWN) |
| 6510 | return; |
| 6511 | |
| 6512 | /* Totally stop the timer */ |
| 6513 | if (!wdtick && bus->wd_timer_valid == true) { |
| 6514 | del_timer_sync(&bus->timer); |
| 6515 | bus->wd_timer_valid = false; |
| 6516 | save_ms = wdtick; |
| 6517 | return; |
| 6518 | } |
| 6519 | |
| 6520 | if (wdtick) { |
| 6521 | brcmf_watchdog_ms = (uint) wdtick; |
| 6522 | |
| 6523 | if (save_ms != brcmf_watchdog_ms) { |
| 6524 | if (bus->wd_timer_valid == true) |
| 6525 | /* Stop timer and restart at new value */ |
| 6526 | del_timer_sync(&bus->timer); |
| 6527 | |
| 6528 | /* Create timer again when watchdog period is |
| 6529 | dynamically changed or in the first instance |
| 6530 | */ |
| 6531 | bus->timer.expires = |
| 6532 | jiffies + brcmf_watchdog_ms * HZ / 1000; |
| 6533 | add_timer(&bus->timer); |
| 6534 | |
| 6535 | } else { |
| 6536 | /* Re arm the timer, at last watchdog period */ |
| 6537 | mod_timer(&bus->timer, |
| 6538 | jiffies + brcmf_watchdog_ms * HZ / 1000); |
| 6539 | } |
| 6540 | |
| 6541 | bus->wd_timer_valid = true; |
| 6542 | save_ms = wdtick; |
| 6543 | } |
| 6544 | } |