Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2010 Broadcom Corporation |
| 3 | * |
| 4 | * Permission to use, copy, modify, and/or distribute this software for any |
| 5 | * purpose with or without fee is hereby granted, provided that the above |
| 6 | * copyright notice and this permission notice appear in all copies. |
| 7 | * |
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 11 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
| 13 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 14 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | */ |
| 16 | |
Greg Kroah-Hartman | a1c16ed | 2010-10-21 11:17:44 -0700 | [diff] [blame] | 17 | #include <linux/types.h> |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 18 | #include <linux/kernel.h> |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 19 | #include <linux/kthread.h> |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 20 | #include <linux/printk.h> |
Stanislav Fomichev | be1c09f | 2011-03-28 01:31:36 +0400 | [diff] [blame] | 21 | #include <linux/pci_ids.h> |
Brett Rudley | c6ac24e | 2010-10-26 11:55:23 -0700 | [diff] [blame] | 22 | #include <linux/netdevice.h> |
Franky Lin | 7c6100e | 2011-06-01 13:45:36 +0200 | [diff] [blame] | 23 | #include <linux/sched.h> |
Franky Lin | 0df4604 | 2011-06-01 13:45:40 +0200 | [diff] [blame] | 24 | #include <linux/mmc/sdio.h> |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 25 | #include <linux/mmc/sdio_func.h> |
| 26 | #include <linux/firmware.h> |
Franky Lin | 7c6100e | 2011-06-01 13:45:36 +0200 | [diff] [blame] | 27 | #include <asm/unaligned.h> |
Roland Vossen | cc3cea5 | 2011-06-01 13:45:59 +0200 | [diff] [blame] | 28 | #include <defs.h> |
Roland Vossen | f97e956 | 2011-06-01 13:45:52 +0200 | [diff] [blame] | 29 | #include <brcmu_wifi.h> |
| 30 | #include <brcmu_utils.h> |
Roland Vossen | cc3cea5 | 2011-06-01 13:45:59 +0200 | [diff] [blame] | 31 | #include <brcm_hw_ids.h> |
Roland Vossen | cc3cea5 | 2011-06-01 13:45:59 +0200 | [diff] [blame] | 32 | #include <soc.h> |
Roland Vossen | c4daa84 | 2011-06-09 16:44:50 +0200 | [diff] [blame] | 33 | #include "sdio_host.h" |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 34 | #include "bcmsdbus.h" |
| 35 | #include "bcmsdh_sdmmc.h" |
Roland Vossen | 4489518 | 2011-06-01 13:45:55 +0200 | [diff] [blame] | 36 | |
| 37 | /* register access macros */ |
Roland Vossen | 4489518 | 2011-06-01 13:45:55 +0200 | [diff] [blame] | 38 | #ifndef __BIG_ENDIAN |
| 39 | #ifndef __mips__ |
Roland Vossen | b61a4be | 2011-06-01 13:45:56 +0200 | [diff] [blame] | 40 | #define R_REG(r) \ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 41 | brcmf_sdcard_reg_read(NULL, (unsigned long)(r), sizeof(*(r))) |
Roland Vossen | 4489518 | 2011-06-01 13:45:55 +0200 | [diff] [blame] | 42 | #else /* __mips__ */ |
Roland Vossen | b61a4be | 2011-06-01 13:45:56 +0200 | [diff] [blame] | 43 | #define R_REG(r) \ |
| 44 | ({ \ |
| 45 | __typeof(*(r)) __osl_v; \ |
| 46 | __asm__ __volatile__("sync"); \ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 47 | __osl_v = brcmf_sdcard_reg_read(NULL, (unsigned long)(r),\ |
Roland Vossen | 2503634 | 2011-06-01 13:45:57 +0200 | [diff] [blame] | 48 | sizeof(*(r))); \ |
Roland Vossen | b61a4be | 2011-06-01 13:45:56 +0200 | [diff] [blame] | 49 | __asm__ __volatile__("sync"); \ |
| 50 | __osl_v; \ |
| 51 | }) |
Roland Vossen | 4489518 | 2011-06-01 13:45:55 +0200 | [diff] [blame] | 52 | #endif /* __mips__ */ |
| 53 | |
| 54 | #define W_REG(r, v) do { \ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 55 | brcmf_sdcard_reg_write(NULL, (unsigned long)(r), sizeof(*(r)), \ |
| 56 | (v)); \ |
Roland Vossen | 4489518 | 2011-06-01 13:45:55 +0200 | [diff] [blame] | 57 | } while (0) |
| 58 | #else /* __BIG_ENDIAN */ |
Roland Vossen | b61a4be | 2011-06-01 13:45:56 +0200 | [diff] [blame] | 59 | #define R_REG(r) \ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 60 | brcmf_sdcard_reg_read(NULL, (unsigned long)(r), sizeof(*(r))) |
Roland Vossen | 4489518 | 2011-06-01 13:45:55 +0200 | [diff] [blame] | 61 | #define W_REG(r, v) do { \ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 62 | brcmf_sdcard_reg_write(NULL, (unsigned long)(r), sizeof(*(r)), \ |
| 63 | (v)); \ |
Roland Vossen | 4489518 | 2011-06-01 13:45:55 +0200 | [diff] [blame] | 64 | } while (0) |
| 65 | #endif /* __BIG_ENDIAN */ |
| 66 | |
Roland Vossen | 4489518 | 2011-06-01 13:45:55 +0200 | [diff] [blame] | 67 | #define AND_REG(r, v) W_REG((r), R_REG(r) & (v)) |
| 68 | #define OR_REG(r, v) W_REG((r), R_REG(r) | (v)) |
| 69 | |
| 70 | #define SET_REG(r, mask, val) \ |
| 71 | W_REG((r), ((R_REG(r) & ~(mask)) | (val))) |
| 72 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 73 | #ifdef BCMDBG |
Roland Vossen | f1c7a08 | 2011-06-01 13:45:09 +0200 | [diff] [blame] | 74 | |
| 75 | /* ARM trap handling */ |
| 76 | |
| 77 | /* Trap types defined by ARM (see arminc.h) */ |
| 78 | |
| 79 | /* Trap locations in lo memory */ |
| 80 | #define TRAP_STRIDE 4 |
| 81 | #define FIRST_TRAP TR_RST |
| 82 | #define LAST_TRAP (TR_FIQ * TRAP_STRIDE) |
| 83 | |
| 84 | #if defined(__ARM_ARCH_4T__) |
| 85 | #define MAX_TRAP_TYPE (TR_FIQ + 1) |
| 86 | #elif defined(__ARM_ARCH_7M__) |
| 87 | #define MAX_TRAP_TYPE (TR_ISR + ARMCM3_NUMINTS) |
| 88 | #endif /* __ARM_ARCH_7M__ */ |
| 89 | |
| 90 | /* The trap structure is defined here as offsets for assembly */ |
| 91 | #define TR_TYPE 0x00 |
| 92 | #define TR_EPC 0x04 |
| 93 | #define TR_CPSR 0x08 |
| 94 | #define TR_SPSR 0x0c |
| 95 | #define TR_REGS 0x10 |
| 96 | #define TR_REG(n) (TR_REGS + (n) * 4) |
| 97 | #define TR_SP TR_REG(13) |
| 98 | #define TR_LR TR_REG(14) |
| 99 | #define TR_PC TR_REG(15) |
| 100 | |
| 101 | #define TRAP_T_SIZE 80 |
| 102 | |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 103 | struct brcmf_trap { |
Roland Vossen | f1c7a08 | 2011-06-01 13:45:09 +0200 | [diff] [blame] | 104 | u32 type; |
| 105 | u32 epc; |
| 106 | u32 cpsr; |
| 107 | u32 spsr; |
| 108 | u32 r0; |
| 109 | u32 r1; |
| 110 | u32 r2; |
| 111 | u32 r3; |
| 112 | u32 r4; |
| 113 | u32 r5; |
| 114 | u32 r6; |
| 115 | u32 r7; |
| 116 | u32 r8; |
| 117 | u32 r9; |
| 118 | u32 r10; |
| 119 | u32 r11; |
| 120 | u32 r12; |
| 121 | u32 r13; |
| 122 | u32 r14; |
| 123 | u32 pc; |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 124 | }; |
Roland Vossen | f1c7a08 | 2011-06-01 13:45:09 +0200 | [diff] [blame] | 125 | |
Roland Vossen | f1c7a08 | 2011-06-01 13:45:09 +0200 | [diff] [blame] | 126 | #define CBUF_LEN (128) |
| 127 | |
| 128 | #define LOG_BUF_LEN 1024 |
| 129 | |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 130 | struct rte_log { |
Roland Vossen | f1c7a08 | 2011-06-01 13:45:09 +0200 | [diff] [blame] | 131 | u32 buf; /* Can't be pointer on (64-bit) hosts */ |
| 132 | uint buf_size; |
| 133 | uint idx; |
| 134 | char *_buf_compat; /* Redundant pointer for backward compat. */ |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 135 | }; |
Roland Vossen | f1c7a08 | 2011-06-01 13:45:09 +0200 | [diff] [blame] | 136 | |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 137 | struct rte_console { |
Roland Vossen | f1c7a08 | 2011-06-01 13:45:09 +0200 | [diff] [blame] | 138 | /* Virtual UART |
| 139 | * When there is no UART (e.g. Quickturn), |
| 140 | * the host should write a complete |
| 141 | * input line directly into cbuf and then write |
| 142 | * the length into vcons_in. |
| 143 | * This may also be used when there is a real UART |
| 144 | * (at risk of conflicting with |
| 145 | * the real UART). vcons_out is currently unused. |
| 146 | */ |
| 147 | volatile uint vcons_in; |
| 148 | volatile uint vcons_out; |
| 149 | |
| 150 | /* Output (logging) buffer |
| 151 | * Console output is written to a ring buffer log_buf at index log_idx. |
| 152 | * The host may read the output when it sees log_idx advance. |
| 153 | * Output will be lost if the output wraps around faster than the host |
| 154 | * polls. |
| 155 | */ |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 156 | struct rte_log log; |
Roland Vossen | f1c7a08 | 2011-06-01 13:45:09 +0200 | [diff] [blame] | 157 | |
| 158 | /* Console input line buffer |
| 159 | * Characters are read one at a time into cbuf |
| 160 | * until <CR> is received, then |
| 161 | * the buffer is processed as a command line. |
| 162 | * Also used for virtual UART. |
| 163 | */ |
| 164 | uint cbuf_idx; |
| 165 | char cbuf[CBUF_LEN]; |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 166 | }; |
Roland Vossen | f1c7a08 | 2011-06-01 13:45:09 +0200 | [diff] [blame] | 167 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 168 | #endif /* BCMDBG */ |
Roland Vossen | 745c9e6 | 2011-06-01 13:45:30 +0200 | [diff] [blame] | 169 | #include <chipcommon.h> |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 170 | |
Roland Vossen | c4daa84 | 2011-06-09 16:44:50 +0200 | [diff] [blame] | 171 | #include "sbsdio.h" |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 172 | |
Roland Vossen | c4daa84 | 2011-06-09 16:44:50 +0200 | [diff] [blame] | 173 | #include "dngl_stats.h" |
| 174 | #include "dhd.h" |
| 175 | #include "dhd_bus.h" |
| 176 | #include "dhd_proto.h" |
| 177 | #include "dhd_dbg.h" |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 178 | #include <sdiovar.h> |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 179 | #include <bcmchip.h> |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 180 | |
| 181 | #ifndef DHDSDIO_MEM_DUMP_FNAME |
| 182 | #define DHDSDIO_MEM_DUMP_FNAME "mem_dump" |
| 183 | #endif |
| 184 | |
Grant Grundler | 26a71a4 | 2011-03-09 10:41:25 -0800 | [diff] [blame] | 185 | #define TXQLEN 2048 /* bulk tx queue length */ |
| 186 | #define TXHI (TXQLEN - 256) /* turn on flow control above TXHI */ |
| 187 | #define TXLOW (TXHI - 256) /* turn off flow control below TXLOW */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 188 | #define PRIOMASK 7 |
| 189 | |
| 190 | #define TXRETRIES 2 /* # of retries for tx frames */ |
| 191 | |
| 192 | #if defined(CONFIG_MACH_SANDGATE2G) |
| 193 | #define DHD_RXBOUND 250 /* Default for max rx frames in |
| 194 | one scheduling */ |
| 195 | #else |
| 196 | #define DHD_RXBOUND 50 /* Default for max rx frames in |
| 197 | one scheduling */ |
| 198 | #endif /* defined(CONFIG_MACH_SANDGATE2G) */ |
| 199 | |
| 200 | #define DHD_TXBOUND 20 /* Default for max tx frames in |
| 201 | one scheduling */ |
| 202 | |
| 203 | #define DHD_TXMINMAX 1 /* Max tx frames if rx still pending */ |
| 204 | |
| 205 | #define MEMBLOCK 2048 /* Block size used for downloading |
| 206 | of dongle image */ |
| 207 | #define MAX_DATA_BUF (32 * 1024) /* Must be large enough to hold |
| 208 | biggest possible glom */ |
| 209 | |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 210 | #ifndef BRCMF_FIRSTREAD |
| 211 | #define BRCMF_FIRSTREAD 32 |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 212 | #endif |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 213 | #if !ISPOWEROF2(BRCMF_FIRSTREAD) |
| 214 | #error BRCMF_FIRSTREAD is not a power of 2! |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 215 | #endif |
| 216 | |
| 217 | /* Total length of frame header for dongle protocol */ |
| 218 | #define SDPCM_HDRLEN (SDPCM_FRAMETAG_LEN + SDPCM_SWHEADER_LEN) |
| 219 | #ifdef SDTEST |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 220 | #define SDPCM_RESERVE (SDPCM_HDRLEN + SDPCM_TEST_HDRLEN + BRCMF_SDALIGN) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 221 | #else |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 222 | #define SDPCM_RESERVE (SDPCM_HDRLEN + BRCMF_SDALIGN) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 223 | #endif |
| 224 | |
Franky Lin | b49b14d | 2011-06-01 13:45:37 +0200 | [diff] [blame] | 225 | /* |
| 226 | * Software allocation of To SB Mailbox resources |
| 227 | */ |
| 228 | |
| 229 | /* tosbmailbox bits corresponding to intstatus bits */ |
| 230 | #define SMB_NAK (1 << 0) /* Frame NAK */ |
| 231 | #define SMB_INT_ACK (1 << 1) /* Host Interrupt ACK */ |
| 232 | #define SMB_USE_OOB (1 << 2) /* Use OOB Wakeup */ |
| 233 | #define SMB_DEV_INT (1 << 3) /* Miscellaneous Interrupt */ |
| 234 | |
| 235 | /* tosbmailboxdata */ |
| 236 | #define SMB_DATA_VERSION_SHIFT 16 /* host protocol version */ |
| 237 | |
| 238 | /* |
| 239 | * Software allocation of To Host Mailbox resources |
| 240 | */ |
| 241 | |
| 242 | /* intstatus bits */ |
| 243 | #define I_HMB_FC_STATE I_HMB_SW0 /* Flow Control State */ |
| 244 | #define I_HMB_FC_CHANGE I_HMB_SW1 /* Flow Control State Changed */ |
| 245 | #define I_HMB_FRAME_IND I_HMB_SW2 /* Frame Indication */ |
| 246 | #define I_HMB_HOST_INT I_HMB_SW3 /* Miscellaneous Interrupt */ |
| 247 | |
| 248 | /* tohostmailboxdata */ |
| 249 | #define HMB_DATA_NAKHANDLED 1 /* retransmit NAK'd frame */ |
| 250 | #define HMB_DATA_DEVREADY 2 /* talk to host after enable */ |
| 251 | #define HMB_DATA_FC 4 /* per prio flowcontrol update flag */ |
| 252 | #define HMB_DATA_FWREADY 8 /* fw ready for protocol activity */ |
| 253 | |
| 254 | #define HMB_DATA_FCDATA_MASK 0xff000000 |
| 255 | #define HMB_DATA_FCDATA_SHIFT 24 |
| 256 | |
| 257 | #define HMB_DATA_VERSION_MASK 0x00ff0000 |
| 258 | #define HMB_DATA_VERSION_SHIFT 16 |
| 259 | |
| 260 | /* |
| 261 | * Software-defined protocol header |
| 262 | */ |
| 263 | |
| 264 | /* Current protocol version */ |
| 265 | #define SDPCM_PROT_VERSION 4 |
| 266 | |
| 267 | /* SW frame header */ |
| 268 | #define SDPCM_PACKET_SEQUENCE(p) (((u8 *)p)[0] & 0xff) |
| 269 | |
| 270 | #define SDPCM_CHANNEL_MASK 0x00000f00 |
| 271 | #define SDPCM_CHANNEL_SHIFT 8 |
| 272 | #define SDPCM_PACKET_CHANNEL(p) (((u8 *)p)[1] & 0x0f) |
| 273 | |
| 274 | #define SDPCM_NEXTLEN_OFFSET 2 |
| 275 | |
| 276 | /* Data Offset from SOF (HW Tag, SW Tag, Pad) */ |
| 277 | #define SDPCM_DOFFSET_OFFSET 3 /* Data Offset */ |
| 278 | #define SDPCM_DOFFSET_VALUE(p) (((u8 *)p)[SDPCM_DOFFSET_OFFSET] & 0xff) |
| 279 | #define SDPCM_DOFFSET_MASK 0xff000000 |
| 280 | #define SDPCM_DOFFSET_SHIFT 24 |
| 281 | #define SDPCM_FCMASK_OFFSET 4 /* Flow control */ |
| 282 | #define SDPCM_FCMASK_VALUE(p) (((u8 *)p)[SDPCM_FCMASK_OFFSET] & 0xff) |
| 283 | #define SDPCM_WINDOW_OFFSET 5 /* Credit based fc */ |
| 284 | #define SDPCM_WINDOW_VALUE(p) (((u8 *)p)[SDPCM_WINDOW_OFFSET] & 0xff) |
| 285 | |
| 286 | #define SDPCM_SWHEADER_LEN 8 /* SW header is 64 bits */ |
| 287 | |
| 288 | /* logical channel numbers */ |
| 289 | #define SDPCM_CONTROL_CHANNEL 0 /* Control channel Id */ |
| 290 | #define SDPCM_EVENT_CHANNEL 1 /* Asyc Event Indication Channel Id */ |
| 291 | #define SDPCM_DATA_CHANNEL 2 /* Data Xmit/Recv Channel Id */ |
| 292 | #define SDPCM_GLOM_CHANNEL 3 /* For coalesced packets */ |
| 293 | #define SDPCM_TEST_CHANNEL 15 /* Reserved for test/debug packets */ |
| 294 | |
| 295 | #define SDPCM_SEQUENCE_WRAP 256 /* wrap-around val for 8bit frame seq */ |
| 296 | |
| 297 | #define SDPCM_GLOMDESC(p) (((u8 *)p)[1] & 0x80) |
| 298 | |
| 299 | /* For TEST_CHANNEL packets, define another 4-byte header */ |
| 300 | #define SDPCM_TEST_HDRLEN 4 /* |
| 301 | * Generally: Cmd(1), Ext(1), Len(2); |
| 302 | * Semantics of Ext byte depend on |
| 303 | * command. Len is current or requested |
| 304 | * frame length, not including test |
| 305 | * header; sent little-endian. |
| 306 | */ |
| 307 | #define SDPCM_TEST_DISCARD 0x01 /* Receiver discards. Ext:pattern id. */ |
| 308 | #define SDPCM_TEST_ECHOREQ 0x02 /* Echo request. Ext:pattern id. */ |
| 309 | #define SDPCM_TEST_ECHORSP 0x03 /* Echo response. Ext:pattern id. */ |
| 310 | #define SDPCM_TEST_BURST 0x04 /* |
| 311 | * Receiver to send a burst. |
| 312 | * Ext is a frame count |
| 313 | */ |
| 314 | #define SDPCM_TEST_SEND 0x05 /* |
| 315 | * Receiver sets send mode. |
| 316 | * Ext is boolean on/off |
| 317 | */ |
| 318 | |
| 319 | /* Handy macro for filling in datagen packets with a pattern */ |
| 320 | #define SDPCM_TEST_FILL(byteno, id) ((u8)(id + byteno)) |
| 321 | |
| 322 | /* |
| 323 | * Shared structure between dongle and the host. |
| 324 | * The structure contains pointers to trap or assert information. |
| 325 | */ |
| 326 | #define SDPCM_SHARED_VERSION 0x0002 |
| 327 | #define SDPCM_SHARED_VERSION_MASK 0x00FF |
| 328 | #define SDPCM_SHARED_ASSERT_BUILT 0x0100 |
| 329 | #define SDPCM_SHARED_ASSERT 0x0200 |
| 330 | #define SDPCM_SHARED_TRAP 0x0400 |
| 331 | |
| 332 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 333 | /* Space for header read, limit for data packets */ |
| 334 | #ifndef MAX_HDR_READ |
| 335 | #define MAX_HDR_READ 32 |
| 336 | #endif |
| 337 | #if !ISPOWEROF2(MAX_HDR_READ) |
| 338 | #error MAX_HDR_READ is not a power of 2! |
| 339 | #endif |
| 340 | |
| 341 | #define MAX_RX_DATASZ 2048 |
| 342 | |
| 343 | /* Maximum milliseconds to wait for F2 to come up */ |
| 344 | #define DHD_WAIT_F2RDY 3000 |
| 345 | |
| 346 | /* Bump up limit on waiting for HT to account for first startup; |
| 347 | * if the image is doing a CRC calculation before programming the PMU |
| 348 | * for HT availability, it could take a couple hundred ms more, so |
| 349 | * max out at a 1 second (1000000us). |
| 350 | */ |
| 351 | #if (PMU_MAX_TRANSITION_DLY <= 1000000) |
| 352 | #undef PMU_MAX_TRANSITION_DLY |
| 353 | #define PMU_MAX_TRANSITION_DLY 1000000 |
| 354 | #endif |
| 355 | |
| 356 | /* Value for ChipClockCSR during initial setup */ |
| 357 | #define DHD_INIT_CLKCTL1 (SBSDIO_FORCE_HW_CLKREQ_OFF | \ |
| 358 | SBSDIO_ALP_AVAIL_REQ) |
| 359 | #define DHD_INIT_CLKCTL2 (SBSDIO_FORCE_HW_CLKREQ_OFF | SBSDIO_FORCE_ALP) |
| 360 | |
| 361 | /* Flags for SDH calls */ |
| 362 | #define F2SYNC (SDIO_REQ_4BYTE | SDIO_REQ_FIXED) |
| 363 | |
Roland Vossen | b6fe70c | 2011-06-01 13:45:19 +0200 | [diff] [blame] | 364 | /* sbimstate */ |
| 365 | #define SBIM_IBE 0x20000 /* inbanderror */ |
| 366 | #define SBIM_TO 0x40000 /* timeout */ |
| 367 | #define SBIM_BY 0x01800000 /* busy (sonics >= 2.3) */ |
| 368 | #define SBIM_RJ 0x02000000 /* reject (sonics >= 2.3) */ |
| 369 | |
| 370 | /* sbtmstatelow */ |
| 371 | #define SBTML_RESET 0x0001 /* reset */ |
| 372 | #define SBTML_REJ_MASK 0x0006 /* reject field */ |
| 373 | #define SBTML_REJ 0x0002 /* reject */ |
| 374 | #define SBTML_TMPREJ 0x0004 /* temporary reject, for error recovery */ |
| 375 | |
| 376 | #define SBTML_SICF_SHIFT 16 /* Shift to locate the SI control flags in sbtml */ |
| 377 | |
| 378 | /* sbtmstatehigh */ |
| 379 | #define SBTMH_SERR 0x0001 /* serror */ |
| 380 | #define SBTMH_INT 0x0002 /* interrupt */ |
| 381 | #define SBTMH_BUSY 0x0004 /* busy */ |
| 382 | #define SBTMH_TO 0x0020 /* timeout (sonics >= 2.3) */ |
| 383 | |
| 384 | #define SBTMH_SISF_SHIFT 16 /* Shift to locate the SI status flags in sbtmh */ |
| 385 | |
| 386 | /* sbidlow */ |
| 387 | #define SBIDL_INIT 0x80 /* initiator */ |
| 388 | |
| 389 | /* sbidhigh */ |
| 390 | #define SBIDH_RC_MASK 0x000f /* revision code */ |
| 391 | #define SBIDH_RCE_MASK 0x7000 /* revision code extension field */ |
| 392 | #define SBIDH_RCE_SHIFT 8 |
| 393 | #define SBCOREREV(sbidh) \ |
| 394 | ((((sbidh) & SBIDH_RCE_MASK) >> SBIDH_RCE_SHIFT) | ((sbidh) & SBIDH_RC_MASK)) |
| 395 | #define SBIDH_CC_MASK 0x8ff0 /* core code */ |
| 396 | #define SBIDH_CC_SHIFT 4 |
| 397 | #define SBIDH_VC_MASK 0xffff0000 /* vendor code */ |
| 398 | #define SBIDH_VC_SHIFT 16 |
| 399 | |
Arend van Spriel | 70dfb58 | 2011-02-25 16:39:17 +0100 | [diff] [blame] | 400 | /* |
| 401 | * Conversion of 802.1D priority to precedence level |
| 402 | */ |
| 403 | #define PRIO2PREC(prio) \ |
| 404 | (((prio) == PRIO_8021D_NONE || (prio) == PRIO_8021D_BE) ? \ |
| 405 | ((prio^2)) : (prio)) |
| 406 | |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 407 | BRCMF_SPINWAIT_SLEEP_INIT(sdioh_spinwait_sleep); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 408 | |
Roland Vossen | b6fe70c | 2011-06-01 13:45:19 +0200 | [diff] [blame] | 409 | /* Core reg address translation */ |
| 410 | #define CORE_CC_REG(base, field) (base + offsetof(chipcregs_t, field)) |
Franky Lin | 597600a | 2011-06-01 13:45:39 +0200 | [diff] [blame] | 411 | #define CORE_BUS_REG(base, field) \ |
| 412 | (base + offsetof(struct sdpcmd_regs, field)) |
Roland Vossen | b6fe70c | 2011-06-01 13:45:19 +0200 | [diff] [blame] | 413 | #define CORE_SB(base, field) \ |
| 414 | (base + SBCONFIGOFF + offsetof(sbconfig_t, field)) |
| 415 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 416 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 417 | /* Device console log buffer state */ |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 418 | struct dhd_console { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 419 | uint count; /* Poll interval msec counter */ |
| 420 | uint log_addr; /* Log struct address (fixed) */ |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 421 | struct rte_log log; /* Log struct (host copy) */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 422 | uint bufsize; /* Size of log buffer */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 423 | u8 *buf; /* Log buffer (host copy) */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 424 | uint last; /* Last buffer read index */ |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 425 | }; |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 426 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 427 | |
Franky Lin | b49b14d | 2011-06-01 13:45:37 +0200 | [diff] [blame] | 428 | struct sdpcm_shared { |
| 429 | u32 flags; |
| 430 | u32 trap_addr; |
| 431 | u32 assert_exp_addr; |
| 432 | u32 assert_file_addr; |
| 433 | u32 assert_line; |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 434 | u32 console_addr; /* Address of struct rte_console */ |
Franky Lin | b49b14d | 2011-06-01 13:45:37 +0200 | [diff] [blame] | 435 | u32 msgtrace_addr; |
| 436 | u8 tag[32]; |
| 437 | }; |
| 438 | |
| 439 | |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 440 | /* misc chip info needed by some of the routines */ |
| 441 | struct chip_info { |
| 442 | u32 chip; |
| 443 | u32 chiprev; |
| 444 | u32 cccorebase; |
| 445 | u32 ccrev; |
| 446 | u32 cccaps; |
| 447 | u32 buscorebase; |
| 448 | u32 buscorerev; |
| 449 | u32 buscoretype; |
| 450 | u32 ramcorebase; |
| 451 | u32 armcorebase; |
| 452 | u32 pmurev; |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 453 | u32 ramsize; |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 454 | }; |
| 455 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 456 | /* Private data for SDIO bus interaction */ |
| 457 | typedef struct dhd_bus { |
| 458 | dhd_pub_t *dhd; |
| 459 | |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 460 | struct brcmf_sdio *sdh; /* Handle for BCMSDH calls */ |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 461 | struct chip_info *ci; /* Chip info struct */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 462 | char *vars; /* Variables (from CIS and/or other) */ |
| 463 | uint varsz; /* Size of variables buffer */ |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 464 | u32 sbaddr; /* Current SB window pointer (-1, invalid) */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 465 | |
Franky Lin | 597600a | 2011-06-01 13:45:39 +0200 | [diff] [blame] | 466 | struct sdpcmd_regs *regs; /* SDIO core */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 467 | uint sdpcmrev; /* SDIO core revision */ |
| 468 | uint armrev; /* CPU core revision */ |
| 469 | uint ramrev; /* SOCRAM core revision */ |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 470 | u32 ramsize; /* Size of RAM in SOCRAM (bytes) */ |
| 471 | u32 orig_ramsize; /* Size of RAM in SOCRAM (bytes) */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 472 | |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 473 | u32 bus; /* gSPI or SDIO bus */ |
| 474 | u32 hostintmask; /* Copy of Host Interrupt Mask */ |
| 475 | u32 intstatus; /* Intstatus bits (events) pending */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 476 | bool dpc_sched; /* Indicates DPC schedule (intrpt rcvd) */ |
| 477 | bool fcstate; /* State of dongle flow-control */ |
| 478 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 479 | u16 cl_devid; /* cached devid for brcmf_sdio_probe_attach() */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 480 | |
| 481 | uint blocksize; /* Block size of SDIO transfers */ |
| 482 | uint roundup; /* Max roundup limit */ |
| 483 | |
| 484 | struct pktq txq; /* Queue length used for flow-control */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 485 | u8 flowcontrol; /* per prio flow control bitmask */ |
| 486 | u8 tx_seq; /* Transmit sequence number (next) */ |
| 487 | u8 tx_max; /* Maximum transmit sequence allowed */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 488 | |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 489 | u8 hdrbuf[MAX_HDR_READ + BRCMF_SDALIGN]; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 490 | u8 *rxhdr; /* Header of current rx frame (in hdrbuf) */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 491 | u16 nextlen; /* Next Read Len from last header */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 492 | u8 rx_seq; /* Receive sequence number (expected) */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 493 | bool rxskip; /* Skip receive (awaiting NAK ACK) */ |
| 494 | |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 495 | struct sk_buff *glomd; /* Packet containing glomming descriptor */ |
| 496 | struct sk_buff *glom; /* Packet chain for glommed superframe */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 497 | uint glomerr; /* Glom packet read errors */ |
| 498 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 499 | u8 *rxbuf; /* Buffer for receiving control packets */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 500 | uint rxblen; /* Allocated length of rxbuf */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 501 | u8 *rxctl; /* Aligned pointer into rxbuf */ |
| 502 | u8 *databuf; /* Buffer for receiving big glom packet */ |
| 503 | u8 *dataptr; /* Aligned pointer into databuf */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 504 | uint rxlen; /* Length of valid data in buffer */ |
| 505 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 506 | u8 sdpcm_ver; /* Bus protocol reported by dongle */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 507 | |
| 508 | bool intr; /* Use interrupts */ |
| 509 | bool poll; /* Use polling */ |
| 510 | bool ipend; /* Device interrupt is pending */ |
| 511 | bool intdis; /* Interrupts disabled by isr */ |
| 512 | uint intrcount; /* Count of device interrupt callbacks */ |
| 513 | uint lastintrs; /* Count as of last watchdog timer */ |
| 514 | uint spurious; /* Count of spurious interrupts */ |
| 515 | uint pollrate; /* Ticks between device polls */ |
| 516 | uint polltick; /* Tick counter */ |
| 517 | uint pollcnt; /* Count of active polls */ |
| 518 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 519 | #ifdef BCMDBG |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 520 | struct dhd_console console; /* Console output polling support */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 521 | uint console_addr; /* Console address from shared struct */ |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 522 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 523 | |
| 524 | uint regfails; /* Count of R_REG/W_REG failures */ |
| 525 | |
| 526 | uint clkstate; /* State of sd and backplane clock(s) */ |
| 527 | bool activity; /* Activity flag for clock down */ |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 528 | s32 idletime; /* Control for activity timeout */ |
| 529 | s32 idlecount; /* Activity timeout counter */ |
| 530 | s32 idleclock; /* How to set bus driver when idle */ |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 531 | s32 sd_rxchain; /* If bcmsdh api accepts PKT chains */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 532 | bool use_rxchain; /* If dhd should use PKT chains */ |
| 533 | bool sleeping; /* Is SDIO bus sleeping? */ |
| 534 | bool rxflow_mode; /* Rx flow control mode */ |
| 535 | bool rxflow; /* Is rx flow control on */ |
| 536 | uint prev_rxlim_hit; /* Is prev rx limit exceeded |
| 537 | (per dpc schedule) */ |
| 538 | bool alp_only; /* Don't use HT clock (ALP only) */ |
| 539 | /* Field to decide if rx of control frames happen in rxbuf or lb-pool */ |
| 540 | bool usebufpool; |
| 541 | |
| 542 | #ifdef SDTEST |
| 543 | /* external loopback */ |
| 544 | bool ext_loop; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 545 | u8 loopid; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 546 | |
| 547 | /* pktgen configuration */ |
| 548 | uint pktgen_freq; /* Ticks between bursts */ |
| 549 | uint pktgen_count; /* Packets to send each burst */ |
| 550 | uint pktgen_print; /* Bursts between count displays */ |
| 551 | uint pktgen_total; /* Stop after this many */ |
| 552 | uint pktgen_minlen; /* Minimum packet data len */ |
| 553 | uint pktgen_maxlen; /* Maximum packet data len */ |
| 554 | uint pktgen_mode; /* Configured mode: tx, rx, or echo */ |
| 555 | uint pktgen_stop; /* Number of tx failures causing stop */ |
| 556 | |
| 557 | /* active pktgen fields */ |
| 558 | uint pktgen_tick; /* Tick counter for bursts */ |
| 559 | uint pktgen_ptick; /* Burst counter for printing */ |
| 560 | uint pktgen_sent; /* Number of test packets generated */ |
| 561 | uint pktgen_rcvd; /* Number of test packets received */ |
| 562 | uint pktgen_fail; /* Number of failed send attempts */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 563 | u16 pktgen_len; /* Length of next packet to send */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 564 | #endif /* SDTEST */ |
| 565 | |
| 566 | /* Some additional counters */ |
| 567 | uint tx_sderrs; /* Count of tx attempts with sd errors */ |
| 568 | uint fcqueued; /* Tx packets that got queued */ |
| 569 | uint rxrtx; /* Count of rtx requests (NAK to dongle) */ |
| 570 | uint rx_toolong; /* Receive frames too long to receive */ |
| 571 | uint rxc_errors; /* SDIO errors when reading control frames */ |
| 572 | uint rx_hdrfail; /* SDIO errors on header reads */ |
| 573 | uint rx_badhdr; /* Bad received headers (roosync?) */ |
| 574 | uint rx_badseq; /* Mismatched rx sequence number */ |
| 575 | uint fc_rcvd; /* Number of flow-control events received */ |
| 576 | uint fc_xoff; /* Number which turned on flow-control */ |
| 577 | uint fc_xon; /* Number which turned off flow-control */ |
| 578 | uint rxglomfail; /* Failed deglom attempts */ |
| 579 | uint rxglomframes; /* Number of glom frames (superframes) */ |
| 580 | uint rxglompkts; /* Number of packets from glom frames */ |
| 581 | uint f2rxhdrs; /* Number of header reads */ |
| 582 | uint f2rxdata; /* Number of frame data reads */ |
| 583 | uint f2txdata; /* Number of f2 frame writes */ |
| 584 | uint f1regdata; /* Number of f1 register accesses */ |
| 585 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 586 | u8 *ctrl_frame_buf; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 587 | u32 ctrl_frame_len; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 588 | bool ctrl_frame_stat; |
Franky Lin | 0f1a87c | 2011-06-29 16:46:32 -0700 | [diff] [blame] | 589 | |
| 590 | spinlock_t txqlock; |
Franky Lin | b7adfa7 | 2011-06-29 16:47:42 -0700 | [diff] [blame] | 591 | wait_queue_head_t ctrl_wait; |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 592 | |
| 593 | struct timer_list timer; |
| 594 | struct completion watchdog_wait; |
| 595 | struct task_struct *watchdog_tsk; |
| 596 | bool wd_timer_valid; |
Franky Lin | 0827888 | 2011-06-29 16:47:45 -0700 | [diff] [blame] | 597 | |
| 598 | struct tasklet_struct tasklet; |
| 599 | struct task_struct *dpc_tsk; |
| 600 | struct completion dpc_wait; |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 601 | |
| 602 | bool threads_only; |
| 603 | struct semaphore sdsem; |
| 604 | spinlock_t sdlock; |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 605 | |
| 606 | const char *fw_name; |
| 607 | const struct firmware *firmware; |
| 608 | const char *nv_name; |
| 609 | u32 fw_ptr; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 610 | } dhd_bus_t; |
| 611 | |
Roland Vossen | b6fe70c | 2011-06-01 13:45:19 +0200 | [diff] [blame] | 612 | typedef volatile struct _sbconfig { |
| 613 | u32 PAD[2]; |
| 614 | u32 sbipsflag; /* initiator port ocp slave flag */ |
| 615 | u32 PAD[3]; |
| 616 | u32 sbtpsflag; /* target port ocp slave flag */ |
| 617 | u32 PAD[11]; |
| 618 | u32 sbtmerrloga; /* (sonics >= 2.3) */ |
| 619 | u32 PAD; |
| 620 | u32 sbtmerrlog; /* (sonics >= 2.3) */ |
| 621 | u32 PAD[3]; |
| 622 | u32 sbadmatch3; /* address match3 */ |
| 623 | u32 PAD; |
| 624 | u32 sbadmatch2; /* address match2 */ |
| 625 | u32 PAD; |
| 626 | u32 sbadmatch1; /* address match1 */ |
| 627 | u32 PAD[7]; |
| 628 | u32 sbimstate; /* initiator agent state */ |
| 629 | u32 sbintvec; /* interrupt mask */ |
| 630 | u32 sbtmstatelow; /* target state */ |
| 631 | u32 sbtmstatehigh; /* target state */ |
| 632 | u32 sbbwa0; /* bandwidth allocation table0 */ |
| 633 | u32 PAD; |
| 634 | u32 sbimconfiglow; /* initiator configuration */ |
| 635 | u32 sbimconfighigh; /* initiator configuration */ |
| 636 | u32 sbadmatch0; /* address match0 */ |
| 637 | u32 PAD; |
| 638 | u32 sbtmconfiglow; /* target configuration */ |
| 639 | u32 sbtmconfighigh; /* target configuration */ |
| 640 | u32 sbbconfig; /* broadcast configuration */ |
| 641 | u32 PAD; |
| 642 | u32 sbbstate; /* broadcast state */ |
| 643 | u32 PAD[3]; |
| 644 | u32 sbactcnfg; /* activate configuration */ |
| 645 | u32 PAD[3]; |
| 646 | u32 sbflagst; /* current sbflags */ |
| 647 | u32 PAD[3]; |
| 648 | u32 sbidlow; /* identification */ |
| 649 | u32 sbidhigh; /* identification */ |
| 650 | } sbconfig_t; |
| 651 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 652 | /* clkstate */ |
| 653 | #define CLK_NONE 0 |
| 654 | #define CLK_SDONLY 1 |
| 655 | #define CLK_PENDING 2 /* Not used yet */ |
| 656 | #define CLK_AVAIL 3 |
| 657 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 658 | #define DHD_NOPMU(dhd) (false) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 659 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 660 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 661 | static int qcount[NUMPRIO]; |
| 662 | static int tx_packets[NUMPRIO]; |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 663 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 664 | |
| 665 | /* Deferred transmit */ |
Franky Lin | 0827888 | 2011-06-29 16:47:45 -0700 | [diff] [blame] | 666 | uint brcmf_deferred_tx = 1; |
| 667 | module_param(brcmf_deferred_tx, uint, 0); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 668 | |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 669 | /* Watchdog thread priority, -1 to use kernel timer */ |
| 670 | int brcmf_watchdog_prio = 97; |
| 671 | module_param(brcmf_watchdog_prio, int, 0); |
| 672 | |
| 673 | /* Watchdog interval */ |
| 674 | uint brcmf_watchdog_ms = 10; |
| 675 | module_param(brcmf_watchdog_ms, uint, 0); |
| 676 | |
Franky Lin | 0827888 | 2011-06-29 16:47:45 -0700 | [diff] [blame] | 677 | /* DPC thread priority, -1 to use tasklet */ |
| 678 | int brcmf_dpc_prio = 98; |
| 679 | module_param(brcmf_dpc_prio, int, 0); |
| 680 | |
Franky Lin | 913af5f | 2011-06-29 16:47:44 -0700 | [diff] [blame] | 681 | #ifdef BCMDBG |
| 682 | /* Console poll interval */ |
| 683 | uint brcmf_console_ms; |
| 684 | module_param(brcmf_console_ms, uint, 0); |
| 685 | #endif /* DHD_DEBUG */ |
| 686 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 687 | /* Tx/Rx bounds */ |
Arend van Spriel | 7af9d0c | 2011-06-29 16:47:19 -0700 | [diff] [blame] | 688 | uint brcmf_txbound; |
| 689 | uint brcmf_rxbound; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 690 | uint dhd_txminmax; |
| 691 | |
| 692 | /* override the RAM size if possible */ |
| 693 | #define DONGLE_MIN_MEMSIZE (128 * 1024) |
Arend van Spriel | 7af9d0c | 2011-06-29 16:47:19 -0700 | [diff] [blame] | 694 | int brcmf_dongle_memsize; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 695 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 696 | static bool dhd_alignctl; |
| 697 | |
| 698 | static bool sd1idle; |
| 699 | |
| 700 | static bool retrydata; |
| 701 | #define RETRYCHAN(chan) (((chan) == SDPCM_EVENT_CHANNEL) || retrydata) |
| 702 | |
| 703 | static const uint watermark = 8; |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 704 | static const uint firstread = BRCMF_FIRSTREAD; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 705 | |
| 706 | #define HDATLEN (firstread - (SDPCM_HDRLEN)) |
| 707 | |
| 708 | /* Retry count for register access failures */ |
| 709 | static const uint retry_limit = 2; |
| 710 | |
| 711 | /* Force even SD lengths (some host controllers mess up on odd bytes) */ |
| 712 | static bool forcealign; |
| 713 | |
| 714 | #define ALIGNMENT 4 |
| 715 | |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 716 | #define PKTALIGN(_p, _len, _align) \ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 717 | do { \ |
| 718 | uint datalign; \ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 719 | datalign = (unsigned long)((_p)->data); \ |
| 720 | datalign = roundup(datalign, (_align)) - datalign; \ |
| 721 | ASSERT(datalign < (_align)); \ |
| 722 | ASSERT((_p)->len >= ((_len) + datalign)); \ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 723 | if (datalign) \ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 724 | skb_pull((_p), datalign); \ |
| 725 | __skb_trim((_p), (_len)); \ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 726 | } while (0) |
| 727 | |
| 728 | /* Limit on rounding up frames */ |
| 729 | static const uint max_roundup = 512; |
| 730 | |
| 731 | /* Try doing readahead */ |
| 732 | static bool dhd_readahead; |
| 733 | |
| 734 | /* To check if there's window offered */ |
| 735 | #define DATAOK(bus) \ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 736 | (((u8)(bus->tx_max - bus->tx_seq) != 0) && \ |
| 737 | (((u8)(bus->tx_max - bus->tx_seq) & 0x80) == 0)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 738 | |
| 739 | /* Macros to get register read/write status */ |
| 740 | /* NOTE: these assume a local dhdsdio_bus_t *bus! */ |
| 741 | #define R_SDREG(regvar, regaddr, retryvar) \ |
| 742 | do { \ |
| 743 | retryvar = 0; \ |
| 744 | do { \ |
Arend van Spriel | ff31c54 | 2011-03-01 10:56:54 +0100 | [diff] [blame] | 745 | regvar = R_REG(regaddr); \ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 746 | } while (brcmf_sdcard_regfail(bus->sdh) && \ |
| 747 | (++retryvar <= retry_limit)); \ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 748 | if (retryvar) { \ |
| 749 | bus->regfails += (retryvar-1); \ |
| 750 | if (retryvar > retry_limit) { \ |
| 751 | DHD_ERROR(("%s: FAILED" #regvar "READ, LINE %d\n", \ |
| 752 | __func__, __LINE__)); \ |
| 753 | regvar = 0; \ |
| 754 | } \ |
| 755 | } \ |
| 756 | } while (0) |
| 757 | |
| 758 | #define W_SDREG(regval, regaddr, retryvar) \ |
| 759 | do { \ |
| 760 | retryvar = 0; \ |
| 761 | do { \ |
Arend van Spriel | ff31c54 | 2011-03-01 10:56:54 +0100 | [diff] [blame] | 762 | W_REG(regaddr, regval); \ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 763 | } while (brcmf_sdcard_regfail(bus->sdh) && \ |
| 764 | (++retryvar <= retry_limit)); \ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 765 | if (retryvar) { \ |
| 766 | bus->regfails += (retryvar-1); \ |
| 767 | if (retryvar > retry_limit) \ |
| 768 | DHD_ERROR(("%s: FAILED REGISTER WRITE, LINE %d\n", \ |
| 769 | __func__, __LINE__)); \ |
| 770 | } \ |
| 771 | } while (0) |
| 772 | |
| 773 | #define DHD_BUS SDIO_BUS |
| 774 | |
| 775 | #define PKT_AVAILABLE() (intstatus & I_HMB_FRAME_IND) |
| 776 | |
| 777 | #define HOSTINTMASK (I_HMB_SW_MASK | I_CHIPACTIVE) |
| 778 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 779 | #ifdef SDTEST |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 780 | static void brcmf_sdbrcm_checkdied(dhd_bus_t *bus, void *pkt, uint seq); |
| 781 | static void brcmf_sdbrcm_sdtest_set(dhd_bus_t *bus, bool start); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 782 | #endif |
| 783 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 784 | #ifdef BCMDBG |
Franky Lin | 913af5f | 2011-06-29 16:47:44 -0700 | [diff] [blame] | 785 | static int brcmf_sdbrcm_bus_console_in(dhd_pub_t *dhdp, unsigned char *msg, |
| 786 | uint msglen); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 787 | static int brcmf_sdbrcm_checkdied(dhd_bus_t *bus, u8 *data, uint size); |
| 788 | static int brcmf_sdbrcm_mem_dump(dhd_bus_t *bus); |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 789 | #endif /* BCMDBG */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 790 | static int brcmf_sdbrcm_download_state(dhd_bus_t *bus, bool enter); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 791 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 792 | static void brcmf_sdbrcm_release(dhd_bus_t *bus); |
| 793 | static void brcmf_sdbrcm_release_malloc(dhd_bus_t *bus); |
| 794 | static void brcmf_sdbrcm_disconnect(void *ptr); |
| 795 | static bool brcmf_sdbrcm_chipmatch(u16 chipid); |
| 796 | 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] | 797 | void *regsva, u16 devid); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 798 | static bool brcmf_sdbrcm_probe_malloc(dhd_bus_t *bus, void *sdh); |
| 799 | static bool brcmf_sdbrcm_probe_init(dhd_bus_t *bus, void *sdh); |
| 800 | static void brcmf_sdbrcm_release_dongle(dhd_bus_t *bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 801 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 802 | static uint brcmf_process_nvram_vars(char *varbuf, uint len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 803 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 804 | static void brcmf_sdbrcm_setmemsize(struct dhd_bus *bus, int mem_size); |
| 805 | 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] | 806 | uint flags, u8 *buf, uint nbytes, |
| 807 | struct sk_buff *pkt, bcmsdh_cmplt_fn_t complete, |
| 808 | void *handle); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 809 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 810 | static bool brcmf_sdbrcm_download_firmware(struct dhd_bus *bus, void *sdh); |
| 811 | static int _brcmf_sdbrcm_download_firmware(struct dhd_bus *bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 812 | |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 813 | static int brcmf_sdbrcm_download_code_file(struct dhd_bus *bus); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 814 | static int brcmf_sdbrcm_download_nvram(struct dhd_bus *bus); |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 815 | static void brcmf_sdbrcm_chip_disablecore(struct brcmf_sdio *sdh, u32 corebase); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 816 | static int brcmf_sdbrcm_chip_attach(struct dhd_bus *bus, void *regs); |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 817 | static void brcmf_sdbrcm_chip_resetcore(struct brcmf_sdio *sdh, u32 corebase); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 818 | static void brcmf_sdbrcm_sdiod_drive_strength_init(struct dhd_bus *bus, |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 819 | u32 drivestrength); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 820 | static void brcmf_sdbrcm_chip_detach(struct dhd_bus *bus); |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 821 | static void brcmf_sdbrcm_wait_for_event(dhd_bus_t *bus, bool *lockvar); |
Franky Lin | b7adfa7 | 2011-06-29 16:47:42 -0700 | [diff] [blame] | 822 | static void brcmf_sdbrcm_wait_event_wakeup(dhd_bus_t *bus); |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 823 | static void brcmf_sdbrcm_watchdog(unsigned long data); |
| 824 | static int brcmf_sdbrcm_watchdog_thread(void *data); |
Franky Lin | 0827888 | 2011-06-29 16:47:45 -0700 | [diff] [blame] | 825 | static int brcmf_sdbrcm_dpc_thread(void *data); |
| 826 | static void brcmf_sdbrcm_dpc_tasklet(unsigned long data); |
| 827 | static void brcmf_sdbrcm_sched_dpc(dhd_bus_t *bus); |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 828 | static void brcmf_sdbrcm_sdlock(dhd_bus_t *bus); |
| 829 | static void brcmf_sdbrcm_sdunlock(dhd_bus_t *bus); |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 830 | static int brcmf_sdbrcm_get_image(char *buf, int len, struct dhd_bus *bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 831 | |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 832 | /* Packet free applicable unconditionally for sdio and sdspi. |
| 833 | * Conditional if bufpool was present for gspi bus. |
| 834 | */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 835 | 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] | 836 | { |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 837 | if ((bus->bus != SPI_BUS) || bus->usebufpool) |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 838 | brcmu_pkt_buf_free_skb(pkt); |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 839 | } |
| 840 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 841 | static void brcmf_sdbrcm_setmemsize(struct dhd_bus *bus, int mem_size) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 842 | { |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 843 | s32 min_size = DONGLE_MIN_MEMSIZE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 844 | /* Restrict the memsize to user specified limit */ |
| 845 | 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] | 846 | brcmf_dongle_memsize, min_size)); |
| 847 | if ((brcmf_dongle_memsize > min_size) && |
| 848 | (brcmf_dongle_memsize < (s32) bus->orig_ramsize)) |
| 849 | bus->ramsize = brcmf_dongle_memsize; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 850 | } |
| 851 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 852 | 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] | 853 | { |
| 854 | int err = 0; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 855 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRLOW, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 856 | (address >> 8) & SBSDIO_SBADDRLOW_MASK, &err); |
| 857 | if (!err) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 858 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_1, |
| 859 | SBSDIO_FUNC1_SBADDRMID, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 860 | (address >> 16) & SBSDIO_SBADDRMID_MASK, &err); |
| 861 | if (!err) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 862 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_1, |
| 863 | SBSDIO_FUNC1_SBADDRHIGH, |
| 864 | (address >> 24) & SBSDIO_SBADDRHIGH_MASK, |
| 865 | &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 866 | return err; |
| 867 | } |
| 868 | |
| 869 | /* Turn backplane clock on or off */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 870 | 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] | 871 | { |
| 872 | int err; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 873 | u8 clkctl, clkreq, devctl; |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 874 | struct brcmf_sdio *sdh; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 875 | |
| 876 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 877 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 878 | clkctl = 0; |
| 879 | sdh = bus->sdh; |
| 880 | |
| 881 | if (on) { |
| 882 | /* Request HT Avail */ |
| 883 | clkreq = |
| 884 | bus->alp_only ? SBSDIO_ALP_AVAIL_REQ : SBSDIO_HT_AVAIL_REQ; |
| 885 | |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 886 | if ((bus->ci->chip == BCM4329_CHIP_ID) |
| 887 | && (bus->ci->chiprev == 0)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 888 | clkreq |= SBSDIO_FORCE_ALP; |
| 889 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 890 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, |
| 891 | SBSDIO_FUNC1_CHIPCLKCSR, clkreq, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 892 | if (err) { |
| 893 | DHD_ERROR(("%s: HT Avail request error: %d\n", |
| 894 | __func__, err)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 895 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 896 | } |
| 897 | |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 898 | if (pendok && ((bus->ci->buscoretype == PCMCIA_CORE_ID) |
| 899 | && (bus->ci->buscorerev == 9))) { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 900 | u32 dummy, retries; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 901 | R_SDREG(dummy, &bus->regs->clockctlstatus, retries); |
| 902 | } |
| 903 | |
| 904 | /* Check current status */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 905 | clkctl = brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
| 906 | SBSDIO_FUNC1_CHIPCLKCSR, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 907 | if (err) { |
| 908 | DHD_ERROR(("%s: HT Avail read error: %d\n", |
| 909 | __func__, err)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 910 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | /* Go to pending and await interrupt if appropriate */ |
| 914 | if (!SBSDIO_CLKAV(clkctl, bus->alp_only) && pendok) { |
| 915 | /* Allow only clock-available interrupt */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 916 | devctl = brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
| 917 | SBSDIO_DEVICE_CTL, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 918 | if (err) { |
| 919 | DHD_ERROR(("%s: Devctl error setting CA: %d\n", |
| 920 | __func__, err)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 921 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | devctl |= SBSDIO_DEVCTL_CA_INT_ONLY; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 925 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, |
| 926 | SBSDIO_DEVICE_CTL, devctl, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 927 | DHD_INFO(("CLKCTL: set PENDING\n")); |
| 928 | bus->clkstate = CLK_PENDING; |
| 929 | |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 930 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 931 | } else if (bus->clkstate == CLK_PENDING) { |
| 932 | /* Cancel CA-only interrupt filter */ |
| 933 | devctl = |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 934 | brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
| 935 | SBSDIO_DEVICE_CTL, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 936 | devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 937 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, |
| 938 | SBSDIO_DEVICE_CTL, devctl, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | /* Otherwise, wait here (polling) for HT Avail */ |
| 942 | if (!SBSDIO_CLKAV(clkctl, bus->alp_only)) { |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 943 | BRCMF_SPINWAIT_SLEEP(sdioh_spinwait_sleep, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 944 | ((clkctl = |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 945 | brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 946 | SBSDIO_FUNC1_CHIPCLKCSR, |
| 947 | &err)), |
| 948 | !SBSDIO_CLKAV(clkctl, bus->alp_only)), |
| 949 | PMU_MAX_TRANSITION_DLY); |
| 950 | } |
| 951 | if (err) { |
| 952 | DHD_ERROR(("%s: HT Avail request error: %d\n", |
| 953 | __func__, err)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 954 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 955 | } |
| 956 | if (!SBSDIO_CLKAV(clkctl, bus->alp_only)) { |
| 957 | DHD_ERROR(("%s: HT Avail timeout (%d): clkctl 0x%02x\n", |
| 958 | __func__, PMU_MAX_TRANSITION_DLY, clkctl)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 959 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | /* Mark clock available */ |
| 963 | bus->clkstate = CLK_AVAIL; |
| 964 | DHD_INFO(("CLKCTL: turned ON\n")); |
| 965 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 966 | #if defined(BCMDBG) |
Arend van Spriel | f3341e7 | 2011-06-29 16:47:28 -0700 | [diff] [blame] | 967 | if (bus->alp_only != true) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 968 | if (SBSDIO_ALPONLY(clkctl)) { |
| 969 | DHD_ERROR(("%s: HT Clock should be on.\n", |
| 970 | __func__)); |
| 971 | } |
| 972 | } |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 973 | #endif /* defined (BCMDBG) */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 974 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 975 | bus->activity = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 976 | } else { |
| 977 | clkreq = 0; |
| 978 | |
| 979 | if (bus->clkstate == CLK_PENDING) { |
| 980 | /* Cancel CA-only interrupt filter */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 981 | devctl = brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
| 982 | SBSDIO_DEVICE_CTL, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 983 | devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 984 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, |
| 985 | SBSDIO_DEVICE_CTL, devctl, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | bus->clkstate = CLK_SDONLY; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 989 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, |
| 990 | SBSDIO_FUNC1_CHIPCLKCSR, clkreq, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 991 | DHD_INFO(("CLKCTL: turned OFF\n")); |
| 992 | if (err) { |
| 993 | DHD_ERROR(("%s: Failed access turning clock off: %d\n", |
| 994 | __func__, err)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 995 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 996 | } |
| 997 | } |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 998 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | /* Change idle/active SD state */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1002 | static int brcmf_sdbrcm_sdclk(dhd_bus_t *bus, bool on) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1003 | { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1004 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 1005 | |
Franky Lin | 602a8ab | 2011-06-01 13:45:04 +0200 | [diff] [blame] | 1006 | if (on) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1007 | bus->clkstate = CLK_SDONLY; |
Franky Lin | 602a8ab | 2011-06-01 13:45:04 +0200 | [diff] [blame] | 1008 | else |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1009 | bus->clkstate = CLK_NONE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1010 | |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 1011 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | /* Transition SD and backplane clock readiness */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1015 | 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] | 1016 | { |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1017 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1018 | uint oldstate = bus->clkstate; |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1019 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1020 | |
| 1021 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 1022 | |
| 1023 | /* Early exit if we're already there */ |
| 1024 | if (bus->clkstate == target) { |
| 1025 | if (target == CLK_AVAIL) { |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 1026 | brcmf_sdbrcm_wd_timer(bus, brcmf_watchdog_ms); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1027 | bus->activity = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1028 | } |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 1029 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1030 | } |
| 1031 | |
| 1032 | switch (target) { |
| 1033 | case CLK_AVAIL: |
| 1034 | /* Make sure SD clock is available */ |
| 1035 | if (bus->clkstate == CLK_NONE) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1036 | brcmf_sdbrcm_sdclk(bus, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1037 | /* Now request HT Avail on the backplane */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1038 | brcmf_sdbrcm_htclk(bus, true, pendok); |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 1039 | brcmf_sdbrcm_wd_timer(bus, brcmf_watchdog_ms); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1040 | bus->activity = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1041 | break; |
| 1042 | |
| 1043 | case CLK_SDONLY: |
| 1044 | /* Remove HT request, or bring up SD clock */ |
| 1045 | if (bus->clkstate == CLK_NONE) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1046 | brcmf_sdbrcm_sdclk(bus, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1047 | else if (bus->clkstate == CLK_AVAIL) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1048 | brcmf_sdbrcm_htclk(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1049 | else |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1050 | DHD_ERROR(("brcmf_sdbrcm_clkctl: request for %d -> %d" |
| 1051 | "\n", bus->clkstate, target)); |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 1052 | brcmf_sdbrcm_wd_timer(bus, brcmf_watchdog_ms); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1053 | break; |
| 1054 | |
| 1055 | case CLK_NONE: |
| 1056 | /* Make sure to remove HT request */ |
| 1057 | if (bus->clkstate == CLK_AVAIL) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1058 | brcmf_sdbrcm_htclk(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1059 | /* Now remove the SD clock */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1060 | brcmf_sdbrcm_sdclk(bus, false); |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 1061 | brcmf_sdbrcm_wd_timer(bus, 0); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1062 | break; |
| 1063 | } |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1064 | #ifdef BCMDBG |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1065 | DHD_INFO(("brcmf_sdbrcm_clkctl: %d -> %d\n", oldstate, bus->clkstate)); |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1066 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1067 | |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 1068 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1069 | } |
| 1070 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1071 | int brcmf_sdbrcm_bussleep(dhd_bus_t *bus, bool sleep) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1072 | { |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 1073 | struct brcmf_sdio *sdh = bus->sdh; |
Franky Lin | 597600a | 2011-06-01 13:45:39 +0200 | [diff] [blame] | 1074 | struct sdpcmd_regs *regs = bus->regs; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1075 | uint retries = 0; |
| 1076 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1077 | DHD_INFO(("brcmf_sdbrcm_bussleep: request %s (currently %s)\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1078 | (sleep ? "SLEEP" : "WAKE"), |
| 1079 | (bus->sleeping ? "SLEEP" : "WAKE"))); |
| 1080 | |
| 1081 | /* Done if we're already in the requested state */ |
| 1082 | if (sleep == bus->sleeping) |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 1083 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1084 | |
| 1085 | /* Going to sleep: set the alarm and turn off the lights... */ |
| 1086 | if (sleep) { |
| 1087 | /* Don't sleep if something is pending */ |
| 1088 | if (bus->dpc_sched || bus->rxskip || pktq_len(&bus->txq)) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 1089 | return -EBUSY; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1090 | |
| 1091 | /* Disable SDIO interrupts (no longer interested) */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1092 | brcmf_sdcard_intr_disable(bus->sdh); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1093 | |
| 1094 | /* Make sure the controller has the bus up */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1095 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1096 | |
| 1097 | /* Tell device to start using OOB wakeup */ |
| 1098 | W_SDREG(SMB_USE_OOB, ®s->tosbmailbox, retries); |
| 1099 | if (retries > retry_limit) |
| 1100 | DHD_ERROR(("CANNOT SIGNAL CHIP, WILL NOT WAKE UP!!\n")); |
| 1101 | |
| 1102 | /* Turn off our contribution to the HT clock request */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1103 | brcmf_sdbrcm_clkctl(bus, CLK_SDONLY, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1104 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1105 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, |
| 1106 | SBSDIO_FUNC1_CHIPCLKCSR, |
| 1107 | SBSDIO_FORCE_HW_CLKREQ_OFF, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1108 | |
| 1109 | /* Isolate the bus */ |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 1110 | if (bus->ci->chip != BCM4329_CHIP_ID |
| 1111 | && bus->ci->chip != BCM4319_CHIP_ID) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1112 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, |
| 1113 | SBSDIO_DEVICE_CTL, |
| 1114 | SBSDIO_DEVCTL_PADS_ISO, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1115 | } |
| 1116 | |
| 1117 | /* Change state */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1118 | bus->sleeping = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1119 | |
| 1120 | } else { |
| 1121 | /* Waking up: bus power up is ok, set local state */ |
| 1122 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1123 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, |
| 1124 | SBSDIO_FUNC1_CHIPCLKCSR, 0, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1125 | |
| 1126 | /* Force pad isolation off if possible |
| 1127 | (in case power never toggled) */ |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 1128 | if ((bus->ci->buscoretype == PCMCIA_CORE_ID) |
| 1129 | && (bus->ci->buscorerev >= 10)) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1130 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, |
| 1131 | SBSDIO_DEVICE_CTL, 0, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1132 | |
| 1133 | /* Make sure the controller has the bus up */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1134 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1135 | |
| 1136 | /* Send misc interrupt to indicate OOB not needed */ |
| 1137 | W_SDREG(0, ®s->tosbmailboxdata, retries); |
| 1138 | if (retries <= retry_limit) |
| 1139 | W_SDREG(SMB_DEV_INT, ®s->tosbmailbox, retries); |
| 1140 | |
| 1141 | if (retries > retry_limit) |
| 1142 | DHD_ERROR(("CANNOT SIGNAL CHIP TO CLEAR OOB!!\n")); |
| 1143 | |
| 1144 | /* Make sure we have SD bus access */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1145 | brcmf_sdbrcm_clkctl(bus, CLK_SDONLY, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1146 | |
| 1147 | /* Change state */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1148 | bus->sleeping = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1149 | |
| 1150 | /* Enable interrupts again */ |
| 1151 | if (bus->intr && (bus->dhd->busstate == DHD_BUS_DATA)) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1152 | bus->intdis = false; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1153 | brcmf_sdcard_intr_enable(bus->sdh); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1154 | } |
| 1155 | } |
| 1156 | |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 1157 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1158 | } |
| 1159 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1160 | #define BUS_WAKE(bus) \ |
| 1161 | do { \ |
| 1162 | if ((bus)->sleeping) \ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1163 | brcmf_sdbrcm_bussleep((bus), false); \ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1164 | } while (0); |
| 1165 | |
| 1166 | /* Writes a HW/SW header into the packet and sends it. */ |
| 1167 | /* Assumes: (a) header space already there, (b) caller holds lock */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1168 | 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] | 1169 | bool free_pkt) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1170 | { |
| 1171 | int ret; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1172 | u8 *frame; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 1173 | u16 len, pad = 0; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1174 | u32 swheader; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1175 | uint retries = 0; |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 1176 | struct brcmf_sdio *sdh; |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 1177 | struct sk_buff *new; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1178 | int i; |
| 1179 | |
| 1180 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 1181 | |
| 1182 | sdh = bus->sdh; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1183 | |
| 1184 | if (bus->dhd->dongle_reset) { |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 1185 | ret = -EPERM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1186 | goto done; |
| 1187 | } |
| 1188 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1189 | frame = (u8 *) (pkt->data); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1190 | |
| 1191 | /* Add alignment padding, allocate new packet if needed */ |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 1192 | pad = ((unsigned long)frame % BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1193 | if (pad) { |
Arend van Spriel | 3be727c | 2010-11-23 22:20:30 +0100 | [diff] [blame] | 1194 | if (skb_headroom(pkt) < pad) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1195 | DHD_INFO(("%s: insufficient headroom %d for %d pad\n", |
Arend van Spriel | 3be727c | 2010-11-23 22:20:30 +0100 | [diff] [blame] | 1196 | __func__, skb_headroom(pkt), pad)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1197 | bus->dhd->tx_realloc++; |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 1198 | new = brcmu_pkt_buf_get_skb(pkt->len + BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1199 | if (!new) { |
| 1200 | DHD_ERROR(("%s: couldn't allocate new %d-byte " |
| 1201 | "packet\n", |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 1202 | __func__, pkt->len + BRCMF_SDALIGN)); |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 1203 | ret = -ENOMEM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1204 | goto done; |
| 1205 | } |
| 1206 | |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 1207 | PKTALIGN(new, pkt->len, BRCMF_SDALIGN); |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 1208 | memcpy(new->data, pkt->data, pkt->len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1209 | if (free_pkt) |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1210 | brcmu_pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1211 | /* free the pkt if canned one is not used */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1212 | free_pkt = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1213 | pkt = new; |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1214 | frame = (u8 *) (pkt->data); |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 1215 | ASSERT(((unsigned long)frame % BRCMF_SDALIGN) == 0); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1216 | pad = 0; |
| 1217 | } else { |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 1218 | skb_push(pkt, pad); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1219 | frame = (u8 *) (pkt->data); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1220 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1221 | ASSERT((pad + SDPCM_HDRLEN) <= (int)(pkt->len)); |
Brett Rudley | 9249ede | 2010-11-30 20:09:49 -0800 | [diff] [blame] | 1222 | memset(frame, 0, pad + SDPCM_HDRLEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1223 | } |
| 1224 | } |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 1225 | ASSERT(pad < BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1226 | |
| 1227 | /* 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] | 1228 | len = (u16) (pkt->len); |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 1229 | *(u16 *) frame = cpu_to_le16(len); |
| 1230 | *(((u16 *) frame) + 1) = cpu_to_le16(~len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1231 | |
| 1232 | /* Software tag: channel, sequence number, data offset */ |
| 1233 | swheader = |
| 1234 | ((chan << SDPCM_CHANNEL_SHIFT) & SDPCM_CHANNEL_MASK) | bus->tx_seq | |
| 1235 | (((pad + |
| 1236 | SDPCM_HDRLEN) << SDPCM_DOFFSET_SHIFT) & SDPCM_DOFFSET_MASK); |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 1237 | |
| 1238 | put_unaligned_le32(swheader, frame + SDPCM_FRAMETAG_LEN); |
| 1239 | put_unaligned_le32(0, frame + SDPCM_FRAMETAG_LEN + sizeof(swheader)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1240 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1241 | #ifdef BCMDBG |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1242 | tx_packets[pkt->priority]++; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1243 | if (DHD_BYTES_ON() && |
| 1244 | (((DHD_CTL_ON() && (chan == SDPCM_CONTROL_CHANNEL)) || |
| 1245 | (DHD_DATA_ON() && (chan != SDPCM_CONTROL_CHANNEL))))) { |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 1246 | printk(KERN_DEBUG "Tx Frame:\n"); |
| 1247 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, frame, len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1248 | } else if (DHD_HDRS_ON()) { |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 1249 | printk(KERN_DEBUG "TxHdr:\n"); |
| 1250 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 1251 | frame, min_t(u16, len, 16)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1252 | } |
| 1253 | #endif |
| 1254 | |
| 1255 | /* Raise len to next SDIO block to eliminate tail command */ |
| 1256 | if (bus->roundup && bus->blocksize && (len > bus->blocksize)) { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 1257 | u16 pad = bus->blocksize - (len % bus->blocksize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1258 | if ((pad <= bus->roundup) && (pad < bus->blocksize)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1259 | len += pad; |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 1260 | } else if (len % BRCMF_SDALIGN) { |
| 1261 | len += BRCMF_SDALIGN - (len % BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1262 | } |
| 1263 | |
| 1264 | /* Some controllers have trouble with odd bytes -- round to even */ |
| 1265 | if (forcealign && (len & (ALIGNMENT - 1))) { |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 1266 | len = roundup(len, ALIGNMENT); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1267 | } |
| 1268 | |
| 1269 | do { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1270 | ret = brcmf_sdbrcm_send_buf(bus, brcmf_sdcard_cur_sbwad(sdh), |
| 1271 | SDIO_FUNC_2, F2SYNC, frame, len, pkt, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1272 | bus->f2txdata++; |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 1273 | ASSERT(ret != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1274 | |
| 1275 | if (ret < 0) { |
| 1276 | /* On failure, abort the command |
| 1277 | and terminate the frame */ |
| 1278 | DHD_INFO(("%s: sdio error %d, abort command and " |
| 1279 | "terminate frame.\n", __func__, ret)); |
| 1280 | bus->tx_sderrs++; |
| 1281 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1282 | brcmf_sdcard_abort(sdh, SDIO_FUNC_2); |
| 1283 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1284 | SBSDIO_FUNC1_FRAMECTRL, SFC_WF_TERM, |
| 1285 | NULL); |
| 1286 | bus->f1regdata++; |
| 1287 | |
| 1288 | for (i = 0; i < 3; i++) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1289 | u8 hi, lo; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1290 | hi = brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1291 | SBSDIO_FUNC1_WFRAMEBCHI, |
| 1292 | NULL); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1293 | lo = brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1294 | SBSDIO_FUNC1_WFRAMEBCLO, |
| 1295 | NULL); |
| 1296 | bus->f1regdata += 2; |
| 1297 | if ((hi == 0) && (lo == 0)) |
| 1298 | break; |
| 1299 | } |
| 1300 | |
| 1301 | } |
| 1302 | if (ret == 0) |
| 1303 | bus->tx_seq = (bus->tx_seq + 1) % SDPCM_SEQUENCE_WRAP; |
| 1304 | |
| 1305 | } while ((ret < 0) && retrydata && retries++ < TXRETRIES); |
| 1306 | |
| 1307 | done: |
| 1308 | /* restore pkt buffer pointer before calling tx complete routine */ |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 1309 | skb_pull(pkt, SDPCM_HDRLEN + pad); |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 1310 | brcmf_sdbrcm_sdunlock(bus); |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 1311 | brcmf_txcomplete(bus->dhd, pkt, ret != 0); |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 1312 | brcmf_sdbrcm_sdlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1313 | |
| 1314 | if (free_pkt) |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1315 | brcmu_pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1316 | |
| 1317 | return ret; |
| 1318 | } |
| 1319 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1320 | 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] | 1321 | { |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 1322 | int ret = -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1323 | uint datalen, prec; |
| 1324 | |
| 1325 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 1326 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1327 | datalen = pkt->len; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1328 | |
| 1329 | #ifdef SDTEST |
| 1330 | /* Push the test header if doing loopback */ |
| 1331 | if (bus->ext_loop) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1332 | u8 *data; |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 1333 | skb_push(pkt, SDPCM_TEST_HDRLEN); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1334 | data = pkt->data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1335 | *data++ = SDPCM_TEST_ECHOREQ; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1336 | *data++ = (u8) bus->loopid++; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1337 | *data++ = (datalen >> 0); |
| 1338 | *data++ = (datalen >> 8); |
| 1339 | datalen += SDPCM_TEST_HDRLEN; |
| 1340 | } |
| 1341 | #endif /* SDTEST */ |
| 1342 | |
| 1343 | /* Add space for the header */ |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 1344 | skb_push(pkt, SDPCM_HDRLEN); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1345 | ASSERT(IS_ALIGNED((unsigned long)(pkt->data), 2)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1346 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1347 | prec = PRIO2PREC((pkt->priority & PRIOMASK)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1348 | |
| 1349 | /* Check for existing queue, current flow-control, |
| 1350 | pending event, or pending clock */ |
Arend van Spriel | 7af9d0c | 2011-06-29 16:47:19 -0700 | [diff] [blame] | 1351 | if (brcmf_deferred_tx || bus->fcstate || pktq_len(&bus->txq) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1352 | || bus->dpc_sched || (!DATAOK(bus)) |
| 1353 | || (bus->flowcontrol & NBITVAL(prec)) |
| 1354 | || (bus->clkstate != CLK_AVAIL)) { |
| 1355 | DHD_TRACE(("%s: deferring pktq len %d\n", __func__, |
| 1356 | pktq_len(&bus->txq))); |
| 1357 | bus->fcqueued++; |
| 1358 | |
| 1359 | /* Priority based enq */ |
Franky Lin | 0f1a87c | 2011-06-29 16:46:32 -0700 | [diff] [blame] | 1360 | spin_lock_bh(&bus->txqlock); |
Arend van Spriel | aba5e0a | 2011-06-29 16:47:03 -0700 | [diff] [blame] | 1361 | 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] | 1362 | skb_pull(pkt, SDPCM_HDRLEN); |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 1363 | brcmf_txcomplete(bus->dhd, pkt, false); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1364 | brcmu_pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1365 | DHD_ERROR(("%s: out of bus->txq !!!\n", __func__)); |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 1366 | ret = -ENOSR; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1367 | } else { |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 1368 | ret = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1369 | } |
Franky Lin | 0f1a87c | 2011-06-29 16:46:32 -0700 | [diff] [blame] | 1370 | spin_unlock_bh(&bus->txqlock); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1371 | |
Grant Grundler | 7c31607 | 2011-03-09 15:04:15 -0800 | [diff] [blame] | 1372 | if (pktq_len(&bus->txq) >= TXHI) |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 1373 | brcmf_txflowcontrol(bus->dhd, 0, ON); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1374 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1375 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1376 | if (pktq_plen(&bus->txq, prec) > qcount[prec]) |
| 1377 | qcount[prec] = pktq_plen(&bus->txq, prec); |
| 1378 | #endif |
| 1379 | /* Schedule DPC if needed to send queued packet(s) */ |
Arend van Spriel | 7af9d0c | 2011-06-29 16:47:19 -0700 | [diff] [blame] | 1380 | if (brcmf_deferred_tx && !bus->dpc_sched) { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1381 | bus->dpc_sched = true; |
Franky Lin | 0827888 | 2011-06-29 16:47:45 -0700 | [diff] [blame] | 1382 | brcmf_sdbrcm_sched_dpc(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1383 | } |
| 1384 | } else { |
| 1385 | /* Lock: we're about to use shared data/code (and SDIO) */ |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 1386 | brcmf_sdbrcm_sdlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1387 | |
| 1388 | /* Otherwise, send it now */ |
| 1389 | BUS_WAKE(bus); |
| 1390 | /* Make sure back plane ht clk is on, no pending allowed */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1391 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1392 | |
| 1393 | #ifndef SDTEST |
| 1394 | DHD_TRACE(("%s: calling txpkt\n", __func__)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1395 | ret = brcmf_sdbrcm_txpkt(bus, pkt, SDPCM_DATA_CHANNEL, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1396 | #else |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1397 | ret = brcmf_sdbrcm_txpkt(bus, pkt, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1398 | (bus->ext_loop ? SDPCM_TEST_CHANNEL : |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1399 | SDPCM_DATA_CHANNEL), true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1400 | #endif |
| 1401 | if (ret) |
| 1402 | bus->dhd->tx_errors++; |
| 1403 | else |
| 1404 | bus->dhd->dstats.tx_bytes += datalen; |
| 1405 | |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 1406 | if (bus->idletime == BRCMF_IDLE_IMMEDIATE && |
| 1407 | !bus->dpc_sched) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1408 | bus->activity = false; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1409 | brcmf_sdbrcm_clkctl(bus, CLK_NONE, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1410 | } |
| 1411 | |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 1412 | brcmf_sdbrcm_sdunlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1413 | } |
| 1414 | |
| 1415 | return ret; |
| 1416 | } |
| 1417 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1418 | static uint brcmf_sdbrcm_sendfromq(dhd_bus_t *bus, uint maxframes) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1419 | { |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 1420 | struct sk_buff *pkt; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1421 | u32 intstatus = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1422 | uint retries = 0; |
| 1423 | int ret = 0, prec_out; |
| 1424 | uint cnt = 0; |
| 1425 | uint datalen; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1426 | u8 tx_prec_map; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1427 | |
| 1428 | dhd_pub_t *dhd = bus->dhd; |
Franky Lin | 597600a | 2011-06-01 13:45:39 +0200 | [diff] [blame] | 1429 | struct sdpcmd_regs *regs = bus->regs; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1430 | |
| 1431 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 1432 | |
| 1433 | tx_prec_map = ~bus->flowcontrol; |
| 1434 | |
| 1435 | /* Send frames until the limit or some other event */ |
| 1436 | for (cnt = 0; (cnt < maxframes) && DATAOK(bus); cnt++) { |
Franky Lin | 0f1a87c | 2011-06-29 16:46:32 -0700 | [diff] [blame] | 1437 | spin_lock_bh(&bus->txqlock); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1438 | pkt = brcmu_pktq_mdeq(&bus->txq, tx_prec_map, &prec_out); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1439 | if (pkt == NULL) { |
Franky Lin | 0f1a87c | 2011-06-29 16:46:32 -0700 | [diff] [blame] | 1440 | spin_unlock_bh(&bus->txqlock); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1441 | break; |
| 1442 | } |
Franky Lin | 0f1a87c | 2011-06-29 16:46:32 -0700 | [diff] [blame] | 1443 | spin_unlock_bh(&bus->txqlock); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1444 | datalen = pkt->len - SDPCM_HDRLEN; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1445 | |
| 1446 | #ifndef SDTEST |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1447 | ret = brcmf_sdbrcm_txpkt(bus, pkt, SDPCM_DATA_CHANNEL, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1448 | #else |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1449 | ret = brcmf_sdbrcm_txpkt(bus, pkt, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1450 | (bus->ext_loop ? SDPCM_TEST_CHANNEL : |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1451 | SDPCM_DATA_CHANNEL), true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1452 | #endif |
| 1453 | if (ret) |
| 1454 | bus->dhd->tx_errors++; |
| 1455 | else |
| 1456 | bus->dhd->dstats.tx_bytes += datalen; |
| 1457 | |
| 1458 | /* In poll mode, need to check for other events */ |
| 1459 | if (!bus->intr && cnt) { |
| 1460 | /* Check device status, signal pending interrupt */ |
| 1461 | R_SDREG(intstatus, ®s->intstatus, retries); |
| 1462 | bus->f2txdata++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1463 | if (brcmf_sdcard_regfail(bus->sdh)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1464 | break; |
| 1465 | if (intstatus & bus->hostintmask) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1466 | bus->ipend = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1467 | } |
| 1468 | } |
| 1469 | |
| 1470 | /* Deflow-control stack if needed */ |
Grant Grundler | 7c31607 | 2011-03-09 15:04:15 -0800 | [diff] [blame] | 1471 | if (dhd->up && (dhd->busstate == DHD_BUS_DATA) && |
Grant Grundler | 26a71a4 | 2011-03-09 10:41:25 -0800 | [diff] [blame] | 1472 | dhd->txoff && (pktq_len(&bus->txq) < TXLOW)) |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 1473 | brcmf_txflowcontrol(dhd, 0, OFF); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1474 | |
| 1475 | return cnt; |
| 1476 | } |
| 1477 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1478 | int |
| 1479 | 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] | 1480 | { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1481 | u8 *frame; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 1482 | u16 len; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1483 | u32 swheader; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1484 | uint retries = 0; |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 1485 | struct brcmf_sdio *sdh = bus->sdh; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1486 | u8 doff = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1487 | int ret = -1; |
| 1488 | int i; |
| 1489 | |
| 1490 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 1491 | |
| 1492 | if (bus->dhd->dongle_reset) |
| 1493 | return -EIO; |
| 1494 | |
| 1495 | /* Back the pointer to make a room for bus header */ |
| 1496 | frame = msg - SDPCM_HDRLEN; |
| 1497 | len = (msglen += SDPCM_HDRLEN); |
| 1498 | |
| 1499 | /* Add alignment padding (optional for ctl frames) */ |
| 1500 | if (dhd_alignctl) { |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 1501 | doff = ((unsigned long)frame % BRCMF_SDALIGN); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 1502 | if (doff) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1503 | frame -= doff; |
| 1504 | len += doff; |
| 1505 | msglen += doff; |
Brett Rudley | 9249ede | 2010-11-30 20:09:49 -0800 | [diff] [blame] | 1506 | memset(frame, 0, doff + SDPCM_HDRLEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1507 | } |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 1508 | ASSERT(doff < BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1509 | } |
| 1510 | doff += SDPCM_HDRLEN; |
| 1511 | |
| 1512 | /* Round send length to next SDIO block */ |
| 1513 | if (bus->roundup && bus->blocksize && (len > bus->blocksize)) { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 1514 | u16 pad = bus->blocksize - (len % bus->blocksize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1515 | if ((pad <= bus->roundup) && (pad < bus->blocksize)) |
| 1516 | len += pad; |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 1517 | } else if (len % BRCMF_SDALIGN) { |
| 1518 | len += BRCMF_SDALIGN - (len % BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1519 | } |
| 1520 | |
| 1521 | /* Satisfy length-alignment requirements */ |
| 1522 | if (forcealign && (len & (ALIGNMENT - 1))) |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 1523 | len = roundup(len, ALIGNMENT); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1524 | |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 1525 | ASSERT(IS_ALIGNED((unsigned long)frame, 2)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1526 | |
| 1527 | /* Need to lock here to protect txseq and SDIO tx calls */ |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 1528 | brcmf_sdbrcm_sdlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1529 | |
| 1530 | BUS_WAKE(bus); |
| 1531 | |
| 1532 | /* Make sure backplane clock is on */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1533 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1534 | |
| 1535 | /* 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] | 1536 | *(u16 *) frame = cpu_to_le16((u16) msglen); |
| 1537 | *(((u16 *) frame) + 1) = cpu_to_le16(~msglen); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1538 | |
| 1539 | /* Software tag: channel, sequence number, data offset */ |
| 1540 | swheader = |
| 1541 | ((SDPCM_CONTROL_CHANNEL << SDPCM_CHANNEL_SHIFT) & |
| 1542 | SDPCM_CHANNEL_MASK) |
| 1543 | | bus->tx_seq | ((doff << SDPCM_DOFFSET_SHIFT) & |
| 1544 | SDPCM_DOFFSET_MASK); |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 1545 | put_unaligned_le32(swheader, frame + SDPCM_FRAMETAG_LEN); |
| 1546 | put_unaligned_le32(0, frame + SDPCM_FRAMETAG_LEN + sizeof(swheader)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1547 | |
| 1548 | if (!DATAOK(bus)) { |
| 1549 | DHD_INFO(("%s: No bus credit bus->tx_max %d, bus->tx_seq %d\n", |
| 1550 | __func__, bus->tx_max, bus->tx_seq)); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1551 | bus->ctrl_frame_stat = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1552 | /* Send from dpc */ |
| 1553 | bus->ctrl_frame_buf = frame; |
| 1554 | bus->ctrl_frame_len = len; |
| 1555 | |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 1556 | brcmf_sdbrcm_wait_for_event(bus, &bus->ctrl_frame_stat); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1557 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1558 | if (bus->ctrl_frame_stat == false) { |
| 1559 | DHD_INFO(("%s: ctrl_frame_stat == false\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1560 | ret = 0; |
| 1561 | } else { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1562 | DHD_INFO(("%s: ctrl_frame_stat == true\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1563 | ret = -1; |
| 1564 | } |
| 1565 | } |
| 1566 | |
| 1567 | if (ret == -1) { |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1568 | #ifdef BCMDBG |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 1569 | if (DHD_BYTES_ON() && DHD_CTL_ON()) { |
| 1570 | printk(KERN_DEBUG "Tx Frame:\n"); |
| 1571 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 1572 | frame, len); |
| 1573 | } else if (DHD_HDRS_ON()) { |
| 1574 | printk(KERN_DEBUG "TxHdr:\n"); |
| 1575 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 1576 | frame, min_t(u16, len, 16)); |
| 1577 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1578 | #endif |
| 1579 | |
| 1580 | do { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1581 | bus->ctrl_frame_stat = false; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1582 | ret = brcmf_sdbrcm_send_buf(bus, |
| 1583 | brcmf_sdcard_cur_sbwad(sdh), SDIO_FUNC_2, |
| 1584 | F2SYNC, frame, len, NULL, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1585 | |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 1586 | ASSERT(ret != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1587 | |
| 1588 | if (ret < 0) { |
| 1589 | /* On failure, abort the command and |
| 1590 | terminate the frame */ |
| 1591 | DHD_INFO(("%s: sdio error %d, abort command and terminate frame.\n", |
| 1592 | __func__, ret)); |
| 1593 | bus->tx_sderrs++; |
| 1594 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1595 | brcmf_sdcard_abort(sdh, SDIO_FUNC_2); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1596 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1597 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1598 | SBSDIO_FUNC1_FRAMECTRL, |
| 1599 | SFC_WF_TERM, NULL); |
| 1600 | bus->f1regdata++; |
| 1601 | |
| 1602 | for (i = 0; i < 3; i++) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1603 | u8 hi, lo; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1604 | hi = brcmf_sdcard_cfg_read(sdh, |
| 1605 | SDIO_FUNC_1, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1606 | SBSDIO_FUNC1_WFRAMEBCHI, |
| 1607 | NULL); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1608 | lo = brcmf_sdcard_cfg_read(sdh, |
| 1609 | SDIO_FUNC_1, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1610 | SBSDIO_FUNC1_WFRAMEBCLO, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1611 | NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1612 | bus->f1regdata += 2; |
| 1613 | if ((hi == 0) && (lo == 0)) |
| 1614 | break; |
| 1615 | } |
| 1616 | |
| 1617 | } |
| 1618 | if (ret == 0) { |
| 1619 | bus->tx_seq = |
| 1620 | (bus->tx_seq + 1) % SDPCM_SEQUENCE_WRAP; |
| 1621 | } |
| 1622 | } while ((ret < 0) && retries++ < TXRETRIES); |
| 1623 | } |
| 1624 | |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 1625 | if ((bus->idletime == BRCMF_IDLE_IMMEDIATE) && !bus->dpc_sched) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1626 | bus->activity = false; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1627 | brcmf_sdbrcm_clkctl(bus, CLK_NONE, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1628 | } |
| 1629 | |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 1630 | brcmf_sdbrcm_sdunlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1631 | |
| 1632 | if (ret) |
| 1633 | bus->dhd->tx_ctlerrs++; |
| 1634 | else |
| 1635 | bus->dhd->tx_ctlpkts++; |
| 1636 | |
| 1637 | return ret ? -EIO : 0; |
| 1638 | } |
| 1639 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1640 | 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] | 1641 | { |
| 1642 | int timeleft; |
| 1643 | uint rxlen = 0; |
| 1644 | bool pending; |
| 1645 | |
| 1646 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 1647 | |
| 1648 | if (bus->dhd->dongle_reset) |
| 1649 | return -EIO; |
| 1650 | |
| 1651 | /* Wait until control frame is available */ |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 1652 | timeleft = brcmf_os_ioctl_resp_wait(bus->dhd, &bus->rxlen, &pending); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1653 | |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 1654 | brcmf_sdbrcm_sdlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1655 | rxlen = bus->rxlen; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 1656 | memcpy(msg, bus->rxctl, min(msglen, rxlen)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1657 | bus->rxlen = 0; |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 1658 | brcmf_sdbrcm_sdunlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1659 | |
| 1660 | if (rxlen) { |
| 1661 | DHD_CTL(("%s: resumed on rxctl frame, got %d expected %d\n", |
| 1662 | __func__, rxlen, msglen)); |
| 1663 | } else if (timeleft == 0) { |
| 1664 | DHD_ERROR(("%s: resumed on timeout\n", __func__)); |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1665 | #ifdef BCMDBG |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 1666 | brcmf_sdbrcm_sdlock(bus); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1667 | brcmf_sdbrcm_checkdied(bus, NULL, 0); |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 1668 | brcmf_sdbrcm_sdunlock(bus); |
| 1669 | #endif /* DHD_DEBUG */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1670 | } else if (pending == true) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1671 | DHD_CTL(("%s: cancelled\n", __func__)); |
| 1672 | return -ERESTARTSYS; |
| 1673 | } else { |
| 1674 | DHD_CTL(("%s: resumed for unknown reason?\n", __func__)); |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1675 | #ifdef BCMDBG |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 1676 | brcmf_sdbrcm_sdlock(bus); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1677 | brcmf_sdbrcm_checkdied(bus, NULL, 0); |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 1678 | brcmf_sdbrcm_sdunlock(bus); |
| 1679 | #endif /* DHD_DEBUG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1680 | } |
| 1681 | |
| 1682 | if (rxlen) |
| 1683 | bus->dhd->rx_ctlpkts++; |
| 1684 | else |
| 1685 | bus->dhd->rx_ctlerrs++; |
| 1686 | |
Jason Cooper | e9887c9 | 2010-10-06 10:08:02 -0400 | [diff] [blame] | 1687 | return rxlen ? (int)rxlen : -ETIMEDOUT; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1688 | } |
| 1689 | |
| 1690 | /* IOVar table */ |
| 1691 | enum { |
| 1692 | IOV_INTR = 1, |
| 1693 | IOV_POLLRATE, |
| 1694 | IOV_SDREG, |
| 1695 | IOV_SBREG, |
| 1696 | IOV_SDCIS, |
| 1697 | IOV_MEMBYTES, |
| 1698 | IOV_MEMSIZE, |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1699 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1700 | IOV_CHECKDIED, |
Franky Lin | 913af5f | 2011-06-29 16:47:44 -0700 | [diff] [blame] | 1701 | IOV_CONS, |
| 1702 | IOV_DCONSOLE_POLL, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1703 | #endif |
| 1704 | IOV_DOWNLOAD, |
| 1705 | IOV_FORCEEVEN, |
| 1706 | IOV_SDIOD_DRIVE, |
| 1707 | IOV_READAHEAD, |
| 1708 | IOV_SDRXCHAIN, |
| 1709 | IOV_ALIGNCTL, |
| 1710 | IOV_SDALIGN, |
| 1711 | IOV_DEVRESET, |
| 1712 | IOV_CPU, |
| 1713 | #ifdef SDTEST |
| 1714 | IOV_PKTGEN, |
| 1715 | IOV_EXTLOOP, |
| 1716 | #endif /* SDTEST */ |
| 1717 | IOV_SPROM, |
| 1718 | IOV_TXBOUND, |
| 1719 | IOV_RXBOUND, |
| 1720 | IOV_TXMINMAX, |
| 1721 | IOV_IDLETIME, |
| 1722 | IOV_IDLECLOCK, |
| 1723 | IOV_SD1IDLE, |
| 1724 | IOV_SLEEP, |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 1725 | IOV_WDTICK, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1726 | IOV_VARS |
| 1727 | }; |
| 1728 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1729 | const struct brcmu_iovar dhdsdio_iovars[] = { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1730 | {"intr", IOV_INTR, 0, IOVT_BOOL, 0}, |
| 1731 | {"sleep", IOV_SLEEP, 0, IOVT_BOOL, 0}, |
| 1732 | {"pollrate", IOV_POLLRATE, 0, IOVT_UINT32, 0}, |
| 1733 | {"idletime", IOV_IDLETIME, 0, IOVT_INT32, 0}, |
| 1734 | {"idleclock", IOV_IDLECLOCK, 0, IOVT_INT32, 0}, |
| 1735 | {"sd1idle", IOV_SD1IDLE, 0, IOVT_BOOL, 0}, |
| 1736 | {"membytes", IOV_MEMBYTES, 0, IOVT_BUFFER, 2 * sizeof(int)}, |
| 1737 | {"memsize", IOV_MEMSIZE, 0, IOVT_UINT32, 0}, |
| 1738 | {"download", IOV_DOWNLOAD, 0, IOVT_BOOL, 0}, |
| 1739 | {"vars", IOV_VARS, 0, IOVT_BUFFER, 0}, |
| 1740 | {"sdiod_drive", IOV_SDIOD_DRIVE, 0, IOVT_UINT32, 0}, |
| 1741 | {"readahead", IOV_READAHEAD, 0, IOVT_BOOL, 0}, |
| 1742 | {"sdrxchain", IOV_SDRXCHAIN, 0, IOVT_BOOL, 0}, |
| 1743 | {"alignctl", IOV_ALIGNCTL, 0, IOVT_BOOL, 0}, |
| 1744 | {"sdalign", IOV_SDALIGN, 0, IOVT_BOOL, 0}, |
| 1745 | {"devreset", IOV_DEVRESET, 0, IOVT_BOOL, 0}, |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 1746 | {"wdtick", IOV_WDTICK, 0, IOVT_UINT32, 0}, |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1747 | #ifdef BCMDBG |
Franky Lin | 913af5f | 2011-06-29 16:47:44 -0700 | [diff] [blame] | 1748 | {"cons", IOV_CONS, 0, IOVT_BUFFER, 0} |
| 1749 | , |
| 1750 | {"dconpoll", IOV_DCONSOLE_POLL, 0, IOVT_UINT32, 0} |
| 1751 | , |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 1752 | {"sdreg", IOV_SDREG, 0, IOVT_BUFFER, sizeof(struct brcmf_sdreg)} |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1753 | , |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 1754 | {"sbreg", IOV_SBREG, 0, IOVT_BUFFER, sizeof(struct brcmf_sdreg)} |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1755 | , |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 1756 | {"sd_cis", IOV_SDCIS, 0, IOVT_BUFFER, BRCMF_IOCTL_MAXLEN} |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1757 | , |
| 1758 | {"forcealign", IOV_FORCEEVEN, 0, IOVT_BOOL, 0} |
| 1759 | , |
| 1760 | {"txbound", IOV_TXBOUND, 0, IOVT_UINT32, 0} |
| 1761 | , |
| 1762 | {"rxbound", IOV_RXBOUND, 0, IOVT_UINT32, 0} |
| 1763 | , |
| 1764 | {"txminmax", IOV_TXMINMAX, 0, IOVT_UINT32, 0} |
| 1765 | , |
| 1766 | {"cpu", IOV_CPU, 0, IOVT_BOOL, 0} |
| 1767 | , |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1768 | {"checkdied", IOV_CHECKDIED, 0, IOVT_BUFFER, 0} |
| 1769 | , |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1770 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1771 | #ifdef SDTEST |
| 1772 | {"extloop", IOV_EXTLOOP, 0, IOVT_BOOL, 0} |
| 1773 | , |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 1774 | {"pktgen", IOV_PKTGEN, 0, IOVT_BUFFER, sizeof(brcmf_pktgen_t)} |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1775 | , |
| 1776 | #endif /* SDTEST */ |
| 1777 | |
| 1778 | {NULL, 0, 0, 0, 0} |
| 1779 | }; |
| 1780 | |
| 1781 | static void |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1782 | 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] | 1783 | { |
| 1784 | uint q1, q2; |
| 1785 | |
| 1786 | if (!div) { |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1787 | brcmu_bprintf(strbuf, "%s N/A", desc); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1788 | } else { |
| 1789 | q1 = num / div; |
| 1790 | q2 = (100 * (num - (q1 * div))) / div; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1791 | brcmu_bprintf(strbuf, "%s %d.%02d", desc, q1, q2); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1792 | } |
| 1793 | } |
| 1794 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1795 | 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] | 1796 | { |
| 1797 | dhd_bus_t *bus = dhdp->bus; |
| 1798 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1799 | brcmu_bprintf(strbuf, "Bus SDIO structure:\n"); |
| 1800 | brcmu_bprintf(strbuf, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1801 | "hostintmask 0x%08x intstatus 0x%08x sdpcm_ver %d\n", |
| 1802 | bus->hostintmask, bus->intstatus, bus->sdpcm_ver); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1803 | brcmu_bprintf(strbuf, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1804 | "fcstate %d qlen %d tx_seq %d, max %d, rxskip %d rxlen %d rx_seq %d\n", |
| 1805 | bus->fcstate, pktq_len(&bus->txq), bus->tx_seq, bus->tx_max, |
| 1806 | bus->rxskip, bus->rxlen, bus->rx_seq); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1807 | brcmu_bprintf(strbuf, "intr %d intrcount %d lastintrs %d spurious %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1808 | bus->intr, bus->intrcount, bus->lastintrs, bus->spurious); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1809 | brcmu_bprintf(strbuf, "pollrate %d pollcnt %d regfails %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1810 | bus->pollrate, bus->pollcnt, bus->regfails); |
| 1811 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1812 | brcmu_bprintf(strbuf, "\nAdditional counters:\n"); |
| 1813 | brcmu_bprintf(strbuf, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1814 | "tx_sderrs %d fcqueued %d rxrtx %d rx_toolong %d rxc_errors %d\n", |
| 1815 | bus->tx_sderrs, bus->fcqueued, bus->rxrtx, bus->rx_toolong, |
| 1816 | bus->rxc_errors); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1817 | brcmu_bprintf(strbuf, "rx_hdrfail %d badhdr %d badseq %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1818 | bus->rx_hdrfail, bus->rx_badhdr, bus->rx_badseq); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1819 | brcmu_bprintf(strbuf, "fc_rcvd %d, fc_xoff %d, fc_xon %d\n", |
| 1820 | bus->fc_rcvd, bus->fc_xoff, bus->fc_xon); |
| 1821 | brcmu_bprintf(strbuf, "rxglomfail %d, rxglomframes %d, rxglompkts %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1822 | bus->rxglomfail, bus->rxglomframes, bus->rxglompkts); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1823 | brcmu_bprintf(strbuf, "f2rx (hdrs/data) %d (%d/%d), f2tx %d f1regs" |
| 1824 | " %d\n", |
| 1825 | (bus->f2rxhdrs + bus->f2rxdata), bus->f2rxhdrs, |
| 1826 | bus->f2rxdata, bus->f2txdata, bus->f1regdata); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1827 | { |
| 1828 | dhd_dump_pct(strbuf, "\nRx: pkts/f2rd", bus->dhd->rx_packets, |
| 1829 | (bus->f2rxhdrs + bus->f2rxdata)); |
| 1830 | dhd_dump_pct(strbuf, ", pkts/f1sd", bus->dhd->rx_packets, |
| 1831 | bus->f1regdata); |
| 1832 | dhd_dump_pct(strbuf, ", pkts/sd", bus->dhd->rx_packets, |
| 1833 | (bus->f2rxhdrs + bus->f2rxdata + bus->f1regdata)); |
| 1834 | dhd_dump_pct(strbuf, ", pkts/int", bus->dhd->rx_packets, |
| 1835 | bus->intrcount); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1836 | brcmu_bprintf(strbuf, "\n"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1837 | |
| 1838 | dhd_dump_pct(strbuf, "Rx: glom pct", (100 * bus->rxglompkts), |
| 1839 | bus->dhd->rx_packets); |
| 1840 | dhd_dump_pct(strbuf, ", pkts/glom", bus->rxglompkts, |
| 1841 | bus->rxglomframes); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1842 | brcmu_bprintf(strbuf, "\n"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1843 | |
| 1844 | dhd_dump_pct(strbuf, "Tx: pkts/f2wr", bus->dhd->tx_packets, |
| 1845 | bus->f2txdata); |
| 1846 | dhd_dump_pct(strbuf, ", pkts/f1sd", bus->dhd->tx_packets, |
| 1847 | bus->f1regdata); |
| 1848 | dhd_dump_pct(strbuf, ", pkts/sd", bus->dhd->tx_packets, |
| 1849 | (bus->f2txdata + bus->f1regdata)); |
| 1850 | dhd_dump_pct(strbuf, ", pkts/int", bus->dhd->tx_packets, |
| 1851 | bus->intrcount); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1852 | brcmu_bprintf(strbuf, "\n"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1853 | |
| 1854 | dhd_dump_pct(strbuf, "Total: pkts/f2rw", |
| 1855 | (bus->dhd->tx_packets + bus->dhd->rx_packets), |
| 1856 | (bus->f2txdata + bus->f2rxhdrs + bus->f2rxdata)); |
| 1857 | dhd_dump_pct(strbuf, ", pkts/f1sd", |
| 1858 | (bus->dhd->tx_packets + bus->dhd->rx_packets), |
| 1859 | bus->f1regdata); |
| 1860 | dhd_dump_pct(strbuf, ", pkts/sd", |
| 1861 | (bus->dhd->tx_packets + bus->dhd->rx_packets), |
| 1862 | (bus->f2txdata + bus->f2rxhdrs + bus->f2rxdata + |
| 1863 | bus->f1regdata)); |
| 1864 | dhd_dump_pct(strbuf, ", pkts/int", |
| 1865 | (bus->dhd->tx_packets + bus->dhd->rx_packets), |
| 1866 | bus->intrcount); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1867 | brcmu_bprintf(strbuf, "\n\n"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1868 | } |
| 1869 | |
| 1870 | #ifdef SDTEST |
| 1871 | if (bus->pktgen_count) { |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1872 | brcmu_bprintf(strbuf, "pktgen config and count:\n"); |
| 1873 | brcmu_bprintf(strbuf, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1874 | "freq %d count %d print %d total %d min %d len %d\n", |
| 1875 | bus->pktgen_freq, bus->pktgen_count, |
| 1876 | bus->pktgen_print, bus->pktgen_total, |
| 1877 | bus->pktgen_minlen, bus->pktgen_maxlen); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1878 | brcmu_bprintf(strbuf, "send attempts %d rcvd %d fail %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1879 | bus->pktgen_sent, bus->pktgen_rcvd, |
| 1880 | bus->pktgen_fail); |
| 1881 | } |
| 1882 | #endif /* SDTEST */ |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1883 | #ifdef BCMDBG |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1884 | brcmu_bprintf(strbuf, "dpc_sched %d host interrupt%spending\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1885 | bus->dpc_sched, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1886 | (brcmf_sdcard_intr_pending(bus->sdh) ? " " : " not ")); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1887 | brcmu_bprintf(strbuf, "blocksize %d roundup %d\n", bus->blocksize, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1888 | bus->roundup); |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 1889 | #endif /* BCMDBG */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1890 | brcmu_bprintf(strbuf, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1891 | "clkstate %d activity %d idletime %d idlecount %d sleeping %d\n", |
| 1892 | bus->clkstate, bus->activity, bus->idletime, bus->idlecount, |
| 1893 | bus->sleeping); |
| 1894 | } |
| 1895 | |
| 1896 | void dhd_bus_clearcounts(dhd_pub_t *dhdp) |
| 1897 | { |
| 1898 | dhd_bus_t *bus = (dhd_bus_t *) dhdp->bus; |
| 1899 | |
| 1900 | bus->intrcount = bus->lastintrs = bus->spurious = bus->regfails = 0; |
| 1901 | bus->rxrtx = bus->rx_toolong = bus->rxc_errors = 0; |
| 1902 | bus->rx_hdrfail = bus->rx_badhdr = bus->rx_badseq = 0; |
| 1903 | bus->tx_sderrs = bus->fc_rcvd = bus->fc_xoff = bus->fc_xon = 0; |
| 1904 | bus->rxglomfail = bus->rxglomframes = bus->rxglompkts = 0; |
| 1905 | bus->f2rxhdrs = bus->f2rxdata = bus->f2txdata = bus->f1regdata = 0; |
| 1906 | } |
| 1907 | |
| 1908 | #ifdef SDTEST |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1909 | static int brcmf_sdbrcm_pktgen_get(dhd_bus_t *bus, u8 *arg) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1910 | { |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 1911 | brcmf_pktgen_t pktgen; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1912 | |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 1913 | pktgen.version = BRCMF_PKTGEN_VERSION; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1914 | pktgen.freq = bus->pktgen_freq; |
| 1915 | pktgen.count = bus->pktgen_count; |
| 1916 | pktgen.print = bus->pktgen_print; |
| 1917 | pktgen.total = bus->pktgen_total; |
| 1918 | pktgen.minlen = bus->pktgen_minlen; |
| 1919 | pktgen.maxlen = bus->pktgen_maxlen; |
| 1920 | pktgen.numsent = bus->pktgen_sent; |
| 1921 | pktgen.numrcvd = bus->pktgen_rcvd; |
| 1922 | pktgen.numfail = bus->pktgen_fail; |
| 1923 | pktgen.mode = bus->pktgen_mode; |
| 1924 | pktgen.stop = bus->pktgen_stop; |
| 1925 | |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 1926 | memcpy(arg, &pktgen, sizeof(pktgen)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1927 | |
| 1928 | return 0; |
| 1929 | } |
| 1930 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1931 | static int brcmf_sdbrcm_pktgen_set(dhd_bus_t *bus, u8 *arg) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1932 | { |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 1933 | brcmf_pktgen_t pktgen; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1934 | uint oldcnt, oldmode; |
| 1935 | |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 1936 | memcpy(&pktgen, arg, sizeof(pktgen)); |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 1937 | if (pktgen.version != BRCMF_PKTGEN_VERSION) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 1938 | return -EINVAL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1939 | |
| 1940 | oldcnt = bus->pktgen_count; |
| 1941 | oldmode = bus->pktgen_mode; |
| 1942 | |
| 1943 | bus->pktgen_freq = pktgen.freq; |
| 1944 | bus->pktgen_count = pktgen.count; |
| 1945 | bus->pktgen_print = pktgen.print; |
| 1946 | bus->pktgen_total = pktgen.total; |
| 1947 | bus->pktgen_minlen = pktgen.minlen; |
| 1948 | bus->pktgen_maxlen = pktgen.maxlen; |
| 1949 | bus->pktgen_mode = pktgen.mode; |
| 1950 | bus->pktgen_stop = pktgen.stop; |
| 1951 | |
| 1952 | bus->pktgen_tick = bus->pktgen_ptick = 0; |
Greg Kroah-Hartman | 3ea2f4d | 2010-10-08 11:39:43 -0700 | [diff] [blame] | 1953 | bus->pktgen_len = max(bus->pktgen_len, bus->pktgen_minlen); |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 1954 | bus->pktgen_len = min(bus->pktgen_len, bus->pktgen_maxlen); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1955 | |
| 1956 | /* Clear counts for a new pktgen (mode change, or was stopped) */ |
| 1957 | if (bus->pktgen_count && (!oldcnt || oldmode != bus->pktgen_mode)) |
| 1958 | bus->pktgen_sent = bus->pktgen_rcvd = bus->pktgen_fail = 0; |
| 1959 | |
| 1960 | return 0; |
| 1961 | } |
| 1962 | #endif /* SDTEST */ |
| 1963 | |
| 1964 | static int |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1965 | 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] | 1966 | uint size) |
| 1967 | { |
| 1968 | int bcmerror = 0; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1969 | u32 sdaddr; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1970 | uint dsize; |
| 1971 | |
| 1972 | /* Determine initial transfer parameters */ |
| 1973 | sdaddr = address & SBSDIO_SB_OFT_ADDR_MASK; |
| 1974 | if ((sdaddr + size) & SBSDIO_SBWINDOW_MASK) |
| 1975 | dsize = (SBSDIO_SB_OFT_ADDR_LIMIT - sdaddr); |
| 1976 | else |
| 1977 | dsize = size; |
| 1978 | |
| 1979 | /* Set the backplane window to include the start address */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1980 | bcmerror = brcmf_sdbrcm_set_siaddr_window(bus, address); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1981 | if (bcmerror) { |
| 1982 | DHD_ERROR(("%s: window change failed\n", __func__)); |
| 1983 | goto xfer_done; |
| 1984 | } |
| 1985 | |
| 1986 | /* Do the transfer(s) */ |
| 1987 | while (size) { |
| 1988 | DHD_INFO(("%s: %s %d bytes at offset 0x%08x in window 0x%08x\n", |
| 1989 | __func__, (write ? "write" : "read"), dsize, |
| 1990 | sdaddr, (address & SBSDIO_SBWINDOW_MASK))); |
| 1991 | bcmerror = |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 1992 | brcmf_sdcard_rwdata(bus->sdh, write, sdaddr, data, dsize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1993 | if (bcmerror) { |
| 1994 | DHD_ERROR(("%s: membytes transfer failed\n", __func__)); |
| 1995 | break; |
| 1996 | } |
| 1997 | |
| 1998 | /* Adjust for next transfer (if any) */ |
| 1999 | size -= dsize; |
| 2000 | if (size) { |
| 2001 | data += dsize; |
| 2002 | address += dsize; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2003 | bcmerror = brcmf_sdbrcm_set_siaddr_window(bus, address); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2004 | if (bcmerror) { |
| 2005 | DHD_ERROR(("%s: window change failed\n", |
| 2006 | __func__)); |
| 2007 | break; |
| 2008 | } |
| 2009 | sdaddr = 0; |
Greg Kroah-Hartman | b61640d | 2010-10-08 12:37:39 -0700 | [diff] [blame] | 2010 | dsize = min_t(uint, SBSDIO_SB_OFT_ADDR_LIMIT, size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2011 | } |
| 2012 | } |
| 2013 | |
| 2014 | xfer_done: |
| 2015 | /* Return the window to backplane enumeration space for core access */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2016 | if (brcmf_sdbrcm_set_siaddr_window(bus, |
| 2017 | brcmf_sdcard_cur_sbwad(bus->sdh))) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2018 | DHD_ERROR(("%s: FAILED to set window back to 0x%x\n", |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2019 | __func__, brcmf_sdcard_cur_sbwad(bus->sdh))); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2020 | } |
| 2021 | |
| 2022 | return bcmerror; |
| 2023 | } |
| 2024 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 2025 | #ifdef BCMDBG |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2026 | 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] | 2027 | { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2028 | u32 addr; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2029 | int rv; |
| 2030 | |
| 2031 | /* Read last word in memory to determine address of |
| 2032 | sdpcm_shared structure */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2033 | rv = brcmf_sdbrcm_membytes(bus, false, bus->ramsize - 4, (u8 *)&addr, |
| 2034 | 4); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2035 | if (rv < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2036 | return rv; |
| 2037 | |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 2038 | addr = le32_to_cpu(addr); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2039 | |
| 2040 | DHD_INFO(("sdpcm_shared address 0x%08X\n", addr)); |
| 2041 | |
| 2042 | /* |
| 2043 | * Check if addr is valid. |
| 2044 | * NVRAM length at the end of memory should have been overwritten. |
| 2045 | */ |
| 2046 | if (addr == 0 || ((~addr >> 16) & 0xffff) == (addr & 0xffff)) { |
| 2047 | DHD_ERROR(("%s: address (0x%08x) of sdpcm_shared invalid\n", |
| 2048 | __func__, addr)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2049 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2050 | } |
| 2051 | |
Roland Vossen | 70963f9 | 2011-06-01 13:45:08 +0200 | [diff] [blame] | 2052 | /* Read rte_shared structure */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2053 | rv = brcmf_sdbrcm_membytes(bus, false, addr, (u8 *) sh, |
Franky Lin | b49b14d | 2011-06-01 13:45:37 +0200 | [diff] [blame] | 2054 | sizeof(struct sdpcm_shared)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2055 | if (rv < 0) |
| 2056 | return rv; |
| 2057 | |
| 2058 | /* Endianness */ |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 2059 | sh->flags = le32_to_cpu(sh->flags); |
| 2060 | sh->trap_addr = le32_to_cpu(sh->trap_addr); |
| 2061 | sh->assert_exp_addr = le32_to_cpu(sh->assert_exp_addr); |
| 2062 | sh->assert_file_addr = le32_to_cpu(sh->assert_file_addr); |
| 2063 | sh->assert_line = le32_to_cpu(sh->assert_line); |
| 2064 | sh->console_addr = le32_to_cpu(sh->console_addr); |
| 2065 | sh->msgtrace_addr = le32_to_cpu(sh->msgtrace_addr); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2066 | |
| 2067 | if ((sh->flags & SDPCM_SHARED_VERSION_MASK) != SDPCM_SHARED_VERSION) { |
| 2068 | DHD_ERROR(("%s: sdpcm_shared version %d in dhd " |
| 2069 | "is different than sdpcm_shared version %d in dongle\n", |
| 2070 | __func__, SDPCM_SHARED_VERSION, |
| 2071 | sh->flags & SDPCM_SHARED_VERSION_MASK)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2072 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2073 | } |
| 2074 | |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 2075 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2076 | } |
| 2077 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2078 | 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] | 2079 | { |
| 2080 | int bcmerror = 0; |
| 2081 | uint msize = 512; |
| 2082 | char *mbuffer = NULL; |
| 2083 | uint maxstrlen = 256; |
| 2084 | char *str = NULL; |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 2085 | struct brcmf_trap tr; |
Franky Lin | b49b14d | 2011-06-01 13:45:37 +0200 | [diff] [blame] | 2086 | struct sdpcm_shared sdpcm_shared; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2087 | struct brcmu_strbuf strbuf; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2088 | |
| 2089 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 2090 | |
| 2091 | if (data == NULL) { |
| 2092 | /* |
| 2093 | * Called after a rx ctrl timeout. "data" is NULL. |
| 2094 | * allocate memory to trace the trap or assert. |
| 2095 | */ |
| 2096 | size = msize; |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2097 | mbuffer = data = kmalloc(msize, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2098 | if (mbuffer == NULL) { |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2099 | DHD_ERROR(("%s: kmalloc(%d) failed\n", __func__, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2100 | msize)); |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2101 | bcmerror = -ENOMEM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2102 | goto done; |
| 2103 | } |
| 2104 | } |
| 2105 | |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2106 | str = kmalloc(maxstrlen, GFP_ATOMIC); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2107 | if (str == NULL) { |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2108 | DHD_ERROR(("%s: kmalloc(%d) failed\n", __func__, maxstrlen)); |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2109 | bcmerror = -ENOMEM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2110 | goto done; |
| 2111 | } |
| 2112 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2113 | bcmerror = brcmf_sdbrcm_readshared(bus, &sdpcm_shared); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2114 | if (bcmerror < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2115 | goto done; |
| 2116 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2117 | brcmu_binit(&strbuf, data, size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2118 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2119 | brcmu_bprintf(&strbuf, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2120 | "msgtrace address : 0x%08X\nconsole address : 0x%08X\n", |
| 2121 | sdpcm_shared.msgtrace_addr, sdpcm_shared.console_addr); |
| 2122 | |
| 2123 | if ((sdpcm_shared.flags & SDPCM_SHARED_ASSERT_BUILT) == 0) { |
| 2124 | /* NOTE: Misspelled assert is intentional - DO NOT FIX. |
| 2125 | * (Avoids conflict with real asserts for programmatic |
| 2126 | * parsing of output.) |
| 2127 | */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2128 | brcmu_bprintf(&strbuf, "Assrt not built in dongle\n"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2129 | } |
| 2130 | |
| 2131 | if ((sdpcm_shared.flags & (SDPCM_SHARED_ASSERT | SDPCM_SHARED_TRAP)) == |
| 2132 | 0) { |
| 2133 | /* NOTE: Misspelled assert is intentional - DO NOT FIX. |
| 2134 | * (Avoids conflict with real asserts for programmatic |
| 2135 | * parsing of output.) |
| 2136 | */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2137 | brcmu_bprintf(&strbuf, "No trap%s in dongle", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2138 | (sdpcm_shared.flags & SDPCM_SHARED_ASSERT_BUILT) |
| 2139 | ? "/assrt" : ""); |
| 2140 | } else { |
| 2141 | if (sdpcm_shared.flags & SDPCM_SHARED_ASSERT) { |
| 2142 | /* Download assert */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2143 | brcmu_bprintf(&strbuf, "Dongle assert"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2144 | if (sdpcm_shared.assert_exp_addr != 0) { |
| 2145 | str[0] = '\0'; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2146 | bcmerror = brcmf_sdbrcm_membytes(bus, false, |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2147 | sdpcm_shared.assert_exp_addr, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2148 | (u8 *) str, maxstrlen); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2149 | if (bcmerror < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2150 | goto done; |
| 2151 | |
| 2152 | str[maxstrlen - 1] = '\0'; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2153 | brcmu_bprintf(&strbuf, " expr \"%s\"", str); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2154 | } |
| 2155 | |
| 2156 | if (sdpcm_shared.assert_file_addr != 0) { |
| 2157 | str[0] = '\0'; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2158 | bcmerror = brcmf_sdbrcm_membytes(bus, false, |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2159 | sdpcm_shared.assert_file_addr, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2160 | (u8 *) str, maxstrlen); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2161 | if (bcmerror < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2162 | goto done; |
| 2163 | |
| 2164 | str[maxstrlen - 1] = '\0'; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2165 | brcmu_bprintf(&strbuf, " file \"%s\"", str); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2166 | } |
| 2167 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2168 | brcmu_bprintf(&strbuf, " line %d ", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2169 | sdpcm_shared.assert_line); |
| 2170 | } |
| 2171 | |
| 2172 | if (sdpcm_shared.flags & SDPCM_SHARED_TRAP) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2173 | bcmerror = brcmf_sdbrcm_membytes(bus, false, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2174 | sdpcm_shared.trap_addr, (u8 *)&tr, |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 2175 | sizeof(struct brcmf_trap)); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2176 | if (bcmerror < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2177 | goto done; |
| 2178 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2179 | brcmu_bprintf(&strbuf, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2180 | "Dongle trap type 0x%x @ epc 0x%x, cpsr 0x%x, spsr 0x%x, sp 0x%x," |
| 2181 | "lp 0x%x, rpc 0x%x Trap offset 0x%x, " |
| 2182 | "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", |
| 2183 | tr.type, tr.epc, tr.cpsr, tr.spsr, tr.r13, |
| 2184 | tr.r14, tr.pc, sdpcm_shared.trap_addr, |
| 2185 | tr.r0, tr.r1, tr.r2, tr.r3, tr.r4, tr.r5, |
| 2186 | tr.r6, tr.r7); |
| 2187 | } |
| 2188 | } |
| 2189 | |
| 2190 | if (sdpcm_shared.flags & (SDPCM_SHARED_ASSERT | SDPCM_SHARED_TRAP)) |
| 2191 | DHD_ERROR(("%s: %s\n", __func__, strbuf.origbuf)); |
| 2192 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 2193 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2194 | if (sdpcm_shared.flags & SDPCM_SHARED_TRAP) { |
| 2195 | /* Mem dump to a file on device */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2196 | brcmf_sdbrcm_mem_dump(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2197 | } |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 2198 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2199 | |
| 2200 | done: |
Ilia Mirkin | 46d994b | 2011-03-13 00:28:56 -0500 | [diff] [blame] | 2201 | kfree(mbuffer); |
| 2202 | kfree(str); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2203 | |
| 2204 | return bcmerror; |
| 2205 | } |
| 2206 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2207 | static int brcmf_sdbrcm_mem_dump(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2208 | { |
| 2209 | int ret = 0; |
| 2210 | int size; /* Full mem size */ |
| 2211 | int start = 0; /* Start address */ |
| 2212 | int read_size = 0; /* Read size of each iteration */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2213 | u8 *buf = NULL, *databuf = NULL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2214 | |
| 2215 | /* Get full mem size */ |
| 2216 | size = bus->ramsize; |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2217 | buf = kmalloc(size, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2218 | if (!buf) { |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 2219 | DHD_ERROR(("%s: Out of memory (%d bytes)\n", __func__, size)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2220 | return -1; |
| 2221 | } |
| 2222 | |
| 2223 | /* Read mem content */ |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 2224 | printk(KERN_DEBUG "Dump dongle memory"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2225 | databuf = buf; |
| 2226 | while (size) { |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 2227 | read_size = min(MEMBLOCK, size); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2228 | ret = brcmf_sdbrcm_membytes(bus, false, start, databuf, |
| 2229 | read_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2230 | if (ret) { |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 2231 | DHD_ERROR(("%s: Error membytes %d\n", __func__, ret)); |
Ilia Mirkin | 46d994b | 2011-03-13 00:28:56 -0500 | [diff] [blame] | 2232 | kfree(buf); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2233 | return -1; |
| 2234 | } |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 2235 | printk("."); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2236 | |
| 2237 | /* Decrement size and increment start address */ |
| 2238 | size -= read_size; |
| 2239 | start += read_size; |
| 2240 | databuf += read_size; |
| 2241 | } |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 2242 | printk(KERN_DEBUG "Done\n"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2243 | |
| 2244 | /* free buf before return !!! */ |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 2245 | if (brcmf_write_to_file(bus->dhd, buf, bus->ramsize)) { |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 2246 | DHD_ERROR(("%s: Error writing to files\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2247 | return -1; |
| 2248 | } |
| 2249 | |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 2250 | /* buf free handled in brcmf_write_to_file, not here */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2251 | return 0; |
| 2252 | } |
| 2253 | |
| 2254 | #define CONSOLE_LINE_MAX 192 |
| 2255 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2256 | static int brcmf_sdbrcm_readconsole(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2257 | { |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 2258 | struct dhd_console *c = &bus->console; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2259 | u8 line[CONSOLE_LINE_MAX], ch; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2260 | u32 n, idx, addr; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2261 | int rv; |
| 2262 | |
| 2263 | /* Don't do anything until FWREADY updates console address */ |
| 2264 | if (bus->console_addr == 0) |
| 2265 | return 0; |
| 2266 | |
| 2267 | /* Read console log struct */ |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 2268 | addr = bus->console_addr + offsetof(struct rte_console, log); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2269 | rv = brcmf_sdbrcm_membytes(bus, false, addr, (u8 *)&c->log, |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2270 | sizeof(c->log)); |
| 2271 | if (rv < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2272 | return rv; |
| 2273 | |
| 2274 | /* Allocate console buffer (one time only) */ |
| 2275 | if (c->buf == NULL) { |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 2276 | c->bufsize = le32_to_cpu(c->log.buf_size); |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2277 | c->buf = kmalloc(c->bufsize, GFP_ATOMIC); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2278 | if (c->buf == NULL) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2279 | return -ENOMEM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2280 | } |
| 2281 | |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 2282 | idx = le32_to_cpu(c->log.idx); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2283 | |
| 2284 | /* Protect against corrupt value */ |
| 2285 | if (idx > c->bufsize) |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2286 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2287 | |
| 2288 | /* Skip reading the console buffer if the index pointer |
| 2289 | has not moved */ |
| 2290 | if (idx == c->last) |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 2291 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2292 | |
| 2293 | /* Read the console buffer */ |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 2294 | addr = le32_to_cpu(c->log.buf); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2295 | rv = brcmf_sdbrcm_membytes(bus, false, addr, c->buf, c->bufsize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2296 | if (rv < 0) |
| 2297 | return rv; |
| 2298 | |
| 2299 | while (c->last != idx) { |
| 2300 | for (n = 0; n < CONSOLE_LINE_MAX - 2; n++) { |
| 2301 | if (c->last == idx) { |
| 2302 | /* This would output a partial line. |
| 2303 | * Instead, back up |
| 2304 | * the buffer pointer and output this |
| 2305 | * line next time around. |
| 2306 | */ |
| 2307 | if (c->last >= n) |
| 2308 | c->last -= n; |
| 2309 | else |
| 2310 | c->last = c->bufsize - n; |
| 2311 | goto break2; |
| 2312 | } |
| 2313 | ch = c->buf[c->last]; |
| 2314 | c->last = (c->last + 1) % c->bufsize; |
| 2315 | if (ch == '\n') |
| 2316 | break; |
| 2317 | line[n] = ch; |
| 2318 | } |
| 2319 | |
| 2320 | if (n > 0) { |
| 2321 | if (line[n - 1] == '\r') |
| 2322 | n--; |
| 2323 | line[n] = 0; |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 2324 | printk(KERN_DEBUG "CONSOLE: %s\n", line); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2325 | } |
| 2326 | } |
| 2327 | break2: |
| 2328 | |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 2329 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2330 | } |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 2331 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2332 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2333 | int brcmf_sdbrcm_downloadvars(dhd_bus_t *bus, void *arg, int len) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2334 | { |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 2335 | int bcmerror = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2336 | |
| 2337 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 2338 | |
| 2339 | /* Basic sanity checks */ |
| 2340 | if (bus->dhd->up) { |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2341 | bcmerror = -EISCONN; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2342 | goto err; |
| 2343 | } |
| 2344 | if (!len) { |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2345 | bcmerror = -EOVERFLOW; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2346 | goto err; |
| 2347 | } |
| 2348 | |
| 2349 | /* Free the old ones and replace with passed variables */ |
Ilia Mirkin | 46d994b | 2011-03-13 00:28:56 -0500 | [diff] [blame] | 2350 | kfree(bus->vars); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2351 | |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2352 | bus->vars = kmalloc(len, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2353 | bus->varsz = bus->vars ? len : 0; |
| 2354 | if (bus->vars == NULL) { |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2355 | bcmerror = -ENOMEM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2356 | goto err; |
| 2357 | } |
| 2358 | |
| 2359 | /* Copy the passed variables, which should include the |
| 2360 | terminating double-null */ |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2361 | memcpy(bus->vars, arg, bus->varsz); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2362 | err: |
| 2363 | return bcmerror; |
| 2364 | } |
| 2365 | |
| 2366 | static int |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2367 | 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] | 2368 | const char *name, void *params, int plen, void *arg, int len, |
| 2369 | int val_size) |
| 2370 | { |
| 2371 | int bcmerror = 0; |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2372 | s32 int_val = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2373 | bool bool_val = 0; |
| 2374 | |
| 2375 | DHD_TRACE(("%s: Enter, action %d name %s params %p plen %d arg %p " |
| 2376 | "len %d val_size %d\n", |
| 2377 | __func__, actionid, name, params, plen, arg, len, val_size)); |
| 2378 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2379 | bcmerror = brcmu_iovar_lencheck(vi, arg, len, IOV_ISSET(actionid)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2380 | if (bcmerror != 0) |
| 2381 | goto exit; |
| 2382 | |
| 2383 | if (plen >= (int)sizeof(int_val)) |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2384 | memcpy(&int_val, params, sizeof(int_val)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2385 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2386 | bool_val = (int_val != 0) ? true : false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2387 | |
| 2388 | /* Some ioctls use the bus */ |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 2389 | brcmf_sdbrcm_sdlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2390 | |
| 2391 | /* Check if dongle is in reset. If so, only allow DEVRESET iovars */ |
| 2392 | if (bus->dhd->dongle_reset && !(actionid == IOV_SVAL(IOV_DEVRESET) || |
| 2393 | actionid == IOV_GVAL(IOV_DEVRESET))) { |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2394 | bcmerror = -EPERM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2395 | goto exit; |
| 2396 | } |
| 2397 | |
| 2398 | /* Handle sleep stuff before any clock mucking */ |
| 2399 | if (vi->varid == IOV_SLEEP) { |
| 2400 | if (IOV_ISSET(actionid)) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2401 | bcmerror = brcmf_sdbrcm_bussleep(bus, bool_val); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2402 | } else { |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2403 | int_val = (s32) bus->sleeping; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2404 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2405 | } |
| 2406 | goto exit; |
| 2407 | } |
| 2408 | |
| 2409 | /* Request clock to allow SDIO accesses */ |
| 2410 | if (!bus->dhd->dongle_reset) { |
| 2411 | BUS_WAKE(bus); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2412 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2413 | } |
| 2414 | |
| 2415 | switch (actionid) { |
| 2416 | case IOV_GVAL(IOV_INTR): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2417 | int_val = (s32) bus->intr; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2418 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2419 | break; |
| 2420 | |
| 2421 | case IOV_SVAL(IOV_INTR): |
| 2422 | bus->intr = bool_val; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2423 | bus->intdis = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2424 | if (bus->dhd->up) { |
| 2425 | if (bus->intr) { |
| 2426 | DHD_INTR(("%s: enable SDIO device interrupts\n", |
| 2427 | __func__)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2428 | brcmf_sdcard_intr_enable(bus->sdh); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2429 | } else { |
| 2430 | DHD_INTR(("%s: disable SDIO interrupts\n", |
| 2431 | __func__)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2432 | brcmf_sdcard_intr_disable(bus->sdh); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2433 | } |
| 2434 | } |
| 2435 | break; |
| 2436 | |
| 2437 | case IOV_GVAL(IOV_POLLRATE): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2438 | int_val = (s32) bus->pollrate; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2439 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2440 | break; |
| 2441 | |
| 2442 | case IOV_SVAL(IOV_POLLRATE): |
| 2443 | bus->pollrate = (uint) int_val; |
| 2444 | bus->poll = (bus->pollrate != 0); |
| 2445 | break; |
| 2446 | |
| 2447 | case IOV_GVAL(IOV_IDLETIME): |
| 2448 | int_val = bus->idletime; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2449 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2450 | break; |
| 2451 | |
| 2452 | case IOV_SVAL(IOV_IDLETIME): |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 2453 | if ((int_val < 0) && (int_val != BRCMF_IDLE_IMMEDIATE)) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2454 | bcmerror = -EINVAL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2455 | else |
| 2456 | bus->idletime = int_val; |
| 2457 | break; |
| 2458 | |
| 2459 | case IOV_GVAL(IOV_IDLECLOCK): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2460 | int_val = (s32) bus->idleclock; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2461 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2462 | break; |
| 2463 | |
| 2464 | case IOV_SVAL(IOV_IDLECLOCK): |
| 2465 | bus->idleclock = int_val; |
| 2466 | break; |
| 2467 | |
| 2468 | case IOV_GVAL(IOV_SD1IDLE): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2469 | int_val = (s32) sd1idle; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2470 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2471 | break; |
| 2472 | |
| 2473 | case IOV_SVAL(IOV_SD1IDLE): |
| 2474 | sd1idle = bool_val; |
| 2475 | break; |
| 2476 | |
| 2477 | case IOV_SVAL(IOV_MEMBYTES): |
| 2478 | case IOV_GVAL(IOV_MEMBYTES): |
| 2479 | { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2480 | u32 address; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2481 | uint size, dsize; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2482 | u8 *data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2483 | |
| 2484 | bool set = (actionid == IOV_SVAL(IOV_MEMBYTES)); |
| 2485 | |
| 2486 | ASSERT(plen >= 2 * sizeof(int)); |
| 2487 | |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2488 | address = (u32) int_val; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2489 | memcpy(&int_val, (char *)params + sizeof(int_val), |
| 2490 | sizeof(int_val)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2491 | size = (uint) int_val; |
| 2492 | |
| 2493 | /* Do some validation */ |
| 2494 | dsize = set ? plen - (2 * sizeof(int)) : len; |
| 2495 | if (dsize < size) { |
| 2496 | DHD_ERROR(("%s: error on %s membytes, addr " |
| 2497 | "0x%08x size %d dsize %d\n", |
| 2498 | __func__, (set ? "set" : "get"), |
| 2499 | address, size, dsize)); |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2500 | bcmerror = -EINVAL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2501 | break; |
| 2502 | } |
| 2503 | |
| 2504 | DHD_INFO(("%s: Request to %s %d bytes at address " |
| 2505 | "0x%08x\n", |
| 2506 | __func__, (set ? "write" : "read"), size, address)); |
| 2507 | |
| 2508 | /* If we know about SOCRAM, check for a fit */ |
| 2509 | if ((bus->orig_ramsize) && |
| 2510 | ((address > bus->orig_ramsize) |
| 2511 | || (address + size > bus->orig_ramsize))) { |
| 2512 | DHD_ERROR(("%s: ramsize 0x%08x doesn't have %d " |
| 2513 | "bytes at 0x%08x\n", |
| 2514 | __func__, bus->orig_ramsize, size, address)); |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2515 | bcmerror = -EINVAL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2516 | break; |
| 2517 | } |
| 2518 | |
| 2519 | /* Generate the actual data pointer */ |
| 2520 | data = |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2521 | set ? (u8 *) params + |
| 2522 | 2 * sizeof(int) : (u8 *) arg; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2523 | |
| 2524 | /* Call to do the transfer */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2525 | bcmerror = brcmf_sdbrcm_membytes(bus, set, address, |
| 2526 | data, size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2527 | |
| 2528 | break; |
| 2529 | } |
| 2530 | |
| 2531 | case IOV_GVAL(IOV_MEMSIZE): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2532 | int_val = (s32) bus->ramsize; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2533 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2534 | break; |
| 2535 | |
| 2536 | case IOV_GVAL(IOV_SDIOD_DRIVE): |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 2537 | int_val = (s32) brcmf_sdiod_drive_strength; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2538 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2539 | break; |
| 2540 | |
| 2541 | case IOV_SVAL(IOV_SDIOD_DRIVE): |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 2542 | brcmf_sdiod_drive_strength = int_val; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2543 | brcmf_sdbrcm_sdiod_drive_strength_init(bus, |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 2544 | brcmf_sdiod_drive_strength); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2545 | break; |
| 2546 | |
| 2547 | case IOV_SVAL(IOV_DOWNLOAD): |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2548 | bcmerror = brcmf_sdbrcm_download_state(bus, bool_val); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2549 | break; |
| 2550 | |
| 2551 | case IOV_SVAL(IOV_VARS): |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2552 | bcmerror = brcmf_sdbrcm_downloadvars(bus, arg, len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2553 | break; |
| 2554 | |
| 2555 | case IOV_GVAL(IOV_READAHEAD): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2556 | int_val = (s32) dhd_readahead; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2557 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2558 | break; |
| 2559 | |
| 2560 | case IOV_SVAL(IOV_READAHEAD): |
| 2561 | if (bool_val && !dhd_readahead) |
| 2562 | bus->nextlen = 0; |
| 2563 | dhd_readahead = bool_val; |
| 2564 | break; |
| 2565 | |
| 2566 | case IOV_GVAL(IOV_SDRXCHAIN): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2567 | int_val = (s32) bus->use_rxchain; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2568 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2569 | break; |
| 2570 | |
| 2571 | case IOV_SVAL(IOV_SDRXCHAIN): |
| 2572 | if (bool_val && !bus->sd_rxchain) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2573 | bcmerror = -ENOTSUPP; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2574 | else |
| 2575 | bus->use_rxchain = bool_val; |
| 2576 | break; |
| 2577 | case IOV_GVAL(IOV_ALIGNCTL): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2578 | int_val = (s32) dhd_alignctl; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2579 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2580 | break; |
| 2581 | |
| 2582 | case IOV_SVAL(IOV_ALIGNCTL): |
| 2583 | dhd_alignctl = bool_val; |
| 2584 | break; |
| 2585 | |
| 2586 | case IOV_GVAL(IOV_SDALIGN): |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 2587 | int_val = BRCMF_SDALIGN; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2588 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2589 | break; |
| 2590 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 2591 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2592 | case IOV_GVAL(IOV_VARS): |
| 2593 | if (bus->varsz < (uint) len) |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2594 | memcpy(arg, bus->vars, bus->varsz); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2595 | else |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2596 | bcmerror = -EOVERFLOW; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2597 | break; |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 2598 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2599 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 2600 | #ifdef BCMDBG |
Franky Lin | 913af5f | 2011-06-29 16:47:44 -0700 | [diff] [blame] | 2601 | case IOV_GVAL(IOV_DCONSOLE_POLL): |
| 2602 | int_val = (s32) brcmf_console_ms; |
| 2603 | memcpy(arg, &int_val, val_size); |
| 2604 | break; |
| 2605 | |
| 2606 | case IOV_SVAL(IOV_DCONSOLE_POLL): |
| 2607 | brcmf_console_ms = (uint) int_val; |
| 2608 | break; |
| 2609 | |
| 2610 | case IOV_SVAL(IOV_CONS): |
| 2611 | if (len > 0) |
| 2612 | bcmerror = brcmf_sdbrcm_bus_console_in(bus->dhd, |
| 2613 | arg, len - 1); |
| 2614 | break; |
| 2615 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2616 | case IOV_GVAL(IOV_SDREG): |
| 2617 | { |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 2618 | struct brcmf_sdreg *sd_ptr; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2619 | u32 addr, size; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2620 | |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 2621 | sd_ptr = (struct brcmf_sdreg *) params; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2622 | |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 2623 | addr = (unsigned long)bus->regs + sd_ptr->offset; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2624 | size = sd_ptr->func; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2625 | int_val = (s32) brcmf_sdcard_reg_read(bus->sdh, addr, |
| 2626 | size); |
| 2627 | if (brcmf_sdcard_regfail(bus->sdh)) |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2628 | bcmerror = -EIO; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2629 | memcpy(arg, &int_val, sizeof(s32)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2630 | break; |
| 2631 | } |
| 2632 | |
| 2633 | case IOV_SVAL(IOV_SDREG): |
| 2634 | { |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 2635 | struct brcmf_sdreg *sd_ptr; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2636 | u32 addr, size; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2637 | |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 2638 | sd_ptr = (struct brcmf_sdreg *) params; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2639 | |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 2640 | addr = (unsigned long)bus->regs + sd_ptr->offset; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2641 | size = sd_ptr->func; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2642 | brcmf_sdcard_reg_write(bus->sdh, addr, size, |
| 2643 | sd_ptr->value); |
| 2644 | if (brcmf_sdcard_regfail(bus->sdh)) |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2645 | bcmerror = -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2646 | break; |
| 2647 | } |
| 2648 | |
| 2649 | /* Same as above, but offset is not backplane |
| 2650 | (not SDIO core) */ |
| 2651 | case IOV_GVAL(IOV_SBREG): |
| 2652 | { |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 2653 | struct brcmf_sdreg sdreg; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2654 | u32 addr, size; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2655 | |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2656 | memcpy(&sdreg, params, sizeof(sdreg)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2657 | |
| 2658 | addr = SI_ENUM_BASE + sdreg.offset; |
| 2659 | size = sdreg.func; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2660 | int_val = (s32) brcmf_sdcard_reg_read(bus->sdh, addr, |
| 2661 | size); |
| 2662 | if (brcmf_sdcard_regfail(bus->sdh)) |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2663 | bcmerror = -EIO; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2664 | memcpy(arg, &int_val, sizeof(s32)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2665 | break; |
| 2666 | } |
| 2667 | |
| 2668 | case IOV_SVAL(IOV_SBREG): |
| 2669 | { |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 2670 | struct brcmf_sdreg sdreg; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2671 | u32 addr, size; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2672 | |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2673 | memcpy(&sdreg, params, sizeof(sdreg)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2674 | |
| 2675 | addr = SI_ENUM_BASE + sdreg.offset; |
| 2676 | size = sdreg.func; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2677 | brcmf_sdcard_reg_write(bus->sdh, addr, size, |
| 2678 | sdreg.value); |
| 2679 | if (brcmf_sdcard_regfail(bus->sdh)) |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2680 | bcmerror = -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2681 | break; |
| 2682 | } |
| 2683 | |
| 2684 | case IOV_GVAL(IOV_SDCIS): |
| 2685 | { |
| 2686 | *(char *)arg = 0; |
| 2687 | |
nohee ko | ea3b8a2 | 2010-10-09 10:34:38 -0700 | [diff] [blame] | 2688 | strcat(arg, "\nFunc 0\n"); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2689 | brcmf_sdcard_cis_read(bus->sdh, 0x10, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2690 | (u8 *) arg + strlen(arg), |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2691 | SBSDIO_CIS_SIZE_LIMIT); |
nohee ko | ea3b8a2 | 2010-10-09 10:34:38 -0700 | [diff] [blame] | 2692 | strcat(arg, "\nFunc 1\n"); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2693 | brcmf_sdcard_cis_read(bus->sdh, 0x11, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2694 | (u8 *) arg + strlen(arg), |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2695 | SBSDIO_CIS_SIZE_LIMIT); |
nohee ko | ea3b8a2 | 2010-10-09 10:34:38 -0700 | [diff] [blame] | 2696 | strcat(arg, "\nFunc 2\n"); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2697 | brcmf_sdcard_cis_read(bus->sdh, 0x12, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2698 | (u8 *) arg + strlen(arg), |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2699 | SBSDIO_CIS_SIZE_LIMIT); |
| 2700 | break; |
| 2701 | } |
| 2702 | |
| 2703 | case IOV_GVAL(IOV_FORCEEVEN): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2704 | int_val = (s32) forcealign; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2705 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2706 | break; |
| 2707 | |
| 2708 | case IOV_SVAL(IOV_FORCEEVEN): |
| 2709 | forcealign = bool_val; |
| 2710 | break; |
| 2711 | |
| 2712 | case IOV_GVAL(IOV_TXBOUND): |
Arend van Spriel | 7af9d0c | 2011-06-29 16:47:19 -0700 | [diff] [blame] | 2713 | int_val = (s32) brcmf_txbound; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2714 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2715 | break; |
| 2716 | |
| 2717 | case IOV_SVAL(IOV_TXBOUND): |
Arend van Spriel | 7af9d0c | 2011-06-29 16:47:19 -0700 | [diff] [blame] | 2718 | brcmf_txbound = (uint) int_val; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2719 | break; |
| 2720 | |
| 2721 | case IOV_GVAL(IOV_RXBOUND): |
Arend van Spriel | 7af9d0c | 2011-06-29 16:47:19 -0700 | [diff] [blame] | 2722 | int_val = (s32) brcmf_rxbound; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2723 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2724 | break; |
| 2725 | |
| 2726 | case IOV_SVAL(IOV_RXBOUND): |
Arend van Spriel | 7af9d0c | 2011-06-29 16:47:19 -0700 | [diff] [blame] | 2727 | brcmf_rxbound = (uint) int_val; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2728 | break; |
| 2729 | |
| 2730 | case IOV_GVAL(IOV_TXMINMAX): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2731 | int_val = (s32) dhd_txminmax; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2732 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2733 | break; |
| 2734 | |
| 2735 | case IOV_SVAL(IOV_TXMINMAX): |
| 2736 | dhd_txminmax = (uint) int_val; |
| 2737 | break; |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 2738 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2739 | |
| 2740 | #ifdef SDTEST |
| 2741 | case IOV_GVAL(IOV_EXTLOOP): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2742 | int_val = (s32) bus->ext_loop; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2743 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2744 | break; |
| 2745 | |
| 2746 | case IOV_SVAL(IOV_EXTLOOP): |
| 2747 | bus->ext_loop = bool_val; |
| 2748 | break; |
| 2749 | |
| 2750 | case IOV_GVAL(IOV_PKTGEN): |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2751 | bcmerror = brcmf_sdbrcm_pktgen_get(bus, arg); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2752 | break; |
| 2753 | |
| 2754 | case IOV_SVAL(IOV_PKTGEN): |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2755 | bcmerror = brcmf_sdbrcm_pktgen_set(bus, arg); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2756 | break; |
| 2757 | #endif /* SDTEST */ |
| 2758 | |
| 2759 | case IOV_SVAL(IOV_DEVRESET): |
| 2760 | DHD_TRACE(("%s: Called set IOV_DEVRESET=%d dongle_reset=%d " |
| 2761 | "busstate=%d\n", |
| 2762 | __func__, bool_val, bus->dhd->dongle_reset, |
| 2763 | bus->dhd->busstate)); |
| 2764 | |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 2765 | brcmf_bus_devreset(bus->dhd, (u8) bool_val); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2766 | |
| 2767 | break; |
| 2768 | |
| 2769 | case IOV_GVAL(IOV_DEVRESET): |
| 2770 | DHD_TRACE(("%s: Called get IOV_DEVRESET\n", __func__)); |
| 2771 | |
| 2772 | /* Get its status */ |
| 2773 | int_val = (bool) bus->dhd->dongle_reset; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2774 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2775 | |
| 2776 | break; |
| 2777 | |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 2778 | case IOV_GVAL(IOV_WDTICK): |
| 2779 | int_val = (s32) brcmf_watchdog_ms; |
| 2780 | memcpy(arg, &int_val, val_size); |
| 2781 | break; |
| 2782 | |
| 2783 | case IOV_SVAL(IOV_WDTICK): |
| 2784 | if (!bus->dhd->up) { |
| 2785 | bcmerror = -ENOLINK; |
| 2786 | break; |
| 2787 | } |
| 2788 | brcmf_sdbrcm_wd_timer(bus, (uint) int_val); |
| 2789 | break; |
| 2790 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2791 | default: |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2792 | bcmerror = -ENOTSUPP; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2793 | break; |
| 2794 | } |
| 2795 | |
| 2796 | exit: |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 2797 | if ((bus->idletime == BRCMF_IDLE_IMMEDIATE) && !bus->dpc_sched) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2798 | bus->activity = false; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2799 | brcmf_sdbrcm_clkctl(bus, CLK_NONE, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2800 | } |
| 2801 | |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 2802 | brcmf_sdbrcm_sdunlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2803 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2804 | if (actionid == IOV_SVAL(IOV_DEVRESET) && bool_val == false) |
Arend van Spriel | aba5e0a | 2011-06-29 16:47:03 -0700 | [diff] [blame] | 2805 | brcmf_c_preinit_ioctls((dhd_pub_t *) bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2806 | |
| 2807 | return bcmerror; |
| 2808 | } |
| 2809 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2810 | static int brcmf_sdbrcm_write_vars(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2811 | { |
| 2812 | int bcmerror = 0; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2813 | u32 varsize; |
| 2814 | u32 varaddr; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2815 | u8 *vbuffer; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2816 | u32 varsizew; |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 2817 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2818 | char *nvram_ularray; |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 2819 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2820 | |
| 2821 | /* Even if there are no vars are to be written, we still |
| 2822 | need to set the ramsize. */ |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 2823 | varsize = bus->varsz ? roundup(bus->varsz, 4) : 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2824 | varaddr = (bus->ramsize - 4) - varsize; |
| 2825 | |
| 2826 | if (bus->vars) { |
Alexander Beregalov | 12d0eb4 | 2011-03-09 03:53:35 +0300 | [diff] [blame] | 2827 | vbuffer = kzalloc(varsize, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2828 | if (!vbuffer) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2829 | return -ENOMEM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2830 | |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2831 | memcpy(vbuffer, bus->vars, bus->varsz); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2832 | |
| 2833 | /* Write the vars list */ |
| 2834 | bcmerror = |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2835 | brcmf_sdbrcm_membytes(bus, true, varaddr, vbuffer, varsize); |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 2836 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2837 | /* Verify NVRAM bytes */ |
| 2838 | DHD_INFO(("Compare NVRAM dl & ul; varsize=%d\n", varsize)); |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2839 | nvram_ularray = kmalloc(varsize, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2840 | if (!nvram_ularray) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2841 | return -ENOMEM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2842 | |
| 2843 | /* Upload image to verify downloaded contents. */ |
| 2844 | memset(nvram_ularray, 0xaa, varsize); |
| 2845 | |
| 2846 | /* Read the vars list to temp buffer for comparison */ |
| 2847 | bcmerror = |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2848 | brcmf_sdbrcm_membytes(bus, false, varaddr, nvram_ularray, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2849 | varsize); |
| 2850 | if (bcmerror) { |
| 2851 | DHD_ERROR(("%s: error %d on reading %d nvram bytes at " |
| 2852 | "0x%08x\n", __func__, bcmerror, varsize, varaddr)); |
| 2853 | } |
| 2854 | /* Compare the org NVRAM with the one read from RAM */ |
| 2855 | if (memcmp(vbuffer, nvram_ularray, varsize)) { |
| 2856 | DHD_ERROR(("%s: Downloaded NVRAM image is corrupted.\n", |
| 2857 | __func__)); |
| 2858 | } else |
| 2859 | DHD_ERROR(("%s: Download/Upload/Compare of NVRAM ok.\n", |
| 2860 | __func__)); |
| 2861 | |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 2862 | kfree(nvram_ularray); |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 2863 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2864 | |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 2865 | kfree(vbuffer); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2866 | } |
| 2867 | |
| 2868 | /* adjust to the user specified RAM */ |
| 2869 | DHD_INFO(("Physical memory size: %d, usable memory size: %d\n", |
| 2870 | bus->orig_ramsize, bus->ramsize)); |
| 2871 | DHD_INFO(("Vars are at %d, orig varsize is %d\n", varaddr, varsize)); |
| 2872 | varsize = ((bus->orig_ramsize - 4) - varaddr); |
| 2873 | |
| 2874 | /* |
| 2875 | * Determine the length token: |
| 2876 | * Varsize, converted to words, in lower 16-bits, checksum |
| 2877 | * in upper 16-bits. |
| 2878 | */ |
| 2879 | if (bcmerror) { |
| 2880 | varsizew = 0; |
| 2881 | } else { |
| 2882 | varsizew = varsize / 4; |
| 2883 | varsizew = (~varsizew << 16) | (varsizew & 0x0000FFFF); |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 2884 | varsizew = cpu_to_le32(varsizew); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2885 | } |
| 2886 | |
| 2887 | DHD_INFO(("New varsize is %d, length token=0x%08x\n", varsize, |
| 2888 | varsizew)); |
| 2889 | |
| 2890 | /* Write the length token to the last word */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2891 | bcmerror = brcmf_sdbrcm_membytes(bus, true, (bus->orig_ramsize - 4), |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2892 | (u8 *)&varsizew, 4); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2893 | |
| 2894 | return bcmerror; |
| 2895 | } |
| 2896 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2897 | static int brcmf_sdbrcm_download_state(dhd_bus_t *bus, bool enter) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2898 | { |
| 2899 | uint retries; |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 2900 | u32 regdata; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2901 | int bcmerror = 0; |
| 2902 | |
| 2903 | /* To enter download state, disable ARM and reset SOCRAM. |
| 2904 | * To exit download state, simply reset ARM (default is RAM boot). |
| 2905 | */ |
| 2906 | if (enter) { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2907 | bus->alp_only = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2908 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2909 | brcmf_sdbrcm_chip_disablecore(bus->sdh, bus->ci->armcorebase); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2910 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2911 | brcmf_sdbrcm_chip_resetcore(bus->sdh, bus->ci->ramcorebase); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2912 | |
| 2913 | /* Clear the top bit of memory */ |
| 2914 | if (bus->ramsize) { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2915 | u32 zeros = 0; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2916 | brcmf_sdbrcm_membytes(bus, true, bus->ramsize - 4, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2917 | (u8 *)&zeros, 4); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2918 | } |
| 2919 | } else { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2920 | regdata = brcmf_sdcard_reg_read(bus->sdh, |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 2921 | CORE_SB(bus->ci->ramcorebase, sbtmstatelow), 4); |
| 2922 | regdata &= (SBTML_RESET | SBTML_REJ_MASK | |
| 2923 | (SICF_CLOCK_EN << SBTML_SICF_SHIFT)); |
| 2924 | if ((SICF_CLOCK_EN << SBTML_SICF_SHIFT) != regdata) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2925 | DHD_ERROR(("%s: SOCRAM core is down after reset?\n", |
| 2926 | __func__)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2927 | bcmerror = -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2928 | goto fail; |
| 2929 | } |
| 2930 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2931 | bcmerror = brcmf_sdbrcm_write_vars(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2932 | if (bcmerror) { |
| 2933 | DHD_ERROR(("%s: no vars written to RAM\n", __func__)); |
| 2934 | bcmerror = 0; |
| 2935 | } |
| 2936 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2937 | W_SDREG(0xFFFFFFFF, &bus->regs->intstatus, retries); |
| 2938 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2939 | brcmf_sdbrcm_chip_resetcore(bus->sdh, bus->ci->armcorebase); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2940 | |
| 2941 | /* Allow HT Clock now that the ARM is running. */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2942 | bus->alp_only = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2943 | |
| 2944 | bus->dhd->busstate = DHD_BUS_LOAD; |
| 2945 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2946 | fail: |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2947 | return bcmerror; |
| 2948 | } |
| 2949 | |
| 2950 | int |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2951 | brcmf_sdbrcm_bus_iovar_op(dhd_pub_t *dhdp, const char *name, |
| 2952 | void *params, int plen, void *arg, int len, bool set) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2953 | { |
| 2954 | dhd_bus_t *bus = dhdp->bus; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2955 | const struct brcmu_iovar *vi = NULL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2956 | int bcmerror = 0; |
| 2957 | int val_size; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2958 | u32 actionid; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2959 | |
| 2960 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 2961 | |
| 2962 | ASSERT(name); |
| 2963 | ASSERT(len >= 0); |
| 2964 | |
| 2965 | /* Get MUST have return space */ |
| 2966 | ASSERT(set || (arg && len)); |
| 2967 | |
| 2968 | /* Set does NOT take qualifiers */ |
| 2969 | ASSERT(!set || (!params && !plen)); |
| 2970 | |
| 2971 | /* Look up var locally; if not found pass to host driver */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2972 | vi = brcmu_iovar_lookup(dhdsdio_iovars, name); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2973 | if (vi == NULL) { |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 2974 | brcmf_sdbrcm_sdlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2975 | |
| 2976 | BUS_WAKE(bus); |
| 2977 | |
| 2978 | /* Turn on clock in case SD command needs backplane */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2979 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2980 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2981 | bcmerror = brcmf_sdcard_iovar_op(bus->sdh, name, params, plen, |
| 2982 | arg, len, set); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2983 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2984 | /* Similar check for blocksize change */ |
| 2985 | if (set && strcmp(name, "sd_blocksize") == 0) { |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2986 | s32 fnum = 2; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 2987 | if (brcmf_sdcard_iovar_op |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2988 | (bus->sdh, "sd_blocksize", &fnum, sizeof(s32), |
| 2989 | &bus->blocksize, sizeof(s32), |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 2990 | false) != 0) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2991 | bus->blocksize = 0; |
| 2992 | DHD_ERROR(("%s: fail on %s get\n", __func__, |
| 2993 | "sd_blocksize")); |
| 2994 | } else { |
| 2995 | DHD_INFO(("%s: noted %s update, value now %d\n", |
| 2996 | __func__, "sd_blocksize", |
| 2997 | bus->blocksize)); |
| 2998 | } |
| 2999 | } |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 3000 | bus->roundup = min(max_roundup, bus->blocksize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3001 | |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 3002 | if (bus->idletime == BRCMF_IDLE_IMMEDIATE && |
| 3003 | !bus->dpc_sched) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3004 | bus->activity = false; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3005 | brcmf_sdbrcm_clkctl(bus, CLK_NONE, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3006 | } |
| 3007 | |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 3008 | brcmf_sdbrcm_sdunlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3009 | goto exit; |
| 3010 | } |
| 3011 | |
| 3012 | DHD_CTL(("%s: %s %s, len %d plen %d\n", __func__, |
| 3013 | name, (set ? "set" : "get"), len, plen)); |
| 3014 | |
| 3015 | /* set up 'params' pointer in case this is a set command so that |
| 3016 | * the convenience int and bool code can be common to set and get |
| 3017 | */ |
| 3018 | if (params == NULL) { |
| 3019 | params = arg; |
| 3020 | plen = len; |
| 3021 | } |
| 3022 | |
| 3023 | if (vi->type == IOVT_VOID) |
| 3024 | val_size = 0; |
| 3025 | else if (vi->type == IOVT_BUFFER) |
| 3026 | val_size = len; |
| 3027 | else |
| 3028 | /* all other types are integer sized */ |
| 3029 | val_size = sizeof(int); |
| 3030 | |
| 3031 | actionid = set ? IOV_SVAL(vi->varid) : IOV_GVAL(vi->varid); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3032 | bcmerror = brcmf_sdbrcm_doiovar(bus, vi, actionid, name, params, plen, |
| 3033 | arg, len, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3034 | |
| 3035 | exit: |
| 3036 | return bcmerror; |
| 3037 | } |
| 3038 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3039 | void brcmf_sdbrcm_bus_stop(struct dhd_bus *bus, bool enforce_mutex) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3040 | { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 3041 | u32 local_hostintmask; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3042 | u8 saveclk; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3043 | uint retries; |
| 3044 | int err; |
| 3045 | |
| 3046 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 3047 | |
| 3048 | if (enforce_mutex) |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 3049 | brcmf_sdbrcm_sdlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3050 | |
| 3051 | BUS_WAKE(bus); |
| 3052 | |
| 3053 | /* Enable clock for device interrupts */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3054 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3055 | |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 3056 | if (bus->watchdog_tsk) { |
| 3057 | send_sig(SIGTERM, bus->watchdog_tsk, 1); |
| 3058 | kthread_stop(bus->watchdog_tsk); |
| 3059 | bus->watchdog_tsk = NULL; |
| 3060 | } |
| 3061 | |
Franky Lin | 0827888 | 2011-06-29 16:47:45 -0700 | [diff] [blame] | 3062 | if (bus->dpc_tsk) { |
| 3063 | send_sig(SIGTERM, bus->dpc_tsk, 1); |
| 3064 | kthread_stop(bus->dpc_tsk); |
| 3065 | bus->dpc_tsk = NULL; |
| 3066 | } else |
| 3067 | tasklet_kill(&bus->tasklet); |
| 3068 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3069 | /* Disable and clear interrupts at the chip level also */ |
| 3070 | W_SDREG(0, &bus->regs->hostintmask, retries); |
| 3071 | local_hostintmask = bus->hostintmask; |
| 3072 | bus->hostintmask = 0; |
| 3073 | |
| 3074 | /* Change our idea of bus state */ |
| 3075 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 3076 | |
| 3077 | /* Force clocks on backplane to be sure F2 interrupt propagates */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3078 | saveclk = brcmf_sdcard_cfg_read(bus->sdh, SDIO_FUNC_1, |
| 3079 | SBSDIO_FUNC1_CHIPCLKCSR, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3080 | if (!err) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3081 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_1, |
| 3082 | SBSDIO_FUNC1_CHIPCLKCSR, |
| 3083 | (saveclk | SBSDIO_FORCE_HT), &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3084 | } |
| 3085 | if (err) { |
| 3086 | DHD_ERROR(("%s: Failed to force clock for F2: err %d\n", |
| 3087 | __func__, err)); |
| 3088 | } |
| 3089 | |
| 3090 | /* Turn off the bus (F2), free any pending packets */ |
| 3091 | DHD_INTR(("%s: disable SDIO interrupts\n", __func__)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3092 | brcmf_sdcard_intr_disable(bus->sdh); |
| 3093 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_0, SDIO_CCCR_IOEx, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3094 | SDIO_FUNC_ENABLE_1, NULL); |
| 3095 | |
| 3096 | /* Clear any pending interrupts now that F2 is disabled */ |
| 3097 | W_SDREG(local_hostintmask, &bus->regs->intstatus, retries); |
| 3098 | |
| 3099 | /* Turn off the backplane clock (only) */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3100 | brcmf_sdbrcm_clkctl(bus, CLK_SDONLY, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3101 | |
| 3102 | /* Clear the data packet queues */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3103 | brcmu_pktq_flush(&bus->txq, true, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3104 | |
| 3105 | /* Clear any held glomming stuff */ |
| 3106 | if (bus->glomd) |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3107 | brcmu_pkt_buf_free_skb(bus->glomd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3108 | |
| 3109 | if (bus->glom) |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3110 | brcmu_pkt_buf_free_skb(bus->glom); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3111 | |
| 3112 | bus->glom = bus->glomd = NULL; |
| 3113 | |
| 3114 | /* Clear rx control and wake any waiters */ |
| 3115 | bus->rxlen = 0; |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 3116 | brcmf_os_ioctl_resp_wake(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3117 | |
| 3118 | /* Reset some F2 state stuff */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3119 | bus->rxskip = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3120 | bus->tx_seq = bus->rx_seq = 0; |
| 3121 | |
| 3122 | if (enforce_mutex) |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 3123 | brcmf_sdbrcm_sdunlock(bus); |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 3124 | |
| 3125 | #if defined(OOB_INTR_ONLY) |
| 3126 | brcmf_sdio_unregister_oob_intr(); |
| 3127 | #endif /* defined(OOB_INTR_ONLY) */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3128 | } |
| 3129 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3130 | int brcmf_sdbrcm_bus_init(dhd_pub_t *dhdp, bool enforce_mutex) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3131 | { |
| 3132 | dhd_bus_t *bus = dhdp->bus; |
Arend van Spriel | bb26354 | 2011-06-29 16:47:53 -0700 | [diff] [blame^] | 3133 | struct brcmf_timeout tmo; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3134 | uint retries = 0; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3135 | u8 ready, enable; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3136 | int err, ret = 0; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3137 | u8 saveclk; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3138 | |
| 3139 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 3140 | |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 3141 | /* try to download image and nvram to the dongle */ |
| 3142 | if (dhdp->busstate == DHD_BUS_DOWN) { |
| 3143 | if (!(brcmf_sdbrcm_download_firmware(bus, bus->sdh))) |
| 3144 | return -1; |
| 3145 | } |
| 3146 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3147 | ASSERT(bus->dhd); |
| 3148 | if (!bus->dhd) |
| 3149 | return 0; |
| 3150 | |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 3151 | /* Start the watchdog timer */ |
| 3152 | bus->dhd->tickcnt = 0; |
| 3153 | brcmf_sdbrcm_wd_timer(bus, brcmf_watchdog_ms); |
| 3154 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3155 | if (enforce_mutex) |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 3156 | brcmf_sdbrcm_sdlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3157 | |
| 3158 | /* Make sure backplane clock is on, needed to generate F2 interrupt */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3159 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3160 | if (bus->clkstate != CLK_AVAIL) |
| 3161 | goto exit; |
| 3162 | |
| 3163 | /* Force clocks on backplane to be sure F2 interrupt propagates */ |
| 3164 | saveclk = |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3165 | brcmf_sdcard_cfg_read(bus->sdh, SDIO_FUNC_1, |
| 3166 | SBSDIO_FUNC1_CHIPCLKCSR, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3167 | if (!err) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3168 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_1, |
| 3169 | SBSDIO_FUNC1_CHIPCLKCSR, |
| 3170 | (saveclk | SBSDIO_FORCE_HT), &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3171 | } |
| 3172 | if (err) { |
| 3173 | DHD_ERROR(("%s: Failed to force clock for F2: err %d\n", |
| 3174 | __func__, err)); |
| 3175 | goto exit; |
| 3176 | } |
| 3177 | |
| 3178 | /* Enable function 2 (frame transfers) */ |
| 3179 | W_SDREG((SDPCM_PROT_VERSION << SMB_DATA_VERSION_SHIFT), |
| 3180 | &bus->regs->tosbmailboxdata, retries); |
| 3181 | enable = (SDIO_FUNC_ENABLE_1 | SDIO_FUNC_ENABLE_2); |
| 3182 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3183 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_0, SDIO_CCCR_IOEx, enable, |
| 3184 | NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3185 | |
| 3186 | /* 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] | 3187 | brcmf_timeout_start(&tmo, DHD_WAIT_F2RDY * 1000); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3188 | |
| 3189 | ready = 0; |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 3190 | while (ready != enable && !brcmf_timeout_expired(&tmo)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3191 | ready = |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3192 | brcmf_sdcard_cfg_read(bus->sdh, SDIO_FUNC_0, SDIO_CCCR_IORx, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3193 | NULL); |
| 3194 | |
| 3195 | DHD_INFO(("%s: enable 0x%02x, ready 0x%02x (waited %uus)\n", |
| 3196 | __func__, enable, ready, tmo.elapsed)); |
| 3197 | |
| 3198 | /* If F2 successfully enabled, set core and enable interrupts */ |
| 3199 | if (ready == enable) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3200 | /* Set up the interrupt mask and enable interrupts */ |
| 3201 | bus->hostintmask = HOSTINTMASK; |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 3202 | W_SDREG(bus->hostintmask, |
| 3203 | (unsigned int *)CORE_BUS_REG(bus->ci->buscorebase, |
| 3204 | hostintmask), retries); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3205 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3206 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_WATERMARK, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3207 | (u8) watermark, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3208 | |
| 3209 | /* Set bus state according to enable result */ |
| 3210 | dhdp->busstate = DHD_BUS_DATA; |
| 3211 | |
| 3212 | /* bcmsdh_intr_unmask(bus->sdh); */ |
| 3213 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3214 | bus->intdis = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3215 | if (bus->intr) { |
| 3216 | DHD_INTR(("%s: enable SDIO device interrupts\n", |
| 3217 | __func__)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3218 | brcmf_sdcard_intr_enable(bus->sdh); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3219 | } else { |
| 3220 | DHD_INTR(("%s: disable SDIO interrupts\n", __func__)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3221 | brcmf_sdcard_intr_disable(bus->sdh); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3222 | } |
| 3223 | |
| 3224 | } |
| 3225 | |
| 3226 | else { |
| 3227 | /* Disable F2 again */ |
| 3228 | enable = SDIO_FUNC_ENABLE_1; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3229 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_0, SDIO_CCCR_IOEx, |
| 3230 | enable, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3231 | } |
| 3232 | |
| 3233 | /* Restore previous clock setting */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3234 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3235 | saveclk, &err); |
| 3236 | |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 3237 | #if defined(OOB_INTR_ONLY) |
| 3238 | /* Host registration for OOB interrupt */ |
| 3239 | if (brcmf_sdio_register_oob_intr(bus->dhd)) { |
| 3240 | brcmf_sdbrcm_wd_timer(bus, 0); |
| 3241 | DHD_ERROR(("%s Host failed to resgister for OOB\n", __func__)); |
| 3242 | ret = -ENODEV; |
| 3243 | goto exit; |
| 3244 | } |
| 3245 | |
| 3246 | /* Enable oob at firmware */ |
| 3247 | brcmf_sdbrcm_enable_oob_intr(bus, true); |
| 3248 | #endif /* defined(OOB_INTR_ONLY) */ |
| 3249 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3250 | /* If we didn't come up, turn off backplane clock */ |
| 3251 | if (dhdp->busstate != DHD_BUS_DATA) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3252 | brcmf_sdbrcm_clkctl(bus, CLK_NONE, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3253 | |
| 3254 | exit: |
| 3255 | if (enforce_mutex) |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 3256 | brcmf_sdbrcm_sdunlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3257 | |
| 3258 | return ret; |
| 3259 | } |
| 3260 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3261 | 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] | 3262 | { |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 3263 | struct brcmf_sdio *sdh = bus->sdh; |
Franky Lin | 597600a | 2011-06-01 13:45:39 +0200 | [diff] [blame] | 3264 | struct sdpcmd_regs *regs = bus->regs; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3265 | uint retries = 0; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3266 | u16 lastrbc; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3267 | u8 hi, lo; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3268 | int err; |
| 3269 | |
| 3270 | DHD_ERROR(("%s: %sterminate frame%s\n", __func__, |
| 3271 | (abort ? "abort command, " : ""), |
| 3272 | (rtx ? ", send NAK" : ""))); |
| 3273 | |
| 3274 | if (abort) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3275 | brcmf_sdcard_abort(sdh, SDIO_FUNC_2); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3276 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3277 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_FRAMECTRL, |
| 3278 | SFC_RF_TERM, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3279 | bus->f1regdata++; |
| 3280 | |
| 3281 | /* Wait until the packet has been flushed (device/FIFO stable) */ |
| 3282 | for (lastrbc = retries = 0xffff; retries > 0; retries--) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3283 | hi = brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
| 3284 | SBSDIO_FUNC1_RFRAMEBCHI, NULL); |
| 3285 | lo = brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
| 3286 | SBSDIO_FUNC1_RFRAMEBCLO, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3287 | bus->f1regdata += 2; |
| 3288 | |
| 3289 | if ((hi == 0) && (lo == 0)) |
| 3290 | break; |
| 3291 | |
| 3292 | if ((hi > (lastrbc >> 8)) && (lo > (lastrbc & 0x00ff))) { |
| 3293 | DHD_ERROR(("%s: count growing: last 0x%04x now " |
| 3294 | "0x%04x\n", |
| 3295 | __func__, lastrbc, ((hi << 8) + lo))); |
| 3296 | } |
| 3297 | lastrbc = (hi << 8) + lo; |
| 3298 | } |
| 3299 | |
| 3300 | if (!retries) { |
| 3301 | DHD_ERROR(("%s: count never zeroed: last 0x%04x\n", |
| 3302 | __func__, lastrbc)); |
| 3303 | } else { |
| 3304 | DHD_INFO(("%s: flush took %d iterations\n", __func__, |
| 3305 | (0xffff - retries))); |
| 3306 | } |
| 3307 | |
| 3308 | if (rtx) { |
| 3309 | bus->rxrtx++; |
| 3310 | W_SDREG(SMB_NAK, ®s->tosbmailbox, retries); |
| 3311 | bus->f1regdata++; |
| 3312 | if (retries <= retry_limit) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3313 | bus->rxskip = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3314 | } |
| 3315 | |
| 3316 | /* Clear partial in any case */ |
| 3317 | bus->nextlen = 0; |
| 3318 | |
| 3319 | /* If we can't reach the device, signal failure */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3320 | if (err || brcmf_sdcard_regfail(sdh)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3321 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 3322 | } |
| 3323 | |
| 3324 | static void |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3325 | 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] | 3326 | { |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 3327 | struct brcmf_sdio *sdh = bus->sdh; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3328 | uint rdlen, pad; |
| 3329 | |
| 3330 | int sdret; |
| 3331 | |
| 3332 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 3333 | |
| 3334 | /* Control data already received in aligned rxctl */ |
| 3335 | if ((bus->bus == SPI_BUS) && (!bus->usebufpool)) |
| 3336 | goto gotpkt; |
| 3337 | |
| 3338 | ASSERT(bus->rxbuf); |
| 3339 | /* Set rxctl for frame (w/optional alignment) */ |
| 3340 | bus->rxctl = bus->rxbuf; |
| 3341 | if (dhd_alignctl) { |
| 3342 | bus->rxctl += firstread; |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 3343 | pad = ((unsigned long)bus->rxctl % BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3344 | if (pad) |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 3345 | bus->rxctl += (BRCMF_SDALIGN - pad); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3346 | bus->rxctl -= firstread; |
| 3347 | } |
| 3348 | ASSERT(bus->rxctl >= bus->rxbuf); |
| 3349 | |
| 3350 | /* Copy the already-read portion over */ |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 3351 | memcpy(bus->rxctl, hdr, firstread); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3352 | if (len <= firstread) |
| 3353 | goto gotpkt; |
| 3354 | |
| 3355 | /* Copy the full data pkt in gSPI case and process ioctl. */ |
| 3356 | if (bus->bus == SPI_BUS) { |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 3357 | memcpy(bus->rxctl, hdr, len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3358 | goto gotpkt; |
| 3359 | } |
| 3360 | |
| 3361 | /* Raise rdlen to next SDIO block to avoid tail command */ |
| 3362 | rdlen = len - firstread; |
| 3363 | if (bus->roundup && bus->blocksize && (rdlen > bus->blocksize)) { |
| 3364 | pad = bus->blocksize - (rdlen % bus->blocksize); |
| 3365 | if ((pad <= bus->roundup) && (pad < bus->blocksize) && |
| 3366 | ((len + pad) < bus->dhd->maxctl)) |
| 3367 | rdlen += pad; |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 3368 | } else if (rdlen % BRCMF_SDALIGN) { |
| 3369 | rdlen += BRCMF_SDALIGN - (rdlen % BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3370 | } |
| 3371 | |
| 3372 | /* Satisfy length-alignment requirements */ |
| 3373 | if (forcealign && (rdlen & (ALIGNMENT - 1))) |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 3374 | rdlen = roundup(rdlen, ALIGNMENT); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3375 | |
| 3376 | /* Drop if the read is too big or it exceeds our maximum */ |
| 3377 | if ((rdlen + firstread) > bus->dhd->maxctl) { |
| 3378 | DHD_ERROR(("%s: %d-byte control read exceeds %d-byte buffer\n", |
| 3379 | __func__, rdlen, bus->dhd->maxctl)); |
| 3380 | bus->dhd->rx_errors++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3381 | brcmf_sdbrcm_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3382 | goto done; |
| 3383 | } |
| 3384 | |
| 3385 | if ((len - doff) > bus->dhd->maxctl) { |
| 3386 | DHD_ERROR(("%s: %d-byte ctl frame (%d-byte ctl data) exceeds " |
| 3387 | "%d-byte limit\n", |
| 3388 | __func__, len, (len - doff), bus->dhd->maxctl)); |
| 3389 | bus->dhd->rx_errors++; |
| 3390 | bus->rx_toolong++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3391 | brcmf_sdbrcm_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3392 | goto done; |
| 3393 | } |
| 3394 | |
| 3395 | /* Read remainder of frame body into the rxctl buffer */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3396 | sdret = brcmf_sdcard_recv_buf(sdh, brcmf_sdcard_cur_sbwad(sdh), |
| 3397 | SDIO_FUNC_2, |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 3398 | F2SYNC, (bus->rxctl + firstread), rdlen, |
| 3399 | NULL, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3400 | bus->f2rxdata++; |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 3401 | ASSERT(sdret != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3402 | |
| 3403 | /* Control frame failures need retransmission */ |
| 3404 | if (sdret < 0) { |
| 3405 | DHD_ERROR(("%s: read %d control bytes failed: %d\n", |
| 3406 | __func__, rdlen, sdret)); |
| 3407 | bus->rxc_errors++; /* dhd.rx_ctlerrs is higher level */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3408 | brcmf_sdbrcm_rxfail(bus, true, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3409 | goto done; |
| 3410 | } |
| 3411 | |
| 3412 | gotpkt: |
| 3413 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 3414 | #ifdef BCMDBG |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 3415 | if (DHD_BYTES_ON() && DHD_CTL_ON()) { |
| 3416 | printk(KERN_DEBUG "RxCtrl:\n"); |
| 3417 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, bus->rxctl, len); |
| 3418 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3419 | #endif |
| 3420 | |
| 3421 | /* Point to valid data and indicate its length */ |
| 3422 | bus->rxctl += doff; |
| 3423 | bus->rxlen = len - doff; |
| 3424 | |
| 3425 | done: |
| 3426 | /* Awake any waiters */ |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 3427 | brcmf_os_ioctl_resp_wake(bus->dhd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3428 | } |
| 3429 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3430 | static u8 brcmf_sdbrcm_rxglom(dhd_bus_t *bus, u8 rxseq) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3431 | { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3432 | u16 dlen, totlen; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3433 | u8 *dptr, num = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3434 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3435 | u16 sublen, check; |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 3436 | struct sk_buff *pfirst, *plast, *pnext, *save_pfirst; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3437 | |
| 3438 | int errcode; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3439 | u8 chan, seq, doff, sfdoff; |
| 3440 | u8 txmax; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3441 | |
| 3442 | int ifidx = 0; |
| 3443 | bool usechain = bus->use_rxchain; |
| 3444 | |
| 3445 | /* If packets, issue read(s) and send up packet chain */ |
| 3446 | /* Return sequence numbers consumed? */ |
| 3447 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3448 | 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] | 3449 | bus->glom)); |
| 3450 | |
| 3451 | /* If there's a descriptor, generate the packet chain */ |
| 3452 | if (bus->glomd) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3453 | pfirst = plast = pnext = NULL; |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3454 | dlen = (u16) (bus->glomd->len); |
| 3455 | dptr = bus->glomd->data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3456 | if (!dlen || (dlen & 1)) { |
| 3457 | DHD_ERROR(("%s: bad glomd len(%d), ignore descriptor\n", |
| 3458 | __func__, dlen)); |
| 3459 | dlen = 0; |
| 3460 | } |
| 3461 | |
| 3462 | for (totlen = num = 0; dlen; num++) { |
| 3463 | /* Get (and move past) next length */ |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 3464 | sublen = get_unaligned_le16(dptr); |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3465 | dlen -= sizeof(u16); |
| 3466 | dptr += sizeof(u16); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3467 | if ((sublen < SDPCM_HDRLEN) || |
| 3468 | ((num == 0) && (sublen < (2 * SDPCM_HDRLEN)))) { |
| 3469 | DHD_ERROR(("%s: descriptor len %d bad: %d\n", |
| 3470 | __func__, num, sublen)); |
| 3471 | pnext = NULL; |
| 3472 | break; |
| 3473 | } |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 3474 | if (sublen % BRCMF_SDALIGN) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3475 | DHD_ERROR(("%s: sublen %d not multiple of %d\n", |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 3476 | __func__, sublen, BRCMF_SDALIGN)); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3477 | usechain = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3478 | } |
| 3479 | totlen += sublen; |
| 3480 | |
| 3481 | /* For last frame, adjust read len so total |
| 3482 | is a block multiple */ |
| 3483 | if (!dlen) { |
| 3484 | sublen += |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 3485 | (roundup(totlen, bus->blocksize) - totlen); |
| 3486 | totlen = roundup(totlen, bus->blocksize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3487 | } |
| 3488 | |
| 3489 | /* Allocate/chain packet for next subframe */ |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 3490 | pnext = brcmu_pkt_buf_get_skb(sublen + BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3491 | if (pnext == NULL) { |
Henry Ptasinski | b33f0e2 | 2011-05-10 22:25:29 +0200 | [diff] [blame] | 3492 | DHD_ERROR(("%s: bcm_pkt_buf_get_skb failed, " |
| 3493 | "num %d len %d\n", __func__, |
| 3494 | num, sublen)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3495 | break; |
| 3496 | } |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3497 | ASSERT(!(pnext->prev)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3498 | if (!pfirst) { |
| 3499 | ASSERT(!plast); |
| 3500 | pfirst = plast = pnext; |
| 3501 | } else { |
| 3502 | ASSERT(plast); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3503 | plast->next = pnext; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3504 | plast = pnext; |
| 3505 | } |
| 3506 | |
| 3507 | /* Adhere to start alignment requirements */ |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 3508 | PKTALIGN(pnext, sublen, BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3509 | } |
| 3510 | |
| 3511 | /* If all allocations succeeded, save packet chain |
| 3512 | in bus structure */ |
| 3513 | if (pnext) { |
| 3514 | DHD_GLOM(("%s: allocated %d-byte packet chain for %d " |
| 3515 | "subframes\n", __func__, totlen, num)); |
| 3516 | if (DHD_GLOM_ON() && bus->nextlen) { |
| 3517 | if (totlen != bus->nextlen) { |
| 3518 | DHD_GLOM(("%s: glomdesc mismatch: nextlen %d glomdesc %d " "rxseq %d\n", |
| 3519 | __func__, bus->nextlen, |
| 3520 | totlen, rxseq)); |
| 3521 | } |
| 3522 | } |
| 3523 | bus->glom = pfirst; |
| 3524 | pfirst = pnext = NULL; |
| 3525 | } else { |
| 3526 | if (pfirst) |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3527 | brcmu_pkt_buf_free_skb(pfirst); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3528 | bus->glom = NULL; |
| 3529 | num = 0; |
| 3530 | } |
| 3531 | |
| 3532 | /* Done with descriptor packet */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3533 | brcmu_pkt_buf_free_skb(bus->glomd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3534 | bus->glomd = NULL; |
| 3535 | bus->nextlen = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3536 | } |
| 3537 | |
| 3538 | /* Ok -- either we just generated a packet chain, |
| 3539 | or had one from before */ |
| 3540 | if (bus->glom) { |
| 3541 | if (DHD_GLOM_ON()) { |
| 3542 | DHD_GLOM(("%s: try superframe read, packet chain:\n", |
| 3543 | __func__)); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3544 | for (pnext = bus->glom; pnext; pnext = pnext->next) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3545 | DHD_GLOM((" %p: %p len 0x%04x (%d)\n", |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3546 | pnext, (u8 *) (pnext->data), |
| 3547 | pnext->len, pnext->len)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3548 | } |
| 3549 | } |
| 3550 | |
| 3551 | pfirst = bus->glom; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3552 | dlen = (u16) brcmu_pkttotlen(pfirst); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3553 | |
| 3554 | /* Do an SDIO read for the superframe. Configurable iovar to |
| 3555 | * read directly into the chained packet, or allocate a large |
| 3556 | * packet and and copy into the chain. |
| 3557 | */ |
| 3558 | if (usechain) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3559 | errcode = brcmf_sdcard_recv_buf(bus->sdh, |
| 3560 | brcmf_sdcard_cur_sbwad(bus->sdh), |
| 3561 | SDIO_FUNC_2, |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 3562 | F2SYNC, (u8 *) pfirst->data, dlen, |
| 3563 | pfirst, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3564 | } else if (bus->dataptr) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3565 | errcode = brcmf_sdcard_recv_buf(bus->sdh, |
| 3566 | brcmf_sdcard_cur_sbwad(bus->sdh), |
| 3567 | SDIO_FUNC_2, |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 3568 | F2SYNC, bus->dataptr, dlen, |
| 3569 | NULL, NULL, NULL); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3570 | sublen = (u16) brcmu_pktfrombuf(pfirst, 0, dlen, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3571 | bus->dataptr); |
| 3572 | if (sublen != dlen) { |
| 3573 | DHD_ERROR(("%s: FAILED TO COPY, dlen %d sublen %d\n", |
| 3574 | __func__, dlen, sublen)); |
| 3575 | errcode = -1; |
| 3576 | } |
| 3577 | pnext = NULL; |
| 3578 | } else { |
| 3579 | DHD_ERROR(("COULDN'T ALLOC %d-BYTE GLOM, FORCE FAILURE\n", |
| 3580 | dlen)); |
| 3581 | errcode = -1; |
| 3582 | } |
| 3583 | bus->f2rxdata++; |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 3584 | ASSERT(errcode != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3585 | |
| 3586 | /* On failure, kill the superframe, allow a couple retries */ |
| 3587 | if (errcode < 0) { |
| 3588 | DHD_ERROR(("%s: glom read of %d bytes failed: %d\n", |
| 3589 | __func__, dlen, errcode)); |
| 3590 | bus->dhd->rx_errors++; |
| 3591 | |
| 3592 | if (bus->glomerr++ < 3) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3593 | brcmf_sdbrcm_rxfail(bus, true, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3594 | } else { |
| 3595 | bus->glomerr = 0; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3596 | brcmf_sdbrcm_rxfail(bus, true, false); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3597 | brcmu_pkt_buf_free_skb(bus->glom); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3598 | bus->rxglomfail++; |
| 3599 | bus->glom = NULL; |
| 3600 | } |
| 3601 | return 0; |
| 3602 | } |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 3603 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3604 | if (DHD_GLOM_ON()) { |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 3605 | printk(KERN_DEBUG "SUPERFRAME:\n"); |
| 3606 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 3607 | pfirst->data, min_t(int, pfirst->len, 48)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3608 | } |
| 3609 | #endif |
| 3610 | |
| 3611 | /* Validate the superframe header */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3612 | dptr = (u8 *) (pfirst->data); |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 3613 | sublen = get_unaligned_le16(dptr); |
| 3614 | check = get_unaligned_le16(dptr + sizeof(u16)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3615 | |
| 3616 | chan = SDPCM_PACKET_CHANNEL(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3617 | seq = SDPCM_PACKET_SEQUENCE(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3618 | bus->nextlen = dptr[SDPCM_FRAMETAG_LEN + SDPCM_NEXTLEN_OFFSET]; |
| 3619 | if ((bus->nextlen << 4) > MAX_RX_DATASZ) { |
| 3620 | DHD_INFO(("%s: nextlen too large (%d) seq %d\n", |
| 3621 | __func__, bus->nextlen, seq)); |
| 3622 | bus->nextlen = 0; |
| 3623 | } |
| 3624 | doff = SDPCM_DOFFSET_VALUE(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3625 | txmax = SDPCM_WINDOW_VALUE(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3626 | |
| 3627 | errcode = 0; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3628 | if ((u16)~(sublen ^ check)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3629 | DHD_ERROR(("%s (superframe): HW hdr error: len/check " |
| 3630 | "0x%04x/0x%04x\n", __func__, sublen, check)); |
| 3631 | errcode = -1; |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 3632 | } else if (roundup(sublen, bus->blocksize) != dlen) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3633 | DHD_ERROR(("%s (superframe): len 0x%04x, rounded " |
| 3634 | "0x%04x, expect 0x%04x\n", |
| 3635 | __func__, sublen, |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 3636 | roundup(sublen, bus->blocksize), dlen)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3637 | errcode = -1; |
| 3638 | } else if (SDPCM_PACKET_CHANNEL(&dptr[SDPCM_FRAMETAG_LEN]) != |
| 3639 | SDPCM_GLOM_CHANNEL) { |
| 3640 | DHD_ERROR(("%s (superframe): bad channel %d\n", |
| 3641 | __func__, |
| 3642 | SDPCM_PACKET_CHANNEL(&dptr |
| 3643 | [SDPCM_FRAMETAG_LEN]))); |
| 3644 | errcode = -1; |
| 3645 | } else if (SDPCM_GLOMDESC(&dptr[SDPCM_FRAMETAG_LEN])) { |
| 3646 | DHD_ERROR(("%s (superframe): got second descriptor?\n", |
| 3647 | __func__)); |
| 3648 | errcode = -1; |
| 3649 | } else if ((doff < SDPCM_HDRLEN) || |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3650 | (doff > (pfirst->len - SDPCM_HDRLEN))) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3651 | DHD_ERROR(("%s (superframe): Bad data offset %d: HW %d " |
| 3652 | "pkt %d min %d\n", |
| 3653 | __func__, doff, sublen, |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3654 | pfirst->len, SDPCM_HDRLEN)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3655 | errcode = -1; |
| 3656 | } |
| 3657 | |
| 3658 | /* Check sequence number of superframe SW header */ |
| 3659 | if (rxseq != seq) { |
| 3660 | DHD_INFO(("%s: (superframe) rx_seq %d, expected %d\n", |
| 3661 | __func__, seq, rxseq)); |
| 3662 | bus->rx_badseq++; |
| 3663 | rxseq = seq; |
| 3664 | } |
| 3665 | |
| 3666 | /* Check window for sanity */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3667 | if ((u8) (txmax - bus->tx_seq) > 0x40) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3668 | DHD_ERROR(("%s: unlikely tx max %d with tx_seq %d\n", |
| 3669 | __func__, txmax, bus->tx_seq)); |
| 3670 | txmax = bus->tx_seq + 2; |
| 3671 | } |
| 3672 | bus->tx_max = txmax; |
| 3673 | |
| 3674 | /* Remove superframe header, remember offset */ |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 3675 | skb_pull(pfirst, doff); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3676 | sfdoff = doff; |
| 3677 | |
| 3678 | /* Validate all the subframe headers */ |
| 3679 | for (num = 0, pnext = pfirst; pnext && !errcode; |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3680 | num++, pnext = pnext->next) { |
| 3681 | dptr = (u8 *) (pnext->data); |
| 3682 | dlen = (u16) (pnext->len); |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 3683 | sublen = get_unaligned_le16(dptr); |
| 3684 | check = get_unaligned_le16(dptr + sizeof(u16)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3685 | chan = SDPCM_PACKET_CHANNEL(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3686 | doff = SDPCM_DOFFSET_VALUE(&dptr[SDPCM_FRAMETAG_LEN]); |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 3687 | #ifdef BCMDBG |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 3688 | if (DHD_GLOM_ON()) { |
| 3689 | printk(KERN_DEBUG "subframe:\n"); |
| 3690 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 3691 | dptr, 32); |
| 3692 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3693 | #endif |
| 3694 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3695 | if ((u16)~(sublen ^ check)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3696 | DHD_ERROR(("%s (subframe %d): HW hdr error: " |
| 3697 | "len/check 0x%04x/0x%04x\n", |
| 3698 | __func__, num, sublen, check)); |
| 3699 | errcode = -1; |
| 3700 | } else if ((sublen > dlen) || (sublen < SDPCM_HDRLEN)) { |
| 3701 | DHD_ERROR(("%s (subframe %d): length mismatch: " |
| 3702 | "len 0x%04x, expect 0x%04x\n", |
| 3703 | __func__, num, sublen, dlen)); |
| 3704 | errcode = -1; |
| 3705 | } else if ((chan != SDPCM_DATA_CHANNEL) && |
| 3706 | (chan != SDPCM_EVENT_CHANNEL)) { |
| 3707 | DHD_ERROR(("%s (subframe %d): bad channel %d\n", |
| 3708 | __func__, num, chan)); |
| 3709 | errcode = -1; |
| 3710 | } else if ((doff < SDPCM_HDRLEN) || (doff > sublen)) { |
| 3711 | DHD_ERROR(("%s (subframe %d): Bad data offset %d: HW %d min %d\n", |
| 3712 | __func__, num, doff, sublen, |
| 3713 | SDPCM_HDRLEN)); |
| 3714 | errcode = -1; |
| 3715 | } |
| 3716 | } |
| 3717 | |
| 3718 | if (errcode) { |
| 3719 | /* Terminate frame on error, request |
| 3720 | a couple retries */ |
| 3721 | if (bus->glomerr++ < 3) { |
| 3722 | /* Restore superframe header space */ |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 3723 | skb_push(pfirst, sfdoff); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3724 | brcmf_sdbrcm_rxfail(bus, true, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3725 | } else { |
| 3726 | bus->glomerr = 0; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3727 | brcmf_sdbrcm_rxfail(bus, true, false); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3728 | brcmu_pkt_buf_free_skb(bus->glom); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3729 | bus->rxglomfail++; |
| 3730 | bus->glom = NULL; |
| 3731 | } |
| 3732 | bus->nextlen = 0; |
| 3733 | return 0; |
| 3734 | } |
| 3735 | |
| 3736 | /* Basic SD framing looks ok - process each packet (header) */ |
| 3737 | save_pfirst = pfirst; |
| 3738 | bus->glom = NULL; |
| 3739 | plast = NULL; |
| 3740 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3741 | for (num = 0; pfirst; rxseq++, pfirst = pnext) { |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3742 | pnext = pfirst->next; |
| 3743 | pfirst->next = NULL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3744 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3745 | dptr = (u8 *) (pfirst->data); |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 3746 | sublen = get_unaligned_le16(dptr); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3747 | chan = SDPCM_PACKET_CHANNEL(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3748 | seq = SDPCM_PACKET_SEQUENCE(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3749 | doff = SDPCM_DOFFSET_VALUE(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3750 | |
| 3751 | DHD_GLOM(("%s: Get subframe %d, %p(%p/%d), sublen %d " |
| 3752 | "chan %d seq %d\n", |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3753 | __func__, num, pfirst, pfirst->data, |
| 3754 | pfirst->len, sublen, chan, seq)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3755 | |
| 3756 | ASSERT((chan == SDPCM_DATA_CHANNEL) |
| 3757 | || (chan == SDPCM_EVENT_CHANNEL)); |
| 3758 | |
| 3759 | if (rxseq != seq) { |
| 3760 | DHD_GLOM(("%s: rx_seq %d, expected %d\n", |
| 3761 | __func__, seq, rxseq)); |
| 3762 | bus->rx_badseq++; |
| 3763 | rxseq = seq; |
| 3764 | } |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 3765 | #ifdef BCMDBG |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 3766 | if (DHD_BYTES_ON() && DHD_DATA_ON()) { |
| 3767 | printk(KERN_DEBUG "Rx Subframe Data:\n"); |
| 3768 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 3769 | dptr, dlen); |
| 3770 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3771 | #endif |
| 3772 | |
Arend van Spriel | 2cb8ada | 2010-11-18 20:46:44 +0100 | [diff] [blame] | 3773 | __skb_trim(pfirst, sublen); |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 3774 | skb_pull(pfirst, doff); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3775 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3776 | if (pfirst->len == 0) { |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3777 | brcmu_pkt_buf_free_skb(pfirst); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3778 | if (plast) { |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3779 | plast->next = pnext; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3780 | } else { |
| 3781 | ASSERT(save_pfirst == pfirst); |
| 3782 | save_pfirst = pnext; |
| 3783 | } |
| 3784 | continue; |
Arend van Spriel | 0aa94b8 | 2011-06-29 16:47:13 -0700 | [diff] [blame] | 3785 | } else if (brcmf_proto_hdrpull(bus->dhd, &ifidx, pfirst) |
| 3786 | != 0) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3787 | DHD_ERROR(("%s: rx protocol error\n", |
| 3788 | __func__)); |
| 3789 | bus->dhd->rx_errors++; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3790 | brcmu_pkt_buf_free_skb(pfirst); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3791 | if (plast) { |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3792 | plast->next = pnext; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3793 | } else { |
| 3794 | ASSERT(save_pfirst == pfirst); |
| 3795 | save_pfirst = pnext; |
| 3796 | } |
| 3797 | continue; |
| 3798 | } |
| 3799 | |
| 3800 | /* this packet will go up, link back into |
| 3801 | chain and count it */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3802 | pfirst->next = pnext; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3803 | plast = pfirst; |
| 3804 | num++; |
| 3805 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 3806 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3807 | if (DHD_GLOM_ON()) { |
| 3808 | DHD_GLOM(("%s subframe %d to stack, %p(%p/%d) " |
| 3809 | "nxt/lnk %p/%p\n", |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3810 | __func__, num, pfirst, pfirst->data, |
| 3811 | pfirst->len, pfirst->next, |
| 3812 | pfirst->prev)); |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 3813 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 3814 | pfirst->data, |
| 3815 | min_t(int, pfirst->len, 32)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3816 | } |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 3817 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3818 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3819 | if (num) { |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 3820 | brcmf_sdbrcm_sdunlock(bus); |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 3821 | brcmf_rx_frame(bus->dhd, ifidx, save_pfirst, num); |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 3822 | brcmf_sdbrcm_sdlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3823 | } |
| 3824 | |
| 3825 | bus->rxglomframes++; |
| 3826 | bus->rxglompkts += num; |
| 3827 | } |
| 3828 | return num; |
| 3829 | } |
| 3830 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3831 | /* Return true if there may be more frames to read */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3832 | static uint |
| 3833 | brcmf_sdbrcm_readframes(dhd_bus_t *bus, uint maxframes, bool *finished) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3834 | { |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 3835 | struct brcmf_sdio *sdh = bus->sdh; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3836 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3837 | u16 len, check; /* Extracted hardware header fields */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3838 | u8 chan, seq, doff; /* Extracted software header fields */ |
| 3839 | u8 fcbits; /* Extracted fcbits from software header */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3840 | |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 3841 | struct sk_buff *pkt; /* Packet for event or data frames */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3842 | u16 pad; /* Number of pad bytes to read */ |
| 3843 | u16 rdlen; /* Total number of bytes to read */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3844 | u8 rxseq; /* Next sequence number to expect */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3845 | uint rxleft = 0; /* Remaining number of frames allowed */ |
| 3846 | int sdret; /* Return code from bcmsdh calls */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3847 | u8 txmax; /* Maximum tx sequence offered */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3848 | bool len_consistent; /* Result of comparing readahead len and |
| 3849 | len from hw-hdr */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3850 | u8 *rxbuf; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3851 | int ifidx = 0; |
| 3852 | uint rxcount = 0; /* Total frames read */ |
| 3853 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 3854 | #if defined(BCMDBG) || defined(SDTEST) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3855 | bool sdtest = false; /* To limit message spew from test mode */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3856 | #endif |
| 3857 | |
| 3858 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 3859 | |
| 3860 | ASSERT(maxframes); |
| 3861 | |
| 3862 | #ifdef SDTEST |
| 3863 | /* Allow pktgen to override maxframes */ |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 3864 | if (bus->pktgen_count && (bus->pktgen_mode == BRCMF_PKTGEN_RECV)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3865 | maxframes = bus->pktgen_count; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3866 | sdtest = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3867 | } |
| 3868 | #endif |
| 3869 | |
| 3870 | /* Not finished unless we encounter no more frames indication */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3871 | *finished = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3872 | |
| 3873 | for (rxseq = bus->rx_seq, rxleft = maxframes; |
| 3874 | !bus->rxskip && rxleft && bus->dhd->busstate != DHD_BUS_DOWN; |
| 3875 | rxseq++, rxleft--) { |
| 3876 | |
| 3877 | /* Handle glomming separately */ |
| 3878 | if (bus->glom || bus->glomd) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3879 | u8 cnt; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3880 | DHD_GLOM(("%s: calling rxglom: glomd %p, glom %p\n", |
| 3881 | __func__, bus->glomd, bus->glom)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3882 | cnt = brcmf_sdbrcm_rxglom(bus, rxseq); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3883 | DHD_GLOM(("%s: rxglom returned %d\n", __func__, cnt)); |
| 3884 | rxseq += cnt - 1; |
| 3885 | rxleft = (rxleft > cnt) ? (rxleft - cnt) : 1; |
| 3886 | continue; |
| 3887 | } |
| 3888 | |
| 3889 | /* Try doing single read if we can */ |
| 3890 | if (dhd_readahead && bus->nextlen) { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3891 | u16 nextlen = bus->nextlen; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3892 | bus->nextlen = 0; |
| 3893 | |
| 3894 | if (bus->bus == SPI_BUS) { |
| 3895 | rdlen = len = nextlen; |
| 3896 | } else { |
| 3897 | rdlen = len = nextlen << 4; |
| 3898 | |
| 3899 | /* Pad read to blocksize for efficiency */ |
| 3900 | if (bus->roundup && bus->blocksize |
| 3901 | && (rdlen > bus->blocksize)) { |
| 3902 | pad = |
| 3903 | bus->blocksize - |
| 3904 | (rdlen % bus->blocksize); |
| 3905 | if ((pad <= bus->roundup) |
| 3906 | && (pad < bus->blocksize) |
| 3907 | && ((rdlen + pad + firstread) < |
| 3908 | MAX_RX_DATASZ)) |
| 3909 | rdlen += pad; |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 3910 | } else if (rdlen % BRCMF_SDALIGN) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3911 | rdlen += |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 3912 | BRCMF_SDALIGN - (rdlen % BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3913 | } |
| 3914 | } |
| 3915 | |
| 3916 | /* We use bus->rxctl buffer in WinXP for initial |
| 3917 | * control pkt receives. |
| 3918 | * Later we use buffer-poll for data as well |
| 3919 | * as control packets. |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3920 | * This is required because dhd receives full |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3921 | * frame in gSPI unlike SDIO. |
| 3922 | * After the frame is received we have to |
| 3923 | * distinguish whether it is data |
| 3924 | * or non-data frame. |
| 3925 | */ |
| 3926 | /* Allocate a packet buffer */ |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 3927 | pkt = brcmu_pkt_buf_get_skb(rdlen + BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3928 | if (!pkt) { |
| 3929 | if (bus->bus == SPI_BUS) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3930 | bus->usebufpool = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3931 | bus->rxctl = bus->rxbuf; |
| 3932 | if (dhd_alignctl) { |
| 3933 | bus->rxctl += firstread; |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 3934 | pad = ((unsigned long)bus->rxctl % |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 3935 | BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3936 | if (pad) |
| 3937 | bus->rxctl += |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 3938 | (BRCMF_SDALIGN - pad); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3939 | bus->rxctl -= firstread; |
| 3940 | } |
| 3941 | ASSERT(bus->rxctl >= bus->rxbuf); |
| 3942 | rxbuf = bus->rxctl; |
| 3943 | /* Read the entire frame */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3944 | sdret = brcmf_sdcard_recv_buf(sdh, |
| 3945 | brcmf_sdcard_cur_sbwad(sdh), |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 3946 | SDIO_FUNC_2, F2SYNC, |
| 3947 | rxbuf, rdlen, |
| 3948 | NULL, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3949 | bus->f2rxdata++; |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 3950 | ASSERT(sdret != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3951 | |
| 3952 | /* Control frame failures need |
| 3953 | retransmission */ |
| 3954 | if (sdret < 0) { |
| 3955 | DHD_ERROR(("%s: read %d control bytes failed: %d\n", |
| 3956 | __func__, |
| 3957 | rdlen, sdret)); |
| 3958 | /* dhd.rx_ctlerrs is higher */ |
| 3959 | bus->rxc_errors++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3960 | brcmf_sdbrcm_rxfail(bus, true, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3961 | (bus->bus == |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3962 | SPI_BUS) ? false |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3963 | : true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3964 | continue; |
| 3965 | } |
| 3966 | } else { |
| 3967 | /* Give up on data, |
| 3968 | request rtx of events */ |
Arend van Spriel | cda64a5 | 2011-05-10 22:25:33 +0200 | [diff] [blame] | 3969 | DHD_ERROR(("%s (nextlen): " |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3970 | "brcmu_pkt_buf_get_skb " |
| 3971 | "failed:" |
Arend van Spriel | cda64a5 | 2011-05-10 22:25:33 +0200 | [diff] [blame] | 3972 | " len %d rdlen %d expected" |
| 3973 | " rxseq %d\n", __func__, |
| 3974 | len, rdlen, rxseq)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3975 | continue; |
| 3976 | } |
| 3977 | } else { |
| 3978 | if (bus->bus == SPI_BUS) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3979 | bus->usebufpool = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3980 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3981 | ASSERT(!(pkt->prev)); |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 3982 | PKTALIGN(pkt, rdlen, BRCMF_SDALIGN); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3983 | rxbuf = (u8 *) (pkt->data); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3984 | /* Read the entire frame */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 3985 | sdret = brcmf_sdcard_recv_buf(sdh, |
| 3986 | brcmf_sdcard_cur_sbwad(sdh), |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3987 | SDIO_FUNC_2, F2SYNC, |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 3988 | rxbuf, rdlen, |
| 3989 | pkt, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3990 | bus->f2rxdata++; |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 3991 | ASSERT(sdret != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3992 | |
| 3993 | if (sdret < 0) { |
| 3994 | DHD_ERROR(("%s (nextlen): read %d bytes failed: %d\n", |
| 3995 | __func__, rdlen, sdret)); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3996 | brcmu_pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3997 | bus->dhd->rx_errors++; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3998 | /* Force retry w/normal header read. |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3999 | * Don't attempt NAK for |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4000 | * gSPI |
| 4001 | */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4002 | brcmf_sdbrcm_rxfail(bus, true, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4003 | (bus->bus == |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4004 | SPI_BUS) ? false : |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4005 | true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4006 | continue; |
| 4007 | } |
| 4008 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4009 | |
| 4010 | /* Now check the header */ |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 4011 | memcpy(bus->rxhdr, rxbuf, SDPCM_HDRLEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4012 | |
| 4013 | /* Extract hardware header fields */ |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 4014 | len = get_unaligned_le16(bus->rxhdr); |
| 4015 | check = get_unaligned_le16(bus->rxhdr + sizeof(u16)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4016 | |
| 4017 | /* All zeros means readahead info was bad */ |
| 4018 | if (!(len | check)) { |
| 4019 | DHD_INFO(("%s (nextlen): read zeros in HW " |
| 4020 | "header???\n", __func__)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4021 | brcmf_sdbrcm_pktfree2(bus, pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4022 | continue; |
| 4023 | } |
| 4024 | |
| 4025 | /* Validate check bytes */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4026 | if ((u16)~(len ^ check)) { |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4027 | DHD_ERROR(("%s (nextlen): HW hdr error:" |
| 4028 | " nextlen/len/check" |
| 4029 | " 0x%04x/0x%04x/0x%04x\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4030 | __func__, nextlen, len, check)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4031 | bus->rx_badhdr++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4032 | brcmf_sdbrcm_rxfail(bus, false, false); |
| 4033 | brcmf_sdbrcm_pktfree2(bus, pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4034 | continue; |
| 4035 | } |
| 4036 | |
| 4037 | /* Validate frame length */ |
| 4038 | if (len < SDPCM_HDRLEN) { |
| 4039 | DHD_ERROR(("%s (nextlen): HW hdr length " |
| 4040 | "invalid: %d\n", __func__, len)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4041 | brcmf_sdbrcm_pktfree2(bus, pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4042 | continue; |
| 4043 | } |
| 4044 | |
| 4045 | /* Check for consistency withreadahead info */ |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 4046 | len_consistent = (nextlen != (roundup(len, 16) >> 4)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4047 | if (len_consistent) { |
| 4048 | /* Mismatch, force retry w/normal |
| 4049 | header (may be >4K) */ |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4050 | DHD_ERROR(("%s (nextlen): mismatch, " |
| 4051 | "nextlen %d len %d rnd %d; " |
| 4052 | "expected rxseq %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4053 | __func__, nextlen, |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 4054 | len, roundup(len, 16), rxseq)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4055 | brcmf_sdbrcm_rxfail(bus, true, |
| 4056 | bus->bus != SPI_BUS); |
| 4057 | brcmf_sdbrcm_pktfree2(bus, pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4058 | continue; |
| 4059 | } |
| 4060 | |
| 4061 | /* Extract software header fields */ |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4062 | chan = SDPCM_PACKET_CHANNEL( |
| 4063 | &bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 4064 | seq = SDPCM_PACKET_SEQUENCE( |
| 4065 | &bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 4066 | doff = SDPCM_DOFFSET_VALUE( |
| 4067 | &bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 4068 | txmax = SDPCM_WINDOW_VALUE( |
| 4069 | &bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4070 | |
| 4071 | bus->nextlen = |
| 4072 | bus->rxhdr[SDPCM_FRAMETAG_LEN + |
| 4073 | SDPCM_NEXTLEN_OFFSET]; |
| 4074 | if ((bus->nextlen << 4) > MAX_RX_DATASZ) { |
| 4075 | DHD_INFO(("%s (nextlen): got frame w/nextlen too large" " (%d), seq %d\n", |
| 4076 | __func__, bus->nextlen, seq)); |
| 4077 | bus->nextlen = 0; |
| 4078 | } |
| 4079 | |
| 4080 | bus->dhd->rx_readahead_cnt++; |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4081 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4082 | /* Handle Flow Control */ |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4083 | fcbits = SDPCM_FCMASK_VALUE( |
| 4084 | &bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4085 | |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4086 | if (bus->flowcontrol != fcbits) { |
| 4087 | if (~bus->flowcontrol & fcbits) |
| 4088 | bus->fc_xoff++; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4089 | |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4090 | if (bus->flowcontrol & ~fcbits) |
| 4091 | bus->fc_xon++; |
| 4092 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4093 | bus->fc_rcvd++; |
| 4094 | bus->flowcontrol = fcbits; |
| 4095 | } |
| 4096 | |
| 4097 | /* Check and update sequence number */ |
| 4098 | if (rxseq != seq) { |
| 4099 | DHD_INFO(("%s (nextlen): rx_seq %d, expected " |
| 4100 | "%d\n", __func__, seq, rxseq)); |
| 4101 | bus->rx_badseq++; |
| 4102 | rxseq = seq; |
| 4103 | } |
| 4104 | |
| 4105 | /* Check window for sanity */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4106 | if ((u8) (txmax - bus->tx_seq) > 0x40) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4107 | DHD_ERROR(("%s: got unlikely tx max %d with " |
| 4108 | "tx_seq %d\n", |
| 4109 | __func__, txmax, bus->tx_seq)); |
| 4110 | txmax = bus->tx_seq + 2; |
| 4111 | } |
| 4112 | bus->tx_max = txmax; |
| 4113 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 4114 | #ifdef BCMDBG |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 4115 | if (DHD_BYTES_ON() && DHD_DATA_ON()) { |
| 4116 | printk(KERN_DEBUG "Rx Data:\n"); |
| 4117 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 4118 | rxbuf, len); |
| 4119 | } else if (DHD_HDRS_ON()) { |
| 4120 | printk(KERN_DEBUG "RxHdr:\n"); |
| 4121 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 4122 | bus->rxhdr, SDPCM_HDRLEN); |
| 4123 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4124 | #endif |
| 4125 | |
| 4126 | if (chan == SDPCM_CONTROL_CHANNEL) { |
| 4127 | if (bus->bus == SPI_BUS) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4128 | brcmf_sdbrcm_read_control(bus, rxbuf, |
| 4129 | len, doff); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4130 | } else { |
| 4131 | DHD_ERROR(("%s (nextlen): readahead on control" " packet %d?\n", |
| 4132 | __func__, seq)); |
| 4133 | /* Force retry w/normal header read */ |
| 4134 | bus->nextlen = 0; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4135 | brcmf_sdbrcm_rxfail(bus, false, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4136 | } |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4137 | brcmf_sdbrcm_pktfree2(bus, pkt); |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4138 | continue; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4139 | } |
| 4140 | |
| 4141 | if ((bus->bus == SPI_BUS) && !bus->usebufpool) { |
| 4142 | DHD_ERROR(("Received %d bytes on %d channel. Running out of " "rx pktbuf's or not yet malloced.\n", |
| 4143 | len, chan)); |
| 4144 | continue; |
| 4145 | } |
| 4146 | |
| 4147 | /* Validate data offset */ |
| 4148 | if ((doff < SDPCM_HDRLEN) || (doff > len)) { |
| 4149 | DHD_ERROR(("%s (nextlen): bad data offset %d: HW len %d min %d\n", |
| 4150 | __func__, doff, len, SDPCM_HDRLEN)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4151 | brcmf_sdbrcm_rxfail(bus, false, false); |
| 4152 | brcmf_sdbrcm_pktfree2(bus, pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4153 | continue; |
| 4154 | } |
| 4155 | |
| 4156 | /* All done with this one -- now deliver the packet */ |
| 4157 | goto deliver; |
| 4158 | } |
| 4159 | /* gSPI frames should not be handled in fractions */ |
| 4160 | if (bus->bus == SPI_BUS) |
| 4161 | break; |
| 4162 | |
| 4163 | /* Read frame header (hardware and software) */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4164 | sdret = brcmf_sdcard_recv_buf(sdh, brcmf_sdcard_cur_sbwad(sdh), |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4165 | SDIO_FUNC_2, F2SYNC, bus->rxhdr, firstread, |
| 4166 | NULL, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4167 | bus->f2rxhdrs++; |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 4168 | ASSERT(sdret != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4169 | |
| 4170 | if (sdret < 0) { |
| 4171 | DHD_ERROR(("%s: RXHEADER FAILED: %d\n", __func__, |
| 4172 | sdret)); |
| 4173 | bus->rx_hdrfail++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4174 | brcmf_sdbrcm_rxfail(bus, true, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4175 | continue; |
| 4176 | } |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 4177 | #ifdef BCMDBG |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 4178 | if (DHD_BYTES_ON() || DHD_HDRS_ON()) { |
| 4179 | printk(KERN_DEBUG "RxHdr:\n"); |
| 4180 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 4181 | bus->rxhdr, SDPCM_HDRLEN); |
| 4182 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4183 | #endif |
| 4184 | |
| 4185 | /* Extract hardware header fields */ |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 4186 | len = get_unaligned_le16(bus->rxhdr); |
| 4187 | check = get_unaligned_le16(bus->rxhdr + sizeof(u16)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4188 | |
| 4189 | /* All zeros means no more frames */ |
| 4190 | if (!(len | check)) { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4191 | *finished = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4192 | break; |
| 4193 | } |
| 4194 | |
| 4195 | /* Validate check bytes */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4196 | if ((u16) ~(len ^ check)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4197 | DHD_ERROR(("%s: HW hdr err: len/check 0x%04x/0x%04x\n", |
| 4198 | __func__, len, check)); |
| 4199 | bus->rx_badhdr++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4200 | brcmf_sdbrcm_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4201 | continue; |
| 4202 | } |
| 4203 | |
| 4204 | /* Validate frame length */ |
| 4205 | if (len < SDPCM_HDRLEN) { |
| 4206 | DHD_ERROR(("%s: HW hdr length invalid: %d\n", |
| 4207 | __func__, len)); |
| 4208 | continue; |
| 4209 | } |
| 4210 | |
| 4211 | /* Extract software header fields */ |
| 4212 | chan = SDPCM_PACKET_CHANNEL(&bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 4213 | seq = SDPCM_PACKET_SEQUENCE(&bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 4214 | doff = SDPCM_DOFFSET_VALUE(&bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 4215 | txmax = SDPCM_WINDOW_VALUE(&bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 4216 | |
| 4217 | /* Validate data offset */ |
| 4218 | if ((doff < SDPCM_HDRLEN) || (doff > len)) { |
| 4219 | DHD_ERROR(("%s: Bad data offset %d: HW len %d, min %d " |
| 4220 | "seq %d\n", |
| 4221 | __func__, doff, len, SDPCM_HDRLEN, seq)); |
| 4222 | bus->rx_badhdr++; |
| 4223 | ASSERT(0); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4224 | brcmf_sdbrcm_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4225 | continue; |
| 4226 | } |
| 4227 | |
| 4228 | /* Save the readahead length if there is one */ |
| 4229 | bus->nextlen = |
| 4230 | bus->rxhdr[SDPCM_FRAMETAG_LEN + SDPCM_NEXTLEN_OFFSET]; |
| 4231 | if ((bus->nextlen << 4) > MAX_RX_DATASZ) { |
| 4232 | DHD_INFO(("%s (nextlen): got frame w/nextlen too large " |
| 4233 | "(%d), seq %d\n", |
| 4234 | __func__, bus->nextlen, seq)); |
| 4235 | bus->nextlen = 0; |
| 4236 | } |
| 4237 | |
| 4238 | /* Handle Flow Control */ |
| 4239 | fcbits = SDPCM_FCMASK_VALUE(&bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 4240 | |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4241 | if (bus->flowcontrol != fcbits) { |
| 4242 | if (~bus->flowcontrol & fcbits) |
| 4243 | bus->fc_xoff++; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4244 | |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4245 | if (bus->flowcontrol & ~fcbits) |
| 4246 | bus->fc_xon++; |
| 4247 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4248 | bus->fc_rcvd++; |
| 4249 | bus->flowcontrol = fcbits; |
| 4250 | } |
| 4251 | |
| 4252 | /* Check and update sequence number */ |
| 4253 | if (rxseq != seq) { |
| 4254 | DHD_INFO(("%s: rx_seq %d, expected %d\n", __func__, |
| 4255 | seq, rxseq)); |
| 4256 | bus->rx_badseq++; |
| 4257 | rxseq = seq; |
| 4258 | } |
| 4259 | |
| 4260 | /* Check window for sanity */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4261 | if ((u8) (txmax - bus->tx_seq) > 0x40) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4262 | DHD_ERROR(("%s: unlikely tx max %d with tx_seq %d\n", |
| 4263 | __func__, txmax, bus->tx_seq)); |
| 4264 | txmax = bus->tx_seq + 2; |
| 4265 | } |
| 4266 | bus->tx_max = txmax; |
| 4267 | |
| 4268 | /* Call a separate function for control frames */ |
| 4269 | if (chan == SDPCM_CONTROL_CHANNEL) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4270 | brcmf_sdbrcm_read_control(bus, bus->rxhdr, len, doff); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4271 | continue; |
| 4272 | } |
| 4273 | |
| 4274 | ASSERT((chan == SDPCM_DATA_CHANNEL) |
| 4275 | || (chan == SDPCM_EVENT_CHANNEL) |
| 4276 | || (chan == SDPCM_TEST_CHANNEL) |
| 4277 | || (chan == SDPCM_GLOM_CHANNEL)); |
| 4278 | |
| 4279 | /* Length to read */ |
| 4280 | rdlen = (len > firstread) ? (len - firstread) : 0; |
| 4281 | |
| 4282 | /* May pad read to blocksize for efficiency */ |
| 4283 | if (bus->roundup && bus->blocksize && |
| 4284 | (rdlen > bus->blocksize)) { |
| 4285 | pad = bus->blocksize - (rdlen % bus->blocksize); |
| 4286 | if ((pad <= bus->roundup) && (pad < bus->blocksize) && |
| 4287 | ((rdlen + pad + firstread) < MAX_RX_DATASZ)) |
| 4288 | rdlen += pad; |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 4289 | } else if (rdlen % BRCMF_SDALIGN) { |
| 4290 | rdlen += BRCMF_SDALIGN - (rdlen % BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4291 | } |
| 4292 | |
| 4293 | /* Satisfy length-alignment requirements */ |
| 4294 | if (forcealign && (rdlen & (ALIGNMENT - 1))) |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 4295 | rdlen = roundup(rdlen, ALIGNMENT); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4296 | |
| 4297 | if ((rdlen + firstread) > MAX_RX_DATASZ) { |
| 4298 | /* Too long -- skip this frame */ |
| 4299 | DHD_ERROR(("%s: too long: len %d rdlen %d\n", |
| 4300 | __func__, len, rdlen)); |
| 4301 | bus->dhd->rx_errors++; |
| 4302 | bus->rx_toolong++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4303 | brcmf_sdbrcm_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4304 | continue; |
| 4305 | } |
| 4306 | |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 4307 | pkt = brcmu_pkt_buf_get_skb(rdlen + firstread + BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4308 | if (!pkt) { |
| 4309 | /* Give up on data, request rtx of events */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4310 | DHD_ERROR(("%s: brcmu_pkt_buf_get_skb failed: rdlen %d" |
| 4311 | " chan %d\n", __func__, rdlen, chan)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4312 | bus->dhd->rx_dropped++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4313 | brcmf_sdbrcm_rxfail(bus, false, RETRYCHAN(chan)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4314 | continue; |
| 4315 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4316 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4317 | ASSERT(!(pkt->prev)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4318 | |
| 4319 | /* Leave room for what we already read, and align remainder */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4320 | ASSERT(firstread < pkt->len); |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 4321 | skb_pull(pkt, firstread); |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 4322 | PKTALIGN(pkt, rdlen, BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4323 | |
| 4324 | /* Read the remaining frame data */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4325 | sdret = brcmf_sdcard_recv_buf(sdh, brcmf_sdcard_cur_sbwad(sdh), |
| 4326 | SDIO_FUNC_2, F2SYNC, ((u8 *) (pkt->data)), |
| 4327 | rdlen, pkt, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4328 | bus->f2rxdata++; |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 4329 | ASSERT(sdret != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4330 | |
| 4331 | if (sdret < 0) { |
| 4332 | DHD_ERROR(("%s: read %d %s bytes failed: %d\n", |
| 4333 | __func__, rdlen, |
| 4334 | ((chan == |
| 4335 | SDPCM_EVENT_CHANNEL) ? "event" : ((chan == |
| 4336 | SDPCM_DATA_CHANNEL) |
| 4337 | ? "data" : "test")), |
| 4338 | sdret)); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4339 | brcmu_pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4340 | bus->dhd->rx_errors++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4341 | brcmf_sdbrcm_rxfail(bus, true, RETRYCHAN(chan)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4342 | continue; |
| 4343 | } |
| 4344 | |
| 4345 | /* Copy the already-read portion */ |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 4346 | skb_push(pkt, firstread); |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 4347 | memcpy(pkt->data, bus->rxhdr, firstread); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4348 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 4349 | #ifdef BCMDBG |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 4350 | if (DHD_BYTES_ON() && DHD_DATA_ON()) { |
| 4351 | printk(KERN_DEBUG "Rx Data:\n"); |
| 4352 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 4353 | pkt->data, len); |
| 4354 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4355 | #endif |
| 4356 | |
| 4357 | deliver: |
| 4358 | /* Save superframe descriptor and allocate packet frame */ |
| 4359 | if (chan == SDPCM_GLOM_CHANNEL) { |
| 4360 | if (SDPCM_GLOMDESC(&bus->rxhdr[SDPCM_FRAMETAG_LEN])) { |
| 4361 | DHD_GLOM(("%s: glom descriptor, %d bytes:\n", |
| 4362 | __func__, len)); |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 4363 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4364 | if (DHD_GLOM_ON()) { |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 4365 | printk(KERN_DEBUG "Glom Data:\n"); |
| 4366 | print_hex_dump_bytes("", |
| 4367 | DUMP_PREFIX_OFFSET, |
| 4368 | pkt->data, len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4369 | } |
| 4370 | #endif |
Arend van Spriel | 2cb8ada | 2010-11-18 20:46:44 +0100 | [diff] [blame] | 4371 | __skb_trim(pkt, len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4372 | ASSERT(doff == SDPCM_HDRLEN); |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 4373 | skb_pull(pkt, SDPCM_HDRLEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4374 | bus->glomd = pkt; |
| 4375 | } else { |
| 4376 | DHD_ERROR(("%s: glom superframe w/o " |
| 4377 | "descriptor!\n", __func__)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4378 | brcmf_sdbrcm_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4379 | } |
| 4380 | continue; |
| 4381 | } |
| 4382 | |
| 4383 | /* Fill in packet len and prio, deliver upward */ |
Arend van Spriel | 2cb8ada | 2010-11-18 20:46:44 +0100 | [diff] [blame] | 4384 | __skb_trim(pkt, len); |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 4385 | skb_pull(pkt, doff); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4386 | |
| 4387 | #ifdef SDTEST |
| 4388 | /* Test channel packets are processed separately */ |
| 4389 | if (chan == SDPCM_TEST_CHANNEL) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4390 | brcmf_sdbrcm_checkdied(bus, pkt, seq); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4391 | continue; |
| 4392 | } |
| 4393 | #endif /* SDTEST */ |
| 4394 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4395 | if (pkt->len == 0) { |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4396 | brcmu_pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4397 | continue; |
Arend van Spriel | 0aa94b8 | 2011-06-29 16:47:13 -0700 | [diff] [blame] | 4398 | } else if (brcmf_proto_hdrpull(bus->dhd, &ifidx, pkt) != 0) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4399 | DHD_ERROR(("%s: rx protocol error\n", __func__)); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4400 | brcmu_pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4401 | bus->dhd->rx_errors++; |
| 4402 | continue; |
| 4403 | } |
| 4404 | |
| 4405 | /* Unlock during rx call */ |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 4406 | brcmf_sdbrcm_sdunlock(bus); |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 4407 | brcmf_rx_frame(bus->dhd, ifidx, pkt, 1); |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 4408 | brcmf_sdbrcm_sdlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4409 | } |
| 4410 | rxcount = maxframes - rxleft; |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 4411 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4412 | /* Message if we hit the limit */ |
| 4413 | if (!rxleft && !sdtest) |
| 4414 | DHD_DATA(("%s: hit rx limit of %d frames\n", __func__, |
| 4415 | maxframes)); |
| 4416 | else |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 4417 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4418 | DHD_DATA(("%s: processed %d frames\n", __func__, rxcount)); |
| 4419 | /* Back off rxseq if awaiting rtx, update rx_seq */ |
| 4420 | if (bus->rxskip) |
| 4421 | rxseq--; |
| 4422 | bus->rx_seq = rxseq; |
| 4423 | |
| 4424 | return rxcount; |
| 4425 | } |
| 4426 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4427 | static u32 brcmf_sdbrcm_hostmail(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4428 | { |
Franky Lin | 597600a | 2011-06-01 13:45:39 +0200 | [diff] [blame] | 4429 | struct sdpcmd_regs *regs = bus->regs; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 4430 | u32 intstatus = 0; |
| 4431 | u32 hmb_data; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4432 | u8 fcbits; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4433 | uint retries = 0; |
| 4434 | |
| 4435 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 4436 | |
| 4437 | /* Read mailbox data and ack that we did so */ |
| 4438 | R_SDREG(hmb_data, ®s->tohostmailboxdata, retries); |
| 4439 | if (retries <= retry_limit) |
| 4440 | W_SDREG(SMB_INT_ACK, ®s->tosbmailbox, retries); |
| 4441 | bus->f1regdata += 2; |
| 4442 | |
| 4443 | /* Dongle recomposed rx frames, accept them again */ |
| 4444 | if (hmb_data & HMB_DATA_NAKHANDLED) { |
| 4445 | DHD_INFO(("Dongle reports NAK handled, expect rtx of %d\n", |
| 4446 | bus->rx_seq)); |
| 4447 | if (!bus->rxskip) |
| 4448 | DHD_ERROR(("%s: unexpected NAKHANDLED!\n", __func__)); |
| 4449 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4450 | bus->rxskip = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4451 | intstatus |= I_HMB_FRAME_IND; |
| 4452 | } |
| 4453 | |
| 4454 | /* |
| 4455 | * DEVREADY does not occur with gSPI. |
| 4456 | */ |
| 4457 | if (hmb_data & (HMB_DATA_DEVREADY | HMB_DATA_FWREADY)) { |
| 4458 | bus->sdpcm_ver = |
| 4459 | (hmb_data & HMB_DATA_VERSION_MASK) >> |
| 4460 | HMB_DATA_VERSION_SHIFT; |
| 4461 | if (bus->sdpcm_ver != SDPCM_PROT_VERSION) |
| 4462 | DHD_ERROR(("Version mismatch, dongle reports %d, " |
| 4463 | "expecting %d\n", |
| 4464 | bus->sdpcm_ver, SDPCM_PROT_VERSION)); |
| 4465 | else |
| 4466 | DHD_INFO(("Dongle ready, protocol version %d\n", |
| 4467 | bus->sdpcm_ver)); |
| 4468 | } |
| 4469 | |
| 4470 | /* |
| 4471 | * 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] | 4472 | * method isn't used any more. |
| 4473 | * remaining backward compatible with older dongles. |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4474 | */ |
| 4475 | if (hmb_data & HMB_DATA_FC) { |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4476 | fcbits = (hmb_data & HMB_DATA_FCDATA_MASK) >> |
| 4477 | HMB_DATA_FCDATA_SHIFT; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4478 | |
| 4479 | if (fcbits & ~bus->flowcontrol) |
| 4480 | bus->fc_xoff++; |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4481 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4482 | if (bus->flowcontrol & ~fcbits) |
| 4483 | bus->fc_xon++; |
| 4484 | |
| 4485 | bus->fc_rcvd++; |
| 4486 | bus->flowcontrol = fcbits; |
| 4487 | } |
| 4488 | |
| 4489 | /* Shouldn't be any others */ |
| 4490 | if (hmb_data & ~(HMB_DATA_DEVREADY | |
| 4491 | HMB_DATA_NAKHANDLED | |
| 4492 | HMB_DATA_FC | |
| 4493 | HMB_DATA_FWREADY | |
| 4494 | HMB_DATA_FCDATA_MASK | HMB_DATA_VERSION_MASK)) { |
| 4495 | DHD_ERROR(("Unknown mailbox data content: 0x%02x\n", hmb_data)); |
| 4496 | } |
| 4497 | |
| 4498 | return intstatus; |
| 4499 | } |
| 4500 | |
Franky Lin | 0827888 | 2011-06-29 16:47:45 -0700 | [diff] [blame] | 4501 | static bool brcmf_sdbrcm_dpc(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4502 | { |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 4503 | struct brcmf_sdio *sdh = bus->sdh; |
Franky Lin | 597600a | 2011-06-01 13:45:39 +0200 | [diff] [blame] | 4504 | struct sdpcmd_regs *regs = bus->regs; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 4505 | u32 intstatus, newstatus = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4506 | uint retries = 0; |
Arend van Spriel | 7af9d0c | 2011-06-29 16:47:19 -0700 | [diff] [blame] | 4507 | uint rxlimit = brcmf_rxbound; /* Rx frames to read before resched */ |
| 4508 | uint txlimit = brcmf_txbound; /* Tx frames to send before resched */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4509 | uint framecnt = 0; /* Temporary counter of tx/rx frames */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4510 | bool rxdone = true; /* Flag for no more read data */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4511 | bool resched = false; /* Flag indicating resched wanted */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4512 | |
| 4513 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 4514 | |
| 4515 | /* Start with leftover status bits */ |
| 4516 | intstatus = bus->intstatus; |
| 4517 | |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 4518 | brcmf_sdbrcm_sdlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4519 | |
| 4520 | /* If waiting for HTAVAIL, check status */ |
| 4521 | if (bus->clkstate == CLK_PENDING) { |
| 4522 | int err; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4523 | u8 clkctl, devctl = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4524 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 4525 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4526 | /* Check for inconsistent device control */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4527 | devctl = brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
| 4528 | SBSDIO_DEVICE_CTL, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4529 | if (err) { |
| 4530 | DHD_ERROR(("%s: error reading DEVCTL: %d\n", |
| 4531 | __func__, err)); |
| 4532 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 4533 | } else { |
| 4534 | ASSERT(devctl & SBSDIO_DEVCTL_CA_INT_ONLY); |
| 4535 | } |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 4536 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4537 | |
| 4538 | /* Read CSR, if clock on switch to AVAIL, else ignore */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4539 | clkctl = brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
| 4540 | SBSDIO_FUNC1_CHIPCLKCSR, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4541 | if (err) { |
| 4542 | DHD_ERROR(("%s: error reading CSR: %d\n", __func__, |
| 4543 | err)); |
| 4544 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 4545 | } |
| 4546 | |
| 4547 | DHD_INFO(("DPC: PENDING, devctl 0x%02x clkctl 0x%02x\n", devctl, |
| 4548 | clkctl)); |
| 4549 | |
| 4550 | if (SBSDIO_HTAV(clkctl)) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4551 | devctl = brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
| 4552 | SBSDIO_DEVICE_CTL, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4553 | if (err) { |
| 4554 | DHD_ERROR(("%s: error reading DEVCTL: %d\n", |
| 4555 | __func__, err)); |
| 4556 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 4557 | } |
| 4558 | devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4559 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, |
| 4560 | SBSDIO_DEVICE_CTL, devctl, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4561 | if (err) { |
| 4562 | DHD_ERROR(("%s: error writing DEVCTL: %d\n", |
| 4563 | __func__, err)); |
| 4564 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 4565 | } |
| 4566 | bus->clkstate = CLK_AVAIL; |
| 4567 | } else { |
| 4568 | goto clkwait; |
| 4569 | } |
| 4570 | } |
| 4571 | |
| 4572 | BUS_WAKE(bus); |
| 4573 | |
| 4574 | /* Make sure backplane clock is on */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4575 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4576 | if (bus->clkstate == CLK_PENDING) |
| 4577 | goto clkwait; |
| 4578 | |
| 4579 | /* Pending interrupt indicates new device status */ |
| 4580 | if (bus->ipend) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4581 | bus->ipend = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4582 | R_SDREG(newstatus, ®s->intstatus, retries); |
| 4583 | bus->f1regdata++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4584 | if (brcmf_sdcard_regfail(bus->sdh)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4585 | newstatus = 0; |
| 4586 | newstatus &= bus->hostintmask; |
| 4587 | bus->fcstate = !!(newstatus & I_HMB_FC_STATE); |
| 4588 | if (newstatus) { |
| 4589 | W_SDREG(newstatus, ®s->intstatus, retries); |
| 4590 | bus->f1regdata++; |
| 4591 | } |
| 4592 | } |
| 4593 | |
| 4594 | /* Merge new bits with previous */ |
| 4595 | intstatus |= newstatus; |
| 4596 | bus->intstatus = 0; |
| 4597 | |
| 4598 | /* Handle flow-control change: read new state in case our ack |
| 4599 | * crossed another change interrupt. If change still set, assume |
| 4600 | * FC ON for safety, let next loop through do the debounce. |
| 4601 | */ |
| 4602 | if (intstatus & I_HMB_FC_CHANGE) { |
| 4603 | intstatus &= ~I_HMB_FC_CHANGE; |
| 4604 | W_SDREG(I_HMB_FC_CHANGE, ®s->intstatus, retries); |
| 4605 | R_SDREG(newstatus, ®s->intstatus, retries); |
| 4606 | bus->f1regdata += 2; |
| 4607 | bus->fcstate = |
| 4608 | !!(newstatus & (I_HMB_FC_STATE | I_HMB_FC_CHANGE)); |
| 4609 | intstatus |= (newstatus & bus->hostintmask); |
| 4610 | } |
| 4611 | |
| 4612 | /* Handle host mailbox indication */ |
| 4613 | if (intstatus & I_HMB_HOST_INT) { |
| 4614 | intstatus &= ~I_HMB_HOST_INT; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4615 | intstatus |= brcmf_sdbrcm_hostmail(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4616 | } |
| 4617 | |
| 4618 | /* Generally don't ask for these, can get CRC errors... */ |
| 4619 | if (intstatus & I_WR_OOSYNC) { |
| 4620 | DHD_ERROR(("Dongle reports WR_OOSYNC\n")); |
| 4621 | intstatus &= ~I_WR_OOSYNC; |
| 4622 | } |
| 4623 | |
| 4624 | if (intstatus & I_RD_OOSYNC) { |
| 4625 | DHD_ERROR(("Dongle reports RD_OOSYNC\n")); |
| 4626 | intstatus &= ~I_RD_OOSYNC; |
| 4627 | } |
| 4628 | |
| 4629 | if (intstatus & I_SBINT) { |
| 4630 | DHD_ERROR(("Dongle reports SBINT\n")); |
| 4631 | intstatus &= ~I_SBINT; |
| 4632 | } |
| 4633 | |
| 4634 | /* Would be active due to wake-wlan in gSPI */ |
| 4635 | if (intstatus & I_CHIPACTIVE) { |
| 4636 | DHD_INFO(("Dongle reports CHIPACTIVE\n")); |
| 4637 | intstatus &= ~I_CHIPACTIVE; |
| 4638 | } |
| 4639 | |
| 4640 | /* Ignore frame indications if rxskip is set */ |
| 4641 | if (bus->rxskip) |
| 4642 | intstatus &= ~I_HMB_FRAME_IND; |
| 4643 | |
| 4644 | /* On frame indication, read available frames */ |
| 4645 | if (PKT_AVAILABLE()) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4646 | framecnt = brcmf_sdbrcm_readframes(bus, rxlimit, &rxdone); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4647 | if (rxdone || bus->rxskip) |
| 4648 | intstatus &= ~I_HMB_FRAME_IND; |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 4649 | rxlimit -= min(framecnt, rxlimit); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4650 | } |
| 4651 | |
| 4652 | /* Keep still-pending events for next scheduling */ |
| 4653 | bus->intstatus = intstatus; |
| 4654 | |
| 4655 | clkwait: |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4656 | /* Re-enable interrupts to detect new device events (mailbox, rx frame) |
| 4657 | * or clock availability. (Allows tx loop to check ipend if desired.) |
| 4658 | * (Unless register access seems hosed, as we may not be able to ACK...) |
| 4659 | */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4660 | if (bus->intr && bus->intdis && !brcmf_sdcard_regfail(sdh)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4661 | DHD_INTR(("%s: enable SDIO interrupts, rxdone %d framecnt %d\n", |
| 4662 | __func__, rxdone, framecnt)); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4663 | bus->intdis = false; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4664 | brcmf_sdcard_intr_enable(sdh); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4665 | } |
| 4666 | |
| 4667 | if (DATAOK(bus) && bus->ctrl_frame_stat && |
| 4668 | (bus->clkstate == CLK_AVAIL)) { |
| 4669 | int ret, i; |
| 4670 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4671 | ret = brcmf_sdbrcm_send_buf(bus, brcmf_sdcard_cur_sbwad(sdh), |
| 4672 | SDIO_FUNC_2, F2SYNC, (u8 *) bus->ctrl_frame_buf, |
| 4673 | (u32) bus->ctrl_frame_len, NULL, NULL, NULL); |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 4674 | ASSERT(ret != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4675 | |
| 4676 | if (ret < 0) { |
| 4677 | /* On failure, abort the command and |
| 4678 | terminate the frame */ |
| 4679 | DHD_INFO(("%s: sdio error %d, abort command and " |
| 4680 | "terminate frame.\n", __func__, ret)); |
| 4681 | bus->tx_sderrs++; |
| 4682 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4683 | brcmf_sdcard_abort(sdh, SDIO_FUNC_2); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4684 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4685 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4686 | SBSDIO_FUNC1_FRAMECTRL, SFC_WF_TERM, |
| 4687 | NULL); |
| 4688 | bus->f1regdata++; |
| 4689 | |
| 4690 | for (i = 0; i < 3; i++) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4691 | u8 hi, lo; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4692 | hi = brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4693 | SBSDIO_FUNC1_WFRAMEBCHI, |
| 4694 | NULL); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4695 | lo = brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4696 | SBSDIO_FUNC1_WFRAMEBCLO, |
| 4697 | NULL); |
| 4698 | bus->f1regdata += 2; |
| 4699 | if ((hi == 0) && (lo == 0)) |
| 4700 | break; |
| 4701 | } |
| 4702 | |
| 4703 | } |
| 4704 | if (ret == 0) |
| 4705 | bus->tx_seq = (bus->tx_seq + 1) % SDPCM_SEQUENCE_WRAP; |
| 4706 | |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 4707 | DHD_INFO(("Return_dpc value is : %d\n", ret)); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4708 | bus->ctrl_frame_stat = false; |
Franky Lin | b7adfa7 | 2011-06-29 16:47:42 -0700 | [diff] [blame] | 4709 | brcmf_sdbrcm_wait_event_wakeup(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4710 | } |
| 4711 | /* Send queued frames (limit 1 if rx may still be pending) */ |
| 4712 | else if ((bus->clkstate == CLK_AVAIL) && !bus->fcstate && |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4713 | brcmu_pktq_mlen(&bus->txq, ~bus->flowcontrol) && txlimit |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4714 | && DATAOK(bus)) { |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 4715 | framecnt = rxdone ? txlimit : min(txlimit, dhd_txminmax); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4716 | framecnt = brcmf_sdbrcm_sendfromq(bus, framecnt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4717 | txlimit -= framecnt; |
| 4718 | } |
| 4719 | |
| 4720 | /* Resched if events or tx frames are pending, |
| 4721 | else await next interrupt */ |
| 4722 | /* On failed register access, all bets are off: |
| 4723 | no resched or interrupts */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4724 | if ((bus->dhd->busstate == DHD_BUS_DOWN) || brcmf_sdcard_regfail(sdh)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4725 | DHD_ERROR(("%s: failed backplane access over SDIO, halting " |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4726 | "operation %d\n", __func__, brcmf_sdcard_regfail(sdh))); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4727 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 4728 | bus->intstatus = 0; |
| 4729 | } else if (bus->clkstate == CLK_PENDING) { |
| 4730 | DHD_INFO(("%s: rescheduled due to CLK_PENDING awaiting " |
| 4731 | "I_CHIPACTIVE interrupt\n", __func__)); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4732 | resched = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4733 | } else if (bus->intstatus || bus->ipend || |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4734 | (!bus->fcstate && brcmu_pktq_mlen(&bus->txq, ~bus->flowcontrol) |
| 4735 | && DATAOK(bus)) || PKT_AVAILABLE()) { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4736 | resched = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4737 | } |
| 4738 | |
| 4739 | bus->dpc_sched = resched; |
| 4740 | |
| 4741 | /* If we're done for now, turn off clock request. */ |
| 4742 | if ((bus->clkstate != CLK_PENDING) |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 4743 | && bus->idletime == BRCMF_IDLE_IMMEDIATE) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4744 | bus->activity = false; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4745 | brcmf_sdbrcm_clkctl(bus, CLK_NONE, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4746 | } |
| 4747 | |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 4748 | brcmf_sdbrcm_sdunlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4749 | |
| 4750 | return resched; |
| 4751 | } |
| 4752 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4753 | void brcmf_sdbrcm_isr(void *arg) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4754 | { |
| 4755 | dhd_bus_t *bus = (dhd_bus_t *) arg; |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 4756 | struct brcmf_sdio *sdh; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4757 | |
| 4758 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 4759 | |
| 4760 | if (!bus) { |
| 4761 | DHD_ERROR(("%s : bus is null pointer , exit\n", __func__)); |
| 4762 | return; |
| 4763 | } |
| 4764 | sdh = bus->sdh; |
| 4765 | |
| 4766 | if (bus->dhd->busstate == DHD_BUS_DOWN) { |
| 4767 | DHD_ERROR(("%s : bus is down. we have nothing to do\n", |
| 4768 | __func__)); |
| 4769 | return; |
| 4770 | } |
| 4771 | /* Count the interrupt call */ |
| 4772 | bus->intrcount++; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4773 | bus->ipend = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4774 | |
| 4775 | /* Shouldn't get this interrupt if we're sleeping? */ |
| 4776 | if (bus->sleeping) { |
| 4777 | DHD_ERROR(("INTERRUPT WHILE SLEEPING??\n")); |
| 4778 | return; |
| 4779 | } |
| 4780 | |
| 4781 | /* Disable additional interrupts (is this needed now)? */ |
| 4782 | if (bus->intr) |
| 4783 | DHD_INTR(("%s: disable SDIO interrupts\n", __func__)); |
| 4784 | else |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4785 | DHD_ERROR(("brcmf_sdbrcm_isr() w/o interrupt configured!\n")); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4786 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4787 | brcmf_sdcard_intr_disable(sdh); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4788 | bus->intdis = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4789 | |
| 4790 | #if defined(SDIO_ISR_THREAD) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4791 | DHD_TRACE(("Calling brcmf_sdbrcm_dpc() from %s\n", __func__)); |
| 4792 | while (brcmf_sdbrcm_dpc(bus)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4793 | ; |
| 4794 | #else |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4795 | bus->dpc_sched = true; |
Franky Lin | 0827888 | 2011-06-29 16:47:45 -0700 | [diff] [blame] | 4796 | brcmf_sdbrcm_sched_dpc(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4797 | #endif |
| 4798 | |
| 4799 | } |
| 4800 | |
| 4801 | #ifdef SDTEST |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4802 | static void brcmf_sdbrcm_pktgen_init(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4803 | { |
| 4804 | /* Default to specified length, or full range */ |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 4805 | if (brcmf_pktgen_len) { |
| 4806 | bus->pktgen_maxlen = min(brcmf_pktgen_len, |
| 4807 | BRCMF_MAX_PKTGEN_LEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4808 | bus->pktgen_minlen = bus->pktgen_maxlen; |
| 4809 | } else { |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 4810 | bus->pktgen_maxlen = BRCMF_MAX_PKTGEN_LEN; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4811 | bus->pktgen_minlen = 0; |
| 4812 | } |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4813 | bus->pktgen_len = (u16) bus->pktgen_minlen; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4814 | |
| 4815 | /* Default to per-watchdog burst with 10s print time */ |
| 4816 | bus->pktgen_freq = 1; |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 4817 | bus->pktgen_print = 10000 / brcmf_watchdog_ms; |
| 4818 | bus->pktgen_count = (brcmf_pktgen * brcmf_watchdog_ms + 999) / 1000; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4819 | |
| 4820 | /* Default to echo mode */ |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 4821 | bus->pktgen_mode = BRCMF_PKTGEN_ECHO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4822 | bus->pktgen_stop = 1; |
| 4823 | } |
| 4824 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4825 | static void brcmf_sdbrcm_pktgen(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4826 | { |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 4827 | struct sk_buff *pkt; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4828 | u8 *data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4829 | uint pktcount; |
| 4830 | uint fillbyte; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4831 | u16 len; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4832 | |
| 4833 | /* Display current count if appropriate */ |
| 4834 | if (bus->pktgen_print && (++bus->pktgen_ptick >= bus->pktgen_print)) { |
| 4835 | bus->pktgen_ptick = 0; |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 4836 | printk(KERN_DEBUG "%s: send attempts %d rcvd %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4837 | __func__, bus->pktgen_sent, bus->pktgen_rcvd); |
| 4838 | } |
| 4839 | |
| 4840 | /* For recv mode, just make sure dongle has started sending */ |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 4841 | if (bus->pktgen_mode == BRCMF_PKTGEN_RECV) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4842 | if (!bus->pktgen_rcvd) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4843 | brcmf_sdbrcm_sdtest_set(bus, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4844 | return; |
| 4845 | } |
| 4846 | |
| 4847 | /* Otherwise, generate or request the specified number of packets */ |
| 4848 | for (pktcount = 0; pktcount < bus->pktgen_count; pktcount++) { |
| 4849 | /* Stop if total has been reached */ |
| 4850 | if (bus->pktgen_total |
| 4851 | && (bus->pktgen_sent >= bus->pktgen_total)) { |
| 4852 | bus->pktgen_count = 0; |
| 4853 | break; |
| 4854 | } |
| 4855 | |
| 4856 | /* Allocate an appropriate-sized packet */ |
| 4857 | len = bus->pktgen_len; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4858 | pkt = brcmu_pkt_buf_get_skb( |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 4859 | (len + SDPCM_HDRLEN + SDPCM_TEST_HDRLEN + BRCMF_SDALIGN), |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4860 | true); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 4861 | if (!pkt) { |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4862 | DHD_ERROR(("%s: brcmu_pkt_buf_get_skb failed!\n", |
| 4863 | __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4864 | break; |
| 4865 | } |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 4866 | PKTALIGN(pkt, (len + SDPCM_HDRLEN + SDPCM_TEST_HDRLEN), |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 4867 | BRCMF_SDALIGN); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4868 | data = (u8 *) (pkt->data) + SDPCM_HDRLEN; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4869 | |
| 4870 | /* Write test header cmd and extra based on mode */ |
| 4871 | switch (bus->pktgen_mode) { |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 4872 | case BRCMF_PKTGEN_ECHO: |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4873 | *data++ = SDPCM_TEST_ECHOREQ; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4874 | *data++ = (u8) bus->pktgen_sent; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4875 | break; |
| 4876 | |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 4877 | case BRCMF_PKTGEN_SEND: |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4878 | *data++ = SDPCM_TEST_DISCARD; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4879 | *data++ = (u8) bus->pktgen_sent; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4880 | break; |
| 4881 | |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 4882 | case BRCMF_PKTGEN_RXBURST: |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4883 | *data++ = SDPCM_TEST_BURST; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4884 | *data++ = (u8) bus->pktgen_count; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4885 | break; |
| 4886 | |
| 4887 | default: |
| 4888 | DHD_ERROR(("Unrecognized pktgen mode %d\n", |
| 4889 | bus->pktgen_mode)); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4890 | brcmu_pkt_buf_free_skb(pkt, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4891 | bus->pktgen_count = 0; |
| 4892 | return; |
| 4893 | } |
| 4894 | |
| 4895 | /* Write test header length field */ |
| 4896 | *data++ = (len >> 0); |
| 4897 | *data++ = (len >> 8); |
| 4898 | |
| 4899 | /* Then fill in the remainder -- N/A for burst, |
| 4900 | but who cares... */ |
| 4901 | for (fillbyte = 0; fillbyte < len; fillbyte++) |
| 4902 | *data++ = |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4903 | SDPCM_TEST_FILL(fillbyte, (u8) bus->pktgen_sent); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4904 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 4905 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4906 | if (DHD_BYTES_ON() && DHD_DATA_ON()) { |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4907 | data = (u8 *) (pkt->data) + SDPCM_HDRLEN; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4908 | printk(KERN_DEBUG "brcmf_sdbrcm_pktgen: Tx Data:\n"); |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 4909 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, data, |
| 4910 | pkt->len - SDPCM_HDRLEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4911 | } |
| 4912 | #endif |
| 4913 | |
| 4914 | /* Send it */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4915 | if (brcmf_sdbrcm_txpkt(bus, pkt, SDPCM_TEST_CHANNEL, true)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4916 | bus->pktgen_fail++; |
| 4917 | if (bus->pktgen_stop |
| 4918 | && bus->pktgen_stop == bus->pktgen_fail) |
| 4919 | bus->pktgen_count = 0; |
| 4920 | } |
| 4921 | bus->pktgen_sent++; |
| 4922 | |
| 4923 | /* Bump length if not fixed, wrap at max */ |
| 4924 | if (++bus->pktgen_len > bus->pktgen_maxlen) |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4925 | bus->pktgen_len = (u16) bus->pktgen_minlen; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4926 | |
| 4927 | /* Special case for burst mode: just send one request! */ |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 4928 | if (bus->pktgen_mode == BRCMF_PKTGEN_RXBURST) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4929 | break; |
| 4930 | } |
| 4931 | } |
| 4932 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4933 | static void brcmf_sdbrcm_sdtest_set(dhd_bus_t *bus, bool start) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4934 | { |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 4935 | struct sk_buff *pkt; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4936 | u8 *data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4937 | |
| 4938 | /* Allocate the packet */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4939 | pkt = brcmu_pkt_buf_get_skb(SDPCM_HDRLEN + SDPCM_TEST_HDRLEN + |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 4940 | BRCMF_SDALIGN, true); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 4941 | if (!pkt) { |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4942 | DHD_ERROR(("%s: brcmu_pkt_buf_get_skb failed!\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4943 | return; |
| 4944 | } |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 4945 | PKTALIGN(pkt, (SDPCM_HDRLEN + SDPCM_TEST_HDRLEN), BRCMF_SDALIGN); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4946 | data = (u8 *) (pkt->data) + SDPCM_HDRLEN; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4947 | |
| 4948 | /* Fill in the test header */ |
| 4949 | *data++ = SDPCM_TEST_SEND; |
| 4950 | *data++ = start; |
| 4951 | *data++ = (bus->pktgen_maxlen >> 0); |
| 4952 | *data++ = (bus->pktgen_maxlen >> 8); |
| 4953 | |
| 4954 | /* Send it */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4955 | if (brcmf_sdbrcm_txpkt(bus, pkt, SDPCM_TEST_CHANNEL, true)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4956 | bus->pktgen_fail++; |
| 4957 | } |
| 4958 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4959 | static void |
| 4960 | 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] | 4961 | { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4962 | u8 *data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4963 | uint pktlen; |
| 4964 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4965 | u8 cmd; |
| 4966 | u8 extra; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4967 | u16 len; |
| 4968 | u16 offset; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4969 | |
| 4970 | /* Check for min length */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4971 | pktlen = pkt->len; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4972 | if (pktlen < SDPCM_TEST_HDRLEN) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4973 | DHD_ERROR(("brcmf_sdbrcm_checkdied: toss runt frame, pktlen " |
| 4974 | "%d\n", pktlen)); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4975 | brcmu_pkt_buf_free_skb(pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4976 | return; |
| 4977 | } |
| 4978 | |
| 4979 | /* Extract header fields */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4980 | data = pkt->data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4981 | cmd = *data++; |
| 4982 | extra = *data++; |
| 4983 | len = *data++; |
| 4984 | len += *data++ << 8; |
| 4985 | |
| 4986 | /* Check length for relevant commands */ |
| 4987 | if (cmd == SDPCM_TEST_DISCARD || cmd == SDPCM_TEST_ECHOREQ |
| 4988 | || cmd == SDPCM_TEST_ECHORSP) { |
| 4989 | if (pktlen != len + SDPCM_TEST_HDRLEN) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 4990 | DHD_ERROR(("brcmf_sdbrcm_checkdied: frame length " |
| 4991 | "mismatch, pktlen %d seq %d" " cmd %d extra %d " |
| 4992 | "len %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4993 | pktlen, seq, cmd, extra, len)); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4994 | brcmu_pkt_buf_free_skb(pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4995 | return; |
| 4996 | } |
| 4997 | } |
| 4998 | |
| 4999 | /* Process as per command */ |
| 5000 | switch (cmd) { |
| 5001 | case SDPCM_TEST_ECHOREQ: |
| 5002 | /* Rx->Tx turnaround ok (even on NDIS w/current |
| 5003 | implementation) */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 5004 | *(u8 *) (pkt->data) = SDPCM_TEST_ECHORSP; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5005 | if (brcmf_sdbrcm_txpkt(bus, pkt, SDPCM_TEST_CHANNEL, true) == 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5006 | bus->pktgen_sent++; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5007 | else { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5008 | bus->pktgen_fail++; |
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 | } |
| 5011 | bus->pktgen_rcvd++; |
| 5012 | break; |
| 5013 | |
| 5014 | case SDPCM_TEST_ECHORSP: |
| 5015 | if (bus->ext_loop) { |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 5016 | brcmu_pkt_buf_free_skb(pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5017 | bus->pktgen_rcvd++; |
| 5018 | break; |
| 5019 | } |
| 5020 | |
| 5021 | for (offset = 0; offset < len; offset++, data++) { |
| 5022 | if (*data != SDPCM_TEST_FILL(offset, extra)) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5023 | DHD_ERROR(("brcmf_sdbrcm_checkdied: echo data " |
| 5024 | "mismatch: " "offset %d (len %d) " |
| 5025 | "expect 0x%02x rcvd 0x%02x\n", |
| 5026 | offset, len, |
| 5027 | SDPCM_TEST_FILL(offset, extra), |
| 5028 | *data)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5029 | break; |
| 5030 | } |
| 5031 | } |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 5032 | brcmu_pkt_buf_free_skb(pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5033 | bus->pktgen_rcvd++; |
| 5034 | break; |
| 5035 | |
| 5036 | case SDPCM_TEST_DISCARD: |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 5037 | brcmu_pkt_buf_free_skb(pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5038 | bus->pktgen_rcvd++; |
| 5039 | break; |
| 5040 | |
| 5041 | case SDPCM_TEST_BURST: |
| 5042 | case SDPCM_TEST_SEND: |
| 5043 | default: |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5044 | DHD_INFO(("brcmf_sdbrcm_checkdied: unsupported or unknown " |
| 5045 | "command, pktlen %d seq %d" " cmd %d extra %d len %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5046 | pktlen, seq, cmd, extra, len)); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 5047 | brcmu_pkt_buf_free_skb(pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5048 | break; |
| 5049 | } |
| 5050 | |
| 5051 | /* For recv mode, stop at limie (and tell dongle to stop sending) */ |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 5052 | if (bus->pktgen_mode == BRCMF_PKTGEN_RECV) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5053 | if (bus->pktgen_total |
| 5054 | && (bus->pktgen_rcvd >= bus->pktgen_total)) { |
| 5055 | bus->pktgen_count = 0; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5056 | brcmf_sdbrcm_sdtest_set(bus, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5057 | } |
| 5058 | } |
| 5059 | } |
| 5060 | #endif /* SDTEST */ |
| 5061 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5062 | extern bool brcmf_sdbrcm_bus_watchdog(dhd_pub_t *dhdp) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5063 | { |
| 5064 | dhd_bus_t *bus; |
| 5065 | |
| 5066 | DHD_TIMER(("%s: Enter\n", __func__)); |
| 5067 | |
| 5068 | bus = dhdp->bus; |
| 5069 | |
| 5070 | if (bus->dhd->dongle_reset) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5071 | return false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5072 | |
| 5073 | /* Ignore the timer if simulating bus down */ |
| 5074 | if (bus->sleeping) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5075 | return false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5076 | |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 5077 | brcmf_sdbrcm_sdlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5078 | |
| 5079 | /* Poll period: check device if appropriate. */ |
| 5080 | if (bus->poll && (++bus->polltick >= bus->pollrate)) { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 5081 | u32 intstatus = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5082 | |
| 5083 | /* Reset poll tick */ |
| 5084 | bus->polltick = 0; |
| 5085 | |
| 5086 | /* Check device if no interrupts */ |
| 5087 | if (!bus->intr || (bus->intrcount == bus->lastintrs)) { |
| 5088 | |
| 5089 | if (!bus->dpc_sched) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 5090 | u8 devpend; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5091 | devpend = brcmf_sdcard_cfg_read(bus->sdh, |
| 5092 | SDIO_FUNC_0, SDIO_CCCR_INTx, |
| 5093 | NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5094 | intstatus = |
| 5095 | devpend & (INTR_STATUS_FUNC1 | |
| 5096 | INTR_STATUS_FUNC2); |
| 5097 | } |
| 5098 | |
| 5099 | /* If there is something, make like the ISR and |
| 5100 | schedule the DPC */ |
| 5101 | if (intstatus) { |
| 5102 | bus->pollcnt++; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5103 | bus->ipend = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5104 | if (bus->intr) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5105 | brcmf_sdcard_intr_disable(bus->sdh); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5106 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5107 | bus->dpc_sched = true; |
Franky Lin | 0827888 | 2011-06-29 16:47:45 -0700 | [diff] [blame] | 5108 | brcmf_sdbrcm_sched_dpc(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5109 | |
| 5110 | } |
| 5111 | } |
| 5112 | |
| 5113 | /* Update interrupt tracking */ |
| 5114 | bus->lastintrs = bus->intrcount; |
| 5115 | } |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 5116 | #ifdef BCMDBG |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5117 | /* Poll for console output periodically */ |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 5118 | if (dhdp->busstate == DHD_BUS_DATA && brcmf_console_ms != 0) { |
| 5119 | bus->console.count += brcmf_watchdog_ms; |
| 5120 | if (bus->console.count >= brcmf_console_ms) { |
| 5121 | bus->console.count -= brcmf_console_ms; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5122 | /* Make sure backplane clock is on */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5123 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
| 5124 | if (brcmf_sdbrcm_readconsole(bus) < 0) |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 5125 | brcmf_console_ms = 0; /* On error, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5126 | stop trying */ |
| 5127 | } |
| 5128 | } |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 5129 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5130 | |
| 5131 | #ifdef SDTEST |
| 5132 | /* Generate packets if configured */ |
| 5133 | if (bus->pktgen_count && (++bus->pktgen_tick >= bus->pktgen_freq)) { |
| 5134 | /* Make sure backplane clock is on */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5135 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5136 | bus->pktgen_tick = 0; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5137 | brcmf_sdbrcm_pktgen(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5138 | } |
| 5139 | #endif |
| 5140 | |
| 5141 | /* On idle timeout clear activity flag and/or turn off clock */ |
| 5142 | if ((bus->idletime > 0) && (bus->clkstate == CLK_AVAIL)) { |
| 5143 | if (++bus->idlecount >= bus->idletime) { |
| 5144 | bus->idlecount = 0; |
| 5145 | if (bus->activity) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5146 | bus->activity = false; |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 5147 | brcmf_sdbrcm_wd_timer(bus, brcmf_watchdog_ms); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5148 | } else { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5149 | brcmf_sdbrcm_clkctl(bus, CLK_NONE, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5150 | } |
| 5151 | } |
| 5152 | } |
| 5153 | |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 5154 | brcmf_sdbrcm_sdunlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5155 | |
| 5156 | return bus->ipend; |
| 5157 | } |
| 5158 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 5159 | #ifdef BCMDBG |
Franky Lin | 913af5f | 2011-06-29 16:47:44 -0700 | [diff] [blame] | 5160 | 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] | 5161 | uint msglen) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5162 | { |
| 5163 | dhd_bus_t *bus = dhdp->bus; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 5164 | u32 addr, val; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5165 | int rv; |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 5166 | struct sk_buff *pkt; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5167 | |
| 5168 | /* Address could be zero if CONSOLE := 0 in dongle Makefile */ |
| 5169 | if (bus->console_addr == 0) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 5170 | return -ENOTSUPP; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5171 | |
| 5172 | /* Exclusive bus access */ |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 5173 | brcmf_sdbrcm_sdlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5174 | |
| 5175 | /* Don't allow input if dongle is in reset */ |
| 5176 | if (bus->dhd->dongle_reset) { |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 5177 | brcmf_sdbrcm_sdunlock(bus); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 5178 | return -EPERM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5179 | } |
| 5180 | |
| 5181 | /* Request clock to allow SDIO accesses */ |
| 5182 | BUS_WAKE(bus); |
| 5183 | /* 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] | 5184 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5185 | |
| 5186 | /* Zero cbuf_index */ |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 5187 | addr = bus->console_addr + offsetof(struct rte_console, cbuf_idx); |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 5188 | val = cpu_to_le32(0); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5189 | rv = brcmf_sdbrcm_membytes(bus, true, addr, (u8 *)&val, sizeof(val)); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5190 | if (rv < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5191 | goto done; |
| 5192 | |
| 5193 | /* Write message into cbuf */ |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 5194 | addr = bus->console_addr + offsetof(struct rte_console, cbuf); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5195 | rv = brcmf_sdbrcm_membytes(bus, true, addr, (u8 *)msg, msglen); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5196 | if (rv < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5197 | goto done; |
| 5198 | |
| 5199 | /* Write length into vcons_in */ |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 5200 | addr = bus->console_addr + offsetof(struct rte_console, vcons_in); |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 5201 | val = cpu_to_le32(msglen); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5202 | rv = brcmf_sdbrcm_membytes(bus, true, addr, (u8 *)&val, sizeof(val)); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5203 | if (rv < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5204 | goto done; |
| 5205 | |
| 5206 | /* Bump dongle by sending an empty event pkt. |
| 5207 | * sdpcm_sendup (RX) checks for virtual console input. |
| 5208 | */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 5209 | pkt = brcmu_pkt_buf_get_skb(4 + SDPCM_RESERVE); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5210 | if ((pkt != NULL) && bus->clkstate == CLK_AVAIL) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5211 | brcmf_sdbrcm_txpkt(bus, pkt, SDPCM_EVENT_CHANNEL, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5212 | |
| 5213 | done: |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 5214 | if ((bus->idletime == BRCMF_IDLE_IMMEDIATE) && !bus->dpc_sched) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5215 | bus->activity = false; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5216 | brcmf_sdbrcm_clkctl(bus, CLK_NONE, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5217 | } |
| 5218 | |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 5219 | brcmf_sdbrcm_sdunlock(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5220 | |
| 5221 | return rv; |
| 5222 | } |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 5223 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5224 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5225 | static bool brcmf_sdbrcm_chipmatch(u16 chipid) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5226 | { |
| 5227 | if (chipid == BCM4325_CHIP_ID) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5228 | return true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5229 | if (chipid == BCM4329_CHIP_ID) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5230 | return true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5231 | if (chipid == BCM4319_CHIP_ID) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5232 | return true; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5233 | return false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5234 | } |
| 5235 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5236 | 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] | 5237 | u16 slot, u16 func, uint bustype, void *regsva, |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 5238 | void *sdh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5239 | { |
| 5240 | int ret; |
| 5241 | dhd_bus_t *bus; |
| 5242 | |
| 5243 | /* Init global variables at run-time, not as part of the declaration. |
| 5244 | * This is required to support init/de-init of the driver. |
| 5245 | * Initialization |
| 5246 | * of globals as part of the declaration results in non-deterministic |
| 5247 | * behavior since the value of the globals may be different on the |
| 5248 | * first time that the driver is initialized vs subsequent |
| 5249 | * initializations. |
| 5250 | */ |
Arend van Spriel | 7af9d0c | 2011-06-29 16:47:19 -0700 | [diff] [blame] | 5251 | brcmf_txbound = DHD_TXBOUND; |
| 5252 | brcmf_rxbound = DHD_RXBOUND; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5253 | dhd_alignctl = true; |
| 5254 | sd1idle = true; |
| 5255 | dhd_readahead = true; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5256 | retrydata = false; |
Arend van Spriel | 7af9d0c | 2011-06-29 16:47:19 -0700 | [diff] [blame] | 5257 | brcmf_dongle_memsize = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5258 | dhd_txminmax = DHD_TXMINMAX; |
| 5259 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5260 | forcealign = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5261 | |
Arend van Spriel | aba5e0a | 2011-06-29 16:47:03 -0700 | [diff] [blame] | 5262 | brcmf_c_init(); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5263 | |
| 5264 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5265 | DHD_INFO(("%s: venid 0x%04x devid 0x%04x\n", __func__, venid, devid)); |
| 5266 | |
| 5267 | /* We make assumptions about address window mappings */ |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 5268 | ASSERT((unsigned long)regsva == SI_ENUM_BASE); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5269 | |
| 5270 | /* BCMSDH passes venid and devid based on CIS parsing -- but |
| 5271 | * low-power start |
| 5272 | * means early parse could fail, so here we should get either an ID |
| 5273 | * we recognize OR (-1) indicating we must request power first. |
| 5274 | */ |
| 5275 | /* Check the Vendor ID */ |
| 5276 | switch (venid) { |
| 5277 | case 0x0000: |
Stanislav Fomichev | be1c09f | 2011-03-28 01:31:36 +0400 | [diff] [blame] | 5278 | case PCI_VENDOR_ID_BROADCOM: |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5279 | break; |
| 5280 | default: |
| 5281 | DHD_ERROR(("%s: unknown vendor: 0x%04x\n", __func__, venid)); |
| 5282 | return NULL; |
| 5283 | } |
| 5284 | |
| 5285 | /* Check the Device ID and make sure it's one that we support */ |
| 5286 | switch (devid) { |
| 5287 | case BCM4325_D11DUAL_ID: /* 4325 802.11a/g id */ |
| 5288 | case BCM4325_D11G_ID: /* 4325 802.11g 2.4Ghz band id */ |
| 5289 | case BCM4325_D11A_ID: /* 4325 802.11a 5Ghz band id */ |
| 5290 | DHD_INFO(("%s: found 4325 Dongle\n", __func__)); |
| 5291 | break; |
| 5292 | case BCM4329_D11NDUAL_ID: /* 4329 802.11n dualband device */ |
| 5293 | case BCM4329_D11N2G_ID: /* 4329 802.11n 2.4G device */ |
| 5294 | case BCM4329_D11N5G_ID: /* 4329 802.11n 5G device */ |
| 5295 | case 0x4329: |
| 5296 | DHD_INFO(("%s: found 4329 Dongle\n", __func__)); |
| 5297 | break; |
| 5298 | case BCM4319_D11N_ID: /* 4319 802.11n id */ |
| 5299 | case BCM4319_D11N2G_ID: /* 4319 802.11n2g id */ |
| 5300 | case BCM4319_D11N5G_ID: /* 4319 802.11n5g id */ |
| 5301 | DHD_INFO(("%s: found 4319 Dongle\n", __func__)); |
| 5302 | break; |
| 5303 | case 0: |
| 5304 | DHD_INFO(("%s: allow device id 0, will check chip internals\n", |
| 5305 | __func__)); |
| 5306 | break; |
| 5307 | |
| 5308 | default: |
| 5309 | DHD_ERROR(("%s: skipping 0x%04x/0x%04x, not a dongle\n", |
| 5310 | __func__, venid, devid)); |
| 5311 | return NULL; |
| 5312 | } |
| 5313 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5314 | /* Allocate private bus interface state */ |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5315 | bus = kzalloc(sizeof(dhd_bus_t), GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5316 | if (!bus) { |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5317 | DHD_ERROR(("%s: kmalloc of dhd_bus_t failed\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5318 | goto fail; |
| 5319 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5320 | bus->sdh = sdh; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5321 | bus->cl_devid = (u16) devid; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5322 | bus->bus = DHD_BUS; |
| 5323 | bus->tx_seq = SDPCM_SEQUENCE_WRAP - 1; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5324 | bus->usebufpool = false; /* Use bufpool if allocated, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5325 | else use locally malloced rxbuf */ |
| 5326 | |
| 5327 | /* attempt to attach to the dongle */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5328 | if (!(brcmf_sdbrcm_probe_attach(bus, sdh, regsva, devid))) { |
| 5329 | DHD_ERROR(("%s: brcmf_sdbrcm_probe_attach failed\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5330 | goto fail; |
| 5331 | } |
| 5332 | |
Franky Lin | 0f1a87c | 2011-06-29 16:46:32 -0700 | [diff] [blame] | 5333 | spin_lock_init(&bus->txqlock); |
Franky Lin | b7adfa7 | 2011-06-29 16:47:42 -0700 | [diff] [blame] | 5334 | init_waitqueue_head(&bus->ctrl_wait); |
Franky Lin | 0f1a87c | 2011-06-29 16:46:32 -0700 | [diff] [blame] | 5335 | |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 5336 | /* Set up the watchdog timer */ |
| 5337 | init_timer(&bus->timer); |
| 5338 | bus->timer.data = (unsigned long)bus; |
| 5339 | bus->timer.function = brcmf_sdbrcm_watchdog; |
| 5340 | |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 5341 | /* Initialize thread based operation and lock */ |
| 5342 | if ((brcmf_watchdog_prio >= 0) && (brcmf_dpc_prio >= 0)) { |
| 5343 | bus->threads_only = true; |
| 5344 | sema_init(&bus->sdsem, 1); |
| 5345 | } else { |
| 5346 | bus->threads_only = false; |
| 5347 | spin_lock_init(&bus->sdlock); |
| 5348 | } |
| 5349 | |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 5350 | if (brcmf_dpc_prio >= 0) { |
| 5351 | /* Initialize watchdog thread */ |
| 5352 | init_completion(&bus->watchdog_wait); |
| 5353 | bus->watchdog_tsk = kthread_run(brcmf_sdbrcm_watchdog_thread, |
| 5354 | bus, "brcmf_watchdog"); |
| 5355 | if (IS_ERR(bus->watchdog_tsk)) { |
| 5356 | printk(KERN_WARNING |
| 5357 | "brcmf_watchdog thread failed to start\n"); |
| 5358 | bus->watchdog_tsk = NULL; |
| 5359 | } |
| 5360 | } else |
| 5361 | bus->watchdog_tsk = NULL; |
| 5362 | |
Franky Lin | 0827888 | 2011-06-29 16:47:45 -0700 | [diff] [blame] | 5363 | /* Set up the bottom half handler */ |
| 5364 | if (brcmf_dpc_prio >= 0) { |
| 5365 | /* Initialize DPC thread */ |
| 5366 | init_completion(&bus->dpc_wait); |
| 5367 | bus->dpc_tsk = kthread_run(brcmf_sdbrcm_dpc_thread, |
| 5368 | bus, "dhd_dpc"); |
| 5369 | if (IS_ERR(bus->dpc_tsk)) { |
| 5370 | printk(KERN_WARNING |
| 5371 | "dhd_dpc thread failed to start\n"); |
| 5372 | bus->dpc_tsk = NULL; |
| 5373 | } |
| 5374 | } else { |
| 5375 | tasklet_init(&bus->tasklet, brcmf_sdbrcm_dpc_tasklet, |
| 5376 | (unsigned long)bus); |
| 5377 | bus->dpc_tsk = NULL; |
| 5378 | } |
| 5379 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5380 | /* Attach to the dhd/OS/network interface */ |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 5381 | bus->dhd = brcmf_attach(bus, SDPCM_RESERVE); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5382 | if (!bus->dhd) { |
| 5383 | DHD_ERROR(("%s: dhd_attach failed\n", __func__)); |
| 5384 | goto fail; |
| 5385 | } |
| 5386 | |
| 5387 | /* Allocate buffers */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5388 | if (!(brcmf_sdbrcm_probe_malloc(bus, sdh))) { |
| 5389 | DHD_ERROR(("%s: brcmf_sdbrcm_probe_malloc failed\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5390 | goto fail; |
| 5391 | } |
| 5392 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5393 | if (!(brcmf_sdbrcm_probe_init(bus, sdh))) { |
| 5394 | DHD_ERROR(("%s: brcmf_sdbrcm_probe_init failed\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5395 | goto fail; |
| 5396 | } |
| 5397 | |
| 5398 | /* Register interrupt callback, but mask it (not operational yet). */ |
| 5399 | DHD_INTR(("%s: disable SDIO interrupts (not interested yet)\n", |
| 5400 | __func__)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5401 | brcmf_sdcard_intr_disable(sdh); |
| 5402 | ret = brcmf_sdcard_intr_reg(sdh, brcmf_sdbrcm_isr, bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5403 | if (ret != 0) { |
| 5404 | DHD_ERROR(("%s: FAILED: bcmsdh_intr_reg returned %d\n", |
| 5405 | __func__, ret)); |
| 5406 | goto fail; |
| 5407 | } |
| 5408 | DHD_INTR(("%s: registered SDIO interrupt function ok\n", __func__)); |
| 5409 | |
| 5410 | DHD_INFO(("%s: completed!!\n", __func__)); |
| 5411 | |
| 5412 | /* if firmware path present try to download and bring up bus */ |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 5413 | ret = brcmf_bus_start(bus->dhd); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5414 | if (ret != 0) { |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 5415 | if (ret == -ENOLINK) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5416 | DHD_ERROR(("%s: dongle is not responding\n", __func__)); |
| 5417 | goto fail; |
| 5418 | } |
| 5419 | } |
| 5420 | /* 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] | 5421 | if (brcmf_net_attach(bus->dhd, 0) != 0) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5422 | DHD_ERROR(("%s: Net attach failed!!\n", __func__)); |
| 5423 | goto fail; |
| 5424 | } |
| 5425 | |
| 5426 | return bus; |
| 5427 | |
| 5428 | fail: |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5429 | brcmf_sdbrcm_release(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5430 | return NULL; |
| 5431 | } |
| 5432 | |
| 5433 | static bool |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5434 | brcmf_sdbrcm_probe_attach(struct dhd_bus *bus, void *sdh, void *regsva, |
| 5435 | u16 devid) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5436 | { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 5437 | u8 clkctl = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5438 | int err = 0; |
| 5439 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5440 | bus->alp_only = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5441 | |
| 5442 | /* Return the window to backplane enumeration space for core access */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5443 | if (brcmf_sdbrcm_set_siaddr_window(bus, SI_ENUM_BASE)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5444 | DHD_ERROR(("%s: FAILED to return to SI_ENUM_BASE\n", __func__)); |
| 5445 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 5446 | #ifdef BCMDBG |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 5447 | printk(KERN_DEBUG "F1 signature read @0x18000000=0x%4x\n", |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5448 | brcmf_sdcard_reg_read(bus->sdh, SI_ENUM_BASE, 4)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5449 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 5450 | #endif /* BCMDBG */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5451 | |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 5452 | /* |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5453 | * Force PLL off until brcmf_sdbrcm_chip_attach() |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 5454 | * programs PLL control regs |
| 5455 | */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5456 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5457 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5458 | DHD_INIT_CLKCTL1, &err); |
| 5459 | if (!err) |
| 5460 | clkctl = |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5461 | brcmf_sdcard_cfg_read(sdh, SDIO_FUNC_1, |
| 5462 | SBSDIO_FUNC1_CHIPCLKCSR, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5463 | |
| 5464 | if (err || ((clkctl & ~SBSDIO_AVBITS) != DHD_INIT_CLKCTL1)) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5465 | DHD_ERROR(("brcmf_sdbrcm_probe: ChipClkCSR access: err %d wrote" |
| 5466 | " 0x%02x read 0x%02x\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5467 | err, DHD_INIT_CLKCTL1, clkctl)); |
| 5468 | goto fail; |
| 5469 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5470 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5471 | if (brcmf_sdbrcm_chip_attach(bus, regsva)) { |
| 5472 | DHD_ERROR(("%s: brcmf_sdbrcm_chip_attach failed!\n", __func__)); |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 5473 | goto fail; |
| 5474 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5475 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5476 | brcmf_sdcard_chipinfo(sdh, bus->ci->chip, bus->ci->chiprev); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5477 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5478 | if (!brcmf_sdbrcm_chipmatch((u16) bus->ci->chip)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5479 | DHD_ERROR(("%s: unsupported chip: 0x%04x\n", |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 5480 | __func__, bus->ci->chip)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5481 | goto fail; |
| 5482 | } |
| 5483 | |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 5484 | brcmf_sdbrcm_sdiod_drive_strength_init(bus, brcmf_sdiod_drive_strength); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5485 | |
| 5486 | /* Get info on the ARM and SOCRAM cores... */ |
| 5487 | if (!DHD_NOPMU(bus)) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5488 | bus->armrev = SBCOREREV(brcmf_sdcard_reg_read(bus->sdh, |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 5489 | CORE_SB(bus->ci->armcorebase, sbidhigh), 4)); |
| 5490 | bus->orig_ramsize = bus->ci->ramsize; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5491 | if (!(bus->orig_ramsize)) { |
| 5492 | DHD_ERROR(("%s: failed to find SOCRAM memory!\n", |
| 5493 | __func__)); |
| 5494 | goto fail; |
| 5495 | } |
| 5496 | bus->ramsize = bus->orig_ramsize; |
Arend van Spriel | 7af9d0c | 2011-06-29 16:47:19 -0700 | [diff] [blame] | 5497 | if (brcmf_dongle_memsize) |
| 5498 | brcmf_sdbrcm_setmemsize(bus, brcmf_dongle_memsize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5499 | |
| 5500 | DHD_ERROR(("DHD: dongle ram size is set to %d(orig %d)\n", |
| 5501 | bus->ramsize, bus->orig_ramsize)); |
| 5502 | } |
| 5503 | |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 5504 | bus->regs = (void *)bus->ci->buscorebase; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5505 | |
| 5506 | /* Set core control so an SDIO reset does a backplane reset */ |
Arend van Spriel | ff31c54 | 2011-03-01 10:56:54 +0100 | [diff] [blame] | 5507 | OR_REG(&bus->regs->corecontrol, CC_BPRESEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5508 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 5509 | brcmu_pktq_init(&bus->txq, (PRIOMASK + 1), TXQLEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5510 | |
| 5511 | /* Locate an appropriately-aligned portion of hdrbuf */ |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 5512 | bus->rxhdr = (u8 *) roundup((unsigned long)&bus->hdrbuf[0], BRCMF_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5513 | |
| 5514 | /* Set the poll and/or interrupt flags */ |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 5515 | bus->intr = (bool) brcmf_intr; |
| 5516 | bus->poll = (bool) brcmf_poll; |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5517 | if (bus->poll) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5518 | bus->pollrate = 1; |
| 5519 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5520 | return true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5521 | |
| 5522 | fail: |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5523 | return false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5524 | } |
| 5525 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5526 | static bool brcmf_sdbrcm_probe_malloc(dhd_bus_t *bus, void *sdh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5527 | { |
| 5528 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5529 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5530 | if (bus->dhd->maxctl) { |
| 5531 | bus->rxblen = |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 5532 | roundup((bus->dhd->maxctl + SDPCM_HDRLEN), |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 5533 | ALIGNMENT) + BRCMF_SDALIGN; |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5534 | bus->rxbuf = kmalloc(bus->rxblen, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5535 | if (!(bus->rxbuf)) { |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5536 | DHD_ERROR(("%s: kmalloc of %d-byte rxbuf failed\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5537 | __func__, bus->rxblen)); |
| 5538 | goto fail; |
| 5539 | } |
| 5540 | } |
| 5541 | |
| 5542 | /* Allocate buffer to receive glomed packet */ |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5543 | bus->databuf = kmalloc(MAX_DATA_BUF, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5544 | if (!(bus->databuf)) { |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5545 | DHD_ERROR(("%s: kmalloc of %d-byte databuf failed\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5546 | __func__, MAX_DATA_BUF)); |
| 5547 | /* release rxbuf which was already located as above */ |
| 5548 | if (!bus->rxblen) |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 5549 | kfree(bus->rxbuf); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5550 | goto fail; |
| 5551 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5552 | |
| 5553 | /* Align the buffer */ |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 5554 | if ((unsigned long)bus->databuf % BRCMF_SDALIGN) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5555 | bus->dataptr = |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 5556 | bus->databuf + (BRCMF_SDALIGN - |
| 5557 | ((unsigned long)bus->databuf % BRCMF_SDALIGN)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5558 | else |
| 5559 | bus->dataptr = bus->databuf; |
| 5560 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5561 | return true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5562 | |
| 5563 | fail: |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5564 | return false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5565 | } |
| 5566 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5567 | static bool brcmf_sdbrcm_probe_init(dhd_bus_t *bus, void *sdh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5568 | { |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 5569 | s32 fnum; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5570 | |
| 5571 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5572 | |
| 5573 | #ifdef SDTEST |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5574 | brcmf_sdbrcm_pktgen_init(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5575 | #endif /* SDTEST */ |
| 5576 | |
| 5577 | /* Disable F2 to clear any intermediate frame state on the dongle */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5578 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_0, SDIO_CCCR_IOEx, |
| 5579 | SDIO_FUNC_ENABLE_1, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5580 | |
| 5581 | bus->dhd->busstate = DHD_BUS_DOWN; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5582 | bus->sleeping = false; |
| 5583 | bus->rxflow = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5584 | bus->prev_rxlim_hit = 0; |
| 5585 | |
| 5586 | /* Done with backplane-dependent accesses, can drop clock... */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5587 | brcmf_sdcard_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, 0, |
| 5588 | NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5589 | |
| 5590 | /* ...and initialize clock/power states */ |
| 5591 | bus->clkstate = CLK_SDONLY; |
Arend van Spriel | 5e92aa8 | 2011-06-29 16:47:08 -0700 | [diff] [blame] | 5592 | bus->idletime = (s32) brcmf_idletime; |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 5593 | bus->idleclock = BRCMF_IDLE_ACTIVE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5594 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5595 | /* Query the F2 block size, set roundup accordingly */ |
| 5596 | fnum = 2; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5597 | if (brcmf_sdcard_iovar_op(sdh, "sd_blocksize", &fnum, sizeof(s32), |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 5598 | &bus->blocksize, sizeof(s32), false) != 0) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5599 | bus->blocksize = 0; |
| 5600 | DHD_ERROR(("%s: fail on %s get\n", __func__, "sd_blocksize")); |
| 5601 | } else { |
| 5602 | DHD_INFO(("%s: Initial value for %s is %d\n", |
| 5603 | __func__, "sd_blocksize", bus->blocksize)); |
| 5604 | } |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 5605 | bus->roundup = min(max_roundup, bus->blocksize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5606 | |
| 5607 | /* Query if bus module supports packet chaining, |
| 5608 | default to use if supported */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5609 | if (brcmf_sdcard_iovar_op(sdh, "sd_rxchain", NULL, 0, |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 5610 | &bus->sd_rxchain, sizeof(s32), |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 5611 | false) != 0) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5612 | bus->sd_rxchain = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5613 | } else { |
| 5614 | DHD_INFO(("%s: bus module (through bcmsdh API) %s chaining\n", |
| 5615 | __func__, |
| 5616 | (bus->sd_rxchain ? "supports" : "does not support"))); |
| 5617 | } |
| 5618 | bus->use_rxchain = (bool) bus->sd_rxchain; |
| 5619 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5620 | return true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5621 | } |
| 5622 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5623 | static bool |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5624 | brcmf_sdbrcm_download_firmware(struct dhd_bus *bus, void *sdh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5625 | { |
| 5626 | bool ret; |
| 5627 | |
| 5628 | /* Download the firmware */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5629 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5630 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5631 | ret = _brcmf_sdbrcm_download_firmware(bus) == 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5632 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5633 | brcmf_sdbrcm_clkctl(bus, CLK_SDONLY, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5634 | |
| 5635 | return ret; |
| 5636 | } |
| 5637 | |
| 5638 | /* Detach and free everything */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5639 | static void brcmf_sdbrcm_release(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5640 | { |
| 5641 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5642 | |
| 5643 | if (bus) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5644 | /* De-register interrupt handler */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5645 | brcmf_sdcard_intr_disable(bus->sdh); |
| 5646 | brcmf_sdcard_intr_dereg(bus->sdh); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5647 | |
| 5648 | if (bus->dhd) { |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 5649 | brcmf_detach(bus->dhd); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5650 | brcmf_sdbrcm_release_dongle(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5651 | bus->dhd = NULL; |
| 5652 | } |
| 5653 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5654 | brcmf_sdbrcm_release_malloc(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5655 | |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 5656 | kfree(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5657 | } |
| 5658 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5659 | DHD_TRACE(("%s: Disconnected\n", __func__)); |
| 5660 | } |
| 5661 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5662 | static void brcmf_sdbrcm_release_malloc(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5663 | { |
| 5664 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5665 | |
| 5666 | if (bus->dhd && bus->dhd->dongle_reset) |
| 5667 | return; |
| 5668 | |
Henry Ptasinski | 521223a | 2011-06-29 16:46:55 -0700 | [diff] [blame] | 5669 | kfree(bus->rxbuf); |
| 5670 | bus->rxctl = bus->rxbuf = NULL; |
| 5671 | bus->rxlen = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5672 | |
Ilia Mirkin | 46d994b | 2011-03-13 00:28:56 -0500 | [diff] [blame] | 5673 | kfree(bus->databuf); |
| 5674 | bus->databuf = NULL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5675 | } |
| 5676 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5677 | static void brcmf_sdbrcm_release_dongle(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5678 | { |
| 5679 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5680 | |
| 5681 | if (bus->dhd && bus->dhd->dongle_reset) |
| 5682 | return; |
| 5683 | |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 5684 | if (bus->ci) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5685 | brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false); |
| 5686 | brcmf_sdbrcm_clkctl(bus, CLK_NONE, false); |
| 5687 | brcmf_sdbrcm_chip_detach(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5688 | if (bus->vars && bus->varsz) |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 5689 | kfree(bus->vars); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5690 | bus->vars = NULL; |
| 5691 | } |
| 5692 | |
| 5693 | DHD_TRACE(("%s: Disconnected\n", __func__)); |
| 5694 | } |
| 5695 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5696 | static void brcmf_sdbrcm_disconnect(void *ptr) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5697 | { |
| 5698 | dhd_bus_t *bus = (dhd_bus_t *)ptr; |
| 5699 | |
| 5700 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5701 | |
| 5702 | if (bus) { |
| 5703 | ASSERT(bus->dhd); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5704 | brcmf_sdbrcm_release(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5705 | } |
| 5706 | |
| 5707 | DHD_TRACE(("%s: Disconnected\n", __func__)); |
| 5708 | } |
| 5709 | |
| 5710 | /* Register/Unregister functions are called by the main DHD entry |
| 5711 | * point (e.g. module insertion) to link with the bus driver, in |
| 5712 | * order to look for or await the device. |
| 5713 | */ |
| 5714 | |
Roland Vossen | 8965004 | 2011-06-29 16:47:22 -0700 | [diff] [blame] | 5715 | static struct brcmf_sdioh_driver dhd_sdio = { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5716 | brcmf_sdbrcm_probe, |
| 5717 | brcmf_sdbrcm_disconnect |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5718 | }; |
| 5719 | |
| 5720 | int dhd_bus_register(void) |
| 5721 | { |
| 5722 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5723 | |
Franky Lin | 0827888 | 2011-06-29 16:47:45 -0700 | [diff] [blame] | 5724 | /* Sanity check on the module parameters */ |
| 5725 | do { |
| 5726 | /* Both watchdog and DPC as tasklets are ok */ |
| 5727 | if ((brcmf_watchdog_prio < 0) && (brcmf_dpc_prio < 0)) |
| 5728 | break; |
| 5729 | |
| 5730 | /* If both watchdog and DPC are threads, TX must be deferred */ |
| 5731 | if ((brcmf_watchdog_prio >= 0) && (brcmf_dpc_prio >= 0) |
| 5732 | && brcmf_deferred_tx) |
| 5733 | break; |
| 5734 | |
| 5735 | DHD_ERROR(("Invalid module parameters.\n")); |
| 5736 | return -EINVAL; |
| 5737 | } while (0); |
| 5738 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5739 | return brcmf_sdio_register(&dhd_sdio); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5740 | } |
| 5741 | |
| 5742 | void dhd_bus_unregister(void) |
| 5743 | { |
| 5744 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5745 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5746 | brcmf_sdio_unregister(); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5747 | } |
| 5748 | |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 5749 | static int brcmf_sdbrcm_download_code_file(struct dhd_bus *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5750 | { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5751 | int offset = 0; |
| 5752 | uint len; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 5753 | u8 *memblock = NULL, *memptr; |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 5754 | int ret; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5755 | |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 5756 | DHD_INFO(("%s: Enter\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5757 | |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 5758 | bus->fw_name = BCM4329_FW_NAME; |
| 5759 | ret = request_firmware(&bus->firmware, bus->fw_name, |
| 5760 | &gInstance->func[2]->dev); |
| 5761 | if (ret) { |
| 5762 | DHD_ERROR(("%s: Fail to request firmware %d\n", __func__, ret)); |
| 5763 | return ret; |
| 5764 | } |
| 5765 | bus->fw_ptr = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5766 | |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 5767 | memptr = memblock = kmalloc(MEMBLOCK + BRCMF_SDALIGN, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5768 | if (memblock == NULL) { |
| 5769 | DHD_ERROR(("%s: Failed to allocate memory %d bytes\n", |
| 5770 | __func__, MEMBLOCK)); |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 5771 | ret = -ENOMEM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5772 | goto err; |
| 5773 | } |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 5774 | if ((u32)(unsigned long)memblock % BRCMF_SDALIGN) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5775 | memptr += |
Arend van Spriel | 8d825a8 | 2011-06-29 16:47:25 -0700 | [diff] [blame] | 5776 | (BRCMF_SDALIGN - ((u32)(unsigned long)memblock % BRCMF_SDALIGN)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5777 | |
| 5778 | /* Download image */ |
| 5779 | while ((len = |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 5780 | brcmf_sdbrcm_get_image((char *)memptr, MEMBLOCK, bus))) { |
| 5781 | ret = brcmf_sdbrcm_membytes(bus, true, offset, memptr, len); |
| 5782 | if (ret) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5783 | DHD_ERROR(("%s: error %d on writing %d membytes at " |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 5784 | "0x%08x\n", __func__, ret, MEMBLOCK, offset)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5785 | goto err; |
| 5786 | } |
| 5787 | |
| 5788 | offset += MEMBLOCK; |
| 5789 | } |
| 5790 | |
| 5791 | err: |
Ilia Mirkin | 46d994b | 2011-03-13 00:28:56 -0500 | [diff] [blame] | 5792 | kfree(memblock); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5793 | |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 5794 | release_firmware(bus->firmware); |
| 5795 | bus->fw_ptr = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5796 | |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 5797 | return ret; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5798 | } |
| 5799 | |
| 5800 | /* |
| 5801 | * ProcessVars:Takes a buffer of "<var>=<value>\n" lines read from a file |
| 5802 | * and ending in a NUL. |
| 5803 | * Removes carriage returns, empty lines, comment lines, and converts |
| 5804 | * newlines to NULs. |
| 5805 | * Shortens buffer as needed and pads with NULs. End of buffer is marked |
| 5806 | * by two NULs. |
| 5807 | */ |
| 5808 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5809 | static uint brcmf_process_nvram_vars(char *varbuf, uint len) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5810 | { |
| 5811 | char *dp; |
| 5812 | bool findNewline; |
| 5813 | int column; |
| 5814 | uint buf_len, n; |
| 5815 | |
| 5816 | dp = varbuf; |
| 5817 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5818 | findNewline = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5819 | column = 0; |
| 5820 | |
| 5821 | for (n = 0; n < len; n++) { |
| 5822 | if (varbuf[n] == 0) |
| 5823 | break; |
| 5824 | if (varbuf[n] == '\r') |
| 5825 | continue; |
| 5826 | if (findNewline && varbuf[n] != '\n') |
| 5827 | continue; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5828 | findNewline = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5829 | if (varbuf[n] == '#') { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5830 | findNewline = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5831 | continue; |
| 5832 | } |
| 5833 | if (varbuf[n] == '\n') { |
| 5834 | if (column == 0) |
| 5835 | continue; |
| 5836 | *dp++ = 0; |
| 5837 | column = 0; |
| 5838 | continue; |
| 5839 | } |
| 5840 | *dp++ = varbuf[n]; |
| 5841 | column++; |
| 5842 | } |
| 5843 | buf_len = dp - varbuf; |
| 5844 | |
| 5845 | while (dp < varbuf + n) |
| 5846 | *dp++ = 0; |
| 5847 | |
| 5848 | return buf_len; |
| 5849 | } |
| 5850 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5851 | static int brcmf_sdbrcm_download_nvram(struct dhd_bus *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5852 | { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5853 | uint len; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5854 | char *memblock = NULL; |
| 5855 | char *bufp; |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 5856 | int ret; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5857 | |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 5858 | bus->nv_name = BCM4329_NV_NAME; |
| 5859 | ret = request_firmware(&bus->firmware, bus->nv_name, |
| 5860 | &gInstance->func[2]->dev); |
| 5861 | if (ret) { |
| 5862 | DHD_ERROR(("%s: Fail to request nvram %d\n", __func__, ret)); |
| 5863 | return ret; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5864 | } |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 5865 | bus->fw_ptr = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5866 | |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5867 | memblock = kmalloc(MEMBLOCK, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5868 | if (memblock == NULL) { |
| 5869 | DHD_ERROR(("%s: Failed to allocate memory %d bytes\n", |
| 5870 | __func__, MEMBLOCK)); |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 5871 | ret = -ENOMEM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5872 | goto err; |
| 5873 | } |
| 5874 | |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 5875 | len = brcmf_sdbrcm_get_image(memblock, MEMBLOCK, bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5876 | |
| 5877 | if (len > 0 && len < MEMBLOCK) { |
| 5878 | bufp = (char *)memblock; |
| 5879 | bufp[len] = 0; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5880 | len = brcmf_process_nvram_vars(bufp, len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5881 | bufp += len; |
| 5882 | *bufp++ = 0; |
| 5883 | if (len) |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 5884 | ret = brcmf_sdbrcm_downloadvars(bus, memblock, len + 1); |
| 5885 | if (ret) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5886 | DHD_ERROR(("%s: error downloading vars: %d\n", |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 5887 | __func__, ret)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5888 | } else { |
| 5889 | DHD_ERROR(("%s: error reading nvram file: %d\n", |
| 5890 | __func__, len)); |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 5891 | ret = -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5892 | } |
| 5893 | |
| 5894 | err: |
Ilia Mirkin | 46d994b | 2011-03-13 00:28:56 -0500 | [diff] [blame] | 5895 | kfree(memblock); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5896 | |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 5897 | release_firmware(bus->firmware); |
| 5898 | bus->fw_ptr = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5899 | |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 5900 | return ret; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5901 | } |
| 5902 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5903 | static int _brcmf_sdbrcm_download_firmware(struct dhd_bus *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5904 | { |
| 5905 | int bcmerror = -1; |
| 5906 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5907 | /* Keep arm in reset */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5908 | if (brcmf_sdbrcm_download_state(bus, true)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5909 | DHD_ERROR(("%s: error placing ARM core in reset\n", __func__)); |
| 5910 | goto err; |
| 5911 | } |
| 5912 | |
| 5913 | /* External image takes precedence if specified */ |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 5914 | if (brcmf_sdbrcm_download_code_file(bus)) { |
| 5915 | DHD_ERROR(("%s: dongle image file download failed\n", |
| 5916 | __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5917 | goto err; |
| 5918 | } |
| 5919 | |
| 5920 | /* EXAMPLE: nvram_array */ |
| 5921 | /* If a valid nvram_arry is specified as above, it can be passed |
| 5922 | down to dongle */ |
| 5923 | /* dhd_bus_set_nvram_params(bus, (char *)&nvram_array); */ |
| 5924 | |
| 5925 | /* External nvram takes precedence if specified */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5926 | if (brcmf_sdbrcm_download_nvram(bus)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5927 | DHD_ERROR(("%s: dongle nvram file download failed\n", |
| 5928 | __func__)); |
| 5929 | } |
| 5930 | |
| 5931 | /* Take arm out of reset */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5932 | if (brcmf_sdbrcm_download_state(bus, false)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5933 | DHD_ERROR(("%s: error getting out of ARM core reset\n", |
| 5934 | __func__)); |
| 5935 | goto err; |
| 5936 | } |
| 5937 | |
| 5938 | bcmerror = 0; |
| 5939 | |
| 5940 | err: |
| 5941 | return bcmerror; |
| 5942 | } |
| 5943 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5944 | |
| 5945 | static int |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5946 | 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] | 5947 | u8 *buf, uint nbytes, struct sk_buff *pkt, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5948 | bcmsdh_cmplt_fn_t complete, void *handle) |
| 5949 | { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5950 | return brcmf_sdcard_send_buf |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5951 | (bus->sdh, addr, fn, flags, buf, nbytes, pkt, complete, |
| 5952 | handle); |
| 5953 | } |
| 5954 | |
| 5955 | uint dhd_bus_chip(struct dhd_bus *bus) |
| 5956 | { |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 5957 | ASSERT(bus->ci != NULL); |
| 5958 | return bus->ci->chip; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5959 | } |
| 5960 | |
| 5961 | void *dhd_bus_pub(struct dhd_bus *bus) |
| 5962 | { |
| 5963 | return bus->dhd; |
| 5964 | } |
| 5965 | |
| 5966 | void *dhd_bus_txq(struct dhd_bus *bus) |
| 5967 | { |
| 5968 | return &bus->txq; |
| 5969 | } |
| 5970 | |
| 5971 | uint dhd_bus_hdrlen(struct dhd_bus *bus) |
| 5972 | { |
| 5973 | return SDPCM_HDRLEN; |
| 5974 | } |
| 5975 | |
Arend van Spriel | a84bac4 | 2011-06-29 16:47:10 -0700 | [diff] [blame] | 5976 | int brcmf_bus_devreset(dhd_pub_t *dhdp, u8 flag) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5977 | { |
| 5978 | int bcmerror = 0; |
| 5979 | dhd_bus_t *bus; |
| 5980 | |
| 5981 | bus = dhdp->bus; |
| 5982 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5983 | if (flag == true) { |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 5984 | brcmf_sdbrcm_wd_timer(bus, 0); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5985 | if (!bus->dhd->dongle_reset) { |
| 5986 | /* Expect app to have torn down any |
| 5987 | connection before calling */ |
| 5988 | /* Stop the bus, disable F2 */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5989 | brcmf_sdbrcm_bus_stop(bus, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5990 | |
| 5991 | /* Clean tx/rx buffer pointers, |
| 5992 | detach from the dongle */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 5993 | brcmf_sdbrcm_release_dongle(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5994 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5995 | bus->dhd->dongle_reset = true; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5996 | bus->dhd->up = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5997 | |
| 5998 | DHD_TRACE(("%s: WLAN OFF DONE\n", __func__)); |
| 5999 | /* App can now remove power from device */ |
| 6000 | } else |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 6001 | bcmerror = -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6002 | } else { |
| 6003 | /* App must have restored power to device before calling */ |
| 6004 | |
| 6005 | DHD_TRACE(("\n\n%s: == WLAN ON ==\n", __func__)); |
| 6006 | |
| 6007 | if (bus->dhd->dongle_reset) { |
| 6008 | /* Turn on WLAN */ |
| 6009 | /* Reset SD client */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6010 | brcmf_sdcard_reset(bus->sdh); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6011 | |
| 6012 | /* Attempt to re-attach & download */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6013 | if (brcmf_sdbrcm_probe_attach(bus, bus->sdh, |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 6014 | (u32 *) SI_ENUM_BASE, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6015 | bus->cl_devid)) { |
| 6016 | /* Attempt to download binary to the dongle */ |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 6017 | if (brcmf_sdbrcm_probe_init(bus, bus->sdh)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6018 | /* Re-init bus, enable F2 transfer */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6019 | brcmf_sdbrcm_bus_init( |
| 6020 | (dhd_pub_t *) bus->dhd, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6021 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 6022 | bus->dhd->dongle_reset = false; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 6023 | bus->dhd->up = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6024 | |
| 6025 | DHD_TRACE(("%s: WLAN ON DONE\n", |
| 6026 | __func__)); |
| 6027 | } else |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 6028 | bcmerror = -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6029 | } else |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 6030 | bcmerror = -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6031 | } else { |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 6032 | bcmerror = -EISCONN; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 6033 | DHD_ERROR(("%s: Set DEVRESET=false invoked when device " |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6034 | "is on\n", __func__)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 6035 | bcmerror = -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6036 | } |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 6037 | brcmf_sdbrcm_wd_timer(bus, brcmf_watchdog_ms); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6038 | } |
| 6039 | return bcmerror; |
| 6040 | } |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6041 | |
| 6042 | static int |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 6043 | brcmf_sdbrcm_chip_recognition(struct brcmf_sdio *sdh, struct chip_info *ci, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6044 | void *regs) |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6045 | { |
| 6046 | u32 regdata; |
| 6047 | |
| 6048 | /* |
| 6049 | * Get CC core rev |
| 6050 | * Chipid is assume to be at offset 0 from regs arg |
| 6051 | * For different chiptypes or old sdio hosts w/o chipcommon, |
| 6052 | * other ways of recognition should be added here. |
| 6053 | */ |
| 6054 | ci->cccorebase = (u32)regs; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6055 | regdata = brcmf_sdcard_reg_read(sdh, |
| 6056 | CORE_CC_REG(ci->cccorebase, chipid), 4); |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6057 | ci->chip = regdata & CID_ID_MASK; |
| 6058 | ci->chiprev = (regdata & CID_REV_MASK) >> CID_REV_SHIFT; |
| 6059 | |
| 6060 | DHD_INFO(("%s: chipid=0x%x chiprev=%d\n", |
| 6061 | __func__, ci->chip, ci->chiprev)); |
| 6062 | |
| 6063 | /* Address of cores for new chips should be added here */ |
| 6064 | switch (ci->chip) { |
| 6065 | case BCM4329_CHIP_ID: |
| 6066 | ci->buscorebase = BCM4329_CORE_BUS_BASE; |
| 6067 | ci->ramcorebase = BCM4329_CORE_SOCRAM_BASE; |
| 6068 | ci->armcorebase = BCM4329_CORE_ARM_BASE; |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 6069 | ci->ramsize = BCM4329_RAMSIZE; |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6070 | break; |
| 6071 | default: |
| 6072 | DHD_ERROR(("%s: chipid 0x%x is not supported\n", |
| 6073 | __func__, ci->chip)); |
| 6074 | return -ENODEV; |
| 6075 | } |
| 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_SB(ci->cccorebase, sbidhigh), 4); |
| 6079 | ci->ccrev = SBCOREREV(regdata); |
| 6080 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6081 | regdata = brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6082 | CORE_CC_REG(ci->cccorebase, pmucapabilities), 4); |
| 6083 | ci->pmurev = regdata & PCAP_REV_MASK; |
| 6084 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6085 | regdata = brcmf_sdcard_reg_read(sdh, |
| 6086 | CORE_SB(ci->buscorebase, sbidhigh), 4); |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6087 | ci->buscorerev = SBCOREREV(regdata); |
| 6088 | ci->buscoretype = (regdata & SBIDH_CC_MASK) >> SBIDH_CC_SHIFT; |
| 6089 | |
| 6090 | DHD_INFO(("%s: ccrev=%d, pmurev=%d, buscore rev/type=%d/0x%x\n", |
| 6091 | __func__, ci->ccrev, ci->pmurev, |
| 6092 | ci->buscorerev, ci->buscoretype)); |
| 6093 | |
| 6094 | /* get chipcommon capabilites */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6095 | ci->cccaps = brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6096 | CORE_CC_REG(ci->cccorebase, capabilities), 4); |
| 6097 | |
| 6098 | return 0; |
| 6099 | } |
| 6100 | |
| 6101 | static void |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 6102 | brcmf_sdbrcm_chip_disablecore(struct brcmf_sdio *sdh, u32 corebase) |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6103 | { |
| 6104 | u32 regdata; |
| 6105 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6106 | regdata = brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6107 | CORE_SB(corebase, sbtmstatelow), 4); |
| 6108 | if (regdata & SBTML_RESET) |
| 6109 | return; |
| 6110 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6111 | regdata = brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6112 | CORE_SB(corebase, sbtmstatelow), 4); |
| 6113 | if ((regdata & (SICF_CLOCK_EN << SBTML_SICF_SHIFT)) != 0) { |
| 6114 | /* |
| 6115 | * set target reject and spin until busy is clear |
| 6116 | * (preserve core-specific bits) |
| 6117 | */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6118 | regdata = brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6119 | CORE_SB(corebase, sbtmstatelow), 4); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6120 | brcmf_sdcard_reg_write(sdh, CORE_SB(corebase, sbtmstatelow), 4, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6121 | regdata | SBTML_REJ); |
| 6122 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6123 | regdata = brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6124 | CORE_SB(corebase, sbtmstatelow), 4); |
| 6125 | udelay(1); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6126 | SPINWAIT((brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6127 | CORE_SB(corebase, sbtmstatehigh), 4) & |
| 6128 | SBTMH_BUSY), 100000); |
| 6129 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6130 | regdata = brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6131 | CORE_SB(corebase, sbtmstatehigh), 4); |
| 6132 | if (regdata & SBTMH_BUSY) |
| 6133 | DHD_ERROR(("%s: ARM core still busy\n", __func__)); |
| 6134 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6135 | regdata = brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6136 | CORE_SB(corebase, sbidlow), 4); |
| 6137 | if (regdata & SBIDL_INIT) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6138 | regdata = brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6139 | CORE_SB(corebase, sbimstate), 4) | |
| 6140 | SBIM_RJ; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6141 | brcmf_sdcard_reg_write(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6142 | CORE_SB(corebase, sbimstate), 4, |
| 6143 | regdata); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6144 | regdata = brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6145 | CORE_SB(corebase, sbimstate), 4); |
| 6146 | udelay(1); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6147 | SPINWAIT((brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6148 | CORE_SB(corebase, sbimstate), 4) & |
| 6149 | SBIM_BY), 100000); |
| 6150 | } |
| 6151 | |
| 6152 | /* set reset and reject while enabling the clocks */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6153 | brcmf_sdcard_reg_write(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6154 | CORE_SB(corebase, sbtmstatelow), 4, |
| 6155 | (((SICF_FGC | SICF_CLOCK_EN) << SBTML_SICF_SHIFT) | |
| 6156 | SBTML_REJ | SBTML_RESET)); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6157 | regdata = brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6158 | CORE_SB(corebase, sbtmstatelow), 4); |
| 6159 | udelay(10); |
| 6160 | |
| 6161 | /* clear the initiator reject bit */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6162 | regdata = brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6163 | CORE_SB(corebase, sbidlow), 4); |
| 6164 | if (regdata & SBIDL_INIT) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6165 | regdata = brcmf_sdcard_reg_read(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6166 | CORE_SB(corebase, sbimstate), 4) & |
| 6167 | ~SBIM_RJ; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6168 | brcmf_sdcard_reg_write(sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6169 | CORE_SB(corebase, sbimstate), 4, |
| 6170 | regdata); |
| 6171 | } |
| 6172 | } |
| 6173 | |
| 6174 | /* leave reset and reject asserted */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6175 | brcmf_sdcard_reg_write(sdh, CORE_SB(corebase, sbtmstatelow), 4, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6176 | (SBTML_REJ | SBTML_RESET)); |
| 6177 | udelay(1); |
| 6178 | } |
| 6179 | |
| 6180 | static int |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6181 | brcmf_sdbrcm_chip_attach(struct dhd_bus *bus, void *regs) |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6182 | { |
| 6183 | struct chip_info *ci; |
| 6184 | int err; |
| 6185 | u8 clkval, clkset; |
| 6186 | |
| 6187 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 6188 | |
| 6189 | /* alloc chip_info_t */ |
| 6190 | ci = kmalloc(sizeof(struct chip_info), GFP_ATOMIC); |
| 6191 | if (NULL == ci) { |
| 6192 | DHD_ERROR(("%s: malloc failed!\n", __func__)); |
| 6193 | return -ENOMEM; |
| 6194 | } |
| 6195 | |
| 6196 | memset((unsigned char *)ci, 0, sizeof(struct chip_info)); |
| 6197 | |
| 6198 | /* bus/core/clk setup for register access */ |
| 6199 | /* Try forcing SDIO core to do ALPAvail request only */ |
| 6200 | clkset = SBSDIO_FORCE_HW_CLKREQ_OFF | SBSDIO_ALP_AVAIL_REQ; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6201 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6202 | clkset, &err); |
| 6203 | if (err) { |
| 6204 | DHD_ERROR(("%s: error writing for HT off\n", __func__)); |
| 6205 | goto fail; |
| 6206 | } |
| 6207 | |
| 6208 | /* If register supported, wait for ALPAvail and then force ALP */ |
| 6209 | /* This may take up to 15 milliseconds */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6210 | clkval = 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, NULL); |
| 6212 | if ((clkval & ~SBSDIO_AVBITS) == clkset) { |
| 6213 | SPINWAIT(((clkval = |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6214 | brcmf_sdcard_cfg_read(bus->sdh, SDIO_FUNC_1, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6215 | SBSDIO_FUNC1_CHIPCLKCSR, |
| 6216 | NULL)), |
| 6217 | !SBSDIO_ALPAV(clkval)), |
| 6218 | PMU_MAX_TRANSITION_DLY); |
| 6219 | if (!SBSDIO_ALPAV(clkval)) { |
| 6220 | DHD_ERROR(("%s: timeout on ALPAV wait, clkval 0x%02x\n", |
| 6221 | __func__, clkval)); |
| 6222 | err = -EBUSY; |
| 6223 | goto fail; |
| 6224 | } |
| 6225 | clkset = SBSDIO_FORCE_HW_CLKREQ_OFF | |
| 6226 | SBSDIO_FORCE_ALP; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6227 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_1, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6228 | SBSDIO_FUNC1_CHIPCLKCSR, |
| 6229 | clkset, &err); |
| 6230 | udelay(65); |
| 6231 | } else { |
| 6232 | DHD_ERROR(("%s: ChipClkCSR access: wrote 0x%02x read 0x%02x\n", |
| 6233 | __func__, clkset, clkval)); |
| 6234 | err = -EACCES; |
| 6235 | goto fail; |
| 6236 | } |
| 6237 | |
| 6238 | /* Also, disable the extra SDIO pull-ups */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6239 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_SDIOPULLUP, |
| 6240 | 0, NULL); |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6241 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6242 | err = brcmf_sdbrcm_chip_recognition(bus->sdh, ci, regs); |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6243 | if (err) |
| 6244 | goto fail; |
| 6245 | |
| 6246 | /* |
| 6247 | * Make sure any on-chip ARM is off (in case strapping is wrong), |
| 6248 | * or downloaded code was already running. |
| 6249 | */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6250 | brcmf_sdbrcm_chip_disablecore(bus->sdh, ci->armcorebase); |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6251 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6252 | brcmf_sdcard_reg_write(bus->sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6253 | CORE_CC_REG(ci->cccorebase, gpiopullup), 4, 0); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6254 | brcmf_sdcard_reg_write(bus->sdh, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6255 | CORE_CC_REG(ci->cccorebase, gpiopulldown), 4, 0); |
| 6256 | |
| 6257 | /* Disable F2 to clear any intermediate frame state on the dongle */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6258 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_0, SDIO_CCCR_IOEx, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6259 | SDIO_FUNC_ENABLE_1, NULL); |
| 6260 | |
| 6261 | /* WAR: cmd52 backplane read so core HW will drop ALPReq */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6262 | clkval = brcmf_sdcard_cfg_read(bus->sdh, SDIO_FUNC_1, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6263 | 0, NULL); |
| 6264 | |
| 6265 | /* Done with backplane-dependent accesses, can drop clock... */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6266 | brcmf_sdcard_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 6267 | 0, NULL); |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6268 | |
| 6269 | bus->ci = ci; |
| 6270 | return 0; |
| 6271 | fail: |
| 6272 | bus->ci = NULL; |
| 6273 | kfree(ci); |
| 6274 | return err; |
| 6275 | } |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6276 | |
| 6277 | static void |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 6278 | brcmf_sdbrcm_chip_resetcore(struct brcmf_sdio *sdh, u32 corebase) |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6279 | { |
| 6280 | u32 regdata; |
| 6281 | |
| 6282 | /* |
| 6283 | * Must do the disable sequence first to work for |
| 6284 | * arbitrary current core state. |
| 6285 | */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6286 | brcmf_sdbrcm_chip_disablecore(sdh, corebase); |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6287 | |
| 6288 | /* |
| 6289 | * Now do the initialization sequence. |
| 6290 | * set reset while enabling the clock and |
| 6291 | * forcing them on throughout the core |
| 6292 | */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6293 | brcmf_sdcard_reg_write(sdh, CORE_SB(corebase, sbtmstatelow), 4, |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6294 | ((SICF_FGC | SICF_CLOCK_EN) << SBTML_SICF_SHIFT) | |
| 6295 | SBTML_RESET); |
| 6296 | udelay(1); |
| 6297 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6298 | regdata = brcmf_sdcard_reg_read(sdh, CORE_SB(corebase, sbtmstatehigh), |
| 6299 | 4); |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6300 | if (regdata & SBTMH_SERR) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6301 | brcmf_sdcard_reg_write(sdh, CORE_SB(corebase, sbtmstatehigh), |
| 6302 | 4, 0); |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6303 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6304 | regdata = brcmf_sdcard_reg_read(sdh, CORE_SB(corebase, sbimstate), 4); |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6305 | if (regdata & (SBIM_IBE | SBIM_TO)) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6306 | brcmf_sdcard_reg_write(sdh, CORE_SB(corebase, sbimstate), 4, |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6307 | regdata & ~(SBIM_IBE | SBIM_TO)); |
| 6308 | |
| 6309 | /* clear reset and allow it to propagate throughout the core */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6310 | brcmf_sdcard_reg_write(sdh, CORE_SB(corebase, sbtmstatelow), 4, |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6311 | (SICF_FGC << SBTML_SICF_SHIFT) | |
| 6312 | (SICF_CLOCK_EN << SBTML_SICF_SHIFT)); |
| 6313 | udelay(1); |
| 6314 | |
| 6315 | /* leave clock enabled */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6316 | brcmf_sdcard_reg_write(sdh, CORE_SB(corebase, sbtmstatelow), 4, |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6317 | (SICF_CLOCK_EN << SBTML_SICF_SHIFT)); |
| 6318 | udelay(1); |
| 6319 | } |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 6320 | |
| 6321 | /* SDIO Pad drive strength to select value mappings */ |
| 6322 | struct sdiod_drive_str { |
| 6323 | u8 strength; /* Pad Drive Strength in mA */ |
| 6324 | u8 sel; /* Chip-specific select value */ |
| 6325 | }; |
| 6326 | |
| 6327 | /* SDIO Drive Strength to sel value table for PMU Rev 1 */ |
| 6328 | static const struct sdiod_drive_str sdiod_drive_strength_tab1[] = { |
| 6329 | { |
| 6330 | 4, 0x2}, { |
| 6331 | 2, 0x3}, { |
| 6332 | 1, 0x0}, { |
| 6333 | 0, 0x0} |
| 6334 | }; |
| 6335 | |
| 6336 | /* SDIO Drive Strength to sel value table for PMU Rev 2, 3 */ |
| 6337 | static const struct sdiod_drive_str sdiod_drive_strength_tab2[] = { |
| 6338 | { |
| 6339 | 12, 0x7}, { |
| 6340 | 10, 0x6}, { |
| 6341 | 8, 0x5}, { |
| 6342 | 6, 0x4}, { |
| 6343 | 4, 0x2}, { |
| 6344 | 2, 0x1}, { |
| 6345 | 0, 0x0} |
| 6346 | }; |
| 6347 | |
| 6348 | /* SDIO Drive Strength to sel value table for PMU Rev 8 (1.8V) */ |
| 6349 | static const struct sdiod_drive_str sdiod_drive_strength_tab3[] = { |
| 6350 | { |
| 6351 | 32, 0x7}, { |
| 6352 | 26, 0x6}, { |
| 6353 | 22, 0x5}, { |
| 6354 | 16, 0x4}, { |
| 6355 | 12, 0x3}, { |
| 6356 | 8, 0x2}, { |
| 6357 | 4, 0x1}, { |
| 6358 | 0, 0x0} |
| 6359 | }; |
| 6360 | |
| 6361 | #define SDIOD_DRVSTR_KEY(chip, pmu) (((chip) << 16) | (pmu)) |
| 6362 | |
| 6363 | static void |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6364 | brcmf_sdbrcm_sdiod_drive_strength_init(struct dhd_bus *bus, u32 drivestrength) { |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 6365 | struct sdiod_drive_str *str_tab = NULL; |
| 6366 | u32 str_mask = 0; |
| 6367 | u32 str_shift = 0; |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 6368 | char chn[8]; |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 6369 | |
| 6370 | if (!(bus->ci->cccaps & CC_CAP_PMU)) |
| 6371 | return; |
| 6372 | |
| 6373 | switch (SDIOD_DRVSTR_KEY(bus->ci->chip, bus->ci->pmurev)) { |
| 6374 | case SDIOD_DRVSTR_KEY(BCM4325_CHIP_ID, 1): |
| 6375 | str_tab = (struct sdiod_drive_str *)&sdiod_drive_strength_tab1; |
| 6376 | str_mask = 0x30000000; |
| 6377 | str_shift = 28; |
| 6378 | break; |
| 6379 | case SDIOD_DRVSTR_KEY(BCM4325_CHIP_ID, 2): |
| 6380 | case SDIOD_DRVSTR_KEY(BCM4325_CHIP_ID, 3): |
| 6381 | str_tab = (struct sdiod_drive_str *)&sdiod_drive_strength_tab2; |
| 6382 | str_mask = 0x00003800; |
| 6383 | str_shift = 11; |
| 6384 | break; |
| 6385 | case SDIOD_DRVSTR_KEY(BCM4336_CHIP_ID, 8): |
| 6386 | str_tab = (struct sdiod_drive_str *)&sdiod_drive_strength_tab3; |
| 6387 | str_mask = 0x00003800; |
| 6388 | str_shift = 11; |
| 6389 | break; |
| 6390 | default: |
| 6391 | DHD_ERROR(("No SDIO Drive strength init" |
| 6392 | "done for chip %s rev %d pmurev %d\n", |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 6393 | brcmu_chipname(bus->ci->chip, chn, 8), |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 6394 | bus->ci->chiprev, bus->ci->pmurev)); |
| 6395 | break; |
| 6396 | } |
| 6397 | |
| 6398 | if (str_tab != NULL) { |
| 6399 | u32 drivestrength_sel = 0; |
| 6400 | u32 cc_data_temp; |
| 6401 | int i; |
| 6402 | |
| 6403 | for (i = 0; str_tab[i].strength != 0; i++) { |
| 6404 | if (drivestrength >= str_tab[i].strength) { |
| 6405 | drivestrength_sel = str_tab[i].sel; |
| 6406 | break; |
| 6407 | } |
| 6408 | } |
| 6409 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6410 | brcmf_sdcard_reg_write(bus->sdh, |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 6411 | CORE_CC_REG(bus->ci->cccorebase, chipcontrol_addr), |
| 6412 | 4, 1); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6413 | cc_data_temp = brcmf_sdcard_reg_read(bus->sdh, |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 6414 | CORE_CC_REG(bus->ci->cccorebase, chipcontrol_addr), 4); |
| 6415 | cc_data_temp &= ~str_mask; |
| 6416 | drivestrength_sel <<= str_shift; |
| 6417 | cc_data_temp |= drivestrength_sel; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6418 | brcmf_sdcard_reg_write(bus->sdh, |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 6419 | CORE_CC_REG(bus->ci->cccorebase, chipcontrol_addr), |
| 6420 | 4, cc_data_temp); |
| 6421 | |
| 6422 | DHD_INFO(("SDIO: %dmA drive strength selected, set to 0x%08x\n", |
| 6423 | drivestrength, cc_data_temp)); |
| 6424 | } |
| 6425 | } |
Franky Lin | cee3cf4 | 2011-04-25 19:34:06 -0700 | [diff] [blame] | 6426 | |
| 6427 | static void |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 6428 | brcmf_sdbrcm_chip_detach(struct dhd_bus *bus) |
Franky Lin | cee3cf4 | 2011-04-25 19:34:06 -0700 | [diff] [blame] | 6429 | { |
| 6430 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 6431 | |
| 6432 | kfree(bus->ci); |
| 6433 | bus->ci = NULL; |
| 6434 | } |
Franky Lin | b7adfa7 | 2011-06-29 16:47:42 -0700 | [diff] [blame] | 6435 | |
| 6436 | static void |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 6437 | brcmf_sdbrcm_wait_for_event(dhd_bus_t *bus, bool *lockvar) |
Franky Lin | b7adfa7 | 2011-06-29 16:47:42 -0700 | [diff] [blame] | 6438 | { |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 6439 | brcmf_sdbrcm_sdunlock(bus); |
| 6440 | wait_event_interruptible_timeout(bus->ctrl_wait, |
Franky Lin | b7adfa7 | 2011-06-29 16:47:42 -0700 | [diff] [blame] | 6441 | (*lockvar == false), HZ * 2); |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 6442 | brcmf_sdbrcm_sdlock(bus); |
Franky Lin | b7adfa7 | 2011-06-29 16:47:42 -0700 | [diff] [blame] | 6443 | return; |
| 6444 | } |
| 6445 | |
| 6446 | static void |
| 6447 | brcmf_sdbrcm_wait_event_wakeup(dhd_bus_t *bus) |
| 6448 | { |
| 6449 | if (waitqueue_active(&bus->ctrl_wait)) |
| 6450 | wake_up_interruptible(&bus->ctrl_wait); |
| 6451 | return; |
| 6452 | } |
Franky Lin | ac49553 | 2011-06-29 16:47:43 -0700 | [diff] [blame] | 6453 | |
| 6454 | static int |
| 6455 | brcmf_sdbrcm_watchdog_thread(void *data) |
| 6456 | { |
| 6457 | dhd_bus_t *bus = (dhd_bus_t *)data; |
| 6458 | |
| 6459 | /* This thread doesn't need any user-level access, |
| 6460 | * so get rid of all our resources |
| 6461 | */ |
| 6462 | if (brcmf_watchdog_prio > 0) { |
| 6463 | struct sched_param param; |
| 6464 | param.sched_priority = (brcmf_watchdog_prio < MAX_RT_PRIO) ? |
| 6465 | brcmf_watchdog_prio : (MAX_RT_PRIO - 1); |
| 6466 | sched_setscheduler(current, SCHED_FIFO, ¶m); |
| 6467 | } |
| 6468 | |
| 6469 | allow_signal(SIGTERM); |
| 6470 | /* Run until signal received */ |
| 6471 | while (1) { |
| 6472 | if (kthread_should_stop()) |
| 6473 | break; |
| 6474 | if (!wait_for_completion_interruptible(&bus->watchdog_wait)) { |
| 6475 | if (bus->dhd->dongle_reset == false) |
| 6476 | brcmf_sdbrcm_bus_watchdog(bus->dhd); |
| 6477 | /* Count the tick for reference */ |
| 6478 | bus->dhd->tickcnt++; |
| 6479 | } else |
| 6480 | break; |
| 6481 | } |
| 6482 | return 0; |
| 6483 | } |
| 6484 | |
| 6485 | static void |
| 6486 | brcmf_sdbrcm_watchdog(unsigned long data) |
| 6487 | { |
| 6488 | dhd_bus_t *bus = (dhd_bus_t *)data; |
| 6489 | |
| 6490 | if (brcmf_watchdog_prio >= 0) { |
| 6491 | if (bus->watchdog_tsk) |
| 6492 | complete(&bus->watchdog_wait); |
| 6493 | else |
| 6494 | return; |
| 6495 | } else { |
| 6496 | brcmf_sdbrcm_bus_watchdog(bus->dhd); |
| 6497 | |
| 6498 | /* Count the tick for reference */ |
| 6499 | bus->dhd->tickcnt++; |
| 6500 | } |
| 6501 | |
| 6502 | /* Reschedule the watchdog */ |
| 6503 | if (bus->wd_timer_valid) |
| 6504 | mod_timer(&bus->timer, jiffies + brcmf_watchdog_ms * HZ / 1000); |
| 6505 | } |
| 6506 | |
| 6507 | void |
| 6508 | brcmf_sdbrcm_wd_timer(struct dhd_bus *bus, uint wdtick) |
| 6509 | { |
| 6510 | static uint save_ms; |
| 6511 | |
| 6512 | /* don't start the wd until fw is loaded */ |
| 6513 | if (bus->dhd->busstate == DHD_BUS_DOWN) |
| 6514 | return; |
| 6515 | |
| 6516 | /* Totally stop the timer */ |
| 6517 | if (!wdtick && bus->wd_timer_valid == true) { |
| 6518 | del_timer_sync(&bus->timer); |
| 6519 | bus->wd_timer_valid = false; |
| 6520 | save_ms = wdtick; |
| 6521 | return; |
| 6522 | } |
| 6523 | |
| 6524 | if (wdtick) { |
| 6525 | brcmf_watchdog_ms = (uint) wdtick; |
| 6526 | |
| 6527 | if (save_ms != brcmf_watchdog_ms) { |
| 6528 | if (bus->wd_timer_valid == true) |
| 6529 | /* Stop timer and restart at new value */ |
| 6530 | del_timer_sync(&bus->timer); |
| 6531 | |
| 6532 | /* Create timer again when watchdog period is |
| 6533 | dynamically changed or in the first instance |
| 6534 | */ |
| 6535 | bus->timer.expires = |
| 6536 | jiffies + brcmf_watchdog_ms * HZ / 1000; |
| 6537 | add_timer(&bus->timer); |
| 6538 | |
| 6539 | } else { |
| 6540 | /* Re arm the timer, at last watchdog period */ |
| 6541 | mod_timer(&bus->timer, |
| 6542 | jiffies + brcmf_watchdog_ms * HZ / 1000); |
| 6543 | } |
| 6544 | |
| 6545 | bus->wd_timer_valid = true; |
| 6546 | save_ms = wdtick; |
| 6547 | } |
| 6548 | } |
Franky Lin | 0827888 | 2011-06-29 16:47:45 -0700 | [diff] [blame] | 6549 | |
| 6550 | static int brcmf_sdbrcm_dpc_thread(void *data) |
| 6551 | { |
| 6552 | dhd_bus_t *bus = (dhd_bus_t *) data; |
| 6553 | |
| 6554 | /* This thread doesn't need any user-level access, |
| 6555 | * so get rid of all our resources |
| 6556 | */ |
| 6557 | if (brcmf_dpc_prio > 0) { |
| 6558 | struct sched_param param; |
| 6559 | param.sched_priority = (brcmf_dpc_prio < MAX_RT_PRIO) ? |
| 6560 | brcmf_dpc_prio : (MAX_RT_PRIO - 1); |
| 6561 | sched_setscheduler(current, SCHED_FIFO, ¶m); |
| 6562 | } |
| 6563 | |
| 6564 | allow_signal(SIGTERM); |
| 6565 | /* Run until signal received */ |
| 6566 | while (1) { |
| 6567 | if (kthread_should_stop()) |
| 6568 | break; |
| 6569 | if (!wait_for_completion_interruptible(&bus->dpc_wait)) { |
| 6570 | /* Call bus dpc unless it indicated down |
| 6571 | (then clean stop) */ |
| 6572 | if (bus->dhd->busstate != DHD_BUS_DOWN) { |
| 6573 | if (brcmf_sdbrcm_dpc(bus)) |
| 6574 | complete(&bus->dpc_wait); |
| 6575 | } else { |
| 6576 | brcmf_sdbrcm_bus_stop(bus, true); |
| 6577 | } |
| 6578 | } else |
| 6579 | break; |
| 6580 | } |
| 6581 | return 0; |
| 6582 | } |
| 6583 | |
| 6584 | static void brcmf_sdbrcm_dpc_tasklet(unsigned long data) |
| 6585 | { |
| 6586 | dhd_bus_t *bus = (dhd_bus_t *) data; |
| 6587 | |
| 6588 | /* Call bus dpc unless it indicated down (then clean stop) */ |
| 6589 | if (bus->dhd->busstate != DHD_BUS_DOWN) { |
| 6590 | if (brcmf_sdbrcm_dpc(bus)) |
| 6591 | tasklet_schedule(&bus->tasklet); |
| 6592 | } else |
| 6593 | brcmf_sdbrcm_bus_stop(bus, true); |
| 6594 | } |
| 6595 | |
| 6596 | static void brcmf_sdbrcm_sched_dpc(dhd_bus_t *bus) |
| 6597 | { |
| 6598 | if (bus->dpc_tsk) { |
| 6599 | complete(&bus->dpc_wait); |
| 6600 | return; |
| 6601 | } |
| 6602 | |
| 6603 | tasklet_schedule(&bus->tasklet); |
| 6604 | } |
Franky Lin | 0f37034 | 2011-06-29 16:47:46 -0700 | [diff] [blame] | 6605 | |
| 6606 | static void brcmf_sdbrcm_sdlock(dhd_bus_t *bus) |
| 6607 | { |
| 6608 | if (bus->threads_only) |
| 6609 | down(&bus->sdsem); |
| 6610 | else |
| 6611 | spin_lock_bh(&bus->sdlock); |
| 6612 | } |
| 6613 | |
| 6614 | static void brcmf_sdbrcm_sdunlock(dhd_bus_t *bus) |
| 6615 | { |
| 6616 | if (bus->threads_only) |
| 6617 | up(&bus->sdsem); |
| 6618 | else |
| 6619 | spin_unlock_bh(&bus->sdlock); |
| 6620 | } |
Franky Lin | b7859cd | 2011-06-29 16:47:47 -0700 | [diff] [blame] | 6621 | |
| 6622 | static int brcmf_sdbrcm_get_image(char *buf, int len, struct dhd_bus *bus) |
| 6623 | { |
| 6624 | if (bus->firmware->size < bus->fw_ptr + len) |
| 6625 | len = bus->firmware->size - bus->fw_ptr; |
| 6626 | |
| 6627 | memcpy(buf, &bus->firmware->data[bus->fw_ptr], len); |
| 6628 | bus->fw_ptr += len; |
| 6629 | return len; |
| 6630 | } |
| 6631 | |
| 6632 | MODULE_FIRMWARE(BCM4329_FW_NAME); |
| 6633 | MODULE_FIRMWARE(BCM4329_NV_NAME); |