Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2010 Broadcom Corporation |
| 3 | * |
| 4 | * Permission to use, copy, modify, and/or distribute this software for any |
| 5 | * purpose with or without fee is hereby granted, provided that the above |
| 6 | * copyright notice and this permission notice appear in all copies. |
| 7 | * |
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 11 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
| 13 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 14 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | */ |
| 16 | |
Greg Kroah-Hartman | a1c16ed | 2010-10-21 11:17:44 -0700 | [diff] [blame] | 17 | #include <linux/types.h> |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 18 | #include <linux/kernel.h> |
| 19 | #include <linux/printk.h> |
Stanislav Fomichev | be1c09f | 2011-03-28 01:31:36 +0400 | [diff] [blame] | 20 | #include <linux/pci_ids.h> |
Brett Rudley | c6ac24e | 2010-10-26 11:55:23 -0700 | [diff] [blame] | 21 | #include <linux/netdevice.h> |
Franky Lin | 7c6100e | 2011-06-01 13:45:36 +0200 | [diff] [blame] | 22 | #include <linux/sched.h> |
Franky Lin | 0df4604 | 2011-06-01 13:45:40 +0200 | [diff] [blame] | 23 | #include <linux/mmc/sdio.h> |
Franky Lin | 7c6100e | 2011-06-01 13:45:36 +0200 | [diff] [blame] | 24 | #include <asm/unaligned.h> |
Roland Vossen | cc3cea5 | 2011-06-01 13:45:59 +0200 | [diff] [blame] | 25 | #include <defs.h> |
Roland Vossen | f97e956 | 2011-06-01 13:45:52 +0200 | [diff] [blame] | 26 | #include <brcmu_wifi.h> |
| 27 | #include <brcmu_utils.h> |
Roland Vossen | cc3cea5 | 2011-06-01 13:45:59 +0200 | [diff] [blame] | 28 | #include <brcm_hw_ids.h> |
Roland Vossen | cc3cea5 | 2011-06-01 13:45:59 +0200 | [diff] [blame] | 29 | #include <soc.h> |
Roland Vossen | c4daa84 | 2011-06-09 16:44:50 +0200 | [diff] [blame] | 30 | #include "sdio_host.h" |
Roland Vossen | 4489518 | 2011-06-01 13:45:55 +0200 | [diff] [blame] | 31 | |
| 32 | /* register access macros */ |
Roland Vossen | 4489518 | 2011-06-01 13:45:55 +0200 | [diff] [blame] | 33 | #ifndef __BIG_ENDIAN |
| 34 | #ifndef __mips__ |
Roland Vossen | b61a4be | 2011-06-01 13:45:56 +0200 | [diff] [blame] | 35 | #define R_REG(r) \ |
Roland Vossen | 2503634 | 2011-06-01 13:45:57 +0200 | [diff] [blame] | 36 | bcmsdh_reg_read(NULL, (unsigned long)(r), sizeof(*(r))) |
Roland Vossen | 4489518 | 2011-06-01 13:45:55 +0200 | [diff] [blame] | 37 | #else /* __mips__ */ |
Roland Vossen | b61a4be | 2011-06-01 13:45:56 +0200 | [diff] [blame] | 38 | #define R_REG(r) \ |
| 39 | ({ \ |
| 40 | __typeof(*(r)) __osl_v; \ |
| 41 | __asm__ __volatile__("sync"); \ |
Roland Vossen | 2503634 | 2011-06-01 13:45:57 +0200 | [diff] [blame] | 42 | __osl_v = bcmsdh_reg_read(NULL, (unsigned long)(r),\ |
| 43 | sizeof(*(r))); \ |
Roland Vossen | b61a4be | 2011-06-01 13:45:56 +0200 | [diff] [blame] | 44 | __asm__ __volatile__("sync"); \ |
| 45 | __osl_v; \ |
| 46 | }) |
Roland Vossen | 4489518 | 2011-06-01 13:45:55 +0200 | [diff] [blame] | 47 | #endif /* __mips__ */ |
| 48 | |
| 49 | #define W_REG(r, v) do { \ |
Roland Vossen | 2503634 | 2011-06-01 13:45:57 +0200 | [diff] [blame] | 50 | bcmsdh_reg_write(NULL, (unsigned long)(r), sizeof(*(r)), (v)); \ |
Roland Vossen | 4489518 | 2011-06-01 13:45:55 +0200 | [diff] [blame] | 51 | } while (0) |
| 52 | #else /* __BIG_ENDIAN */ |
Roland Vossen | b61a4be | 2011-06-01 13:45:56 +0200 | [diff] [blame] | 53 | #define R_REG(r) \ |
Roland Vossen | 2503634 | 2011-06-01 13:45:57 +0200 | [diff] [blame] | 54 | bcmsdh_reg_read(NULL, (unsigned long)(r), sizeof(*(r))) |
Roland Vossen | 4489518 | 2011-06-01 13:45:55 +0200 | [diff] [blame] | 55 | #define W_REG(r, v) do { \ |
Roland Vossen | 2503634 | 2011-06-01 13:45:57 +0200 | [diff] [blame] | 56 | bcmsdh_reg_write(NULL, (unsigned long)(r), sizeof(*(r)), (v)); \ |
Roland Vossen | 4489518 | 2011-06-01 13:45:55 +0200 | [diff] [blame] | 57 | } while (0) |
| 58 | #endif /* __BIG_ENDIAN */ |
| 59 | |
Roland Vossen | 4489518 | 2011-06-01 13:45:55 +0200 | [diff] [blame] | 60 | #define AND_REG(r, v) W_REG((r), R_REG(r) & (v)) |
| 61 | #define OR_REG(r, v) W_REG((r), R_REG(r) | (v)) |
| 62 | |
| 63 | #define SET_REG(r, mask, val) \ |
| 64 | W_REG((r), ((R_REG(r) & ~(mask)) | (val))) |
| 65 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 66 | #ifdef DHD_DEBUG |
Roland Vossen | f1c7a08 | 2011-06-01 13:45:09 +0200 | [diff] [blame] | 67 | |
| 68 | /* ARM trap handling */ |
| 69 | |
| 70 | /* Trap types defined by ARM (see arminc.h) */ |
| 71 | |
| 72 | /* Trap locations in lo memory */ |
| 73 | #define TRAP_STRIDE 4 |
| 74 | #define FIRST_TRAP TR_RST |
| 75 | #define LAST_TRAP (TR_FIQ * TRAP_STRIDE) |
| 76 | |
| 77 | #if defined(__ARM_ARCH_4T__) |
| 78 | #define MAX_TRAP_TYPE (TR_FIQ + 1) |
| 79 | #elif defined(__ARM_ARCH_7M__) |
| 80 | #define MAX_TRAP_TYPE (TR_ISR + ARMCM3_NUMINTS) |
| 81 | #endif /* __ARM_ARCH_7M__ */ |
| 82 | |
| 83 | /* The trap structure is defined here as offsets for assembly */ |
| 84 | #define TR_TYPE 0x00 |
| 85 | #define TR_EPC 0x04 |
| 86 | #define TR_CPSR 0x08 |
| 87 | #define TR_SPSR 0x0c |
| 88 | #define TR_REGS 0x10 |
| 89 | #define TR_REG(n) (TR_REGS + (n) * 4) |
| 90 | #define TR_SP TR_REG(13) |
| 91 | #define TR_LR TR_REG(14) |
| 92 | #define TR_PC TR_REG(15) |
| 93 | |
| 94 | #define TRAP_T_SIZE 80 |
| 95 | |
Roland Vossen | f1c7a08 | 2011-06-01 13:45:09 +0200 | [diff] [blame] | 96 | typedef struct _trap_struct { |
| 97 | u32 type; |
| 98 | u32 epc; |
| 99 | u32 cpsr; |
| 100 | u32 spsr; |
| 101 | u32 r0; |
| 102 | u32 r1; |
| 103 | u32 r2; |
| 104 | u32 r3; |
| 105 | u32 r4; |
| 106 | u32 r5; |
| 107 | u32 r6; |
| 108 | u32 r7; |
| 109 | u32 r8; |
| 110 | u32 r9; |
| 111 | u32 r10; |
| 112 | u32 r11; |
| 113 | u32 r12; |
| 114 | u32 r13; |
| 115 | u32 r14; |
| 116 | u32 pc; |
| 117 | } trap_t; |
| 118 | |
Roland Vossen | f1c7a08 | 2011-06-01 13:45:09 +0200 | [diff] [blame] | 119 | #define CBUF_LEN (128) |
| 120 | |
| 121 | #define LOG_BUF_LEN 1024 |
| 122 | |
| 123 | typedef struct { |
| 124 | u32 buf; /* Can't be pointer on (64-bit) hosts */ |
| 125 | uint buf_size; |
| 126 | uint idx; |
| 127 | char *_buf_compat; /* Redundant pointer for backward compat. */ |
| 128 | } rte_log_t; |
| 129 | |
| 130 | typedef struct { |
| 131 | /* Virtual UART |
| 132 | * When there is no UART (e.g. Quickturn), |
| 133 | * the host should write a complete |
| 134 | * input line directly into cbuf and then write |
| 135 | * the length into vcons_in. |
| 136 | * This may also be used when there is a real UART |
| 137 | * (at risk of conflicting with |
| 138 | * the real UART). vcons_out is currently unused. |
| 139 | */ |
| 140 | volatile uint vcons_in; |
| 141 | volatile uint vcons_out; |
| 142 | |
| 143 | /* Output (logging) buffer |
| 144 | * Console output is written to a ring buffer log_buf at index log_idx. |
| 145 | * The host may read the output when it sees log_idx advance. |
| 146 | * Output will be lost if the output wraps around faster than the host |
| 147 | * polls. |
| 148 | */ |
| 149 | rte_log_t log; |
| 150 | |
| 151 | /* Console input line buffer |
| 152 | * Characters are read one at a time into cbuf |
| 153 | * until <CR> is received, then |
| 154 | * the buffer is processed as a command line. |
| 155 | * Also used for virtual UART. |
| 156 | */ |
| 157 | uint cbuf_idx; |
| 158 | char cbuf[CBUF_LEN]; |
| 159 | } rte_cons_t; |
| 160 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 161 | #endif /* DHD_DEBUG */ |
Roland Vossen | 745c9e6 | 2011-06-01 13:45:30 +0200 | [diff] [blame] | 162 | #include <chipcommon.h> |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 163 | |
Roland Vossen | c4daa84 | 2011-06-09 16:44:50 +0200 | [diff] [blame] | 164 | #include "sbsdio.h" |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 165 | |
Roland Vossen | c4daa84 | 2011-06-09 16:44:50 +0200 | [diff] [blame] | 166 | #include "dngl_stats.h" |
| 167 | #include "dhd.h" |
| 168 | #include "dhd_bus.h" |
| 169 | #include "dhd_proto.h" |
| 170 | #include "dhd_dbg.h" |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 171 | #include <sdiovar.h> |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 172 | #include <bcmchip.h> |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 173 | |
| 174 | #ifndef DHDSDIO_MEM_DUMP_FNAME |
| 175 | #define DHDSDIO_MEM_DUMP_FNAME "mem_dump" |
| 176 | #endif |
| 177 | |
Grant Grundler | 26a71a4 | 2011-03-09 10:41:25 -0800 | [diff] [blame] | 178 | #define TXQLEN 2048 /* bulk tx queue length */ |
| 179 | #define TXHI (TXQLEN - 256) /* turn on flow control above TXHI */ |
| 180 | #define TXLOW (TXHI - 256) /* turn off flow control below TXLOW */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 181 | #define PRIOMASK 7 |
| 182 | |
| 183 | #define TXRETRIES 2 /* # of retries for tx frames */ |
| 184 | |
| 185 | #if defined(CONFIG_MACH_SANDGATE2G) |
| 186 | #define DHD_RXBOUND 250 /* Default for max rx frames in |
| 187 | one scheduling */ |
| 188 | #else |
| 189 | #define DHD_RXBOUND 50 /* Default for max rx frames in |
| 190 | one scheduling */ |
| 191 | #endif /* defined(CONFIG_MACH_SANDGATE2G) */ |
| 192 | |
| 193 | #define DHD_TXBOUND 20 /* Default for max tx frames in |
| 194 | one scheduling */ |
| 195 | |
| 196 | #define DHD_TXMINMAX 1 /* Max tx frames if rx still pending */ |
| 197 | |
| 198 | #define MEMBLOCK 2048 /* Block size used for downloading |
| 199 | of dongle image */ |
| 200 | #define MAX_DATA_BUF (32 * 1024) /* Must be large enough to hold |
| 201 | biggest possible glom */ |
| 202 | |
| 203 | /* Packet alignment for most efficient SDIO (can change based on platform) */ |
| 204 | #ifndef DHD_SDALIGN |
| 205 | #define DHD_SDALIGN 32 |
| 206 | #endif |
| 207 | #if !ISPOWEROF2(DHD_SDALIGN) |
| 208 | #error DHD_SDALIGN is not a power of 2! |
| 209 | #endif |
| 210 | |
| 211 | #ifndef DHD_FIRSTREAD |
| 212 | #define DHD_FIRSTREAD 32 |
| 213 | #endif |
| 214 | #if !ISPOWEROF2(DHD_FIRSTREAD) |
| 215 | #error DHD_FIRSTREAD is not a power of 2! |
| 216 | #endif |
| 217 | |
| 218 | /* Total length of frame header for dongle protocol */ |
| 219 | #define SDPCM_HDRLEN (SDPCM_FRAMETAG_LEN + SDPCM_SWHEADER_LEN) |
| 220 | #ifdef SDTEST |
| 221 | #define SDPCM_RESERVE (SDPCM_HDRLEN + SDPCM_TEST_HDRLEN + DHD_SDALIGN) |
| 222 | #else |
| 223 | #define SDPCM_RESERVE (SDPCM_HDRLEN + DHD_SDALIGN) |
| 224 | #endif |
| 225 | |
Franky Lin | b49b14d | 2011-06-01 13:45:37 +0200 | [diff] [blame] | 226 | /* |
| 227 | * Software allocation of To SB Mailbox resources |
| 228 | */ |
| 229 | |
| 230 | /* tosbmailbox bits corresponding to intstatus bits */ |
| 231 | #define SMB_NAK (1 << 0) /* Frame NAK */ |
| 232 | #define SMB_INT_ACK (1 << 1) /* Host Interrupt ACK */ |
| 233 | #define SMB_USE_OOB (1 << 2) /* Use OOB Wakeup */ |
| 234 | #define SMB_DEV_INT (1 << 3) /* Miscellaneous Interrupt */ |
| 235 | |
| 236 | /* tosbmailboxdata */ |
| 237 | #define SMB_DATA_VERSION_SHIFT 16 /* host protocol version */ |
| 238 | |
| 239 | /* |
| 240 | * Software allocation of To Host Mailbox resources |
| 241 | */ |
| 242 | |
| 243 | /* intstatus bits */ |
| 244 | #define I_HMB_FC_STATE I_HMB_SW0 /* Flow Control State */ |
| 245 | #define I_HMB_FC_CHANGE I_HMB_SW1 /* Flow Control State Changed */ |
| 246 | #define I_HMB_FRAME_IND I_HMB_SW2 /* Frame Indication */ |
| 247 | #define I_HMB_HOST_INT I_HMB_SW3 /* Miscellaneous Interrupt */ |
| 248 | |
| 249 | /* tohostmailboxdata */ |
| 250 | #define HMB_DATA_NAKHANDLED 1 /* retransmit NAK'd frame */ |
| 251 | #define HMB_DATA_DEVREADY 2 /* talk to host after enable */ |
| 252 | #define HMB_DATA_FC 4 /* per prio flowcontrol update flag */ |
| 253 | #define HMB_DATA_FWREADY 8 /* fw ready for protocol activity */ |
| 254 | |
| 255 | #define HMB_DATA_FCDATA_MASK 0xff000000 |
| 256 | #define HMB_DATA_FCDATA_SHIFT 24 |
| 257 | |
| 258 | #define HMB_DATA_VERSION_MASK 0x00ff0000 |
| 259 | #define HMB_DATA_VERSION_SHIFT 16 |
| 260 | |
| 261 | /* |
| 262 | * Software-defined protocol header |
| 263 | */ |
| 264 | |
| 265 | /* Current protocol version */ |
| 266 | #define SDPCM_PROT_VERSION 4 |
| 267 | |
| 268 | /* SW frame header */ |
| 269 | #define SDPCM_PACKET_SEQUENCE(p) (((u8 *)p)[0] & 0xff) |
| 270 | |
| 271 | #define SDPCM_CHANNEL_MASK 0x00000f00 |
| 272 | #define SDPCM_CHANNEL_SHIFT 8 |
| 273 | #define SDPCM_PACKET_CHANNEL(p) (((u8 *)p)[1] & 0x0f) |
| 274 | |
| 275 | #define SDPCM_NEXTLEN_OFFSET 2 |
| 276 | |
| 277 | /* Data Offset from SOF (HW Tag, SW Tag, Pad) */ |
| 278 | #define SDPCM_DOFFSET_OFFSET 3 /* Data Offset */ |
| 279 | #define SDPCM_DOFFSET_VALUE(p) (((u8 *)p)[SDPCM_DOFFSET_OFFSET] & 0xff) |
| 280 | #define SDPCM_DOFFSET_MASK 0xff000000 |
| 281 | #define SDPCM_DOFFSET_SHIFT 24 |
| 282 | #define SDPCM_FCMASK_OFFSET 4 /* Flow control */ |
| 283 | #define SDPCM_FCMASK_VALUE(p) (((u8 *)p)[SDPCM_FCMASK_OFFSET] & 0xff) |
| 284 | #define SDPCM_WINDOW_OFFSET 5 /* Credit based fc */ |
| 285 | #define SDPCM_WINDOW_VALUE(p) (((u8 *)p)[SDPCM_WINDOW_OFFSET] & 0xff) |
| 286 | |
| 287 | #define SDPCM_SWHEADER_LEN 8 /* SW header is 64 bits */ |
| 288 | |
| 289 | /* logical channel numbers */ |
| 290 | #define SDPCM_CONTROL_CHANNEL 0 /* Control channel Id */ |
| 291 | #define SDPCM_EVENT_CHANNEL 1 /* Asyc Event Indication Channel Id */ |
| 292 | #define SDPCM_DATA_CHANNEL 2 /* Data Xmit/Recv Channel Id */ |
| 293 | #define SDPCM_GLOM_CHANNEL 3 /* For coalesced packets */ |
| 294 | #define SDPCM_TEST_CHANNEL 15 /* Reserved for test/debug packets */ |
| 295 | |
| 296 | #define SDPCM_SEQUENCE_WRAP 256 /* wrap-around val for 8bit frame seq */ |
| 297 | |
| 298 | #define SDPCM_GLOMDESC(p) (((u8 *)p)[1] & 0x80) |
| 299 | |
| 300 | /* For TEST_CHANNEL packets, define another 4-byte header */ |
| 301 | #define SDPCM_TEST_HDRLEN 4 /* |
| 302 | * Generally: Cmd(1), Ext(1), Len(2); |
| 303 | * Semantics of Ext byte depend on |
| 304 | * command. Len is current or requested |
| 305 | * frame length, not including test |
| 306 | * header; sent little-endian. |
| 307 | */ |
| 308 | #define SDPCM_TEST_DISCARD 0x01 /* Receiver discards. Ext:pattern id. */ |
| 309 | #define SDPCM_TEST_ECHOREQ 0x02 /* Echo request. Ext:pattern id. */ |
| 310 | #define SDPCM_TEST_ECHORSP 0x03 /* Echo response. Ext:pattern id. */ |
| 311 | #define SDPCM_TEST_BURST 0x04 /* |
| 312 | * Receiver to send a burst. |
| 313 | * Ext is a frame count |
| 314 | */ |
| 315 | #define SDPCM_TEST_SEND 0x05 /* |
| 316 | * Receiver sets send mode. |
| 317 | * Ext is boolean on/off |
| 318 | */ |
| 319 | |
| 320 | /* Handy macro for filling in datagen packets with a pattern */ |
| 321 | #define SDPCM_TEST_FILL(byteno, id) ((u8)(id + byteno)) |
| 322 | |
| 323 | /* |
| 324 | * Shared structure between dongle and the host. |
| 325 | * The structure contains pointers to trap or assert information. |
| 326 | */ |
| 327 | #define SDPCM_SHARED_VERSION 0x0002 |
| 328 | #define SDPCM_SHARED_VERSION_MASK 0x00FF |
| 329 | #define SDPCM_SHARED_ASSERT_BUILT 0x0100 |
| 330 | #define SDPCM_SHARED_ASSERT 0x0200 |
| 331 | #define SDPCM_SHARED_TRAP 0x0400 |
| 332 | |
| 333 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 334 | /* Space for header read, limit for data packets */ |
| 335 | #ifndef MAX_HDR_READ |
| 336 | #define MAX_HDR_READ 32 |
| 337 | #endif |
| 338 | #if !ISPOWEROF2(MAX_HDR_READ) |
| 339 | #error MAX_HDR_READ is not a power of 2! |
| 340 | #endif |
| 341 | |
| 342 | #define MAX_RX_DATASZ 2048 |
| 343 | |
| 344 | /* Maximum milliseconds to wait for F2 to come up */ |
| 345 | #define DHD_WAIT_F2RDY 3000 |
| 346 | |
| 347 | /* Bump up limit on waiting for HT to account for first startup; |
| 348 | * if the image is doing a CRC calculation before programming the PMU |
| 349 | * for HT availability, it could take a couple hundred ms more, so |
| 350 | * max out at a 1 second (1000000us). |
| 351 | */ |
| 352 | #if (PMU_MAX_TRANSITION_DLY <= 1000000) |
| 353 | #undef PMU_MAX_TRANSITION_DLY |
| 354 | #define PMU_MAX_TRANSITION_DLY 1000000 |
| 355 | #endif |
| 356 | |
| 357 | /* Value for ChipClockCSR during initial setup */ |
| 358 | #define DHD_INIT_CLKCTL1 (SBSDIO_FORCE_HW_CLKREQ_OFF | \ |
| 359 | SBSDIO_ALP_AVAIL_REQ) |
| 360 | #define DHD_INIT_CLKCTL2 (SBSDIO_FORCE_HW_CLKREQ_OFF | SBSDIO_FORCE_ALP) |
| 361 | |
| 362 | /* Flags for SDH calls */ |
| 363 | #define F2SYNC (SDIO_REQ_4BYTE | SDIO_REQ_FIXED) |
| 364 | |
Roland Vossen | b6fe70c | 2011-06-01 13:45:19 +0200 | [diff] [blame] | 365 | /* sbimstate */ |
| 366 | #define SBIM_IBE 0x20000 /* inbanderror */ |
| 367 | #define SBIM_TO 0x40000 /* timeout */ |
| 368 | #define SBIM_BY 0x01800000 /* busy (sonics >= 2.3) */ |
| 369 | #define SBIM_RJ 0x02000000 /* reject (sonics >= 2.3) */ |
| 370 | |
| 371 | /* sbtmstatelow */ |
| 372 | #define SBTML_RESET 0x0001 /* reset */ |
| 373 | #define SBTML_REJ_MASK 0x0006 /* reject field */ |
| 374 | #define SBTML_REJ 0x0002 /* reject */ |
| 375 | #define SBTML_TMPREJ 0x0004 /* temporary reject, for error recovery */ |
| 376 | |
| 377 | #define SBTML_SICF_SHIFT 16 /* Shift to locate the SI control flags in sbtml */ |
| 378 | |
| 379 | /* sbtmstatehigh */ |
| 380 | #define SBTMH_SERR 0x0001 /* serror */ |
| 381 | #define SBTMH_INT 0x0002 /* interrupt */ |
| 382 | #define SBTMH_BUSY 0x0004 /* busy */ |
| 383 | #define SBTMH_TO 0x0020 /* timeout (sonics >= 2.3) */ |
| 384 | |
| 385 | #define SBTMH_SISF_SHIFT 16 /* Shift to locate the SI status flags in sbtmh */ |
| 386 | |
| 387 | /* sbidlow */ |
| 388 | #define SBIDL_INIT 0x80 /* initiator */ |
| 389 | |
| 390 | /* sbidhigh */ |
| 391 | #define SBIDH_RC_MASK 0x000f /* revision code */ |
| 392 | #define SBIDH_RCE_MASK 0x7000 /* revision code extension field */ |
| 393 | #define SBIDH_RCE_SHIFT 8 |
| 394 | #define SBCOREREV(sbidh) \ |
| 395 | ((((sbidh) & SBIDH_RCE_MASK) >> SBIDH_RCE_SHIFT) | ((sbidh) & SBIDH_RC_MASK)) |
| 396 | #define SBIDH_CC_MASK 0x8ff0 /* core code */ |
| 397 | #define SBIDH_CC_SHIFT 4 |
| 398 | #define SBIDH_VC_MASK 0xffff0000 /* vendor code */ |
| 399 | #define SBIDH_VC_SHIFT 16 |
| 400 | |
Arend van Spriel | 70dfb58 | 2011-02-25 16:39:17 +0100 | [diff] [blame] | 401 | /* |
| 402 | * Conversion of 802.1D priority to precedence level |
| 403 | */ |
| 404 | #define PRIO2PREC(prio) \ |
| 405 | (((prio) == PRIO_8021D_NONE || (prio) == PRIO_8021D_BE) ? \ |
| 406 | ((prio^2)) : (prio)) |
| 407 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 408 | DHD_SPINWAIT_SLEEP_INIT(sdioh_spinwait_sleep); |
| 409 | extern int dhdcdc_set_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf, |
| 410 | uint len); |
| 411 | |
Roland Vossen | b6fe70c | 2011-06-01 13:45:19 +0200 | [diff] [blame] | 412 | /* Core reg address translation */ |
| 413 | #define CORE_CC_REG(base, field) (base + offsetof(chipcregs_t, field)) |
Franky Lin | 597600a | 2011-06-01 13:45:39 +0200 | [diff] [blame] | 414 | #define CORE_BUS_REG(base, field) \ |
| 415 | (base + offsetof(struct sdpcmd_regs, field)) |
Roland Vossen | b6fe70c | 2011-06-01 13:45:19 +0200 | [diff] [blame] | 416 | #define CORE_SB(base, field) \ |
| 417 | (base + SBCONFIGOFF + offsetof(sbconfig_t, field)) |
| 418 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 419 | #ifdef DHD_DEBUG |
| 420 | /* Device console log buffer state */ |
| 421 | typedef struct dhd_console { |
| 422 | uint count; /* Poll interval msec counter */ |
| 423 | uint log_addr; /* Log struct address (fixed) */ |
Roland Vossen | 70963f9 | 2011-06-01 13:45:08 +0200 | [diff] [blame] | 424 | rte_log_t log; /* Log struct (host copy) */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 425 | uint bufsize; /* Size of log buffer */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 426 | u8 *buf; /* Log buffer (host copy) */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 427 | uint last; /* Last buffer read index */ |
| 428 | } dhd_console_t; |
| 429 | #endif /* DHD_DEBUG */ |
| 430 | |
Franky Lin | b49b14d | 2011-06-01 13:45:37 +0200 | [diff] [blame] | 431 | struct sdpcm_shared { |
| 432 | u32 flags; |
| 433 | u32 trap_addr; |
| 434 | u32 assert_exp_addr; |
| 435 | u32 assert_file_addr; |
| 436 | u32 assert_line; |
| 437 | u32 console_addr; /* Address of rte_cons_t */ |
| 438 | u32 msgtrace_addr; |
| 439 | u8 tag[32]; |
| 440 | }; |
| 441 | |
| 442 | |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 443 | /* misc chip info needed by some of the routines */ |
| 444 | struct chip_info { |
| 445 | u32 chip; |
| 446 | u32 chiprev; |
| 447 | u32 cccorebase; |
| 448 | u32 ccrev; |
| 449 | u32 cccaps; |
| 450 | u32 buscorebase; |
| 451 | u32 buscorerev; |
| 452 | u32 buscoretype; |
| 453 | u32 ramcorebase; |
| 454 | u32 armcorebase; |
| 455 | u32 pmurev; |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 456 | u32 ramsize; |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 457 | }; |
| 458 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 459 | /* Private data for SDIO bus interaction */ |
| 460 | typedef struct dhd_bus { |
| 461 | dhd_pub_t *dhd; |
| 462 | |
| 463 | bcmsdh_info_t *sdh; /* Handle for BCMSDH calls */ |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 464 | struct chip_info *ci; /* Chip info struct */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 465 | char *vars; /* Variables (from CIS and/or other) */ |
| 466 | uint varsz; /* Size of variables buffer */ |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 467 | u32 sbaddr; /* Current SB window pointer (-1, invalid) */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 468 | |
Franky Lin | 597600a | 2011-06-01 13:45:39 +0200 | [diff] [blame] | 469 | struct sdpcmd_regs *regs; /* SDIO core */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 470 | uint sdpcmrev; /* SDIO core revision */ |
| 471 | uint armrev; /* CPU core revision */ |
| 472 | uint ramrev; /* SOCRAM core revision */ |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 473 | u32 ramsize; /* Size of RAM in SOCRAM (bytes) */ |
| 474 | u32 orig_ramsize; /* Size of RAM in SOCRAM (bytes) */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 475 | |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 476 | u32 bus; /* gSPI or SDIO bus */ |
| 477 | u32 hostintmask; /* Copy of Host Interrupt Mask */ |
| 478 | u32 intstatus; /* Intstatus bits (events) pending */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 479 | bool dpc_sched; /* Indicates DPC schedule (intrpt rcvd) */ |
| 480 | bool fcstate; /* State of dongle flow-control */ |
| 481 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 482 | u16 cl_devid; /* cached devid for dhdsdio_probe_attach() */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 483 | char *fw_path; /* module_param: path to firmware image */ |
| 484 | char *nv_path; /* module_param: path to nvram vars file */ |
| 485 | const char *nvram_params; /* user specified nvram params. */ |
| 486 | |
| 487 | uint blocksize; /* Block size of SDIO transfers */ |
| 488 | uint roundup; /* Max roundup limit */ |
| 489 | |
| 490 | struct pktq txq; /* Queue length used for flow-control */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 491 | u8 flowcontrol; /* per prio flow control bitmask */ |
| 492 | u8 tx_seq; /* Transmit sequence number (next) */ |
| 493 | u8 tx_max; /* Maximum transmit sequence allowed */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 494 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 495 | u8 hdrbuf[MAX_HDR_READ + DHD_SDALIGN]; |
| 496 | u8 *rxhdr; /* Header of current rx frame (in hdrbuf) */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 497 | u16 nextlen; /* Next Read Len from last header */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 498 | u8 rx_seq; /* Receive sequence number (expected) */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 499 | bool rxskip; /* Skip receive (awaiting NAK ACK) */ |
| 500 | |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 501 | struct sk_buff *glomd; /* Packet containing glomming descriptor */ |
| 502 | struct sk_buff *glom; /* Packet chain for glommed superframe */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 503 | uint glomerr; /* Glom packet read errors */ |
| 504 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 505 | u8 *rxbuf; /* Buffer for receiving control packets */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 506 | uint rxblen; /* Allocated length of rxbuf */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 507 | u8 *rxctl; /* Aligned pointer into rxbuf */ |
| 508 | u8 *databuf; /* Buffer for receiving big glom packet */ |
| 509 | u8 *dataptr; /* Aligned pointer into databuf */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 510 | uint rxlen; /* Length of valid data in buffer */ |
| 511 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 512 | u8 sdpcm_ver; /* Bus protocol reported by dongle */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 513 | |
| 514 | bool intr; /* Use interrupts */ |
| 515 | bool poll; /* Use polling */ |
| 516 | bool ipend; /* Device interrupt is pending */ |
| 517 | bool intdis; /* Interrupts disabled by isr */ |
| 518 | uint intrcount; /* Count of device interrupt callbacks */ |
| 519 | uint lastintrs; /* Count as of last watchdog timer */ |
| 520 | uint spurious; /* Count of spurious interrupts */ |
| 521 | uint pollrate; /* Ticks between device polls */ |
| 522 | uint polltick; /* Tick counter */ |
| 523 | uint pollcnt; /* Count of active polls */ |
| 524 | |
| 525 | #ifdef DHD_DEBUG |
| 526 | dhd_console_t console; /* Console output polling support */ |
| 527 | uint console_addr; /* Console address from shared struct */ |
| 528 | #endif /* DHD_DEBUG */ |
| 529 | |
| 530 | uint regfails; /* Count of R_REG/W_REG failures */ |
| 531 | |
| 532 | uint clkstate; /* State of sd and backplane clock(s) */ |
| 533 | bool activity; /* Activity flag for clock down */ |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 534 | s32 idletime; /* Control for activity timeout */ |
| 535 | s32 idlecount; /* Activity timeout counter */ |
| 536 | s32 idleclock; /* How to set bus driver when idle */ |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 537 | s32 sd_rxchain; /* If bcmsdh api accepts PKT chains */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 538 | bool use_rxchain; /* If dhd should use PKT chains */ |
| 539 | bool sleeping; /* Is SDIO bus sleeping? */ |
| 540 | bool rxflow_mode; /* Rx flow control mode */ |
| 541 | bool rxflow; /* Is rx flow control on */ |
| 542 | uint prev_rxlim_hit; /* Is prev rx limit exceeded |
| 543 | (per dpc schedule) */ |
| 544 | bool alp_only; /* Don't use HT clock (ALP only) */ |
| 545 | /* Field to decide if rx of control frames happen in rxbuf or lb-pool */ |
| 546 | bool usebufpool; |
| 547 | |
| 548 | #ifdef SDTEST |
| 549 | /* external loopback */ |
| 550 | bool ext_loop; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 551 | u8 loopid; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 552 | |
| 553 | /* pktgen configuration */ |
| 554 | uint pktgen_freq; /* Ticks between bursts */ |
| 555 | uint pktgen_count; /* Packets to send each burst */ |
| 556 | uint pktgen_print; /* Bursts between count displays */ |
| 557 | uint pktgen_total; /* Stop after this many */ |
| 558 | uint pktgen_minlen; /* Minimum packet data len */ |
| 559 | uint pktgen_maxlen; /* Maximum packet data len */ |
| 560 | uint pktgen_mode; /* Configured mode: tx, rx, or echo */ |
| 561 | uint pktgen_stop; /* Number of tx failures causing stop */ |
| 562 | |
| 563 | /* active pktgen fields */ |
| 564 | uint pktgen_tick; /* Tick counter for bursts */ |
| 565 | uint pktgen_ptick; /* Burst counter for printing */ |
| 566 | uint pktgen_sent; /* Number of test packets generated */ |
| 567 | uint pktgen_rcvd; /* Number of test packets received */ |
| 568 | uint pktgen_fail; /* Number of failed send attempts */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 569 | u16 pktgen_len; /* Length of next packet to send */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 570 | #endif /* SDTEST */ |
| 571 | |
| 572 | /* Some additional counters */ |
| 573 | uint tx_sderrs; /* Count of tx attempts with sd errors */ |
| 574 | uint fcqueued; /* Tx packets that got queued */ |
| 575 | uint rxrtx; /* Count of rtx requests (NAK to dongle) */ |
| 576 | uint rx_toolong; /* Receive frames too long to receive */ |
| 577 | uint rxc_errors; /* SDIO errors when reading control frames */ |
| 578 | uint rx_hdrfail; /* SDIO errors on header reads */ |
| 579 | uint rx_badhdr; /* Bad received headers (roosync?) */ |
| 580 | uint rx_badseq; /* Mismatched rx sequence number */ |
| 581 | uint fc_rcvd; /* Number of flow-control events received */ |
| 582 | uint fc_xoff; /* Number which turned on flow-control */ |
| 583 | uint fc_xon; /* Number which turned off flow-control */ |
| 584 | uint rxglomfail; /* Failed deglom attempts */ |
| 585 | uint rxglomframes; /* Number of glom frames (superframes) */ |
| 586 | uint rxglompkts; /* Number of packets from glom frames */ |
| 587 | uint f2rxhdrs; /* Number of header reads */ |
| 588 | uint f2rxdata; /* Number of frame data reads */ |
| 589 | uint f2txdata; /* Number of f2 frame writes */ |
| 590 | uint f1regdata; /* Number of f1 register accesses */ |
| 591 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 592 | u8 *ctrl_frame_buf; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 593 | u32 ctrl_frame_len; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 594 | bool ctrl_frame_stat; |
Franky Lin | 0f1a87c | 2011-06-29 16:46:32 -0700 | [diff] [blame^] | 595 | |
| 596 | spinlock_t txqlock; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 597 | } dhd_bus_t; |
| 598 | |
Roland Vossen | b6fe70c | 2011-06-01 13:45:19 +0200 | [diff] [blame] | 599 | typedef volatile struct _sbconfig { |
| 600 | u32 PAD[2]; |
| 601 | u32 sbipsflag; /* initiator port ocp slave flag */ |
| 602 | u32 PAD[3]; |
| 603 | u32 sbtpsflag; /* target port ocp slave flag */ |
| 604 | u32 PAD[11]; |
| 605 | u32 sbtmerrloga; /* (sonics >= 2.3) */ |
| 606 | u32 PAD; |
| 607 | u32 sbtmerrlog; /* (sonics >= 2.3) */ |
| 608 | u32 PAD[3]; |
| 609 | u32 sbadmatch3; /* address match3 */ |
| 610 | u32 PAD; |
| 611 | u32 sbadmatch2; /* address match2 */ |
| 612 | u32 PAD; |
| 613 | u32 sbadmatch1; /* address match1 */ |
| 614 | u32 PAD[7]; |
| 615 | u32 sbimstate; /* initiator agent state */ |
| 616 | u32 sbintvec; /* interrupt mask */ |
| 617 | u32 sbtmstatelow; /* target state */ |
| 618 | u32 sbtmstatehigh; /* target state */ |
| 619 | u32 sbbwa0; /* bandwidth allocation table0 */ |
| 620 | u32 PAD; |
| 621 | u32 sbimconfiglow; /* initiator configuration */ |
| 622 | u32 sbimconfighigh; /* initiator configuration */ |
| 623 | u32 sbadmatch0; /* address match0 */ |
| 624 | u32 PAD; |
| 625 | u32 sbtmconfiglow; /* target configuration */ |
| 626 | u32 sbtmconfighigh; /* target configuration */ |
| 627 | u32 sbbconfig; /* broadcast configuration */ |
| 628 | u32 PAD; |
| 629 | u32 sbbstate; /* broadcast state */ |
| 630 | u32 PAD[3]; |
| 631 | u32 sbactcnfg; /* activate configuration */ |
| 632 | u32 PAD[3]; |
| 633 | u32 sbflagst; /* current sbflags */ |
| 634 | u32 PAD[3]; |
| 635 | u32 sbidlow; /* identification */ |
| 636 | u32 sbidhigh; /* identification */ |
| 637 | } sbconfig_t; |
| 638 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 639 | /* clkstate */ |
| 640 | #define CLK_NONE 0 |
| 641 | #define CLK_SDONLY 1 |
| 642 | #define CLK_PENDING 2 /* Not used yet */ |
| 643 | #define CLK_AVAIL 3 |
| 644 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 645 | #define DHD_NOPMU(dhd) (false) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 646 | |
| 647 | #ifdef DHD_DEBUG |
| 648 | static int qcount[NUMPRIO]; |
| 649 | static int tx_packets[NUMPRIO]; |
| 650 | #endif /* DHD_DEBUG */ |
| 651 | |
| 652 | /* Deferred transmit */ |
| 653 | const uint dhd_deferred_tx = 1; |
| 654 | |
| 655 | extern uint dhd_watchdog_ms; |
| 656 | extern void dhd_os_wd_timer(void *bus, uint wdtick); |
| 657 | |
| 658 | /* Tx/Rx bounds */ |
| 659 | uint dhd_txbound; |
| 660 | uint dhd_rxbound; |
| 661 | uint dhd_txminmax; |
| 662 | |
| 663 | /* override the RAM size if possible */ |
| 664 | #define DONGLE_MIN_MEMSIZE (128 * 1024) |
| 665 | int dhd_dongle_memsize; |
| 666 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 667 | static bool dhd_alignctl; |
| 668 | |
| 669 | static bool sd1idle; |
| 670 | |
| 671 | static bool retrydata; |
| 672 | #define RETRYCHAN(chan) (((chan) == SDPCM_EVENT_CHANNEL) || retrydata) |
| 673 | |
| 674 | static const uint watermark = 8; |
| 675 | static const uint firstread = DHD_FIRSTREAD; |
| 676 | |
| 677 | #define HDATLEN (firstread - (SDPCM_HDRLEN)) |
| 678 | |
| 679 | /* Retry count for register access failures */ |
| 680 | static const uint retry_limit = 2; |
| 681 | |
| 682 | /* Force even SD lengths (some host controllers mess up on odd bytes) */ |
| 683 | static bool forcealign; |
| 684 | |
| 685 | #define ALIGNMENT 4 |
| 686 | |
| 687 | #if defined(OOB_INTR_ONLY) && defined(HW_OOB) |
| 688 | extern void bcmsdh_enable_hw_oob_intr(void *sdh, bool enable); |
| 689 | #endif |
| 690 | |
| 691 | #if defined(OOB_INTR_ONLY) && defined(SDIO_ISR_THREAD) |
| 692 | #error OOB_INTR_ONLY is NOT working with SDIO_ISR_THREAD |
| 693 | #endif /* defined(OOB_INTR_ONLY) && defined(SDIO_ISR_THREAD) */ |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 694 | #define PKTALIGN(_p, _len, _align) \ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 695 | do { \ |
| 696 | uint datalign; \ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 697 | datalign = (unsigned long)((_p)->data); \ |
| 698 | datalign = roundup(datalign, (_align)) - datalign; \ |
| 699 | ASSERT(datalign < (_align)); \ |
| 700 | ASSERT((_p)->len >= ((_len) + datalign)); \ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 701 | if (datalign) \ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 702 | skb_pull((_p), datalign); \ |
| 703 | __skb_trim((_p), (_len)); \ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 704 | } while (0) |
| 705 | |
| 706 | /* Limit on rounding up frames */ |
| 707 | static const uint max_roundup = 512; |
| 708 | |
| 709 | /* Try doing readahead */ |
| 710 | static bool dhd_readahead; |
| 711 | |
| 712 | /* To check if there's window offered */ |
| 713 | #define DATAOK(bus) \ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 714 | (((u8)(bus->tx_max - bus->tx_seq) != 0) && \ |
| 715 | (((u8)(bus->tx_max - bus->tx_seq) & 0x80) == 0)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 716 | |
| 717 | /* Macros to get register read/write status */ |
| 718 | /* NOTE: these assume a local dhdsdio_bus_t *bus! */ |
| 719 | #define R_SDREG(regvar, regaddr, retryvar) \ |
| 720 | do { \ |
| 721 | retryvar = 0; \ |
| 722 | do { \ |
Arend van Spriel | ff31c54 | 2011-03-01 10:56:54 +0100 | [diff] [blame] | 723 | regvar = R_REG(regaddr); \ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 724 | } while (bcmsdh_regfail(bus->sdh) && (++retryvar <= retry_limit)); \ |
| 725 | if (retryvar) { \ |
| 726 | bus->regfails += (retryvar-1); \ |
| 727 | if (retryvar > retry_limit) { \ |
| 728 | DHD_ERROR(("%s: FAILED" #regvar "READ, LINE %d\n", \ |
| 729 | __func__, __LINE__)); \ |
| 730 | regvar = 0; \ |
| 731 | } \ |
| 732 | } \ |
| 733 | } while (0) |
| 734 | |
| 735 | #define W_SDREG(regval, regaddr, retryvar) \ |
| 736 | do { \ |
| 737 | retryvar = 0; \ |
| 738 | do { \ |
Arend van Spriel | ff31c54 | 2011-03-01 10:56:54 +0100 | [diff] [blame] | 739 | W_REG(regaddr, regval); \ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 740 | } while (bcmsdh_regfail(bus->sdh) && (++retryvar <= retry_limit)); \ |
| 741 | if (retryvar) { \ |
| 742 | bus->regfails += (retryvar-1); \ |
| 743 | if (retryvar > retry_limit) \ |
| 744 | DHD_ERROR(("%s: FAILED REGISTER WRITE, LINE %d\n", \ |
| 745 | __func__, __LINE__)); \ |
| 746 | } \ |
| 747 | } while (0) |
| 748 | |
| 749 | #define DHD_BUS SDIO_BUS |
| 750 | |
| 751 | #define PKT_AVAILABLE() (intstatus & I_HMB_FRAME_IND) |
| 752 | |
| 753 | #define HOSTINTMASK (I_HMB_SW_MASK | I_CHIPACTIVE) |
| 754 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 755 | #ifdef SDTEST |
| 756 | static void dhdsdio_testrcv(dhd_bus_t *bus, void *pkt, uint seq); |
| 757 | static void dhdsdio_sdtest_set(dhd_bus_t *bus, bool start); |
| 758 | #endif |
| 759 | |
| 760 | #ifdef DHD_DEBUG |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 761 | static int dhdsdio_checkdied(dhd_bus_t *bus, u8 *data, uint size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 762 | static int dhdsdio_mem_dump(dhd_bus_t *bus); |
| 763 | #endif /* DHD_DEBUG */ |
| 764 | static int dhdsdio_download_state(dhd_bus_t *bus, bool enter); |
| 765 | |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 766 | static void dhdsdio_release(dhd_bus_t *bus); |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 767 | static void dhdsdio_release_malloc(dhd_bus_t *bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 768 | static void dhdsdio_disconnect(void *ptr); |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 769 | static bool dhdsdio_chipmatch(u16 chipid); |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 770 | static bool dhdsdio_probe_attach(dhd_bus_t *bus, void *sdh, |
| 771 | void *regsva, u16 devid); |
| 772 | static bool dhdsdio_probe_malloc(dhd_bus_t *bus, void *sdh); |
| 773 | static bool dhdsdio_probe_init(dhd_bus_t *bus, void *sdh); |
| 774 | static void dhdsdio_release_dongle(dhd_bus_t *bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 775 | |
| 776 | static uint process_nvram_vars(char *varbuf, uint len); |
| 777 | |
| 778 | static void dhd_dongle_setmemsize(struct dhd_bus *bus, int mem_size); |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 779 | static int dhd_bcmsdh_send_buf(dhd_bus_t *bus, u32 addr, uint fn, |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 780 | uint flags, u8 *buf, uint nbytes, |
| 781 | struct sk_buff *pkt, bcmsdh_cmplt_fn_t complete, |
| 782 | void *handle); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 783 | |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 784 | static bool dhdsdio_download_firmware(struct dhd_bus *bus, void *sdh); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 785 | static int _dhdsdio_download_firmware(struct dhd_bus *bus); |
| 786 | |
| 787 | static int dhdsdio_download_code_file(struct dhd_bus *bus, char *image_path); |
| 788 | static int dhdsdio_download_nvram(struct dhd_bus *bus); |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 789 | static void dhdsdio_chip_disablecore(bcmsdh_info_t *sdh, u32 corebase); |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 790 | static int dhdsdio_chip_attach(struct dhd_bus *bus, void *regs); |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 791 | static void dhdsdio_chip_resetcore(bcmsdh_info_t *sdh, u32 corebase); |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 792 | static void dhdsdio_sdiod_drive_strength_init(struct dhd_bus *bus, |
| 793 | u32 drivestrength); |
Franky Lin | cee3cf4 | 2011-04-25 19:34:06 -0700 | [diff] [blame] | 794 | static void dhdsdio_chip_detach(struct dhd_bus *bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 795 | |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 796 | /* Packet free applicable unconditionally for sdio and sdspi. |
| 797 | * Conditional if bufpool was present for gspi bus. |
| 798 | */ |
| 799 | static void dhdsdio_pktfree2(dhd_bus_t *bus, struct sk_buff *pkt) |
| 800 | { |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 801 | if ((bus->bus != SPI_BUS) || bus->usebufpool) |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 802 | brcmu_pkt_buf_free_skb(pkt); |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 803 | } |
| 804 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 805 | static void dhd_dongle_setmemsize(struct dhd_bus *bus, int mem_size) |
| 806 | { |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 807 | s32 min_size = DONGLE_MIN_MEMSIZE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 808 | /* Restrict the memsize to user specified limit */ |
| 809 | DHD_ERROR(("user: Restrict the dongle ram size to %d, min %d\n", |
| 810 | dhd_dongle_memsize, min_size)); |
| 811 | if ((dhd_dongle_memsize > min_size) && |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 812 | (dhd_dongle_memsize < (s32) bus->orig_ramsize)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 813 | bus->ramsize = dhd_dongle_memsize; |
| 814 | } |
| 815 | |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 816 | static int dhdsdio_set_siaddr_window(dhd_bus_t *bus, u32 address) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 817 | { |
| 818 | int err = 0; |
| 819 | bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRLOW, |
| 820 | (address >> 8) & SBSDIO_SBADDRLOW_MASK, &err); |
| 821 | if (!err) |
| 822 | bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRMID, |
| 823 | (address >> 16) & SBSDIO_SBADDRMID_MASK, &err); |
| 824 | if (!err) |
| 825 | bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRHIGH, |
| 826 | (address >> 24) & SBSDIO_SBADDRHIGH_MASK, |
| 827 | &err); |
| 828 | return err; |
| 829 | } |
| 830 | |
| 831 | /* Turn backplane clock on or off */ |
| 832 | static int dhdsdio_htclk(dhd_bus_t *bus, bool on, bool pendok) |
| 833 | { |
| 834 | int err; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 835 | u8 clkctl, clkreq, devctl; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 836 | bcmsdh_info_t *sdh; |
| 837 | |
| 838 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 839 | |
| 840 | #if defined(OOB_INTR_ONLY) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 841 | pendok = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 842 | #endif |
| 843 | clkctl = 0; |
| 844 | sdh = bus->sdh; |
| 845 | |
| 846 | if (on) { |
| 847 | /* Request HT Avail */ |
| 848 | clkreq = |
| 849 | bus->alp_only ? SBSDIO_ALP_AVAIL_REQ : SBSDIO_HT_AVAIL_REQ; |
| 850 | |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 851 | if ((bus->ci->chip == BCM4329_CHIP_ID) |
| 852 | && (bus->ci->chiprev == 0)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 853 | clkreq |= SBSDIO_FORCE_ALP; |
| 854 | |
| 855 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 856 | clkreq, &err); |
| 857 | if (err) { |
| 858 | DHD_ERROR(("%s: HT Avail request error: %d\n", |
| 859 | __func__, err)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 860 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 861 | } |
| 862 | |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 863 | if (pendok && ((bus->ci->buscoretype == PCMCIA_CORE_ID) |
| 864 | && (bus->ci->buscorerev == 9))) { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 865 | u32 dummy, retries; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 866 | R_SDREG(dummy, &bus->regs->clockctlstatus, retries); |
| 867 | } |
| 868 | |
| 869 | /* Check current status */ |
| 870 | clkctl = |
| 871 | bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 872 | &err); |
| 873 | if (err) { |
| 874 | DHD_ERROR(("%s: HT Avail read error: %d\n", |
| 875 | __func__, err)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 876 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | /* Go to pending and await interrupt if appropriate */ |
| 880 | if (!SBSDIO_CLKAV(clkctl, bus->alp_only) && pendok) { |
| 881 | /* Allow only clock-available interrupt */ |
| 882 | devctl = |
| 883 | bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL, |
| 884 | &err); |
| 885 | if (err) { |
| 886 | DHD_ERROR(("%s: Devctl error setting CA: %d\n", |
| 887 | __func__, err)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 888 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 889 | } |
| 890 | |
| 891 | devctl |= SBSDIO_DEVCTL_CA_INT_ONLY; |
| 892 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL, |
| 893 | devctl, &err); |
| 894 | DHD_INFO(("CLKCTL: set PENDING\n")); |
| 895 | bus->clkstate = CLK_PENDING; |
| 896 | |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 897 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 898 | } else if (bus->clkstate == CLK_PENDING) { |
| 899 | /* Cancel CA-only interrupt filter */ |
| 900 | devctl = |
| 901 | bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL, |
| 902 | &err); |
| 903 | devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY; |
| 904 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL, |
| 905 | devctl, &err); |
| 906 | } |
| 907 | |
| 908 | /* Otherwise, wait here (polling) for HT Avail */ |
| 909 | if (!SBSDIO_CLKAV(clkctl, bus->alp_only)) { |
| 910 | SPINWAIT_SLEEP(sdioh_spinwait_sleep, |
| 911 | ((clkctl = |
| 912 | bcmsdh_cfg_read(sdh, SDIO_FUNC_1, |
| 913 | SBSDIO_FUNC1_CHIPCLKCSR, |
| 914 | &err)), |
| 915 | !SBSDIO_CLKAV(clkctl, bus->alp_only)), |
| 916 | PMU_MAX_TRANSITION_DLY); |
| 917 | } |
| 918 | if (err) { |
| 919 | DHD_ERROR(("%s: HT Avail request error: %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 | if (!SBSDIO_CLKAV(clkctl, bus->alp_only)) { |
| 924 | DHD_ERROR(("%s: HT Avail timeout (%d): clkctl 0x%02x\n", |
| 925 | __func__, PMU_MAX_TRANSITION_DLY, clkctl)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 926 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 927 | } |
| 928 | |
| 929 | /* Mark clock available */ |
| 930 | bus->clkstate = CLK_AVAIL; |
| 931 | DHD_INFO(("CLKCTL: turned ON\n")); |
| 932 | |
| 933 | #if defined(DHD_DEBUG) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 934 | if (bus->alp_only == true) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 935 | #if !defined(BCMLXSDMMC) |
| 936 | if (!SBSDIO_ALPONLY(clkctl)) { |
| 937 | DHD_ERROR(("%s: HT Clock, when ALP Only\n", |
| 938 | __func__)); |
| 939 | } |
| 940 | #endif /* !defined(BCMLXSDMMC) */ |
| 941 | } else { |
| 942 | if (SBSDIO_ALPONLY(clkctl)) { |
| 943 | DHD_ERROR(("%s: HT Clock should be on.\n", |
| 944 | __func__)); |
| 945 | } |
| 946 | } |
| 947 | #endif /* defined (DHD_DEBUG) */ |
| 948 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 949 | bus->activity = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 950 | } else { |
| 951 | clkreq = 0; |
| 952 | |
| 953 | if (bus->clkstate == CLK_PENDING) { |
| 954 | /* Cancel CA-only interrupt filter */ |
| 955 | devctl = |
| 956 | bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL, |
| 957 | &err); |
| 958 | devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY; |
| 959 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL, |
| 960 | devctl, &err); |
| 961 | } |
| 962 | |
| 963 | bus->clkstate = CLK_SDONLY; |
| 964 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 965 | clkreq, &err); |
| 966 | DHD_INFO(("CLKCTL: turned OFF\n")); |
| 967 | if (err) { |
| 968 | DHD_ERROR(("%s: Failed access turning clock off: %d\n", |
| 969 | __func__, err)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 970 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 971 | } |
| 972 | } |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 973 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | /* Change idle/active SD state */ |
| 977 | static int dhdsdio_sdclk(dhd_bus_t *bus, bool on) |
| 978 | { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 979 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 980 | |
Franky Lin | 602a8ab | 2011-06-01 13:45:04 +0200 | [diff] [blame] | 981 | if (on) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 982 | bus->clkstate = CLK_SDONLY; |
Franky Lin | 602a8ab | 2011-06-01 13:45:04 +0200 | [diff] [blame] | 983 | else |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 984 | bus->clkstate = CLK_NONE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 985 | |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 986 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 987 | } |
| 988 | |
| 989 | /* Transition SD and backplane clock readiness */ |
| 990 | static int dhdsdio_clkctl(dhd_bus_t *bus, uint target, bool pendok) |
| 991 | { |
| 992 | #ifdef DHD_DEBUG |
| 993 | uint oldstate = bus->clkstate; |
| 994 | #endif /* DHD_DEBUG */ |
| 995 | |
| 996 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 997 | |
| 998 | /* Early exit if we're already there */ |
| 999 | if (bus->clkstate == target) { |
| 1000 | if (target == CLK_AVAIL) { |
| 1001 | dhd_os_wd_timer(bus->dhd, dhd_watchdog_ms); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1002 | bus->activity = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1003 | } |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 1004 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | switch (target) { |
| 1008 | case CLK_AVAIL: |
| 1009 | /* Make sure SD clock is available */ |
| 1010 | if (bus->clkstate == CLK_NONE) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1011 | dhdsdio_sdclk(bus, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1012 | /* Now request HT Avail on the backplane */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1013 | dhdsdio_htclk(bus, true, pendok); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1014 | dhd_os_wd_timer(bus->dhd, dhd_watchdog_ms); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1015 | bus->activity = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1016 | break; |
| 1017 | |
| 1018 | case CLK_SDONLY: |
| 1019 | /* Remove HT request, or bring up SD clock */ |
| 1020 | if (bus->clkstate == CLK_NONE) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1021 | dhdsdio_sdclk(bus, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1022 | else if (bus->clkstate == CLK_AVAIL) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1023 | dhdsdio_htclk(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1024 | else |
| 1025 | DHD_ERROR(("dhdsdio_clkctl: request for %d -> %d\n", |
| 1026 | bus->clkstate, target)); |
| 1027 | dhd_os_wd_timer(bus->dhd, dhd_watchdog_ms); |
| 1028 | break; |
| 1029 | |
| 1030 | case CLK_NONE: |
| 1031 | /* Make sure to remove HT request */ |
| 1032 | if (bus->clkstate == CLK_AVAIL) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1033 | dhdsdio_htclk(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1034 | /* Now remove the SD clock */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1035 | dhdsdio_sdclk(bus, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1036 | dhd_os_wd_timer(bus->dhd, 0); |
| 1037 | break; |
| 1038 | } |
| 1039 | #ifdef DHD_DEBUG |
| 1040 | DHD_INFO(("dhdsdio_clkctl: %d -> %d\n", oldstate, bus->clkstate)); |
| 1041 | #endif /* DHD_DEBUG */ |
| 1042 | |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 1043 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1044 | } |
| 1045 | |
| 1046 | int dhdsdio_bussleep(dhd_bus_t *bus, bool sleep) |
| 1047 | { |
| 1048 | bcmsdh_info_t *sdh = bus->sdh; |
Franky Lin | 597600a | 2011-06-01 13:45:39 +0200 | [diff] [blame] | 1049 | struct sdpcmd_regs *regs = bus->regs; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1050 | uint retries = 0; |
| 1051 | |
| 1052 | DHD_INFO(("dhdsdio_bussleep: request %s (currently %s)\n", |
| 1053 | (sleep ? "SLEEP" : "WAKE"), |
| 1054 | (bus->sleeping ? "SLEEP" : "WAKE"))); |
| 1055 | |
| 1056 | /* Done if we're already in the requested state */ |
| 1057 | if (sleep == bus->sleeping) |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 1058 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1059 | |
| 1060 | /* Going to sleep: set the alarm and turn off the lights... */ |
| 1061 | if (sleep) { |
| 1062 | /* Don't sleep if something is pending */ |
| 1063 | if (bus->dpc_sched || bus->rxskip || pktq_len(&bus->txq)) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 1064 | return -EBUSY; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1065 | |
| 1066 | /* Disable SDIO interrupts (no longer interested) */ |
| 1067 | bcmsdh_intr_disable(bus->sdh); |
| 1068 | |
| 1069 | /* Make sure the controller has the bus up */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1070 | dhdsdio_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1071 | |
| 1072 | /* Tell device to start using OOB wakeup */ |
| 1073 | W_SDREG(SMB_USE_OOB, ®s->tosbmailbox, retries); |
| 1074 | if (retries > retry_limit) |
| 1075 | DHD_ERROR(("CANNOT SIGNAL CHIP, WILL NOT WAKE UP!!\n")); |
| 1076 | |
| 1077 | /* Turn off our contribution to the HT clock request */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1078 | dhdsdio_clkctl(bus, CLK_SDONLY, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1079 | |
| 1080 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 1081 | SBSDIO_FORCE_HW_CLKREQ_OFF, NULL); |
| 1082 | |
| 1083 | /* Isolate the bus */ |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 1084 | if (bus->ci->chip != BCM4329_CHIP_ID |
| 1085 | && bus->ci->chip != BCM4319_CHIP_ID) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1086 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL, |
| 1087 | SBSDIO_DEVCTL_PADS_ISO, NULL); |
| 1088 | } |
| 1089 | |
| 1090 | /* Change state */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1091 | bus->sleeping = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1092 | |
| 1093 | } else { |
| 1094 | /* Waking up: bus power up is ok, set local state */ |
| 1095 | |
| 1096 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 1097 | 0, NULL); |
| 1098 | |
| 1099 | /* Force pad isolation off if possible |
| 1100 | (in case power never toggled) */ |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 1101 | if ((bus->ci->buscoretype == PCMCIA_CORE_ID) |
| 1102 | && (bus->ci->buscorerev >= 10)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1103 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL, 0, |
| 1104 | NULL); |
| 1105 | |
| 1106 | /* Make sure the controller has the bus up */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1107 | dhdsdio_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1108 | |
| 1109 | /* Send misc interrupt to indicate OOB not needed */ |
| 1110 | W_SDREG(0, ®s->tosbmailboxdata, retries); |
| 1111 | if (retries <= retry_limit) |
| 1112 | W_SDREG(SMB_DEV_INT, ®s->tosbmailbox, retries); |
| 1113 | |
| 1114 | if (retries > retry_limit) |
| 1115 | DHD_ERROR(("CANNOT SIGNAL CHIP TO CLEAR OOB!!\n")); |
| 1116 | |
| 1117 | /* Make sure we have SD bus access */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1118 | dhdsdio_clkctl(bus, CLK_SDONLY, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1119 | |
| 1120 | /* Change state */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1121 | bus->sleeping = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1122 | |
| 1123 | /* Enable interrupts again */ |
| 1124 | if (bus->intr && (bus->dhd->busstate == DHD_BUS_DATA)) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1125 | bus->intdis = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1126 | bcmsdh_intr_enable(bus->sdh); |
| 1127 | } |
| 1128 | } |
| 1129 | |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 1130 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1131 | } |
| 1132 | |
| 1133 | #if defined(OOB_INTR_ONLY) |
| 1134 | void dhd_enable_oob_intr(struct dhd_bus *bus, bool enable) |
| 1135 | { |
| 1136 | #if defined(HW_OOB) |
| 1137 | bcmsdh_enable_hw_oob_intr(bus->sdh, enable); |
| 1138 | #else |
| 1139 | sdpcmd_regs_t *regs = bus->regs; |
| 1140 | uint retries = 0; |
| 1141 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1142 | dhdsdio_clkctl(bus, CLK_AVAIL, false); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1143 | if (enable == true) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1144 | |
| 1145 | /* Tell device to start using OOB wakeup */ |
| 1146 | W_SDREG(SMB_USE_OOB, ®s->tosbmailbox, retries); |
| 1147 | if (retries > retry_limit) |
| 1148 | DHD_ERROR(("CANNOT SIGNAL CHIP, WILL NOT WAKE UP!!\n")); |
| 1149 | |
| 1150 | } else { |
| 1151 | /* Send misc interrupt to indicate OOB not needed */ |
| 1152 | W_SDREG(0, ®s->tosbmailboxdata, retries); |
| 1153 | if (retries <= retry_limit) |
| 1154 | W_SDREG(SMB_DEV_INT, ®s->tosbmailbox, retries); |
| 1155 | } |
| 1156 | |
| 1157 | /* Turn off our contribution to the HT clock request */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1158 | dhdsdio_clkctl(bus, CLK_SDONLY, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1159 | #endif /* !defined(HW_OOB) */ |
| 1160 | } |
| 1161 | #endif /* defined(OOB_INTR_ONLY) */ |
| 1162 | |
| 1163 | #define BUS_WAKE(bus) \ |
| 1164 | do { \ |
| 1165 | if ((bus)->sleeping) \ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1166 | dhdsdio_bussleep((bus), false); \ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1167 | } while (0); |
| 1168 | |
| 1169 | /* Writes a HW/SW header into the packet and sends it. */ |
| 1170 | /* Assumes: (a) header space already there, (b) caller holds lock */ |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 1171 | static int dhdsdio_txpkt(dhd_bus_t *bus, struct sk_buff *pkt, uint chan, |
| 1172 | bool free_pkt) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1173 | { |
| 1174 | int ret; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1175 | u8 *frame; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 1176 | u16 len, pad = 0; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1177 | u32 swheader; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1178 | uint retries = 0; |
| 1179 | bcmsdh_info_t *sdh; |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 1180 | struct sk_buff *new; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1181 | int i; |
| 1182 | |
| 1183 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 1184 | |
| 1185 | sdh = bus->sdh; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1186 | |
| 1187 | if (bus->dhd->dongle_reset) { |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 1188 | ret = -EPERM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1189 | goto done; |
| 1190 | } |
| 1191 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1192 | frame = (u8 *) (pkt->data); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1193 | |
| 1194 | /* Add alignment padding, allocate new packet if needed */ |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 1195 | pad = ((unsigned long)frame % DHD_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1196 | if (pad) { |
Arend van Spriel | 3be727c | 2010-11-23 22:20:30 +0100 | [diff] [blame] | 1197 | if (skb_headroom(pkt) < pad) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1198 | DHD_INFO(("%s: insufficient headroom %d for %d pad\n", |
Arend van Spriel | 3be727c | 2010-11-23 22:20:30 +0100 | [diff] [blame] | 1199 | __func__, skb_headroom(pkt), pad)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1200 | bus->dhd->tx_realloc++; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1201 | new = brcmu_pkt_buf_get_skb(pkt->len + DHD_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1202 | if (!new) { |
| 1203 | DHD_ERROR(("%s: couldn't allocate new %d-byte " |
| 1204 | "packet\n", |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1205 | __func__, pkt->len + DHD_SDALIGN)); |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 1206 | ret = -ENOMEM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1207 | goto done; |
| 1208 | } |
| 1209 | |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 1210 | PKTALIGN(new, pkt->len, DHD_SDALIGN); |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 1211 | memcpy(new->data, pkt->data, pkt->len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1212 | if (free_pkt) |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1213 | brcmu_pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1214 | /* free the pkt if canned one is not used */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1215 | free_pkt = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1216 | pkt = new; |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1217 | frame = (u8 *) (pkt->data); |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 1218 | ASSERT(((unsigned long)frame % DHD_SDALIGN) == 0); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1219 | pad = 0; |
| 1220 | } else { |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 1221 | skb_push(pkt, pad); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1222 | frame = (u8 *) (pkt->data); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1223 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1224 | ASSERT((pad + SDPCM_HDRLEN) <= (int)(pkt->len)); |
Brett Rudley | 9249ede | 2010-11-30 20:09:49 -0800 | [diff] [blame] | 1225 | memset(frame, 0, pad + SDPCM_HDRLEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1226 | } |
| 1227 | } |
| 1228 | ASSERT(pad < DHD_SDALIGN); |
| 1229 | |
| 1230 | /* 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] | 1231 | len = (u16) (pkt->len); |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 1232 | *(u16 *) frame = cpu_to_le16(len); |
| 1233 | *(((u16 *) frame) + 1) = cpu_to_le16(~len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1234 | |
| 1235 | /* Software tag: channel, sequence number, data offset */ |
| 1236 | swheader = |
| 1237 | ((chan << SDPCM_CHANNEL_SHIFT) & SDPCM_CHANNEL_MASK) | bus->tx_seq | |
| 1238 | (((pad + |
| 1239 | SDPCM_HDRLEN) << SDPCM_DOFFSET_SHIFT) & SDPCM_DOFFSET_MASK); |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 1240 | |
| 1241 | put_unaligned_le32(swheader, frame + SDPCM_FRAMETAG_LEN); |
| 1242 | put_unaligned_le32(0, frame + SDPCM_FRAMETAG_LEN + sizeof(swheader)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1243 | |
| 1244 | #ifdef DHD_DEBUG |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1245 | tx_packets[pkt->priority]++; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1246 | if (DHD_BYTES_ON() && |
| 1247 | (((DHD_CTL_ON() && (chan == SDPCM_CONTROL_CHANNEL)) || |
| 1248 | (DHD_DATA_ON() && (chan != SDPCM_CONTROL_CHANNEL))))) { |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 1249 | printk(KERN_DEBUG "Tx Frame:\n"); |
| 1250 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, frame, len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1251 | } else if (DHD_HDRS_ON()) { |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 1252 | printk(KERN_DEBUG "TxHdr:\n"); |
| 1253 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 1254 | frame, min_t(u16, len, 16)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1255 | } |
| 1256 | #endif |
| 1257 | |
| 1258 | /* Raise len to next SDIO block to eliminate tail command */ |
| 1259 | if (bus->roundup && bus->blocksize && (len > bus->blocksize)) { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 1260 | u16 pad = bus->blocksize - (len % bus->blocksize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1261 | if ((pad <= bus->roundup) && (pad < bus->blocksize)) |
| 1262 | #ifdef NOTUSED |
Arend van Spriel | 3be727c | 2010-11-23 22:20:30 +0100 | [diff] [blame] | 1263 | if (pad <= skb_tailroom(pkt)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1264 | #endif /* NOTUSED */ |
| 1265 | len += pad; |
| 1266 | } else if (len % DHD_SDALIGN) { |
| 1267 | len += DHD_SDALIGN - (len % DHD_SDALIGN); |
| 1268 | } |
| 1269 | |
| 1270 | /* Some controllers have trouble with odd bytes -- round to even */ |
| 1271 | if (forcealign && (len & (ALIGNMENT - 1))) { |
| 1272 | #ifdef NOTUSED |
Arend van Spriel | 3be727c | 2010-11-23 22:20:30 +0100 | [diff] [blame] | 1273 | if (skb_tailroom(pkt)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1274 | #endif |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 1275 | len = roundup(len, ALIGNMENT); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1276 | #ifdef NOTUSED |
| 1277 | else |
| 1278 | DHD_ERROR(("%s: sending unrounded %d-byte packet\n", |
| 1279 | __func__, len)); |
| 1280 | #endif |
| 1281 | } |
| 1282 | |
| 1283 | do { |
| 1284 | ret = |
| 1285 | dhd_bcmsdh_send_buf(bus, bcmsdh_cur_sbwad(sdh), SDIO_FUNC_2, |
| 1286 | F2SYNC, frame, len, pkt, NULL, NULL); |
| 1287 | bus->f2txdata++; |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 1288 | ASSERT(ret != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1289 | |
| 1290 | if (ret < 0) { |
| 1291 | /* On failure, abort the command |
| 1292 | and terminate the frame */ |
| 1293 | DHD_INFO(("%s: sdio error %d, abort command and " |
| 1294 | "terminate frame.\n", __func__, ret)); |
| 1295 | bus->tx_sderrs++; |
| 1296 | |
| 1297 | bcmsdh_abort(sdh, SDIO_FUNC_2); |
| 1298 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, |
| 1299 | SBSDIO_FUNC1_FRAMECTRL, SFC_WF_TERM, |
| 1300 | NULL); |
| 1301 | bus->f1regdata++; |
| 1302 | |
| 1303 | for (i = 0; i < 3; i++) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1304 | u8 hi, lo; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1305 | hi = bcmsdh_cfg_read(sdh, SDIO_FUNC_1, |
| 1306 | SBSDIO_FUNC1_WFRAMEBCHI, |
| 1307 | NULL); |
| 1308 | lo = bcmsdh_cfg_read(sdh, SDIO_FUNC_1, |
| 1309 | SBSDIO_FUNC1_WFRAMEBCLO, |
| 1310 | NULL); |
| 1311 | bus->f1regdata += 2; |
| 1312 | if ((hi == 0) && (lo == 0)) |
| 1313 | break; |
| 1314 | } |
| 1315 | |
| 1316 | } |
| 1317 | if (ret == 0) |
| 1318 | bus->tx_seq = (bus->tx_seq + 1) % SDPCM_SEQUENCE_WRAP; |
| 1319 | |
| 1320 | } while ((ret < 0) && retrydata && retries++ < TXRETRIES); |
| 1321 | |
| 1322 | done: |
| 1323 | /* restore pkt buffer pointer before calling tx complete routine */ |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 1324 | skb_pull(pkt, SDPCM_HDRLEN + pad); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1325 | dhd_os_sdunlock(bus->dhd); |
| 1326 | dhd_txcomplete(bus->dhd, pkt, ret != 0); |
| 1327 | dhd_os_sdlock(bus->dhd); |
| 1328 | |
| 1329 | if (free_pkt) |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1330 | brcmu_pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1331 | |
| 1332 | return ret; |
| 1333 | } |
| 1334 | |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 1335 | int dhd_bus_txdata(struct dhd_bus *bus, struct sk_buff *pkt) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1336 | { |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 1337 | int ret = -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1338 | uint datalen, prec; |
| 1339 | |
| 1340 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 1341 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1342 | datalen = pkt->len; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1343 | |
| 1344 | #ifdef SDTEST |
| 1345 | /* Push the test header if doing loopback */ |
| 1346 | if (bus->ext_loop) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1347 | u8 *data; |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 1348 | skb_push(pkt, SDPCM_TEST_HDRLEN); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1349 | data = pkt->data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1350 | *data++ = SDPCM_TEST_ECHOREQ; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1351 | *data++ = (u8) bus->loopid++; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1352 | *data++ = (datalen >> 0); |
| 1353 | *data++ = (datalen >> 8); |
| 1354 | datalen += SDPCM_TEST_HDRLEN; |
| 1355 | } |
| 1356 | #endif /* SDTEST */ |
| 1357 | |
| 1358 | /* Add space for the header */ |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 1359 | skb_push(pkt, SDPCM_HDRLEN); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1360 | ASSERT(IS_ALIGNED((unsigned long)(pkt->data), 2)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1361 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1362 | prec = PRIO2PREC((pkt->priority & PRIOMASK)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1363 | |
| 1364 | /* Check for existing queue, current flow-control, |
| 1365 | pending event, or pending clock */ |
| 1366 | if (dhd_deferred_tx || bus->fcstate || pktq_len(&bus->txq) |
| 1367 | || bus->dpc_sched || (!DATAOK(bus)) |
| 1368 | || (bus->flowcontrol & NBITVAL(prec)) |
| 1369 | || (bus->clkstate != CLK_AVAIL)) { |
| 1370 | DHD_TRACE(("%s: deferring pktq len %d\n", __func__, |
| 1371 | pktq_len(&bus->txq))); |
| 1372 | bus->fcqueued++; |
| 1373 | |
| 1374 | /* Priority based enq */ |
Franky Lin | 0f1a87c | 2011-06-29 16:46:32 -0700 | [diff] [blame^] | 1375 | spin_lock_bh(&bus->txqlock); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1376 | if (dhd_prec_enq(bus->dhd, &bus->txq, pkt, prec) == false) { |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 1377 | skb_pull(pkt, SDPCM_HDRLEN); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1378 | dhd_txcomplete(bus->dhd, pkt, false); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1379 | brcmu_pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1380 | DHD_ERROR(("%s: out of bus->txq !!!\n", __func__)); |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 1381 | ret = -ENOSR; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1382 | } else { |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 1383 | ret = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1384 | } |
Franky Lin | 0f1a87c | 2011-06-29 16:46:32 -0700 | [diff] [blame^] | 1385 | spin_unlock_bh(&bus->txqlock); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1386 | |
Grant Grundler | 7c31607 | 2011-03-09 15:04:15 -0800 | [diff] [blame] | 1387 | if (pktq_len(&bus->txq) >= TXHI) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1388 | dhd_txflowcontrol(bus->dhd, 0, ON); |
| 1389 | |
| 1390 | #ifdef DHD_DEBUG |
| 1391 | if (pktq_plen(&bus->txq, prec) > qcount[prec]) |
| 1392 | qcount[prec] = pktq_plen(&bus->txq, prec); |
| 1393 | #endif |
| 1394 | /* Schedule DPC if needed to send queued packet(s) */ |
| 1395 | if (dhd_deferred_tx && !bus->dpc_sched) { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1396 | bus->dpc_sched = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1397 | dhd_sched_dpc(bus->dhd); |
| 1398 | } |
| 1399 | } else { |
| 1400 | /* Lock: we're about to use shared data/code (and SDIO) */ |
| 1401 | dhd_os_sdlock(bus->dhd); |
| 1402 | |
| 1403 | /* Otherwise, send it now */ |
| 1404 | BUS_WAKE(bus); |
| 1405 | /* Make sure back plane ht clk is on, no pending allowed */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1406 | dhdsdio_clkctl(bus, CLK_AVAIL, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1407 | |
| 1408 | #ifndef SDTEST |
| 1409 | DHD_TRACE(("%s: calling txpkt\n", __func__)); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1410 | ret = dhdsdio_txpkt(bus, pkt, SDPCM_DATA_CHANNEL, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1411 | #else |
| 1412 | ret = dhdsdio_txpkt(bus, pkt, |
| 1413 | (bus->ext_loop ? SDPCM_TEST_CHANNEL : |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1414 | SDPCM_DATA_CHANNEL), true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1415 | #endif |
| 1416 | if (ret) |
| 1417 | bus->dhd->tx_errors++; |
| 1418 | else |
| 1419 | bus->dhd->dstats.tx_bytes += datalen; |
| 1420 | |
| 1421 | if ((bus->idletime == DHD_IDLE_IMMEDIATE) && !bus->dpc_sched) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1422 | bus->activity = false; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1423 | dhdsdio_clkctl(bus, CLK_NONE, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1424 | } |
| 1425 | |
| 1426 | dhd_os_sdunlock(bus->dhd); |
| 1427 | } |
| 1428 | |
| 1429 | return ret; |
| 1430 | } |
| 1431 | |
| 1432 | static uint dhdsdio_sendfromq(dhd_bus_t *bus, uint maxframes) |
| 1433 | { |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 1434 | struct sk_buff *pkt; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1435 | u32 intstatus = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1436 | uint retries = 0; |
| 1437 | int ret = 0, prec_out; |
| 1438 | uint cnt = 0; |
| 1439 | uint datalen; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1440 | u8 tx_prec_map; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1441 | |
| 1442 | dhd_pub_t *dhd = bus->dhd; |
Franky Lin | 597600a | 2011-06-01 13:45:39 +0200 | [diff] [blame] | 1443 | struct sdpcmd_regs *regs = bus->regs; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1444 | |
| 1445 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 1446 | |
| 1447 | tx_prec_map = ~bus->flowcontrol; |
| 1448 | |
| 1449 | /* Send frames until the limit or some other event */ |
| 1450 | for (cnt = 0; (cnt < maxframes) && DATAOK(bus); cnt++) { |
Franky Lin | 0f1a87c | 2011-06-29 16:46:32 -0700 | [diff] [blame^] | 1451 | spin_lock_bh(&bus->txqlock); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1452 | pkt = brcmu_pktq_mdeq(&bus->txq, tx_prec_map, &prec_out); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1453 | if (pkt == NULL) { |
Franky Lin | 0f1a87c | 2011-06-29 16:46:32 -0700 | [diff] [blame^] | 1454 | spin_unlock_bh(&bus->txqlock); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1455 | break; |
| 1456 | } |
Franky Lin | 0f1a87c | 2011-06-29 16:46:32 -0700 | [diff] [blame^] | 1457 | spin_unlock_bh(&bus->txqlock); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1458 | datalen = pkt->len - SDPCM_HDRLEN; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1459 | |
| 1460 | #ifndef SDTEST |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1461 | ret = dhdsdio_txpkt(bus, pkt, SDPCM_DATA_CHANNEL, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1462 | #else |
| 1463 | ret = dhdsdio_txpkt(bus, pkt, |
| 1464 | (bus->ext_loop ? SDPCM_TEST_CHANNEL : |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1465 | SDPCM_DATA_CHANNEL), true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1466 | #endif |
| 1467 | if (ret) |
| 1468 | bus->dhd->tx_errors++; |
| 1469 | else |
| 1470 | bus->dhd->dstats.tx_bytes += datalen; |
| 1471 | |
| 1472 | /* In poll mode, need to check for other events */ |
| 1473 | if (!bus->intr && cnt) { |
| 1474 | /* Check device status, signal pending interrupt */ |
| 1475 | R_SDREG(intstatus, ®s->intstatus, retries); |
| 1476 | bus->f2txdata++; |
| 1477 | if (bcmsdh_regfail(bus->sdh)) |
| 1478 | break; |
| 1479 | if (intstatus & bus->hostintmask) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1480 | bus->ipend = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1481 | } |
| 1482 | } |
| 1483 | |
| 1484 | /* Deflow-control stack if needed */ |
Grant Grundler | 7c31607 | 2011-03-09 15:04:15 -0800 | [diff] [blame] | 1485 | if (dhd->up && (dhd->busstate == DHD_BUS_DATA) && |
Grant Grundler | 26a71a4 | 2011-03-09 10:41:25 -0800 | [diff] [blame] | 1486 | dhd->txoff && (pktq_len(&bus->txq) < TXLOW)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1487 | dhd_txflowcontrol(dhd, 0, OFF); |
| 1488 | |
| 1489 | return cnt; |
| 1490 | } |
| 1491 | |
Greg Kroah-Hartman | 580a0bd | 2010-10-05 11:09:48 -0700 | [diff] [blame] | 1492 | int dhd_bus_txctl(struct dhd_bus *bus, unsigned char *msg, uint msglen) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1493 | { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1494 | u8 *frame; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 1495 | u16 len; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1496 | u32 swheader; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1497 | uint retries = 0; |
| 1498 | bcmsdh_info_t *sdh = bus->sdh; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1499 | u8 doff = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1500 | int ret = -1; |
| 1501 | int i; |
| 1502 | |
| 1503 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 1504 | |
| 1505 | if (bus->dhd->dongle_reset) |
| 1506 | return -EIO; |
| 1507 | |
| 1508 | /* Back the pointer to make a room for bus header */ |
| 1509 | frame = msg - SDPCM_HDRLEN; |
| 1510 | len = (msglen += SDPCM_HDRLEN); |
| 1511 | |
| 1512 | /* Add alignment padding (optional for ctl frames) */ |
| 1513 | if (dhd_alignctl) { |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 1514 | doff = ((unsigned long)frame % DHD_SDALIGN); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 1515 | if (doff) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1516 | frame -= doff; |
| 1517 | len += doff; |
| 1518 | msglen += doff; |
Brett Rudley | 9249ede | 2010-11-30 20:09:49 -0800 | [diff] [blame] | 1519 | memset(frame, 0, doff + SDPCM_HDRLEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1520 | } |
| 1521 | ASSERT(doff < DHD_SDALIGN); |
| 1522 | } |
| 1523 | doff += SDPCM_HDRLEN; |
| 1524 | |
| 1525 | /* Round send length to next SDIO block */ |
| 1526 | if (bus->roundup && bus->blocksize && (len > bus->blocksize)) { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 1527 | u16 pad = bus->blocksize - (len % bus->blocksize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1528 | if ((pad <= bus->roundup) && (pad < bus->blocksize)) |
| 1529 | len += pad; |
| 1530 | } else if (len % DHD_SDALIGN) { |
| 1531 | len += DHD_SDALIGN - (len % DHD_SDALIGN); |
| 1532 | } |
| 1533 | |
| 1534 | /* Satisfy length-alignment requirements */ |
| 1535 | if (forcealign && (len & (ALIGNMENT - 1))) |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 1536 | len = roundup(len, ALIGNMENT); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1537 | |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 1538 | ASSERT(IS_ALIGNED((unsigned long)frame, 2)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1539 | |
| 1540 | /* Need to lock here to protect txseq and SDIO tx calls */ |
| 1541 | dhd_os_sdlock(bus->dhd); |
| 1542 | |
| 1543 | BUS_WAKE(bus); |
| 1544 | |
| 1545 | /* Make sure backplane clock is on */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1546 | dhdsdio_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1547 | |
| 1548 | /* 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] | 1549 | *(u16 *) frame = cpu_to_le16((u16) msglen); |
| 1550 | *(((u16 *) frame) + 1) = cpu_to_le16(~msglen); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1551 | |
| 1552 | /* Software tag: channel, sequence number, data offset */ |
| 1553 | swheader = |
| 1554 | ((SDPCM_CONTROL_CHANNEL << SDPCM_CHANNEL_SHIFT) & |
| 1555 | SDPCM_CHANNEL_MASK) |
| 1556 | | bus->tx_seq | ((doff << SDPCM_DOFFSET_SHIFT) & |
| 1557 | SDPCM_DOFFSET_MASK); |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 1558 | put_unaligned_le32(swheader, frame + SDPCM_FRAMETAG_LEN); |
| 1559 | put_unaligned_le32(0, frame + SDPCM_FRAMETAG_LEN + sizeof(swheader)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1560 | |
| 1561 | if (!DATAOK(bus)) { |
| 1562 | DHD_INFO(("%s: No bus credit bus->tx_max %d, bus->tx_seq %d\n", |
| 1563 | __func__, bus->tx_max, bus->tx_seq)); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1564 | bus->ctrl_frame_stat = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1565 | /* Send from dpc */ |
| 1566 | bus->ctrl_frame_buf = frame; |
| 1567 | bus->ctrl_frame_len = len; |
| 1568 | |
| 1569 | dhd_wait_for_event(bus->dhd, &bus->ctrl_frame_stat); |
| 1570 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1571 | if (bus->ctrl_frame_stat == false) { |
| 1572 | DHD_INFO(("%s: ctrl_frame_stat == false\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1573 | ret = 0; |
| 1574 | } else { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1575 | DHD_INFO(("%s: ctrl_frame_stat == true\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1576 | ret = -1; |
| 1577 | } |
| 1578 | } |
| 1579 | |
| 1580 | if (ret == -1) { |
| 1581 | #ifdef DHD_DEBUG |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 1582 | if (DHD_BYTES_ON() && DHD_CTL_ON()) { |
| 1583 | printk(KERN_DEBUG "Tx Frame:\n"); |
| 1584 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 1585 | frame, len); |
| 1586 | } else if (DHD_HDRS_ON()) { |
| 1587 | printk(KERN_DEBUG "TxHdr:\n"); |
| 1588 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 1589 | frame, min_t(u16, len, 16)); |
| 1590 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1591 | #endif |
| 1592 | |
| 1593 | do { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1594 | bus->ctrl_frame_stat = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1595 | ret = |
| 1596 | dhd_bcmsdh_send_buf(bus, bcmsdh_cur_sbwad(sdh), |
| 1597 | SDIO_FUNC_2, F2SYNC, frame, len, |
| 1598 | NULL, NULL, NULL); |
| 1599 | |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 1600 | ASSERT(ret != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1601 | |
| 1602 | if (ret < 0) { |
| 1603 | /* On failure, abort the command and |
| 1604 | terminate the frame */ |
| 1605 | DHD_INFO(("%s: sdio error %d, abort command and terminate frame.\n", |
| 1606 | __func__, ret)); |
| 1607 | bus->tx_sderrs++; |
| 1608 | |
| 1609 | bcmsdh_abort(sdh, SDIO_FUNC_2); |
| 1610 | |
| 1611 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, |
| 1612 | SBSDIO_FUNC1_FRAMECTRL, |
| 1613 | SFC_WF_TERM, NULL); |
| 1614 | bus->f1regdata++; |
| 1615 | |
| 1616 | for (i = 0; i < 3; i++) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1617 | u8 hi, lo; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1618 | hi = bcmsdh_cfg_read(sdh, SDIO_FUNC_1, |
| 1619 | SBSDIO_FUNC1_WFRAMEBCHI, |
| 1620 | NULL); |
| 1621 | lo = bcmsdh_cfg_read(sdh, SDIO_FUNC_1, |
| 1622 | SBSDIO_FUNC1_WFRAMEBCLO, |
| 1623 | NULL); |
| 1624 | bus->f1regdata += 2; |
| 1625 | if ((hi == 0) && (lo == 0)) |
| 1626 | break; |
| 1627 | } |
| 1628 | |
| 1629 | } |
| 1630 | if (ret == 0) { |
| 1631 | bus->tx_seq = |
| 1632 | (bus->tx_seq + 1) % SDPCM_SEQUENCE_WRAP; |
| 1633 | } |
| 1634 | } while ((ret < 0) && retries++ < TXRETRIES); |
| 1635 | } |
| 1636 | |
| 1637 | if ((bus->idletime == DHD_IDLE_IMMEDIATE) && !bus->dpc_sched) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1638 | bus->activity = false; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1639 | dhdsdio_clkctl(bus, CLK_NONE, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1640 | } |
| 1641 | |
| 1642 | dhd_os_sdunlock(bus->dhd); |
| 1643 | |
| 1644 | if (ret) |
| 1645 | bus->dhd->tx_ctlerrs++; |
| 1646 | else |
| 1647 | bus->dhd->tx_ctlpkts++; |
| 1648 | |
| 1649 | return ret ? -EIO : 0; |
| 1650 | } |
| 1651 | |
Greg Kroah-Hartman | 580a0bd | 2010-10-05 11:09:48 -0700 | [diff] [blame] | 1652 | int dhd_bus_rxctl(struct dhd_bus *bus, unsigned char *msg, uint msglen) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1653 | { |
| 1654 | int timeleft; |
| 1655 | uint rxlen = 0; |
| 1656 | bool pending; |
| 1657 | |
| 1658 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 1659 | |
| 1660 | if (bus->dhd->dongle_reset) |
| 1661 | return -EIO; |
| 1662 | |
| 1663 | /* Wait until control frame is available */ |
| 1664 | timeleft = dhd_os_ioctl_resp_wait(bus->dhd, &bus->rxlen, &pending); |
| 1665 | |
| 1666 | dhd_os_sdlock(bus->dhd); |
| 1667 | rxlen = bus->rxlen; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 1668 | memcpy(msg, bus->rxctl, min(msglen, rxlen)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1669 | bus->rxlen = 0; |
| 1670 | dhd_os_sdunlock(bus->dhd); |
| 1671 | |
| 1672 | if (rxlen) { |
| 1673 | DHD_CTL(("%s: resumed on rxctl frame, got %d expected %d\n", |
| 1674 | __func__, rxlen, msglen)); |
| 1675 | } else if (timeleft == 0) { |
| 1676 | DHD_ERROR(("%s: resumed on timeout\n", __func__)); |
| 1677 | #ifdef DHD_DEBUG |
| 1678 | dhd_os_sdlock(bus->dhd); |
| 1679 | dhdsdio_checkdied(bus, NULL, 0); |
| 1680 | dhd_os_sdunlock(bus->dhd); |
| 1681 | #endif /* DHD_DEBUG */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1682 | } else if (pending == true) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1683 | DHD_CTL(("%s: cancelled\n", __func__)); |
| 1684 | return -ERESTARTSYS; |
| 1685 | } else { |
| 1686 | DHD_CTL(("%s: resumed for unknown reason?\n", __func__)); |
| 1687 | #ifdef DHD_DEBUG |
| 1688 | dhd_os_sdlock(bus->dhd); |
| 1689 | dhdsdio_checkdied(bus, NULL, 0); |
| 1690 | dhd_os_sdunlock(bus->dhd); |
| 1691 | #endif /* DHD_DEBUG */ |
| 1692 | } |
| 1693 | |
| 1694 | if (rxlen) |
| 1695 | bus->dhd->rx_ctlpkts++; |
| 1696 | else |
| 1697 | bus->dhd->rx_ctlerrs++; |
| 1698 | |
Jason Cooper | e9887c9 | 2010-10-06 10:08:02 -0400 | [diff] [blame] | 1699 | return rxlen ? (int)rxlen : -ETIMEDOUT; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1700 | } |
| 1701 | |
| 1702 | /* IOVar table */ |
| 1703 | enum { |
| 1704 | IOV_INTR = 1, |
| 1705 | IOV_POLLRATE, |
| 1706 | IOV_SDREG, |
| 1707 | IOV_SBREG, |
| 1708 | IOV_SDCIS, |
| 1709 | IOV_MEMBYTES, |
| 1710 | IOV_MEMSIZE, |
| 1711 | #ifdef DHD_DEBUG |
| 1712 | IOV_CHECKDIED, |
| 1713 | #endif |
| 1714 | IOV_DOWNLOAD, |
| 1715 | IOV_FORCEEVEN, |
| 1716 | IOV_SDIOD_DRIVE, |
| 1717 | IOV_READAHEAD, |
| 1718 | IOV_SDRXCHAIN, |
| 1719 | IOV_ALIGNCTL, |
| 1720 | IOV_SDALIGN, |
| 1721 | IOV_DEVRESET, |
| 1722 | IOV_CPU, |
| 1723 | #ifdef SDTEST |
| 1724 | IOV_PKTGEN, |
| 1725 | IOV_EXTLOOP, |
| 1726 | #endif /* SDTEST */ |
| 1727 | IOV_SPROM, |
| 1728 | IOV_TXBOUND, |
| 1729 | IOV_RXBOUND, |
| 1730 | IOV_TXMINMAX, |
| 1731 | IOV_IDLETIME, |
| 1732 | IOV_IDLECLOCK, |
| 1733 | IOV_SD1IDLE, |
| 1734 | IOV_SLEEP, |
| 1735 | IOV_VARS |
| 1736 | }; |
| 1737 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1738 | const struct brcmu_iovar dhdsdio_iovars[] = { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1739 | {"intr", IOV_INTR, 0, IOVT_BOOL, 0}, |
| 1740 | {"sleep", IOV_SLEEP, 0, IOVT_BOOL, 0}, |
| 1741 | {"pollrate", IOV_POLLRATE, 0, IOVT_UINT32, 0}, |
| 1742 | {"idletime", IOV_IDLETIME, 0, IOVT_INT32, 0}, |
| 1743 | {"idleclock", IOV_IDLECLOCK, 0, IOVT_INT32, 0}, |
| 1744 | {"sd1idle", IOV_SD1IDLE, 0, IOVT_BOOL, 0}, |
| 1745 | {"membytes", IOV_MEMBYTES, 0, IOVT_BUFFER, 2 * sizeof(int)}, |
| 1746 | {"memsize", IOV_MEMSIZE, 0, IOVT_UINT32, 0}, |
| 1747 | {"download", IOV_DOWNLOAD, 0, IOVT_BOOL, 0}, |
| 1748 | {"vars", IOV_VARS, 0, IOVT_BUFFER, 0}, |
| 1749 | {"sdiod_drive", IOV_SDIOD_DRIVE, 0, IOVT_UINT32, 0}, |
| 1750 | {"readahead", IOV_READAHEAD, 0, IOVT_BOOL, 0}, |
| 1751 | {"sdrxchain", IOV_SDRXCHAIN, 0, IOVT_BOOL, 0}, |
| 1752 | {"alignctl", IOV_ALIGNCTL, 0, IOVT_BOOL, 0}, |
| 1753 | {"sdalign", IOV_SDALIGN, 0, IOVT_BOOL, 0}, |
| 1754 | {"devreset", IOV_DEVRESET, 0, IOVT_BOOL, 0}, |
| 1755 | #ifdef DHD_DEBUG |
| 1756 | {"sdreg", IOV_SDREG, 0, IOVT_BUFFER, sizeof(sdreg_t)} |
| 1757 | , |
| 1758 | {"sbreg", IOV_SBREG, 0, IOVT_BUFFER, sizeof(sdreg_t)} |
| 1759 | , |
| 1760 | {"sd_cis", IOV_SDCIS, 0, IOVT_BUFFER, DHD_IOCTL_MAXLEN} |
| 1761 | , |
| 1762 | {"forcealign", IOV_FORCEEVEN, 0, IOVT_BOOL, 0} |
| 1763 | , |
| 1764 | {"txbound", IOV_TXBOUND, 0, IOVT_UINT32, 0} |
| 1765 | , |
| 1766 | {"rxbound", IOV_RXBOUND, 0, IOVT_UINT32, 0} |
| 1767 | , |
| 1768 | {"txminmax", IOV_TXMINMAX, 0, IOVT_UINT32, 0} |
| 1769 | , |
| 1770 | {"cpu", IOV_CPU, 0, IOVT_BOOL, 0} |
| 1771 | , |
| 1772 | #ifdef DHD_DEBUG |
| 1773 | {"checkdied", IOV_CHECKDIED, 0, IOVT_BUFFER, 0} |
| 1774 | , |
| 1775 | #endif /* DHD_DEBUG */ |
| 1776 | #endif /* DHD_DEBUG */ |
| 1777 | #ifdef SDTEST |
| 1778 | {"extloop", IOV_EXTLOOP, 0, IOVT_BOOL, 0} |
| 1779 | , |
| 1780 | {"pktgen", IOV_PKTGEN, 0, IOVT_BUFFER, sizeof(dhd_pktgen_t)} |
| 1781 | , |
| 1782 | #endif /* SDTEST */ |
| 1783 | |
| 1784 | {NULL, 0, 0, 0, 0} |
| 1785 | }; |
| 1786 | |
| 1787 | static void |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1788 | 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] | 1789 | { |
| 1790 | uint q1, q2; |
| 1791 | |
| 1792 | if (!div) { |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1793 | brcmu_bprintf(strbuf, "%s N/A", desc); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1794 | } else { |
| 1795 | q1 = num / div; |
| 1796 | q2 = (100 * (num - (q1 * div))) / div; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1797 | brcmu_bprintf(strbuf, "%s %d.%02d", desc, q1, q2); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1798 | } |
| 1799 | } |
| 1800 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1801 | void dhd_bus_dump(dhd_pub_t *dhdp, struct brcmu_strbuf *strbuf) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1802 | { |
| 1803 | dhd_bus_t *bus = dhdp->bus; |
| 1804 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1805 | brcmu_bprintf(strbuf, "Bus SDIO structure:\n"); |
| 1806 | brcmu_bprintf(strbuf, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1807 | "hostintmask 0x%08x intstatus 0x%08x sdpcm_ver %d\n", |
| 1808 | bus->hostintmask, bus->intstatus, bus->sdpcm_ver); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1809 | brcmu_bprintf(strbuf, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1810 | "fcstate %d qlen %d tx_seq %d, max %d, rxskip %d rxlen %d rx_seq %d\n", |
| 1811 | bus->fcstate, pktq_len(&bus->txq), bus->tx_seq, bus->tx_max, |
| 1812 | bus->rxskip, bus->rxlen, bus->rx_seq); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1813 | brcmu_bprintf(strbuf, "intr %d intrcount %d lastintrs %d spurious %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1814 | bus->intr, bus->intrcount, bus->lastintrs, bus->spurious); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1815 | brcmu_bprintf(strbuf, "pollrate %d pollcnt %d regfails %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1816 | bus->pollrate, bus->pollcnt, bus->regfails); |
| 1817 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1818 | brcmu_bprintf(strbuf, "\nAdditional counters:\n"); |
| 1819 | brcmu_bprintf(strbuf, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1820 | "tx_sderrs %d fcqueued %d rxrtx %d rx_toolong %d rxc_errors %d\n", |
| 1821 | bus->tx_sderrs, bus->fcqueued, bus->rxrtx, bus->rx_toolong, |
| 1822 | bus->rxc_errors); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1823 | brcmu_bprintf(strbuf, "rx_hdrfail %d badhdr %d badseq %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1824 | bus->rx_hdrfail, bus->rx_badhdr, bus->rx_badseq); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1825 | brcmu_bprintf(strbuf, "fc_rcvd %d, fc_xoff %d, fc_xon %d\n", |
| 1826 | bus->fc_rcvd, bus->fc_xoff, bus->fc_xon); |
| 1827 | brcmu_bprintf(strbuf, "rxglomfail %d, rxglomframes %d, rxglompkts %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1828 | bus->rxglomfail, bus->rxglomframes, bus->rxglompkts); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1829 | brcmu_bprintf(strbuf, "f2rx (hdrs/data) %d (%d/%d), f2tx %d f1regs" |
| 1830 | " %d\n", |
| 1831 | (bus->f2rxhdrs + bus->f2rxdata), bus->f2rxhdrs, |
| 1832 | bus->f2rxdata, bus->f2txdata, bus->f1regdata); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1833 | { |
| 1834 | dhd_dump_pct(strbuf, "\nRx: pkts/f2rd", bus->dhd->rx_packets, |
| 1835 | (bus->f2rxhdrs + bus->f2rxdata)); |
| 1836 | dhd_dump_pct(strbuf, ", pkts/f1sd", bus->dhd->rx_packets, |
| 1837 | bus->f1regdata); |
| 1838 | dhd_dump_pct(strbuf, ", pkts/sd", bus->dhd->rx_packets, |
| 1839 | (bus->f2rxhdrs + bus->f2rxdata + bus->f1regdata)); |
| 1840 | dhd_dump_pct(strbuf, ", pkts/int", bus->dhd->rx_packets, |
| 1841 | bus->intrcount); |
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, "Rx: glom pct", (100 * bus->rxglompkts), |
| 1845 | bus->dhd->rx_packets); |
| 1846 | dhd_dump_pct(strbuf, ", pkts/glom", bus->rxglompkts, |
| 1847 | bus->rxglomframes); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1848 | brcmu_bprintf(strbuf, "\n"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1849 | |
| 1850 | dhd_dump_pct(strbuf, "Tx: pkts/f2wr", bus->dhd->tx_packets, |
| 1851 | bus->f2txdata); |
| 1852 | dhd_dump_pct(strbuf, ", pkts/f1sd", bus->dhd->tx_packets, |
| 1853 | bus->f1regdata); |
| 1854 | dhd_dump_pct(strbuf, ", pkts/sd", bus->dhd->tx_packets, |
| 1855 | (bus->f2txdata + bus->f1regdata)); |
| 1856 | dhd_dump_pct(strbuf, ", pkts/int", bus->dhd->tx_packets, |
| 1857 | bus->intrcount); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1858 | brcmu_bprintf(strbuf, "\n"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1859 | |
| 1860 | dhd_dump_pct(strbuf, "Total: pkts/f2rw", |
| 1861 | (bus->dhd->tx_packets + bus->dhd->rx_packets), |
| 1862 | (bus->f2txdata + bus->f2rxhdrs + bus->f2rxdata)); |
| 1863 | dhd_dump_pct(strbuf, ", pkts/f1sd", |
| 1864 | (bus->dhd->tx_packets + bus->dhd->rx_packets), |
| 1865 | bus->f1regdata); |
| 1866 | dhd_dump_pct(strbuf, ", pkts/sd", |
| 1867 | (bus->dhd->tx_packets + bus->dhd->rx_packets), |
| 1868 | (bus->f2txdata + bus->f2rxhdrs + bus->f2rxdata + |
| 1869 | bus->f1regdata)); |
| 1870 | dhd_dump_pct(strbuf, ", pkts/int", |
| 1871 | (bus->dhd->tx_packets + bus->dhd->rx_packets), |
| 1872 | bus->intrcount); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1873 | brcmu_bprintf(strbuf, "\n\n"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1874 | } |
| 1875 | |
| 1876 | #ifdef SDTEST |
| 1877 | if (bus->pktgen_count) { |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1878 | brcmu_bprintf(strbuf, "pktgen config and count:\n"); |
| 1879 | brcmu_bprintf(strbuf, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1880 | "freq %d count %d print %d total %d min %d len %d\n", |
| 1881 | bus->pktgen_freq, bus->pktgen_count, |
| 1882 | bus->pktgen_print, bus->pktgen_total, |
| 1883 | bus->pktgen_minlen, bus->pktgen_maxlen); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1884 | brcmu_bprintf(strbuf, "send attempts %d rcvd %d fail %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1885 | bus->pktgen_sent, bus->pktgen_rcvd, |
| 1886 | bus->pktgen_fail); |
| 1887 | } |
| 1888 | #endif /* SDTEST */ |
| 1889 | #ifdef DHD_DEBUG |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1890 | brcmu_bprintf(strbuf, "dpc_sched %d host interrupt%spending\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1891 | bus->dpc_sched, |
| 1892 | (bcmsdh_intr_pending(bus->sdh) ? " " : " not ")); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1893 | brcmu_bprintf(strbuf, "blocksize %d roundup %d\n", bus->blocksize, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1894 | bus->roundup); |
| 1895 | #endif /* DHD_DEBUG */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 1896 | brcmu_bprintf(strbuf, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1897 | "clkstate %d activity %d idletime %d idlecount %d sleeping %d\n", |
| 1898 | bus->clkstate, bus->activity, bus->idletime, bus->idlecount, |
| 1899 | bus->sleeping); |
| 1900 | } |
| 1901 | |
| 1902 | void dhd_bus_clearcounts(dhd_pub_t *dhdp) |
| 1903 | { |
| 1904 | dhd_bus_t *bus = (dhd_bus_t *) dhdp->bus; |
| 1905 | |
| 1906 | bus->intrcount = bus->lastintrs = bus->spurious = bus->regfails = 0; |
| 1907 | bus->rxrtx = bus->rx_toolong = bus->rxc_errors = 0; |
| 1908 | bus->rx_hdrfail = bus->rx_badhdr = bus->rx_badseq = 0; |
| 1909 | bus->tx_sderrs = bus->fc_rcvd = bus->fc_xoff = bus->fc_xon = 0; |
| 1910 | bus->rxglomfail = bus->rxglomframes = bus->rxglompkts = 0; |
| 1911 | bus->f2rxhdrs = bus->f2rxdata = bus->f2txdata = bus->f1regdata = 0; |
| 1912 | } |
| 1913 | |
| 1914 | #ifdef SDTEST |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1915 | static int dhdsdio_pktgen_get(dhd_bus_t *bus, u8 *arg) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1916 | { |
| 1917 | dhd_pktgen_t pktgen; |
| 1918 | |
| 1919 | pktgen.version = DHD_PKTGEN_VERSION; |
| 1920 | pktgen.freq = bus->pktgen_freq; |
| 1921 | pktgen.count = bus->pktgen_count; |
| 1922 | pktgen.print = bus->pktgen_print; |
| 1923 | pktgen.total = bus->pktgen_total; |
| 1924 | pktgen.minlen = bus->pktgen_minlen; |
| 1925 | pktgen.maxlen = bus->pktgen_maxlen; |
| 1926 | pktgen.numsent = bus->pktgen_sent; |
| 1927 | pktgen.numrcvd = bus->pktgen_rcvd; |
| 1928 | pktgen.numfail = bus->pktgen_fail; |
| 1929 | pktgen.mode = bus->pktgen_mode; |
| 1930 | pktgen.stop = bus->pktgen_stop; |
| 1931 | |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 1932 | memcpy(arg, &pktgen, sizeof(pktgen)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1933 | |
| 1934 | return 0; |
| 1935 | } |
| 1936 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1937 | static int dhdsdio_pktgen_set(dhd_bus_t *bus, u8 *arg) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1938 | { |
| 1939 | dhd_pktgen_t pktgen; |
| 1940 | uint oldcnt, oldmode; |
| 1941 | |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 1942 | memcpy(&pktgen, arg, sizeof(pktgen)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1943 | if (pktgen.version != DHD_PKTGEN_VERSION) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 1944 | return -EINVAL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1945 | |
| 1946 | oldcnt = bus->pktgen_count; |
| 1947 | oldmode = bus->pktgen_mode; |
| 1948 | |
| 1949 | bus->pktgen_freq = pktgen.freq; |
| 1950 | bus->pktgen_count = pktgen.count; |
| 1951 | bus->pktgen_print = pktgen.print; |
| 1952 | bus->pktgen_total = pktgen.total; |
| 1953 | bus->pktgen_minlen = pktgen.minlen; |
| 1954 | bus->pktgen_maxlen = pktgen.maxlen; |
| 1955 | bus->pktgen_mode = pktgen.mode; |
| 1956 | bus->pktgen_stop = pktgen.stop; |
| 1957 | |
| 1958 | bus->pktgen_tick = bus->pktgen_ptick = 0; |
Greg Kroah-Hartman | 3ea2f4d | 2010-10-08 11:39:43 -0700 | [diff] [blame] | 1959 | bus->pktgen_len = max(bus->pktgen_len, bus->pktgen_minlen); |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 1960 | bus->pktgen_len = min(bus->pktgen_len, bus->pktgen_maxlen); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1961 | |
| 1962 | /* Clear counts for a new pktgen (mode change, or was stopped) */ |
| 1963 | if (bus->pktgen_count && (!oldcnt || oldmode != bus->pktgen_mode)) |
| 1964 | bus->pktgen_sent = bus->pktgen_rcvd = bus->pktgen_fail = 0; |
| 1965 | |
| 1966 | return 0; |
| 1967 | } |
| 1968 | #endif /* SDTEST */ |
| 1969 | |
| 1970 | static int |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1971 | dhdsdio_membytes(dhd_bus_t *bus, bool write, u32 address, u8 *data, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1972 | uint size) |
| 1973 | { |
| 1974 | int bcmerror = 0; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1975 | u32 sdaddr; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1976 | uint dsize; |
| 1977 | |
| 1978 | /* Determine initial transfer parameters */ |
| 1979 | sdaddr = address & SBSDIO_SB_OFT_ADDR_MASK; |
| 1980 | if ((sdaddr + size) & SBSDIO_SBWINDOW_MASK) |
| 1981 | dsize = (SBSDIO_SB_OFT_ADDR_LIMIT - sdaddr); |
| 1982 | else |
| 1983 | dsize = size; |
| 1984 | |
| 1985 | /* Set the backplane window to include the start address */ |
| 1986 | bcmerror = dhdsdio_set_siaddr_window(bus, address); |
| 1987 | if (bcmerror) { |
| 1988 | DHD_ERROR(("%s: window change failed\n", __func__)); |
| 1989 | goto xfer_done; |
| 1990 | } |
| 1991 | |
| 1992 | /* Do the transfer(s) */ |
| 1993 | while (size) { |
| 1994 | DHD_INFO(("%s: %s %d bytes at offset 0x%08x in window 0x%08x\n", |
| 1995 | __func__, (write ? "write" : "read"), dsize, |
| 1996 | sdaddr, (address & SBSDIO_SBWINDOW_MASK))); |
| 1997 | bcmerror = |
| 1998 | bcmsdh_rwdata(bus->sdh, write, sdaddr, data, dsize); |
| 1999 | if (bcmerror) { |
| 2000 | DHD_ERROR(("%s: membytes transfer failed\n", __func__)); |
| 2001 | break; |
| 2002 | } |
| 2003 | |
| 2004 | /* Adjust for next transfer (if any) */ |
| 2005 | size -= dsize; |
| 2006 | if (size) { |
| 2007 | data += dsize; |
| 2008 | address += dsize; |
| 2009 | bcmerror = dhdsdio_set_siaddr_window(bus, address); |
| 2010 | if (bcmerror) { |
| 2011 | DHD_ERROR(("%s: window change failed\n", |
| 2012 | __func__)); |
| 2013 | break; |
| 2014 | } |
| 2015 | sdaddr = 0; |
Greg Kroah-Hartman | b61640d | 2010-10-08 12:37:39 -0700 | [diff] [blame] | 2016 | dsize = min_t(uint, SBSDIO_SB_OFT_ADDR_LIMIT, size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2017 | } |
| 2018 | } |
| 2019 | |
| 2020 | xfer_done: |
| 2021 | /* Return the window to backplane enumeration space for core access */ |
| 2022 | if (dhdsdio_set_siaddr_window(bus, bcmsdh_cur_sbwad(bus->sdh))) { |
| 2023 | DHD_ERROR(("%s: FAILED to set window back to 0x%x\n", |
| 2024 | __func__, bcmsdh_cur_sbwad(bus->sdh))); |
| 2025 | } |
| 2026 | |
| 2027 | return bcmerror; |
| 2028 | } |
| 2029 | |
| 2030 | #ifdef DHD_DEBUG |
Franky Lin | b49b14d | 2011-06-01 13:45:37 +0200 | [diff] [blame] | 2031 | static int dhdsdio_readshared(dhd_bus_t *bus, struct sdpcm_shared *sh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2032 | { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2033 | u32 addr; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2034 | int rv; |
| 2035 | |
| 2036 | /* Read last word in memory to determine address of |
| 2037 | sdpcm_shared structure */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2038 | rv = dhdsdio_membytes(bus, false, bus->ramsize - 4, (u8 *)&addr, 4); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2039 | if (rv < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2040 | return rv; |
| 2041 | |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 2042 | addr = le32_to_cpu(addr); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2043 | |
| 2044 | DHD_INFO(("sdpcm_shared address 0x%08X\n", addr)); |
| 2045 | |
| 2046 | /* |
| 2047 | * Check if addr is valid. |
| 2048 | * NVRAM length at the end of memory should have been overwritten. |
| 2049 | */ |
| 2050 | if (addr == 0 || ((~addr >> 16) & 0xffff) == (addr & 0xffff)) { |
| 2051 | DHD_ERROR(("%s: address (0x%08x) of sdpcm_shared invalid\n", |
| 2052 | __func__, addr)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2053 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2054 | } |
| 2055 | |
Roland Vossen | 70963f9 | 2011-06-01 13:45:08 +0200 | [diff] [blame] | 2056 | /* Read rte_shared structure */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2057 | rv = dhdsdio_membytes(bus, false, addr, (u8 *) sh, |
Franky Lin | b49b14d | 2011-06-01 13:45:37 +0200 | [diff] [blame] | 2058 | sizeof(struct sdpcm_shared)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2059 | if (rv < 0) |
| 2060 | return rv; |
| 2061 | |
| 2062 | /* Endianness */ |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 2063 | sh->flags = le32_to_cpu(sh->flags); |
| 2064 | sh->trap_addr = le32_to_cpu(sh->trap_addr); |
| 2065 | sh->assert_exp_addr = le32_to_cpu(sh->assert_exp_addr); |
| 2066 | sh->assert_file_addr = le32_to_cpu(sh->assert_file_addr); |
| 2067 | sh->assert_line = le32_to_cpu(sh->assert_line); |
| 2068 | sh->console_addr = le32_to_cpu(sh->console_addr); |
| 2069 | sh->msgtrace_addr = le32_to_cpu(sh->msgtrace_addr); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2070 | |
| 2071 | if ((sh->flags & SDPCM_SHARED_VERSION_MASK) != SDPCM_SHARED_VERSION) { |
| 2072 | DHD_ERROR(("%s: sdpcm_shared version %d in dhd " |
| 2073 | "is different than sdpcm_shared version %d in dongle\n", |
| 2074 | __func__, SDPCM_SHARED_VERSION, |
| 2075 | sh->flags & SDPCM_SHARED_VERSION_MASK)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2076 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2077 | } |
| 2078 | |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 2079 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2080 | } |
| 2081 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2082 | static int dhdsdio_checkdied(dhd_bus_t *bus, u8 *data, uint size) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2083 | { |
| 2084 | int bcmerror = 0; |
| 2085 | uint msize = 512; |
| 2086 | char *mbuffer = NULL; |
| 2087 | uint maxstrlen = 256; |
| 2088 | char *str = NULL; |
| 2089 | trap_t tr; |
Franky Lin | b49b14d | 2011-06-01 13:45:37 +0200 | [diff] [blame] | 2090 | struct sdpcm_shared sdpcm_shared; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2091 | struct brcmu_strbuf strbuf; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2092 | |
| 2093 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 2094 | |
| 2095 | if (data == NULL) { |
| 2096 | /* |
| 2097 | * Called after a rx ctrl timeout. "data" is NULL. |
| 2098 | * allocate memory to trace the trap or assert. |
| 2099 | */ |
| 2100 | size = msize; |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2101 | mbuffer = data = kmalloc(msize, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2102 | if (mbuffer == NULL) { |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2103 | DHD_ERROR(("%s: kmalloc(%d) failed\n", __func__, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2104 | msize)); |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2105 | bcmerror = -ENOMEM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2106 | goto done; |
| 2107 | } |
| 2108 | } |
| 2109 | |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2110 | str = kmalloc(maxstrlen, GFP_ATOMIC); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2111 | if (str == NULL) { |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2112 | DHD_ERROR(("%s: kmalloc(%d) failed\n", __func__, maxstrlen)); |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2113 | bcmerror = -ENOMEM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2114 | goto done; |
| 2115 | } |
| 2116 | |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2117 | bcmerror = dhdsdio_readshared(bus, &sdpcm_shared); |
| 2118 | if (bcmerror < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2119 | goto done; |
| 2120 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2121 | brcmu_binit(&strbuf, data, size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2122 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2123 | brcmu_bprintf(&strbuf, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2124 | "msgtrace address : 0x%08X\nconsole address : 0x%08X\n", |
| 2125 | sdpcm_shared.msgtrace_addr, sdpcm_shared.console_addr); |
| 2126 | |
| 2127 | if ((sdpcm_shared.flags & SDPCM_SHARED_ASSERT_BUILT) == 0) { |
| 2128 | /* NOTE: Misspelled assert is intentional - DO NOT FIX. |
| 2129 | * (Avoids conflict with real asserts for programmatic |
| 2130 | * parsing of output.) |
| 2131 | */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2132 | brcmu_bprintf(&strbuf, "Assrt not built in dongle\n"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2133 | } |
| 2134 | |
| 2135 | if ((sdpcm_shared.flags & (SDPCM_SHARED_ASSERT | SDPCM_SHARED_TRAP)) == |
| 2136 | 0) { |
| 2137 | /* NOTE: Misspelled assert is intentional - DO NOT FIX. |
| 2138 | * (Avoids conflict with real asserts for programmatic |
| 2139 | * parsing of output.) |
| 2140 | */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2141 | brcmu_bprintf(&strbuf, "No trap%s in dongle", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2142 | (sdpcm_shared.flags & SDPCM_SHARED_ASSERT_BUILT) |
| 2143 | ? "/assrt" : ""); |
| 2144 | } else { |
| 2145 | if (sdpcm_shared.flags & SDPCM_SHARED_ASSERT) { |
| 2146 | /* Download assert */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2147 | brcmu_bprintf(&strbuf, "Dongle assert"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2148 | if (sdpcm_shared.assert_exp_addr != 0) { |
| 2149 | str[0] = '\0'; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2150 | bcmerror = dhdsdio_membytes(bus, false, |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2151 | sdpcm_shared.assert_exp_addr, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2152 | (u8 *) str, maxstrlen); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2153 | if (bcmerror < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2154 | goto done; |
| 2155 | |
| 2156 | str[maxstrlen - 1] = '\0'; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2157 | brcmu_bprintf(&strbuf, " expr \"%s\"", str); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2158 | } |
| 2159 | |
| 2160 | if (sdpcm_shared.assert_file_addr != 0) { |
| 2161 | str[0] = '\0'; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2162 | bcmerror = dhdsdio_membytes(bus, false, |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2163 | sdpcm_shared.assert_file_addr, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2164 | (u8 *) str, maxstrlen); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2165 | if (bcmerror < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2166 | goto done; |
| 2167 | |
| 2168 | str[maxstrlen - 1] = '\0'; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2169 | brcmu_bprintf(&strbuf, " file \"%s\"", str); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2170 | } |
| 2171 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2172 | brcmu_bprintf(&strbuf, " line %d ", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2173 | sdpcm_shared.assert_line); |
| 2174 | } |
| 2175 | |
| 2176 | if (sdpcm_shared.flags & SDPCM_SHARED_TRAP) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2177 | bcmerror = dhdsdio_membytes(bus, false, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2178 | sdpcm_shared.trap_addr, (u8 *)&tr, |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2179 | sizeof(trap_t)); |
| 2180 | if (bcmerror < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2181 | goto done; |
| 2182 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2183 | brcmu_bprintf(&strbuf, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2184 | "Dongle trap type 0x%x @ epc 0x%x, cpsr 0x%x, spsr 0x%x, sp 0x%x," |
| 2185 | "lp 0x%x, rpc 0x%x Trap offset 0x%x, " |
| 2186 | "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", |
| 2187 | tr.type, tr.epc, tr.cpsr, tr.spsr, tr.r13, |
| 2188 | tr.r14, tr.pc, sdpcm_shared.trap_addr, |
| 2189 | tr.r0, tr.r1, tr.r2, tr.r3, tr.r4, tr.r5, |
| 2190 | tr.r6, tr.r7); |
| 2191 | } |
| 2192 | } |
| 2193 | |
| 2194 | if (sdpcm_shared.flags & (SDPCM_SHARED_ASSERT | SDPCM_SHARED_TRAP)) |
| 2195 | DHD_ERROR(("%s: %s\n", __func__, strbuf.origbuf)); |
| 2196 | |
| 2197 | #ifdef DHD_DEBUG |
| 2198 | if (sdpcm_shared.flags & SDPCM_SHARED_TRAP) { |
| 2199 | /* Mem dump to a file on device */ |
| 2200 | dhdsdio_mem_dump(bus); |
| 2201 | } |
| 2202 | #endif /* DHD_DEBUG */ |
| 2203 | |
| 2204 | done: |
Ilia Mirkin | 46d994b | 2011-03-13 00:28:56 -0500 | [diff] [blame] | 2205 | kfree(mbuffer); |
| 2206 | kfree(str); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2207 | |
| 2208 | return bcmerror; |
| 2209 | } |
| 2210 | |
| 2211 | static int dhdsdio_mem_dump(dhd_bus_t *bus) |
| 2212 | { |
| 2213 | int ret = 0; |
| 2214 | int size; /* Full mem size */ |
| 2215 | int start = 0; /* Start address */ |
| 2216 | int read_size = 0; /* Read size of each iteration */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2217 | u8 *buf = NULL, *databuf = NULL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2218 | |
| 2219 | /* Get full mem size */ |
| 2220 | size = bus->ramsize; |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2221 | buf = kmalloc(size, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2222 | if (!buf) { |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 2223 | DHD_ERROR(("%s: Out of memory (%d bytes)\n", __func__, size)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2224 | return -1; |
| 2225 | } |
| 2226 | |
| 2227 | /* Read mem content */ |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 2228 | printk(KERN_DEBUG "Dump dongle memory"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2229 | databuf = buf; |
| 2230 | while (size) { |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 2231 | read_size = min(MEMBLOCK, size); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2232 | ret = dhdsdio_membytes(bus, false, start, databuf, read_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2233 | if (ret) { |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 2234 | DHD_ERROR(("%s: Error membytes %d\n", __func__, ret)); |
Ilia Mirkin | 46d994b | 2011-03-13 00:28:56 -0500 | [diff] [blame] | 2235 | kfree(buf); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2236 | return -1; |
| 2237 | } |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 2238 | printk("."); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2239 | |
| 2240 | /* Decrement size and increment start address */ |
| 2241 | size -= read_size; |
| 2242 | start += read_size; |
| 2243 | databuf += read_size; |
| 2244 | } |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 2245 | printk(KERN_DEBUG "Done\n"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2246 | |
| 2247 | /* free buf before return !!! */ |
| 2248 | if (write_to_file(bus->dhd, buf, bus->ramsize)) { |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 2249 | DHD_ERROR(("%s: Error writing to files\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2250 | return -1; |
| 2251 | } |
| 2252 | |
| 2253 | /* buf free handled in write_to_file, not here */ |
| 2254 | return 0; |
| 2255 | } |
| 2256 | |
| 2257 | #define CONSOLE_LINE_MAX 192 |
| 2258 | |
| 2259 | static int dhdsdio_readconsole(dhd_bus_t *bus) |
| 2260 | { |
| 2261 | dhd_console_t *c = &bus->console; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2262 | u8 line[CONSOLE_LINE_MAX], ch; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2263 | u32 n, idx, addr; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2264 | int rv; |
| 2265 | |
| 2266 | /* Don't do anything until FWREADY updates console address */ |
| 2267 | if (bus->console_addr == 0) |
| 2268 | return 0; |
| 2269 | |
| 2270 | /* Read console log struct */ |
Roland Vossen | 70963f9 | 2011-06-01 13:45:08 +0200 | [diff] [blame] | 2271 | addr = bus->console_addr + offsetof(rte_cons_t, log); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2272 | rv = dhdsdio_membytes(bus, false, addr, (u8 *)&c->log, |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2273 | sizeof(c->log)); |
| 2274 | if (rv < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2275 | return rv; |
| 2276 | |
| 2277 | /* Allocate console buffer (one time only) */ |
| 2278 | if (c->buf == NULL) { |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 2279 | c->bufsize = le32_to_cpu(c->log.buf_size); |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2280 | c->buf = kmalloc(c->bufsize, GFP_ATOMIC); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2281 | if (c->buf == NULL) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2282 | return -ENOMEM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2283 | } |
| 2284 | |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 2285 | idx = le32_to_cpu(c->log.idx); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2286 | |
| 2287 | /* Protect against corrupt value */ |
| 2288 | if (idx > c->bufsize) |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2289 | return -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2290 | |
| 2291 | /* Skip reading the console buffer if the index pointer |
| 2292 | has not moved */ |
| 2293 | if (idx == c->last) |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 2294 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2295 | |
| 2296 | /* Read the console buffer */ |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 2297 | addr = le32_to_cpu(c->log.buf); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2298 | rv = dhdsdio_membytes(bus, false, addr, c->buf, c->bufsize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2299 | if (rv < 0) |
| 2300 | return rv; |
| 2301 | |
| 2302 | while (c->last != idx) { |
| 2303 | for (n = 0; n < CONSOLE_LINE_MAX - 2; n++) { |
| 2304 | if (c->last == idx) { |
| 2305 | /* This would output a partial line. |
| 2306 | * Instead, back up |
| 2307 | * the buffer pointer and output this |
| 2308 | * line next time around. |
| 2309 | */ |
| 2310 | if (c->last >= n) |
| 2311 | c->last -= n; |
| 2312 | else |
| 2313 | c->last = c->bufsize - n; |
| 2314 | goto break2; |
| 2315 | } |
| 2316 | ch = c->buf[c->last]; |
| 2317 | c->last = (c->last + 1) % c->bufsize; |
| 2318 | if (ch == '\n') |
| 2319 | break; |
| 2320 | line[n] = ch; |
| 2321 | } |
| 2322 | |
| 2323 | if (n > 0) { |
| 2324 | if (line[n - 1] == '\r') |
| 2325 | n--; |
| 2326 | line[n] = 0; |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 2327 | printk(KERN_DEBUG "CONSOLE: %s\n", line); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2328 | } |
| 2329 | } |
| 2330 | break2: |
| 2331 | |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 2332 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2333 | } |
| 2334 | #endif /* DHD_DEBUG */ |
| 2335 | |
| 2336 | int dhdsdio_downloadvars(dhd_bus_t *bus, void *arg, int len) |
| 2337 | { |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 2338 | int bcmerror = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2339 | |
| 2340 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 2341 | |
| 2342 | /* Basic sanity checks */ |
| 2343 | if (bus->dhd->up) { |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2344 | bcmerror = -EISCONN; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2345 | goto err; |
| 2346 | } |
| 2347 | if (!len) { |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2348 | bcmerror = -EOVERFLOW; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2349 | goto err; |
| 2350 | } |
| 2351 | |
| 2352 | /* Free the old ones and replace with passed variables */ |
Ilia Mirkin | 46d994b | 2011-03-13 00:28:56 -0500 | [diff] [blame] | 2353 | kfree(bus->vars); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2354 | |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2355 | bus->vars = kmalloc(len, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2356 | bus->varsz = bus->vars ? len : 0; |
| 2357 | if (bus->vars == NULL) { |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2358 | bcmerror = -ENOMEM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2359 | goto err; |
| 2360 | } |
| 2361 | |
| 2362 | /* Copy the passed variables, which should include the |
| 2363 | terminating double-null */ |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2364 | memcpy(bus->vars, arg, bus->varsz); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2365 | err: |
| 2366 | return bcmerror; |
| 2367 | } |
| 2368 | |
| 2369 | static int |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2370 | dhdsdio_doiovar(dhd_bus_t *bus, const struct brcmu_iovar *vi, u32 actionid, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2371 | const char *name, void *params, int plen, void *arg, int len, |
| 2372 | int val_size) |
| 2373 | { |
| 2374 | int bcmerror = 0; |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2375 | s32 int_val = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2376 | bool bool_val = 0; |
| 2377 | |
| 2378 | DHD_TRACE(("%s: Enter, action %d name %s params %p plen %d arg %p " |
| 2379 | "len %d val_size %d\n", |
| 2380 | __func__, actionid, name, params, plen, arg, len, val_size)); |
| 2381 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2382 | bcmerror = brcmu_iovar_lencheck(vi, arg, len, IOV_ISSET(actionid)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2383 | if (bcmerror != 0) |
| 2384 | goto exit; |
| 2385 | |
| 2386 | if (plen >= (int)sizeof(int_val)) |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2387 | memcpy(&int_val, params, sizeof(int_val)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2388 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2389 | bool_val = (int_val != 0) ? true : false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2390 | |
| 2391 | /* Some ioctls use the bus */ |
| 2392 | dhd_os_sdlock(bus->dhd); |
| 2393 | |
| 2394 | /* Check if dongle is in reset. If so, only allow DEVRESET iovars */ |
| 2395 | if (bus->dhd->dongle_reset && !(actionid == IOV_SVAL(IOV_DEVRESET) || |
| 2396 | actionid == IOV_GVAL(IOV_DEVRESET))) { |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2397 | bcmerror = -EPERM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2398 | goto exit; |
| 2399 | } |
| 2400 | |
| 2401 | /* Handle sleep stuff before any clock mucking */ |
| 2402 | if (vi->varid == IOV_SLEEP) { |
| 2403 | if (IOV_ISSET(actionid)) { |
| 2404 | bcmerror = dhdsdio_bussleep(bus, bool_val); |
| 2405 | } else { |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2406 | int_val = (s32) bus->sleeping; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2407 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2408 | } |
| 2409 | goto exit; |
| 2410 | } |
| 2411 | |
| 2412 | /* Request clock to allow SDIO accesses */ |
| 2413 | if (!bus->dhd->dongle_reset) { |
| 2414 | BUS_WAKE(bus); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2415 | dhdsdio_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2416 | } |
| 2417 | |
| 2418 | switch (actionid) { |
| 2419 | case IOV_GVAL(IOV_INTR): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2420 | int_val = (s32) bus->intr; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2421 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2422 | break; |
| 2423 | |
| 2424 | case IOV_SVAL(IOV_INTR): |
| 2425 | bus->intr = bool_val; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2426 | bus->intdis = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2427 | if (bus->dhd->up) { |
| 2428 | if (bus->intr) { |
| 2429 | DHD_INTR(("%s: enable SDIO device interrupts\n", |
| 2430 | __func__)); |
| 2431 | bcmsdh_intr_enable(bus->sdh); |
| 2432 | } else { |
| 2433 | DHD_INTR(("%s: disable SDIO interrupts\n", |
| 2434 | __func__)); |
| 2435 | bcmsdh_intr_disable(bus->sdh); |
| 2436 | } |
| 2437 | } |
| 2438 | break; |
| 2439 | |
| 2440 | case IOV_GVAL(IOV_POLLRATE): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2441 | int_val = (s32) bus->pollrate; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2442 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2443 | break; |
| 2444 | |
| 2445 | case IOV_SVAL(IOV_POLLRATE): |
| 2446 | bus->pollrate = (uint) int_val; |
| 2447 | bus->poll = (bus->pollrate != 0); |
| 2448 | break; |
| 2449 | |
| 2450 | case IOV_GVAL(IOV_IDLETIME): |
| 2451 | int_val = bus->idletime; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2452 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2453 | break; |
| 2454 | |
| 2455 | case IOV_SVAL(IOV_IDLETIME): |
| 2456 | if ((int_val < 0) && (int_val != DHD_IDLE_IMMEDIATE)) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2457 | bcmerror = -EINVAL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2458 | else |
| 2459 | bus->idletime = int_val; |
| 2460 | break; |
| 2461 | |
| 2462 | case IOV_GVAL(IOV_IDLECLOCK): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2463 | int_val = (s32) bus->idleclock; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2464 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2465 | break; |
| 2466 | |
| 2467 | case IOV_SVAL(IOV_IDLECLOCK): |
| 2468 | bus->idleclock = int_val; |
| 2469 | break; |
| 2470 | |
| 2471 | case IOV_GVAL(IOV_SD1IDLE): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2472 | int_val = (s32) sd1idle; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2473 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2474 | break; |
| 2475 | |
| 2476 | case IOV_SVAL(IOV_SD1IDLE): |
| 2477 | sd1idle = bool_val; |
| 2478 | break; |
| 2479 | |
| 2480 | case IOV_SVAL(IOV_MEMBYTES): |
| 2481 | case IOV_GVAL(IOV_MEMBYTES): |
| 2482 | { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2483 | u32 address; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2484 | uint size, dsize; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2485 | u8 *data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2486 | |
| 2487 | bool set = (actionid == IOV_SVAL(IOV_MEMBYTES)); |
| 2488 | |
| 2489 | ASSERT(plen >= 2 * sizeof(int)); |
| 2490 | |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2491 | address = (u32) int_val; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2492 | memcpy(&int_val, (char *)params + sizeof(int_val), |
| 2493 | sizeof(int_val)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2494 | size = (uint) int_val; |
| 2495 | |
| 2496 | /* Do some validation */ |
| 2497 | dsize = set ? plen - (2 * sizeof(int)) : len; |
| 2498 | if (dsize < size) { |
| 2499 | DHD_ERROR(("%s: error on %s membytes, addr " |
| 2500 | "0x%08x size %d dsize %d\n", |
| 2501 | __func__, (set ? "set" : "get"), |
| 2502 | address, size, dsize)); |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2503 | bcmerror = -EINVAL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2504 | break; |
| 2505 | } |
| 2506 | |
| 2507 | DHD_INFO(("%s: Request to %s %d bytes at address " |
| 2508 | "0x%08x\n", |
| 2509 | __func__, (set ? "write" : "read"), size, address)); |
| 2510 | |
| 2511 | /* If we know about SOCRAM, check for a fit */ |
| 2512 | if ((bus->orig_ramsize) && |
| 2513 | ((address > bus->orig_ramsize) |
| 2514 | || (address + size > bus->orig_ramsize))) { |
| 2515 | DHD_ERROR(("%s: ramsize 0x%08x doesn't have %d " |
| 2516 | "bytes at 0x%08x\n", |
| 2517 | __func__, bus->orig_ramsize, size, address)); |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2518 | bcmerror = -EINVAL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2519 | break; |
| 2520 | } |
| 2521 | |
| 2522 | /* Generate the actual data pointer */ |
| 2523 | data = |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2524 | set ? (u8 *) params + |
| 2525 | 2 * sizeof(int) : (u8 *) arg; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2526 | |
| 2527 | /* Call to do the transfer */ |
| 2528 | bcmerror = |
| 2529 | dhdsdio_membytes(bus, set, address, data, size); |
| 2530 | |
| 2531 | break; |
| 2532 | } |
| 2533 | |
| 2534 | case IOV_GVAL(IOV_MEMSIZE): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2535 | int_val = (s32) bus->ramsize; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2536 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2537 | break; |
| 2538 | |
| 2539 | case IOV_GVAL(IOV_SDIOD_DRIVE): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2540 | int_val = (s32) dhd_sdiod_drive_strength; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2541 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2542 | break; |
| 2543 | |
| 2544 | case IOV_SVAL(IOV_SDIOD_DRIVE): |
| 2545 | dhd_sdiod_drive_strength = int_val; |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 2546 | dhdsdio_sdiod_drive_strength_init(bus, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2547 | dhd_sdiod_drive_strength); |
| 2548 | break; |
| 2549 | |
| 2550 | case IOV_SVAL(IOV_DOWNLOAD): |
| 2551 | bcmerror = dhdsdio_download_state(bus, bool_val); |
| 2552 | break; |
| 2553 | |
| 2554 | case IOV_SVAL(IOV_VARS): |
| 2555 | bcmerror = dhdsdio_downloadvars(bus, arg, len); |
| 2556 | break; |
| 2557 | |
| 2558 | case IOV_GVAL(IOV_READAHEAD): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2559 | int_val = (s32) dhd_readahead; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2560 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2561 | break; |
| 2562 | |
| 2563 | case IOV_SVAL(IOV_READAHEAD): |
| 2564 | if (bool_val && !dhd_readahead) |
| 2565 | bus->nextlen = 0; |
| 2566 | dhd_readahead = bool_val; |
| 2567 | break; |
| 2568 | |
| 2569 | case IOV_GVAL(IOV_SDRXCHAIN): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2570 | int_val = (s32) bus->use_rxchain; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2571 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2572 | break; |
| 2573 | |
| 2574 | case IOV_SVAL(IOV_SDRXCHAIN): |
| 2575 | if (bool_val && !bus->sd_rxchain) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2576 | bcmerror = -ENOTSUPP; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2577 | else |
| 2578 | bus->use_rxchain = bool_val; |
| 2579 | break; |
| 2580 | case IOV_GVAL(IOV_ALIGNCTL): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2581 | int_val = (s32) dhd_alignctl; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2582 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2583 | break; |
| 2584 | |
| 2585 | case IOV_SVAL(IOV_ALIGNCTL): |
| 2586 | dhd_alignctl = bool_val; |
| 2587 | break; |
| 2588 | |
| 2589 | case IOV_GVAL(IOV_SDALIGN): |
| 2590 | int_val = DHD_SDALIGN; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2591 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2592 | break; |
| 2593 | |
| 2594 | #ifdef DHD_DEBUG |
| 2595 | case IOV_GVAL(IOV_VARS): |
| 2596 | if (bus->varsz < (uint) len) |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2597 | memcpy(arg, bus->vars, bus->varsz); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2598 | else |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2599 | bcmerror = -EOVERFLOW; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2600 | break; |
| 2601 | #endif /* DHD_DEBUG */ |
| 2602 | |
| 2603 | #ifdef DHD_DEBUG |
| 2604 | case IOV_GVAL(IOV_SDREG): |
| 2605 | { |
| 2606 | sdreg_t *sd_ptr; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2607 | u32 addr, size; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2608 | |
| 2609 | sd_ptr = (sdreg_t *) params; |
| 2610 | |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 2611 | addr = (unsigned long)bus->regs + sd_ptr->offset; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2612 | size = sd_ptr->func; |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2613 | int_val = (s32) bcmsdh_reg_read(bus->sdh, addr, size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2614 | if (bcmsdh_regfail(bus->sdh)) |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2615 | bcmerror = -EIO; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2616 | memcpy(arg, &int_val, sizeof(s32)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2617 | break; |
| 2618 | } |
| 2619 | |
| 2620 | case IOV_SVAL(IOV_SDREG): |
| 2621 | { |
| 2622 | sdreg_t *sd_ptr; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2623 | u32 addr, size; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2624 | |
| 2625 | sd_ptr = (sdreg_t *) params; |
| 2626 | |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 2627 | addr = (unsigned long)bus->regs + sd_ptr->offset; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2628 | size = sd_ptr->func; |
| 2629 | bcmsdh_reg_write(bus->sdh, addr, size, sd_ptr->value); |
| 2630 | if (bcmsdh_regfail(bus->sdh)) |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2631 | bcmerror = -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2632 | break; |
| 2633 | } |
| 2634 | |
| 2635 | /* Same as above, but offset is not backplane |
| 2636 | (not SDIO core) */ |
| 2637 | case IOV_GVAL(IOV_SBREG): |
| 2638 | { |
| 2639 | sdreg_t sdreg; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2640 | u32 addr, size; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2641 | |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2642 | memcpy(&sdreg, params, sizeof(sdreg)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2643 | |
| 2644 | addr = SI_ENUM_BASE + sdreg.offset; |
| 2645 | size = sdreg.func; |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2646 | int_val = (s32) bcmsdh_reg_read(bus->sdh, addr, size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2647 | if (bcmsdh_regfail(bus->sdh)) |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2648 | bcmerror = -EIO; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2649 | memcpy(arg, &int_val, sizeof(s32)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2650 | break; |
| 2651 | } |
| 2652 | |
| 2653 | case IOV_SVAL(IOV_SBREG): |
| 2654 | { |
| 2655 | sdreg_t sdreg; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2656 | u32 addr, size; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2657 | |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2658 | memcpy(&sdreg, params, sizeof(sdreg)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2659 | |
| 2660 | addr = SI_ENUM_BASE + sdreg.offset; |
| 2661 | size = sdreg.func; |
| 2662 | bcmsdh_reg_write(bus->sdh, addr, size, sdreg.value); |
| 2663 | if (bcmsdh_regfail(bus->sdh)) |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2664 | bcmerror = -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2665 | break; |
| 2666 | } |
| 2667 | |
| 2668 | case IOV_GVAL(IOV_SDCIS): |
| 2669 | { |
| 2670 | *(char *)arg = 0; |
| 2671 | |
nohee ko | ea3b8a2 | 2010-10-09 10:34:38 -0700 | [diff] [blame] | 2672 | strcat(arg, "\nFunc 0\n"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2673 | bcmsdh_cis_read(bus->sdh, 0x10, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2674 | (u8 *) arg + strlen(arg), |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2675 | SBSDIO_CIS_SIZE_LIMIT); |
nohee ko | ea3b8a2 | 2010-10-09 10:34:38 -0700 | [diff] [blame] | 2676 | strcat(arg, "\nFunc 1\n"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2677 | bcmsdh_cis_read(bus->sdh, 0x11, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2678 | (u8 *) arg + strlen(arg), |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2679 | SBSDIO_CIS_SIZE_LIMIT); |
nohee ko | ea3b8a2 | 2010-10-09 10:34:38 -0700 | [diff] [blame] | 2680 | strcat(arg, "\nFunc 2\n"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2681 | bcmsdh_cis_read(bus->sdh, 0x12, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2682 | (u8 *) arg + strlen(arg), |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2683 | SBSDIO_CIS_SIZE_LIMIT); |
| 2684 | break; |
| 2685 | } |
| 2686 | |
| 2687 | case IOV_GVAL(IOV_FORCEEVEN): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2688 | int_val = (s32) forcealign; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2689 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2690 | break; |
| 2691 | |
| 2692 | case IOV_SVAL(IOV_FORCEEVEN): |
| 2693 | forcealign = bool_val; |
| 2694 | break; |
| 2695 | |
| 2696 | case IOV_GVAL(IOV_TXBOUND): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2697 | int_val = (s32) dhd_txbound; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2698 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2699 | break; |
| 2700 | |
| 2701 | case IOV_SVAL(IOV_TXBOUND): |
| 2702 | dhd_txbound = (uint) int_val; |
| 2703 | break; |
| 2704 | |
| 2705 | case IOV_GVAL(IOV_RXBOUND): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2706 | int_val = (s32) dhd_rxbound; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2707 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2708 | break; |
| 2709 | |
| 2710 | case IOV_SVAL(IOV_RXBOUND): |
| 2711 | dhd_rxbound = (uint) int_val; |
| 2712 | break; |
| 2713 | |
| 2714 | case IOV_GVAL(IOV_TXMINMAX): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2715 | int_val = (s32) dhd_txminmax; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2716 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2717 | break; |
| 2718 | |
| 2719 | case IOV_SVAL(IOV_TXMINMAX): |
| 2720 | dhd_txminmax = (uint) int_val; |
| 2721 | break; |
| 2722 | #endif /* DHD_DEBUG */ |
| 2723 | |
| 2724 | #ifdef SDTEST |
| 2725 | case IOV_GVAL(IOV_EXTLOOP): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2726 | int_val = (s32) bus->ext_loop; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2727 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2728 | break; |
| 2729 | |
| 2730 | case IOV_SVAL(IOV_EXTLOOP): |
| 2731 | bus->ext_loop = bool_val; |
| 2732 | break; |
| 2733 | |
| 2734 | case IOV_GVAL(IOV_PKTGEN): |
| 2735 | bcmerror = dhdsdio_pktgen_get(bus, arg); |
| 2736 | break; |
| 2737 | |
| 2738 | case IOV_SVAL(IOV_PKTGEN): |
| 2739 | bcmerror = dhdsdio_pktgen_set(bus, arg); |
| 2740 | break; |
| 2741 | #endif /* SDTEST */ |
| 2742 | |
| 2743 | case IOV_SVAL(IOV_DEVRESET): |
| 2744 | DHD_TRACE(("%s: Called set IOV_DEVRESET=%d dongle_reset=%d " |
| 2745 | "busstate=%d\n", |
| 2746 | __func__, bool_val, bus->dhd->dongle_reset, |
| 2747 | bus->dhd->busstate)); |
| 2748 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2749 | dhd_bus_devreset(bus->dhd, (u8) bool_val); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2750 | |
| 2751 | break; |
| 2752 | |
| 2753 | case IOV_GVAL(IOV_DEVRESET): |
| 2754 | DHD_TRACE(("%s: Called get IOV_DEVRESET\n", __func__)); |
| 2755 | |
| 2756 | /* Get its status */ |
| 2757 | int_val = (bool) bus->dhd->dongle_reset; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2758 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2759 | |
| 2760 | break; |
| 2761 | |
| 2762 | default: |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2763 | bcmerror = -ENOTSUPP; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2764 | break; |
| 2765 | } |
| 2766 | |
| 2767 | exit: |
| 2768 | if ((bus->idletime == DHD_IDLE_IMMEDIATE) && !bus->dpc_sched) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2769 | bus->activity = false; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2770 | dhdsdio_clkctl(bus, CLK_NONE, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2771 | } |
| 2772 | |
| 2773 | dhd_os_sdunlock(bus->dhd); |
| 2774 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2775 | if (actionid == IOV_SVAL(IOV_DEVRESET) && bool_val == false) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2776 | dhd_preinit_ioctls((dhd_pub_t *) bus->dhd); |
| 2777 | |
| 2778 | return bcmerror; |
| 2779 | } |
| 2780 | |
| 2781 | static int dhdsdio_write_vars(dhd_bus_t *bus) |
| 2782 | { |
| 2783 | int bcmerror = 0; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2784 | u32 varsize; |
| 2785 | u32 varaddr; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2786 | u8 *vbuffer; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2787 | u32 varsizew; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2788 | #ifdef DHD_DEBUG |
| 2789 | char *nvram_ularray; |
| 2790 | #endif /* DHD_DEBUG */ |
| 2791 | |
| 2792 | /* Even if there are no vars are to be written, we still |
| 2793 | need to set the ramsize. */ |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 2794 | varsize = bus->varsz ? roundup(bus->varsz, 4) : 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2795 | varaddr = (bus->ramsize - 4) - varsize; |
| 2796 | |
| 2797 | if (bus->vars) { |
Alexander Beregalov | 12d0eb4 | 2011-03-09 03:53:35 +0300 | [diff] [blame] | 2798 | vbuffer = kzalloc(varsize, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2799 | if (!vbuffer) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2800 | return -ENOMEM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2801 | |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2802 | memcpy(vbuffer, bus->vars, bus->varsz); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2803 | |
| 2804 | /* Write the vars list */ |
| 2805 | bcmerror = |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2806 | dhdsdio_membytes(bus, true, varaddr, vbuffer, varsize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2807 | #ifdef DHD_DEBUG |
| 2808 | /* Verify NVRAM bytes */ |
| 2809 | DHD_INFO(("Compare NVRAM dl & ul; varsize=%d\n", varsize)); |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2810 | nvram_ularray = kmalloc(varsize, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2811 | if (!nvram_ularray) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 2812 | return -ENOMEM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2813 | |
| 2814 | /* Upload image to verify downloaded contents. */ |
| 2815 | memset(nvram_ularray, 0xaa, varsize); |
| 2816 | |
| 2817 | /* Read the vars list to temp buffer for comparison */ |
| 2818 | bcmerror = |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2819 | dhdsdio_membytes(bus, false, varaddr, nvram_ularray, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2820 | varsize); |
| 2821 | if (bcmerror) { |
| 2822 | DHD_ERROR(("%s: error %d on reading %d nvram bytes at " |
| 2823 | "0x%08x\n", __func__, bcmerror, varsize, varaddr)); |
| 2824 | } |
| 2825 | /* Compare the org NVRAM with the one read from RAM */ |
| 2826 | if (memcmp(vbuffer, nvram_ularray, varsize)) { |
| 2827 | DHD_ERROR(("%s: Downloaded NVRAM image is corrupted.\n", |
| 2828 | __func__)); |
| 2829 | } else |
| 2830 | DHD_ERROR(("%s: Download/Upload/Compare of NVRAM ok.\n", |
| 2831 | __func__)); |
| 2832 | |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 2833 | kfree(nvram_ularray); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2834 | #endif /* DHD_DEBUG */ |
| 2835 | |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 2836 | kfree(vbuffer); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2837 | } |
| 2838 | |
| 2839 | /* adjust to the user specified RAM */ |
| 2840 | DHD_INFO(("Physical memory size: %d, usable memory size: %d\n", |
| 2841 | bus->orig_ramsize, bus->ramsize)); |
| 2842 | DHD_INFO(("Vars are at %d, orig varsize is %d\n", varaddr, varsize)); |
| 2843 | varsize = ((bus->orig_ramsize - 4) - varaddr); |
| 2844 | |
| 2845 | /* |
| 2846 | * Determine the length token: |
| 2847 | * Varsize, converted to words, in lower 16-bits, checksum |
| 2848 | * in upper 16-bits. |
| 2849 | */ |
| 2850 | if (bcmerror) { |
| 2851 | varsizew = 0; |
| 2852 | } else { |
| 2853 | varsizew = varsize / 4; |
| 2854 | varsizew = (~varsizew << 16) | (varsizew & 0x0000FFFF); |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 2855 | varsizew = cpu_to_le32(varsizew); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2856 | } |
| 2857 | |
| 2858 | DHD_INFO(("New varsize is %d, length token=0x%08x\n", varsize, |
| 2859 | varsizew)); |
| 2860 | |
| 2861 | /* Write the length token to the last word */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2862 | bcmerror = dhdsdio_membytes(bus, true, (bus->orig_ramsize - 4), |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2863 | (u8 *)&varsizew, 4); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2864 | |
| 2865 | return bcmerror; |
| 2866 | } |
| 2867 | |
| 2868 | static int dhdsdio_download_state(dhd_bus_t *bus, bool enter) |
| 2869 | { |
| 2870 | uint retries; |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 2871 | u32 regdata; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2872 | int bcmerror = 0; |
| 2873 | |
| 2874 | /* To enter download state, disable ARM and reset SOCRAM. |
| 2875 | * To exit download state, simply reset ARM (default is RAM boot). |
| 2876 | */ |
| 2877 | if (enter) { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2878 | bus->alp_only = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2879 | |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 2880 | dhdsdio_chip_disablecore(bus->sdh, bus->ci->armcorebase); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2881 | |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 2882 | dhdsdio_chip_resetcore(bus->sdh, bus->ci->ramcorebase); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2883 | |
| 2884 | /* Clear the top bit of memory */ |
| 2885 | if (bus->ramsize) { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2886 | u32 zeros = 0; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2887 | dhdsdio_membytes(bus, true, bus->ramsize - 4, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2888 | (u8 *)&zeros, 4); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2889 | } |
| 2890 | } else { |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 2891 | regdata = bcmsdh_reg_read(bus->sdh, |
| 2892 | CORE_SB(bus->ci->ramcorebase, sbtmstatelow), 4); |
| 2893 | regdata &= (SBTML_RESET | SBTML_REJ_MASK | |
| 2894 | (SICF_CLOCK_EN << SBTML_SICF_SHIFT)); |
| 2895 | if ((SICF_CLOCK_EN << SBTML_SICF_SHIFT) != regdata) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2896 | DHD_ERROR(("%s: SOCRAM core is down after reset?\n", |
| 2897 | __func__)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 2898 | bcmerror = -EBADE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2899 | goto fail; |
| 2900 | } |
| 2901 | |
| 2902 | bcmerror = dhdsdio_write_vars(bus); |
| 2903 | if (bcmerror) { |
| 2904 | DHD_ERROR(("%s: no vars written to RAM\n", __func__)); |
| 2905 | bcmerror = 0; |
| 2906 | } |
| 2907 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2908 | W_SDREG(0xFFFFFFFF, &bus->regs->intstatus, retries); |
| 2909 | |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 2910 | dhdsdio_chip_resetcore(bus->sdh, bus->ci->armcorebase); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2911 | |
| 2912 | /* Allow HT Clock now that the ARM is running. */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2913 | bus->alp_only = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2914 | |
| 2915 | bus->dhd->busstate = DHD_BUS_LOAD; |
| 2916 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2917 | fail: |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2918 | return bcmerror; |
| 2919 | } |
| 2920 | |
| 2921 | int |
| 2922 | dhd_bus_iovar_op(dhd_pub_t *dhdp, const char *name, |
| 2923 | void *params, int plen, void *arg, int len, bool set) |
| 2924 | { |
| 2925 | dhd_bus_t *bus = dhdp->bus; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2926 | const struct brcmu_iovar *vi = NULL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2927 | int bcmerror = 0; |
| 2928 | int val_size; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2929 | u32 actionid; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2930 | |
| 2931 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 2932 | |
| 2933 | ASSERT(name); |
| 2934 | ASSERT(len >= 0); |
| 2935 | |
| 2936 | /* Get MUST have return space */ |
| 2937 | ASSERT(set || (arg && len)); |
| 2938 | |
| 2939 | /* Set does NOT take qualifiers */ |
| 2940 | ASSERT(!set || (!params && !plen)); |
| 2941 | |
| 2942 | /* Look up var locally; if not found pass to host driver */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 2943 | vi = brcmu_iovar_lookup(dhdsdio_iovars, name); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2944 | if (vi == NULL) { |
| 2945 | dhd_os_sdlock(bus->dhd); |
| 2946 | |
| 2947 | BUS_WAKE(bus); |
| 2948 | |
| 2949 | /* Turn on clock in case SD command needs backplane */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2950 | dhdsdio_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2951 | |
| 2952 | bcmerror = |
| 2953 | bcmsdh_iovar_op(bus->sdh, name, params, plen, arg, len, |
| 2954 | set); |
| 2955 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2956 | /* Similar check for blocksize change */ |
| 2957 | if (set && strcmp(name, "sd_blocksize") == 0) { |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2958 | s32 fnum = 2; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2959 | if (bcmsdh_iovar_op |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2960 | (bus->sdh, "sd_blocksize", &fnum, sizeof(s32), |
| 2961 | &bus->blocksize, sizeof(s32), |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 2962 | false) != 0) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2963 | bus->blocksize = 0; |
| 2964 | DHD_ERROR(("%s: fail on %s get\n", __func__, |
| 2965 | "sd_blocksize")); |
| 2966 | } else { |
| 2967 | DHD_INFO(("%s: noted %s update, value now %d\n", |
| 2968 | __func__, "sd_blocksize", |
| 2969 | bus->blocksize)); |
| 2970 | } |
| 2971 | } |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 2972 | bus->roundup = min(max_roundup, bus->blocksize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2973 | |
| 2974 | if ((bus->idletime == DHD_IDLE_IMMEDIATE) && !bus->dpc_sched) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2975 | bus->activity = false; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2976 | dhdsdio_clkctl(bus, CLK_NONE, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2977 | } |
| 2978 | |
| 2979 | dhd_os_sdunlock(bus->dhd); |
| 2980 | goto exit; |
| 2981 | } |
| 2982 | |
| 2983 | DHD_CTL(("%s: %s %s, len %d plen %d\n", __func__, |
| 2984 | name, (set ? "set" : "get"), len, plen)); |
| 2985 | |
| 2986 | /* set up 'params' pointer in case this is a set command so that |
| 2987 | * the convenience int and bool code can be common to set and get |
| 2988 | */ |
| 2989 | if (params == NULL) { |
| 2990 | params = arg; |
| 2991 | plen = len; |
| 2992 | } |
| 2993 | |
| 2994 | if (vi->type == IOVT_VOID) |
| 2995 | val_size = 0; |
| 2996 | else if (vi->type == IOVT_BUFFER) |
| 2997 | val_size = len; |
| 2998 | else |
| 2999 | /* all other types are integer sized */ |
| 3000 | val_size = sizeof(int); |
| 3001 | |
| 3002 | actionid = set ? IOV_SVAL(vi->varid) : IOV_GVAL(vi->varid); |
| 3003 | bcmerror = |
| 3004 | dhdsdio_doiovar(bus, vi, actionid, name, params, plen, arg, len, |
| 3005 | val_size); |
| 3006 | |
| 3007 | exit: |
| 3008 | return bcmerror; |
| 3009 | } |
| 3010 | |
| 3011 | void dhd_bus_stop(struct dhd_bus *bus, bool enforce_mutex) |
| 3012 | { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 3013 | u32 local_hostintmask; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3014 | u8 saveclk; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3015 | uint retries; |
| 3016 | int err; |
| 3017 | |
| 3018 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 3019 | |
| 3020 | if (enforce_mutex) |
| 3021 | dhd_os_sdlock(bus->dhd); |
| 3022 | |
| 3023 | BUS_WAKE(bus); |
| 3024 | |
| 3025 | /* Enable clock for device interrupts */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3026 | dhdsdio_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3027 | |
| 3028 | /* Disable and clear interrupts at the chip level also */ |
| 3029 | W_SDREG(0, &bus->regs->hostintmask, retries); |
| 3030 | local_hostintmask = bus->hostintmask; |
| 3031 | bus->hostintmask = 0; |
| 3032 | |
| 3033 | /* Change our idea of bus state */ |
| 3034 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 3035 | |
| 3036 | /* Force clocks on backplane to be sure F2 interrupt propagates */ |
| 3037 | saveclk = |
| 3038 | bcmsdh_cfg_read(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 3039 | &err); |
| 3040 | if (!err) { |
| 3041 | bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 3042 | (saveclk | SBSDIO_FORCE_HT), &err); |
| 3043 | } |
| 3044 | if (err) { |
| 3045 | DHD_ERROR(("%s: Failed to force clock for F2: err %d\n", |
| 3046 | __func__, err)); |
| 3047 | } |
| 3048 | |
| 3049 | /* Turn off the bus (F2), free any pending packets */ |
| 3050 | DHD_INTR(("%s: disable SDIO interrupts\n", __func__)); |
| 3051 | bcmsdh_intr_disable(bus->sdh); |
Franky Lin | 0df4604 | 2011-06-01 13:45:40 +0200 | [diff] [blame] | 3052 | bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_0, SDIO_CCCR_IOEx, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3053 | SDIO_FUNC_ENABLE_1, NULL); |
| 3054 | |
| 3055 | /* Clear any pending interrupts now that F2 is disabled */ |
| 3056 | W_SDREG(local_hostintmask, &bus->regs->intstatus, retries); |
| 3057 | |
| 3058 | /* Turn off the backplane clock (only) */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3059 | dhdsdio_clkctl(bus, CLK_SDONLY, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3060 | |
| 3061 | /* Clear the data packet queues */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3062 | brcmu_pktq_flush(&bus->txq, true, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3063 | |
| 3064 | /* Clear any held glomming stuff */ |
| 3065 | if (bus->glomd) |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3066 | brcmu_pkt_buf_free_skb(bus->glomd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3067 | |
| 3068 | if (bus->glom) |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3069 | brcmu_pkt_buf_free_skb(bus->glom); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3070 | |
| 3071 | bus->glom = bus->glomd = NULL; |
| 3072 | |
| 3073 | /* Clear rx control and wake any waiters */ |
| 3074 | bus->rxlen = 0; |
| 3075 | dhd_os_ioctl_resp_wake(bus->dhd); |
| 3076 | |
| 3077 | /* Reset some F2 state stuff */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3078 | bus->rxskip = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3079 | bus->tx_seq = bus->rx_seq = 0; |
| 3080 | |
| 3081 | if (enforce_mutex) |
| 3082 | dhd_os_sdunlock(bus->dhd); |
| 3083 | } |
| 3084 | |
| 3085 | int dhd_bus_init(dhd_pub_t *dhdp, bool enforce_mutex) |
| 3086 | { |
| 3087 | dhd_bus_t *bus = dhdp->bus; |
| 3088 | dhd_timeout_t tmo; |
| 3089 | uint retries = 0; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3090 | u8 ready, enable; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3091 | int err, ret = 0; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3092 | u8 saveclk; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3093 | |
| 3094 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 3095 | |
| 3096 | ASSERT(bus->dhd); |
| 3097 | if (!bus->dhd) |
| 3098 | return 0; |
| 3099 | |
| 3100 | if (enforce_mutex) |
| 3101 | dhd_os_sdlock(bus->dhd); |
| 3102 | |
| 3103 | /* Make sure backplane clock is on, needed to generate F2 interrupt */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3104 | dhdsdio_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3105 | if (bus->clkstate != CLK_AVAIL) |
| 3106 | goto exit; |
| 3107 | |
| 3108 | /* Force clocks on backplane to be sure F2 interrupt propagates */ |
| 3109 | saveclk = |
| 3110 | bcmsdh_cfg_read(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 3111 | &err); |
| 3112 | if (!err) { |
| 3113 | bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 3114 | (saveclk | SBSDIO_FORCE_HT), &err); |
| 3115 | } |
| 3116 | if (err) { |
| 3117 | DHD_ERROR(("%s: Failed to force clock for F2: err %d\n", |
| 3118 | __func__, err)); |
| 3119 | goto exit; |
| 3120 | } |
| 3121 | |
| 3122 | /* Enable function 2 (frame transfers) */ |
| 3123 | W_SDREG((SDPCM_PROT_VERSION << SMB_DATA_VERSION_SHIFT), |
| 3124 | &bus->regs->tosbmailboxdata, retries); |
| 3125 | enable = (SDIO_FUNC_ENABLE_1 | SDIO_FUNC_ENABLE_2); |
| 3126 | |
Franky Lin | 0df4604 | 2011-06-01 13:45:40 +0200 | [diff] [blame] | 3127 | bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_0, SDIO_CCCR_IOEx, enable, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3128 | |
| 3129 | /* Give the dongle some time to do its thing and set IOR2 */ |
| 3130 | dhd_timeout_start(&tmo, DHD_WAIT_F2RDY * 1000); |
| 3131 | |
| 3132 | ready = 0; |
| 3133 | while (ready != enable && !dhd_timeout_expired(&tmo)) |
| 3134 | ready = |
Franky Lin | 0df4604 | 2011-06-01 13:45:40 +0200 | [diff] [blame] | 3135 | bcmsdh_cfg_read(bus->sdh, SDIO_FUNC_0, SDIO_CCCR_IORx, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3136 | NULL); |
| 3137 | |
| 3138 | DHD_INFO(("%s: enable 0x%02x, ready 0x%02x (waited %uus)\n", |
| 3139 | __func__, enable, ready, tmo.elapsed)); |
| 3140 | |
| 3141 | /* If F2 successfully enabled, set core and enable interrupts */ |
| 3142 | if (ready == enable) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3143 | /* Set up the interrupt mask and enable interrupts */ |
| 3144 | bus->hostintmask = HOSTINTMASK; |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 3145 | W_SDREG(bus->hostintmask, |
| 3146 | (unsigned int *)CORE_BUS_REG(bus->ci->buscorebase, |
| 3147 | hostintmask), retries); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3148 | |
| 3149 | bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_WATERMARK, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3150 | (u8) watermark, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3151 | |
| 3152 | /* Set bus state according to enable result */ |
| 3153 | dhdp->busstate = DHD_BUS_DATA; |
| 3154 | |
| 3155 | /* bcmsdh_intr_unmask(bus->sdh); */ |
| 3156 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3157 | bus->intdis = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3158 | if (bus->intr) { |
| 3159 | DHD_INTR(("%s: enable SDIO device interrupts\n", |
| 3160 | __func__)); |
| 3161 | bcmsdh_intr_enable(bus->sdh); |
| 3162 | } else { |
| 3163 | DHD_INTR(("%s: disable SDIO interrupts\n", __func__)); |
| 3164 | bcmsdh_intr_disable(bus->sdh); |
| 3165 | } |
| 3166 | |
| 3167 | } |
| 3168 | |
| 3169 | else { |
| 3170 | /* Disable F2 again */ |
| 3171 | enable = SDIO_FUNC_ENABLE_1; |
Franky Lin | 0df4604 | 2011-06-01 13:45:40 +0200 | [diff] [blame] | 3172 | bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_0, SDIO_CCCR_IOEx, enable, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3173 | NULL); |
| 3174 | } |
| 3175 | |
| 3176 | /* Restore previous clock setting */ |
| 3177 | bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 3178 | saveclk, &err); |
| 3179 | |
| 3180 | /* If we didn't come up, turn off backplane clock */ |
| 3181 | if (dhdp->busstate != DHD_BUS_DATA) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3182 | dhdsdio_clkctl(bus, CLK_NONE, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3183 | |
| 3184 | exit: |
| 3185 | if (enforce_mutex) |
| 3186 | dhd_os_sdunlock(bus->dhd); |
| 3187 | |
| 3188 | return ret; |
| 3189 | } |
| 3190 | |
| 3191 | static void dhdsdio_rxfail(dhd_bus_t *bus, bool abort, bool rtx) |
| 3192 | { |
| 3193 | bcmsdh_info_t *sdh = bus->sdh; |
Franky Lin | 597600a | 2011-06-01 13:45:39 +0200 | [diff] [blame] | 3194 | struct sdpcmd_regs *regs = bus->regs; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3195 | uint retries = 0; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3196 | u16 lastrbc; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3197 | u8 hi, lo; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3198 | int err; |
| 3199 | |
| 3200 | DHD_ERROR(("%s: %sterminate frame%s\n", __func__, |
| 3201 | (abort ? "abort command, " : ""), |
| 3202 | (rtx ? ", send NAK" : ""))); |
| 3203 | |
| 3204 | if (abort) |
| 3205 | bcmsdh_abort(sdh, SDIO_FUNC_2); |
| 3206 | |
| 3207 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_FRAMECTRL, SFC_RF_TERM, |
| 3208 | &err); |
| 3209 | bus->f1regdata++; |
| 3210 | |
| 3211 | /* Wait until the packet has been flushed (device/FIFO stable) */ |
| 3212 | for (lastrbc = retries = 0xffff; retries > 0; retries--) { |
| 3213 | hi = bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_RFRAMEBCHI, |
| 3214 | NULL); |
| 3215 | lo = bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_RFRAMEBCLO, |
| 3216 | NULL); |
| 3217 | bus->f1regdata += 2; |
| 3218 | |
| 3219 | if ((hi == 0) && (lo == 0)) |
| 3220 | break; |
| 3221 | |
| 3222 | if ((hi > (lastrbc >> 8)) && (lo > (lastrbc & 0x00ff))) { |
| 3223 | DHD_ERROR(("%s: count growing: last 0x%04x now " |
| 3224 | "0x%04x\n", |
| 3225 | __func__, lastrbc, ((hi << 8) + lo))); |
| 3226 | } |
| 3227 | lastrbc = (hi << 8) + lo; |
| 3228 | } |
| 3229 | |
| 3230 | if (!retries) { |
| 3231 | DHD_ERROR(("%s: count never zeroed: last 0x%04x\n", |
| 3232 | __func__, lastrbc)); |
| 3233 | } else { |
| 3234 | DHD_INFO(("%s: flush took %d iterations\n", __func__, |
| 3235 | (0xffff - retries))); |
| 3236 | } |
| 3237 | |
| 3238 | if (rtx) { |
| 3239 | bus->rxrtx++; |
| 3240 | W_SDREG(SMB_NAK, ®s->tosbmailbox, retries); |
| 3241 | bus->f1regdata++; |
| 3242 | if (retries <= retry_limit) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3243 | bus->rxskip = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3244 | } |
| 3245 | |
| 3246 | /* Clear partial in any case */ |
| 3247 | bus->nextlen = 0; |
| 3248 | |
| 3249 | /* If we can't reach the device, signal failure */ |
| 3250 | if (err || bcmsdh_regfail(sdh)) |
| 3251 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 3252 | } |
| 3253 | |
| 3254 | static void |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3255 | dhdsdio_read_control(dhd_bus_t *bus, u8 *hdr, uint len, uint doff) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3256 | { |
| 3257 | bcmsdh_info_t *sdh = bus->sdh; |
| 3258 | uint rdlen, pad; |
| 3259 | |
| 3260 | int sdret; |
| 3261 | |
| 3262 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 3263 | |
| 3264 | /* Control data already received in aligned rxctl */ |
| 3265 | if ((bus->bus == SPI_BUS) && (!bus->usebufpool)) |
| 3266 | goto gotpkt; |
| 3267 | |
| 3268 | ASSERT(bus->rxbuf); |
| 3269 | /* Set rxctl for frame (w/optional alignment) */ |
| 3270 | bus->rxctl = bus->rxbuf; |
| 3271 | if (dhd_alignctl) { |
| 3272 | bus->rxctl += firstread; |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 3273 | pad = ((unsigned long)bus->rxctl % DHD_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3274 | if (pad) |
| 3275 | bus->rxctl += (DHD_SDALIGN - pad); |
| 3276 | bus->rxctl -= firstread; |
| 3277 | } |
| 3278 | ASSERT(bus->rxctl >= bus->rxbuf); |
| 3279 | |
| 3280 | /* Copy the already-read portion over */ |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 3281 | memcpy(bus->rxctl, hdr, firstread); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3282 | if (len <= firstread) |
| 3283 | goto gotpkt; |
| 3284 | |
| 3285 | /* Copy the full data pkt in gSPI case and process ioctl. */ |
| 3286 | if (bus->bus == SPI_BUS) { |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 3287 | memcpy(bus->rxctl, hdr, len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3288 | goto gotpkt; |
| 3289 | } |
| 3290 | |
| 3291 | /* Raise rdlen to next SDIO block to avoid tail command */ |
| 3292 | rdlen = len - firstread; |
| 3293 | if (bus->roundup && bus->blocksize && (rdlen > bus->blocksize)) { |
| 3294 | pad = bus->blocksize - (rdlen % bus->blocksize); |
| 3295 | if ((pad <= bus->roundup) && (pad < bus->blocksize) && |
| 3296 | ((len + pad) < bus->dhd->maxctl)) |
| 3297 | rdlen += pad; |
| 3298 | } else if (rdlen % DHD_SDALIGN) { |
| 3299 | rdlen += DHD_SDALIGN - (rdlen % DHD_SDALIGN); |
| 3300 | } |
| 3301 | |
| 3302 | /* Satisfy length-alignment requirements */ |
| 3303 | if (forcealign && (rdlen & (ALIGNMENT - 1))) |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 3304 | rdlen = roundup(rdlen, ALIGNMENT); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3305 | |
| 3306 | /* Drop if the read is too big or it exceeds our maximum */ |
| 3307 | if ((rdlen + firstread) > bus->dhd->maxctl) { |
| 3308 | DHD_ERROR(("%s: %d-byte control read exceeds %d-byte buffer\n", |
| 3309 | __func__, rdlen, bus->dhd->maxctl)); |
| 3310 | bus->dhd->rx_errors++; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3311 | dhdsdio_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3312 | goto done; |
| 3313 | } |
| 3314 | |
| 3315 | if ((len - doff) > bus->dhd->maxctl) { |
| 3316 | DHD_ERROR(("%s: %d-byte ctl frame (%d-byte ctl data) exceeds " |
| 3317 | "%d-byte limit\n", |
| 3318 | __func__, len, (len - doff), bus->dhd->maxctl)); |
| 3319 | bus->dhd->rx_errors++; |
| 3320 | bus->rx_toolong++; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3321 | dhdsdio_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3322 | goto done; |
| 3323 | } |
| 3324 | |
| 3325 | /* Read remainder of frame body into the rxctl buffer */ |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 3326 | sdret = bcmsdh_recv_buf(bus, bcmsdh_cur_sbwad(sdh), SDIO_FUNC_2, |
| 3327 | F2SYNC, (bus->rxctl + firstread), rdlen, |
| 3328 | NULL, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3329 | bus->f2rxdata++; |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 3330 | ASSERT(sdret != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3331 | |
| 3332 | /* Control frame failures need retransmission */ |
| 3333 | if (sdret < 0) { |
| 3334 | DHD_ERROR(("%s: read %d control bytes failed: %d\n", |
| 3335 | __func__, rdlen, sdret)); |
| 3336 | bus->rxc_errors++; /* dhd.rx_ctlerrs is higher level */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3337 | dhdsdio_rxfail(bus, true, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3338 | goto done; |
| 3339 | } |
| 3340 | |
| 3341 | gotpkt: |
| 3342 | |
| 3343 | #ifdef DHD_DEBUG |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 3344 | if (DHD_BYTES_ON() && DHD_CTL_ON()) { |
| 3345 | printk(KERN_DEBUG "RxCtrl:\n"); |
| 3346 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, bus->rxctl, len); |
| 3347 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3348 | #endif |
| 3349 | |
| 3350 | /* Point to valid data and indicate its length */ |
| 3351 | bus->rxctl += doff; |
| 3352 | bus->rxlen = len - doff; |
| 3353 | |
| 3354 | done: |
| 3355 | /* Awake any waiters */ |
| 3356 | dhd_os_ioctl_resp_wake(bus->dhd); |
| 3357 | } |
| 3358 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3359 | static u8 dhdsdio_rxglom(dhd_bus_t *bus, u8 rxseq) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3360 | { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3361 | u16 dlen, totlen; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3362 | u8 *dptr, num = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3363 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3364 | u16 sublen, check; |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 3365 | struct sk_buff *pfirst, *plast, *pnext, *save_pfirst; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3366 | |
| 3367 | int errcode; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3368 | u8 chan, seq, doff, sfdoff; |
| 3369 | u8 txmax; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3370 | |
| 3371 | int ifidx = 0; |
| 3372 | bool usechain = bus->use_rxchain; |
| 3373 | |
| 3374 | /* If packets, issue read(s) and send up packet chain */ |
| 3375 | /* Return sequence numbers consumed? */ |
| 3376 | |
| 3377 | DHD_TRACE(("dhdsdio_rxglom: start: glomd %p glom %p\n", bus->glomd, |
| 3378 | bus->glom)); |
| 3379 | |
| 3380 | /* If there's a descriptor, generate the packet chain */ |
| 3381 | if (bus->glomd) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3382 | pfirst = plast = pnext = NULL; |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3383 | dlen = (u16) (bus->glomd->len); |
| 3384 | dptr = bus->glomd->data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3385 | if (!dlen || (dlen & 1)) { |
| 3386 | DHD_ERROR(("%s: bad glomd len(%d), ignore descriptor\n", |
| 3387 | __func__, dlen)); |
| 3388 | dlen = 0; |
| 3389 | } |
| 3390 | |
| 3391 | for (totlen = num = 0; dlen; num++) { |
| 3392 | /* Get (and move past) next length */ |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 3393 | sublen = get_unaligned_le16(dptr); |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3394 | dlen -= sizeof(u16); |
| 3395 | dptr += sizeof(u16); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3396 | if ((sublen < SDPCM_HDRLEN) || |
| 3397 | ((num == 0) && (sublen < (2 * SDPCM_HDRLEN)))) { |
| 3398 | DHD_ERROR(("%s: descriptor len %d bad: %d\n", |
| 3399 | __func__, num, sublen)); |
| 3400 | pnext = NULL; |
| 3401 | break; |
| 3402 | } |
| 3403 | if (sublen % DHD_SDALIGN) { |
| 3404 | DHD_ERROR(("%s: sublen %d not multiple of %d\n", |
| 3405 | __func__, sublen, DHD_SDALIGN)); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3406 | usechain = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3407 | } |
| 3408 | totlen += sublen; |
| 3409 | |
| 3410 | /* For last frame, adjust read len so total |
| 3411 | is a block multiple */ |
| 3412 | if (!dlen) { |
| 3413 | sublen += |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 3414 | (roundup(totlen, bus->blocksize) - totlen); |
| 3415 | totlen = roundup(totlen, bus->blocksize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3416 | } |
| 3417 | |
| 3418 | /* Allocate/chain packet for next subframe */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3419 | pnext = brcmu_pkt_buf_get_skb(sublen + DHD_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3420 | if (pnext == NULL) { |
Henry Ptasinski | b33f0e2 | 2011-05-10 22:25:29 +0200 | [diff] [blame] | 3421 | DHD_ERROR(("%s: bcm_pkt_buf_get_skb failed, " |
| 3422 | "num %d len %d\n", __func__, |
| 3423 | num, sublen)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3424 | break; |
| 3425 | } |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3426 | ASSERT(!(pnext->prev)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3427 | if (!pfirst) { |
| 3428 | ASSERT(!plast); |
| 3429 | pfirst = plast = pnext; |
| 3430 | } else { |
| 3431 | ASSERT(plast); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3432 | plast->next = pnext; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3433 | plast = pnext; |
| 3434 | } |
| 3435 | |
| 3436 | /* Adhere to start alignment requirements */ |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 3437 | PKTALIGN(pnext, sublen, DHD_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3438 | } |
| 3439 | |
| 3440 | /* If all allocations succeeded, save packet chain |
| 3441 | in bus structure */ |
| 3442 | if (pnext) { |
| 3443 | DHD_GLOM(("%s: allocated %d-byte packet chain for %d " |
| 3444 | "subframes\n", __func__, totlen, num)); |
| 3445 | if (DHD_GLOM_ON() && bus->nextlen) { |
| 3446 | if (totlen != bus->nextlen) { |
| 3447 | DHD_GLOM(("%s: glomdesc mismatch: nextlen %d glomdesc %d " "rxseq %d\n", |
| 3448 | __func__, bus->nextlen, |
| 3449 | totlen, rxseq)); |
| 3450 | } |
| 3451 | } |
| 3452 | bus->glom = pfirst; |
| 3453 | pfirst = pnext = NULL; |
| 3454 | } else { |
| 3455 | if (pfirst) |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3456 | brcmu_pkt_buf_free_skb(pfirst); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3457 | bus->glom = NULL; |
| 3458 | num = 0; |
| 3459 | } |
| 3460 | |
| 3461 | /* Done with descriptor packet */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3462 | brcmu_pkt_buf_free_skb(bus->glomd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3463 | bus->glomd = NULL; |
| 3464 | bus->nextlen = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3465 | } |
| 3466 | |
| 3467 | /* Ok -- either we just generated a packet chain, |
| 3468 | or had one from before */ |
| 3469 | if (bus->glom) { |
| 3470 | if (DHD_GLOM_ON()) { |
| 3471 | DHD_GLOM(("%s: try superframe read, packet chain:\n", |
| 3472 | __func__)); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3473 | for (pnext = bus->glom; pnext; pnext = pnext->next) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3474 | DHD_GLOM((" %p: %p len 0x%04x (%d)\n", |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3475 | pnext, (u8 *) (pnext->data), |
| 3476 | pnext->len, pnext->len)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3477 | } |
| 3478 | } |
| 3479 | |
| 3480 | pfirst = bus->glom; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3481 | dlen = (u16) brcmu_pkttotlen(pfirst); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3482 | |
| 3483 | /* Do an SDIO read for the superframe. Configurable iovar to |
| 3484 | * read directly into the chained packet, or allocate a large |
| 3485 | * packet and and copy into the chain. |
| 3486 | */ |
| 3487 | if (usechain) { |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 3488 | errcode = bcmsdh_recv_buf(bus, |
| 3489 | bcmsdh_cur_sbwad(bus->sdh), SDIO_FUNC_2, |
| 3490 | F2SYNC, (u8 *) pfirst->data, dlen, |
| 3491 | pfirst, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3492 | } else if (bus->dataptr) { |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 3493 | errcode = bcmsdh_recv_buf(bus, |
| 3494 | bcmsdh_cur_sbwad(bus->sdh), SDIO_FUNC_2, |
| 3495 | F2SYNC, bus->dataptr, dlen, |
| 3496 | NULL, NULL, NULL); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3497 | sublen = (u16) brcmu_pktfrombuf(pfirst, 0, dlen, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3498 | bus->dataptr); |
| 3499 | if (sublen != dlen) { |
| 3500 | DHD_ERROR(("%s: FAILED TO COPY, dlen %d sublen %d\n", |
| 3501 | __func__, dlen, sublen)); |
| 3502 | errcode = -1; |
| 3503 | } |
| 3504 | pnext = NULL; |
| 3505 | } else { |
| 3506 | DHD_ERROR(("COULDN'T ALLOC %d-BYTE GLOM, FORCE FAILURE\n", |
| 3507 | dlen)); |
| 3508 | errcode = -1; |
| 3509 | } |
| 3510 | bus->f2rxdata++; |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 3511 | ASSERT(errcode != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3512 | |
| 3513 | /* On failure, kill the superframe, allow a couple retries */ |
| 3514 | if (errcode < 0) { |
| 3515 | DHD_ERROR(("%s: glom read of %d bytes failed: %d\n", |
| 3516 | __func__, dlen, errcode)); |
| 3517 | bus->dhd->rx_errors++; |
| 3518 | |
| 3519 | if (bus->glomerr++ < 3) { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3520 | dhdsdio_rxfail(bus, true, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3521 | } else { |
| 3522 | bus->glomerr = 0; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3523 | dhdsdio_rxfail(bus, true, false); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3524 | brcmu_pkt_buf_free_skb(bus->glom); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3525 | bus->rxglomfail++; |
| 3526 | bus->glom = NULL; |
| 3527 | } |
| 3528 | return 0; |
| 3529 | } |
| 3530 | #ifdef DHD_DEBUG |
| 3531 | if (DHD_GLOM_ON()) { |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 3532 | printk(KERN_DEBUG "SUPERFRAME:\n"); |
| 3533 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 3534 | pfirst->data, min_t(int, pfirst->len, 48)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3535 | } |
| 3536 | #endif |
| 3537 | |
| 3538 | /* Validate the superframe header */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3539 | dptr = (u8 *) (pfirst->data); |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 3540 | sublen = get_unaligned_le16(dptr); |
| 3541 | check = get_unaligned_le16(dptr + sizeof(u16)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3542 | |
| 3543 | chan = SDPCM_PACKET_CHANNEL(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3544 | seq = SDPCM_PACKET_SEQUENCE(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3545 | bus->nextlen = dptr[SDPCM_FRAMETAG_LEN + SDPCM_NEXTLEN_OFFSET]; |
| 3546 | if ((bus->nextlen << 4) > MAX_RX_DATASZ) { |
| 3547 | DHD_INFO(("%s: nextlen too large (%d) seq %d\n", |
| 3548 | __func__, bus->nextlen, seq)); |
| 3549 | bus->nextlen = 0; |
| 3550 | } |
| 3551 | doff = SDPCM_DOFFSET_VALUE(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3552 | txmax = SDPCM_WINDOW_VALUE(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3553 | |
| 3554 | errcode = 0; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3555 | if ((u16)~(sublen ^ check)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3556 | DHD_ERROR(("%s (superframe): HW hdr error: len/check " |
| 3557 | "0x%04x/0x%04x\n", __func__, sublen, check)); |
| 3558 | errcode = -1; |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 3559 | } else if (roundup(sublen, bus->blocksize) != dlen) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3560 | DHD_ERROR(("%s (superframe): len 0x%04x, rounded " |
| 3561 | "0x%04x, expect 0x%04x\n", |
| 3562 | __func__, sublen, |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 3563 | roundup(sublen, bus->blocksize), dlen)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3564 | errcode = -1; |
| 3565 | } else if (SDPCM_PACKET_CHANNEL(&dptr[SDPCM_FRAMETAG_LEN]) != |
| 3566 | SDPCM_GLOM_CHANNEL) { |
| 3567 | DHD_ERROR(("%s (superframe): bad channel %d\n", |
| 3568 | __func__, |
| 3569 | SDPCM_PACKET_CHANNEL(&dptr |
| 3570 | [SDPCM_FRAMETAG_LEN]))); |
| 3571 | errcode = -1; |
| 3572 | } else if (SDPCM_GLOMDESC(&dptr[SDPCM_FRAMETAG_LEN])) { |
| 3573 | DHD_ERROR(("%s (superframe): got second descriptor?\n", |
| 3574 | __func__)); |
| 3575 | errcode = -1; |
| 3576 | } else if ((doff < SDPCM_HDRLEN) || |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3577 | (doff > (pfirst->len - SDPCM_HDRLEN))) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3578 | DHD_ERROR(("%s (superframe): Bad data offset %d: HW %d " |
| 3579 | "pkt %d min %d\n", |
| 3580 | __func__, doff, sublen, |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3581 | pfirst->len, SDPCM_HDRLEN)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3582 | errcode = -1; |
| 3583 | } |
| 3584 | |
| 3585 | /* Check sequence number of superframe SW header */ |
| 3586 | if (rxseq != seq) { |
| 3587 | DHD_INFO(("%s: (superframe) rx_seq %d, expected %d\n", |
| 3588 | __func__, seq, rxseq)); |
| 3589 | bus->rx_badseq++; |
| 3590 | rxseq = seq; |
| 3591 | } |
| 3592 | |
| 3593 | /* Check window for sanity */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3594 | if ((u8) (txmax - bus->tx_seq) > 0x40) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3595 | DHD_ERROR(("%s: unlikely tx max %d with tx_seq %d\n", |
| 3596 | __func__, txmax, bus->tx_seq)); |
| 3597 | txmax = bus->tx_seq + 2; |
| 3598 | } |
| 3599 | bus->tx_max = txmax; |
| 3600 | |
| 3601 | /* Remove superframe header, remember offset */ |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 3602 | skb_pull(pfirst, doff); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3603 | sfdoff = doff; |
| 3604 | |
| 3605 | /* Validate all the subframe headers */ |
| 3606 | for (num = 0, pnext = pfirst; pnext && !errcode; |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3607 | num++, pnext = pnext->next) { |
| 3608 | dptr = (u8 *) (pnext->data); |
| 3609 | dlen = (u16) (pnext->len); |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 3610 | sublen = get_unaligned_le16(dptr); |
| 3611 | check = get_unaligned_le16(dptr + sizeof(u16)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3612 | chan = SDPCM_PACKET_CHANNEL(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3613 | doff = SDPCM_DOFFSET_VALUE(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3614 | #ifdef DHD_DEBUG |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 3615 | if (DHD_GLOM_ON()) { |
| 3616 | printk(KERN_DEBUG "subframe:\n"); |
| 3617 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 3618 | dptr, 32); |
| 3619 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3620 | #endif |
| 3621 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3622 | if ((u16)~(sublen ^ check)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3623 | DHD_ERROR(("%s (subframe %d): HW hdr error: " |
| 3624 | "len/check 0x%04x/0x%04x\n", |
| 3625 | __func__, num, sublen, check)); |
| 3626 | errcode = -1; |
| 3627 | } else if ((sublen > dlen) || (sublen < SDPCM_HDRLEN)) { |
| 3628 | DHD_ERROR(("%s (subframe %d): length mismatch: " |
| 3629 | "len 0x%04x, expect 0x%04x\n", |
| 3630 | __func__, num, sublen, dlen)); |
| 3631 | errcode = -1; |
| 3632 | } else if ((chan != SDPCM_DATA_CHANNEL) && |
| 3633 | (chan != SDPCM_EVENT_CHANNEL)) { |
| 3634 | DHD_ERROR(("%s (subframe %d): bad channel %d\n", |
| 3635 | __func__, num, chan)); |
| 3636 | errcode = -1; |
| 3637 | } else if ((doff < SDPCM_HDRLEN) || (doff > sublen)) { |
| 3638 | DHD_ERROR(("%s (subframe %d): Bad data offset %d: HW %d min %d\n", |
| 3639 | __func__, num, doff, sublen, |
| 3640 | SDPCM_HDRLEN)); |
| 3641 | errcode = -1; |
| 3642 | } |
| 3643 | } |
| 3644 | |
| 3645 | if (errcode) { |
| 3646 | /* Terminate frame on error, request |
| 3647 | a couple retries */ |
| 3648 | if (bus->glomerr++ < 3) { |
| 3649 | /* Restore superframe header space */ |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 3650 | skb_push(pfirst, sfdoff); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3651 | dhdsdio_rxfail(bus, true, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3652 | } else { |
| 3653 | bus->glomerr = 0; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3654 | dhdsdio_rxfail(bus, true, false); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3655 | brcmu_pkt_buf_free_skb(bus->glom); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3656 | bus->rxglomfail++; |
| 3657 | bus->glom = NULL; |
| 3658 | } |
| 3659 | bus->nextlen = 0; |
| 3660 | return 0; |
| 3661 | } |
| 3662 | |
| 3663 | /* Basic SD framing looks ok - process each packet (header) */ |
| 3664 | save_pfirst = pfirst; |
| 3665 | bus->glom = NULL; |
| 3666 | plast = NULL; |
| 3667 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3668 | for (num = 0; pfirst; rxseq++, pfirst = pnext) { |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3669 | pnext = pfirst->next; |
| 3670 | pfirst->next = NULL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3671 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3672 | dptr = (u8 *) (pfirst->data); |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 3673 | sublen = get_unaligned_le16(dptr); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3674 | chan = SDPCM_PACKET_CHANNEL(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3675 | seq = SDPCM_PACKET_SEQUENCE(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3676 | doff = SDPCM_DOFFSET_VALUE(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3677 | |
| 3678 | DHD_GLOM(("%s: Get subframe %d, %p(%p/%d), sublen %d " |
| 3679 | "chan %d seq %d\n", |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3680 | __func__, num, pfirst, pfirst->data, |
| 3681 | pfirst->len, sublen, chan, seq)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3682 | |
| 3683 | ASSERT((chan == SDPCM_DATA_CHANNEL) |
| 3684 | || (chan == SDPCM_EVENT_CHANNEL)); |
| 3685 | |
| 3686 | if (rxseq != seq) { |
| 3687 | DHD_GLOM(("%s: rx_seq %d, expected %d\n", |
| 3688 | __func__, seq, rxseq)); |
| 3689 | bus->rx_badseq++; |
| 3690 | rxseq = seq; |
| 3691 | } |
| 3692 | #ifdef DHD_DEBUG |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 3693 | if (DHD_BYTES_ON() && DHD_DATA_ON()) { |
| 3694 | printk(KERN_DEBUG "Rx Subframe Data:\n"); |
| 3695 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 3696 | dptr, dlen); |
| 3697 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3698 | #endif |
| 3699 | |
Arend van Spriel | 2cb8ada | 2010-11-18 20:46:44 +0100 | [diff] [blame] | 3700 | __skb_trim(pfirst, sublen); |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 3701 | skb_pull(pfirst, doff); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3702 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3703 | if (pfirst->len == 0) { |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3704 | brcmu_pkt_buf_free_skb(pfirst); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3705 | if (plast) { |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3706 | plast->next = pnext; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3707 | } else { |
| 3708 | ASSERT(save_pfirst == pfirst); |
| 3709 | save_pfirst = pnext; |
| 3710 | } |
| 3711 | continue; |
| 3712 | } else if (dhd_prot_hdrpull(bus->dhd, &ifidx, pfirst) != |
| 3713 | 0) { |
| 3714 | DHD_ERROR(("%s: rx protocol error\n", |
| 3715 | __func__)); |
| 3716 | bus->dhd->rx_errors++; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3717 | brcmu_pkt_buf_free_skb(pfirst); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3718 | if (plast) { |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3719 | plast->next = pnext; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3720 | } else { |
| 3721 | ASSERT(save_pfirst == pfirst); |
| 3722 | save_pfirst = pnext; |
| 3723 | } |
| 3724 | continue; |
| 3725 | } |
| 3726 | |
| 3727 | /* this packet will go up, link back into |
| 3728 | chain and count it */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3729 | pfirst->next = pnext; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3730 | plast = pfirst; |
| 3731 | num++; |
| 3732 | |
| 3733 | #ifdef DHD_DEBUG |
| 3734 | if (DHD_GLOM_ON()) { |
| 3735 | DHD_GLOM(("%s subframe %d to stack, %p(%p/%d) " |
| 3736 | "nxt/lnk %p/%p\n", |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3737 | __func__, num, pfirst, pfirst->data, |
| 3738 | pfirst->len, pfirst->next, |
| 3739 | pfirst->prev)); |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 3740 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 3741 | pfirst->data, |
| 3742 | min_t(int, pfirst->len, 32)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3743 | } |
| 3744 | #endif /* DHD_DEBUG */ |
| 3745 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3746 | if (num) { |
| 3747 | dhd_os_sdunlock(bus->dhd); |
| 3748 | dhd_rx_frame(bus->dhd, ifidx, save_pfirst, num); |
| 3749 | dhd_os_sdlock(bus->dhd); |
| 3750 | } |
| 3751 | |
| 3752 | bus->rxglomframes++; |
| 3753 | bus->rxglompkts += num; |
| 3754 | } |
| 3755 | return num; |
| 3756 | } |
| 3757 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3758 | /* Return true if there may be more frames to read */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3759 | static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished) |
| 3760 | { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3761 | bcmsdh_info_t *sdh = bus->sdh; |
| 3762 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3763 | u16 len, check; /* Extracted hardware header fields */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3764 | u8 chan, seq, doff; /* Extracted software header fields */ |
| 3765 | u8 fcbits; /* Extracted fcbits from software header */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3766 | |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 3767 | struct sk_buff *pkt; /* Packet for event or data frames */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3768 | u16 pad; /* Number of pad bytes to read */ |
| 3769 | u16 rdlen; /* Total number of bytes to read */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3770 | u8 rxseq; /* Next sequence number to expect */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3771 | uint rxleft = 0; /* Remaining number of frames allowed */ |
| 3772 | int sdret; /* Return code from bcmsdh calls */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3773 | u8 txmax; /* Maximum tx sequence offered */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3774 | bool len_consistent; /* Result of comparing readahead len and |
| 3775 | len from hw-hdr */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3776 | u8 *rxbuf; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3777 | int ifidx = 0; |
| 3778 | uint rxcount = 0; /* Total frames read */ |
| 3779 | |
| 3780 | #if defined(DHD_DEBUG) || defined(SDTEST) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3781 | bool sdtest = false; /* To limit message spew from test mode */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3782 | #endif |
| 3783 | |
| 3784 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 3785 | |
| 3786 | ASSERT(maxframes); |
| 3787 | |
| 3788 | #ifdef SDTEST |
| 3789 | /* Allow pktgen to override maxframes */ |
| 3790 | if (bus->pktgen_count && (bus->pktgen_mode == DHD_PKTGEN_RECV)) { |
| 3791 | maxframes = bus->pktgen_count; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3792 | sdtest = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3793 | } |
| 3794 | #endif |
| 3795 | |
| 3796 | /* Not finished unless we encounter no more frames indication */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3797 | *finished = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3798 | |
| 3799 | for (rxseq = bus->rx_seq, rxleft = maxframes; |
| 3800 | !bus->rxskip && rxleft && bus->dhd->busstate != DHD_BUS_DOWN; |
| 3801 | rxseq++, rxleft--) { |
| 3802 | |
| 3803 | /* Handle glomming separately */ |
| 3804 | if (bus->glom || bus->glomd) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3805 | u8 cnt; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3806 | DHD_GLOM(("%s: calling rxglom: glomd %p, glom %p\n", |
| 3807 | __func__, bus->glomd, bus->glom)); |
| 3808 | cnt = dhdsdio_rxglom(bus, rxseq); |
| 3809 | DHD_GLOM(("%s: rxglom returned %d\n", __func__, cnt)); |
| 3810 | rxseq += cnt - 1; |
| 3811 | rxleft = (rxleft > cnt) ? (rxleft - cnt) : 1; |
| 3812 | continue; |
| 3813 | } |
| 3814 | |
| 3815 | /* Try doing single read if we can */ |
| 3816 | if (dhd_readahead && bus->nextlen) { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3817 | u16 nextlen = bus->nextlen; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3818 | bus->nextlen = 0; |
| 3819 | |
| 3820 | if (bus->bus == SPI_BUS) { |
| 3821 | rdlen = len = nextlen; |
| 3822 | } else { |
| 3823 | rdlen = len = nextlen << 4; |
| 3824 | |
| 3825 | /* Pad read to blocksize for efficiency */ |
| 3826 | if (bus->roundup && bus->blocksize |
| 3827 | && (rdlen > bus->blocksize)) { |
| 3828 | pad = |
| 3829 | bus->blocksize - |
| 3830 | (rdlen % bus->blocksize); |
| 3831 | if ((pad <= bus->roundup) |
| 3832 | && (pad < bus->blocksize) |
| 3833 | && ((rdlen + pad + firstread) < |
| 3834 | MAX_RX_DATASZ)) |
| 3835 | rdlen += pad; |
| 3836 | } else if (rdlen % DHD_SDALIGN) { |
| 3837 | rdlen += |
| 3838 | DHD_SDALIGN - (rdlen % DHD_SDALIGN); |
| 3839 | } |
| 3840 | } |
| 3841 | |
| 3842 | /* We use bus->rxctl buffer in WinXP for initial |
| 3843 | * control pkt receives. |
| 3844 | * Later we use buffer-poll for data as well |
| 3845 | * as control packets. |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3846 | * This is required because dhd receives full |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3847 | * frame in gSPI unlike SDIO. |
| 3848 | * After the frame is received we have to |
| 3849 | * distinguish whether it is data |
| 3850 | * or non-data frame. |
| 3851 | */ |
| 3852 | /* Allocate a packet buffer */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3853 | pkt = brcmu_pkt_buf_get_skb(rdlen + DHD_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3854 | if (!pkt) { |
| 3855 | if (bus->bus == SPI_BUS) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3856 | bus->usebufpool = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3857 | bus->rxctl = bus->rxbuf; |
| 3858 | if (dhd_alignctl) { |
| 3859 | bus->rxctl += firstread; |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 3860 | pad = ((unsigned long)bus->rxctl % |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3861 | DHD_SDALIGN); |
| 3862 | if (pad) |
| 3863 | bus->rxctl += |
| 3864 | (DHD_SDALIGN - pad); |
| 3865 | bus->rxctl -= firstread; |
| 3866 | } |
| 3867 | ASSERT(bus->rxctl >= bus->rxbuf); |
| 3868 | rxbuf = bus->rxctl; |
| 3869 | /* Read the entire frame */ |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 3870 | sdret = bcmsdh_recv_buf(bus, |
| 3871 | bcmsdh_cur_sbwad(sdh), |
| 3872 | SDIO_FUNC_2, F2SYNC, |
| 3873 | rxbuf, rdlen, |
| 3874 | NULL, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3875 | bus->f2rxdata++; |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 3876 | ASSERT(sdret != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3877 | |
| 3878 | /* Control frame failures need |
| 3879 | retransmission */ |
| 3880 | if (sdret < 0) { |
| 3881 | DHD_ERROR(("%s: read %d control bytes failed: %d\n", |
| 3882 | __func__, |
| 3883 | rdlen, sdret)); |
| 3884 | /* dhd.rx_ctlerrs is higher */ |
| 3885 | bus->rxc_errors++; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3886 | dhdsdio_rxfail(bus, true, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3887 | (bus->bus == |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3888 | SPI_BUS) ? false |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3889 | : true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3890 | continue; |
| 3891 | } |
| 3892 | } else { |
| 3893 | /* Give up on data, |
| 3894 | request rtx of events */ |
Arend van Spriel | cda64a5 | 2011-05-10 22:25:33 +0200 | [diff] [blame] | 3895 | DHD_ERROR(("%s (nextlen): " |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3896 | "brcmu_pkt_buf_get_skb " |
| 3897 | "failed:" |
Arend van Spriel | cda64a5 | 2011-05-10 22:25:33 +0200 | [diff] [blame] | 3898 | " len %d rdlen %d expected" |
| 3899 | " rxseq %d\n", __func__, |
| 3900 | len, rdlen, rxseq)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3901 | continue; |
| 3902 | } |
| 3903 | } else { |
| 3904 | if (bus->bus == SPI_BUS) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3905 | bus->usebufpool = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3906 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3907 | ASSERT(!(pkt->prev)); |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 3908 | PKTALIGN(pkt, rdlen, DHD_SDALIGN); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3909 | rxbuf = (u8 *) (pkt->data); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3910 | /* Read the entire frame */ |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 3911 | sdret = bcmsdh_recv_buf(bus, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3912 | bcmsdh_cur_sbwad(sdh), |
| 3913 | SDIO_FUNC_2, F2SYNC, |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 3914 | rxbuf, rdlen, |
| 3915 | pkt, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3916 | bus->f2rxdata++; |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 3917 | ASSERT(sdret != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3918 | |
| 3919 | if (sdret < 0) { |
| 3920 | DHD_ERROR(("%s (nextlen): read %d bytes failed: %d\n", |
| 3921 | __func__, rdlen, sdret)); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 3922 | brcmu_pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3923 | bus->dhd->rx_errors++; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3924 | /* Force retry w/normal header read. |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3925 | * Don't attempt NAK for |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3926 | * gSPI |
| 3927 | */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3928 | dhdsdio_rxfail(bus, true, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3929 | (bus->bus == |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3930 | SPI_BUS) ? false : |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3931 | true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3932 | continue; |
| 3933 | } |
| 3934 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3935 | |
| 3936 | /* Now check the header */ |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 3937 | memcpy(bus->rxhdr, rxbuf, SDPCM_HDRLEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3938 | |
| 3939 | /* Extract hardware header fields */ |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 3940 | len = get_unaligned_le16(bus->rxhdr); |
| 3941 | check = get_unaligned_le16(bus->rxhdr + sizeof(u16)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3942 | |
| 3943 | /* All zeros means readahead info was bad */ |
| 3944 | if (!(len | check)) { |
| 3945 | DHD_INFO(("%s (nextlen): read zeros in HW " |
| 3946 | "header???\n", __func__)); |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 3947 | dhdsdio_pktfree2(bus, pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3948 | continue; |
| 3949 | } |
| 3950 | |
| 3951 | /* Validate check bytes */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3952 | if ((u16)~(len ^ check)) { |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 3953 | DHD_ERROR(("%s (nextlen): HW hdr error:" |
| 3954 | " nextlen/len/check" |
| 3955 | " 0x%04x/0x%04x/0x%04x\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3956 | __func__, nextlen, len, check)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3957 | bus->rx_badhdr++; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3958 | dhdsdio_rxfail(bus, false, false); |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 3959 | dhdsdio_pktfree2(bus, pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3960 | continue; |
| 3961 | } |
| 3962 | |
| 3963 | /* Validate frame length */ |
| 3964 | if (len < SDPCM_HDRLEN) { |
| 3965 | DHD_ERROR(("%s (nextlen): HW hdr length " |
| 3966 | "invalid: %d\n", __func__, len)); |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 3967 | dhdsdio_pktfree2(bus, pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3968 | continue; |
| 3969 | } |
| 3970 | |
| 3971 | /* Check for consistency withreadahead info */ |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 3972 | len_consistent = (nextlen != (roundup(len, 16) >> 4)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3973 | if (len_consistent) { |
| 3974 | /* Mismatch, force retry w/normal |
| 3975 | header (may be >4K) */ |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 3976 | DHD_ERROR(("%s (nextlen): mismatch, " |
| 3977 | "nextlen %d len %d rnd %d; " |
| 3978 | "expected rxseq %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3979 | __func__, nextlen, |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 3980 | len, roundup(len, 16), rxseq)); |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 3981 | dhdsdio_rxfail(bus, true, (bus->bus != SPI_BUS)); |
| 3982 | dhdsdio_pktfree2(bus, pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3983 | continue; |
| 3984 | } |
| 3985 | |
| 3986 | /* Extract software header fields */ |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 3987 | chan = SDPCM_PACKET_CHANNEL( |
| 3988 | &bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 3989 | seq = SDPCM_PACKET_SEQUENCE( |
| 3990 | &bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 3991 | doff = SDPCM_DOFFSET_VALUE( |
| 3992 | &bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 3993 | txmax = SDPCM_WINDOW_VALUE( |
| 3994 | &bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3995 | |
| 3996 | bus->nextlen = |
| 3997 | bus->rxhdr[SDPCM_FRAMETAG_LEN + |
| 3998 | SDPCM_NEXTLEN_OFFSET]; |
| 3999 | if ((bus->nextlen << 4) > MAX_RX_DATASZ) { |
| 4000 | DHD_INFO(("%s (nextlen): got frame w/nextlen too large" " (%d), seq %d\n", |
| 4001 | __func__, bus->nextlen, seq)); |
| 4002 | bus->nextlen = 0; |
| 4003 | } |
| 4004 | |
| 4005 | bus->dhd->rx_readahead_cnt++; |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4006 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4007 | /* Handle Flow Control */ |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4008 | fcbits = SDPCM_FCMASK_VALUE( |
| 4009 | &bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4010 | |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4011 | if (bus->flowcontrol != fcbits) { |
| 4012 | if (~bus->flowcontrol & fcbits) |
| 4013 | bus->fc_xoff++; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4014 | |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4015 | if (bus->flowcontrol & ~fcbits) |
| 4016 | bus->fc_xon++; |
| 4017 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4018 | bus->fc_rcvd++; |
| 4019 | bus->flowcontrol = fcbits; |
| 4020 | } |
| 4021 | |
| 4022 | /* Check and update sequence number */ |
| 4023 | if (rxseq != seq) { |
| 4024 | DHD_INFO(("%s (nextlen): rx_seq %d, expected " |
| 4025 | "%d\n", __func__, seq, rxseq)); |
| 4026 | bus->rx_badseq++; |
| 4027 | rxseq = seq; |
| 4028 | } |
| 4029 | |
| 4030 | /* Check window for sanity */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4031 | if ((u8) (txmax - bus->tx_seq) > 0x40) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4032 | DHD_ERROR(("%s: got unlikely tx max %d with " |
| 4033 | "tx_seq %d\n", |
| 4034 | __func__, txmax, bus->tx_seq)); |
| 4035 | txmax = bus->tx_seq + 2; |
| 4036 | } |
| 4037 | bus->tx_max = txmax; |
| 4038 | |
| 4039 | #ifdef DHD_DEBUG |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 4040 | if (DHD_BYTES_ON() && DHD_DATA_ON()) { |
| 4041 | printk(KERN_DEBUG "Rx Data:\n"); |
| 4042 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 4043 | rxbuf, len); |
| 4044 | } else if (DHD_HDRS_ON()) { |
| 4045 | printk(KERN_DEBUG "RxHdr:\n"); |
| 4046 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 4047 | bus->rxhdr, SDPCM_HDRLEN); |
| 4048 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4049 | #endif |
| 4050 | |
| 4051 | if (chan == SDPCM_CONTROL_CHANNEL) { |
| 4052 | if (bus->bus == SPI_BUS) { |
| 4053 | dhdsdio_read_control(bus, rxbuf, len, |
| 4054 | doff); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4055 | } else { |
| 4056 | DHD_ERROR(("%s (nextlen): readahead on control" " packet %d?\n", |
| 4057 | __func__, seq)); |
| 4058 | /* Force retry w/normal header read */ |
| 4059 | bus->nextlen = 0; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4060 | dhdsdio_rxfail(bus, false, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4061 | } |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4062 | dhdsdio_pktfree2(bus, pkt); |
| 4063 | continue; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4064 | } |
| 4065 | |
| 4066 | if ((bus->bus == SPI_BUS) && !bus->usebufpool) { |
| 4067 | DHD_ERROR(("Received %d bytes on %d channel. Running out of " "rx pktbuf's or not yet malloced.\n", |
| 4068 | len, chan)); |
| 4069 | continue; |
| 4070 | } |
| 4071 | |
| 4072 | /* Validate data offset */ |
| 4073 | if ((doff < SDPCM_HDRLEN) || (doff > len)) { |
| 4074 | DHD_ERROR(("%s (nextlen): bad data offset %d: HW len %d min %d\n", |
| 4075 | __func__, doff, len, SDPCM_HDRLEN)); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4076 | dhdsdio_rxfail(bus, false, false); |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4077 | dhdsdio_pktfree2(bus, pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4078 | continue; |
| 4079 | } |
| 4080 | |
| 4081 | /* All done with this one -- now deliver the packet */ |
| 4082 | goto deliver; |
| 4083 | } |
| 4084 | /* gSPI frames should not be handled in fractions */ |
| 4085 | if (bus->bus == SPI_BUS) |
| 4086 | break; |
| 4087 | |
| 4088 | /* Read frame header (hardware and software) */ |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4089 | sdret = bcmsdh_recv_buf(bus, bcmsdh_cur_sbwad(sdh), |
| 4090 | SDIO_FUNC_2, F2SYNC, bus->rxhdr, firstread, |
| 4091 | NULL, NULL, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4092 | bus->f2rxhdrs++; |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 4093 | ASSERT(sdret != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4094 | |
| 4095 | if (sdret < 0) { |
| 4096 | DHD_ERROR(("%s: RXHEADER FAILED: %d\n", __func__, |
| 4097 | sdret)); |
| 4098 | bus->rx_hdrfail++; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4099 | dhdsdio_rxfail(bus, true, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4100 | continue; |
| 4101 | } |
| 4102 | #ifdef DHD_DEBUG |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 4103 | if (DHD_BYTES_ON() || DHD_HDRS_ON()) { |
| 4104 | printk(KERN_DEBUG "RxHdr:\n"); |
| 4105 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 4106 | bus->rxhdr, SDPCM_HDRLEN); |
| 4107 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4108 | #endif |
| 4109 | |
| 4110 | /* Extract hardware header fields */ |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 4111 | len = get_unaligned_le16(bus->rxhdr); |
| 4112 | check = get_unaligned_le16(bus->rxhdr + sizeof(u16)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4113 | |
| 4114 | /* All zeros means no more frames */ |
| 4115 | if (!(len | check)) { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4116 | *finished = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4117 | break; |
| 4118 | } |
| 4119 | |
| 4120 | /* Validate check bytes */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4121 | if ((u16) ~(len ^ check)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4122 | DHD_ERROR(("%s: HW hdr err: len/check 0x%04x/0x%04x\n", |
| 4123 | __func__, len, check)); |
| 4124 | bus->rx_badhdr++; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4125 | dhdsdio_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4126 | continue; |
| 4127 | } |
| 4128 | |
| 4129 | /* Validate frame length */ |
| 4130 | if (len < SDPCM_HDRLEN) { |
| 4131 | DHD_ERROR(("%s: HW hdr length invalid: %d\n", |
| 4132 | __func__, len)); |
| 4133 | continue; |
| 4134 | } |
| 4135 | |
| 4136 | /* Extract software header fields */ |
| 4137 | chan = SDPCM_PACKET_CHANNEL(&bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 4138 | seq = SDPCM_PACKET_SEQUENCE(&bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 4139 | doff = SDPCM_DOFFSET_VALUE(&bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 4140 | txmax = SDPCM_WINDOW_VALUE(&bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 4141 | |
| 4142 | /* Validate data offset */ |
| 4143 | if ((doff < SDPCM_HDRLEN) || (doff > len)) { |
| 4144 | DHD_ERROR(("%s: Bad data offset %d: HW len %d, min %d " |
| 4145 | "seq %d\n", |
| 4146 | __func__, doff, len, SDPCM_HDRLEN, seq)); |
| 4147 | bus->rx_badhdr++; |
| 4148 | ASSERT(0); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4149 | dhdsdio_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4150 | continue; |
| 4151 | } |
| 4152 | |
| 4153 | /* Save the readahead length if there is one */ |
| 4154 | bus->nextlen = |
| 4155 | bus->rxhdr[SDPCM_FRAMETAG_LEN + SDPCM_NEXTLEN_OFFSET]; |
| 4156 | if ((bus->nextlen << 4) > MAX_RX_DATASZ) { |
| 4157 | DHD_INFO(("%s (nextlen): got frame w/nextlen too large " |
| 4158 | "(%d), seq %d\n", |
| 4159 | __func__, bus->nextlen, seq)); |
| 4160 | bus->nextlen = 0; |
| 4161 | } |
| 4162 | |
| 4163 | /* Handle Flow Control */ |
| 4164 | fcbits = SDPCM_FCMASK_VALUE(&bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 4165 | |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4166 | if (bus->flowcontrol != fcbits) { |
| 4167 | if (~bus->flowcontrol & fcbits) |
| 4168 | bus->fc_xoff++; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4169 | |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4170 | if (bus->flowcontrol & ~fcbits) |
| 4171 | bus->fc_xon++; |
| 4172 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4173 | bus->fc_rcvd++; |
| 4174 | bus->flowcontrol = fcbits; |
| 4175 | } |
| 4176 | |
| 4177 | /* Check and update sequence number */ |
| 4178 | if (rxseq != seq) { |
| 4179 | DHD_INFO(("%s: rx_seq %d, expected %d\n", __func__, |
| 4180 | seq, rxseq)); |
| 4181 | bus->rx_badseq++; |
| 4182 | rxseq = seq; |
| 4183 | } |
| 4184 | |
| 4185 | /* Check window for sanity */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4186 | if ((u8) (txmax - bus->tx_seq) > 0x40) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4187 | DHD_ERROR(("%s: unlikely tx max %d with tx_seq %d\n", |
| 4188 | __func__, txmax, bus->tx_seq)); |
| 4189 | txmax = bus->tx_seq + 2; |
| 4190 | } |
| 4191 | bus->tx_max = txmax; |
| 4192 | |
| 4193 | /* Call a separate function for control frames */ |
| 4194 | if (chan == SDPCM_CONTROL_CHANNEL) { |
| 4195 | dhdsdio_read_control(bus, bus->rxhdr, len, doff); |
| 4196 | continue; |
| 4197 | } |
| 4198 | |
| 4199 | ASSERT((chan == SDPCM_DATA_CHANNEL) |
| 4200 | || (chan == SDPCM_EVENT_CHANNEL) |
| 4201 | || (chan == SDPCM_TEST_CHANNEL) |
| 4202 | || (chan == SDPCM_GLOM_CHANNEL)); |
| 4203 | |
| 4204 | /* Length to read */ |
| 4205 | rdlen = (len > firstread) ? (len - firstread) : 0; |
| 4206 | |
| 4207 | /* May pad read to blocksize for efficiency */ |
| 4208 | if (bus->roundup && bus->blocksize && |
| 4209 | (rdlen > bus->blocksize)) { |
| 4210 | pad = bus->blocksize - (rdlen % bus->blocksize); |
| 4211 | if ((pad <= bus->roundup) && (pad < bus->blocksize) && |
| 4212 | ((rdlen + pad + firstread) < MAX_RX_DATASZ)) |
| 4213 | rdlen += pad; |
| 4214 | } else if (rdlen % DHD_SDALIGN) { |
| 4215 | rdlen += DHD_SDALIGN - (rdlen % DHD_SDALIGN); |
| 4216 | } |
| 4217 | |
| 4218 | /* Satisfy length-alignment requirements */ |
| 4219 | if (forcealign && (rdlen & (ALIGNMENT - 1))) |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 4220 | rdlen = roundup(rdlen, ALIGNMENT); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4221 | |
| 4222 | if ((rdlen + firstread) > MAX_RX_DATASZ) { |
| 4223 | /* Too long -- skip this frame */ |
| 4224 | DHD_ERROR(("%s: too long: len %d rdlen %d\n", |
| 4225 | __func__, len, rdlen)); |
| 4226 | bus->dhd->rx_errors++; |
| 4227 | bus->rx_toolong++; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4228 | dhdsdio_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4229 | continue; |
| 4230 | } |
| 4231 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4232 | pkt = brcmu_pkt_buf_get_skb(rdlen + firstread + DHD_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4233 | if (!pkt) { |
| 4234 | /* Give up on data, request rtx of events */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4235 | DHD_ERROR(("%s: brcmu_pkt_buf_get_skb failed: rdlen %d" |
| 4236 | " chan %d\n", __func__, rdlen, chan)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4237 | bus->dhd->rx_dropped++; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4238 | dhdsdio_rxfail(bus, false, RETRYCHAN(chan)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4239 | continue; |
| 4240 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4241 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4242 | ASSERT(!(pkt->prev)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4243 | |
| 4244 | /* Leave room for what we already read, and align remainder */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4245 | ASSERT(firstread < pkt->len); |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 4246 | skb_pull(pkt, firstread); |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 4247 | PKTALIGN(pkt, rdlen, DHD_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4248 | |
| 4249 | /* Read the remaining frame data */ |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4250 | sdret = bcmsdh_recv_buf(bus, bcmsdh_cur_sbwad(sdh), SDIO_FUNC_2, |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4251 | F2SYNC, ((u8 *) (pkt->data)), rdlen, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4252 | pkt, NULL, NULL); |
| 4253 | bus->f2rxdata++; |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 4254 | ASSERT(sdret != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4255 | |
| 4256 | if (sdret < 0) { |
| 4257 | DHD_ERROR(("%s: read %d %s bytes failed: %d\n", |
| 4258 | __func__, rdlen, |
| 4259 | ((chan == |
| 4260 | SDPCM_EVENT_CHANNEL) ? "event" : ((chan == |
| 4261 | SDPCM_DATA_CHANNEL) |
| 4262 | ? "data" : "test")), |
| 4263 | sdret)); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4264 | brcmu_pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4265 | bus->dhd->rx_errors++; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4266 | dhdsdio_rxfail(bus, true, RETRYCHAN(chan)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4267 | continue; |
| 4268 | } |
| 4269 | |
| 4270 | /* Copy the already-read portion */ |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 4271 | skb_push(pkt, firstread); |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 4272 | memcpy(pkt->data, bus->rxhdr, firstread); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4273 | |
| 4274 | #ifdef DHD_DEBUG |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 4275 | if (DHD_BYTES_ON() && DHD_DATA_ON()) { |
| 4276 | printk(KERN_DEBUG "Rx Data:\n"); |
| 4277 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 4278 | pkt->data, len); |
| 4279 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4280 | #endif |
| 4281 | |
| 4282 | deliver: |
| 4283 | /* Save superframe descriptor and allocate packet frame */ |
| 4284 | if (chan == SDPCM_GLOM_CHANNEL) { |
| 4285 | if (SDPCM_GLOMDESC(&bus->rxhdr[SDPCM_FRAMETAG_LEN])) { |
| 4286 | DHD_GLOM(("%s: glom descriptor, %d bytes:\n", |
| 4287 | __func__, len)); |
| 4288 | #ifdef DHD_DEBUG |
| 4289 | if (DHD_GLOM_ON()) { |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 4290 | printk(KERN_DEBUG "Glom Data:\n"); |
| 4291 | print_hex_dump_bytes("", |
| 4292 | DUMP_PREFIX_OFFSET, |
| 4293 | pkt->data, len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4294 | } |
| 4295 | #endif |
Arend van Spriel | 2cb8ada | 2010-11-18 20:46:44 +0100 | [diff] [blame] | 4296 | __skb_trim(pkt, len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4297 | ASSERT(doff == SDPCM_HDRLEN); |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 4298 | skb_pull(pkt, SDPCM_HDRLEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4299 | bus->glomd = pkt; |
| 4300 | } else { |
| 4301 | DHD_ERROR(("%s: glom superframe w/o " |
| 4302 | "descriptor!\n", __func__)); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4303 | dhdsdio_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4304 | } |
| 4305 | continue; |
| 4306 | } |
| 4307 | |
| 4308 | /* Fill in packet len and prio, deliver upward */ |
Arend van Spriel | 2cb8ada | 2010-11-18 20:46:44 +0100 | [diff] [blame] | 4309 | __skb_trim(pkt, len); |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 4310 | skb_pull(pkt, doff); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4311 | |
| 4312 | #ifdef SDTEST |
| 4313 | /* Test channel packets are processed separately */ |
| 4314 | if (chan == SDPCM_TEST_CHANNEL) { |
| 4315 | dhdsdio_testrcv(bus, pkt, seq); |
| 4316 | continue; |
| 4317 | } |
| 4318 | #endif /* SDTEST */ |
| 4319 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4320 | if (pkt->len == 0) { |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4321 | brcmu_pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4322 | continue; |
| 4323 | } else if (dhd_prot_hdrpull(bus->dhd, &ifidx, pkt) != 0) { |
| 4324 | DHD_ERROR(("%s: rx protocol error\n", __func__)); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4325 | brcmu_pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4326 | bus->dhd->rx_errors++; |
| 4327 | continue; |
| 4328 | } |
| 4329 | |
| 4330 | /* Unlock during rx call */ |
| 4331 | dhd_os_sdunlock(bus->dhd); |
| 4332 | dhd_rx_frame(bus->dhd, ifidx, pkt, 1); |
| 4333 | dhd_os_sdlock(bus->dhd); |
| 4334 | } |
| 4335 | rxcount = maxframes - rxleft; |
| 4336 | #ifdef DHD_DEBUG |
| 4337 | /* Message if we hit the limit */ |
| 4338 | if (!rxleft && !sdtest) |
| 4339 | DHD_DATA(("%s: hit rx limit of %d frames\n", __func__, |
| 4340 | maxframes)); |
| 4341 | else |
| 4342 | #endif /* DHD_DEBUG */ |
| 4343 | DHD_DATA(("%s: processed %d frames\n", __func__, rxcount)); |
| 4344 | /* Back off rxseq if awaiting rtx, update rx_seq */ |
| 4345 | if (bus->rxskip) |
| 4346 | rxseq--; |
| 4347 | bus->rx_seq = rxseq; |
| 4348 | |
| 4349 | return rxcount; |
| 4350 | } |
| 4351 | |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 4352 | static u32 dhdsdio_hostmail(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4353 | { |
Franky Lin | 597600a | 2011-06-01 13:45:39 +0200 | [diff] [blame] | 4354 | struct sdpcmd_regs *regs = bus->regs; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 4355 | u32 intstatus = 0; |
| 4356 | u32 hmb_data; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4357 | u8 fcbits; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4358 | uint retries = 0; |
| 4359 | |
| 4360 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 4361 | |
| 4362 | /* Read mailbox data and ack that we did so */ |
| 4363 | R_SDREG(hmb_data, ®s->tohostmailboxdata, retries); |
| 4364 | if (retries <= retry_limit) |
| 4365 | W_SDREG(SMB_INT_ACK, ®s->tosbmailbox, retries); |
| 4366 | bus->f1regdata += 2; |
| 4367 | |
| 4368 | /* Dongle recomposed rx frames, accept them again */ |
| 4369 | if (hmb_data & HMB_DATA_NAKHANDLED) { |
| 4370 | DHD_INFO(("Dongle reports NAK handled, expect rtx of %d\n", |
| 4371 | bus->rx_seq)); |
| 4372 | if (!bus->rxskip) |
| 4373 | DHD_ERROR(("%s: unexpected NAKHANDLED!\n", __func__)); |
| 4374 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4375 | bus->rxskip = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4376 | intstatus |= I_HMB_FRAME_IND; |
| 4377 | } |
| 4378 | |
| 4379 | /* |
| 4380 | * DEVREADY does not occur with gSPI. |
| 4381 | */ |
| 4382 | if (hmb_data & (HMB_DATA_DEVREADY | HMB_DATA_FWREADY)) { |
| 4383 | bus->sdpcm_ver = |
| 4384 | (hmb_data & HMB_DATA_VERSION_MASK) >> |
| 4385 | HMB_DATA_VERSION_SHIFT; |
| 4386 | if (bus->sdpcm_ver != SDPCM_PROT_VERSION) |
| 4387 | DHD_ERROR(("Version mismatch, dongle reports %d, " |
| 4388 | "expecting %d\n", |
| 4389 | bus->sdpcm_ver, SDPCM_PROT_VERSION)); |
| 4390 | else |
| 4391 | DHD_INFO(("Dongle ready, protocol version %d\n", |
| 4392 | bus->sdpcm_ver)); |
| 4393 | } |
| 4394 | |
| 4395 | /* |
| 4396 | * 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] | 4397 | * method isn't used any more. |
| 4398 | * remaining backward compatible with older dongles. |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4399 | */ |
| 4400 | if (hmb_data & HMB_DATA_FC) { |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4401 | fcbits = (hmb_data & HMB_DATA_FCDATA_MASK) >> |
| 4402 | HMB_DATA_FCDATA_SHIFT; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4403 | |
| 4404 | if (fcbits & ~bus->flowcontrol) |
| 4405 | bus->fc_xoff++; |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 4406 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4407 | if (bus->flowcontrol & ~fcbits) |
| 4408 | bus->fc_xon++; |
| 4409 | |
| 4410 | bus->fc_rcvd++; |
| 4411 | bus->flowcontrol = fcbits; |
| 4412 | } |
| 4413 | |
| 4414 | /* Shouldn't be any others */ |
| 4415 | if (hmb_data & ~(HMB_DATA_DEVREADY | |
| 4416 | HMB_DATA_NAKHANDLED | |
| 4417 | HMB_DATA_FC | |
| 4418 | HMB_DATA_FWREADY | |
| 4419 | HMB_DATA_FCDATA_MASK | HMB_DATA_VERSION_MASK)) { |
| 4420 | DHD_ERROR(("Unknown mailbox data content: 0x%02x\n", hmb_data)); |
| 4421 | } |
| 4422 | |
| 4423 | return intstatus; |
| 4424 | } |
| 4425 | |
| 4426 | bool dhdsdio_dpc(dhd_bus_t *bus) |
| 4427 | { |
| 4428 | bcmsdh_info_t *sdh = bus->sdh; |
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, newstatus = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4431 | uint retries = 0; |
| 4432 | uint rxlimit = dhd_rxbound; /* Rx frames to read before resched */ |
| 4433 | uint txlimit = dhd_txbound; /* Tx frames to send before resched */ |
| 4434 | uint framecnt = 0; /* Temporary counter of tx/rx frames */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4435 | bool rxdone = true; /* Flag for no more read data */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4436 | bool resched = false; /* Flag indicating resched wanted */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4437 | |
| 4438 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 4439 | |
| 4440 | /* Start with leftover status bits */ |
| 4441 | intstatus = bus->intstatus; |
| 4442 | |
| 4443 | dhd_os_sdlock(bus->dhd); |
| 4444 | |
| 4445 | /* If waiting for HTAVAIL, check status */ |
| 4446 | if (bus->clkstate == CLK_PENDING) { |
| 4447 | int err; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4448 | u8 clkctl, devctl = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4449 | |
| 4450 | #ifdef DHD_DEBUG |
| 4451 | /* Check for inconsistent device control */ |
| 4452 | devctl = |
| 4453 | bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL, &err); |
| 4454 | if (err) { |
| 4455 | DHD_ERROR(("%s: error reading DEVCTL: %d\n", |
| 4456 | __func__, err)); |
| 4457 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 4458 | } else { |
| 4459 | ASSERT(devctl & SBSDIO_DEVCTL_CA_INT_ONLY); |
| 4460 | } |
| 4461 | #endif /* DHD_DEBUG */ |
| 4462 | |
| 4463 | /* Read CSR, if clock on switch to AVAIL, else ignore */ |
| 4464 | clkctl = |
| 4465 | bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 4466 | &err); |
| 4467 | if (err) { |
| 4468 | DHD_ERROR(("%s: error reading CSR: %d\n", __func__, |
| 4469 | err)); |
| 4470 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 4471 | } |
| 4472 | |
| 4473 | DHD_INFO(("DPC: PENDING, devctl 0x%02x clkctl 0x%02x\n", devctl, |
| 4474 | clkctl)); |
| 4475 | |
| 4476 | if (SBSDIO_HTAV(clkctl)) { |
| 4477 | devctl = |
| 4478 | bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL, |
| 4479 | &err); |
| 4480 | if (err) { |
| 4481 | DHD_ERROR(("%s: error reading DEVCTL: %d\n", |
| 4482 | __func__, err)); |
| 4483 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 4484 | } |
| 4485 | devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY; |
| 4486 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL, |
| 4487 | devctl, &err); |
| 4488 | if (err) { |
| 4489 | DHD_ERROR(("%s: error writing DEVCTL: %d\n", |
| 4490 | __func__, err)); |
| 4491 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 4492 | } |
| 4493 | bus->clkstate = CLK_AVAIL; |
| 4494 | } else { |
| 4495 | goto clkwait; |
| 4496 | } |
| 4497 | } |
| 4498 | |
| 4499 | BUS_WAKE(bus); |
| 4500 | |
| 4501 | /* Make sure backplane clock is on */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4502 | dhdsdio_clkctl(bus, CLK_AVAIL, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4503 | if (bus->clkstate == CLK_PENDING) |
| 4504 | goto clkwait; |
| 4505 | |
| 4506 | /* Pending interrupt indicates new device status */ |
| 4507 | if (bus->ipend) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4508 | bus->ipend = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4509 | R_SDREG(newstatus, ®s->intstatus, retries); |
| 4510 | bus->f1regdata++; |
| 4511 | if (bcmsdh_regfail(bus->sdh)) |
| 4512 | newstatus = 0; |
| 4513 | newstatus &= bus->hostintmask; |
| 4514 | bus->fcstate = !!(newstatus & I_HMB_FC_STATE); |
| 4515 | if (newstatus) { |
| 4516 | W_SDREG(newstatus, ®s->intstatus, retries); |
| 4517 | bus->f1regdata++; |
| 4518 | } |
| 4519 | } |
| 4520 | |
| 4521 | /* Merge new bits with previous */ |
| 4522 | intstatus |= newstatus; |
| 4523 | bus->intstatus = 0; |
| 4524 | |
| 4525 | /* Handle flow-control change: read new state in case our ack |
| 4526 | * crossed another change interrupt. If change still set, assume |
| 4527 | * FC ON for safety, let next loop through do the debounce. |
| 4528 | */ |
| 4529 | if (intstatus & I_HMB_FC_CHANGE) { |
| 4530 | intstatus &= ~I_HMB_FC_CHANGE; |
| 4531 | W_SDREG(I_HMB_FC_CHANGE, ®s->intstatus, retries); |
| 4532 | R_SDREG(newstatus, ®s->intstatus, retries); |
| 4533 | bus->f1regdata += 2; |
| 4534 | bus->fcstate = |
| 4535 | !!(newstatus & (I_HMB_FC_STATE | I_HMB_FC_CHANGE)); |
| 4536 | intstatus |= (newstatus & bus->hostintmask); |
| 4537 | } |
| 4538 | |
| 4539 | /* Handle host mailbox indication */ |
| 4540 | if (intstatus & I_HMB_HOST_INT) { |
| 4541 | intstatus &= ~I_HMB_HOST_INT; |
| 4542 | intstatus |= dhdsdio_hostmail(bus); |
| 4543 | } |
| 4544 | |
| 4545 | /* Generally don't ask for these, can get CRC errors... */ |
| 4546 | if (intstatus & I_WR_OOSYNC) { |
| 4547 | DHD_ERROR(("Dongle reports WR_OOSYNC\n")); |
| 4548 | intstatus &= ~I_WR_OOSYNC; |
| 4549 | } |
| 4550 | |
| 4551 | if (intstatus & I_RD_OOSYNC) { |
| 4552 | DHD_ERROR(("Dongle reports RD_OOSYNC\n")); |
| 4553 | intstatus &= ~I_RD_OOSYNC; |
| 4554 | } |
| 4555 | |
| 4556 | if (intstatus & I_SBINT) { |
| 4557 | DHD_ERROR(("Dongle reports SBINT\n")); |
| 4558 | intstatus &= ~I_SBINT; |
| 4559 | } |
| 4560 | |
| 4561 | /* Would be active due to wake-wlan in gSPI */ |
| 4562 | if (intstatus & I_CHIPACTIVE) { |
| 4563 | DHD_INFO(("Dongle reports CHIPACTIVE\n")); |
| 4564 | intstatus &= ~I_CHIPACTIVE; |
| 4565 | } |
| 4566 | |
| 4567 | /* Ignore frame indications if rxskip is set */ |
| 4568 | if (bus->rxskip) |
| 4569 | intstatus &= ~I_HMB_FRAME_IND; |
| 4570 | |
| 4571 | /* On frame indication, read available frames */ |
| 4572 | if (PKT_AVAILABLE()) { |
| 4573 | framecnt = dhdsdio_readframes(bus, rxlimit, &rxdone); |
| 4574 | if (rxdone || bus->rxskip) |
| 4575 | intstatus &= ~I_HMB_FRAME_IND; |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 4576 | rxlimit -= min(framecnt, rxlimit); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4577 | } |
| 4578 | |
| 4579 | /* Keep still-pending events for next scheduling */ |
| 4580 | bus->intstatus = intstatus; |
| 4581 | |
| 4582 | clkwait: |
| 4583 | #if defined(OOB_INTR_ONLY) |
| 4584 | bcmsdh_oob_intr_set(1); |
| 4585 | #endif /* (OOB_INTR_ONLY) */ |
| 4586 | /* Re-enable interrupts to detect new device events (mailbox, rx frame) |
| 4587 | * or clock availability. (Allows tx loop to check ipend if desired.) |
| 4588 | * (Unless register access seems hosed, as we may not be able to ACK...) |
| 4589 | */ |
| 4590 | if (bus->intr && bus->intdis && !bcmsdh_regfail(sdh)) { |
| 4591 | DHD_INTR(("%s: enable SDIO interrupts, rxdone %d framecnt %d\n", |
| 4592 | __func__, rxdone, framecnt)); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4593 | bus->intdis = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4594 | bcmsdh_intr_enable(sdh); |
| 4595 | } |
| 4596 | |
| 4597 | if (DATAOK(bus) && bus->ctrl_frame_stat && |
| 4598 | (bus->clkstate == CLK_AVAIL)) { |
| 4599 | int ret, i; |
| 4600 | |
| 4601 | ret = |
| 4602 | dhd_bcmsdh_send_buf(bus, bcmsdh_cur_sbwad(sdh), SDIO_FUNC_2, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4603 | F2SYNC, (u8 *) bus->ctrl_frame_buf, |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 4604 | (u32) bus->ctrl_frame_len, NULL, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4605 | NULL, NULL); |
Roland Vossen | b7ef2a9 | 2011-05-03 11:35:02 +0200 | [diff] [blame] | 4606 | ASSERT(ret != -BCME_PENDING); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4607 | |
| 4608 | if (ret < 0) { |
| 4609 | /* On failure, abort the command and |
| 4610 | terminate the frame */ |
| 4611 | DHD_INFO(("%s: sdio error %d, abort command and " |
| 4612 | "terminate frame.\n", __func__, ret)); |
| 4613 | bus->tx_sderrs++; |
| 4614 | |
| 4615 | bcmsdh_abort(sdh, SDIO_FUNC_2); |
| 4616 | |
| 4617 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, |
| 4618 | SBSDIO_FUNC1_FRAMECTRL, SFC_WF_TERM, |
| 4619 | NULL); |
| 4620 | bus->f1regdata++; |
| 4621 | |
| 4622 | for (i = 0; i < 3; i++) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4623 | u8 hi, lo; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4624 | hi = bcmsdh_cfg_read(sdh, SDIO_FUNC_1, |
| 4625 | SBSDIO_FUNC1_WFRAMEBCHI, |
| 4626 | NULL); |
| 4627 | lo = bcmsdh_cfg_read(sdh, SDIO_FUNC_1, |
| 4628 | SBSDIO_FUNC1_WFRAMEBCLO, |
| 4629 | NULL); |
| 4630 | bus->f1regdata += 2; |
| 4631 | if ((hi == 0) && (lo == 0)) |
| 4632 | break; |
| 4633 | } |
| 4634 | |
| 4635 | } |
| 4636 | if (ret == 0) |
| 4637 | bus->tx_seq = (bus->tx_seq + 1) % SDPCM_SEQUENCE_WRAP; |
| 4638 | |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 4639 | DHD_INFO(("Return_dpc value is : %d\n", ret)); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4640 | bus->ctrl_frame_stat = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4641 | dhd_wait_event_wakeup(bus->dhd); |
| 4642 | } |
| 4643 | /* Send queued frames (limit 1 if rx may still be pending) */ |
| 4644 | else if ((bus->clkstate == CLK_AVAIL) && !bus->fcstate && |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4645 | brcmu_pktq_mlen(&bus->txq, ~bus->flowcontrol) && txlimit |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4646 | && DATAOK(bus)) { |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 4647 | framecnt = rxdone ? txlimit : min(txlimit, dhd_txminmax); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4648 | framecnt = dhdsdio_sendfromq(bus, framecnt); |
| 4649 | txlimit -= framecnt; |
| 4650 | } |
| 4651 | |
| 4652 | /* Resched if events or tx frames are pending, |
| 4653 | else await next interrupt */ |
| 4654 | /* On failed register access, all bets are off: |
| 4655 | no resched or interrupts */ |
| 4656 | if ((bus->dhd->busstate == DHD_BUS_DOWN) || bcmsdh_regfail(sdh)) { |
| 4657 | DHD_ERROR(("%s: failed backplane access over SDIO, halting " |
| 4658 | "operation %d\n", __func__, bcmsdh_regfail(sdh))); |
| 4659 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 4660 | bus->intstatus = 0; |
| 4661 | } else if (bus->clkstate == CLK_PENDING) { |
| 4662 | DHD_INFO(("%s: rescheduled due to CLK_PENDING awaiting " |
| 4663 | "I_CHIPACTIVE interrupt\n", __func__)); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4664 | resched = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4665 | } else if (bus->intstatus || bus->ipend || |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4666 | (!bus->fcstate && brcmu_pktq_mlen(&bus->txq, ~bus->flowcontrol) |
| 4667 | && DATAOK(bus)) || PKT_AVAILABLE()) { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4668 | resched = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4669 | } |
| 4670 | |
| 4671 | bus->dpc_sched = resched; |
| 4672 | |
| 4673 | /* If we're done for now, turn off clock request. */ |
| 4674 | if ((bus->clkstate != CLK_PENDING) |
| 4675 | && bus->idletime == DHD_IDLE_IMMEDIATE) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4676 | bus->activity = false; |
| 4677 | dhdsdio_clkctl(bus, CLK_NONE, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4678 | } |
| 4679 | |
| 4680 | dhd_os_sdunlock(bus->dhd); |
| 4681 | |
| 4682 | return resched; |
| 4683 | } |
| 4684 | |
| 4685 | bool dhd_bus_dpc(struct dhd_bus *bus) |
| 4686 | { |
| 4687 | bool resched; |
| 4688 | |
| 4689 | /* Call the DPC directly. */ |
| 4690 | DHD_TRACE(("Calling dhdsdio_dpc() from %s\n", __func__)); |
| 4691 | resched = dhdsdio_dpc(bus); |
| 4692 | |
| 4693 | return resched; |
| 4694 | } |
| 4695 | |
| 4696 | void dhdsdio_isr(void *arg) |
| 4697 | { |
| 4698 | dhd_bus_t *bus = (dhd_bus_t *) arg; |
| 4699 | bcmsdh_info_t *sdh; |
| 4700 | |
| 4701 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 4702 | |
| 4703 | if (!bus) { |
| 4704 | DHD_ERROR(("%s : bus is null pointer , exit\n", __func__)); |
| 4705 | return; |
| 4706 | } |
| 4707 | sdh = bus->sdh; |
| 4708 | |
| 4709 | if (bus->dhd->busstate == DHD_BUS_DOWN) { |
| 4710 | DHD_ERROR(("%s : bus is down. we have nothing to do\n", |
| 4711 | __func__)); |
| 4712 | return; |
| 4713 | } |
| 4714 | /* Count the interrupt call */ |
| 4715 | bus->intrcount++; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4716 | bus->ipend = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4717 | |
| 4718 | /* Shouldn't get this interrupt if we're sleeping? */ |
| 4719 | if (bus->sleeping) { |
| 4720 | DHD_ERROR(("INTERRUPT WHILE SLEEPING??\n")); |
| 4721 | return; |
| 4722 | } |
| 4723 | |
| 4724 | /* Disable additional interrupts (is this needed now)? */ |
| 4725 | if (bus->intr) |
| 4726 | DHD_INTR(("%s: disable SDIO interrupts\n", __func__)); |
| 4727 | else |
| 4728 | DHD_ERROR(("dhdsdio_isr() w/o interrupt configured!\n")); |
| 4729 | |
| 4730 | bcmsdh_intr_disable(sdh); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4731 | bus->intdis = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4732 | |
| 4733 | #if defined(SDIO_ISR_THREAD) |
| 4734 | DHD_TRACE(("Calling dhdsdio_dpc() from %s\n", __func__)); |
| 4735 | while (dhdsdio_dpc(bus)) |
| 4736 | ; |
| 4737 | #else |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4738 | bus->dpc_sched = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4739 | dhd_sched_dpc(bus->dhd); |
| 4740 | #endif |
| 4741 | |
| 4742 | } |
| 4743 | |
| 4744 | #ifdef SDTEST |
| 4745 | static void dhdsdio_pktgen_init(dhd_bus_t *bus) |
| 4746 | { |
| 4747 | /* Default to specified length, or full range */ |
| 4748 | if (dhd_pktgen_len) { |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 4749 | bus->pktgen_maxlen = min(dhd_pktgen_len, MAX_PKTGEN_LEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4750 | bus->pktgen_minlen = bus->pktgen_maxlen; |
| 4751 | } else { |
| 4752 | bus->pktgen_maxlen = MAX_PKTGEN_LEN; |
| 4753 | bus->pktgen_minlen = 0; |
| 4754 | } |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4755 | bus->pktgen_len = (u16) bus->pktgen_minlen; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4756 | |
| 4757 | /* Default to per-watchdog burst with 10s print time */ |
| 4758 | bus->pktgen_freq = 1; |
| 4759 | bus->pktgen_print = 10000 / dhd_watchdog_ms; |
| 4760 | bus->pktgen_count = (dhd_pktgen * dhd_watchdog_ms + 999) / 1000; |
| 4761 | |
| 4762 | /* Default to echo mode */ |
| 4763 | bus->pktgen_mode = DHD_PKTGEN_ECHO; |
| 4764 | bus->pktgen_stop = 1; |
| 4765 | } |
| 4766 | |
| 4767 | static void dhdsdio_pktgen(dhd_bus_t *bus) |
| 4768 | { |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 4769 | struct sk_buff *pkt; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4770 | u8 *data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4771 | uint pktcount; |
| 4772 | uint fillbyte; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4773 | u16 len; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4774 | |
| 4775 | /* Display current count if appropriate */ |
| 4776 | if (bus->pktgen_print && (++bus->pktgen_ptick >= bus->pktgen_print)) { |
| 4777 | bus->pktgen_ptick = 0; |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 4778 | printk(KERN_DEBUG "%s: send attempts %d rcvd %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4779 | __func__, bus->pktgen_sent, bus->pktgen_rcvd); |
| 4780 | } |
| 4781 | |
| 4782 | /* For recv mode, just make sure dongle has started sending */ |
| 4783 | if (bus->pktgen_mode == DHD_PKTGEN_RECV) { |
| 4784 | if (!bus->pktgen_rcvd) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4785 | dhdsdio_sdtest_set(bus, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4786 | return; |
| 4787 | } |
| 4788 | |
| 4789 | /* Otherwise, generate or request the specified number of packets */ |
| 4790 | for (pktcount = 0; pktcount < bus->pktgen_count; pktcount++) { |
| 4791 | /* Stop if total has been reached */ |
| 4792 | if (bus->pktgen_total |
| 4793 | && (bus->pktgen_sent >= bus->pktgen_total)) { |
| 4794 | bus->pktgen_count = 0; |
| 4795 | break; |
| 4796 | } |
| 4797 | |
| 4798 | /* Allocate an appropriate-sized packet */ |
| 4799 | len = bus->pktgen_len; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4800 | pkt = brcmu_pkt_buf_get_skb( |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 4801 | (len + SDPCM_HDRLEN + SDPCM_TEST_HDRLEN + DHD_SDALIGN), |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4802 | true); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 4803 | if (!pkt) { |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4804 | DHD_ERROR(("%s: brcmu_pkt_buf_get_skb failed!\n", |
| 4805 | __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4806 | break; |
| 4807 | } |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 4808 | PKTALIGN(pkt, (len + SDPCM_HDRLEN + SDPCM_TEST_HDRLEN), |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4809 | DHD_SDALIGN); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4810 | data = (u8 *) (pkt->data) + SDPCM_HDRLEN; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4811 | |
| 4812 | /* Write test header cmd and extra based on mode */ |
| 4813 | switch (bus->pktgen_mode) { |
| 4814 | case DHD_PKTGEN_ECHO: |
| 4815 | *data++ = SDPCM_TEST_ECHOREQ; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4816 | *data++ = (u8) bus->pktgen_sent; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4817 | break; |
| 4818 | |
| 4819 | case DHD_PKTGEN_SEND: |
| 4820 | *data++ = SDPCM_TEST_DISCARD; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4821 | *data++ = (u8) bus->pktgen_sent; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4822 | break; |
| 4823 | |
| 4824 | case DHD_PKTGEN_RXBURST: |
| 4825 | *data++ = SDPCM_TEST_BURST; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4826 | *data++ = (u8) bus->pktgen_count; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4827 | break; |
| 4828 | |
| 4829 | default: |
| 4830 | DHD_ERROR(("Unrecognized pktgen mode %d\n", |
| 4831 | bus->pktgen_mode)); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4832 | brcmu_pkt_buf_free_skb(pkt, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4833 | bus->pktgen_count = 0; |
| 4834 | return; |
| 4835 | } |
| 4836 | |
| 4837 | /* Write test header length field */ |
| 4838 | *data++ = (len >> 0); |
| 4839 | *data++ = (len >> 8); |
| 4840 | |
| 4841 | /* Then fill in the remainder -- N/A for burst, |
| 4842 | but who cares... */ |
| 4843 | for (fillbyte = 0; fillbyte < len; fillbyte++) |
| 4844 | *data++ = |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4845 | SDPCM_TEST_FILL(fillbyte, (u8) bus->pktgen_sent); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4846 | |
| 4847 | #ifdef DHD_DEBUG |
| 4848 | if (DHD_BYTES_ON() && DHD_DATA_ON()) { |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4849 | data = (u8 *) (pkt->data) + SDPCM_HDRLEN; |
Arend van Spriel | 3422731 | 2011-05-10 22:25:32 +0200 | [diff] [blame] | 4850 | printk(KERN_DEBUG "dhdsdio_pktgen: Tx Data:\n"); |
| 4851 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, data, |
| 4852 | pkt->len - SDPCM_HDRLEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4853 | } |
| 4854 | #endif |
| 4855 | |
| 4856 | /* Send it */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4857 | if (dhdsdio_txpkt(bus, pkt, SDPCM_TEST_CHANNEL, true)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4858 | bus->pktgen_fail++; |
| 4859 | if (bus->pktgen_stop |
| 4860 | && bus->pktgen_stop == bus->pktgen_fail) |
| 4861 | bus->pktgen_count = 0; |
| 4862 | } |
| 4863 | bus->pktgen_sent++; |
| 4864 | |
| 4865 | /* Bump length if not fixed, wrap at max */ |
| 4866 | if (++bus->pktgen_len > bus->pktgen_maxlen) |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4867 | bus->pktgen_len = (u16) bus->pktgen_minlen; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4868 | |
| 4869 | /* Special case for burst mode: just send one request! */ |
| 4870 | if (bus->pktgen_mode == DHD_PKTGEN_RXBURST) |
| 4871 | break; |
| 4872 | } |
| 4873 | } |
| 4874 | |
| 4875 | static void dhdsdio_sdtest_set(dhd_bus_t *bus, bool start) |
| 4876 | { |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 4877 | struct sk_buff *pkt; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4878 | u8 *data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4879 | |
| 4880 | /* Allocate the packet */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4881 | pkt = brcmu_pkt_buf_get_skb(SDPCM_HDRLEN + SDPCM_TEST_HDRLEN + |
Henry Ptasinski | b33f0e2 | 2011-05-10 22:25:29 +0200 | [diff] [blame] | 4882 | DHD_SDALIGN, true); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 4883 | if (!pkt) { |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4884 | DHD_ERROR(("%s: brcmu_pkt_buf_get_skb failed!\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4885 | return; |
| 4886 | } |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 4887 | PKTALIGN(pkt, (SDPCM_HDRLEN + SDPCM_TEST_HDRLEN), DHD_SDALIGN); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4888 | data = (u8 *) (pkt->data) + SDPCM_HDRLEN; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4889 | |
| 4890 | /* Fill in the test header */ |
| 4891 | *data++ = SDPCM_TEST_SEND; |
| 4892 | *data++ = start; |
| 4893 | *data++ = (bus->pktgen_maxlen >> 0); |
| 4894 | *data++ = (bus->pktgen_maxlen >> 8); |
| 4895 | |
| 4896 | /* Send it */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4897 | if (dhdsdio_txpkt(bus, pkt, SDPCM_TEST_CHANNEL, true)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4898 | bus->pktgen_fail++; |
| 4899 | } |
| 4900 | |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 4901 | static void dhdsdio_testrcv(dhd_bus_t *bus, struct sk_buff *pkt, uint seq) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4902 | { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4903 | u8 *data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4904 | uint pktlen; |
| 4905 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4906 | u8 cmd; |
| 4907 | u8 extra; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4908 | u16 len; |
| 4909 | u16 offset; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4910 | |
| 4911 | /* Check for min length */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4912 | pktlen = pkt->len; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4913 | if (pktlen < SDPCM_TEST_HDRLEN) { |
| 4914 | DHD_ERROR(("dhdsdio_restrcv: toss runt frame, pktlen %d\n", |
| 4915 | pktlen)); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4916 | brcmu_pkt_buf_free_skb(pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4917 | return; |
| 4918 | } |
| 4919 | |
| 4920 | /* Extract header fields */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4921 | data = pkt->data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4922 | cmd = *data++; |
| 4923 | extra = *data++; |
| 4924 | len = *data++; |
| 4925 | len += *data++ << 8; |
| 4926 | |
| 4927 | /* Check length for relevant commands */ |
| 4928 | if (cmd == SDPCM_TEST_DISCARD || cmd == SDPCM_TEST_ECHOREQ |
| 4929 | || cmd == SDPCM_TEST_ECHORSP) { |
| 4930 | if (pktlen != len + SDPCM_TEST_HDRLEN) { |
| 4931 | DHD_ERROR(("dhdsdio_testrcv: frame length mismatch, " |
| 4932 | "pktlen %d seq %d" " cmd %d extra %d len %d\n", |
| 4933 | pktlen, seq, cmd, extra, len)); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4934 | brcmu_pkt_buf_free_skb(pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4935 | return; |
| 4936 | } |
| 4937 | } |
| 4938 | |
| 4939 | /* Process as per command */ |
| 4940 | switch (cmd) { |
| 4941 | case SDPCM_TEST_ECHOREQ: |
| 4942 | /* Rx->Tx turnaround ok (even on NDIS w/current |
| 4943 | implementation) */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4944 | *(u8 *) (pkt->data) = SDPCM_TEST_ECHORSP; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4945 | if (dhdsdio_txpkt(bus, pkt, SDPCM_TEST_CHANNEL, true) == 0) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4946 | bus->pktgen_sent++; |
| 4947 | } else { |
| 4948 | bus->pktgen_fail++; |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4949 | brcmu_pkt_buf_free_skb(pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4950 | } |
| 4951 | bus->pktgen_rcvd++; |
| 4952 | break; |
| 4953 | |
| 4954 | case SDPCM_TEST_ECHORSP: |
| 4955 | if (bus->ext_loop) { |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4956 | brcmu_pkt_buf_free_skb(pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4957 | bus->pktgen_rcvd++; |
| 4958 | break; |
| 4959 | } |
| 4960 | |
| 4961 | for (offset = 0; offset < len; offset++, data++) { |
| 4962 | if (*data != SDPCM_TEST_FILL(offset, extra)) { |
| 4963 | DHD_ERROR(("dhdsdio_testrcv: echo data mismatch: " "offset %d (len %d) expect 0x%02x rcvd 0x%02x\n", |
| 4964 | offset, len, |
| 4965 | SDPCM_TEST_FILL(offset, extra), *data)); |
| 4966 | break; |
| 4967 | } |
| 4968 | } |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4969 | brcmu_pkt_buf_free_skb(pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4970 | bus->pktgen_rcvd++; |
| 4971 | break; |
| 4972 | |
| 4973 | case SDPCM_TEST_DISCARD: |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4974 | brcmu_pkt_buf_free_skb(pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4975 | bus->pktgen_rcvd++; |
| 4976 | break; |
| 4977 | |
| 4978 | case SDPCM_TEST_BURST: |
| 4979 | case SDPCM_TEST_SEND: |
| 4980 | default: |
| 4981 | DHD_INFO(("dhdsdio_testrcv: unsupported or unknown command, " |
| 4982 | "pktlen %d seq %d" " cmd %d extra %d len %d\n", |
| 4983 | pktlen, seq, cmd, extra, len)); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 4984 | brcmu_pkt_buf_free_skb(pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4985 | break; |
| 4986 | } |
| 4987 | |
| 4988 | /* For recv mode, stop at limie (and tell dongle to stop sending) */ |
| 4989 | if (bus->pktgen_mode == DHD_PKTGEN_RECV) { |
| 4990 | if (bus->pktgen_total |
| 4991 | && (bus->pktgen_rcvd >= bus->pktgen_total)) { |
| 4992 | bus->pktgen_count = 0; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4993 | dhdsdio_sdtest_set(bus, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4994 | } |
| 4995 | } |
| 4996 | } |
| 4997 | #endif /* SDTEST */ |
| 4998 | |
| 4999 | extern bool dhd_bus_watchdog(dhd_pub_t *dhdp) |
| 5000 | { |
| 5001 | dhd_bus_t *bus; |
| 5002 | |
| 5003 | DHD_TIMER(("%s: Enter\n", __func__)); |
| 5004 | |
| 5005 | bus = dhdp->bus; |
| 5006 | |
| 5007 | if (bus->dhd->dongle_reset) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5008 | return false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5009 | |
| 5010 | /* Ignore the timer if simulating bus down */ |
| 5011 | if (bus->sleeping) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5012 | return false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5013 | |
| 5014 | dhd_os_sdlock(bus->dhd); |
| 5015 | |
| 5016 | /* Poll period: check device if appropriate. */ |
| 5017 | if (bus->poll && (++bus->polltick >= bus->pollrate)) { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 5018 | u32 intstatus = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5019 | |
| 5020 | /* Reset poll tick */ |
| 5021 | bus->polltick = 0; |
| 5022 | |
| 5023 | /* Check device if no interrupts */ |
| 5024 | if (!bus->intr || (bus->intrcount == bus->lastintrs)) { |
| 5025 | |
| 5026 | if (!bus->dpc_sched) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 5027 | u8 devpend; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5028 | devpend = bcmsdh_cfg_read(bus->sdh, SDIO_FUNC_0, |
Franky Lin | 0df4604 | 2011-06-01 13:45:40 +0200 | [diff] [blame] | 5029 | SDIO_CCCR_INTx, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5030 | NULL); |
| 5031 | intstatus = |
| 5032 | devpend & (INTR_STATUS_FUNC1 | |
| 5033 | INTR_STATUS_FUNC2); |
| 5034 | } |
| 5035 | |
| 5036 | /* If there is something, make like the ISR and |
| 5037 | schedule the DPC */ |
| 5038 | if (intstatus) { |
| 5039 | bus->pollcnt++; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5040 | bus->ipend = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5041 | if (bus->intr) |
| 5042 | bcmsdh_intr_disable(bus->sdh); |
| 5043 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5044 | bus->dpc_sched = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5045 | dhd_sched_dpc(bus->dhd); |
| 5046 | |
| 5047 | } |
| 5048 | } |
| 5049 | |
| 5050 | /* Update interrupt tracking */ |
| 5051 | bus->lastintrs = bus->intrcount; |
| 5052 | } |
| 5053 | #ifdef DHD_DEBUG |
| 5054 | /* Poll for console output periodically */ |
| 5055 | if (dhdp->busstate == DHD_BUS_DATA && dhd_console_ms != 0) { |
| 5056 | bus->console.count += dhd_watchdog_ms; |
| 5057 | if (bus->console.count >= dhd_console_ms) { |
| 5058 | bus->console.count -= dhd_console_ms; |
| 5059 | /* Make sure backplane clock is on */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5060 | dhdsdio_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5061 | if (dhdsdio_readconsole(bus) < 0) |
| 5062 | dhd_console_ms = 0; /* On error, |
| 5063 | stop trying */ |
| 5064 | } |
| 5065 | } |
| 5066 | #endif /* DHD_DEBUG */ |
| 5067 | |
| 5068 | #ifdef SDTEST |
| 5069 | /* Generate packets if configured */ |
| 5070 | if (bus->pktgen_count && (++bus->pktgen_tick >= bus->pktgen_freq)) { |
| 5071 | /* Make sure backplane clock is on */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5072 | dhdsdio_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5073 | bus->pktgen_tick = 0; |
| 5074 | dhdsdio_pktgen(bus); |
| 5075 | } |
| 5076 | #endif |
| 5077 | |
| 5078 | /* On idle timeout clear activity flag and/or turn off clock */ |
| 5079 | if ((bus->idletime > 0) && (bus->clkstate == CLK_AVAIL)) { |
| 5080 | if (++bus->idlecount >= bus->idletime) { |
| 5081 | bus->idlecount = 0; |
| 5082 | if (bus->activity) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5083 | bus->activity = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5084 | dhd_os_wd_timer(bus->dhd, dhd_watchdog_ms); |
| 5085 | } else { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5086 | dhdsdio_clkctl(bus, CLK_NONE, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5087 | } |
| 5088 | } |
| 5089 | } |
| 5090 | |
| 5091 | dhd_os_sdunlock(bus->dhd); |
| 5092 | |
| 5093 | return bus->ipend; |
| 5094 | } |
| 5095 | |
| 5096 | #ifdef DHD_DEBUG |
Greg Kroah-Hartman | 580a0bd | 2010-10-05 11:09:48 -0700 | [diff] [blame] | 5097 | extern int dhd_bus_console_in(dhd_pub_t *dhdp, unsigned char *msg, uint msglen) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5098 | { |
| 5099 | dhd_bus_t *bus = dhdp->bus; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 5100 | u32 addr, val; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5101 | int rv; |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 5102 | struct sk_buff *pkt; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5103 | |
| 5104 | /* Address could be zero if CONSOLE := 0 in dongle Makefile */ |
| 5105 | if (bus->console_addr == 0) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 5106 | return -ENOTSUPP; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5107 | |
| 5108 | /* Exclusive bus access */ |
| 5109 | dhd_os_sdlock(bus->dhd); |
| 5110 | |
| 5111 | /* Don't allow input if dongle is in reset */ |
| 5112 | if (bus->dhd->dongle_reset) { |
| 5113 | dhd_os_sdunlock(bus->dhd); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 5114 | return -EPERM; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5115 | } |
| 5116 | |
| 5117 | /* Request clock to allow SDIO accesses */ |
| 5118 | BUS_WAKE(bus); |
| 5119 | /* No pend allowed since txpkt is called later, ht clk has to be on */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5120 | dhdsdio_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5121 | |
| 5122 | /* Zero cbuf_index */ |
Roland Vossen | 70963f9 | 2011-06-01 13:45:08 +0200 | [diff] [blame] | 5123 | addr = bus->console_addr + offsetof(rte_cons_t, cbuf_idx); |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 5124 | val = cpu_to_le32(0); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5125 | rv = dhdsdio_membytes(bus, true, addr, (u8 *)&val, sizeof(val)); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5126 | if (rv < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5127 | goto done; |
| 5128 | |
| 5129 | /* Write message into cbuf */ |
Roland Vossen | 70963f9 | 2011-06-01 13:45:08 +0200 | [diff] [blame] | 5130 | addr = bus->console_addr + offsetof(rte_cons_t, cbuf); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5131 | rv = dhdsdio_membytes(bus, true, addr, (u8 *)msg, msglen); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5132 | if (rv < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5133 | goto done; |
| 5134 | |
| 5135 | /* Write length into vcons_in */ |
Roland Vossen | 70963f9 | 2011-06-01 13:45:08 +0200 | [diff] [blame] | 5136 | addr = bus->console_addr + offsetof(rte_cons_t, vcons_in); |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 5137 | val = cpu_to_le32(msglen); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5138 | rv = dhdsdio_membytes(bus, true, addr, (u8 *)&val, sizeof(val)); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5139 | if (rv < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5140 | goto done; |
| 5141 | |
| 5142 | /* Bump dongle by sending an empty event pkt. |
| 5143 | * sdpcm_sendup (RX) checks for virtual console input. |
| 5144 | */ |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 5145 | pkt = brcmu_pkt_buf_get_skb(4 + SDPCM_RESERVE); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5146 | if ((pkt != NULL) && bus->clkstate == CLK_AVAIL) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5147 | dhdsdio_txpkt(bus, pkt, SDPCM_EVENT_CHANNEL, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5148 | |
| 5149 | done: |
| 5150 | if ((bus->idletime == DHD_IDLE_IMMEDIATE) && !bus->dpc_sched) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5151 | bus->activity = false; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5152 | dhdsdio_clkctl(bus, CLK_NONE, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5153 | } |
| 5154 | |
| 5155 | dhd_os_sdunlock(bus->dhd); |
| 5156 | |
| 5157 | return rv; |
| 5158 | } |
| 5159 | #endif /* DHD_DEBUG */ |
| 5160 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5161 | static bool dhdsdio_chipmatch(u16 chipid) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5162 | { |
| 5163 | if (chipid == BCM4325_CHIP_ID) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5164 | return true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5165 | if (chipid == BCM4329_CHIP_ID) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5166 | return true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5167 | if (chipid == BCM4319_CHIP_ID) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5168 | return true; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5169 | return false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5170 | } |
| 5171 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5172 | static void *dhdsdio_probe(u16 venid, u16 devid, u16 bus_no, |
| 5173 | u16 slot, u16 func, uint bustype, void *regsva, |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 5174 | void *sdh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5175 | { |
| 5176 | int ret; |
| 5177 | dhd_bus_t *bus; |
| 5178 | |
| 5179 | /* Init global variables at run-time, not as part of the declaration. |
| 5180 | * This is required to support init/de-init of the driver. |
| 5181 | * Initialization |
| 5182 | * of globals as part of the declaration results in non-deterministic |
| 5183 | * behavior since the value of the globals may be different on the |
| 5184 | * first time that the driver is initialized vs subsequent |
| 5185 | * initializations. |
| 5186 | */ |
| 5187 | dhd_txbound = DHD_TXBOUND; |
| 5188 | dhd_rxbound = DHD_RXBOUND; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5189 | dhd_alignctl = true; |
| 5190 | sd1idle = true; |
| 5191 | dhd_readahead = true; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5192 | retrydata = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5193 | dhd_dongle_memsize = 0; |
| 5194 | dhd_txminmax = DHD_TXMINMAX; |
| 5195 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5196 | forcealign = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5197 | |
| 5198 | dhd_common_init(); |
| 5199 | |
| 5200 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5201 | DHD_INFO(("%s: venid 0x%04x devid 0x%04x\n", __func__, venid, devid)); |
| 5202 | |
| 5203 | /* We make assumptions about address window mappings */ |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 5204 | ASSERT((unsigned long)regsva == SI_ENUM_BASE); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5205 | |
| 5206 | /* BCMSDH passes venid and devid based on CIS parsing -- but |
| 5207 | * low-power start |
| 5208 | * means early parse could fail, so here we should get either an ID |
| 5209 | * we recognize OR (-1) indicating we must request power first. |
| 5210 | */ |
| 5211 | /* Check the Vendor ID */ |
| 5212 | switch (venid) { |
| 5213 | case 0x0000: |
Stanislav Fomichev | be1c09f | 2011-03-28 01:31:36 +0400 | [diff] [blame] | 5214 | case PCI_VENDOR_ID_BROADCOM: |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5215 | break; |
| 5216 | default: |
| 5217 | DHD_ERROR(("%s: unknown vendor: 0x%04x\n", __func__, venid)); |
| 5218 | return NULL; |
| 5219 | } |
| 5220 | |
| 5221 | /* Check the Device ID and make sure it's one that we support */ |
| 5222 | switch (devid) { |
| 5223 | case BCM4325_D11DUAL_ID: /* 4325 802.11a/g id */ |
| 5224 | case BCM4325_D11G_ID: /* 4325 802.11g 2.4Ghz band id */ |
| 5225 | case BCM4325_D11A_ID: /* 4325 802.11a 5Ghz band id */ |
| 5226 | DHD_INFO(("%s: found 4325 Dongle\n", __func__)); |
| 5227 | break; |
| 5228 | case BCM4329_D11NDUAL_ID: /* 4329 802.11n dualband device */ |
| 5229 | case BCM4329_D11N2G_ID: /* 4329 802.11n 2.4G device */ |
| 5230 | case BCM4329_D11N5G_ID: /* 4329 802.11n 5G device */ |
| 5231 | case 0x4329: |
| 5232 | DHD_INFO(("%s: found 4329 Dongle\n", __func__)); |
| 5233 | break; |
| 5234 | case BCM4319_D11N_ID: /* 4319 802.11n id */ |
| 5235 | case BCM4319_D11N2G_ID: /* 4319 802.11n2g id */ |
| 5236 | case BCM4319_D11N5G_ID: /* 4319 802.11n5g id */ |
| 5237 | DHD_INFO(("%s: found 4319 Dongle\n", __func__)); |
| 5238 | break; |
| 5239 | case 0: |
| 5240 | DHD_INFO(("%s: allow device id 0, will check chip internals\n", |
| 5241 | __func__)); |
| 5242 | break; |
| 5243 | |
| 5244 | default: |
| 5245 | DHD_ERROR(("%s: skipping 0x%04x/0x%04x, not a dongle\n", |
| 5246 | __func__, venid, devid)); |
| 5247 | return NULL; |
| 5248 | } |
| 5249 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5250 | /* Allocate private bus interface state */ |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5251 | bus = kzalloc(sizeof(dhd_bus_t), GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5252 | if (!bus) { |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5253 | DHD_ERROR(("%s: kmalloc of dhd_bus_t failed\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5254 | goto fail; |
| 5255 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5256 | bus->sdh = sdh; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5257 | bus->cl_devid = (u16) devid; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5258 | bus->bus = DHD_BUS; |
| 5259 | bus->tx_seq = SDPCM_SEQUENCE_WRAP - 1; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5260 | bus->usebufpool = false; /* Use bufpool if allocated, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5261 | else use locally malloced rxbuf */ |
| 5262 | |
| 5263 | /* attempt to attach to the dongle */ |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 5264 | if (!(dhdsdio_probe_attach(bus, sdh, regsva, devid))) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5265 | DHD_ERROR(("%s: dhdsdio_probe_attach failed\n", __func__)); |
| 5266 | goto fail; |
| 5267 | } |
| 5268 | |
Franky Lin | 0f1a87c | 2011-06-29 16:46:32 -0700 | [diff] [blame^] | 5269 | spin_lock_init(&bus->txqlock); |
| 5270 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5271 | /* Attach to the dhd/OS/network interface */ |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 5272 | bus->dhd = dhd_attach(bus, SDPCM_RESERVE); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5273 | if (!bus->dhd) { |
| 5274 | DHD_ERROR(("%s: dhd_attach failed\n", __func__)); |
| 5275 | goto fail; |
| 5276 | } |
| 5277 | |
| 5278 | /* Allocate buffers */ |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 5279 | if (!(dhdsdio_probe_malloc(bus, sdh))) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5280 | DHD_ERROR(("%s: dhdsdio_probe_malloc failed\n", __func__)); |
| 5281 | goto fail; |
| 5282 | } |
| 5283 | |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 5284 | if (!(dhdsdio_probe_init(bus, sdh))) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5285 | DHD_ERROR(("%s: dhdsdio_probe_init failed\n", __func__)); |
| 5286 | goto fail; |
| 5287 | } |
| 5288 | |
| 5289 | /* Register interrupt callback, but mask it (not operational yet). */ |
| 5290 | DHD_INTR(("%s: disable SDIO interrupts (not interested yet)\n", |
| 5291 | __func__)); |
| 5292 | bcmsdh_intr_disable(sdh); |
| 5293 | ret = bcmsdh_intr_reg(sdh, dhdsdio_isr, bus); |
| 5294 | if (ret != 0) { |
| 5295 | DHD_ERROR(("%s: FAILED: bcmsdh_intr_reg returned %d\n", |
| 5296 | __func__, ret)); |
| 5297 | goto fail; |
| 5298 | } |
| 5299 | DHD_INTR(("%s: registered SDIO interrupt function ok\n", __func__)); |
| 5300 | |
| 5301 | DHD_INFO(("%s: completed!!\n", __func__)); |
| 5302 | |
| 5303 | /* if firmware path present try to download and bring up bus */ |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5304 | ret = dhd_bus_start(bus->dhd); |
| 5305 | if (ret != 0) { |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 5306 | if (ret == -ENOLINK) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5307 | DHD_ERROR(("%s: dongle is not responding\n", __func__)); |
| 5308 | goto fail; |
| 5309 | } |
| 5310 | } |
| 5311 | /* Ok, have the per-port tell the stack we're open for business */ |
| 5312 | if (dhd_net_attach(bus->dhd, 0) != 0) { |
| 5313 | DHD_ERROR(("%s: Net attach failed!!\n", __func__)); |
| 5314 | goto fail; |
| 5315 | } |
| 5316 | |
| 5317 | return bus; |
| 5318 | |
| 5319 | fail: |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 5320 | dhdsdio_release(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5321 | return NULL; |
| 5322 | } |
| 5323 | |
| 5324 | static bool |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 5325 | dhdsdio_probe_attach(struct dhd_bus *bus, void *sdh, void *regsva, u16 devid) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5326 | { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 5327 | u8 clkctl = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5328 | int err = 0; |
| 5329 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5330 | bus->alp_only = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5331 | |
| 5332 | /* Return the window to backplane enumeration space for core access */ |
| 5333 | if (dhdsdio_set_siaddr_window(bus, SI_ENUM_BASE)) |
| 5334 | DHD_ERROR(("%s: FAILED to return to SI_ENUM_BASE\n", __func__)); |
| 5335 | |
| 5336 | #ifdef DHD_DEBUG |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 5337 | printk(KERN_DEBUG "F1 signature read @0x18000000=0x%4x\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5338 | bcmsdh_reg_read(bus->sdh, SI_ENUM_BASE, 4)); |
| 5339 | |
| 5340 | #endif /* DHD_DEBUG */ |
| 5341 | |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 5342 | /* |
| 5343 | * Force PLL off until dhdsdio_chip_attach() |
| 5344 | * programs PLL control regs |
| 5345 | */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5346 | |
| 5347 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 5348 | DHD_INIT_CLKCTL1, &err); |
| 5349 | if (!err) |
| 5350 | clkctl = |
| 5351 | bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 5352 | &err); |
| 5353 | |
| 5354 | if (err || ((clkctl & ~SBSDIO_AVBITS) != DHD_INIT_CLKCTL1)) { |
| 5355 | DHD_ERROR(("dhdsdio_probe: ChipClkCSR access: err %d wrote " |
| 5356 | "0x%02x read 0x%02x\n", |
| 5357 | err, DHD_INIT_CLKCTL1, clkctl)); |
| 5358 | goto fail; |
| 5359 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5360 | |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 5361 | if (dhdsdio_chip_attach(bus, regsva)) { |
| 5362 | DHD_ERROR(("%s: dhdsdio_chip_attach failed!\n", __func__)); |
| 5363 | goto fail; |
| 5364 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5365 | |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 5366 | bcmsdh_chipinfo(sdh, bus->ci->chip, bus->ci->chiprev); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5367 | |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 5368 | if (!dhdsdio_chipmatch((u16) bus->ci->chip)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5369 | DHD_ERROR(("%s: unsupported chip: 0x%04x\n", |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 5370 | __func__, bus->ci->chip)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5371 | goto fail; |
| 5372 | } |
| 5373 | |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 5374 | dhdsdio_sdiod_drive_strength_init(bus, dhd_sdiod_drive_strength); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5375 | |
| 5376 | /* Get info on the ARM and SOCRAM cores... */ |
| 5377 | if (!DHD_NOPMU(bus)) { |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 5378 | bus->armrev = SBCOREREV(bcmsdh_reg_read(bus->sdh, |
| 5379 | CORE_SB(bus->ci->armcorebase, sbidhigh), 4)); |
| 5380 | bus->orig_ramsize = bus->ci->ramsize; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5381 | if (!(bus->orig_ramsize)) { |
| 5382 | DHD_ERROR(("%s: failed to find SOCRAM memory!\n", |
| 5383 | __func__)); |
| 5384 | goto fail; |
| 5385 | } |
| 5386 | bus->ramsize = bus->orig_ramsize; |
| 5387 | if (dhd_dongle_memsize) |
| 5388 | dhd_dongle_setmemsize(bus, dhd_dongle_memsize); |
| 5389 | |
| 5390 | DHD_ERROR(("DHD: dongle ram size is set to %d(orig %d)\n", |
| 5391 | bus->ramsize, bus->orig_ramsize)); |
| 5392 | } |
| 5393 | |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 5394 | bus->regs = (void *)bus->ci->buscorebase; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5395 | |
| 5396 | /* Set core control so an SDIO reset does a backplane reset */ |
Arend van Spriel | ff31c54 | 2011-03-01 10:56:54 +0100 | [diff] [blame] | 5397 | OR_REG(&bus->regs->corecontrol, CC_BPRESEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5398 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 5399 | brcmu_pktq_init(&bus->txq, (PRIOMASK + 1), TXQLEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5400 | |
| 5401 | /* Locate an appropriately-aligned portion of hdrbuf */ |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 5402 | bus->rxhdr = (u8 *) roundup((unsigned long)&bus->hdrbuf[0], DHD_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5403 | |
| 5404 | /* Set the poll and/or interrupt flags */ |
| 5405 | bus->intr = (bool) dhd_intr; |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5406 | bus->poll = (bool) dhd_poll; |
| 5407 | if (bus->poll) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5408 | bus->pollrate = 1; |
| 5409 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5410 | return true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5411 | |
| 5412 | fail: |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5413 | return false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5414 | } |
| 5415 | |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 5416 | static bool dhdsdio_probe_malloc(dhd_bus_t *bus, void *sdh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5417 | { |
| 5418 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5419 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5420 | if (bus->dhd->maxctl) { |
| 5421 | bus->rxblen = |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 5422 | roundup((bus->dhd->maxctl + SDPCM_HDRLEN), |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5423 | ALIGNMENT) + DHD_SDALIGN; |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5424 | bus->rxbuf = kmalloc(bus->rxblen, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5425 | if (!(bus->rxbuf)) { |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5426 | DHD_ERROR(("%s: kmalloc of %d-byte rxbuf failed\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5427 | __func__, bus->rxblen)); |
| 5428 | goto fail; |
| 5429 | } |
| 5430 | } |
| 5431 | |
| 5432 | /* Allocate buffer to receive glomed packet */ |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5433 | bus->databuf = kmalloc(MAX_DATA_BUF, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5434 | if (!(bus->databuf)) { |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5435 | DHD_ERROR(("%s: kmalloc of %d-byte databuf failed\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5436 | __func__, MAX_DATA_BUF)); |
| 5437 | /* release rxbuf which was already located as above */ |
| 5438 | if (!bus->rxblen) |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 5439 | kfree(bus->rxbuf); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5440 | goto fail; |
| 5441 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5442 | |
| 5443 | /* Align the buffer */ |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 5444 | if ((unsigned long)bus->databuf % DHD_SDALIGN) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5445 | bus->dataptr = |
| 5446 | bus->databuf + (DHD_SDALIGN - |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 5447 | ((unsigned long)bus->databuf % DHD_SDALIGN)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5448 | else |
| 5449 | bus->dataptr = bus->databuf; |
| 5450 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5451 | return true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5452 | |
| 5453 | fail: |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5454 | return false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5455 | } |
| 5456 | |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 5457 | static bool dhdsdio_probe_init(dhd_bus_t *bus, void *sdh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5458 | { |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 5459 | s32 fnum; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5460 | |
| 5461 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5462 | |
| 5463 | #ifdef SDTEST |
| 5464 | dhdsdio_pktgen_init(bus); |
| 5465 | #endif /* SDTEST */ |
| 5466 | |
| 5467 | /* Disable F2 to clear any intermediate frame state on the dongle */ |
Franky Lin | 0df4604 | 2011-06-01 13:45:40 +0200 | [diff] [blame] | 5468 | bcmsdh_cfg_write(sdh, SDIO_FUNC_0, SDIO_CCCR_IOEx, SDIO_FUNC_ENABLE_1, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5469 | NULL); |
| 5470 | |
| 5471 | bus->dhd->busstate = DHD_BUS_DOWN; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5472 | bus->sleeping = false; |
| 5473 | bus->rxflow = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5474 | bus->prev_rxlim_hit = 0; |
| 5475 | |
| 5476 | /* Done with backplane-dependent accesses, can drop clock... */ |
| 5477 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, 0, NULL); |
| 5478 | |
| 5479 | /* ...and initialize clock/power states */ |
| 5480 | bus->clkstate = CLK_SDONLY; |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 5481 | bus->idletime = (s32) dhd_idletime; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5482 | bus->idleclock = DHD_IDLE_ACTIVE; |
| 5483 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5484 | /* Query the F2 block size, set roundup accordingly */ |
| 5485 | fnum = 2; |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 5486 | if (bcmsdh_iovar_op(sdh, "sd_blocksize", &fnum, sizeof(s32), |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 5487 | &bus->blocksize, sizeof(s32), false) != 0) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5488 | bus->blocksize = 0; |
| 5489 | DHD_ERROR(("%s: fail on %s get\n", __func__, "sd_blocksize")); |
| 5490 | } else { |
| 5491 | DHD_INFO(("%s: Initial value for %s is %d\n", |
| 5492 | __func__, "sd_blocksize", bus->blocksize)); |
| 5493 | } |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 5494 | bus->roundup = min(max_roundup, bus->blocksize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5495 | |
| 5496 | /* Query if bus module supports packet chaining, |
| 5497 | default to use if supported */ |
| 5498 | if (bcmsdh_iovar_op(sdh, "sd_rxchain", NULL, 0, |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 5499 | &bus->sd_rxchain, sizeof(s32), |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 5500 | false) != 0) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5501 | bus->sd_rxchain = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5502 | } else { |
| 5503 | DHD_INFO(("%s: bus module (through bcmsdh API) %s chaining\n", |
| 5504 | __func__, |
| 5505 | (bus->sd_rxchain ? "supports" : "does not support"))); |
| 5506 | } |
| 5507 | bus->use_rxchain = (bool) bus->sd_rxchain; |
| 5508 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5509 | return true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5510 | } |
| 5511 | |
| 5512 | bool |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 5513 | dhd_bus_download_firmware(struct dhd_bus *bus, char *fw_path, char *nv_path) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5514 | { |
| 5515 | bool ret; |
| 5516 | bus->fw_path = fw_path; |
| 5517 | bus->nv_path = nv_path; |
| 5518 | |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 5519 | ret = dhdsdio_download_firmware(bus, bus->sdh); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5520 | |
| 5521 | return ret; |
| 5522 | } |
| 5523 | |
| 5524 | static bool |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 5525 | dhdsdio_download_firmware(struct dhd_bus *bus, void *sdh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5526 | { |
| 5527 | bool ret; |
| 5528 | |
| 5529 | /* Download the firmware */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5530 | dhdsdio_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5531 | |
| 5532 | ret = _dhdsdio_download_firmware(bus) == 0; |
| 5533 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5534 | dhdsdio_clkctl(bus, CLK_SDONLY, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5535 | |
| 5536 | return ret; |
| 5537 | } |
| 5538 | |
| 5539 | /* Detach and free everything */ |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 5540 | static void dhdsdio_release(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5541 | { |
| 5542 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5543 | |
| 5544 | if (bus) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5545 | /* De-register interrupt handler */ |
| 5546 | bcmsdh_intr_disable(bus->sdh); |
| 5547 | bcmsdh_intr_dereg(bus->sdh); |
| 5548 | |
| 5549 | if (bus->dhd) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5550 | dhd_detach(bus->dhd); |
Franky Lin | cee3cf4 | 2011-04-25 19:34:06 -0700 | [diff] [blame] | 5551 | dhdsdio_release_dongle(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5552 | bus->dhd = NULL; |
| 5553 | } |
| 5554 | |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 5555 | dhdsdio_release_malloc(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5556 | |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 5557 | kfree(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5558 | } |
| 5559 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5560 | DHD_TRACE(("%s: Disconnected\n", __func__)); |
| 5561 | } |
| 5562 | |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 5563 | static void dhdsdio_release_malloc(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5564 | { |
| 5565 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5566 | |
| 5567 | if (bus->dhd && bus->dhd->dongle_reset) |
| 5568 | return; |
| 5569 | |
| 5570 | if (bus->rxbuf) { |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 5571 | kfree(bus->rxbuf); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5572 | bus->rxctl = bus->rxbuf = NULL; |
| 5573 | bus->rxlen = 0; |
| 5574 | } |
| 5575 | |
Ilia Mirkin | 46d994b | 2011-03-13 00:28:56 -0500 | [diff] [blame] | 5576 | kfree(bus->databuf); |
| 5577 | bus->databuf = NULL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5578 | } |
| 5579 | |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 5580 | static void dhdsdio_release_dongle(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5581 | { |
| 5582 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5583 | |
| 5584 | if (bus->dhd && bus->dhd->dongle_reset) |
| 5585 | return; |
| 5586 | |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 5587 | if (bus->ci) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5588 | dhdsdio_clkctl(bus, CLK_AVAIL, false); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5589 | dhdsdio_clkctl(bus, CLK_NONE, false); |
Franky Lin | cee3cf4 | 2011-04-25 19:34:06 -0700 | [diff] [blame] | 5590 | dhdsdio_chip_detach(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5591 | if (bus->vars && bus->varsz) |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 5592 | kfree(bus->vars); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5593 | bus->vars = NULL; |
| 5594 | } |
| 5595 | |
| 5596 | DHD_TRACE(("%s: Disconnected\n", __func__)); |
| 5597 | } |
| 5598 | |
| 5599 | static void dhdsdio_disconnect(void *ptr) |
| 5600 | { |
| 5601 | dhd_bus_t *bus = (dhd_bus_t *)ptr; |
| 5602 | |
| 5603 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5604 | |
| 5605 | if (bus) { |
| 5606 | ASSERT(bus->dhd); |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 5607 | dhdsdio_release(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5608 | } |
| 5609 | |
| 5610 | DHD_TRACE(("%s: Disconnected\n", __func__)); |
| 5611 | } |
| 5612 | |
| 5613 | /* Register/Unregister functions are called by the main DHD entry |
| 5614 | * point (e.g. module insertion) to link with the bus driver, in |
| 5615 | * order to look for or await the device. |
| 5616 | */ |
| 5617 | |
| 5618 | static bcmsdh_driver_t dhd_sdio = { |
| 5619 | dhdsdio_probe, |
| 5620 | dhdsdio_disconnect |
| 5621 | }; |
| 5622 | |
| 5623 | int dhd_bus_register(void) |
| 5624 | { |
| 5625 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5626 | |
| 5627 | return bcmsdh_register(&dhd_sdio); |
| 5628 | } |
| 5629 | |
| 5630 | void dhd_bus_unregister(void) |
| 5631 | { |
| 5632 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5633 | |
| 5634 | bcmsdh_unregister(); |
| 5635 | } |
| 5636 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5637 | static int dhdsdio_download_code_file(struct dhd_bus *bus, char *fw_path) |
| 5638 | { |
| 5639 | int bcmerror = -1; |
| 5640 | int offset = 0; |
| 5641 | uint len; |
| 5642 | void *image = NULL; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 5643 | u8 *memblock = NULL, *memptr; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5644 | |
| 5645 | DHD_INFO(("%s: download firmware %s\n", __func__, fw_path)); |
| 5646 | |
| 5647 | image = dhd_os_open_image(fw_path); |
| 5648 | if (image == NULL) |
| 5649 | goto err; |
| 5650 | |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5651 | memptr = memblock = kmalloc(MEMBLOCK + DHD_SDALIGN, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5652 | if (memblock == NULL) { |
| 5653 | DHD_ERROR(("%s: Failed to allocate memory %d bytes\n", |
| 5654 | __func__, MEMBLOCK)); |
| 5655 | goto err; |
| 5656 | } |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 5657 | if ((u32)(unsigned long)memblock % DHD_SDALIGN) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5658 | memptr += |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 5659 | (DHD_SDALIGN - ((u32)(unsigned long)memblock % DHD_SDALIGN)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5660 | |
| 5661 | /* Download image */ |
| 5662 | while ((len = |
| 5663 | dhd_os_get_image_block((char *)memptr, MEMBLOCK, image))) { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5664 | bcmerror = dhdsdio_membytes(bus, true, offset, memptr, len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5665 | if (bcmerror) { |
| 5666 | DHD_ERROR(("%s: error %d on writing %d membytes at " |
| 5667 | "0x%08x\n", __func__, bcmerror, MEMBLOCK, offset)); |
| 5668 | goto err; |
| 5669 | } |
| 5670 | |
| 5671 | offset += MEMBLOCK; |
| 5672 | } |
| 5673 | |
| 5674 | err: |
Ilia Mirkin | 46d994b | 2011-03-13 00:28:56 -0500 | [diff] [blame] | 5675 | kfree(memblock); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5676 | |
| 5677 | if (image) |
| 5678 | dhd_os_close_image(image); |
| 5679 | |
| 5680 | return bcmerror; |
| 5681 | } |
| 5682 | |
| 5683 | /* |
| 5684 | * ProcessVars:Takes a buffer of "<var>=<value>\n" lines read from a file |
| 5685 | * and ending in a NUL. |
| 5686 | * Removes carriage returns, empty lines, comment lines, and converts |
| 5687 | * newlines to NULs. |
| 5688 | * Shortens buffer as needed and pads with NULs. End of buffer is marked |
| 5689 | * by two NULs. |
| 5690 | */ |
| 5691 | |
| 5692 | static uint process_nvram_vars(char *varbuf, uint len) |
| 5693 | { |
| 5694 | char *dp; |
| 5695 | bool findNewline; |
| 5696 | int column; |
| 5697 | uint buf_len, n; |
| 5698 | |
| 5699 | dp = varbuf; |
| 5700 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5701 | findNewline = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5702 | column = 0; |
| 5703 | |
| 5704 | for (n = 0; n < len; n++) { |
| 5705 | if (varbuf[n] == 0) |
| 5706 | break; |
| 5707 | if (varbuf[n] == '\r') |
| 5708 | continue; |
| 5709 | if (findNewline && varbuf[n] != '\n') |
| 5710 | continue; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5711 | findNewline = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5712 | if (varbuf[n] == '#') { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5713 | findNewline = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5714 | continue; |
| 5715 | } |
| 5716 | if (varbuf[n] == '\n') { |
| 5717 | if (column == 0) |
| 5718 | continue; |
| 5719 | *dp++ = 0; |
| 5720 | column = 0; |
| 5721 | continue; |
| 5722 | } |
| 5723 | *dp++ = varbuf[n]; |
| 5724 | column++; |
| 5725 | } |
| 5726 | buf_len = dp - varbuf; |
| 5727 | |
| 5728 | while (dp < varbuf + n) |
| 5729 | *dp++ = 0; |
| 5730 | |
| 5731 | return buf_len; |
| 5732 | } |
| 5733 | |
| 5734 | /* |
| 5735 | EXAMPLE: nvram_array |
| 5736 | nvram_arry format: |
| 5737 | name=value |
| 5738 | Use carriage return at the end of each assignment, |
| 5739 | and an empty string with |
| 5740 | carriage return at the end of array. |
| 5741 | |
| 5742 | For example: |
| 5743 | unsigned char nvram_array[] = {"name1=value1\n", |
| 5744 | "name2=value2\n", "\n"}; |
| 5745 | Hex values start with 0x, and mac addr format: xx:xx:xx:xx:xx:xx. |
| 5746 | |
| 5747 | Search "EXAMPLE: nvram_array" to see how the array is activated. |
| 5748 | */ |
| 5749 | |
| 5750 | void dhd_bus_set_nvram_params(struct dhd_bus *bus, const char *nvram_params) |
| 5751 | { |
| 5752 | bus->nvram_params = nvram_params; |
| 5753 | } |
| 5754 | |
| 5755 | static int dhdsdio_download_nvram(struct dhd_bus *bus) |
| 5756 | { |
| 5757 | int bcmerror = -1; |
| 5758 | uint len; |
| 5759 | void *image = NULL; |
| 5760 | char *memblock = NULL; |
| 5761 | char *bufp; |
| 5762 | char *nv_path; |
| 5763 | bool nvram_file_exists; |
| 5764 | |
| 5765 | nv_path = bus->nv_path; |
| 5766 | |
| 5767 | nvram_file_exists = ((nv_path != NULL) && (nv_path[0] != '\0')); |
| 5768 | if (!nvram_file_exists && (bus->nvram_params == NULL)) |
| 5769 | return 0; |
| 5770 | |
| 5771 | if (nvram_file_exists) { |
| 5772 | image = dhd_os_open_image(nv_path); |
| 5773 | if (image == NULL) |
| 5774 | goto err; |
| 5775 | } |
| 5776 | |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5777 | memblock = kmalloc(MEMBLOCK, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5778 | if (memblock == NULL) { |
| 5779 | DHD_ERROR(("%s: Failed to allocate memory %d bytes\n", |
| 5780 | __func__, MEMBLOCK)); |
| 5781 | goto err; |
| 5782 | } |
| 5783 | |
| 5784 | /* Download variables */ |
| 5785 | if (nvram_file_exists) { |
| 5786 | len = dhd_os_get_image_block(memblock, MEMBLOCK, image); |
| 5787 | } else { |
| 5788 | len = strlen(bus->nvram_params); |
| 5789 | ASSERT(len <= MEMBLOCK); |
| 5790 | if (len > MEMBLOCK) |
| 5791 | len = MEMBLOCK; |
| 5792 | memcpy(memblock, bus->nvram_params, len); |
| 5793 | } |
| 5794 | |
| 5795 | if (len > 0 && len < MEMBLOCK) { |
| 5796 | bufp = (char *)memblock; |
| 5797 | bufp[len] = 0; |
| 5798 | len = process_nvram_vars(bufp, len); |
| 5799 | bufp += len; |
| 5800 | *bufp++ = 0; |
| 5801 | if (len) |
| 5802 | bcmerror = dhdsdio_downloadvars(bus, memblock, len + 1); |
| 5803 | if (bcmerror) { |
| 5804 | DHD_ERROR(("%s: error downloading vars: %d\n", |
| 5805 | __func__, bcmerror)); |
| 5806 | } |
| 5807 | } else { |
| 5808 | DHD_ERROR(("%s: error reading nvram file: %d\n", |
| 5809 | __func__, len)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 5810 | bcmerror = -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5811 | } |
| 5812 | |
| 5813 | err: |
Ilia Mirkin | 46d994b | 2011-03-13 00:28:56 -0500 | [diff] [blame] | 5814 | kfree(memblock); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5815 | |
| 5816 | if (image) |
| 5817 | dhd_os_close_image(image); |
| 5818 | |
| 5819 | return bcmerror; |
| 5820 | } |
| 5821 | |
| 5822 | static int _dhdsdio_download_firmware(struct dhd_bus *bus) |
| 5823 | { |
| 5824 | int bcmerror = -1; |
| 5825 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5826 | bool embed = false; /* download embedded firmware */ |
| 5827 | bool dlok = false; /* download firmware succeeded */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5828 | |
| 5829 | /* Out immediately if no image to download */ |
Franky Lin | a4181fb | 2011-06-01 13:45:34 +0200 | [diff] [blame] | 5830 | if ((bus->fw_path == NULL) || (bus->fw_path[0] == '\0')) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5831 | return bcmerror; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5832 | |
| 5833 | /* Keep arm in reset */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5834 | if (dhdsdio_download_state(bus, true)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5835 | DHD_ERROR(("%s: error placing ARM core in reset\n", __func__)); |
| 5836 | goto err; |
| 5837 | } |
| 5838 | |
| 5839 | /* External image takes precedence if specified */ |
| 5840 | if ((bus->fw_path != NULL) && (bus->fw_path[0] != '\0')) { |
| 5841 | if (dhdsdio_download_code_file(bus, bus->fw_path)) { |
| 5842 | DHD_ERROR(("%s: dongle image file download failed\n", |
| 5843 | __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5844 | goto err; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5845 | } else { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5846 | embed = false; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5847 | dlok = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5848 | } |
| 5849 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5850 | if (!dlok) { |
| 5851 | DHD_ERROR(("%s: dongle image download failed\n", __func__)); |
| 5852 | goto err; |
| 5853 | } |
| 5854 | |
| 5855 | /* EXAMPLE: nvram_array */ |
| 5856 | /* If a valid nvram_arry is specified as above, it can be passed |
| 5857 | down to dongle */ |
| 5858 | /* dhd_bus_set_nvram_params(bus, (char *)&nvram_array); */ |
| 5859 | |
| 5860 | /* External nvram takes precedence if specified */ |
| 5861 | if (dhdsdio_download_nvram(bus)) { |
| 5862 | DHD_ERROR(("%s: dongle nvram file download failed\n", |
| 5863 | __func__)); |
| 5864 | } |
| 5865 | |
| 5866 | /* Take arm out of reset */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5867 | if (dhdsdio_download_state(bus, false)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5868 | DHD_ERROR(("%s: error getting out of ARM core reset\n", |
| 5869 | __func__)); |
| 5870 | goto err; |
| 5871 | } |
| 5872 | |
| 5873 | bcmerror = 0; |
| 5874 | |
| 5875 | err: |
| 5876 | return bcmerror; |
| 5877 | } |
| 5878 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5879 | |
| 5880 | static int |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 5881 | dhd_bcmsdh_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] | 5882 | u8 *buf, uint nbytes, struct sk_buff *pkt, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5883 | bcmsdh_cmplt_fn_t complete, void *handle) |
| 5884 | { |
| 5885 | return bcmsdh_send_buf |
| 5886 | (bus->sdh, addr, fn, flags, buf, nbytes, pkt, complete, |
| 5887 | handle); |
| 5888 | } |
| 5889 | |
| 5890 | uint dhd_bus_chip(struct dhd_bus *bus) |
| 5891 | { |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 5892 | ASSERT(bus->ci != NULL); |
| 5893 | return bus->ci->chip; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5894 | } |
| 5895 | |
| 5896 | void *dhd_bus_pub(struct dhd_bus *bus) |
| 5897 | { |
| 5898 | return bus->dhd; |
| 5899 | } |
| 5900 | |
| 5901 | void *dhd_bus_txq(struct dhd_bus *bus) |
| 5902 | { |
| 5903 | return &bus->txq; |
| 5904 | } |
| 5905 | |
| 5906 | uint dhd_bus_hdrlen(struct dhd_bus *bus) |
| 5907 | { |
| 5908 | return SDPCM_HDRLEN; |
| 5909 | } |
| 5910 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 5911 | int dhd_bus_devreset(dhd_pub_t *dhdp, u8 flag) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5912 | { |
| 5913 | int bcmerror = 0; |
| 5914 | dhd_bus_t *bus; |
| 5915 | |
| 5916 | bus = dhdp->bus; |
| 5917 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5918 | if (flag == true) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5919 | if (!bus->dhd->dongle_reset) { |
| 5920 | /* Expect app to have torn down any |
| 5921 | connection before calling */ |
| 5922 | /* Stop the bus, disable F2 */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5923 | dhd_bus_stop(bus, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5924 | |
| 5925 | /* Clean tx/rx buffer pointers, |
| 5926 | detach from the dongle */ |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 5927 | dhdsdio_release_dongle(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5928 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5929 | bus->dhd->dongle_reset = true; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5930 | bus->dhd->up = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5931 | |
| 5932 | DHD_TRACE(("%s: WLAN OFF DONE\n", __func__)); |
| 5933 | /* App can now remove power from device */ |
| 5934 | } else |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 5935 | bcmerror = -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5936 | } else { |
| 5937 | /* App must have restored power to device before calling */ |
| 5938 | |
| 5939 | DHD_TRACE(("\n\n%s: == WLAN ON ==\n", __func__)); |
| 5940 | |
| 5941 | if (bus->dhd->dongle_reset) { |
| 5942 | /* Turn on WLAN */ |
| 5943 | /* Reset SD client */ |
| 5944 | bcmsdh_reset(bus->sdh); |
| 5945 | |
| 5946 | /* Attempt to re-attach & download */ |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 5947 | if (dhdsdio_probe_attach(bus, bus->sdh, |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 5948 | (u32 *) SI_ENUM_BASE, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5949 | bus->cl_devid)) { |
| 5950 | /* Attempt to download binary to the dongle */ |
| 5951 | if (dhdsdio_probe_init |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 5952 | (bus, bus->sdh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5953 | && dhdsdio_download_firmware(bus, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5954 | bus->sdh)) { |
| 5955 | |
| 5956 | /* Re-init bus, enable F2 transfer */ |
| 5957 | dhd_bus_init((dhd_pub_t *) bus->dhd, |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5958 | false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5959 | |
| 5960 | #if defined(OOB_INTR_ONLY) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5961 | dhd_enable_oob_intr(bus, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5962 | #endif /* defined(OOB_INTR_ONLY) */ |
| 5963 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5964 | bus->dhd->dongle_reset = false; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5965 | bus->dhd->up = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5966 | |
| 5967 | DHD_TRACE(("%s: WLAN ON DONE\n", |
| 5968 | __func__)); |
| 5969 | } else |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 5970 | bcmerror = -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5971 | } else |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 5972 | bcmerror = -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5973 | } else { |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 5974 | bcmerror = -EISCONN; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5975 | DHD_ERROR(("%s: Set DEVRESET=false invoked when device " |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5976 | "is on\n", __func__)); |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 5977 | bcmerror = -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5978 | } |
| 5979 | } |
| 5980 | return bcmerror; |
| 5981 | } |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 5982 | |
| 5983 | static int |
| 5984 | dhdsdio_chip_recognition(bcmsdh_info_t *sdh, struct chip_info *ci, void *regs) |
| 5985 | { |
| 5986 | u32 regdata; |
| 5987 | |
| 5988 | /* |
| 5989 | * Get CC core rev |
| 5990 | * Chipid is assume to be at offset 0 from regs arg |
| 5991 | * For different chiptypes or old sdio hosts w/o chipcommon, |
| 5992 | * other ways of recognition should be added here. |
| 5993 | */ |
| 5994 | ci->cccorebase = (u32)regs; |
| 5995 | regdata = bcmsdh_reg_read(sdh, CORE_CC_REG(ci->cccorebase, chipid), 4); |
| 5996 | ci->chip = regdata & CID_ID_MASK; |
| 5997 | ci->chiprev = (regdata & CID_REV_MASK) >> CID_REV_SHIFT; |
| 5998 | |
| 5999 | DHD_INFO(("%s: chipid=0x%x chiprev=%d\n", |
| 6000 | __func__, ci->chip, ci->chiprev)); |
| 6001 | |
| 6002 | /* Address of cores for new chips should be added here */ |
| 6003 | switch (ci->chip) { |
| 6004 | case BCM4329_CHIP_ID: |
| 6005 | ci->buscorebase = BCM4329_CORE_BUS_BASE; |
| 6006 | ci->ramcorebase = BCM4329_CORE_SOCRAM_BASE; |
| 6007 | ci->armcorebase = BCM4329_CORE_ARM_BASE; |
Franky Lin | c05df63 | 2011-04-25 19:34:07 -0700 | [diff] [blame] | 6008 | ci->ramsize = BCM4329_RAMSIZE; |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6009 | break; |
| 6010 | default: |
| 6011 | DHD_ERROR(("%s: chipid 0x%x is not supported\n", |
| 6012 | __func__, ci->chip)); |
| 6013 | return -ENODEV; |
| 6014 | } |
| 6015 | |
| 6016 | regdata = bcmsdh_reg_read(sdh, |
| 6017 | CORE_SB(ci->cccorebase, sbidhigh), 4); |
| 6018 | ci->ccrev = SBCOREREV(regdata); |
| 6019 | |
| 6020 | regdata = bcmsdh_reg_read(sdh, |
| 6021 | CORE_CC_REG(ci->cccorebase, pmucapabilities), 4); |
| 6022 | ci->pmurev = regdata & PCAP_REV_MASK; |
| 6023 | |
| 6024 | regdata = bcmsdh_reg_read(sdh, CORE_SB(ci->buscorebase, sbidhigh), 4); |
| 6025 | ci->buscorerev = SBCOREREV(regdata); |
| 6026 | ci->buscoretype = (regdata & SBIDH_CC_MASK) >> SBIDH_CC_SHIFT; |
| 6027 | |
| 6028 | DHD_INFO(("%s: ccrev=%d, pmurev=%d, buscore rev/type=%d/0x%x\n", |
| 6029 | __func__, ci->ccrev, ci->pmurev, |
| 6030 | ci->buscorerev, ci->buscoretype)); |
| 6031 | |
| 6032 | /* get chipcommon capabilites */ |
| 6033 | ci->cccaps = bcmsdh_reg_read(sdh, |
| 6034 | CORE_CC_REG(ci->cccorebase, capabilities), 4); |
| 6035 | |
| 6036 | return 0; |
| 6037 | } |
| 6038 | |
| 6039 | static void |
| 6040 | dhdsdio_chip_disablecore(bcmsdh_info_t *sdh, u32 corebase) |
| 6041 | { |
| 6042 | u32 regdata; |
| 6043 | |
| 6044 | regdata = bcmsdh_reg_read(sdh, |
| 6045 | CORE_SB(corebase, sbtmstatelow), 4); |
| 6046 | if (regdata & SBTML_RESET) |
| 6047 | return; |
| 6048 | |
| 6049 | regdata = bcmsdh_reg_read(sdh, |
| 6050 | CORE_SB(corebase, sbtmstatelow), 4); |
| 6051 | if ((regdata & (SICF_CLOCK_EN << SBTML_SICF_SHIFT)) != 0) { |
| 6052 | /* |
| 6053 | * set target reject and spin until busy is clear |
| 6054 | * (preserve core-specific bits) |
| 6055 | */ |
| 6056 | regdata = bcmsdh_reg_read(sdh, |
| 6057 | CORE_SB(corebase, sbtmstatelow), 4); |
| 6058 | bcmsdh_reg_write(sdh, CORE_SB(corebase, sbtmstatelow), 4, |
| 6059 | regdata | SBTML_REJ); |
| 6060 | |
| 6061 | regdata = bcmsdh_reg_read(sdh, |
| 6062 | CORE_SB(corebase, sbtmstatelow), 4); |
| 6063 | udelay(1); |
| 6064 | SPINWAIT((bcmsdh_reg_read(sdh, |
| 6065 | CORE_SB(corebase, sbtmstatehigh), 4) & |
| 6066 | SBTMH_BUSY), 100000); |
| 6067 | |
| 6068 | regdata = bcmsdh_reg_read(sdh, |
| 6069 | CORE_SB(corebase, sbtmstatehigh), 4); |
| 6070 | if (regdata & SBTMH_BUSY) |
| 6071 | DHD_ERROR(("%s: ARM core still busy\n", __func__)); |
| 6072 | |
| 6073 | regdata = bcmsdh_reg_read(sdh, |
| 6074 | CORE_SB(corebase, sbidlow), 4); |
| 6075 | if (regdata & SBIDL_INIT) { |
| 6076 | regdata = bcmsdh_reg_read(sdh, |
| 6077 | CORE_SB(corebase, sbimstate), 4) | |
| 6078 | SBIM_RJ; |
| 6079 | bcmsdh_reg_write(sdh, |
| 6080 | CORE_SB(corebase, sbimstate), 4, |
| 6081 | regdata); |
| 6082 | regdata = bcmsdh_reg_read(sdh, |
| 6083 | CORE_SB(corebase, sbimstate), 4); |
| 6084 | udelay(1); |
| 6085 | SPINWAIT((bcmsdh_reg_read(sdh, |
| 6086 | CORE_SB(corebase, sbimstate), 4) & |
| 6087 | SBIM_BY), 100000); |
| 6088 | } |
| 6089 | |
| 6090 | /* set reset and reject while enabling the clocks */ |
| 6091 | bcmsdh_reg_write(sdh, |
| 6092 | CORE_SB(corebase, sbtmstatelow), 4, |
| 6093 | (((SICF_FGC | SICF_CLOCK_EN) << SBTML_SICF_SHIFT) | |
| 6094 | SBTML_REJ | SBTML_RESET)); |
| 6095 | regdata = bcmsdh_reg_read(sdh, |
| 6096 | CORE_SB(corebase, sbtmstatelow), 4); |
| 6097 | udelay(10); |
| 6098 | |
| 6099 | /* clear the initiator reject bit */ |
| 6100 | regdata = bcmsdh_reg_read(sdh, |
| 6101 | CORE_SB(corebase, sbidlow), 4); |
| 6102 | if (regdata & SBIDL_INIT) { |
| 6103 | regdata = bcmsdh_reg_read(sdh, |
| 6104 | CORE_SB(corebase, sbimstate), 4) & |
| 6105 | ~SBIM_RJ; |
| 6106 | bcmsdh_reg_write(sdh, |
| 6107 | CORE_SB(corebase, sbimstate), 4, |
| 6108 | regdata); |
| 6109 | } |
| 6110 | } |
| 6111 | |
| 6112 | /* leave reset and reject asserted */ |
| 6113 | bcmsdh_reg_write(sdh, CORE_SB(corebase, sbtmstatelow), 4, |
| 6114 | (SBTML_REJ | SBTML_RESET)); |
| 6115 | udelay(1); |
| 6116 | } |
| 6117 | |
| 6118 | static int |
| 6119 | dhdsdio_chip_attach(struct dhd_bus *bus, void *regs) |
| 6120 | { |
| 6121 | struct chip_info *ci; |
| 6122 | int err; |
| 6123 | u8 clkval, clkset; |
| 6124 | |
| 6125 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 6126 | |
| 6127 | /* alloc chip_info_t */ |
| 6128 | ci = kmalloc(sizeof(struct chip_info), GFP_ATOMIC); |
| 6129 | if (NULL == ci) { |
| 6130 | DHD_ERROR(("%s: malloc failed!\n", __func__)); |
| 6131 | return -ENOMEM; |
| 6132 | } |
| 6133 | |
| 6134 | memset((unsigned char *)ci, 0, sizeof(struct chip_info)); |
| 6135 | |
| 6136 | /* bus/core/clk setup for register access */ |
| 6137 | /* Try forcing SDIO core to do ALPAvail request only */ |
| 6138 | clkset = SBSDIO_FORCE_HW_CLKREQ_OFF | SBSDIO_ALP_AVAIL_REQ; |
| 6139 | bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 6140 | clkset, &err); |
| 6141 | if (err) { |
| 6142 | DHD_ERROR(("%s: error writing for HT off\n", __func__)); |
| 6143 | goto fail; |
| 6144 | } |
| 6145 | |
| 6146 | /* If register supported, wait for ALPAvail and then force ALP */ |
| 6147 | /* This may take up to 15 milliseconds */ |
| 6148 | clkval = bcmsdh_cfg_read(bus->sdh, SDIO_FUNC_1, |
| 6149 | SBSDIO_FUNC1_CHIPCLKCSR, NULL); |
| 6150 | if ((clkval & ~SBSDIO_AVBITS) == clkset) { |
| 6151 | SPINWAIT(((clkval = |
| 6152 | bcmsdh_cfg_read(bus->sdh, SDIO_FUNC_1, |
| 6153 | SBSDIO_FUNC1_CHIPCLKCSR, |
| 6154 | NULL)), |
| 6155 | !SBSDIO_ALPAV(clkval)), |
| 6156 | PMU_MAX_TRANSITION_DLY); |
| 6157 | if (!SBSDIO_ALPAV(clkval)) { |
| 6158 | DHD_ERROR(("%s: timeout on ALPAV wait, clkval 0x%02x\n", |
| 6159 | __func__, clkval)); |
| 6160 | err = -EBUSY; |
| 6161 | goto fail; |
| 6162 | } |
| 6163 | clkset = SBSDIO_FORCE_HW_CLKREQ_OFF | |
| 6164 | SBSDIO_FORCE_ALP; |
| 6165 | bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, |
| 6166 | SBSDIO_FUNC1_CHIPCLKCSR, |
| 6167 | clkset, &err); |
| 6168 | udelay(65); |
| 6169 | } else { |
| 6170 | DHD_ERROR(("%s: ChipClkCSR access: wrote 0x%02x read 0x%02x\n", |
| 6171 | __func__, clkset, clkval)); |
| 6172 | err = -EACCES; |
| 6173 | goto fail; |
| 6174 | } |
| 6175 | |
| 6176 | /* Also, disable the extra SDIO pull-ups */ |
| 6177 | bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_SDIOPULLUP, 0, |
| 6178 | NULL); |
| 6179 | |
| 6180 | err = dhdsdio_chip_recognition(bus->sdh, ci, regs); |
| 6181 | if (err) |
| 6182 | goto fail; |
| 6183 | |
| 6184 | /* |
| 6185 | * Make sure any on-chip ARM is off (in case strapping is wrong), |
| 6186 | * or downloaded code was already running. |
| 6187 | */ |
| 6188 | dhdsdio_chip_disablecore(bus->sdh, ci->armcorebase); |
| 6189 | |
| 6190 | bcmsdh_reg_write(bus->sdh, |
| 6191 | CORE_CC_REG(ci->cccorebase, gpiopullup), 4, 0); |
| 6192 | bcmsdh_reg_write(bus->sdh, |
| 6193 | CORE_CC_REG(ci->cccorebase, gpiopulldown), 4, 0); |
| 6194 | |
| 6195 | /* Disable F2 to clear any intermediate frame state on the dongle */ |
Franky Lin | 0df4604 | 2011-06-01 13:45:40 +0200 | [diff] [blame] | 6196 | bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_0, SDIO_CCCR_IOEx, |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6197 | SDIO_FUNC_ENABLE_1, NULL); |
| 6198 | |
| 6199 | /* WAR: cmd52 backplane read so core HW will drop ALPReq */ |
| 6200 | clkval = bcmsdh_cfg_read(bus->sdh, SDIO_FUNC_1, |
| 6201 | 0, NULL); |
| 6202 | |
| 6203 | /* Done with backplane-dependent accesses, can drop clock... */ |
| 6204 | bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, 0, |
| 6205 | NULL); |
| 6206 | |
| 6207 | bus->ci = ci; |
| 6208 | return 0; |
| 6209 | fail: |
| 6210 | bus->ci = NULL; |
| 6211 | kfree(ci); |
| 6212 | return err; |
| 6213 | } |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6214 | |
| 6215 | static void |
| 6216 | dhdsdio_chip_resetcore(bcmsdh_info_t *sdh, u32 corebase) |
| 6217 | { |
| 6218 | u32 regdata; |
| 6219 | |
| 6220 | /* |
| 6221 | * Must do the disable sequence first to work for |
| 6222 | * arbitrary current core state. |
| 6223 | */ |
| 6224 | dhdsdio_chip_disablecore(sdh, corebase); |
| 6225 | |
| 6226 | /* |
| 6227 | * Now do the initialization sequence. |
| 6228 | * set reset while enabling the clock and |
| 6229 | * forcing them on throughout the core |
| 6230 | */ |
| 6231 | bcmsdh_reg_write(sdh, CORE_SB(corebase, sbtmstatelow), 4, |
| 6232 | ((SICF_FGC | SICF_CLOCK_EN) << SBTML_SICF_SHIFT) | |
| 6233 | SBTML_RESET); |
| 6234 | udelay(1); |
| 6235 | |
| 6236 | regdata = bcmsdh_reg_read(sdh, CORE_SB(corebase, sbtmstatehigh), 4); |
| 6237 | if (regdata & SBTMH_SERR) |
| 6238 | bcmsdh_reg_write(sdh, CORE_SB(corebase, sbtmstatehigh), 4, 0); |
| 6239 | |
| 6240 | regdata = bcmsdh_reg_read(sdh, CORE_SB(corebase, sbimstate), 4); |
| 6241 | if (regdata & (SBIM_IBE | SBIM_TO)) |
| 6242 | bcmsdh_reg_write(sdh, CORE_SB(corebase, sbimstate), 4, |
| 6243 | regdata & ~(SBIM_IBE | SBIM_TO)); |
| 6244 | |
| 6245 | /* clear reset and allow it to propagate throughout the core */ |
| 6246 | bcmsdh_reg_write(sdh, CORE_SB(corebase, sbtmstatelow), 4, |
| 6247 | (SICF_FGC << SBTML_SICF_SHIFT) | |
| 6248 | (SICF_CLOCK_EN << SBTML_SICF_SHIFT)); |
| 6249 | udelay(1); |
| 6250 | |
| 6251 | /* leave clock enabled */ |
| 6252 | bcmsdh_reg_write(sdh, CORE_SB(corebase, sbtmstatelow), 4, |
| 6253 | (SICF_CLOCK_EN << SBTML_SICF_SHIFT)); |
| 6254 | udelay(1); |
| 6255 | } |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 6256 | |
| 6257 | /* SDIO Pad drive strength to select value mappings */ |
| 6258 | struct sdiod_drive_str { |
| 6259 | u8 strength; /* Pad Drive Strength in mA */ |
| 6260 | u8 sel; /* Chip-specific select value */ |
| 6261 | }; |
| 6262 | |
| 6263 | /* SDIO Drive Strength to sel value table for PMU Rev 1 */ |
| 6264 | static const struct sdiod_drive_str sdiod_drive_strength_tab1[] = { |
| 6265 | { |
| 6266 | 4, 0x2}, { |
| 6267 | 2, 0x3}, { |
| 6268 | 1, 0x0}, { |
| 6269 | 0, 0x0} |
| 6270 | }; |
| 6271 | |
| 6272 | /* SDIO Drive Strength to sel value table for PMU Rev 2, 3 */ |
| 6273 | static const struct sdiod_drive_str sdiod_drive_strength_tab2[] = { |
| 6274 | { |
| 6275 | 12, 0x7}, { |
| 6276 | 10, 0x6}, { |
| 6277 | 8, 0x5}, { |
| 6278 | 6, 0x4}, { |
| 6279 | 4, 0x2}, { |
| 6280 | 2, 0x1}, { |
| 6281 | 0, 0x0} |
| 6282 | }; |
| 6283 | |
| 6284 | /* SDIO Drive Strength to sel value table for PMU Rev 8 (1.8V) */ |
| 6285 | static const struct sdiod_drive_str sdiod_drive_strength_tab3[] = { |
| 6286 | { |
| 6287 | 32, 0x7}, { |
| 6288 | 26, 0x6}, { |
| 6289 | 22, 0x5}, { |
| 6290 | 16, 0x4}, { |
| 6291 | 12, 0x3}, { |
| 6292 | 8, 0x2}, { |
| 6293 | 4, 0x1}, { |
| 6294 | 0, 0x0} |
| 6295 | }; |
| 6296 | |
| 6297 | #define SDIOD_DRVSTR_KEY(chip, pmu) (((chip) << 16) | (pmu)) |
| 6298 | |
| 6299 | static void |
| 6300 | dhdsdio_sdiod_drive_strength_init(struct dhd_bus *bus, u32 drivestrength) { |
| 6301 | struct sdiod_drive_str *str_tab = NULL; |
| 6302 | u32 str_mask = 0; |
| 6303 | u32 str_shift = 0; |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 6304 | char chn[8]; |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 6305 | |
| 6306 | if (!(bus->ci->cccaps & CC_CAP_PMU)) |
| 6307 | return; |
| 6308 | |
| 6309 | switch (SDIOD_DRVSTR_KEY(bus->ci->chip, bus->ci->pmurev)) { |
| 6310 | case SDIOD_DRVSTR_KEY(BCM4325_CHIP_ID, 1): |
| 6311 | str_tab = (struct sdiod_drive_str *)&sdiod_drive_strength_tab1; |
| 6312 | str_mask = 0x30000000; |
| 6313 | str_shift = 28; |
| 6314 | break; |
| 6315 | case SDIOD_DRVSTR_KEY(BCM4325_CHIP_ID, 2): |
| 6316 | case SDIOD_DRVSTR_KEY(BCM4325_CHIP_ID, 3): |
| 6317 | str_tab = (struct sdiod_drive_str *)&sdiod_drive_strength_tab2; |
| 6318 | str_mask = 0x00003800; |
| 6319 | str_shift = 11; |
| 6320 | break; |
| 6321 | case SDIOD_DRVSTR_KEY(BCM4336_CHIP_ID, 8): |
| 6322 | str_tab = (struct sdiod_drive_str *)&sdiod_drive_strength_tab3; |
| 6323 | str_mask = 0x00003800; |
| 6324 | str_shift = 11; |
| 6325 | break; |
| 6326 | default: |
| 6327 | DHD_ERROR(("No SDIO Drive strength init" |
| 6328 | "done for chip %s rev %d pmurev %d\n", |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 6329 | brcmu_chipname(bus->ci->chip, chn, 8), |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame] | 6330 | bus->ci->chiprev, bus->ci->pmurev)); |
| 6331 | break; |
| 6332 | } |
| 6333 | |
| 6334 | if (str_tab != NULL) { |
| 6335 | u32 drivestrength_sel = 0; |
| 6336 | u32 cc_data_temp; |
| 6337 | int i; |
| 6338 | |
| 6339 | for (i = 0; str_tab[i].strength != 0; i++) { |
| 6340 | if (drivestrength >= str_tab[i].strength) { |
| 6341 | drivestrength_sel = str_tab[i].sel; |
| 6342 | break; |
| 6343 | } |
| 6344 | } |
| 6345 | |
| 6346 | bcmsdh_reg_write(bus->sdh, |
| 6347 | CORE_CC_REG(bus->ci->cccorebase, chipcontrol_addr), |
| 6348 | 4, 1); |
| 6349 | cc_data_temp = bcmsdh_reg_read(bus->sdh, |
| 6350 | CORE_CC_REG(bus->ci->cccorebase, chipcontrol_addr), 4); |
| 6351 | cc_data_temp &= ~str_mask; |
| 6352 | drivestrength_sel <<= str_shift; |
| 6353 | cc_data_temp |= drivestrength_sel; |
| 6354 | bcmsdh_reg_write(bus->sdh, |
| 6355 | CORE_CC_REG(bus->ci->cccorebase, chipcontrol_addr), |
| 6356 | 4, cc_data_temp); |
| 6357 | |
| 6358 | DHD_INFO(("SDIO: %dmA drive strength selected, set to 0x%08x\n", |
| 6359 | drivestrength, cc_data_temp)); |
| 6360 | } |
| 6361 | } |
Franky Lin | cee3cf4 | 2011-04-25 19:34:06 -0700 | [diff] [blame] | 6362 | |
| 6363 | static void |
| 6364 | dhdsdio_chip_detach(struct dhd_bus *bus) |
| 6365 | { |
| 6366 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 6367 | |
| 6368 | kfree(bus->ci); |
| 6369 | bus->ci = NULL; |
| 6370 | } |