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> |
| 18 | #include <bcmdefs.h> |
Brett Rudley | c6ac24e | 2010-10-26 11:55:23 -0700 | [diff] [blame^] | 19 | #include <linux/netdevice.h> |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 20 | #include <osl.h> |
| 21 | #include <bcmsdh.h> |
| 22 | |
| 23 | #ifdef BCMEMBEDIMAGE |
| 24 | #include BCMEMBEDIMAGE |
| 25 | #endif /* BCMEMBEDIMAGE */ |
| 26 | |
| 27 | #include <bcmdefs.h> |
| 28 | #include <bcmutils.h> |
| 29 | #include <bcmendian.h> |
| 30 | #include <bcmdevs.h> |
| 31 | |
| 32 | #include <siutils.h> |
| 33 | #include <hndpmu.h> |
| 34 | #include <hndsoc.h> |
| 35 | #ifdef DHD_DEBUG |
| 36 | #include <hndrte_armtrap.h> |
| 37 | #include <hndrte_cons.h> |
| 38 | #endif /* DHD_DEBUG */ |
| 39 | #include <sbchipc.h> |
| 40 | #include <sbhnddma.h> |
| 41 | |
| 42 | #include <sdio.h> |
| 43 | #include <sbsdio.h> |
| 44 | #include <sbsdpcmdev.h> |
| 45 | #include <bcmsdpcm.h> |
| 46 | |
| 47 | #include <proto/ethernet.h> |
| 48 | #include <proto/802.1d.h> |
| 49 | #include <proto/802.11.h> |
| 50 | |
| 51 | #include <dngl_stats.h> |
| 52 | #include <dhd.h> |
| 53 | #include <dhd_bus.h> |
| 54 | #include <dhd_proto.h> |
| 55 | #include <dhd_dbg.h> |
| 56 | #include <dhdioctl.h> |
| 57 | #include <sdiovar.h> |
| 58 | #include <siutils_priv.h> |
| 59 | |
| 60 | #ifndef DHDSDIO_MEM_DUMP_FNAME |
| 61 | #define DHDSDIO_MEM_DUMP_FNAME "mem_dump" |
| 62 | #endif |
| 63 | |
| 64 | #define QLEN 256 /* bulk rx and tx queue lengths */ |
| 65 | #define FCHI (QLEN - 10) |
| 66 | #define FCLOW (FCHI / 2) |
| 67 | #define PRIOMASK 7 |
| 68 | |
| 69 | #define TXRETRIES 2 /* # of retries for tx frames */ |
| 70 | |
| 71 | #if defined(CONFIG_MACH_SANDGATE2G) |
| 72 | #define DHD_RXBOUND 250 /* Default for max rx frames in |
| 73 | one scheduling */ |
| 74 | #else |
| 75 | #define DHD_RXBOUND 50 /* Default for max rx frames in |
| 76 | one scheduling */ |
| 77 | #endif /* defined(CONFIG_MACH_SANDGATE2G) */ |
| 78 | |
| 79 | #define DHD_TXBOUND 20 /* Default for max tx frames in |
| 80 | one scheduling */ |
| 81 | |
| 82 | #define DHD_TXMINMAX 1 /* Max tx frames if rx still pending */ |
| 83 | |
| 84 | #define MEMBLOCK 2048 /* Block size used for downloading |
| 85 | of dongle image */ |
| 86 | #define MAX_DATA_BUF (32 * 1024) /* Must be large enough to hold |
| 87 | biggest possible glom */ |
| 88 | |
| 89 | /* Packet alignment for most efficient SDIO (can change based on platform) */ |
| 90 | #ifndef DHD_SDALIGN |
| 91 | #define DHD_SDALIGN 32 |
| 92 | #endif |
| 93 | #if !ISPOWEROF2(DHD_SDALIGN) |
| 94 | #error DHD_SDALIGN is not a power of 2! |
| 95 | #endif |
| 96 | |
| 97 | #ifndef DHD_FIRSTREAD |
| 98 | #define DHD_FIRSTREAD 32 |
| 99 | #endif |
| 100 | #if !ISPOWEROF2(DHD_FIRSTREAD) |
| 101 | #error DHD_FIRSTREAD is not a power of 2! |
| 102 | #endif |
| 103 | |
| 104 | /* Total length of frame header for dongle protocol */ |
| 105 | #define SDPCM_HDRLEN (SDPCM_FRAMETAG_LEN + SDPCM_SWHEADER_LEN) |
| 106 | #ifdef SDTEST |
| 107 | #define SDPCM_RESERVE (SDPCM_HDRLEN + SDPCM_TEST_HDRLEN + DHD_SDALIGN) |
| 108 | #else |
| 109 | #define SDPCM_RESERVE (SDPCM_HDRLEN + DHD_SDALIGN) |
| 110 | #endif |
| 111 | |
| 112 | /* Space for header read, limit for data packets */ |
| 113 | #ifndef MAX_HDR_READ |
| 114 | #define MAX_HDR_READ 32 |
| 115 | #endif |
| 116 | #if !ISPOWEROF2(MAX_HDR_READ) |
| 117 | #error MAX_HDR_READ is not a power of 2! |
| 118 | #endif |
| 119 | |
| 120 | #define MAX_RX_DATASZ 2048 |
| 121 | |
| 122 | /* Maximum milliseconds to wait for F2 to come up */ |
| 123 | #define DHD_WAIT_F2RDY 3000 |
| 124 | |
| 125 | /* Bump up limit on waiting for HT to account for first startup; |
| 126 | * if the image is doing a CRC calculation before programming the PMU |
| 127 | * for HT availability, it could take a couple hundred ms more, so |
| 128 | * max out at a 1 second (1000000us). |
| 129 | */ |
| 130 | #if (PMU_MAX_TRANSITION_DLY <= 1000000) |
| 131 | #undef PMU_MAX_TRANSITION_DLY |
| 132 | #define PMU_MAX_TRANSITION_DLY 1000000 |
| 133 | #endif |
| 134 | |
| 135 | /* Value for ChipClockCSR during initial setup */ |
| 136 | #define DHD_INIT_CLKCTL1 (SBSDIO_FORCE_HW_CLKREQ_OFF | \ |
| 137 | SBSDIO_ALP_AVAIL_REQ) |
| 138 | #define DHD_INIT_CLKCTL2 (SBSDIO_FORCE_HW_CLKREQ_OFF | SBSDIO_FORCE_ALP) |
| 139 | |
| 140 | /* Flags for SDH calls */ |
| 141 | #define F2SYNC (SDIO_REQ_4BYTE | SDIO_REQ_FIXED) |
| 142 | |
| 143 | /* Packet free applicable unconditionally for sdio and sdspi. Conditional if |
| 144 | * bufpool was present for gspi bus. |
| 145 | */ |
| 146 | #define PKTFREE2() if ((bus->bus != SPI_BUS) || bus->usebufpool) \ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 147 | PKTFREE(bus->dhd->osh, pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 148 | DHD_SPINWAIT_SLEEP_INIT(sdioh_spinwait_sleep); |
| 149 | extern int dhdcdc_set_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf, |
| 150 | uint len); |
| 151 | |
| 152 | #ifdef DHD_DEBUG |
| 153 | /* Device console log buffer state */ |
| 154 | typedef struct dhd_console { |
| 155 | uint count; /* Poll interval msec counter */ |
| 156 | uint log_addr; /* Log struct address (fixed) */ |
| 157 | hndrte_log_t log; /* Log struct (host copy) */ |
| 158 | uint bufsize; /* Size of log buffer */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 159 | u8 *buf; /* Log buffer (host copy) */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 160 | uint last; /* Last buffer read index */ |
| 161 | } dhd_console_t; |
| 162 | #endif /* DHD_DEBUG */ |
| 163 | |
| 164 | /* Private data for SDIO bus interaction */ |
| 165 | typedef struct dhd_bus { |
| 166 | dhd_pub_t *dhd; |
| 167 | |
| 168 | bcmsdh_info_t *sdh; /* Handle for BCMSDH calls */ |
| 169 | si_t *sih; /* Handle for SI calls */ |
| 170 | char *vars; /* Variables (from CIS and/or other) */ |
| 171 | uint varsz; /* Size of variables buffer */ |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 172 | u32 sbaddr; /* Current SB window pointer (-1, invalid) */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 173 | |
| 174 | sdpcmd_regs_t *regs; /* Registers for SDIO core */ |
| 175 | uint sdpcmrev; /* SDIO core revision */ |
| 176 | uint armrev; /* CPU core revision */ |
| 177 | uint ramrev; /* SOCRAM core revision */ |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 178 | u32 ramsize; /* Size of RAM in SOCRAM (bytes) */ |
| 179 | u32 orig_ramsize; /* Size of RAM in SOCRAM (bytes) */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 180 | |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 181 | u32 bus; /* gSPI or SDIO bus */ |
| 182 | u32 hostintmask; /* Copy of Host Interrupt Mask */ |
| 183 | u32 intstatus; /* Intstatus bits (events) pending */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 184 | bool dpc_sched; /* Indicates DPC schedule (intrpt rcvd) */ |
| 185 | bool fcstate; /* State of dongle flow-control */ |
| 186 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 187 | u16 cl_devid; /* cached devid for dhdsdio_probe_attach() */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 188 | char *fw_path; /* module_param: path to firmware image */ |
| 189 | char *nv_path; /* module_param: path to nvram vars file */ |
| 190 | const char *nvram_params; /* user specified nvram params. */ |
| 191 | |
| 192 | uint blocksize; /* Block size of SDIO transfers */ |
| 193 | uint roundup; /* Max roundup limit */ |
| 194 | |
| 195 | struct pktq txq; /* Queue length used for flow-control */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 196 | u8 flowcontrol; /* per prio flow control bitmask */ |
| 197 | u8 tx_seq; /* Transmit sequence number (next) */ |
| 198 | u8 tx_max; /* Maximum transmit sequence allowed */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 199 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 200 | u8 hdrbuf[MAX_HDR_READ + DHD_SDALIGN]; |
| 201 | u8 *rxhdr; /* Header of current rx frame (in hdrbuf) */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 202 | u16 nextlen; /* Next Read Len from last header */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 203 | u8 rx_seq; /* Receive sequence number (expected) */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 204 | bool rxskip; /* Skip receive (awaiting NAK ACK) */ |
| 205 | |
| 206 | void *glomd; /* Packet containing glomming descriptor */ |
| 207 | void *glom; /* Packet chain for glommed superframe */ |
| 208 | uint glomerr; /* Glom packet read errors */ |
| 209 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 210 | u8 *rxbuf; /* Buffer for receiving control packets */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 211 | uint rxblen; /* Allocated length of rxbuf */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 212 | u8 *rxctl; /* Aligned pointer into rxbuf */ |
| 213 | u8 *databuf; /* Buffer for receiving big glom packet */ |
| 214 | u8 *dataptr; /* Aligned pointer into databuf */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 215 | uint rxlen; /* Length of valid data in buffer */ |
| 216 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 217 | u8 sdpcm_ver; /* Bus protocol reported by dongle */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 218 | |
| 219 | bool intr; /* Use interrupts */ |
| 220 | bool poll; /* Use polling */ |
| 221 | bool ipend; /* Device interrupt is pending */ |
| 222 | bool intdis; /* Interrupts disabled by isr */ |
| 223 | uint intrcount; /* Count of device interrupt callbacks */ |
| 224 | uint lastintrs; /* Count as of last watchdog timer */ |
| 225 | uint spurious; /* Count of spurious interrupts */ |
| 226 | uint pollrate; /* Ticks between device polls */ |
| 227 | uint polltick; /* Tick counter */ |
| 228 | uint pollcnt; /* Count of active polls */ |
| 229 | |
| 230 | #ifdef DHD_DEBUG |
| 231 | dhd_console_t console; /* Console output polling support */ |
| 232 | uint console_addr; /* Console address from shared struct */ |
| 233 | #endif /* DHD_DEBUG */ |
| 234 | |
| 235 | uint regfails; /* Count of R_REG/W_REG failures */ |
| 236 | |
| 237 | uint clkstate; /* State of sd and backplane clock(s) */ |
| 238 | bool activity; /* Activity flag for clock down */ |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 239 | s32 idletime; /* Control for activity timeout */ |
| 240 | s32 idlecount; /* Activity timeout counter */ |
| 241 | s32 idleclock; /* How to set bus driver when idle */ |
| 242 | s32 sd_divisor; /* Speed control to bus driver */ |
| 243 | s32 sd_mode; /* Mode control to bus driver */ |
| 244 | s32 sd_rxchain; /* If bcmsdh api accepts PKT chains */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 245 | bool use_rxchain; /* If dhd should use PKT chains */ |
| 246 | bool sleeping; /* Is SDIO bus sleeping? */ |
| 247 | bool rxflow_mode; /* Rx flow control mode */ |
| 248 | bool rxflow; /* Is rx flow control on */ |
| 249 | uint prev_rxlim_hit; /* Is prev rx limit exceeded |
| 250 | (per dpc schedule) */ |
| 251 | bool alp_only; /* Don't use HT clock (ALP only) */ |
| 252 | /* Field to decide if rx of control frames happen in rxbuf or lb-pool */ |
| 253 | bool usebufpool; |
| 254 | |
| 255 | #ifdef SDTEST |
| 256 | /* external loopback */ |
| 257 | bool ext_loop; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 258 | u8 loopid; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 259 | |
| 260 | /* pktgen configuration */ |
| 261 | uint pktgen_freq; /* Ticks between bursts */ |
| 262 | uint pktgen_count; /* Packets to send each burst */ |
| 263 | uint pktgen_print; /* Bursts between count displays */ |
| 264 | uint pktgen_total; /* Stop after this many */ |
| 265 | uint pktgen_minlen; /* Minimum packet data len */ |
| 266 | uint pktgen_maxlen; /* Maximum packet data len */ |
| 267 | uint pktgen_mode; /* Configured mode: tx, rx, or echo */ |
| 268 | uint pktgen_stop; /* Number of tx failures causing stop */ |
| 269 | |
| 270 | /* active pktgen fields */ |
| 271 | uint pktgen_tick; /* Tick counter for bursts */ |
| 272 | uint pktgen_ptick; /* Burst counter for printing */ |
| 273 | uint pktgen_sent; /* Number of test packets generated */ |
| 274 | uint pktgen_rcvd; /* Number of test packets received */ |
| 275 | uint pktgen_fail; /* Number of failed send attempts */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 276 | u16 pktgen_len; /* Length of next packet to send */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 277 | #endif /* SDTEST */ |
| 278 | |
| 279 | /* Some additional counters */ |
| 280 | uint tx_sderrs; /* Count of tx attempts with sd errors */ |
| 281 | uint fcqueued; /* Tx packets that got queued */ |
| 282 | uint rxrtx; /* Count of rtx requests (NAK to dongle) */ |
| 283 | uint rx_toolong; /* Receive frames too long to receive */ |
| 284 | uint rxc_errors; /* SDIO errors when reading control frames */ |
| 285 | uint rx_hdrfail; /* SDIO errors on header reads */ |
| 286 | uint rx_badhdr; /* Bad received headers (roosync?) */ |
| 287 | uint rx_badseq; /* Mismatched rx sequence number */ |
| 288 | uint fc_rcvd; /* Number of flow-control events received */ |
| 289 | uint fc_xoff; /* Number which turned on flow-control */ |
| 290 | uint fc_xon; /* Number which turned off flow-control */ |
| 291 | uint rxglomfail; /* Failed deglom attempts */ |
| 292 | uint rxglomframes; /* Number of glom frames (superframes) */ |
| 293 | uint rxglompkts; /* Number of packets from glom frames */ |
| 294 | uint f2rxhdrs; /* Number of header reads */ |
| 295 | uint f2rxdata; /* Number of frame data reads */ |
| 296 | uint f2txdata; /* Number of f2 frame writes */ |
| 297 | uint f1regdata; /* Number of f1 register accesses */ |
| 298 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 299 | u8 *ctrl_frame_buf; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 300 | u32 ctrl_frame_len; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 301 | bool ctrl_frame_stat; |
| 302 | } dhd_bus_t; |
| 303 | |
| 304 | /* clkstate */ |
| 305 | #define CLK_NONE 0 |
| 306 | #define CLK_SDONLY 1 |
| 307 | #define CLK_PENDING 2 /* Not used yet */ |
| 308 | #define CLK_AVAIL 3 |
| 309 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 310 | #define DHD_NOPMU(dhd) (false) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 311 | |
| 312 | #ifdef DHD_DEBUG |
| 313 | static int qcount[NUMPRIO]; |
| 314 | static int tx_packets[NUMPRIO]; |
| 315 | #endif /* DHD_DEBUG */ |
| 316 | |
| 317 | /* Deferred transmit */ |
| 318 | const uint dhd_deferred_tx = 1; |
| 319 | |
| 320 | extern uint dhd_watchdog_ms; |
| 321 | extern void dhd_os_wd_timer(void *bus, uint wdtick); |
| 322 | |
| 323 | /* Tx/Rx bounds */ |
| 324 | uint dhd_txbound; |
| 325 | uint dhd_rxbound; |
| 326 | uint dhd_txminmax; |
| 327 | |
| 328 | /* override the RAM size if possible */ |
| 329 | #define DONGLE_MIN_MEMSIZE (128 * 1024) |
| 330 | int dhd_dongle_memsize; |
| 331 | |
| 332 | static bool dhd_doflow; |
| 333 | static bool dhd_alignctl; |
| 334 | |
| 335 | static bool sd1idle; |
| 336 | |
| 337 | static bool retrydata; |
| 338 | #define RETRYCHAN(chan) (((chan) == SDPCM_EVENT_CHANNEL) || retrydata) |
| 339 | |
| 340 | static const uint watermark = 8; |
| 341 | static const uint firstread = DHD_FIRSTREAD; |
| 342 | |
| 343 | #define HDATLEN (firstread - (SDPCM_HDRLEN)) |
| 344 | |
| 345 | /* Retry count for register access failures */ |
| 346 | static const uint retry_limit = 2; |
| 347 | |
| 348 | /* Force even SD lengths (some host controllers mess up on odd bytes) */ |
| 349 | static bool forcealign; |
| 350 | |
| 351 | #define ALIGNMENT 4 |
| 352 | |
| 353 | #if defined(OOB_INTR_ONLY) && defined(HW_OOB) |
| 354 | extern void bcmsdh_enable_hw_oob_intr(void *sdh, bool enable); |
| 355 | #endif |
| 356 | |
| 357 | #if defined(OOB_INTR_ONLY) && defined(SDIO_ISR_THREAD) |
| 358 | #error OOB_INTR_ONLY is NOT working with SDIO_ISR_THREAD |
| 359 | #endif /* defined(OOB_INTR_ONLY) && defined(SDIO_ISR_THREAD) */ |
| 360 | #define PKTALIGN(osh, p, len, align) \ |
| 361 | do { \ |
| 362 | uint datalign; \ |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 363 | datalign = (unsigned long)PKTDATA((p)); \ |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 364 | datalign = roundup(datalign, (align)) - datalign; \ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 365 | ASSERT(datalign < (align)); \ |
| 366 | ASSERT(PKTLEN((p)) >= ((len) + datalign)); \ |
| 367 | if (datalign) \ |
| 368 | PKTPULL((p), datalign); \ |
| 369 | PKTSETLEN((p), (len)); \ |
| 370 | } while (0) |
| 371 | |
| 372 | /* Limit on rounding up frames */ |
| 373 | static const uint max_roundup = 512; |
| 374 | |
| 375 | /* Try doing readahead */ |
| 376 | static bool dhd_readahead; |
| 377 | |
| 378 | /* To check if there's window offered */ |
| 379 | #define DATAOK(bus) \ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 380 | (((u8)(bus->tx_max - bus->tx_seq) != 0) && \ |
| 381 | (((u8)(bus->tx_max - bus->tx_seq) & 0x80) == 0)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 382 | |
| 383 | /* Macros to get register read/write status */ |
| 384 | /* NOTE: these assume a local dhdsdio_bus_t *bus! */ |
| 385 | #define R_SDREG(regvar, regaddr, retryvar) \ |
| 386 | do { \ |
| 387 | retryvar = 0; \ |
| 388 | do { \ |
| 389 | regvar = R_REG(bus->dhd->osh, regaddr); \ |
| 390 | } while (bcmsdh_regfail(bus->sdh) && (++retryvar <= retry_limit)); \ |
| 391 | if (retryvar) { \ |
| 392 | bus->regfails += (retryvar-1); \ |
| 393 | if (retryvar > retry_limit) { \ |
| 394 | DHD_ERROR(("%s: FAILED" #regvar "READ, LINE %d\n", \ |
| 395 | __func__, __LINE__)); \ |
| 396 | regvar = 0; \ |
| 397 | } \ |
| 398 | } \ |
| 399 | } while (0) |
| 400 | |
| 401 | #define W_SDREG(regval, regaddr, retryvar) \ |
| 402 | do { \ |
| 403 | retryvar = 0; \ |
| 404 | do { \ |
| 405 | W_REG(bus->dhd->osh, regaddr, regval); \ |
| 406 | } while (bcmsdh_regfail(bus->sdh) && (++retryvar <= retry_limit)); \ |
| 407 | if (retryvar) { \ |
| 408 | bus->regfails += (retryvar-1); \ |
| 409 | if (retryvar > retry_limit) \ |
| 410 | DHD_ERROR(("%s: FAILED REGISTER WRITE, LINE %d\n", \ |
| 411 | __func__, __LINE__)); \ |
| 412 | } \ |
| 413 | } while (0) |
| 414 | |
| 415 | #define DHD_BUS SDIO_BUS |
| 416 | |
| 417 | #define PKT_AVAILABLE() (intstatus & I_HMB_FRAME_IND) |
| 418 | |
| 419 | #define HOSTINTMASK (I_HMB_SW_MASK | I_CHIPACTIVE) |
| 420 | |
| 421 | #define GSPI_PR55150_BAILOUT |
| 422 | |
| 423 | #ifdef SDTEST |
| 424 | static void dhdsdio_testrcv(dhd_bus_t *bus, void *pkt, uint seq); |
| 425 | static void dhdsdio_sdtest_set(dhd_bus_t *bus, bool start); |
| 426 | #endif |
| 427 | |
| 428 | #ifdef DHD_DEBUG |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 429 | static int dhdsdio_checkdied(dhd_bus_t *bus, u8 *data, uint size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 430 | static int dhdsdio_mem_dump(dhd_bus_t *bus); |
| 431 | #endif /* DHD_DEBUG */ |
| 432 | static int dhdsdio_download_state(dhd_bus_t *bus, bool enter); |
| 433 | |
| 434 | static void dhdsdio_release(dhd_bus_t *bus, osl_t *osh); |
| 435 | static void dhdsdio_release_malloc(dhd_bus_t *bus, osl_t *osh); |
| 436 | static void dhdsdio_disconnect(void *ptr); |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 437 | static bool dhdsdio_chipmatch(u16 chipid); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 438 | static bool dhdsdio_probe_attach(dhd_bus_t *bus, osl_t *osh, void *sdh, |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 439 | void *regsva, u16 devid); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 440 | static bool dhdsdio_probe_malloc(dhd_bus_t *bus, osl_t *osh, void *sdh); |
| 441 | static bool dhdsdio_probe_init(dhd_bus_t *bus, osl_t *osh, void *sdh); |
| 442 | static void dhdsdio_release_dongle(dhd_bus_t *bus, osl_t * osh); |
| 443 | |
| 444 | static uint process_nvram_vars(char *varbuf, uint len); |
| 445 | |
| 446 | 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] | 447 | static int dhd_bcmsdh_recv_buf(dhd_bus_t *bus, u32 addr, uint fn, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 448 | uint flags, u8 *buf, uint nbytes, void *pkt, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 449 | bcmsdh_cmplt_fn_t complete, void *handle); |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 450 | static int dhd_bcmsdh_send_buf(dhd_bus_t *bus, u32 addr, uint fn, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 451 | uint flags, u8 *buf, uint nbytes, void *pkt, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 452 | bcmsdh_cmplt_fn_t complete, void *handle); |
| 453 | |
| 454 | static bool dhdsdio_download_firmware(struct dhd_bus *bus, osl_t *osh, |
| 455 | void *sdh); |
| 456 | static int _dhdsdio_download_firmware(struct dhd_bus *bus); |
| 457 | |
| 458 | static int dhdsdio_download_code_file(struct dhd_bus *bus, char *image_path); |
| 459 | static int dhdsdio_download_nvram(struct dhd_bus *bus); |
| 460 | #ifdef BCMEMBEDIMAGE |
| 461 | static int dhdsdio_download_code_array(struct dhd_bus *bus); |
| 462 | #endif |
| 463 | |
| 464 | static void dhd_dongle_setmemsize(struct dhd_bus *bus, int mem_size) |
| 465 | { |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 466 | s32 min_size = DONGLE_MIN_MEMSIZE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 467 | /* Restrict the memsize to user specified limit */ |
| 468 | DHD_ERROR(("user: Restrict the dongle ram size to %d, min %d\n", |
| 469 | dhd_dongle_memsize, min_size)); |
| 470 | if ((dhd_dongle_memsize > min_size) && |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 471 | (dhd_dongle_memsize < (s32) bus->orig_ramsize)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 472 | bus->ramsize = dhd_dongle_memsize; |
| 473 | } |
| 474 | |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 475 | static int dhdsdio_set_siaddr_window(dhd_bus_t *bus, u32 address) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 476 | { |
| 477 | int err = 0; |
| 478 | bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRLOW, |
| 479 | (address >> 8) & SBSDIO_SBADDRLOW_MASK, &err); |
| 480 | if (!err) |
| 481 | bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRMID, |
| 482 | (address >> 16) & SBSDIO_SBADDRMID_MASK, &err); |
| 483 | if (!err) |
| 484 | bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRHIGH, |
| 485 | (address >> 24) & SBSDIO_SBADDRHIGH_MASK, |
| 486 | &err); |
| 487 | return err; |
| 488 | } |
| 489 | |
| 490 | /* Turn backplane clock on or off */ |
| 491 | static int dhdsdio_htclk(dhd_bus_t *bus, bool on, bool pendok) |
| 492 | { |
| 493 | int err; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 494 | u8 clkctl, clkreq, devctl; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 495 | bcmsdh_info_t *sdh; |
| 496 | |
| 497 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 498 | |
| 499 | #if defined(OOB_INTR_ONLY) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 500 | pendok = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 501 | #endif |
| 502 | clkctl = 0; |
| 503 | sdh = bus->sdh; |
| 504 | |
| 505 | if (on) { |
| 506 | /* Request HT Avail */ |
| 507 | clkreq = |
| 508 | bus->alp_only ? SBSDIO_ALP_AVAIL_REQ : SBSDIO_HT_AVAIL_REQ; |
| 509 | |
| 510 | if ((bus->sih->chip == BCM4329_CHIP_ID) |
| 511 | && (bus->sih->chiprev == 0)) |
| 512 | clkreq |= SBSDIO_FORCE_ALP; |
| 513 | |
| 514 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 515 | clkreq, &err); |
| 516 | if (err) { |
| 517 | DHD_ERROR(("%s: HT Avail request error: %d\n", |
| 518 | __func__, err)); |
| 519 | return BCME_ERROR; |
| 520 | } |
| 521 | |
| 522 | if (pendok && ((bus->sih->buscoretype == PCMCIA_CORE_ID) |
| 523 | && (bus->sih->buscorerev == 9))) { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 524 | u32 dummy, retries; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 525 | R_SDREG(dummy, &bus->regs->clockctlstatus, retries); |
| 526 | } |
| 527 | |
| 528 | /* Check current status */ |
| 529 | clkctl = |
| 530 | bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 531 | &err); |
| 532 | if (err) { |
| 533 | DHD_ERROR(("%s: HT Avail read error: %d\n", |
| 534 | __func__, err)); |
| 535 | return BCME_ERROR; |
| 536 | } |
| 537 | |
| 538 | /* Go to pending and await interrupt if appropriate */ |
| 539 | if (!SBSDIO_CLKAV(clkctl, bus->alp_only) && pendok) { |
| 540 | /* Allow only clock-available interrupt */ |
| 541 | devctl = |
| 542 | bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL, |
| 543 | &err); |
| 544 | if (err) { |
| 545 | DHD_ERROR(("%s: Devctl error setting CA: %d\n", |
| 546 | __func__, err)); |
| 547 | return BCME_ERROR; |
| 548 | } |
| 549 | |
| 550 | devctl |= SBSDIO_DEVCTL_CA_INT_ONLY; |
| 551 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL, |
| 552 | devctl, &err); |
| 553 | DHD_INFO(("CLKCTL: set PENDING\n")); |
| 554 | bus->clkstate = CLK_PENDING; |
| 555 | |
| 556 | return BCME_OK; |
| 557 | } else if (bus->clkstate == CLK_PENDING) { |
| 558 | /* Cancel CA-only interrupt filter */ |
| 559 | devctl = |
| 560 | bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL, |
| 561 | &err); |
| 562 | devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY; |
| 563 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL, |
| 564 | devctl, &err); |
| 565 | } |
| 566 | |
| 567 | /* Otherwise, wait here (polling) for HT Avail */ |
| 568 | if (!SBSDIO_CLKAV(clkctl, bus->alp_only)) { |
| 569 | SPINWAIT_SLEEP(sdioh_spinwait_sleep, |
| 570 | ((clkctl = |
| 571 | bcmsdh_cfg_read(sdh, SDIO_FUNC_1, |
| 572 | SBSDIO_FUNC1_CHIPCLKCSR, |
| 573 | &err)), |
| 574 | !SBSDIO_CLKAV(clkctl, bus->alp_only)), |
| 575 | PMU_MAX_TRANSITION_DLY); |
| 576 | } |
| 577 | if (err) { |
| 578 | DHD_ERROR(("%s: HT Avail request error: %d\n", |
| 579 | __func__, err)); |
| 580 | return BCME_ERROR; |
| 581 | } |
| 582 | if (!SBSDIO_CLKAV(clkctl, bus->alp_only)) { |
| 583 | DHD_ERROR(("%s: HT Avail timeout (%d): clkctl 0x%02x\n", |
| 584 | __func__, PMU_MAX_TRANSITION_DLY, clkctl)); |
| 585 | return BCME_ERROR; |
| 586 | } |
| 587 | |
| 588 | /* Mark clock available */ |
| 589 | bus->clkstate = CLK_AVAIL; |
| 590 | DHD_INFO(("CLKCTL: turned ON\n")); |
| 591 | |
| 592 | #if defined(DHD_DEBUG) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 593 | if (bus->alp_only == true) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 594 | #if !defined(BCMLXSDMMC) |
| 595 | if (!SBSDIO_ALPONLY(clkctl)) { |
| 596 | DHD_ERROR(("%s: HT Clock, when ALP Only\n", |
| 597 | __func__)); |
| 598 | } |
| 599 | #endif /* !defined(BCMLXSDMMC) */ |
| 600 | } else { |
| 601 | if (SBSDIO_ALPONLY(clkctl)) { |
| 602 | DHD_ERROR(("%s: HT Clock should be on.\n", |
| 603 | __func__)); |
| 604 | } |
| 605 | } |
| 606 | #endif /* defined (DHD_DEBUG) */ |
| 607 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 608 | bus->activity = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 609 | } else { |
| 610 | clkreq = 0; |
| 611 | |
| 612 | if (bus->clkstate == CLK_PENDING) { |
| 613 | /* Cancel CA-only interrupt filter */ |
| 614 | devctl = |
| 615 | bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL, |
| 616 | &err); |
| 617 | devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY; |
| 618 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL, |
| 619 | devctl, &err); |
| 620 | } |
| 621 | |
| 622 | bus->clkstate = CLK_SDONLY; |
| 623 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 624 | clkreq, &err); |
| 625 | DHD_INFO(("CLKCTL: turned OFF\n")); |
| 626 | if (err) { |
| 627 | DHD_ERROR(("%s: Failed access turning clock off: %d\n", |
| 628 | __func__, err)); |
| 629 | return BCME_ERROR; |
| 630 | } |
| 631 | } |
| 632 | return BCME_OK; |
| 633 | } |
| 634 | |
| 635 | /* Change idle/active SD state */ |
| 636 | static int dhdsdio_sdclk(dhd_bus_t *bus, bool on) |
| 637 | { |
| 638 | int err; |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 639 | s32 iovalue; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 640 | |
| 641 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 642 | |
| 643 | if (on) { |
| 644 | if (bus->idleclock == DHD_IDLE_STOP) { |
| 645 | /* Turn on clock and restore mode */ |
| 646 | iovalue = 1; |
| 647 | err = bcmsdh_iovar_op(bus->sdh, "sd_clock", NULL, 0, |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 648 | &iovalue, sizeof(iovalue), true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 649 | if (err) { |
| 650 | DHD_ERROR(("%s: error enabling sd_clock: %d\n", |
| 651 | __func__, err)); |
| 652 | return BCME_ERROR; |
| 653 | } |
| 654 | |
| 655 | iovalue = bus->sd_mode; |
| 656 | err = bcmsdh_iovar_op(bus->sdh, "sd_mode", NULL, 0, |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 657 | &iovalue, sizeof(iovalue), true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 658 | if (err) { |
| 659 | DHD_ERROR(("%s: error changing sd_mode: %d\n", |
| 660 | __func__, err)); |
| 661 | return BCME_ERROR; |
| 662 | } |
| 663 | } else if (bus->idleclock != DHD_IDLE_ACTIVE) { |
| 664 | /* Restore clock speed */ |
| 665 | iovalue = bus->sd_divisor; |
| 666 | err = bcmsdh_iovar_op(bus->sdh, "sd_divisor", NULL, 0, |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 667 | &iovalue, sizeof(iovalue), true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 668 | if (err) { |
| 669 | DHD_ERROR(("%s: error restoring sd_divisor: %d\n", |
| 670 | __func__, err)); |
| 671 | return BCME_ERROR; |
| 672 | } |
| 673 | } |
| 674 | bus->clkstate = CLK_SDONLY; |
| 675 | } else { |
| 676 | /* Stop or slow the SD clock itself */ |
| 677 | if ((bus->sd_divisor == -1) || (bus->sd_mode == -1)) { |
| 678 | DHD_TRACE(("%s: can't idle clock, divisor %d mode %d\n", |
| 679 | __func__, bus->sd_divisor, bus->sd_mode)); |
| 680 | return BCME_ERROR; |
| 681 | } |
| 682 | if (bus->idleclock == DHD_IDLE_STOP) { |
| 683 | if (sd1idle) { |
| 684 | /* Change to SD1 mode and turn off clock */ |
| 685 | iovalue = 1; |
| 686 | err = |
| 687 | bcmsdh_iovar_op(bus->sdh, "sd_mode", NULL, |
| 688 | 0, &iovalue, |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 689 | sizeof(iovalue), true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 690 | if (err) { |
| 691 | DHD_ERROR(("%s: error changing sd_clock: %d\n", |
| 692 | __func__, err)); |
| 693 | return BCME_ERROR; |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | iovalue = 0; |
| 698 | err = bcmsdh_iovar_op(bus->sdh, "sd_clock", NULL, 0, |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 699 | &iovalue, sizeof(iovalue), true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 700 | if (err) { |
| 701 | DHD_ERROR(("%s: error disabling sd_clock: %d\n", |
| 702 | __func__, err)); |
| 703 | return BCME_ERROR; |
| 704 | } |
| 705 | } else if (bus->idleclock != DHD_IDLE_ACTIVE) { |
| 706 | /* Set divisor to idle value */ |
| 707 | iovalue = bus->idleclock; |
| 708 | err = bcmsdh_iovar_op(bus->sdh, "sd_divisor", NULL, 0, |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 709 | &iovalue, sizeof(iovalue), true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 710 | if (err) { |
| 711 | DHD_ERROR(("%s: error changing sd_divisor: %d\n", |
| 712 | __func__, err)); |
| 713 | return BCME_ERROR; |
| 714 | } |
| 715 | } |
| 716 | bus->clkstate = CLK_NONE; |
| 717 | } |
| 718 | |
| 719 | return BCME_OK; |
| 720 | } |
| 721 | |
| 722 | /* Transition SD and backplane clock readiness */ |
| 723 | static int dhdsdio_clkctl(dhd_bus_t *bus, uint target, bool pendok) |
| 724 | { |
| 725 | #ifdef DHD_DEBUG |
| 726 | uint oldstate = bus->clkstate; |
| 727 | #endif /* DHD_DEBUG */ |
| 728 | |
| 729 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 730 | |
| 731 | /* Early exit if we're already there */ |
| 732 | if (bus->clkstate == target) { |
| 733 | if (target == CLK_AVAIL) { |
| 734 | dhd_os_wd_timer(bus->dhd, dhd_watchdog_ms); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 735 | bus->activity = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 736 | } |
| 737 | return BCME_OK; |
| 738 | } |
| 739 | |
| 740 | switch (target) { |
| 741 | case CLK_AVAIL: |
| 742 | /* Make sure SD clock is available */ |
| 743 | if (bus->clkstate == CLK_NONE) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 744 | dhdsdio_sdclk(bus, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 745 | /* Now request HT Avail on the backplane */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 746 | dhdsdio_htclk(bus, true, pendok); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 747 | dhd_os_wd_timer(bus->dhd, dhd_watchdog_ms); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 748 | bus->activity = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 749 | break; |
| 750 | |
| 751 | case CLK_SDONLY: |
| 752 | /* Remove HT request, or bring up SD clock */ |
| 753 | if (bus->clkstate == CLK_NONE) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 754 | dhdsdio_sdclk(bus, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 755 | else if (bus->clkstate == CLK_AVAIL) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 756 | dhdsdio_htclk(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 757 | else |
| 758 | DHD_ERROR(("dhdsdio_clkctl: request for %d -> %d\n", |
| 759 | bus->clkstate, target)); |
| 760 | dhd_os_wd_timer(bus->dhd, dhd_watchdog_ms); |
| 761 | break; |
| 762 | |
| 763 | case CLK_NONE: |
| 764 | /* Make sure to remove HT request */ |
| 765 | if (bus->clkstate == CLK_AVAIL) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 766 | dhdsdio_htclk(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 767 | /* Now remove the SD clock */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 768 | dhdsdio_sdclk(bus, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 769 | dhd_os_wd_timer(bus->dhd, 0); |
| 770 | break; |
| 771 | } |
| 772 | #ifdef DHD_DEBUG |
| 773 | DHD_INFO(("dhdsdio_clkctl: %d -> %d\n", oldstate, bus->clkstate)); |
| 774 | #endif /* DHD_DEBUG */ |
| 775 | |
| 776 | return BCME_OK; |
| 777 | } |
| 778 | |
| 779 | int dhdsdio_bussleep(dhd_bus_t *bus, bool sleep) |
| 780 | { |
| 781 | bcmsdh_info_t *sdh = bus->sdh; |
| 782 | sdpcmd_regs_t *regs = bus->regs; |
| 783 | uint retries = 0; |
| 784 | |
| 785 | DHD_INFO(("dhdsdio_bussleep: request %s (currently %s)\n", |
| 786 | (sleep ? "SLEEP" : "WAKE"), |
| 787 | (bus->sleeping ? "SLEEP" : "WAKE"))); |
| 788 | |
| 789 | /* Done if we're already in the requested state */ |
| 790 | if (sleep == bus->sleeping) |
| 791 | return BCME_OK; |
| 792 | |
| 793 | /* Going to sleep: set the alarm and turn off the lights... */ |
| 794 | if (sleep) { |
| 795 | /* Don't sleep if something is pending */ |
| 796 | if (bus->dpc_sched || bus->rxskip || pktq_len(&bus->txq)) |
| 797 | return BCME_BUSY; |
| 798 | |
| 799 | /* Disable SDIO interrupts (no longer interested) */ |
| 800 | bcmsdh_intr_disable(bus->sdh); |
| 801 | |
| 802 | /* Make sure the controller has the bus up */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 803 | dhdsdio_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 804 | |
| 805 | /* Tell device to start using OOB wakeup */ |
| 806 | W_SDREG(SMB_USE_OOB, ®s->tosbmailbox, retries); |
| 807 | if (retries > retry_limit) |
| 808 | DHD_ERROR(("CANNOT SIGNAL CHIP, WILL NOT WAKE UP!!\n")); |
| 809 | |
| 810 | /* Turn off our contribution to the HT clock request */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 811 | dhdsdio_clkctl(bus, CLK_SDONLY, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 812 | |
| 813 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 814 | SBSDIO_FORCE_HW_CLKREQ_OFF, NULL); |
| 815 | |
| 816 | /* Isolate the bus */ |
| 817 | if (bus->sih->chip != BCM4329_CHIP_ID |
| 818 | && bus->sih->chip != BCM4319_CHIP_ID) { |
| 819 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL, |
| 820 | SBSDIO_DEVCTL_PADS_ISO, NULL); |
| 821 | } |
| 822 | |
| 823 | /* Change state */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 824 | bus->sleeping = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 825 | |
| 826 | } else { |
| 827 | /* Waking up: bus power up is ok, set local state */ |
| 828 | |
| 829 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 830 | 0, NULL); |
| 831 | |
| 832 | /* Force pad isolation off if possible |
| 833 | (in case power never toggled) */ |
| 834 | if ((bus->sih->buscoretype == PCMCIA_CORE_ID) |
| 835 | && (bus->sih->buscorerev >= 10)) |
| 836 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL, 0, |
| 837 | NULL); |
| 838 | |
| 839 | /* Make sure the controller has the bus up */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 840 | dhdsdio_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 841 | |
| 842 | /* Send misc interrupt to indicate OOB not needed */ |
| 843 | W_SDREG(0, ®s->tosbmailboxdata, retries); |
| 844 | if (retries <= retry_limit) |
| 845 | W_SDREG(SMB_DEV_INT, ®s->tosbmailbox, retries); |
| 846 | |
| 847 | if (retries > retry_limit) |
| 848 | DHD_ERROR(("CANNOT SIGNAL CHIP TO CLEAR OOB!!\n")); |
| 849 | |
| 850 | /* Make sure we have SD bus access */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 851 | dhdsdio_clkctl(bus, CLK_SDONLY, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 852 | |
| 853 | /* Change state */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 854 | bus->sleeping = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 855 | |
| 856 | /* Enable interrupts again */ |
| 857 | if (bus->intr && (bus->dhd->busstate == DHD_BUS_DATA)) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 858 | bus->intdis = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 859 | bcmsdh_intr_enable(bus->sdh); |
| 860 | } |
| 861 | } |
| 862 | |
| 863 | return BCME_OK; |
| 864 | } |
| 865 | |
| 866 | #if defined(OOB_INTR_ONLY) |
| 867 | void dhd_enable_oob_intr(struct dhd_bus *bus, bool enable) |
| 868 | { |
| 869 | #if defined(HW_OOB) |
| 870 | bcmsdh_enable_hw_oob_intr(bus->sdh, enable); |
| 871 | #else |
| 872 | sdpcmd_regs_t *regs = bus->regs; |
| 873 | uint retries = 0; |
| 874 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 875 | dhdsdio_clkctl(bus, CLK_AVAIL, false); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 876 | if (enable == true) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 877 | |
| 878 | /* Tell device to start using OOB wakeup */ |
| 879 | W_SDREG(SMB_USE_OOB, ®s->tosbmailbox, retries); |
| 880 | if (retries > retry_limit) |
| 881 | DHD_ERROR(("CANNOT SIGNAL CHIP, WILL NOT WAKE UP!!\n")); |
| 882 | |
| 883 | } else { |
| 884 | /* Send misc interrupt to indicate OOB not needed */ |
| 885 | W_SDREG(0, ®s->tosbmailboxdata, retries); |
| 886 | if (retries <= retry_limit) |
| 887 | W_SDREG(SMB_DEV_INT, ®s->tosbmailbox, retries); |
| 888 | } |
| 889 | |
| 890 | /* Turn off our contribution to the HT clock request */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 891 | dhdsdio_clkctl(bus, CLK_SDONLY, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 892 | #endif /* !defined(HW_OOB) */ |
| 893 | } |
| 894 | #endif /* defined(OOB_INTR_ONLY) */ |
| 895 | |
| 896 | #define BUS_WAKE(bus) \ |
| 897 | do { \ |
| 898 | if ((bus)->sleeping) \ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 899 | dhdsdio_bussleep((bus), false); \ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 900 | } while (0); |
| 901 | |
| 902 | /* Writes a HW/SW header into the packet and sends it. */ |
| 903 | /* Assumes: (a) header space already there, (b) caller holds lock */ |
| 904 | static int dhdsdio_txpkt(dhd_bus_t *bus, void *pkt, uint chan, bool free_pkt) |
| 905 | { |
| 906 | int ret; |
| 907 | osl_t *osh; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 908 | u8 *frame; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 909 | u16 len, pad = 0; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 910 | u32 swheader; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 911 | uint retries = 0; |
| 912 | bcmsdh_info_t *sdh; |
| 913 | void *new; |
| 914 | int i; |
| 915 | |
| 916 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 917 | |
| 918 | sdh = bus->sdh; |
| 919 | osh = bus->dhd->osh; |
| 920 | |
| 921 | if (bus->dhd->dongle_reset) { |
| 922 | ret = BCME_NOTREADY; |
| 923 | goto done; |
| 924 | } |
| 925 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 926 | frame = (u8 *) PKTDATA(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 927 | |
| 928 | /* Add alignment padding, allocate new packet if needed */ |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 929 | pad = ((unsigned long)frame % DHD_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 930 | if (pad) { |
| 931 | if (PKTHEADROOM(pkt) < pad) { |
| 932 | DHD_INFO(("%s: insufficient headroom %d for %d pad\n", |
| 933 | __func__, (int)PKTHEADROOM(pkt), pad)); |
| 934 | bus->dhd->tx_realloc++; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 935 | new = PKTGET(osh, (PKTLEN(pkt) + DHD_SDALIGN), true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 936 | if (!new) { |
| 937 | DHD_ERROR(("%s: couldn't allocate new %d-byte " |
| 938 | "packet\n", |
| 939 | __func__, PKTLEN(pkt) + DHD_SDALIGN)); |
| 940 | ret = BCME_NOMEM; |
| 941 | goto done; |
| 942 | } |
| 943 | |
| 944 | PKTALIGN(osh, new, PKTLEN(pkt), DHD_SDALIGN); |
| 945 | bcopy(PKTDATA(pkt), PKTDATA(new), PKTLEN(pkt)); |
| 946 | if (free_pkt) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 947 | PKTFREE(osh, pkt, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 948 | /* free the pkt if canned one is not used */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 949 | free_pkt = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 950 | pkt = new; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 951 | frame = (u8 *) PKTDATA(pkt); |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 952 | ASSERT(((unsigned long)frame % DHD_SDALIGN) == 0); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 953 | pad = 0; |
| 954 | } else { |
| 955 | PKTPUSH(pkt, pad); |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 956 | frame = (u8 *) PKTDATA(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 957 | |
| 958 | ASSERT((pad + SDPCM_HDRLEN) <= (int)PKTLEN(pkt)); |
| 959 | bzero(frame, pad + SDPCM_HDRLEN); |
| 960 | } |
| 961 | } |
| 962 | ASSERT(pad < DHD_SDALIGN); |
| 963 | |
| 964 | /* Hardware tag: 2 byte len followed by 2 byte ~len check (all LE) */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 965 | len = (u16) PKTLEN(pkt); |
| 966 | *(u16 *) frame = htol16(len); |
| 967 | *(((u16 *) frame) + 1) = htol16(~len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 968 | |
| 969 | /* Software tag: channel, sequence number, data offset */ |
| 970 | swheader = |
| 971 | ((chan << SDPCM_CHANNEL_SHIFT) & SDPCM_CHANNEL_MASK) | bus->tx_seq | |
| 972 | (((pad + |
| 973 | SDPCM_HDRLEN) << SDPCM_DOFFSET_SHIFT) & SDPCM_DOFFSET_MASK); |
| 974 | htol32_ua_store(swheader, frame + SDPCM_FRAMETAG_LEN); |
| 975 | htol32_ua_store(0, frame + SDPCM_FRAMETAG_LEN + sizeof(swheader)); |
| 976 | |
| 977 | #ifdef DHD_DEBUG |
| 978 | tx_packets[PKTPRIO(pkt)]++; |
| 979 | if (DHD_BYTES_ON() && |
| 980 | (((DHD_CTL_ON() && (chan == SDPCM_CONTROL_CHANNEL)) || |
| 981 | (DHD_DATA_ON() && (chan != SDPCM_CONTROL_CHANNEL))))) { |
| 982 | prhex("Tx Frame", frame, len); |
| 983 | } else if (DHD_HDRS_ON()) { |
Greg Kroah-Hartman | b61640d | 2010-10-08 12:37:39 -0700 | [diff] [blame] | 984 | prhex("TxHdr", frame, min_t(u16, len, 16)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 985 | } |
| 986 | #endif |
| 987 | |
| 988 | /* Raise len to next SDIO block to eliminate tail command */ |
| 989 | if (bus->roundup && bus->blocksize && (len > bus->blocksize)) { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 990 | u16 pad = bus->blocksize - (len % bus->blocksize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 991 | if ((pad <= bus->roundup) && (pad < bus->blocksize)) |
| 992 | #ifdef NOTUSED |
| 993 | if (pad <= PKTTAILROOM(pkt)) |
| 994 | #endif /* NOTUSED */ |
| 995 | len += pad; |
| 996 | } else if (len % DHD_SDALIGN) { |
| 997 | len += DHD_SDALIGN - (len % DHD_SDALIGN); |
| 998 | } |
| 999 | |
| 1000 | /* Some controllers have trouble with odd bytes -- round to even */ |
| 1001 | if (forcealign && (len & (ALIGNMENT - 1))) { |
| 1002 | #ifdef NOTUSED |
| 1003 | if (PKTTAILROOM(pkt)) |
| 1004 | #endif |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 1005 | len = roundup(len, ALIGNMENT); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1006 | #ifdef NOTUSED |
| 1007 | else |
| 1008 | DHD_ERROR(("%s: sending unrounded %d-byte packet\n", |
| 1009 | __func__, len)); |
| 1010 | #endif |
| 1011 | } |
| 1012 | |
| 1013 | do { |
| 1014 | ret = |
| 1015 | dhd_bcmsdh_send_buf(bus, bcmsdh_cur_sbwad(sdh), SDIO_FUNC_2, |
| 1016 | F2SYNC, frame, len, pkt, NULL, NULL); |
| 1017 | bus->f2txdata++; |
| 1018 | ASSERT(ret != BCME_PENDING); |
| 1019 | |
| 1020 | if (ret < 0) { |
| 1021 | /* On failure, abort the command |
| 1022 | and terminate the frame */ |
| 1023 | DHD_INFO(("%s: sdio error %d, abort command and " |
| 1024 | "terminate frame.\n", __func__, ret)); |
| 1025 | bus->tx_sderrs++; |
| 1026 | |
| 1027 | bcmsdh_abort(sdh, SDIO_FUNC_2); |
| 1028 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, |
| 1029 | SBSDIO_FUNC1_FRAMECTRL, SFC_WF_TERM, |
| 1030 | NULL); |
| 1031 | bus->f1regdata++; |
| 1032 | |
| 1033 | for (i = 0; i < 3; i++) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1034 | u8 hi, lo; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1035 | hi = bcmsdh_cfg_read(sdh, SDIO_FUNC_1, |
| 1036 | SBSDIO_FUNC1_WFRAMEBCHI, |
| 1037 | NULL); |
| 1038 | lo = bcmsdh_cfg_read(sdh, SDIO_FUNC_1, |
| 1039 | SBSDIO_FUNC1_WFRAMEBCLO, |
| 1040 | NULL); |
| 1041 | bus->f1regdata += 2; |
| 1042 | if ((hi == 0) && (lo == 0)) |
| 1043 | break; |
| 1044 | } |
| 1045 | |
| 1046 | } |
| 1047 | if (ret == 0) |
| 1048 | bus->tx_seq = (bus->tx_seq + 1) % SDPCM_SEQUENCE_WRAP; |
| 1049 | |
| 1050 | } while ((ret < 0) && retrydata && retries++ < TXRETRIES); |
| 1051 | |
| 1052 | done: |
| 1053 | /* restore pkt buffer pointer before calling tx complete routine */ |
| 1054 | PKTPULL(pkt, SDPCM_HDRLEN + pad); |
| 1055 | dhd_os_sdunlock(bus->dhd); |
| 1056 | dhd_txcomplete(bus->dhd, pkt, ret != 0); |
| 1057 | dhd_os_sdlock(bus->dhd); |
| 1058 | |
| 1059 | if (free_pkt) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1060 | PKTFREE(osh, pkt, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1061 | |
| 1062 | return ret; |
| 1063 | } |
| 1064 | |
| 1065 | int dhd_bus_txdata(struct dhd_bus *bus, void *pkt) |
| 1066 | { |
| 1067 | int ret = BCME_ERROR; |
| 1068 | osl_t *osh; |
| 1069 | uint datalen, prec; |
| 1070 | |
| 1071 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 1072 | |
| 1073 | osh = bus->dhd->osh; |
| 1074 | datalen = PKTLEN(pkt); |
| 1075 | |
| 1076 | #ifdef SDTEST |
| 1077 | /* Push the test header if doing loopback */ |
| 1078 | if (bus->ext_loop) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1079 | u8 *data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1080 | PKTPUSH(pkt, SDPCM_TEST_HDRLEN); |
| 1081 | data = PKTDATA(pkt); |
| 1082 | *data++ = SDPCM_TEST_ECHOREQ; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1083 | *data++ = (u8) bus->loopid++; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1084 | *data++ = (datalen >> 0); |
| 1085 | *data++ = (datalen >> 8); |
| 1086 | datalen += SDPCM_TEST_HDRLEN; |
| 1087 | } |
| 1088 | #endif /* SDTEST */ |
| 1089 | |
| 1090 | /* Add space for the header */ |
| 1091 | PKTPUSH(pkt, SDPCM_HDRLEN); |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 1092 | ASSERT(IS_ALIGNED((unsigned long)PKTDATA(pkt), 2)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1093 | |
| 1094 | prec = PRIO2PREC((PKTPRIO(pkt) & PRIOMASK)); |
| 1095 | |
| 1096 | /* Check for existing queue, current flow-control, |
| 1097 | pending event, or pending clock */ |
| 1098 | if (dhd_deferred_tx || bus->fcstate || pktq_len(&bus->txq) |
| 1099 | || bus->dpc_sched || (!DATAOK(bus)) |
| 1100 | || (bus->flowcontrol & NBITVAL(prec)) |
| 1101 | || (bus->clkstate != CLK_AVAIL)) { |
| 1102 | DHD_TRACE(("%s: deferring pktq len %d\n", __func__, |
| 1103 | pktq_len(&bus->txq))); |
| 1104 | bus->fcqueued++; |
| 1105 | |
| 1106 | /* Priority based enq */ |
| 1107 | dhd_os_sdlock_txq(bus->dhd); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1108 | if (dhd_prec_enq(bus->dhd, &bus->txq, pkt, prec) == false) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1109 | PKTPULL(pkt, SDPCM_HDRLEN); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1110 | dhd_txcomplete(bus->dhd, pkt, false); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1111 | PKTFREE(osh, pkt, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1112 | DHD_ERROR(("%s: out of bus->txq !!!\n", __func__)); |
| 1113 | ret = BCME_NORESOURCE; |
| 1114 | } else { |
| 1115 | ret = BCME_OK; |
| 1116 | } |
| 1117 | dhd_os_sdunlock_txq(bus->dhd); |
| 1118 | |
| 1119 | if ((pktq_len(&bus->txq) >= FCHI) && dhd_doflow) |
| 1120 | dhd_txflowcontrol(bus->dhd, 0, ON); |
| 1121 | |
| 1122 | #ifdef DHD_DEBUG |
| 1123 | if (pktq_plen(&bus->txq, prec) > qcount[prec]) |
| 1124 | qcount[prec] = pktq_plen(&bus->txq, prec); |
| 1125 | #endif |
| 1126 | /* Schedule DPC if needed to send queued packet(s) */ |
| 1127 | if (dhd_deferred_tx && !bus->dpc_sched) { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1128 | bus->dpc_sched = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1129 | dhd_sched_dpc(bus->dhd); |
| 1130 | } |
| 1131 | } else { |
| 1132 | /* Lock: we're about to use shared data/code (and SDIO) */ |
| 1133 | dhd_os_sdlock(bus->dhd); |
| 1134 | |
| 1135 | /* Otherwise, send it now */ |
| 1136 | BUS_WAKE(bus); |
| 1137 | /* Make sure back plane ht clk is on, no pending allowed */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1138 | dhdsdio_clkctl(bus, CLK_AVAIL, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1139 | |
| 1140 | #ifndef SDTEST |
| 1141 | DHD_TRACE(("%s: calling txpkt\n", __func__)); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1142 | ret = dhdsdio_txpkt(bus, pkt, SDPCM_DATA_CHANNEL, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1143 | #else |
| 1144 | ret = dhdsdio_txpkt(bus, pkt, |
| 1145 | (bus->ext_loop ? SDPCM_TEST_CHANNEL : |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1146 | SDPCM_DATA_CHANNEL), true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1147 | #endif |
| 1148 | if (ret) |
| 1149 | bus->dhd->tx_errors++; |
| 1150 | else |
| 1151 | bus->dhd->dstats.tx_bytes += datalen; |
| 1152 | |
| 1153 | if ((bus->idletime == DHD_IDLE_IMMEDIATE) && !bus->dpc_sched) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1154 | bus->activity = false; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1155 | dhdsdio_clkctl(bus, CLK_NONE, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1156 | } |
| 1157 | |
| 1158 | dhd_os_sdunlock(bus->dhd); |
| 1159 | } |
| 1160 | |
| 1161 | return ret; |
| 1162 | } |
| 1163 | |
| 1164 | static uint dhdsdio_sendfromq(dhd_bus_t *bus, uint maxframes) |
| 1165 | { |
| 1166 | void *pkt; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1167 | u32 intstatus = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1168 | uint retries = 0; |
| 1169 | int ret = 0, prec_out; |
| 1170 | uint cnt = 0; |
| 1171 | uint datalen; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1172 | u8 tx_prec_map; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1173 | |
| 1174 | dhd_pub_t *dhd = bus->dhd; |
| 1175 | sdpcmd_regs_t *regs = bus->regs; |
| 1176 | |
| 1177 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 1178 | |
| 1179 | tx_prec_map = ~bus->flowcontrol; |
| 1180 | |
| 1181 | /* Send frames until the limit or some other event */ |
| 1182 | for (cnt = 0; (cnt < maxframes) && DATAOK(bus); cnt++) { |
| 1183 | dhd_os_sdlock_txq(bus->dhd); |
| 1184 | pkt = pktq_mdeq(&bus->txq, tx_prec_map, &prec_out); |
| 1185 | if (pkt == NULL) { |
| 1186 | dhd_os_sdunlock_txq(bus->dhd); |
| 1187 | break; |
| 1188 | } |
| 1189 | dhd_os_sdunlock_txq(bus->dhd); |
| 1190 | datalen = PKTLEN(pkt) - SDPCM_HDRLEN; |
| 1191 | |
| 1192 | #ifndef SDTEST |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1193 | ret = dhdsdio_txpkt(bus, pkt, SDPCM_DATA_CHANNEL, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1194 | #else |
| 1195 | ret = dhdsdio_txpkt(bus, pkt, |
| 1196 | (bus->ext_loop ? SDPCM_TEST_CHANNEL : |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1197 | SDPCM_DATA_CHANNEL), true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1198 | #endif |
| 1199 | if (ret) |
| 1200 | bus->dhd->tx_errors++; |
| 1201 | else |
| 1202 | bus->dhd->dstats.tx_bytes += datalen; |
| 1203 | |
| 1204 | /* In poll mode, need to check for other events */ |
| 1205 | if (!bus->intr && cnt) { |
| 1206 | /* Check device status, signal pending interrupt */ |
| 1207 | R_SDREG(intstatus, ®s->intstatus, retries); |
| 1208 | bus->f2txdata++; |
| 1209 | if (bcmsdh_regfail(bus->sdh)) |
| 1210 | break; |
| 1211 | if (intstatus & bus->hostintmask) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1212 | bus->ipend = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1213 | } |
| 1214 | } |
| 1215 | |
| 1216 | /* Deflow-control stack if needed */ |
| 1217 | if (dhd_doflow && dhd->up && (dhd->busstate == DHD_BUS_DATA) && |
| 1218 | dhd->txoff && (pktq_len(&bus->txq) < FCLOW)) |
| 1219 | dhd_txflowcontrol(dhd, 0, OFF); |
| 1220 | |
| 1221 | return cnt; |
| 1222 | } |
| 1223 | |
Greg Kroah-Hartman | 580a0bd | 2010-10-05 11:09:48 -0700 | [diff] [blame] | 1224 | 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] | 1225 | { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1226 | u8 *frame; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 1227 | u16 len; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1228 | u32 swheader; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1229 | uint retries = 0; |
| 1230 | bcmsdh_info_t *sdh = bus->sdh; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1231 | u8 doff = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1232 | int ret = -1; |
| 1233 | int i; |
| 1234 | |
| 1235 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 1236 | |
| 1237 | if (bus->dhd->dongle_reset) |
| 1238 | return -EIO; |
| 1239 | |
| 1240 | /* Back the pointer to make a room for bus header */ |
| 1241 | frame = msg - SDPCM_HDRLEN; |
| 1242 | len = (msglen += SDPCM_HDRLEN); |
| 1243 | |
| 1244 | /* Add alignment padding (optional for ctl frames) */ |
| 1245 | if (dhd_alignctl) { |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 1246 | doff = ((unsigned long)frame % DHD_SDALIGN); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 1247 | if (doff) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1248 | frame -= doff; |
| 1249 | len += doff; |
| 1250 | msglen += doff; |
| 1251 | bzero(frame, doff + SDPCM_HDRLEN); |
| 1252 | } |
| 1253 | ASSERT(doff < DHD_SDALIGN); |
| 1254 | } |
| 1255 | doff += SDPCM_HDRLEN; |
| 1256 | |
| 1257 | /* Round send length to next SDIO block */ |
| 1258 | if (bus->roundup && bus->blocksize && (len > bus->blocksize)) { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 1259 | u16 pad = bus->blocksize - (len % bus->blocksize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1260 | if ((pad <= bus->roundup) && (pad < bus->blocksize)) |
| 1261 | len += pad; |
| 1262 | } else if (len % DHD_SDALIGN) { |
| 1263 | len += DHD_SDALIGN - (len % DHD_SDALIGN); |
| 1264 | } |
| 1265 | |
| 1266 | /* Satisfy length-alignment requirements */ |
| 1267 | if (forcealign && (len & (ALIGNMENT - 1))) |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 1268 | len = roundup(len, ALIGNMENT); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1269 | |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 1270 | ASSERT(IS_ALIGNED((unsigned long)frame, 2)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1271 | |
| 1272 | /* Need to lock here to protect txseq and SDIO tx calls */ |
| 1273 | dhd_os_sdlock(bus->dhd); |
| 1274 | |
| 1275 | BUS_WAKE(bus); |
| 1276 | |
| 1277 | /* Make sure backplane clock is on */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1278 | dhdsdio_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1279 | |
| 1280 | /* Hardware tag: 2 byte len followed by 2 byte ~len check (all LE) */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 1281 | *(u16 *) frame = htol16((u16) msglen); |
| 1282 | *(((u16 *) frame) + 1) = htol16(~msglen); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1283 | |
| 1284 | /* Software tag: channel, sequence number, data offset */ |
| 1285 | swheader = |
| 1286 | ((SDPCM_CONTROL_CHANNEL << SDPCM_CHANNEL_SHIFT) & |
| 1287 | SDPCM_CHANNEL_MASK) |
| 1288 | | bus->tx_seq | ((doff << SDPCM_DOFFSET_SHIFT) & |
| 1289 | SDPCM_DOFFSET_MASK); |
| 1290 | htol32_ua_store(swheader, frame + SDPCM_FRAMETAG_LEN); |
| 1291 | htol32_ua_store(0, frame + SDPCM_FRAMETAG_LEN + sizeof(swheader)); |
| 1292 | |
| 1293 | if (!DATAOK(bus)) { |
| 1294 | DHD_INFO(("%s: No bus credit bus->tx_max %d, bus->tx_seq %d\n", |
| 1295 | __func__, bus->tx_max, bus->tx_seq)); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1296 | bus->ctrl_frame_stat = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1297 | /* Send from dpc */ |
| 1298 | bus->ctrl_frame_buf = frame; |
| 1299 | bus->ctrl_frame_len = len; |
| 1300 | |
| 1301 | dhd_wait_for_event(bus->dhd, &bus->ctrl_frame_stat); |
| 1302 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1303 | if (bus->ctrl_frame_stat == false) { |
| 1304 | DHD_INFO(("%s: ctrl_frame_stat == false\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1305 | ret = 0; |
| 1306 | } else { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1307 | DHD_INFO(("%s: ctrl_frame_stat == true\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1308 | ret = -1; |
| 1309 | } |
| 1310 | } |
| 1311 | |
| 1312 | if (ret == -1) { |
| 1313 | #ifdef DHD_DEBUG |
| 1314 | if (DHD_BYTES_ON() && DHD_CTL_ON()) |
| 1315 | prhex("Tx Frame", frame, len); |
| 1316 | else if (DHD_HDRS_ON()) |
Greg Kroah-Hartman | b61640d | 2010-10-08 12:37:39 -0700 | [diff] [blame] | 1317 | prhex("TxHdr", frame, min_t(u16, len, 16)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1318 | #endif |
| 1319 | |
| 1320 | do { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1321 | bus->ctrl_frame_stat = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1322 | ret = |
| 1323 | dhd_bcmsdh_send_buf(bus, bcmsdh_cur_sbwad(sdh), |
| 1324 | SDIO_FUNC_2, F2SYNC, frame, len, |
| 1325 | NULL, NULL, NULL); |
| 1326 | |
| 1327 | ASSERT(ret != BCME_PENDING); |
| 1328 | |
| 1329 | if (ret < 0) { |
| 1330 | /* On failure, abort the command and |
| 1331 | terminate the frame */ |
| 1332 | DHD_INFO(("%s: sdio error %d, abort command and terminate frame.\n", |
| 1333 | __func__, ret)); |
| 1334 | bus->tx_sderrs++; |
| 1335 | |
| 1336 | bcmsdh_abort(sdh, SDIO_FUNC_2); |
| 1337 | |
| 1338 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, |
| 1339 | SBSDIO_FUNC1_FRAMECTRL, |
| 1340 | SFC_WF_TERM, NULL); |
| 1341 | bus->f1regdata++; |
| 1342 | |
| 1343 | for (i = 0; i < 3; i++) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1344 | u8 hi, lo; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1345 | hi = bcmsdh_cfg_read(sdh, SDIO_FUNC_1, |
| 1346 | SBSDIO_FUNC1_WFRAMEBCHI, |
| 1347 | NULL); |
| 1348 | lo = bcmsdh_cfg_read(sdh, SDIO_FUNC_1, |
| 1349 | SBSDIO_FUNC1_WFRAMEBCLO, |
| 1350 | NULL); |
| 1351 | bus->f1regdata += 2; |
| 1352 | if ((hi == 0) && (lo == 0)) |
| 1353 | break; |
| 1354 | } |
| 1355 | |
| 1356 | } |
| 1357 | if (ret == 0) { |
| 1358 | bus->tx_seq = |
| 1359 | (bus->tx_seq + 1) % SDPCM_SEQUENCE_WRAP; |
| 1360 | } |
| 1361 | } while ((ret < 0) && retries++ < TXRETRIES); |
| 1362 | } |
| 1363 | |
| 1364 | if ((bus->idletime == DHD_IDLE_IMMEDIATE) && !bus->dpc_sched) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1365 | bus->activity = false; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1366 | dhdsdio_clkctl(bus, CLK_NONE, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1367 | } |
| 1368 | |
| 1369 | dhd_os_sdunlock(bus->dhd); |
| 1370 | |
| 1371 | if (ret) |
| 1372 | bus->dhd->tx_ctlerrs++; |
| 1373 | else |
| 1374 | bus->dhd->tx_ctlpkts++; |
| 1375 | |
| 1376 | return ret ? -EIO : 0; |
| 1377 | } |
| 1378 | |
Greg Kroah-Hartman | 580a0bd | 2010-10-05 11:09:48 -0700 | [diff] [blame] | 1379 | 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] | 1380 | { |
| 1381 | int timeleft; |
| 1382 | uint rxlen = 0; |
| 1383 | bool pending; |
| 1384 | |
| 1385 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 1386 | |
| 1387 | if (bus->dhd->dongle_reset) |
| 1388 | return -EIO; |
| 1389 | |
| 1390 | /* Wait until control frame is available */ |
| 1391 | timeleft = dhd_os_ioctl_resp_wait(bus->dhd, &bus->rxlen, &pending); |
| 1392 | |
| 1393 | dhd_os_sdlock(bus->dhd); |
| 1394 | rxlen = bus->rxlen; |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 1395 | bcopy(bus->rxctl, msg, min(msglen, rxlen)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1396 | bus->rxlen = 0; |
| 1397 | dhd_os_sdunlock(bus->dhd); |
| 1398 | |
| 1399 | if (rxlen) { |
| 1400 | DHD_CTL(("%s: resumed on rxctl frame, got %d expected %d\n", |
| 1401 | __func__, rxlen, msglen)); |
| 1402 | } else if (timeleft == 0) { |
| 1403 | DHD_ERROR(("%s: resumed on timeout\n", __func__)); |
| 1404 | #ifdef DHD_DEBUG |
| 1405 | dhd_os_sdlock(bus->dhd); |
| 1406 | dhdsdio_checkdied(bus, NULL, 0); |
| 1407 | dhd_os_sdunlock(bus->dhd); |
| 1408 | #endif /* DHD_DEBUG */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1409 | } else if (pending == true) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1410 | DHD_CTL(("%s: cancelled\n", __func__)); |
| 1411 | return -ERESTARTSYS; |
| 1412 | } else { |
| 1413 | DHD_CTL(("%s: resumed for unknown reason?\n", __func__)); |
| 1414 | #ifdef DHD_DEBUG |
| 1415 | dhd_os_sdlock(bus->dhd); |
| 1416 | dhdsdio_checkdied(bus, NULL, 0); |
| 1417 | dhd_os_sdunlock(bus->dhd); |
| 1418 | #endif /* DHD_DEBUG */ |
| 1419 | } |
| 1420 | |
| 1421 | if (rxlen) |
| 1422 | bus->dhd->rx_ctlpkts++; |
| 1423 | else |
| 1424 | bus->dhd->rx_ctlerrs++; |
| 1425 | |
Jason Cooper | e9887c9 | 2010-10-06 10:08:02 -0400 | [diff] [blame] | 1426 | return rxlen ? (int)rxlen : -ETIMEDOUT; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1427 | } |
| 1428 | |
| 1429 | /* IOVar table */ |
| 1430 | enum { |
| 1431 | IOV_INTR = 1, |
| 1432 | IOV_POLLRATE, |
| 1433 | IOV_SDREG, |
| 1434 | IOV_SBREG, |
| 1435 | IOV_SDCIS, |
| 1436 | IOV_MEMBYTES, |
| 1437 | IOV_MEMSIZE, |
| 1438 | #ifdef DHD_DEBUG |
| 1439 | IOV_CHECKDIED, |
| 1440 | #endif |
| 1441 | IOV_DOWNLOAD, |
| 1442 | IOV_FORCEEVEN, |
| 1443 | IOV_SDIOD_DRIVE, |
| 1444 | IOV_READAHEAD, |
| 1445 | IOV_SDRXCHAIN, |
| 1446 | IOV_ALIGNCTL, |
| 1447 | IOV_SDALIGN, |
| 1448 | IOV_DEVRESET, |
| 1449 | IOV_CPU, |
| 1450 | #ifdef SDTEST |
| 1451 | IOV_PKTGEN, |
| 1452 | IOV_EXTLOOP, |
| 1453 | #endif /* SDTEST */ |
| 1454 | IOV_SPROM, |
| 1455 | IOV_TXBOUND, |
| 1456 | IOV_RXBOUND, |
| 1457 | IOV_TXMINMAX, |
| 1458 | IOV_IDLETIME, |
| 1459 | IOV_IDLECLOCK, |
| 1460 | IOV_SD1IDLE, |
| 1461 | IOV_SLEEP, |
| 1462 | IOV_VARS |
| 1463 | }; |
| 1464 | |
| 1465 | const bcm_iovar_t dhdsdio_iovars[] = { |
| 1466 | {"intr", IOV_INTR, 0, IOVT_BOOL, 0}, |
| 1467 | {"sleep", IOV_SLEEP, 0, IOVT_BOOL, 0}, |
| 1468 | {"pollrate", IOV_POLLRATE, 0, IOVT_UINT32, 0}, |
| 1469 | {"idletime", IOV_IDLETIME, 0, IOVT_INT32, 0}, |
| 1470 | {"idleclock", IOV_IDLECLOCK, 0, IOVT_INT32, 0}, |
| 1471 | {"sd1idle", IOV_SD1IDLE, 0, IOVT_BOOL, 0}, |
| 1472 | {"membytes", IOV_MEMBYTES, 0, IOVT_BUFFER, 2 * sizeof(int)}, |
| 1473 | {"memsize", IOV_MEMSIZE, 0, IOVT_UINT32, 0}, |
| 1474 | {"download", IOV_DOWNLOAD, 0, IOVT_BOOL, 0}, |
| 1475 | {"vars", IOV_VARS, 0, IOVT_BUFFER, 0}, |
| 1476 | {"sdiod_drive", IOV_SDIOD_DRIVE, 0, IOVT_UINT32, 0}, |
| 1477 | {"readahead", IOV_READAHEAD, 0, IOVT_BOOL, 0}, |
| 1478 | {"sdrxchain", IOV_SDRXCHAIN, 0, IOVT_BOOL, 0}, |
| 1479 | {"alignctl", IOV_ALIGNCTL, 0, IOVT_BOOL, 0}, |
| 1480 | {"sdalign", IOV_SDALIGN, 0, IOVT_BOOL, 0}, |
| 1481 | {"devreset", IOV_DEVRESET, 0, IOVT_BOOL, 0}, |
| 1482 | #ifdef DHD_DEBUG |
| 1483 | {"sdreg", IOV_SDREG, 0, IOVT_BUFFER, sizeof(sdreg_t)} |
| 1484 | , |
| 1485 | {"sbreg", IOV_SBREG, 0, IOVT_BUFFER, sizeof(sdreg_t)} |
| 1486 | , |
| 1487 | {"sd_cis", IOV_SDCIS, 0, IOVT_BUFFER, DHD_IOCTL_MAXLEN} |
| 1488 | , |
| 1489 | {"forcealign", IOV_FORCEEVEN, 0, IOVT_BOOL, 0} |
| 1490 | , |
| 1491 | {"txbound", IOV_TXBOUND, 0, IOVT_UINT32, 0} |
| 1492 | , |
| 1493 | {"rxbound", IOV_RXBOUND, 0, IOVT_UINT32, 0} |
| 1494 | , |
| 1495 | {"txminmax", IOV_TXMINMAX, 0, IOVT_UINT32, 0} |
| 1496 | , |
| 1497 | {"cpu", IOV_CPU, 0, IOVT_BOOL, 0} |
| 1498 | , |
| 1499 | #ifdef DHD_DEBUG |
| 1500 | {"checkdied", IOV_CHECKDIED, 0, IOVT_BUFFER, 0} |
| 1501 | , |
| 1502 | #endif /* DHD_DEBUG */ |
| 1503 | #endif /* DHD_DEBUG */ |
| 1504 | #ifdef SDTEST |
| 1505 | {"extloop", IOV_EXTLOOP, 0, IOVT_BOOL, 0} |
| 1506 | , |
| 1507 | {"pktgen", IOV_PKTGEN, 0, IOVT_BUFFER, sizeof(dhd_pktgen_t)} |
| 1508 | , |
| 1509 | #endif /* SDTEST */ |
| 1510 | |
| 1511 | {NULL, 0, 0, 0, 0} |
| 1512 | }; |
| 1513 | |
| 1514 | static void |
| 1515 | dhd_dump_pct(struct bcmstrbuf *strbuf, char *desc, uint num, uint div) |
| 1516 | { |
| 1517 | uint q1, q2; |
| 1518 | |
| 1519 | if (!div) { |
| 1520 | bcm_bprintf(strbuf, "%s N/A", desc); |
| 1521 | } else { |
| 1522 | q1 = num / div; |
| 1523 | q2 = (100 * (num - (q1 * div))) / div; |
| 1524 | bcm_bprintf(strbuf, "%s %d.%02d", desc, q1, q2); |
| 1525 | } |
| 1526 | } |
| 1527 | |
| 1528 | void dhd_bus_dump(dhd_pub_t *dhdp, struct bcmstrbuf *strbuf) |
| 1529 | { |
| 1530 | dhd_bus_t *bus = dhdp->bus; |
| 1531 | |
| 1532 | bcm_bprintf(strbuf, "Bus SDIO structure:\n"); |
| 1533 | bcm_bprintf(strbuf, |
| 1534 | "hostintmask 0x%08x intstatus 0x%08x sdpcm_ver %d\n", |
| 1535 | bus->hostintmask, bus->intstatus, bus->sdpcm_ver); |
| 1536 | bcm_bprintf(strbuf, |
| 1537 | "fcstate %d qlen %d tx_seq %d, max %d, rxskip %d rxlen %d rx_seq %d\n", |
| 1538 | bus->fcstate, pktq_len(&bus->txq), bus->tx_seq, bus->tx_max, |
| 1539 | bus->rxskip, bus->rxlen, bus->rx_seq); |
| 1540 | bcm_bprintf(strbuf, "intr %d intrcount %d lastintrs %d spurious %d\n", |
| 1541 | bus->intr, bus->intrcount, bus->lastintrs, bus->spurious); |
| 1542 | bcm_bprintf(strbuf, "pollrate %d pollcnt %d regfails %d\n", |
| 1543 | bus->pollrate, bus->pollcnt, bus->regfails); |
| 1544 | |
| 1545 | bcm_bprintf(strbuf, "\nAdditional counters:\n"); |
| 1546 | bcm_bprintf(strbuf, |
| 1547 | "tx_sderrs %d fcqueued %d rxrtx %d rx_toolong %d rxc_errors %d\n", |
| 1548 | bus->tx_sderrs, bus->fcqueued, bus->rxrtx, bus->rx_toolong, |
| 1549 | bus->rxc_errors); |
| 1550 | bcm_bprintf(strbuf, "rx_hdrfail %d badhdr %d badseq %d\n", |
| 1551 | bus->rx_hdrfail, bus->rx_badhdr, bus->rx_badseq); |
| 1552 | bcm_bprintf(strbuf, "fc_rcvd %d, fc_xoff %d, fc_xon %d\n", bus->fc_rcvd, |
| 1553 | bus->fc_xoff, bus->fc_xon); |
| 1554 | bcm_bprintf(strbuf, "rxglomfail %d, rxglomframes %d, rxglompkts %d\n", |
| 1555 | bus->rxglomfail, bus->rxglomframes, bus->rxglompkts); |
| 1556 | bcm_bprintf(strbuf, "f2rx (hdrs/data) %d (%d/%d), f2tx %d f1regs %d\n", |
| 1557 | (bus->f2rxhdrs + bus->f2rxdata), bus->f2rxhdrs, |
| 1558 | bus->f2rxdata, bus->f2txdata, bus->f1regdata); |
| 1559 | { |
| 1560 | dhd_dump_pct(strbuf, "\nRx: pkts/f2rd", bus->dhd->rx_packets, |
| 1561 | (bus->f2rxhdrs + bus->f2rxdata)); |
| 1562 | dhd_dump_pct(strbuf, ", pkts/f1sd", bus->dhd->rx_packets, |
| 1563 | bus->f1regdata); |
| 1564 | dhd_dump_pct(strbuf, ", pkts/sd", bus->dhd->rx_packets, |
| 1565 | (bus->f2rxhdrs + bus->f2rxdata + bus->f1regdata)); |
| 1566 | dhd_dump_pct(strbuf, ", pkts/int", bus->dhd->rx_packets, |
| 1567 | bus->intrcount); |
| 1568 | bcm_bprintf(strbuf, "\n"); |
| 1569 | |
| 1570 | dhd_dump_pct(strbuf, "Rx: glom pct", (100 * bus->rxglompkts), |
| 1571 | bus->dhd->rx_packets); |
| 1572 | dhd_dump_pct(strbuf, ", pkts/glom", bus->rxglompkts, |
| 1573 | bus->rxglomframes); |
| 1574 | bcm_bprintf(strbuf, "\n"); |
| 1575 | |
| 1576 | dhd_dump_pct(strbuf, "Tx: pkts/f2wr", bus->dhd->tx_packets, |
| 1577 | bus->f2txdata); |
| 1578 | dhd_dump_pct(strbuf, ", pkts/f1sd", bus->dhd->tx_packets, |
| 1579 | bus->f1regdata); |
| 1580 | dhd_dump_pct(strbuf, ", pkts/sd", bus->dhd->tx_packets, |
| 1581 | (bus->f2txdata + bus->f1regdata)); |
| 1582 | dhd_dump_pct(strbuf, ", pkts/int", bus->dhd->tx_packets, |
| 1583 | bus->intrcount); |
| 1584 | bcm_bprintf(strbuf, "\n"); |
| 1585 | |
| 1586 | dhd_dump_pct(strbuf, "Total: pkts/f2rw", |
| 1587 | (bus->dhd->tx_packets + bus->dhd->rx_packets), |
| 1588 | (bus->f2txdata + bus->f2rxhdrs + bus->f2rxdata)); |
| 1589 | dhd_dump_pct(strbuf, ", pkts/f1sd", |
| 1590 | (bus->dhd->tx_packets + bus->dhd->rx_packets), |
| 1591 | bus->f1regdata); |
| 1592 | dhd_dump_pct(strbuf, ", pkts/sd", |
| 1593 | (bus->dhd->tx_packets + bus->dhd->rx_packets), |
| 1594 | (bus->f2txdata + bus->f2rxhdrs + bus->f2rxdata + |
| 1595 | bus->f1regdata)); |
| 1596 | dhd_dump_pct(strbuf, ", pkts/int", |
| 1597 | (bus->dhd->tx_packets + bus->dhd->rx_packets), |
| 1598 | bus->intrcount); |
| 1599 | bcm_bprintf(strbuf, "\n\n"); |
| 1600 | } |
| 1601 | |
| 1602 | #ifdef SDTEST |
| 1603 | if (bus->pktgen_count) { |
| 1604 | bcm_bprintf(strbuf, "pktgen config and count:\n"); |
| 1605 | bcm_bprintf(strbuf, |
| 1606 | "freq %d count %d print %d total %d min %d len %d\n", |
| 1607 | bus->pktgen_freq, bus->pktgen_count, |
| 1608 | bus->pktgen_print, bus->pktgen_total, |
| 1609 | bus->pktgen_minlen, bus->pktgen_maxlen); |
| 1610 | bcm_bprintf(strbuf, "send attempts %d rcvd %d fail %d\n", |
| 1611 | bus->pktgen_sent, bus->pktgen_rcvd, |
| 1612 | bus->pktgen_fail); |
| 1613 | } |
| 1614 | #endif /* SDTEST */ |
| 1615 | #ifdef DHD_DEBUG |
| 1616 | bcm_bprintf(strbuf, "dpc_sched %d host interrupt%spending\n", |
| 1617 | bus->dpc_sched, |
| 1618 | (bcmsdh_intr_pending(bus->sdh) ? " " : " not ")); |
| 1619 | bcm_bprintf(strbuf, "blocksize %d roundup %d\n", bus->blocksize, |
| 1620 | bus->roundup); |
| 1621 | #endif /* DHD_DEBUG */ |
| 1622 | bcm_bprintf(strbuf, |
| 1623 | "clkstate %d activity %d idletime %d idlecount %d sleeping %d\n", |
| 1624 | bus->clkstate, bus->activity, bus->idletime, bus->idlecount, |
| 1625 | bus->sleeping); |
| 1626 | } |
| 1627 | |
| 1628 | void dhd_bus_clearcounts(dhd_pub_t *dhdp) |
| 1629 | { |
| 1630 | dhd_bus_t *bus = (dhd_bus_t *) dhdp->bus; |
| 1631 | |
| 1632 | bus->intrcount = bus->lastintrs = bus->spurious = bus->regfails = 0; |
| 1633 | bus->rxrtx = bus->rx_toolong = bus->rxc_errors = 0; |
| 1634 | bus->rx_hdrfail = bus->rx_badhdr = bus->rx_badseq = 0; |
| 1635 | bus->tx_sderrs = bus->fc_rcvd = bus->fc_xoff = bus->fc_xon = 0; |
| 1636 | bus->rxglomfail = bus->rxglomframes = bus->rxglompkts = 0; |
| 1637 | bus->f2rxhdrs = bus->f2rxdata = bus->f2txdata = bus->f1regdata = 0; |
| 1638 | } |
| 1639 | |
| 1640 | #ifdef SDTEST |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1641 | static int dhdsdio_pktgen_get(dhd_bus_t *bus, u8 *arg) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1642 | { |
| 1643 | dhd_pktgen_t pktgen; |
| 1644 | |
| 1645 | pktgen.version = DHD_PKTGEN_VERSION; |
| 1646 | pktgen.freq = bus->pktgen_freq; |
| 1647 | pktgen.count = bus->pktgen_count; |
| 1648 | pktgen.print = bus->pktgen_print; |
| 1649 | pktgen.total = bus->pktgen_total; |
| 1650 | pktgen.minlen = bus->pktgen_minlen; |
| 1651 | pktgen.maxlen = bus->pktgen_maxlen; |
| 1652 | pktgen.numsent = bus->pktgen_sent; |
| 1653 | pktgen.numrcvd = bus->pktgen_rcvd; |
| 1654 | pktgen.numfail = bus->pktgen_fail; |
| 1655 | pktgen.mode = bus->pktgen_mode; |
| 1656 | pktgen.stop = bus->pktgen_stop; |
| 1657 | |
| 1658 | bcopy(&pktgen, arg, sizeof(pktgen)); |
| 1659 | |
| 1660 | return 0; |
| 1661 | } |
| 1662 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1663 | static int dhdsdio_pktgen_set(dhd_bus_t *bus, u8 *arg) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1664 | { |
| 1665 | dhd_pktgen_t pktgen; |
| 1666 | uint oldcnt, oldmode; |
| 1667 | |
| 1668 | bcopy(arg, &pktgen, sizeof(pktgen)); |
| 1669 | if (pktgen.version != DHD_PKTGEN_VERSION) |
| 1670 | return BCME_BADARG; |
| 1671 | |
| 1672 | oldcnt = bus->pktgen_count; |
| 1673 | oldmode = bus->pktgen_mode; |
| 1674 | |
| 1675 | bus->pktgen_freq = pktgen.freq; |
| 1676 | bus->pktgen_count = pktgen.count; |
| 1677 | bus->pktgen_print = pktgen.print; |
| 1678 | bus->pktgen_total = pktgen.total; |
| 1679 | bus->pktgen_minlen = pktgen.minlen; |
| 1680 | bus->pktgen_maxlen = pktgen.maxlen; |
| 1681 | bus->pktgen_mode = pktgen.mode; |
| 1682 | bus->pktgen_stop = pktgen.stop; |
| 1683 | |
| 1684 | bus->pktgen_tick = bus->pktgen_ptick = 0; |
Greg Kroah-Hartman | 3ea2f4d | 2010-10-08 11:39:43 -0700 | [diff] [blame] | 1685 | bus->pktgen_len = max(bus->pktgen_len, bus->pktgen_minlen); |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 1686 | bus->pktgen_len = min(bus->pktgen_len, bus->pktgen_maxlen); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1687 | |
| 1688 | /* Clear counts for a new pktgen (mode change, or was stopped) */ |
| 1689 | if (bus->pktgen_count && (!oldcnt || oldmode != bus->pktgen_mode)) |
| 1690 | bus->pktgen_sent = bus->pktgen_rcvd = bus->pktgen_fail = 0; |
| 1691 | |
| 1692 | return 0; |
| 1693 | } |
| 1694 | #endif /* SDTEST */ |
| 1695 | |
| 1696 | static int |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1697 | dhdsdio_membytes(dhd_bus_t *bus, bool write, u32 address, u8 *data, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1698 | uint size) |
| 1699 | { |
| 1700 | int bcmerror = 0; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1701 | u32 sdaddr; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1702 | uint dsize; |
| 1703 | |
| 1704 | /* Determine initial transfer parameters */ |
| 1705 | sdaddr = address & SBSDIO_SB_OFT_ADDR_MASK; |
| 1706 | if ((sdaddr + size) & SBSDIO_SBWINDOW_MASK) |
| 1707 | dsize = (SBSDIO_SB_OFT_ADDR_LIMIT - sdaddr); |
| 1708 | else |
| 1709 | dsize = size; |
| 1710 | |
| 1711 | /* Set the backplane window to include the start address */ |
| 1712 | bcmerror = dhdsdio_set_siaddr_window(bus, address); |
| 1713 | if (bcmerror) { |
| 1714 | DHD_ERROR(("%s: window change failed\n", __func__)); |
| 1715 | goto xfer_done; |
| 1716 | } |
| 1717 | |
| 1718 | /* Do the transfer(s) */ |
| 1719 | while (size) { |
| 1720 | DHD_INFO(("%s: %s %d bytes at offset 0x%08x in window 0x%08x\n", |
| 1721 | __func__, (write ? "write" : "read"), dsize, |
| 1722 | sdaddr, (address & SBSDIO_SBWINDOW_MASK))); |
| 1723 | bcmerror = |
| 1724 | bcmsdh_rwdata(bus->sdh, write, sdaddr, data, dsize); |
| 1725 | if (bcmerror) { |
| 1726 | DHD_ERROR(("%s: membytes transfer failed\n", __func__)); |
| 1727 | break; |
| 1728 | } |
| 1729 | |
| 1730 | /* Adjust for next transfer (if any) */ |
| 1731 | size -= dsize; |
| 1732 | if (size) { |
| 1733 | data += dsize; |
| 1734 | address += dsize; |
| 1735 | bcmerror = dhdsdio_set_siaddr_window(bus, address); |
| 1736 | if (bcmerror) { |
| 1737 | DHD_ERROR(("%s: window change failed\n", |
| 1738 | __func__)); |
| 1739 | break; |
| 1740 | } |
| 1741 | sdaddr = 0; |
Greg Kroah-Hartman | b61640d | 2010-10-08 12:37:39 -0700 | [diff] [blame] | 1742 | dsize = min_t(uint, SBSDIO_SB_OFT_ADDR_LIMIT, size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1743 | } |
| 1744 | } |
| 1745 | |
| 1746 | xfer_done: |
| 1747 | /* Return the window to backplane enumeration space for core access */ |
| 1748 | if (dhdsdio_set_siaddr_window(bus, bcmsdh_cur_sbwad(bus->sdh))) { |
| 1749 | DHD_ERROR(("%s: FAILED to set window back to 0x%x\n", |
| 1750 | __func__, bcmsdh_cur_sbwad(bus->sdh))); |
| 1751 | } |
| 1752 | |
| 1753 | return bcmerror; |
| 1754 | } |
| 1755 | |
| 1756 | #ifdef DHD_DEBUG |
| 1757 | static int dhdsdio_readshared(dhd_bus_t *bus, sdpcm_shared_t *sh) |
| 1758 | { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1759 | u32 addr; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1760 | int rv; |
| 1761 | |
| 1762 | /* Read last word in memory to determine address of |
| 1763 | sdpcm_shared structure */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1764 | rv = dhdsdio_membytes(bus, false, bus->ramsize - 4, (u8 *)&addr, 4); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 1765 | if (rv < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1766 | return rv; |
| 1767 | |
| 1768 | addr = ltoh32(addr); |
| 1769 | |
| 1770 | DHD_INFO(("sdpcm_shared address 0x%08X\n", addr)); |
| 1771 | |
| 1772 | /* |
| 1773 | * Check if addr is valid. |
| 1774 | * NVRAM length at the end of memory should have been overwritten. |
| 1775 | */ |
| 1776 | if (addr == 0 || ((~addr >> 16) & 0xffff) == (addr & 0xffff)) { |
| 1777 | DHD_ERROR(("%s: address (0x%08x) of sdpcm_shared invalid\n", |
| 1778 | __func__, addr)); |
| 1779 | return BCME_ERROR; |
| 1780 | } |
| 1781 | |
| 1782 | /* Read hndrte_shared structure */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1783 | rv = dhdsdio_membytes(bus, false, addr, (u8 *) sh, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1784 | sizeof(sdpcm_shared_t)); |
| 1785 | if (rv < 0) |
| 1786 | return rv; |
| 1787 | |
| 1788 | /* Endianness */ |
| 1789 | sh->flags = ltoh32(sh->flags); |
| 1790 | sh->trap_addr = ltoh32(sh->trap_addr); |
| 1791 | sh->assert_exp_addr = ltoh32(sh->assert_exp_addr); |
| 1792 | sh->assert_file_addr = ltoh32(sh->assert_file_addr); |
| 1793 | sh->assert_line = ltoh32(sh->assert_line); |
| 1794 | sh->console_addr = ltoh32(sh->console_addr); |
| 1795 | sh->msgtrace_addr = ltoh32(sh->msgtrace_addr); |
| 1796 | |
| 1797 | if ((sh->flags & SDPCM_SHARED_VERSION_MASK) != SDPCM_SHARED_VERSION) { |
| 1798 | DHD_ERROR(("%s: sdpcm_shared version %d in dhd " |
| 1799 | "is different than sdpcm_shared version %d in dongle\n", |
| 1800 | __func__, SDPCM_SHARED_VERSION, |
| 1801 | sh->flags & SDPCM_SHARED_VERSION_MASK)); |
| 1802 | return BCME_ERROR; |
| 1803 | } |
| 1804 | |
| 1805 | return BCME_OK; |
| 1806 | } |
| 1807 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1808 | static int dhdsdio_checkdied(dhd_bus_t *bus, u8 *data, uint size) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1809 | { |
| 1810 | int bcmerror = 0; |
| 1811 | uint msize = 512; |
| 1812 | char *mbuffer = NULL; |
| 1813 | uint maxstrlen = 256; |
| 1814 | char *str = NULL; |
| 1815 | trap_t tr; |
| 1816 | sdpcm_shared_t sdpcm_shared; |
| 1817 | struct bcmstrbuf strbuf; |
| 1818 | |
| 1819 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 1820 | |
| 1821 | if (data == NULL) { |
| 1822 | /* |
| 1823 | * Called after a rx ctrl timeout. "data" is NULL. |
| 1824 | * allocate memory to trace the trap or assert. |
| 1825 | */ |
| 1826 | size = msize; |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 1827 | mbuffer = data = kmalloc(msize, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1828 | if (mbuffer == NULL) { |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 1829 | DHD_ERROR(("%s: kmalloc(%d) failed\n", __func__, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1830 | msize)); |
| 1831 | bcmerror = BCME_NOMEM; |
| 1832 | goto done; |
| 1833 | } |
| 1834 | } |
| 1835 | |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 1836 | str = kmalloc(maxstrlen, GFP_ATOMIC); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 1837 | if (str == NULL) { |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 1838 | DHD_ERROR(("%s: kmalloc(%d) failed\n", __func__, maxstrlen)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1839 | bcmerror = BCME_NOMEM; |
| 1840 | goto done; |
| 1841 | } |
| 1842 | |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 1843 | bcmerror = dhdsdio_readshared(bus, &sdpcm_shared); |
| 1844 | if (bcmerror < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1845 | goto done; |
| 1846 | |
| 1847 | bcm_binit(&strbuf, data, size); |
| 1848 | |
| 1849 | bcm_bprintf(&strbuf, |
| 1850 | "msgtrace address : 0x%08X\nconsole address : 0x%08X\n", |
| 1851 | sdpcm_shared.msgtrace_addr, sdpcm_shared.console_addr); |
| 1852 | |
| 1853 | if ((sdpcm_shared.flags & SDPCM_SHARED_ASSERT_BUILT) == 0) { |
| 1854 | /* NOTE: Misspelled assert is intentional - DO NOT FIX. |
| 1855 | * (Avoids conflict with real asserts for programmatic |
| 1856 | * parsing of output.) |
| 1857 | */ |
| 1858 | bcm_bprintf(&strbuf, "Assrt not built in dongle\n"); |
| 1859 | } |
| 1860 | |
| 1861 | if ((sdpcm_shared.flags & (SDPCM_SHARED_ASSERT | SDPCM_SHARED_TRAP)) == |
| 1862 | 0) { |
| 1863 | /* NOTE: Misspelled assert is intentional - DO NOT FIX. |
| 1864 | * (Avoids conflict with real asserts for programmatic |
| 1865 | * parsing of output.) |
| 1866 | */ |
| 1867 | bcm_bprintf(&strbuf, "No trap%s in dongle", |
| 1868 | (sdpcm_shared.flags & SDPCM_SHARED_ASSERT_BUILT) |
| 1869 | ? "/assrt" : ""); |
| 1870 | } else { |
| 1871 | if (sdpcm_shared.flags & SDPCM_SHARED_ASSERT) { |
| 1872 | /* Download assert */ |
| 1873 | bcm_bprintf(&strbuf, "Dongle assert"); |
| 1874 | if (sdpcm_shared.assert_exp_addr != 0) { |
| 1875 | str[0] = '\0'; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1876 | bcmerror = dhdsdio_membytes(bus, false, |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 1877 | sdpcm_shared.assert_exp_addr, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1878 | (u8 *) str, maxstrlen); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 1879 | if (bcmerror < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1880 | goto done; |
| 1881 | |
| 1882 | str[maxstrlen - 1] = '\0'; |
| 1883 | bcm_bprintf(&strbuf, " expr \"%s\"", str); |
| 1884 | } |
| 1885 | |
| 1886 | if (sdpcm_shared.assert_file_addr != 0) { |
| 1887 | str[0] = '\0'; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1888 | bcmerror = dhdsdio_membytes(bus, false, |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 1889 | sdpcm_shared.assert_file_addr, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1890 | (u8 *) str, maxstrlen); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 1891 | if (bcmerror < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1892 | goto done; |
| 1893 | |
| 1894 | str[maxstrlen - 1] = '\0'; |
| 1895 | bcm_bprintf(&strbuf, " file \"%s\"", str); |
| 1896 | } |
| 1897 | |
| 1898 | bcm_bprintf(&strbuf, " line %d ", |
| 1899 | sdpcm_shared.assert_line); |
| 1900 | } |
| 1901 | |
| 1902 | if (sdpcm_shared.flags & SDPCM_SHARED_TRAP) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1903 | bcmerror = dhdsdio_membytes(bus, false, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1904 | sdpcm_shared.trap_addr, (u8 *)&tr, |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 1905 | sizeof(trap_t)); |
| 1906 | if (bcmerror < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1907 | goto done; |
| 1908 | |
| 1909 | bcm_bprintf(&strbuf, |
| 1910 | "Dongle trap type 0x%x @ epc 0x%x, cpsr 0x%x, spsr 0x%x, sp 0x%x," |
| 1911 | "lp 0x%x, rpc 0x%x Trap offset 0x%x, " |
| 1912 | "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", |
| 1913 | tr.type, tr.epc, tr.cpsr, tr.spsr, tr.r13, |
| 1914 | tr.r14, tr.pc, sdpcm_shared.trap_addr, |
| 1915 | tr.r0, tr.r1, tr.r2, tr.r3, tr.r4, tr.r5, |
| 1916 | tr.r6, tr.r7); |
| 1917 | } |
| 1918 | } |
| 1919 | |
| 1920 | if (sdpcm_shared.flags & (SDPCM_SHARED_ASSERT | SDPCM_SHARED_TRAP)) |
| 1921 | DHD_ERROR(("%s: %s\n", __func__, strbuf.origbuf)); |
| 1922 | |
| 1923 | #ifdef DHD_DEBUG |
| 1924 | if (sdpcm_shared.flags & SDPCM_SHARED_TRAP) { |
| 1925 | /* Mem dump to a file on device */ |
| 1926 | dhdsdio_mem_dump(bus); |
| 1927 | } |
| 1928 | #endif /* DHD_DEBUG */ |
| 1929 | |
| 1930 | done: |
| 1931 | if (mbuffer) |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 1932 | kfree(mbuffer); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1933 | if (str) |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 1934 | kfree(str); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1935 | |
| 1936 | return bcmerror; |
| 1937 | } |
| 1938 | |
| 1939 | static int dhdsdio_mem_dump(dhd_bus_t *bus) |
| 1940 | { |
| 1941 | int ret = 0; |
| 1942 | int size; /* Full mem size */ |
| 1943 | int start = 0; /* Start address */ |
| 1944 | int read_size = 0; /* Read size of each iteration */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1945 | u8 *buf = NULL, *databuf = NULL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1946 | |
| 1947 | /* Get full mem size */ |
| 1948 | size = bus->ramsize; |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 1949 | buf = kmalloc(size, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1950 | if (!buf) { |
| 1951 | printf("%s: Out of memory (%d bytes)\n", __func__, size); |
| 1952 | return -1; |
| 1953 | } |
| 1954 | |
| 1955 | /* Read mem content */ |
| 1956 | printf("Dump dongle memory"); |
| 1957 | databuf = buf; |
| 1958 | while (size) { |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 1959 | read_size = min(MEMBLOCK, size); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1960 | ret = dhdsdio_membytes(bus, false, start, databuf, read_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1961 | if (ret) { |
| 1962 | printf("%s: Error membytes %d\n", __func__, ret); |
| 1963 | if (buf) |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 1964 | kfree(buf); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1965 | return -1; |
| 1966 | } |
| 1967 | printf("."); |
| 1968 | |
| 1969 | /* Decrement size and increment start address */ |
| 1970 | size -= read_size; |
| 1971 | start += read_size; |
| 1972 | databuf += read_size; |
| 1973 | } |
| 1974 | printf("Done\n"); |
| 1975 | |
| 1976 | /* free buf before return !!! */ |
| 1977 | if (write_to_file(bus->dhd, buf, bus->ramsize)) { |
| 1978 | printf("%s: Error writing to files\n", __func__); |
| 1979 | return -1; |
| 1980 | } |
| 1981 | |
| 1982 | /* buf free handled in write_to_file, not here */ |
| 1983 | return 0; |
| 1984 | } |
| 1985 | |
| 1986 | #define CONSOLE_LINE_MAX 192 |
| 1987 | |
| 1988 | static int dhdsdio_readconsole(dhd_bus_t *bus) |
| 1989 | { |
| 1990 | dhd_console_t *c = &bus->console; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1991 | u8 line[CONSOLE_LINE_MAX], ch; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1992 | u32 n, idx, addr; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1993 | int rv; |
| 1994 | |
| 1995 | /* Don't do anything until FWREADY updates console address */ |
| 1996 | if (bus->console_addr == 0) |
| 1997 | return 0; |
| 1998 | |
| 1999 | /* Read console log struct */ |
Greg Kroah-Hartman | ce0f1b8 | 2010-10-08 11:44:45 -0700 | [diff] [blame] | 2000 | addr = bus->console_addr + offsetof(hndrte_cons_t, log); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2001 | rv = dhdsdio_membytes(bus, false, addr, (u8 *)&c->log, |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2002 | sizeof(c->log)); |
| 2003 | if (rv < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2004 | return rv; |
| 2005 | |
| 2006 | /* Allocate console buffer (one time only) */ |
| 2007 | if (c->buf == NULL) { |
| 2008 | c->bufsize = ltoh32(c->log.buf_size); |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2009 | c->buf = kmalloc(c->bufsize, GFP_ATOMIC); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2010 | if (c->buf == NULL) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2011 | return BCME_NOMEM; |
| 2012 | } |
| 2013 | |
| 2014 | idx = ltoh32(c->log.idx); |
| 2015 | |
| 2016 | /* Protect against corrupt value */ |
| 2017 | if (idx > c->bufsize) |
| 2018 | return BCME_ERROR; |
| 2019 | |
| 2020 | /* Skip reading the console buffer if the index pointer |
| 2021 | has not moved */ |
| 2022 | if (idx == c->last) |
| 2023 | return BCME_OK; |
| 2024 | |
| 2025 | /* Read the console buffer */ |
| 2026 | addr = ltoh32(c->log.buf); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2027 | rv = dhdsdio_membytes(bus, false, addr, c->buf, c->bufsize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2028 | if (rv < 0) |
| 2029 | return rv; |
| 2030 | |
| 2031 | while (c->last != idx) { |
| 2032 | for (n = 0; n < CONSOLE_LINE_MAX - 2; n++) { |
| 2033 | if (c->last == idx) { |
| 2034 | /* This would output a partial line. |
| 2035 | * Instead, back up |
| 2036 | * the buffer pointer and output this |
| 2037 | * line next time around. |
| 2038 | */ |
| 2039 | if (c->last >= n) |
| 2040 | c->last -= n; |
| 2041 | else |
| 2042 | c->last = c->bufsize - n; |
| 2043 | goto break2; |
| 2044 | } |
| 2045 | ch = c->buf[c->last]; |
| 2046 | c->last = (c->last + 1) % c->bufsize; |
| 2047 | if (ch == '\n') |
| 2048 | break; |
| 2049 | line[n] = ch; |
| 2050 | } |
| 2051 | |
| 2052 | if (n > 0) { |
| 2053 | if (line[n - 1] == '\r') |
| 2054 | n--; |
| 2055 | line[n] = 0; |
| 2056 | printf("CONSOLE: %s\n", line); |
| 2057 | } |
| 2058 | } |
| 2059 | break2: |
| 2060 | |
| 2061 | return BCME_OK; |
| 2062 | } |
| 2063 | #endif /* DHD_DEBUG */ |
| 2064 | |
| 2065 | int dhdsdio_downloadvars(dhd_bus_t *bus, void *arg, int len) |
| 2066 | { |
| 2067 | int bcmerror = BCME_OK; |
| 2068 | |
| 2069 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 2070 | |
| 2071 | /* Basic sanity checks */ |
| 2072 | if (bus->dhd->up) { |
| 2073 | bcmerror = BCME_NOTDOWN; |
| 2074 | goto err; |
| 2075 | } |
| 2076 | if (!len) { |
| 2077 | bcmerror = BCME_BUFTOOSHORT; |
| 2078 | goto err; |
| 2079 | } |
| 2080 | |
| 2081 | /* Free the old ones and replace with passed variables */ |
| 2082 | if (bus->vars) |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 2083 | kfree(bus->vars); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2084 | |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2085 | bus->vars = kmalloc(len, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2086 | bus->varsz = bus->vars ? len : 0; |
| 2087 | if (bus->vars == NULL) { |
| 2088 | bcmerror = BCME_NOMEM; |
| 2089 | goto err; |
| 2090 | } |
| 2091 | |
| 2092 | /* Copy the passed variables, which should include the |
| 2093 | terminating double-null */ |
| 2094 | bcopy(arg, bus->vars, bus->varsz); |
| 2095 | err: |
| 2096 | return bcmerror; |
| 2097 | } |
| 2098 | |
| 2099 | static int |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2100 | dhdsdio_doiovar(dhd_bus_t *bus, const bcm_iovar_t *vi, u32 actionid, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2101 | const char *name, void *params, int plen, void *arg, int len, |
| 2102 | int val_size) |
| 2103 | { |
| 2104 | int bcmerror = 0; |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2105 | s32 int_val = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2106 | bool bool_val = 0; |
| 2107 | |
| 2108 | DHD_TRACE(("%s: Enter, action %d name %s params %p plen %d arg %p " |
| 2109 | "len %d val_size %d\n", |
| 2110 | __func__, actionid, name, params, plen, arg, len, val_size)); |
| 2111 | |
| 2112 | bcmerror = bcm_iovar_lencheck(vi, arg, len, IOV_ISSET(actionid)); |
| 2113 | if (bcmerror != 0) |
| 2114 | goto exit; |
| 2115 | |
| 2116 | if (plen >= (int)sizeof(int_val)) |
| 2117 | bcopy(params, &int_val, sizeof(int_val)); |
| 2118 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2119 | bool_val = (int_val != 0) ? true : false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2120 | |
| 2121 | /* Some ioctls use the bus */ |
| 2122 | dhd_os_sdlock(bus->dhd); |
| 2123 | |
| 2124 | /* Check if dongle is in reset. If so, only allow DEVRESET iovars */ |
| 2125 | if (bus->dhd->dongle_reset && !(actionid == IOV_SVAL(IOV_DEVRESET) || |
| 2126 | actionid == IOV_GVAL(IOV_DEVRESET))) { |
| 2127 | bcmerror = BCME_NOTREADY; |
| 2128 | goto exit; |
| 2129 | } |
| 2130 | |
| 2131 | /* Handle sleep stuff before any clock mucking */ |
| 2132 | if (vi->varid == IOV_SLEEP) { |
| 2133 | if (IOV_ISSET(actionid)) { |
| 2134 | bcmerror = dhdsdio_bussleep(bus, bool_val); |
| 2135 | } else { |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2136 | int_val = (s32) bus->sleeping; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2137 | bcopy(&int_val, arg, val_size); |
| 2138 | } |
| 2139 | goto exit; |
| 2140 | } |
| 2141 | |
| 2142 | /* Request clock to allow SDIO accesses */ |
| 2143 | if (!bus->dhd->dongle_reset) { |
| 2144 | BUS_WAKE(bus); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2145 | dhdsdio_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2146 | } |
| 2147 | |
| 2148 | switch (actionid) { |
| 2149 | case IOV_GVAL(IOV_INTR): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2150 | int_val = (s32) bus->intr; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2151 | bcopy(&int_val, arg, val_size); |
| 2152 | break; |
| 2153 | |
| 2154 | case IOV_SVAL(IOV_INTR): |
| 2155 | bus->intr = bool_val; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2156 | bus->intdis = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2157 | if (bus->dhd->up) { |
| 2158 | if (bus->intr) { |
| 2159 | DHD_INTR(("%s: enable SDIO device interrupts\n", |
| 2160 | __func__)); |
| 2161 | bcmsdh_intr_enable(bus->sdh); |
| 2162 | } else { |
| 2163 | DHD_INTR(("%s: disable SDIO interrupts\n", |
| 2164 | __func__)); |
| 2165 | bcmsdh_intr_disable(bus->sdh); |
| 2166 | } |
| 2167 | } |
| 2168 | break; |
| 2169 | |
| 2170 | case IOV_GVAL(IOV_POLLRATE): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2171 | int_val = (s32) bus->pollrate; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2172 | bcopy(&int_val, arg, val_size); |
| 2173 | break; |
| 2174 | |
| 2175 | case IOV_SVAL(IOV_POLLRATE): |
| 2176 | bus->pollrate = (uint) int_val; |
| 2177 | bus->poll = (bus->pollrate != 0); |
| 2178 | break; |
| 2179 | |
| 2180 | case IOV_GVAL(IOV_IDLETIME): |
| 2181 | int_val = bus->idletime; |
| 2182 | bcopy(&int_val, arg, val_size); |
| 2183 | break; |
| 2184 | |
| 2185 | case IOV_SVAL(IOV_IDLETIME): |
| 2186 | if ((int_val < 0) && (int_val != DHD_IDLE_IMMEDIATE)) |
| 2187 | bcmerror = BCME_BADARG; |
| 2188 | else |
| 2189 | bus->idletime = int_val; |
| 2190 | break; |
| 2191 | |
| 2192 | case IOV_GVAL(IOV_IDLECLOCK): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2193 | int_val = (s32) bus->idleclock; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2194 | bcopy(&int_val, arg, val_size); |
| 2195 | break; |
| 2196 | |
| 2197 | case IOV_SVAL(IOV_IDLECLOCK): |
| 2198 | bus->idleclock = int_val; |
| 2199 | break; |
| 2200 | |
| 2201 | case IOV_GVAL(IOV_SD1IDLE): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2202 | int_val = (s32) sd1idle; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2203 | bcopy(&int_val, arg, val_size); |
| 2204 | break; |
| 2205 | |
| 2206 | case IOV_SVAL(IOV_SD1IDLE): |
| 2207 | sd1idle = bool_val; |
| 2208 | break; |
| 2209 | |
| 2210 | case IOV_SVAL(IOV_MEMBYTES): |
| 2211 | case IOV_GVAL(IOV_MEMBYTES): |
| 2212 | { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2213 | u32 address; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2214 | uint size, dsize; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2215 | u8 *data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2216 | |
| 2217 | bool set = (actionid == IOV_SVAL(IOV_MEMBYTES)); |
| 2218 | |
| 2219 | ASSERT(plen >= 2 * sizeof(int)); |
| 2220 | |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2221 | address = (u32) int_val; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2222 | bcopy((char *)params + sizeof(int_val), &int_val, |
| 2223 | sizeof(int_val)); |
| 2224 | size = (uint) int_val; |
| 2225 | |
| 2226 | /* Do some validation */ |
| 2227 | dsize = set ? plen - (2 * sizeof(int)) : len; |
| 2228 | if (dsize < size) { |
| 2229 | DHD_ERROR(("%s: error on %s membytes, addr " |
| 2230 | "0x%08x size %d dsize %d\n", |
| 2231 | __func__, (set ? "set" : "get"), |
| 2232 | address, size, dsize)); |
| 2233 | bcmerror = BCME_BADARG; |
| 2234 | break; |
| 2235 | } |
| 2236 | |
| 2237 | DHD_INFO(("%s: Request to %s %d bytes at address " |
| 2238 | "0x%08x\n", |
| 2239 | __func__, (set ? "write" : "read"), size, address)); |
| 2240 | |
| 2241 | /* If we know about SOCRAM, check for a fit */ |
| 2242 | if ((bus->orig_ramsize) && |
| 2243 | ((address > bus->orig_ramsize) |
| 2244 | || (address + size > bus->orig_ramsize))) { |
| 2245 | DHD_ERROR(("%s: ramsize 0x%08x doesn't have %d " |
| 2246 | "bytes at 0x%08x\n", |
| 2247 | __func__, bus->orig_ramsize, size, address)); |
| 2248 | bcmerror = BCME_BADARG; |
| 2249 | break; |
| 2250 | } |
| 2251 | |
| 2252 | /* Generate the actual data pointer */ |
| 2253 | data = |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2254 | set ? (u8 *) params + |
| 2255 | 2 * sizeof(int) : (u8 *) arg; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2256 | |
| 2257 | /* Call to do the transfer */ |
| 2258 | bcmerror = |
| 2259 | dhdsdio_membytes(bus, set, address, data, size); |
| 2260 | |
| 2261 | break; |
| 2262 | } |
| 2263 | |
| 2264 | case IOV_GVAL(IOV_MEMSIZE): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2265 | int_val = (s32) bus->ramsize; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2266 | bcopy(&int_val, arg, val_size); |
| 2267 | break; |
| 2268 | |
| 2269 | case IOV_GVAL(IOV_SDIOD_DRIVE): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2270 | int_val = (s32) dhd_sdiod_drive_strength; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2271 | bcopy(&int_val, arg, val_size); |
| 2272 | break; |
| 2273 | |
| 2274 | case IOV_SVAL(IOV_SDIOD_DRIVE): |
| 2275 | dhd_sdiod_drive_strength = int_val; |
| 2276 | si_sdiod_drive_strength_init(bus->sih, bus->dhd->osh, |
| 2277 | dhd_sdiod_drive_strength); |
| 2278 | break; |
| 2279 | |
| 2280 | case IOV_SVAL(IOV_DOWNLOAD): |
| 2281 | bcmerror = dhdsdio_download_state(bus, bool_val); |
| 2282 | break; |
| 2283 | |
| 2284 | case IOV_SVAL(IOV_VARS): |
| 2285 | bcmerror = dhdsdio_downloadvars(bus, arg, len); |
| 2286 | break; |
| 2287 | |
| 2288 | case IOV_GVAL(IOV_READAHEAD): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2289 | int_val = (s32) dhd_readahead; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2290 | bcopy(&int_val, arg, val_size); |
| 2291 | break; |
| 2292 | |
| 2293 | case IOV_SVAL(IOV_READAHEAD): |
| 2294 | if (bool_val && !dhd_readahead) |
| 2295 | bus->nextlen = 0; |
| 2296 | dhd_readahead = bool_val; |
| 2297 | break; |
| 2298 | |
| 2299 | case IOV_GVAL(IOV_SDRXCHAIN): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2300 | int_val = (s32) bus->use_rxchain; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2301 | bcopy(&int_val, arg, val_size); |
| 2302 | break; |
| 2303 | |
| 2304 | case IOV_SVAL(IOV_SDRXCHAIN): |
| 2305 | if (bool_val && !bus->sd_rxchain) |
| 2306 | bcmerror = BCME_UNSUPPORTED; |
| 2307 | else |
| 2308 | bus->use_rxchain = bool_val; |
| 2309 | break; |
| 2310 | case IOV_GVAL(IOV_ALIGNCTL): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2311 | int_val = (s32) dhd_alignctl; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2312 | bcopy(&int_val, arg, val_size); |
| 2313 | break; |
| 2314 | |
| 2315 | case IOV_SVAL(IOV_ALIGNCTL): |
| 2316 | dhd_alignctl = bool_val; |
| 2317 | break; |
| 2318 | |
| 2319 | case IOV_GVAL(IOV_SDALIGN): |
| 2320 | int_val = DHD_SDALIGN; |
| 2321 | bcopy(&int_val, arg, val_size); |
| 2322 | break; |
| 2323 | |
| 2324 | #ifdef DHD_DEBUG |
| 2325 | case IOV_GVAL(IOV_VARS): |
| 2326 | if (bus->varsz < (uint) len) |
| 2327 | bcopy(bus->vars, arg, bus->varsz); |
| 2328 | else |
| 2329 | bcmerror = BCME_BUFTOOSHORT; |
| 2330 | break; |
| 2331 | #endif /* DHD_DEBUG */ |
| 2332 | |
| 2333 | #ifdef DHD_DEBUG |
| 2334 | case IOV_GVAL(IOV_SDREG): |
| 2335 | { |
| 2336 | sdreg_t *sd_ptr; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2337 | u32 addr, size; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2338 | |
| 2339 | sd_ptr = (sdreg_t *) params; |
| 2340 | |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 2341 | addr = (unsigned long)bus->regs + sd_ptr->offset; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2342 | size = sd_ptr->func; |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2343 | int_val = (s32) bcmsdh_reg_read(bus->sdh, addr, size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2344 | if (bcmsdh_regfail(bus->sdh)) |
| 2345 | bcmerror = BCME_SDIO_ERROR; |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2346 | bcopy(&int_val, arg, sizeof(s32)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2347 | break; |
| 2348 | } |
| 2349 | |
| 2350 | case IOV_SVAL(IOV_SDREG): |
| 2351 | { |
| 2352 | sdreg_t *sd_ptr; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2353 | u32 addr, size; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2354 | |
| 2355 | sd_ptr = (sdreg_t *) params; |
| 2356 | |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 2357 | addr = (unsigned long)bus->regs + sd_ptr->offset; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2358 | size = sd_ptr->func; |
| 2359 | bcmsdh_reg_write(bus->sdh, addr, size, sd_ptr->value); |
| 2360 | if (bcmsdh_regfail(bus->sdh)) |
| 2361 | bcmerror = BCME_SDIO_ERROR; |
| 2362 | break; |
| 2363 | } |
| 2364 | |
| 2365 | /* Same as above, but offset is not backplane |
| 2366 | (not SDIO core) */ |
| 2367 | case IOV_GVAL(IOV_SBREG): |
| 2368 | { |
| 2369 | sdreg_t sdreg; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2370 | u32 addr, size; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2371 | |
| 2372 | bcopy(params, &sdreg, sizeof(sdreg)); |
| 2373 | |
| 2374 | addr = SI_ENUM_BASE + sdreg.offset; |
| 2375 | size = sdreg.func; |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2376 | int_val = (s32) bcmsdh_reg_read(bus->sdh, addr, size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2377 | if (bcmsdh_regfail(bus->sdh)) |
| 2378 | bcmerror = BCME_SDIO_ERROR; |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2379 | bcopy(&int_val, arg, sizeof(s32)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2380 | break; |
| 2381 | } |
| 2382 | |
| 2383 | case IOV_SVAL(IOV_SBREG): |
| 2384 | { |
| 2385 | sdreg_t sdreg; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2386 | u32 addr, size; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2387 | |
| 2388 | bcopy(params, &sdreg, sizeof(sdreg)); |
| 2389 | |
| 2390 | addr = SI_ENUM_BASE + sdreg.offset; |
| 2391 | size = sdreg.func; |
| 2392 | bcmsdh_reg_write(bus->sdh, addr, size, sdreg.value); |
| 2393 | if (bcmsdh_regfail(bus->sdh)) |
| 2394 | bcmerror = BCME_SDIO_ERROR; |
| 2395 | break; |
| 2396 | } |
| 2397 | |
| 2398 | case IOV_GVAL(IOV_SDCIS): |
| 2399 | { |
| 2400 | *(char *)arg = 0; |
| 2401 | |
nohee ko | ea3b8a2 | 2010-10-09 10:34:38 -0700 | [diff] [blame] | 2402 | strcat(arg, "\nFunc 0\n"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2403 | bcmsdh_cis_read(bus->sdh, 0x10, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2404 | (u8 *) arg + strlen(arg), |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2405 | SBSDIO_CIS_SIZE_LIMIT); |
nohee ko | ea3b8a2 | 2010-10-09 10:34:38 -0700 | [diff] [blame] | 2406 | strcat(arg, "\nFunc 1\n"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2407 | bcmsdh_cis_read(bus->sdh, 0x11, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2408 | (u8 *) arg + strlen(arg), |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2409 | SBSDIO_CIS_SIZE_LIMIT); |
nohee ko | ea3b8a2 | 2010-10-09 10:34:38 -0700 | [diff] [blame] | 2410 | strcat(arg, "\nFunc 2\n"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2411 | bcmsdh_cis_read(bus->sdh, 0x12, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2412 | (u8 *) arg + strlen(arg), |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2413 | SBSDIO_CIS_SIZE_LIMIT); |
| 2414 | break; |
| 2415 | } |
| 2416 | |
| 2417 | case IOV_GVAL(IOV_FORCEEVEN): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2418 | int_val = (s32) forcealign; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2419 | bcopy(&int_val, arg, val_size); |
| 2420 | break; |
| 2421 | |
| 2422 | case IOV_SVAL(IOV_FORCEEVEN): |
| 2423 | forcealign = bool_val; |
| 2424 | break; |
| 2425 | |
| 2426 | case IOV_GVAL(IOV_TXBOUND): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2427 | int_val = (s32) dhd_txbound; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2428 | bcopy(&int_val, arg, val_size); |
| 2429 | break; |
| 2430 | |
| 2431 | case IOV_SVAL(IOV_TXBOUND): |
| 2432 | dhd_txbound = (uint) int_val; |
| 2433 | break; |
| 2434 | |
| 2435 | case IOV_GVAL(IOV_RXBOUND): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2436 | int_val = (s32) dhd_rxbound; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2437 | bcopy(&int_val, arg, val_size); |
| 2438 | break; |
| 2439 | |
| 2440 | case IOV_SVAL(IOV_RXBOUND): |
| 2441 | dhd_rxbound = (uint) int_val; |
| 2442 | break; |
| 2443 | |
| 2444 | case IOV_GVAL(IOV_TXMINMAX): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2445 | int_val = (s32) dhd_txminmax; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2446 | bcopy(&int_val, arg, val_size); |
| 2447 | break; |
| 2448 | |
| 2449 | case IOV_SVAL(IOV_TXMINMAX): |
| 2450 | dhd_txminmax = (uint) int_val; |
| 2451 | break; |
| 2452 | #endif /* DHD_DEBUG */ |
| 2453 | |
| 2454 | #ifdef SDTEST |
| 2455 | case IOV_GVAL(IOV_EXTLOOP): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2456 | int_val = (s32) bus->ext_loop; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2457 | bcopy(&int_val, arg, val_size); |
| 2458 | break; |
| 2459 | |
| 2460 | case IOV_SVAL(IOV_EXTLOOP): |
| 2461 | bus->ext_loop = bool_val; |
| 2462 | break; |
| 2463 | |
| 2464 | case IOV_GVAL(IOV_PKTGEN): |
| 2465 | bcmerror = dhdsdio_pktgen_get(bus, arg); |
| 2466 | break; |
| 2467 | |
| 2468 | case IOV_SVAL(IOV_PKTGEN): |
| 2469 | bcmerror = dhdsdio_pktgen_set(bus, arg); |
| 2470 | break; |
| 2471 | #endif /* SDTEST */ |
| 2472 | |
| 2473 | case IOV_SVAL(IOV_DEVRESET): |
| 2474 | DHD_TRACE(("%s: Called set IOV_DEVRESET=%d dongle_reset=%d " |
| 2475 | "busstate=%d\n", |
| 2476 | __func__, bool_val, bus->dhd->dongle_reset, |
| 2477 | bus->dhd->busstate)); |
| 2478 | |
| 2479 | ASSERT(bus->dhd->osh); |
| 2480 | /* ASSERT(bus->cl_devid); */ |
| 2481 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2482 | dhd_bus_devreset(bus->dhd, (u8) bool_val); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2483 | |
| 2484 | break; |
| 2485 | |
| 2486 | case IOV_GVAL(IOV_DEVRESET): |
| 2487 | DHD_TRACE(("%s: Called get IOV_DEVRESET\n", __func__)); |
| 2488 | |
| 2489 | /* Get its status */ |
| 2490 | int_val = (bool) bus->dhd->dongle_reset; |
| 2491 | bcopy(&int_val, arg, val_size); |
| 2492 | |
| 2493 | break; |
| 2494 | |
| 2495 | default: |
| 2496 | bcmerror = BCME_UNSUPPORTED; |
| 2497 | break; |
| 2498 | } |
| 2499 | |
| 2500 | exit: |
| 2501 | if ((bus->idletime == DHD_IDLE_IMMEDIATE) && !bus->dpc_sched) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2502 | bus->activity = false; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2503 | dhdsdio_clkctl(bus, CLK_NONE, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2504 | } |
| 2505 | |
| 2506 | dhd_os_sdunlock(bus->dhd); |
| 2507 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2508 | if (actionid == IOV_SVAL(IOV_DEVRESET) && bool_val == false) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2509 | dhd_preinit_ioctls((dhd_pub_t *) bus->dhd); |
| 2510 | |
| 2511 | return bcmerror; |
| 2512 | } |
| 2513 | |
| 2514 | static int dhdsdio_write_vars(dhd_bus_t *bus) |
| 2515 | { |
| 2516 | int bcmerror = 0; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2517 | u32 varsize; |
| 2518 | u32 varaddr; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2519 | u8 *vbuffer; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2520 | u32 varsizew; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2521 | #ifdef DHD_DEBUG |
| 2522 | char *nvram_ularray; |
| 2523 | #endif /* DHD_DEBUG */ |
| 2524 | |
| 2525 | /* Even if there are no vars are to be written, we still |
| 2526 | need to set the ramsize. */ |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 2527 | varsize = bus->varsz ? roundup(bus->varsz, 4) : 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2528 | varaddr = (bus->ramsize - 4) - varsize; |
| 2529 | |
| 2530 | if (bus->vars) { |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2531 | vbuffer = kmalloc(varsize, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2532 | if (!vbuffer) |
| 2533 | return BCME_NOMEM; |
| 2534 | |
| 2535 | bzero(vbuffer, varsize); |
| 2536 | bcopy(bus->vars, vbuffer, bus->varsz); |
| 2537 | |
| 2538 | /* Write the vars list */ |
| 2539 | bcmerror = |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2540 | dhdsdio_membytes(bus, true, varaddr, vbuffer, varsize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2541 | #ifdef DHD_DEBUG |
| 2542 | /* Verify NVRAM bytes */ |
| 2543 | DHD_INFO(("Compare NVRAM dl & ul; varsize=%d\n", varsize)); |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2544 | nvram_ularray = kmalloc(varsize, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2545 | if (!nvram_ularray) |
| 2546 | return BCME_NOMEM; |
| 2547 | |
| 2548 | /* Upload image to verify downloaded contents. */ |
| 2549 | memset(nvram_ularray, 0xaa, varsize); |
| 2550 | |
| 2551 | /* Read the vars list to temp buffer for comparison */ |
| 2552 | bcmerror = |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2553 | dhdsdio_membytes(bus, false, varaddr, nvram_ularray, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2554 | varsize); |
| 2555 | if (bcmerror) { |
| 2556 | DHD_ERROR(("%s: error %d on reading %d nvram bytes at " |
| 2557 | "0x%08x\n", __func__, bcmerror, varsize, varaddr)); |
| 2558 | } |
| 2559 | /* Compare the org NVRAM with the one read from RAM */ |
| 2560 | if (memcmp(vbuffer, nvram_ularray, varsize)) { |
| 2561 | DHD_ERROR(("%s: Downloaded NVRAM image is corrupted.\n", |
| 2562 | __func__)); |
| 2563 | } else |
| 2564 | DHD_ERROR(("%s: Download/Upload/Compare of NVRAM ok.\n", |
| 2565 | __func__)); |
| 2566 | |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 2567 | kfree(nvram_ularray); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2568 | #endif /* DHD_DEBUG */ |
| 2569 | |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 2570 | kfree(vbuffer); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2571 | } |
| 2572 | |
| 2573 | /* adjust to the user specified RAM */ |
| 2574 | DHD_INFO(("Physical memory size: %d, usable memory size: %d\n", |
| 2575 | bus->orig_ramsize, bus->ramsize)); |
| 2576 | DHD_INFO(("Vars are at %d, orig varsize is %d\n", varaddr, varsize)); |
| 2577 | varsize = ((bus->orig_ramsize - 4) - varaddr); |
| 2578 | |
| 2579 | /* |
| 2580 | * Determine the length token: |
| 2581 | * Varsize, converted to words, in lower 16-bits, checksum |
| 2582 | * in upper 16-bits. |
| 2583 | */ |
| 2584 | if (bcmerror) { |
| 2585 | varsizew = 0; |
| 2586 | } else { |
| 2587 | varsizew = varsize / 4; |
| 2588 | varsizew = (~varsizew << 16) | (varsizew & 0x0000FFFF); |
| 2589 | varsizew = htol32(varsizew); |
| 2590 | } |
| 2591 | |
| 2592 | DHD_INFO(("New varsize is %d, length token=0x%08x\n", varsize, |
| 2593 | varsizew)); |
| 2594 | |
| 2595 | /* Write the length token to the last word */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2596 | bcmerror = dhdsdio_membytes(bus, true, (bus->orig_ramsize - 4), |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2597 | (u8 *)&varsizew, 4); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2598 | |
| 2599 | return bcmerror; |
| 2600 | } |
| 2601 | |
| 2602 | static int dhdsdio_download_state(dhd_bus_t *bus, bool enter) |
| 2603 | { |
| 2604 | uint retries; |
| 2605 | int bcmerror = 0; |
| 2606 | |
| 2607 | /* To enter download state, disable ARM and reset SOCRAM. |
| 2608 | * To exit download state, simply reset ARM (default is RAM boot). |
| 2609 | */ |
| 2610 | if (enter) { |
| 2611 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2612 | bus->alp_only = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2613 | |
| 2614 | if (!(si_setcore(bus->sih, ARM7S_CORE_ID, 0)) && |
| 2615 | !(si_setcore(bus->sih, ARMCM3_CORE_ID, 0))) { |
| 2616 | DHD_ERROR(("%s: Failed to find ARM core!\n", __func__)); |
| 2617 | bcmerror = BCME_ERROR; |
| 2618 | goto fail; |
| 2619 | } |
| 2620 | |
| 2621 | si_core_disable(bus->sih, 0); |
| 2622 | if (bcmsdh_regfail(bus->sdh)) { |
| 2623 | bcmerror = BCME_SDIO_ERROR; |
| 2624 | goto fail; |
| 2625 | } |
| 2626 | |
| 2627 | if (!(si_setcore(bus->sih, SOCRAM_CORE_ID, 0))) { |
| 2628 | DHD_ERROR(("%s: Failed to find SOCRAM core!\n", |
| 2629 | __func__)); |
| 2630 | bcmerror = BCME_ERROR; |
| 2631 | goto fail; |
| 2632 | } |
| 2633 | |
| 2634 | si_core_reset(bus->sih, 0, 0); |
| 2635 | if (bcmsdh_regfail(bus->sdh)) { |
| 2636 | DHD_ERROR(("%s: Failure trying reset SOCRAM core?\n", |
| 2637 | __func__)); |
| 2638 | bcmerror = BCME_SDIO_ERROR; |
| 2639 | goto fail; |
| 2640 | } |
| 2641 | |
| 2642 | /* Clear the top bit of memory */ |
| 2643 | if (bus->ramsize) { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2644 | u32 zeros = 0; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2645 | dhdsdio_membytes(bus, true, bus->ramsize - 4, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2646 | (u8 *)&zeros, 4); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2647 | } |
| 2648 | } else { |
| 2649 | if (!(si_setcore(bus->sih, SOCRAM_CORE_ID, 0))) { |
| 2650 | DHD_ERROR(("%s: Failed to find SOCRAM core!\n", |
| 2651 | __func__)); |
| 2652 | bcmerror = BCME_ERROR; |
| 2653 | goto fail; |
| 2654 | } |
| 2655 | |
| 2656 | if (!si_iscoreup(bus->sih)) { |
| 2657 | DHD_ERROR(("%s: SOCRAM core is down after reset?\n", |
| 2658 | __func__)); |
| 2659 | bcmerror = BCME_ERROR; |
| 2660 | goto fail; |
| 2661 | } |
| 2662 | |
| 2663 | bcmerror = dhdsdio_write_vars(bus); |
| 2664 | if (bcmerror) { |
| 2665 | DHD_ERROR(("%s: no vars written to RAM\n", __func__)); |
| 2666 | bcmerror = 0; |
| 2667 | } |
| 2668 | |
| 2669 | if (!si_setcore(bus->sih, PCMCIA_CORE_ID, 0) && |
| 2670 | !si_setcore(bus->sih, SDIOD_CORE_ID, 0)) { |
| 2671 | DHD_ERROR(("%s: Can't change back to SDIO core?\n", |
| 2672 | __func__)); |
| 2673 | bcmerror = BCME_ERROR; |
| 2674 | goto fail; |
| 2675 | } |
| 2676 | W_SDREG(0xFFFFFFFF, &bus->regs->intstatus, retries); |
| 2677 | |
| 2678 | if (!(si_setcore(bus->sih, ARM7S_CORE_ID, 0)) && |
| 2679 | !(si_setcore(bus->sih, ARMCM3_CORE_ID, 0))) { |
| 2680 | DHD_ERROR(("%s: Failed to find ARM core!\n", __func__)); |
| 2681 | bcmerror = BCME_ERROR; |
| 2682 | goto fail; |
| 2683 | } |
| 2684 | |
| 2685 | si_core_reset(bus->sih, 0, 0); |
| 2686 | if (bcmsdh_regfail(bus->sdh)) { |
| 2687 | DHD_ERROR(("%s: Failure trying to reset ARM core?\n", |
| 2688 | __func__)); |
| 2689 | bcmerror = BCME_SDIO_ERROR; |
| 2690 | goto fail; |
| 2691 | } |
| 2692 | |
| 2693 | /* Allow HT Clock now that the ARM is running. */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2694 | bus->alp_only = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2695 | |
| 2696 | bus->dhd->busstate = DHD_BUS_LOAD; |
| 2697 | } |
| 2698 | |
| 2699 | fail: |
| 2700 | /* Always return to SDIOD core */ |
| 2701 | if (!si_setcore(bus->sih, PCMCIA_CORE_ID, 0)) |
| 2702 | si_setcore(bus->sih, SDIOD_CORE_ID, 0); |
| 2703 | |
| 2704 | return bcmerror; |
| 2705 | } |
| 2706 | |
| 2707 | int |
| 2708 | dhd_bus_iovar_op(dhd_pub_t *dhdp, const char *name, |
| 2709 | void *params, int plen, void *arg, int len, bool set) |
| 2710 | { |
| 2711 | dhd_bus_t *bus = dhdp->bus; |
| 2712 | const bcm_iovar_t *vi = NULL; |
| 2713 | int bcmerror = 0; |
| 2714 | int val_size; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2715 | u32 actionid; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2716 | |
| 2717 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 2718 | |
| 2719 | ASSERT(name); |
| 2720 | ASSERT(len >= 0); |
| 2721 | |
| 2722 | /* Get MUST have return space */ |
| 2723 | ASSERT(set || (arg && len)); |
| 2724 | |
| 2725 | /* Set does NOT take qualifiers */ |
| 2726 | ASSERT(!set || (!params && !plen)); |
| 2727 | |
| 2728 | /* Look up var locally; if not found pass to host driver */ |
| 2729 | vi = bcm_iovar_lookup(dhdsdio_iovars, name); |
| 2730 | if (vi == NULL) { |
| 2731 | dhd_os_sdlock(bus->dhd); |
| 2732 | |
| 2733 | BUS_WAKE(bus); |
| 2734 | |
| 2735 | /* Turn on clock in case SD command needs backplane */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2736 | dhdsdio_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2737 | |
| 2738 | bcmerror = |
| 2739 | bcmsdh_iovar_op(bus->sdh, name, params, plen, arg, len, |
| 2740 | set); |
| 2741 | |
| 2742 | /* Check for bus configuration changes of interest */ |
| 2743 | |
| 2744 | /* If it was divisor change, read the new one */ |
| 2745 | if (set && strcmp(name, "sd_divisor") == 0) { |
| 2746 | if (bcmsdh_iovar_op(bus->sdh, "sd_divisor", NULL, 0, |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2747 | &bus->sd_divisor, sizeof(s32), |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2748 | false) != BCME_OK) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2749 | bus->sd_divisor = -1; |
| 2750 | DHD_ERROR(("%s: fail on %s get\n", __func__, |
| 2751 | name)); |
| 2752 | } else { |
| 2753 | DHD_INFO(("%s: noted %s update, value now %d\n", |
| 2754 | __func__, name, bus->sd_divisor)); |
| 2755 | } |
| 2756 | } |
| 2757 | /* If it was a mode change, read the new one */ |
| 2758 | if (set && strcmp(name, "sd_mode") == 0) { |
| 2759 | if (bcmsdh_iovar_op(bus->sdh, "sd_mode", NULL, 0, |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2760 | &bus->sd_mode, sizeof(s32), |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2761 | false) != BCME_OK) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2762 | bus->sd_mode = -1; |
| 2763 | DHD_ERROR(("%s: fail on %s get\n", __func__, |
| 2764 | name)); |
| 2765 | } else { |
| 2766 | DHD_INFO(("%s: noted %s update, value now %d\n", |
| 2767 | __func__, name, bus->sd_mode)); |
| 2768 | } |
| 2769 | } |
| 2770 | /* Similar check for blocksize change */ |
| 2771 | if (set && strcmp(name, "sd_blocksize") == 0) { |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2772 | s32 fnum = 2; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2773 | if (bcmsdh_iovar_op |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2774 | (bus->sdh, "sd_blocksize", &fnum, sizeof(s32), |
| 2775 | &bus->blocksize, sizeof(s32), |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2776 | false) != BCME_OK) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2777 | bus->blocksize = 0; |
| 2778 | DHD_ERROR(("%s: fail on %s get\n", __func__, |
| 2779 | "sd_blocksize")); |
| 2780 | } else { |
| 2781 | DHD_INFO(("%s: noted %s update, value now %d\n", |
| 2782 | __func__, "sd_blocksize", |
| 2783 | bus->blocksize)); |
| 2784 | } |
| 2785 | } |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 2786 | bus->roundup = min(max_roundup, bus->blocksize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2787 | |
| 2788 | if ((bus->idletime == DHD_IDLE_IMMEDIATE) && !bus->dpc_sched) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2789 | bus->activity = false; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2790 | dhdsdio_clkctl(bus, CLK_NONE, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2791 | } |
| 2792 | |
| 2793 | dhd_os_sdunlock(bus->dhd); |
| 2794 | goto exit; |
| 2795 | } |
| 2796 | |
| 2797 | DHD_CTL(("%s: %s %s, len %d plen %d\n", __func__, |
| 2798 | name, (set ? "set" : "get"), len, plen)); |
| 2799 | |
| 2800 | /* set up 'params' pointer in case this is a set command so that |
| 2801 | * the convenience int and bool code can be common to set and get |
| 2802 | */ |
| 2803 | if (params == NULL) { |
| 2804 | params = arg; |
| 2805 | plen = len; |
| 2806 | } |
| 2807 | |
| 2808 | if (vi->type == IOVT_VOID) |
| 2809 | val_size = 0; |
| 2810 | else if (vi->type == IOVT_BUFFER) |
| 2811 | val_size = len; |
| 2812 | else |
| 2813 | /* all other types are integer sized */ |
| 2814 | val_size = sizeof(int); |
| 2815 | |
| 2816 | actionid = set ? IOV_SVAL(vi->varid) : IOV_GVAL(vi->varid); |
| 2817 | bcmerror = |
| 2818 | dhdsdio_doiovar(bus, vi, actionid, name, params, plen, arg, len, |
| 2819 | val_size); |
| 2820 | |
| 2821 | exit: |
| 2822 | return bcmerror; |
| 2823 | } |
| 2824 | |
| 2825 | void dhd_bus_stop(struct dhd_bus *bus, bool enforce_mutex) |
| 2826 | { |
| 2827 | osl_t *osh = bus->dhd->osh; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2828 | u32 local_hostintmask; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2829 | u8 saveclk; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2830 | uint retries; |
| 2831 | int err; |
| 2832 | |
| 2833 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 2834 | |
| 2835 | if (enforce_mutex) |
| 2836 | dhd_os_sdlock(bus->dhd); |
| 2837 | |
| 2838 | BUS_WAKE(bus); |
| 2839 | |
| 2840 | /* Enable clock for device interrupts */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2841 | dhdsdio_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2842 | |
| 2843 | /* Disable and clear interrupts at the chip level also */ |
| 2844 | W_SDREG(0, &bus->regs->hostintmask, retries); |
| 2845 | local_hostintmask = bus->hostintmask; |
| 2846 | bus->hostintmask = 0; |
| 2847 | |
| 2848 | /* Change our idea of bus state */ |
| 2849 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 2850 | |
| 2851 | /* Force clocks on backplane to be sure F2 interrupt propagates */ |
| 2852 | saveclk = |
| 2853 | bcmsdh_cfg_read(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 2854 | &err); |
| 2855 | if (!err) { |
| 2856 | bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 2857 | (saveclk | SBSDIO_FORCE_HT), &err); |
| 2858 | } |
| 2859 | if (err) { |
| 2860 | DHD_ERROR(("%s: Failed to force clock for F2: err %d\n", |
| 2861 | __func__, err)); |
| 2862 | } |
| 2863 | |
| 2864 | /* Turn off the bus (F2), free any pending packets */ |
| 2865 | DHD_INTR(("%s: disable SDIO interrupts\n", __func__)); |
| 2866 | bcmsdh_intr_disable(bus->sdh); |
| 2867 | bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_0, SDIOD_CCCR_IOEN, |
| 2868 | SDIO_FUNC_ENABLE_1, NULL); |
| 2869 | |
| 2870 | /* Clear any pending interrupts now that F2 is disabled */ |
| 2871 | W_SDREG(local_hostintmask, &bus->regs->intstatus, retries); |
| 2872 | |
| 2873 | /* Turn off the backplane clock (only) */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2874 | dhdsdio_clkctl(bus, CLK_SDONLY, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2875 | |
| 2876 | /* Clear the data packet queues */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2877 | pktq_flush(osh, &bus->txq, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2878 | |
| 2879 | /* Clear any held glomming stuff */ |
| 2880 | if (bus->glomd) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2881 | PKTFREE(osh, bus->glomd, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2882 | |
| 2883 | if (bus->glom) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2884 | PKTFREE(osh, bus->glom, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2885 | |
| 2886 | bus->glom = bus->glomd = NULL; |
| 2887 | |
| 2888 | /* Clear rx control and wake any waiters */ |
| 2889 | bus->rxlen = 0; |
| 2890 | dhd_os_ioctl_resp_wake(bus->dhd); |
| 2891 | |
| 2892 | /* Reset some F2 state stuff */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2893 | bus->rxskip = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2894 | bus->tx_seq = bus->rx_seq = 0; |
| 2895 | |
| 2896 | if (enforce_mutex) |
| 2897 | dhd_os_sdunlock(bus->dhd); |
| 2898 | } |
| 2899 | |
| 2900 | int dhd_bus_init(dhd_pub_t *dhdp, bool enforce_mutex) |
| 2901 | { |
| 2902 | dhd_bus_t *bus = dhdp->bus; |
| 2903 | dhd_timeout_t tmo; |
| 2904 | uint retries = 0; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2905 | u8 ready, enable; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2906 | int err, ret = 0; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2907 | u8 saveclk; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2908 | |
| 2909 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 2910 | |
| 2911 | ASSERT(bus->dhd); |
| 2912 | if (!bus->dhd) |
| 2913 | return 0; |
| 2914 | |
| 2915 | if (enforce_mutex) |
| 2916 | dhd_os_sdlock(bus->dhd); |
| 2917 | |
| 2918 | /* Make sure backplane clock is on, needed to generate F2 interrupt */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2919 | dhdsdio_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2920 | if (bus->clkstate != CLK_AVAIL) |
| 2921 | goto exit; |
| 2922 | |
| 2923 | /* Force clocks on backplane to be sure F2 interrupt propagates */ |
| 2924 | saveclk = |
| 2925 | bcmsdh_cfg_read(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 2926 | &err); |
| 2927 | if (!err) { |
| 2928 | bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 2929 | (saveclk | SBSDIO_FORCE_HT), &err); |
| 2930 | } |
| 2931 | if (err) { |
| 2932 | DHD_ERROR(("%s: Failed to force clock for F2: err %d\n", |
| 2933 | __func__, err)); |
| 2934 | goto exit; |
| 2935 | } |
| 2936 | |
| 2937 | /* Enable function 2 (frame transfers) */ |
| 2938 | W_SDREG((SDPCM_PROT_VERSION << SMB_DATA_VERSION_SHIFT), |
| 2939 | &bus->regs->tosbmailboxdata, retries); |
| 2940 | enable = (SDIO_FUNC_ENABLE_1 | SDIO_FUNC_ENABLE_2); |
| 2941 | |
| 2942 | bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_0, SDIOD_CCCR_IOEN, enable, NULL); |
| 2943 | |
| 2944 | /* Give the dongle some time to do its thing and set IOR2 */ |
| 2945 | dhd_timeout_start(&tmo, DHD_WAIT_F2RDY * 1000); |
| 2946 | |
| 2947 | ready = 0; |
| 2948 | while (ready != enable && !dhd_timeout_expired(&tmo)) |
| 2949 | ready = |
| 2950 | bcmsdh_cfg_read(bus->sdh, SDIO_FUNC_0, SDIOD_CCCR_IORDY, |
| 2951 | NULL); |
| 2952 | |
| 2953 | DHD_INFO(("%s: enable 0x%02x, ready 0x%02x (waited %uus)\n", |
| 2954 | __func__, enable, ready, tmo.elapsed)); |
| 2955 | |
| 2956 | /* If F2 successfully enabled, set core and enable interrupts */ |
| 2957 | if (ready == enable) { |
| 2958 | /* Make sure we're talking to the core. */ |
| 2959 | bus->regs = si_setcore(bus->sih, PCMCIA_CORE_ID, 0); |
| 2960 | if (!(bus->regs)) |
| 2961 | bus->regs = si_setcore(bus->sih, SDIOD_CORE_ID, 0); |
| 2962 | |
| 2963 | /* Set up the interrupt mask and enable interrupts */ |
| 2964 | bus->hostintmask = HOSTINTMASK; |
| 2965 | W_SDREG(bus->hostintmask, &bus->regs->hostintmask, retries); |
| 2966 | |
| 2967 | bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_WATERMARK, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2968 | (u8) watermark, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2969 | |
| 2970 | /* Set bus state according to enable result */ |
| 2971 | dhdp->busstate = DHD_BUS_DATA; |
| 2972 | |
| 2973 | /* bcmsdh_intr_unmask(bus->sdh); */ |
| 2974 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2975 | bus->intdis = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2976 | if (bus->intr) { |
| 2977 | DHD_INTR(("%s: enable SDIO device interrupts\n", |
| 2978 | __func__)); |
| 2979 | bcmsdh_intr_enable(bus->sdh); |
| 2980 | } else { |
| 2981 | DHD_INTR(("%s: disable SDIO interrupts\n", __func__)); |
| 2982 | bcmsdh_intr_disable(bus->sdh); |
| 2983 | } |
| 2984 | |
| 2985 | } |
| 2986 | |
| 2987 | else { |
| 2988 | /* Disable F2 again */ |
| 2989 | enable = SDIO_FUNC_ENABLE_1; |
| 2990 | bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_0, SDIOD_CCCR_IOEN, enable, |
| 2991 | NULL); |
| 2992 | } |
| 2993 | |
| 2994 | /* Restore previous clock setting */ |
| 2995 | bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 2996 | saveclk, &err); |
| 2997 | |
| 2998 | /* If we didn't come up, turn off backplane clock */ |
| 2999 | if (dhdp->busstate != DHD_BUS_DATA) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3000 | dhdsdio_clkctl(bus, CLK_NONE, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3001 | |
| 3002 | exit: |
| 3003 | if (enforce_mutex) |
| 3004 | dhd_os_sdunlock(bus->dhd); |
| 3005 | |
| 3006 | return ret; |
| 3007 | } |
| 3008 | |
| 3009 | static void dhdsdio_rxfail(dhd_bus_t *bus, bool abort, bool rtx) |
| 3010 | { |
| 3011 | bcmsdh_info_t *sdh = bus->sdh; |
| 3012 | sdpcmd_regs_t *regs = bus->regs; |
| 3013 | uint retries = 0; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3014 | u16 lastrbc; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3015 | u8 hi, lo; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3016 | int err; |
| 3017 | |
| 3018 | DHD_ERROR(("%s: %sterminate frame%s\n", __func__, |
| 3019 | (abort ? "abort command, " : ""), |
| 3020 | (rtx ? ", send NAK" : ""))); |
| 3021 | |
| 3022 | if (abort) |
| 3023 | bcmsdh_abort(sdh, SDIO_FUNC_2); |
| 3024 | |
| 3025 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_FRAMECTRL, SFC_RF_TERM, |
| 3026 | &err); |
| 3027 | bus->f1regdata++; |
| 3028 | |
| 3029 | /* Wait until the packet has been flushed (device/FIFO stable) */ |
| 3030 | for (lastrbc = retries = 0xffff; retries > 0; retries--) { |
| 3031 | hi = bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_RFRAMEBCHI, |
| 3032 | NULL); |
| 3033 | lo = bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_RFRAMEBCLO, |
| 3034 | NULL); |
| 3035 | bus->f1regdata += 2; |
| 3036 | |
| 3037 | if ((hi == 0) && (lo == 0)) |
| 3038 | break; |
| 3039 | |
| 3040 | if ((hi > (lastrbc >> 8)) && (lo > (lastrbc & 0x00ff))) { |
| 3041 | DHD_ERROR(("%s: count growing: last 0x%04x now " |
| 3042 | "0x%04x\n", |
| 3043 | __func__, lastrbc, ((hi << 8) + lo))); |
| 3044 | } |
| 3045 | lastrbc = (hi << 8) + lo; |
| 3046 | } |
| 3047 | |
| 3048 | if (!retries) { |
| 3049 | DHD_ERROR(("%s: count never zeroed: last 0x%04x\n", |
| 3050 | __func__, lastrbc)); |
| 3051 | } else { |
| 3052 | DHD_INFO(("%s: flush took %d iterations\n", __func__, |
| 3053 | (0xffff - retries))); |
| 3054 | } |
| 3055 | |
| 3056 | if (rtx) { |
| 3057 | bus->rxrtx++; |
| 3058 | W_SDREG(SMB_NAK, ®s->tosbmailbox, retries); |
| 3059 | bus->f1regdata++; |
| 3060 | if (retries <= retry_limit) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3061 | bus->rxskip = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3062 | } |
| 3063 | |
| 3064 | /* Clear partial in any case */ |
| 3065 | bus->nextlen = 0; |
| 3066 | |
| 3067 | /* If we can't reach the device, signal failure */ |
| 3068 | if (err || bcmsdh_regfail(sdh)) |
| 3069 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 3070 | } |
| 3071 | |
| 3072 | static void |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3073 | 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] | 3074 | { |
| 3075 | bcmsdh_info_t *sdh = bus->sdh; |
| 3076 | uint rdlen, pad; |
| 3077 | |
| 3078 | int sdret; |
| 3079 | |
| 3080 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 3081 | |
| 3082 | /* Control data already received in aligned rxctl */ |
| 3083 | if ((bus->bus == SPI_BUS) && (!bus->usebufpool)) |
| 3084 | goto gotpkt; |
| 3085 | |
| 3086 | ASSERT(bus->rxbuf); |
| 3087 | /* Set rxctl for frame (w/optional alignment) */ |
| 3088 | bus->rxctl = bus->rxbuf; |
| 3089 | if (dhd_alignctl) { |
| 3090 | bus->rxctl += firstread; |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 3091 | pad = ((unsigned long)bus->rxctl % DHD_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3092 | if (pad) |
| 3093 | bus->rxctl += (DHD_SDALIGN - pad); |
| 3094 | bus->rxctl -= firstread; |
| 3095 | } |
| 3096 | ASSERT(bus->rxctl >= bus->rxbuf); |
| 3097 | |
| 3098 | /* Copy the already-read portion over */ |
| 3099 | bcopy(hdr, bus->rxctl, firstread); |
| 3100 | if (len <= firstread) |
| 3101 | goto gotpkt; |
| 3102 | |
| 3103 | /* Copy the full data pkt in gSPI case and process ioctl. */ |
| 3104 | if (bus->bus == SPI_BUS) { |
| 3105 | bcopy(hdr, bus->rxctl, len); |
| 3106 | goto gotpkt; |
| 3107 | } |
| 3108 | |
| 3109 | /* Raise rdlen to next SDIO block to avoid tail command */ |
| 3110 | rdlen = len - firstread; |
| 3111 | if (bus->roundup && bus->blocksize && (rdlen > bus->blocksize)) { |
| 3112 | pad = bus->blocksize - (rdlen % bus->blocksize); |
| 3113 | if ((pad <= bus->roundup) && (pad < bus->blocksize) && |
| 3114 | ((len + pad) < bus->dhd->maxctl)) |
| 3115 | rdlen += pad; |
| 3116 | } else if (rdlen % DHD_SDALIGN) { |
| 3117 | rdlen += DHD_SDALIGN - (rdlen % DHD_SDALIGN); |
| 3118 | } |
| 3119 | |
| 3120 | /* Satisfy length-alignment requirements */ |
| 3121 | if (forcealign && (rdlen & (ALIGNMENT - 1))) |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 3122 | rdlen = roundup(rdlen, ALIGNMENT); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3123 | |
| 3124 | /* Drop if the read is too big or it exceeds our maximum */ |
| 3125 | if ((rdlen + firstread) > bus->dhd->maxctl) { |
| 3126 | DHD_ERROR(("%s: %d-byte control read exceeds %d-byte buffer\n", |
| 3127 | __func__, rdlen, bus->dhd->maxctl)); |
| 3128 | bus->dhd->rx_errors++; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3129 | dhdsdio_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3130 | goto done; |
| 3131 | } |
| 3132 | |
| 3133 | if ((len - doff) > bus->dhd->maxctl) { |
| 3134 | DHD_ERROR(("%s: %d-byte ctl frame (%d-byte ctl data) exceeds " |
| 3135 | "%d-byte limit\n", |
| 3136 | __func__, len, (len - doff), bus->dhd->maxctl)); |
| 3137 | bus->dhd->rx_errors++; |
| 3138 | bus->rx_toolong++; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3139 | dhdsdio_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3140 | goto done; |
| 3141 | } |
| 3142 | |
| 3143 | /* Read remainder of frame body into the rxctl buffer */ |
| 3144 | sdret = |
| 3145 | dhd_bcmsdh_recv_buf(bus, bcmsdh_cur_sbwad(sdh), SDIO_FUNC_2, F2SYNC, |
| 3146 | (bus->rxctl + firstread), rdlen, NULL, NULL, |
| 3147 | NULL); |
| 3148 | bus->f2rxdata++; |
| 3149 | ASSERT(sdret != BCME_PENDING); |
| 3150 | |
| 3151 | /* Control frame failures need retransmission */ |
| 3152 | if (sdret < 0) { |
| 3153 | DHD_ERROR(("%s: read %d control bytes failed: %d\n", |
| 3154 | __func__, rdlen, sdret)); |
| 3155 | bus->rxc_errors++; /* dhd.rx_ctlerrs is higher level */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3156 | dhdsdio_rxfail(bus, true, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3157 | goto done; |
| 3158 | } |
| 3159 | |
| 3160 | gotpkt: |
| 3161 | |
| 3162 | #ifdef DHD_DEBUG |
| 3163 | if (DHD_BYTES_ON() && DHD_CTL_ON()) |
| 3164 | prhex("RxCtrl", bus->rxctl, len); |
| 3165 | #endif |
| 3166 | |
| 3167 | /* Point to valid data and indicate its length */ |
| 3168 | bus->rxctl += doff; |
| 3169 | bus->rxlen = len - doff; |
| 3170 | |
| 3171 | done: |
| 3172 | /* Awake any waiters */ |
| 3173 | dhd_os_ioctl_resp_wake(bus->dhd); |
| 3174 | } |
| 3175 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3176 | static u8 dhdsdio_rxglom(dhd_bus_t *bus, u8 rxseq) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3177 | { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3178 | u16 dlen, totlen; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3179 | u8 *dptr, num = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3180 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3181 | u16 sublen, check; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3182 | void *pfirst, *plast, *pnext, *save_pfirst; |
| 3183 | osl_t *osh = bus->dhd->osh; |
| 3184 | |
| 3185 | int errcode; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3186 | u8 chan, seq, doff, sfdoff; |
| 3187 | u8 txmax; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3188 | |
| 3189 | int ifidx = 0; |
| 3190 | bool usechain = bus->use_rxchain; |
| 3191 | |
| 3192 | /* If packets, issue read(s) and send up packet chain */ |
| 3193 | /* Return sequence numbers consumed? */ |
| 3194 | |
| 3195 | DHD_TRACE(("dhdsdio_rxglom: start: glomd %p glom %p\n", bus->glomd, |
| 3196 | bus->glom)); |
| 3197 | |
| 3198 | /* If there's a descriptor, generate the packet chain */ |
| 3199 | if (bus->glomd) { |
| 3200 | dhd_os_sdlock_rxq(bus->dhd); |
| 3201 | |
| 3202 | pfirst = plast = pnext = NULL; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3203 | dlen = (u16) PKTLEN(bus->glomd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3204 | dptr = PKTDATA(bus->glomd); |
| 3205 | if (!dlen || (dlen & 1)) { |
| 3206 | DHD_ERROR(("%s: bad glomd len(%d), ignore descriptor\n", |
| 3207 | __func__, dlen)); |
| 3208 | dlen = 0; |
| 3209 | } |
| 3210 | |
| 3211 | for (totlen = num = 0; dlen; num++) { |
| 3212 | /* Get (and move past) next length */ |
| 3213 | sublen = ltoh16_ua(dptr); |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3214 | dlen -= sizeof(u16); |
| 3215 | dptr += sizeof(u16); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3216 | if ((sublen < SDPCM_HDRLEN) || |
| 3217 | ((num == 0) && (sublen < (2 * SDPCM_HDRLEN)))) { |
| 3218 | DHD_ERROR(("%s: descriptor len %d bad: %d\n", |
| 3219 | __func__, num, sublen)); |
| 3220 | pnext = NULL; |
| 3221 | break; |
| 3222 | } |
| 3223 | if (sublen % DHD_SDALIGN) { |
| 3224 | DHD_ERROR(("%s: sublen %d not multiple of %d\n", |
| 3225 | __func__, sublen, DHD_SDALIGN)); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3226 | usechain = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3227 | } |
| 3228 | totlen += sublen; |
| 3229 | |
| 3230 | /* For last frame, adjust read len so total |
| 3231 | is a block multiple */ |
| 3232 | if (!dlen) { |
| 3233 | sublen += |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 3234 | (roundup(totlen, bus->blocksize) - totlen); |
| 3235 | totlen = roundup(totlen, bus->blocksize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3236 | } |
| 3237 | |
| 3238 | /* Allocate/chain packet for next subframe */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3239 | pnext = PKTGET(osh, sublen + DHD_SDALIGN, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3240 | if (pnext == NULL) { |
| 3241 | DHD_ERROR(("%s: PKTGET failed, num %d len %d\n", |
| 3242 | __func__, num, sublen)); |
| 3243 | break; |
| 3244 | } |
| 3245 | ASSERT(!PKTLINK(pnext)); |
| 3246 | if (!pfirst) { |
| 3247 | ASSERT(!plast); |
| 3248 | pfirst = plast = pnext; |
| 3249 | } else { |
| 3250 | ASSERT(plast); |
| 3251 | PKTSETNEXT(plast, pnext); |
| 3252 | plast = pnext; |
| 3253 | } |
| 3254 | |
| 3255 | /* Adhere to start alignment requirements */ |
| 3256 | PKTALIGN(osh, pnext, sublen, DHD_SDALIGN); |
| 3257 | } |
| 3258 | |
| 3259 | /* If all allocations succeeded, save packet chain |
| 3260 | in bus structure */ |
| 3261 | if (pnext) { |
| 3262 | DHD_GLOM(("%s: allocated %d-byte packet chain for %d " |
| 3263 | "subframes\n", __func__, totlen, num)); |
| 3264 | if (DHD_GLOM_ON() && bus->nextlen) { |
| 3265 | if (totlen != bus->nextlen) { |
| 3266 | DHD_GLOM(("%s: glomdesc mismatch: nextlen %d glomdesc %d " "rxseq %d\n", |
| 3267 | __func__, bus->nextlen, |
| 3268 | totlen, rxseq)); |
| 3269 | } |
| 3270 | } |
| 3271 | bus->glom = pfirst; |
| 3272 | pfirst = pnext = NULL; |
| 3273 | } else { |
| 3274 | if (pfirst) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3275 | PKTFREE(osh, pfirst, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3276 | bus->glom = NULL; |
| 3277 | num = 0; |
| 3278 | } |
| 3279 | |
| 3280 | /* Done with descriptor packet */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3281 | PKTFREE(osh, bus->glomd, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3282 | bus->glomd = NULL; |
| 3283 | bus->nextlen = 0; |
| 3284 | |
| 3285 | dhd_os_sdunlock_rxq(bus->dhd); |
| 3286 | } |
| 3287 | |
| 3288 | /* Ok -- either we just generated a packet chain, |
| 3289 | or had one from before */ |
| 3290 | if (bus->glom) { |
| 3291 | if (DHD_GLOM_ON()) { |
| 3292 | DHD_GLOM(("%s: try superframe read, packet chain:\n", |
| 3293 | __func__)); |
| 3294 | for (pnext = bus->glom; pnext; pnext = PKTNEXT(pnext)) { |
| 3295 | DHD_GLOM((" %p: %p len 0x%04x (%d)\n", |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3296 | pnext, (u8 *) PKTDATA(pnext), |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3297 | PKTLEN(pnext), PKTLEN(pnext))); |
| 3298 | } |
| 3299 | } |
| 3300 | |
| 3301 | pfirst = bus->glom; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3302 | dlen = (u16) pkttotlen(osh, pfirst); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3303 | |
| 3304 | /* Do an SDIO read for the superframe. Configurable iovar to |
| 3305 | * read directly into the chained packet, or allocate a large |
| 3306 | * packet and and copy into the chain. |
| 3307 | */ |
| 3308 | if (usechain) { |
| 3309 | errcode = dhd_bcmsdh_recv_buf(bus, |
| 3310 | bcmsdh_cur_sbwad |
| 3311 | (bus->sdh), SDIO_FUNC_2, |
| 3312 | F2SYNC, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3313 | (u8 *) PKTDATA(pfirst), |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3314 | dlen, pfirst, NULL, NULL); |
| 3315 | } else if (bus->dataptr) { |
| 3316 | errcode = dhd_bcmsdh_recv_buf(bus, |
| 3317 | bcmsdh_cur_sbwad |
| 3318 | (bus->sdh), SDIO_FUNC_2, |
| 3319 | F2SYNC, bus->dataptr, |
| 3320 | dlen, NULL, NULL, NULL); |
| 3321 | sublen = |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3322 | (u16) pktfrombuf(osh, pfirst, 0, dlen, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3323 | bus->dataptr); |
| 3324 | if (sublen != dlen) { |
| 3325 | DHD_ERROR(("%s: FAILED TO COPY, dlen %d sublen %d\n", |
| 3326 | __func__, dlen, sublen)); |
| 3327 | errcode = -1; |
| 3328 | } |
| 3329 | pnext = NULL; |
| 3330 | } else { |
| 3331 | DHD_ERROR(("COULDN'T ALLOC %d-BYTE GLOM, FORCE FAILURE\n", |
| 3332 | dlen)); |
| 3333 | errcode = -1; |
| 3334 | } |
| 3335 | bus->f2rxdata++; |
| 3336 | ASSERT(errcode != BCME_PENDING); |
| 3337 | |
| 3338 | /* On failure, kill the superframe, allow a couple retries */ |
| 3339 | if (errcode < 0) { |
| 3340 | DHD_ERROR(("%s: glom read of %d bytes failed: %d\n", |
| 3341 | __func__, dlen, errcode)); |
| 3342 | bus->dhd->rx_errors++; |
| 3343 | |
| 3344 | if (bus->glomerr++ < 3) { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3345 | dhdsdio_rxfail(bus, true, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3346 | } else { |
| 3347 | bus->glomerr = 0; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3348 | dhdsdio_rxfail(bus, true, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3349 | dhd_os_sdlock_rxq(bus->dhd); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3350 | PKTFREE(osh, bus->glom, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3351 | dhd_os_sdunlock_rxq(bus->dhd); |
| 3352 | bus->rxglomfail++; |
| 3353 | bus->glom = NULL; |
| 3354 | } |
| 3355 | return 0; |
| 3356 | } |
| 3357 | #ifdef DHD_DEBUG |
| 3358 | if (DHD_GLOM_ON()) { |
| 3359 | prhex("SUPERFRAME", PKTDATA(pfirst), |
Greg Kroah-Hartman | b61640d | 2010-10-08 12:37:39 -0700 | [diff] [blame] | 3360 | min_t(int, PKTLEN(pfirst), 48)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3361 | } |
| 3362 | #endif |
| 3363 | |
| 3364 | /* Validate the superframe header */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3365 | dptr = (u8 *) PKTDATA(pfirst); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3366 | sublen = ltoh16_ua(dptr); |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3367 | check = ltoh16_ua(dptr + sizeof(u16)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3368 | |
| 3369 | chan = SDPCM_PACKET_CHANNEL(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3370 | seq = SDPCM_PACKET_SEQUENCE(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3371 | bus->nextlen = dptr[SDPCM_FRAMETAG_LEN + SDPCM_NEXTLEN_OFFSET]; |
| 3372 | if ((bus->nextlen << 4) > MAX_RX_DATASZ) { |
| 3373 | DHD_INFO(("%s: nextlen too large (%d) seq %d\n", |
| 3374 | __func__, bus->nextlen, seq)); |
| 3375 | bus->nextlen = 0; |
| 3376 | } |
| 3377 | doff = SDPCM_DOFFSET_VALUE(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3378 | txmax = SDPCM_WINDOW_VALUE(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3379 | |
| 3380 | errcode = 0; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3381 | if ((u16)~(sublen ^ check)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3382 | DHD_ERROR(("%s (superframe): HW hdr error: len/check " |
| 3383 | "0x%04x/0x%04x\n", __func__, sublen, check)); |
| 3384 | errcode = -1; |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 3385 | } else if (roundup(sublen, bus->blocksize) != dlen) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3386 | DHD_ERROR(("%s (superframe): len 0x%04x, rounded " |
| 3387 | "0x%04x, expect 0x%04x\n", |
| 3388 | __func__, sublen, |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 3389 | roundup(sublen, bus->blocksize), dlen)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3390 | errcode = -1; |
| 3391 | } else if (SDPCM_PACKET_CHANNEL(&dptr[SDPCM_FRAMETAG_LEN]) != |
| 3392 | SDPCM_GLOM_CHANNEL) { |
| 3393 | DHD_ERROR(("%s (superframe): bad channel %d\n", |
| 3394 | __func__, |
| 3395 | SDPCM_PACKET_CHANNEL(&dptr |
| 3396 | [SDPCM_FRAMETAG_LEN]))); |
| 3397 | errcode = -1; |
| 3398 | } else if (SDPCM_GLOMDESC(&dptr[SDPCM_FRAMETAG_LEN])) { |
| 3399 | DHD_ERROR(("%s (superframe): got second descriptor?\n", |
| 3400 | __func__)); |
| 3401 | errcode = -1; |
| 3402 | } else if ((doff < SDPCM_HDRLEN) || |
| 3403 | (doff > (PKTLEN(pfirst) - SDPCM_HDRLEN))) { |
| 3404 | DHD_ERROR(("%s (superframe): Bad data offset %d: HW %d " |
| 3405 | "pkt %d min %d\n", |
| 3406 | __func__, doff, sublen, |
| 3407 | PKTLEN(pfirst), SDPCM_HDRLEN)); |
| 3408 | errcode = -1; |
| 3409 | } |
| 3410 | |
| 3411 | /* Check sequence number of superframe SW header */ |
| 3412 | if (rxseq != seq) { |
| 3413 | DHD_INFO(("%s: (superframe) rx_seq %d, expected %d\n", |
| 3414 | __func__, seq, rxseq)); |
| 3415 | bus->rx_badseq++; |
| 3416 | rxseq = seq; |
| 3417 | } |
| 3418 | |
| 3419 | /* Check window for sanity */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3420 | if ((u8) (txmax - bus->tx_seq) > 0x40) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3421 | DHD_ERROR(("%s: unlikely tx max %d with tx_seq %d\n", |
| 3422 | __func__, txmax, bus->tx_seq)); |
| 3423 | txmax = bus->tx_seq + 2; |
| 3424 | } |
| 3425 | bus->tx_max = txmax; |
| 3426 | |
| 3427 | /* Remove superframe header, remember offset */ |
| 3428 | PKTPULL(pfirst, doff); |
| 3429 | sfdoff = doff; |
| 3430 | |
| 3431 | /* Validate all the subframe headers */ |
| 3432 | for (num = 0, pnext = pfirst; pnext && !errcode; |
| 3433 | num++, pnext = PKTNEXT(pnext)) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3434 | dptr = (u8 *) PKTDATA(pnext); |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3435 | dlen = (u16) PKTLEN(pnext); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3436 | sublen = ltoh16_ua(dptr); |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3437 | check = ltoh16_ua(dptr + sizeof(u16)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3438 | chan = SDPCM_PACKET_CHANNEL(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3439 | doff = SDPCM_DOFFSET_VALUE(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3440 | #ifdef DHD_DEBUG |
| 3441 | if (DHD_GLOM_ON()) |
| 3442 | prhex("subframe", dptr, 32); |
| 3443 | #endif |
| 3444 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3445 | if ((u16)~(sublen ^ check)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3446 | DHD_ERROR(("%s (subframe %d): HW hdr error: " |
| 3447 | "len/check 0x%04x/0x%04x\n", |
| 3448 | __func__, num, sublen, check)); |
| 3449 | errcode = -1; |
| 3450 | } else if ((sublen > dlen) || (sublen < SDPCM_HDRLEN)) { |
| 3451 | DHD_ERROR(("%s (subframe %d): length mismatch: " |
| 3452 | "len 0x%04x, expect 0x%04x\n", |
| 3453 | __func__, num, sublen, dlen)); |
| 3454 | errcode = -1; |
| 3455 | } else if ((chan != SDPCM_DATA_CHANNEL) && |
| 3456 | (chan != SDPCM_EVENT_CHANNEL)) { |
| 3457 | DHD_ERROR(("%s (subframe %d): bad channel %d\n", |
| 3458 | __func__, num, chan)); |
| 3459 | errcode = -1; |
| 3460 | } else if ((doff < SDPCM_HDRLEN) || (doff > sublen)) { |
| 3461 | DHD_ERROR(("%s (subframe %d): Bad data offset %d: HW %d min %d\n", |
| 3462 | __func__, num, doff, sublen, |
| 3463 | SDPCM_HDRLEN)); |
| 3464 | errcode = -1; |
| 3465 | } |
| 3466 | } |
| 3467 | |
| 3468 | if (errcode) { |
| 3469 | /* Terminate frame on error, request |
| 3470 | a couple retries */ |
| 3471 | if (bus->glomerr++ < 3) { |
| 3472 | /* Restore superframe header space */ |
| 3473 | PKTPUSH(pfirst, sfdoff); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3474 | dhdsdio_rxfail(bus, true, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3475 | } else { |
| 3476 | bus->glomerr = 0; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3477 | dhdsdio_rxfail(bus, true, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3478 | dhd_os_sdlock_rxq(bus->dhd); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3479 | PKTFREE(osh, bus->glom, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3480 | dhd_os_sdunlock_rxq(bus->dhd); |
| 3481 | bus->rxglomfail++; |
| 3482 | bus->glom = NULL; |
| 3483 | } |
| 3484 | bus->nextlen = 0; |
| 3485 | return 0; |
| 3486 | } |
| 3487 | |
| 3488 | /* Basic SD framing looks ok - process each packet (header) */ |
| 3489 | save_pfirst = pfirst; |
| 3490 | bus->glom = NULL; |
| 3491 | plast = NULL; |
| 3492 | |
| 3493 | dhd_os_sdlock_rxq(bus->dhd); |
| 3494 | for (num = 0; pfirst; rxseq++, pfirst = pnext) { |
| 3495 | pnext = PKTNEXT(pfirst); |
| 3496 | PKTSETNEXT(pfirst, NULL); |
| 3497 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3498 | dptr = (u8 *) PKTDATA(pfirst); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3499 | sublen = ltoh16_ua(dptr); |
| 3500 | chan = SDPCM_PACKET_CHANNEL(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3501 | seq = SDPCM_PACKET_SEQUENCE(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3502 | doff = SDPCM_DOFFSET_VALUE(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3503 | |
| 3504 | DHD_GLOM(("%s: Get subframe %d, %p(%p/%d), sublen %d " |
| 3505 | "chan %d seq %d\n", |
| 3506 | __func__, num, pfirst, PKTDATA(pfirst), |
| 3507 | PKTLEN(pfirst), sublen, chan, seq)); |
| 3508 | |
| 3509 | ASSERT((chan == SDPCM_DATA_CHANNEL) |
| 3510 | || (chan == SDPCM_EVENT_CHANNEL)); |
| 3511 | |
| 3512 | if (rxseq != seq) { |
| 3513 | DHD_GLOM(("%s: rx_seq %d, expected %d\n", |
| 3514 | __func__, seq, rxseq)); |
| 3515 | bus->rx_badseq++; |
| 3516 | rxseq = seq; |
| 3517 | } |
| 3518 | #ifdef DHD_DEBUG |
| 3519 | if (DHD_BYTES_ON() && DHD_DATA_ON()) |
| 3520 | prhex("Rx Subframe Data", dptr, dlen); |
| 3521 | #endif |
| 3522 | |
| 3523 | PKTSETLEN(pfirst, sublen); |
| 3524 | PKTPULL(pfirst, doff); |
| 3525 | |
| 3526 | if (PKTLEN(pfirst) == 0) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3527 | PKTFREE(bus->dhd->osh, pfirst, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3528 | if (plast) { |
| 3529 | PKTSETNEXT(plast, pnext); |
| 3530 | } else { |
| 3531 | ASSERT(save_pfirst == pfirst); |
| 3532 | save_pfirst = pnext; |
| 3533 | } |
| 3534 | continue; |
| 3535 | } else if (dhd_prot_hdrpull(bus->dhd, &ifidx, pfirst) != |
| 3536 | 0) { |
| 3537 | DHD_ERROR(("%s: rx protocol error\n", |
| 3538 | __func__)); |
| 3539 | bus->dhd->rx_errors++; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3540 | PKTFREE(osh, pfirst, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3541 | if (plast) { |
| 3542 | PKTSETNEXT(plast, pnext); |
| 3543 | } else { |
| 3544 | ASSERT(save_pfirst == pfirst); |
| 3545 | save_pfirst = pnext; |
| 3546 | } |
| 3547 | continue; |
| 3548 | } |
| 3549 | |
| 3550 | /* this packet will go up, link back into |
| 3551 | chain and count it */ |
| 3552 | PKTSETNEXT(pfirst, pnext); |
| 3553 | plast = pfirst; |
| 3554 | num++; |
| 3555 | |
| 3556 | #ifdef DHD_DEBUG |
| 3557 | if (DHD_GLOM_ON()) { |
| 3558 | DHD_GLOM(("%s subframe %d to stack, %p(%p/%d) " |
| 3559 | "nxt/lnk %p/%p\n", |
| 3560 | __func__, num, pfirst, PKTDATA(pfirst), |
| 3561 | PKTLEN(pfirst), PKTNEXT(pfirst), |
| 3562 | PKTLINK(pfirst))); |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3563 | prhex("", (u8 *) PKTDATA(pfirst), |
Greg Kroah-Hartman | b61640d | 2010-10-08 12:37:39 -0700 | [diff] [blame] | 3564 | min_t(int, PKTLEN(pfirst), 32)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3565 | } |
| 3566 | #endif /* DHD_DEBUG */ |
| 3567 | } |
| 3568 | dhd_os_sdunlock_rxq(bus->dhd); |
| 3569 | if (num) { |
| 3570 | dhd_os_sdunlock(bus->dhd); |
| 3571 | dhd_rx_frame(bus->dhd, ifidx, save_pfirst, num); |
| 3572 | dhd_os_sdlock(bus->dhd); |
| 3573 | } |
| 3574 | |
| 3575 | bus->rxglomframes++; |
| 3576 | bus->rxglompkts += num; |
| 3577 | } |
| 3578 | return num; |
| 3579 | } |
| 3580 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3581 | /* Return true if there may be more frames to read */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3582 | static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished) |
| 3583 | { |
| 3584 | osl_t *osh = bus->dhd->osh; |
| 3585 | bcmsdh_info_t *sdh = bus->sdh; |
| 3586 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3587 | u16 len, check; /* Extracted hardware header fields */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3588 | u8 chan, seq, doff; /* Extracted software header fields */ |
| 3589 | u8 fcbits; /* Extracted fcbits from software header */ |
| 3590 | u8 delta; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3591 | |
| 3592 | void *pkt; /* Packet for event or data frames */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3593 | u16 pad; /* Number of pad bytes to read */ |
| 3594 | u16 rdlen; /* Total number of bytes to read */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3595 | u8 rxseq; /* Next sequence number to expect */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3596 | uint rxleft = 0; /* Remaining number of frames allowed */ |
| 3597 | int sdret; /* Return code from bcmsdh calls */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3598 | u8 txmax; /* Maximum tx sequence offered */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3599 | bool len_consistent; /* Result of comparing readahead len and |
| 3600 | len from hw-hdr */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3601 | u8 *rxbuf; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3602 | int ifidx = 0; |
| 3603 | uint rxcount = 0; /* Total frames read */ |
| 3604 | |
| 3605 | #if defined(DHD_DEBUG) || defined(SDTEST) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3606 | bool sdtest = false; /* To limit message spew from test mode */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3607 | #endif |
| 3608 | |
| 3609 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 3610 | |
| 3611 | ASSERT(maxframes); |
| 3612 | |
| 3613 | #ifdef SDTEST |
| 3614 | /* Allow pktgen to override maxframes */ |
| 3615 | if (bus->pktgen_count && (bus->pktgen_mode == DHD_PKTGEN_RECV)) { |
| 3616 | maxframes = bus->pktgen_count; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3617 | sdtest = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3618 | } |
| 3619 | #endif |
| 3620 | |
| 3621 | /* Not finished unless we encounter no more frames indication */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3622 | *finished = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3623 | |
| 3624 | for (rxseq = bus->rx_seq, rxleft = maxframes; |
| 3625 | !bus->rxskip && rxleft && bus->dhd->busstate != DHD_BUS_DOWN; |
| 3626 | rxseq++, rxleft--) { |
| 3627 | |
| 3628 | /* Handle glomming separately */ |
| 3629 | if (bus->glom || bus->glomd) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3630 | u8 cnt; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3631 | DHD_GLOM(("%s: calling rxglom: glomd %p, glom %p\n", |
| 3632 | __func__, bus->glomd, bus->glom)); |
| 3633 | cnt = dhdsdio_rxglom(bus, rxseq); |
| 3634 | DHD_GLOM(("%s: rxglom returned %d\n", __func__, cnt)); |
| 3635 | rxseq += cnt - 1; |
| 3636 | rxleft = (rxleft > cnt) ? (rxleft - cnt) : 1; |
| 3637 | continue; |
| 3638 | } |
| 3639 | |
| 3640 | /* Try doing single read if we can */ |
| 3641 | if (dhd_readahead && bus->nextlen) { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3642 | u16 nextlen = bus->nextlen; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3643 | bus->nextlen = 0; |
| 3644 | |
| 3645 | if (bus->bus == SPI_BUS) { |
| 3646 | rdlen = len = nextlen; |
| 3647 | } else { |
| 3648 | rdlen = len = nextlen << 4; |
| 3649 | |
| 3650 | /* Pad read to blocksize for efficiency */ |
| 3651 | if (bus->roundup && bus->blocksize |
| 3652 | && (rdlen > bus->blocksize)) { |
| 3653 | pad = |
| 3654 | bus->blocksize - |
| 3655 | (rdlen % bus->blocksize); |
| 3656 | if ((pad <= bus->roundup) |
| 3657 | && (pad < bus->blocksize) |
| 3658 | && ((rdlen + pad + firstread) < |
| 3659 | MAX_RX_DATASZ)) |
| 3660 | rdlen += pad; |
| 3661 | } else if (rdlen % DHD_SDALIGN) { |
| 3662 | rdlen += |
| 3663 | DHD_SDALIGN - (rdlen % DHD_SDALIGN); |
| 3664 | } |
| 3665 | } |
| 3666 | |
| 3667 | /* We use bus->rxctl buffer in WinXP for initial |
| 3668 | * control pkt receives. |
| 3669 | * Later we use buffer-poll for data as well |
| 3670 | * as control packets. |
| 3671 | * This is required becuase dhd receives full |
| 3672 | * frame in gSPI unlike SDIO. |
| 3673 | * After the frame is received we have to |
| 3674 | * distinguish whether it is data |
| 3675 | * or non-data frame. |
| 3676 | */ |
| 3677 | /* Allocate a packet buffer */ |
| 3678 | dhd_os_sdlock_rxq(bus->dhd); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3679 | pkt = PKTGET(osh, rdlen + DHD_SDALIGN, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3680 | if (!pkt) { |
| 3681 | if (bus->bus == SPI_BUS) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3682 | bus->usebufpool = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3683 | bus->rxctl = bus->rxbuf; |
| 3684 | if (dhd_alignctl) { |
| 3685 | bus->rxctl += firstread; |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 3686 | pad = ((unsigned long)bus->rxctl % |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3687 | DHD_SDALIGN); |
| 3688 | if (pad) |
| 3689 | bus->rxctl += |
| 3690 | (DHD_SDALIGN - pad); |
| 3691 | bus->rxctl -= firstread; |
| 3692 | } |
| 3693 | ASSERT(bus->rxctl >= bus->rxbuf); |
| 3694 | rxbuf = bus->rxctl; |
| 3695 | /* Read the entire frame */ |
| 3696 | sdret = dhd_bcmsdh_recv_buf(bus, |
| 3697 | bcmsdh_cur_sbwad |
| 3698 | (sdh), |
| 3699 | SDIO_FUNC_2, |
| 3700 | F2SYNC, |
| 3701 | rxbuf, |
| 3702 | rdlen, NULL, |
| 3703 | NULL, NULL); |
| 3704 | bus->f2rxdata++; |
| 3705 | ASSERT(sdret != BCME_PENDING); |
| 3706 | |
| 3707 | /* Control frame failures need |
| 3708 | retransmission */ |
| 3709 | if (sdret < 0) { |
| 3710 | DHD_ERROR(("%s: read %d control bytes failed: %d\n", |
| 3711 | __func__, |
| 3712 | rdlen, sdret)); |
| 3713 | /* dhd.rx_ctlerrs is higher */ |
| 3714 | bus->rxc_errors++; |
| 3715 | dhd_os_sdunlock_rxq(bus->dhd); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3716 | dhdsdio_rxfail(bus, true, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3717 | (bus->bus == |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3718 | SPI_BUS) ? false |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3719 | : true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3720 | continue; |
| 3721 | } |
| 3722 | } else { |
| 3723 | /* Give up on data, |
| 3724 | request rtx of events */ |
| 3725 | DHD_ERROR(("%s (nextlen): PKTGET failed: len %d rdlen %d " "expected rxseq %d\n", |
| 3726 | __func__, len, rdlen, rxseq)); |
| 3727 | /* Just go try again w/normal |
| 3728 | header read */ |
| 3729 | dhd_os_sdunlock_rxq(bus->dhd); |
| 3730 | continue; |
| 3731 | } |
| 3732 | } else { |
| 3733 | if (bus->bus == SPI_BUS) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3734 | bus->usebufpool = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3735 | |
| 3736 | ASSERT(!PKTLINK(pkt)); |
| 3737 | PKTALIGN(osh, pkt, rdlen, DHD_SDALIGN); |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3738 | rxbuf = (u8 *) PKTDATA(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3739 | /* Read the entire frame */ |
| 3740 | sdret = |
| 3741 | dhd_bcmsdh_recv_buf(bus, |
| 3742 | bcmsdh_cur_sbwad(sdh), |
| 3743 | SDIO_FUNC_2, F2SYNC, |
| 3744 | rxbuf, rdlen, pkt, NULL, |
| 3745 | NULL); |
| 3746 | bus->f2rxdata++; |
| 3747 | ASSERT(sdret != BCME_PENDING); |
| 3748 | |
| 3749 | if (sdret < 0) { |
| 3750 | DHD_ERROR(("%s (nextlen): read %d bytes failed: %d\n", |
| 3751 | __func__, rdlen, sdret)); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3752 | PKTFREE(bus->dhd->osh, pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3753 | bus->dhd->rx_errors++; |
| 3754 | dhd_os_sdunlock_rxq(bus->dhd); |
| 3755 | /* Force retry w/normal header read. |
| 3756 | * Don't attemp NAK for |
| 3757 | * gSPI |
| 3758 | */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3759 | dhdsdio_rxfail(bus, true, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3760 | (bus->bus == |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3761 | SPI_BUS) ? false : |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3762 | true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3763 | continue; |
| 3764 | } |
| 3765 | } |
| 3766 | dhd_os_sdunlock_rxq(bus->dhd); |
| 3767 | |
| 3768 | /* Now check the header */ |
| 3769 | bcopy(rxbuf, bus->rxhdr, SDPCM_HDRLEN); |
| 3770 | |
| 3771 | /* Extract hardware header fields */ |
| 3772 | len = ltoh16_ua(bus->rxhdr); |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3773 | check = ltoh16_ua(bus->rxhdr + sizeof(u16)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3774 | |
| 3775 | /* All zeros means readahead info was bad */ |
| 3776 | if (!(len | check)) { |
| 3777 | DHD_INFO(("%s (nextlen): read zeros in HW " |
| 3778 | "header???\n", __func__)); |
| 3779 | dhd_os_sdlock_rxq(bus->dhd); |
| 3780 | PKTFREE2(); |
| 3781 | dhd_os_sdunlock_rxq(bus->dhd); |
| 3782 | GSPI_PR55150_BAILOUT; |
| 3783 | continue; |
| 3784 | } |
| 3785 | |
| 3786 | /* Validate check bytes */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3787 | if ((u16)~(len ^ check)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3788 | DHD_ERROR(("%s (nextlen): HW hdr error: nextlen/len/check" " 0x%04x/0x%04x/0x%04x\n", |
| 3789 | __func__, nextlen, len, check)); |
| 3790 | dhd_os_sdlock_rxq(bus->dhd); |
| 3791 | PKTFREE2(); |
| 3792 | dhd_os_sdunlock_rxq(bus->dhd); |
| 3793 | bus->rx_badhdr++; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3794 | dhdsdio_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3795 | GSPI_PR55150_BAILOUT; |
| 3796 | continue; |
| 3797 | } |
| 3798 | |
| 3799 | /* Validate frame length */ |
| 3800 | if (len < SDPCM_HDRLEN) { |
| 3801 | DHD_ERROR(("%s (nextlen): HW hdr length " |
| 3802 | "invalid: %d\n", __func__, len)); |
| 3803 | dhd_os_sdlock_rxq(bus->dhd); |
| 3804 | PKTFREE2(); |
| 3805 | dhd_os_sdunlock_rxq(bus->dhd); |
| 3806 | GSPI_PR55150_BAILOUT; |
| 3807 | continue; |
| 3808 | } |
| 3809 | |
| 3810 | /* Check for consistency withreadahead info */ |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 3811 | len_consistent = (nextlen != (roundup(len, 16) >> 4)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3812 | if (len_consistent) { |
| 3813 | /* Mismatch, force retry w/normal |
| 3814 | header (may be >4K) */ |
| 3815 | DHD_ERROR(("%s (nextlen): mismatch, nextlen %d len %d rnd %d; " "expected rxseq %d\n", |
| 3816 | __func__, nextlen, |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 3817 | len, roundup(len, 16), rxseq)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3818 | dhd_os_sdlock_rxq(bus->dhd); |
| 3819 | PKTFREE2(); |
| 3820 | dhd_os_sdunlock_rxq(bus->dhd); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3821 | dhdsdio_rxfail(bus, true, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3822 | (bus->bus == |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3823 | SPI_BUS) ? false : true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3824 | GSPI_PR55150_BAILOUT; |
| 3825 | continue; |
| 3826 | } |
| 3827 | |
| 3828 | /* Extract software header fields */ |
| 3829 | chan = |
| 3830 | SDPCM_PACKET_CHANNEL(&bus->rxhdr |
| 3831 | [SDPCM_FRAMETAG_LEN]); |
| 3832 | seq = |
| 3833 | SDPCM_PACKET_SEQUENCE(&bus->rxhdr |
| 3834 | [SDPCM_FRAMETAG_LEN]); |
| 3835 | doff = |
| 3836 | SDPCM_DOFFSET_VALUE(&bus->rxhdr |
| 3837 | [SDPCM_FRAMETAG_LEN]); |
| 3838 | txmax = |
| 3839 | SDPCM_WINDOW_VALUE(&bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 3840 | |
| 3841 | bus->nextlen = |
| 3842 | bus->rxhdr[SDPCM_FRAMETAG_LEN + |
| 3843 | SDPCM_NEXTLEN_OFFSET]; |
| 3844 | if ((bus->nextlen << 4) > MAX_RX_DATASZ) { |
| 3845 | DHD_INFO(("%s (nextlen): got frame w/nextlen too large" " (%d), seq %d\n", |
| 3846 | __func__, bus->nextlen, seq)); |
| 3847 | bus->nextlen = 0; |
| 3848 | } |
| 3849 | |
| 3850 | bus->dhd->rx_readahead_cnt++; |
| 3851 | /* Handle Flow Control */ |
| 3852 | fcbits = |
| 3853 | SDPCM_FCMASK_VALUE(&bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 3854 | |
| 3855 | delta = 0; |
| 3856 | if (~bus->flowcontrol & fcbits) { |
| 3857 | bus->fc_xoff++; |
| 3858 | delta = 1; |
| 3859 | } |
| 3860 | if (bus->flowcontrol & ~fcbits) { |
| 3861 | bus->fc_xon++; |
| 3862 | delta = 1; |
| 3863 | } |
| 3864 | |
| 3865 | if (delta) { |
| 3866 | bus->fc_rcvd++; |
| 3867 | bus->flowcontrol = fcbits; |
| 3868 | } |
| 3869 | |
| 3870 | /* Check and update sequence number */ |
| 3871 | if (rxseq != seq) { |
| 3872 | DHD_INFO(("%s (nextlen): rx_seq %d, expected " |
| 3873 | "%d\n", __func__, seq, rxseq)); |
| 3874 | bus->rx_badseq++; |
| 3875 | rxseq = seq; |
| 3876 | } |
| 3877 | |
| 3878 | /* Check window for sanity */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3879 | if ((u8) (txmax - bus->tx_seq) > 0x40) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3880 | DHD_ERROR(("%s: got unlikely tx max %d with " |
| 3881 | "tx_seq %d\n", |
| 3882 | __func__, txmax, bus->tx_seq)); |
| 3883 | txmax = bus->tx_seq + 2; |
| 3884 | } |
| 3885 | bus->tx_max = txmax; |
| 3886 | |
| 3887 | #ifdef DHD_DEBUG |
| 3888 | if (DHD_BYTES_ON() && DHD_DATA_ON()) |
| 3889 | prhex("Rx Data", rxbuf, len); |
| 3890 | else if (DHD_HDRS_ON()) |
| 3891 | prhex("RxHdr", bus->rxhdr, SDPCM_HDRLEN); |
| 3892 | #endif |
| 3893 | |
| 3894 | if (chan == SDPCM_CONTROL_CHANNEL) { |
| 3895 | if (bus->bus == SPI_BUS) { |
| 3896 | dhdsdio_read_control(bus, rxbuf, len, |
| 3897 | doff); |
| 3898 | if (bus->usebufpool) { |
| 3899 | dhd_os_sdlock_rxq(bus->dhd); |
| 3900 | PKTFREE(bus->dhd->osh, pkt, |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3901 | false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3902 | dhd_os_sdunlock_rxq(bus->dhd); |
| 3903 | } |
| 3904 | continue; |
| 3905 | } else { |
| 3906 | DHD_ERROR(("%s (nextlen): readahead on control" " packet %d?\n", |
| 3907 | __func__, seq)); |
| 3908 | /* Force retry w/normal header read */ |
| 3909 | bus->nextlen = 0; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3910 | dhdsdio_rxfail(bus, false, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3911 | dhd_os_sdlock_rxq(bus->dhd); |
| 3912 | PKTFREE2(); |
| 3913 | dhd_os_sdunlock_rxq(bus->dhd); |
| 3914 | continue; |
| 3915 | } |
| 3916 | } |
| 3917 | |
| 3918 | if ((bus->bus == SPI_BUS) && !bus->usebufpool) { |
| 3919 | DHD_ERROR(("Received %d bytes on %d channel. Running out of " "rx pktbuf's or not yet malloced.\n", |
| 3920 | len, chan)); |
| 3921 | continue; |
| 3922 | } |
| 3923 | |
| 3924 | /* Validate data offset */ |
| 3925 | if ((doff < SDPCM_HDRLEN) || (doff > len)) { |
| 3926 | DHD_ERROR(("%s (nextlen): bad data offset %d: HW len %d min %d\n", |
| 3927 | __func__, doff, len, SDPCM_HDRLEN)); |
| 3928 | dhd_os_sdlock_rxq(bus->dhd); |
| 3929 | PKTFREE2(); |
| 3930 | dhd_os_sdunlock_rxq(bus->dhd); |
| 3931 | ASSERT(0); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3932 | dhdsdio_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3933 | continue; |
| 3934 | } |
| 3935 | |
| 3936 | /* All done with this one -- now deliver the packet */ |
| 3937 | goto deliver; |
| 3938 | } |
| 3939 | /* gSPI frames should not be handled in fractions */ |
| 3940 | if (bus->bus == SPI_BUS) |
| 3941 | break; |
| 3942 | |
| 3943 | /* Read frame header (hardware and software) */ |
| 3944 | sdret = |
| 3945 | dhd_bcmsdh_recv_buf(bus, bcmsdh_cur_sbwad(sdh), SDIO_FUNC_2, |
| 3946 | F2SYNC, bus->rxhdr, firstread, NULL, |
| 3947 | NULL, NULL); |
| 3948 | bus->f2rxhdrs++; |
| 3949 | ASSERT(sdret != BCME_PENDING); |
| 3950 | |
| 3951 | if (sdret < 0) { |
| 3952 | DHD_ERROR(("%s: RXHEADER FAILED: %d\n", __func__, |
| 3953 | sdret)); |
| 3954 | bus->rx_hdrfail++; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3955 | dhdsdio_rxfail(bus, true, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3956 | continue; |
| 3957 | } |
| 3958 | #ifdef DHD_DEBUG |
| 3959 | if (DHD_BYTES_ON() || DHD_HDRS_ON()) |
| 3960 | prhex("RxHdr", bus->rxhdr, SDPCM_HDRLEN); |
| 3961 | #endif |
| 3962 | |
| 3963 | /* Extract hardware header fields */ |
| 3964 | len = ltoh16_ua(bus->rxhdr); |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3965 | check = ltoh16_ua(bus->rxhdr + sizeof(u16)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3966 | |
| 3967 | /* All zeros means no more frames */ |
| 3968 | if (!(len | check)) { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3969 | *finished = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3970 | break; |
| 3971 | } |
| 3972 | |
| 3973 | /* Validate check bytes */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3974 | if ((u16) ~(len ^ check)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3975 | DHD_ERROR(("%s: HW hdr err: len/check 0x%04x/0x%04x\n", |
| 3976 | __func__, len, check)); |
| 3977 | bus->rx_badhdr++; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3978 | dhdsdio_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3979 | continue; |
| 3980 | } |
| 3981 | |
| 3982 | /* Validate frame length */ |
| 3983 | if (len < SDPCM_HDRLEN) { |
| 3984 | DHD_ERROR(("%s: HW hdr length invalid: %d\n", |
| 3985 | __func__, len)); |
| 3986 | continue; |
| 3987 | } |
| 3988 | |
| 3989 | /* Extract software header fields */ |
| 3990 | chan = SDPCM_PACKET_CHANNEL(&bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 3991 | seq = SDPCM_PACKET_SEQUENCE(&bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 3992 | doff = SDPCM_DOFFSET_VALUE(&bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 3993 | txmax = SDPCM_WINDOW_VALUE(&bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 3994 | |
| 3995 | /* Validate data offset */ |
| 3996 | if ((doff < SDPCM_HDRLEN) || (doff > len)) { |
| 3997 | DHD_ERROR(("%s: Bad data offset %d: HW len %d, min %d " |
| 3998 | "seq %d\n", |
| 3999 | __func__, doff, len, SDPCM_HDRLEN, seq)); |
| 4000 | bus->rx_badhdr++; |
| 4001 | ASSERT(0); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4002 | dhdsdio_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4003 | continue; |
| 4004 | } |
| 4005 | |
| 4006 | /* Save the readahead length if there is one */ |
| 4007 | bus->nextlen = |
| 4008 | bus->rxhdr[SDPCM_FRAMETAG_LEN + SDPCM_NEXTLEN_OFFSET]; |
| 4009 | if ((bus->nextlen << 4) > MAX_RX_DATASZ) { |
| 4010 | DHD_INFO(("%s (nextlen): got frame w/nextlen too large " |
| 4011 | "(%d), seq %d\n", |
| 4012 | __func__, bus->nextlen, seq)); |
| 4013 | bus->nextlen = 0; |
| 4014 | } |
| 4015 | |
| 4016 | /* Handle Flow Control */ |
| 4017 | fcbits = SDPCM_FCMASK_VALUE(&bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 4018 | |
| 4019 | delta = 0; |
| 4020 | if (~bus->flowcontrol & fcbits) { |
| 4021 | bus->fc_xoff++; |
| 4022 | delta = 1; |
| 4023 | } |
| 4024 | if (bus->flowcontrol & ~fcbits) { |
| 4025 | bus->fc_xon++; |
| 4026 | delta = 1; |
| 4027 | } |
| 4028 | |
| 4029 | if (delta) { |
| 4030 | bus->fc_rcvd++; |
| 4031 | bus->flowcontrol = fcbits; |
| 4032 | } |
| 4033 | |
| 4034 | /* Check and update sequence number */ |
| 4035 | if (rxseq != seq) { |
| 4036 | DHD_INFO(("%s: rx_seq %d, expected %d\n", __func__, |
| 4037 | seq, rxseq)); |
| 4038 | bus->rx_badseq++; |
| 4039 | rxseq = seq; |
| 4040 | } |
| 4041 | |
| 4042 | /* Check window for sanity */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4043 | if ((u8) (txmax - bus->tx_seq) > 0x40) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4044 | DHD_ERROR(("%s: unlikely tx max %d with tx_seq %d\n", |
| 4045 | __func__, txmax, bus->tx_seq)); |
| 4046 | txmax = bus->tx_seq + 2; |
| 4047 | } |
| 4048 | bus->tx_max = txmax; |
| 4049 | |
| 4050 | /* Call a separate function for control frames */ |
| 4051 | if (chan == SDPCM_CONTROL_CHANNEL) { |
| 4052 | dhdsdio_read_control(bus, bus->rxhdr, len, doff); |
| 4053 | continue; |
| 4054 | } |
| 4055 | |
| 4056 | ASSERT((chan == SDPCM_DATA_CHANNEL) |
| 4057 | || (chan == SDPCM_EVENT_CHANNEL) |
| 4058 | || (chan == SDPCM_TEST_CHANNEL) |
| 4059 | || (chan == SDPCM_GLOM_CHANNEL)); |
| 4060 | |
| 4061 | /* Length to read */ |
| 4062 | rdlen = (len > firstread) ? (len - firstread) : 0; |
| 4063 | |
| 4064 | /* May pad read to blocksize for efficiency */ |
| 4065 | if (bus->roundup && bus->blocksize && |
| 4066 | (rdlen > bus->blocksize)) { |
| 4067 | pad = bus->blocksize - (rdlen % bus->blocksize); |
| 4068 | if ((pad <= bus->roundup) && (pad < bus->blocksize) && |
| 4069 | ((rdlen + pad + firstread) < MAX_RX_DATASZ)) |
| 4070 | rdlen += pad; |
| 4071 | } else if (rdlen % DHD_SDALIGN) { |
| 4072 | rdlen += DHD_SDALIGN - (rdlen % DHD_SDALIGN); |
| 4073 | } |
| 4074 | |
| 4075 | /* Satisfy length-alignment requirements */ |
| 4076 | if (forcealign && (rdlen & (ALIGNMENT - 1))) |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 4077 | rdlen = roundup(rdlen, ALIGNMENT); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4078 | |
| 4079 | if ((rdlen + firstread) > MAX_RX_DATASZ) { |
| 4080 | /* Too long -- skip this frame */ |
| 4081 | DHD_ERROR(("%s: too long: len %d rdlen %d\n", |
| 4082 | __func__, len, rdlen)); |
| 4083 | bus->dhd->rx_errors++; |
| 4084 | bus->rx_toolong++; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4085 | dhdsdio_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4086 | continue; |
| 4087 | } |
| 4088 | |
| 4089 | dhd_os_sdlock_rxq(bus->dhd); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4090 | pkt = PKTGET(osh, (rdlen + firstread + DHD_SDALIGN), false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4091 | if (!pkt) { |
| 4092 | /* Give up on data, request rtx of events */ |
| 4093 | DHD_ERROR(("%s: PKTGET failed: rdlen %d chan %d\n", |
| 4094 | __func__, rdlen, chan)); |
| 4095 | bus->dhd->rx_dropped++; |
| 4096 | dhd_os_sdunlock_rxq(bus->dhd); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4097 | dhdsdio_rxfail(bus, false, RETRYCHAN(chan)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4098 | continue; |
| 4099 | } |
| 4100 | dhd_os_sdunlock_rxq(bus->dhd); |
| 4101 | |
| 4102 | ASSERT(!PKTLINK(pkt)); |
| 4103 | |
| 4104 | /* Leave room for what we already read, and align remainder */ |
| 4105 | ASSERT(firstread < (PKTLEN(pkt))); |
| 4106 | PKTPULL(pkt, firstread); |
| 4107 | PKTALIGN(osh, pkt, rdlen, DHD_SDALIGN); |
| 4108 | |
| 4109 | /* Read the remaining frame data */ |
| 4110 | sdret = |
| 4111 | dhd_bcmsdh_recv_buf(bus, bcmsdh_cur_sbwad(sdh), SDIO_FUNC_2, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4112 | F2SYNC, ((u8 *) PKTDATA(pkt)), rdlen, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4113 | pkt, NULL, NULL); |
| 4114 | bus->f2rxdata++; |
| 4115 | ASSERT(sdret != BCME_PENDING); |
| 4116 | |
| 4117 | if (sdret < 0) { |
| 4118 | DHD_ERROR(("%s: read %d %s bytes failed: %d\n", |
| 4119 | __func__, rdlen, |
| 4120 | ((chan == |
| 4121 | SDPCM_EVENT_CHANNEL) ? "event" : ((chan == |
| 4122 | SDPCM_DATA_CHANNEL) |
| 4123 | ? "data" : "test")), |
| 4124 | sdret)); |
| 4125 | dhd_os_sdlock_rxq(bus->dhd); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4126 | PKTFREE(bus->dhd->osh, pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4127 | dhd_os_sdunlock_rxq(bus->dhd); |
| 4128 | bus->dhd->rx_errors++; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4129 | dhdsdio_rxfail(bus, true, RETRYCHAN(chan)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4130 | continue; |
| 4131 | } |
| 4132 | |
| 4133 | /* Copy the already-read portion */ |
| 4134 | PKTPUSH(pkt, firstread); |
| 4135 | bcopy(bus->rxhdr, PKTDATA(pkt), firstread); |
| 4136 | |
| 4137 | #ifdef DHD_DEBUG |
| 4138 | if (DHD_BYTES_ON() && DHD_DATA_ON()) |
| 4139 | prhex("Rx Data", PKTDATA(pkt), len); |
| 4140 | #endif |
| 4141 | |
| 4142 | deliver: |
| 4143 | /* Save superframe descriptor and allocate packet frame */ |
| 4144 | if (chan == SDPCM_GLOM_CHANNEL) { |
| 4145 | if (SDPCM_GLOMDESC(&bus->rxhdr[SDPCM_FRAMETAG_LEN])) { |
| 4146 | DHD_GLOM(("%s: glom descriptor, %d bytes:\n", |
| 4147 | __func__, len)); |
| 4148 | #ifdef DHD_DEBUG |
| 4149 | if (DHD_GLOM_ON()) { |
| 4150 | prhex("Glom Data", PKTDATA(pkt), len); |
| 4151 | } |
| 4152 | #endif |
| 4153 | PKTSETLEN(pkt, len); |
| 4154 | ASSERT(doff == SDPCM_HDRLEN); |
| 4155 | PKTPULL(pkt, SDPCM_HDRLEN); |
| 4156 | bus->glomd = pkt; |
| 4157 | } else { |
| 4158 | DHD_ERROR(("%s: glom superframe w/o " |
| 4159 | "descriptor!\n", __func__)); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4160 | dhdsdio_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4161 | } |
| 4162 | continue; |
| 4163 | } |
| 4164 | |
| 4165 | /* Fill in packet len and prio, deliver upward */ |
| 4166 | PKTSETLEN(pkt, len); |
| 4167 | PKTPULL(pkt, doff); |
| 4168 | |
| 4169 | #ifdef SDTEST |
| 4170 | /* Test channel packets are processed separately */ |
| 4171 | if (chan == SDPCM_TEST_CHANNEL) { |
| 4172 | dhdsdio_testrcv(bus, pkt, seq); |
| 4173 | continue; |
| 4174 | } |
| 4175 | #endif /* SDTEST */ |
| 4176 | |
| 4177 | if (PKTLEN(pkt) == 0) { |
| 4178 | dhd_os_sdlock_rxq(bus->dhd); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4179 | PKTFREE(bus->dhd->osh, pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4180 | dhd_os_sdunlock_rxq(bus->dhd); |
| 4181 | continue; |
| 4182 | } else if (dhd_prot_hdrpull(bus->dhd, &ifidx, pkt) != 0) { |
| 4183 | DHD_ERROR(("%s: rx protocol error\n", __func__)); |
| 4184 | dhd_os_sdlock_rxq(bus->dhd); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4185 | PKTFREE(bus->dhd->osh, pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4186 | dhd_os_sdunlock_rxq(bus->dhd); |
| 4187 | bus->dhd->rx_errors++; |
| 4188 | continue; |
| 4189 | } |
| 4190 | |
| 4191 | /* Unlock during rx call */ |
| 4192 | dhd_os_sdunlock(bus->dhd); |
| 4193 | dhd_rx_frame(bus->dhd, ifidx, pkt, 1); |
| 4194 | dhd_os_sdlock(bus->dhd); |
| 4195 | } |
| 4196 | rxcount = maxframes - rxleft; |
| 4197 | #ifdef DHD_DEBUG |
| 4198 | /* Message if we hit the limit */ |
| 4199 | if (!rxleft && !sdtest) |
| 4200 | DHD_DATA(("%s: hit rx limit of %d frames\n", __func__, |
| 4201 | maxframes)); |
| 4202 | else |
| 4203 | #endif /* DHD_DEBUG */ |
| 4204 | DHD_DATA(("%s: processed %d frames\n", __func__, rxcount)); |
| 4205 | /* Back off rxseq if awaiting rtx, update rx_seq */ |
| 4206 | if (bus->rxskip) |
| 4207 | rxseq--; |
| 4208 | bus->rx_seq = rxseq; |
| 4209 | |
| 4210 | return rxcount; |
| 4211 | } |
| 4212 | |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 4213 | static u32 dhdsdio_hostmail(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4214 | { |
| 4215 | sdpcmd_regs_t *regs = bus->regs; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 4216 | u32 intstatus = 0; |
| 4217 | u32 hmb_data; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4218 | u8 fcbits; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4219 | uint retries = 0; |
| 4220 | |
| 4221 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 4222 | |
| 4223 | /* Read mailbox data and ack that we did so */ |
| 4224 | R_SDREG(hmb_data, ®s->tohostmailboxdata, retries); |
| 4225 | if (retries <= retry_limit) |
| 4226 | W_SDREG(SMB_INT_ACK, ®s->tosbmailbox, retries); |
| 4227 | bus->f1regdata += 2; |
| 4228 | |
| 4229 | /* Dongle recomposed rx frames, accept them again */ |
| 4230 | if (hmb_data & HMB_DATA_NAKHANDLED) { |
| 4231 | DHD_INFO(("Dongle reports NAK handled, expect rtx of %d\n", |
| 4232 | bus->rx_seq)); |
| 4233 | if (!bus->rxskip) |
| 4234 | DHD_ERROR(("%s: unexpected NAKHANDLED!\n", __func__)); |
| 4235 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4236 | bus->rxskip = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4237 | intstatus |= I_HMB_FRAME_IND; |
| 4238 | } |
| 4239 | |
| 4240 | /* |
| 4241 | * DEVREADY does not occur with gSPI. |
| 4242 | */ |
| 4243 | if (hmb_data & (HMB_DATA_DEVREADY | HMB_DATA_FWREADY)) { |
| 4244 | bus->sdpcm_ver = |
| 4245 | (hmb_data & HMB_DATA_VERSION_MASK) >> |
| 4246 | HMB_DATA_VERSION_SHIFT; |
| 4247 | if (bus->sdpcm_ver != SDPCM_PROT_VERSION) |
| 4248 | DHD_ERROR(("Version mismatch, dongle reports %d, " |
| 4249 | "expecting %d\n", |
| 4250 | bus->sdpcm_ver, SDPCM_PROT_VERSION)); |
| 4251 | else |
| 4252 | DHD_INFO(("Dongle ready, protocol version %d\n", |
| 4253 | bus->sdpcm_ver)); |
| 4254 | } |
| 4255 | |
| 4256 | /* |
| 4257 | * Flow Control has been moved into the RX headers and this out of band |
| 4258 | * method isn't used any more. Leae this here for possibly |
| 4259 | * remaining backward |
| 4260 | * compatible with older dongles |
| 4261 | */ |
| 4262 | if (hmb_data & HMB_DATA_FC) { |
| 4263 | fcbits = |
| 4264 | (hmb_data & HMB_DATA_FCDATA_MASK) >> HMB_DATA_FCDATA_SHIFT; |
| 4265 | |
| 4266 | if (fcbits & ~bus->flowcontrol) |
| 4267 | bus->fc_xoff++; |
| 4268 | if (bus->flowcontrol & ~fcbits) |
| 4269 | bus->fc_xon++; |
| 4270 | |
| 4271 | bus->fc_rcvd++; |
| 4272 | bus->flowcontrol = fcbits; |
| 4273 | } |
| 4274 | |
| 4275 | /* Shouldn't be any others */ |
| 4276 | if (hmb_data & ~(HMB_DATA_DEVREADY | |
| 4277 | HMB_DATA_NAKHANDLED | |
| 4278 | HMB_DATA_FC | |
| 4279 | HMB_DATA_FWREADY | |
| 4280 | HMB_DATA_FCDATA_MASK | HMB_DATA_VERSION_MASK)) { |
| 4281 | DHD_ERROR(("Unknown mailbox data content: 0x%02x\n", hmb_data)); |
| 4282 | } |
| 4283 | |
| 4284 | return intstatus; |
| 4285 | } |
| 4286 | |
| 4287 | bool dhdsdio_dpc(dhd_bus_t *bus) |
| 4288 | { |
| 4289 | bcmsdh_info_t *sdh = bus->sdh; |
| 4290 | sdpcmd_regs_t *regs = bus->regs; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 4291 | u32 intstatus, newstatus = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4292 | uint retries = 0; |
| 4293 | uint rxlimit = dhd_rxbound; /* Rx frames to read before resched */ |
| 4294 | uint txlimit = dhd_txbound; /* Tx frames to send before resched */ |
| 4295 | uint framecnt = 0; /* Temporary counter of tx/rx frames */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4296 | bool rxdone = true; /* Flag for no more read data */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4297 | bool resched = false; /* Flag indicating resched wanted */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4298 | |
| 4299 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 4300 | |
| 4301 | /* Start with leftover status bits */ |
| 4302 | intstatus = bus->intstatus; |
| 4303 | |
| 4304 | dhd_os_sdlock(bus->dhd); |
| 4305 | |
| 4306 | /* If waiting for HTAVAIL, check status */ |
| 4307 | if (bus->clkstate == CLK_PENDING) { |
| 4308 | int err; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4309 | u8 clkctl, devctl = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4310 | |
| 4311 | #ifdef DHD_DEBUG |
| 4312 | /* Check for inconsistent device control */ |
| 4313 | devctl = |
| 4314 | bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL, &err); |
| 4315 | if (err) { |
| 4316 | DHD_ERROR(("%s: error reading DEVCTL: %d\n", |
| 4317 | __func__, err)); |
| 4318 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 4319 | } else { |
| 4320 | ASSERT(devctl & SBSDIO_DEVCTL_CA_INT_ONLY); |
| 4321 | } |
| 4322 | #endif /* DHD_DEBUG */ |
| 4323 | |
| 4324 | /* Read CSR, if clock on switch to AVAIL, else ignore */ |
| 4325 | clkctl = |
| 4326 | bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 4327 | &err); |
| 4328 | if (err) { |
| 4329 | DHD_ERROR(("%s: error reading CSR: %d\n", __func__, |
| 4330 | err)); |
| 4331 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 4332 | } |
| 4333 | |
| 4334 | DHD_INFO(("DPC: PENDING, devctl 0x%02x clkctl 0x%02x\n", devctl, |
| 4335 | clkctl)); |
| 4336 | |
| 4337 | if (SBSDIO_HTAV(clkctl)) { |
| 4338 | devctl = |
| 4339 | bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL, |
| 4340 | &err); |
| 4341 | if (err) { |
| 4342 | DHD_ERROR(("%s: error reading DEVCTL: %d\n", |
| 4343 | __func__, err)); |
| 4344 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 4345 | } |
| 4346 | devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY; |
| 4347 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL, |
| 4348 | devctl, &err); |
| 4349 | if (err) { |
| 4350 | DHD_ERROR(("%s: error writing DEVCTL: %d\n", |
| 4351 | __func__, err)); |
| 4352 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 4353 | } |
| 4354 | bus->clkstate = CLK_AVAIL; |
| 4355 | } else { |
| 4356 | goto clkwait; |
| 4357 | } |
| 4358 | } |
| 4359 | |
| 4360 | BUS_WAKE(bus); |
| 4361 | |
| 4362 | /* Make sure backplane clock is on */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4363 | dhdsdio_clkctl(bus, CLK_AVAIL, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4364 | if (bus->clkstate == CLK_PENDING) |
| 4365 | goto clkwait; |
| 4366 | |
| 4367 | /* Pending interrupt indicates new device status */ |
| 4368 | if (bus->ipend) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4369 | bus->ipend = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4370 | R_SDREG(newstatus, ®s->intstatus, retries); |
| 4371 | bus->f1regdata++; |
| 4372 | if (bcmsdh_regfail(bus->sdh)) |
| 4373 | newstatus = 0; |
| 4374 | newstatus &= bus->hostintmask; |
| 4375 | bus->fcstate = !!(newstatus & I_HMB_FC_STATE); |
| 4376 | if (newstatus) { |
| 4377 | W_SDREG(newstatus, ®s->intstatus, retries); |
| 4378 | bus->f1regdata++; |
| 4379 | } |
| 4380 | } |
| 4381 | |
| 4382 | /* Merge new bits with previous */ |
| 4383 | intstatus |= newstatus; |
| 4384 | bus->intstatus = 0; |
| 4385 | |
| 4386 | /* Handle flow-control change: read new state in case our ack |
| 4387 | * crossed another change interrupt. If change still set, assume |
| 4388 | * FC ON for safety, let next loop through do the debounce. |
| 4389 | */ |
| 4390 | if (intstatus & I_HMB_FC_CHANGE) { |
| 4391 | intstatus &= ~I_HMB_FC_CHANGE; |
| 4392 | W_SDREG(I_HMB_FC_CHANGE, ®s->intstatus, retries); |
| 4393 | R_SDREG(newstatus, ®s->intstatus, retries); |
| 4394 | bus->f1regdata += 2; |
| 4395 | bus->fcstate = |
| 4396 | !!(newstatus & (I_HMB_FC_STATE | I_HMB_FC_CHANGE)); |
| 4397 | intstatus |= (newstatus & bus->hostintmask); |
| 4398 | } |
| 4399 | |
| 4400 | /* Handle host mailbox indication */ |
| 4401 | if (intstatus & I_HMB_HOST_INT) { |
| 4402 | intstatus &= ~I_HMB_HOST_INT; |
| 4403 | intstatus |= dhdsdio_hostmail(bus); |
| 4404 | } |
| 4405 | |
| 4406 | /* Generally don't ask for these, can get CRC errors... */ |
| 4407 | if (intstatus & I_WR_OOSYNC) { |
| 4408 | DHD_ERROR(("Dongle reports WR_OOSYNC\n")); |
| 4409 | intstatus &= ~I_WR_OOSYNC; |
| 4410 | } |
| 4411 | |
| 4412 | if (intstatus & I_RD_OOSYNC) { |
| 4413 | DHD_ERROR(("Dongle reports RD_OOSYNC\n")); |
| 4414 | intstatus &= ~I_RD_OOSYNC; |
| 4415 | } |
| 4416 | |
| 4417 | if (intstatus & I_SBINT) { |
| 4418 | DHD_ERROR(("Dongle reports SBINT\n")); |
| 4419 | intstatus &= ~I_SBINT; |
| 4420 | } |
| 4421 | |
| 4422 | /* Would be active due to wake-wlan in gSPI */ |
| 4423 | if (intstatus & I_CHIPACTIVE) { |
| 4424 | DHD_INFO(("Dongle reports CHIPACTIVE\n")); |
| 4425 | intstatus &= ~I_CHIPACTIVE; |
| 4426 | } |
| 4427 | |
| 4428 | /* Ignore frame indications if rxskip is set */ |
| 4429 | if (bus->rxskip) |
| 4430 | intstatus &= ~I_HMB_FRAME_IND; |
| 4431 | |
| 4432 | /* On frame indication, read available frames */ |
| 4433 | if (PKT_AVAILABLE()) { |
| 4434 | framecnt = dhdsdio_readframes(bus, rxlimit, &rxdone); |
| 4435 | if (rxdone || bus->rxskip) |
| 4436 | intstatus &= ~I_HMB_FRAME_IND; |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 4437 | rxlimit -= min(framecnt, rxlimit); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4438 | } |
| 4439 | |
| 4440 | /* Keep still-pending events for next scheduling */ |
| 4441 | bus->intstatus = intstatus; |
| 4442 | |
| 4443 | clkwait: |
| 4444 | #if defined(OOB_INTR_ONLY) |
| 4445 | bcmsdh_oob_intr_set(1); |
| 4446 | #endif /* (OOB_INTR_ONLY) */ |
| 4447 | /* Re-enable interrupts to detect new device events (mailbox, rx frame) |
| 4448 | * or clock availability. (Allows tx loop to check ipend if desired.) |
| 4449 | * (Unless register access seems hosed, as we may not be able to ACK...) |
| 4450 | */ |
| 4451 | if (bus->intr && bus->intdis && !bcmsdh_regfail(sdh)) { |
| 4452 | DHD_INTR(("%s: enable SDIO interrupts, rxdone %d framecnt %d\n", |
| 4453 | __func__, rxdone, framecnt)); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4454 | bus->intdis = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4455 | bcmsdh_intr_enable(sdh); |
| 4456 | } |
| 4457 | |
| 4458 | if (DATAOK(bus) && bus->ctrl_frame_stat && |
| 4459 | (bus->clkstate == CLK_AVAIL)) { |
| 4460 | int ret, i; |
| 4461 | |
| 4462 | ret = |
| 4463 | 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] | 4464 | F2SYNC, (u8 *) bus->ctrl_frame_buf, |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 4465 | (u32) bus->ctrl_frame_len, NULL, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4466 | NULL, NULL); |
| 4467 | ASSERT(ret != BCME_PENDING); |
| 4468 | |
| 4469 | if (ret < 0) { |
| 4470 | /* On failure, abort the command and |
| 4471 | terminate the frame */ |
| 4472 | DHD_INFO(("%s: sdio error %d, abort command and " |
| 4473 | "terminate frame.\n", __func__, ret)); |
| 4474 | bus->tx_sderrs++; |
| 4475 | |
| 4476 | bcmsdh_abort(sdh, SDIO_FUNC_2); |
| 4477 | |
| 4478 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, |
| 4479 | SBSDIO_FUNC1_FRAMECTRL, SFC_WF_TERM, |
| 4480 | NULL); |
| 4481 | bus->f1regdata++; |
| 4482 | |
| 4483 | for (i = 0; i < 3; i++) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4484 | u8 hi, lo; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4485 | hi = bcmsdh_cfg_read(sdh, SDIO_FUNC_1, |
| 4486 | SBSDIO_FUNC1_WFRAMEBCHI, |
| 4487 | NULL); |
| 4488 | lo = bcmsdh_cfg_read(sdh, SDIO_FUNC_1, |
| 4489 | SBSDIO_FUNC1_WFRAMEBCLO, |
| 4490 | NULL); |
| 4491 | bus->f1regdata += 2; |
| 4492 | if ((hi == 0) && (lo == 0)) |
| 4493 | break; |
| 4494 | } |
| 4495 | |
| 4496 | } |
| 4497 | if (ret == 0) |
| 4498 | bus->tx_seq = (bus->tx_seq + 1) % SDPCM_SEQUENCE_WRAP; |
| 4499 | |
| 4500 | printf("Return_dpc value is : %d\n", ret); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4501 | bus->ctrl_frame_stat = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4502 | dhd_wait_event_wakeup(bus->dhd); |
| 4503 | } |
| 4504 | /* Send queued frames (limit 1 if rx may still be pending) */ |
| 4505 | else if ((bus->clkstate == CLK_AVAIL) && !bus->fcstate && |
| 4506 | pktq_mlen(&bus->txq, ~bus->flowcontrol) && txlimit |
| 4507 | && DATAOK(bus)) { |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 4508 | framecnt = rxdone ? txlimit : min(txlimit, dhd_txminmax); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4509 | framecnt = dhdsdio_sendfromq(bus, framecnt); |
| 4510 | txlimit -= framecnt; |
| 4511 | } |
| 4512 | |
| 4513 | /* Resched if events or tx frames are pending, |
| 4514 | else await next interrupt */ |
| 4515 | /* On failed register access, all bets are off: |
| 4516 | no resched or interrupts */ |
| 4517 | if ((bus->dhd->busstate == DHD_BUS_DOWN) || bcmsdh_regfail(sdh)) { |
| 4518 | DHD_ERROR(("%s: failed backplane access over SDIO, halting " |
| 4519 | "operation %d\n", __func__, bcmsdh_regfail(sdh))); |
| 4520 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 4521 | bus->intstatus = 0; |
| 4522 | } else if (bus->clkstate == CLK_PENDING) { |
| 4523 | DHD_INFO(("%s: rescheduled due to CLK_PENDING awaiting " |
| 4524 | "I_CHIPACTIVE interrupt\n", __func__)); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4525 | resched = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4526 | } else if (bus->intstatus || bus->ipend || |
| 4527 | (!bus->fcstate && pktq_mlen(&bus->txq, ~bus->flowcontrol) && |
| 4528 | DATAOK(bus)) || PKT_AVAILABLE()) { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4529 | resched = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4530 | } |
| 4531 | |
| 4532 | bus->dpc_sched = resched; |
| 4533 | |
| 4534 | /* If we're done for now, turn off clock request. */ |
| 4535 | if ((bus->clkstate != CLK_PENDING) |
| 4536 | && bus->idletime == DHD_IDLE_IMMEDIATE) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4537 | bus->activity = false; |
| 4538 | dhdsdio_clkctl(bus, CLK_NONE, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4539 | } |
| 4540 | |
| 4541 | dhd_os_sdunlock(bus->dhd); |
| 4542 | |
| 4543 | return resched; |
| 4544 | } |
| 4545 | |
| 4546 | bool dhd_bus_dpc(struct dhd_bus *bus) |
| 4547 | { |
| 4548 | bool resched; |
| 4549 | |
| 4550 | /* Call the DPC directly. */ |
| 4551 | DHD_TRACE(("Calling dhdsdio_dpc() from %s\n", __func__)); |
| 4552 | resched = dhdsdio_dpc(bus); |
| 4553 | |
| 4554 | return resched; |
| 4555 | } |
| 4556 | |
| 4557 | void dhdsdio_isr(void *arg) |
| 4558 | { |
| 4559 | dhd_bus_t *bus = (dhd_bus_t *) arg; |
| 4560 | bcmsdh_info_t *sdh; |
| 4561 | |
| 4562 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 4563 | |
| 4564 | if (!bus) { |
| 4565 | DHD_ERROR(("%s : bus is null pointer , exit\n", __func__)); |
| 4566 | return; |
| 4567 | } |
| 4568 | sdh = bus->sdh; |
| 4569 | |
| 4570 | if (bus->dhd->busstate == DHD_BUS_DOWN) { |
| 4571 | DHD_ERROR(("%s : bus is down. we have nothing to do\n", |
| 4572 | __func__)); |
| 4573 | return; |
| 4574 | } |
| 4575 | /* Count the interrupt call */ |
| 4576 | bus->intrcount++; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4577 | bus->ipend = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4578 | |
| 4579 | /* Shouldn't get this interrupt if we're sleeping? */ |
| 4580 | if (bus->sleeping) { |
| 4581 | DHD_ERROR(("INTERRUPT WHILE SLEEPING??\n")); |
| 4582 | return; |
| 4583 | } |
| 4584 | |
| 4585 | /* Disable additional interrupts (is this needed now)? */ |
| 4586 | if (bus->intr) |
| 4587 | DHD_INTR(("%s: disable SDIO interrupts\n", __func__)); |
| 4588 | else |
| 4589 | DHD_ERROR(("dhdsdio_isr() w/o interrupt configured!\n")); |
| 4590 | |
| 4591 | bcmsdh_intr_disable(sdh); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4592 | bus->intdis = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4593 | |
| 4594 | #if defined(SDIO_ISR_THREAD) |
| 4595 | DHD_TRACE(("Calling dhdsdio_dpc() from %s\n", __func__)); |
| 4596 | while (dhdsdio_dpc(bus)) |
| 4597 | ; |
| 4598 | #else |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4599 | bus->dpc_sched = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4600 | dhd_sched_dpc(bus->dhd); |
| 4601 | #endif |
| 4602 | |
| 4603 | } |
| 4604 | |
| 4605 | #ifdef SDTEST |
| 4606 | static void dhdsdio_pktgen_init(dhd_bus_t *bus) |
| 4607 | { |
| 4608 | /* Default to specified length, or full range */ |
| 4609 | if (dhd_pktgen_len) { |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 4610 | bus->pktgen_maxlen = min(dhd_pktgen_len, MAX_PKTGEN_LEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4611 | bus->pktgen_minlen = bus->pktgen_maxlen; |
| 4612 | } else { |
| 4613 | bus->pktgen_maxlen = MAX_PKTGEN_LEN; |
| 4614 | bus->pktgen_minlen = 0; |
| 4615 | } |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4616 | bus->pktgen_len = (u16) bus->pktgen_minlen; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4617 | |
| 4618 | /* Default to per-watchdog burst with 10s print time */ |
| 4619 | bus->pktgen_freq = 1; |
| 4620 | bus->pktgen_print = 10000 / dhd_watchdog_ms; |
| 4621 | bus->pktgen_count = (dhd_pktgen * dhd_watchdog_ms + 999) / 1000; |
| 4622 | |
| 4623 | /* Default to echo mode */ |
| 4624 | bus->pktgen_mode = DHD_PKTGEN_ECHO; |
| 4625 | bus->pktgen_stop = 1; |
| 4626 | } |
| 4627 | |
| 4628 | static void dhdsdio_pktgen(dhd_bus_t *bus) |
| 4629 | { |
| 4630 | void *pkt; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4631 | u8 *data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4632 | uint pktcount; |
| 4633 | uint fillbyte; |
| 4634 | osl_t *osh = bus->dhd->osh; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4635 | u16 len; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4636 | |
| 4637 | /* Display current count if appropriate */ |
| 4638 | if (bus->pktgen_print && (++bus->pktgen_ptick >= bus->pktgen_print)) { |
| 4639 | bus->pktgen_ptick = 0; |
| 4640 | printf("%s: send attempts %d rcvd %d\n", |
| 4641 | __func__, bus->pktgen_sent, bus->pktgen_rcvd); |
| 4642 | } |
| 4643 | |
| 4644 | /* For recv mode, just make sure dongle has started sending */ |
| 4645 | if (bus->pktgen_mode == DHD_PKTGEN_RECV) { |
| 4646 | if (!bus->pktgen_rcvd) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4647 | dhdsdio_sdtest_set(bus, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4648 | return; |
| 4649 | } |
| 4650 | |
| 4651 | /* Otherwise, generate or request the specified number of packets */ |
| 4652 | for (pktcount = 0; pktcount < bus->pktgen_count; pktcount++) { |
| 4653 | /* Stop if total has been reached */ |
| 4654 | if (bus->pktgen_total |
| 4655 | && (bus->pktgen_sent >= bus->pktgen_total)) { |
| 4656 | bus->pktgen_count = 0; |
| 4657 | break; |
| 4658 | } |
| 4659 | |
| 4660 | /* Allocate an appropriate-sized packet */ |
| 4661 | len = bus->pktgen_len; |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 4662 | pkt = PKTGET(osh, |
| 4663 | (len + SDPCM_HDRLEN + SDPCM_TEST_HDRLEN + DHD_SDALIGN), |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4664 | true); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 4665 | if (!pkt) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4666 | DHD_ERROR(("%s: PKTGET failed!\n", __func__)); |
| 4667 | break; |
| 4668 | } |
| 4669 | PKTALIGN(osh, pkt, (len + SDPCM_HDRLEN + SDPCM_TEST_HDRLEN), |
| 4670 | DHD_SDALIGN); |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4671 | data = (u8 *) PKTDATA(pkt) + SDPCM_HDRLEN; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4672 | |
| 4673 | /* Write test header cmd and extra based on mode */ |
| 4674 | switch (bus->pktgen_mode) { |
| 4675 | case DHD_PKTGEN_ECHO: |
| 4676 | *data++ = SDPCM_TEST_ECHOREQ; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4677 | *data++ = (u8) bus->pktgen_sent; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4678 | break; |
| 4679 | |
| 4680 | case DHD_PKTGEN_SEND: |
| 4681 | *data++ = SDPCM_TEST_DISCARD; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4682 | *data++ = (u8) bus->pktgen_sent; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4683 | break; |
| 4684 | |
| 4685 | case DHD_PKTGEN_RXBURST: |
| 4686 | *data++ = SDPCM_TEST_BURST; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4687 | *data++ = (u8) bus->pktgen_count; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4688 | break; |
| 4689 | |
| 4690 | default: |
| 4691 | DHD_ERROR(("Unrecognized pktgen mode %d\n", |
| 4692 | bus->pktgen_mode)); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4693 | PKTFREE(osh, pkt, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4694 | bus->pktgen_count = 0; |
| 4695 | return; |
| 4696 | } |
| 4697 | |
| 4698 | /* Write test header length field */ |
| 4699 | *data++ = (len >> 0); |
| 4700 | *data++ = (len >> 8); |
| 4701 | |
| 4702 | /* Then fill in the remainder -- N/A for burst, |
| 4703 | but who cares... */ |
| 4704 | for (fillbyte = 0; fillbyte < len; fillbyte++) |
| 4705 | *data++ = |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4706 | SDPCM_TEST_FILL(fillbyte, (u8) bus->pktgen_sent); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4707 | |
| 4708 | #ifdef DHD_DEBUG |
| 4709 | if (DHD_BYTES_ON() && DHD_DATA_ON()) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4710 | data = (u8 *) PKTDATA(pkt) + SDPCM_HDRLEN; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4711 | prhex("dhdsdio_pktgen: Tx Data", data, |
| 4712 | PKTLEN(pkt) - SDPCM_HDRLEN); |
| 4713 | } |
| 4714 | #endif |
| 4715 | |
| 4716 | /* Send it */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4717 | if (dhdsdio_txpkt(bus, pkt, SDPCM_TEST_CHANNEL, true)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4718 | bus->pktgen_fail++; |
| 4719 | if (bus->pktgen_stop |
| 4720 | && bus->pktgen_stop == bus->pktgen_fail) |
| 4721 | bus->pktgen_count = 0; |
| 4722 | } |
| 4723 | bus->pktgen_sent++; |
| 4724 | |
| 4725 | /* Bump length if not fixed, wrap at max */ |
| 4726 | if (++bus->pktgen_len > bus->pktgen_maxlen) |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4727 | bus->pktgen_len = (u16) bus->pktgen_minlen; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4728 | |
| 4729 | /* Special case for burst mode: just send one request! */ |
| 4730 | if (bus->pktgen_mode == DHD_PKTGEN_RXBURST) |
| 4731 | break; |
| 4732 | } |
| 4733 | } |
| 4734 | |
| 4735 | static void dhdsdio_sdtest_set(dhd_bus_t *bus, bool start) |
| 4736 | { |
| 4737 | void *pkt; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4738 | u8 *data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4739 | osl_t *osh = bus->dhd->osh; |
| 4740 | |
| 4741 | /* Allocate the packet */ |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 4742 | pkt = PKTGET(osh, SDPCM_HDRLEN + SDPCM_TEST_HDRLEN + DHD_SDALIGN, |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4743 | true); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 4744 | if (!pkt) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4745 | DHD_ERROR(("%s: PKTGET failed!\n", __func__)); |
| 4746 | return; |
| 4747 | } |
| 4748 | PKTALIGN(osh, pkt, (SDPCM_HDRLEN + SDPCM_TEST_HDRLEN), DHD_SDALIGN); |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4749 | data = (u8 *) PKTDATA(pkt) + SDPCM_HDRLEN; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4750 | |
| 4751 | /* Fill in the test header */ |
| 4752 | *data++ = SDPCM_TEST_SEND; |
| 4753 | *data++ = start; |
| 4754 | *data++ = (bus->pktgen_maxlen >> 0); |
| 4755 | *data++ = (bus->pktgen_maxlen >> 8); |
| 4756 | |
| 4757 | /* Send it */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4758 | if (dhdsdio_txpkt(bus, pkt, SDPCM_TEST_CHANNEL, true)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4759 | bus->pktgen_fail++; |
| 4760 | } |
| 4761 | |
| 4762 | static void dhdsdio_testrcv(dhd_bus_t *bus, void *pkt, uint seq) |
| 4763 | { |
| 4764 | osl_t *osh = bus->dhd->osh; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4765 | u8 *data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4766 | uint pktlen; |
| 4767 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4768 | u8 cmd; |
| 4769 | u8 extra; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4770 | u16 len; |
| 4771 | u16 offset; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4772 | |
| 4773 | /* Check for min length */ |
| 4774 | pktlen = PKTLEN(pkt); |
| 4775 | if (pktlen < SDPCM_TEST_HDRLEN) { |
| 4776 | DHD_ERROR(("dhdsdio_restrcv: toss runt frame, pktlen %d\n", |
| 4777 | pktlen)); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4778 | PKTFREE(osh, pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4779 | return; |
| 4780 | } |
| 4781 | |
| 4782 | /* Extract header fields */ |
| 4783 | data = PKTDATA(pkt); |
| 4784 | cmd = *data++; |
| 4785 | extra = *data++; |
| 4786 | len = *data++; |
| 4787 | len += *data++ << 8; |
| 4788 | |
| 4789 | /* Check length for relevant commands */ |
| 4790 | if (cmd == SDPCM_TEST_DISCARD || cmd == SDPCM_TEST_ECHOREQ |
| 4791 | || cmd == SDPCM_TEST_ECHORSP) { |
| 4792 | if (pktlen != len + SDPCM_TEST_HDRLEN) { |
| 4793 | DHD_ERROR(("dhdsdio_testrcv: frame length mismatch, " |
| 4794 | "pktlen %d seq %d" " cmd %d extra %d len %d\n", |
| 4795 | pktlen, seq, cmd, extra, len)); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4796 | PKTFREE(osh, pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4797 | return; |
| 4798 | } |
| 4799 | } |
| 4800 | |
| 4801 | /* Process as per command */ |
| 4802 | switch (cmd) { |
| 4803 | case SDPCM_TEST_ECHOREQ: |
| 4804 | /* Rx->Tx turnaround ok (even on NDIS w/current |
| 4805 | implementation) */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4806 | *(u8 *) (PKTDATA(pkt)) = SDPCM_TEST_ECHORSP; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4807 | if (dhdsdio_txpkt(bus, pkt, SDPCM_TEST_CHANNEL, true) == 0) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4808 | bus->pktgen_sent++; |
| 4809 | } else { |
| 4810 | bus->pktgen_fail++; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4811 | PKTFREE(osh, pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4812 | } |
| 4813 | bus->pktgen_rcvd++; |
| 4814 | break; |
| 4815 | |
| 4816 | case SDPCM_TEST_ECHORSP: |
| 4817 | if (bus->ext_loop) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4818 | PKTFREE(osh, pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4819 | bus->pktgen_rcvd++; |
| 4820 | break; |
| 4821 | } |
| 4822 | |
| 4823 | for (offset = 0; offset < len; offset++, data++) { |
| 4824 | if (*data != SDPCM_TEST_FILL(offset, extra)) { |
| 4825 | DHD_ERROR(("dhdsdio_testrcv: echo data mismatch: " "offset %d (len %d) expect 0x%02x rcvd 0x%02x\n", |
| 4826 | offset, len, |
| 4827 | SDPCM_TEST_FILL(offset, extra), *data)); |
| 4828 | break; |
| 4829 | } |
| 4830 | } |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4831 | PKTFREE(osh, pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4832 | bus->pktgen_rcvd++; |
| 4833 | break; |
| 4834 | |
| 4835 | case SDPCM_TEST_DISCARD: |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4836 | PKTFREE(osh, pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4837 | bus->pktgen_rcvd++; |
| 4838 | break; |
| 4839 | |
| 4840 | case SDPCM_TEST_BURST: |
| 4841 | case SDPCM_TEST_SEND: |
| 4842 | default: |
| 4843 | DHD_INFO(("dhdsdio_testrcv: unsupported or unknown command, " |
| 4844 | "pktlen %d seq %d" " cmd %d extra %d len %d\n", |
| 4845 | pktlen, seq, cmd, extra, len)); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4846 | PKTFREE(osh, pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4847 | break; |
| 4848 | } |
| 4849 | |
| 4850 | /* For recv mode, stop at limie (and tell dongle to stop sending) */ |
| 4851 | if (bus->pktgen_mode == DHD_PKTGEN_RECV) { |
| 4852 | if (bus->pktgen_total |
| 4853 | && (bus->pktgen_rcvd >= bus->pktgen_total)) { |
| 4854 | bus->pktgen_count = 0; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4855 | dhdsdio_sdtest_set(bus, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4856 | } |
| 4857 | } |
| 4858 | } |
| 4859 | #endif /* SDTEST */ |
| 4860 | |
| 4861 | extern bool dhd_bus_watchdog(dhd_pub_t *dhdp) |
| 4862 | { |
| 4863 | dhd_bus_t *bus; |
| 4864 | |
| 4865 | DHD_TIMER(("%s: Enter\n", __func__)); |
| 4866 | |
| 4867 | bus = dhdp->bus; |
| 4868 | |
| 4869 | if (bus->dhd->dongle_reset) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4870 | return false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4871 | |
| 4872 | /* Ignore the timer if simulating bus down */ |
| 4873 | if (bus->sleeping) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4874 | return false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4875 | |
| 4876 | dhd_os_sdlock(bus->dhd); |
| 4877 | |
| 4878 | /* Poll period: check device if appropriate. */ |
| 4879 | if (bus->poll && (++bus->polltick >= bus->pollrate)) { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 4880 | u32 intstatus = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4881 | |
| 4882 | /* Reset poll tick */ |
| 4883 | bus->polltick = 0; |
| 4884 | |
| 4885 | /* Check device if no interrupts */ |
| 4886 | if (!bus->intr || (bus->intrcount == bus->lastintrs)) { |
| 4887 | |
| 4888 | if (!bus->dpc_sched) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4889 | u8 devpend; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4890 | devpend = bcmsdh_cfg_read(bus->sdh, SDIO_FUNC_0, |
| 4891 | SDIOD_CCCR_INTPEND, |
| 4892 | NULL); |
| 4893 | intstatus = |
| 4894 | devpend & (INTR_STATUS_FUNC1 | |
| 4895 | INTR_STATUS_FUNC2); |
| 4896 | } |
| 4897 | |
| 4898 | /* If there is something, make like the ISR and |
| 4899 | schedule the DPC */ |
| 4900 | if (intstatus) { |
| 4901 | bus->pollcnt++; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4902 | bus->ipend = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4903 | if (bus->intr) |
| 4904 | bcmsdh_intr_disable(bus->sdh); |
| 4905 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4906 | bus->dpc_sched = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4907 | dhd_sched_dpc(bus->dhd); |
| 4908 | |
| 4909 | } |
| 4910 | } |
| 4911 | |
| 4912 | /* Update interrupt tracking */ |
| 4913 | bus->lastintrs = bus->intrcount; |
| 4914 | } |
| 4915 | #ifdef DHD_DEBUG |
| 4916 | /* Poll for console output periodically */ |
| 4917 | if (dhdp->busstate == DHD_BUS_DATA && dhd_console_ms != 0) { |
| 4918 | bus->console.count += dhd_watchdog_ms; |
| 4919 | if (bus->console.count >= dhd_console_ms) { |
| 4920 | bus->console.count -= dhd_console_ms; |
| 4921 | /* Make sure backplane clock is on */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4922 | dhdsdio_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4923 | if (dhdsdio_readconsole(bus) < 0) |
| 4924 | dhd_console_ms = 0; /* On error, |
| 4925 | stop trying */ |
| 4926 | } |
| 4927 | } |
| 4928 | #endif /* DHD_DEBUG */ |
| 4929 | |
| 4930 | #ifdef SDTEST |
| 4931 | /* Generate packets if configured */ |
| 4932 | if (bus->pktgen_count && (++bus->pktgen_tick >= bus->pktgen_freq)) { |
| 4933 | /* Make sure backplane clock is on */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4934 | dhdsdio_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4935 | bus->pktgen_tick = 0; |
| 4936 | dhdsdio_pktgen(bus); |
| 4937 | } |
| 4938 | #endif |
| 4939 | |
| 4940 | /* On idle timeout clear activity flag and/or turn off clock */ |
| 4941 | if ((bus->idletime > 0) && (bus->clkstate == CLK_AVAIL)) { |
| 4942 | if (++bus->idlecount >= bus->idletime) { |
| 4943 | bus->idlecount = 0; |
| 4944 | if (bus->activity) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4945 | bus->activity = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4946 | dhd_os_wd_timer(bus->dhd, dhd_watchdog_ms); |
| 4947 | } else { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4948 | dhdsdio_clkctl(bus, CLK_NONE, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4949 | } |
| 4950 | } |
| 4951 | } |
| 4952 | |
| 4953 | dhd_os_sdunlock(bus->dhd); |
| 4954 | |
| 4955 | return bus->ipend; |
| 4956 | } |
| 4957 | |
| 4958 | #ifdef DHD_DEBUG |
Greg Kroah-Hartman | 580a0bd | 2010-10-05 11:09:48 -0700 | [diff] [blame] | 4959 | 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] | 4960 | { |
| 4961 | dhd_bus_t *bus = dhdp->bus; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 4962 | u32 addr, val; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4963 | int rv; |
| 4964 | void *pkt; |
| 4965 | |
| 4966 | /* Address could be zero if CONSOLE := 0 in dongle Makefile */ |
| 4967 | if (bus->console_addr == 0) |
| 4968 | return BCME_UNSUPPORTED; |
| 4969 | |
| 4970 | /* Exclusive bus access */ |
| 4971 | dhd_os_sdlock(bus->dhd); |
| 4972 | |
| 4973 | /* Don't allow input if dongle is in reset */ |
| 4974 | if (bus->dhd->dongle_reset) { |
| 4975 | dhd_os_sdunlock(bus->dhd); |
| 4976 | return BCME_NOTREADY; |
| 4977 | } |
| 4978 | |
| 4979 | /* Request clock to allow SDIO accesses */ |
| 4980 | BUS_WAKE(bus); |
| 4981 | /* 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] | 4982 | dhdsdio_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4983 | |
| 4984 | /* Zero cbuf_index */ |
Greg Kroah-Hartman | ce0f1b8 | 2010-10-08 11:44:45 -0700 | [diff] [blame] | 4985 | addr = bus->console_addr + offsetof(hndrte_cons_t, cbuf_idx); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4986 | val = htol32(0); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4987 | rv = dhdsdio_membytes(bus, true, addr, (u8 *)&val, sizeof(val)); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 4988 | if (rv < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4989 | goto done; |
| 4990 | |
| 4991 | /* Write message into cbuf */ |
Greg Kroah-Hartman | ce0f1b8 | 2010-10-08 11:44:45 -0700 | [diff] [blame] | 4992 | addr = bus->console_addr + offsetof(hndrte_cons_t, cbuf); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4993 | rv = dhdsdio_membytes(bus, true, addr, (u8 *)msg, msglen); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 4994 | if (rv < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4995 | goto done; |
| 4996 | |
| 4997 | /* Write length into vcons_in */ |
Greg Kroah-Hartman | ce0f1b8 | 2010-10-08 11:44:45 -0700 | [diff] [blame] | 4998 | addr = bus->console_addr + offsetof(hndrte_cons_t, vcons_in); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4999 | val = htol32(msglen); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5000 | rv = dhdsdio_membytes(bus, true, addr, (u8 *)&val, sizeof(val)); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5001 | if (rv < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5002 | goto done; |
| 5003 | |
| 5004 | /* Bump dongle by sending an empty event pkt. |
| 5005 | * sdpcm_sendup (RX) checks for virtual console input. |
| 5006 | */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5007 | pkt = PKTGET(bus->dhd->osh, 4 + SDPCM_RESERVE, true); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5008 | if ((pkt != NULL) && bus->clkstate == CLK_AVAIL) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5009 | dhdsdio_txpkt(bus, pkt, SDPCM_EVENT_CHANNEL, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5010 | |
| 5011 | done: |
| 5012 | if ((bus->idletime == DHD_IDLE_IMMEDIATE) && !bus->dpc_sched) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5013 | bus->activity = false; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5014 | dhdsdio_clkctl(bus, CLK_NONE, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5015 | } |
| 5016 | |
| 5017 | dhd_os_sdunlock(bus->dhd); |
| 5018 | |
| 5019 | return rv; |
| 5020 | } |
| 5021 | #endif /* DHD_DEBUG */ |
| 5022 | |
| 5023 | #ifdef DHD_DEBUG |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 5024 | static void dhd_dump_cis(uint fn, u8 *cis) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5025 | { |
| 5026 | uint byte, tag, tdata; |
| 5027 | DHD_INFO(("Function %d CIS:\n", fn)); |
| 5028 | |
| 5029 | for (tdata = byte = 0; byte < SBSDIO_CIS_SIZE_LIMIT; byte++) { |
| 5030 | if ((byte % 16) == 0) |
| 5031 | DHD_INFO((" ")); |
| 5032 | DHD_INFO(("%02x ", cis[byte])); |
| 5033 | if ((byte % 16) == 15) |
| 5034 | DHD_INFO(("\n")); |
| 5035 | if (!tdata--) { |
| 5036 | tag = cis[byte]; |
| 5037 | if (tag == 0xff) |
| 5038 | break; |
| 5039 | else if (!tag) |
| 5040 | tdata = 0; |
| 5041 | else if ((byte + 1) < SBSDIO_CIS_SIZE_LIMIT) |
| 5042 | tdata = cis[byte + 1] + 1; |
| 5043 | else |
| 5044 | DHD_INFO(("]")); |
| 5045 | } |
| 5046 | } |
| 5047 | if ((byte % 16) != 15) |
| 5048 | DHD_INFO(("\n")); |
| 5049 | } |
| 5050 | #endif /* DHD_DEBUG */ |
| 5051 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5052 | static bool dhdsdio_chipmatch(u16 chipid) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5053 | { |
| 5054 | if (chipid == BCM4325_CHIP_ID) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5055 | return true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5056 | if (chipid == BCM4329_CHIP_ID) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5057 | return true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5058 | if (chipid == BCM4319_CHIP_ID) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5059 | return true; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5060 | return false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5061 | } |
| 5062 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5063 | static void *dhdsdio_probe(u16 venid, u16 devid, u16 bus_no, |
| 5064 | u16 slot, u16 func, uint bustype, void *regsva, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5065 | osl_t *osh, void *sdh) |
| 5066 | { |
| 5067 | int ret; |
| 5068 | dhd_bus_t *bus; |
| 5069 | |
| 5070 | /* Init global variables at run-time, not as part of the declaration. |
| 5071 | * This is required to support init/de-init of the driver. |
| 5072 | * Initialization |
| 5073 | * of globals as part of the declaration results in non-deterministic |
| 5074 | * behavior since the value of the globals may be different on the |
| 5075 | * first time that the driver is initialized vs subsequent |
| 5076 | * initializations. |
| 5077 | */ |
| 5078 | dhd_txbound = DHD_TXBOUND; |
| 5079 | dhd_rxbound = DHD_RXBOUND; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5080 | dhd_alignctl = true; |
| 5081 | sd1idle = true; |
| 5082 | dhd_readahead = true; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5083 | retrydata = false; |
| 5084 | dhd_doflow = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5085 | dhd_dongle_memsize = 0; |
| 5086 | dhd_txminmax = DHD_TXMINMAX; |
| 5087 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5088 | forcealign = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5089 | |
| 5090 | dhd_common_init(); |
| 5091 | |
| 5092 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5093 | DHD_INFO(("%s: venid 0x%04x devid 0x%04x\n", __func__, venid, devid)); |
| 5094 | |
| 5095 | /* We make assumptions about address window mappings */ |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 5096 | ASSERT((unsigned long)regsva == SI_ENUM_BASE); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5097 | |
| 5098 | /* BCMSDH passes venid and devid based on CIS parsing -- but |
| 5099 | * low-power start |
| 5100 | * means early parse could fail, so here we should get either an ID |
| 5101 | * we recognize OR (-1) indicating we must request power first. |
| 5102 | */ |
| 5103 | /* Check the Vendor ID */ |
| 5104 | switch (venid) { |
| 5105 | case 0x0000: |
| 5106 | case VENDOR_BROADCOM: |
| 5107 | break; |
| 5108 | default: |
| 5109 | DHD_ERROR(("%s: unknown vendor: 0x%04x\n", __func__, venid)); |
| 5110 | return NULL; |
| 5111 | } |
| 5112 | |
| 5113 | /* Check the Device ID and make sure it's one that we support */ |
| 5114 | switch (devid) { |
| 5115 | case BCM4325_D11DUAL_ID: /* 4325 802.11a/g id */ |
| 5116 | case BCM4325_D11G_ID: /* 4325 802.11g 2.4Ghz band id */ |
| 5117 | case BCM4325_D11A_ID: /* 4325 802.11a 5Ghz band id */ |
| 5118 | DHD_INFO(("%s: found 4325 Dongle\n", __func__)); |
| 5119 | break; |
| 5120 | case BCM4329_D11NDUAL_ID: /* 4329 802.11n dualband device */ |
| 5121 | case BCM4329_D11N2G_ID: /* 4329 802.11n 2.4G device */ |
| 5122 | case BCM4329_D11N5G_ID: /* 4329 802.11n 5G device */ |
| 5123 | case 0x4329: |
| 5124 | DHD_INFO(("%s: found 4329 Dongle\n", __func__)); |
| 5125 | break; |
| 5126 | case BCM4319_D11N_ID: /* 4319 802.11n id */ |
| 5127 | case BCM4319_D11N2G_ID: /* 4319 802.11n2g id */ |
| 5128 | case BCM4319_D11N5G_ID: /* 4319 802.11n5g id */ |
| 5129 | DHD_INFO(("%s: found 4319 Dongle\n", __func__)); |
| 5130 | break; |
| 5131 | case 0: |
| 5132 | DHD_INFO(("%s: allow device id 0, will check chip internals\n", |
| 5133 | __func__)); |
| 5134 | break; |
| 5135 | |
| 5136 | default: |
| 5137 | DHD_ERROR(("%s: skipping 0x%04x/0x%04x, not a dongle\n", |
| 5138 | __func__, venid, devid)); |
| 5139 | return NULL; |
| 5140 | } |
| 5141 | |
| 5142 | if (osh == NULL) { |
| 5143 | /* Ask the OS interface part for an OSL handle */ |
| 5144 | osh = dhd_osl_attach(sdh, DHD_BUS); |
| 5145 | if (!osh) { |
| 5146 | DHD_ERROR(("%s: osl_attach failed!\n", __func__)); |
| 5147 | return NULL; |
| 5148 | } |
| 5149 | } |
| 5150 | |
| 5151 | /* Allocate private bus interface state */ |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5152 | bus = kzalloc(sizeof(dhd_bus_t), GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5153 | if (!bus) { |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5154 | DHD_ERROR(("%s: kmalloc of dhd_bus_t failed\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5155 | goto fail; |
| 5156 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5157 | bus->sdh = sdh; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5158 | bus->cl_devid = (u16) devid; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5159 | bus->bus = DHD_BUS; |
| 5160 | bus->tx_seq = SDPCM_SEQUENCE_WRAP - 1; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5161 | bus->usebufpool = false; /* Use bufpool if allocated, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5162 | else use locally malloced rxbuf */ |
| 5163 | |
| 5164 | /* attempt to attach to the dongle */ |
| 5165 | if (!(dhdsdio_probe_attach(bus, osh, sdh, regsva, devid))) { |
| 5166 | DHD_ERROR(("%s: dhdsdio_probe_attach failed\n", __func__)); |
| 5167 | goto fail; |
| 5168 | } |
| 5169 | |
| 5170 | /* Attach to the dhd/OS/network interface */ |
| 5171 | bus->dhd = dhd_attach(osh, bus, SDPCM_RESERVE); |
| 5172 | if (!bus->dhd) { |
| 5173 | DHD_ERROR(("%s: dhd_attach failed\n", __func__)); |
| 5174 | goto fail; |
| 5175 | } |
| 5176 | |
| 5177 | /* Allocate buffers */ |
| 5178 | if (!(dhdsdio_probe_malloc(bus, osh, sdh))) { |
| 5179 | DHD_ERROR(("%s: dhdsdio_probe_malloc failed\n", __func__)); |
| 5180 | goto fail; |
| 5181 | } |
| 5182 | |
| 5183 | if (!(dhdsdio_probe_init(bus, osh, sdh))) { |
| 5184 | DHD_ERROR(("%s: dhdsdio_probe_init failed\n", __func__)); |
| 5185 | goto fail; |
| 5186 | } |
| 5187 | |
| 5188 | /* Register interrupt callback, but mask it (not operational yet). */ |
| 5189 | DHD_INTR(("%s: disable SDIO interrupts (not interested yet)\n", |
| 5190 | __func__)); |
| 5191 | bcmsdh_intr_disable(sdh); |
| 5192 | ret = bcmsdh_intr_reg(sdh, dhdsdio_isr, bus); |
| 5193 | if (ret != 0) { |
| 5194 | DHD_ERROR(("%s: FAILED: bcmsdh_intr_reg returned %d\n", |
| 5195 | __func__, ret)); |
| 5196 | goto fail; |
| 5197 | } |
| 5198 | DHD_INTR(("%s: registered SDIO interrupt function ok\n", __func__)); |
| 5199 | |
| 5200 | DHD_INFO(("%s: completed!!\n", __func__)); |
| 5201 | |
| 5202 | /* if firmware path present try to download and bring up bus */ |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5203 | ret = dhd_bus_start(bus->dhd); |
| 5204 | if (ret != 0) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5205 | if (ret == BCME_NOTUP) { |
| 5206 | DHD_ERROR(("%s: dongle is not responding\n", __func__)); |
| 5207 | goto fail; |
| 5208 | } |
| 5209 | } |
| 5210 | /* Ok, have the per-port tell the stack we're open for business */ |
| 5211 | if (dhd_net_attach(bus->dhd, 0) != 0) { |
| 5212 | DHD_ERROR(("%s: Net attach failed!!\n", __func__)); |
| 5213 | goto fail; |
| 5214 | } |
| 5215 | |
| 5216 | return bus; |
| 5217 | |
| 5218 | fail: |
| 5219 | dhdsdio_release(bus, osh); |
| 5220 | return NULL; |
| 5221 | } |
| 5222 | |
| 5223 | static bool |
| 5224 | dhdsdio_probe_attach(struct dhd_bus *bus, osl_t *osh, void *sdh, void *regsva, |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5225 | u16 devid) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5226 | { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 5227 | u8 clkctl = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5228 | int err = 0; |
| 5229 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5230 | bus->alp_only = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5231 | |
| 5232 | /* Return the window to backplane enumeration space for core access */ |
| 5233 | if (dhdsdio_set_siaddr_window(bus, SI_ENUM_BASE)) |
| 5234 | DHD_ERROR(("%s: FAILED to return to SI_ENUM_BASE\n", __func__)); |
| 5235 | |
| 5236 | #ifdef DHD_DEBUG |
| 5237 | printf("F1 signature read @0x18000000=0x%4x\n", |
| 5238 | bcmsdh_reg_read(bus->sdh, SI_ENUM_BASE, 4)); |
| 5239 | |
| 5240 | #endif /* DHD_DEBUG */ |
| 5241 | |
| 5242 | /* Force PLL off until si_attach() programs PLL control regs */ |
| 5243 | |
| 5244 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 5245 | DHD_INIT_CLKCTL1, &err); |
| 5246 | if (!err) |
| 5247 | clkctl = |
| 5248 | bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 5249 | &err); |
| 5250 | |
| 5251 | if (err || ((clkctl & ~SBSDIO_AVBITS) != DHD_INIT_CLKCTL1)) { |
| 5252 | DHD_ERROR(("dhdsdio_probe: ChipClkCSR access: err %d wrote " |
| 5253 | "0x%02x read 0x%02x\n", |
| 5254 | err, DHD_INIT_CLKCTL1, clkctl)); |
| 5255 | goto fail; |
| 5256 | } |
| 5257 | #ifdef DHD_DEBUG |
| 5258 | if (DHD_INFO_ON()) { |
| 5259 | uint fn, numfn; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 5260 | u8 *cis[SDIOD_MAX_IOFUNCS]; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5261 | int err = 0; |
| 5262 | |
| 5263 | numfn = bcmsdh_query_iofnum(sdh); |
| 5264 | ASSERT(numfn <= SDIOD_MAX_IOFUNCS); |
| 5265 | |
| 5266 | /* Make sure ALP is available before trying to read CIS */ |
| 5267 | SPINWAIT(((clkctl = bcmsdh_cfg_read(sdh, SDIO_FUNC_1, |
| 5268 | SBSDIO_FUNC1_CHIPCLKCSR, |
| 5269 | NULL)), |
| 5270 | !SBSDIO_ALPAV(clkctl)), PMU_MAX_TRANSITION_DLY); |
| 5271 | |
| 5272 | /* Now request ALP be put on the bus */ |
| 5273 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 5274 | DHD_INIT_CLKCTL2, &err); |
mike.rapoport@gmail.com | 7383141 | 2010-10-13 00:09:07 +0200 | [diff] [blame] | 5275 | udelay(65); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5276 | |
| 5277 | for (fn = 0; fn <= numfn; fn++) { |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5278 | cis[fn] = kmalloc(SBSDIO_CIS_SIZE_LIMIT, GFP_ATOMIC); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5279 | if (!cis[fn]) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5280 | DHD_INFO(("dhdsdio_probe: fn %d cis malloc " |
| 5281 | "failed\n", fn)); |
| 5282 | break; |
| 5283 | } |
| 5284 | bzero(cis[fn], SBSDIO_CIS_SIZE_LIMIT); |
| 5285 | |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5286 | err = bcmsdh_cis_read(sdh, fn, cis[fn], |
| 5287 | SBSDIO_CIS_SIZE_LIMIT); |
| 5288 | if (err) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5289 | DHD_INFO(("dhdsdio_probe: fn %d cis read " |
| 5290 | "err %d\n", fn, err)); |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 5291 | kfree(cis[fn]); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5292 | break; |
| 5293 | } |
| 5294 | dhd_dump_cis(fn, cis[fn]); |
| 5295 | } |
| 5296 | |
| 5297 | while (fn-- > 0) { |
| 5298 | ASSERT(cis[fn]); |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 5299 | kfree(cis[fn]); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5300 | } |
| 5301 | |
| 5302 | if (err) { |
| 5303 | DHD_ERROR(("dhdsdio_probe: error read/parsing CIS\n")); |
| 5304 | goto fail; |
| 5305 | } |
| 5306 | } |
| 5307 | #endif /* DHD_DEBUG */ |
| 5308 | |
| 5309 | /* si_attach() will provide an SI handle and scan the backplane */ |
| 5310 | bus->sih = si_attach((uint) devid, osh, regsva, DHD_BUS, sdh, |
| 5311 | &bus->vars, &bus->varsz); |
| 5312 | if (!(bus->sih)) { |
| 5313 | DHD_ERROR(("%s: si_attach failed!\n", __func__)); |
| 5314 | goto fail; |
| 5315 | } |
| 5316 | |
| 5317 | bcmsdh_chipinfo(sdh, bus->sih->chip, bus->sih->chiprev); |
| 5318 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5319 | if (!dhdsdio_chipmatch((u16) bus->sih->chip)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5320 | DHD_ERROR(("%s: unsupported chip: 0x%04x\n", |
| 5321 | __func__, bus->sih->chip)); |
| 5322 | goto fail; |
| 5323 | } |
| 5324 | |
| 5325 | si_sdiod_drive_strength_init(bus->sih, osh, dhd_sdiod_drive_strength); |
| 5326 | |
| 5327 | /* Get info on the ARM and SOCRAM cores... */ |
| 5328 | if (!DHD_NOPMU(bus)) { |
| 5329 | if ((si_setcore(bus->sih, ARM7S_CORE_ID, 0)) || |
| 5330 | (si_setcore(bus->sih, ARMCM3_CORE_ID, 0))) { |
| 5331 | bus->armrev = si_corerev(bus->sih); |
| 5332 | } else { |
| 5333 | DHD_ERROR(("%s: failed to find ARM core!\n", __func__)); |
| 5334 | goto fail; |
| 5335 | } |
| 5336 | bus->orig_ramsize = si_socram_size(bus->sih); |
| 5337 | if (!(bus->orig_ramsize)) { |
| 5338 | DHD_ERROR(("%s: failed to find SOCRAM memory!\n", |
| 5339 | __func__)); |
| 5340 | goto fail; |
| 5341 | } |
| 5342 | bus->ramsize = bus->orig_ramsize; |
| 5343 | if (dhd_dongle_memsize) |
| 5344 | dhd_dongle_setmemsize(bus, dhd_dongle_memsize); |
| 5345 | |
| 5346 | DHD_ERROR(("DHD: dongle ram size is set to %d(orig %d)\n", |
| 5347 | bus->ramsize, bus->orig_ramsize)); |
| 5348 | } |
| 5349 | |
| 5350 | /* ...but normally deal with the SDPCMDEV core */ |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5351 | bus->regs = si_setcore(bus->sih, PCMCIA_CORE_ID, 0); |
| 5352 | if (!bus->regs) { |
| 5353 | bus->regs = si_setcore(bus->sih, SDIOD_CORE_ID, 0); |
| 5354 | if (!bus->regs) { |
| 5355 | DHD_ERROR(("%s: failed to find SDIODEV core!\n", |
| 5356 | __func__)); |
| 5357 | goto fail; |
| 5358 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5359 | } |
| 5360 | bus->sdpcmrev = si_corerev(bus->sih); |
| 5361 | |
| 5362 | /* Set core control so an SDIO reset does a backplane reset */ |
| 5363 | OR_REG(osh, &bus->regs->corecontrol, CC_BPRESEN); |
| 5364 | |
| 5365 | pktq_init(&bus->txq, (PRIOMASK + 1), QLEN); |
| 5366 | |
| 5367 | /* Locate an appropriately-aligned portion of hdrbuf */ |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 5368 | bus->rxhdr = (u8 *) roundup((unsigned long)&bus->hdrbuf[0], DHD_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5369 | |
| 5370 | /* Set the poll and/or interrupt flags */ |
| 5371 | bus->intr = (bool) dhd_intr; |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5372 | bus->poll = (bool) dhd_poll; |
| 5373 | if (bus->poll) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5374 | bus->pollrate = 1; |
| 5375 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5376 | return true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5377 | |
| 5378 | fail: |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5379 | return false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5380 | } |
| 5381 | |
| 5382 | static bool dhdsdio_probe_malloc(dhd_bus_t *bus, osl_t *osh, void *sdh) |
| 5383 | { |
| 5384 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5385 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5386 | if (bus->dhd->maxctl) { |
| 5387 | bus->rxblen = |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 5388 | roundup((bus->dhd->maxctl + SDPCM_HDRLEN), |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5389 | ALIGNMENT) + DHD_SDALIGN; |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5390 | bus->rxbuf = kmalloc(bus->rxblen, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5391 | if (!(bus->rxbuf)) { |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5392 | DHD_ERROR(("%s: kmalloc of %d-byte rxbuf failed\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5393 | __func__, bus->rxblen)); |
| 5394 | goto fail; |
| 5395 | } |
| 5396 | } |
| 5397 | |
| 5398 | /* Allocate buffer to receive glomed packet */ |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5399 | bus->databuf = kmalloc(MAX_DATA_BUF, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5400 | if (!(bus->databuf)) { |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5401 | DHD_ERROR(("%s: kmalloc of %d-byte databuf failed\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5402 | __func__, MAX_DATA_BUF)); |
| 5403 | /* release rxbuf which was already located as above */ |
| 5404 | if (!bus->rxblen) |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 5405 | kfree(bus->rxbuf); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5406 | goto fail; |
| 5407 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5408 | |
| 5409 | /* Align the buffer */ |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 5410 | if ((unsigned long)bus->databuf % DHD_SDALIGN) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5411 | bus->dataptr = |
| 5412 | bus->databuf + (DHD_SDALIGN - |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 5413 | ((unsigned long)bus->databuf % DHD_SDALIGN)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5414 | else |
| 5415 | bus->dataptr = bus->databuf; |
| 5416 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5417 | return true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5418 | |
| 5419 | fail: |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5420 | return false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5421 | } |
| 5422 | |
| 5423 | static bool dhdsdio_probe_init(dhd_bus_t *bus, osl_t *osh, void *sdh) |
| 5424 | { |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 5425 | s32 fnum; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5426 | |
| 5427 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5428 | |
| 5429 | #ifdef SDTEST |
| 5430 | dhdsdio_pktgen_init(bus); |
| 5431 | #endif /* SDTEST */ |
| 5432 | |
| 5433 | /* Disable F2 to clear any intermediate frame state on the dongle */ |
| 5434 | bcmsdh_cfg_write(sdh, SDIO_FUNC_0, SDIOD_CCCR_IOEN, SDIO_FUNC_ENABLE_1, |
| 5435 | NULL); |
| 5436 | |
| 5437 | bus->dhd->busstate = DHD_BUS_DOWN; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5438 | bus->sleeping = false; |
| 5439 | bus->rxflow = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5440 | bus->prev_rxlim_hit = 0; |
| 5441 | |
| 5442 | /* Done with backplane-dependent accesses, can drop clock... */ |
| 5443 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, 0, NULL); |
| 5444 | |
| 5445 | /* ...and initialize clock/power states */ |
| 5446 | bus->clkstate = CLK_SDONLY; |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 5447 | bus->idletime = (s32) dhd_idletime; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5448 | bus->idleclock = DHD_IDLE_ACTIVE; |
| 5449 | |
| 5450 | /* Query the SD clock speed */ |
| 5451 | if (bcmsdh_iovar_op(sdh, "sd_divisor", NULL, 0, |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 5452 | &bus->sd_divisor, sizeof(s32), |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5453 | false) != BCME_OK) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5454 | DHD_ERROR(("%s: fail on %s get\n", __func__, "sd_divisor")); |
| 5455 | bus->sd_divisor = -1; |
| 5456 | } else { |
| 5457 | DHD_INFO(("%s: Initial value for %s is %d\n", |
| 5458 | __func__, "sd_divisor", bus->sd_divisor)); |
| 5459 | } |
| 5460 | |
| 5461 | /* Query the SD bus mode */ |
| 5462 | if (bcmsdh_iovar_op(sdh, "sd_mode", NULL, 0, |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5463 | &bus->sd_mode, sizeof(s32), false) != BCME_OK) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5464 | DHD_ERROR(("%s: fail on %s get\n", __func__, "sd_mode")); |
| 5465 | bus->sd_mode = -1; |
| 5466 | } else { |
| 5467 | DHD_INFO(("%s: Initial value for %s is %d\n", |
| 5468 | __func__, "sd_mode", bus->sd_mode)); |
| 5469 | } |
| 5470 | |
| 5471 | /* Query the F2 block size, set roundup accordingly */ |
| 5472 | fnum = 2; |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 5473 | if (bcmsdh_iovar_op(sdh, "sd_blocksize", &fnum, sizeof(s32), |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5474 | &bus->blocksize, sizeof(s32), false) != BCME_OK) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5475 | bus->blocksize = 0; |
| 5476 | DHD_ERROR(("%s: fail on %s get\n", __func__, "sd_blocksize")); |
| 5477 | } else { |
| 5478 | DHD_INFO(("%s: Initial value for %s is %d\n", |
| 5479 | __func__, "sd_blocksize", bus->blocksize)); |
| 5480 | } |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 5481 | bus->roundup = min(max_roundup, bus->blocksize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5482 | |
| 5483 | /* Query if bus module supports packet chaining, |
| 5484 | default to use if supported */ |
| 5485 | if (bcmsdh_iovar_op(sdh, "sd_rxchain", NULL, 0, |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 5486 | &bus->sd_rxchain, sizeof(s32), |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5487 | false) != BCME_OK) { |
| 5488 | bus->sd_rxchain = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5489 | } else { |
| 5490 | DHD_INFO(("%s: bus module (through bcmsdh API) %s chaining\n", |
| 5491 | __func__, |
| 5492 | (bus->sd_rxchain ? "supports" : "does not support"))); |
| 5493 | } |
| 5494 | bus->use_rxchain = (bool) bus->sd_rxchain; |
| 5495 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5496 | return true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5497 | } |
| 5498 | |
| 5499 | bool |
| 5500 | dhd_bus_download_firmware(struct dhd_bus *bus, osl_t *osh, |
| 5501 | char *fw_path, char *nv_path) |
| 5502 | { |
| 5503 | bool ret; |
| 5504 | bus->fw_path = fw_path; |
| 5505 | bus->nv_path = nv_path; |
| 5506 | |
| 5507 | ret = dhdsdio_download_firmware(bus, osh, bus->sdh); |
| 5508 | |
| 5509 | return ret; |
| 5510 | } |
| 5511 | |
| 5512 | static bool |
| 5513 | dhdsdio_download_firmware(struct dhd_bus *bus, osl_t *osh, void *sdh) |
| 5514 | { |
| 5515 | bool ret; |
| 5516 | |
| 5517 | /* Download the firmware */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5518 | dhdsdio_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5519 | |
| 5520 | ret = _dhdsdio_download_firmware(bus) == 0; |
| 5521 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5522 | dhdsdio_clkctl(bus, CLK_SDONLY, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5523 | |
| 5524 | return ret; |
| 5525 | } |
| 5526 | |
| 5527 | /* Detach and free everything */ |
| 5528 | static void dhdsdio_release(dhd_bus_t *bus, osl_t *osh) |
| 5529 | { |
| 5530 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5531 | |
| 5532 | if (bus) { |
| 5533 | ASSERT(osh); |
| 5534 | |
| 5535 | /* De-register interrupt handler */ |
| 5536 | bcmsdh_intr_disable(bus->sdh); |
| 5537 | bcmsdh_intr_dereg(bus->sdh); |
| 5538 | |
| 5539 | if (bus->dhd) { |
| 5540 | |
| 5541 | dhdsdio_release_dongle(bus, osh); |
| 5542 | |
| 5543 | dhd_detach(bus->dhd); |
| 5544 | bus->dhd = NULL; |
| 5545 | } |
| 5546 | |
| 5547 | dhdsdio_release_malloc(bus, osh); |
| 5548 | |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 5549 | kfree(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5550 | } |
| 5551 | |
| 5552 | if (osh) |
| 5553 | dhd_osl_detach(osh); |
| 5554 | |
| 5555 | DHD_TRACE(("%s: Disconnected\n", __func__)); |
| 5556 | } |
| 5557 | |
| 5558 | static void dhdsdio_release_malloc(dhd_bus_t *bus, osl_t *osh) |
| 5559 | { |
| 5560 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5561 | |
| 5562 | if (bus->dhd && bus->dhd->dongle_reset) |
| 5563 | return; |
| 5564 | |
| 5565 | if (bus->rxbuf) { |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 5566 | kfree(bus->rxbuf); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5567 | bus->rxctl = bus->rxbuf = NULL; |
| 5568 | bus->rxlen = 0; |
| 5569 | } |
| 5570 | |
| 5571 | if (bus->databuf) { |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 5572 | kfree(bus->databuf); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5573 | bus->databuf = NULL; |
| 5574 | } |
| 5575 | } |
| 5576 | |
| 5577 | static void dhdsdio_release_dongle(dhd_bus_t *bus, osl_t *osh) |
| 5578 | { |
| 5579 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5580 | |
| 5581 | if (bus->dhd && bus->dhd->dongle_reset) |
| 5582 | return; |
| 5583 | |
| 5584 | if (bus->sih) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5585 | dhdsdio_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5586 | #if !defined(BCMLXSDMMC) |
| 5587 | si_watchdog(bus->sih, 4); |
| 5588 | #endif /* !defined(BCMLXSDMMC) */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5589 | dhdsdio_clkctl(bus, CLK_NONE, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5590 | si_detach(bus->sih); |
| 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); |
| 5607 | dhdsdio_release(bus, bus->dhd->osh); |
| 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 | |
| 5637 | #ifdef BCMEMBEDIMAGE |
| 5638 | static int dhdsdio_download_code_array(struct dhd_bus *bus) |
| 5639 | { |
| 5640 | int bcmerror = -1; |
| 5641 | int offset = 0; |
| 5642 | |
| 5643 | DHD_INFO(("%s: download embedded firmware...\n", __func__)); |
| 5644 | |
| 5645 | /* Download image */ |
| 5646 | while ((offset + MEMBLOCK) < sizeof(dlarray)) { |
| 5647 | bcmerror = |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5648 | dhdsdio_membytes(bus, true, offset, dlarray + offset, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5649 | MEMBLOCK); |
| 5650 | if (bcmerror) { |
| 5651 | DHD_ERROR(("%s: error %d on writing %d membytes at " |
| 5652 | "0x%08x\n", |
| 5653 | __func__, bcmerror, MEMBLOCK, offset)); |
| 5654 | goto err; |
| 5655 | } |
| 5656 | |
| 5657 | offset += MEMBLOCK; |
| 5658 | } |
| 5659 | |
| 5660 | if (offset < sizeof(dlarray)) { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5661 | bcmerror = dhdsdio_membytes(bus, true, offset, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5662 | dlarray + offset, |
| 5663 | sizeof(dlarray) - offset); |
| 5664 | if (bcmerror) { |
| 5665 | DHD_ERROR(("%s: error %d on writing %d membytes at " |
| 5666 | "0x%08x\n", __func__, bcmerror, |
| 5667 | sizeof(dlarray) - offset, offset)); |
| 5668 | goto err; |
| 5669 | } |
| 5670 | } |
| 5671 | #ifdef DHD_DEBUG |
| 5672 | /* Upload and compare the downloaded code */ |
| 5673 | { |
| 5674 | unsigned char *ularray; |
| 5675 | |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5676 | ularray = kmalloc(bus->ramsize, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5677 | /* Upload image to verify downloaded contents. */ |
| 5678 | offset = 0; |
| 5679 | memset(ularray, 0xaa, bus->ramsize); |
| 5680 | while ((offset + MEMBLOCK) < sizeof(dlarray)) { |
| 5681 | bcmerror = |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5682 | dhdsdio_membytes(bus, false, offset, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5683 | ularray + offset, MEMBLOCK); |
| 5684 | if (bcmerror) { |
| 5685 | DHD_ERROR(("%s: error %d on reading %d membytes" |
| 5686 | " at 0x%08x\n", |
| 5687 | __func__, bcmerror, MEMBLOCK, offset)); |
| 5688 | goto err; |
| 5689 | } |
| 5690 | |
| 5691 | offset += MEMBLOCK; |
| 5692 | } |
| 5693 | |
| 5694 | if (offset < sizeof(dlarray)) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5695 | bcmerror = dhdsdio_membytes(bus, false, offset, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5696 | ularray + offset, |
| 5697 | sizeof(dlarray) - offset); |
| 5698 | if (bcmerror) { |
| 5699 | DHD_ERROR(("%s: error %d on reading %d membytes at 0x%08x\n", |
| 5700 | __func__, bcmerror, |
| 5701 | sizeof(dlarray) - offset, offset)); |
| 5702 | goto err; |
| 5703 | } |
| 5704 | } |
| 5705 | |
| 5706 | if (memcmp(dlarray, ularray, sizeof(dlarray))) { |
| 5707 | DHD_ERROR(("%s: Downloaded image is corrupted.\n", |
| 5708 | __func__)); |
| 5709 | ASSERT(0); |
| 5710 | goto err; |
| 5711 | } else |
| 5712 | DHD_ERROR(("%s: Download/Upload/Compare succeeded.\n", |
| 5713 | __func__)); |
| 5714 | |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 5715 | kfree(ularray); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5716 | } |
| 5717 | #endif /* DHD_DEBUG */ |
| 5718 | |
| 5719 | err: |
| 5720 | return bcmerror; |
| 5721 | } |
| 5722 | #endif /* BCMEMBEDIMAGE */ |
| 5723 | |
| 5724 | static int dhdsdio_download_code_file(struct dhd_bus *bus, char *fw_path) |
| 5725 | { |
| 5726 | int bcmerror = -1; |
| 5727 | int offset = 0; |
| 5728 | uint len; |
| 5729 | void *image = NULL; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 5730 | u8 *memblock = NULL, *memptr; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5731 | |
| 5732 | DHD_INFO(("%s: download firmware %s\n", __func__, fw_path)); |
| 5733 | |
| 5734 | image = dhd_os_open_image(fw_path); |
| 5735 | if (image == NULL) |
| 5736 | goto err; |
| 5737 | |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5738 | memptr = memblock = kmalloc(MEMBLOCK + DHD_SDALIGN, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5739 | if (memblock == NULL) { |
| 5740 | DHD_ERROR(("%s: Failed to allocate memory %d bytes\n", |
| 5741 | __func__, MEMBLOCK)); |
| 5742 | goto err; |
| 5743 | } |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 5744 | if ((u32)(unsigned long)memblock % DHD_SDALIGN) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5745 | memptr += |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 5746 | (DHD_SDALIGN - ((u32)(unsigned long)memblock % DHD_SDALIGN)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5747 | |
| 5748 | /* Download image */ |
| 5749 | while ((len = |
| 5750 | dhd_os_get_image_block((char *)memptr, MEMBLOCK, image))) { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5751 | bcmerror = dhdsdio_membytes(bus, true, offset, memptr, len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5752 | if (bcmerror) { |
| 5753 | DHD_ERROR(("%s: error %d on writing %d membytes at " |
| 5754 | "0x%08x\n", __func__, bcmerror, MEMBLOCK, offset)); |
| 5755 | goto err; |
| 5756 | } |
| 5757 | |
| 5758 | offset += MEMBLOCK; |
| 5759 | } |
| 5760 | |
| 5761 | err: |
| 5762 | if (memblock) |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 5763 | kfree(memblock); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5764 | |
| 5765 | if (image) |
| 5766 | dhd_os_close_image(image); |
| 5767 | |
| 5768 | return bcmerror; |
| 5769 | } |
| 5770 | |
| 5771 | /* |
| 5772 | * ProcessVars:Takes a buffer of "<var>=<value>\n" lines read from a file |
| 5773 | * and ending in a NUL. |
| 5774 | * Removes carriage returns, empty lines, comment lines, and converts |
| 5775 | * newlines to NULs. |
| 5776 | * Shortens buffer as needed and pads with NULs. End of buffer is marked |
| 5777 | * by two NULs. |
| 5778 | */ |
| 5779 | |
| 5780 | static uint process_nvram_vars(char *varbuf, uint len) |
| 5781 | { |
| 5782 | char *dp; |
| 5783 | bool findNewline; |
| 5784 | int column; |
| 5785 | uint buf_len, n; |
| 5786 | |
| 5787 | dp = varbuf; |
| 5788 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5789 | findNewline = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5790 | column = 0; |
| 5791 | |
| 5792 | for (n = 0; n < len; n++) { |
| 5793 | if (varbuf[n] == 0) |
| 5794 | break; |
| 5795 | if (varbuf[n] == '\r') |
| 5796 | continue; |
| 5797 | if (findNewline && varbuf[n] != '\n') |
| 5798 | continue; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5799 | findNewline = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5800 | if (varbuf[n] == '#') { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5801 | findNewline = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5802 | continue; |
| 5803 | } |
| 5804 | if (varbuf[n] == '\n') { |
| 5805 | if (column == 0) |
| 5806 | continue; |
| 5807 | *dp++ = 0; |
| 5808 | column = 0; |
| 5809 | continue; |
| 5810 | } |
| 5811 | *dp++ = varbuf[n]; |
| 5812 | column++; |
| 5813 | } |
| 5814 | buf_len = dp - varbuf; |
| 5815 | |
| 5816 | while (dp < varbuf + n) |
| 5817 | *dp++ = 0; |
| 5818 | |
| 5819 | return buf_len; |
| 5820 | } |
| 5821 | |
| 5822 | /* |
| 5823 | EXAMPLE: nvram_array |
| 5824 | nvram_arry format: |
| 5825 | name=value |
| 5826 | Use carriage return at the end of each assignment, |
| 5827 | and an empty string with |
| 5828 | carriage return at the end of array. |
| 5829 | |
| 5830 | For example: |
| 5831 | unsigned char nvram_array[] = {"name1=value1\n", |
| 5832 | "name2=value2\n", "\n"}; |
| 5833 | Hex values start with 0x, and mac addr format: xx:xx:xx:xx:xx:xx. |
| 5834 | |
| 5835 | Search "EXAMPLE: nvram_array" to see how the array is activated. |
| 5836 | */ |
| 5837 | |
| 5838 | void dhd_bus_set_nvram_params(struct dhd_bus *bus, const char *nvram_params) |
| 5839 | { |
| 5840 | bus->nvram_params = nvram_params; |
| 5841 | } |
| 5842 | |
| 5843 | static int dhdsdio_download_nvram(struct dhd_bus *bus) |
| 5844 | { |
| 5845 | int bcmerror = -1; |
| 5846 | uint len; |
| 5847 | void *image = NULL; |
| 5848 | char *memblock = NULL; |
| 5849 | char *bufp; |
| 5850 | char *nv_path; |
| 5851 | bool nvram_file_exists; |
| 5852 | |
| 5853 | nv_path = bus->nv_path; |
| 5854 | |
| 5855 | nvram_file_exists = ((nv_path != NULL) && (nv_path[0] != '\0')); |
| 5856 | if (!nvram_file_exists && (bus->nvram_params == NULL)) |
| 5857 | return 0; |
| 5858 | |
| 5859 | if (nvram_file_exists) { |
| 5860 | image = dhd_os_open_image(nv_path); |
| 5861 | if (image == NULL) |
| 5862 | goto err; |
| 5863 | } |
| 5864 | |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5865 | memblock = kmalloc(MEMBLOCK, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5866 | if (memblock == NULL) { |
| 5867 | DHD_ERROR(("%s: Failed to allocate memory %d bytes\n", |
| 5868 | __func__, MEMBLOCK)); |
| 5869 | goto err; |
| 5870 | } |
| 5871 | |
| 5872 | /* Download variables */ |
| 5873 | if (nvram_file_exists) { |
| 5874 | len = dhd_os_get_image_block(memblock, MEMBLOCK, image); |
| 5875 | } else { |
| 5876 | len = strlen(bus->nvram_params); |
| 5877 | ASSERT(len <= MEMBLOCK); |
| 5878 | if (len > MEMBLOCK) |
| 5879 | len = MEMBLOCK; |
| 5880 | memcpy(memblock, bus->nvram_params, len); |
| 5881 | } |
| 5882 | |
| 5883 | if (len > 0 && len < MEMBLOCK) { |
| 5884 | bufp = (char *)memblock; |
| 5885 | bufp[len] = 0; |
| 5886 | len = process_nvram_vars(bufp, len); |
| 5887 | bufp += len; |
| 5888 | *bufp++ = 0; |
| 5889 | if (len) |
| 5890 | bcmerror = dhdsdio_downloadvars(bus, memblock, len + 1); |
| 5891 | if (bcmerror) { |
| 5892 | DHD_ERROR(("%s: error downloading vars: %d\n", |
| 5893 | __func__, bcmerror)); |
| 5894 | } |
| 5895 | } else { |
| 5896 | DHD_ERROR(("%s: error reading nvram file: %d\n", |
| 5897 | __func__, len)); |
| 5898 | bcmerror = BCME_SDIO_ERROR; |
| 5899 | } |
| 5900 | |
| 5901 | err: |
| 5902 | if (memblock) |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 5903 | kfree(memblock); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5904 | |
| 5905 | if (image) |
| 5906 | dhd_os_close_image(image); |
| 5907 | |
| 5908 | return bcmerror; |
| 5909 | } |
| 5910 | |
| 5911 | static int _dhdsdio_download_firmware(struct dhd_bus *bus) |
| 5912 | { |
| 5913 | int bcmerror = -1; |
| 5914 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5915 | bool embed = false; /* download embedded firmware */ |
| 5916 | bool dlok = false; /* download firmware succeeded */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5917 | |
| 5918 | /* Out immediately if no image to download */ |
| 5919 | if ((bus->fw_path == NULL) || (bus->fw_path[0] == '\0')) { |
| 5920 | #ifdef BCMEMBEDIMAGE |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5921 | embed = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5922 | #else |
| 5923 | return bcmerror; |
| 5924 | #endif |
| 5925 | } |
| 5926 | |
| 5927 | /* Keep arm in reset */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5928 | if (dhdsdio_download_state(bus, true)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5929 | DHD_ERROR(("%s: error placing ARM core in reset\n", __func__)); |
| 5930 | goto err; |
| 5931 | } |
| 5932 | |
| 5933 | /* External image takes precedence if specified */ |
| 5934 | if ((bus->fw_path != NULL) && (bus->fw_path[0] != '\0')) { |
| 5935 | if (dhdsdio_download_code_file(bus, bus->fw_path)) { |
| 5936 | DHD_ERROR(("%s: dongle image file download failed\n", |
| 5937 | __func__)); |
| 5938 | #ifdef BCMEMBEDIMAGE |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5939 | embed = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5940 | #else |
| 5941 | goto err; |
| 5942 | #endif |
| 5943 | } else { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5944 | embed = false; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5945 | dlok = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5946 | } |
| 5947 | } |
| 5948 | #ifdef BCMEMBEDIMAGE |
| 5949 | if (embed) { |
| 5950 | if (dhdsdio_download_code_array(bus)) { |
| 5951 | DHD_ERROR(("%s: dongle image array download failed\n", |
| 5952 | __func__)); |
| 5953 | goto err; |
| 5954 | } else { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5955 | dlok = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5956 | } |
| 5957 | } |
| 5958 | #endif |
| 5959 | if (!dlok) { |
| 5960 | DHD_ERROR(("%s: dongle image download failed\n", __func__)); |
| 5961 | goto err; |
| 5962 | } |
| 5963 | |
| 5964 | /* EXAMPLE: nvram_array */ |
| 5965 | /* If a valid nvram_arry is specified as above, it can be passed |
| 5966 | down to dongle */ |
| 5967 | /* dhd_bus_set_nvram_params(bus, (char *)&nvram_array); */ |
| 5968 | |
| 5969 | /* External nvram takes precedence if specified */ |
| 5970 | if (dhdsdio_download_nvram(bus)) { |
| 5971 | DHD_ERROR(("%s: dongle nvram file download failed\n", |
| 5972 | __func__)); |
| 5973 | } |
| 5974 | |
| 5975 | /* Take arm out of reset */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5976 | if (dhdsdio_download_state(bus, false)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5977 | DHD_ERROR(("%s: error getting out of ARM core reset\n", |
| 5978 | __func__)); |
| 5979 | goto err; |
| 5980 | } |
| 5981 | |
| 5982 | bcmerror = 0; |
| 5983 | |
| 5984 | err: |
| 5985 | return bcmerror; |
| 5986 | } |
| 5987 | |
| 5988 | static int |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 5989 | dhd_bcmsdh_recv_buf(dhd_bus_t *bus, u32 addr, uint fn, uint flags, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 5990 | u8 *buf, uint nbytes, void *pkt, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5991 | bcmsdh_cmplt_fn_t complete, void *handle) |
| 5992 | { |
| 5993 | int status; |
| 5994 | |
| 5995 | /* 4329: GSPI check */ |
| 5996 | status = |
| 5997 | bcmsdh_recv_buf(bus->sdh, addr, fn, flags, buf, nbytes, pkt, |
| 5998 | complete, handle); |
| 5999 | return status; |
| 6000 | } |
| 6001 | |
| 6002 | static int |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 6003 | dhd_bcmsdh_send_buf(dhd_bus_t *bus, u32 addr, uint fn, uint flags, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 6004 | u8 *buf, uint nbytes, void *pkt, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6005 | bcmsdh_cmplt_fn_t complete, void *handle) |
| 6006 | { |
| 6007 | return bcmsdh_send_buf |
| 6008 | (bus->sdh, addr, fn, flags, buf, nbytes, pkt, complete, |
| 6009 | handle); |
| 6010 | } |
| 6011 | |
| 6012 | uint dhd_bus_chip(struct dhd_bus *bus) |
| 6013 | { |
| 6014 | ASSERT(bus->sih != NULL); |
| 6015 | return bus->sih->chip; |
| 6016 | } |
| 6017 | |
| 6018 | void *dhd_bus_pub(struct dhd_bus *bus) |
| 6019 | { |
| 6020 | return bus->dhd; |
| 6021 | } |
| 6022 | |
| 6023 | void *dhd_bus_txq(struct dhd_bus *bus) |
| 6024 | { |
| 6025 | return &bus->txq; |
| 6026 | } |
| 6027 | |
| 6028 | uint dhd_bus_hdrlen(struct dhd_bus *bus) |
| 6029 | { |
| 6030 | return SDPCM_HDRLEN; |
| 6031 | } |
| 6032 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 6033 | int dhd_bus_devreset(dhd_pub_t *dhdp, u8 flag) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6034 | { |
| 6035 | int bcmerror = 0; |
| 6036 | dhd_bus_t *bus; |
| 6037 | |
| 6038 | bus = dhdp->bus; |
| 6039 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 6040 | if (flag == true) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6041 | if (!bus->dhd->dongle_reset) { |
| 6042 | /* Expect app to have torn down any |
| 6043 | connection before calling */ |
| 6044 | /* Stop the bus, disable F2 */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 6045 | dhd_bus_stop(bus, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6046 | |
| 6047 | /* Clean tx/rx buffer pointers, |
| 6048 | detach from the dongle */ |
| 6049 | dhdsdio_release_dongle(bus, bus->dhd->osh); |
| 6050 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 6051 | bus->dhd->dongle_reset = true; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 6052 | bus->dhd->up = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6053 | |
| 6054 | DHD_TRACE(("%s: WLAN OFF DONE\n", __func__)); |
| 6055 | /* App can now remove power from device */ |
| 6056 | } else |
| 6057 | bcmerror = BCME_SDIO_ERROR; |
| 6058 | } else { |
| 6059 | /* App must have restored power to device before calling */ |
| 6060 | |
| 6061 | DHD_TRACE(("\n\n%s: == WLAN ON ==\n", __func__)); |
| 6062 | |
| 6063 | if (bus->dhd->dongle_reset) { |
| 6064 | /* Turn on WLAN */ |
| 6065 | /* Reset SD client */ |
| 6066 | bcmsdh_reset(bus->sdh); |
| 6067 | |
| 6068 | /* Attempt to re-attach & download */ |
| 6069 | if (dhdsdio_probe_attach(bus, bus->dhd->osh, bus->sdh, |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 6070 | (u32 *) SI_ENUM_BASE, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6071 | bus->cl_devid)) { |
| 6072 | /* Attempt to download binary to the dongle */ |
| 6073 | if (dhdsdio_probe_init |
| 6074 | (bus, bus->dhd->osh, bus->sdh) |
| 6075 | && dhdsdio_download_firmware(bus, |
| 6076 | bus->dhd->osh, |
| 6077 | bus->sdh)) { |
| 6078 | |
| 6079 | /* Re-init bus, enable F2 transfer */ |
| 6080 | dhd_bus_init((dhd_pub_t *) bus->dhd, |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 6081 | false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6082 | |
| 6083 | #if defined(OOB_INTR_ONLY) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 6084 | dhd_enable_oob_intr(bus, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6085 | #endif /* defined(OOB_INTR_ONLY) */ |
| 6086 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 6087 | bus->dhd->dongle_reset = false; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 6088 | bus->dhd->up = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6089 | |
| 6090 | DHD_TRACE(("%s: WLAN ON DONE\n", |
| 6091 | __func__)); |
| 6092 | } else |
| 6093 | bcmerror = BCME_SDIO_ERROR; |
| 6094 | } else |
| 6095 | bcmerror = BCME_SDIO_ERROR; |
| 6096 | } else { |
| 6097 | bcmerror = BCME_NOTDOWN; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 6098 | DHD_ERROR(("%s: Set DEVRESET=false invoked when device " |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6099 | "is on\n", __func__)); |
| 6100 | bcmerror = BCME_SDIO_ERROR; |
| 6101 | } |
| 6102 | } |
| 6103 | return bcmerror; |
| 6104 | } |