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> |
Stanislav Fomichev | be1c09f | 2011-03-28 01:31:36 +0400 | [diff] [blame] | 18 | #include <linux/pci_ids.h> |
Greg Kroah-Hartman | a1c16ed | 2010-10-21 11:17:44 -0700 | [diff] [blame] | 19 | #include <bcmdefs.h> |
Brett Rudley | c6ac24e | 2010-10-26 11:55:23 -0700 | [diff] [blame] | 20 | #include <linux/netdevice.h> |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 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> |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 56 | #include <bcmchip.h> |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 57 | |
| 58 | #ifndef DHDSDIO_MEM_DUMP_FNAME |
| 59 | #define DHDSDIO_MEM_DUMP_FNAME "mem_dump" |
| 60 | #endif |
| 61 | |
Grant Grundler | 26a71a4 | 2011-03-09 10:41:25 -0800 | [diff] [blame] | 62 | #define TXQLEN 2048 /* bulk tx queue length */ |
| 63 | #define TXHI (TXQLEN - 256) /* turn on flow control above TXHI */ |
| 64 | #define TXLOW (TXHI - 256) /* turn off flow control below TXLOW */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 65 | #define PRIOMASK 7 |
| 66 | |
| 67 | #define TXRETRIES 2 /* # of retries for tx frames */ |
| 68 | |
| 69 | #if defined(CONFIG_MACH_SANDGATE2G) |
| 70 | #define DHD_RXBOUND 250 /* Default for max rx frames in |
| 71 | one scheduling */ |
| 72 | #else |
| 73 | #define DHD_RXBOUND 50 /* Default for max rx frames in |
| 74 | one scheduling */ |
| 75 | #endif /* defined(CONFIG_MACH_SANDGATE2G) */ |
| 76 | |
| 77 | #define DHD_TXBOUND 20 /* Default for max tx frames in |
| 78 | one scheduling */ |
| 79 | |
| 80 | #define DHD_TXMINMAX 1 /* Max tx frames if rx still pending */ |
| 81 | |
| 82 | #define MEMBLOCK 2048 /* Block size used for downloading |
| 83 | of dongle image */ |
| 84 | #define MAX_DATA_BUF (32 * 1024) /* Must be large enough to hold |
| 85 | biggest possible glom */ |
| 86 | |
| 87 | /* Packet alignment for most efficient SDIO (can change based on platform) */ |
| 88 | #ifndef DHD_SDALIGN |
| 89 | #define DHD_SDALIGN 32 |
| 90 | #endif |
| 91 | #if !ISPOWEROF2(DHD_SDALIGN) |
| 92 | #error DHD_SDALIGN is not a power of 2! |
| 93 | #endif |
| 94 | |
| 95 | #ifndef DHD_FIRSTREAD |
| 96 | #define DHD_FIRSTREAD 32 |
| 97 | #endif |
| 98 | #if !ISPOWEROF2(DHD_FIRSTREAD) |
| 99 | #error DHD_FIRSTREAD is not a power of 2! |
| 100 | #endif |
| 101 | |
| 102 | /* Total length of frame header for dongle protocol */ |
| 103 | #define SDPCM_HDRLEN (SDPCM_FRAMETAG_LEN + SDPCM_SWHEADER_LEN) |
| 104 | #ifdef SDTEST |
| 105 | #define SDPCM_RESERVE (SDPCM_HDRLEN + SDPCM_TEST_HDRLEN + DHD_SDALIGN) |
| 106 | #else |
| 107 | #define SDPCM_RESERVE (SDPCM_HDRLEN + DHD_SDALIGN) |
| 108 | #endif |
| 109 | |
| 110 | /* Space for header read, limit for data packets */ |
| 111 | #ifndef MAX_HDR_READ |
| 112 | #define MAX_HDR_READ 32 |
| 113 | #endif |
| 114 | #if !ISPOWEROF2(MAX_HDR_READ) |
| 115 | #error MAX_HDR_READ is not a power of 2! |
| 116 | #endif |
| 117 | |
| 118 | #define MAX_RX_DATASZ 2048 |
| 119 | |
| 120 | /* Maximum milliseconds to wait for F2 to come up */ |
| 121 | #define DHD_WAIT_F2RDY 3000 |
| 122 | |
| 123 | /* Bump up limit on waiting for HT to account for first startup; |
| 124 | * if the image is doing a CRC calculation before programming the PMU |
| 125 | * for HT availability, it could take a couple hundred ms more, so |
| 126 | * max out at a 1 second (1000000us). |
| 127 | */ |
| 128 | #if (PMU_MAX_TRANSITION_DLY <= 1000000) |
| 129 | #undef PMU_MAX_TRANSITION_DLY |
| 130 | #define PMU_MAX_TRANSITION_DLY 1000000 |
| 131 | #endif |
| 132 | |
| 133 | /* Value for ChipClockCSR during initial setup */ |
| 134 | #define DHD_INIT_CLKCTL1 (SBSDIO_FORCE_HW_CLKREQ_OFF | \ |
| 135 | SBSDIO_ALP_AVAIL_REQ) |
| 136 | #define DHD_INIT_CLKCTL2 (SBSDIO_FORCE_HW_CLKREQ_OFF | SBSDIO_FORCE_ALP) |
| 137 | |
| 138 | /* Flags for SDH calls */ |
| 139 | #define F2SYNC (SDIO_REQ_4BYTE | SDIO_REQ_FIXED) |
| 140 | |
| 141 | /* Packet free applicable unconditionally for sdio and sdspi. Conditional if |
| 142 | * bufpool was present for gspi bus. |
| 143 | */ |
| 144 | #define PKTFREE2() if ((bus->bus != SPI_BUS) || bus->usebufpool) \ |
Arend van Spriel | a30825a | 2011-03-02 21:18:46 +0100 | [diff] [blame] | 145 | pkt_buf_free_skb(pkt); |
Arend van Spriel | 70dfb58 | 2011-02-25 16:39:17 +0100 | [diff] [blame] | 146 | |
| 147 | /* |
| 148 | * Conversion of 802.1D priority to precedence level |
| 149 | */ |
| 150 | #define PRIO2PREC(prio) \ |
| 151 | (((prio) == PRIO_8021D_NONE || (prio) == PRIO_8021D_BE) ? \ |
| 152 | ((prio^2)) : (prio)) |
| 153 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 154 | DHD_SPINWAIT_SLEEP_INIT(sdioh_spinwait_sleep); |
| 155 | extern int dhdcdc_set_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf, |
| 156 | uint len); |
| 157 | |
| 158 | #ifdef DHD_DEBUG |
| 159 | /* Device console log buffer state */ |
| 160 | typedef struct dhd_console { |
| 161 | uint count; /* Poll interval msec counter */ |
| 162 | uint log_addr; /* Log struct address (fixed) */ |
| 163 | hndrte_log_t log; /* Log struct (host copy) */ |
| 164 | uint bufsize; /* Size of log buffer */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 165 | u8 *buf; /* Log buffer (host copy) */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 166 | uint last; /* Last buffer read index */ |
| 167 | } dhd_console_t; |
| 168 | #endif /* DHD_DEBUG */ |
| 169 | |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 170 | /* misc chip info needed by some of the routines */ |
| 171 | struct chip_info { |
| 172 | u32 chip; |
| 173 | u32 chiprev; |
| 174 | u32 cccorebase; |
| 175 | u32 ccrev; |
| 176 | u32 cccaps; |
| 177 | u32 buscorebase; |
| 178 | u32 buscorerev; |
| 179 | u32 buscoretype; |
| 180 | u32 ramcorebase; |
| 181 | u32 armcorebase; |
| 182 | u32 pmurev; |
| 183 | }; |
| 184 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 185 | /* Private data for SDIO bus interaction */ |
| 186 | typedef struct dhd_bus { |
| 187 | dhd_pub_t *dhd; |
| 188 | |
| 189 | bcmsdh_info_t *sdh; /* Handle for BCMSDH calls */ |
| 190 | si_t *sih; /* Handle for SI calls */ |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 191 | struct chip_info *ci; /* Chip info struct */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 192 | char *vars; /* Variables (from CIS and/or other) */ |
| 193 | uint varsz; /* Size of variables buffer */ |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 194 | u32 sbaddr; /* Current SB window pointer (-1, invalid) */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 195 | |
| 196 | sdpcmd_regs_t *regs; /* Registers for SDIO core */ |
| 197 | uint sdpcmrev; /* SDIO core revision */ |
| 198 | uint armrev; /* CPU core revision */ |
| 199 | uint ramrev; /* SOCRAM core revision */ |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 200 | u32 ramsize; /* Size of RAM in SOCRAM (bytes) */ |
| 201 | u32 orig_ramsize; /* Size of RAM in SOCRAM (bytes) */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 202 | |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 203 | u32 bus; /* gSPI or SDIO bus */ |
| 204 | u32 hostintmask; /* Copy of Host Interrupt Mask */ |
| 205 | u32 intstatus; /* Intstatus bits (events) pending */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 206 | bool dpc_sched; /* Indicates DPC schedule (intrpt rcvd) */ |
| 207 | bool fcstate; /* State of dongle flow-control */ |
| 208 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 209 | u16 cl_devid; /* cached devid for dhdsdio_probe_attach() */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 210 | char *fw_path; /* module_param: path to firmware image */ |
| 211 | char *nv_path; /* module_param: path to nvram vars file */ |
| 212 | const char *nvram_params; /* user specified nvram params. */ |
| 213 | |
| 214 | uint blocksize; /* Block size of SDIO transfers */ |
| 215 | uint roundup; /* Max roundup limit */ |
| 216 | |
| 217 | struct pktq txq; /* Queue length used for flow-control */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 218 | u8 flowcontrol; /* per prio flow control bitmask */ |
| 219 | u8 tx_seq; /* Transmit sequence number (next) */ |
| 220 | u8 tx_max; /* Maximum transmit sequence allowed */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 221 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 222 | u8 hdrbuf[MAX_HDR_READ + DHD_SDALIGN]; |
| 223 | u8 *rxhdr; /* Header of current rx frame (in hdrbuf) */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 224 | u16 nextlen; /* Next Read Len from last header */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 225 | u8 rx_seq; /* Receive sequence number (expected) */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 226 | bool rxskip; /* Skip receive (awaiting NAK ACK) */ |
| 227 | |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 228 | struct sk_buff *glomd; /* Packet containing glomming descriptor */ |
| 229 | struct sk_buff *glom; /* Packet chain for glommed superframe */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 230 | uint glomerr; /* Glom packet read errors */ |
| 231 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 232 | u8 *rxbuf; /* Buffer for receiving control packets */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 233 | uint rxblen; /* Allocated length of rxbuf */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 234 | u8 *rxctl; /* Aligned pointer into rxbuf */ |
| 235 | u8 *databuf; /* Buffer for receiving big glom packet */ |
| 236 | u8 *dataptr; /* Aligned pointer into databuf */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 237 | uint rxlen; /* Length of valid data in buffer */ |
| 238 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 239 | u8 sdpcm_ver; /* Bus protocol reported by dongle */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 240 | |
| 241 | bool intr; /* Use interrupts */ |
| 242 | bool poll; /* Use polling */ |
| 243 | bool ipend; /* Device interrupt is pending */ |
| 244 | bool intdis; /* Interrupts disabled by isr */ |
| 245 | uint intrcount; /* Count of device interrupt callbacks */ |
| 246 | uint lastintrs; /* Count as of last watchdog timer */ |
| 247 | uint spurious; /* Count of spurious interrupts */ |
| 248 | uint pollrate; /* Ticks between device polls */ |
| 249 | uint polltick; /* Tick counter */ |
| 250 | uint pollcnt; /* Count of active polls */ |
| 251 | |
| 252 | #ifdef DHD_DEBUG |
| 253 | dhd_console_t console; /* Console output polling support */ |
| 254 | uint console_addr; /* Console address from shared struct */ |
| 255 | #endif /* DHD_DEBUG */ |
| 256 | |
| 257 | uint regfails; /* Count of R_REG/W_REG failures */ |
| 258 | |
| 259 | uint clkstate; /* State of sd and backplane clock(s) */ |
| 260 | bool activity; /* Activity flag for clock down */ |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 261 | s32 idletime; /* Control for activity timeout */ |
| 262 | s32 idlecount; /* Activity timeout counter */ |
| 263 | s32 idleclock; /* How to set bus driver when idle */ |
| 264 | s32 sd_divisor; /* Speed control to bus driver */ |
| 265 | s32 sd_mode; /* Mode control to bus driver */ |
| 266 | s32 sd_rxchain; /* If bcmsdh api accepts PKT chains */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 267 | bool use_rxchain; /* If dhd should use PKT chains */ |
| 268 | bool sleeping; /* Is SDIO bus sleeping? */ |
| 269 | bool rxflow_mode; /* Rx flow control mode */ |
| 270 | bool rxflow; /* Is rx flow control on */ |
| 271 | uint prev_rxlim_hit; /* Is prev rx limit exceeded |
| 272 | (per dpc schedule) */ |
| 273 | bool alp_only; /* Don't use HT clock (ALP only) */ |
| 274 | /* Field to decide if rx of control frames happen in rxbuf or lb-pool */ |
| 275 | bool usebufpool; |
| 276 | |
| 277 | #ifdef SDTEST |
| 278 | /* external loopback */ |
| 279 | bool ext_loop; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 280 | u8 loopid; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 281 | |
| 282 | /* pktgen configuration */ |
| 283 | uint pktgen_freq; /* Ticks between bursts */ |
| 284 | uint pktgen_count; /* Packets to send each burst */ |
| 285 | uint pktgen_print; /* Bursts between count displays */ |
| 286 | uint pktgen_total; /* Stop after this many */ |
| 287 | uint pktgen_minlen; /* Minimum packet data len */ |
| 288 | uint pktgen_maxlen; /* Maximum packet data len */ |
| 289 | uint pktgen_mode; /* Configured mode: tx, rx, or echo */ |
| 290 | uint pktgen_stop; /* Number of tx failures causing stop */ |
| 291 | |
| 292 | /* active pktgen fields */ |
| 293 | uint pktgen_tick; /* Tick counter for bursts */ |
| 294 | uint pktgen_ptick; /* Burst counter for printing */ |
| 295 | uint pktgen_sent; /* Number of test packets generated */ |
| 296 | uint pktgen_rcvd; /* Number of test packets received */ |
| 297 | uint pktgen_fail; /* Number of failed send attempts */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 298 | u16 pktgen_len; /* Length of next packet to send */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 299 | #endif /* SDTEST */ |
| 300 | |
| 301 | /* Some additional counters */ |
| 302 | uint tx_sderrs; /* Count of tx attempts with sd errors */ |
| 303 | uint fcqueued; /* Tx packets that got queued */ |
| 304 | uint rxrtx; /* Count of rtx requests (NAK to dongle) */ |
| 305 | uint rx_toolong; /* Receive frames too long to receive */ |
| 306 | uint rxc_errors; /* SDIO errors when reading control frames */ |
| 307 | uint rx_hdrfail; /* SDIO errors on header reads */ |
| 308 | uint rx_badhdr; /* Bad received headers (roosync?) */ |
| 309 | uint rx_badseq; /* Mismatched rx sequence number */ |
| 310 | uint fc_rcvd; /* Number of flow-control events received */ |
| 311 | uint fc_xoff; /* Number which turned on flow-control */ |
| 312 | uint fc_xon; /* Number which turned off flow-control */ |
| 313 | uint rxglomfail; /* Failed deglom attempts */ |
| 314 | uint rxglomframes; /* Number of glom frames (superframes) */ |
| 315 | uint rxglompkts; /* Number of packets from glom frames */ |
| 316 | uint f2rxhdrs; /* Number of header reads */ |
| 317 | uint f2rxdata; /* Number of frame data reads */ |
| 318 | uint f2txdata; /* Number of f2 frame writes */ |
| 319 | uint f1regdata; /* Number of f1 register accesses */ |
| 320 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 321 | u8 *ctrl_frame_buf; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 322 | u32 ctrl_frame_len; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 323 | bool ctrl_frame_stat; |
| 324 | } dhd_bus_t; |
| 325 | |
| 326 | /* clkstate */ |
| 327 | #define CLK_NONE 0 |
| 328 | #define CLK_SDONLY 1 |
| 329 | #define CLK_PENDING 2 /* Not used yet */ |
| 330 | #define CLK_AVAIL 3 |
| 331 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 332 | #define DHD_NOPMU(dhd) (false) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 333 | |
| 334 | #ifdef DHD_DEBUG |
| 335 | static int qcount[NUMPRIO]; |
| 336 | static int tx_packets[NUMPRIO]; |
| 337 | #endif /* DHD_DEBUG */ |
| 338 | |
| 339 | /* Deferred transmit */ |
| 340 | const uint dhd_deferred_tx = 1; |
| 341 | |
| 342 | extern uint dhd_watchdog_ms; |
| 343 | extern void dhd_os_wd_timer(void *bus, uint wdtick); |
| 344 | |
| 345 | /* Tx/Rx bounds */ |
| 346 | uint dhd_txbound; |
| 347 | uint dhd_rxbound; |
| 348 | uint dhd_txminmax; |
| 349 | |
| 350 | /* override the RAM size if possible */ |
| 351 | #define DONGLE_MIN_MEMSIZE (128 * 1024) |
| 352 | int dhd_dongle_memsize; |
| 353 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 354 | static bool dhd_alignctl; |
| 355 | |
| 356 | static bool sd1idle; |
| 357 | |
| 358 | static bool retrydata; |
| 359 | #define RETRYCHAN(chan) (((chan) == SDPCM_EVENT_CHANNEL) || retrydata) |
| 360 | |
| 361 | static const uint watermark = 8; |
| 362 | static const uint firstread = DHD_FIRSTREAD; |
| 363 | |
| 364 | #define HDATLEN (firstread - (SDPCM_HDRLEN)) |
| 365 | |
| 366 | /* Retry count for register access failures */ |
| 367 | static const uint retry_limit = 2; |
| 368 | |
| 369 | /* Force even SD lengths (some host controllers mess up on odd bytes) */ |
| 370 | static bool forcealign; |
| 371 | |
| 372 | #define ALIGNMENT 4 |
| 373 | |
| 374 | #if defined(OOB_INTR_ONLY) && defined(HW_OOB) |
| 375 | extern void bcmsdh_enable_hw_oob_intr(void *sdh, bool enable); |
| 376 | #endif |
| 377 | |
| 378 | #if defined(OOB_INTR_ONLY) && defined(SDIO_ISR_THREAD) |
| 379 | #error OOB_INTR_ONLY is NOT working with SDIO_ISR_THREAD |
| 380 | #endif /* defined(OOB_INTR_ONLY) && defined(SDIO_ISR_THREAD) */ |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 381 | #define PKTALIGN(_p, _len, _align) \ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 382 | do { \ |
| 383 | uint datalign; \ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 384 | datalign = (unsigned long)((_p)->data); \ |
| 385 | datalign = roundup(datalign, (_align)) - datalign; \ |
| 386 | ASSERT(datalign < (_align)); \ |
| 387 | ASSERT((_p)->len >= ((_len) + datalign)); \ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 388 | if (datalign) \ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 389 | skb_pull((_p), datalign); \ |
| 390 | __skb_trim((_p), (_len)); \ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 391 | } while (0) |
| 392 | |
| 393 | /* Limit on rounding up frames */ |
| 394 | static const uint max_roundup = 512; |
| 395 | |
| 396 | /* Try doing readahead */ |
| 397 | static bool dhd_readahead; |
| 398 | |
| 399 | /* To check if there's window offered */ |
| 400 | #define DATAOK(bus) \ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 401 | (((u8)(bus->tx_max - bus->tx_seq) != 0) && \ |
| 402 | (((u8)(bus->tx_max - bus->tx_seq) & 0x80) == 0)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 403 | |
| 404 | /* Macros to get register read/write status */ |
| 405 | /* NOTE: these assume a local dhdsdio_bus_t *bus! */ |
| 406 | #define R_SDREG(regvar, regaddr, retryvar) \ |
| 407 | do { \ |
| 408 | retryvar = 0; \ |
| 409 | do { \ |
Arend van Spriel | ff31c54 | 2011-03-01 10:56:54 +0100 | [diff] [blame] | 410 | regvar = R_REG(regaddr); \ |
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" #regvar "READ, LINE %d\n", \ |
| 416 | __func__, __LINE__)); \ |
| 417 | regvar = 0; \ |
| 418 | } \ |
| 419 | } \ |
| 420 | } while (0) |
| 421 | |
| 422 | #define W_SDREG(regval, regaddr, retryvar) \ |
| 423 | do { \ |
| 424 | retryvar = 0; \ |
| 425 | do { \ |
Arend van Spriel | ff31c54 | 2011-03-01 10:56:54 +0100 | [diff] [blame] | 426 | W_REG(regaddr, regval); \ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 427 | } while (bcmsdh_regfail(bus->sdh) && (++retryvar <= retry_limit)); \ |
| 428 | if (retryvar) { \ |
| 429 | bus->regfails += (retryvar-1); \ |
| 430 | if (retryvar > retry_limit) \ |
| 431 | DHD_ERROR(("%s: FAILED REGISTER WRITE, LINE %d\n", \ |
| 432 | __func__, __LINE__)); \ |
| 433 | } \ |
| 434 | } while (0) |
| 435 | |
| 436 | #define DHD_BUS SDIO_BUS |
| 437 | |
| 438 | #define PKT_AVAILABLE() (intstatus & I_HMB_FRAME_IND) |
| 439 | |
| 440 | #define HOSTINTMASK (I_HMB_SW_MASK | I_CHIPACTIVE) |
| 441 | |
| 442 | #define GSPI_PR55150_BAILOUT |
| 443 | |
| 444 | #ifdef SDTEST |
| 445 | static void dhdsdio_testrcv(dhd_bus_t *bus, void *pkt, uint seq); |
| 446 | static void dhdsdio_sdtest_set(dhd_bus_t *bus, bool start); |
| 447 | #endif |
| 448 | |
| 449 | #ifdef DHD_DEBUG |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 450 | static int dhdsdio_checkdied(dhd_bus_t *bus, u8 *data, uint size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 451 | static int dhdsdio_mem_dump(dhd_bus_t *bus); |
| 452 | #endif /* DHD_DEBUG */ |
| 453 | static int dhdsdio_download_state(dhd_bus_t *bus, bool enter); |
| 454 | |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 455 | static void dhdsdio_release(dhd_bus_t *bus); |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 456 | static void dhdsdio_release_malloc(dhd_bus_t *bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 457 | static void dhdsdio_disconnect(void *ptr); |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 458 | static bool dhdsdio_chipmatch(u16 chipid); |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 459 | static bool dhdsdio_probe_attach(dhd_bus_t *bus, void *sdh, |
| 460 | void *regsva, u16 devid); |
| 461 | static bool dhdsdio_probe_malloc(dhd_bus_t *bus, void *sdh); |
| 462 | static bool dhdsdio_probe_init(dhd_bus_t *bus, void *sdh); |
| 463 | static void dhdsdio_release_dongle(dhd_bus_t *bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 464 | |
| 465 | static uint process_nvram_vars(char *varbuf, uint len); |
| 466 | |
| 467 | 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] | 468 | 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] | 469 | uint flags, u8 *buf, uint nbytes, |
| 470 | struct sk_buff *pkt, bcmsdh_cmplt_fn_t complete, |
| 471 | void *handle); |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 472 | 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] | 473 | uint flags, u8 *buf, uint nbytes, |
| 474 | struct sk_buff *pkt, bcmsdh_cmplt_fn_t complete, |
| 475 | void *handle); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 476 | |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 477 | static bool dhdsdio_download_firmware(struct dhd_bus *bus, void *sdh); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 478 | static int _dhdsdio_download_firmware(struct dhd_bus *bus); |
| 479 | |
| 480 | static int dhdsdio_download_code_file(struct dhd_bus *bus, char *image_path); |
| 481 | static int dhdsdio_download_nvram(struct dhd_bus *bus); |
| 482 | #ifdef BCMEMBEDIMAGE |
| 483 | static int dhdsdio_download_code_array(struct dhd_bus *bus); |
| 484 | #endif |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 485 | static void dhdsdio_chip_disablecore(bcmsdh_info_t *sdh, u32 corebase); |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 486 | static int dhdsdio_chip_attach(struct dhd_bus *bus, void *regs); |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 487 | static void dhdsdio_chip_resetcore(bcmsdh_info_t *sdh, u32 corebase); |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame^] | 488 | static void dhdsdio_sdiod_drive_strength_init(struct dhd_bus *bus, |
| 489 | u32 drivestrength); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 490 | |
| 491 | static void dhd_dongle_setmemsize(struct dhd_bus *bus, int mem_size) |
| 492 | { |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 493 | s32 min_size = DONGLE_MIN_MEMSIZE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 494 | /* Restrict the memsize to user specified limit */ |
| 495 | DHD_ERROR(("user: Restrict the dongle ram size to %d, min %d\n", |
| 496 | dhd_dongle_memsize, min_size)); |
| 497 | if ((dhd_dongle_memsize > min_size) && |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 498 | (dhd_dongle_memsize < (s32) bus->orig_ramsize)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 499 | bus->ramsize = dhd_dongle_memsize; |
| 500 | } |
| 501 | |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 502 | static int dhdsdio_set_siaddr_window(dhd_bus_t *bus, u32 address) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 503 | { |
| 504 | int err = 0; |
| 505 | bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRLOW, |
| 506 | (address >> 8) & SBSDIO_SBADDRLOW_MASK, &err); |
| 507 | if (!err) |
| 508 | bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRMID, |
| 509 | (address >> 16) & SBSDIO_SBADDRMID_MASK, &err); |
| 510 | if (!err) |
| 511 | bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRHIGH, |
| 512 | (address >> 24) & SBSDIO_SBADDRHIGH_MASK, |
| 513 | &err); |
| 514 | return err; |
| 515 | } |
| 516 | |
| 517 | /* Turn backplane clock on or off */ |
| 518 | static int dhdsdio_htclk(dhd_bus_t *bus, bool on, bool pendok) |
| 519 | { |
| 520 | int err; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 521 | u8 clkctl, clkreq, devctl; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 522 | bcmsdh_info_t *sdh; |
| 523 | |
| 524 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 525 | |
| 526 | #if defined(OOB_INTR_ONLY) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 527 | pendok = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 528 | #endif |
| 529 | clkctl = 0; |
| 530 | sdh = bus->sdh; |
| 531 | |
| 532 | if (on) { |
| 533 | /* Request HT Avail */ |
| 534 | clkreq = |
| 535 | bus->alp_only ? SBSDIO_ALP_AVAIL_REQ : SBSDIO_HT_AVAIL_REQ; |
| 536 | |
| 537 | if ((bus->sih->chip == BCM4329_CHIP_ID) |
| 538 | && (bus->sih->chiprev == 0)) |
| 539 | clkreq |= SBSDIO_FORCE_ALP; |
| 540 | |
| 541 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 542 | clkreq, &err); |
| 543 | if (err) { |
| 544 | DHD_ERROR(("%s: HT Avail request error: %d\n", |
| 545 | __func__, err)); |
| 546 | return BCME_ERROR; |
| 547 | } |
| 548 | |
| 549 | if (pendok && ((bus->sih->buscoretype == PCMCIA_CORE_ID) |
| 550 | && (bus->sih->buscorerev == 9))) { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 551 | u32 dummy, retries; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 552 | R_SDREG(dummy, &bus->regs->clockctlstatus, retries); |
| 553 | } |
| 554 | |
| 555 | /* Check current status */ |
| 556 | clkctl = |
| 557 | bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 558 | &err); |
| 559 | if (err) { |
| 560 | DHD_ERROR(("%s: HT Avail read error: %d\n", |
| 561 | __func__, err)); |
| 562 | return BCME_ERROR; |
| 563 | } |
| 564 | |
| 565 | /* Go to pending and await interrupt if appropriate */ |
| 566 | if (!SBSDIO_CLKAV(clkctl, bus->alp_only) && pendok) { |
| 567 | /* Allow only clock-available interrupt */ |
| 568 | devctl = |
| 569 | bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL, |
| 570 | &err); |
| 571 | if (err) { |
| 572 | DHD_ERROR(("%s: Devctl error setting CA: %d\n", |
| 573 | __func__, err)); |
| 574 | return BCME_ERROR; |
| 575 | } |
| 576 | |
| 577 | devctl |= SBSDIO_DEVCTL_CA_INT_ONLY; |
| 578 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL, |
| 579 | devctl, &err); |
| 580 | DHD_INFO(("CLKCTL: set PENDING\n")); |
| 581 | bus->clkstate = CLK_PENDING; |
| 582 | |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 583 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 584 | } else if (bus->clkstate == CLK_PENDING) { |
| 585 | /* Cancel CA-only interrupt filter */ |
| 586 | devctl = |
| 587 | bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL, |
| 588 | &err); |
| 589 | devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY; |
| 590 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL, |
| 591 | devctl, &err); |
| 592 | } |
| 593 | |
| 594 | /* Otherwise, wait here (polling) for HT Avail */ |
| 595 | if (!SBSDIO_CLKAV(clkctl, bus->alp_only)) { |
| 596 | SPINWAIT_SLEEP(sdioh_spinwait_sleep, |
| 597 | ((clkctl = |
| 598 | bcmsdh_cfg_read(sdh, SDIO_FUNC_1, |
| 599 | SBSDIO_FUNC1_CHIPCLKCSR, |
| 600 | &err)), |
| 601 | !SBSDIO_CLKAV(clkctl, bus->alp_only)), |
| 602 | PMU_MAX_TRANSITION_DLY); |
| 603 | } |
| 604 | if (err) { |
| 605 | DHD_ERROR(("%s: HT Avail request error: %d\n", |
| 606 | __func__, err)); |
| 607 | return BCME_ERROR; |
| 608 | } |
| 609 | if (!SBSDIO_CLKAV(clkctl, bus->alp_only)) { |
| 610 | DHD_ERROR(("%s: HT Avail timeout (%d): clkctl 0x%02x\n", |
| 611 | __func__, PMU_MAX_TRANSITION_DLY, clkctl)); |
| 612 | return BCME_ERROR; |
| 613 | } |
| 614 | |
| 615 | /* Mark clock available */ |
| 616 | bus->clkstate = CLK_AVAIL; |
| 617 | DHD_INFO(("CLKCTL: turned ON\n")); |
| 618 | |
| 619 | #if defined(DHD_DEBUG) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 620 | if (bus->alp_only == true) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 621 | #if !defined(BCMLXSDMMC) |
| 622 | if (!SBSDIO_ALPONLY(clkctl)) { |
| 623 | DHD_ERROR(("%s: HT Clock, when ALP Only\n", |
| 624 | __func__)); |
| 625 | } |
| 626 | #endif /* !defined(BCMLXSDMMC) */ |
| 627 | } else { |
| 628 | if (SBSDIO_ALPONLY(clkctl)) { |
| 629 | DHD_ERROR(("%s: HT Clock should be on.\n", |
| 630 | __func__)); |
| 631 | } |
| 632 | } |
| 633 | #endif /* defined (DHD_DEBUG) */ |
| 634 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 635 | bus->activity = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 636 | } else { |
| 637 | clkreq = 0; |
| 638 | |
| 639 | if (bus->clkstate == CLK_PENDING) { |
| 640 | /* Cancel CA-only interrupt filter */ |
| 641 | devctl = |
| 642 | bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL, |
| 643 | &err); |
| 644 | devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY; |
| 645 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL, |
| 646 | devctl, &err); |
| 647 | } |
| 648 | |
| 649 | bus->clkstate = CLK_SDONLY; |
| 650 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 651 | clkreq, &err); |
| 652 | DHD_INFO(("CLKCTL: turned OFF\n")); |
| 653 | if (err) { |
| 654 | DHD_ERROR(("%s: Failed access turning clock off: %d\n", |
| 655 | __func__, err)); |
| 656 | return BCME_ERROR; |
| 657 | } |
| 658 | } |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 659 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | /* Change idle/active SD state */ |
| 663 | static int dhdsdio_sdclk(dhd_bus_t *bus, bool on) |
| 664 | { |
| 665 | int err; |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 666 | s32 iovalue; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 667 | |
| 668 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 669 | |
| 670 | if (on) { |
| 671 | if (bus->idleclock == DHD_IDLE_STOP) { |
| 672 | /* Turn on clock and restore mode */ |
| 673 | iovalue = 1; |
| 674 | err = bcmsdh_iovar_op(bus->sdh, "sd_clock", NULL, 0, |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 675 | &iovalue, sizeof(iovalue), true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 676 | if (err) { |
| 677 | DHD_ERROR(("%s: error enabling sd_clock: %d\n", |
| 678 | __func__, err)); |
| 679 | return BCME_ERROR; |
| 680 | } |
| 681 | |
| 682 | iovalue = bus->sd_mode; |
| 683 | err = bcmsdh_iovar_op(bus->sdh, "sd_mode", NULL, 0, |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 684 | &iovalue, sizeof(iovalue), true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 685 | if (err) { |
| 686 | DHD_ERROR(("%s: error changing sd_mode: %d\n", |
| 687 | __func__, err)); |
| 688 | return BCME_ERROR; |
| 689 | } |
| 690 | } else if (bus->idleclock != DHD_IDLE_ACTIVE) { |
| 691 | /* Restore clock speed */ |
| 692 | iovalue = bus->sd_divisor; |
| 693 | err = bcmsdh_iovar_op(bus->sdh, "sd_divisor", NULL, 0, |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 694 | &iovalue, sizeof(iovalue), true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 695 | if (err) { |
| 696 | DHD_ERROR(("%s: error restoring sd_divisor: %d\n", |
| 697 | __func__, err)); |
| 698 | return BCME_ERROR; |
| 699 | } |
| 700 | } |
| 701 | bus->clkstate = CLK_SDONLY; |
| 702 | } else { |
| 703 | /* Stop or slow the SD clock itself */ |
| 704 | if ((bus->sd_divisor == -1) || (bus->sd_mode == -1)) { |
| 705 | DHD_TRACE(("%s: can't idle clock, divisor %d mode %d\n", |
| 706 | __func__, bus->sd_divisor, bus->sd_mode)); |
| 707 | return BCME_ERROR; |
| 708 | } |
| 709 | if (bus->idleclock == DHD_IDLE_STOP) { |
| 710 | if (sd1idle) { |
| 711 | /* Change to SD1 mode and turn off clock */ |
| 712 | iovalue = 1; |
| 713 | err = |
| 714 | bcmsdh_iovar_op(bus->sdh, "sd_mode", NULL, |
| 715 | 0, &iovalue, |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 716 | sizeof(iovalue), true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 717 | if (err) { |
| 718 | DHD_ERROR(("%s: error changing sd_clock: %d\n", |
| 719 | __func__, err)); |
| 720 | return BCME_ERROR; |
| 721 | } |
| 722 | } |
| 723 | |
| 724 | iovalue = 0; |
| 725 | err = bcmsdh_iovar_op(bus->sdh, "sd_clock", NULL, 0, |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 726 | &iovalue, sizeof(iovalue), true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 727 | if (err) { |
| 728 | DHD_ERROR(("%s: error disabling sd_clock: %d\n", |
| 729 | __func__, err)); |
| 730 | return BCME_ERROR; |
| 731 | } |
| 732 | } else if (bus->idleclock != DHD_IDLE_ACTIVE) { |
| 733 | /* Set divisor to idle value */ |
| 734 | iovalue = bus->idleclock; |
| 735 | err = bcmsdh_iovar_op(bus->sdh, "sd_divisor", NULL, 0, |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 736 | &iovalue, sizeof(iovalue), true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 737 | if (err) { |
| 738 | DHD_ERROR(("%s: error changing sd_divisor: %d\n", |
| 739 | __func__, err)); |
| 740 | return BCME_ERROR; |
| 741 | } |
| 742 | } |
| 743 | bus->clkstate = CLK_NONE; |
| 744 | } |
| 745 | |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 746 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | /* Transition SD and backplane clock readiness */ |
| 750 | static int dhdsdio_clkctl(dhd_bus_t *bus, uint target, bool pendok) |
| 751 | { |
| 752 | #ifdef DHD_DEBUG |
| 753 | uint oldstate = bus->clkstate; |
| 754 | #endif /* DHD_DEBUG */ |
| 755 | |
| 756 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 757 | |
| 758 | /* Early exit if we're already there */ |
| 759 | if (bus->clkstate == target) { |
| 760 | if (target == CLK_AVAIL) { |
| 761 | dhd_os_wd_timer(bus->dhd, dhd_watchdog_ms); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 762 | bus->activity = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 763 | } |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 764 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | switch (target) { |
| 768 | case CLK_AVAIL: |
| 769 | /* Make sure SD clock is available */ |
| 770 | if (bus->clkstate == CLK_NONE) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 771 | dhdsdio_sdclk(bus, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 772 | /* Now request HT Avail on the backplane */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 773 | dhdsdio_htclk(bus, true, pendok); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 774 | dhd_os_wd_timer(bus->dhd, dhd_watchdog_ms); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 775 | bus->activity = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 776 | break; |
| 777 | |
| 778 | case CLK_SDONLY: |
| 779 | /* Remove HT request, or bring up SD clock */ |
| 780 | if (bus->clkstate == CLK_NONE) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 781 | dhdsdio_sdclk(bus, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 782 | else if (bus->clkstate == CLK_AVAIL) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 783 | dhdsdio_htclk(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 784 | else |
| 785 | DHD_ERROR(("dhdsdio_clkctl: request for %d -> %d\n", |
| 786 | bus->clkstate, target)); |
| 787 | dhd_os_wd_timer(bus->dhd, dhd_watchdog_ms); |
| 788 | break; |
| 789 | |
| 790 | case CLK_NONE: |
| 791 | /* Make sure to remove HT request */ |
| 792 | if (bus->clkstate == CLK_AVAIL) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 793 | dhdsdio_htclk(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 794 | /* Now remove the SD clock */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 795 | dhdsdio_sdclk(bus, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 796 | dhd_os_wd_timer(bus->dhd, 0); |
| 797 | break; |
| 798 | } |
| 799 | #ifdef DHD_DEBUG |
| 800 | DHD_INFO(("dhdsdio_clkctl: %d -> %d\n", oldstate, bus->clkstate)); |
| 801 | #endif /* DHD_DEBUG */ |
| 802 | |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 803 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | int dhdsdio_bussleep(dhd_bus_t *bus, bool sleep) |
| 807 | { |
| 808 | bcmsdh_info_t *sdh = bus->sdh; |
| 809 | sdpcmd_regs_t *regs = bus->regs; |
| 810 | uint retries = 0; |
| 811 | |
| 812 | DHD_INFO(("dhdsdio_bussleep: request %s (currently %s)\n", |
| 813 | (sleep ? "SLEEP" : "WAKE"), |
| 814 | (bus->sleeping ? "SLEEP" : "WAKE"))); |
| 815 | |
| 816 | /* Done if we're already in the requested state */ |
| 817 | if (sleep == bus->sleeping) |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 818 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 819 | |
| 820 | /* Going to sleep: set the alarm and turn off the lights... */ |
| 821 | if (sleep) { |
| 822 | /* Don't sleep if something is pending */ |
| 823 | if (bus->dpc_sched || bus->rxskip || pktq_len(&bus->txq)) |
| 824 | return BCME_BUSY; |
| 825 | |
| 826 | /* Disable SDIO interrupts (no longer interested) */ |
| 827 | bcmsdh_intr_disable(bus->sdh); |
| 828 | |
| 829 | /* Make sure the controller has the bus up */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 830 | dhdsdio_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 831 | |
| 832 | /* Tell device to start using OOB wakeup */ |
| 833 | W_SDREG(SMB_USE_OOB, ®s->tosbmailbox, retries); |
| 834 | if (retries > retry_limit) |
| 835 | DHD_ERROR(("CANNOT SIGNAL CHIP, WILL NOT WAKE UP!!\n")); |
| 836 | |
| 837 | /* Turn off our contribution to the HT clock request */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 838 | dhdsdio_clkctl(bus, CLK_SDONLY, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 839 | |
| 840 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 841 | SBSDIO_FORCE_HW_CLKREQ_OFF, NULL); |
| 842 | |
| 843 | /* Isolate the bus */ |
| 844 | if (bus->sih->chip != BCM4329_CHIP_ID |
| 845 | && bus->sih->chip != BCM4319_CHIP_ID) { |
| 846 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL, |
| 847 | SBSDIO_DEVCTL_PADS_ISO, NULL); |
| 848 | } |
| 849 | |
| 850 | /* Change state */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 851 | bus->sleeping = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 852 | |
| 853 | } else { |
| 854 | /* Waking up: bus power up is ok, set local state */ |
| 855 | |
| 856 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 857 | 0, NULL); |
| 858 | |
| 859 | /* Force pad isolation off if possible |
| 860 | (in case power never toggled) */ |
| 861 | if ((bus->sih->buscoretype == PCMCIA_CORE_ID) |
| 862 | && (bus->sih->buscorerev >= 10)) |
| 863 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL, 0, |
| 864 | NULL); |
| 865 | |
| 866 | /* Make sure the controller has the bus up */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 867 | dhdsdio_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 868 | |
| 869 | /* Send misc interrupt to indicate OOB not needed */ |
| 870 | W_SDREG(0, ®s->tosbmailboxdata, retries); |
| 871 | if (retries <= retry_limit) |
| 872 | W_SDREG(SMB_DEV_INT, ®s->tosbmailbox, retries); |
| 873 | |
| 874 | if (retries > retry_limit) |
| 875 | DHD_ERROR(("CANNOT SIGNAL CHIP TO CLEAR OOB!!\n")); |
| 876 | |
| 877 | /* Make sure we have SD bus access */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 878 | dhdsdio_clkctl(bus, CLK_SDONLY, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 879 | |
| 880 | /* Change state */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 881 | bus->sleeping = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 882 | |
| 883 | /* Enable interrupts again */ |
| 884 | if (bus->intr && (bus->dhd->busstate == DHD_BUS_DATA)) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 885 | bus->intdis = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 886 | bcmsdh_intr_enable(bus->sdh); |
| 887 | } |
| 888 | } |
| 889 | |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 890 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | #if defined(OOB_INTR_ONLY) |
| 894 | void dhd_enable_oob_intr(struct dhd_bus *bus, bool enable) |
| 895 | { |
| 896 | #if defined(HW_OOB) |
| 897 | bcmsdh_enable_hw_oob_intr(bus->sdh, enable); |
| 898 | #else |
| 899 | sdpcmd_regs_t *regs = bus->regs; |
| 900 | uint retries = 0; |
| 901 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 902 | dhdsdio_clkctl(bus, CLK_AVAIL, false); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 903 | if (enable == true) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 904 | |
| 905 | /* Tell device to start using OOB wakeup */ |
| 906 | W_SDREG(SMB_USE_OOB, ®s->tosbmailbox, retries); |
| 907 | if (retries > retry_limit) |
| 908 | DHD_ERROR(("CANNOT SIGNAL CHIP, WILL NOT WAKE UP!!\n")); |
| 909 | |
| 910 | } else { |
| 911 | /* Send misc interrupt to indicate OOB not needed */ |
| 912 | W_SDREG(0, ®s->tosbmailboxdata, retries); |
| 913 | if (retries <= retry_limit) |
| 914 | W_SDREG(SMB_DEV_INT, ®s->tosbmailbox, retries); |
| 915 | } |
| 916 | |
| 917 | /* Turn off our contribution to the HT clock request */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 918 | dhdsdio_clkctl(bus, CLK_SDONLY, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 919 | #endif /* !defined(HW_OOB) */ |
| 920 | } |
| 921 | #endif /* defined(OOB_INTR_ONLY) */ |
| 922 | |
| 923 | #define BUS_WAKE(bus) \ |
| 924 | do { \ |
| 925 | if ((bus)->sleeping) \ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 926 | dhdsdio_bussleep((bus), false); \ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 927 | } while (0); |
| 928 | |
| 929 | /* Writes a HW/SW header into the packet and sends it. */ |
| 930 | /* Assumes: (a) header space already there, (b) caller holds lock */ |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 931 | static int dhdsdio_txpkt(dhd_bus_t *bus, struct sk_buff *pkt, uint chan, |
| 932 | bool free_pkt) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 933 | { |
| 934 | int ret; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 935 | u8 *frame; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 936 | u16 len, pad = 0; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 937 | u32 swheader; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 938 | uint retries = 0; |
| 939 | bcmsdh_info_t *sdh; |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 940 | struct sk_buff *new; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 941 | int i; |
| 942 | |
| 943 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 944 | |
| 945 | sdh = bus->sdh; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 946 | |
| 947 | if (bus->dhd->dongle_reset) { |
| 948 | ret = BCME_NOTREADY; |
| 949 | goto done; |
| 950 | } |
| 951 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 952 | frame = (u8 *) (pkt->data); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 953 | |
| 954 | /* Add alignment padding, allocate new packet if needed */ |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 955 | pad = ((unsigned long)frame % DHD_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 956 | if (pad) { |
Arend van Spriel | 3be727c | 2010-11-23 22:20:30 +0100 | [diff] [blame] | 957 | if (skb_headroom(pkt) < pad) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 958 | DHD_INFO(("%s: insufficient headroom %d for %d pad\n", |
Arend van Spriel | 3be727c | 2010-11-23 22:20:30 +0100 | [diff] [blame] | 959 | __func__, skb_headroom(pkt), pad)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 960 | bus->dhd->tx_realloc++; |
Arend van Spriel | a30825a | 2011-03-02 21:18:46 +0100 | [diff] [blame] | 961 | new = pkt_buf_get_skb(pkt->len + DHD_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 962 | if (!new) { |
| 963 | DHD_ERROR(("%s: couldn't allocate new %d-byte " |
| 964 | "packet\n", |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 965 | __func__, pkt->len + DHD_SDALIGN)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 966 | ret = BCME_NOMEM; |
| 967 | goto done; |
| 968 | } |
| 969 | |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 970 | PKTALIGN(new, pkt->len, DHD_SDALIGN); |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 971 | memcpy(new->data, pkt->data, pkt->len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 972 | if (free_pkt) |
Arend van Spriel | a30825a | 2011-03-02 21:18:46 +0100 | [diff] [blame] | 973 | pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 974 | /* free the pkt if canned one is not used */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 975 | free_pkt = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 976 | pkt = new; |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 977 | frame = (u8 *) (pkt->data); |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 978 | ASSERT(((unsigned long)frame % DHD_SDALIGN) == 0); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 979 | pad = 0; |
| 980 | } else { |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 981 | skb_push(pkt, pad); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 982 | frame = (u8 *) (pkt->data); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 983 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 984 | ASSERT((pad + SDPCM_HDRLEN) <= (int)(pkt->len)); |
Brett Rudley | 9249ede | 2010-11-30 20:09:49 -0800 | [diff] [blame] | 985 | memset(frame, 0, pad + SDPCM_HDRLEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 986 | } |
| 987 | } |
| 988 | ASSERT(pad < DHD_SDALIGN); |
| 989 | |
| 990 | /* 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] | 991 | len = (u16) (pkt->len); |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 992 | *(u16 *) frame = cpu_to_le16(len); |
| 993 | *(((u16 *) frame) + 1) = cpu_to_le16(~len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 994 | |
| 995 | /* Software tag: channel, sequence number, data offset */ |
| 996 | swheader = |
| 997 | ((chan << SDPCM_CHANNEL_SHIFT) & SDPCM_CHANNEL_MASK) | bus->tx_seq | |
| 998 | (((pad + |
| 999 | SDPCM_HDRLEN) << SDPCM_DOFFSET_SHIFT) & SDPCM_DOFFSET_MASK); |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 1000 | |
| 1001 | put_unaligned_le32(swheader, frame + SDPCM_FRAMETAG_LEN); |
| 1002 | put_unaligned_le32(0, frame + SDPCM_FRAMETAG_LEN + sizeof(swheader)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1003 | |
| 1004 | #ifdef DHD_DEBUG |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1005 | tx_packets[pkt->priority]++; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1006 | if (DHD_BYTES_ON() && |
| 1007 | (((DHD_CTL_ON() && (chan == SDPCM_CONTROL_CHANNEL)) || |
| 1008 | (DHD_DATA_ON() && (chan != SDPCM_CONTROL_CHANNEL))))) { |
| 1009 | prhex("Tx Frame", frame, len); |
| 1010 | } else if (DHD_HDRS_ON()) { |
Greg Kroah-Hartman | b61640d | 2010-10-08 12:37:39 -0700 | [diff] [blame] | 1011 | prhex("TxHdr", frame, min_t(u16, len, 16)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1012 | } |
| 1013 | #endif |
| 1014 | |
| 1015 | /* Raise len to next SDIO block to eliminate tail command */ |
| 1016 | if (bus->roundup && bus->blocksize && (len > bus->blocksize)) { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 1017 | u16 pad = bus->blocksize - (len % bus->blocksize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1018 | if ((pad <= bus->roundup) && (pad < bus->blocksize)) |
| 1019 | #ifdef NOTUSED |
Arend van Spriel | 3be727c | 2010-11-23 22:20:30 +0100 | [diff] [blame] | 1020 | if (pad <= skb_tailroom(pkt)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1021 | #endif /* NOTUSED */ |
| 1022 | len += pad; |
| 1023 | } else if (len % DHD_SDALIGN) { |
| 1024 | len += DHD_SDALIGN - (len % DHD_SDALIGN); |
| 1025 | } |
| 1026 | |
| 1027 | /* Some controllers have trouble with odd bytes -- round to even */ |
| 1028 | if (forcealign && (len & (ALIGNMENT - 1))) { |
| 1029 | #ifdef NOTUSED |
Arend van Spriel | 3be727c | 2010-11-23 22:20:30 +0100 | [diff] [blame] | 1030 | if (skb_tailroom(pkt)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1031 | #endif |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 1032 | len = roundup(len, ALIGNMENT); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1033 | #ifdef NOTUSED |
| 1034 | else |
| 1035 | DHD_ERROR(("%s: sending unrounded %d-byte packet\n", |
| 1036 | __func__, len)); |
| 1037 | #endif |
| 1038 | } |
| 1039 | |
| 1040 | do { |
| 1041 | ret = |
| 1042 | dhd_bcmsdh_send_buf(bus, bcmsdh_cur_sbwad(sdh), SDIO_FUNC_2, |
| 1043 | F2SYNC, frame, len, pkt, NULL, NULL); |
| 1044 | bus->f2txdata++; |
| 1045 | ASSERT(ret != BCME_PENDING); |
| 1046 | |
| 1047 | if (ret < 0) { |
| 1048 | /* On failure, abort the command |
| 1049 | and terminate the frame */ |
| 1050 | DHD_INFO(("%s: sdio error %d, abort command and " |
| 1051 | "terminate frame.\n", __func__, ret)); |
| 1052 | bus->tx_sderrs++; |
| 1053 | |
| 1054 | bcmsdh_abort(sdh, SDIO_FUNC_2); |
| 1055 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, |
| 1056 | SBSDIO_FUNC1_FRAMECTRL, SFC_WF_TERM, |
| 1057 | NULL); |
| 1058 | bus->f1regdata++; |
| 1059 | |
| 1060 | for (i = 0; i < 3; i++) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1061 | u8 hi, lo; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1062 | hi = bcmsdh_cfg_read(sdh, SDIO_FUNC_1, |
| 1063 | SBSDIO_FUNC1_WFRAMEBCHI, |
| 1064 | NULL); |
| 1065 | lo = bcmsdh_cfg_read(sdh, SDIO_FUNC_1, |
| 1066 | SBSDIO_FUNC1_WFRAMEBCLO, |
| 1067 | NULL); |
| 1068 | bus->f1regdata += 2; |
| 1069 | if ((hi == 0) && (lo == 0)) |
| 1070 | break; |
| 1071 | } |
| 1072 | |
| 1073 | } |
| 1074 | if (ret == 0) |
| 1075 | bus->tx_seq = (bus->tx_seq + 1) % SDPCM_SEQUENCE_WRAP; |
| 1076 | |
| 1077 | } while ((ret < 0) && retrydata && retries++ < TXRETRIES); |
| 1078 | |
| 1079 | done: |
| 1080 | /* restore pkt buffer pointer before calling tx complete routine */ |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 1081 | skb_pull(pkt, SDPCM_HDRLEN + pad); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1082 | dhd_os_sdunlock(bus->dhd); |
| 1083 | dhd_txcomplete(bus->dhd, pkt, ret != 0); |
| 1084 | dhd_os_sdlock(bus->dhd); |
| 1085 | |
| 1086 | if (free_pkt) |
Arend van Spriel | a30825a | 2011-03-02 21:18:46 +0100 | [diff] [blame] | 1087 | pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1088 | |
| 1089 | return ret; |
| 1090 | } |
| 1091 | |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 1092 | int dhd_bus_txdata(struct dhd_bus *bus, struct sk_buff *pkt) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1093 | { |
| 1094 | int ret = BCME_ERROR; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1095 | uint datalen, prec; |
| 1096 | |
| 1097 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 1098 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1099 | datalen = pkt->len; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1100 | |
| 1101 | #ifdef SDTEST |
| 1102 | /* Push the test header if doing loopback */ |
| 1103 | if (bus->ext_loop) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1104 | u8 *data; |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 1105 | skb_push(pkt, SDPCM_TEST_HDRLEN); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1106 | data = pkt->data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1107 | *data++ = SDPCM_TEST_ECHOREQ; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1108 | *data++ = (u8) bus->loopid++; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1109 | *data++ = (datalen >> 0); |
| 1110 | *data++ = (datalen >> 8); |
| 1111 | datalen += SDPCM_TEST_HDRLEN; |
| 1112 | } |
| 1113 | #endif /* SDTEST */ |
| 1114 | |
| 1115 | /* Add space for the header */ |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 1116 | skb_push(pkt, SDPCM_HDRLEN); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1117 | ASSERT(IS_ALIGNED((unsigned long)(pkt->data), 2)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1118 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1119 | prec = PRIO2PREC((pkt->priority & PRIOMASK)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1120 | |
| 1121 | /* Check for existing queue, current flow-control, |
| 1122 | pending event, or pending clock */ |
| 1123 | if (dhd_deferred_tx || bus->fcstate || pktq_len(&bus->txq) |
| 1124 | || bus->dpc_sched || (!DATAOK(bus)) |
| 1125 | || (bus->flowcontrol & NBITVAL(prec)) |
| 1126 | || (bus->clkstate != CLK_AVAIL)) { |
| 1127 | DHD_TRACE(("%s: deferring pktq len %d\n", __func__, |
| 1128 | pktq_len(&bus->txq))); |
| 1129 | bus->fcqueued++; |
| 1130 | |
| 1131 | /* Priority based enq */ |
| 1132 | dhd_os_sdlock_txq(bus->dhd); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1133 | if (dhd_prec_enq(bus->dhd, &bus->txq, pkt, prec) == false) { |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 1134 | skb_pull(pkt, SDPCM_HDRLEN); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1135 | dhd_txcomplete(bus->dhd, pkt, false); |
Arend van Spriel | a30825a | 2011-03-02 21:18:46 +0100 | [diff] [blame] | 1136 | pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1137 | DHD_ERROR(("%s: out of bus->txq !!!\n", __func__)); |
| 1138 | ret = BCME_NORESOURCE; |
| 1139 | } else { |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 1140 | ret = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1141 | } |
| 1142 | dhd_os_sdunlock_txq(bus->dhd); |
| 1143 | |
Grant Grundler | 7c31607 | 2011-03-09 15:04:15 -0800 | [diff] [blame] | 1144 | if (pktq_len(&bus->txq) >= TXHI) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1145 | dhd_txflowcontrol(bus->dhd, 0, ON); |
| 1146 | |
| 1147 | #ifdef DHD_DEBUG |
| 1148 | if (pktq_plen(&bus->txq, prec) > qcount[prec]) |
| 1149 | qcount[prec] = pktq_plen(&bus->txq, prec); |
| 1150 | #endif |
| 1151 | /* Schedule DPC if needed to send queued packet(s) */ |
| 1152 | if (dhd_deferred_tx && !bus->dpc_sched) { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1153 | bus->dpc_sched = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1154 | dhd_sched_dpc(bus->dhd); |
| 1155 | } |
| 1156 | } else { |
| 1157 | /* Lock: we're about to use shared data/code (and SDIO) */ |
| 1158 | dhd_os_sdlock(bus->dhd); |
| 1159 | |
| 1160 | /* Otherwise, send it now */ |
| 1161 | BUS_WAKE(bus); |
| 1162 | /* Make sure back plane ht clk is on, no pending allowed */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1163 | dhdsdio_clkctl(bus, CLK_AVAIL, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1164 | |
| 1165 | #ifndef SDTEST |
| 1166 | DHD_TRACE(("%s: calling txpkt\n", __func__)); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1167 | ret = dhdsdio_txpkt(bus, pkt, SDPCM_DATA_CHANNEL, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1168 | #else |
| 1169 | ret = dhdsdio_txpkt(bus, pkt, |
| 1170 | (bus->ext_loop ? SDPCM_TEST_CHANNEL : |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1171 | SDPCM_DATA_CHANNEL), true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1172 | #endif |
| 1173 | if (ret) |
| 1174 | bus->dhd->tx_errors++; |
| 1175 | else |
| 1176 | bus->dhd->dstats.tx_bytes += datalen; |
| 1177 | |
| 1178 | if ((bus->idletime == DHD_IDLE_IMMEDIATE) && !bus->dpc_sched) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1179 | bus->activity = false; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1180 | dhdsdio_clkctl(bus, CLK_NONE, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1181 | } |
| 1182 | |
| 1183 | dhd_os_sdunlock(bus->dhd); |
| 1184 | } |
| 1185 | |
| 1186 | return ret; |
| 1187 | } |
| 1188 | |
| 1189 | static uint dhdsdio_sendfromq(dhd_bus_t *bus, uint maxframes) |
| 1190 | { |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 1191 | struct sk_buff *pkt; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1192 | u32 intstatus = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1193 | uint retries = 0; |
| 1194 | int ret = 0, prec_out; |
| 1195 | uint cnt = 0; |
| 1196 | uint datalen; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1197 | u8 tx_prec_map; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1198 | |
| 1199 | dhd_pub_t *dhd = bus->dhd; |
| 1200 | sdpcmd_regs_t *regs = bus->regs; |
| 1201 | |
| 1202 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 1203 | |
| 1204 | tx_prec_map = ~bus->flowcontrol; |
| 1205 | |
| 1206 | /* Send frames until the limit or some other event */ |
| 1207 | for (cnt = 0; (cnt < maxframes) && DATAOK(bus); cnt++) { |
| 1208 | dhd_os_sdlock_txq(bus->dhd); |
| 1209 | pkt = pktq_mdeq(&bus->txq, tx_prec_map, &prec_out); |
| 1210 | if (pkt == NULL) { |
| 1211 | dhd_os_sdunlock_txq(bus->dhd); |
| 1212 | break; |
| 1213 | } |
| 1214 | dhd_os_sdunlock_txq(bus->dhd); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 1215 | datalen = pkt->len - SDPCM_HDRLEN; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1216 | |
| 1217 | #ifndef SDTEST |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1218 | ret = dhdsdio_txpkt(bus, pkt, SDPCM_DATA_CHANNEL, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1219 | #else |
| 1220 | ret = dhdsdio_txpkt(bus, pkt, |
| 1221 | (bus->ext_loop ? SDPCM_TEST_CHANNEL : |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1222 | SDPCM_DATA_CHANNEL), true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1223 | #endif |
| 1224 | if (ret) |
| 1225 | bus->dhd->tx_errors++; |
| 1226 | else |
| 1227 | bus->dhd->dstats.tx_bytes += datalen; |
| 1228 | |
| 1229 | /* In poll mode, need to check for other events */ |
| 1230 | if (!bus->intr && cnt) { |
| 1231 | /* Check device status, signal pending interrupt */ |
| 1232 | R_SDREG(intstatus, ®s->intstatus, retries); |
| 1233 | bus->f2txdata++; |
| 1234 | if (bcmsdh_regfail(bus->sdh)) |
| 1235 | break; |
| 1236 | if (intstatus & bus->hostintmask) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1237 | bus->ipend = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1238 | } |
| 1239 | } |
| 1240 | |
| 1241 | /* Deflow-control stack if needed */ |
Grant Grundler | 7c31607 | 2011-03-09 15:04:15 -0800 | [diff] [blame] | 1242 | if (dhd->up && (dhd->busstate == DHD_BUS_DATA) && |
Grant Grundler | 26a71a4 | 2011-03-09 10:41:25 -0800 | [diff] [blame] | 1243 | dhd->txoff && (pktq_len(&bus->txq) < TXLOW)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1244 | dhd_txflowcontrol(dhd, 0, OFF); |
| 1245 | |
| 1246 | return cnt; |
| 1247 | } |
| 1248 | |
Greg Kroah-Hartman | 580a0bd | 2010-10-05 11:09:48 -0700 | [diff] [blame] | 1249 | 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] | 1250 | { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1251 | u8 *frame; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 1252 | u16 len; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1253 | u32 swheader; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1254 | uint retries = 0; |
| 1255 | bcmsdh_info_t *sdh = bus->sdh; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1256 | u8 doff = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1257 | int ret = -1; |
| 1258 | int i; |
| 1259 | |
| 1260 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 1261 | |
| 1262 | if (bus->dhd->dongle_reset) |
| 1263 | return -EIO; |
| 1264 | |
| 1265 | /* Back the pointer to make a room for bus header */ |
| 1266 | frame = msg - SDPCM_HDRLEN; |
| 1267 | len = (msglen += SDPCM_HDRLEN); |
| 1268 | |
| 1269 | /* Add alignment padding (optional for ctl frames) */ |
| 1270 | if (dhd_alignctl) { |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 1271 | doff = ((unsigned long)frame % DHD_SDALIGN); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 1272 | if (doff) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1273 | frame -= doff; |
| 1274 | len += doff; |
| 1275 | msglen += doff; |
Brett Rudley | 9249ede | 2010-11-30 20:09:49 -0800 | [diff] [blame] | 1276 | memset(frame, 0, doff + SDPCM_HDRLEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1277 | } |
| 1278 | ASSERT(doff < DHD_SDALIGN); |
| 1279 | } |
| 1280 | doff += SDPCM_HDRLEN; |
| 1281 | |
| 1282 | /* Round send length to next SDIO block */ |
| 1283 | if (bus->roundup && bus->blocksize && (len > bus->blocksize)) { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 1284 | u16 pad = bus->blocksize - (len % bus->blocksize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1285 | if ((pad <= bus->roundup) && (pad < bus->blocksize)) |
| 1286 | len += pad; |
| 1287 | } else if (len % DHD_SDALIGN) { |
| 1288 | len += DHD_SDALIGN - (len % DHD_SDALIGN); |
| 1289 | } |
| 1290 | |
| 1291 | /* Satisfy length-alignment requirements */ |
| 1292 | if (forcealign && (len & (ALIGNMENT - 1))) |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 1293 | len = roundup(len, ALIGNMENT); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1294 | |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 1295 | ASSERT(IS_ALIGNED((unsigned long)frame, 2)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1296 | |
| 1297 | /* Need to lock here to protect txseq and SDIO tx calls */ |
| 1298 | dhd_os_sdlock(bus->dhd); |
| 1299 | |
| 1300 | BUS_WAKE(bus); |
| 1301 | |
| 1302 | /* Make sure backplane clock is on */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1303 | dhdsdio_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1304 | |
| 1305 | /* 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] | 1306 | *(u16 *) frame = cpu_to_le16((u16) msglen); |
| 1307 | *(((u16 *) frame) + 1) = cpu_to_le16(~msglen); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1308 | |
| 1309 | /* Software tag: channel, sequence number, data offset */ |
| 1310 | swheader = |
| 1311 | ((SDPCM_CONTROL_CHANNEL << SDPCM_CHANNEL_SHIFT) & |
| 1312 | SDPCM_CHANNEL_MASK) |
| 1313 | | bus->tx_seq | ((doff << SDPCM_DOFFSET_SHIFT) & |
| 1314 | SDPCM_DOFFSET_MASK); |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 1315 | put_unaligned_le32(swheader, frame + SDPCM_FRAMETAG_LEN); |
| 1316 | put_unaligned_le32(0, frame + SDPCM_FRAMETAG_LEN + sizeof(swheader)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1317 | |
| 1318 | if (!DATAOK(bus)) { |
| 1319 | DHD_INFO(("%s: No bus credit bus->tx_max %d, bus->tx_seq %d\n", |
| 1320 | __func__, bus->tx_max, bus->tx_seq)); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1321 | bus->ctrl_frame_stat = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1322 | /* Send from dpc */ |
| 1323 | bus->ctrl_frame_buf = frame; |
| 1324 | bus->ctrl_frame_len = len; |
| 1325 | |
| 1326 | dhd_wait_for_event(bus->dhd, &bus->ctrl_frame_stat); |
| 1327 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1328 | if (bus->ctrl_frame_stat == false) { |
| 1329 | DHD_INFO(("%s: ctrl_frame_stat == false\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1330 | ret = 0; |
| 1331 | } else { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1332 | DHD_INFO(("%s: ctrl_frame_stat == true\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1333 | ret = -1; |
| 1334 | } |
| 1335 | } |
| 1336 | |
| 1337 | if (ret == -1) { |
| 1338 | #ifdef DHD_DEBUG |
| 1339 | if (DHD_BYTES_ON() && DHD_CTL_ON()) |
| 1340 | prhex("Tx Frame", frame, len); |
| 1341 | else if (DHD_HDRS_ON()) |
Greg Kroah-Hartman | b61640d | 2010-10-08 12:37:39 -0700 | [diff] [blame] | 1342 | prhex("TxHdr", frame, min_t(u16, len, 16)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1343 | #endif |
| 1344 | |
| 1345 | do { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1346 | bus->ctrl_frame_stat = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1347 | ret = |
| 1348 | dhd_bcmsdh_send_buf(bus, bcmsdh_cur_sbwad(sdh), |
| 1349 | SDIO_FUNC_2, F2SYNC, frame, len, |
| 1350 | NULL, NULL, NULL); |
| 1351 | |
| 1352 | ASSERT(ret != BCME_PENDING); |
| 1353 | |
| 1354 | if (ret < 0) { |
| 1355 | /* On failure, abort the command and |
| 1356 | terminate the frame */ |
| 1357 | DHD_INFO(("%s: sdio error %d, abort command and terminate frame.\n", |
| 1358 | __func__, ret)); |
| 1359 | bus->tx_sderrs++; |
| 1360 | |
| 1361 | bcmsdh_abort(sdh, SDIO_FUNC_2); |
| 1362 | |
| 1363 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, |
| 1364 | SBSDIO_FUNC1_FRAMECTRL, |
| 1365 | SFC_WF_TERM, NULL); |
| 1366 | bus->f1regdata++; |
| 1367 | |
| 1368 | for (i = 0; i < 3; i++) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1369 | u8 hi, lo; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1370 | hi = bcmsdh_cfg_read(sdh, SDIO_FUNC_1, |
| 1371 | SBSDIO_FUNC1_WFRAMEBCHI, |
| 1372 | NULL); |
| 1373 | lo = bcmsdh_cfg_read(sdh, SDIO_FUNC_1, |
| 1374 | SBSDIO_FUNC1_WFRAMEBCLO, |
| 1375 | NULL); |
| 1376 | bus->f1regdata += 2; |
| 1377 | if ((hi == 0) && (lo == 0)) |
| 1378 | break; |
| 1379 | } |
| 1380 | |
| 1381 | } |
| 1382 | if (ret == 0) { |
| 1383 | bus->tx_seq = |
| 1384 | (bus->tx_seq + 1) % SDPCM_SEQUENCE_WRAP; |
| 1385 | } |
| 1386 | } while ((ret < 0) && retries++ < TXRETRIES); |
| 1387 | } |
| 1388 | |
| 1389 | if ((bus->idletime == DHD_IDLE_IMMEDIATE) && !bus->dpc_sched) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1390 | bus->activity = false; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1391 | dhdsdio_clkctl(bus, CLK_NONE, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1392 | } |
| 1393 | |
| 1394 | dhd_os_sdunlock(bus->dhd); |
| 1395 | |
| 1396 | if (ret) |
| 1397 | bus->dhd->tx_ctlerrs++; |
| 1398 | else |
| 1399 | bus->dhd->tx_ctlpkts++; |
| 1400 | |
| 1401 | return ret ? -EIO : 0; |
| 1402 | } |
| 1403 | |
Greg Kroah-Hartman | 580a0bd | 2010-10-05 11:09:48 -0700 | [diff] [blame] | 1404 | 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] | 1405 | { |
| 1406 | int timeleft; |
| 1407 | uint rxlen = 0; |
| 1408 | bool pending; |
| 1409 | |
| 1410 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 1411 | |
| 1412 | if (bus->dhd->dongle_reset) |
| 1413 | return -EIO; |
| 1414 | |
| 1415 | /* Wait until control frame is available */ |
| 1416 | timeleft = dhd_os_ioctl_resp_wait(bus->dhd, &bus->rxlen, &pending); |
| 1417 | |
| 1418 | dhd_os_sdlock(bus->dhd); |
| 1419 | rxlen = bus->rxlen; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 1420 | memcpy(msg, bus->rxctl, min(msglen, rxlen)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1421 | bus->rxlen = 0; |
| 1422 | dhd_os_sdunlock(bus->dhd); |
| 1423 | |
| 1424 | if (rxlen) { |
| 1425 | DHD_CTL(("%s: resumed on rxctl frame, got %d expected %d\n", |
| 1426 | __func__, rxlen, msglen)); |
| 1427 | } else if (timeleft == 0) { |
| 1428 | DHD_ERROR(("%s: resumed on timeout\n", __func__)); |
| 1429 | #ifdef DHD_DEBUG |
| 1430 | dhd_os_sdlock(bus->dhd); |
| 1431 | dhdsdio_checkdied(bus, NULL, 0); |
| 1432 | dhd_os_sdunlock(bus->dhd); |
| 1433 | #endif /* DHD_DEBUG */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 1434 | } else if (pending == true) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1435 | DHD_CTL(("%s: cancelled\n", __func__)); |
| 1436 | return -ERESTARTSYS; |
| 1437 | } else { |
| 1438 | DHD_CTL(("%s: resumed for unknown reason?\n", __func__)); |
| 1439 | #ifdef DHD_DEBUG |
| 1440 | dhd_os_sdlock(bus->dhd); |
| 1441 | dhdsdio_checkdied(bus, NULL, 0); |
| 1442 | dhd_os_sdunlock(bus->dhd); |
| 1443 | #endif /* DHD_DEBUG */ |
| 1444 | } |
| 1445 | |
| 1446 | if (rxlen) |
| 1447 | bus->dhd->rx_ctlpkts++; |
| 1448 | else |
| 1449 | bus->dhd->rx_ctlerrs++; |
| 1450 | |
Jason Cooper | e9887c9 | 2010-10-06 10:08:02 -0400 | [diff] [blame] | 1451 | return rxlen ? (int)rxlen : -ETIMEDOUT; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1452 | } |
| 1453 | |
| 1454 | /* IOVar table */ |
| 1455 | enum { |
| 1456 | IOV_INTR = 1, |
| 1457 | IOV_POLLRATE, |
| 1458 | IOV_SDREG, |
| 1459 | IOV_SBREG, |
| 1460 | IOV_SDCIS, |
| 1461 | IOV_MEMBYTES, |
| 1462 | IOV_MEMSIZE, |
| 1463 | #ifdef DHD_DEBUG |
| 1464 | IOV_CHECKDIED, |
| 1465 | #endif |
| 1466 | IOV_DOWNLOAD, |
| 1467 | IOV_FORCEEVEN, |
| 1468 | IOV_SDIOD_DRIVE, |
| 1469 | IOV_READAHEAD, |
| 1470 | IOV_SDRXCHAIN, |
| 1471 | IOV_ALIGNCTL, |
| 1472 | IOV_SDALIGN, |
| 1473 | IOV_DEVRESET, |
| 1474 | IOV_CPU, |
| 1475 | #ifdef SDTEST |
| 1476 | IOV_PKTGEN, |
| 1477 | IOV_EXTLOOP, |
| 1478 | #endif /* SDTEST */ |
| 1479 | IOV_SPROM, |
| 1480 | IOV_TXBOUND, |
| 1481 | IOV_RXBOUND, |
| 1482 | IOV_TXMINMAX, |
| 1483 | IOV_IDLETIME, |
| 1484 | IOV_IDLECLOCK, |
| 1485 | IOV_SD1IDLE, |
| 1486 | IOV_SLEEP, |
| 1487 | IOV_VARS |
| 1488 | }; |
| 1489 | |
| 1490 | const bcm_iovar_t dhdsdio_iovars[] = { |
| 1491 | {"intr", IOV_INTR, 0, IOVT_BOOL, 0}, |
| 1492 | {"sleep", IOV_SLEEP, 0, IOVT_BOOL, 0}, |
| 1493 | {"pollrate", IOV_POLLRATE, 0, IOVT_UINT32, 0}, |
| 1494 | {"idletime", IOV_IDLETIME, 0, IOVT_INT32, 0}, |
| 1495 | {"idleclock", IOV_IDLECLOCK, 0, IOVT_INT32, 0}, |
| 1496 | {"sd1idle", IOV_SD1IDLE, 0, IOVT_BOOL, 0}, |
| 1497 | {"membytes", IOV_MEMBYTES, 0, IOVT_BUFFER, 2 * sizeof(int)}, |
| 1498 | {"memsize", IOV_MEMSIZE, 0, IOVT_UINT32, 0}, |
| 1499 | {"download", IOV_DOWNLOAD, 0, IOVT_BOOL, 0}, |
| 1500 | {"vars", IOV_VARS, 0, IOVT_BUFFER, 0}, |
| 1501 | {"sdiod_drive", IOV_SDIOD_DRIVE, 0, IOVT_UINT32, 0}, |
| 1502 | {"readahead", IOV_READAHEAD, 0, IOVT_BOOL, 0}, |
| 1503 | {"sdrxchain", IOV_SDRXCHAIN, 0, IOVT_BOOL, 0}, |
| 1504 | {"alignctl", IOV_ALIGNCTL, 0, IOVT_BOOL, 0}, |
| 1505 | {"sdalign", IOV_SDALIGN, 0, IOVT_BOOL, 0}, |
| 1506 | {"devreset", IOV_DEVRESET, 0, IOVT_BOOL, 0}, |
| 1507 | #ifdef DHD_DEBUG |
| 1508 | {"sdreg", IOV_SDREG, 0, IOVT_BUFFER, sizeof(sdreg_t)} |
| 1509 | , |
| 1510 | {"sbreg", IOV_SBREG, 0, IOVT_BUFFER, sizeof(sdreg_t)} |
| 1511 | , |
| 1512 | {"sd_cis", IOV_SDCIS, 0, IOVT_BUFFER, DHD_IOCTL_MAXLEN} |
| 1513 | , |
| 1514 | {"forcealign", IOV_FORCEEVEN, 0, IOVT_BOOL, 0} |
| 1515 | , |
| 1516 | {"txbound", IOV_TXBOUND, 0, IOVT_UINT32, 0} |
| 1517 | , |
| 1518 | {"rxbound", IOV_RXBOUND, 0, IOVT_UINT32, 0} |
| 1519 | , |
| 1520 | {"txminmax", IOV_TXMINMAX, 0, IOVT_UINT32, 0} |
| 1521 | , |
| 1522 | {"cpu", IOV_CPU, 0, IOVT_BOOL, 0} |
| 1523 | , |
| 1524 | #ifdef DHD_DEBUG |
| 1525 | {"checkdied", IOV_CHECKDIED, 0, IOVT_BUFFER, 0} |
| 1526 | , |
| 1527 | #endif /* DHD_DEBUG */ |
| 1528 | #endif /* DHD_DEBUG */ |
| 1529 | #ifdef SDTEST |
| 1530 | {"extloop", IOV_EXTLOOP, 0, IOVT_BOOL, 0} |
| 1531 | , |
| 1532 | {"pktgen", IOV_PKTGEN, 0, IOVT_BUFFER, sizeof(dhd_pktgen_t)} |
| 1533 | , |
| 1534 | #endif /* SDTEST */ |
| 1535 | |
| 1536 | {NULL, 0, 0, 0, 0} |
| 1537 | }; |
| 1538 | |
| 1539 | static void |
| 1540 | dhd_dump_pct(struct bcmstrbuf *strbuf, char *desc, uint num, uint div) |
| 1541 | { |
| 1542 | uint q1, q2; |
| 1543 | |
| 1544 | if (!div) { |
| 1545 | bcm_bprintf(strbuf, "%s N/A", desc); |
| 1546 | } else { |
| 1547 | q1 = num / div; |
| 1548 | q2 = (100 * (num - (q1 * div))) / div; |
| 1549 | bcm_bprintf(strbuf, "%s %d.%02d", desc, q1, q2); |
| 1550 | } |
| 1551 | } |
| 1552 | |
| 1553 | void dhd_bus_dump(dhd_pub_t *dhdp, struct bcmstrbuf *strbuf) |
| 1554 | { |
| 1555 | dhd_bus_t *bus = dhdp->bus; |
| 1556 | |
| 1557 | bcm_bprintf(strbuf, "Bus SDIO structure:\n"); |
| 1558 | bcm_bprintf(strbuf, |
| 1559 | "hostintmask 0x%08x intstatus 0x%08x sdpcm_ver %d\n", |
| 1560 | bus->hostintmask, bus->intstatus, bus->sdpcm_ver); |
| 1561 | bcm_bprintf(strbuf, |
| 1562 | "fcstate %d qlen %d tx_seq %d, max %d, rxskip %d rxlen %d rx_seq %d\n", |
| 1563 | bus->fcstate, pktq_len(&bus->txq), bus->tx_seq, bus->tx_max, |
| 1564 | bus->rxskip, bus->rxlen, bus->rx_seq); |
| 1565 | bcm_bprintf(strbuf, "intr %d intrcount %d lastintrs %d spurious %d\n", |
| 1566 | bus->intr, bus->intrcount, bus->lastintrs, bus->spurious); |
| 1567 | bcm_bprintf(strbuf, "pollrate %d pollcnt %d regfails %d\n", |
| 1568 | bus->pollrate, bus->pollcnt, bus->regfails); |
| 1569 | |
| 1570 | bcm_bprintf(strbuf, "\nAdditional counters:\n"); |
| 1571 | bcm_bprintf(strbuf, |
| 1572 | "tx_sderrs %d fcqueued %d rxrtx %d rx_toolong %d rxc_errors %d\n", |
| 1573 | bus->tx_sderrs, bus->fcqueued, bus->rxrtx, bus->rx_toolong, |
| 1574 | bus->rxc_errors); |
| 1575 | bcm_bprintf(strbuf, "rx_hdrfail %d badhdr %d badseq %d\n", |
| 1576 | bus->rx_hdrfail, bus->rx_badhdr, bus->rx_badseq); |
| 1577 | bcm_bprintf(strbuf, "fc_rcvd %d, fc_xoff %d, fc_xon %d\n", bus->fc_rcvd, |
| 1578 | bus->fc_xoff, bus->fc_xon); |
| 1579 | bcm_bprintf(strbuf, "rxglomfail %d, rxglomframes %d, rxglompkts %d\n", |
| 1580 | bus->rxglomfail, bus->rxglomframes, bus->rxglompkts); |
| 1581 | bcm_bprintf(strbuf, "f2rx (hdrs/data) %d (%d/%d), f2tx %d f1regs %d\n", |
| 1582 | (bus->f2rxhdrs + bus->f2rxdata), bus->f2rxhdrs, |
| 1583 | bus->f2rxdata, bus->f2txdata, bus->f1regdata); |
| 1584 | { |
| 1585 | dhd_dump_pct(strbuf, "\nRx: pkts/f2rd", bus->dhd->rx_packets, |
| 1586 | (bus->f2rxhdrs + bus->f2rxdata)); |
| 1587 | dhd_dump_pct(strbuf, ", pkts/f1sd", bus->dhd->rx_packets, |
| 1588 | bus->f1regdata); |
| 1589 | dhd_dump_pct(strbuf, ", pkts/sd", bus->dhd->rx_packets, |
| 1590 | (bus->f2rxhdrs + bus->f2rxdata + bus->f1regdata)); |
| 1591 | dhd_dump_pct(strbuf, ", pkts/int", bus->dhd->rx_packets, |
| 1592 | bus->intrcount); |
| 1593 | bcm_bprintf(strbuf, "\n"); |
| 1594 | |
| 1595 | dhd_dump_pct(strbuf, "Rx: glom pct", (100 * bus->rxglompkts), |
| 1596 | bus->dhd->rx_packets); |
| 1597 | dhd_dump_pct(strbuf, ", pkts/glom", bus->rxglompkts, |
| 1598 | bus->rxglomframes); |
| 1599 | bcm_bprintf(strbuf, "\n"); |
| 1600 | |
| 1601 | dhd_dump_pct(strbuf, "Tx: pkts/f2wr", bus->dhd->tx_packets, |
| 1602 | bus->f2txdata); |
| 1603 | dhd_dump_pct(strbuf, ", pkts/f1sd", bus->dhd->tx_packets, |
| 1604 | bus->f1regdata); |
| 1605 | dhd_dump_pct(strbuf, ", pkts/sd", bus->dhd->tx_packets, |
| 1606 | (bus->f2txdata + bus->f1regdata)); |
| 1607 | dhd_dump_pct(strbuf, ", pkts/int", bus->dhd->tx_packets, |
| 1608 | bus->intrcount); |
| 1609 | bcm_bprintf(strbuf, "\n"); |
| 1610 | |
| 1611 | dhd_dump_pct(strbuf, "Total: pkts/f2rw", |
| 1612 | (bus->dhd->tx_packets + bus->dhd->rx_packets), |
| 1613 | (bus->f2txdata + bus->f2rxhdrs + bus->f2rxdata)); |
| 1614 | dhd_dump_pct(strbuf, ", pkts/f1sd", |
| 1615 | (bus->dhd->tx_packets + bus->dhd->rx_packets), |
| 1616 | bus->f1regdata); |
| 1617 | dhd_dump_pct(strbuf, ", pkts/sd", |
| 1618 | (bus->dhd->tx_packets + bus->dhd->rx_packets), |
| 1619 | (bus->f2txdata + bus->f2rxhdrs + bus->f2rxdata + |
| 1620 | bus->f1regdata)); |
| 1621 | dhd_dump_pct(strbuf, ", pkts/int", |
| 1622 | (bus->dhd->tx_packets + bus->dhd->rx_packets), |
| 1623 | bus->intrcount); |
| 1624 | bcm_bprintf(strbuf, "\n\n"); |
| 1625 | } |
| 1626 | |
| 1627 | #ifdef SDTEST |
| 1628 | if (bus->pktgen_count) { |
| 1629 | bcm_bprintf(strbuf, "pktgen config and count:\n"); |
| 1630 | bcm_bprintf(strbuf, |
| 1631 | "freq %d count %d print %d total %d min %d len %d\n", |
| 1632 | bus->pktgen_freq, bus->pktgen_count, |
| 1633 | bus->pktgen_print, bus->pktgen_total, |
| 1634 | bus->pktgen_minlen, bus->pktgen_maxlen); |
| 1635 | bcm_bprintf(strbuf, "send attempts %d rcvd %d fail %d\n", |
| 1636 | bus->pktgen_sent, bus->pktgen_rcvd, |
| 1637 | bus->pktgen_fail); |
| 1638 | } |
| 1639 | #endif /* SDTEST */ |
| 1640 | #ifdef DHD_DEBUG |
| 1641 | bcm_bprintf(strbuf, "dpc_sched %d host interrupt%spending\n", |
| 1642 | bus->dpc_sched, |
| 1643 | (bcmsdh_intr_pending(bus->sdh) ? " " : " not ")); |
| 1644 | bcm_bprintf(strbuf, "blocksize %d roundup %d\n", bus->blocksize, |
| 1645 | bus->roundup); |
| 1646 | #endif /* DHD_DEBUG */ |
| 1647 | bcm_bprintf(strbuf, |
| 1648 | "clkstate %d activity %d idletime %d idlecount %d sleeping %d\n", |
| 1649 | bus->clkstate, bus->activity, bus->idletime, bus->idlecount, |
| 1650 | bus->sleeping); |
| 1651 | } |
| 1652 | |
| 1653 | void dhd_bus_clearcounts(dhd_pub_t *dhdp) |
| 1654 | { |
| 1655 | dhd_bus_t *bus = (dhd_bus_t *) dhdp->bus; |
| 1656 | |
| 1657 | bus->intrcount = bus->lastintrs = bus->spurious = bus->regfails = 0; |
| 1658 | bus->rxrtx = bus->rx_toolong = bus->rxc_errors = 0; |
| 1659 | bus->rx_hdrfail = bus->rx_badhdr = bus->rx_badseq = 0; |
| 1660 | bus->tx_sderrs = bus->fc_rcvd = bus->fc_xoff = bus->fc_xon = 0; |
| 1661 | bus->rxglomfail = bus->rxglomframes = bus->rxglompkts = 0; |
| 1662 | bus->f2rxhdrs = bus->f2rxdata = bus->f2txdata = bus->f1regdata = 0; |
| 1663 | } |
| 1664 | |
| 1665 | #ifdef SDTEST |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1666 | static int dhdsdio_pktgen_get(dhd_bus_t *bus, u8 *arg) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1667 | { |
| 1668 | dhd_pktgen_t pktgen; |
| 1669 | |
| 1670 | pktgen.version = DHD_PKTGEN_VERSION; |
| 1671 | pktgen.freq = bus->pktgen_freq; |
| 1672 | pktgen.count = bus->pktgen_count; |
| 1673 | pktgen.print = bus->pktgen_print; |
| 1674 | pktgen.total = bus->pktgen_total; |
| 1675 | pktgen.minlen = bus->pktgen_minlen; |
| 1676 | pktgen.maxlen = bus->pktgen_maxlen; |
| 1677 | pktgen.numsent = bus->pktgen_sent; |
| 1678 | pktgen.numrcvd = bus->pktgen_rcvd; |
| 1679 | pktgen.numfail = bus->pktgen_fail; |
| 1680 | pktgen.mode = bus->pktgen_mode; |
| 1681 | pktgen.stop = bus->pktgen_stop; |
| 1682 | |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 1683 | memcpy(arg, &pktgen, sizeof(pktgen)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1684 | |
| 1685 | return 0; |
| 1686 | } |
| 1687 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1688 | static int dhdsdio_pktgen_set(dhd_bus_t *bus, u8 *arg) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1689 | { |
| 1690 | dhd_pktgen_t pktgen; |
| 1691 | uint oldcnt, oldmode; |
| 1692 | |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 1693 | memcpy(&pktgen, arg, sizeof(pktgen)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1694 | if (pktgen.version != DHD_PKTGEN_VERSION) |
| 1695 | return BCME_BADARG; |
| 1696 | |
| 1697 | oldcnt = bus->pktgen_count; |
| 1698 | oldmode = bus->pktgen_mode; |
| 1699 | |
| 1700 | bus->pktgen_freq = pktgen.freq; |
| 1701 | bus->pktgen_count = pktgen.count; |
| 1702 | bus->pktgen_print = pktgen.print; |
| 1703 | bus->pktgen_total = pktgen.total; |
| 1704 | bus->pktgen_minlen = pktgen.minlen; |
| 1705 | bus->pktgen_maxlen = pktgen.maxlen; |
| 1706 | bus->pktgen_mode = pktgen.mode; |
| 1707 | bus->pktgen_stop = pktgen.stop; |
| 1708 | |
| 1709 | bus->pktgen_tick = bus->pktgen_ptick = 0; |
Greg Kroah-Hartman | 3ea2f4d | 2010-10-08 11:39:43 -0700 | [diff] [blame] | 1710 | bus->pktgen_len = max(bus->pktgen_len, bus->pktgen_minlen); |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 1711 | bus->pktgen_len = min(bus->pktgen_len, bus->pktgen_maxlen); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1712 | |
| 1713 | /* Clear counts for a new pktgen (mode change, or was stopped) */ |
| 1714 | if (bus->pktgen_count && (!oldcnt || oldmode != bus->pktgen_mode)) |
| 1715 | bus->pktgen_sent = bus->pktgen_rcvd = bus->pktgen_fail = 0; |
| 1716 | |
| 1717 | return 0; |
| 1718 | } |
| 1719 | #endif /* SDTEST */ |
| 1720 | |
| 1721 | static int |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1722 | dhdsdio_membytes(dhd_bus_t *bus, bool write, u32 address, u8 *data, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1723 | uint size) |
| 1724 | { |
| 1725 | int bcmerror = 0; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1726 | u32 sdaddr; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1727 | uint dsize; |
| 1728 | |
| 1729 | /* Determine initial transfer parameters */ |
| 1730 | sdaddr = address & SBSDIO_SB_OFT_ADDR_MASK; |
| 1731 | if ((sdaddr + size) & SBSDIO_SBWINDOW_MASK) |
| 1732 | dsize = (SBSDIO_SB_OFT_ADDR_LIMIT - sdaddr); |
| 1733 | else |
| 1734 | dsize = size; |
| 1735 | |
| 1736 | /* Set the backplane window to include the start address */ |
| 1737 | bcmerror = dhdsdio_set_siaddr_window(bus, address); |
| 1738 | if (bcmerror) { |
| 1739 | DHD_ERROR(("%s: window change failed\n", __func__)); |
| 1740 | goto xfer_done; |
| 1741 | } |
| 1742 | |
| 1743 | /* Do the transfer(s) */ |
| 1744 | while (size) { |
| 1745 | DHD_INFO(("%s: %s %d bytes at offset 0x%08x in window 0x%08x\n", |
| 1746 | __func__, (write ? "write" : "read"), dsize, |
| 1747 | sdaddr, (address & SBSDIO_SBWINDOW_MASK))); |
| 1748 | bcmerror = |
| 1749 | bcmsdh_rwdata(bus->sdh, write, sdaddr, data, dsize); |
| 1750 | if (bcmerror) { |
| 1751 | DHD_ERROR(("%s: membytes transfer failed\n", __func__)); |
| 1752 | break; |
| 1753 | } |
| 1754 | |
| 1755 | /* Adjust for next transfer (if any) */ |
| 1756 | size -= dsize; |
| 1757 | if (size) { |
| 1758 | data += dsize; |
| 1759 | address += dsize; |
| 1760 | bcmerror = dhdsdio_set_siaddr_window(bus, address); |
| 1761 | if (bcmerror) { |
| 1762 | DHD_ERROR(("%s: window change failed\n", |
| 1763 | __func__)); |
| 1764 | break; |
| 1765 | } |
| 1766 | sdaddr = 0; |
Greg Kroah-Hartman | b61640d | 2010-10-08 12:37:39 -0700 | [diff] [blame] | 1767 | dsize = min_t(uint, SBSDIO_SB_OFT_ADDR_LIMIT, size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1768 | } |
| 1769 | } |
| 1770 | |
| 1771 | xfer_done: |
| 1772 | /* Return the window to backplane enumeration space for core access */ |
| 1773 | if (dhdsdio_set_siaddr_window(bus, bcmsdh_cur_sbwad(bus->sdh))) { |
| 1774 | DHD_ERROR(("%s: FAILED to set window back to 0x%x\n", |
| 1775 | __func__, bcmsdh_cur_sbwad(bus->sdh))); |
| 1776 | } |
| 1777 | |
| 1778 | return bcmerror; |
| 1779 | } |
| 1780 | |
| 1781 | #ifdef DHD_DEBUG |
| 1782 | static int dhdsdio_readshared(dhd_bus_t *bus, sdpcm_shared_t *sh) |
| 1783 | { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1784 | u32 addr; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1785 | int rv; |
| 1786 | |
| 1787 | /* Read last word in memory to determine address of |
| 1788 | sdpcm_shared structure */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1789 | rv = dhdsdio_membytes(bus, false, bus->ramsize - 4, (u8 *)&addr, 4); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 1790 | if (rv < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1791 | return rv; |
| 1792 | |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 1793 | addr = le32_to_cpu(addr); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1794 | |
| 1795 | DHD_INFO(("sdpcm_shared address 0x%08X\n", addr)); |
| 1796 | |
| 1797 | /* |
| 1798 | * Check if addr is valid. |
| 1799 | * NVRAM length at the end of memory should have been overwritten. |
| 1800 | */ |
| 1801 | if (addr == 0 || ((~addr >> 16) & 0xffff) == (addr & 0xffff)) { |
| 1802 | DHD_ERROR(("%s: address (0x%08x) of sdpcm_shared invalid\n", |
| 1803 | __func__, addr)); |
| 1804 | return BCME_ERROR; |
| 1805 | } |
| 1806 | |
| 1807 | /* Read hndrte_shared structure */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1808 | rv = dhdsdio_membytes(bus, false, addr, (u8 *) sh, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1809 | sizeof(sdpcm_shared_t)); |
| 1810 | if (rv < 0) |
| 1811 | return rv; |
| 1812 | |
| 1813 | /* Endianness */ |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 1814 | sh->flags = le32_to_cpu(sh->flags); |
| 1815 | sh->trap_addr = le32_to_cpu(sh->trap_addr); |
| 1816 | sh->assert_exp_addr = le32_to_cpu(sh->assert_exp_addr); |
| 1817 | sh->assert_file_addr = le32_to_cpu(sh->assert_file_addr); |
| 1818 | sh->assert_line = le32_to_cpu(sh->assert_line); |
| 1819 | sh->console_addr = le32_to_cpu(sh->console_addr); |
| 1820 | sh->msgtrace_addr = le32_to_cpu(sh->msgtrace_addr); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1821 | |
| 1822 | if ((sh->flags & SDPCM_SHARED_VERSION_MASK) != SDPCM_SHARED_VERSION) { |
| 1823 | DHD_ERROR(("%s: sdpcm_shared version %d in dhd " |
| 1824 | "is different than sdpcm_shared version %d in dongle\n", |
| 1825 | __func__, SDPCM_SHARED_VERSION, |
| 1826 | sh->flags & SDPCM_SHARED_VERSION_MASK)); |
| 1827 | return BCME_ERROR; |
| 1828 | } |
| 1829 | |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 1830 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1831 | } |
| 1832 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1833 | static int dhdsdio_checkdied(dhd_bus_t *bus, u8 *data, uint size) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1834 | { |
| 1835 | int bcmerror = 0; |
| 1836 | uint msize = 512; |
| 1837 | char *mbuffer = NULL; |
| 1838 | uint maxstrlen = 256; |
| 1839 | char *str = NULL; |
| 1840 | trap_t tr; |
| 1841 | sdpcm_shared_t sdpcm_shared; |
| 1842 | struct bcmstrbuf strbuf; |
| 1843 | |
| 1844 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 1845 | |
| 1846 | if (data == NULL) { |
| 1847 | /* |
| 1848 | * Called after a rx ctrl timeout. "data" is NULL. |
| 1849 | * allocate memory to trace the trap or assert. |
| 1850 | */ |
| 1851 | size = msize; |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 1852 | mbuffer = data = kmalloc(msize, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1853 | if (mbuffer == NULL) { |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 1854 | DHD_ERROR(("%s: kmalloc(%d) failed\n", __func__, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1855 | msize)); |
| 1856 | bcmerror = BCME_NOMEM; |
| 1857 | goto done; |
| 1858 | } |
| 1859 | } |
| 1860 | |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 1861 | str = kmalloc(maxstrlen, GFP_ATOMIC); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 1862 | if (str == NULL) { |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 1863 | DHD_ERROR(("%s: kmalloc(%d) failed\n", __func__, maxstrlen)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1864 | bcmerror = BCME_NOMEM; |
| 1865 | goto done; |
| 1866 | } |
| 1867 | |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 1868 | bcmerror = dhdsdio_readshared(bus, &sdpcm_shared); |
| 1869 | if (bcmerror < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1870 | goto done; |
| 1871 | |
| 1872 | bcm_binit(&strbuf, data, size); |
| 1873 | |
| 1874 | bcm_bprintf(&strbuf, |
| 1875 | "msgtrace address : 0x%08X\nconsole address : 0x%08X\n", |
| 1876 | sdpcm_shared.msgtrace_addr, sdpcm_shared.console_addr); |
| 1877 | |
| 1878 | if ((sdpcm_shared.flags & SDPCM_SHARED_ASSERT_BUILT) == 0) { |
| 1879 | /* NOTE: Misspelled assert is intentional - DO NOT FIX. |
| 1880 | * (Avoids conflict with real asserts for programmatic |
| 1881 | * parsing of output.) |
| 1882 | */ |
| 1883 | bcm_bprintf(&strbuf, "Assrt not built in dongle\n"); |
| 1884 | } |
| 1885 | |
| 1886 | if ((sdpcm_shared.flags & (SDPCM_SHARED_ASSERT | SDPCM_SHARED_TRAP)) == |
| 1887 | 0) { |
| 1888 | /* NOTE: Misspelled assert is intentional - DO NOT FIX. |
| 1889 | * (Avoids conflict with real asserts for programmatic |
| 1890 | * parsing of output.) |
| 1891 | */ |
| 1892 | bcm_bprintf(&strbuf, "No trap%s in dongle", |
| 1893 | (sdpcm_shared.flags & SDPCM_SHARED_ASSERT_BUILT) |
| 1894 | ? "/assrt" : ""); |
| 1895 | } else { |
| 1896 | if (sdpcm_shared.flags & SDPCM_SHARED_ASSERT) { |
| 1897 | /* Download assert */ |
| 1898 | bcm_bprintf(&strbuf, "Dongle assert"); |
| 1899 | if (sdpcm_shared.assert_exp_addr != 0) { |
| 1900 | str[0] = '\0'; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1901 | bcmerror = dhdsdio_membytes(bus, false, |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 1902 | sdpcm_shared.assert_exp_addr, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1903 | (u8 *) str, maxstrlen); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 1904 | if (bcmerror < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1905 | goto done; |
| 1906 | |
| 1907 | str[maxstrlen - 1] = '\0'; |
| 1908 | bcm_bprintf(&strbuf, " expr \"%s\"", str); |
| 1909 | } |
| 1910 | |
| 1911 | if (sdpcm_shared.assert_file_addr != 0) { |
| 1912 | str[0] = '\0'; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1913 | bcmerror = dhdsdio_membytes(bus, false, |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 1914 | sdpcm_shared.assert_file_addr, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1915 | (u8 *) str, maxstrlen); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 1916 | if (bcmerror < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1917 | goto done; |
| 1918 | |
| 1919 | str[maxstrlen - 1] = '\0'; |
| 1920 | bcm_bprintf(&strbuf, " file \"%s\"", str); |
| 1921 | } |
| 1922 | |
| 1923 | bcm_bprintf(&strbuf, " line %d ", |
| 1924 | sdpcm_shared.assert_line); |
| 1925 | } |
| 1926 | |
| 1927 | if (sdpcm_shared.flags & SDPCM_SHARED_TRAP) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1928 | bcmerror = dhdsdio_membytes(bus, false, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1929 | sdpcm_shared.trap_addr, (u8 *)&tr, |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 1930 | sizeof(trap_t)); |
| 1931 | if (bcmerror < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1932 | goto done; |
| 1933 | |
| 1934 | bcm_bprintf(&strbuf, |
| 1935 | "Dongle trap type 0x%x @ epc 0x%x, cpsr 0x%x, spsr 0x%x, sp 0x%x," |
| 1936 | "lp 0x%x, rpc 0x%x Trap offset 0x%x, " |
| 1937 | "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", |
| 1938 | tr.type, tr.epc, tr.cpsr, tr.spsr, tr.r13, |
| 1939 | tr.r14, tr.pc, sdpcm_shared.trap_addr, |
| 1940 | tr.r0, tr.r1, tr.r2, tr.r3, tr.r4, tr.r5, |
| 1941 | tr.r6, tr.r7); |
| 1942 | } |
| 1943 | } |
| 1944 | |
| 1945 | if (sdpcm_shared.flags & (SDPCM_SHARED_ASSERT | SDPCM_SHARED_TRAP)) |
| 1946 | DHD_ERROR(("%s: %s\n", __func__, strbuf.origbuf)); |
| 1947 | |
| 1948 | #ifdef DHD_DEBUG |
| 1949 | if (sdpcm_shared.flags & SDPCM_SHARED_TRAP) { |
| 1950 | /* Mem dump to a file on device */ |
| 1951 | dhdsdio_mem_dump(bus); |
| 1952 | } |
| 1953 | #endif /* DHD_DEBUG */ |
| 1954 | |
| 1955 | done: |
Ilia Mirkin | 46d994b | 2011-03-13 00:28:56 -0500 | [diff] [blame] | 1956 | kfree(mbuffer); |
| 1957 | kfree(str); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1958 | |
| 1959 | return bcmerror; |
| 1960 | } |
| 1961 | |
| 1962 | static int dhdsdio_mem_dump(dhd_bus_t *bus) |
| 1963 | { |
| 1964 | int ret = 0; |
| 1965 | int size; /* Full mem size */ |
| 1966 | int start = 0; /* Start address */ |
| 1967 | int read_size = 0; /* Read size of each iteration */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 1968 | u8 *buf = NULL, *databuf = NULL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1969 | |
| 1970 | /* Get full mem size */ |
| 1971 | size = bus->ramsize; |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 1972 | buf = kmalloc(size, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1973 | if (!buf) { |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 1974 | DHD_ERROR(("%s: Out of memory (%d bytes)\n", __func__, size)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1975 | return -1; |
| 1976 | } |
| 1977 | |
| 1978 | /* Read mem content */ |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 1979 | printk(KERN_DEBUG "Dump dongle memory"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1980 | databuf = buf; |
| 1981 | while (size) { |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 1982 | read_size = min(MEMBLOCK, size); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 1983 | ret = dhdsdio_membytes(bus, false, start, databuf, read_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1984 | if (ret) { |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 1985 | DHD_ERROR(("%s: Error membytes %d\n", __func__, ret)); |
Ilia Mirkin | 46d994b | 2011-03-13 00:28:56 -0500 | [diff] [blame] | 1986 | kfree(buf); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1987 | return -1; |
| 1988 | } |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 1989 | printk("."); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1990 | |
| 1991 | /* Decrement size and increment start address */ |
| 1992 | size -= read_size; |
| 1993 | start += read_size; |
| 1994 | databuf += read_size; |
| 1995 | } |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 1996 | printk(KERN_DEBUG "Done\n"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 1997 | |
| 1998 | /* free buf before return !!! */ |
| 1999 | if (write_to_file(bus->dhd, buf, bus->ramsize)) { |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 2000 | DHD_ERROR(("%s: Error writing to files\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2001 | return -1; |
| 2002 | } |
| 2003 | |
| 2004 | /* buf free handled in write_to_file, not here */ |
| 2005 | return 0; |
| 2006 | } |
| 2007 | |
| 2008 | #define CONSOLE_LINE_MAX 192 |
| 2009 | |
| 2010 | static int dhdsdio_readconsole(dhd_bus_t *bus) |
| 2011 | { |
| 2012 | dhd_console_t *c = &bus->console; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2013 | u8 line[CONSOLE_LINE_MAX], ch; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2014 | u32 n, idx, addr; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2015 | int rv; |
| 2016 | |
| 2017 | /* Don't do anything until FWREADY updates console address */ |
| 2018 | if (bus->console_addr == 0) |
| 2019 | return 0; |
| 2020 | |
| 2021 | /* Read console log struct */ |
Greg Kroah-Hartman | ce0f1b8 | 2010-10-08 11:44:45 -0700 | [diff] [blame] | 2022 | addr = bus->console_addr + offsetof(hndrte_cons_t, log); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2023 | rv = dhdsdio_membytes(bus, false, addr, (u8 *)&c->log, |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2024 | sizeof(c->log)); |
| 2025 | if (rv < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2026 | return rv; |
| 2027 | |
| 2028 | /* Allocate console buffer (one time only) */ |
| 2029 | if (c->buf == NULL) { |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 2030 | c->bufsize = le32_to_cpu(c->log.buf_size); |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2031 | c->buf = kmalloc(c->bufsize, GFP_ATOMIC); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 2032 | if (c->buf == NULL) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2033 | return BCME_NOMEM; |
| 2034 | } |
| 2035 | |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 2036 | idx = le32_to_cpu(c->log.idx); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2037 | |
| 2038 | /* Protect against corrupt value */ |
| 2039 | if (idx > c->bufsize) |
| 2040 | return BCME_ERROR; |
| 2041 | |
| 2042 | /* Skip reading the console buffer if the index pointer |
| 2043 | has not moved */ |
| 2044 | if (idx == c->last) |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 2045 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2046 | |
| 2047 | /* Read the console buffer */ |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 2048 | addr = le32_to_cpu(c->log.buf); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2049 | rv = dhdsdio_membytes(bus, false, addr, c->buf, c->bufsize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2050 | if (rv < 0) |
| 2051 | return rv; |
| 2052 | |
| 2053 | while (c->last != idx) { |
| 2054 | for (n = 0; n < CONSOLE_LINE_MAX - 2; n++) { |
| 2055 | if (c->last == idx) { |
| 2056 | /* This would output a partial line. |
| 2057 | * Instead, back up |
| 2058 | * the buffer pointer and output this |
| 2059 | * line next time around. |
| 2060 | */ |
| 2061 | if (c->last >= n) |
| 2062 | c->last -= n; |
| 2063 | else |
| 2064 | c->last = c->bufsize - n; |
| 2065 | goto break2; |
| 2066 | } |
| 2067 | ch = c->buf[c->last]; |
| 2068 | c->last = (c->last + 1) % c->bufsize; |
| 2069 | if (ch == '\n') |
| 2070 | break; |
| 2071 | line[n] = ch; |
| 2072 | } |
| 2073 | |
| 2074 | if (n > 0) { |
| 2075 | if (line[n - 1] == '\r') |
| 2076 | n--; |
| 2077 | line[n] = 0; |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 2078 | printk(KERN_DEBUG "CONSOLE: %s\n", line); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2079 | } |
| 2080 | } |
| 2081 | break2: |
| 2082 | |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 2083 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2084 | } |
| 2085 | #endif /* DHD_DEBUG */ |
| 2086 | |
| 2087 | int dhdsdio_downloadvars(dhd_bus_t *bus, void *arg, int len) |
| 2088 | { |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 2089 | int bcmerror = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2090 | |
| 2091 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 2092 | |
| 2093 | /* Basic sanity checks */ |
| 2094 | if (bus->dhd->up) { |
| 2095 | bcmerror = BCME_NOTDOWN; |
| 2096 | goto err; |
| 2097 | } |
| 2098 | if (!len) { |
| 2099 | bcmerror = BCME_BUFTOOSHORT; |
| 2100 | goto err; |
| 2101 | } |
| 2102 | |
| 2103 | /* Free the old ones and replace with passed variables */ |
Ilia Mirkin | 46d994b | 2011-03-13 00:28:56 -0500 | [diff] [blame] | 2104 | kfree(bus->vars); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2105 | |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2106 | bus->vars = kmalloc(len, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2107 | bus->varsz = bus->vars ? len : 0; |
| 2108 | if (bus->vars == NULL) { |
| 2109 | bcmerror = BCME_NOMEM; |
| 2110 | goto err; |
| 2111 | } |
| 2112 | |
| 2113 | /* Copy the passed variables, which should include the |
| 2114 | terminating double-null */ |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2115 | memcpy(bus->vars, arg, bus->varsz); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2116 | err: |
| 2117 | return bcmerror; |
| 2118 | } |
| 2119 | |
| 2120 | static int |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2121 | 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] | 2122 | const char *name, void *params, int plen, void *arg, int len, |
| 2123 | int val_size) |
| 2124 | { |
| 2125 | int bcmerror = 0; |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2126 | s32 int_val = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2127 | bool bool_val = 0; |
| 2128 | |
| 2129 | DHD_TRACE(("%s: Enter, action %d name %s params %p plen %d arg %p " |
| 2130 | "len %d val_size %d\n", |
| 2131 | __func__, actionid, name, params, plen, arg, len, val_size)); |
| 2132 | |
| 2133 | bcmerror = bcm_iovar_lencheck(vi, arg, len, IOV_ISSET(actionid)); |
| 2134 | if (bcmerror != 0) |
| 2135 | goto exit; |
| 2136 | |
| 2137 | if (plen >= (int)sizeof(int_val)) |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2138 | memcpy(&int_val, params, sizeof(int_val)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2139 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2140 | bool_val = (int_val != 0) ? true : false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2141 | |
| 2142 | /* Some ioctls use the bus */ |
| 2143 | dhd_os_sdlock(bus->dhd); |
| 2144 | |
| 2145 | /* Check if dongle is in reset. If so, only allow DEVRESET iovars */ |
| 2146 | if (bus->dhd->dongle_reset && !(actionid == IOV_SVAL(IOV_DEVRESET) || |
| 2147 | actionid == IOV_GVAL(IOV_DEVRESET))) { |
| 2148 | bcmerror = BCME_NOTREADY; |
| 2149 | goto exit; |
| 2150 | } |
| 2151 | |
| 2152 | /* Handle sleep stuff before any clock mucking */ |
| 2153 | if (vi->varid == IOV_SLEEP) { |
| 2154 | if (IOV_ISSET(actionid)) { |
| 2155 | bcmerror = dhdsdio_bussleep(bus, bool_val); |
| 2156 | } else { |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2157 | int_val = (s32) bus->sleeping; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2158 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2159 | } |
| 2160 | goto exit; |
| 2161 | } |
| 2162 | |
| 2163 | /* Request clock to allow SDIO accesses */ |
| 2164 | if (!bus->dhd->dongle_reset) { |
| 2165 | BUS_WAKE(bus); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2166 | dhdsdio_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2167 | } |
| 2168 | |
| 2169 | switch (actionid) { |
| 2170 | case IOV_GVAL(IOV_INTR): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2171 | int_val = (s32) bus->intr; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2172 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2173 | break; |
| 2174 | |
| 2175 | case IOV_SVAL(IOV_INTR): |
| 2176 | bus->intr = bool_val; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2177 | bus->intdis = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2178 | if (bus->dhd->up) { |
| 2179 | if (bus->intr) { |
| 2180 | DHD_INTR(("%s: enable SDIO device interrupts\n", |
| 2181 | __func__)); |
| 2182 | bcmsdh_intr_enable(bus->sdh); |
| 2183 | } else { |
| 2184 | DHD_INTR(("%s: disable SDIO interrupts\n", |
| 2185 | __func__)); |
| 2186 | bcmsdh_intr_disable(bus->sdh); |
| 2187 | } |
| 2188 | } |
| 2189 | break; |
| 2190 | |
| 2191 | case IOV_GVAL(IOV_POLLRATE): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2192 | int_val = (s32) bus->pollrate; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2193 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2194 | break; |
| 2195 | |
| 2196 | case IOV_SVAL(IOV_POLLRATE): |
| 2197 | bus->pollrate = (uint) int_val; |
| 2198 | bus->poll = (bus->pollrate != 0); |
| 2199 | break; |
| 2200 | |
| 2201 | case IOV_GVAL(IOV_IDLETIME): |
| 2202 | int_val = bus->idletime; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2203 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2204 | break; |
| 2205 | |
| 2206 | case IOV_SVAL(IOV_IDLETIME): |
| 2207 | if ((int_val < 0) && (int_val != DHD_IDLE_IMMEDIATE)) |
| 2208 | bcmerror = BCME_BADARG; |
| 2209 | else |
| 2210 | bus->idletime = int_val; |
| 2211 | break; |
| 2212 | |
| 2213 | case IOV_GVAL(IOV_IDLECLOCK): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2214 | int_val = (s32) bus->idleclock; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2215 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2216 | break; |
| 2217 | |
| 2218 | case IOV_SVAL(IOV_IDLECLOCK): |
| 2219 | bus->idleclock = int_val; |
| 2220 | break; |
| 2221 | |
| 2222 | case IOV_GVAL(IOV_SD1IDLE): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2223 | int_val = (s32) sd1idle; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2224 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2225 | break; |
| 2226 | |
| 2227 | case IOV_SVAL(IOV_SD1IDLE): |
| 2228 | sd1idle = bool_val; |
| 2229 | break; |
| 2230 | |
| 2231 | case IOV_SVAL(IOV_MEMBYTES): |
| 2232 | case IOV_GVAL(IOV_MEMBYTES): |
| 2233 | { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2234 | u32 address; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2235 | uint size, dsize; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2236 | u8 *data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2237 | |
| 2238 | bool set = (actionid == IOV_SVAL(IOV_MEMBYTES)); |
| 2239 | |
| 2240 | ASSERT(plen >= 2 * sizeof(int)); |
| 2241 | |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2242 | address = (u32) int_val; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2243 | memcpy(&int_val, (char *)params + sizeof(int_val), |
| 2244 | sizeof(int_val)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2245 | size = (uint) int_val; |
| 2246 | |
| 2247 | /* Do some validation */ |
| 2248 | dsize = set ? plen - (2 * sizeof(int)) : len; |
| 2249 | if (dsize < size) { |
| 2250 | DHD_ERROR(("%s: error on %s membytes, addr " |
| 2251 | "0x%08x size %d dsize %d\n", |
| 2252 | __func__, (set ? "set" : "get"), |
| 2253 | address, size, dsize)); |
| 2254 | bcmerror = BCME_BADARG; |
| 2255 | break; |
| 2256 | } |
| 2257 | |
| 2258 | DHD_INFO(("%s: Request to %s %d bytes at address " |
| 2259 | "0x%08x\n", |
| 2260 | __func__, (set ? "write" : "read"), size, address)); |
| 2261 | |
| 2262 | /* If we know about SOCRAM, check for a fit */ |
| 2263 | if ((bus->orig_ramsize) && |
| 2264 | ((address > bus->orig_ramsize) |
| 2265 | || (address + size > bus->orig_ramsize))) { |
| 2266 | DHD_ERROR(("%s: ramsize 0x%08x doesn't have %d " |
| 2267 | "bytes at 0x%08x\n", |
| 2268 | __func__, bus->orig_ramsize, size, address)); |
| 2269 | bcmerror = BCME_BADARG; |
| 2270 | break; |
| 2271 | } |
| 2272 | |
| 2273 | /* Generate the actual data pointer */ |
| 2274 | data = |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2275 | set ? (u8 *) params + |
| 2276 | 2 * sizeof(int) : (u8 *) arg; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2277 | |
| 2278 | /* Call to do the transfer */ |
| 2279 | bcmerror = |
| 2280 | dhdsdio_membytes(bus, set, address, data, size); |
| 2281 | |
| 2282 | break; |
| 2283 | } |
| 2284 | |
| 2285 | case IOV_GVAL(IOV_MEMSIZE): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2286 | int_val = (s32) bus->ramsize; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2287 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2288 | break; |
| 2289 | |
| 2290 | case IOV_GVAL(IOV_SDIOD_DRIVE): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2291 | int_val = (s32) dhd_sdiod_drive_strength; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2292 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2293 | break; |
| 2294 | |
| 2295 | case IOV_SVAL(IOV_SDIOD_DRIVE): |
| 2296 | dhd_sdiod_drive_strength = int_val; |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame^] | 2297 | dhdsdio_sdiod_drive_strength_init(bus, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2298 | dhd_sdiod_drive_strength); |
| 2299 | break; |
| 2300 | |
| 2301 | case IOV_SVAL(IOV_DOWNLOAD): |
| 2302 | bcmerror = dhdsdio_download_state(bus, bool_val); |
| 2303 | break; |
| 2304 | |
| 2305 | case IOV_SVAL(IOV_VARS): |
| 2306 | bcmerror = dhdsdio_downloadvars(bus, arg, len); |
| 2307 | break; |
| 2308 | |
| 2309 | case IOV_GVAL(IOV_READAHEAD): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2310 | int_val = (s32) dhd_readahead; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2311 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2312 | break; |
| 2313 | |
| 2314 | case IOV_SVAL(IOV_READAHEAD): |
| 2315 | if (bool_val && !dhd_readahead) |
| 2316 | bus->nextlen = 0; |
| 2317 | dhd_readahead = bool_val; |
| 2318 | break; |
| 2319 | |
| 2320 | case IOV_GVAL(IOV_SDRXCHAIN): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2321 | int_val = (s32) bus->use_rxchain; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2322 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2323 | break; |
| 2324 | |
| 2325 | case IOV_SVAL(IOV_SDRXCHAIN): |
| 2326 | if (bool_val && !bus->sd_rxchain) |
| 2327 | bcmerror = BCME_UNSUPPORTED; |
| 2328 | else |
| 2329 | bus->use_rxchain = bool_val; |
| 2330 | break; |
| 2331 | case IOV_GVAL(IOV_ALIGNCTL): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2332 | int_val = (s32) dhd_alignctl; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2333 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2334 | break; |
| 2335 | |
| 2336 | case IOV_SVAL(IOV_ALIGNCTL): |
| 2337 | dhd_alignctl = bool_val; |
| 2338 | break; |
| 2339 | |
| 2340 | case IOV_GVAL(IOV_SDALIGN): |
| 2341 | int_val = DHD_SDALIGN; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2342 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2343 | break; |
| 2344 | |
| 2345 | #ifdef DHD_DEBUG |
| 2346 | case IOV_GVAL(IOV_VARS): |
| 2347 | if (bus->varsz < (uint) len) |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2348 | memcpy(arg, bus->vars, bus->varsz); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2349 | else |
| 2350 | bcmerror = BCME_BUFTOOSHORT; |
| 2351 | break; |
| 2352 | #endif /* DHD_DEBUG */ |
| 2353 | |
| 2354 | #ifdef DHD_DEBUG |
| 2355 | case IOV_GVAL(IOV_SDREG): |
| 2356 | { |
| 2357 | sdreg_t *sd_ptr; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2358 | u32 addr, size; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2359 | |
| 2360 | sd_ptr = (sdreg_t *) params; |
| 2361 | |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 2362 | addr = (unsigned long)bus->regs + sd_ptr->offset; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2363 | size = sd_ptr->func; |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2364 | int_val = (s32) bcmsdh_reg_read(bus->sdh, addr, size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2365 | if (bcmsdh_regfail(bus->sdh)) |
| 2366 | bcmerror = BCME_SDIO_ERROR; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2367 | memcpy(arg, &int_val, sizeof(s32)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2368 | break; |
| 2369 | } |
| 2370 | |
| 2371 | case IOV_SVAL(IOV_SDREG): |
| 2372 | { |
| 2373 | sdreg_t *sd_ptr; |
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 | |
| 2376 | sd_ptr = (sdreg_t *) params; |
| 2377 | |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 2378 | addr = (unsigned long)bus->regs + sd_ptr->offset; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2379 | size = sd_ptr->func; |
| 2380 | bcmsdh_reg_write(bus->sdh, addr, size, sd_ptr->value); |
| 2381 | if (bcmsdh_regfail(bus->sdh)) |
| 2382 | bcmerror = BCME_SDIO_ERROR; |
| 2383 | break; |
| 2384 | } |
| 2385 | |
| 2386 | /* Same as above, but offset is not backplane |
| 2387 | (not SDIO core) */ |
| 2388 | case IOV_GVAL(IOV_SBREG): |
| 2389 | { |
| 2390 | sdreg_t sdreg; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2391 | u32 addr, size; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2392 | |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2393 | memcpy(&sdreg, params, sizeof(sdreg)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2394 | |
| 2395 | addr = SI_ENUM_BASE + sdreg.offset; |
| 2396 | size = sdreg.func; |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2397 | int_val = (s32) bcmsdh_reg_read(bus->sdh, addr, size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2398 | if (bcmsdh_regfail(bus->sdh)) |
| 2399 | bcmerror = BCME_SDIO_ERROR; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2400 | memcpy(arg, &int_val, sizeof(s32)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2401 | break; |
| 2402 | } |
| 2403 | |
| 2404 | case IOV_SVAL(IOV_SBREG): |
| 2405 | { |
| 2406 | sdreg_t sdreg; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2407 | u32 addr, size; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2408 | |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2409 | memcpy(&sdreg, params, sizeof(sdreg)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2410 | |
| 2411 | addr = SI_ENUM_BASE + sdreg.offset; |
| 2412 | size = sdreg.func; |
| 2413 | bcmsdh_reg_write(bus->sdh, addr, size, sdreg.value); |
| 2414 | if (bcmsdh_regfail(bus->sdh)) |
| 2415 | bcmerror = BCME_SDIO_ERROR; |
| 2416 | break; |
| 2417 | } |
| 2418 | |
| 2419 | case IOV_GVAL(IOV_SDCIS): |
| 2420 | { |
| 2421 | *(char *)arg = 0; |
| 2422 | |
nohee ko | ea3b8a2 | 2010-10-09 10:34:38 -0700 | [diff] [blame] | 2423 | strcat(arg, "\nFunc 0\n"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2424 | bcmsdh_cis_read(bus->sdh, 0x10, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2425 | (u8 *) arg + strlen(arg), |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2426 | SBSDIO_CIS_SIZE_LIMIT); |
nohee ko | ea3b8a2 | 2010-10-09 10:34:38 -0700 | [diff] [blame] | 2427 | strcat(arg, "\nFunc 1\n"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2428 | bcmsdh_cis_read(bus->sdh, 0x11, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2429 | (u8 *) arg + strlen(arg), |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2430 | SBSDIO_CIS_SIZE_LIMIT); |
nohee ko | ea3b8a2 | 2010-10-09 10:34:38 -0700 | [diff] [blame] | 2431 | strcat(arg, "\nFunc 2\n"); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2432 | bcmsdh_cis_read(bus->sdh, 0x12, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2433 | (u8 *) arg + strlen(arg), |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2434 | SBSDIO_CIS_SIZE_LIMIT); |
| 2435 | break; |
| 2436 | } |
| 2437 | |
| 2438 | case IOV_GVAL(IOV_FORCEEVEN): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2439 | int_val = (s32) forcealign; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2440 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2441 | break; |
| 2442 | |
| 2443 | case IOV_SVAL(IOV_FORCEEVEN): |
| 2444 | forcealign = bool_val; |
| 2445 | break; |
| 2446 | |
| 2447 | case IOV_GVAL(IOV_TXBOUND): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2448 | int_val = (s32) dhd_txbound; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2449 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2450 | break; |
| 2451 | |
| 2452 | case IOV_SVAL(IOV_TXBOUND): |
| 2453 | dhd_txbound = (uint) int_val; |
| 2454 | break; |
| 2455 | |
| 2456 | case IOV_GVAL(IOV_RXBOUND): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2457 | int_val = (s32) dhd_rxbound; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2458 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2459 | break; |
| 2460 | |
| 2461 | case IOV_SVAL(IOV_RXBOUND): |
| 2462 | dhd_rxbound = (uint) int_val; |
| 2463 | break; |
| 2464 | |
| 2465 | case IOV_GVAL(IOV_TXMINMAX): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2466 | int_val = (s32) dhd_txminmax; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2467 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2468 | break; |
| 2469 | |
| 2470 | case IOV_SVAL(IOV_TXMINMAX): |
| 2471 | dhd_txminmax = (uint) int_val; |
| 2472 | break; |
| 2473 | #endif /* DHD_DEBUG */ |
| 2474 | |
| 2475 | #ifdef SDTEST |
| 2476 | case IOV_GVAL(IOV_EXTLOOP): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2477 | int_val = (s32) bus->ext_loop; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2478 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2479 | break; |
| 2480 | |
| 2481 | case IOV_SVAL(IOV_EXTLOOP): |
| 2482 | bus->ext_loop = bool_val; |
| 2483 | break; |
| 2484 | |
| 2485 | case IOV_GVAL(IOV_PKTGEN): |
| 2486 | bcmerror = dhdsdio_pktgen_get(bus, arg); |
| 2487 | break; |
| 2488 | |
| 2489 | case IOV_SVAL(IOV_PKTGEN): |
| 2490 | bcmerror = dhdsdio_pktgen_set(bus, arg); |
| 2491 | break; |
| 2492 | #endif /* SDTEST */ |
| 2493 | |
| 2494 | case IOV_SVAL(IOV_DEVRESET): |
| 2495 | DHD_TRACE(("%s: Called set IOV_DEVRESET=%d dongle_reset=%d " |
| 2496 | "busstate=%d\n", |
| 2497 | __func__, bool_val, bus->dhd->dongle_reset, |
| 2498 | bus->dhd->busstate)); |
| 2499 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2500 | dhd_bus_devreset(bus->dhd, (u8) bool_val); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2501 | |
| 2502 | break; |
| 2503 | |
| 2504 | case IOV_GVAL(IOV_DEVRESET): |
| 2505 | DHD_TRACE(("%s: Called get IOV_DEVRESET\n", __func__)); |
| 2506 | |
| 2507 | /* Get its status */ |
| 2508 | int_val = (bool) bus->dhd->dongle_reset; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2509 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2510 | |
| 2511 | break; |
| 2512 | |
| 2513 | default: |
| 2514 | bcmerror = BCME_UNSUPPORTED; |
| 2515 | break; |
| 2516 | } |
| 2517 | |
| 2518 | exit: |
| 2519 | if ((bus->idletime == DHD_IDLE_IMMEDIATE) && !bus->dpc_sched) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2520 | bus->activity = false; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2521 | dhdsdio_clkctl(bus, CLK_NONE, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2522 | } |
| 2523 | |
| 2524 | dhd_os_sdunlock(bus->dhd); |
| 2525 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2526 | if (actionid == IOV_SVAL(IOV_DEVRESET) && bool_val == false) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2527 | dhd_preinit_ioctls((dhd_pub_t *) bus->dhd); |
| 2528 | |
| 2529 | return bcmerror; |
| 2530 | } |
| 2531 | |
| 2532 | static int dhdsdio_write_vars(dhd_bus_t *bus) |
| 2533 | { |
| 2534 | int bcmerror = 0; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2535 | u32 varsize; |
| 2536 | u32 varaddr; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2537 | u8 *vbuffer; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2538 | u32 varsizew; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2539 | #ifdef DHD_DEBUG |
| 2540 | char *nvram_ularray; |
| 2541 | #endif /* DHD_DEBUG */ |
| 2542 | |
| 2543 | /* Even if there are no vars are to be written, we still |
| 2544 | need to set the ramsize. */ |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 2545 | varsize = bus->varsz ? roundup(bus->varsz, 4) : 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2546 | varaddr = (bus->ramsize - 4) - varsize; |
| 2547 | |
| 2548 | if (bus->vars) { |
Alexander Beregalov | 12d0eb4 | 2011-03-09 03:53:35 +0300 | [diff] [blame] | 2549 | vbuffer = kzalloc(varsize, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2550 | if (!vbuffer) |
| 2551 | return BCME_NOMEM; |
| 2552 | |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 2553 | memcpy(vbuffer, bus->vars, bus->varsz); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2554 | |
| 2555 | /* Write the vars list */ |
| 2556 | bcmerror = |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2557 | dhdsdio_membytes(bus, true, varaddr, vbuffer, varsize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2558 | #ifdef DHD_DEBUG |
| 2559 | /* Verify NVRAM bytes */ |
| 2560 | DHD_INFO(("Compare NVRAM dl & ul; varsize=%d\n", varsize)); |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 2561 | nvram_ularray = kmalloc(varsize, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2562 | if (!nvram_ularray) |
| 2563 | return BCME_NOMEM; |
| 2564 | |
| 2565 | /* Upload image to verify downloaded contents. */ |
| 2566 | memset(nvram_ularray, 0xaa, varsize); |
| 2567 | |
| 2568 | /* Read the vars list to temp buffer for comparison */ |
| 2569 | bcmerror = |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2570 | dhdsdio_membytes(bus, false, varaddr, nvram_ularray, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2571 | varsize); |
| 2572 | if (bcmerror) { |
| 2573 | DHD_ERROR(("%s: error %d on reading %d nvram bytes at " |
| 2574 | "0x%08x\n", __func__, bcmerror, varsize, varaddr)); |
| 2575 | } |
| 2576 | /* Compare the org NVRAM with the one read from RAM */ |
| 2577 | if (memcmp(vbuffer, nvram_ularray, varsize)) { |
| 2578 | DHD_ERROR(("%s: Downloaded NVRAM image is corrupted.\n", |
| 2579 | __func__)); |
| 2580 | } else |
| 2581 | DHD_ERROR(("%s: Download/Upload/Compare of NVRAM ok.\n", |
| 2582 | __func__)); |
| 2583 | |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 2584 | kfree(nvram_ularray); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2585 | #endif /* DHD_DEBUG */ |
| 2586 | |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 2587 | kfree(vbuffer); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2588 | } |
| 2589 | |
| 2590 | /* adjust to the user specified RAM */ |
| 2591 | DHD_INFO(("Physical memory size: %d, usable memory size: %d\n", |
| 2592 | bus->orig_ramsize, bus->ramsize)); |
| 2593 | DHD_INFO(("Vars are at %d, orig varsize is %d\n", varaddr, varsize)); |
| 2594 | varsize = ((bus->orig_ramsize - 4) - varaddr); |
| 2595 | |
| 2596 | /* |
| 2597 | * Determine the length token: |
| 2598 | * Varsize, converted to words, in lower 16-bits, checksum |
| 2599 | * in upper 16-bits. |
| 2600 | */ |
| 2601 | if (bcmerror) { |
| 2602 | varsizew = 0; |
| 2603 | } else { |
| 2604 | varsizew = varsize / 4; |
| 2605 | varsizew = (~varsizew << 16) | (varsizew & 0x0000FFFF); |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 2606 | varsizew = cpu_to_le32(varsizew); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2607 | } |
| 2608 | |
| 2609 | DHD_INFO(("New varsize is %d, length token=0x%08x\n", varsize, |
| 2610 | varsizew)); |
| 2611 | |
| 2612 | /* Write the length token to the last word */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2613 | bcmerror = dhdsdio_membytes(bus, true, (bus->orig_ramsize - 4), |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2614 | (u8 *)&varsizew, 4); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2615 | |
| 2616 | return bcmerror; |
| 2617 | } |
| 2618 | |
| 2619 | static int dhdsdio_download_state(dhd_bus_t *bus, bool enter) |
| 2620 | { |
| 2621 | uint retries; |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 2622 | u32 regdata; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2623 | int bcmerror = 0; |
| 2624 | |
| 2625 | /* To enter download state, disable ARM and reset SOCRAM. |
| 2626 | * To exit download state, simply reset ARM (default is RAM boot). |
| 2627 | */ |
| 2628 | if (enter) { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2629 | bus->alp_only = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2630 | |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 2631 | dhdsdio_chip_disablecore(bus->sdh, bus->ci->armcorebase); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2632 | |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 2633 | dhdsdio_chip_resetcore(bus->sdh, bus->ci->ramcorebase); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2634 | |
| 2635 | /* Clear the top bit of memory */ |
| 2636 | if (bus->ramsize) { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2637 | u32 zeros = 0; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2638 | dhdsdio_membytes(bus, true, bus->ramsize - 4, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2639 | (u8 *)&zeros, 4); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2640 | } |
| 2641 | } else { |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 2642 | regdata = bcmsdh_reg_read(bus->sdh, |
| 2643 | CORE_SB(bus->ci->ramcorebase, sbtmstatelow), 4); |
| 2644 | regdata &= (SBTML_RESET | SBTML_REJ_MASK | |
| 2645 | (SICF_CLOCK_EN << SBTML_SICF_SHIFT)); |
| 2646 | if ((SICF_CLOCK_EN << SBTML_SICF_SHIFT) != regdata) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2647 | DHD_ERROR(("%s: SOCRAM core is down after reset?\n", |
| 2648 | __func__)); |
| 2649 | bcmerror = BCME_ERROR; |
| 2650 | goto fail; |
| 2651 | } |
| 2652 | |
| 2653 | bcmerror = dhdsdio_write_vars(bus); |
| 2654 | if (bcmerror) { |
| 2655 | DHD_ERROR(("%s: no vars written to RAM\n", __func__)); |
| 2656 | bcmerror = 0; |
| 2657 | } |
| 2658 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2659 | W_SDREG(0xFFFFFFFF, &bus->regs->intstatus, retries); |
| 2660 | |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 2661 | dhdsdio_chip_resetcore(bus->sdh, bus->ci->armcorebase); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2662 | |
| 2663 | /* Allow HT Clock now that the ARM is running. */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2664 | bus->alp_only = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2665 | |
| 2666 | bus->dhd->busstate = DHD_BUS_LOAD; |
| 2667 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2668 | fail: |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2669 | return bcmerror; |
| 2670 | } |
| 2671 | |
| 2672 | int |
| 2673 | dhd_bus_iovar_op(dhd_pub_t *dhdp, const char *name, |
| 2674 | void *params, int plen, void *arg, int len, bool set) |
| 2675 | { |
| 2676 | dhd_bus_t *bus = dhdp->bus; |
| 2677 | const bcm_iovar_t *vi = NULL; |
| 2678 | int bcmerror = 0; |
| 2679 | int val_size; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2680 | u32 actionid; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2681 | |
| 2682 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 2683 | |
| 2684 | ASSERT(name); |
| 2685 | ASSERT(len >= 0); |
| 2686 | |
| 2687 | /* Get MUST have return space */ |
| 2688 | ASSERT(set || (arg && len)); |
| 2689 | |
| 2690 | /* Set does NOT take qualifiers */ |
| 2691 | ASSERT(!set || (!params && !plen)); |
| 2692 | |
| 2693 | /* Look up var locally; if not found pass to host driver */ |
| 2694 | vi = bcm_iovar_lookup(dhdsdio_iovars, name); |
| 2695 | if (vi == NULL) { |
| 2696 | dhd_os_sdlock(bus->dhd); |
| 2697 | |
| 2698 | BUS_WAKE(bus); |
| 2699 | |
| 2700 | /* Turn on clock in case SD command needs backplane */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2701 | dhdsdio_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2702 | |
| 2703 | bcmerror = |
| 2704 | bcmsdh_iovar_op(bus->sdh, name, params, plen, arg, len, |
| 2705 | set); |
| 2706 | |
| 2707 | /* Check for bus configuration changes of interest */ |
| 2708 | |
| 2709 | /* If it was divisor change, read the new one */ |
| 2710 | if (set && strcmp(name, "sd_divisor") == 0) { |
| 2711 | if (bcmsdh_iovar_op(bus->sdh, "sd_divisor", NULL, 0, |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2712 | &bus->sd_divisor, sizeof(s32), |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 2713 | false) != 0) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2714 | bus->sd_divisor = -1; |
| 2715 | DHD_ERROR(("%s: fail on %s get\n", __func__, |
| 2716 | name)); |
| 2717 | } else { |
| 2718 | DHD_INFO(("%s: noted %s update, value now %d\n", |
| 2719 | __func__, name, bus->sd_divisor)); |
| 2720 | } |
| 2721 | } |
| 2722 | /* If it was a mode change, read the new one */ |
| 2723 | if (set && strcmp(name, "sd_mode") == 0) { |
| 2724 | if (bcmsdh_iovar_op(bus->sdh, "sd_mode", NULL, 0, |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2725 | &bus->sd_mode, sizeof(s32), |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 2726 | false) != 0) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2727 | bus->sd_mode = -1; |
| 2728 | DHD_ERROR(("%s: fail on %s get\n", __func__, |
| 2729 | name)); |
| 2730 | } else { |
| 2731 | DHD_INFO(("%s: noted %s update, value now %d\n", |
| 2732 | __func__, name, bus->sd_mode)); |
| 2733 | } |
| 2734 | } |
| 2735 | /* Similar check for blocksize change */ |
| 2736 | if (set && strcmp(name, "sd_blocksize") == 0) { |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2737 | s32 fnum = 2; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2738 | if (bcmsdh_iovar_op |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 2739 | (bus->sdh, "sd_blocksize", &fnum, sizeof(s32), |
| 2740 | &bus->blocksize, sizeof(s32), |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 2741 | false) != 0) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2742 | bus->blocksize = 0; |
| 2743 | DHD_ERROR(("%s: fail on %s get\n", __func__, |
| 2744 | "sd_blocksize")); |
| 2745 | } else { |
| 2746 | DHD_INFO(("%s: noted %s update, value now %d\n", |
| 2747 | __func__, "sd_blocksize", |
| 2748 | bus->blocksize)); |
| 2749 | } |
| 2750 | } |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 2751 | bus->roundup = min(max_roundup, bus->blocksize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2752 | |
| 2753 | if ((bus->idletime == DHD_IDLE_IMMEDIATE) && !bus->dpc_sched) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2754 | bus->activity = false; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2755 | dhdsdio_clkctl(bus, CLK_NONE, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2756 | } |
| 2757 | |
| 2758 | dhd_os_sdunlock(bus->dhd); |
| 2759 | goto exit; |
| 2760 | } |
| 2761 | |
| 2762 | DHD_CTL(("%s: %s %s, len %d plen %d\n", __func__, |
| 2763 | name, (set ? "set" : "get"), len, plen)); |
| 2764 | |
| 2765 | /* set up 'params' pointer in case this is a set command so that |
| 2766 | * the convenience int and bool code can be common to set and get |
| 2767 | */ |
| 2768 | if (params == NULL) { |
| 2769 | params = arg; |
| 2770 | plen = len; |
| 2771 | } |
| 2772 | |
| 2773 | if (vi->type == IOVT_VOID) |
| 2774 | val_size = 0; |
| 2775 | else if (vi->type == IOVT_BUFFER) |
| 2776 | val_size = len; |
| 2777 | else |
| 2778 | /* all other types are integer sized */ |
| 2779 | val_size = sizeof(int); |
| 2780 | |
| 2781 | actionid = set ? IOV_SVAL(vi->varid) : IOV_GVAL(vi->varid); |
| 2782 | bcmerror = |
| 2783 | dhdsdio_doiovar(bus, vi, actionid, name, params, plen, arg, len, |
| 2784 | val_size); |
| 2785 | |
| 2786 | exit: |
| 2787 | return bcmerror; |
| 2788 | } |
| 2789 | |
| 2790 | void dhd_bus_stop(struct dhd_bus *bus, bool enforce_mutex) |
| 2791 | { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2792 | u32 local_hostintmask; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2793 | u8 saveclk; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2794 | uint retries; |
| 2795 | int err; |
| 2796 | |
| 2797 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 2798 | |
| 2799 | if (enforce_mutex) |
| 2800 | dhd_os_sdlock(bus->dhd); |
| 2801 | |
| 2802 | BUS_WAKE(bus); |
| 2803 | |
| 2804 | /* Enable clock for device interrupts */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2805 | dhdsdio_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2806 | |
| 2807 | /* Disable and clear interrupts at the chip level also */ |
| 2808 | W_SDREG(0, &bus->regs->hostintmask, retries); |
| 2809 | local_hostintmask = bus->hostintmask; |
| 2810 | bus->hostintmask = 0; |
| 2811 | |
| 2812 | /* Change our idea of bus state */ |
| 2813 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 2814 | |
| 2815 | /* Force clocks on backplane to be sure F2 interrupt propagates */ |
| 2816 | saveclk = |
| 2817 | bcmsdh_cfg_read(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 2818 | &err); |
| 2819 | if (!err) { |
| 2820 | bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 2821 | (saveclk | SBSDIO_FORCE_HT), &err); |
| 2822 | } |
| 2823 | if (err) { |
| 2824 | DHD_ERROR(("%s: Failed to force clock for F2: err %d\n", |
| 2825 | __func__, err)); |
| 2826 | } |
| 2827 | |
| 2828 | /* Turn off the bus (F2), free any pending packets */ |
| 2829 | DHD_INTR(("%s: disable SDIO interrupts\n", __func__)); |
| 2830 | bcmsdh_intr_disable(bus->sdh); |
| 2831 | bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_0, SDIOD_CCCR_IOEN, |
| 2832 | SDIO_FUNC_ENABLE_1, NULL); |
| 2833 | |
| 2834 | /* Clear any pending interrupts now that F2 is disabled */ |
| 2835 | W_SDREG(local_hostintmask, &bus->regs->intstatus, retries); |
| 2836 | |
| 2837 | /* Turn off the backplane clock (only) */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2838 | dhdsdio_clkctl(bus, CLK_SDONLY, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2839 | |
| 2840 | /* Clear the data packet queues */ |
Arend van Spriel | 537ebbb | 2011-03-02 21:18:47 +0100 | [diff] [blame] | 2841 | pktq_flush(&bus->txq, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2842 | |
| 2843 | /* Clear any held glomming stuff */ |
| 2844 | if (bus->glomd) |
Arend van Spriel | a30825a | 2011-03-02 21:18:46 +0100 | [diff] [blame] | 2845 | pkt_buf_free_skb(bus->glomd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2846 | |
| 2847 | if (bus->glom) |
Arend van Spriel | a30825a | 2011-03-02 21:18:46 +0100 | [diff] [blame] | 2848 | pkt_buf_free_skb(bus->glom); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2849 | |
| 2850 | bus->glom = bus->glomd = NULL; |
| 2851 | |
| 2852 | /* Clear rx control and wake any waiters */ |
| 2853 | bus->rxlen = 0; |
| 2854 | dhd_os_ioctl_resp_wake(bus->dhd); |
| 2855 | |
| 2856 | /* Reset some F2 state stuff */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2857 | bus->rxskip = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2858 | bus->tx_seq = bus->rx_seq = 0; |
| 2859 | |
| 2860 | if (enforce_mutex) |
| 2861 | dhd_os_sdunlock(bus->dhd); |
| 2862 | } |
| 2863 | |
| 2864 | int dhd_bus_init(dhd_pub_t *dhdp, bool enforce_mutex) |
| 2865 | { |
| 2866 | dhd_bus_t *bus = dhdp->bus; |
| 2867 | dhd_timeout_t tmo; |
| 2868 | uint retries = 0; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2869 | u8 ready, enable; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2870 | int err, ret = 0; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2871 | u8 saveclk; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2872 | |
| 2873 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 2874 | |
| 2875 | ASSERT(bus->dhd); |
| 2876 | if (!bus->dhd) |
| 2877 | return 0; |
| 2878 | |
| 2879 | if (enforce_mutex) |
| 2880 | dhd_os_sdlock(bus->dhd); |
| 2881 | |
| 2882 | /* Make sure backplane clock is on, needed to generate F2 interrupt */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2883 | dhdsdio_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2884 | if (bus->clkstate != CLK_AVAIL) |
| 2885 | goto exit; |
| 2886 | |
| 2887 | /* Force clocks on backplane to be sure F2 interrupt propagates */ |
| 2888 | saveclk = |
| 2889 | bcmsdh_cfg_read(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 2890 | &err); |
| 2891 | if (!err) { |
| 2892 | bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 2893 | (saveclk | SBSDIO_FORCE_HT), &err); |
| 2894 | } |
| 2895 | if (err) { |
| 2896 | DHD_ERROR(("%s: Failed to force clock for F2: err %d\n", |
| 2897 | __func__, err)); |
| 2898 | goto exit; |
| 2899 | } |
| 2900 | |
| 2901 | /* Enable function 2 (frame transfers) */ |
| 2902 | W_SDREG((SDPCM_PROT_VERSION << SMB_DATA_VERSION_SHIFT), |
| 2903 | &bus->regs->tosbmailboxdata, retries); |
| 2904 | enable = (SDIO_FUNC_ENABLE_1 | SDIO_FUNC_ENABLE_2); |
| 2905 | |
| 2906 | bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_0, SDIOD_CCCR_IOEN, enable, NULL); |
| 2907 | |
| 2908 | /* Give the dongle some time to do its thing and set IOR2 */ |
| 2909 | dhd_timeout_start(&tmo, DHD_WAIT_F2RDY * 1000); |
| 2910 | |
| 2911 | ready = 0; |
| 2912 | while (ready != enable && !dhd_timeout_expired(&tmo)) |
| 2913 | ready = |
| 2914 | bcmsdh_cfg_read(bus->sdh, SDIO_FUNC_0, SDIOD_CCCR_IORDY, |
| 2915 | NULL); |
| 2916 | |
| 2917 | DHD_INFO(("%s: enable 0x%02x, ready 0x%02x (waited %uus)\n", |
| 2918 | __func__, enable, ready, tmo.elapsed)); |
| 2919 | |
| 2920 | /* If F2 successfully enabled, set core and enable interrupts */ |
| 2921 | if (ready == enable) { |
| 2922 | /* Make sure we're talking to the core. */ |
| 2923 | bus->regs = si_setcore(bus->sih, PCMCIA_CORE_ID, 0); |
| 2924 | if (!(bus->regs)) |
| 2925 | bus->regs = si_setcore(bus->sih, SDIOD_CORE_ID, 0); |
| 2926 | |
| 2927 | /* Set up the interrupt mask and enable interrupts */ |
| 2928 | bus->hostintmask = HOSTINTMASK; |
| 2929 | W_SDREG(bus->hostintmask, &bus->regs->hostintmask, retries); |
| 2930 | |
| 2931 | bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_WATERMARK, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2932 | (u8) watermark, &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2933 | |
| 2934 | /* Set bus state according to enable result */ |
| 2935 | dhdp->busstate = DHD_BUS_DATA; |
| 2936 | |
| 2937 | /* bcmsdh_intr_unmask(bus->sdh); */ |
| 2938 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2939 | bus->intdis = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2940 | if (bus->intr) { |
| 2941 | DHD_INTR(("%s: enable SDIO device interrupts\n", |
| 2942 | __func__)); |
| 2943 | bcmsdh_intr_enable(bus->sdh); |
| 2944 | } else { |
| 2945 | DHD_INTR(("%s: disable SDIO interrupts\n", __func__)); |
| 2946 | bcmsdh_intr_disable(bus->sdh); |
| 2947 | } |
| 2948 | |
| 2949 | } |
| 2950 | |
| 2951 | else { |
| 2952 | /* Disable F2 again */ |
| 2953 | enable = SDIO_FUNC_ENABLE_1; |
| 2954 | bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_0, SDIOD_CCCR_IOEN, enable, |
| 2955 | NULL); |
| 2956 | } |
| 2957 | |
| 2958 | /* Restore previous clock setting */ |
| 2959 | bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 2960 | saveclk, &err); |
| 2961 | |
| 2962 | /* If we didn't come up, turn off backplane clock */ |
| 2963 | if (dhdp->busstate != DHD_BUS_DATA) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2964 | dhdsdio_clkctl(bus, CLK_NONE, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2965 | |
| 2966 | exit: |
| 2967 | if (enforce_mutex) |
| 2968 | dhd_os_sdunlock(bus->dhd); |
| 2969 | |
| 2970 | return ret; |
| 2971 | } |
| 2972 | |
| 2973 | static void dhdsdio_rxfail(dhd_bus_t *bus, bool abort, bool rtx) |
| 2974 | { |
| 2975 | bcmsdh_info_t *sdh = bus->sdh; |
| 2976 | sdpcmd_regs_t *regs = bus->regs; |
| 2977 | uint retries = 0; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 2978 | u16 lastrbc; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 2979 | u8 hi, lo; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 2980 | int err; |
| 2981 | |
| 2982 | DHD_ERROR(("%s: %sterminate frame%s\n", __func__, |
| 2983 | (abort ? "abort command, " : ""), |
| 2984 | (rtx ? ", send NAK" : ""))); |
| 2985 | |
| 2986 | if (abort) |
| 2987 | bcmsdh_abort(sdh, SDIO_FUNC_2); |
| 2988 | |
| 2989 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_FRAMECTRL, SFC_RF_TERM, |
| 2990 | &err); |
| 2991 | bus->f1regdata++; |
| 2992 | |
| 2993 | /* Wait until the packet has been flushed (device/FIFO stable) */ |
| 2994 | for (lastrbc = retries = 0xffff; retries > 0; retries--) { |
| 2995 | hi = bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_RFRAMEBCHI, |
| 2996 | NULL); |
| 2997 | lo = bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_RFRAMEBCLO, |
| 2998 | NULL); |
| 2999 | bus->f1regdata += 2; |
| 3000 | |
| 3001 | if ((hi == 0) && (lo == 0)) |
| 3002 | break; |
| 3003 | |
| 3004 | if ((hi > (lastrbc >> 8)) && (lo > (lastrbc & 0x00ff))) { |
| 3005 | DHD_ERROR(("%s: count growing: last 0x%04x now " |
| 3006 | "0x%04x\n", |
| 3007 | __func__, lastrbc, ((hi << 8) + lo))); |
| 3008 | } |
| 3009 | lastrbc = (hi << 8) + lo; |
| 3010 | } |
| 3011 | |
| 3012 | if (!retries) { |
| 3013 | DHD_ERROR(("%s: count never zeroed: last 0x%04x\n", |
| 3014 | __func__, lastrbc)); |
| 3015 | } else { |
| 3016 | DHD_INFO(("%s: flush took %d iterations\n", __func__, |
| 3017 | (0xffff - retries))); |
| 3018 | } |
| 3019 | |
| 3020 | if (rtx) { |
| 3021 | bus->rxrtx++; |
| 3022 | W_SDREG(SMB_NAK, ®s->tosbmailbox, retries); |
| 3023 | bus->f1regdata++; |
| 3024 | if (retries <= retry_limit) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3025 | bus->rxskip = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3026 | } |
| 3027 | |
| 3028 | /* Clear partial in any case */ |
| 3029 | bus->nextlen = 0; |
| 3030 | |
| 3031 | /* If we can't reach the device, signal failure */ |
| 3032 | if (err || bcmsdh_regfail(sdh)) |
| 3033 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 3034 | } |
| 3035 | |
| 3036 | static void |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3037 | 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] | 3038 | { |
| 3039 | bcmsdh_info_t *sdh = bus->sdh; |
| 3040 | uint rdlen, pad; |
| 3041 | |
| 3042 | int sdret; |
| 3043 | |
| 3044 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 3045 | |
| 3046 | /* Control data already received in aligned rxctl */ |
| 3047 | if ((bus->bus == SPI_BUS) && (!bus->usebufpool)) |
| 3048 | goto gotpkt; |
| 3049 | |
| 3050 | ASSERT(bus->rxbuf); |
| 3051 | /* Set rxctl for frame (w/optional alignment) */ |
| 3052 | bus->rxctl = bus->rxbuf; |
| 3053 | if (dhd_alignctl) { |
| 3054 | bus->rxctl += firstread; |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 3055 | pad = ((unsigned long)bus->rxctl % DHD_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3056 | if (pad) |
| 3057 | bus->rxctl += (DHD_SDALIGN - pad); |
| 3058 | bus->rxctl -= firstread; |
| 3059 | } |
| 3060 | ASSERT(bus->rxctl >= bus->rxbuf); |
| 3061 | |
| 3062 | /* Copy the already-read portion over */ |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 3063 | memcpy(bus->rxctl, hdr, firstread); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3064 | if (len <= firstread) |
| 3065 | goto gotpkt; |
| 3066 | |
| 3067 | /* Copy the full data pkt in gSPI case and process ioctl. */ |
| 3068 | if (bus->bus == SPI_BUS) { |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 3069 | memcpy(bus->rxctl, hdr, len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3070 | goto gotpkt; |
| 3071 | } |
| 3072 | |
| 3073 | /* Raise rdlen to next SDIO block to avoid tail command */ |
| 3074 | rdlen = len - firstread; |
| 3075 | if (bus->roundup && bus->blocksize && (rdlen > bus->blocksize)) { |
| 3076 | pad = bus->blocksize - (rdlen % bus->blocksize); |
| 3077 | if ((pad <= bus->roundup) && (pad < bus->blocksize) && |
| 3078 | ((len + pad) < bus->dhd->maxctl)) |
| 3079 | rdlen += pad; |
| 3080 | } else if (rdlen % DHD_SDALIGN) { |
| 3081 | rdlen += DHD_SDALIGN - (rdlen % DHD_SDALIGN); |
| 3082 | } |
| 3083 | |
| 3084 | /* Satisfy length-alignment requirements */ |
| 3085 | if (forcealign && (rdlen & (ALIGNMENT - 1))) |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 3086 | rdlen = roundup(rdlen, ALIGNMENT); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3087 | |
| 3088 | /* Drop if the read is too big or it exceeds our maximum */ |
| 3089 | if ((rdlen + firstread) > bus->dhd->maxctl) { |
| 3090 | DHD_ERROR(("%s: %d-byte control read exceeds %d-byte buffer\n", |
| 3091 | __func__, rdlen, bus->dhd->maxctl)); |
| 3092 | bus->dhd->rx_errors++; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3093 | dhdsdio_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3094 | goto done; |
| 3095 | } |
| 3096 | |
| 3097 | if ((len - doff) > bus->dhd->maxctl) { |
| 3098 | DHD_ERROR(("%s: %d-byte ctl frame (%d-byte ctl data) exceeds " |
| 3099 | "%d-byte limit\n", |
| 3100 | __func__, len, (len - doff), bus->dhd->maxctl)); |
| 3101 | bus->dhd->rx_errors++; |
| 3102 | bus->rx_toolong++; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3103 | dhdsdio_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3104 | goto done; |
| 3105 | } |
| 3106 | |
| 3107 | /* Read remainder of frame body into the rxctl buffer */ |
| 3108 | sdret = |
| 3109 | dhd_bcmsdh_recv_buf(bus, bcmsdh_cur_sbwad(sdh), SDIO_FUNC_2, F2SYNC, |
| 3110 | (bus->rxctl + firstread), rdlen, NULL, NULL, |
| 3111 | NULL); |
| 3112 | bus->f2rxdata++; |
| 3113 | ASSERT(sdret != BCME_PENDING); |
| 3114 | |
| 3115 | /* Control frame failures need retransmission */ |
| 3116 | if (sdret < 0) { |
| 3117 | DHD_ERROR(("%s: read %d control bytes failed: %d\n", |
| 3118 | __func__, rdlen, sdret)); |
| 3119 | bus->rxc_errors++; /* dhd.rx_ctlerrs is higher level */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3120 | dhdsdio_rxfail(bus, true, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3121 | goto done; |
| 3122 | } |
| 3123 | |
| 3124 | gotpkt: |
| 3125 | |
| 3126 | #ifdef DHD_DEBUG |
| 3127 | if (DHD_BYTES_ON() && DHD_CTL_ON()) |
| 3128 | prhex("RxCtrl", bus->rxctl, len); |
| 3129 | #endif |
| 3130 | |
| 3131 | /* Point to valid data and indicate its length */ |
| 3132 | bus->rxctl += doff; |
| 3133 | bus->rxlen = len - doff; |
| 3134 | |
| 3135 | done: |
| 3136 | /* Awake any waiters */ |
| 3137 | dhd_os_ioctl_resp_wake(bus->dhd); |
| 3138 | } |
| 3139 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3140 | static u8 dhdsdio_rxglom(dhd_bus_t *bus, u8 rxseq) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3141 | { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3142 | u16 dlen, totlen; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3143 | u8 *dptr, num = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3144 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3145 | u16 sublen, check; |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 3146 | struct sk_buff *pfirst, *plast, *pnext, *save_pfirst; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3147 | |
| 3148 | int errcode; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3149 | u8 chan, seq, doff, sfdoff; |
| 3150 | u8 txmax; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3151 | |
| 3152 | int ifidx = 0; |
| 3153 | bool usechain = bus->use_rxchain; |
| 3154 | |
| 3155 | /* If packets, issue read(s) and send up packet chain */ |
| 3156 | /* Return sequence numbers consumed? */ |
| 3157 | |
| 3158 | DHD_TRACE(("dhdsdio_rxglom: start: glomd %p glom %p\n", bus->glomd, |
| 3159 | bus->glom)); |
| 3160 | |
| 3161 | /* If there's a descriptor, generate the packet chain */ |
| 3162 | if (bus->glomd) { |
| 3163 | dhd_os_sdlock_rxq(bus->dhd); |
| 3164 | |
| 3165 | pfirst = plast = pnext = NULL; |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3166 | dlen = (u16) (bus->glomd->len); |
| 3167 | dptr = bus->glomd->data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3168 | if (!dlen || (dlen & 1)) { |
| 3169 | DHD_ERROR(("%s: bad glomd len(%d), ignore descriptor\n", |
| 3170 | __func__, dlen)); |
| 3171 | dlen = 0; |
| 3172 | } |
| 3173 | |
| 3174 | for (totlen = num = 0; dlen; num++) { |
| 3175 | /* Get (and move past) next length */ |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 3176 | sublen = get_unaligned_le16(dptr); |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3177 | dlen -= sizeof(u16); |
| 3178 | dptr += sizeof(u16); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3179 | if ((sublen < SDPCM_HDRLEN) || |
| 3180 | ((num == 0) && (sublen < (2 * SDPCM_HDRLEN)))) { |
| 3181 | DHD_ERROR(("%s: descriptor len %d bad: %d\n", |
| 3182 | __func__, num, sublen)); |
| 3183 | pnext = NULL; |
| 3184 | break; |
| 3185 | } |
| 3186 | if (sublen % DHD_SDALIGN) { |
| 3187 | DHD_ERROR(("%s: sublen %d not multiple of %d\n", |
| 3188 | __func__, sublen, DHD_SDALIGN)); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3189 | usechain = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3190 | } |
| 3191 | totlen += sublen; |
| 3192 | |
| 3193 | /* For last frame, adjust read len so total |
| 3194 | is a block multiple */ |
| 3195 | if (!dlen) { |
| 3196 | sublen += |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 3197 | (roundup(totlen, bus->blocksize) - totlen); |
| 3198 | totlen = roundup(totlen, bus->blocksize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3199 | } |
| 3200 | |
| 3201 | /* Allocate/chain packet for next subframe */ |
Arend van Spriel | a30825a | 2011-03-02 21:18:46 +0100 | [diff] [blame] | 3202 | pnext = pkt_buf_get_skb(sublen + DHD_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3203 | if (pnext == NULL) { |
Arend van Spriel | f09e023 | 2010-12-04 16:35:42 +0100 | [diff] [blame] | 3204 | 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] | 3205 | __func__, num, sublen)); |
| 3206 | break; |
| 3207 | } |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3208 | ASSERT(!(pnext->prev)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3209 | if (!pfirst) { |
| 3210 | ASSERT(!plast); |
| 3211 | pfirst = plast = pnext; |
| 3212 | } else { |
| 3213 | ASSERT(plast); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3214 | plast->next = pnext; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3215 | plast = pnext; |
| 3216 | } |
| 3217 | |
| 3218 | /* Adhere to start alignment requirements */ |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 3219 | PKTALIGN(pnext, sublen, DHD_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3220 | } |
| 3221 | |
| 3222 | /* If all allocations succeeded, save packet chain |
| 3223 | in bus structure */ |
| 3224 | if (pnext) { |
| 3225 | DHD_GLOM(("%s: allocated %d-byte packet chain for %d " |
| 3226 | "subframes\n", __func__, totlen, num)); |
| 3227 | if (DHD_GLOM_ON() && bus->nextlen) { |
| 3228 | if (totlen != bus->nextlen) { |
| 3229 | DHD_GLOM(("%s: glomdesc mismatch: nextlen %d glomdesc %d " "rxseq %d\n", |
| 3230 | __func__, bus->nextlen, |
| 3231 | totlen, rxseq)); |
| 3232 | } |
| 3233 | } |
| 3234 | bus->glom = pfirst; |
| 3235 | pfirst = pnext = NULL; |
| 3236 | } else { |
| 3237 | if (pfirst) |
Arend van Spriel | a30825a | 2011-03-02 21:18:46 +0100 | [diff] [blame] | 3238 | pkt_buf_free_skb(pfirst); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3239 | bus->glom = NULL; |
| 3240 | num = 0; |
| 3241 | } |
| 3242 | |
| 3243 | /* Done with descriptor packet */ |
Arend van Spriel | a30825a | 2011-03-02 21:18:46 +0100 | [diff] [blame] | 3244 | pkt_buf_free_skb(bus->glomd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3245 | bus->glomd = NULL; |
| 3246 | bus->nextlen = 0; |
| 3247 | |
| 3248 | dhd_os_sdunlock_rxq(bus->dhd); |
| 3249 | } |
| 3250 | |
| 3251 | /* Ok -- either we just generated a packet chain, |
| 3252 | or had one from before */ |
| 3253 | if (bus->glom) { |
| 3254 | if (DHD_GLOM_ON()) { |
| 3255 | DHD_GLOM(("%s: try superframe read, packet chain:\n", |
| 3256 | __func__)); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3257 | for (pnext = bus->glom; pnext; pnext = pnext->next) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3258 | DHD_GLOM((" %p: %p len 0x%04x (%d)\n", |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3259 | pnext, (u8 *) (pnext->data), |
| 3260 | pnext->len, pnext->len)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3261 | } |
| 3262 | } |
| 3263 | |
| 3264 | pfirst = bus->glom; |
Arend van Spriel | d6075c9 | 2011-02-25 16:39:21 +0100 | [diff] [blame] | 3265 | dlen = (u16) pkttotlen(pfirst); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3266 | |
| 3267 | /* Do an SDIO read for the superframe. Configurable iovar to |
| 3268 | * read directly into the chained packet, or allocate a large |
| 3269 | * packet and and copy into the chain. |
| 3270 | */ |
| 3271 | if (usechain) { |
| 3272 | errcode = dhd_bcmsdh_recv_buf(bus, |
| 3273 | bcmsdh_cur_sbwad |
| 3274 | (bus->sdh), SDIO_FUNC_2, |
| 3275 | F2SYNC, |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3276 | (u8 *) pfirst->data, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3277 | dlen, pfirst, NULL, NULL); |
| 3278 | } else if (bus->dataptr) { |
| 3279 | errcode = dhd_bcmsdh_recv_buf(bus, |
| 3280 | bcmsdh_cur_sbwad |
| 3281 | (bus->sdh), SDIO_FUNC_2, |
| 3282 | F2SYNC, bus->dataptr, |
| 3283 | dlen, NULL, NULL, NULL); |
| 3284 | sublen = |
Arend van Spriel | 26bcc18 | 2011-03-01 10:56:55 +0100 | [diff] [blame] | 3285 | (u16) pktfrombuf(pfirst, 0, dlen, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3286 | bus->dataptr); |
| 3287 | if (sublen != dlen) { |
| 3288 | DHD_ERROR(("%s: FAILED TO COPY, dlen %d sublen %d\n", |
| 3289 | __func__, dlen, sublen)); |
| 3290 | errcode = -1; |
| 3291 | } |
| 3292 | pnext = NULL; |
| 3293 | } else { |
| 3294 | DHD_ERROR(("COULDN'T ALLOC %d-BYTE GLOM, FORCE FAILURE\n", |
| 3295 | dlen)); |
| 3296 | errcode = -1; |
| 3297 | } |
| 3298 | bus->f2rxdata++; |
| 3299 | ASSERT(errcode != BCME_PENDING); |
| 3300 | |
| 3301 | /* On failure, kill the superframe, allow a couple retries */ |
| 3302 | if (errcode < 0) { |
| 3303 | DHD_ERROR(("%s: glom read of %d bytes failed: %d\n", |
| 3304 | __func__, dlen, errcode)); |
| 3305 | bus->dhd->rx_errors++; |
| 3306 | |
| 3307 | if (bus->glomerr++ < 3) { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3308 | dhdsdio_rxfail(bus, true, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3309 | } else { |
| 3310 | bus->glomerr = 0; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3311 | dhdsdio_rxfail(bus, true, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3312 | dhd_os_sdlock_rxq(bus->dhd); |
Arend van Spriel | a30825a | 2011-03-02 21:18:46 +0100 | [diff] [blame] | 3313 | pkt_buf_free_skb(bus->glom); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3314 | dhd_os_sdunlock_rxq(bus->dhd); |
| 3315 | bus->rxglomfail++; |
| 3316 | bus->glom = NULL; |
| 3317 | } |
| 3318 | return 0; |
| 3319 | } |
| 3320 | #ifdef DHD_DEBUG |
| 3321 | if (DHD_GLOM_ON()) { |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3322 | prhex("SUPERFRAME", pfirst->data, |
| 3323 | min_t(int, pfirst->len, 48)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3324 | } |
| 3325 | #endif |
| 3326 | |
| 3327 | /* Validate the superframe header */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3328 | dptr = (u8 *) (pfirst->data); |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 3329 | sublen = get_unaligned_le16(dptr); |
| 3330 | check = get_unaligned_le16(dptr + sizeof(u16)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3331 | |
| 3332 | chan = SDPCM_PACKET_CHANNEL(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3333 | seq = SDPCM_PACKET_SEQUENCE(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3334 | bus->nextlen = dptr[SDPCM_FRAMETAG_LEN + SDPCM_NEXTLEN_OFFSET]; |
| 3335 | if ((bus->nextlen << 4) > MAX_RX_DATASZ) { |
| 3336 | DHD_INFO(("%s: nextlen too large (%d) seq %d\n", |
| 3337 | __func__, bus->nextlen, seq)); |
| 3338 | bus->nextlen = 0; |
| 3339 | } |
| 3340 | doff = SDPCM_DOFFSET_VALUE(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3341 | txmax = SDPCM_WINDOW_VALUE(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3342 | |
| 3343 | errcode = 0; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3344 | if ((u16)~(sublen ^ check)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3345 | DHD_ERROR(("%s (superframe): HW hdr error: len/check " |
| 3346 | "0x%04x/0x%04x\n", __func__, sublen, check)); |
| 3347 | errcode = -1; |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 3348 | } else if (roundup(sublen, bus->blocksize) != dlen) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3349 | DHD_ERROR(("%s (superframe): len 0x%04x, rounded " |
| 3350 | "0x%04x, expect 0x%04x\n", |
| 3351 | __func__, sublen, |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 3352 | roundup(sublen, bus->blocksize), dlen)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3353 | errcode = -1; |
| 3354 | } else if (SDPCM_PACKET_CHANNEL(&dptr[SDPCM_FRAMETAG_LEN]) != |
| 3355 | SDPCM_GLOM_CHANNEL) { |
| 3356 | DHD_ERROR(("%s (superframe): bad channel %d\n", |
| 3357 | __func__, |
| 3358 | SDPCM_PACKET_CHANNEL(&dptr |
| 3359 | [SDPCM_FRAMETAG_LEN]))); |
| 3360 | errcode = -1; |
| 3361 | } else if (SDPCM_GLOMDESC(&dptr[SDPCM_FRAMETAG_LEN])) { |
| 3362 | DHD_ERROR(("%s (superframe): got second descriptor?\n", |
| 3363 | __func__)); |
| 3364 | errcode = -1; |
| 3365 | } else if ((doff < SDPCM_HDRLEN) || |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3366 | (doff > (pfirst->len - SDPCM_HDRLEN))) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3367 | DHD_ERROR(("%s (superframe): Bad data offset %d: HW %d " |
| 3368 | "pkt %d min %d\n", |
| 3369 | __func__, doff, sublen, |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3370 | pfirst->len, SDPCM_HDRLEN)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3371 | errcode = -1; |
| 3372 | } |
| 3373 | |
| 3374 | /* Check sequence number of superframe SW header */ |
| 3375 | if (rxseq != seq) { |
| 3376 | DHD_INFO(("%s: (superframe) rx_seq %d, expected %d\n", |
| 3377 | __func__, seq, rxseq)); |
| 3378 | bus->rx_badseq++; |
| 3379 | rxseq = seq; |
| 3380 | } |
| 3381 | |
| 3382 | /* Check window for sanity */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3383 | if ((u8) (txmax - bus->tx_seq) > 0x40) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3384 | DHD_ERROR(("%s: unlikely tx max %d with tx_seq %d\n", |
| 3385 | __func__, txmax, bus->tx_seq)); |
| 3386 | txmax = bus->tx_seq + 2; |
| 3387 | } |
| 3388 | bus->tx_max = txmax; |
| 3389 | |
| 3390 | /* Remove superframe header, remember offset */ |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 3391 | skb_pull(pfirst, doff); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3392 | sfdoff = doff; |
| 3393 | |
| 3394 | /* Validate all the subframe headers */ |
| 3395 | for (num = 0, pnext = pfirst; pnext && !errcode; |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3396 | num++, pnext = pnext->next) { |
| 3397 | dptr = (u8 *) (pnext->data); |
| 3398 | dlen = (u16) (pnext->len); |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 3399 | sublen = get_unaligned_le16(dptr); |
| 3400 | check = get_unaligned_le16(dptr + sizeof(u16)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3401 | chan = SDPCM_PACKET_CHANNEL(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3402 | doff = SDPCM_DOFFSET_VALUE(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3403 | #ifdef DHD_DEBUG |
| 3404 | if (DHD_GLOM_ON()) |
| 3405 | prhex("subframe", dptr, 32); |
| 3406 | #endif |
| 3407 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3408 | if ((u16)~(sublen ^ check)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3409 | DHD_ERROR(("%s (subframe %d): HW hdr error: " |
| 3410 | "len/check 0x%04x/0x%04x\n", |
| 3411 | __func__, num, sublen, check)); |
| 3412 | errcode = -1; |
| 3413 | } else if ((sublen > dlen) || (sublen < SDPCM_HDRLEN)) { |
| 3414 | DHD_ERROR(("%s (subframe %d): length mismatch: " |
| 3415 | "len 0x%04x, expect 0x%04x\n", |
| 3416 | __func__, num, sublen, dlen)); |
| 3417 | errcode = -1; |
| 3418 | } else if ((chan != SDPCM_DATA_CHANNEL) && |
| 3419 | (chan != SDPCM_EVENT_CHANNEL)) { |
| 3420 | DHD_ERROR(("%s (subframe %d): bad channel %d\n", |
| 3421 | __func__, num, chan)); |
| 3422 | errcode = -1; |
| 3423 | } else if ((doff < SDPCM_HDRLEN) || (doff > sublen)) { |
| 3424 | DHD_ERROR(("%s (subframe %d): Bad data offset %d: HW %d min %d\n", |
| 3425 | __func__, num, doff, sublen, |
| 3426 | SDPCM_HDRLEN)); |
| 3427 | errcode = -1; |
| 3428 | } |
| 3429 | } |
| 3430 | |
| 3431 | if (errcode) { |
| 3432 | /* Terminate frame on error, request |
| 3433 | a couple retries */ |
| 3434 | if (bus->glomerr++ < 3) { |
| 3435 | /* Restore superframe header space */ |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 3436 | skb_push(pfirst, sfdoff); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3437 | dhdsdio_rxfail(bus, true, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3438 | } else { |
| 3439 | bus->glomerr = 0; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3440 | dhdsdio_rxfail(bus, true, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3441 | dhd_os_sdlock_rxq(bus->dhd); |
Arend van Spriel | a30825a | 2011-03-02 21:18:46 +0100 | [diff] [blame] | 3442 | pkt_buf_free_skb(bus->glom); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3443 | dhd_os_sdunlock_rxq(bus->dhd); |
| 3444 | bus->rxglomfail++; |
| 3445 | bus->glom = NULL; |
| 3446 | } |
| 3447 | bus->nextlen = 0; |
| 3448 | return 0; |
| 3449 | } |
| 3450 | |
| 3451 | /* Basic SD framing looks ok - process each packet (header) */ |
| 3452 | save_pfirst = pfirst; |
| 3453 | bus->glom = NULL; |
| 3454 | plast = NULL; |
| 3455 | |
| 3456 | dhd_os_sdlock_rxq(bus->dhd); |
| 3457 | for (num = 0; pfirst; rxseq++, pfirst = pnext) { |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3458 | pnext = pfirst->next; |
| 3459 | pfirst->next = NULL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3460 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3461 | dptr = (u8 *) (pfirst->data); |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 3462 | sublen = get_unaligned_le16(dptr); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3463 | chan = SDPCM_PACKET_CHANNEL(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3464 | seq = SDPCM_PACKET_SEQUENCE(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3465 | doff = SDPCM_DOFFSET_VALUE(&dptr[SDPCM_FRAMETAG_LEN]); |
| 3466 | |
| 3467 | DHD_GLOM(("%s: Get subframe %d, %p(%p/%d), sublen %d " |
| 3468 | "chan %d seq %d\n", |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3469 | __func__, num, pfirst, pfirst->data, |
| 3470 | pfirst->len, sublen, chan, seq)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3471 | |
| 3472 | ASSERT((chan == SDPCM_DATA_CHANNEL) |
| 3473 | || (chan == SDPCM_EVENT_CHANNEL)); |
| 3474 | |
| 3475 | if (rxseq != seq) { |
| 3476 | DHD_GLOM(("%s: rx_seq %d, expected %d\n", |
| 3477 | __func__, seq, rxseq)); |
| 3478 | bus->rx_badseq++; |
| 3479 | rxseq = seq; |
| 3480 | } |
| 3481 | #ifdef DHD_DEBUG |
| 3482 | if (DHD_BYTES_ON() && DHD_DATA_ON()) |
| 3483 | prhex("Rx Subframe Data", dptr, dlen); |
| 3484 | #endif |
| 3485 | |
Arend van Spriel | 2cb8ada | 2010-11-18 20:46:44 +0100 | [diff] [blame] | 3486 | __skb_trim(pfirst, sublen); |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 3487 | skb_pull(pfirst, doff); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3488 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3489 | if (pfirst->len == 0) { |
Arend van Spriel | a30825a | 2011-03-02 21:18:46 +0100 | [diff] [blame] | 3490 | pkt_buf_free_skb(pfirst); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3491 | if (plast) { |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3492 | plast->next = pnext; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3493 | } else { |
| 3494 | ASSERT(save_pfirst == pfirst); |
| 3495 | save_pfirst = pnext; |
| 3496 | } |
| 3497 | continue; |
| 3498 | } else if (dhd_prot_hdrpull(bus->dhd, &ifidx, pfirst) != |
| 3499 | 0) { |
| 3500 | DHD_ERROR(("%s: rx protocol error\n", |
| 3501 | __func__)); |
| 3502 | bus->dhd->rx_errors++; |
Arend van Spriel | a30825a | 2011-03-02 21:18:46 +0100 | [diff] [blame] | 3503 | pkt_buf_free_skb(pfirst); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3504 | if (plast) { |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3505 | plast->next = pnext; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3506 | } else { |
| 3507 | ASSERT(save_pfirst == pfirst); |
| 3508 | save_pfirst = pnext; |
| 3509 | } |
| 3510 | continue; |
| 3511 | } |
| 3512 | |
| 3513 | /* this packet will go up, link back into |
| 3514 | chain and count it */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3515 | pfirst->next = pnext; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3516 | plast = pfirst; |
| 3517 | num++; |
| 3518 | |
| 3519 | #ifdef DHD_DEBUG |
| 3520 | if (DHD_GLOM_ON()) { |
| 3521 | DHD_GLOM(("%s subframe %d to stack, %p(%p/%d) " |
| 3522 | "nxt/lnk %p/%p\n", |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3523 | __func__, num, pfirst, pfirst->data, |
| 3524 | pfirst->len, pfirst->next, |
| 3525 | pfirst->prev)); |
| 3526 | prhex("", (u8 *) pfirst->data, |
| 3527 | min_t(int, pfirst->len, 32)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3528 | } |
| 3529 | #endif /* DHD_DEBUG */ |
| 3530 | } |
| 3531 | dhd_os_sdunlock_rxq(bus->dhd); |
| 3532 | if (num) { |
| 3533 | dhd_os_sdunlock(bus->dhd); |
| 3534 | dhd_rx_frame(bus->dhd, ifidx, save_pfirst, num); |
| 3535 | dhd_os_sdlock(bus->dhd); |
| 3536 | } |
| 3537 | |
| 3538 | bus->rxglomframes++; |
| 3539 | bus->rxglompkts += num; |
| 3540 | } |
| 3541 | return num; |
| 3542 | } |
| 3543 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3544 | /* Return true if there may be more frames to read */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3545 | static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished) |
| 3546 | { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3547 | bcmsdh_info_t *sdh = bus->sdh; |
| 3548 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3549 | u16 len, check; /* Extracted hardware header fields */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3550 | u8 chan, seq, doff; /* Extracted software header fields */ |
| 3551 | u8 fcbits; /* Extracted fcbits from software header */ |
| 3552 | u8 delta; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3553 | |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 3554 | struct sk_buff *pkt; /* Packet for event or data frames */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3555 | u16 pad; /* Number of pad bytes to read */ |
| 3556 | u16 rdlen; /* Total number of bytes to read */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3557 | u8 rxseq; /* Next sequence number to expect */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3558 | uint rxleft = 0; /* Remaining number of frames allowed */ |
| 3559 | int sdret; /* Return code from bcmsdh calls */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3560 | u8 txmax; /* Maximum tx sequence offered */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3561 | bool len_consistent; /* Result of comparing readahead len and |
| 3562 | len from hw-hdr */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3563 | u8 *rxbuf; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3564 | int ifidx = 0; |
| 3565 | uint rxcount = 0; /* Total frames read */ |
| 3566 | |
| 3567 | #if defined(DHD_DEBUG) || defined(SDTEST) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3568 | bool sdtest = false; /* To limit message spew from test mode */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3569 | #endif |
| 3570 | |
| 3571 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 3572 | |
| 3573 | ASSERT(maxframes); |
| 3574 | |
| 3575 | #ifdef SDTEST |
| 3576 | /* Allow pktgen to override maxframes */ |
| 3577 | if (bus->pktgen_count && (bus->pktgen_mode == DHD_PKTGEN_RECV)) { |
| 3578 | maxframes = bus->pktgen_count; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3579 | sdtest = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3580 | } |
| 3581 | #endif |
| 3582 | |
| 3583 | /* Not finished unless we encounter no more frames indication */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3584 | *finished = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3585 | |
| 3586 | for (rxseq = bus->rx_seq, rxleft = maxframes; |
| 3587 | !bus->rxskip && rxleft && bus->dhd->busstate != DHD_BUS_DOWN; |
| 3588 | rxseq++, rxleft--) { |
| 3589 | |
| 3590 | /* Handle glomming separately */ |
| 3591 | if (bus->glom || bus->glomd) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3592 | u8 cnt; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3593 | DHD_GLOM(("%s: calling rxglom: glomd %p, glom %p\n", |
| 3594 | __func__, bus->glomd, bus->glom)); |
| 3595 | cnt = dhdsdio_rxglom(bus, rxseq); |
| 3596 | DHD_GLOM(("%s: rxglom returned %d\n", __func__, cnt)); |
| 3597 | rxseq += cnt - 1; |
| 3598 | rxleft = (rxleft > cnt) ? (rxleft - cnt) : 1; |
| 3599 | continue; |
| 3600 | } |
| 3601 | |
| 3602 | /* Try doing single read if we can */ |
| 3603 | if (dhd_readahead && bus->nextlen) { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3604 | u16 nextlen = bus->nextlen; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3605 | bus->nextlen = 0; |
| 3606 | |
| 3607 | if (bus->bus == SPI_BUS) { |
| 3608 | rdlen = len = nextlen; |
| 3609 | } else { |
| 3610 | rdlen = len = nextlen << 4; |
| 3611 | |
| 3612 | /* Pad read to blocksize for efficiency */ |
| 3613 | if (bus->roundup && bus->blocksize |
| 3614 | && (rdlen > bus->blocksize)) { |
| 3615 | pad = |
| 3616 | bus->blocksize - |
| 3617 | (rdlen % bus->blocksize); |
| 3618 | if ((pad <= bus->roundup) |
| 3619 | && (pad < bus->blocksize) |
| 3620 | && ((rdlen + pad + firstread) < |
| 3621 | MAX_RX_DATASZ)) |
| 3622 | rdlen += pad; |
| 3623 | } else if (rdlen % DHD_SDALIGN) { |
| 3624 | rdlen += |
| 3625 | DHD_SDALIGN - (rdlen % DHD_SDALIGN); |
| 3626 | } |
| 3627 | } |
| 3628 | |
| 3629 | /* We use bus->rxctl buffer in WinXP for initial |
| 3630 | * control pkt receives. |
| 3631 | * Later we use buffer-poll for data as well |
| 3632 | * as control packets. |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3633 | * This is required because dhd receives full |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3634 | * frame in gSPI unlike SDIO. |
| 3635 | * After the frame is received we have to |
| 3636 | * distinguish whether it is data |
| 3637 | * or non-data frame. |
| 3638 | */ |
| 3639 | /* Allocate a packet buffer */ |
| 3640 | dhd_os_sdlock_rxq(bus->dhd); |
Arend van Spriel | a30825a | 2011-03-02 21:18:46 +0100 | [diff] [blame] | 3641 | pkt = pkt_buf_get_skb(rdlen + DHD_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3642 | if (!pkt) { |
| 3643 | if (bus->bus == SPI_BUS) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3644 | bus->usebufpool = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3645 | bus->rxctl = bus->rxbuf; |
| 3646 | if (dhd_alignctl) { |
| 3647 | bus->rxctl += firstread; |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 3648 | pad = ((unsigned long)bus->rxctl % |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3649 | DHD_SDALIGN); |
| 3650 | if (pad) |
| 3651 | bus->rxctl += |
| 3652 | (DHD_SDALIGN - pad); |
| 3653 | bus->rxctl -= firstread; |
| 3654 | } |
| 3655 | ASSERT(bus->rxctl >= bus->rxbuf); |
| 3656 | rxbuf = bus->rxctl; |
| 3657 | /* Read the entire frame */ |
| 3658 | sdret = dhd_bcmsdh_recv_buf(bus, |
| 3659 | bcmsdh_cur_sbwad |
| 3660 | (sdh), |
| 3661 | SDIO_FUNC_2, |
| 3662 | F2SYNC, |
| 3663 | rxbuf, |
| 3664 | rdlen, NULL, |
| 3665 | NULL, NULL); |
| 3666 | bus->f2rxdata++; |
| 3667 | ASSERT(sdret != BCME_PENDING); |
| 3668 | |
| 3669 | /* Control frame failures need |
| 3670 | retransmission */ |
| 3671 | if (sdret < 0) { |
| 3672 | DHD_ERROR(("%s: read %d control bytes failed: %d\n", |
| 3673 | __func__, |
| 3674 | rdlen, sdret)); |
| 3675 | /* dhd.rx_ctlerrs is higher */ |
| 3676 | bus->rxc_errors++; |
| 3677 | dhd_os_sdunlock_rxq(bus->dhd); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3678 | dhdsdio_rxfail(bus, true, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3679 | (bus->bus == |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3680 | SPI_BUS) ? false |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3681 | : true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3682 | continue; |
| 3683 | } |
| 3684 | } else { |
| 3685 | /* Give up on data, |
| 3686 | request rtx of events */ |
Arend van Spriel | f09e023 | 2010-12-04 16:35:42 +0100 | [diff] [blame] | 3687 | 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] | 3688 | __func__, len, rdlen, rxseq)); |
| 3689 | /* Just go try again w/normal |
| 3690 | header read */ |
| 3691 | dhd_os_sdunlock_rxq(bus->dhd); |
| 3692 | continue; |
| 3693 | } |
| 3694 | } else { |
| 3695 | if (bus->bus == SPI_BUS) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3696 | bus->usebufpool = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3697 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3698 | ASSERT(!(pkt->prev)); |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 3699 | PKTALIGN(pkt, rdlen, DHD_SDALIGN); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 3700 | rxbuf = (u8 *) (pkt->data); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3701 | /* Read the entire frame */ |
| 3702 | sdret = |
| 3703 | dhd_bcmsdh_recv_buf(bus, |
| 3704 | bcmsdh_cur_sbwad(sdh), |
| 3705 | SDIO_FUNC_2, F2SYNC, |
| 3706 | rxbuf, rdlen, pkt, NULL, |
| 3707 | NULL); |
| 3708 | bus->f2rxdata++; |
| 3709 | ASSERT(sdret != BCME_PENDING); |
| 3710 | |
| 3711 | if (sdret < 0) { |
| 3712 | DHD_ERROR(("%s (nextlen): read %d bytes failed: %d\n", |
| 3713 | __func__, rdlen, sdret)); |
Arend van Spriel | a30825a | 2011-03-02 21:18:46 +0100 | [diff] [blame] | 3714 | pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3715 | bus->dhd->rx_errors++; |
| 3716 | dhd_os_sdunlock_rxq(bus->dhd); |
| 3717 | /* Force retry w/normal header read. |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3718 | * Don't attempt NAK for |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3719 | * gSPI |
| 3720 | */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3721 | dhdsdio_rxfail(bus, true, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3722 | (bus->bus == |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3723 | SPI_BUS) ? false : |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3724 | true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3725 | continue; |
| 3726 | } |
| 3727 | } |
| 3728 | dhd_os_sdunlock_rxq(bus->dhd); |
| 3729 | |
| 3730 | /* Now check the header */ |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 3731 | memcpy(bus->rxhdr, rxbuf, SDPCM_HDRLEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3732 | |
| 3733 | /* Extract hardware header fields */ |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 3734 | len = get_unaligned_le16(bus->rxhdr); |
| 3735 | check = get_unaligned_le16(bus->rxhdr + sizeof(u16)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3736 | |
| 3737 | /* All zeros means readahead info was bad */ |
| 3738 | if (!(len | check)) { |
| 3739 | DHD_INFO(("%s (nextlen): read zeros in HW " |
| 3740 | "header???\n", __func__)); |
| 3741 | dhd_os_sdlock_rxq(bus->dhd); |
| 3742 | PKTFREE2(); |
| 3743 | dhd_os_sdunlock_rxq(bus->dhd); |
| 3744 | GSPI_PR55150_BAILOUT; |
| 3745 | continue; |
| 3746 | } |
| 3747 | |
| 3748 | /* Validate check bytes */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3749 | if ((u16)~(len ^ check)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3750 | DHD_ERROR(("%s (nextlen): HW hdr error: nextlen/len/check" " 0x%04x/0x%04x/0x%04x\n", |
| 3751 | __func__, nextlen, len, check)); |
| 3752 | dhd_os_sdlock_rxq(bus->dhd); |
| 3753 | PKTFREE2(); |
| 3754 | dhd_os_sdunlock_rxq(bus->dhd); |
| 3755 | bus->rx_badhdr++; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3756 | dhdsdio_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3757 | GSPI_PR55150_BAILOUT; |
| 3758 | continue; |
| 3759 | } |
| 3760 | |
| 3761 | /* Validate frame length */ |
| 3762 | if (len < SDPCM_HDRLEN) { |
| 3763 | DHD_ERROR(("%s (nextlen): HW hdr length " |
| 3764 | "invalid: %d\n", __func__, len)); |
| 3765 | dhd_os_sdlock_rxq(bus->dhd); |
| 3766 | PKTFREE2(); |
| 3767 | dhd_os_sdunlock_rxq(bus->dhd); |
| 3768 | GSPI_PR55150_BAILOUT; |
| 3769 | continue; |
| 3770 | } |
| 3771 | |
| 3772 | /* Check for consistency withreadahead info */ |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 3773 | len_consistent = (nextlen != (roundup(len, 16) >> 4)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3774 | if (len_consistent) { |
| 3775 | /* Mismatch, force retry w/normal |
| 3776 | header (may be >4K) */ |
| 3777 | DHD_ERROR(("%s (nextlen): mismatch, nextlen %d len %d rnd %d; " "expected rxseq %d\n", |
| 3778 | __func__, nextlen, |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 3779 | len, roundup(len, 16), rxseq)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3780 | dhd_os_sdlock_rxq(bus->dhd); |
| 3781 | PKTFREE2(); |
| 3782 | dhd_os_sdunlock_rxq(bus->dhd); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3783 | dhdsdio_rxfail(bus, true, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3784 | (bus->bus == |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3785 | SPI_BUS) ? false : true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3786 | GSPI_PR55150_BAILOUT; |
| 3787 | continue; |
| 3788 | } |
| 3789 | |
| 3790 | /* Extract software header fields */ |
| 3791 | chan = |
| 3792 | SDPCM_PACKET_CHANNEL(&bus->rxhdr |
| 3793 | [SDPCM_FRAMETAG_LEN]); |
| 3794 | seq = |
| 3795 | SDPCM_PACKET_SEQUENCE(&bus->rxhdr |
| 3796 | [SDPCM_FRAMETAG_LEN]); |
| 3797 | doff = |
| 3798 | SDPCM_DOFFSET_VALUE(&bus->rxhdr |
| 3799 | [SDPCM_FRAMETAG_LEN]); |
| 3800 | txmax = |
| 3801 | SDPCM_WINDOW_VALUE(&bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 3802 | |
| 3803 | bus->nextlen = |
| 3804 | bus->rxhdr[SDPCM_FRAMETAG_LEN + |
| 3805 | SDPCM_NEXTLEN_OFFSET]; |
| 3806 | if ((bus->nextlen << 4) > MAX_RX_DATASZ) { |
| 3807 | DHD_INFO(("%s (nextlen): got frame w/nextlen too large" " (%d), seq %d\n", |
| 3808 | __func__, bus->nextlen, seq)); |
| 3809 | bus->nextlen = 0; |
| 3810 | } |
| 3811 | |
| 3812 | bus->dhd->rx_readahead_cnt++; |
| 3813 | /* Handle Flow Control */ |
| 3814 | fcbits = |
| 3815 | SDPCM_FCMASK_VALUE(&bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 3816 | |
| 3817 | delta = 0; |
| 3818 | if (~bus->flowcontrol & fcbits) { |
| 3819 | bus->fc_xoff++; |
| 3820 | delta = 1; |
| 3821 | } |
| 3822 | if (bus->flowcontrol & ~fcbits) { |
| 3823 | bus->fc_xon++; |
| 3824 | delta = 1; |
| 3825 | } |
| 3826 | |
| 3827 | if (delta) { |
| 3828 | bus->fc_rcvd++; |
| 3829 | bus->flowcontrol = fcbits; |
| 3830 | } |
| 3831 | |
| 3832 | /* Check and update sequence number */ |
| 3833 | if (rxseq != seq) { |
| 3834 | DHD_INFO(("%s (nextlen): rx_seq %d, expected " |
| 3835 | "%d\n", __func__, seq, rxseq)); |
| 3836 | bus->rx_badseq++; |
| 3837 | rxseq = seq; |
| 3838 | } |
| 3839 | |
| 3840 | /* Check window for sanity */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 3841 | if ((u8) (txmax - bus->tx_seq) > 0x40) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3842 | DHD_ERROR(("%s: got unlikely tx max %d with " |
| 3843 | "tx_seq %d\n", |
| 3844 | __func__, txmax, bus->tx_seq)); |
| 3845 | txmax = bus->tx_seq + 2; |
| 3846 | } |
| 3847 | bus->tx_max = txmax; |
| 3848 | |
| 3849 | #ifdef DHD_DEBUG |
| 3850 | if (DHD_BYTES_ON() && DHD_DATA_ON()) |
| 3851 | prhex("Rx Data", rxbuf, len); |
| 3852 | else if (DHD_HDRS_ON()) |
| 3853 | prhex("RxHdr", bus->rxhdr, SDPCM_HDRLEN); |
| 3854 | #endif |
| 3855 | |
| 3856 | if (chan == SDPCM_CONTROL_CHANNEL) { |
| 3857 | if (bus->bus == SPI_BUS) { |
| 3858 | dhdsdio_read_control(bus, rxbuf, len, |
| 3859 | doff); |
| 3860 | if (bus->usebufpool) { |
| 3861 | dhd_os_sdlock_rxq(bus->dhd); |
Arend van Spriel | a30825a | 2011-03-02 21:18:46 +0100 | [diff] [blame] | 3862 | pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3863 | dhd_os_sdunlock_rxq(bus->dhd); |
| 3864 | } |
| 3865 | continue; |
| 3866 | } else { |
| 3867 | DHD_ERROR(("%s (nextlen): readahead on control" " packet %d?\n", |
| 3868 | __func__, seq)); |
| 3869 | /* Force retry w/normal header read */ |
| 3870 | bus->nextlen = 0; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3871 | dhdsdio_rxfail(bus, false, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3872 | dhd_os_sdlock_rxq(bus->dhd); |
| 3873 | PKTFREE2(); |
| 3874 | dhd_os_sdunlock_rxq(bus->dhd); |
| 3875 | continue; |
| 3876 | } |
| 3877 | } |
| 3878 | |
| 3879 | if ((bus->bus == SPI_BUS) && !bus->usebufpool) { |
| 3880 | DHD_ERROR(("Received %d bytes on %d channel. Running out of " "rx pktbuf's or not yet malloced.\n", |
| 3881 | len, chan)); |
| 3882 | continue; |
| 3883 | } |
| 3884 | |
| 3885 | /* Validate data offset */ |
| 3886 | if ((doff < SDPCM_HDRLEN) || (doff > len)) { |
| 3887 | DHD_ERROR(("%s (nextlen): bad data offset %d: HW len %d min %d\n", |
| 3888 | __func__, doff, len, SDPCM_HDRLEN)); |
| 3889 | dhd_os_sdlock_rxq(bus->dhd); |
| 3890 | PKTFREE2(); |
| 3891 | dhd_os_sdunlock_rxq(bus->dhd); |
| 3892 | ASSERT(0); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3893 | dhdsdio_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3894 | continue; |
| 3895 | } |
| 3896 | |
| 3897 | /* All done with this one -- now deliver the packet */ |
| 3898 | goto deliver; |
| 3899 | } |
| 3900 | /* gSPI frames should not be handled in fractions */ |
| 3901 | if (bus->bus == SPI_BUS) |
| 3902 | break; |
| 3903 | |
| 3904 | /* Read frame header (hardware and software) */ |
| 3905 | sdret = |
| 3906 | dhd_bcmsdh_recv_buf(bus, bcmsdh_cur_sbwad(sdh), SDIO_FUNC_2, |
| 3907 | F2SYNC, bus->rxhdr, firstread, NULL, |
| 3908 | NULL, NULL); |
| 3909 | bus->f2rxhdrs++; |
| 3910 | ASSERT(sdret != BCME_PENDING); |
| 3911 | |
| 3912 | if (sdret < 0) { |
| 3913 | DHD_ERROR(("%s: RXHEADER FAILED: %d\n", __func__, |
| 3914 | sdret)); |
| 3915 | bus->rx_hdrfail++; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3916 | dhdsdio_rxfail(bus, true, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3917 | continue; |
| 3918 | } |
| 3919 | #ifdef DHD_DEBUG |
| 3920 | if (DHD_BYTES_ON() || DHD_HDRS_ON()) |
| 3921 | prhex("RxHdr", bus->rxhdr, SDPCM_HDRLEN); |
| 3922 | #endif |
| 3923 | |
| 3924 | /* Extract hardware header fields */ |
Stanislav Fomichev | 56dfe3c | 2011-02-20 21:43:33 +0300 | [diff] [blame] | 3925 | len = get_unaligned_le16(bus->rxhdr); |
| 3926 | check = get_unaligned_le16(bus->rxhdr + sizeof(u16)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3927 | |
| 3928 | /* All zeros means no more frames */ |
| 3929 | if (!(len | check)) { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 3930 | *finished = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3931 | break; |
| 3932 | } |
| 3933 | |
| 3934 | /* Validate check bytes */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 3935 | if ((u16) ~(len ^ check)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3936 | DHD_ERROR(("%s: HW hdr err: len/check 0x%04x/0x%04x\n", |
| 3937 | __func__, len, check)); |
| 3938 | bus->rx_badhdr++; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3939 | dhdsdio_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3940 | continue; |
| 3941 | } |
| 3942 | |
| 3943 | /* Validate frame length */ |
| 3944 | if (len < SDPCM_HDRLEN) { |
| 3945 | DHD_ERROR(("%s: HW hdr length invalid: %d\n", |
| 3946 | __func__, len)); |
| 3947 | continue; |
| 3948 | } |
| 3949 | |
| 3950 | /* Extract software header fields */ |
| 3951 | chan = SDPCM_PACKET_CHANNEL(&bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 3952 | seq = SDPCM_PACKET_SEQUENCE(&bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 3953 | doff = SDPCM_DOFFSET_VALUE(&bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 3954 | txmax = SDPCM_WINDOW_VALUE(&bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 3955 | |
| 3956 | /* Validate data offset */ |
| 3957 | if ((doff < SDPCM_HDRLEN) || (doff > len)) { |
| 3958 | DHD_ERROR(("%s: Bad data offset %d: HW len %d, min %d " |
| 3959 | "seq %d\n", |
| 3960 | __func__, doff, len, SDPCM_HDRLEN, seq)); |
| 3961 | bus->rx_badhdr++; |
| 3962 | ASSERT(0); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 3963 | dhdsdio_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 3964 | continue; |
| 3965 | } |
| 3966 | |
| 3967 | /* Save the readahead length if there is one */ |
| 3968 | bus->nextlen = |
| 3969 | bus->rxhdr[SDPCM_FRAMETAG_LEN + SDPCM_NEXTLEN_OFFSET]; |
| 3970 | if ((bus->nextlen << 4) > MAX_RX_DATASZ) { |
| 3971 | DHD_INFO(("%s (nextlen): got frame w/nextlen too large " |
| 3972 | "(%d), seq %d\n", |
| 3973 | __func__, bus->nextlen, seq)); |
| 3974 | bus->nextlen = 0; |
| 3975 | } |
| 3976 | |
| 3977 | /* Handle Flow Control */ |
| 3978 | fcbits = SDPCM_FCMASK_VALUE(&bus->rxhdr[SDPCM_FRAMETAG_LEN]); |
| 3979 | |
| 3980 | delta = 0; |
| 3981 | if (~bus->flowcontrol & fcbits) { |
| 3982 | bus->fc_xoff++; |
| 3983 | delta = 1; |
| 3984 | } |
| 3985 | if (bus->flowcontrol & ~fcbits) { |
| 3986 | bus->fc_xon++; |
| 3987 | delta = 1; |
| 3988 | } |
| 3989 | |
| 3990 | if (delta) { |
| 3991 | bus->fc_rcvd++; |
| 3992 | bus->flowcontrol = fcbits; |
| 3993 | } |
| 3994 | |
| 3995 | /* Check and update sequence number */ |
| 3996 | if (rxseq != seq) { |
| 3997 | DHD_INFO(("%s: rx_seq %d, expected %d\n", __func__, |
| 3998 | seq, rxseq)); |
| 3999 | bus->rx_badseq++; |
| 4000 | rxseq = seq; |
| 4001 | } |
| 4002 | |
| 4003 | /* Check window for sanity */ |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4004 | if ((u8) (txmax - bus->tx_seq) > 0x40) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4005 | DHD_ERROR(("%s: unlikely tx max %d with tx_seq %d\n", |
| 4006 | __func__, txmax, bus->tx_seq)); |
| 4007 | txmax = bus->tx_seq + 2; |
| 4008 | } |
| 4009 | bus->tx_max = txmax; |
| 4010 | |
| 4011 | /* Call a separate function for control frames */ |
| 4012 | if (chan == SDPCM_CONTROL_CHANNEL) { |
| 4013 | dhdsdio_read_control(bus, bus->rxhdr, len, doff); |
| 4014 | continue; |
| 4015 | } |
| 4016 | |
| 4017 | ASSERT((chan == SDPCM_DATA_CHANNEL) |
| 4018 | || (chan == SDPCM_EVENT_CHANNEL) |
| 4019 | || (chan == SDPCM_TEST_CHANNEL) |
| 4020 | || (chan == SDPCM_GLOM_CHANNEL)); |
| 4021 | |
| 4022 | /* Length to read */ |
| 4023 | rdlen = (len > firstread) ? (len - firstread) : 0; |
| 4024 | |
| 4025 | /* May pad read to blocksize for efficiency */ |
| 4026 | if (bus->roundup && bus->blocksize && |
| 4027 | (rdlen > bus->blocksize)) { |
| 4028 | pad = bus->blocksize - (rdlen % bus->blocksize); |
| 4029 | if ((pad <= bus->roundup) && (pad < bus->blocksize) && |
| 4030 | ((rdlen + pad + firstread) < MAX_RX_DATASZ)) |
| 4031 | rdlen += pad; |
| 4032 | } else if (rdlen % DHD_SDALIGN) { |
| 4033 | rdlen += DHD_SDALIGN - (rdlen % DHD_SDALIGN); |
| 4034 | } |
| 4035 | |
| 4036 | /* Satisfy length-alignment requirements */ |
| 4037 | if (forcealign && (rdlen & (ALIGNMENT - 1))) |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 4038 | rdlen = roundup(rdlen, ALIGNMENT); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4039 | |
| 4040 | if ((rdlen + firstread) > MAX_RX_DATASZ) { |
| 4041 | /* Too long -- skip this frame */ |
| 4042 | DHD_ERROR(("%s: too long: len %d rdlen %d\n", |
| 4043 | __func__, len, rdlen)); |
| 4044 | bus->dhd->rx_errors++; |
| 4045 | bus->rx_toolong++; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4046 | dhdsdio_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4047 | continue; |
| 4048 | } |
| 4049 | |
| 4050 | dhd_os_sdlock_rxq(bus->dhd); |
Arend van Spriel | a30825a | 2011-03-02 21:18:46 +0100 | [diff] [blame] | 4051 | pkt = pkt_buf_get_skb(rdlen + firstread + DHD_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4052 | if (!pkt) { |
| 4053 | /* Give up on data, request rtx of events */ |
Arend van Spriel | f09e023 | 2010-12-04 16:35:42 +0100 | [diff] [blame] | 4054 | 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] | 4055 | __func__, rdlen, chan)); |
| 4056 | bus->dhd->rx_dropped++; |
| 4057 | dhd_os_sdunlock_rxq(bus->dhd); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4058 | dhdsdio_rxfail(bus, false, RETRYCHAN(chan)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4059 | continue; |
| 4060 | } |
| 4061 | dhd_os_sdunlock_rxq(bus->dhd); |
| 4062 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4063 | ASSERT(!(pkt->prev)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4064 | |
| 4065 | /* Leave room for what we already read, and align remainder */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4066 | ASSERT(firstread < pkt->len); |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 4067 | skb_pull(pkt, firstread); |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 4068 | PKTALIGN(pkt, rdlen, DHD_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4069 | |
| 4070 | /* Read the remaining frame data */ |
| 4071 | sdret = |
| 4072 | 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] | 4073 | F2SYNC, ((u8 *) (pkt->data)), rdlen, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4074 | pkt, NULL, NULL); |
| 4075 | bus->f2rxdata++; |
| 4076 | ASSERT(sdret != BCME_PENDING); |
| 4077 | |
| 4078 | if (sdret < 0) { |
| 4079 | DHD_ERROR(("%s: read %d %s bytes failed: %d\n", |
| 4080 | __func__, rdlen, |
| 4081 | ((chan == |
| 4082 | SDPCM_EVENT_CHANNEL) ? "event" : ((chan == |
| 4083 | SDPCM_DATA_CHANNEL) |
| 4084 | ? "data" : "test")), |
| 4085 | sdret)); |
| 4086 | dhd_os_sdlock_rxq(bus->dhd); |
Arend van Spriel | a30825a | 2011-03-02 21:18:46 +0100 | [diff] [blame] | 4087 | pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4088 | dhd_os_sdunlock_rxq(bus->dhd); |
| 4089 | bus->dhd->rx_errors++; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4090 | dhdsdio_rxfail(bus, true, RETRYCHAN(chan)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4091 | continue; |
| 4092 | } |
| 4093 | |
| 4094 | /* Copy the already-read portion */ |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 4095 | skb_push(pkt, firstread); |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 4096 | memcpy(pkt->data, bus->rxhdr, firstread); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4097 | |
| 4098 | #ifdef DHD_DEBUG |
| 4099 | if (DHD_BYTES_ON() && DHD_DATA_ON()) |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4100 | prhex("Rx Data", pkt->data, len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4101 | #endif |
| 4102 | |
| 4103 | deliver: |
| 4104 | /* Save superframe descriptor and allocate packet frame */ |
| 4105 | if (chan == SDPCM_GLOM_CHANNEL) { |
| 4106 | if (SDPCM_GLOMDESC(&bus->rxhdr[SDPCM_FRAMETAG_LEN])) { |
| 4107 | DHD_GLOM(("%s: glom descriptor, %d bytes:\n", |
| 4108 | __func__, len)); |
| 4109 | #ifdef DHD_DEBUG |
| 4110 | if (DHD_GLOM_ON()) { |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4111 | prhex("Glom Data", pkt->data, len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4112 | } |
| 4113 | #endif |
Arend van Spriel | 2cb8ada | 2010-11-18 20:46:44 +0100 | [diff] [blame] | 4114 | __skb_trim(pkt, len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4115 | ASSERT(doff == SDPCM_HDRLEN); |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 4116 | skb_pull(pkt, SDPCM_HDRLEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4117 | bus->glomd = pkt; |
| 4118 | } else { |
| 4119 | DHD_ERROR(("%s: glom superframe w/o " |
| 4120 | "descriptor!\n", __func__)); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4121 | dhdsdio_rxfail(bus, false, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4122 | } |
| 4123 | continue; |
| 4124 | } |
| 4125 | |
| 4126 | /* Fill in packet len and prio, deliver upward */ |
Arend van Spriel | 2cb8ada | 2010-11-18 20:46:44 +0100 | [diff] [blame] | 4127 | __skb_trim(pkt, len); |
Arend van Spriel | c303ecb | 2010-11-18 20:46:43 +0100 | [diff] [blame] | 4128 | skb_pull(pkt, doff); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4129 | |
| 4130 | #ifdef SDTEST |
| 4131 | /* Test channel packets are processed separately */ |
| 4132 | if (chan == SDPCM_TEST_CHANNEL) { |
| 4133 | dhdsdio_testrcv(bus, pkt, seq); |
| 4134 | continue; |
| 4135 | } |
| 4136 | #endif /* SDTEST */ |
| 4137 | |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4138 | if (pkt->len == 0) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4139 | dhd_os_sdlock_rxq(bus->dhd); |
Arend van Spriel | a30825a | 2011-03-02 21:18:46 +0100 | [diff] [blame] | 4140 | pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4141 | dhd_os_sdunlock_rxq(bus->dhd); |
| 4142 | continue; |
| 4143 | } else if (dhd_prot_hdrpull(bus->dhd, &ifidx, pkt) != 0) { |
| 4144 | DHD_ERROR(("%s: rx protocol error\n", __func__)); |
| 4145 | dhd_os_sdlock_rxq(bus->dhd); |
Arend van Spriel | a30825a | 2011-03-02 21:18:46 +0100 | [diff] [blame] | 4146 | pkt_buf_free_skb(pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4147 | dhd_os_sdunlock_rxq(bus->dhd); |
| 4148 | bus->dhd->rx_errors++; |
| 4149 | continue; |
| 4150 | } |
| 4151 | |
| 4152 | /* Unlock during rx call */ |
| 4153 | dhd_os_sdunlock(bus->dhd); |
| 4154 | dhd_rx_frame(bus->dhd, ifidx, pkt, 1); |
| 4155 | dhd_os_sdlock(bus->dhd); |
| 4156 | } |
| 4157 | rxcount = maxframes - rxleft; |
| 4158 | #ifdef DHD_DEBUG |
| 4159 | /* Message if we hit the limit */ |
| 4160 | if (!rxleft && !sdtest) |
| 4161 | DHD_DATA(("%s: hit rx limit of %d frames\n", __func__, |
| 4162 | maxframes)); |
| 4163 | else |
| 4164 | #endif /* DHD_DEBUG */ |
| 4165 | DHD_DATA(("%s: processed %d frames\n", __func__, rxcount)); |
| 4166 | /* Back off rxseq if awaiting rtx, update rx_seq */ |
| 4167 | if (bus->rxskip) |
| 4168 | rxseq--; |
| 4169 | bus->rx_seq = rxseq; |
| 4170 | |
| 4171 | return rxcount; |
| 4172 | } |
| 4173 | |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 4174 | static u32 dhdsdio_hostmail(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4175 | { |
| 4176 | sdpcmd_regs_t *regs = bus->regs; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 4177 | u32 intstatus = 0; |
| 4178 | u32 hmb_data; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4179 | u8 fcbits; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4180 | uint retries = 0; |
| 4181 | |
| 4182 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 4183 | |
| 4184 | /* Read mailbox data and ack that we did so */ |
| 4185 | R_SDREG(hmb_data, ®s->tohostmailboxdata, retries); |
| 4186 | if (retries <= retry_limit) |
| 4187 | W_SDREG(SMB_INT_ACK, ®s->tosbmailbox, retries); |
| 4188 | bus->f1regdata += 2; |
| 4189 | |
| 4190 | /* Dongle recomposed rx frames, accept them again */ |
| 4191 | if (hmb_data & HMB_DATA_NAKHANDLED) { |
| 4192 | DHD_INFO(("Dongle reports NAK handled, expect rtx of %d\n", |
| 4193 | bus->rx_seq)); |
| 4194 | if (!bus->rxskip) |
| 4195 | DHD_ERROR(("%s: unexpected NAKHANDLED!\n", __func__)); |
| 4196 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4197 | bus->rxskip = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4198 | intstatus |= I_HMB_FRAME_IND; |
| 4199 | } |
| 4200 | |
| 4201 | /* |
| 4202 | * DEVREADY does not occur with gSPI. |
| 4203 | */ |
| 4204 | if (hmb_data & (HMB_DATA_DEVREADY | HMB_DATA_FWREADY)) { |
| 4205 | bus->sdpcm_ver = |
| 4206 | (hmb_data & HMB_DATA_VERSION_MASK) >> |
| 4207 | HMB_DATA_VERSION_SHIFT; |
| 4208 | if (bus->sdpcm_ver != SDPCM_PROT_VERSION) |
| 4209 | DHD_ERROR(("Version mismatch, dongle reports %d, " |
| 4210 | "expecting %d\n", |
| 4211 | bus->sdpcm_ver, SDPCM_PROT_VERSION)); |
| 4212 | else |
| 4213 | DHD_INFO(("Dongle ready, protocol version %d\n", |
| 4214 | bus->sdpcm_ver)); |
| 4215 | } |
| 4216 | |
| 4217 | /* |
| 4218 | * Flow Control has been moved into the RX headers and this out of band |
| 4219 | * method isn't used any more. Leae this here for possibly |
| 4220 | * remaining backward |
| 4221 | * compatible with older dongles |
| 4222 | */ |
| 4223 | if (hmb_data & HMB_DATA_FC) { |
| 4224 | fcbits = |
| 4225 | (hmb_data & HMB_DATA_FCDATA_MASK) >> HMB_DATA_FCDATA_SHIFT; |
| 4226 | |
| 4227 | if (fcbits & ~bus->flowcontrol) |
| 4228 | bus->fc_xoff++; |
| 4229 | if (bus->flowcontrol & ~fcbits) |
| 4230 | bus->fc_xon++; |
| 4231 | |
| 4232 | bus->fc_rcvd++; |
| 4233 | bus->flowcontrol = fcbits; |
| 4234 | } |
| 4235 | |
| 4236 | /* Shouldn't be any others */ |
| 4237 | if (hmb_data & ~(HMB_DATA_DEVREADY | |
| 4238 | HMB_DATA_NAKHANDLED | |
| 4239 | HMB_DATA_FC | |
| 4240 | HMB_DATA_FWREADY | |
| 4241 | HMB_DATA_FCDATA_MASK | HMB_DATA_VERSION_MASK)) { |
| 4242 | DHD_ERROR(("Unknown mailbox data content: 0x%02x\n", hmb_data)); |
| 4243 | } |
| 4244 | |
| 4245 | return intstatus; |
| 4246 | } |
| 4247 | |
| 4248 | bool dhdsdio_dpc(dhd_bus_t *bus) |
| 4249 | { |
| 4250 | bcmsdh_info_t *sdh = bus->sdh; |
| 4251 | sdpcmd_regs_t *regs = bus->regs; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 4252 | u32 intstatus, newstatus = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4253 | uint retries = 0; |
| 4254 | uint rxlimit = dhd_rxbound; /* Rx frames to read before resched */ |
| 4255 | uint txlimit = dhd_txbound; /* Tx frames to send before resched */ |
| 4256 | uint framecnt = 0; /* Temporary counter of tx/rx frames */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4257 | bool rxdone = true; /* Flag for no more read data */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4258 | bool resched = false; /* Flag indicating resched wanted */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4259 | |
| 4260 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 4261 | |
| 4262 | /* Start with leftover status bits */ |
| 4263 | intstatus = bus->intstatus; |
| 4264 | |
| 4265 | dhd_os_sdlock(bus->dhd); |
| 4266 | |
| 4267 | /* If waiting for HTAVAIL, check status */ |
| 4268 | if (bus->clkstate == CLK_PENDING) { |
| 4269 | int err; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4270 | u8 clkctl, devctl = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4271 | |
| 4272 | #ifdef DHD_DEBUG |
| 4273 | /* Check for inconsistent device control */ |
| 4274 | devctl = |
| 4275 | bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL, &err); |
| 4276 | if (err) { |
| 4277 | DHD_ERROR(("%s: error reading DEVCTL: %d\n", |
| 4278 | __func__, err)); |
| 4279 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 4280 | } else { |
| 4281 | ASSERT(devctl & SBSDIO_DEVCTL_CA_INT_ONLY); |
| 4282 | } |
| 4283 | #endif /* DHD_DEBUG */ |
| 4284 | |
| 4285 | /* Read CSR, if clock on switch to AVAIL, else ignore */ |
| 4286 | clkctl = |
| 4287 | bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 4288 | &err); |
| 4289 | if (err) { |
| 4290 | DHD_ERROR(("%s: error reading CSR: %d\n", __func__, |
| 4291 | err)); |
| 4292 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 4293 | } |
| 4294 | |
| 4295 | DHD_INFO(("DPC: PENDING, devctl 0x%02x clkctl 0x%02x\n", devctl, |
| 4296 | clkctl)); |
| 4297 | |
| 4298 | if (SBSDIO_HTAV(clkctl)) { |
| 4299 | devctl = |
| 4300 | bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL, |
| 4301 | &err); |
| 4302 | if (err) { |
| 4303 | DHD_ERROR(("%s: error reading DEVCTL: %d\n", |
| 4304 | __func__, err)); |
| 4305 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 4306 | } |
| 4307 | devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY; |
| 4308 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL, |
| 4309 | devctl, &err); |
| 4310 | if (err) { |
| 4311 | DHD_ERROR(("%s: error writing DEVCTL: %d\n", |
| 4312 | __func__, err)); |
| 4313 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 4314 | } |
| 4315 | bus->clkstate = CLK_AVAIL; |
| 4316 | } else { |
| 4317 | goto clkwait; |
| 4318 | } |
| 4319 | } |
| 4320 | |
| 4321 | BUS_WAKE(bus); |
| 4322 | |
| 4323 | /* Make sure backplane clock is on */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4324 | dhdsdio_clkctl(bus, CLK_AVAIL, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4325 | if (bus->clkstate == CLK_PENDING) |
| 4326 | goto clkwait; |
| 4327 | |
| 4328 | /* Pending interrupt indicates new device status */ |
| 4329 | if (bus->ipend) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4330 | bus->ipend = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4331 | R_SDREG(newstatus, ®s->intstatus, retries); |
| 4332 | bus->f1regdata++; |
| 4333 | if (bcmsdh_regfail(bus->sdh)) |
| 4334 | newstatus = 0; |
| 4335 | newstatus &= bus->hostintmask; |
| 4336 | bus->fcstate = !!(newstatus & I_HMB_FC_STATE); |
| 4337 | if (newstatus) { |
| 4338 | W_SDREG(newstatus, ®s->intstatus, retries); |
| 4339 | bus->f1regdata++; |
| 4340 | } |
| 4341 | } |
| 4342 | |
| 4343 | /* Merge new bits with previous */ |
| 4344 | intstatus |= newstatus; |
| 4345 | bus->intstatus = 0; |
| 4346 | |
| 4347 | /* Handle flow-control change: read new state in case our ack |
| 4348 | * crossed another change interrupt. If change still set, assume |
| 4349 | * FC ON for safety, let next loop through do the debounce. |
| 4350 | */ |
| 4351 | if (intstatus & I_HMB_FC_CHANGE) { |
| 4352 | intstatus &= ~I_HMB_FC_CHANGE; |
| 4353 | W_SDREG(I_HMB_FC_CHANGE, ®s->intstatus, retries); |
| 4354 | R_SDREG(newstatus, ®s->intstatus, retries); |
| 4355 | bus->f1regdata += 2; |
| 4356 | bus->fcstate = |
| 4357 | !!(newstatus & (I_HMB_FC_STATE | I_HMB_FC_CHANGE)); |
| 4358 | intstatus |= (newstatus & bus->hostintmask); |
| 4359 | } |
| 4360 | |
| 4361 | /* Handle host mailbox indication */ |
| 4362 | if (intstatus & I_HMB_HOST_INT) { |
| 4363 | intstatus &= ~I_HMB_HOST_INT; |
| 4364 | intstatus |= dhdsdio_hostmail(bus); |
| 4365 | } |
| 4366 | |
| 4367 | /* Generally don't ask for these, can get CRC errors... */ |
| 4368 | if (intstatus & I_WR_OOSYNC) { |
| 4369 | DHD_ERROR(("Dongle reports WR_OOSYNC\n")); |
| 4370 | intstatus &= ~I_WR_OOSYNC; |
| 4371 | } |
| 4372 | |
| 4373 | if (intstatus & I_RD_OOSYNC) { |
| 4374 | DHD_ERROR(("Dongle reports RD_OOSYNC\n")); |
| 4375 | intstatus &= ~I_RD_OOSYNC; |
| 4376 | } |
| 4377 | |
| 4378 | if (intstatus & I_SBINT) { |
| 4379 | DHD_ERROR(("Dongle reports SBINT\n")); |
| 4380 | intstatus &= ~I_SBINT; |
| 4381 | } |
| 4382 | |
| 4383 | /* Would be active due to wake-wlan in gSPI */ |
| 4384 | if (intstatus & I_CHIPACTIVE) { |
| 4385 | DHD_INFO(("Dongle reports CHIPACTIVE\n")); |
| 4386 | intstatus &= ~I_CHIPACTIVE; |
| 4387 | } |
| 4388 | |
| 4389 | /* Ignore frame indications if rxskip is set */ |
| 4390 | if (bus->rxskip) |
| 4391 | intstatus &= ~I_HMB_FRAME_IND; |
| 4392 | |
| 4393 | /* On frame indication, read available frames */ |
| 4394 | if (PKT_AVAILABLE()) { |
| 4395 | framecnt = dhdsdio_readframes(bus, rxlimit, &rxdone); |
| 4396 | if (rxdone || bus->rxskip) |
| 4397 | intstatus &= ~I_HMB_FRAME_IND; |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 4398 | rxlimit -= min(framecnt, rxlimit); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4399 | } |
| 4400 | |
| 4401 | /* Keep still-pending events for next scheduling */ |
| 4402 | bus->intstatus = intstatus; |
| 4403 | |
| 4404 | clkwait: |
| 4405 | #if defined(OOB_INTR_ONLY) |
| 4406 | bcmsdh_oob_intr_set(1); |
| 4407 | #endif /* (OOB_INTR_ONLY) */ |
| 4408 | /* Re-enable interrupts to detect new device events (mailbox, rx frame) |
| 4409 | * or clock availability. (Allows tx loop to check ipend if desired.) |
| 4410 | * (Unless register access seems hosed, as we may not be able to ACK...) |
| 4411 | */ |
| 4412 | if (bus->intr && bus->intdis && !bcmsdh_regfail(sdh)) { |
| 4413 | DHD_INTR(("%s: enable SDIO interrupts, rxdone %d framecnt %d\n", |
| 4414 | __func__, rxdone, framecnt)); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4415 | bus->intdis = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4416 | bcmsdh_intr_enable(sdh); |
| 4417 | } |
| 4418 | |
| 4419 | if (DATAOK(bus) && bus->ctrl_frame_stat && |
| 4420 | (bus->clkstate == CLK_AVAIL)) { |
| 4421 | int ret, i; |
| 4422 | |
| 4423 | ret = |
| 4424 | 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] | 4425 | F2SYNC, (u8 *) bus->ctrl_frame_buf, |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 4426 | (u32) bus->ctrl_frame_len, NULL, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4427 | NULL, NULL); |
| 4428 | ASSERT(ret != BCME_PENDING); |
| 4429 | |
| 4430 | if (ret < 0) { |
| 4431 | /* On failure, abort the command and |
| 4432 | terminate the frame */ |
| 4433 | DHD_INFO(("%s: sdio error %d, abort command and " |
| 4434 | "terminate frame.\n", __func__, ret)); |
| 4435 | bus->tx_sderrs++; |
| 4436 | |
| 4437 | bcmsdh_abort(sdh, SDIO_FUNC_2); |
| 4438 | |
| 4439 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, |
| 4440 | SBSDIO_FUNC1_FRAMECTRL, SFC_WF_TERM, |
| 4441 | NULL); |
| 4442 | bus->f1regdata++; |
| 4443 | |
| 4444 | for (i = 0; i < 3; i++) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4445 | u8 hi, lo; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4446 | hi = bcmsdh_cfg_read(sdh, SDIO_FUNC_1, |
| 4447 | SBSDIO_FUNC1_WFRAMEBCHI, |
| 4448 | NULL); |
| 4449 | lo = bcmsdh_cfg_read(sdh, SDIO_FUNC_1, |
| 4450 | SBSDIO_FUNC1_WFRAMEBCLO, |
| 4451 | NULL); |
| 4452 | bus->f1regdata += 2; |
| 4453 | if ((hi == 0) && (lo == 0)) |
| 4454 | break; |
| 4455 | } |
| 4456 | |
| 4457 | } |
| 4458 | if (ret == 0) |
| 4459 | bus->tx_seq = (bus->tx_seq + 1) % SDPCM_SEQUENCE_WRAP; |
| 4460 | |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 4461 | DHD_INFO(("Return_dpc value is : %d\n", ret)); |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4462 | bus->ctrl_frame_stat = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4463 | dhd_wait_event_wakeup(bus->dhd); |
| 4464 | } |
| 4465 | /* Send queued frames (limit 1 if rx may still be pending) */ |
| 4466 | else if ((bus->clkstate == CLK_AVAIL) && !bus->fcstate && |
| 4467 | pktq_mlen(&bus->txq, ~bus->flowcontrol) && txlimit |
| 4468 | && DATAOK(bus)) { |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 4469 | framecnt = rxdone ? txlimit : min(txlimit, dhd_txminmax); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4470 | framecnt = dhdsdio_sendfromq(bus, framecnt); |
| 4471 | txlimit -= framecnt; |
| 4472 | } |
| 4473 | |
| 4474 | /* Resched if events or tx frames are pending, |
| 4475 | else await next interrupt */ |
| 4476 | /* On failed register access, all bets are off: |
| 4477 | no resched or interrupts */ |
| 4478 | if ((bus->dhd->busstate == DHD_BUS_DOWN) || bcmsdh_regfail(sdh)) { |
| 4479 | DHD_ERROR(("%s: failed backplane access over SDIO, halting " |
| 4480 | "operation %d\n", __func__, bcmsdh_regfail(sdh))); |
| 4481 | bus->dhd->busstate = DHD_BUS_DOWN; |
| 4482 | bus->intstatus = 0; |
| 4483 | } else if (bus->clkstate == CLK_PENDING) { |
| 4484 | DHD_INFO(("%s: rescheduled due to CLK_PENDING awaiting " |
| 4485 | "I_CHIPACTIVE interrupt\n", __func__)); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4486 | resched = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4487 | } else if (bus->intstatus || bus->ipend || |
| 4488 | (!bus->fcstate && pktq_mlen(&bus->txq, ~bus->flowcontrol) && |
| 4489 | DATAOK(bus)) || PKT_AVAILABLE()) { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4490 | resched = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4491 | } |
| 4492 | |
| 4493 | bus->dpc_sched = resched; |
| 4494 | |
| 4495 | /* If we're done for now, turn off clock request. */ |
| 4496 | if ((bus->clkstate != CLK_PENDING) |
| 4497 | && bus->idletime == DHD_IDLE_IMMEDIATE) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4498 | bus->activity = false; |
| 4499 | dhdsdio_clkctl(bus, CLK_NONE, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4500 | } |
| 4501 | |
| 4502 | dhd_os_sdunlock(bus->dhd); |
| 4503 | |
| 4504 | return resched; |
| 4505 | } |
| 4506 | |
| 4507 | bool dhd_bus_dpc(struct dhd_bus *bus) |
| 4508 | { |
| 4509 | bool resched; |
| 4510 | |
| 4511 | /* Call the DPC directly. */ |
| 4512 | DHD_TRACE(("Calling dhdsdio_dpc() from %s\n", __func__)); |
| 4513 | resched = dhdsdio_dpc(bus); |
| 4514 | |
| 4515 | return resched; |
| 4516 | } |
| 4517 | |
| 4518 | void dhdsdio_isr(void *arg) |
| 4519 | { |
| 4520 | dhd_bus_t *bus = (dhd_bus_t *) arg; |
| 4521 | bcmsdh_info_t *sdh; |
| 4522 | |
| 4523 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 4524 | |
| 4525 | if (!bus) { |
| 4526 | DHD_ERROR(("%s : bus is null pointer , exit\n", __func__)); |
| 4527 | return; |
| 4528 | } |
| 4529 | sdh = bus->sdh; |
| 4530 | |
| 4531 | if (bus->dhd->busstate == DHD_BUS_DOWN) { |
| 4532 | DHD_ERROR(("%s : bus is down. we have nothing to do\n", |
| 4533 | __func__)); |
| 4534 | return; |
| 4535 | } |
| 4536 | /* Count the interrupt call */ |
| 4537 | bus->intrcount++; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4538 | bus->ipend = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4539 | |
| 4540 | /* Shouldn't get this interrupt if we're sleeping? */ |
| 4541 | if (bus->sleeping) { |
| 4542 | DHD_ERROR(("INTERRUPT WHILE SLEEPING??\n")); |
| 4543 | return; |
| 4544 | } |
| 4545 | |
| 4546 | /* Disable additional interrupts (is this needed now)? */ |
| 4547 | if (bus->intr) |
| 4548 | DHD_INTR(("%s: disable SDIO interrupts\n", __func__)); |
| 4549 | else |
| 4550 | DHD_ERROR(("dhdsdio_isr() w/o interrupt configured!\n")); |
| 4551 | |
| 4552 | bcmsdh_intr_disable(sdh); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4553 | bus->intdis = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4554 | |
| 4555 | #if defined(SDIO_ISR_THREAD) |
| 4556 | DHD_TRACE(("Calling dhdsdio_dpc() from %s\n", __func__)); |
| 4557 | while (dhdsdio_dpc(bus)) |
| 4558 | ; |
| 4559 | #else |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4560 | bus->dpc_sched = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4561 | dhd_sched_dpc(bus->dhd); |
| 4562 | #endif |
| 4563 | |
| 4564 | } |
| 4565 | |
| 4566 | #ifdef SDTEST |
| 4567 | static void dhdsdio_pktgen_init(dhd_bus_t *bus) |
| 4568 | { |
| 4569 | /* Default to specified length, or full range */ |
| 4570 | if (dhd_pktgen_len) { |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 4571 | bus->pktgen_maxlen = min(dhd_pktgen_len, MAX_PKTGEN_LEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4572 | bus->pktgen_minlen = bus->pktgen_maxlen; |
| 4573 | } else { |
| 4574 | bus->pktgen_maxlen = MAX_PKTGEN_LEN; |
| 4575 | bus->pktgen_minlen = 0; |
| 4576 | } |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4577 | bus->pktgen_len = (u16) bus->pktgen_minlen; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4578 | |
| 4579 | /* Default to per-watchdog burst with 10s print time */ |
| 4580 | bus->pktgen_freq = 1; |
| 4581 | bus->pktgen_print = 10000 / dhd_watchdog_ms; |
| 4582 | bus->pktgen_count = (dhd_pktgen * dhd_watchdog_ms + 999) / 1000; |
| 4583 | |
| 4584 | /* Default to echo mode */ |
| 4585 | bus->pktgen_mode = DHD_PKTGEN_ECHO; |
| 4586 | bus->pktgen_stop = 1; |
| 4587 | } |
| 4588 | |
| 4589 | static void dhdsdio_pktgen(dhd_bus_t *bus) |
| 4590 | { |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 4591 | struct sk_buff *pkt; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4592 | u8 *data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4593 | uint pktcount; |
| 4594 | uint fillbyte; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4595 | u16 len; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4596 | |
| 4597 | /* Display current count if appropriate */ |
| 4598 | if (bus->pktgen_print && (++bus->pktgen_ptick >= bus->pktgen_print)) { |
| 4599 | bus->pktgen_ptick = 0; |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 4600 | printk(KERN_DEBUG "%s: send attempts %d rcvd %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4601 | __func__, bus->pktgen_sent, bus->pktgen_rcvd); |
| 4602 | } |
| 4603 | |
| 4604 | /* For recv mode, just make sure dongle has started sending */ |
| 4605 | if (bus->pktgen_mode == DHD_PKTGEN_RECV) { |
| 4606 | if (!bus->pktgen_rcvd) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4607 | dhdsdio_sdtest_set(bus, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4608 | return; |
| 4609 | } |
| 4610 | |
| 4611 | /* Otherwise, generate or request the specified number of packets */ |
| 4612 | for (pktcount = 0; pktcount < bus->pktgen_count; pktcount++) { |
| 4613 | /* Stop if total has been reached */ |
| 4614 | if (bus->pktgen_total |
| 4615 | && (bus->pktgen_sent >= bus->pktgen_total)) { |
| 4616 | bus->pktgen_count = 0; |
| 4617 | break; |
| 4618 | } |
| 4619 | |
| 4620 | /* Allocate an appropriate-sized packet */ |
| 4621 | len = bus->pktgen_len; |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 4622 | pkt = pkt_buf_get_skb( |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 4623 | (len + SDPCM_HDRLEN + SDPCM_TEST_HDRLEN + DHD_SDALIGN), |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4624 | true); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 4625 | if (!pkt) { |
Arend van Spriel | f09e023 | 2010-12-04 16:35:42 +0100 | [diff] [blame] | 4626 | DHD_ERROR(("%s: pkt_buf_get_skb failed!\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4627 | break; |
| 4628 | } |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 4629 | PKTALIGN(pkt, (len + SDPCM_HDRLEN + SDPCM_TEST_HDRLEN), |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4630 | DHD_SDALIGN); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4631 | data = (u8 *) (pkt->data) + SDPCM_HDRLEN; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4632 | |
| 4633 | /* Write test header cmd and extra based on mode */ |
| 4634 | switch (bus->pktgen_mode) { |
| 4635 | case DHD_PKTGEN_ECHO: |
| 4636 | *data++ = SDPCM_TEST_ECHOREQ; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4637 | *data++ = (u8) bus->pktgen_sent; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4638 | break; |
| 4639 | |
| 4640 | case DHD_PKTGEN_SEND: |
| 4641 | *data++ = SDPCM_TEST_DISCARD; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4642 | *data++ = (u8) bus->pktgen_sent; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4643 | break; |
| 4644 | |
| 4645 | case DHD_PKTGEN_RXBURST: |
| 4646 | *data++ = SDPCM_TEST_BURST; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4647 | *data++ = (u8) bus->pktgen_count; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4648 | break; |
| 4649 | |
| 4650 | default: |
| 4651 | DHD_ERROR(("Unrecognized pktgen mode %d\n", |
| 4652 | bus->pktgen_mode)); |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 4653 | pkt_buf_free_skb(pkt, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4654 | bus->pktgen_count = 0; |
| 4655 | return; |
| 4656 | } |
| 4657 | |
| 4658 | /* Write test header length field */ |
| 4659 | *data++ = (len >> 0); |
| 4660 | *data++ = (len >> 8); |
| 4661 | |
| 4662 | /* Then fill in the remainder -- N/A for burst, |
| 4663 | but who cares... */ |
| 4664 | for (fillbyte = 0; fillbyte < len; fillbyte++) |
| 4665 | *data++ = |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4666 | SDPCM_TEST_FILL(fillbyte, (u8) bus->pktgen_sent); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4667 | |
| 4668 | #ifdef DHD_DEBUG |
| 4669 | if (DHD_BYTES_ON() && DHD_DATA_ON()) { |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4670 | data = (u8 *) (pkt->data) + SDPCM_HDRLEN; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4671 | prhex("dhdsdio_pktgen: Tx Data", data, |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4672 | pkt->len - SDPCM_HDRLEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4673 | } |
| 4674 | #endif |
| 4675 | |
| 4676 | /* Send it */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4677 | if (dhdsdio_txpkt(bus, pkt, SDPCM_TEST_CHANNEL, true)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4678 | bus->pktgen_fail++; |
| 4679 | if (bus->pktgen_stop |
| 4680 | && bus->pktgen_stop == bus->pktgen_fail) |
| 4681 | bus->pktgen_count = 0; |
| 4682 | } |
| 4683 | bus->pktgen_sent++; |
| 4684 | |
| 4685 | /* Bump length if not fixed, wrap at max */ |
| 4686 | if (++bus->pktgen_len > bus->pktgen_maxlen) |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4687 | bus->pktgen_len = (u16) bus->pktgen_minlen; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4688 | |
| 4689 | /* Special case for burst mode: just send one request! */ |
| 4690 | if (bus->pktgen_mode == DHD_PKTGEN_RXBURST) |
| 4691 | break; |
| 4692 | } |
| 4693 | } |
| 4694 | |
| 4695 | static void dhdsdio_sdtest_set(dhd_bus_t *bus, bool start) |
| 4696 | { |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 4697 | struct sk_buff *pkt; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4698 | u8 *data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4699 | |
| 4700 | /* Allocate the packet */ |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 4701 | 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] | 4702 | true); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 4703 | if (!pkt) { |
Arend van Spriel | f09e023 | 2010-12-04 16:35:42 +0100 | [diff] [blame] | 4704 | DHD_ERROR(("%s: pkt_buf_get_skb failed!\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4705 | return; |
| 4706 | } |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 4707 | PKTALIGN(pkt, (SDPCM_HDRLEN + SDPCM_TEST_HDRLEN), DHD_SDALIGN); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4708 | data = (u8 *) (pkt->data) + SDPCM_HDRLEN; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4709 | |
| 4710 | /* Fill in the test header */ |
| 4711 | *data++ = SDPCM_TEST_SEND; |
| 4712 | *data++ = start; |
| 4713 | *data++ = (bus->pktgen_maxlen >> 0); |
| 4714 | *data++ = (bus->pktgen_maxlen >> 8); |
| 4715 | |
| 4716 | /* Send it */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4717 | if (dhdsdio_txpkt(bus, pkt, SDPCM_TEST_CHANNEL, true)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4718 | bus->pktgen_fail++; |
| 4719 | } |
| 4720 | |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 4721 | 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] | 4722 | { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4723 | u8 *data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4724 | uint pktlen; |
| 4725 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4726 | u8 cmd; |
| 4727 | u8 extra; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 4728 | u16 len; |
| 4729 | u16 offset; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4730 | |
| 4731 | /* Check for min length */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4732 | pktlen = pkt->len; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4733 | if (pktlen < SDPCM_TEST_HDRLEN) { |
| 4734 | DHD_ERROR(("dhdsdio_restrcv: toss runt frame, pktlen %d\n", |
| 4735 | pktlen)); |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 4736 | pkt_buf_free_skb(pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4737 | return; |
| 4738 | } |
| 4739 | |
| 4740 | /* Extract header fields */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4741 | data = pkt->data; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4742 | cmd = *data++; |
| 4743 | extra = *data++; |
| 4744 | len = *data++; |
| 4745 | len += *data++ << 8; |
| 4746 | |
| 4747 | /* Check length for relevant commands */ |
| 4748 | if (cmd == SDPCM_TEST_DISCARD || cmd == SDPCM_TEST_ECHOREQ |
| 4749 | || cmd == SDPCM_TEST_ECHORSP) { |
| 4750 | if (pktlen != len + SDPCM_TEST_HDRLEN) { |
| 4751 | DHD_ERROR(("dhdsdio_testrcv: frame length mismatch, " |
| 4752 | "pktlen %d seq %d" " cmd %d extra %d len %d\n", |
| 4753 | pktlen, seq, cmd, extra, len)); |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 4754 | pkt_buf_free_skb(pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4755 | return; |
| 4756 | } |
| 4757 | } |
| 4758 | |
| 4759 | /* Process as per command */ |
| 4760 | switch (cmd) { |
| 4761 | case SDPCM_TEST_ECHOREQ: |
| 4762 | /* Rx->Tx turnaround ok (even on NDIS w/current |
| 4763 | implementation) */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 4764 | *(u8 *) (pkt->data) = SDPCM_TEST_ECHORSP; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4765 | if (dhdsdio_txpkt(bus, pkt, SDPCM_TEST_CHANNEL, true) == 0) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4766 | bus->pktgen_sent++; |
| 4767 | } else { |
| 4768 | bus->pktgen_fail++; |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 4769 | pkt_buf_free_skb(pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4770 | } |
| 4771 | bus->pktgen_rcvd++; |
| 4772 | break; |
| 4773 | |
| 4774 | case SDPCM_TEST_ECHORSP: |
| 4775 | if (bus->ext_loop) { |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 4776 | pkt_buf_free_skb(pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4777 | bus->pktgen_rcvd++; |
| 4778 | break; |
| 4779 | } |
| 4780 | |
| 4781 | for (offset = 0; offset < len; offset++, data++) { |
| 4782 | if (*data != SDPCM_TEST_FILL(offset, extra)) { |
| 4783 | DHD_ERROR(("dhdsdio_testrcv: echo data mismatch: " "offset %d (len %d) expect 0x%02x rcvd 0x%02x\n", |
| 4784 | offset, len, |
| 4785 | SDPCM_TEST_FILL(offset, extra), *data)); |
| 4786 | break; |
| 4787 | } |
| 4788 | } |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 4789 | pkt_buf_free_skb(pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4790 | bus->pktgen_rcvd++; |
| 4791 | break; |
| 4792 | |
| 4793 | case SDPCM_TEST_DISCARD: |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 4794 | pkt_buf_free_skb(pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4795 | bus->pktgen_rcvd++; |
| 4796 | break; |
| 4797 | |
| 4798 | case SDPCM_TEST_BURST: |
| 4799 | case SDPCM_TEST_SEND: |
| 4800 | default: |
| 4801 | DHD_INFO(("dhdsdio_testrcv: unsupported or unknown command, " |
| 4802 | "pktlen %d seq %d" " cmd %d extra %d len %d\n", |
| 4803 | pktlen, seq, cmd, extra, len)); |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 4804 | pkt_buf_free_skb(pkt, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4805 | break; |
| 4806 | } |
| 4807 | |
| 4808 | /* For recv mode, stop at limie (and tell dongle to stop sending) */ |
| 4809 | if (bus->pktgen_mode == DHD_PKTGEN_RECV) { |
| 4810 | if (bus->pktgen_total |
| 4811 | && (bus->pktgen_rcvd >= bus->pktgen_total)) { |
| 4812 | bus->pktgen_count = 0; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4813 | dhdsdio_sdtest_set(bus, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4814 | } |
| 4815 | } |
| 4816 | } |
| 4817 | #endif /* SDTEST */ |
| 4818 | |
| 4819 | extern bool dhd_bus_watchdog(dhd_pub_t *dhdp) |
| 4820 | { |
| 4821 | dhd_bus_t *bus; |
| 4822 | |
| 4823 | DHD_TIMER(("%s: Enter\n", __func__)); |
| 4824 | |
| 4825 | bus = dhdp->bus; |
| 4826 | |
| 4827 | if (bus->dhd->dongle_reset) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4828 | return false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4829 | |
| 4830 | /* Ignore the timer if simulating bus down */ |
| 4831 | if (bus->sleeping) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4832 | return false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4833 | |
| 4834 | dhd_os_sdlock(bus->dhd); |
| 4835 | |
| 4836 | /* Poll period: check device if appropriate. */ |
| 4837 | if (bus->poll && (++bus->polltick >= bus->pollrate)) { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 4838 | u32 intstatus = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4839 | |
| 4840 | /* Reset poll tick */ |
| 4841 | bus->polltick = 0; |
| 4842 | |
| 4843 | /* Check device if no interrupts */ |
| 4844 | if (!bus->intr || (bus->intrcount == bus->lastintrs)) { |
| 4845 | |
| 4846 | if (!bus->dpc_sched) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4847 | u8 devpend; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4848 | devpend = bcmsdh_cfg_read(bus->sdh, SDIO_FUNC_0, |
| 4849 | SDIOD_CCCR_INTPEND, |
| 4850 | NULL); |
| 4851 | intstatus = |
| 4852 | devpend & (INTR_STATUS_FUNC1 | |
| 4853 | INTR_STATUS_FUNC2); |
| 4854 | } |
| 4855 | |
| 4856 | /* If there is something, make like the ISR and |
| 4857 | schedule the DPC */ |
| 4858 | if (intstatus) { |
| 4859 | bus->pollcnt++; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4860 | bus->ipend = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4861 | if (bus->intr) |
| 4862 | bcmsdh_intr_disable(bus->sdh); |
| 4863 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4864 | bus->dpc_sched = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4865 | dhd_sched_dpc(bus->dhd); |
| 4866 | |
| 4867 | } |
| 4868 | } |
| 4869 | |
| 4870 | /* Update interrupt tracking */ |
| 4871 | bus->lastintrs = bus->intrcount; |
| 4872 | } |
| 4873 | #ifdef DHD_DEBUG |
| 4874 | /* Poll for console output periodically */ |
| 4875 | if (dhdp->busstate == DHD_BUS_DATA && dhd_console_ms != 0) { |
| 4876 | bus->console.count += dhd_watchdog_ms; |
| 4877 | if (bus->console.count >= dhd_console_ms) { |
| 4878 | bus->console.count -= dhd_console_ms; |
| 4879 | /* Make sure backplane clock is on */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4880 | dhdsdio_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4881 | if (dhdsdio_readconsole(bus) < 0) |
| 4882 | dhd_console_ms = 0; /* On error, |
| 4883 | stop trying */ |
| 4884 | } |
| 4885 | } |
| 4886 | #endif /* DHD_DEBUG */ |
| 4887 | |
| 4888 | #ifdef SDTEST |
| 4889 | /* Generate packets if configured */ |
| 4890 | if (bus->pktgen_count && (++bus->pktgen_tick >= bus->pktgen_freq)) { |
| 4891 | /* Make sure backplane clock is on */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4892 | dhdsdio_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4893 | bus->pktgen_tick = 0; |
| 4894 | dhdsdio_pktgen(bus); |
| 4895 | } |
| 4896 | #endif |
| 4897 | |
| 4898 | /* On idle timeout clear activity flag and/or turn off clock */ |
| 4899 | if ((bus->idletime > 0) && (bus->clkstate == CLK_AVAIL)) { |
| 4900 | if (++bus->idlecount >= bus->idletime) { |
| 4901 | bus->idlecount = 0; |
| 4902 | if (bus->activity) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4903 | bus->activity = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4904 | dhd_os_wd_timer(bus->dhd, dhd_watchdog_ms); |
| 4905 | } else { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4906 | dhdsdio_clkctl(bus, CLK_NONE, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4907 | } |
| 4908 | } |
| 4909 | } |
| 4910 | |
| 4911 | dhd_os_sdunlock(bus->dhd); |
| 4912 | |
| 4913 | return bus->ipend; |
| 4914 | } |
| 4915 | |
| 4916 | #ifdef DHD_DEBUG |
Greg Kroah-Hartman | 580a0bd | 2010-10-05 11:09:48 -0700 | [diff] [blame] | 4917 | 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] | 4918 | { |
| 4919 | dhd_bus_t *bus = dhdp->bus; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 4920 | u32 addr, val; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4921 | int rv; |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 4922 | struct sk_buff *pkt; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4923 | |
| 4924 | /* Address could be zero if CONSOLE := 0 in dongle Makefile */ |
| 4925 | if (bus->console_addr == 0) |
| 4926 | return BCME_UNSUPPORTED; |
| 4927 | |
| 4928 | /* Exclusive bus access */ |
| 4929 | dhd_os_sdlock(bus->dhd); |
| 4930 | |
| 4931 | /* Don't allow input if dongle is in reset */ |
| 4932 | if (bus->dhd->dongle_reset) { |
| 4933 | dhd_os_sdunlock(bus->dhd); |
| 4934 | return BCME_NOTREADY; |
| 4935 | } |
| 4936 | |
| 4937 | /* Request clock to allow SDIO accesses */ |
| 4938 | BUS_WAKE(bus); |
| 4939 | /* 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] | 4940 | dhdsdio_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4941 | |
| 4942 | /* Zero cbuf_index */ |
Greg Kroah-Hartman | ce0f1b8 | 2010-10-08 11:44:45 -0700 | [diff] [blame] | 4943 | addr = bus->console_addr + offsetof(hndrte_cons_t, cbuf_idx); |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 4944 | val = cpu_to_le32(0); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4945 | rv = dhdsdio_membytes(bus, true, addr, (u8 *)&val, sizeof(val)); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 4946 | if (rv < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4947 | goto done; |
| 4948 | |
| 4949 | /* Write message into cbuf */ |
Greg Kroah-Hartman | ce0f1b8 | 2010-10-08 11:44:45 -0700 | [diff] [blame] | 4950 | addr = bus->console_addr + offsetof(hndrte_cons_t, cbuf); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4951 | rv = dhdsdio_membytes(bus, true, addr, (u8 *)msg, msglen); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 4952 | if (rv < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4953 | goto done; |
| 4954 | |
| 4955 | /* Write length into vcons_in */ |
Greg Kroah-Hartman | ce0f1b8 | 2010-10-08 11:44:45 -0700 | [diff] [blame] | 4956 | addr = bus->console_addr + offsetof(hndrte_cons_t, vcons_in); |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 4957 | val = cpu_to_le32(msglen); |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4958 | rv = dhdsdio_membytes(bus, true, addr, (u8 *)&val, sizeof(val)); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 4959 | if (rv < 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4960 | goto done; |
| 4961 | |
| 4962 | /* Bump dongle by sending an empty event pkt. |
| 4963 | * sdpcm_sendup (RX) checks for virtual console input. |
| 4964 | */ |
Arend van Spriel | a30825a | 2011-03-02 21:18:46 +0100 | [diff] [blame] | 4965 | pkt = pkt_buf_get_skb(4 + SDPCM_RESERVE); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 4966 | if ((pkt != NULL) && bus->clkstate == CLK_AVAIL) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4967 | dhdsdio_txpkt(bus, pkt, SDPCM_EVENT_CHANNEL, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4968 | |
| 4969 | done: |
| 4970 | if ((bus->idletime == DHD_IDLE_IMMEDIATE) && !bus->dpc_sched) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 4971 | bus->activity = false; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 4972 | dhdsdio_clkctl(bus, CLK_NONE, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4973 | } |
| 4974 | |
| 4975 | dhd_os_sdunlock(bus->dhd); |
| 4976 | |
| 4977 | return rv; |
| 4978 | } |
| 4979 | #endif /* DHD_DEBUG */ |
| 4980 | |
| 4981 | #ifdef DHD_DEBUG |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 4982 | static void dhd_dump_cis(uint fn, u8 *cis) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 4983 | { |
| 4984 | uint byte, tag, tdata; |
| 4985 | DHD_INFO(("Function %d CIS:\n", fn)); |
| 4986 | |
| 4987 | for (tdata = byte = 0; byte < SBSDIO_CIS_SIZE_LIMIT; byte++) { |
| 4988 | if ((byte % 16) == 0) |
| 4989 | DHD_INFO((" ")); |
| 4990 | DHD_INFO(("%02x ", cis[byte])); |
| 4991 | if ((byte % 16) == 15) |
| 4992 | DHD_INFO(("\n")); |
| 4993 | if (!tdata--) { |
| 4994 | tag = cis[byte]; |
| 4995 | if (tag == 0xff) |
| 4996 | break; |
| 4997 | else if (!tag) |
| 4998 | tdata = 0; |
| 4999 | else if ((byte + 1) < SBSDIO_CIS_SIZE_LIMIT) |
| 5000 | tdata = cis[byte + 1] + 1; |
| 5001 | else |
| 5002 | DHD_INFO(("]")); |
| 5003 | } |
| 5004 | } |
| 5005 | if ((byte % 16) != 15) |
| 5006 | DHD_INFO(("\n")); |
| 5007 | } |
| 5008 | #endif /* DHD_DEBUG */ |
| 5009 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5010 | static bool dhdsdio_chipmatch(u16 chipid) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5011 | { |
| 5012 | if (chipid == BCM4325_CHIP_ID) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5013 | return true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5014 | if (chipid == BCM4329_CHIP_ID) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5015 | return true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5016 | if (chipid == BCM4319_CHIP_ID) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5017 | return true; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5018 | return false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5019 | } |
| 5020 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5021 | static void *dhdsdio_probe(u16 venid, u16 devid, u16 bus_no, |
| 5022 | u16 slot, u16 func, uint bustype, void *regsva, |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 5023 | void *sdh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5024 | { |
| 5025 | int ret; |
| 5026 | dhd_bus_t *bus; |
| 5027 | |
| 5028 | /* Init global variables at run-time, not as part of the declaration. |
| 5029 | * This is required to support init/de-init of the driver. |
| 5030 | * Initialization |
| 5031 | * of globals as part of the declaration results in non-deterministic |
| 5032 | * behavior since the value of the globals may be different on the |
| 5033 | * first time that the driver is initialized vs subsequent |
| 5034 | * initializations. |
| 5035 | */ |
| 5036 | dhd_txbound = DHD_TXBOUND; |
| 5037 | dhd_rxbound = DHD_RXBOUND; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5038 | dhd_alignctl = true; |
| 5039 | sd1idle = true; |
| 5040 | dhd_readahead = true; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5041 | retrydata = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5042 | dhd_dongle_memsize = 0; |
| 5043 | dhd_txminmax = DHD_TXMINMAX; |
| 5044 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5045 | forcealign = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5046 | |
| 5047 | dhd_common_init(); |
| 5048 | |
| 5049 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5050 | DHD_INFO(("%s: venid 0x%04x devid 0x%04x\n", __func__, venid, devid)); |
| 5051 | |
| 5052 | /* We make assumptions about address window mappings */ |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 5053 | ASSERT((unsigned long)regsva == SI_ENUM_BASE); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5054 | |
| 5055 | /* BCMSDH passes venid and devid based on CIS parsing -- but |
| 5056 | * low-power start |
| 5057 | * means early parse could fail, so here we should get either an ID |
| 5058 | * we recognize OR (-1) indicating we must request power first. |
| 5059 | */ |
| 5060 | /* Check the Vendor ID */ |
| 5061 | switch (venid) { |
| 5062 | case 0x0000: |
Stanislav Fomichev | be1c09f | 2011-03-28 01:31:36 +0400 | [diff] [blame] | 5063 | case PCI_VENDOR_ID_BROADCOM: |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5064 | break; |
| 5065 | default: |
| 5066 | DHD_ERROR(("%s: unknown vendor: 0x%04x\n", __func__, venid)); |
| 5067 | return NULL; |
| 5068 | } |
| 5069 | |
| 5070 | /* Check the Device ID and make sure it's one that we support */ |
| 5071 | switch (devid) { |
| 5072 | case BCM4325_D11DUAL_ID: /* 4325 802.11a/g id */ |
| 5073 | case BCM4325_D11G_ID: /* 4325 802.11g 2.4Ghz band id */ |
| 5074 | case BCM4325_D11A_ID: /* 4325 802.11a 5Ghz band id */ |
| 5075 | DHD_INFO(("%s: found 4325 Dongle\n", __func__)); |
| 5076 | break; |
| 5077 | case BCM4329_D11NDUAL_ID: /* 4329 802.11n dualband device */ |
| 5078 | case BCM4329_D11N2G_ID: /* 4329 802.11n 2.4G device */ |
| 5079 | case BCM4329_D11N5G_ID: /* 4329 802.11n 5G device */ |
| 5080 | case 0x4329: |
| 5081 | DHD_INFO(("%s: found 4329 Dongle\n", __func__)); |
| 5082 | break; |
| 5083 | case BCM4319_D11N_ID: /* 4319 802.11n id */ |
| 5084 | case BCM4319_D11N2G_ID: /* 4319 802.11n2g id */ |
| 5085 | case BCM4319_D11N5G_ID: /* 4319 802.11n5g id */ |
| 5086 | DHD_INFO(("%s: found 4319 Dongle\n", __func__)); |
| 5087 | break; |
| 5088 | case 0: |
| 5089 | DHD_INFO(("%s: allow device id 0, will check chip internals\n", |
| 5090 | __func__)); |
| 5091 | break; |
| 5092 | |
| 5093 | default: |
| 5094 | DHD_ERROR(("%s: skipping 0x%04x/0x%04x, not a dongle\n", |
| 5095 | __func__, venid, devid)); |
| 5096 | return NULL; |
| 5097 | } |
| 5098 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5099 | /* Allocate private bus interface state */ |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5100 | bus = kzalloc(sizeof(dhd_bus_t), GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5101 | if (!bus) { |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5102 | DHD_ERROR(("%s: kmalloc of dhd_bus_t failed\n", __func__)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5103 | goto fail; |
| 5104 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5105 | bus->sdh = sdh; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5106 | bus->cl_devid = (u16) devid; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5107 | bus->bus = DHD_BUS; |
| 5108 | bus->tx_seq = SDPCM_SEQUENCE_WRAP - 1; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5109 | bus->usebufpool = false; /* Use bufpool if allocated, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5110 | else use locally malloced rxbuf */ |
| 5111 | |
| 5112 | /* attempt to attach to the dongle */ |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 5113 | if (!(dhdsdio_probe_attach(bus, sdh, regsva, devid))) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5114 | DHD_ERROR(("%s: dhdsdio_probe_attach failed\n", __func__)); |
| 5115 | goto fail; |
| 5116 | } |
| 5117 | |
| 5118 | /* Attach to the dhd/OS/network interface */ |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 5119 | bus->dhd = dhd_attach(bus, SDPCM_RESERVE); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5120 | if (!bus->dhd) { |
| 5121 | DHD_ERROR(("%s: dhd_attach failed\n", __func__)); |
| 5122 | goto fail; |
| 5123 | } |
| 5124 | |
| 5125 | /* Allocate buffers */ |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 5126 | if (!(dhdsdio_probe_malloc(bus, sdh))) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5127 | DHD_ERROR(("%s: dhdsdio_probe_malloc failed\n", __func__)); |
| 5128 | goto fail; |
| 5129 | } |
| 5130 | |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 5131 | if (!(dhdsdio_probe_init(bus, sdh))) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5132 | DHD_ERROR(("%s: dhdsdio_probe_init failed\n", __func__)); |
| 5133 | goto fail; |
| 5134 | } |
| 5135 | |
| 5136 | /* Register interrupt callback, but mask it (not operational yet). */ |
| 5137 | DHD_INTR(("%s: disable SDIO interrupts (not interested yet)\n", |
| 5138 | __func__)); |
| 5139 | bcmsdh_intr_disable(sdh); |
| 5140 | ret = bcmsdh_intr_reg(sdh, dhdsdio_isr, bus); |
| 5141 | if (ret != 0) { |
| 5142 | DHD_ERROR(("%s: FAILED: bcmsdh_intr_reg returned %d\n", |
| 5143 | __func__, ret)); |
| 5144 | goto fail; |
| 5145 | } |
| 5146 | DHD_INTR(("%s: registered SDIO interrupt function ok\n", __func__)); |
| 5147 | |
| 5148 | DHD_INFO(("%s: completed!!\n", __func__)); |
| 5149 | |
| 5150 | /* if firmware path present try to download and bring up bus */ |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5151 | ret = dhd_bus_start(bus->dhd); |
| 5152 | if (ret != 0) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5153 | if (ret == BCME_NOTUP) { |
| 5154 | DHD_ERROR(("%s: dongle is not responding\n", __func__)); |
| 5155 | goto fail; |
| 5156 | } |
| 5157 | } |
| 5158 | /* Ok, have the per-port tell the stack we're open for business */ |
| 5159 | if (dhd_net_attach(bus->dhd, 0) != 0) { |
| 5160 | DHD_ERROR(("%s: Net attach failed!!\n", __func__)); |
| 5161 | goto fail; |
| 5162 | } |
| 5163 | |
| 5164 | return bus; |
| 5165 | |
| 5166 | fail: |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 5167 | dhdsdio_release(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5168 | return NULL; |
| 5169 | } |
| 5170 | |
| 5171 | static bool |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 5172 | 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] | 5173 | { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 5174 | u8 clkctl = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5175 | int err = 0; |
| 5176 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5177 | bus->alp_only = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5178 | |
| 5179 | /* Return the window to backplane enumeration space for core access */ |
| 5180 | if (dhdsdio_set_siaddr_window(bus, SI_ENUM_BASE)) |
| 5181 | DHD_ERROR(("%s: FAILED to return to SI_ENUM_BASE\n", __func__)); |
| 5182 | |
| 5183 | #ifdef DHD_DEBUG |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 5184 | printk(KERN_DEBUG "F1 signature read @0x18000000=0x%4x\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5185 | bcmsdh_reg_read(bus->sdh, SI_ENUM_BASE, 4)); |
| 5186 | |
| 5187 | #endif /* DHD_DEBUG */ |
| 5188 | |
| 5189 | /* Force PLL off until si_attach() programs PLL control regs */ |
| 5190 | |
| 5191 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 5192 | DHD_INIT_CLKCTL1, &err); |
| 5193 | if (!err) |
| 5194 | clkctl = |
| 5195 | bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 5196 | &err); |
| 5197 | |
| 5198 | if (err || ((clkctl & ~SBSDIO_AVBITS) != DHD_INIT_CLKCTL1)) { |
| 5199 | DHD_ERROR(("dhdsdio_probe: ChipClkCSR access: err %d wrote " |
| 5200 | "0x%02x read 0x%02x\n", |
| 5201 | err, DHD_INIT_CLKCTL1, clkctl)); |
| 5202 | goto fail; |
| 5203 | } |
| 5204 | #ifdef DHD_DEBUG |
| 5205 | if (DHD_INFO_ON()) { |
| 5206 | uint fn, numfn; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 5207 | u8 *cis[SDIOD_MAX_IOFUNCS]; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5208 | int err = 0; |
| 5209 | |
| 5210 | numfn = bcmsdh_query_iofnum(sdh); |
| 5211 | ASSERT(numfn <= SDIOD_MAX_IOFUNCS); |
| 5212 | |
| 5213 | /* Make sure ALP is available before trying to read CIS */ |
| 5214 | SPINWAIT(((clkctl = bcmsdh_cfg_read(sdh, SDIO_FUNC_1, |
| 5215 | SBSDIO_FUNC1_CHIPCLKCSR, |
| 5216 | NULL)), |
| 5217 | !SBSDIO_ALPAV(clkctl)), PMU_MAX_TRANSITION_DLY); |
| 5218 | |
| 5219 | /* Now request ALP be put on the bus */ |
| 5220 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 5221 | DHD_INIT_CLKCTL2, &err); |
mike.rapoport@gmail.com | 7383141 | 2010-10-13 00:09:07 +0200 | [diff] [blame] | 5222 | udelay(65); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5223 | |
| 5224 | for (fn = 0; fn <= numfn; fn++) { |
Alexander Beregalov | 12d0eb4 | 2011-03-09 03:53:35 +0300 | [diff] [blame] | 5225 | cis[fn] = kzalloc(SBSDIO_CIS_SIZE_LIMIT, GFP_ATOMIC); |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5226 | if (!cis[fn]) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5227 | DHD_INFO(("dhdsdio_probe: fn %d cis malloc " |
| 5228 | "failed\n", fn)); |
| 5229 | break; |
| 5230 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5231 | |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5232 | err = bcmsdh_cis_read(sdh, fn, cis[fn], |
| 5233 | SBSDIO_CIS_SIZE_LIMIT); |
| 5234 | if (err) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5235 | DHD_INFO(("dhdsdio_probe: fn %d cis read " |
| 5236 | "err %d\n", fn, err)); |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 5237 | kfree(cis[fn]); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5238 | break; |
| 5239 | } |
| 5240 | dhd_dump_cis(fn, cis[fn]); |
| 5241 | } |
| 5242 | |
| 5243 | while (fn-- > 0) { |
| 5244 | ASSERT(cis[fn]); |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 5245 | kfree(cis[fn]); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5246 | } |
| 5247 | |
| 5248 | if (err) { |
| 5249 | DHD_ERROR(("dhdsdio_probe: error read/parsing CIS\n")); |
| 5250 | goto fail; |
| 5251 | } |
| 5252 | } |
| 5253 | #endif /* DHD_DEBUG */ |
| 5254 | |
| 5255 | /* si_attach() will provide an SI handle and scan the backplane */ |
Arend van Spriel | 26bcc18 | 2011-03-01 10:56:55 +0100 | [diff] [blame] | 5256 | bus->sih = si_attach((uint) devid, regsva, DHD_BUS, sdh, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5257 | &bus->vars, &bus->varsz); |
| 5258 | if (!(bus->sih)) { |
| 5259 | DHD_ERROR(("%s: si_attach failed!\n", __func__)); |
| 5260 | goto fail; |
| 5261 | } |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 5262 | if (dhdsdio_chip_attach(bus, regsva)) { |
| 5263 | DHD_ERROR(("%s: dhdsdio_chip_attach failed!\n", __func__)); |
| 5264 | goto fail; |
| 5265 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5266 | |
| 5267 | bcmsdh_chipinfo(sdh, bus->sih->chip, bus->sih->chiprev); |
| 5268 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 5269 | if (!dhdsdio_chipmatch((u16) bus->sih->chip)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5270 | DHD_ERROR(("%s: unsupported chip: 0x%04x\n", |
| 5271 | __func__, bus->sih->chip)); |
| 5272 | goto fail; |
| 5273 | } |
| 5274 | |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame^] | 5275 | dhdsdio_sdiod_drive_strength_init(bus, dhd_sdiod_drive_strength); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5276 | |
| 5277 | /* Get info on the ARM and SOCRAM cores... */ |
| 5278 | if (!DHD_NOPMU(bus)) { |
| 5279 | if ((si_setcore(bus->sih, ARM7S_CORE_ID, 0)) || |
| 5280 | (si_setcore(bus->sih, ARMCM3_CORE_ID, 0))) { |
| 5281 | bus->armrev = si_corerev(bus->sih); |
| 5282 | } else { |
| 5283 | DHD_ERROR(("%s: failed to find ARM core!\n", __func__)); |
| 5284 | goto fail; |
| 5285 | } |
| 5286 | bus->orig_ramsize = si_socram_size(bus->sih); |
| 5287 | if (!(bus->orig_ramsize)) { |
| 5288 | DHD_ERROR(("%s: failed to find SOCRAM memory!\n", |
| 5289 | __func__)); |
| 5290 | goto fail; |
| 5291 | } |
| 5292 | bus->ramsize = bus->orig_ramsize; |
| 5293 | if (dhd_dongle_memsize) |
| 5294 | dhd_dongle_setmemsize(bus, dhd_dongle_memsize); |
| 5295 | |
| 5296 | DHD_ERROR(("DHD: dongle ram size is set to %d(orig %d)\n", |
| 5297 | bus->ramsize, bus->orig_ramsize)); |
| 5298 | } |
| 5299 | |
| 5300 | /* ...but normally deal with the SDPCMDEV core */ |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5301 | bus->regs = si_setcore(bus->sih, PCMCIA_CORE_ID, 0); |
| 5302 | if (!bus->regs) { |
| 5303 | bus->regs = si_setcore(bus->sih, SDIOD_CORE_ID, 0); |
| 5304 | if (!bus->regs) { |
| 5305 | DHD_ERROR(("%s: failed to find SDIODEV core!\n", |
| 5306 | __func__)); |
| 5307 | goto fail; |
| 5308 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5309 | } |
| 5310 | bus->sdpcmrev = si_corerev(bus->sih); |
| 5311 | |
| 5312 | /* Set core control so an SDIO reset does a backplane reset */ |
Arend van Spriel | ff31c54 | 2011-03-01 10:56:54 +0100 | [diff] [blame] | 5313 | OR_REG(&bus->regs->corecontrol, CC_BPRESEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5314 | |
Grant Grundler | 26a71a4 | 2011-03-09 10:41:25 -0800 | [diff] [blame] | 5315 | pktq_init(&bus->txq, (PRIOMASK + 1), TXQLEN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5316 | |
| 5317 | /* Locate an appropriately-aligned portion of hdrbuf */ |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 5318 | bus->rxhdr = (u8 *) roundup((unsigned long)&bus->hdrbuf[0], DHD_SDALIGN); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5319 | |
| 5320 | /* Set the poll and/or interrupt flags */ |
| 5321 | bus->intr = (bool) dhd_intr; |
Jason Cooper | 9b89032 | 2010-09-30 15:15:39 -0400 | [diff] [blame] | 5322 | bus->poll = (bool) dhd_poll; |
| 5323 | if (bus->poll) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5324 | bus->pollrate = 1; |
| 5325 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5326 | return true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5327 | |
| 5328 | fail: |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5329 | return false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5330 | } |
| 5331 | |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 5332 | static bool dhdsdio_probe_malloc(dhd_bus_t *bus, void *sdh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5333 | { |
| 5334 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5335 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5336 | if (bus->dhd->maxctl) { |
| 5337 | bus->rxblen = |
Greg Kroah-Hartman | e18d531 | 2010-10-08 11:59:06 -0700 | [diff] [blame] | 5338 | roundup((bus->dhd->maxctl + SDPCM_HDRLEN), |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5339 | ALIGNMENT) + DHD_SDALIGN; |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5340 | bus->rxbuf = kmalloc(bus->rxblen, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5341 | if (!(bus->rxbuf)) { |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5342 | DHD_ERROR(("%s: kmalloc of %d-byte rxbuf failed\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5343 | __func__, bus->rxblen)); |
| 5344 | goto fail; |
| 5345 | } |
| 5346 | } |
| 5347 | |
| 5348 | /* Allocate buffer to receive glomed packet */ |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5349 | bus->databuf = kmalloc(MAX_DATA_BUF, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5350 | if (!(bus->databuf)) { |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5351 | DHD_ERROR(("%s: kmalloc of %d-byte databuf failed\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5352 | __func__, MAX_DATA_BUF)); |
| 5353 | /* release rxbuf which was already located as above */ |
| 5354 | if (!bus->rxblen) |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 5355 | kfree(bus->rxbuf); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5356 | goto fail; |
| 5357 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5358 | |
| 5359 | /* Align the buffer */ |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 5360 | if ((unsigned long)bus->databuf % DHD_SDALIGN) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5361 | bus->dataptr = |
| 5362 | bus->databuf + (DHD_SDALIGN - |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 5363 | ((unsigned long)bus->databuf % DHD_SDALIGN)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5364 | else |
| 5365 | bus->dataptr = bus->databuf; |
| 5366 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5367 | return true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5368 | |
| 5369 | fail: |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5370 | return false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5371 | } |
| 5372 | |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 5373 | static bool dhdsdio_probe_init(dhd_bus_t *bus, void *sdh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5374 | { |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 5375 | s32 fnum; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5376 | |
| 5377 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5378 | |
| 5379 | #ifdef SDTEST |
| 5380 | dhdsdio_pktgen_init(bus); |
| 5381 | #endif /* SDTEST */ |
| 5382 | |
| 5383 | /* Disable F2 to clear any intermediate frame state on the dongle */ |
| 5384 | bcmsdh_cfg_write(sdh, SDIO_FUNC_0, SDIOD_CCCR_IOEN, SDIO_FUNC_ENABLE_1, |
| 5385 | NULL); |
| 5386 | |
| 5387 | bus->dhd->busstate = DHD_BUS_DOWN; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5388 | bus->sleeping = false; |
| 5389 | bus->rxflow = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5390 | bus->prev_rxlim_hit = 0; |
| 5391 | |
| 5392 | /* Done with backplane-dependent accesses, can drop clock... */ |
| 5393 | bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, 0, NULL); |
| 5394 | |
| 5395 | /* ...and initialize clock/power states */ |
| 5396 | bus->clkstate = CLK_SDONLY; |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 5397 | bus->idletime = (s32) dhd_idletime; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5398 | bus->idleclock = DHD_IDLE_ACTIVE; |
| 5399 | |
| 5400 | /* Query the SD clock speed */ |
| 5401 | if (bcmsdh_iovar_op(sdh, "sd_divisor", NULL, 0, |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 5402 | &bus->sd_divisor, sizeof(s32), |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 5403 | false) != 0) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5404 | DHD_ERROR(("%s: fail on %s get\n", __func__, "sd_divisor")); |
| 5405 | bus->sd_divisor = -1; |
| 5406 | } else { |
| 5407 | DHD_INFO(("%s: Initial value for %s is %d\n", |
| 5408 | __func__, "sd_divisor", bus->sd_divisor)); |
| 5409 | } |
| 5410 | |
| 5411 | /* Query the SD bus mode */ |
| 5412 | if (bcmsdh_iovar_op(sdh, "sd_mode", NULL, 0, |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 5413 | &bus->sd_mode, sizeof(s32), false) != 0) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5414 | DHD_ERROR(("%s: fail on %s get\n", __func__, "sd_mode")); |
| 5415 | bus->sd_mode = -1; |
| 5416 | } else { |
| 5417 | DHD_INFO(("%s: Initial value for %s is %d\n", |
| 5418 | __func__, "sd_mode", bus->sd_mode)); |
| 5419 | } |
| 5420 | |
| 5421 | /* Query the F2 block size, set roundup accordingly */ |
| 5422 | fnum = 2; |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 5423 | if (bcmsdh_iovar_op(sdh, "sd_blocksize", &fnum, sizeof(s32), |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 5424 | &bus->blocksize, sizeof(s32), false) != 0) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5425 | bus->blocksize = 0; |
| 5426 | DHD_ERROR(("%s: fail on %s get\n", __func__, "sd_blocksize")); |
| 5427 | } else { |
| 5428 | DHD_INFO(("%s: Initial value for %s is %d\n", |
| 5429 | __func__, "sd_blocksize", bus->blocksize)); |
| 5430 | } |
Greg Kroah-Hartman | 7068c2f | 2010-10-08 11:34:59 -0700 | [diff] [blame] | 5431 | bus->roundup = min(max_roundup, bus->blocksize); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5432 | |
| 5433 | /* Query if bus module supports packet chaining, |
| 5434 | default to use if supported */ |
| 5435 | if (bcmsdh_iovar_op(sdh, "sd_rxchain", NULL, 0, |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 5436 | &bus->sd_rxchain, sizeof(s32), |
Roland Vossen | a1c5ad8 | 2011-04-11 15:16:24 +0200 | [diff] [blame] | 5437 | false) != 0) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5438 | bus->sd_rxchain = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5439 | } else { |
| 5440 | DHD_INFO(("%s: bus module (through bcmsdh API) %s chaining\n", |
| 5441 | __func__, |
| 5442 | (bus->sd_rxchain ? "supports" : "does not support"))); |
| 5443 | } |
| 5444 | bus->use_rxchain = (bool) bus->sd_rxchain; |
| 5445 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5446 | return true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5447 | } |
| 5448 | |
| 5449 | bool |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 5450 | 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] | 5451 | { |
| 5452 | bool ret; |
| 5453 | bus->fw_path = fw_path; |
| 5454 | bus->nv_path = nv_path; |
| 5455 | |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 5456 | ret = dhdsdio_download_firmware(bus, bus->sdh); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5457 | |
| 5458 | return ret; |
| 5459 | } |
| 5460 | |
| 5461 | static bool |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 5462 | dhdsdio_download_firmware(struct dhd_bus *bus, void *sdh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5463 | { |
| 5464 | bool ret; |
| 5465 | |
| 5466 | /* Download the firmware */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5467 | dhdsdio_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5468 | |
| 5469 | ret = _dhdsdio_download_firmware(bus) == 0; |
| 5470 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5471 | dhdsdio_clkctl(bus, CLK_SDONLY, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5472 | |
| 5473 | return ret; |
| 5474 | } |
| 5475 | |
| 5476 | /* Detach and free everything */ |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 5477 | static void dhdsdio_release(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5478 | { |
| 5479 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5480 | |
| 5481 | if (bus) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5482 | /* De-register interrupt handler */ |
| 5483 | bcmsdh_intr_disable(bus->sdh); |
| 5484 | bcmsdh_intr_dereg(bus->sdh); |
| 5485 | |
| 5486 | if (bus->dhd) { |
| 5487 | |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 5488 | dhdsdio_release_dongle(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5489 | |
| 5490 | dhd_detach(bus->dhd); |
| 5491 | bus->dhd = NULL; |
| 5492 | } |
| 5493 | |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 5494 | dhdsdio_release_malloc(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5495 | |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 5496 | kfree(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5497 | } |
| 5498 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5499 | DHD_TRACE(("%s: Disconnected\n", __func__)); |
| 5500 | } |
| 5501 | |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 5502 | static void dhdsdio_release_malloc(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5503 | { |
| 5504 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5505 | |
| 5506 | if (bus->dhd && bus->dhd->dongle_reset) |
| 5507 | return; |
| 5508 | |
| 5509 | if (bus->rxbuf) { |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 5510 | kfree(bus->rxbuf); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5511 | bus->rxctl = bus->rxbuf = NULL; |
| 5512 | bus->rxlen = 0; |
| 5513 | } |
| 5514 | |
Ilia Mirkin | 46d994b | 2011-03-13 00:28:56 -0500 | [diff] [blame] | 5515 | kfree(bus->databuf); |
| 5516 | bus->databuf = NULL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5517 | } |
| 5518 | |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 5519 | static void dhdsdio_release_dongle(dhd_bus_t *bus) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5520 | { |
| 5521 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5522 | |
| 5523 | if (bus->dhd && bus->dhd->dongle_reset) |
| 5524 | return; |
| 5525 | |
| 5526 | if (bus->sih) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5527 | dhdsdio_clkctl(bus, CLK_AVAIL, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5528 | #if !defined(BCMLXSDMMC) |
| 5529 | si_watchdog(bus->sih, 4); |
| 5530 | #endif /* !defined(BCMLXSDMMC) */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5531 | dhdsdio_clkctl(bus, CLK_NONE, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5532 | si_detach(bus->sih); |
| 5533 | if (bus->vars && bus->varsz) |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 5534 | kfree(bus->vars); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5535 | bus->vars = NULL; |
| 5536 | } |
| 5537 | |
| 5538 | DHD_TRACE(("%s: Disconnected\n", __func__)); |
| 5539 | } |
| 5540 | |
| 5541 | static void dhdsdio_disconnect(void *ptr) |
| 5542 | { |
| 5543 | dhd_bus_t *bus = (dhd_bus_t *)ptr; |
| 5544 | |
| 5545 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5546 | |
| 5547 | if (bus) { |
| 5548 | ASSERT(bus->dhd); |
Arend van Spriel | 3c9d4c3 | 2011-03-02 21:18:48 +0100 | [diff] [blame] | 5549 | dhdsdio_release(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5550 | } |
| 5551 | |
| 5552 | DHD_TRACE(("%s: Disconnected\n", __func__)); |
| 5553 | } |
| 5554 | |
| 5555 | /* Register/Unregister functions are called by the main DHD entry |
| 5556 | * point (e.g. module insertion) to link with the bus driver, in |
| 5557 | * order to look for or await the device. |
| 5558 | */ |
| 5559 | |
| 5560 | static bcmsdh_driver_t dhd_sdio = { |
| 5561 | dhdsdio_probe, |
| 5562 | dhdsdio_disconnect |
| 5563 | }; |
| 5564 | |
| 5565 | int dhd_bus_register(void) |
| 5566 | { |
| 5567 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5568 | |
| 5569 | return bcmsdh_register(&dhd_sdio); |
| 5570 | } |
| 5571 | |
| 5572 | void dhd_bus_unregister(void) |
| 5573 | { |
| 5574 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 5575 | |
| 5576 | bcmsdh_unregister(); |
| 5577 | } |
| 5578 | |
| 5579 | #ifdef BCMEMBEDIMAGE |
| 5580 | static int dhdsdio_download_code_array(struct dhd_bus *bus) |
| 5581 | { |
| 5582 | int bcmerror = -1; |
| 5583 | int offset = 0; |
| 5584 | |
| 5585 | DHD_INFO(("%s: download embedded firmware...\n", __func__)); |
| 5586 | |
| 5587 | /* Download image */ |
| 5588 | while ((offset + MEMBLOCK) < sizeof(dlarray)) { |
| 5589 | bcmerror = |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5590 | dhdsdio_membytes(bus, true, offset, dlarray + offset, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5591 | MEMBLOCK); |
| 5592 | if (bcmerror) { |
| 5593 | DHD_ERROR(("%s: error %d on writing %d membytes at " |
| 5594 | "0x%08x\n", |
| 5595 | __func__, bcmerror, MEMBLOCK, offset)); |
| 5596 | goto err; |
| 5597 | } |
| 5598 | |
| 5599 | offset += MEMBLOCK; |
| 5600 | } |
| 5601 | |
| 5602 | if (offset < sizeof(dlarray)) { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5603 | bcmerror = dhdsdio_membytes(bus, true, offset, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5604 | dlarray + offset, |
| 5605 | sizeof(dlarray) - offset); |
| 5606 | if (bcmerror) { |
| 5607 | DHD_ERROR(("%s: error %d on writing %d membytes at " |
| 5608 | "0x%08x\n", __func__, bcmerror, |
| 5609 | sizeof(dlarray) - offset, offset)); |
| 5610 | goto err; |
| 5611 | } |
| 5612 | } |
| 5613 | #ifdef DHD_DEBUG |
| 5614 | /* Upload and compare the downloaded code */ |
| 5615 | { |
| 5616 | unsigned char *ularray; |
| 5617 | |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5618 | ularray = kmalloc(bus->ramsize, GFP_ATOMIC); |
Alexander Beregalov | 570edd3 | 2011-03-13 21:58:47 +0300 | [diff] [blame] | 5619 | if (!ularray) { |
| 5620 | bcmerror = BCME_NOMEM; |
| 5621 | goto err; |
| 5622 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5623 | /* Upload image to verify downloaded contents. */ |
| 5624 | offset = 0; |
| 5625 | memset(ularray, 0xaa, bus->ramsize); |
| 5626 | while ((offset + MEMBLOCK) < sizeof(dlarray)) { |
| 5627 | bcmerror = |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5628 | dhdsdio_membytes(bus, false, offset, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5629 | ularray + offset, MEMBLOCK); |
| 5630 | if (bcmerror) { |
| 5631 | DHD_ERROR(("%s: error %d on reading %d membytes" |
| 5632 | " at 0x%08x\n", |
| 5633 | __func__, bcmerror, MEMBLOCK, offset)); |
Alexander Beregalov | 570edd3 | 2011-03-13 21:58:47 +0300 | [diff] [blame] | 5634 | goto free; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5635 | } |
| 5636 | |
| 5637 | offset += MEMBLOCK; |
| 5638 | } |
| 5639 | |
| 5640 | if (offset < sizeof(dlarray)) { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5641 | bcmerror = dhdsdio_membytes(bus, false, offset, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5642 | ularray + offset, |
| 5643 | sizeof(dlarray) - offset); |
| 5644 | if (bcmerror) { |
| 5645 | DHD_ERROR(("%s: error %d on reading %d membytes at 0x%08x\n", |
| 5646 | __func__, bcmerror, |
| 5647 | sizeof(dlarray) - offset, offset)); |
Alexander Beregalov | 570edd3 | 2011-03-13 21:58:47 +0300 | [diff] [blame] | 5648 | goto free; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5649 | } |
| 5650 | } |
| 5651 | |
| 5652 | if (memcmp(dlarray, ularray, sizeof(dlarray))) { |
| 5653 | DHD_ERROR(("%s: Downloaded image is corrupted.\n", |
| 5654 | __func__)); |
| 5655 | ASSERT(0); |
Alexander Beregalov | 570edd3 | 2011-03-13 21:58:47 +0300 | [diff] [blame] | 5656 | goto free; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5657 | } else |
| 5658 | DHD_ERROR(("%s: Download/Upload/Compare succeeded.\n", |
| 5659 | __func__)); |
Alexander Beregalov | 570edd3 | 2011-03-13 21:58:47 +0300 | [diff] [blame] | 5660 | free: |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 5661 | kfree(ularray); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5662 | } |
| 5663 | #endif /* DHD_DEBUG */ |
| 5664 | |
| 5665 | err: |
| 5666 | return bcmerror; |
| 5667 | } |
| 5668 | #endif /* BCMEMBEDIMAGE */ |
| 5669 | |
| 5670 | static int dhdsdio_download_code_file(struct dhd_bus *bus, char *fw_path) |
| 5671 | { |
| 5672 | int bcmerror = -1; |
| 5673 | int offset = 0; |
| 5674 | uint len; |
| 5675 | void *image = NULL; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 5676 | u8 *memblock = NULL, *memptr; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5677 | |
| 5678 | DHD_INFO(("%s: download firmware %s\n", __func__, fw_path)); |
| 5679 | |
| 5680 | image = dhd_os_open_image(fw_path); |
| 5681 | if (image == NULL) |
| 5682 | goto err; |
| 5683 | |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5684 | memptr = memblock = kmalloc(MEMBLOCK + DHD_SDALIGN, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5685 | if (memblock == NULL) { |
| 5686 | DHD_ERROR(("%s: Failed to allocate memory %d bytes\n", |
| 5687 | __func__, MEMBLOCK)); |
| 5688 | goto err; |
| 5689 | } |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 5690 | if ((u32)(unsigned long)memblock % DHD_SDALIGN) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5691 | memptr += |
Greg Kroah-Hartman | f024c48 | 2010-10-21 10:50:21 -0700 | [diff] [blame] | 5692 | (DHD_SDALIGN - ((u32)(unsigned long)memblock % DHD_SDALIGN)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5693 | |
| 5694 | /* Download image */ |
| 5695 | while ((len = |
| 5696 | dhd_os_get_image_block((char *)memptr, MEMBLOCK, image))) { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5697 | bcmerror = dhdsdio_membytes(bus, true, offset, memptr, len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5698 | if (bcmerror) { |
| 5699 | DHD_ERROR(("%s: error %d on writing %d membytes at " |
| 5700 | "0x%08x\n", __func__, bcmerror, MEMBLOCK, offset)); |
| 5701 | goto err; |
| 5702 | } |
| 5703 | |
| 5704 | offset += MEMBLOCK; |
| 5705 | } |
| 5706 | |
| 5707 | err: |
Ilia Mirkin | 46d994b | 2011-03-13 00:28:56 -0500 | [diff] [blame] | 5708 | kfree(memblock); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5709 | |
| 5710 | if (image) |
| 5711 | dhd_os_close_image(image); |
| 5712 | |
| 5713 | return bcmerror; |
| 5714 | } |
| 5715 | |
| 5716 | /* |
| 5717 | * ProcessVars:Takes a buffer of "<var>=<value>\n" lines read from a file |
| 5718 | * and ending in a NUL. |
| 5719 | * Removes carriage returns, empty lines, comment lines, and converts |
| 5720 | * newlines to NULs. |
| 5721 | * Shortens buffer as needed and pads with NULs. End of buffer is marked |
| 5722 | * by two NULs. |
| 5723 | */ |
| 5724 | |
| 5725 | static uint process_nvram_vars(char *varbuf, uint len) |
| 5726 | { |
| 5727 | char *dp; |
| 5728 | bool findNewline; |
| 5729 | int column; |
| 5730 | uint buf_len, n; |
| 5731 | |
| 5732 | dp = varbuf; |
| 5733 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5734 | findNewline = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5735 | column = 0; |
| 5736 | |
| 5737 | for (n = 0; n < len; n++) { |
| 5738 | if (varbuf[n] == 0) |
| 5739 | break; |
| 5740 | if (varbuf[n] == '\r') |
| 5741 | continue; |
| 5742 | if (findNewline && varbuf[n] != '\n') |
| 5743 | continue; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5744 | findNewline = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5745 | if (varbuf[n] == '#') { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5746 | findNewline = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5747 | continue; |
| 5748 | } |
| 5749 | if (varbuf[n] == '\n') { |
| 5750 | if (column == 0) |
| 5751 | continue; |
| 5752 | *dp++ = 0; |
| 5753 | column = 0; |
| 5754 | continue; |
| 5755 | } |
| 5756 | *dp++ = varbuf[n]; |
| 5757 | column++; |
| 5758 | } |
| 5759 | buf_len = dp - varbuf; |
| 5760 | |
| 5761 | while (dp < varbuf + n) |
| 5762 | *dp++ = 0; |
| 5763 | |
| 5764 | return buf_len; |
| 5765 | } |
| 5766 | |
| 5767 | /* |
| 5768 | EXAMPLE: nvram_array |
| 5769 | nvram_arry format: |
| 5770 | name=value |
| 5771 | Use carriage return at the end of each assignment, |
| 5772 | and an empty string with |
| 5773 | carriage return at the end of array. |
| 5774 | |
| 5775 | For example: |
| 5776 | unsigned char nvram_array[] = {"name1=value1\n", |
| 5777 | "name2=value2\n", "\n"}; |
| 5778 | Hex values start with 0x, and mac addr format: xx:xx:xx:xx:xx:xx. |
| 5779 | |
| 5780 | Search "EXAMPLE: nvram_array" to see how the array is activated. |
| 5781 | */ |
| 5782 | |
| 5783 | void dhd_bus_set_nvram_params(struct dhd_bus *bus, const char *nvram_params) |
| 5784 | { |
| 5785 | bus->nvram_params = nvram_params; |
| 5786 | } |
| 5787 | |
| 5788 | static int dhdsdio_download_nvram(struct dhd_bus *bus) |
| 5789 | { |
| 5790 | int bcmerror = -1; |
| 5791 | uint len; |
| 5792 | void *image = NULL; |
| 5793 | char *memblock = NULL; |
| 5794 | char *bufp; |
| 5795 | char *nv_path; |
| 5796 | bool nvram_file_exists; |
| 5797 | |
| 5798 | nv_path = bus->nv_path; |
| 5799 | |
| 5800 | nvram_file_exists = ((nv_path != NULL) && (nv_path[0] != '\0')); |
| 5801 | if (!nvram_file_exists && (bus->nvram_params == NULL)) |
| 5802 | return 0; |
| 5803 | |
| 5804 | if (nvram_file_exists) { |
| 5805 | image = dhd_os_open_image(nv_path); |
| 5806 | if (image == NULL) |
| 5807 | goto err; |
| 5808 | } |
| 5809 | |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame] | 5810 | memblock = kmalloc(MEMBLOCK, GFP_ATOMIC); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5811 | if (memblock == NULL) { |
| 5812 | DHD_ERROR(("%s: Failed to allocate memory %d bytes\n", |
| 5813 | __func__, MEMBLOCK)); |
| 5814 | goto err; |
| 5815 | } |
| 5816 | |
| 5817 | /* Download variables */ |
| 5818 | if (nvram_file_exists) { |
| 5819 | len = dhd_os_get_image_block(memblock, MEMBLOCK, image); |
| 5820 | } else { |
| 5821 | len = strlen(bus->nvram_params); |
| 5822 | ASSERT(len <= MEMBLOCK); |
| 5823 | if (len > MEMBLOCK) |
| 5824 | len = MEMBLOCK; |
| 5825 | memcpy(memblock, bus->nvram_params, len); |
| 5826 | } |
| 5827 | |
| 5828 | if (len > 0 && len < MEMBLOCK) { |
| 5829 | bufp = (char *)memblock; |
| 5830 | bufp[len] = 0; |
| 5831 | len = process_nvram_vars(bufp, len); |
| 5832 | bufp += len; |
| 5833 | *bufp++ = 0; |
| 5834 | if (len) |
| 5835 | bcmerror = dhdsdio_downloadvars(bus, memblock, len + 1); |
| 5836 | if (bcmerror) { |
| 5837 | DHD_ERROR(("%s: error downloading vars: %d\n", |
| 5838 | __func__, bcmerror)); |
| 5839 | } |
| 5840 | } else { |
| 5841 | DHD_ERROR(("%s: error reading nvram file: %d\n", |
| 5842 | __func__, len)); |
| 5843 | bcmerror = BCME_SDIO_ERROR; |
| 5844 | } |
| 5845 | |
| 5846 | err: |
Ilia Mirkin | 46d994b | 2011-03-13 00:28:56 -0500 | [diff] [blame] | 5847 | kfree(memblock); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5848 | |
| 5849 | if (image) |
| 5850 | dhd_os_close_image(image); |
| 5851 | |
| 5852 | return bcmerror; |
| 5853 | } |
| 5854 | |
| 5855 | static int _dhdsdio_download_firmware(struct dhd_bus *bus) |
| 5856 | { |
| 5857 | int bcmerror = -1; |
| 5858 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5859 | bool embed = false; /* download embedded firmware */ |
| 5860 | bool dlok = false; /* download firmware succeeded */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5861 | |
| 5862 | /* Out immediately if no image to download */ |
| 5863 | if ((bus->fw_path == NULL) || (bus->fw_path[0] == '\0')) { |
| 5864 | #ifdef BCMEMBEDIMAGE |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5865 | embed = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5866 | #else |
| 5867 | return bcmerror; |
| 5868 | #endif |
| 5869 | } |
| 5870 | |
| 5871 | /* Keep arm in reset */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5872 | if (dhdsdio_download_state(bus, true)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5873 | DHD_ERROR(("%s: error placing ARM core in reset\n", __func__)); |
| 5874 | goto err; |
| 5875 | } |
| 5876 | |
| 5877 | /* External image takes precedence if specified */ |
| 5878 | if ((bus->fw_path != NULL) && (bus->fw_path[0] != '\0')) { |
| 5879 | if (dhdsdio_download_code_file(bus, bus->fw_path)) { |
| 5880 | DHD_ERROR(("%s: dongle image file download failed\n", |
| 5881 | __func__)); |
| 5882 | #ifdef BCMEMBEDIMAGE |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5883 | embed = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5884 | #else |
| 5885 | goto err; |
| 5886 | #endif |
| 5887 | } else { |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5888 | embed = false; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5889 | dlok = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5890 | } |
| 5891 | } |
| 5892 | #ifdef BCMEMBEDIMAGE |
| 5893 | if (embed) { |
| 5894 | if (dhdsdio_download_code_array(bus)) { |
| 5895 | DHD_ERROR(("%s: dongle image array download failed\n", |
| 5896 | __func__)); |
| 5897 | goto err; |
| 5898 | } else { |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5899 | dlok = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5900 | } |
| 5901 | } |
| 5902 | #endif |
| 5903 | if (!dlok) { |
| 5904 | DHD_ERROR(("%s: dongle image download failed\n", __func__)); |
| 5905 | goto err; |
| 5906 | } |
| 5907 | |
| 5908 | /* EXAMPLE: nvram_array */ |
| 5909 | /* If a valid nvram_arry is specified as above, it can be passed |
| 5910 | down to dongle */ |
| 5911 | /* dhd_bus_set_nvram_params(bus, (char *)&nvram_array); */ |
| 5912 | |
| 5913 | /* External nvram takes precedence if specified */ |
| 5914 | if (dhdsdio_download_nvram(bus)) { |
| 5915 | DHD_ERROR(("%s: dongle nvram file download failed\n", |
| 5916 | __func__)); |
| 5917 | } |
| 5918 | |
| 5919 | /* Take arm out of reset */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5920 | if (dhdsdio_download_state(bus, false)) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5921 | DHD_ERROR(("%s: error getting out of ARM core reset\n", |
| 5922 | __func__)); |
| 5923 | goto err; |
| 5924 | } |
| 5925 | |
| 5926 | bcmerror = 0; |
| 5927 | |
| 5928 | err: |
| 5929 | return bcmerror; |
| 5930 | } |
| 5931 | |
| 5932 | static int |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 5933 | 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] | 5934 | u8 *buf, uint nbytes, struct sk_buff *pkt, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5935 | bcmsdh_cmplt_fn_t complete, void *handle) |
| 5936 | { |
| 5937 | int status; |
| 5938 | |
| 5939 | /* 4329: GSPI check */ |
| 5940 | status = |
| 5941 | bcmsdh_recv_buf(bus->sdh, addr, fn, flags, buf, nbytes, pkt, |
| 5942 | complete, handle); |
| 5943 | return status; |
| 5944 | } |
| 5945 | |
| 5946 | static int |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 5947 | 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] | 5948 | u8 *buf, uint nbytes, struct sk_buff *pkt, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5949 | bcmsdh_cmplt_fn_t complete, void *handle) |
| 5950 | { |
| 5951 | return bcmsdh_send_buf |
| 5952 | (bus->sdh, addr, fn, flags, buf, nbytes, pkt, complete, |
| 5953 | handle); |
| 5954 | } |
| 5955 | |
| 5956 | uint dhd_bus_chip(struct dhd_bus *bus) |
| 5957 | { |
| 5958 | ASSERT(bus->sih != NULL); |
| 5959 | return bus->sih->chip; |
| 5960 | } |
| 5961 | |
| 5962 | void *dhd_bus_pub(struct dhd_bus *bus) |
| 5963 | { |
| 5964 | return bus->dhd; |
| 5965 | } |
| 5966 | |
| 5967 | void *dhd_bus_txq(struct dhd_bus *bus) |
| 5968 | { |
| 5969 | return &bus->txq; |
| 5970 | } |
| 5971 | |
| 5972 | uint dhd_bus_hdrlen(struct dhd_bus *bus) |
| 5973 | { |
| 5974 | return SDPCM_HDRLEN; |
| 5975 | } |
| 5976 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 5977 | int dhd_bus_devreset(dhd_pub_t *dhdp, u8 flag) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5978 | { |
| 5979 | int bcmerror = 0; |
| 5980 | dhd_bus_t *bus; |
| 5981 | |
| 5982 | bus = dhdp->bus; |
| 5983 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5984 | if (flag == true) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5985 | if (!bus->dhd->dongle_reset) { |
| 5986 | /* Expect app to have torn down any |
| 5987 | connection before calling */ |
| 5988 | /* Stop the bus, disable F2 */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5989 | dhd_bus_stop(bus, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5990 | |
| 5991 | /* Clean tx/rx buffer pointers, |
| 5992 | detach from the dongle */ |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 5993 | dhdsdio_release_dongle(bus); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5994 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 5995 | bus->dhd->dongle_reset = true; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 5996 | bus->dhd->up = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 5997 | |
| 5998 | DHD_TRACE(("%s: WLAN OFF DONE\n", __func__)); |
| 5999 | /* App can now remove power from device */ |
| 6000 | } else |
| 6001 | bcmerror = BCME_SDIO_ERROR; |
| 6002 | } else { |
| 6003 | /* App must have restored power to device before calling */ |
| 6004 | |
| 6005 | DHD_TRACE(("\n\n%s: == WLAN ON ==\n", __func__)); |
| 6006 | |
| 6007 | if (bus->dhd->dongle_reset) { |
| 6008 | /* Turn on WLAN */ |
| 6009 | /* Reset SD client */ |
| 6010 | bcmsdh_reset(bus->sdh); |
| 6011 | |
| 6012 | /* Attempt to re-attach & download */ |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 6013 | if (dhdsdio_probe_attach(bus, bus->sdh, |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 6014 | (u32 *) SI_ENUM_BASE, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6015 | bus->cl_devid)) { |
| 6016 | /* Attempt to download binary to the dongle */ |
| 6017 | if (dhdsdio_probe_init |
Arend van Spriel | 8da4a3a | 2011-03-02 21:18:42 +0100 | [diff] [blame] | 6018 | (bus, bus->sdh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6019 | && dhdsdio_download_firmware(bus, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6020 | bus->sdh)) { |
| 6021 | |
| 6022 | /* Re-init bus, enable F2 transfer */ |
| 6023 | dhd_bus_init((dhd_pub_t *) bus->dhd, |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 6024 | false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6025 | |
| 6026 | #if defined(OOB_INTR_ONLY) |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 6027 | dhd_enable_oob_intr(bus, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6028 | #endif /* defined(OOB_INTR_ONLY) */ |
| 6029 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 6030 | bus->dhd->dongle_reset = false; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 6031 | bus->dhd->up = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6032 | |
| 6033 | DHD_TRACE(("%s: WLAN ON DONE\n", |
| 6034 | __func__)); |
| 6035 | } else |
| 6036 | bcmerror = BCME_SDIO_ERROR; |
| 6037 | } else |
| 6038 | bcmerror = BCME_SDIO_ERROR; |
| 6039 | } else { |
| 6040 | bcmerror = BCME_NOTDOWN; |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 6041 | DHD_ERROR(("%s: Set DEVRESET=false invoked when device " |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 6042 | "is on\n", __func__)); |
| 6043 | bcmerror = BCME_SDIO_ERROR; |
| 6044 | } |
| 6045 | } |
| 6046 | return bcmerror; |
| 6047 | } |
Franky Lin | cb63e4c | 2011-04-25 15:45:08 -0700 | [diff] [blame] | 6048 | |
| 6049 | static int |
| 6050 | dhdsdio_chip_recognition(bcmsdh_info_t *sdh, struct chip_info *ci, void *regs) |
| 6051 | { |
| 6052 | u32 regdata; |
| 6053 | |
| 6054 | /* |
| 6055 | * Get CC core rev |
| 6056 | * Chipid is assume to be at offset 0 from regs arg |
| 6057 | * For different chiptypes or old sdio hosts w/o chipcommon, |
| 6058 | * other ways of recognition should be added here. |
| 6059 | */ |
| 6060 | ci->cccorebase = (u32)regs; |
| 6061 | regdata = bcmsdh_reg_read(sdh, CORE_CC_REG(ci->cccorebase, chipid), 4); |
| 6062 | ci->chip = regdata & CID_ID_MASK; |
| 6063 | ci->chiprev = (regdata & CID_REV_MASK) >> CID_REV_SHIFT; |
| 6064 | |
| 6065 | DHD_INFO(("%s: chipid=0x%x chiprev=%d\n", |
| 6066 | __func__, ci->chip, ci->chiprev)); |
| 6067 | |
| 6068 | /* Address of cores for new chips should be added here */ |
| 6069 | switch (ci->chip) { |
| 6070 | case BCM4329_CHIP_ID: |
| 6071 | ci->buscorebase = BCM4329_CORE_BUS_BASE; |
| 6072 | ci->ramcorebase = BCM4329_CORE_SOCRAM_BASE; |
| 6073 | ci->armcorebase = BCM4329_CORE_ARM_BASE; |
| 6074 | break; |
| 6075 | default: |
| 6076 | DHD_ERROR(("%s: chipid 0x%x is not supported\n", |
| 6077 | __func__, ci->chip)); |
| 6078 | return -ENODEV; |
| 6079 | } |
| 6080 | |
| 6081 | regdata = bcmsdh_reg_read(sdh, |
| 6082 | CORE_SB(ci->cccorebase, sbidhigh), 4); |
| 6083 | ci->ccrev = SBCOREREV(regdata); |
| 6084 | |
| 6085 | regdata = bcmsdh_reg_read(sdh, |
| 6086 | CORE_CC_REG(ci->cccorebase, pmucapabilities), 4); |
| 6087 | ci->pmurev = regdata & PCAP_REV_MASK; |
| 6088 | |
| 6089 | regdata = bcmsdh_reg_read(sdh, CORE_SB(ci->buscorebase, sbidhigh), 4); |
| 6090 | ci->buscorerev = SBCOREREV(regdata); |
| 6091 | ci->buscoretype = (regdata & SBIDH_CC_MASK) >> SBIDH_CC_SHIFT; |
| 6092 | |
| 6093 | DHD_INFO(("%s: ccrev=%d, pmurev=%d, buscore rev/type=%d/0x%x\n", |
| 6094 | __func__, ci->ccrev, ci->pmurev, |
| 6095 | ci->buscorerev, ci->buscoretype)); |
| 6096 | |
| 6097 | /* get chipcommon capabilites */ |
| 6098 | ci->cccaps = bcmsdh_reg_read(sdh, |
| 6099 | CORE_CC_REG(ci->cccorebase, capabilities), 4); |
| 6100 | |
| 6101 | return 0; |
| 6102 | } |
| 6103 | |
| 6104 | static void |
| 6105 | dhdsdio_chip_disablecore(bcmsdh_info_t *sdh, u32 corebase) |
| 6106 | { |
| 6107 | u32 regdata; |
| 6108 | |
| 6109 | regdata = bcmsdh_reg_read(sdh, |
| 6110 | CORE_SB(corebase, sbtmstatelow), 4); |
| 6111 | if (regdata & SBTML_RESET) |
| 6112 | return; |
| 6113 | |
| 6114 | regdata = bcmsdh_reg_read(sdh, |
| 6115 | CORE_SB(corebase, sbtmstatelow), 4); |
| 6116 | if ((regdata & (SICF_CLOCK_EN << SBTML_SICF_SHIFT)) != 0) { |
| 6117 | /* |
| 6118 | * set target reject and spin until busy is clear |
| 6119 | * (preserve core-specific bits) |
| 6120 | */ |
| 6121 | regdata = bcmsdh_reg_read(sdh, |
| 6122 | CORE_SB(corebase, sbtmstatelow), 4); |
| 6123 | bcmsdh_reg_write(sdh, CORE_SB(corebase, sbtmstatelow), 4, |
| 6124 | regdata | SBTML_REJ); |
| 6125 | |
| 6126 | regdata = bcmsdh_reg_read(sdh, |
| 6127 | CORE_SB(corebase, sbtmstatelow), 4); |
| 6128 | udelay(1); |
| 6129 | SPINWAIT((bcmsdh_reg_read(sdh, |
| 6130 | CORE_SB(corebase, sbtmstatehigh), 4) & |
| 6131 | SBTMH_BUSY), 100000); |
| 6132 | |
| 6133 | regdata = bcmsdh_reg_read(sdh, |
| 6134 | CORE_SB(corebase, sbtmstatehigh), 4); |
| 6135 | if (regdata & SBTMH_BUSY) |
| 6136 | DHD_ERROR(("%s: ARM core still busy\n", __func__)); |
| 6137 | |
| 6138 | regdata = bcmsdh_reg_read(sdh, |
| 6139 | CORE_SB(corebase, sbidlow), 4); |
| 6140 | if (regdata & SBIDL_INIT) { |
| 6141 | regdata = bcmsdh_reg_read(sdh, |
| 6142 | CORE_SB(corebase, sbimstate), 4) | |
| 6143 | SBIM_RJ; |
| 6144 | bcmsdh_reg_write(sdh, |
| 6145 | CORE_SB(corebase, sbimstate), 4, |
| 6146 | regdata); |
| 6147 | regdata = bcmsdh_reg_read(sdh, |
| 6148 | CORE_SB(corebase, sbimstate), 4); |
| 6149 | udelay(1); |
| 6150 | SPINWAIT((bcmsdh_reg_read(sdh, |
| 6151 | CORE_SB(corebase, sbimstate), 4) & |
| 6152 | SBIM_BY), 100000); |
| 6153 | } |
| 6154 | |
| 6155 | /* set reset and reject while enabling the clocks */ |
| 6156 | bcmsdh_reg_write(sdh, |
| 6157 | CORE_SB(corebase, sbtmstatelow), 4, |
| 6158 | (((SICF_FGC | SICF_CLOCK_EN) << SBTML_SICF_SHIFT) | |
| 6159 | SBTML_REJ | SBTML_RESET)); |
| 6160 | regdata = bcmsdh_reg_read(sdh, |
| 6161 | CORE_SB(corebase, sbtmstatelow), 4); |
| 6162 | udelay(10); |
| 6163 | |
| 6164 | /* clear the initiator reject bit */ |
| 6165 | regdata = bcmsdh_reg_read(sdh, |
| 6166 | CORE_SB(corebase, sbidlow), 4); |
| 6167 | if (regdata & SBIDL_INIT) { |
| 6168 | regdata = bcmsdh_reg_read(sdh, |
| 6169 | CORE_SB(corebase, sbimstate), 4) & |
| 6170 | ~SBIM_RJ; |
| 6171 | bcmsdh_reg_write(sdh, |
| 6172 | CORE_SB(corebase, sbimstate), 4, |
| 6173 | regdata); |
| 6174 | } |
| 6175 | } |
| 6176 | |
| 6177 | /* leave reset and reject asserted */ |
| 6178 | bcmsdh_reg_write(sdh, CORE_SB(corebase, sbtmstatelow), 4, |
| 6179 | (SBTML_REJ | SBTML_RESET)); |
| 6180 | udelay(1); |
| 6181 | } |
| 6182 | |
| 6183 | static int |
| 6184 | dhdsdio_chip_attach(struct dhd_bus *bus, void *regs) |
| 6185 | { |
| 6186 | struct chip_info *ci; |
| 6187 | int err; |
| 6188 | u8 clkval, clkset; |
| 6189 | |
| 6190 | DHD_TRACE(("%s: Enter\n", __func__)); |
| 6191 | |
| 6192 | /* alloc chip_info_t */ |
| 6193 | ci = kmalloc(sizeof(struct chip_info), GFP_ATOMIC); |
| 6194 | if (NULL == ci) { |
| 6195 | DHD_ERROR(("%s: malloc failed!\n", __func__)); |
| 6196 | return -ENOMEM; |
| 6197 | } |
| 6198 | |
| 6199 | memset((unsigned char *)ci, 0, sizeof(struct chip_info)); |
| 6200 | |
| 6201 | /* bus/core/clk setup for register access */ |
| 6202 | /* Try forcing SDIO core to do ALPAvail request only */ |
| 6203 | clkset = SBSDIO_FORCE_HW_CLKREQ_OFF | SBSDIO_ALP_AVAIL_REQ; |
| 6204 | bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, |
| 6205 | clkset, &err); |
| 6206 | if (err) { |
| 6207 | DHD_ERROR(("%s: error writing for HT off\n", __func__)); |
| 6208 | goto fail; |
| 6209 | } |
| 6210 | |
| 6211 | /* If register supported, wait for ALPAvail and then force ALP */ |
| 6212 | /* This may take up to 15 milliseconds */ |
| 6213 | clkval = bcmsdh_cfg_read(bus->sdh, SDIO_FUNC_1, |
| 6214 | SBSDIO_FUNC1_CHIPCLKCSR, NULL); |
| 6215 | if ((clkval & ~SBSDIO_AVBITS) == clkset) { |
| 6216 | SPINWAIT(((clkval = |
| 6217 | bcmsdh_cfg_read(bus->sdh, SDIO_FUNC_1, |
| 6218 | SBSDIO_FUNC1_CHIPCLKCSR, |
| 6219 | NULL)), |
| 6220 | !SBSDIO_ALPAV(clkval)), |
| 6221 | PMU_MAX_TRANSITION_DLY); |
| 6222 | if (!SBSDIO_ALPAV(clkval)) { |
| 6223 | DHD_ERROR(("%s: timeout on ALPAV wait, clkval 0x%02x\n", |
| 6224 | __func__, clkval)); |
| 6225 | err = -EBUSY; |
| 6226 | goto fail; |
| 6227 | } |
| 6228 | clkset = SBSDIO_FORCE_HW_CLKREQ_OFF | |
| 6229 | SBSDIO_FORCE_ALP; |
| 6230 | bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, |
| 6231 | SBSDIO_FUNC1_CHIPCLKCSR, |
| 6232 | clkset, &err); |
| 6233 | udelay(65); |
| 6234 | } else { |
| 6235 | DHD_ERROR(("%s: ChipClkCSR access: wrote 0x%02x read 0x%02x\n", |
| 6236 | __func__, clkset, clkval)); |
| 6237 | err = -EACCES; |
| 6238 | goto fail; |
| 6239 | } |
| 6240 | |
| 6241 | /* Also, disable the extra SDIO pull-ups */ |
| 6242 | bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_SDIOPULLUP, 0, |
| 6243 | NULL); |
| 6244 | |
| 6245 | err = dhdsdio_chip_recognition(bus->sdh, ci, regs); |
| 6246 | if (err) |
| 6247 | goto fail; |
| 6248 | |
| 6249 | /* |
| 6250 | * Make sure any on-chip ARM is off (in case strapping is wrong), |
| 6251 | * or downloaded code was already running. |
| 6252 | */ |
| 6253 | dhdsdio_chip_disablecore(bus->sdh, ci->armcorebase); |
| 6254 | |
| 6255 | bcmsdh_reg_write(bus->sdh, |
| 6256 | CORE_CC_REG(ci->cccorebase, gpiopullup), 4, 0); |
| 6257 | bcmsdh_reg_write(bus->sdh, |
| 6258 | CORE_CC_REG(ci->cccorebase, gpiopulldown), 4, 0); |
| 6259 | |
| 6260 | /* Disable F2 to clear any intermediate frame state on the dongle */ |
| 6261 | bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_0, SDIOD_CCCR_IOEN, |
| 6262 | SDIO_FUNC_ENABLE_1, NULL); |
| 6263 | |
| 6264 | /* WAR: cmd52 backplane read so core HW will drop ALPReq */ |
| 6265 | clkval = bcmsdh_cfg_read(bus->sdh, SDIO_FUNC_1, |
| 6266 | 0, NULL); |
| 6267 | |
| 6268 | /* Done with backplane-dependent accesses, can drop clock... */ |
| 6269 | bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, 0, |
| 6270 | NULL); |
| 6271 | |
| 6272 | bus->ci = ci; |
| 6273 | return 0; |
| 6274 | fail: |
| 6275 | bus->ci = NULL; |
| 6276 | kfree(ci); |
| 6277 | return err; |
| 6278 | } |
Franky Lin | eb5dc51 | 2011-04-25 19:34:04 -0700 | [diff] [blame] | 6279 | |
| 6280 | static void |
| 6281 | dhdsdio_chip_resetcore(bcmsdh_info_t *sdh, u32 corebase) |
| 6282 | { |
| 6283 | u32 regdata; |
| 6284 | |
| 6285 | /* |
| 6286 | * Must do the disable sequence first to work for |
| 6287 | * arbitrary current core state. |
| 6288 | */ |
| 6289 | dhdsdio_chip_disablecore(sdh, corebase); |
| 6290 | |
| 6291 | /* |
| 6292 | * Now do the initialization sequence. |
| 6293 | * set reset while enabling the clock and |
| 6294 | * forcing them on throughout the core |
| 6295 | */ |
| 6296 | bcmsdh_reg_write(sdh, CORE_SB(corebase, sbtmstatelow), 4, |
| 6297 | ((SICF_FGC | SICF_CLOCK_EN) << SBTML_SICF_SHIFT) | |
| 6298 | SBTML_RESET); |
| 6299 | udelay(1); |
| 6300 | |
| 6301 | regdata = bcmsdh_reg_read(sdh, CORE_SB(corebase, sbtmstatehigh), 4); |
| 6302 | if (regdata & SBTMH_SERR) |
| 6303 | bcmsdh_reg_write(sdh, CORE_SB(corebase, sbtmstatehigh), 4, 0); |
| 6304 | |
| 6305 | regdata = bcmsdh_reg_read(sdh, CORE_SB(corebase, sbimstate), 4); |
| 6306 | if (regdata & (SBIM_IBE | SBIM_TO)) |
| 6307 | bcmsdh_reg_write(sdh, CORE_SB(corebase, sbimstate), 4, |
| 6308 | regdata & ~(SBIM_IBE | SBIM_TO)); |
| 6309 | |
| 6310 | /* clear reset and allow it to propagate throughout the core */ |
| 6311 | bcmsdh_reg_write(sdh, CORE_SB(corebase, sbtmstatelow), 4, |
| 6312 | (SICF_FGC << SBTML_SICF_SHIFT) | |
| 6313 | (SICF_CLOCK_EN << SBTML_SICF_SHIFT)); |
| 6314 | udelay(1); |
| 6315 | |
| 6316 | /* leave clock enabled */ |
| 6317 | bcmsdh_reg_write(sdh, CORE_SB(corebase, sbtmstatelow), 4, |
| 6318 | (SICF_CLOCK_EN << SBTML_SICF_SHIFT)); |
| 6319 | udelay(1); |
| 6320 | } |
Franky Lin | 5d0d7a9 | 2011-04-25 19:34:05 -0700 | [diff] [blame^] | 6321 | |
| 6322 | /* SDIO Pad drive strength to select value mappings */ |
| 6323 | struct sdiod_drive_str { |
| 6324 | u8 strength; /* Pad Drive Strength in mA */ |
| 6325 | u8 sel; /* Chip-specific select value */ |
| 6326 | }; |
| 6327 | |
| 6328 | /* SDIO Drive Strength to sel value table for PMU Rev 1 */ |
| 6329 | static const struct sdiod_drive_str sdiod_drive_strength_tab1[] = { |
| 6330 | { |
| 6331 | 4, 0x2}, { |
| 6332 | 2, 0x3}, { |
| 6333 | 1, 0x0}, { |
| 6334 | 0, 0x0} |
| 6335 | }; |
| 6336 | |
| 6337 | /* SDIO Drive Strength to sel value table for PMU Rev 2, 3 */ |
| 6338 | static const struct sdiod_drive_str sdiod_drive_strength_tab2[] = { |
| 6339 | { |
| 6340 | 12, 0x7}, { |
| 6341 | 10, 0x6}, { |
| 6342 | 8, 0x5}, { |
| 6343 | 6, 0x4}, { |
| 6344 | 4, 0x2}, { |
| 6345 | 2, 0x1}, { |
| 6346 | 0, 0x0} |
| 6347 | }; |
| 6348 | |
| 6349 | /* SDIO Drive Strength to sel value table for PMU Rev 8 (1.8V) */ |
| 6350 | static const struct sdiod_drive_str sdiod_drive_strength_tab3[] = { |
| 6351 | { |
| 6352 | 32, 0x7}, { |
| 6353 | 26, 0x6}, { |
| 6354 | 22, 0x5}, { |
| 6355 | 16, 0x4}, { |
| 6356 | 12, 0x3}, { |
| 6357 | 8, 0x2}, { |
| 6358 | 4, 0x1}, { |
| 6359 | 0, 0x0} |
| 6360 | }; |
| 6361 | |
| 6362 | #define SDIOD_DRVSTR_KEY(chip, pmu) (((chip) << 16) | (pmu)) |
| 6363 | |
| 6364 | static void |
| 6365 | dhdsdio_sdiod_drive_strength_init(struct dhd_bus *bus, u32 drivestrength) { |
| 6366 | struct sdiod_drive_str *str_tab = NULL; |
| 6367 | u32 str_mask = 0; |
| 6368 | u32 str_shift = 0; |
| 6369 | #ifdef BCMDBG |
| 6370 | char chn[8]; |
| 6371 | #endif |
| 6372 | |
| 6373 | if (!(bus->ci->cccaps & CC_CAP_PMU)) |
| 6374 | return; |
| 6375 | |
| 6376 | switch (SDIOD_DRVSTR_KEY(bus->ci->chip, bus->ci->pmurev)) { |
| 6377 | case SDIOD_DRVSTR_KEY(BCM4325_CHIP_ID, 1): |
| 6378 | str_tab = (struct sdiod_drive_str *)&sdiod_drive_strength_tab1; |
| 6379 | str_mask = 0x30000000; |
| 6380 | str_shift = 28; |
| 6381 | break; |
| 6382 | case SDIOD_DRVSTR_KEY(BCM4325_CHIP_ID, 2): |
| 6383 | case SDIOD_DRVSTR_KEY(BCM4325_CHIP_ID, 3): |
| 6384 | str_tab = (struct sdiod_drive_str *)&sdiod_drive_strength_tab2; |
| 6385 | str_mask = 0x00003800; |
| 6386 | str_shift = 11; |
| 6387 | break; |
| 6388 | case SDIOD_DRVSTR_KEY(BCM4336_CHIP_ID, 8): |
| 6389 | str_tab = (struct sdiod_drive_str *)&sdiod_drive_strength_tab3; |
| 6390 | str_mask = 0x00003800; |
| 6391 | str_shift = 11; |
| 6392 | break; |
| 6393 | default: |
| 6394 | DHD_ERROR(("No SDIO Drive strength init" |
| 6395 | "done for chip %s rev %d pmurev %d\n", |
| 6396 | bcm_chipname(bus->ci->chip, chn, 8), |
| 6397 | bus->ci->chiprev, bus->ci->pmurev)); |
| 6398 | break; |
| 6399 | } |
| 6400 | |
| 6401 | if (str_tab != NULL) { |
| 6402 | u32 drivestrength_sel = 0; |
| 6403 | u32 cc_data_temp; |
| 6404 | int i; |
| 6405 | |
| 6406 | for (i = 0; str_tab[i].strength != 0; i++) { |
| 6407 | if (drivestrength >= str_tab[i].strength) { |
| 6408 | drivestrength_sel = str_tab[i].sel; |
| 6409 | break; |
| 6410 | } |
| 6411 | } |
| 6412 | |
| 6413 | bcmsdh_reg_write(bus->sdh, |
| 6414 | CORE_CC_REG(bus->ci->cccorebase, chipcontrol_addr), |
| 6415 | 4, 1); |
| 6416 | cc_data_temp = bcmsdh_reg_read(bus->sdh, |
| 6417 | CORE_CC_REG(bus->ci->cccorebase, chipcontrol_addr), 4); |
| 6418 | cc_data_temp &= ~str_mask; |
| 6419 | drivestrength_sel <<= str_shift; |
| 6420 | cc_data_temp |= drivestrength_sel; |
| 6421 | bcmsdh_reg_write(bus->sdh, |
| 6422 | CORE_CC_REG(bus->ci->cccorebase, chipcontrol_addr), |
| 6423 | 4, cc_data_temp); |
| 6424 | |
| 6425 | DHD_INFO(("SDIO: %dmA drive strength selected, set to 0x%08x\n", |
| 6426 | drivestrength, cc_data_temp)); |
| 6427 | } |
| 6428 | } |