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