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