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