blob: 49e73b210ced44a3111573700a0d9231d9bec73e [file] [log] [blame]
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001/*
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-Hartmana1c16ed2010-10-21 11:17:44 -070017#include <linux/types.h>
Stanislav Fomichevbe1c09f2011-03-28 01:31:36 +040018#include <linux/pci_ids.h>
Greg Kroah-Hartmana1c16ed2010-10-21 11:17:44 -070019#include <bcmdefs.h>
Brett Rudleyc6ac24e2010-10-26 11:55:23 -070020#include <linux/netdevice.h>
Henry Ptasinskicf2b4482010-09-20 22:33:12 -070021#include <bcmsdh.h>
22
23#ifdef BCMEMBEDIMAGE
24#include BCMEMBEDIMAGE
25#endif /* BCMEMBEDIMAGE */
26
27#include <bcmdefs.h>
28#include <bcmutils.h>
Henry Ptasinskicf2b4482010-09-20 22:33:12 -070029#include <bcmdevs.h>
30
Henry Ptasinskicf2b4482010-09-20 22:33:12 -070031#include <hndsoc.h>
32#ifdef DHD_DEBUG
33#include <hndrte_armtrap.h>
34#include <hndrte_cons.h>
35#endif /* DHD_DEBUG */
36#include <sbchipc.h>
37#include <sbhnddma.h>
38
39#include <sdio.h>
40#include <sbsdio.h>
41#include <sbsdpcmdev.h>
42#include <bcmsdpcm.h>
43
Henry Ptasinskicf2b4482010-09-20 22:33:12 -070044#include <proto/802.11.h>
45
46#include <dngl_stats.h>
47#include <dhd.h>
48#include <dhd_bus.h>
49#include <dhd_proto.h>
50#include <dhd_dbg.h>
51#include <dhdioctl.h>
52#include <sdiovar.h>
Franky Lincb63e4c2011-04-25 15:45:08 -070053#include <bcmchip.h>
Henry Ptasinskicf2b4482010-09-20 22:33:12 -070054
55#ifndef DHDSDIO_MEM_DUMP_FNAME
56#define DHDSDIO_MEM_DUMP_FNAME "mem_dump"
57#endif
58
Grant Grundler26a71a42011-03-09 10:41:25 -080059#define TXQLEN 2048 /* bulk tx queue length */
60#define TXHI (TXQLEN - 256) /* turn on flow control above TXHI */
61#define TXLOW (TXHI - 256) /* turn off flow control below TXLOW */
Henry Ptasinskicf2b4482010-09-20 22:33:12 -070062#define PRIOMASK 7
63
64#define TXRETRIES 2 /* # of retries for tx frames */
65
66#if defined(CONFIG_MACH_SANDGATE2G)
67#define DHD_RXBOUND 250 /* Default for max rx frames in
68 one scheduling */
69#else
70#define DHD_RXBOUND 50 /* Default for max rx frames in
71 one scheduling */
72#endif /* defined(CONFIG_MACH_SANDGATE2G) */
73
74#define DHD_TXBOUND 20 /* Default for max tx frames in
75 one scheduling */
76
77#define DHD_TXMINMAX 1 /* Max tx frames if rx still pending */
78
79#define MEMBLOCK 2048 /* Block size used for downloading
80 of dongle image */
81#define MAX_DATA_BUF (32 * 1024) /* Must be large enough to hold
82 biggest possible glom */
83
84/* Packet alignment for most efficient SDIO (can change based on platform) */
85#ifndef DHD_SDALIGN
86#define DHD_SDALIGN 32
87#endif
88#if !ISPOWEROF2(DHD_SDALIGN)
89#error DHD_SDALIGN is not a power of 2!
90#endif
91
92#ifndef DHD_FIRSTREAD
93#define DHD_FIRSTREAD 32
94#endif
95#if !ISPOWEROF2(DHD_FIRSTREAD)
96#error DHD_FIRSTREAD is not a power of 2!
97#endif
98
99/* Total length of frame header for dongle protocol */
100#define SDPCM_HDRLEN (SDPCM_FRAMETAG_LEN + SDPCM_SWHEADER_LEN)
101#ifdef SDTEST
102#define SDPCM_RESERVE (SDPCM_HDRLEN + SDPCM_TEST_HDRLEN + DHD_SDALIGN)
103#else
104#define SDPCM_RESERVE (SDPCM_HDRLEN + DHD_SDALIGN)
105#endif
106
107/* Space for header read, limit for data packets */
108#ifndef MAX_HDR_READ
109#define MAX_HDR_READ 32
110#endif
111#if !ISPOWEROF2(MAX_HDR_READ)
112#error MAX_HDR_READ is not a power of 2!
113#endif
114
115#define MAX_RX_DATASZ 2048
116
117/* Maximum milliseconds to wait for F2 to come up */
118#define DHD_WAIT_F2RDY 3000
119
120/* Bump up limit on waiting for HT to account for first startup;
121 * if the image is doing a CRC calculation before programming the PMU
122 * for HT availability, it could take a couple hundred ms more, so
123 * max out at a 1 second (1000000us).
124 */
125#if (PMU_MAX_TRANSITION_DLY <= 1000000)
126#undef PMU_MAX_TRANSITION_DLY
127#define PMU_MAX_TRANSITION_DLY 1000000
128#endif
129
130/* Value for ChipClockCSR during initial setup */
131#define DHD_INIT_CLKCTL1 (SBSDIO_FORCE_HW_CLKREQ_OFF | \
132 SBSDIO_ALP_AVAIL_REQ)
133#define DHD_INIT_CLKCTL2 (SBSDIO_FORCE_HW_CLKREQ_OFF | SBSDIO_FORCE_ALP)
134
135/* Flags for SDH calls */
136#define F2SYNC (SDIO_REQ_4BYTE | SDIO_REQ_FIXED)
137
Arend van Spriel70dfb582011-02-25 16:39:17 +0100138/*
139 * Conversion of 802.1D priority to precedence level
140 */
141#define PRIO2PREC(prio) \
142 (((prio) == PRIO_8021D_NONE || (prio) == PRIO_8021D_BE) ? \
143 ((prio^2)) : (prio))
144
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700145DHD_SPINWAIT_SLEEP_INIT(sdioh_spinwait_sleep);
146extern int dhdcdc_set_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf,
147 uint len);
148
149#ifdef DHD_DEBUG
150/* Device console log buffer state */
151typedef struct dhd_console {
152 uint count; /* Poll interval msec counter */
153 uint log_addr; /* Log struct address (fixed) */
154 hndrte_log_t log; /* Log struct (host copy) */
155 uint bufsize; /* Size of log buffer */
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -0700156 u8 *buf; /* Log buffer (host copy) */
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700157 uint last; /* Last buffer read index */
158} dhd_console_t;
159#endif /* DHD_DEBUG */
160
Franky Lincb63e4c2011-04-25 15:45:08 -0700161/* misc chip info needed by some of the routines */
162struct chip_info {
163 u32 chip;
164 u32 chiprev;
165 u32 cccorebase;
166 u32 ccrev;
167 u32 cccaps;
168 u32 buscorebase;
169 u32 buscorerev;
170 u32 buscoretype;
171 u32 ramcorebase;
172 u32 armcorebase;
173 u32 pmurev;
Franky Linc05df632011-04-25 19:34:07 -0700174 u32 ramsize;
Franky Lincb63e4c2011-04-25 15:45:08 -0700175};
176
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700177/* Private data for SDIO bus interaction */
178typedef struct dhd_bus {
179 dhd_pub_t *dhd;
180
181 bcmsdh_info_t *sdh; /* Handle for BCMSDH calls */
Franky Lincb63e4c2011-04-25 15:45:08 -0700182 struct chip_info *ci; /* Chip info struct */
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700183 char *vars; /* Variables (from CIS and/or other) */
184 uint varsz; /* Size of variables buffer */
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700185 u32 sbaddr; /* Current SB window pointer (-1, invalid) */
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700186
187 sdpcmd_regs_t *regs; /* Registers for SDIO core */
188 uint sdpcmrev; /* SDIO core revision */
189 uint armrev; /* CPU core revision */
190 uint ramrev; /* SOCRAM core revision */
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700191 u32 ramsize; /* Size of RAM in SOCRAM (bytes) */
192 u32 orig_ramsize; /* Size of RAM in SOCRAM (bytes) */
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700193
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700194 u32 bus; /* gSPI or SDIO bus */
195 u32 hostintmask; /* Copy of Host Interrupt Mask */
196 u32 intstatus; /* Intstatus bits (events) pending */
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700197 bool dpc_sched; /* Indicates DPC schedule (intrpt rcvd) */
198 bool fcstate; /* State of dongle flow-control */
199
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -0700200 u16 cl_devid; /* cached devid for dhdsdio_probe_attach() */
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700201 char *fw_path; /* module_param: path to firmware image */
202 char *nv_path; /* module_param: path to nvram vars file */
203 const char *nvram_params; /* user specified nvram params. */
204
205 uint blocksize; /* Block size of SDIO transfers */
206 uint roundup; /* Max roundup limit */
207
208 struct pktq txq; /* Queue length used for flow-control */
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -0700209 u8 flowcontrol; /* per prio flow control bitmask */
210 u8 tx_seq; /* Transmit sequence number (next) */
211 u8 tx_max; /* Maximum transmit sequence allowed */
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700212
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -0700213 u8 hdrbuf[MAX_HDR_READ + DHD_SDALIGN];
214 u8 *rxhdr; /* Header of current rx frame (in hdrbuf) */
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -0700215 u16 nextlen; /* Next Read Len from last header */
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -0700216 u8 rx_seq; /* Receive sequence number (expected) */
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700217 bool rxskip; /* Skip receive (awaiting NAK ACK) */
218
Arend van Sprielc26b1372010-11-23 14:06:23 +0100219 struct sk_buff *glomd; /* Packet containing glomming descriptor */
220 struct sk_buff *glom; /* Packet chain for glommed superframe */
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700221 uint glomerr; /* Glom packet read errors */
222
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -0700223 u8 *rxbuf; /* Buffer for receiving control packets */
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700224 uint rxblen; /* Allocated length of rxbuf */
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -0700225 u8 *rxctl; /* Aligned pointer into rxbuf */
226 u8 *databuf; /* Buffer for receiving big glom packet */
227 u8 *dataptr; /* Aligned pointer into databuf */
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700228 uint rxlen; /* Length of valid data in buffer */
229
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -0700230 u8 sdpcm_ver; /* Bus protocol reported by dongle */
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700231
232 bool intr; /* Use interrupts */
233 bool poll; /* Use polling */
234 bool ipend; /* Device interrupt is pending */
235 bool intdis; /* Interrupts disabled by isr */
236 uint intrcount; /* Count of device interrupt callbacks */
237 uint lastintrs; /* Count as of last watchdog timer */
238 uint spurious; /* Count of spurious interrupts */
239 uint pollrate; /* Ticks between device polls */
240 uint polltick; /* Tick counter */
241 uint pollcnt; /* Count of active polls */
242
243#ifdef DHD_DEBUG
244 dhd_console_t console; /* Console output polling support */
245 uint console_addr; /* Console address from shared struct */
246#endif /* DHD_DEBUG */
247
248 uint regfails; /* Count of R_REG/W_REG failures */
249
250 uint clkstate; /* State of sd and backplane clock(s) */
251 bool activity; /* Activity flag for clock down */
Greg Kroah-Hartman3e264162010-10-08 11:11:13 -0700252 s32 idletime; /* Control for activity timeout */
253 s32 idlecount; /* Activity timeout counter */
254 s32 idleclock; /* How to set bus driver when idle */
255 s32 sd_divisor; /* Speed control to bus driver */
256 s32 sd_mode; /* Mode control to bus driver */
257 s32 sd_rxchain; /* If bcmsdh api accepts PKT chains */
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700258 bool use_rxchain; /* If dhd should use PKT chains */
259 bool sleeping; /* Is SDIO bus sleeping? */
260 bool rxflow_mode; /* Rx flow control mode */
261 bool rxflow; /* Is rx flow control on */
262 uint prev_rxlim_hit; /* Is prev rx limit exceeded
263 (per dpc schedule) */
264 bool alp_only; /* Don't use HT clock (ALP only) */
265/* Field to decide if rx of control frames happen in rxbuf or lb-pool */
266 bool usebufpool;
267
268#ifdef SDTEST
269 /* external loopback */
270 bool ext_loop;
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -0700271 u8 loopid;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700272
273 /* pktgen configuration */
274 uint pktgen_freq; /* Ticks between bursts */
275 uint pktgen_count; /* Packets to send each burst */
276 uint pktgen_print; /* Bursts between count displays */
277 uint pktgen_total; /* Stop after this many */
278 uint pktgen_minlen; /* Minimum packet data len */
279 uint pktgen_maxlen; /* Maximum packet data len */
280 uint pktgen_mode; /* Configured mode: tx, rx, or echo */
281 uint pktgen_stop; /* Number of tx failures causing stop */
282
283 /* active pktgen fields */
284 uint pktgen_tick; /* Tick counter for bursts */
285 uint pktgen_ptick; /* Burst counter for printing */
286 uint pktgen_sent; /* Number of test packets generated */
287 uint pktgen_rcvd; /* Number of test packets received */
288 uint pktgen_fail; /* Number of failed send attempts */
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -0700289 u16 pktgen_len; /* Length of next packet to send */
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700290#endif /* SDTEST */
291
292 /* Some additional counters */
293 uint tx_sderrs; /* Count of tx attempts with sd errors */
294 uint fcqueued; /* Tx packets that got queued */
295 uint rxrtx; /* Count of rtx requests (NAK to dongle) */
296 uint rx_toolong; /* Receive frames too long to receive */
297 uint rxc_errors; /* SDIO errors when reading control frames */
298 uint rx_hdrfail; /* SDIO errors on header reads */
299 uint rx_badhdr; /* Bad received headers (roosync?) */
300 uint rx_badseq; /* Mismatched rx sequence number */
301 uint fc_rcvd; /* Number of flow-control events received */
302 uint fc_xoff; /* Number which turned on flow-control */
303 uint fc_xon; /* Number which turned off flow-control */
304 uint rxglomfail; /* Failed deglom attempts */
305 uint rxglomframes; /* Number of glom frames (superframes) */
306 uint rxglompkts; /* Number of packets from glom frames */
307 uint f2rxhdrs; /* Number of header reads */
308 uint f2rxdata; /* Number of frame data reads */
309 uint f2txdata; /* Number of f2 frame writes */
310 uint f1regdata; /* Number of f1 register accesses */
311
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -0700312 u8 *ctrl_frame_buf;
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700313 u32 ctrl_frame_len;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700314 bool ctrl_frame_stat;
315} dhd_bus_t;
316
317/* clkstate */
318#define CLK_NONE 0
319#define CLK_SDONLY 1
320#define CLK_PENDING 2 /* Not used yet */
321#define CLK_AVAIL 3
322
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -0700323#define DHD_NOPMU(dhd) (false)
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700324
325#ifdef DHD_DEBUG
326static int qcount[NUMPRIO];
327static int tx_packets[NUMPRIO];
328#endif /* DHD_DEBUG */
329
330/* Deferred transmit */
331const uint dhd_deferred_tx = 1;
332
333extern uint dhd_watchdog_ms;
334extern void dhd_os_wd_timer(void *bus, uint wdtick);
335
336/* Tx/Rx bounds */
337uint dhd_txbound;
338uint dhd_rxbound;
339uint dhd_txminmax;
340
341/* override the RAM size if possible */
342#define DONGLE_MIN_MEMSIZE (128 * 1024)
343int dhd_dongle_memsize;
344
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700345static bool dhd_alignctl;
346
347static bool sd1idle;
348
349static bool retrydata;
350#define RETRYCHAN(chan) (((chan) == SDPCM_EVENT_CHANNEL) || retrydata)
351
352static const uint watermark = 8;
353static const uint firstread = DHD_FIRSTREAD;
354
355#define HDATLEN (firstread - (SDPCM_HDRLEN))
356
357/* Retry count for register access failures */
358static const uint retry_limit = 2;
359
360/* Force even SD lengths (some host controllers mess up on odd bytes) */
361static bool forcealign;
362
363#define ALIGNMENT 4
364
365#if defined(OOB_INTR_ONLY) && defined(HW_OOB)
366extern void bcmsdh_enable_hw_oob_intr(void *sdh, bool enable);
367#endif
368
369#if defined(OOB_INTR_ONLY) && defined(SDIO_ISR_THREAD)
370#error OOB_INTR_ONLY is NOT working with SDIO_ISR_THREAD
371#endif /* defined(OOB_INTR_ONLY) && defined(SDIO_ISR_THREAD) */
Arend van Spriel3c9d4c32011-03-02 21:18:48 +0100372#define PKTALIGN(_p, _len, _align) \
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700373 do { \
374 uint datalign; \
Arend van Spriel54991ad2010-11-23 14:06:24 +0100375 datalign = (unsigned long)((_p)->data); \
376 datalign = roundup(datalign, (_align)) - datalign; \
377 ASSERT(datalign < (_align)); \
378 ASSERT((_p)->len >= ((_len) + datalign)); \
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700379 if (datalign) \
Arend van Spriel54991ad2010-11-23 14:06:24 +0100380 skb_pull((_p), datalign); \
381 __skb_trim((_p), (_len)); \
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700382 } while (0)
383
384/* Limit on rounding up frames */
385static const uint max_roundup = 512;
386
387/* Try doing readahead */
388static bool dhd_readahead;
389
390/* To check if there's window offered */
391#define DATAOK(bus) \
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -0700392 (((u8)(bus->tx_max - bus->tx_seq) != 0) && \
393 (((u8)(bus->tx_max - bus->tx_seq) & 0x80) == 0))
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700394
395/* Macros to get register read/write status */
396/* NOTE: these assume a local dhdsdio_bus_t *bus! */
397#define R_SDREG(regvar, regaddr, retryvar) \
398do { \
399 retryvar = 0; \
400 do { \
Arend van Sprielff31c542011-03-01 10:56:54 +0100401 regvar = R_REG(regaddr); \
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700402 } while (bcmsdh_regfail(bus->sdh) && (++retryvar <= retry_limit)); \
403 if (retryvar) { \
404 bus->regfails += (retryvar-1); \
405 if (retryvar > retry_limit) { \
406 DHD_ERROR(("%s: FAILED" #regvar "READ, LINE %d\n", \
407 __func__, __LINE__)); \
408 regvar = 0; \
409 } \
410 } \
411} while (0)
412
413#define W_SDREG(regval, regaddr, retryvar) \
414do { \
415 retryvar = 0; \
416 do { \
Arend van Sprielff31c542011-03-01 10:56:54 +0100417 W_REG(regaddr, regval); \
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700418 } while (bcmsdh_regfail(bus->sdh) && (++retryvar <= retry_limit)); \
419 if (retryvar) { \
420 bus->regfails += (retryvar-1); \
421 if (retryvar > retry_limit) \
422 DHD_ERROR(("%s: FAILED REGISTER WRITE, LINE %d\n", \
423 __func__, __LINE__)); \
424 } \
425} while (0)
426
427#define DHD_BUS SDIO_BUS
428
429#define PKT_AVAILABLE() (intstatus & I_HMB_FRAME_IND)
430
431#define HOSTINTMASK (I_HMB_SW_MASK | I_CHIPACTIVE)
432
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700433#ifdef SDTEST
434static void dhdsdio_testrcv(dhd_bus_t *bus, void *pkt, uint seq);
435static void dhdsdio_sdtest_set(dhd_bus_t *bus, bool start);
436#endif
437
438#ifdef DHD_DEBUG
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -0700439static int dhdsdio_checkdied(dhd_bus_t *bus, u8 *data, uint size);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700440static int dhdsdio_mem_dump(dhd_bus_t *bus);
441#endif /* DHD_DEBUG */
442static int dhdsdio_download_state(dhd_bus_t *bus, bool enter);
443
Arend van Spriel3c9d4c32011-03-02 21:18:48 +0100444static void dhdsdio_release(dhd_bus_t *bus);
Arend van Spriel8da4a3a2011-03-02 21:18:42 +0100445static void dhdsdio_release_malloc(dhd_bus_t *bus);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700446static void dhdsdio_disconnect(void *ptr);
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -0700447static bool dhdsdio_chipmatch(u16 chipid);
Arend van Spriel8da4a3a2011-03-02 21:18:42 +0100448static bool dhdsdio_probe_attach(dhd_bus_t *bus, void *sdh,
449 void *regsva, u16 devid);
450static bool dhdsdio_probe_malloc(dhd_bus_t *bus, void *sdh);
451static bool dhdsdio_probe_init(dhd_bus_t *bus, void *sdh);
452static void dhdsdio_release_dongle(dhd_bus_t *bus);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700453
454static uint process_nvram_vars(char *varbuf, uint len);
455
456static void dhd_dongle_setmemsize(struct dhd_bus *bus, int mem_size);
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700457static int dhd_bcmsdh_send_buf(dhd_bus_t *bus, u32 addr, uint fn,
Arend van Sprielc26b1372010-11-23 14:06:23 +0100458 uint flags, u8 *buf, uint nbytes,
459 struct sk_buff *pkt, bcmsdh_cmplt_fn_t complete,
460 void *handle);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700461
Arend van Spriel8da4a3a2011-03-02 21:18:42 +0100462static bool dhdsdio_download_firmware(struct dhd_bus *bus, void *sdh);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700463static int _dhdsdio_download_firmware(struct dhd_bus *bus);
464
465static int dhdsdio_download_code_file(struct dhd_bus *bus, char *image_path);
466static int dhdsdio_download_nvram(struct dhd_bus *bus);
467#ifdef BCMEMBEDIMAGE
468static int dhdsdio_download_code_array(struct dhd_bus *bus);
469#endif
Franky Lineb5dc512011-04-25 19:34:04 -0700470static void dhdsdio_chip_disablecore(bcmsdh_info_t *sdh, u32 corebase);
Franky Lincb63e4c2011-04-25 15:45:08 -0700471static int dhdsdio_chip_attach(struct dhd_bus *bus, void *regs);
Franky Lineb5dc512011-04-25 19:34:04 -0700472static void dhdsdio_chip_resetcore(bcmsdh_info_t *sdh, u32 corebase);
Franky Lin5d0d7a92011-04-25 19:34:05 -0700473static void dhdsdio_sdiod_drive_strength_init(struct dhd_bus *bus,
474 u32 drivestrength);
Franky Lincee3cf42011-04-25 19:34:06 -0700475static void dhdsdio_chip_detach(struct dhd_bus *bus);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700476
Grant Grundler4b455e02011-05-04 09:59:47 -0700477/* Packet free applicable unconditionally for sdio and sdspi.
478 * Conditional if bufpool was present for gspi bus.
479 */
480static void dhdsdio_pktfree2(dhd_bus_t *bus, struct sk_buff *pkt)
481{
482 dhd_os_sdlock_rxq(bus->dhd);
483 if ((bus->bus != SPI_BUS) || bus->usebufpool)
Henry Ptasinskib33f0e22011-05-10 22:25:29 +0200484 bcm_pkt_buf_free_skb(pkt);
Grant Grundler4b455e02011-05-04 09:59:47 -0700485 dhd_os_sdunlock_rxq(bus->dhd);
486}
487
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700488static void dhd_dongle_setmemsize(struct dhd_bus *bus, int mem_size)
489{
Greg Kroah-Hartman3e264162010-10-08 11:11:13 -0700490 s32 min_size = DONGLE_MIN_MEMSIZE;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700491 /* Restrict the memsize to user specified limit */
492 DHD_ERROR(("user: Restrict the dongle ram size to %d, min %d\n",
493 dhd_dongle_memsize, min_size));
494 if ((dhd_dongle_memsize > min_size) &&
Greg Kroah-Hartman3e264162010-10-08 11:11:13 -0700495 (dhd_dongle_memsize < (s32) bus->orig_ramsize))
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700496 bus->ramsize = dhd_dongle_memsize;
497}
498
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700499static int dhdsdio_set_siaddr_window(dhd_bus_t *bus, u32 address)
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700500{
501 int err = 0;
502 bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRLOW,
503 (address >> 8) & SBSDIO_SBADDRLOW_MASK, &err);
504 if (!err)
505 bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRMID,
506 (address >> 16) & SBSDIO_SBADDRMID_MASK, &err);
507 if (!err)
508 bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRHIGH,
509 (address >> 24) & SBSDIO_SBADDRHIGH_MASK,
510 &err);
511 return err;
512}
513
514/* Turn backplane clock on or off */
515static int dhdsdio_htclk(dhd_bus_t *bus, bool on, bool pendok)
516{
517 int err;
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -0700518 u8 clkctl, clkreq, devctl;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700519 bcmsdh_info_t *sdh;
520
521 DHD_TRACE(("%s: Enter\n", __func__));
522
523#if defined(OOB_INTR_ONLY)
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -0700524 pendok = false;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700525#endif
526 clkctl = 0;
527 sdh = bus->sdh;
528
529 if (on) {
530 /* Request HT Avail */
531 clkreq =
532 bus->alp_only ? SBSDIO_ALP_AVAIL_REQ : SBSDIO_HT_AVAIL_REQ;
533
Franky Linc05df632011-04-25 19:34:07 -0700534 if ((bus->ci->chip == BCM4329_CHIP_ID)
535 && (bus->ci->chiprev == 0))
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700536 clkreq |= SBSDIO_FORCE_ALP;
537
538 bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR,
539 clkreq, &err);
540 if (err) {
541 DHD_ERROR(("%s: HT Avail request error: %d\n",
542 __func__, err));
Roland Vossenb74ac122011-05-03 11:35:20 +0200543 return -EBADE;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700544 }
545
Franky Linc05df632011-04-25 19:34:07 -0700546 if (pendok && ((bus->ci->buscoretype == PCMCIA_CORE_ID)
547 && (bus->ci->buscorerev == 9))) {
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700548 u32 dummy, retries;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700549 R_SDREG(dummy, &bus->regs->clockctlstatus, retries);
550 }
551
552 /* Check current status */
553 clkctl =
554 bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR,
555 &err);
556 if (err) {
557 DHD_ERROR(("%s: HT Avail read error: %d\n",
558 __func__, err));
Roland Vossenb74ac122011-05-03 11:35:20 +0200559 return -EBADE;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700560 }
561
562 /* Go to pending and await interrupt if appropriate */
563 if (!SBSDIO_CLKAV(clkctl, bus->alp_only) && pendok) {
564 /* Allow only clock-available interrupt */
565 devctl =
566 bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL,
567 &err);
568 if (err) {
569 DHD_ERROR(("%s: Devctl error setting CA: %d\n",
570 __func__, err));
Roland Vossenb74ac122011-05-03 11:35:20 +0200571 return -EBADE;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700572 }
573
574 devctl |= SBSDIO_DEVCTL_CA_INT_ONLY;
575 bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL,
576 devctl, &err);
577 DHD_INFO(("CLKCTL: set PENDING\n"));
578 bus->clkstate = CLK_PENDING;
579
Roland Vossena1c5ad82011-04-11 15:16:24 +0200580 return 0;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700581 } else if (bus->clkstate == CLK_PENDING) {
582 /* Cancel CA-only interrupt filter */
583 devctl =
584 bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL,
585 &err);
586 devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY;
587 bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL,
588 devctl, &err);
589 }
590
591 /* Otherwise, wait here (polling) for HT Avail */
592 if (!SBSDIO_CLKAV(clkctl, bus->alp_only)) {
593 SPINWAIT_SLEEP(sdioh_spinwait_sleep,
594 ((clkctl =
595 bcmsdh_cfg_read(sdh, SDIO_FUNC_1,
596 SBSDIO_FUNC1_CHIPCLKCSR,
597 &err)),
598 !SBSDIO_CLKAV(clkctl, bus->alp_only)),
599 PMU_MAX_TRANSITION_DLY);
600 }
601 if (err) {
602 DHD_ERROR(("%s: HT Avail request error: %d\n",
603 __func__, err));
Roland Vossenb74ac122011-05-03 11:35:20 +0200604 return -EBADE;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700605 }
606 if (!SBSDIO_CLKAV(clkctl, bus->alp_only)) {
607 DHD_ERROR(("%s: HT Avail timeout (%d): clkctl 0x%02x\n",
608 __func__, PMU_MAX_TRANSITION_DLY, clkctl));
Roland Vossenb74ac122011-05-03 11:35:20 +0200609 return -EBADE;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700610 }
611
612 /* Mark clock available */
613 bus->clkstate = CLK_AVAIL;
614 DHD_INFO(("CLKCTL: turned ON\n"));
615
616#if defined(DHD_DEBUG)
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -0700617 if (bus->alp_only == true) {
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700618#if !defined(BCMLXSDMMC)
619 if (!SBSDIO_ALPONLY(clkctl)) {
620 DHD_ERROR(("%s: HT Clock, when ALP Only\n",
621 __func__));
622 }
623#endif /* !defined(BCMLXSDMMC) */
624 } else {
625 if (SBSDIO_ALPONLY(clkctl)) {
626 DHD_ERROR(("%s: HT Clock should be on.\n",
627 __func__));
628 }
629 }
630#endif /* defined (DHD_DEBUG) */
631
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -0700632 bus->activity = true;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700633 } else {
634 clkreq = 0;
635
636 if (bus->clkstate == CLK_PENDING) {
637 /* Cancel CA-only interrupt filter */
638 devctl =
639 bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL,
640 &err);
641 devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY;
642 bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL,
643 devctl, &err);
644 }
645
646 bus->clkstate = CLK_SDONLY;
647 bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR,
648 clkreq, &err);
649 DHD_INFO(("CLKCTL: turned OFF\n"));
650 if (err) {
651 DHD_ERROR(("%s: Failed access turning clock off: %d\n",
652 __func__, err));
Roland Vossenb74ac122011-05-03 11:35:20 +0200653 return -EBADE;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700654 }
655 }
Roland Vossena1c5ad82011-04-11 15:16:24 +0200656 return 0;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700657}
658
659/* Change idle/active SD state */
660static int dhdsdio_sdclk(dhd_bus_t *bus, bool on)
661{
662 int err;
Greg Kroah-Hartman3e264162010-10-08 11:11:13 -0700663 s32 iovalue;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700664
665 DHD_TRACE(("%s: Enter\n", __func__));
666
667 if (on) {
668 if (bus->idleclock == DHD_IDLE_STOP) {
669 /* Turn on clock and restore mode */
670 iovalue = 1;
671 err = bcmsdh_iovar_op(bus->sdh, "sd_clock", NULL, 0,
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -0700672 &iovalue, sizeof(iovalue), true);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700673 if (err) {
674 DHD_ERROR(("%s: error enabling sd_clock: %d\n",
675 __func__, err));
Roland Vossenb74ac122011-05-03 11:35:20 +0200676 return -EBADE;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700677 }
678
679 iovalue = bus->sd_mode;
680 err = bcmsdh_iovar_op(bus->sdh, "sd_mode", NULL, 0,
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -0700681 &iovalue, sizeof(iovalue), true);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700682 if (err) {
683 DHD_ERROR(("%s: error changing sd_mode: %d\n",
684 __func__, err));
Roland Vossenb74ac122011-05-03 11:35:20 +0200685 return -EBADE;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700686 }
687 } else if (bus->idleclock != DHD_IDLE_ACTIVE) {
688 /* Restore clock speed */
689 iovalue = bus->sd_divisor;
690 err = bcmsdh_iovar_op(bus->sdh, "sd_divisor", NULL, 0,
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -0700691 &iovalue, sizeof(iovalue), true);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700692 if (err) {
693 DHD_ERROR(("%s: error restoring sd_divisor: %d\n",
694 __func__, err));
Roland Vossenb74ac122011-05-03 11:35:20 +0200695 return -EBADE;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700696 }
697 }
698 bus->clkstate = CLK_SDONLY;
699 } else {
700 /* Stop or slow the SD clock itself */
701 if ((bus->sd_divisor == -1) || (bus->sd_mode == -1)) {
702 DHD_TRACE(("%s: can't idle clock, divisor %d mode %d\n",
703 __func__, bus->sd_divisor, bus->sd_mode));
Roland Vossenb74ac122011-05-03 11:35:20 +0200704 return -EBADE;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700705 }
706 if (bus->idleclock == DHD_IDLE_STOP) {
707 if (sd1idle) {
708 /* Change to SD1 mode and turn off clock */
709 iovalue = 1;
710 err =
711 bcmsdh_iovar_op(bus->sdh, "sd_mode", NULL,
712 0, &iovalue,
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -0700713 sizeof(iovalue), true);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700714 if (err) {
715 DHD_ERROR(("%s: error changing sd_clock: %d\n",
716 __func__, err));
Roland Vossenb74ac122011-05-03 11:35:20 +0200717 return -EBADE;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700718 }
719 }
720
721 iovalue = 0;
722 err = bcmsdh_iovar_op(bus->sdh, "sd_clock", NULL, 0,
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -0700723 &iovalue, sizeof(iovalue), true);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700724 if (err) {
725 DHD_ERROR(("%s: error disabling sd_clock: %d\n",
726 __func__, err));
Roland Vossenb74ac122011-05-03 11:35:20 +0200727 return -EBADE;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700728 }
729 } else if (bus->idleclock != DHD_IDLE_ACTIVE) {
730 /* Set divisor to idle value */
731 iovalue = bus->idleclock;
732 err = bcmsdh_iovar_op(bus->sdh, "sd_divisor", NULL, 0,
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -0700733 &iovalue, sizeof(iovalue), true);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700734 if (err) {
735 DHD_ERROR(("%s: error changing sd_divisor: %d\n",
736 __func__, err));
Roland Vossenb74ac122011-05-03 11:35:20 +0200737 return -EBADE;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700738 }
739 }
740 bus->clkstate = CLK_NONE;
741 }
742
Roland Vossena1c5ad82011-04-11 15:16:24 +0200743 return 0;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700744}
745
746/* Transition SD and backplane clock readiness */
747static int dhdsdio_clkctl(dhd_bus_t *bus, uint target, bool pendok)
748{
749#ifdef DHD_DEBUG
750 uint oldstate = bus->clkstate;
751#endif /* DHD_DEBUG */
752
753 DHD_TRACE(("%s: Enter\n", __func__));
754
755 /* Early exit if we're already there */
756 if (bus->clkstate == target) {
757 if (target == CLK_AVAIL) {
758 dhd_os_wd_timer(bus->dhd, dhd_watchdog_ms);
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -0700759 bus->activity = true;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700760 }
Roland Vossena1c5ad82011-04-11 15:16:24 +0200761 return 0;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700762 }
763
764 switch (target) {
765 case CLK_AVAIL:
766 /* Make sure SD clock is available */
767 if (bus->clkstate == CLK_NONE)
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -0700768 dhdsdio_sdclk(bus, true);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700769 /* Now request HT Avail on the backplane */
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -0700770 dhdsdio_htclk(bus, true, pendok);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700771 dhd_os_wd_timer(bus->dhd, dhd_watchdog_ms);
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -0700772 bus->activity = true;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700773 break;
774
775 case CLK_SDONLY:
776 /* Remove HT request, or bring up SD clock */
777 if (bus->clkstate == CLK_NONE)
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -0700778 dhdsdio_sdclk(bus, true);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700779 else if (bus->clkstate == CLK_AVAIL)
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -0700780 dhdsdio_htclk(bus, false, false);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700781 else
782 DHD_ERROR(("dhdsdio_clkctl: request for %d -> %d\n",
783 bus->clkstate, target));
784 dhd_os_wd_timer(bus->dhd, dhd_watchdog_ms);
785 break;
786
787 case CLK_NONE:
788 /* Make sure to remove HT request */
789 if (bus->clkstate == CLK_AVAIL)
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -0700790 dhdsdio_htclk(bus, false, false);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700791 /* Now remove the SD clock */
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -0700792 dhdsdio_sdclk(bus, false);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700793 dhd_os_wd_timer(bus->dhd, 0);
794 break;
795 }
796#ifdef DHD_DEBUG
797 DHD_INFO(("dhdsdio_clkctl: %d -> %d\n", oldstate, bus->clkstate));
798#endif /* DHD_DEBUG */
799
Roland Vossena1c5ad82011-04-11 15:16:24 +0200800 return 0;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700801}
802
803int dhdsdio_bussleep(dhd_bus_t *bus, bool sleep)
804{
805 bcmsdh_info_t *sdh = bus->sdh;
806 sdpcmd_regs_t *regs = bus->regs;
807 uint retries = 0;
808
809 DHD_INFO(("dhdsdio_bussleep: request %s (currently %s)\n",
810 (sleep ? "SLEEP" : "WAKE"),
811 (bus->sleeping ? "SLEEP" : "WAKE")));
812
813 /* Done if we're already in the requested state */
814 if (sleep == bus->sleeping)
Roland Vossena1c5ad82011-04-11 15:16:24 +0200815 return 0;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700816
817 /* Going to sleep: set the alarm and turn off the lights... */
818 if (sleep) {
819 /* Don't sleep if something is pending */
820 if (bus->dpc_sched || bus->rxskip || pktq_len(&bus->txq))
Roland Vossene10d82d2011-05-03 11:35:19 +0200821 return -EBUSY;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700822
823 /* Disable SDIO interrupts (no longer interested) */
824 bcmsdh_intr_disable(bus->sdh);
825
826 /* Make sure the controller has the bus up */
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -0700827 dhdsdio_clkctl(bus, CLK_AVAIL, false);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700828
829 /* Tell device to start using OOB wakeup */
830 W_SDREG(SMB_USE_OOB, &regs->tosbmailbox, retries);
831 if (retries > retry_limit)
832 DHD_ERROR(("CANNOT SIGNAL CHIP, WILL NOT WAKE UP!!\n"));
833
834 /* Turn off our contribution to the HT clock request */
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -0700835 dhdsdio_clkctl(bus, CLK_SDONLY, false);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700836
837 bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR,
838 SBSDIO_FORCE_HW_CLKREQ_OFF, NULL);
839
840 /* Isolate the bus */
Franky Linc05df632011-04-25 19:34:07 -0700841 if (bus->ci->chip != BCM4329_CHIP_ID
842 && bus->ci->chip != BCM4319_CHIP_ID) {
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700843 bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL,
844 SBSDIO_DEVCTL_PADS_ISO, NULL);
845 }
846
847 /* Change state */
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -0700848 bus->sleeping = true;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700849
850 } else {
851 /* Waking up: bus power up is ok, set local state */
852
853 bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR,
854 0, NULL);
855
856 /* Force pad isolation off if possible
857 (in case power never toggled) */
Franky Linc05df632011-04-25 19:34:07 -0700858 if ((bus->ci->buscoretype == PCMCIA_CORE_ID)
859 && (bus->ci->buscorerev >= 10))
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700860 bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL, 0,
861 NULL);
862
863 /* Make sure the controller has the bus up */
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -0700864 dhdsdio_clkctl(bus, CLK_AVAIL, false);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700865
866 /* Send misc interrupt to indicate OOB not needed */
867 W_SDREG(0, &regs->tosbmailboxdata, retries);
868 if (retries <= retry_limit)
869 W_SDREG(SMB_DEV_INT, &regs->tosbmailbox, retries);
870
871 if (retries > retry_limit)
872 DHD_ERROR(("CANNOT SIGNAL CHIP TO CLEAR OOB!!\n"));
873
874 /* Make sure we have SD bus access */
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -0700875 dhdsdio_clkctl(bus, CLK_SDONLY, false);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700876
877 /* Change state */
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -0700878 bus->sleeping = false;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700879
880 /* Enable interrupts again */
881 if (bus->intr && (bus->dhd->busstate == DHD_BUS_DATA)) {
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -0700882 bus->intdis = false;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700883 bcmsdh_intr_enable(bus->sdh);
884 }
885 }
886
Roland Vossena1c5ad82011-04-11 15:16:24 +0200887 return 0;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700888}
889
890#if defined(OOB_INTR_ONLY)
891void dhd_enable_oob_intr(struct dhd_bus *bus, bool enable)
892{
893#if defined(HW_OOB)
894 bcmsdh_enable_hw_oob_intr(bus->sdh, enable);
895#else
896 sdpcmd_regs_t *regs = bus->regs;
897 uint retries = 0;
898
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -0700899 dhdsdio_clkctl(bus, CLK_AVAIL, false);
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -0700900 if (enable == true) {
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700901
902 /* Tell device to start using OOB wakeup */
903 W_SDREG(SMB_USE_OOB, &regs->tosbmailbox, retries);
904 if (retries > retry_limit)
905 DHD_ERROR(("CANNOT SIGNAL CHIP, WILL NOT WAKE UP!!\n"));
906
907 } else {
908 /* Send misc interrupt to indicate OOB not needed */
909 W_SDREG(0, &regs->tosbmailboxdata, retries);
910 if (retries <= retry_limit)
911 W_SDREG(SMB_DEV_INT, &regs->tosbmailbox, retries);
912 }
913
914 /* Turn off our contribution to the HT clock request */
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -0700915 dhdsdio_clkctl(bus, CLK_SDONLY, false);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700916#endif /* !defined(HW_OOB) */
917}
918#endif /* defined(OOB_INTR_ONLY) */
919
920#define BUS_WAKE(bus) \
921 do { \
922 if ((bus)->sleeping) \
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -0700923 dhdsdio_bussleep((bus), false); \
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700924 } while (0);
925
926/* Writes a HW/SW header into the packet and sends it. */
927/* Assumes: (a) header space already there, (b) caller holds lock */
Arend van Sprielc26b1372010-11-23 14:06:23 +0100928static int dhdsdio_txpkt(dhd_bus_t *bus, struct sk_buff *pkt, uint chan,
929 bool free_pkt)
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700930{
931 int ret;
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -0700932 u8 *frame;
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -0700933 u16 len, pad = 0;
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700934 u32 swheader;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700935 uint retries = 0;
936 bcmsdh_info_t *sdh;
Arend van Sprielc26b1372010-11-23 14:06:23 +0100937 struct sk_buff *new;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700938 int i;
939
940 DHD_TRACE(("%s: Enter\n", __func__));
941
942 sdh = bus->sdh;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700943
944 if (bus->dhd->dongle_reset) {
Roland Vossenb74ac122011-05-03 11:35:20 +0200945 ret = -EPERM;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700946 goto done;
947 }
948
Arend van Spriel54991ad2010-11-23 14:06:24 +0100949 frame = (u8 *) (pkt->data);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700950
951 /* Add alignment padding, allocate new packet if needed */
Greg Kroah-Hartmanf024c482010-10-21 10:50:21 -0700952 pad = ((unsigned long)frame % DHD_SDALIGN);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700953 if (pad) {
Arend van Spriel3be727c2010-11-23 22:20:30 +0100954 if (skb_headroom(pkt) < pad) {
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700955 DHD_INFO(("%s: insufficient headroom %d for %d pad\n",
Arend van Spriel3be727c2010-11-23 22:20:30 +0100956 __func__, skb_headroom(pkt), pad));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700957 bus->dhd->tx_realloc++;
Henry Ptasinskib33f0e22011-05-10 22:25:29 +0200958 new = bcm_pkt_buf_get_skb(pkt->len + DHD_SDALIGN);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700959 if (!new) {
960 DHD_ERROR(("%s: couldn't allocate new %d-byte "
961 "packet\n",
Arend van Spriel54991ad2010-11-23 14:06:24 +0100962 __func__, pkt->len + DHD_SDALIGN));
Roland Vossene10d82d2011-05-03 11:35:19 +0200963 ret = -ENOMEM;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700964 goto done;
965 }
966
Arend van Spriel3c9d4c32011-03-02 21:18:48 +0100967 PKTALIGN(new, pkt->len, DHD_SDALIGN);
Stanislav Fomichev02160692011-02-15 01:05:10 +0300968 memcpy(new->data, pkt->data, pkt->len);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700969 if (free_pkt)
Henry Ptasinskib33f0e22011-05-10 22:25:29 +0200970 bcm_pkt_buf_free_skb(pkt);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700971 /* free the pkt if canned one is not used */
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -0700972 free_pkt = true;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700973 pkt = new;
Arend van Spriel54991ad2010-11-23 14:06:24 +0100974 frame = (u8 *) (pkt->data);
Greg Kroah-Hartmanf024c482010-10-21 10:50:21 -0700975 ASSERT(((unsigned long)frame % DHD_SDALIGN) == 0);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700976 pad = 0;
977 } else {
Arend van Sprielc303ecb2010-11-18 20:46:43 +0100978 skb_push(pkt, pad);
Arend van Spriel54991ad2010-11-23 14:06:24 +0100979 frame = (u8 *) (pkt->data);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700980
Arend van Spriel54991ad2010-11-23 14:06:24 +0100981 ASSERT((pad + SDPCM_HDRLEN) <= (int)(pkt->len));
Brett Rudley9249ede2010-11-30 20:09:49 -0800982 memset(frame, 0, pad + SDPCM_HDRLEN);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700983 }
984 }
985 ASSERT(pad < DHD_SDALIGN);
986
987 /* Hardware tag: 2 byte len followed by 2 byte ~len check (all LE) */
Arend van Spriel54991ad2010-11-23 14:06:24 +0100988 len = (u16) (pkt->len);
Stanislav Fomichev628f10b2011-02-20 21:43:32 +0300989 *(u16 *) frame = cpu_to_le16(len);
990 *(((u16 *) frame) + 1) = cpu_to_le16(~len);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -0700991
992 /* Software tag: channel, sequence number, data offset */
993 swheader =
994 ((chan << SDPCM_CHANNEL_SHIFT) & SDPCM_CHANNEL_MASK) | bus->tx_seq |
995 (((pad +
996 SDPCM_HDRLEN) << SDPCM_DOFFSET_SHIFT) & SDPCM_DOFFSET_MASK);
Stanislav Fomichev56dfe3c2011-02-20 21:43:33 +0300997
998 put_unaligned_le32(swheader, frame + SDPCM_FRAMETAG_LEN);
999 put_unaligned_le32(0, frame + SDPCM_FRAMETAG_LEN + sizeof(swheader));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001000
1001#ifdef DHD_DEBUG
Arend van Spriel54991ad2010-11-23 14:06:24 +01001002 tx_packets[pkt->priority]++;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001003 if (DHD_BYTES_ON() &&
1004 (((DHD_CTL_ON() && (chan == SDPCM_CONTROL_CHANNEL)) ||
1005 (DHD_DATA_ON() && (chan != SDPCM_CONTROL_CHANNEL))))) {
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02001006 bcm_prhex("Tx Frame", frame, len);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001007 } else if (DHD_HDRS_ON()) {
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02001008 bcm_prhex("TxHdr", frame, min_t(u16, len, 16));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001009 }
1010#endif
1011
1012 /* Raise len to next SDIO block to eliminate tail command */
1013 if (bus->roundup && bus->blocksize && (len > bus->blocksize)) {
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -07001014 u16 pad = bus->blocksize - (len % bus->blocksize);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001015 if ((pad <= bus->roundup) && (pad < bus->blocksize))
1016#ifdef NOTUSED
Arend van Spriel3be727c2010-11-23 22:20:30 +01001017 if (pad <= skb_tailroom(pkt))
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001018#endif /* NOTUSED */
1019 len += pad;
1020 } else if (len % DHD_SDALIGN) {
1021 len += DHD_SDALIGN - (len % DHD_SDALIGN);
1022 }
1023
1024 /* Some controllers have trouble with odd bytes -- round to even */
1025 if (forcealign && (len & (ALIGNMENT - 1))) {
1026#ifdef NOTUSED
Arend van Spriel3be727c2010-11-23 22:20:30 +01001027 if (skb_tailroom(pkt))
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001028#endif
Greg Kroah-Hartmane18d5312010-10-08 11:59:06 -07001029 len = roundup(len, ALIGNMENT);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001030#ifdef NOTUSED
1031 else
1032 DHD_ERROR(("%s: sending unrounded %d-byte packet\n",
1033 __func__, len));
1034#endif
1035 }
1036
1037 do {
1038 ret =
1039 dhd_bcmsdh_send_buf(bus, bcmsdh_cur_sbwad(sdh), SDIO_FUNC_2,
1040 F2SYNC, frame, len, pkt, NULL, NULL);
1041 bus->f2txdata++;
Roland Vossenb7ef2a92011-05-03 11:35:02 +02001042 ASSERT(ret != -BCME_PENDING);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001043
1044 if (ret < 0) {
1045 /* On failure, abort the command
1046 and terminate the frame */
1047 DHD_INFO(("%s: sdio error %d, abort command and "
1048 "terminate frame.\n", __func__, ret));
1049 bus->tx_sderrs++;
1050
1051 bcmsdh_abort(sdh, SDIO_FUNC_2);
1052 bcmsdh_cfg_write(sdh, SDIO_FUNC_1,
1053 SBSDIO_FUNC1_FRAMECTRL, SFC_WF_TERM,
1054 NULL);
1055 bus->f1regdata++;
1056
1057 for (i = 0; i < 3; i++) {
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07001058 u8 hi, lo;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001059 hi = bcmsdh_cfg_read(sdh, SDIO_FUNC_1,
1060 SBSDIO_FUNC1_WFRAMEBCHI,
1061 NULL);
1062 lo = bcmsdh_cfg_read(sdh, SDIO_FUNC_1,
1063 SBSDIO_FUNC1_WFRAMEBCLO,
1064 NULL);
1065 bus->f1regdata += 2;
1066 if ((hi == 0) && (lo == 0))
1067 break;
1068 }
1069
1070 }
1071 if (ret == 0)
1072 bus->tx_seq = (bus->tx_seq + 1) % SDPCM_SEQUENCE_WRAP;
1073
1074 } while ((ret < 0) && retrydata && retries++ < TXRETRIES);
1075
1076done:
1077 /* restore pkt buffer pointer before calling tx complete routine */
Arend van Sprielc303ecb2010-11-18 20:46:43 +01001078 skb_pull(pkt, SDPCM_HDRLEN + pad);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001079 dhd_os_sdunlock(bus->dhd);
1080 dhd_txcomplete(bus->dhd, pkt, ret != 0);
1081 dhd_os_sdlock(bus->dhd);
1082
1083 if (free_pkt)
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02001084 bcm_pkt_buf_free_skb(pkt);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001085
1086 return ret;
1087}
1088
Arend van Sprielc26b1372010-11-23 14:06:23 +01001089int dhd_bus_txdata(struct dhd_bus *bus, struct sk_buff *pkt)
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001090{
Roland Vossenb74ac122011-05-03 11:35:20 +02001091 int ret = -EBADE;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001092 uint datalen, prec;
1093
1094 DHD_TRACE(("%s: Enter\n", __func__));
1095
Arend van Spriel54991ad2010-11-23 14:06:24 +01001096 datalen = pkt->len;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001097
1098#ifdef SDTEST
1099 /* Push the test header if doing loopback */
1100 if (bus->ext_loop) {
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07001101 u8 *data;
Arend van Sprielc303ecb2010-11-18 20:46:43 +01001102 skb_push(pkt, SDPCM_TEST_HDRLEN);
Arend van Spriel54991ad2010-11-23 14:06:24 +01001103 data = pkt->data;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001104 *data++ = SDPCM_TEST_ECHOREQ;
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07001105 *data++ = (u8) bus->loopid++;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001106 *data++ = (datalen >> 0);
1107 *data++ = (datalen >> 8);
1108 datalen += SDPCM_TEST_HDRLEN;
1109 }
1110#endif /* SDTEST */
1111
1112 /* Add space for the header */
Arend van Sprielc303ecb2010-11-18 20:46:43 +01001113 skb_push(pkt, SDPCM_HDRLEN);
Arend van Spriel54991ad2010-11-23 14:06:24 +01001114 ASSERT(IS_ALIGNED((unsigned long)(pkt->data), 2));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001115
Arend van Spriel54991ad2010-11-23 14:06:24 +01001116 prec = PRIO2PREC((pkt->priority & PRIOMASK));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001117
1118 /* Check for existing queue, current flow-control,
1119 pending event, or pending clock */
1120 if (dhd_deferred_tx || bus->fcstate || pktq_len(&bus->txq)
1121 || bus->dpc_sched || (!DATAOK(bus))
1122 || (bus->flowcontrol & NBITVAL(prec))
1123 || (bus->clkstate != CLK_AVAIL)) {
1124 DHD_TRACE(("%s: deferring pktq len %d\n", __func__,
1125 pktq_len(&bus->txq)));
1126 bus->fcqueued++;
1127
1128 /* Priority based enq */
1129 dhd_os_sdlock_txq(bus->dhd);
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07001130 if (dhd_prec_enq(bus->dhd, &bus->txq, pkt, prec) == false) {
Arend van Sprielc303ecb2010-11-18 20:46:43 +01001131 skb_pull(pkt, SDPCM_HDRLEN);
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07001132 dhd_txcomplete(bus->dhd, pkt, false);
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02001133 bcm_pkt_buf_free_skb(pkt);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001134 DHD_ERROR(("%s: out of bus->txq !!!\n", __func__));
Roland Vossene10d82d2011-05-03 11:35:19 +02001135 ret = -ENOSR;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001136 } else {
Roland Vossena1c5ad82011-04-11 15:16:24 +02001137 ret = 0;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001138 }
1139 dhd_os_sdunlock_txq(bus->dhd);
1140
Grant Grundler7c316072011-03-09 15:04:15 -08001141 if (pktq_len(&bus->txq) >= TXHI)
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001142 dhd_txflowcontrol(bus->dhd, 0, ON);
1143
1144#ifdef DHD_DEBUG
1145 if (pktq_plen(&bus->txq, prec) > qcount[prec])
1146 qcount[prec] = pktq_plen(&bus->txq, prec);
1147#endif
1148 /* Schedule DPC if needed to send queued packet(s) */
1149 if (dhd_deferred_tx && !bus->dpc_sched) {
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07001150 bus->dpc_sched = true;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001151 dhd_sched_dpc(bus->dhd);
1152 }
1153 } else {
1154 /* Lock: we're about to use shared data/code (and SDIO) */
1155 dhd_os_sdlock(bus->dhd);
1156
1157 /* Otherwise, send it now */
1158 BUS_WAKE(bus);
1159 /* Make sure back plane ht clk is on, no pending allowed */
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07001160 dhdsdio_clkctl(bus, CLK_AVAIL, true);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001161
1162#ifndef SDTEST
1163 DHD_TRACE(("%s: calling txpkt\n", __func__));
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07001164 ret = dhdsdio_txpkt(bus, pkt, SDPCM_DATA_CHANNEL, true);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001165#else
1166 ret = dhdsdio_txpkt(bus, pkt,
1167 (bus->ext_loop ? SDPCM_TEST_CHANNEL :
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07001168 SDPCM_DATA_CHANNEL), true);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001169#endif
1170 if (ret)
1171 bus->dhd->tx_errors++;
1172 else
1173 bus->dhd->dstats.tx_bytes += datalen;
1174
1175 if ((bus->idletime == DHD_IDLE_IMMEDIATE) && !bus->dpc_sched) {
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07001176 bus->activity = false;
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07001177 dhdsdio_clkctl(bus, CLK_NONE, true);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001178 }
1179
1180 dhd_os_sdunlock(bus->dhd);
1181 }
1182
1183 return ret;
1184}
1185
1186static uint dhdsdio_sendfromq(dhd_bus_t *bus, uint maxframes)
1187{
Arend van Sprielc26b1372010-11-23 14:06:23 +01001188 struct sk_buff *pkt;
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -07001189 u32 intstatus = 0;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001190 uint retries = 0;
1191 int ret = 0, prec_out;
1192 uint cnt = 0;
1193 uint datalen;
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07001194 u8 tx_prec_map;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001195
1196 dhd_pub_t *dhd = bus->dhd;
1197 sdpcmd_regs_t *regs = bus->regs;
1198
1199 DHD_TRACE(("%s: Enter\n", __func__));
1200
1201 tx_prec_map = ~bus->flowcontrol;
1202
1203 /* Send frames until the limit or some other event */
1204 for (cnt = 0; (cnt < maxframes) && DATAOK(bus); cnt++) {
1205 dhd_os_sdlock_txq(bus->dhd);
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02001206 pkt = bcm_pktq_mdeq(&bus->txq, tx_prec_map, &prec_out);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001207 if (pkt == NULL) {
1208 dhd_os_sdunlock_txq(bus->dhd);
1209 break;
1210 }
1211 dhd_os_sdunlock_txq(bus->dhd);
Arend van Spriel54991ad2010-11-23 14:06:24 +01001212 datalen = pkt->len - SDPCM_HDRLEN;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001213
1214#ifndef SDTEST
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07001215 ret = dhdsdio_txpkt(bus, pkt, SDPCM_DATA_CHANNEL, true);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001216#else
1217 ret = dhdsdio_txpkt(bus, pkt,
1218 (bus->ext_loop ? SDPCM_TEST_CHANNEL :
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07001219 SDPCM_DATA_CHANNEL), true);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001220#endif
1221 if (ret)
1222 bus->dhd->tx_errors++;
1223 else
1224 bus->dhd->dstats.tx_bytes += datalen;
1225
1226 /* In poll mode, need to check for other events */
1227 if (!bus->intr && cnt) {
1228 /* Check device status, signal pending interrupt */
1229 R_SDREG(intstatus, &regs->intstatus, retries);
1230 bus->f2txdata++;
1231 if (bcmsdh_regfail(bus->sdh))
1232 break;
1233 if (intstatus & bus->hostintmask)
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07001234 bus->ipend = true;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001235 }
1236 }
1237
1238 /* Deflow-control stack if needed */
Grant Grundler7c316072011-03-09 15:04:15 -08001239 if (dhd->up && (dhd->busstate == DHD_BUS_DATA) &&
Grant Grundler26a71a42011-03-09 10:41:25 -08001240 dhd->txoff && (pktq_len(&bus->txq) < TXLOW))
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001241 dhd_txflowcontrol(dhd, 0, OFF);
1242
1243 return cnt;
1244}
1245
Greg Kroah-Hartman580a0bd2010-10-05 11:09:48 -07001246int dhd_bus_txctl(struct dhd_bus *bus, unsigned char *msg, uint msglen)
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001247{
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07001248 u8 *frame;
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -07001249 u16 len;
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -07001250 u32 swheader;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001251 uint retries = 0;
1252 bcmsdh_info_t *sdh = bus->sdh;
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07001253 u8 doff = 0;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001254 int ret = -1;
1255 int i;
1256
1257 DHD_TRACE(("%s: Enter\n", __func__));
1258
1259 if (bus->dhd->dongle_reset)
1260 return -EIO;
1261
1262 /* Back the pointer to make a room for bus header */
1263 frame = msg - SDPCM_HDRLEN;
1264 len = (msglen += SDPCM_HDRLEN);
1265
1266 /* Add alignment padding (optional for ctl frames) */
1267 if (dhd_alignctl) {
Greg Kroah-Hartmanf024c482010-10-21 10:50:21 -07001268 doff = ((unsigned long)frame % DHD_SDALIGN);
Jason Cooper9b890322010-09-30 15:15:39 -04001269 if (doff) {
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001270 frame -= doff;
1271 len += doff;
1272 msglen += doff;
Brett Rudley9249ede2010-11-30 20:09:49 -08001273 memset(frame, 0, doff + SDPCM_HDRLEN);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001274 }
1275 ASSERT(doff < DHD_SDALIGN);
1276 }
1277 doff += SDPCM_HDRLEN;
1278
1279 /* Round send length to next SDIO block */
1280 if (bus->roundup && bus->blocksize && (len > bus->blocksize)) {
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -07001281 u16 pad = bus->blocksize - (len % bus->blocksize);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001282 if ((pad <= bus->roundup) && (pad < bus->blocksize))
1283 len += pad;
1284 } else if (len % DHD_SDALIGN) {
1285 len += DHD_SDALIGN - (len % DHD_SDALIGN);
1286 }
1287
1288 /* Satisfy length-alignment requirements */
1289 if (forcealign && (len & (ALIGNMENT - 1)))
Greg Kroah-Hartmane18d5312010-10-08 11:59:06 -07001290 len = roundup(len, ALIGNMENT);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001291
Greg Kroah-Hartmanf024c482010-10-21 10:50:21 -07001292 ASSERT(IS_ALIGNED((unsigned long)frame, 2));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001293
1294 /* Need to lock here to protect txseq and SDIO tx calls */
1295 dhd_os_sdlock(bus->dhd);
1296
1297 BUS_WAKE(bus);
1298
1299 /* Make sure backplane clock is on */
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07001300 dhdsdio_clkctl(bus, CLK_AVAIL, false);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001301
1302 /* Hardware tag: 2 byte len followed by 2 byte ~len check (all LE) */
Stanislav Fomichev628f10b2011-02-20 21:43:32 +03001303 *(u16 *) frame = cpu_to_le16((u16) msglen);
1304 *(((u16 *) frame) + 1) = cpu_to_le16(~msglen);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001305
1306 /* Software tag: channel, sequence number, data offset */
1307 swheader =
1308 ((SDPCM_CONTROL_CHANNEL << SDPCM_CHANNEL_SHIFT) &
1309 SDPCM_CHANNEL_MASK)
1310 | bus->tx_seq | ((doff << SDPCM_DOFFSET_SHIFT) &
1311 SDPCM_DOFFSET_MASK);
Stanislav Fomichev56dfe3c2011-02-20 21:43:33 +03001312 put_unaligned_le32(swheader, frame + SDPCM_FRAMETAG_LEN);
1313 put_unaligned_le32(0, frame + SDPCM_FRAMETAG_LEN + sizeof(swheader));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001314
1315 if (!DATAOK(bus)) {
1316 DHD_INFO(("%s: No bus credit bus->tx_max %d, bus->tx_seq %d\n",
1317 __func__, bus->tx_max, bus->tx_seq));
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07001318 bus->ctrl_frame_stat = true;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001319 /* Send from dpc */
1320 bus->ctrl_frame_buf = frame;
1321 bus->ctrl_frame_len = len;
1322
1323 dhd_wait_for_event(bus->dhd, &bus->ctrl_frame_stat);
1324
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07001325 if (bus->ctrl_frame_stat == false) {
1326 DHD_INFO(("%s: ctrl_frame_stat == false\n", __func__));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001327 ret = 0;
1328 } else {
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07001329 DHD_INFO(("%s: ctrl_frame_stat == true\n", __func__));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001330 ret = -1;
1331 }
1332 }
1333
1334 if (ret == -1) {
1335#ifdef DHD_DEBUG
1336 if (DHD_BYTES_ON() && DHD_CTL_ON())
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02001337 bcm_prhex("Tx Frame", frame, len);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001338 else if (DHD_HDRS_ON())
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02001339 bcm_prhex("TxHdr", frame, min_t(u16, len, 16));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001340#endif
1341
1342 do {
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07001343 bus->ctrl_frame_stat = false;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001344 ret =
1345 dhd_bcmsdh_send_buf(bus, bcmsdh_cur_sbwad(sdh),
1346 SDIO_FUNC_2, F2SYNC, frame, len,
1347 NULL, NULL, NULL);
1348
Roland Vossenb7ef2a92011-05-03 11:35:02 +02001349 ASSERT(ret != -BCME_PENDING);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001350
1351 if (ret < 0) {
1352 /* On failure, abort the command and
1353 terminate the frame */
1354 DHD_INFO(("%s: sdio error %d, abort command and terminate frame.\n",
1355 __func__, ret));
1356 bus->tx_sderrs++;
1357
1358 bcmsdh_abort(sdh, SDIO_FUNC_2);
1359
1360 bcmsdh_cfg_write(sdh, SDIO_FUNC_1,
1361 SBSDIO_FUNC1_FRAMECTRL,
1362 SFC_WF_TERM, NULL);
1363 bus->f1regdata++;
1364
1365 for (i = 0; i < 3; i++) {
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07001366 u8 hi, lo;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001367 hi = bcmsdh_cfg_read(sdh, SDIO_FUNC_1,
1368 SBSDIO_FUNC1_WFRAMEBCHI,
1369 NULL);
1370 lo = bcmsdh_cfg_read(sdh, SDIO_FUNC_1,
1371 SBSDIO_FUNC1_WFRAMEBCLO,
1372 NULL);
1373 bus->f1regdata += 2;
1374 if ((hi == 0) && (lo == 0))
1375 break;
1376 }
1377
1378 }
1379 if (ret == 0) {
1380 bus->tx_seq =
1381 (bus->tx_seq + 1) % SDPCM_SEQUENCE_WRAP;
1382 }
1383 } while ((ret < 0) && retries++ < TXRETRIES);
1384 }
1385
1386 if ((bus->idletime == DHD_IDLE_IMMEDIATE) && !bus->dpc_sched) {
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07001387 bus->activity = false;
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07001388 dhdsdio_clkctl(bus, CLK_NONE, true);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001389 }
1390
1391 dhd_os_sdunlock(bus->dhd);
1392
1393 if (ret)
1394 bus->dhd->tx_ctlerrs++;
1395 else
1396 bus->dhd->tx_ctlpkts++;
1397
1398 return ret ? -EIO : 0;
1399}
1400
Greg Kroah-Hartman580a0bd2010-10-05 11:09:48 -07001401int dhd_bus_rxctl(struct dhd_bus *bus, unsigned char *msg, uint msglen)
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001402{
1403 int timeleft;
1404 uint rxlen = 0;
1405 bool pending;
1406
1407 DHD_TRACE(("%s: Enter\n", __func__));
1408
1409 if (bus->dhd->dongle_reset)
1410 return -EIO;
1411
1412 /* Wait until control frame is available */
1413 timeleft = dhd_os_ioctl_resp_wait(bus->dhd, &bus->rxlen, &pending);
1414
1415 dhd_os_sdlock(bus->dhd);
1416 rxlen = bus->rxlen;
Stanislav Fomichev02160692011-02-15 01:05:10 +03001417 memcpy(msg, bus->rxctl, min(msglen, rxlen));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001418 bus->rxlen = 0;
1419 dhd_os_sdunlock(bus->dhd);
1420
1421 if (rxlen) {
1422 DHD_CTL(("%s: resumed on rxctl frame, got %d expected %d\n",
1423 __func__, rxlen, msglen));
1424 } else if (timeleft == 0) {
1425 DHD_ERROR(("%s: resumed on timeout\n", __func__));
1426#ifdef DHD_DEBUG
1427 dhd_os_sdlock(bus->dhd);
1428 dhdsdio_checkdied(bus, NULL, 0);
1429 dhd_os_sdunlock(bus->dhd);
1430#endif /* DHD_DEBUG */
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07001431 } else if (pending == true) {
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001432 DHD_CTL(("%s: cancelled\n", __func__));
1433 return -ERESTARTSYS;
1434 } else {
1435 DHD_CTL(("%s: resumed for unknown reason?\n", __func__));
1436#ifdef DHD_DEBUG
1437 dhd_os_sdlock(bus->dhd);
1438 dhdsdio_checkdied(bus, NULL, 0);
1439 dhd_os_sdunlock(bus->dhd);
1440#endif /* DHD_DEBUG */
1441 }
1442
1443 if (rxlen)
1444 bus->dhd->rx_ctlpkts++;
1445 else
1446 bus->dhd->rx_ctlerrs++;
1447
Jason Coopere9887c92010-10-06 10:08:02 -04001448 return rxlen ? (int)rxlen : -ETIMEDOUT;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001449}
1450
1451/* IOVar table */
1452enum {
1453 IOV_INTR = 1,
1454 IOV_POLLRATE,
1455 IOV_SDREG,
1456 IOV_SBREG,
1457 IOV_SDCIS,
1458 IOV_MEMBYTES,
1459 IOV_MEMSIZE,
1460#ifdef DHD_DEBUG
1461 IOV_CHECKDIED,
1462#endif
1463 IOV_DOWNLOAD,
1464 IOV_FORCEEVEN,
1465 IOV_SDIOD_DRIVE,
1466 IOV_READAHEAD,
1467 IOV_SDRXCHAIN,
1468 IOV_ALIGNCTL,
1469 IOV_SDALIGN,
1470 IOV_DEVRESET,
1471 IOV_CPU,
1472#ifdef SDTEST
1473 IOV_PKTGEN,
1474 IOV_EXTLOOP,
1475#endif /* SDTEST */
1476 IOV_SPROM,
1477 IOV_TXBOUND,
1478 IOV_RXBOUND,
1479 IOV_TXMINMAX,
1480 IOV_IDLETIME,
1481 IOV_IDLECLOCK,
1482 IOV_SD1IDLE,
1483 IOV_SLEEP,
1484 IOV_VARS
1485};
1486
1487const bcm_iovar_t dhdsdio_iovars[] = {
1488 {"intr", IOV_INTR, 0, IOVT_BOOL, 0},
1489 {"sleep", IOV_SLEEP, 0, IOVT_BOOL, 0},
1490 {"pollrate", IOV_POLLRATE, 0, IOVT_UINT32, 0},
1491 {"idletime", IOV_IDLETIME, 0, IOVT_INT32, 0},
1492 {"idleclock", IOV_IDLECLOCK, 0, IOVT_INT32, 0},
1493 {"sd1idle", IOV_SD1IDLE, 0, IOVT_BOOL, 0},
1494 {"membytes", IOV_MEMBYTES, 0, IOVT_BUFFER, 2 * sizeof(int)},
1495 {"memsize", IOV_MEMSIZE, 0, IOVT_UINT32, 0},
1496 {"download", IOV_DOWNLOAD, 0, IOVT_BOOL, 0},
1497 {"vars", IOV_VARS, 0, IOVT_BUFFER, 0},
1498 {"sdiod_drive", IOV_SDIOD_DRIVE, 0, IOVT_UINT32, 0},
1499 {"readahead", IOV_READAHEAD, 0, IOVT_BOOL, 0},
1500 {"sdrxchain", IOV_SDRXCHAIN, 0, IOVT_BOOL, 0},
1501 {"alignctl", IOV_ALIGNCTL, 0, IOVT_BOOL, 0},
1502 {"sdalign", IOV_SDALIGN, 0, IOVT_BOOL, 0},
1503 {"devreset", IOV_DEVRESET, 0, IOVT_BOOL, 0},
1504#ifdef DHD_DEBUG
1505 {"sdreg", IOV_SDREG, 0, IOVT_BUFFER, sizeof(sdreg_t)}
1506 ,
1507 {"sbreg", IOV_SBREG, 0, IOVT_BUFFER, sizeof(sdreg_t)}
1508 ,
1509 {"sd_cis", IOV_SDCIS, 0, IOVT_BUFFER, DHD_IOCTL_MAXLEN}
1510 ,
1511 {"forcealign", IOV_FORCEEVEN, 0, IOVT_BOOL, 0}
1512 ,
1513 {"txbound", IOV_TXBOUND, 0, IOVT_UINT32, 0}
1514 ,
1515 {"rxbound", IOV_RXBOUND, 0, IOVT_UINT32, 0}
1516 ,
1517 {"txminmax", IOV_TXMINMAX, 0, IOVT_UINT32, 0}
1518 ,
1519 {"cpu", IOV_CPU, 0, IOVT_BOOL, 0}
1520 ,
1521#ifdef DHD_DEBUG
1522 {"checkdied", IOV_CHECKDIED, 0, IOVT_BUFFER, 0}
1523 ,
1524#endif /* DHD_DEBUG */
1525#endif /* DHD_DEBUG */
1526#ifdef SDTEST
1527 {"extloop", IOV_EXTLOOP, 0, IOVT_BOOL, 0}
1528 ,
1529 {"pktgen", IOV_PKTGEN, 0, IOVT_BUFFER, sizeof(dhd_pktgen_t)}
1530 ,
1531#endif /* SDTEST */
1532
1533 {NULL, 0, 0, 0, 0}
1534};
1535
1536static void
1537dhd_dump_pct(struct bcmstrbuf *strbuf, char *desc, uint num, uint div)
1538{
1539 uint q1, q2;
1540
1541 if (!div) {
1542 bcm_bprintf(strbuf, "%s N/A", desc);
1543 } else {
1544 q1 = num / div;
1545 q2 = (100 * (num - (q1 * div))) / div;
1546 bcm_bprintf(strbuf, "%s %d.%02d", desc, q1, q2);
1547 }
1548}
1549
1550void dhd_bus_dump(dhd_pub_t *dhdp, struct bcmstrbuf *strbuf)
1551{
1552 dhd_bus_t *bus = dhdp->bus;
1553
1554 bcm_bprintf(strbuf, "Bus SDIO structure:\n");
1555 bcm_bprintf(strbuf,
1556 "hostintmask 0x%08x intstatus 0x%08x sdpcm_ver %d\n",
1557 bus->hostintmask, bus->intstatus, bus->sdpcm_ver);
1558 bcm_bprintf(strbuf,
1559 "fcstate %d qlen %d tx_seq %d, max %d, rxskip %d rxlen %d rx_seq %d\n",
1560 bus->fcstate, pktq_len(&bus->txq), bus->tx_seq, bus->tx_max,
1561 bus->rxskip, bus->rxlen, bus->rx_seq);
1562 bcm_bprintf(strbuf, "intr %d intrcount %d lastintrs %d spurious %d\n",
1563 bus->intr, bus->intrcount, bus->lastintrs, bus->spurious);
1564 bcm_bprintf(strbuf, "pollrate %d pollcnt %d regfails %d\n",
1565 bus->pollrate, bus->pollcnt, bus->regfails);
1566
1567 bcm_bprintf(strbuf, "\nAdditional counters:\n");
1568 bcm_bprintf(strbuf,
1569 "tx_sderrs %d fcqueued %d rxrtx %d rx_toolong %d rxc_errors %d\n",
1570 bus->tx_sderrs, bus->fcqueued, bus->rxrtx, bus->rx_toolong,
1571 bus->rxc_errors);
1572 bcm_bprintf(strbuf, "rx_hdrfail %d badhdr %d badseq %d\n",
1573 bus->rx_hdrfail, bus->rx_badhdr, bus->rx_badseq);
1574 bcm_bprintf(strbuf, "fc_rcvd %d, fc_xoff %d, fc_xon %d\n", bus->fc_rcvd,
1575 bus->fc_xoff, bus->fc_xon);
1576 bcm_bprintf(strbuf, "rxglomfail %d, rxglomframes %d, rxglompkts %d\n",
1577 bus->rxglomfail, bus->rxglomframes, bus->rxglompkts);
1578 bcm_bprintf(strbuf, "f2rx (hdrs/data) %d (%d/%d), f2tx %d f1regs %d\n",
1579 (bus->f2rxhdrs + bus->f2rxdata), bus->f2rxhdrs,
1580 bus->f2rxdata, bus->f2txdata, bus->f1regdata);
1581 {
1582 dhd_dump_pct(strbuf, "\nRx: pkts/f2rd", bus->dhd->rx_packets,
1583 (bus->f2rxhdrs + bus->f2rxdata));
1584 dhd_dump_pct(strbuf, ", pkts/f1sd", bus->dhd->rx_packets,
1585 bus->f1regdata);
1586 dhd_dump_pct(strbuf, ", pkts/sd", bus->dhd->rx_packets,
1587 (bus->f2rxhdrs + bus->f2rxdata + bus->f1regdata));
1588 dhd_dump_pct(strbuf, ", pkts/int", bus->dhd->rx_packets,
1589 bus->intrcount);
1590 bcm_bprintf(strbuf, "\n");
1591
1592 dhd_dump_pct(strbuf, "Rx: glom pct", (100 * bus->rxglompkts),
1593 bus->dhd->rx_packets);
1594 dhd_dump_pct(strbuf, ", pkts/glom", bus->rxglompkts,
1595 bus->rxglomframes);
1596 bcm_bprintf(strbuf, "\n");
1597
1598 dhd_dump_pct(strbuf, "Tx: pkts/f2wr", bus->dhd->tx_packets,
1599 bus->f2txdata);
1600 dhd_dump_pct(strbuf, ", pkts/f1sd", bus->dhd->tx_packets,
1601 bus->f1regdata);
1602 dhd_dump_pct(strbuf, ", pkts/sd", bus->dhd->tx_packets,
1603 (bus->f2txdata + bus->f1regdata));
1604 dhd_dump_pct(strbuf, ", pkts/int", bus->dhd->tx_packets,
1605 bus->intrcount);
1606 bcm_bprintf(strbuf, "\n");
1607
1608 dhd_dump_pct(strbuf, "Total: pkts/f2rw",
1609 (bus->dhd->tx_packets + bus->dhd->rx_packets),
1610 (bus->f2txdata + bus->f2rxhdrs + bus->f2rxdata));
1611 dhd_dump_pct(strbuf, ", pkts/f1sd",
1612 (bus->dhd->tx_packets + bus->dhd->rx_packets),
1613 bus->f1regdata);
1614 dhd_dump_pct(strbuf, ", pkts/sd",
1615 (bus->dhd->tx_packets + bus->dhd->rx_packets),
1616 (bus->f2txdata + bus->f2rxhdrs + bus->f2rxdata +
1617 bus->f1regdata));
1618 dhd_dump_pct(strbuf, ", pkts/int",
1619 (bus->dhd->tx_packets + bus->dhd->rx_packets),
1620 bus->intrcount);
1621 bcm_bprintf(strbuf, "\n\n");
1622 }
1623
1624#ifdef SDTEST
1625 if (bus->pktgen_count) {
1626 bcm_bprintf(strbuf, "pktgen config and count:\n");
1627 bcm_bprintf(strbuf,
1628 "freq %d count %d print %d total %d min %d len %d\n",
1629 bus->pktgen_freq, bus->pktgen_count,
1630 bus->pktgen_print, bus->pktgen_total,
1631 bus->pktgen_minlen, bus->pktgen_maxlen);
1632 bcm_bprintf(strbuf, "send attempts %d rcvd %d fail %d\n",
1633 bus->pktgen_sent, bus->pktgen_rcvd,
1634 bus->pktgen_fail);
1635 }
1636#endif /* SDTEST */
1637#ifdef DHD_DEBUG
1638 bcm_bprintf(strbuf, "dpc_sched %d host interrupt%spending\n",
1639 bus->dpc_sched,
1640 (bcmsdh_intr_pending(bus->sdh) ? " " : " not "));
1641 bcm_bprintf(strbuf, "blocksize %d roundup %d\n", bus->blocksize,
1642 bus->roundup);
1643#endif /* DHD_DEBUG */
1644 bcm_bprintf(strbuf,
1645 "clkstate %d activity %d idletime %d idlecount %d sleeping %d\n",
1646 bus->clkstate, bus->activity, bus->idletime, bus->idlecount,
1647 bus->sleeping);
1648}
1649
1650void dhd_bus_clearcounts(dhd_pub_t *dhdp)
1651{
1652 dhd_bus_t *bus = (dhd_bus_t *) dhdp->bus;
1653
1654 bus->intrcount = bus->lastintrs = bus->spurious = bus->regfails = 0;
1655 bus->rxrtx = bus->rx_toolong = bus->rxc_errors = 0;
1656 bus->rx_hdrfail = bus->rx_badhdr = bus->rx_badseq = 0;
1657 bus->tx_sderrs = bus->fc_rcvd = bus->fc_xoff = bus->fc_xon = 0;
1658 bus->rxglomfail = bus->rxglomframes = bus->rxglompkts = 0;
1659 bus->f2rxhdrs = bus->f2rxdata = bus->f2txdata = bus->f1regdata = 0;
1660}
1661
1662#ifdef SDTEST
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07001663static int dhdsdio_pktgen_get(dhd_bus_t *bus, u8 *arg)
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001664{
1665 dhd_pktgen_t pktgen;
1666
1667 pktgen.version = DHD_PKTGEN_VERSION;
1668 pktgen.freq = bus->pktgen_freq;
1669 pktgen.count = bus->pktgen_count;
1670 pktgen.print = bus->pktgen_print;
1671 pktgen.total = bus->pktgen_total;
1672 pktgen.minlen = bus->pktgen_minlen;
1673 pktgen.maxlen = bus->pktgen_maxlen;
1674 pktgen.numsent = bus->pktgen_sent;
1675 pktgen.numrcvd = bus->pktgen_rcvd;
1676 pktgen.numfail = bus->pktgen_fail;
1677 pktgen.mode = bus->pktgen_mode;
1678 pktgen.stop = bus->pktgen_stop;
1679
Stanislav Fomichev02160692011-02-15 01:05:10 +03001680 memcpy(arg, &pktgen, sizeof(pktgen));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001681
1682 return 0;
1683}
1684
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07001685static int dhdsdio_pktgen_set(dhd_bus_t *bus, u8 *arg)
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001686{
1687 dhd_pktgen_t pktgen;
1688 uint oldcnt, oldmode;
1689
Stanislav Fomichev02160692011-02-15 01:05:10 +03001690 memcpy(&pktgen, arg, sizeof(pktgen));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001691 if (pktgen.version != DHD_PKTGEN_VERSION)
Roland Vossene10d82d2011-05-03 11:35:19 +02001692 return -EINVAL;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001693
1694 oldcnt = bus->pktgen_count;
1695 oldmode = bus->pktgen_mode;
1696
1697 bus->pktgen_freq = pktgen.freq;
1698 bus->pktgen_count = pktgen.count;
1699 bus->pktgen_print = pktgen.print;
1700 bus->pktgen_total = pktgen.total;
1701 bus->pktgen_minlen = pktgen.minlen;
1702 bus->pktgen_maxlen = pktgen.maxlen;
1703 bus->pktgen_mode = pktgen.mode;
1704 bus->pktgen_stop = pktgen.stop;
1705
1706 bus->pktgen_tick = bus->pktgen_ptick = 0;
Greg Kroah-Hartman3ea2f4d2010-10-08 11:39:43 -07001707 bus->pktgen_len = max(bus->pktgen_len, bus->pktgen_minlen);
Greg Kroah-Hartman7068c2f2010-10-08 11:34:59 -07001708 bus->pktgen_len = min(bus->pktgen_len, bus->pktgen_maxlen);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001709
1710 /* Clear counts for a new pktgen (mode change, or was stopped) */
1711 if (bus->pktgen_count && (!oldcnt || oldmode != bus->pktgen_mode))
1712 bus->pktgen_sent = bus->pktgen_rcvd = bus->pktgen_fail = 0;
1713
1714 return 0;
1715}
1716#endif /* SDTEST */
1717
1718static int
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -07001719dhdsdio_membytes(dhd_bus_t *bus, bool write, u32 address, u8 *data,
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001720 uint size)
1721{
1722 int bcmerror = 0;
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -07001723 u32 sdaddr;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001724 uint dsize;
1725
1726 /* Determine initial transfer parameters */
1727 sdaddr = address & SBSDIO_SB_OFT_ADDR_MASK;
1728 if ((sdaddr + size) & SBSDIO_SBWINDOW_MASK)
1729 dsize = (SBSDIO_SB_OFT_ADDR_LIMIT - sdaddr);
1730 else
1731 dsize = size;
1732
1733 /* Set the backplane window to include the start address */
1734 bcmerror = dhdsdio_set_siaddr_window(bus, address);
1735 if (bcmerror) {
1736 DHD_ERROR(("%s: window change failed\n", __func__));
1737 goto xfer_done;
1738 }
1739
1740 /* Do the transfer(s) */
1741 while (size) {
1742 DHD_INFO(("%s: %s %d bytes at offset 0x%08x in window 0x%08x\n",
1743 __func__, (write ? "write" : "read"), dsize,
1744 sdaddr, (address & SBSDIO_SBWINDOW_MASK)));
1745 bcmerror =
1746 bcmsdh_rwdata(bus->sdh, write, sdaddr, data, dsize);
1747 if (bcmerror) {
1748 DHD_ERROR(("%s: membytes transfer failed\n", __func__));
1749 break;
1750 }
1751
1752 /* Adjust for next transfer (if any) */
1753 size -= dsize;
1754 if (size) {
1755 data += dsize;
1756 address += dsize;
1757 bcmerror = dhdsdio_set_siaddr_window(bus, address);
1758 if (bcmerror) {
1759 DHD_ERROR(("%s: window change failed\n",
1760 __func__));
1761 break;
1762 }
1763 sdaddr = 0;
Greg Kroah-Hartmanb61640d2010-10-08 12:37:39 -07001764 dsize = min_t(uint, SBSDIO_SB_OFT_ADDR_LIMIT, size);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001765 }
1766 }
1767
1768xfer_done:
1769 /* Return the window to backplane enumeration space for core access */
1770 if (dhdsdio_set_siaddr_window(bus, bcmsdh_cur_sbwad(bus->sdh))) {
1771 DHD_ERROR(("%s: FAILED to set window back to 0x%x\n",
1772 __func__, bcmsdh_cur_sbwad(bus->sdh)));
1773 }
1774
1775 return bcmerror;
1776}
1777
1778#ifdef DHD_DEBUG
1779static int dhdsdio_readshared(dhd_bus_t *bus, sdpcm_shared_t *sh)
1780{
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -07001781 u32 addr;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001782 int rv;
1783
1784 /* Read last word in memory to determine address of
1785 sdpcm_shared structure */
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07001786 rv = dhdsdio_membytes(bus, false, bus->ramsize - 4, (u8 *)&addr, 4);
Jason Cooper9b890322010-09-30 15:15:39 -04001787 if (rv < 0)
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001788 return rv;
1789
Stanislav Fomichev628f10b2011-02-20 21:43:32 +03001790 addr = le32_to_cpu(addr);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001791
1792 DHD_INFO(("sdpcm_shared address 0x%08X\n", addr));
1793
1794 /*
1795 * Check if addr is valid.
1796 * NVRAM length at the end of memory should have been overwritten.
1797 */
1798 if (addr == 0 || ((~addr >> 16) & 0xffff) == (addr & 0xffff)) {
1799 DHD_ERROR(("%s: address (0x%08x) of sdpcm_shared invalid\n",
1800 __func__, addr));
Roland Vossenb74ac122011-05-03 11:35:20 +02001801 return -EBADE;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001802 }
1803
1804 /* Read hndrte_shared structure */
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07001805 rv = dhdsdio_membytes(bus, false, addr, (u8 *) sh,
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001806 sizeof(sdpcm_shared_t));
1807 if (rv < 0)
1808 return rv;
1809
1810 /* Endianness */
Stanislav Fomichev628f10b2011-02-20 21:43:32 +03001811 sh->flags = le32_to_cpu(sh->flags);
1812 sh->trap_addr = le32_to_cpu(sh->trap_addr);
1813 sh->assert_exp_addr = le32_to_cpu(sh->assert_exp_addr);
1814 sh->assert_file_addr = le32_to_cpu(sh->assert_file_addr);
1815 sh->assert_line = le32_to_cpu(sh->assert_line);
1816 sh->console_addr = le32_to_cpu(sh->console_addr);
1817 sh->msgtrace_addr = le32_to_cpu(sh->msgtrace_addr);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001818
1819 if ((sh->flags & SDPCM_SHARED_VERSION_MASK) != SDPCM_SHARED_VERSION) {
1820 DHD_ERROR(("%s: sdpcm_shared version %d in dhd "
1821 "is different than sdpcm_shared version %d in dongle\n",
1822 __func__, SDPCM_SHARED_VERSION,
1823 sh->flags & SDPCM_SHARED_VERSION_MASK));
Roland Vossenb74ac122011-05-03 11:35:20 +02001824 return -EBADE;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001825 }
1826
Roland Vossena1c5ad82011-04-11 15:16:24 +02001827 return 0;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001828}
1829
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07001830static int dhdsdio_checkdied(dhd_bus_t *bus, u8 *data, uint size)
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001831{
1832 int bcmerror = 0;
1833 uint msize = 512;
1834 char *mbuffer = NULL;
1835 uint maxstrlen = 256;
1836 char *str = NULL;
1837 trap_t tr;
1838 sdpcm_shared_t sdpcm_shared;
1839 struct bcmstrbuf strbuf;
1840
1841 DHD_TRACE(("%s: Enter\n", __func__));
1842
1843 if (data == NULL) {
1844 /*
1845 * Called after a rx ctrl timeout. "data" is NULL.
1846 * allocate memory to trace the trap or assert.
1847 */
1848 size = msize;
mike.rapoport@gmail.com5fcc1fc2010-10-13 00:09:10 +02001849 mbuffer = data = kmalloc(msize, GFP_ATOMIC);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001850 if (mbuffer == NULL) {
mike.rapoport@gmail.com5fcc1fc2010-10-13 00:09:10 +02001851 DHD_ERROR(("%s: kmalloc(%d) failed\n", __func__,
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001852 msize));
Roland Vossene10d82d2011-05-03 11:35:19 +02001853 bcmerror = -ENOMEM;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001854 goto done;
1855 }
1856 }
1857
mike.rapoport@gmail.com5fcc1fc2010-10-13 00:09:10 +02001858 str = kmalloc(maxstrlen, GFP_ATOMIC);
Jason Cooper9b890322010-09-30 15:15:39 -04001859 if (str == NULL) {
mike.rapoport@gmail.com5fcc1fc2010-10-13 00:09:10 +02001860 DHD_ERROR(("%s: kmalloc(%d) failed\n", __func__, maxstrlen));
Roland Vossene10d82d2011-05-03 11:35:19 +02001861 bcmerror = -ENOMEM;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001862 goto done;
1863 }
1864
Jason Cooper9b890322010-09-30 15:15:39 -04001865 bcmerror = dhdsdio_readshared(bus, &sdpcm_shared);
1866 if (bcmerror < 0)
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001867 goto done;
1868
1869 bcm_binit(&strbuf, data, size);
1870
1871 bcm_bprintf(&strbuf,
1872 "msgtrace address : 0x%08X\nconsole address : 0x%08X\n",
1873 sdpcm_shared.msgtrace_addr, sdpcm_shared.console_addr);
1874
1875 if ((sdpcm_shared.flags & SDPCM_SHARED_ASSERT_BUILT) == 0) {
1876 /* NOTE: Misspelled assert is intentional - DO NOT FIX.
1877 * (Avoids conflict with real asserts for programmatic
1878 * parsing of output.)
1879 */
1880 bcm_bprintf(&strbuf, "Assrt not built in dongle\n");
1881 }
1882
1883 if ((sdpcm_shared.flags & (SDPCM_SHARED_ASSERT | SDPCM_SHARED_TRAP)) ==
1884 0) {
1885 /* NOTE: Misspelled assert is intentional - DO NOT FIX.
1886 * (Avoids conflict with real asserts for programmatic
1887 * parsing of output.)
1888 */
1889 bcm_bprintf(&strbuf, "No trap%s in dongle",
1890 (sdpcm_shared.flags & SDPCM_SHARED_ASSERT_BUILT)
1891 ? "/assrt" : "");
1892 } else {
1893 if (sdpcm_shared.flags & SDPCM_SHARED_ASSERT) {
1894 /* Download assert */
1895 bcm_bprintf(&strbuf, "Dongle assert");
1896 if (sdpcm_shared.assert_exp_addr != 0) {
1897 str[0] = '\0';
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07001898 bcmerror = dhdsdio_membytes(bus, false,
Jason Cooper9b890322010-09-30 15:15:39 -04001899 sdpcm_shared.assert_exp_addr,
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07001900 (u8 *) str, maxstrlen);
Jason Cooper9b890322010-09-30 15:15:39 -04001901 if (bcmerror < 0)
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001902 goto done;
1903
1904 str[maxstrlen - 1] = '\0';
1905 bcm_bprintf(&strbuf, " expr \"%s\"", str);
1906 }
1907
1908 if (sdpcm_shared.assert_file_addr != 0) {
1909 str[0] = '\0';
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07001910 bcmerror = dhdsdio_membytes(bus, false,
Jason Cooper9b890322010-09-30 15:15:39 -04001911 sdpcm_shared.assert_file_addr,
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07001912 (u8 *) str, maxstrlen);
Jason Cooper9b890322010-09-30 15:15:39 -04001913 if (bcmerror < 0)
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001914 goto done;
1915
1916 str[maxstrlen - 1] = '\0';
1917 bcm_bprintf(&strbuf, " file \"%s\"", str);
1918 }
1919
1920 bcm_bprintf(&strbuf, " line %d ",
1921 sdpcm_shared.assert_line);
1922 }
1923
1924 if (sdpcm_shared.flags & SDPCM_SHARED_TRAP) {
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07001925 bcmerror = dhdsdio_membytes(bus, false,
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07001926 sdpcm_shared.trap_addr, (u8 *)&tr,
Jason Cooper9b890322010-09-30 15:15:39 -04001927 sizeof(trap_t));
1928 if (bcmerror < 0)
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001929 goto done;
1930
1931 bcm_bprintf(&strbuf,
1932 "Dongle trap type 0x%x @ epc 0x%x, cpsr 0x%x, spsr 0x%x, sp 0x%x,"
1933 "lp 0x%x, rpc 0x%x Trap offset 0x%x, "
1934 "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",
1935 tr.type, tr.epc, tr.cpsr, tr.spsr, tr.r13,
1936 tr.r14, tr.pc, sdpcm_shared.trap_addr,
1937 tr.r0, tr.r1, tr.r2, tr.r3, tr.r4, tr.r5,
1938 tr.r6, tr.r7);
1939 }
1940 }
1941
1942 if (sdpcm_shared.flags & (SDPCM_SHARED_ASSERT | SDPCM_SHARED_TRAP))
1943 DHD_ERROR(("%s: %s\n", __func__, strbuf.origbuf));
1944
1945#ifdef DHD_DEBUG
1946 if (sdpcm_shared.flags & SDPCM_SHARED_TRAP) {
1947 /* Mem dump to a file on device */
1948 dhdsdio_mem_dump(bus);
1949 }
1950#endif /* DHD_DEBUG */
1951
1952done:
Ilia Mirkin46d994b2011-03-13 00:28:56 -05001953 kfree(mbuffer);
1954 kfree(str);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001955
1956 return bcmerror;
1957}
1958
1959static int dhdsdio_mem_dump(dhd_bus_t *bus)
1960{
1961 int ret = 0;
1962 int size; /* Full mem size */
1963 int start = 0; /* Start address */
1964 int read_size = 0; /* Read size of each iteration */
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07001965 u8 *buf = NULL, *databuf = NULL;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001966
1967 /* Get full mem size */
1968 size = bus->ramsize;
mike.rapoport@gmail.com5fcc1fc2010-10-13 00:09:10 +02001969 buf = kmalloc(size, GFP_ATOMIC);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001970 if (!buf) {
Arend van Spriel0bef7742011-02-10 12:03:44 +01001971 DHD_ERROR(("%s: Out of memory (%d bytes)\n", __func__, size));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001972 return -1;
1973 }
1974
1975 /* Read mem content */
Arend van Spriel0bef7742011-02-10 12:03:44 +01001976 printk(KERN_DEBUG "Dump dongle memory");
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001977 databuf = buf;
1978 while (size) {
Greg Kroah-Hartman7068c2f2010-10-08 11:34:59 -07001979 read_size = min(MEMBLOCK, size);
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07001980 ret = dhdsdio_membytes(bus, false, start, databuf, read_size);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001981 if (ret) {
Arend van Spriel0bef7742011-02-10 12:03:44 +01001982 DHD_ERROR(("%s: Error membytes %d\n", __func__, ret));
Ilia Mirkin46d994b2011-03-13 00:28:56 -05001983 kfree(buf);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001984 return -1;
1985 }
Arend van Spriel0bef7742011-02-10 12:03:44 +01001986 printk(".");
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001987
1988 /* Decrement size and increment start address */
1989 size -= read_size;
1990 start += read_size;
1991 databuf += read_size;
1992 }
Arend van Spriel0bef7742011-02-10 12:03:44 +01001993 printk(KERN_DEBUG "Done\n");
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001994
1995 /* free buf before return !!! */
1996 if (write_to_file(bus->dhd, buf, bus->ramsize)) {
Arend van Spriel0bef7742011-02-10 12:03:44 +01001997 DHD_ERROR(("%s: Error writing to files\n", __func__));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07001998 return -1;
1999 }
2000
2001 /* buf free handled in write_to_file, not here */
2002 return 0;
2003}
2004
2005#define CONSOLE_LINE_MAX 192
2006
2007static int dhdsdio_readconsole(dhd_bus_t *bus)
2008{
2009 dhd_console_t *c = &bus->console;
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07002010 u8 line[CONSOLE_LINE_MAX], ch;
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -07002011 u32 n, idx, addr;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002012 int rv;
2013
2014 /* Don't do anything until FWREADY updates console address */
2015 if (bus->console_addr == 0)
2016 return 0;
2017
2018 /* Read console log struct */
Greg Kroah-Hartmance0f1b82010-10-08 11:44:45 -07002019 addr = bus->console_addr + offsetof(hndrte_cons_t, log);
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07002020 rv = dhdsdio_membytes(bus, false, addr, (u8 *)&c->log,
Jason Cooper9b890322010-09-30 15:15:39 -04002021 sizeof(c->log));
2022 if (rv < 0)
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002023 return rv;
2024
2025 /* Allocate console buffer (one time only) */
2026 if (c->buf == NULL) {
Stanislav Fomichev628f10b2011-02-20 21:43:32 +03002027 c->bufsize = le32_to_cpu(c->log.buf_size);
mike.rapoport@gmail.com5fcc1fc2010-10-13 00:09:10 +02002028 c->buf = kmalloc(c->bufsize, GFP_ATOMIC);
Jason Cooper9b890322010-09-30 15:15:39 -04002029 if (c->buf == NULL)
Roland Vossene10d82d2011-05-03 11:35:19 +02002030 return -ENOMEM;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002031 }
2032
Stanislav Fomichev628f10b2011-02-20 21:43:32 +03002033 idx = le32_to_cpu(c->log.idx);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002034
2035 /* Protect against corrupt value */
2036 if (idx > c->bufsize)
Roland Vossenb74ac122011-05-03 11:35:20 +02002037 return -EBADE;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002038
2039 /* Skip reading the console buffer if the index pointer
2040 has not moved */
2041 if (idx == c->last)
Roland Vossena1c5ad82011-04-11 15:16:24 +02002042 return 0;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002043
2044 /* Read the console buffer */
Stanislav Fomichev628f10b2011-02-20 21:43:32 +03002045 addr = le32_to_cpu(c->log.buf);
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07002046 rv = dhdsdio_membytes(bus, false, addr, c->buf, c->bufsize);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002047 if (rv < 0)
2048 return rv;
2049
2050 while (c->last != idx) {
2051 for (n = 0; n < CONSOLE_LINE_MAX - 2; n++) {
2052 if (c->last == idx) {
2053 /* This would output a partial line.
2054 * Instead, back up
2055 * the buffer pointer and output this
2056 * line next time around.
2057 */
2058 if (c->last >= n)
2059 c->last -= n;
2060 else
2061 c->last = c->bufsize - n;
2062 goto break2;
2063 }
2064 ch = c->buf[c->last];
2065 c->last = (c->last + 1) % c->bufsize;
2066 if (ch == '\n')
2067 break;
2068 line[n] = ch;
2069 }
2070
2071 if (n > 0) {
2072 if (line[n - 1] == '\r')
2073 n--;
2074 line[n] = 0;
Arend van Spriel0bef7742011-02-10 12:03:44 +01002075 printk(KERN_DEBUG "CONSOLE: %s\n", line);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002076 }
2077 }
2078break2:
2079
Roland Vossena1c5ad82011-04-11 15:16:24 +02002080 return 0;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002081}
2082#endif /* DHD_DEBUG */
2083
2084int dhdsdio_downloadvars(dhd_bus_t *bus, void *arg, int len)
2085{
Roland Vossena1c5ad82011-04-11 15:16:24 +02002086 int bcmerror = 0;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002087
2088 DHD_TRACE(("%s: Enter\n", __func__));
2089
2090 /* Basic sanity checks */
2091 if (bus->dhd->up) {
Roland Vossenb74ac122011-05-03 11:35:20 +02002092 bcmerror = -EISCONN;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002093 goto err;
2094 }
2095 if (!len) {
Roland Vossene10d82d2011-05-03 11:35:19 +02002096 bcmerror = -EOVERFLOW;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002097 goto err;
2098 }
2099
2100 /* Free the old ones and replace with passed variables */
Ilia Mirkin46d994b2011-03-13 00:28:56 -05002101 kfree(bus->vars);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002102
mike.rapoport@gmail.com5fcc1fc2010-10-13 00:09:10 +02002103 bus->vars = kmalloc(len, GFP_ATOMIC);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002104 bus->varsz = bus->vars ? len : 0;
2105 if (bus->vars == NULL) {
Roland Vossene10d82d2011-05-03 11:35:19 +02002106 bcmerror = -ENOMEM;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002107 goto err;
2108 }
2109
2110 /* Copy the passed variables, which should include the
2111 terminating double-null */
Stanislav Fomichev02160692011-02-15 01:05:10 +03002112 memcpy(bus->vars, arg, bus->varsz);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002113err:
2114 return bcmerror;
2115}
2116
2117static int
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -07002118dhdsdio_doiovar(dhd_bus_t *bus, const bcm_iovar_t *vi, u32 actionid,
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002119 const char *name, void *params, int plen, void *arg, int len,
2120 int val_size)
2121{
2122 int bcmerror = 0;
Greg Kroah-Hartman3e264162010-10-08 11:11:13 -07002123 s32 int_val = 0;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002124 bool bool_val = 0;
2125
2126 DHD_TRACE(("%s: Enter, action %d name %s params %p plen %d arg %p "
2127 "len %d val_size %d\n",
2128 __func__, actionid, name, params, plen, arg, len, val_size));
2129
2130 bcmerror = bcm_iovar_lencheck(vi, arg, len, IOV_ISSET(actionid));
2131 if (bcmerror != 0)
2132 goto exit;
2133
2134 if (plen >= (int)sizeof(int_val))
Stanislav Fomichev02160692011-02-15 01:05:10 +03002135 memcpy(&int_val, params, sizeof(int_val));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002136
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07002137 bool_val = (int_val != 0) ? true : false;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002138
2139 /* Some ioctls use the bus */
2140 dhd_os_sdlock(bus->dhd);
2141
2142 /* Check if dongle is in reset. If so, only allow DEVRESET iovars */
2143 if (bus->dhd->dongle_reset && !(actionid == IOV_SVAL(IOV_DEVRESET) ||
2144 actionid == IOV_GVAL(IOV_DEVRESET))) {
Roland Vossenb74ac122011-05-03 11:35:20 +02002145 bcmerror = -EPERM;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002146 goto exit;
2147 }
2148
2149 /* Handle sleep stuff before any clock mucking */
2150 if (vi->varid == IOV_SLEEP) {
2151 if (IOV_ISSET(actionid)) {
2152 bcmerror = dhdsdio_bussleep(bus, bool_val);
2153 } else {
Greg Kroah-Hartman3e264162010-10-08 11:11:13 -07002154 int_val = (s32) bus->sleeping;
Stanislav Fomichev02160692011-02-15 01:05:10 +03002155 memcpy(arg, &int_val, val_size);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002156 }
2157 goto exit;
2158 }
2159
2160 /* Request clock to allow SDIO accesses */
2161 if (!bus->dhd->dongle_reset) {
2162 BUS_WAKE(bus);
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07002163 dhdsdio_clkctl(bus, CLK_AVAIL, false);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002164 }
2165
2166 switch (actionid) {
2167 case IOV_GVAL(IOV_INTR):
Greg Kroah-Hartman3e264162010-10-08 11:11:13 -07002168 int_val = (s32) bus->intr;
Stanislav Fomichev02160692011-02-15 01:05:10 +03002169 memcpy(arg, &int_val, val_size);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002170 break;
2171
2172 case IOV_SVAL(IOV_INTR):
2173 bus->intr = bool_val;
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07002174 bus->intdis = false;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002175 if (bus->dhd->up) {
2176 if (bus->intr) {
2177 DHD_INTR(("%s: enable SDIO device interrupts\n",
2178 __func__));
2179 bcmsdh_intr_enable(bus->sdh);
2180 } else {
2181 DHD_INTR(("%s: disable SDIO interrupts\n",
2182 __func__));
2183 bcmsdh_intr_disable(bus->sdh);
2184 }
2185 }
2186 break;
2187
2188 case IOV_GVAL(IOV_POLLRATE):
Greg Kroah-Hartman3e264162010-10-08 11:11:13 -07002189 int_val = (s32) bus->pollrate;
Stanislav Fomichev02160692011-02-15 01:05:10 +03002190 memcpy(arg, &int_val, val_size);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002191 break;
2192
2193 case IOV_SVAL(IOV_POLLRATE):
2194 bus->pollrate = (uint) int_val;
2195 bus->poll = (bus->pollrate != 0);
2196 break;
2197
2198 case IOV_GVAL(IOV_IDLETIME):
2199 int_val = bus->idletime;
Stanislav Fomichev02160692011-02-15 01:05:10 +03002200 memcpy(arg, &int_val, val_size);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002201 break;
2202
2203 case IOV_SVAL(IOV_IDLETIME):
2204 if ((int_val < 0) && (int_val != DHD_IDLE_IMMEDIATE))
Roland Vossene10d82d2011-05-03 11:35:19 +02002205 bcmerror = -EINVAL;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002206 else
2207 bus->idletime = int_val;
2208 break;
2209
2210 case IOV_GVAL(IOV_IDLECLOCK):
Greg Kroah-Hartman3e264162010-10-08 11:11:13 -07002211 int_val = (s32) bus->idleclock;
Stanislav Fomichev02160692011-02-15 01:05:10 +03002212 memcpy(arg, &int_val, val_size);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002213 break;
2214
2215 case IOV_SVAL(IOV_IDLECLOCK):
2216 bus->idleclock = int_val;
2217 break;
2218
2219 case IOV_GVAL(IOV_SD1IDLE):
Greg Kroah-Hartman3e264162010-10-08 11:11:13 -07002220 int_val = (s32) sd1idle;
Stanislav Fomichev02160692011-02-15 01:05:10 +03002221 memcpy(arg, &int_val, val_size);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002222 break;
2223
2224 case IOV_SVAL(IOV_SD1IDLE):
2225 sd1idle = bool_val;
2226 break;
2227
2228 case IOV_SVAL(IOV_MEMBYTES):
2229 case IOV_GVAL(IOV_MEMBYTES):
2230 {
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -07002231 u32 address;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002232 uint size, dsize;
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07002233 u8 *data;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002234
2235 bool set = (actionid == IOV_SVAL(IOV_MEMBYTES));
2236
2237 ASSERT(plen >= 2 * sizeof(int));
2238
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -07002239 address = (u32) int_val;
Stanislav Fomichev02160692011-02-15 01:05:10 +03002240 memcpy(&int_val, (char *)params + sizeof(int_val),
2241 sizeof(int_val));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002242 size = (uint) int_val;
2243
2244 /* Do some validation */
2245 dsize = set ? plen - (2 * sizeof(int)) : len;
2246 if (dsize < size) {
2247 DHD_ERROR(("%s: error on %s membytes, addr "
2248 "0x%08x size %d dsize %d\n",
2249 __func__, (set ? "set" : "get"),
2250 address, size, dsize));
Roland Vossene10d82d2011-05-03 11:35:19 +02002251 bcmerror = -EINVAL;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002252 break;
2253 }
2254
2255 DHD_INFO(("%s: Request to %s %d bytes at address "
2256 "0x%08x\n",
2257 __func__, (set ? "write" : "read"), size, address));
2258
2259 /* If we know about SOCRAM, check for a fit */
2260 if ((bus->orig_ramsize) &&
2261 ((address > bus->orig_ramsize)
2262 || (address + size > bus->orig_ramsize))) {
2263 DHD_ERROR(("%s: ramsize 0x%08x doesn't have %d "
2264 "bytes at 0x%08x\n",
2265 __func__, bus->orig_ramsize, size, address));
Roland Vossene10d82d2011-05-03 11:35:19 +02002266 bcmerror = -EINVAL;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002267 break;
2268 }
2269
2270 /* Generate the actual data pointer */
2271 data =
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07002272 set ? (u8 *) params +
2273 2 * sizeof(int) : (u8 *) arg;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002274
2275 /* Call to do the transfer */
2276 bcmerror =
2277 dhdsdio_membytes(bus, set, address, data, size);
2278
2279 break;
2280 }
2281
2282 case IOV_GVAL(IOV_MEMSIZE):
Greg Kroah-Hartman3e264162010-10-08 11:11:13 -07002283 int_val = (s32) bus->ramsize;
Stanislav Fomichev02160692011-02-15 01:05:10 +03002284 memcpy(arg, &int_val, val_size);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002285 break;
2286
2287 case IOV_GVAL(IOV_SDIOD_DRIVE):
Greg Kroah-Hartman3e264162010-10-08 11:11:13 -07002288 int_val = (s32) dhd_sdiod_drive_strength;
Stanislav Fomichev02160692011-02-15 01:05:10 +03002289 memcpy(arg, &int_val, val_size);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002290 break;
2291
2292 case IOV_SVAL(IOV_SDIOD_DRIVE):
2293 dhd_sdiod_drive_strength = int_val;
Franky Lin5d0d7a92011-04-25 19:34:05 -07002294 dhdsdio_sdiod_drive_strength_init(bus,
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002295 dhd_sdiod_drive_strength);
2296 break;
2297
2298 case IOV_SVAL(IOV_DOWNLOAD):
2299 bcmerror = dhdsdio_download_state(bus, bool_val);
2300 break;
2301
2302 case IOV_SVAL(IOV_VARS):
2303 bcmerror = dhdsdio_downloadvars(bus, arg, len);
2304 break;
2305
2306 case IOV_GVAL(IOV_READAHEAD):
Greg Kroah-Hartman3e264162010-10-08 11:11:13 -07002307 int_val = (s32) dhd_readahead;
Stanislav Fomichev02160692011-02-15 01:05:10 +03002308 memcpy(arg, &int_val, val_size);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002309 break;
2310
2311 case IOV_SVAL(IOV_READAHEAD):
2312 if (bool_val && !dhd_readahead)
2313 bus->nextlen = 0;
2314 dhd_readahead = bool_val;
2315 break;
2316
2317 case IOV_GVAL(IOV_SDRXCHAIN):
Greg Kroah-Hartman3e264162010-10-08 11:11:13 -07002318 int_val = (s32) bus->use_rxchain;
Stanislav Fomichev02160692011-02-15 01:05:10 +03002319 memcpy(arg, &int_val, val_size);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002320 break;
2321
2322 case IOV_SVAL(IOV_SDRXCHAIN):
2323 if (bool_val && !bus->sd_rxchain)
Roland Vossene10d82d2011-05-03 11:35:19 +02002324 bcmerror = -ENOTSUPP;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002325 else
2326 bus->use_rxchain = bool_val;
2327 break;
2328 case IOV_GVAL(IOV_ALIGNCTL):
Greg Kroah-Hartman3e264162010-10-08 11:11:13 -07002329 int_val = (s32) dhd_alignctl;
Stanislav Fomichev02160692011-02-15 01:05:10 +03002330 memcpy(arg, &int_val, val_size);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002331 break;
2332
2333 case IOV_SVAL(IOV_ALIGNCTL):
2334 dhd_alignctl = bool_val;
2335 break;
2336
2337 case IOV_GVAL(IOV_SDALIGN):
2338 int_val = DHD_SDALIGN;
Stanislav Fomichev02160692011-02-15 01:05:10 +03002339 memcpy(arg, &int_val, val_size);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002340 break;
2341
2342#ifdef DHD_DEBUG
2343 case IOV_GVAL(IOV_VARS):
2344 if (bus->varsz < (uint) len)
Stanislav Fomichev02160692011-02-15 01:05:10 +03002345 memcpy(arg, bus->vars, bus->varsz);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002346 else
Roland Vossene10d82d2011-05-03 11:35:19 +02002347 bcmerror = -EOVERFLOW;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002348 break;
2349#endif /* DHD_DEBUG */
2350
2351#ifdef DHD_DEBUG
2352 case IOV_GVAL(IOV_SDREG):
2353 {
2354 sdreg_t *sd_ptr;
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -07002355 u32 addr, size;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002356
2357 sd_ptr = (sdreg_t *) params;
2358
Greg Kroah-Hartmanf024c482010-10-21 10:50:21 -07002359 addr = (unsigned long)bus->regs + sd_ptr->offset;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002360 size = sd_ptr->func;
Greg Kroah-Hartman3e264162010-10-08 11:11:13 -07002361 int_val = (s32) bcmsdh_reg_read(bus->sdh, addr, size);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002362 if (bcmsdh_regfail(bus->sdh))
Roland Vossenb74ac122011-05-03 11:35:20 +02002363 bcmerror = -EIO;
Stanislav Fomichev02160692011-02-15 01:05:10 +03002364 memcpy(arg, &int_val, sizeof(s32));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002365 break;
2366 }
2367
2368 case IOV_SVAL(IOV_SDREG):
2369 {
2370 sdreg_t *sd_ptr;
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -07002371 u32 addr, size;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002372
2373 sd_ptr = (sdreg_t *) params;
2374
Greg Kroah-Hartmanf024c482010-10-21 10:50:21 -07002375 addr = (unsigned long)bus->regs + sd_ptr->offset;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002376 size = sd_ptr->func;
2377 bcmsdh_reg_write(bus->sdh, addr, size, sd_ptr->value);
2378 if (bcmsdh_regfail(bus->sdh))
Roland Vossenb74ac122011-05-03 11:35:20 +02002379 bcmerror = -EIO;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002380 break;
2381 }
2382
2383 /* Same as above, but offset is not backplane
2384 (not SDIO core) */
2385 case IOV_GVAL(IOV_SBREG):
2386 {
2387 sdreg_t sdreg;
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -07002388 u32 addr, size;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002389
Stanislav Fomichev02160692011-02-15 01:05:10 +03002390 memcpy(&sdreg, params, sizeof(sdreg));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002391
2392 addr = SI_ENUM_BASE + sdreg.offset;
2393 size = sdreg.func;
Greg Kroah-Hartman3e264162010-10-08 11:11:13 -07002394 int_val = (s32) bcmsdh_reg_read(bus->sdh, addr, size);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002395 if (bcmsdh_regfail(bus->sdh))
Roland Vossenb74ac122011-05-03 11:35:20 +02002396 bcmerror = -EIO;
Stanislav Fomichev02160692011-02-15 01:05:10 +03002397 memcpy(arg, &int_val, sizeof(s32));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002398 break;
2399 }
2400
2401 case IOV_SVAL(IOV_SBREG):
2402 {
2403 sdreg_t sdreg;
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -07002404 u32 addr, size;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002405
Stanislav Fomichev02160692011-02-15 01:05:10 +03002406 memcpy(&sdreg, params, sizeof(sdreg));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002407
2408 addr = SI_ENUM_BASE + sdreg.offset;
2409 size = sdreg.func;
2410 bcmsdh_reg_write(bus->sdh, addr, size, sdreg.value);
2411 if (bcmsdh_regfail(bus->sdh))
Roland Vossenb74ac122011-05-03 11:35:20 +02002412 bcmerror = -EIO;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002413 break;
2414 }
2415
2416 case IOV_GVAL(IOV_SDCIS):
2417 {
2418 *(char *)arg = 0;
2419
nohee koea3b8a22010-10-09 10:34:38 -07002420 strcat(arg, "\nFunc 0\n");
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002421 bcmsdh_cis_read(bus->sdh, 0x10,
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07002422 (u8 *) arg + strlen(arg),
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002423 SBSDIO_CIS_SIZE_LIMIT);
nohee koea3b8a22010-10-09 10:34:38 -07002424 strcat(arg, "\nFunc 1\n");
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002425 bcmsdh_cis_read(bus->sdh, 0x11,
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07002426 (u8 *) arg + strlen(arg),
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002427 SBSDIO_CIS_SIZE_LIMIT);
nohee koea3b8a22010-10-09 10:34:38 -07002428 strcat(arg, "\nFunc 2\n");
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002429 bcmsdh_cis_read(bus->sdh, 0x12,
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07002430 (u8 *) arg + strlen(arg),
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002431 SBSDIO_CIS_SIZE_LIMIT);
2432 break;
2433 }
2434
2435 case IOV_GVAL(IOV_FORCEEVEN):
Greg Kroah-Hartman3e264162010-10-08 11:11:13 -07002436 int_val = (s32) forcealign;
Stanislav Fomichev02160692011-02-15 01:05:10 +03002437 memcpy(arg, &int_val, val_size);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002438 break;
2439
2440 case IOV_SVAL(IOV_FORCEEVEN):
2441 forcealign = bool_val;
2442 break;
2443
2444 case IOV_GVAL(IOV_TXBOUND):
Greg Kroah-Hartman3e264162010-10-08 11:11:13 -07002445 int_val = (s32) dhd_txbound;
Stanislav Fomichev02160692011-02-15 01:05:10 +03002446 memcpy(arg, &int_val, val_size);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002447 break;
2448
2449 case IOV_SVAL(IOV_TXBOUND):
2450 dhd_txbound = (uint) int_val;
2451 break;
2452
2453 case IOV_GVAL(IOV_RXBOUND):
Greg Kroah-Hartman3e264162010-10-08 11:11:13 -07002454 int_val = (s32) dhd_rxbound;
Stanislav Fomichev02160692011-02-15 01:05:10 +03002455 memcpy(arg, &int_val, val_size);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002456 break;
2457
2458 case IOV_SVAL(IOV_RXBOUND):
2459 dhd_rxbound = (uint) int_val;
2460 break;
2461
2462 case IOV_GVAL(IOV_TXMINMAX):
Greg Kroah-Hartman3e264162010-10-08 11:11:13 -07002463 int_val = (s32) dhd_txminmax;
Stanislav Fomichev02160692011-02-15 01:05:10 +03002464 memcpy(arg, &int_val, val_size);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002465 break;
2466
2467 case IOV_SVAL(IOV_TXMINMAX):
2468 dhd_txminmax = (uint) int_val;
2469 break;
2470#endif /* DHD_DEBUG */
2471
2472#ifdef SDTEST
2473 case IOV_GVAL(IOV_EXTLOOP):
Greg Kroah-Hartman3e264162010-10-08 11:11:13 -07002474 int_val = (s32) bus->ext_loop;
Stanislav Fomichev02160692011-02-15 01:05:10 +03002475 memcpy(arg, &int_val, val_size);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002476 break;
2477
2478 case IOV_SVAL(IOV_EXTLOOP):
2479 bus->ext_loop = bool_val;
2480 break;
2481
2482 case IOV_GVAL(IOV_PKTGEN):
2483 bcmerror = dhdsdio_pktgen_get(bus, arg);
2484 break;
2485
2486 case IOV_SVAL(IOV_PKTGEN):
2487 bcmerror = dhdsdio_pktgen_set(bus, arg);
2488 break;
2489#endif /* SDTEST */
2490
2491 case IOV_SVAL(IOV_DEVRESET):
2492 DHD_TRACE(("%s: Called set IOV_DEVRESET=%d dongle_reset=%d "
2493 "busstate=%d\n",
2494 __func__, bool_val, bus->dhd->dongle_reset,
2495 bus->dhd->busstate));
2496
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07002497 dhd_bus_devreset(bus->dhd, (u8) bool_val);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002498
2499 break;
2500
2501 case IOV_GVAL(IOV_DEVRESET):
2502 DHD_TRACE(("%s: Called get IOV_DEVRESET\n", __func__));
2503
2504 /* Get its status */
2505 int_val = (bool) bus->dhd->dongle_reset;
Stanislav Fomichev02160692011-02-15 01:05:10 +03002506 memcpy(arg, &int_val, val_size);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002507
2508 break;
2509
2510 default:
Roland Vossene10d82d2011-05-03 11:35:19 +02002511 bcmerror = -ENOTSUPP;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002512 break;
2513 }
2514
2515exit:
2516 if ((bus->idletime == DHD_IDLE_IMMEDIATE) && !bus->dpc_sched) {
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07002517 bus->activity = false;
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07002518 dhdsdio_clkctl(bus, CLK_NONE, true);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002519 }
2520
2521 dhd_os_sdunlock(bus->dhd);
2522
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07002523 if (actionid == IOV_SVAL(IOV_DEVRESET) && bool_val == false)
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002524 dhd_preinit_ioctls((dhd_pub_t *) bus->dhd);
2525
2526 return bcmerror;
2527}
2528
2529static int dhdsdio_write_vars(dhd_bus_t *bus)
2530{
2531 int bcmerror = 0;
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -07002532 u32 varsize;
2533 u32 varaddr;
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07002534 u8 *vbuffer;
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -07002535 u32 varsizew;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002536#ifdef DHD_DEBUG
2537 char *nvram_ularray;
2538#endif /* DHD_DEBUG */
2539
2540 /* Even if there are no vars are to be written, we still
2541 need to set the ramsize. */
Greg Kroah-Hartmane18d5312010-10-08 11:59:06 -07002542 varsize = bus->varsz ? roundup(bus->varsz, 4) : 0;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002543 varaddr = (bus->ramsize - 4) - varsize;
2544
2545 if (bus->vars) {
Alexander Beregalov12d0eb42011-03-09 03:53:35 +03002546 vbuffer = kzalloc(varsize, GFP_ATOMIC);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002547 if (!vbuffer)
Roland Vossene10d82d2011-05-03 11:35:19 +02002548 return -ENOMEM;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002549
Stanislav Fomichev02160692011-02-15 01:05:10 +03002550 memcpy(vbuffer, bus->vars, bus->varsz);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002551
2552 /* Write the vars list */
2553 bcmerror =
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07002554 dhdsdio_membytes(bus, true, varaddr, vbuffer, varsize);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002555#ifdef DHD_DEBUG
2556 /* Verify NVRAM bytes */
2557 DHD_INFO(("Compare NVRAM dl & ul; varsize=%d\n", varsize));
mike.rapoport@gmail.com5fcc1fc2010-10-13 00:09:10 +02002558 nvram_ularray = kmalloc(varsize, GFP_ATOMIC);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002559 if (!nvram_ularray)
Roland Vossene10d82d2011-05-03 11:35:19 +02002560 return -ENOMEM;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002561
2562 /* Upload image to verify downloaded contents. */
2563 memset(nvram_ularray, 0xaa, varsize);
2564
2565 /* Read the vars list to temp buffer for comparison */
2566 bcmerror =
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07002567 dhdsdio_membytes(bus, false, varaddr, nvram_ularray,
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002568 varsize);
2569 if (bcmerror) {
2570 DHD_ERROR(("%s: error %d on reading %d nvram bytes at "
2571 "0x%08x\n", __func__, bcmerror, varsize, varaddr));
2572 }
2573 /* Compare the org NVRAM with the one read from RAM */
2574 if (memcmp(vbuffer, nvram_ularray, varsize)) {
2575 DHD_ERROR(("%s: Downloaded NVRAM image is corrupted.\n",
2576 __func__));
2577 } else
2578 DHD_ERROR(("%s: Download/Upload/Compare of NVRAM ok.\n",
2579 __func__));
2580
mike.rapoport@gmail.com182acb32010-10-13 00:09:12 +02002581 kfree(nvram_ularray);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002582#endif /* DHD_DEBUG */
2583
mike.rapoport@gmail.com182acb32010-10-13 00:09:12 +02002584 kfree(vbuffer);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002585 }
2586
2587 /* adjust to the user specified RAM */
2588 DHD_INFO(("Physical memory size: %d, usable memory size: %d\n",
2589 bus->orig_ramsize, bus->ramsize));
2590 DHD_INFO(("Vars are at %d, orig varsize is %d\n", varaddr, varsize));
2591 varsize = ((bus->orig_ramsize - 4) - varaddr);
2592
2593 /*
2594 * Determine the length token:
2595 * Varsize, converted to words, in lower 16-bits, checksum
2596 * in upper 16-bits.
2597 */
2598 if (bcmerror) {
2599 varsizew = 0;
2600 } else {
2601 varsizew = varsize / 4;
2602 varsizew = (~varsizew << 16) | (varsizew & 0x0000FFFF);
Stanislav Fomichev628f10b2011-02-20 21:43:32 +03002603 varsizew = cpu_to_le32(varsizew);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002604 }
2605
2606 DHD_INFO(("New varsize is %d, length token=0x%08x\n", varsize,
2607 varsizew));
2608
2609 /* Write the length token to the last word */
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07002610 bcmerror = dhdsdio_membytes(bus, true, (bus->orig_ramsize - 4),
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07002611 (u8 *)&varsizew, 4);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002612
2613 return bcmerror;
2614}
2615
2616static int dhdsdio_download_state(dhd_bus_t *bus, bool enter)
2617{
2618 uint retries;
Franky Lineb5dc512011-04-25 19:34:04 -07002619 u32 regdata;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002620 int bcmerror = 0;
2621
2622 /* To enter download state, disable ARM and reset SOCRAM.
2623 * To exit download state, simply reset ARM (default is RAM boot).
2624 */
2625 if (enter) {
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07002626 bus->alp_only = true;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002627
Franky Lineb5dc512011-04-25 19:34:04 -07002628 dhdsdio_chip_disablecore(bus->sdh, bus->ci->armcorebase);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002629
Franky Lineb5dc512011-04-25 19:34:04 -07002630 dhdsdio_chip_resetcore(bus->sdh, bus->ci->ramcorebase);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002631
2632 /* Clear the top bit of memory */
2633 if (bus->ramsize) {
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -07002634 u32 zeros = 0;
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07002635 dhdsdio_membytes(bus, true, bus->ramsize - 4,
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07002636 (u8 *)&zeros, 4);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002637 }
2638 } else {
Franky Lineb5dc512011-04-25 19:34:04 -07002639 regdata = bcmsdh_reg_read(bus->sdh,
2640 CORE_SB(bus->ci->ramcorebase, sbtmstatelow), 4);
2641 regdata &= (SBTML_RESET | SBTML_REJ_MASK |
2642 (SICF_CLOCK_EN << SBTML_SICF_SHIFT));
2643 if ((SICF_CLOCK_EN << SBTML_SICF_SHIFT) != regdata) {
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002644 DHD_ERROR(("%s: SOCRAM core is down after reset?\n",
2645 __func__));
Roland Vossenb74ac122011-05-03 11:35:20 +02002646 bcmerror = -EBADE;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002647 goto fail;
2648 }
2649
2650 bcmerror = dhdsdio_write_vars(bus);
2651 if (bcmerror) {
2652 DHD_ERROR(("%s: no vars written to RAM\n", __func__));
2653 bcmerror = 0;
2654 }
2655
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002656 W_SDREG(0xFFFFFFFF, &bus->regs->intstatus, retries);
2657
Franky Lineb5dc512011-04-25 19:34:04 -07002658 dhdsdio_chip_resetcore(bus->sdh, bus->ci->armcorebase);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002659
2660 /* Allow HT Clock now that the ARM is running. */
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07002661 bus->alp_only = false;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002662
2663 bus->dhd->busstate = DHD_BUS_LOAD;
2664 }
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002665fail:
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002666 return bcmerror;
2667}
2668
2669int
2670dhd_bus_iovar_op(dhd_pub_t *dhdp, const char *name,
2671 void *params, int plen, void *arg, int len, bool set)
2672{
2673 dhd_bus_t *bus = dhdp->bus;
2674 const bcm_iovar_t *vi = NULL;
2675 int bcmerror = 0;
2676 int val_size;
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -07002677 u32 actionid;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002678
2679 DHD_TRACE(("%s: Enter\n", __func__));
2680
2681 ASSERT(name);
2682 ASSERT(len >= 0);
2683
2684 /* Get MUST have return space */
2685 ASSERT(set || (arg && len));
2686
2687 /* Set does NOT take qualifiers */
2688 ASSERT(!set || (!params && !plen));
2689
2690 /* Look up var locally; if not found pass to host driver */
2691 vi = bcm_iovar_lookup(dhdsdio_iovars, name);
2692 if (vi == NULL) {
2693 dhd_os_sdlock(bus->dhd);
2694
2695 BUS_WAKE(bus);
2696
2697 /* Turn on clock in case SD command needs backplane */
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07002698 dhdsdio_clkctl(bus, CLK_AVAIL, false);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002699
2700 bcmerror =
2701 bcmsdh_iovar_op(bus->sdh, name, params, plen, arg, len,
2702 set);
2703
2704 /* Check for bus configuration changes of interest */
2705
2706 /* If it was divisor change, read the new one */
2707 if (set && strcmp(name, "sd_divisor") == 0) {
2708 if (bcmsdh_iovar_op(bus->sdh, "sd_divisor", NULL, 0,
Greg Kroah-Hartman3e264162010-10-08 11:11:13 -07002709 &bus->sd_divisor, sizeof(s32),
Roland Vossena1c5ad82011-04-11 15:16:24 +02002710 false) != 0) {
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002711 bus->sd_divisor = -1;
2712 DHD_ERROR(("%s: fail on %s get\n", __func__,
2713 name));
2714 } else {
2715 DHD_INFO(("%s: noted %s update, value now %d\n",
2716 __func__, name, bus->sd_divisor));
2717 }
2718 }
2719 /* If it was a mode change, read the new one */
2720 if (set && strcmp(name, "sd_mode") == 0) {
2721 if (bcmsdh_iovar_op(bus->sdh, "sd_mode", NULL, 0,
Greg Kroah-Hartman3e264162010-10-08 11:11:13 -07002722 &bus->sd_mode, sizeof(s32),
Roland Vossena1c5ad82011-04-11 15:16:24 +02002723 false) != 0) {
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002724 bus->sd_mode = -1;
2725 DHD_ERROR(("%s: fail on %s get\n", __func__,
2726 name));
2727 } else {
2728 DHD_INFO(("%s: noted %s update, value now %d\n",
2729 __func__, name, bus->sd_mode));
2730 }
2731 }
2732 /* Similar check for blocksize change */
2733 if (set && strcmp(name, "sd_blocksize") == 0) {
Greg Kroah-Hartman3e264162010-10-08 11:11:13 -07002734 s32 fnum = 2;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002735 if (bcmsdh_iovar_op
Greg Kroah-Hartman3e264162010-10-08 11:11:13 -07002736 (bus->sdh, "sd_blocksize", &fnum, sizeof(s32),
2737 &bus->blocksize, sizeof(s32),
Roland Vossena1c5ad82011-04-11 15:16:24 +02002738 false) != 0) {
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002739 bus->blocksize = 0;
2740 DHD_ERROR(("%s: fail on %s get\n", __func__,
2741 "sd_blocksize"));
2742 } else {
2743 DHD_INFO(("%s: noted %s update, value now %d\n",
2744 __func__, "sd_blocksize",
2745 bus->blocksize));
2746 }
2747 }
Greg Kroah-Hartman7068c2f2010-10-08 11:34:59 -07002748 bus->roundup = min(max_roundup, bus->blocksize);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002749
2750 if ((bus->idletime == DHD_IDLE_IMMEDIATE) && !bus->dpc_sched) {
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07002751 bus->activity = false;
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07002752 dhdsdio_clkctl(bus, CLK_NONE, true);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002753 }
2754
2755 dhd_os_sdunlock(bus->dhd);
2756 goto exit;
2757 }
2758
2759 DHD_CTL(("%s: %s %s, len %d plen %d\n", __func__,
2760 name, (set ? "set" : "get"), len, plen));
2761
2762 /* set up 'params' pointer in case this is a set command so that
2763 * the convenience int and bool code can be common to set and get
2764 */
2765 if (params == NULL) {
2766 params = arg;
2767 plen = len;
2768 }
2769
2770 if (vi->type == IOVT_VOID)
2771 val_size = 0;
2772 else if (vi->type == IOVT_BUFFER)
2773 val_size = len;
2774 else
2775 /* all other types are integer sized */
2776 val_size = sizeof(int);
2777
2778 actionid = set ? IOV_SVAL(vi->varid) : IOV_GVAL(vi->varid);
2779 bcmerror =
2780 dhdsdio_doiovar(bus, vi, actionid, name, params, plen, arg, len,
2781 val_size);
2782
2783exit:
2784 return bcmerror;
2785}
2786
2787void dhd_bus_stop(struct dhd_bus *bus, bool enforce_mutex)
2788{
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -07002789 u32 local_hostintmask;
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07002790 u8 saveclk;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002791 uint retries;
2792 int err;
2793
2794 DHD_TRACE(("%s: Enter\n", __func__));
2795
2796 if (enforce_mutex)
2797 dhd_os_sdlock(bus->dhd);
2798
2799 BUS_WAKE(bus);
2800
2801 /* Enable clock for device interrupts */
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07002802 dhdsdio_clkctl(bus, CLK_AVAIL, false);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002803
2804 /* Disable and clear interrupts at the chip level also */
2805 W_SDREG(0, &bus->regs->hostintmask, retries);
2806 local_hostintmask = bus->hostintmask;
2807 bus->hostintmask = 0;
2808
2809 /* Change our idea of bus state */
2810 bus->dhd->busstate = DHD_BUS_DOWN;
2811
2812 /* Force clocks on backplane to be sure F2 interrupt propagates */
2813 saveclk =
2814 bcmsdh_cfg_read(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR,
2815 &err);
2816 if (!err) {
2817 bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR,
2818 (saveclk | SBSDIO_FORCE_HT), &err);
2819 }
2820 if (err) {
2821 DHD_ERROR(("%s: Failed to force clock for F2: err %d\n",
2822 __func__, err));
2823 }
2824
2825 /* Turn off the bus (F2), free any pending packets */
2826 DHD_INTR(("%s: disable SDIO interrupts\n", __func__));
2827 bcmsdh_intr_disable(bus->sdh);
2828 bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_0, SDIOD_CCCR_IOEN,
2829 SDIO_FUNC_ENABLE_1, NULL);
2830
2831 /* Clear any pending interrupts now that F2 is disabled */
2832 W_SDREG(local_hostintmask, &bus->regs->intstatus, retries);
2833
2834 /* Turn off the backplane clock (only) */
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07002835 dhdsdio_clkctl(bus, CLK_SDONLY, false);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002836
2837 /* Clear the data packet queues */
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02002838 bcm_pktq_flush(&bus->txq, true, NULL, 0);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002839
2840 /* Clear any held glomming stuff */
2841 if (bus->glomd)
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02002842 bcm_pkt_buf_free_skb(bus->glomd);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002843
2844 if (bus->glom)
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02002845 bcm_pkt_buf_free_skb(bus->glom);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002846
2847 bus->glom = bus->glomd = NULL;
2848
2849 /* Clear rx control and wake any waiters */
2850 bus->rxlen = 0;
2851 dhd_os_ioctl_resp_wake(bus->dhd);
2852
2853 /* Reset some F2 state stuff */
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07002854 bus->rxskip = false;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002855 bus->tx_seq = bus->rx_seq = 0;
2856
2857 if (enforce_mutex)
2858 dhd_os_sdunlock(bus->dhd);
2859}
2860
2861int dhd_bus_init(dhd_pub_t *dhdp, bool enforce_mutex)
2862{
2863 dhd_bus_t *bus = dhdp->bus;
2864 dhd_timeout_t tmo;
2865 uint retries = 0;
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07002866 u8 ready, enable;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002867 int err, ret = 0;
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07002868 u8 saveclk;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002869
2870 DHD_TRACE(("%s: Enter\n", __func__));
2871
2872 ASSERT(bus->dhd);
2873 if (!bus->dhd)
2874 return 0;
2875
2876 if (enforce_mutex)
2877 dhd_os_sdlock(bus->dhd);
2878
2879 /* Make sure backplane clock is on, needed to generate F2 interrupt */
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07002880 dhdsdio_clkctl(bus, CLK_AVAIL, false);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002881 if (bus->clkstate != CLK_AVAIL)
2882 goto exit;
2883
2884 /* Force clocks on backplane to be sure F2 interrupt propagates */
2885 saveclk =
2886 bcmsdh_cfg_read(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR,
2887 &err);
2888 if (!err) {
2889 bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR,
2890 (saveclk | SBSDIO_FORCE_HT), &err);
2891 }
2892 if (err) {
2893 DHD_ERROR(("%s: Failed to force clock for F2: err %d\n",
2894 __func__, err));
2895 goto exit;
2896 }
2897
2898 /* Enable function 2 (frame transfers) */
2899 W_SDREG((SDPCM_PROT_VERSION << SMB_DATA_VERSION_SHIFT),
2900 &bus->regs->tosbmailboxdata, retries);
2901 enable = (SDIO_FUNC_ENABLE_1 | SDIO_FUNC_ENABLE_2);
2902
2903 bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_0, SDIOD_CCCR_IOEN, enable, NULL);
2904
2905 /* Give the dongle some time to do its thing and set IOR2 */
2906 dhd_timeout_start(&tmo, DHD_WAIT_F2RDY * 1000);
2907
2908 ready = 0;
2909 while (ready != enable && !dhd_timeout_expired(&tmo))
2910 ready =
2911 bcmsdh_cfg_read(bus->sdh, SDIO_FUNC_0, SDIOD_CCCR_IORDY,
2912 NULL);
2913
2914 DHD_INFO(("%s: enable 0x%02x, ready 0x%02x (waited %uus)\n",
2915 __func__, enable, ready, tmo.elapsed));
2916
2917 /* If F2 successfully enabled, set core and enable interrupts */
2918 if (ready == enable) {
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002919 /* Set up the interrupt mask and enable interrupts */
2920 bus->hostintmask = HOSTINTMASK;
Franky Linc05df632011-04-25 19:34:07 -07002921 W_SDREG(bus->hostintmask,
2922 (unsigned int *)CORE_BUS_REG(bus->ci->buscorebase,
2923 hostintmask), retries);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002924
2925 bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_WATERMARK,
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07002926 (u8) watermark, &err);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002927
2928 /* Set bus state according to enable result */
2929 dhdp->busstate = DHD_BUS_DATA;
2930
2931 /* bcmsdh_intr_unmask(bus->sdh); */
2932
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07002933 bus->intdis = false;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002934 if (bus->intr) {
2935 DHD_INTR(("%s: enable SDIO device interrupts\n",
2936 __func__));
2937 bcmsdh_intr_enable(bus->sdh);
2938 } else {
2939 DHD_INTR(("%s: disable SDIO interrupts\n", __func__));
2940 bcmsdh_intr_disable(bus->sdh);
2941 }
2942
2943 }
2944
2945 else {
2946 /* Disable F2 again */
2947 enable = SDIO_FUNC_ENABLE_1;
2948 bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_0, SDIOD_CCCR_IOEN, enable,
2949 NULL);
2950 }
2951
2952 /* Restore previous clock setting */
2953 bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR,
2954 saveclk, &err);
2955
2956 /* If we didn't come up, turn off backplane clock */
2957 if (dhdp->busstate != DHD_BUS_DATA)
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07002958 dhdsdio_clkctl(bus, CLK_NONE, false);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002959
2960exit:
2961 if (enforce_mutex)
2962 dhd_os_sdunlock(bus->dhd);
2963
2964 return ret;
2965}
2966
2967static void dhdsdio_rxfail(dhd_bus_t *bus, bool abort, bool rtx)
2968{
2969 bcmsdh_info_t *sdh = bus->sdh;
2970 sdpcmd_regs_t *regs = bus->regs;
2971 uint retries = 0;
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -07002972 u16 lastrbc;
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07002973 u8 hi, lo;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07002974 int err;
2975
2976 DHD_ERROR(("%s: %sterminate frame%s\n", __func__,
2977 (abort ? "abort command, " : ""),
2978 (rtx ? ", send NAK" : "")));
2979
2980 if (abort)
2981 bcmsdh_abort(sdh, SDIO_FUNC_2);
2982
2983 bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_FRAMECTRL, SFC_RF_TERM,
2984 &err);
2985 bus->f1regdata++;
2986
2987 /* Wait until the packet has been flushed (device/FIFO stable) */
2988 for (lastrbc = retries = 0xffff; retries > 0; retries--) {
2989 hi = bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_RFRAMEBCHI,
2990 NULL);
2991 lo = bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_RFRAMEBCLO,
2992 NULL);
2993 bus->f1regdata += 2;
2994
2995 if ((hi == 0) && (lo == 0))
2996 break;
2997
2998 if ((hi > (lastrbc >> 8)) && (lo > (lastrbc & 0x00ff))) {
2999 DHD_ERROR(("%s: count growing: last 0x%04x now "
3000 "0x%04x\n",
3001 __func__, lastrbc, ((hi << 8) + lo)));
3002 }
3003 lastrbc = (hi << 8) + lo;
3004 }
3005
3006 if (!retries) {
3007 DHD_ERROR(("%s: count never zeroed: last 0x%04x\n",
3008 __func__, lastrbc));
3009 } else {
3010 DHD_INFO(("%s: flush took %d iterations\n", __func__,
3011 (0xffff - retries)));
3012 }
3013
3014 if (rtx) {
3015 bus->rxrtx++;
3016 W_SDREG(SMB_NAK, &regs->tosbmailbox, retries);
3017 bus->f1regdata++;
3018 if (retries <= retry_limit)
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07003019 bus->rxskip = true;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003020 }
3021
3022 /* Clear partial in any case */
3023 bus->nextlen = 0;
3024
3025 /* If we can't reach the device, signal failure */
3026 if (err || bcmsdh_regfail(sdh))
3027 bus->dhd->busstate = DHD_BUS_DOWN;
3028}
3029
3030static void
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07003031dhdsdio_read_control(dhd_bus_t *bus, u8 *hdr, uint len, uint doff)
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003032{
3033 bcmsdh_info_t *sdh = bus->sdh;
3034 uint rdlen, pad;
3035
3036 int sdret;
3037
3038 DHD_TRACE(("%s: Enter\n", __func__));
3039
3040 /* Control data already received in aligned rxctl */
3041 if ((bus->bus == SPI_BUS) && (!bus->usebufpool))
3042 goto gotpkt;
3043
3044 ASSERT(bus->rxbuf);
3045 /* Set rxctl for frame (w/optional alignment) */
3046 bus->rxctl = bus->rxbuf;
3047 if (dhd_alignctl) {
3048 bus->rxctl += firstread;
Greg Kroah-Hartmanf024c482010-10-21 10:50:21 -07003049 pad = ((unsigned long)bus->rxctl % DHD_SDALIGN);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003050 if (pad)
3051 bus->rxctl += (DHD_SDALIGN - pad);
3052 bus->rxctl -= firstread;
3053 }
3054 ASSERT(bus->rxctl >= bus->rxbuf);
3055
3056 /* Copy the already-read portion over */
Stanislav Fomichev02160692011-02-15 01:05:10 +03003057 memcpy(bus->rxctl, hdr, firstread);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003058 if (len <= firstread)
3059 goto gotpkt;
3060
3061 /* Copy the full data pkt in gSPI case and process ioctl. */
3062 if (bus->bus == SPI_BUS) {
Stanislav Fomichev02160692011-02-15 01:05:10 +03003063 memcpy(bus->rxctl, hdr, len);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003064 goto gotpkt;
3065 }
3066
3067 /* Raise rdlen to next SDIO block to avoid tail command */
3068 rdlen = len - firstread;
3069 if (bus->roundup && bus->blocksize && (rdlen > bus->blocksize)) {
3070 pad = bus->blocksize - (rdlen % bus->blocksize);
3071 if ((pad <= bus->roundup) && (pad < bus->blocksize) &&
3072 ((len + pad) < bus->dhd->maxctl))
3073 rdlen += pad;
3074 } else if (rdlen % DHD_SDALIGN) {
3075 rdlen += DHD_SDALIGN - (rdlen % DHD_SDALIGN);
3076 }
3077
3078 /* Satisfy length-alignment requirements */
3079 if (forcealign && (rdlen & (ALIGNMENT - 1)))
Greg Kroah-Hartmane18d5312010-10-08 11:59:06 -07003080 rdlen = roundup(rdlen, ALIGNMENT);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003081
3082 /* Drop if the read is too big or it exceeds our maximum */
3083 if ((rdlen + firstread) > bus->dhd->maxctl) {
3084 DHD_ERROR(("%s: %d-byte control read exceeds %d-byte buffer\n",
3085 __func__, rdlen, bus->dhd->maxctl));
3086 bus->dhd->rx_errors++;
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07003087 dhdsdio_rxfail(bus, false, false);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003088 goto done;
3089 }
3090
3091 if ((len - doff) > bus->dhd->maxctl) {
3092 DHD_ERROR(("%s: %d-byte ctl frame (%d-byte ctl data) exceeds "
3093 "%d-byte limit\n",
3094 __func__, len, (len - doff), bus->dhd->maxctl));
3095 bus->dhd->rx_errors++;
3096 bus->rx_toolong++;
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07003097 dhdsdio_rxfail(bus, false, false);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003098 goto done;
3099 }
3100
3101 /* Read remainder of frame body into the rxctl buffer */
Grant Grundler4b455e02011-05-04 09:59:47 -07003102 sdret = bcmsdh_recv_buf(bus, bcmsdh_cur_sbwad(sdh), SDIO_FUNC_2,
3103 F2SYNC, (bus->rxctl + firstread), rdlen,
3104 NULL, NULL, NULL);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003105 bus->f2rxdata++;
Roland Vossenb7ef2a92011-05-03 11:35:02 +02003106 ASSERT(sdret != -BCME_PENDING);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003107
3108 /* Control frame failures need retransmission */
3109 if (sdret < 0) {
3110 DHD_ERROR(("%s: read %d control bytes failed: %d\n",
3111 __func__, rdlen, sdret));
3112 bus->rxc_errors++; /* dhd.rx_ctlerrs is higher level */
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07003113 dhdsdio_rxfail(bus, true, true);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003114 goto done;
3115 }
3116
3117gotpkt:
3118
3119#ifdef DHD_DEBUG
3120 if (DHD_BYTES_ON() && DHD_CTL_ON())
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02003121 bcm_prhex("RxCtrl", bus->rxctl, len);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003122#endif
3123
3124 /* Point to valid data and indicate its length */
3125 bus->rxctl += doff;
3126 bus->rxlen = len - doff;
3127
3128done:
3129 /* Awake any waiters */
3130 dhd_os_ioctl_resp_wake(bus->dhd);
3131}
3132
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07003133static u8 dhdsdio_rxglom(dhd_bus_t *bus, u8 rxseq)
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003134{
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -07003135 u16 dlen, totlen;
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07003136 u8 *dptr, num = 0;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003137
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -07003138 u16 sublen, check;
Arend van Sprielc26b1372010-11-23 14:06:23 +01003139 struct sk_buff *pfirst, *plast, *pnext, *save_pfirst;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003140
3141 int errcode;
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07003142 u8 chan, seq, doff, sfdoff;
3143 u8 txmax;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003144
3145 int ifidx = 0;
3146 bool usechain = bus->use_rxchain;
3147
3148 /* If packets, issue read(s) and send up packet chain */
3149 /* Return sequence numbers consumed? */
3150
3151 DHD_TRACE(("dhdsdio_rxglom: start: glomd %p glom %p\n", bus->glomd,
3152 bus->glom));
3153
3154 /* If there's a descriptor, generate the packet chain */
3155 if (bus->glomd) {
3156 dhd_os_sdlock_rxq(bus->dhd);
3157
3158 pfirst = plast = pnext = NULL;
Arend van Spriel54991ad2010-11-23 14:06:24 +01003159 dlen = (u16) (bus->glomd->len);
3160 dptr = bus->glomd->data;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003161 if (!dlen || (dlen & 1)) {
3162 DHD_ERROR(("%s: bad glomd len(%d), ignore descriptor\n",
3163 __func__, dlen));
3164 dlen = 0;
3165 }
3166
3167 for (totlen = num = 0; dlen; num++) {
3168 /* Get (and move past) next length */
Stanislav Fomichev56dfe3c2011-02-20 21:43:33 +03003169 sublen = get_unaligned_le16(dptr);
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -07003170 dlen -= sizeof(u16);
3171 dptr += sizeof(u16);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003172 if ((sublen < SDPCM_HDRLEN) ||
3173 ((num == 0) && (sublen < (2 * SDPCM_HDRLEN)))) {
3174 DHD_ERROR(("%s: descriptor len %d bad: %d\n",
3175 __func__, num, sublen));
3176 pnext = NULL;
3177 break;
3178 }
3179 if (sublen % DHD_SDALIGN) {
3180 DHD_ERROR(("%s: sublen %d not multiple of %d\n",
3181 __func__, sublen, DHD_SDALIGN));
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07003182 usechain = false;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003183 }
3184 totlen += sublen;
3185
3186 /* For last frame, adjust read len so total
3187 is a block multiple */
3188 if (!dlen) {
3189 sublen +=
Greg Kroah-Hartmane18d5312010-10-08 11:59:06 -07003190 (roundup(totlen, bus->blocksize) - totlen);
3191 totlen = roundup(totlen, bus->blocksize);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003192 }
3193
3194 /* Allocate/chain packet for next subframe */
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02003195 pnext = bcm_pkt_buf_get_skb(sublen + DHD_SDALIGN);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003196 if (pnext == NULL) {
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02003197 DHD_ERROR(("%s: bcm_pkt_buf_get_skb failed, "
3198 "num %d len %d\n", __func__,
3199 num, sublen));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003200 break;
3201 }
Arend van Spriel54991ad2010-11-23 14:06:24 +01003202 ASSERT(!(pnext->prev));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003203 if (!pfirst) {
3204 ASSERT(!plast);
3205 pfirst = plast = pnext;
3206 } else {
3207 ASSERT(plast);
Arend van Spriel54991ad2010-11-23 14:06:24 +01003208 plast->next = pnext;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003209 plast = pnext;
3210 }
3211
3212 /* Adhere to start alignment requirements */
Arend van Spriel3c9d4c32011-03-02 21:18:48 +01003213 PKTALIGN(pnext, sublen, DHD_SDALIGN);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003214 }
3215
3216 /* If all allocations succeeded, save packet chain
3217 in bus structure */
3218 if (pnext) {
3219 DHD_GLOM(("%s: allocated %d-byte packet chain for %d "
3220 "subframes\n", __func__, totlen, num));
3221 if (DHD_GLOM_ON() && bus->nextlen) {
3222 if (totlen != bus->nextlen) {
3223 DHD_GLOM(("%s: glomdesc mismatch: nextlen %d glomdesc %d " "rxseq %d\n",
3224 __func__, bus->nextlen,
3225 totlen, rxseq));
3226 }
3227 }
3228 bus->glom = pfirst;
3229 pfirst = pnext = NULL;
3230 } else {
3231 if (pfirst)
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02003232 bcm_pkt_buf_free_skb(pfirst);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003233 bus->glom = NULL;
3234 num = 0;
3235 }
3236
3237 /* Done with descriptor packet */
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02003238 bcm_pkt_buf_free_skb(bus->glomd);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003239 bus->glomd = NULL;
3240 bus->nextlen = 0;
3241
3242 dhd_os_sdunlock_rxq(bus->dhd);
3243 }
3244
3245 /* Ok -- either we just generated a packet chain,
3246 or had one from before */
3247 if (bus->glom) {
3248 if (DHD_GLOM_ON()) {
3249 DHD_GLOM(("%s: try superframe read, packet chain:\n",
3250 __func__));
Arend van Spriel54991ad2010-11-23 14:06:24 +01003251 for (pnext = bus->glom; pnext; pnext = pnext->next) {
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003252 DHD_GLOM((" %p: %p len 0x%04x (%d)\n",
Arend van Spriel54991ad2010-11-23 14:06:24 +01003253 pnext, (u8 *) (pnext->data),
3254 pnext->len, pnext->len));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003255 }
3256 }
3257
3258 pfirst = bus->glom;
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02003259 dlen = (u16) bcm_pkttotlen(pfirst);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003260
3261 /* Do an SDIO read for the superframe. Configurable iovar to
3262 * read directly into the chained packet, or allocate a large
3263 * packet and and copy into the chain.
3264 */
3265 if (usechain) {
Grant Grundler4b455e02011-05-04 09:59:47 -07003266 errcode = bcmsdh_recv_buf(bus,
3267 bcmsdh_cur_sbwad(bus->sdh), SDIO_FUNC_2,
3268 F2SYNC, (u8 *) pfirst->data, dlen,
3269 pfirst, NULL, NULL);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003270 } else if (bus->dataptr) {
Grant Grundler4b455e02011-05-04 09:59:47 -07003271 errcode = bcmsdh_recv_buf(bus,
3272 bcmsdh_cur_sbwad(bus->sdh), SDIO_FUNC_2,
3273 F2SYNC, bus->dataptr, dlen,
3274 NULL, NULL, NULL);
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02003275 sublen = (u16) bcm_pktfrombuf(pfirst, 0, dlen,
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003276 bus->dataptr);
3277 if (sublen != dlen) {
3278 DHD_ERROR(("%s: FAILED TO COPY, dlen %d sublen %d\n",
3279 __func__, dlen, sublen));
3280 errcode = -1;
3281 }
3282 pnext = NULL;
3283 } else {
3284 DHD_ERROR(("COULDN'T ALLOC %d-BYTE GLOM, FORCE FAILURE\n",
3285 dlen));
3286 errcode = -1;
3287 }
3288 bus->f2rxdata++;
Roland Vossenb7ef2a92011-05-03 11:35:02 +02003289 ASSERT(errcode != -BCME_PENDING);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003290
3291 /* On failure, kill the superframe, allow a couple retries */
3292 if (errcode < 0) {
3293 DHD_ERROR(("%s: glom read of %d bytes failed: %d\n",
3294 __func__, dlen, errcode));
3295 bus->dhd->rx_errors++;
3296
3297 if (bus->glomerr++ < 3) {
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07003298 dhdsdio_rxfail(bus, true, true);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003299 } else {
3300 bus->glomerr = 0;
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07003301 dhdsdio_rxfail(bus, true, false);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003302 dhd_os_sdlock_rxq(bus->dhd);
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02003303 bcm_pkt_buf_free_skb(bus->glom);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003304 dhd_os_sdunlock_rxq(bus->dhd);
3305 bus->rxglomfail++;
3306 bus->glom = NULL;
3307 }
3308 return 0;
3309 }
3310#ifdef DHD_DEBUG
3311 if (DHD_GLOM_ON()) {
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02003312 bcm_prhex("SUPERFRAME", pfirst->data,
Arend van Spriel54991ad2010-11-23 14:06:24 +01003313 min_t(int, pfirst->len, 48));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003314 }
3315#endif
3316
3317 /* Validate the superframe header */
Arend van Spriel54991ad2010-11-23 14:06:24 +01003318 dptr = (u8 *) (pfirst->data);
Stanislav Fomichev56dfe3c2011-02-20 21:43:33 +03003319 sublen = get_unaligned_le16(dptr);
3320 check = get_unaligned_le16(dptr + sizeof(u16));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003321
3322 chan = SDPCM_PACKET_CHANNEL(&dptr[SDPCM_FRAMETAG_LEN]);
3323 seq = SDPCM_PACKET_SEQUENCE(&dptr[SDPCM_FRAMETAG_LEN]);
3324 bus->nextlen = dptr[SDPCM_FRAMETAG_LEN + SDPCM_NEXTLEN_OFFSET];
3325 if ((bus->nextlen << 4) > MAX_RX_DATASZ) {
3326 DHD_INFO(("%s: nextlen too large (%d) seq %d\n",
3327 __func__, bus->nextlen, seq));
3328 bus->nextlen = 0;
3329 }
3330 doff = SDPCM_DOFFSET_VALUE(&dptr[SDPCM_FRAMETAG_LEN]);
3331 txmax = SDPCM_WINDOW_VALUE(&dptr[SDPCM_FRAMETAG_LEN]);
3332
3333 errcode = 0;
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -07003334 if ((u16)~(sublen ^ check)) {
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003335 DHD_ERROR(("%s (superframe): HW hdr error: len/check "
3336 "0x%04x/0x%04x\n", __func__, sublen, check));
3337 errcode = -1;
Greg Kroah-Hartmane18d5312010-10-08 11:59:06 -07003338 } else if (roundup(sublen, bus->blocksize) != dlen) {
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003339 DHD_ERROR(("%s (superframe): len 0x%04x, rounded "
3340 "0x%04x, expect 0x%04x\n",
3341 __func__, sublen,
Greg Kroah-Hartmane18d5312010-10-08 11:59:06 -07003342 roundup(sublen, bus->blocksize), dlen));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003343 errcode = -1;
3344 } else if (SDPCM_PACKET_CHANNEL(&dptr[SDPCM_FRAMETAG_LEN]) !=
3345 SDPCM_GLOM_CHANNEL) {
3346 DHD_ERROR(("%s (superframe): bad channel %d\n",
3347 __func__,
3348 SDPCM_PACKET_CHANNEL(&dptr
3349 [SDPCM_FRAMETAG_LEN])));
3350 errcode = -1;
3351 } else if (SDPCM_GLOMDESC(&dptr[SDPCM_FRAMETAG_LEN])) {
3352 DHD_ERROR(("%s (superframe): got second descriptor?\n",
3353 __func__));
3354 errcode = -1;
3355 } else if ((doff < SDPCM_HDRLEN) ||
Arend van Spriel54991ad2010-11-23 14:06:24 +01003356 (doff > (pfirst->len - SDPCM_HDRLEN))) {
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003357 DHD_ERROR(("%s (superframe): Bad data offset %d: HW %d "
3358 "pkt %d min %d\n",
3359 __func__, doff, sublen,
Arend van Spriel54991ad2010-11-23 14:06:24 +01003360 pfirst->len, SDPCM_HDRLEN));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003361 errcode = -1;
3362 }
3363
3364 /* Check sequence number of superframe SW header */
3365 if (rxseq != seq) {
3366 DHD_INFO(("%s: (superframe) rx_seq %d, expected %d\n",
3367 __func__, seq, rxseq));
3368 bus->rx_badseq++;
3369 rxseq = seq;
3370 }
3371
3372 /* Check window for sanity */
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07003373 if ((u8) (txmax - bus->tx_seq) > 0x40) {
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003374 DHD_ERROR(("%s: unlikely tx max %d with tx_seq %d\n",
3375 __func__, txmax, bus->tx_seq));
3376 txmax = bus->tx_seq + 2;
3377 }
3378 bus->tx_max = txmax;
3379
3380 /* Remove superframe header, remember offset */
Arend van Sprielc303ecb2010-11-18 20:46:43 +01003381 skb_pull(pfirst, doff);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003382 sfdoff = doff;
3383
3384 /* Validate all the subframe headers */
3385 for (num = 0, pnext = pfirst; pnext && !errcode;
Arend van Spriel54991ad2010-11-23 14:06:24 +01003386 num++, pnext = pnext->next) {
3387 dptr = (u8 *) (pnext->data);
3388 dlen = (u16) (pnext->len);
Stanislav Fomichev56dfe3c2011-02-20 21:43:33 +03003389 sublen = get_unaligned_le16(dptr);
3390 check = get_unaligned_le16(dptr + sizeof(u16));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003391 chan = SDPCM_PACKET_CHANNEL(&dptr[SDPCM_FRAMETAG_LEN]);
3392 doff = SDPCM_DOFFSET_VALUE(&dptr[SDPCM_FRAMETAG_LEN]);
3393#ifdef DHD_DEBUG
3394 if (DHD_GLOM_ON())
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02003395 bcm_prhex("subframe", dptr, 32);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003396#endif
3397
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -07003398 if ((u16)~(sublen ^ check)) {
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003399 DHD_ERROR(("%s (subframe %d): HW hdr error: "
3400 "len/check 0x%04x/0x%04x\n",
3401 __func__, num, sublen, check));
3402 errcode = -1;
3403 } else if ((sublen > dlen) || (sublen < SDPCM_HDRLEN)) {
3404 DHD_ERROR(("%s (subframe %d): length mismatch: "
3405 "len 0x%04x, expect 0x%04x\n",
3406 __func__, num, sublen, dlen));
3407 errcode = -1;
3408 } else if ((chan != SDPCM_DATA_CHANNEL) &&
3409 (chan != SDPCM_EVENT_CHANNEL)) {
3410 DHD_ERROR(("%s (subframe %d): bad channel %d\n",
3411 __func__, num, chan));
3412 errcode = -1;
3413 } else if ((doff < SDPCM_HDRLEN) || (doff > sublen)) {
3414 DHD_ERROR(("%s (subframe %d): Bad data offset %d: HW %d min %d\n",
3415 __func__, num, doff, sublen,
3416 SDPCM_HDRLEN));
3417 errcode = -1;
3418 }
3419 }
3420
3421 if (errcode) {
3422 /* Terminate frame on error, request
3423 a couple retries */
3424 if (bus->glomerr++ < 3) {
3425 /* Restore superframe header space */
Arend van Sprielc303ecb2010-11-18 20:46:43 +01003426 skb_push(pfirst, sfdoff);
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07003427 dhdsdio_rxfail(bus, true, true);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003428 } else {
3429 bus->glomerr = 0;
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07003430 dhdsdio_rxfail(bus, true, false);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003431 dhd_os_sdlock_rxq(bus->dhd);
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02003432 bcm_pkt_buf_free_skb(bus->glom);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003433 dhd_os_sdunlock_rxq(bus->dhd);
3434 bus->rxglomfail++;
3435 bus->glom = NULL;
3436 }
3437 bus->nextlen = 0;
3438 return 0;
3439 }
3440
3441 /* Basic SD framing looks ok - process each packet (header) */
3442 save_pfirst = pfirst;
3443 bus->glom = NULL;
3444 plast = NULL;
3445
3446 dhd_os_sdlock_rxq(bus->dhd);
3447 for (num = 0; pfirst; rxseq++, pfirst = pnext) {
Arend van Spriel54991ad2010-11-23 14:06:24 +01003448 pnext = pfirst->next;
3449 pfirst->next = NULL;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003450
Arend van Spriel54991ad2010-11-23 14:06:24 +01003451 dptr = (u8 *) (pfirst->data);
Stanislav Fomichev56dfe3c2011-02-20 21:43:33 +03003452 sublen = get_unaligned_le16(dptr);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003453 chan = SDPCM_PACKET_CHANNEL(&dptr[SDPCM_FRAMETAG_LEN]);
3454 seq = SDPCM_PACKET_SEQUENCE(&dptr[SDPCM_FRAMETAG_LEN]);
3455 doff = SDPCM_DOFFSET_VALUE(&dptr[SDPCM_FRAMETAG_LEN]);
3456
3457 DHD_GLOM(("%s: Get subframe %d, %p(%p/%d), sublen %d "
3458 "chan %d seq %d\n",
Arend van Spriel54991ad2010-11-23 14:06:24 +01003459 __func__, num, pfirst, pfirst->data,
3460 pfirst->len, sublen, chan, seq));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003461
3462 ASSERT((chan == SDPCM_DATA_CHANNEL)
3463 || (chan == SDPCM_EVENT_CHANNEL));
3464
3465 if (rxseq != seq) {
3466 DHD_GLOM(("%s: rx_seq %d, expected %d\n",
3467 __func__, seq, rxseq));
3468 bus->rx_badseq++;
3469 rxseq = seq;
3470 }
3471#ifdef DHD_DEBUG
3472 if (DHD_BYTES_ON() && DHD_DATA_ON())
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02003473 bcm_prhex("Rx Subframe Data", dptr, dlen);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003474#endif
3475
Arend van Spriel2cb8ada2010-11-18 20:46:44 +01003476 __skb_trim(pfirst, sublen);
Arend van Sprielc303ecb2010-11-18 20:46:43 +01003477 skb_pull(pfirst, doff);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003478
Arend van Spriel54991ad2010-11-23 14:06:24 +01003479 if (pfirst->len == 0) {
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02003480 bcm_pkt_buf_free_skb(pfirst);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003481 if (plast) {
Arend van Spriel54991ad2010-11-23 14:06:24 +01003482 plast->next = pnext;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003483 } else {
3484 ASSERT(save_pfirst == pfirst);
3485 save_pfirst = pnext;
3486 }
3487 continue;
3488 } else if (dhd_prot_hdrpull(bus->dhd, &ifidx, pfirst) !=
3489 0) {
3490 DHD_ERROR(("%s: rx protocol error\n",
3491 __func__));
3492 bus->dhd->rx_errors++;
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02003493 bcm_pkt_buf_free_skb(pfirst);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003494 if (plast) {
Arend van Spriel54991ad2010-11-23 14:06:24 +01003495 plast->next = pnext;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003496 } else {
3497 ASSERT(save_pfirst == pfirst);
3498 save_pfirst = pnext;
3499 }
3500 continue;
3501 }
3502
3503 /* this packet will go up, link back into
3504 chain and count it */
Arend van Spriel54991ad2010-11-23 14:06:24 +01003505 pfirst->next = pnext;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003506 plast = pfirst;
3507 num++;
3508
3509#ifdef DHD_DEBUG
3510 if (DHD_GLOM_ON()) {
3511 DHD_GLOM(("%s subframe %d to stack, %p(%p/%d) "
3512 "nxt/lnk %p/%p\n",
Arend van Spriel54991ad2010-11-23 14:06:24 +01003513 __func__, num, pfirst, pfirst->data,
3514 pfirst->len, pfirst->next,
3515 pfirst->prev));
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02003516 bcm_prhex("", (u8 *) pfirst->data,
Arend van Spriel54991ad2010-11-23 14:06:24 +01003517 min_t(int, pfirst->len, 32));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003518 }
3519#endif /* DHD_DEBUG */
3520 }
3521 dhd_os_sdunlock_rxq(bus->dhd);
3522 if (num) {
3523 dhd_os_sdunlock(bus->dhd);
3524 dhd_rx_frame(bus->dhd, ifidx, save_pfirst, num);
3525 dhd_os_sdlock(bus->dhd);
3526 }
3527
3528 bus->rxglomframes++;
3529 bus->rxglompkts += num;
3530 }
3531 return num;
3532}
3533
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07003534/* Return true if there may be more frames to read */
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003535static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
3536{
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003537 bcmsdh_info_t *sdh = bus->sdh;
3538
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -07003539 u16 len, check; /* Extracted hardware header fields */
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07003540 u8 chan, seq, doff; /* Extracted software header fields */
3541 u8 fcbits; /* Extracted fcbits from software header */
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003542
Arend van Sprielc26b1372010-11-23 14:06:23 +01003543 struct sk_buff *pkt; /* Packet for event or data frames */
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -07003544 u16 pad; /* Number of pad bytes to read */
3545 u16 rdlen; /* Total number of bytes to read */
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07003546 u8 rxseq; /* Next sequence number to expect */
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003547 uint rxleft = 0; /* Remaining number of frames allowed */
3548 int sdret; /* Return code from bcmsdh calls */
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07003549 u8 txmax; /* Maximum tx sequence offered */
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003550 bool len_consistent; /* Result of comparing readahead len and
3551 len from hw-hdr */
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07003552 u8 *rxbuf;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003553 int ifidx = 0;
3554 uint rxcount = 0; /* Total frames read */
3555
3556#if defined(DHD_DEBUG) || defined(SDTEST)
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07003557 bool sdtest = false; /* To limit message spew from test mode */
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003558#endif
3559
3560 DHD_TRACE(("%s: Enter\n", __func__));
3561
3562 ASSERT(maxframes);
3563
3564#ifdef SDTEST
3565 /* Allow pktgen to override maxframes */
3566 if (bus->pktgen_count && (bus->pktgen_mode == DHD_PKTGEN_RECV)) {
3567 maxframes = bus->pktgen_count;
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07003568 sdtest = true;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003569 }
3570#endif
3571
3572 /* Not finished unless we encounter no more frames indication */
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07003573 *finished = false;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003574
3575 for (rxseq = bus->rx_seq, rxleft = maxframes;
3576 !bus->rxskip && rxleft && bus->dhd->busstate != DHD_BUS_DOWN;
3577 rxseq++, rxleft--) {
3578
3579 /* Handle glomming separately */
3580 if (bus->glom || bus->glomd) {
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07003581 u8 cnt;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003582 DHD_GLOM(("%s: calling rxglom: glomd %p, glom %p\n",
3583 __func__, bus->glomd, bus->glom));
3584 cnt = dhdsdio_rxglom(bus, rxseq);
3585 DHD_GLOM(("%s: rxglom returned %d\n", __func__, cnt));
3586 rxseq += cnt - 1;
3587 rxleft = (rxleft > cnt) ? (rxleft - cnt) : 1;
3588 continue;
3589 }
3590
3591 /* Try doing single read if we can */
3592 if (dhd_readahead && bus->nextlen) {
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -07003593 u16 nextlen = bus->nextlen;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003594 bus->nextlen = 0;
3595
3596 if (bus->bus == SPI_BUS) {
3597 rdlen = len = nextlen;
3598 } else {
3599 rdlen = len = nextlen << 4;
3600
3601 /* Pad read to blocksize for efficiency */
3602 if (bus->roundup && bus->blocksize
3603 && (rdlen > bus->blocksize)) {
3604 pad =
3605 bus->blocksize -
3606 (rdlen % bus->blocksize);
3607 if ((pad <= bus->roundup)
3608 && (pad < bus->blocksize)
3609 && ((rdlen + pad + firstread) <
3610 MAX_RX_DATASZ))
3611 rdlen += pad;
3612 } else if (rdlen % DHD_SDALIGN) {
3613 rdlen +=
3614 DHD_SDALIGN - (rdlen % DHD_SDALIGN);
3615 }
3616 }
3617
3618 /* We use bus->rxctl buffer in WinXP for initial
3619 * control pkt receives.
3620 * Later we use buffer-poll for data as well
3621 * as control packets.
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003622 * This is required because dhd receives full
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003623 * frame in gSPI unlike SDIO.
3624 * After the frame is received we have to
3625 * distinguish whether it is data
3626 * or non-data frame.
3627 */
3628 /* Allocate a packet buffer */
3629 dhd_os_sdlock_rxq(bus->dhd);
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02003630 pkt = bcm_pkt_buf_get_skb(rdlen + DHD_SDALIGN);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003631 if (!pkt) {
3632 if (bus->bus == SPI_BUS) {
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07003633 bus->usebufpool = false;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003634 bus->rxctl = bus->rxbuf;
3635 if (dhd_alignctl) {
3636 bus->rxctl += firstread;
Greg Kroah-Hartmanf024c482010-10-21 10:50:21 -07003637 pad = ((unsigned long)bus->rxctl %
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003638 DHD_SDALIGN);
3639 if (pad)
3640 bus->rxctl +=
3641 (DHD_SDALIGN - pad);
3642 bus->rxctl -= firstread;
3643 }
3644 ASSERT(bus->rxctl >= bus->rxbuf);
3645 rxbuf = bus->rxctl;
3646 /* Read the entire frame */
Grant Grundler4b455e02011-05-04 09:59:47 -07003647 sdret = bcmsdh_recv_buf(bus,
3648 bcmsdh_cur_sbwad(sdh),
3649 SDIO_FUNC_2, F2SYNC,
3650 rxbuf, rdlen,
3651 NULL, NULL, NULL);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003652 bus->f2rxdata++;
Roland Vossenb7ef2a92011-05-03 11:35:02 +02003653 ASSERT(sdret != -BCME_PENDING);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003654
3655 /* Control frame failures need
3656 retransmission */
3657 if (sdret < 0) {
3658 DHD_ERROR(("%s: read %d control bytes failed: %d\n",
3659 __func__,
3660 rdlen, sdret));
3661 /* dhd.rx_ctlerrs is higher */
3662 bus->rxc_errors++;
3663 dhd_os_sdunlock_rxq(bus->dhd);
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07003664 dhdsdio_rxfail(bus, true,
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003665 (bus->bus ==
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07003666 SPI_BUS) ? false
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07003667 : true);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003668 continue;
3669 }
3670 } else {
3671 /* Give up on data,
3672 request rtx of events */
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02003673 DHD_ERROR(("%s (nextlen): bcm_pkt_buf_get_skb failed: len %d rdlen %d " "expected rxseq %d\n",
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003674 __func__, len, rdlen, rxseq));
3675 /* Just go try again w/normal
3676 header read */
3677 dhd_os_sdunlock_rxq(bus->dhd);
3678 continue;
3679 }
3680 } else {
3681 if (bus->bus == SPI_BUS)
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07003682 bus->usebufpool = true;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003683
Arend van Spriel54991ad2010-11-23 14:06:24 +01003684 ASSERT(!(pkt->prev));
Arend van Spriel3c9d4c32011-03-02 21:18:48 +01003685 PKTALIGN(pkt, rdlen, DHD_SDALIGN);
Arend van Spriel54991ad2010-11-23 14:06:24 +01003686 rxbuf = (u8 *) (pkt->data);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003687 /* Read the entire frame */
Grant Grundler4b455e02011-05-04 09:59:47 -07003688 sdret = bcmsdh_recv_buf(bus,
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003689 bcmsdh_cur_sbwad(sdh),
3690 SDIO_FUNC_2, F2SYNC,
Grant Grundler4b455e02011-05-04 09:59:47 -07003691 rxbuf, rdlen,
3692 pkt, NULL, NULL);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003693 bus->f2rxdata++;
Roland Vossenb7ef2a92011-05-03 11:35:02 +02003694 ASSERT(sdret != -BCME_PENDING);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003695
3696 if (sdret < 0) {
3697 DHD_ERROR(("%s (nextlen): read %d bytes failed: %d\n",
3698 __func__, rdlen, sdret));
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02003699 bcm_pkt_buf_free_skb(pkt);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003700 bus->dhd->rx_errors++;
3701 dhd_os_sdunlock_rxq(bus->dhd);
3702 /* Force retry w/normal header read.
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003703 * Don't attempt NAK for
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003704 * gSPI
3705 */
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07003706 dhdsdio_rxfail(bus, true,
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003707 (bus->bus ==
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07003708 SPI_BUS) ? false :
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07003709 true);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003710 continue;
3711 }
3712 }
3713 dhd_os_sdunlock_rxq(bus->dhd);
3714
3715 /* Now check the header */
Stanislav Fomichev02160692011-02-15 01:05:10 +03003716 memcpy(bus->rxhdr, rxbuf, SDPCM_HDRLEN);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003717
3718 /* Extract hardware header fields */
Stanislav Fomichev56dfe3c2011-02-20 21:43:33 +03003719 len = get_unaligned_le16(bus->rxhdr);
3720 check = get_unaligned_le16(bus->rxhdr + sizeof(u16));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003721
3722 /* All zeros means readahead info was bad */
3723 if (!(len | check)) {
3724 DHD_INFO(("%s (nextlen): read zeros in HW "
3725 "header???\n", __func__));
Grant Grundler4b455e02011-05-04 09:59:47 -07003726 dhdsdio_pktfree2(bus, pkt);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003727 continue;
3728 }
3729
3730 /* Validate check bytes */
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -07003731 if ((u16)~(len ^ check)) {
Grant Grundler4b455e02011-05-04 09:59:47 -07003732 DHD_ERROR(("%s (nextlen): HW hdr error:"
3733 " nextlen/len/check"
3734 " 0x%04x/0x%04x/0x%04x\n",
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003735 __func__, nextlen, len, check));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003736 bus->rx_badhdr++;
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07003737 dhdsdio_rxfail(bus, false, false);
Grant Grundler4b455e02011-05-04 09:59:47 -07003738 dhdsdio_pktfree2(bus, pkt);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003739 continue;
3740 }
3741
3742 /* Validate frame length */
3743 if (len < SDPCM_HDRLEN) {
3744 DHD_ERROR(("%s (nextlen): HW hdr length "
3745 "invalid: %d\n", __func__, len));
Grant Grundler4b455e02011-05-04 09:59:47 -07003746 dhdsdio_pktfree2(bus, pkt);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003747 continue;
3748 }
3749
3750 /* Check for consistency withreadahead info */
Greg Kroah-Hartmane18d5312010-10-08 11:59:06 -07003751 len_consistent = (nextlen != (roundup(len, 16) >> 4));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003752 if (len_consistent) {
3753 /* Mismatch, force retry w/normal
3754 header (may be >4K) */
Grant Grundler4b455e02011-05-04 09:59:47 -07003755 DHD_ERROR(("%s (nextlen): mismatch, "
3756 "nextlen %d len %d rnd %d; "
3757 "expected rxseq %d\n",
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003758 __func__, nextlen,
Greg Kroah-Hartmane18d5312010-10-08 11:59:06 -07003759 len, roundup(len, 16), rxseq));
Grant Grundler4b455e02011-05-04 09:59:47 -07003760 dhdsdio_rxfail(bus, true, (bus->bus != SPI_BUS));
3761 dhdsdio_pktfree2(bus, pkt);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003762 continue;
3763 }
3764
3765 /* Extract software header fields */
Grant Grundler4b455e02011-05-04 09:59:47 -07003766 chan = SDPCM_PACKET_CHANNEL(
3767 &bus->rxhdr[SDPCM_FRAMETAG_LEN]);
3768 seq = SDPCM_PACKET_SEQUENCE(
3769 &bus->rxhdr[SDPCM_FRAMETAG_LEN]);
3770 doff = SDPCM_DOFFSET_VALUE(
3771 &bus->rxhdr[SDPCM_FRAMETAG_LEN]);
3772 txmax = SDPCM_WINDOW_VALUE(
3773 &bus->rxhdr[SDPCM_FRAMETAG_LEN]);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003774
3775 bus->nextlen =
3776 bus->rxhdr[SDPCM_FRAMETAG_LEN +
3777 SDPCM_NEXTLEN_OFFSET];
3778 if ((bus->nextlen << 4) > MAX_RX_DATASZ) {
3779 DHD_INFO(("%s (nextlen): got frame w/nextlen too large" " (%d), seq %d\n",
3780 __func__, bus->nextlen, seq));
3781 bus->nextlen = 0;
3782 }
3783
3784 bus->dhd->rx_readahead_cnt++;
Grant Grundler4b455e02011-05-04 09:59:47 -07003785
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003786 /* Handle Flow Control */
Grant Grundler4b455e02011-05-04 09:59:47 -07003787 fcbits = SDPCM_FCMASK_VALUE(
3788 &bus->rxhdr[SDPCM_FRAMETAG_LEN]);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003789
Grant Grundler4b455e02011-05-04 09:59:47 -07003790 if (bus->flowcontrol != fcbits) {
3791 if (~bus->flowcontrol & fcbits)
3792 bus->fc_xoff++;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003793
Grant Grundler4b455e02011-05-04 09:59:47 -07003794 if (bus->flowcontrol & ~fcbits)
3795 bus->fc_xon++;
3796
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003797 bus->fc_rcvd++;
3798 bus->flowcontrol = fcbits;
3799 }
3800
3801 /* Check and update sequence number */
3802 if (rxseq != seq) {
3803 DHD_INFO(("%s (nextlen): rx_seq %d, expected "
3804 "%d\n", __func__, seq, rxseq));
3805 bus->rx_badseq++;
3806 rxseq = seq;
3807 }
3808
3809 /* Check window for sanity */
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07003810 if ((u8) (txmax - bus->tx_seq) > 0x40) {
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003811 DHD_ERROR(("%s: got unlikely tx max %d with "
3812 "tx_seq %d\n",
3813 __func__, txmax, bus->tx_seq));
3814 txmax = bus->tx_seq + 2;
3815 }
3816 bus->tx_max = txmax;
3817
3818#ifdef DHD_DEBUG
3819 if (DHD_BYTES_ON() && DHD_DATA_ON())
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02003820 bcm_prhex("Rx Data", rxbuf, len);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003821 else if (DHD_HDRS_ON())
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02003822 bcm_prhex("RxHdr", bus->rxhdr, SDPCM_HDRLEN);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003823#endif
3824
3825 if (chan == SDPCM_CONTROL_CHANNEL) {
3826 if (bus->bus == SPI_BUS) {
3827 dhdsdio_read_control(bus, rxbuf, len,
3828 doff);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003829 } else {
3830 DHD_ERROR(("%s (nextlen): readahead on control" " packet %d?\n",
3831 __func__, seq));
3832 /* Force retry w/normal header read */
3833 bus->nextlen = 0;
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07003834 dhdsdio_rxfail(bus, false, true);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003835 }
Grant Grundler4b455e02011-05-04 09:59:47 -07003836 dhdsdio_pktfree2(bus, pkt);
3837 continue;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003838 }
3839
3840 if ((bus->bus == SPI_BUS) && !bus->usebufpool) {
3841 DHD_ERROR(("Received %d bytes on %d channel. Running out of " "rx pktbuf's or not yet malloced.\n",
3842 len, chan));
3843 continue;
3844 }
3845
3846 /* Validate data offset */
3847 if ((doff < SDPCM_HDRLEN) || (doff > len)) {
3848 DHD_ERROR(("%s (nextlen): bad data offset %d: HW len %d min %d\n",
3849 __func__, doff, len, SDPCM_HDRLEN));
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07003850 dhdsdio_rxfail(bus, false, false);
Grant Grundler4b455e02011-05-04 09:59:47 -07003851 dhdsdio_pktfree2(bus, pkt);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003852 continue;
3853 }
3854
3855 /* All done with this one -- now deliver the packet */
3856 goto deliver;
3857 }
3858 /* gSPI frames should not be handled in fractions */
3859 if (bus->bus == SPI_BUS)
3860 break;
3861
3862 /* Read frame header (hardware and software) */
Grant Grundler4b455e02011-05-04 09:59:47 -07003863 sdret = bcmsdh_recv_buf(bus, bcmsdh_cur_sbwad(sdh),
3864 SDIO_FUNC_2, F2SYNC, bus->rxhdr, firstread,
3865 NULL, NULL, NULL);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003866 bus->f2rxhdrs++;
Roland Vossenb7ef2a92011-05-03 11:35:02 +02003867 ASSERT(sdret != -BCME_PENDING);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003868
3869 if (sdret < 0) {
3870 DHD_ERROR(("%s: RXHEADER FAILED: %d\n", __func__,
3871 sdret));
3872 bus->rx_hdrfail++;
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07003873 dhdsdio_rxfail(bus, true, true);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003874 continue;
3875 }
3876#ifdef DHD_DEBUG
3877 if (DHD_BYTES_ON() || DHD_HDRS_ON())
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02003878 bcm_prhex("RxHdr", bus->rxhdr, SDPCM_HDRLEN);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003879#endif
3880
3881 /* Extract hardware header fields */
Stanislav Fomichev56dfe3c2011-02-20 21:43:33 +03003882 len = get_unaligned_le16(bus->rxhdr);
3883 check = get_unaligned_le16(bus->rxhdr + sizeof(u16));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003884
3885 /* All zeros means no more frames */
3886 if (!(len | check)) {
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07003887 *finished = true;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003888 break;
3889 }
3890
3891 /* Validate check bytes */
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -07003892 if ((u16) ~(len ^ check)) {
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003893 DHD_ERROR(("%s: HW hdr err: len/check 0x%04x/0x%04x\n",
3894 __func__, len, check));
3895 bus->rx_badhdr++;
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07003896 dhdsdio_rxfail(bus, false, false);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003897 continue;
3898 }
3899
3900 /* Validate frame length */
3901 if (len < SDPCM_HDRLEN) {
3902 DHD_ERROR(("%s: HW hdr length invalid: %d\n",
3903 __func__, len));
3904 continue;
3905 }
3906
3907 /* Extract software header fields */
3908 chan = SDPCM_PACKET_CHANNEL(&bus->rxhdr[SDPCM_FRAMETAG_LEN]);
3909 seq = SDPCM_PACKET_SEQUENCE(&bus->rxhdr[SDPCM_FRAMETAG_LEN]);
3910 doff = SDPCM_DOFFSET_VALUE(&bus->rxhdr[SDPCM_FRAMETAG_LEN]);
3911 txmax = SDPCM_WINDOW_VALUE(&bus->rxhdr[SDPCM_FRAMETAG_LEN]);
3912
3913 /* Validate data offset */
3914 if ((doff < SDPCM_HDRLEN) || (doff > len)) {
3915 DHD_ERROR(("%s: Bad data offset %d: HW len %d, min %d "
3916 "seq %d\n",
3917 __func__, doff, len, SDPCM_HDRLEN, seq));
3918 bus->rx_badhdr++;
3919 ASSERT(0);
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07003920 dhdsdio_rxfail(bus, false, false);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003921 continue;
3922 }
3923
3924 /* Save the readahead length if there is one */
3925 bus->nextlen =
3926 bus->rxhdr[SDPCM_FRAMETAG_LEN + SDPCM_NEXTLEN_OFFSET];
3927 if ((bus->nextlen << 4) > MAX_RX_DATASZ) {
3928 DHD_INFO(("%s (nextlen): got frame w/nextlen too large "
3929 "(%d), seq %d\n",
3930 __func__, bus->nextlen, seq));
3931 bus->nextlen = 0;
3932 }
3933
3934 /* Handle Flow Control */
3935 fcbits = SDPCM_FCMASK_VALUE(&bus->rxhdr[SDPCM_FRAMETAG_LEN]);
3936
Grant Grundler4b455e02011-05-04 09:59:47 -07003937 if (bus->flowcontrol != fcbits) {
3938 if (~bus->flowcontrol & fcbits)
3939 bus->fc_xoff++;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003940
Grant Grundler4b455e02011-05-04 09:59:47 -07003941 if (bus->flowcontrol & ~fcbits)
3942 bus->fc_xon++;
3943
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003944 bus->fc_rcvd++;
3945 bus->flowcontrol = fcbits;
3946 }
3947
3948 /* Check and update sequence number */
3949 if (rxseq != seq) {
3950 DHD_INFO(("%s: rx_seq %d, expected %d\n", __func__,
3951 seq, rxseq));
3952 bus->rx_badseq++;
3953 rxseq = seq;
3954 }
3955
3956 /* Check window for sanity */
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07003957 if ((u8) (txmax - bus->tx_seq) > 0x40) {
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003958 DHD_ERROR(("%s: unlikely tx max %d with tx_seq %d\n",
3959 __func__, txmax, bus->tx_seq));
3960 txmax = bus->tx_seq + 2;
3961 }
3962 bus->tx_max = txmax;
3963
3964 /* Call a separate function for control frames */
3965 if (chan == SDPCM_CONTROL_CHANNEL) {
3966 dhdsdio_read_control(bus, bus->rxhdr, len, doff);
3967 continue;
3968 }
3969
3970 ASSERT((chan == SDPCM_DATA_CHANNEL)
3971 || (chan == SDPCM_EVENT_CHANNEL)
3972 || (chan == SDPCM_TEST_CHANNEL)
3973 || (chan == SDPCM_GLOM_CHANNEL));
3974
3975 /* Length to read */
3976 rdlen = (len > firstread) ? (len - firstread) : 0;
3977
3978 /* May pad read to blocksize for efficiency */
3979 if (bus->roundup && bus->blocksize &&
3980 (rdlen > bus->blocksize)) {
3981 pad = bus->blocksize - (rdlen % bus->blocksize);
3982 if ((pad <= bus->roundup) && (pad < bus->blocksize) &&
3983 ((rdlen + pad + firstread) < MAX_RX_DATASZ))
3984 rdlen += pad;
3985 } else if (rdlen % DHD_SDALIGN) {
3986 rdlen += DHD_SDALIGN - (rdlen % DHD_SDALIGN);
3987 }
3988
3989 /* Satisfy length-alignment requirements */
3990 if (forcealign && (rdlen & (ALIGNMENT - 1)))
Greg Kroah-Hartmane18d5312010-10-08 11:59:06 -07003991 rdlen = roundup(rdlen, ALIGNMENT);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07003992
3993 if ((rdlen + firstread) > MAX_RX_DATASZ) {
3994 /* Too long -- skip this frame */
3995 DHD_ERROR(("%s: too long: len %d rdlen %d\n",
3996 __func__, len, rdlen));
3997 bus->dhd->rx_errors++;
3998 bus->rx_toolong++;
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07003999 dhdsdio_rxfail(bus, false, false);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004000 continue;
4001 }
4002
4003 dhd_os_sdlock_rxq(bus->dhd);
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02004004 pkt = bcm_pkt_buf_get_skb(rdlen + firstread + DHD_SDALIGN);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004005 if (!pkt) {
4006 /* Give up on data, request rtx of events */
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02004007 DHD_ERROR(("%s: bcm_pkt_buf_get_skb failed: rdlen %d "
4008 "chan %d\n", __func__, rdlen, chan));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004009 bus->dhd->rx_dropped++;
4010 dhd_os_sdunlock_rxq(bus->dhd);
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07004011 dhdsdio_rxfail(bus, false, RETRYCHAN(chan));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004012 continue;
4013 }
4014 dhd_os_sdunlock_rxq(bus->dhd);
4015
Arend van Spriel54991ad2010-11-23 14:06:24 +01004016 ASSERT(!(pkt->prev));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004017
4018 /* Leave room for what we already read, and align remainder */
Arend van Spriel54991ad2010-11-23 14:06:24 +01004019 ASSERT(firstread < pkt->len);
Arend van Sprielc303ecb2010-11-18 20:46:43 +01004020 skb_pull(pkt, firstread);
Arend van Spriel3c9d4c32011-03-02 21:18:48 +01004021 PKTALIGN(pkt, rdlen, DHD_SDALIGN);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004022
4023 /* Read the remaining frame data */
Grant Grundler4b455e02011-05-04 09:59:47 -07004024 sdret = bcmsdh_recv_buf(bus, bcmsdh_cur_sbwad(sdh), SDIO_FUNC_2,
Arend van Spriel54991ad2010-11-23 14:06:24 +01004025 F2SYNC, ((u8 *) (pkt->data)), rdlen,
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004026 pkt, NULL, NULL);
4027 bus->f2rxdata++;
Roland Vossenb7ef2a92011-05-03 11:35:02 +02004028 ASSERT(sdret != -BCME_PENDING);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004029
4030 if (sdret < 0) {
4031 DHD_ERROR(("%s: read %d %s bytes failed: %d\n",
4032 __func__, rdlen,
4033 ((chan ==
4034 SDPCM_EVENT_CHANNEL) ? "event" : ((chan ==
4035 SDPCM_DATA_CHANNEL)
4036 ? "data" : "test")),
4037 sdret));
4038 dhd_os_sdlock_rxq(bus->dhd);
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02004039 bcm_pkt_buf_free_skb(pkt);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004040 dhd_os_sdunlock_rxq(bus->dhd);
4041 bus->dhd->rx_errors++;
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07004042 dhdsdio_rxfail(bus, true, RETRYCHAN(chan));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004043 continue;
4044 }
4045
4046 /* Copy the already-read portion */
Arend van Sprielc303ecb2010-11-18 20:46:43 +01004047 skb_push(pkt, firstread);
Stanislav Fomichev02160692011-02-15 01:05:10 +03004048 memcpy(pkt->data, bus->rxhdr, firstread);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004049
4050#ifdef DHD_DEBUG
4051 if (DHD_BYTES_ON() && DHD_DATA_ON())
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02004052 bcm_prhex("Rx Data", pkt->data, len);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004053#endif
4054
4055deliver:
4056 /* Save superframe descriptor and allocate packet frame */
4057 if (chan == SDPCM_GLOM_CHANNEL) {
4058 if (SDPCM_GLOMDESC(&bus->rxhdr[SDPCM_FRAMETAG_LEN])) {
4059 DHD_GLOM(("%s: glom descriptor, %d bytes:\n",
4060 __func__, len));
4061#ifdef DHD_DEBUG
4062 if (DHD_GLOM_ON()) {
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02004063 bcm_prhex("Glom Data", pkt->data, len);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004064 }
4065#endif
Arend van Spriel2cb8ada2010-11-18 20:46:44 +01004066 __skb_trim(pkt, len);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004067 ASSERT(doff == SDPCM_HDRLEN);
Arend van Sprielc303ecb2010-11-18 20:46:43 +01004068 skb_pull(pkt, SDPCM_HDRLEN);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004069 bus->glomd = pkt;
4070 } else {
4071 DHD_ERROR(("%s: glom superframe w/o "
4072 "descriptor!\n", __func__));
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07004073 dhdsdio_rxfail(bus, false, false);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004074 }
4075 continue;
4076 }
4077
4078 /* Fill in packet len and prio, deliver upward */
Arend van Spriel2cb8ada2010-11-18 20:46:44 +01004079 __skb_trim(pkt, len);
Arend van Sprielc303ecb2010-11-18 20:46:43 +01004080 skb_pull(pkt, doff);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004081
4082#ifdef SDTEST
4083 /* Test channel packets are processed separately */
4084 if (chan == SDPCM_TEST_CHANNEL) {
4085 dhdsdio_testrcv(bus, pkt, seq);
4086 continue;
4087 }
4088#endif /* SDTEST */
4089
Arend van Spriel54991ad2010-11-23 14:06:24 +01004090 if (pkt->len == 0) {
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004091 dhd_os_sdlock_rxq(bus->dhd);
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02004092 bcm_pkt_buf_free_skb(pkt);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004093 dhd_os_sdunlock_rxq(bus->dhd);
4094 continue;
4095 } else if (dhd_prot_hdrpull(bus->dhd, &ifidx, pkt) != 0) {
4096 DHD_ERROR(("%s: rx protocol error\n", __func__));
4097 dhd_os_sdlock_rxq(bus->dhd);
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02004098 bcm_pkt_buf_free_skb(pkt);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004099 dhd_os_sdunlock_rxq(bus->dhd);
4100 bus->dhd->rx_errors++;
4101 continue;
4102 }
4103
4104 /* Unlock during rx call */
4105 dhd_os_sdunlock(bus->dhd);
4106 dhd_rx_frame(bus->dhd, ifidx, pkt, 1);
4107 dhd_os_sdlock(bus->dhd);
4108 }
4109 rxcount = maxframes - rxleft;
4110#ifdef DHD_DEBUG
4111 /* Message if we hit the limit */
4112 if (!rxleft && !sdtest)
4113 DHD_DATA(("%s: hit rx limit of %d frames\n", __func__,
4114 maxframes));
4115 else
4116#endif /* DHD_DEBUG */
4117 DHD_DATA(("%s: processed %d frames\n", __func__, rxcount));
4118 /* Back off rxseq if awaiting rtx, update rx_seq */
4119 if (bus->rxskip)
4120 rxseq--;
4121 bus->rx_seq = rxseq;
4122
4123 return rxcount;
4124}
4125
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -07004126static u32 dhdsdio_hostmail(dhd_bus_t *bus)
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004127{
4128 sdpcmd_regs_t *regs = bus->regs;
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -07004129 u32 intstatus = 0;
4130 u32 hmb_data;
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07004131 u8 fcbits;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004132 uint retries = 0;
4133
4134 DHD_TRACE(("%s: Enter\n", __func__));
4135
4136 /* Read mailbox data and ack that we did so */
4137 R_SDREG(hmb_data, &regs->tohostmailboxdata, retries);
4138 if (retries <= retry_limit)
4139 W_SDREG(SMB_INT_ACK, &regs->tosbmailbox, retries);
4140 bus->f1regdata += 2;
4141
4142 /* Dongle recomposed rx frames, accept them again */
4143 if (hmb_data & HMB_DATA_NAKHANDLED) {
4144 DHD_INFO(("Dongle reports NAK handled, expect rtx of %d\n",
4145 bus->rx_seq));
4146 if (!bus->rxskip)
4147 DHD_ERROR(("%s: unexpected NAKHANDLED!\n", __func__));
4148
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07004149 bus->rxskip = false;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004150 intstatus |= I_HMB_FRAME_IND;
4151 }
4152
4153 /*
4154 * DEVREADY does not occur with gSPI.
4155 */
4156 if (hmb_data & (HMB_DATA_DEVREADY | HMB_DATA_FWREADY)) {
4157 bus->sdpcm_ver =
4158 (hmb_data & HMB_DATA_VERSION_MASK) >>
4159 HMB_DATA_VERSION_SHIFT;
4160 if (bus->sdpcm_ver != SDPCM_PROT_VERSION)
4161 DHD_ERROR(("Version mismatch, dongle reports %d, "
4162 "expecting %d\n",
4163 bus->sdpcm_ver, SDPCM_PROT_VERSION));
4164 else
4165 DHD_INFO(("Dongle ready, protocol version %d\n",
4166 bus->sdpcm_ver));
4167 }
4168
4169 /*
4170 * Flow Control has been moved into the RX headers and this out of band
Grant Grundler4b455e02011-05-04 09:59:47 -07004171 * method isn't used any more.
4172 * remaining backward compatible with older dongles.
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004173 */
4174 if (hmb_data & HMB_DATA_FC) {
Grant Grundler4b455e02011-05-04 09:59:47 -07004175 fcbits = (hmb_data & HMB_DATA_FCDATA_MASK) >>
4176 HMB_DATA_FCDATA_SHIFT;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004177
4178 if (fcbits & ~bus->flowcontrol)
4179 bus->fc_xoff++;
Grant Grundler4b455e02011-05-04 09:59:47 -07004180
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004181 if (bus->flowcontrol & ~fcbits)
4182 bus->fc_xon++;
4183
4184 bus->fc_rcvd++;
4185 bus->flowcontrol = fcbits;
4186 }
4187
4188 /* Shouldn't be any others */
4189 if (hmb_data & ~(HMB_DATA_DEVREADY |
4190 HMB_DATA_NAKHANDLED |
4191 HMB_DATA_FC |
4192 HMB_DATA_FWREADY |
4193 HMB_DATA_FCDATA_MASK | HMB_DATA_VERSION_MASK)) {
4194 DHD_ERROR(("Unknown mailbox data content: 0x%02x\n", hmb_data));
4195 }
4196
4197 return intstatus;
4198}
4199
4200bool dhdsdio_dpc(dhd_bus_t *bus)
4201{
4202 bcmsdh_info_t *sdh = bus->sdh;
4203 sdpcmd_regs_t *regs = bus->regs;
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -07004204 u32 intstatus, newstatus = 0;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004205 uint retries = 0;
4206 uint rxlimit = dhd_rxbound; /* Rx frames to read before resched */
4207 uint txlimit = dhd_txbound; /* Tx frames to send before resched */
4208 uint framecnt = 0; /* Temporary counter of tx/rx frames */
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07004209 bool rxdone = true; /* Flag for no more read data */
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07004210 bool resched = false; /* Flag indicating resched wanted */
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004211
4212 DHD_TRACE(("%s: Enter\n", __func__));
4213
4214 /* Start with leftover status bits */
4215 intstatus = bus->intstatus;
4216
4217 dhd_os_sdlock(bus->dhd);
4218
4219 /* If waiting for HTAVAIL, check status */
4220 if (bus->clkstate == CLK_PENDING) {
4221 int err;
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07004222 u8 clkctl, devctl = 0;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004223
4224#ifdef DHD_DEBUG
4225 /* Check for inconsistent device control */
4226 devctl =
4227 bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL, &err);
4228 if (err) {
4229 DHD_ERROR(("%s: error reading DEVCTL: %d\n",
4230 __func__, err));
4231 bus->dhd->busstate = DHD_BUS_DOWN;
4232 } else {
4233 ASSERT(devctl & SBSDIO_DEVCTL_CA_INT_ONLY);
4234 }
4235#endif /* DHD_DEBUG */
4236
4237 /* Read CSR, if clock on switch to AVAIL, else ignore */
4238 clkctl =
4239 bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR,
4240 &err);
4241 if (err) {
4242 DHD_ERROR(("%s: error reading CSR: %d\n", __func__,
4243 err));
4244 bus->dhd->busstate = DHD_BUS_DOWN;
4245 }
4246
4247 DHD_INFO(("DPC: PENDING, devctl 0x%02x clkctl 0x%02x\n", devctl,
4248 clkctl));
4249
4250 if (SBSDIO_HTAV(clkctl)) {
4251 devctl =
4252 bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL,
4253 &err);
4254 if (err) {
4255 DHD_ERROR(("%s: error reading DEVCTL: %d\n",
4256 __func__, err));
4257 bus->dhd->busstate = DHD_BUS_DOWN;
4258 }
4259 devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY;
4260 bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL,
4261 devctl, &err);
4262 if (err) {
4263 DHD_ERROR(("%s: error writing DEVCTL: %d\n",
4264 __func__, err));
4265 bus->dhd->busstate = DHD_BUS_DOWN;
4266 }
4267 bus->clkstate = CLK_AVAIL;
4268 } else {
4269 goto clkwait;
4270 }
4271 }
4272
4273 BUS_WAKE(bus);
4274
4275 /* Make sure backplane clock is on */
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07004276 dhdsdio_clkctl(bus, CLK_AVAIL, true);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004277 if (bus->clkstate == CLK_PENDING)
4278 goto clkwait;
4279
4280 /* Pending interrupt indicates new device status */
4281 if (bus->ipend) {
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07004282 bus->ipend = false;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004283 R_SDREG(newstatus, &regs->intstatus, retries);
4284 bus->f1regdata++;
4285 if (bcmsdh_regfail(bus->sdh))
4286 newstatus = 0;
4287 newstatus &= bus->hostintmask;
4288 bus->fcstate = !!(newstatus & I_HMB_FC_STATE);
4289 if (newstatus) {
4290 W_SDREG(newstatus, &regs->intstatus, retries);
4291 bus->f1regdata++;
4292 }
4293 }
4294
4295 /* Merge new bits with previous */
4296 intstatus |= newstatus;
4297 bus->intstatus = 0;
4298
4299 /* Handle flow-control change: read new state in case our ack
4300 * crossed another change interrupt. If change still set, assume
4301 * FC ON for safety, let next loop through do the debounce.
4302 */
4303 if (intstatus & I_HMB_FC_CHANGE) {
4304 intstatus &= ~I_HMB_FC_CHANGE;
4305 W_SDREG(I_HMB_FC_CHANGE, &regs->intstatus, retries);
4306 R_SDREG(newstatus, &regs->intstatus, retries);
4307 bus->f1regdata += 2;
4308 bus->fcstate =
4309 !!(newstatus & (I_HMB_FC_STATE | I_HMB_FC_CHANGE));
4310 intstatus |= (newstatus & bus->hostintmask);
4311 }
4312
4313 /* Handle host mailbox indication */
4314 if (intstatus & I_HMB_HOST_INT) {
4315 intstatus &= ~I_HMB_HOST_INT;
4316 intstatus |= dhdsdio_hostmail(bus);
4317 }
4318
4319 /* Generally don't ask for these, can get CRC errors... */
4320 if (intstatus & I_WR_OOSYNC) {
4321 DHD_ERROR(("Dongle reports WR_OOSYNC\n"));
4322 intstatus &= ~I_WR_OOSYNC;
4323 }
4324
4325 if (intstatus & I_RD_OOSYNC) {
4326 DHD_ERROR(("Dongle reports RD_OOSYNC\n"));
4327 intstatus &= ~I_RD_OOSYNC;
4328 }
4329
4330 if (intstatus & I_SBINT) {
4331 DHD_ERROR(("Dongle reports SBINT\n"));
4332 intstatus &= ~I_SBINT;
4333 }
4334
4335 /* Would be active due to wake-wlan in gSPI */
4336 if (intstatus & I_CHIPACTIVE) {
4337 DHD_INFO(("Dongle reports CHIPACTIVE\n"));
4338 intstatus &= ~I_CHIPACTIVE;
4339 }
4340
4341 /* Ignore frame indications if rxskip is set */
4342 if (bus->rxskip)
4343 intstatus &= ~I_HMB_FRAME_IND;
4344
4345 /* On frame indication, read available frames */
4346 if (PKT_AVAILABLE()) {
4347 framecnt = dhdsdio_readframes(bus, rxlimit, &rxdone);
4348 if (rxdone || bus->rxskip)
4349 intstatus &= ~I_HMB_FRAME_IND;
Greg Kroah-Hartman7068c2f2010-10-08 11:34:59 -07004350 rxlimit -= min(framecnt, rxlimit);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004351 }
4352
4353 /* Keep still-pending events for next scheduling */
4354 bus->intstatus = intstatus;
4355
4356clkwait:
4357#if defined(OOB_INTR_ONLY)
4358 bcmsdh_oob_intr_set(1);
4359#endif /* (OOB_INTR_ONLY) */
4360 /* Re-enable interrupts to detect new device events (mailbox, rx frame)
4361 * or clock availability. (Allows tx loop to check ipend if desired.)
4362 * (Unless register access seems hosed, as we may not be able to ACK...)
4363 */
4364 if (bus->intr && bus->intdis && !bcmsdh_regfail(sdh)) {
4365 DHD_INTR(("%s: enable SDIO interrupts, rxdone %d framecnt %d\n",
4366 __func__, rxdone, framecnt));
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07004367 bus->intdis = false;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004368 bcmsdh_intr_enable(sdh);
4369 }
4370
4371 if (DATAOK(bus) && bus->ctrl_frame_stat &&
4372 (bus->clkstate == CLK_AVAIL)) {
4373 int ret, i;
4374
4375 ret =
4376 dhd_bcmsdh_send_buf(bus, bcmsdh_cur_sbwad(sdh), SDIO_FUNC_2,
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07004377 F2SYNC, (u8 *) bus->ctrl_frame_buf,
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -07004378 (u32) bus->ctrl_frame_len, NULL,
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004379 NULL, NULL);
Roland Vossenb7ef2a92011-05-03 11:35:02 +02004380 ASSERT(ret != -BCME_PENDING);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004381
4382 if (ret < 0) {
4383 /* On failure, abort the command and
4384 terminate the frame */
4385 DHD_INFO(("%s: sdio error %d, abort command and "
4386 "terminate frame.\n", __func__, ret));
4387 bus->tx_sderrs++;
4388
4389 bcmsdh_abort(sdh, SDIO_FUNC_2);
4390
4391 bcmsdh_cfg_write(sdh, SDIO_FUNC_1,
4392 SBSDIO_FUNC1_FRAMECTRL, SFC_WF_TERM,
4393 NULL);
4394 bus->f1regdata++;
4395
4396 for (i = 0; i < 3; i++) {
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07004397 u8 hi, lo;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004398 hi = bcmsdh_cfg_read(sdh, SDIO_FUNC_1,
4399 SBSDIO_FUNC1_WFRAMEBCHI,
4400 NULL);
4401 lo = bcmsdh_cfg_read(sdh, SDIO_FUNC_1,
4402 SBSDIO_FUNC1_WFRAMEBCLO,
4403 NULL);
4404 bus->f1regdata += 2;
4405 if ((hi == 0) && (lo == 0))
4406 break;
4407 }
4408
4409 }
4410 if (ret == 0)
4411 bus->tx_seq = (bus->tx_seq + 1) % SDPCM_SEQUENCE_WRAP;
4412
Arend van Spriel0bef7742011-02-10 12:03:44 +01004413 DHD_INFO(("Return_dpc value is : %d\n", ret));
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07004414 bus->ctrl_frame_stat = false;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004415 dhd_wait_event_wakeup(bus->dhd);
4416 }
4417 /* Send queued frames (limit 1 if rx may still be pending) */
4418 else if ((bus->clkstate == CLK_AVAIL) && !bus->fcstate &&
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02004419 bcm_pktq_mlen(&bus->txq, ~bus->flowcontrol) && txlimit
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004420 && DATAOK(bus)) {
Greg Kroah-Hartman7068c2f2010-10-08 11:34:59 -07004421 framecnt = rxdone ? txlimit : min(txlimit, dhd_txminmax);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004422 framecnt = dhdsdio_sendfromq(bus, framecnt);
4423 txlimit -= framecnt;
4424 }
4425
4426 /* Resched if events or tx frames are pending,
4427 else await next interrupt */
4428 /* On failed register access, all bets are off:
4429 no resched or interrupts */
4430 if ((bus->dhd->busstate == DHD_BUS_DOWN) || bcmsdh_regfail(sdh)) {
4431 DHD_ERROR(("%s: failed backplane access over SDIO, halting "
4432 "operation %d\n", __func__, bcmsdh_regfail(sdh)));
4433 bus->dhd->busstate = DHD_BUS_DOWN;
4434 bus->intstatus = 0;
4435 } else if (bus->clkstate == CLK_PENDING) {
4436 DHD_INFO(("%s: rescheduled due to CLK_PENDING awaiting "
4437 "I_CHIPACTIVE interrupt\n", __func__));
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07004438 resched = true;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004439 } else if (bus->intstatus || bus->ipend ||
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02004440 (!bus->fcstate && bcm_pktq_mlen(&bus->txq, ~bus->flowcontrol) &&
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004441 DATAOK(bus)) || PKT_AVAILABLE()) {
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07004442 resched = true;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004443 }
4444
4445 bus->dpc_sched = resched;
4446
4447 /* If we're done for now, turn off clock request. */
4448 if ((bus->clkstate != CLK_PENDING)
4449 && bus->idletime == DHD_IDLE_IMMEDIATE) {
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07004450 bus->activity = false;
4451 dhdsdio_clkctl(bus, CLK_NONE, false);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004452 }
4453
4454 dhd_os_sdunlock(bus->dhd);
4455
4456 return resched;
4457}
4458
4459bool dhd_bus_dpc(struct dhd_bus *bus)
4460{
4461 bool resched;
4462
4463 /* Call the DPC directly. */
4464 DHD_TRACE(("Calling dhdsdio_dpc() from %s\n", __func__));
4465 resched = dhdsdio_dpc(bus);
4466
4467 return resched;
4468}
4469
4470void dhdsdio_isr(void *arg)
4471{
4472 dhd_bus_t *bus = (dhd_bus_t *) arg;
4473 bcmsdh_info_t *sdh;
4474
4475 DHD_TRACE(("%s: Enter\n", __func__));
4476
4477 if (!bus) {
4478 DHD_ERROR(("%s : bus is null pointer , exit\n", __func__));
4479 return;
4480 }
4481 sdh = bus->sdh;
4482
4483 if (bus->dhd->busstate == DHD_BUS_DOWN) {
4484 DHD_ERROR(("%s : bus is down. we have nothing to do\n",
4485 __func__));
4486 return;
4487 }
4488 /* Count the interrupt call */
4489 bus->intrcount++;
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07004490 bus->ipend = true;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004491
4492 /* Shouldn't get this interrupt if we're sleeping? */
4493 if (bus->sleeping) {
4494 DHD_ERROR(("INTERRUPT WHILE SLEEPING??\n"));
4495 return;
4496 }
4497
4498 /* Disable additional interrupts (is this needed now)? */
4499 if (bus->intr)
4500 DHD_INTR(("%s: disable SDIO interrupts\n", __func__));
4501 else
4502 DHD_ERROR(("dhdsdio_isr() w/o interrupt configured!\n"));
4503
4504 bcmsdh_intr_disable(sdh);
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07004505 bus->intdis = true;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004506
4507#if defined(SDIO_ISR_THREAD)
4508 DHD_TRACE(("Calling dhdsdio_dpc() from %s\n", __func__));
4509 while (dhdsdio_dpc(bus))
4510 ;
4511#else
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07004512 bus->dpc_sched = true;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004513 dhd_sched_dpc(bus->dhd);
4514#endif
4515
4516}
4517
4518#ifdef SDTEST
4519static void dhdsdio_pktgen_init(dhd_bus_t *bus)
4520{
4521 /* Default to specified length, or full range */
4522 if (dhd_pktgen_len) {
Greg Kroah-Hartman7068c2f2010-10-08 11:34:59 -07004523 bus->pktgen_maxlen = min(dhd_pktgen_len, MAX_PKTGEN_LEN);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004524 bus->pktgen_minlen = bus->pktgen_maxlen;
4525 } else {
4526 bus->pktgen_maxlen = MAX_PKTGEN_LEN;
4527 bus->pktgen_minlen = 0;
4528 }
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -07004529 bus->pktgen_len = (u16) bus->pktgen_minlen;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004530
4531 /* Default to per-watchdog burst with 10s print time */
4532 bus->pktgen_freq = 1;
4533 bus->pktgen_print = 10000 / dhd_watchdog_ms;
4534 bus->pktgen_count = (dhd_pktgen * dhd_watchdog_ms + 999) / 1000;
4535
4536 /* Default to echo mode */
4537 bus->pktgen_mode = DHD_PKTGEN_ECHO;
4538 bus->pktgen_stop = 1;
4539}
4540
4541static void dhdsdio_pktgen(dhd_bus_t *bus)
4542{
Arend van Sprielc26b1372010-11-23 14:06:23 +01004543 struct sk_buff *pkt;
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07004544 u8 *data;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004545 uint pktcount;
4546 uint fillbyte;
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -07004547 u16 len;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004548
4549 /* Display current count if appropriate */
4550 if (bus->pktgen_print && (++bus->pktgen_ptick >= bus->pktgen_print)) {
4551 bus->pktgen_ptick = 0;
Arend van Spriel0bef7742011-02-10 12:03:44 +01004552 printk(KERN_DEBUG "%s: send attempts %d rcvd %d\n",
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004553 __func__, bus->pktgen_sent, bus->pktgen_rcvd);
4554 }
4555
4556 /* For recv mode, just make sure dongle has started sending */
4557 if (bus->pktgen_mode == DHD_PKTGEN_RECV) {
4558 if (!bus->pktgen_rcvd)
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07004559 dhdsdio_sdtest_set(bus, true);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004560 return;
4561 }
4562
4563 /* Otherwise, generate or request the specified number of packets */
4564 for (pktcount = 0; pktcount < bus->pktgen_count; pktcount++) {
4565 /* Stop if total has been reached */
4566 if (bus->pktgen_total
4567 && (bus->pktgen_sent >= bus->pktgen_total)) {
4568 bus->pktgen_count = 0;
4569 break;
4570 }
4571
4572 /* Allocate an appropriate-sized packet */
4573 len = bus->pktgen_len;
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02004574 pkt = bcm_pkt_buf_get_skb(
Jason Cooper9b890322010-09-30 15:15:39 -04004575 (len + SDPCM_HDRLEN + SDPCM_TEST_HDRLEN + DHD_SDALIGN),
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07004576 true);
Jason Cooper9b890322010-09-30 15:15:39 -04004577 if (!pkt) {
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02004578 DHD_ERROR(("%s: bcm_pkt_buf_get_skb failed!\n",
4579 __func__));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004580 break;
4581 }
Arend van Spriel3c9d4c32011-03-02 21:18:48 +01004582 PKTALIGN(pkt, (len + SDPCM_HDRLEN + SDPCM_TEST_HDRLEN),
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004583 DHD_SDALIGN);
Arend van Spriel54991ad2010-11-23 14:06:24 +01004584 data = (u8 *) (pkt->data) + SDPCM_HDRLEN;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004585
4586 /* Write test header cmd and extra based on mode */
4587 switch (bus->pktgen_mode) {
4588 case DHD_PKTGEN_ECHO:
4589 *data++ = SDPCM_TEST_ECHOREQ;
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07004590 *data++ = (u8) bus->pktgen_sent;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004591 break;
4592
4593 case DHD_PKTGEN_SEND:
4594 *data++ = SDPCM_TEST_DISCARD;
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07004595 *data++ = (u8) bus->pktgen_sent;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004596 break;
4597
4598 case DHD_PKTGEN_RXBURST:
4599 *data++ = SDPCM_TEST_BURST;
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07004600 *data++ = (u8) bus->pktgen_count;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004601 break;
4602
4603 default:
4604 DHD_ERROR(("Unrecognized pktgen mode %d\n",
4605 bus->pktgen_mode));
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02004606 bcm_pkt_buf_free_skb(pkt, true);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004607 bus->pktgen_count = 0;
4608 return;
4609 }
4610
4611 /* Write test header length field */
4612 *data++ = (len >> 0);
4613 *data++ = (len >> 8);
4614
4615 /* Then fill in the remainder -- N/A for burst,
4616 but who cares... */
4617 for (fillbyte = 0; fillbyte < len; fillbyte++)
4618 *data++ =
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07004619 SDPCM_TEST_FILL(fillbyte, (u8) bus->pktgen_sent);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004620
4621#ifdef DHD_DEBUG
4622 if (DHD_BYTES_ON() && DHD_DATA_ON()) {
Arend van Spriel54991ad2010-11-23 14:06:24 +01004623 data = (u8 *) (pkt->data) + SDPCM_HDRLEN;
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02004624 bcm_prhex("dhdsdio_pktgen: Tx Data", data,
Arend van Spriel54991ad2010-11-23 14:06:24 +01004625 pkt->len - SDPCM_HDRLEN);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004626 }
4627#endif
4628
4629 /* Send it */
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07004630 if (dhdsdio_txpkt(bus, pkt, SDPCM_TEST_CHANNEL, true)) {
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004631 bus->pktgen_fail++;
4632 if (bus->pktgen_stop
4633 && bus->pktgen_stop == bus->pktgen_fail)
4634 bus->pktgen_count = 0;
4635 }
4636 bus->pktgen_sent++;
4637
4638 /* Bump length if not fixed, wrap at max */
4639 if (++bus->pktgen_len > bus->pktgen_maxlen)
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -07004640 bus->pktgen_len = (u16) bus->pktgen_minlen;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004641
4642 /* Special case for burst mode: just send one request! */
4643 if (bus->pktgen_mode == DHD_PKTGEN_RXBURST)
4644 break;
4645 }
4646}
4647
4648static void dhdsdio_sdtest_set(dhd_bus_t *bus, bool start)
4649{
Arend van Sprielc26b1372010-11-23 14:06:23 +01004650 struct sk_buff *pkt;
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07004651 u8 *data;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004652
4653 /* Allocate the packet */
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02004654 pkt = bcm_pkt_buf_get_skb(SDPCM_HDRLEN + SDPCM_TEST_HDRLEN +
4655 DHD_SDALIGN, true);
Jason Cooper9b890322010-09-30 15:15:39 -04004656 if (!pkt) {
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02004657 DHD_ERROR(("%s: bcm_pkt_buf_get_skb failed!\n", __func__));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004658 return;
4659 }
Arend van Spriel3c9d4c32011-03-02 21:18:48 +01004660 PKTALIGN(pkt, (SDPCM_HDRLEN + SDPCM_TEST_HDRLEN), DHD_SDALIGN);
Arend van Spriel54991ad2010-11-23 14:06:24 +01004661 data = (u8 *) (pkt->data) + SDPCM_HDRLEN;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004662
4663 /* Fill in the test header */
4664 *data++ = SDPCM_TEST_SEND;
4665 *data++ = start;
4666 *data++ = (bus->pktgen_maxlen >> 0);
4667 *data++ = (bus->pktgen_maxlen >> 8);
4668
4669 /* Send it */
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07004670 if (dhdsdio_txpkt(bus, pkt, SDPCM_TEST_CHANNEL, true))
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004671 bus->pktgen_fail++;
4672}
4673
Arend van Sprielc26b1372010-11-23 14:06:23 +01004674static void dhdsdio_testrcv(dhd_bus_t *bus, struct sk_buff *pkt, uint seq)
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004675{
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07004676 u8 *data;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004677 uint pktlen;
4678
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07004679 u8 cmd;
4680 u8 extra;
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -07004681 u16 len;
4682 u16 offset;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004683
4684 /* Check for min length */
Arend van Spriel54991ad2010-11-23 14:06:24 +01004685 pktlen = pkt->len;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004686 if (pktlen < SDPCM_TEST_HDRLEN) {
4687 DHD_ERROR(("dhdsdio_restrcv: toss runt frame, pktlen %d\n",
4688 pktlen));
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02004689 bcm_pkt_buf_free_skb(pkt, false);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004690 return;
4691 }
4692
4693 /* Extract header fields */
Arend van Spriel54991ad2010-11-23 14:06:24 +01004694 data = pkt->data;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004695 cmd = *data++;
4696 extra = *data++;
4697 len = *data++;
4698 len += *data++ << 8;
4699
4700 /* Check length for relevant commands */
4701 if (cmd == SDPCM_TEST_DISCARD || cmd == SDPCM_TEST_ECHOREQ
4702 || cmd == SDPCM_TEST_ECHORSP) {
4703 if (pktlen != len + SDPCM_TEST_HDRLEN) {
4704 DHD_ERROR(("dhdsdio_testrcv: frame length mismatch, "
4705 "pktlen %d seq %d" " cmd %d extra %d len %d\n",
4706 pktlen, seq, cmd, extra, len));
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02004707 bcm_pkt_buf_free_skb(pkt, false);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004708 return;
4709 }
4710 }
4711
4712 /* Process as per command */
4713 switch (cmd) {
4714 case SDPCM_TEST_ECHOREQ:
4715 /* Rx->Tx turnaround ok (even on NDIS w/current
4716 implementation) */
Arend van Spriel54991ad2010-11-23 14:06:24 +01004717 *(u8 *) (pkt->data) = SDPCM_TEST_ECHORSP;
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07004718 if (dhdsdio_txpkt(bus, pkt, SDPCM_TEST_CHANNEL, true) == 0) {
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004719 bus->pktgen_sent++;
4720 } else {
4721 bus->pktgen_fail++;
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02004722 bcm_pkt_buf_free_skb(pkt, false);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004723 }
4724 bus->pktgen_rcvd++;
4725 break;
4726
4727 case SDPCM_TEST_ECHORSP:
4728 if (bus->ext_loop) {
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02004729 bcm_pkt_buf_free_skb(pkt, false);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004730 bus->pktgen_rcvd++;
4731 break;
4732 }
4733
4734 for (offset = 0; offset < len; offset++, data++) {
4735 if (*data != SDPCM_TEST_FILL(offset, extra)) {
4736 DHD_ERROR(("dhdsdio_testrcv: echo data mismatch: " "offset %d (len %d) expect 0x%02x rcvd 0x%02x\n",
4737 offset, len,
4738 SDPCM_TEST_FILL(offset, extra), *data));
4739 break;
4740 }
4741 }
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02004742 bcm_pkt_buf_free_skb(pkt, false);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004743 bus->pktgen_rcvd++;
4744 break;
4745
4746 case SDPCM_TEST_DISCARD:
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02004747 bcm_pkt_buf_free_skb(pkt, false);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004748 bus->pktgen_rcvd++;
4749 break;
4750
4751 case SDPCM_TEST_BURST:
4752 case SDPCM_TEST_SEND:
4753 default:
4754 DHD_INFO(("dhdsdio_testrcv: unsupported or unknown command, "
4755 "pktlen %d seq %d" " cmd %d extra %d len %d\n",
4756 pktlen, seq, cmd, extra, len));
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02004757 bcm_pkt_buf_free_skb(pkt, false);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004758 break;
4759 }
4760
4761 /* For recv mode, stop at limie (and tell dongle to stop sending) */
4762 if (bus->pktgen_mode == DHD_PKTGEN_RECV) {
4763 if (bus->pktgen_total
4764 && (bus->pktgen_rcvd >= bus->pktgen_total)) {
4765 bus->pktgen_count = 0;
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07004766 dhdsdio_sdtest_set(bus, false);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004767 }
4768 }
4769}
4770#endif /* SDTEST */
4771
4772extern bool dhd_bus_watchdog(dhd_pub_t *dhdp)
4773{
4774 dhd_bus_t *bus;
4775
4776 DHD_TIMER(("%s: Enter\n", __func__));
4777
4778 bus = dhdp->bus;
4779
4780 if (bus->dhd->dongle_reset)
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07004781 return false;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004782
4783 /* Ignore the timer if simulating bus down */
4784 if (bus->sleeping)
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07004785 return false;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004786
4787 dhd_os_sdlock(bus->dhd);
4788
4789 /* Poll period: check device if appropriate. */
4790 if (bus->poll && (++bus->polltick >= bus->pollrate)) {
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -07004791 u32 intstatus = 0;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004792
4793 /* Reset poll tick */
4794 bus->polltick = 0;
4795
4796 /* Check device if no interrupts */
4797 if (!bus->intr || (bus->intrcount == bus->lastintrs)) {
4798
4799 if (!bus->dpc_sched) {
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07004800 u8 devpend;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004801 devpend = bcmsdh_cfg_read(bus->sdh, SDIO_FUNC_0,
4802 SDIOD_CCCR_INTPEND,
4803 NULL);
4804 intstatus =
4805 devpend & (INTR_STATUS_FUNC1 |
4806 INTR_STATUS_FUNC2);
4807 }
4808
4809 /* If there is something, make like the ISR and
4810 schedule the DPC */
4811 if (intstatus) {
4812 bus->pollcnt++;
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07004813 bus->ipend = true;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004814 if (bus->intr)
4815 bcmsdh_intr_disable(bus->sdh);
4816
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07004817 bus->dpc_sched = true;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004818 dhd_sched_dpc(bus->dhd);
4819
4820 }
4821 }
4822
4823 /* Update interrupt tracking */
4824 bus->lastintrs = bus->intrcount;
4825 }
4826#ifdef DHD_DEBUG
4827 /* Poll for console output periodically */
4828 if (dhdp->busstate == DHD_BUS_DATA && dhd_console_ms != 0) {
4829 bus->console.count += dhd_watchdog_ms;
4830 if (bus->console.count >= dhd_console_ms) {
4831 bus->console.count -= dhd_console_ms;
4832 /* Make sure backplane clock is on */
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07004833 dhdsdio_clkctl(bus, CLK_AVAIL, false);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004834 if (dhdsdio_readconsole(bus) < 0)
4835 dhd_console_ms = 0; /* On error,
4836 stop trying */
4837 }
4838 }
4839#endif /* DHD_DEBUG */
4840
4841#ifdef SDTEST
4842 /* Generate packets if configured */
4843 if (bus->pktgen_count && (++bus->pktgen_tick >= bus->pktgen_freq)) {
4844 /* Make sure backplane clock is on */
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07004845 dhdsdio_clkctl(bus, CLK_AVAIL, false);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004846 bus->pktgen_tick = 0;
4847 dhdsdio_pktgen(bus);
4848 }
4849#endif
4850
4851 /* On idle timeout clear activity flag and/or turn off clock */
4852 if ((bus->idletime > 0) && (bus->clkstate == CLK_AVAIL)) {
4853 if (++bus->idlecount >= bus->idletime) {
4854 bus->idlecount = 0;
4855 if (bus->activity) {
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07004856 bus->activity = false;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004857 dhd_os_wd_timer(bus->dhd, dhd_watchdog_ms);
4858 } else {
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07004859 dhdsdio_clkctl(bus, CLK_NONE, false);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004860 }
4861 }
4862 }
4863
4864 dhd_os_sdunlock(bus->dhd);
4865
4866 return bus->ipend;
4867}
4868
4869#ifdef DHD_DEBUG
Greg Kroah-Hartman580a0bd2010-10-05 11:09:48 -07004870extern int dhd_bus_console_in(dhd_pub_t *dhdp, unsigned char *msg, uint msglen)
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004871{
4872 dhd_bus_t *bus = dhdp->bus;
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -07004873 u32 addr, val;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004874 int rv;
Arend van Sprielc26b1372010-11-23 14:06:23 +01004875 struct sk_buff *pkt;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004876
4877 /* Address could be zero if CONSOLE := 0 in dongle Makefile */
4878 if (bus->console_addr == 0)
Roland Vossene10d82d2011-05-03 11:35:19 +02004879 return -ENOTSUPP;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004880
4881 /* Exclusive bus access */
4882 dhd_os_sdlock(bus->dhd);
4883
4884 /* Don't allow input if dongle is in reset */
4885 if (bus->dhd->dongle_reset) {
4886 dhd_os_sdunlock(bus->dhd);
Roland Vossenb74ac122011-05-03 11:35:20 +02004887 return -EPERM;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004888 }
4889
4890 /* Request clock to allow SDIO accesses */
4891 BUS_WAKE(bus);
4892 /* No pend allowed since txpkt is called later, ht clk has to be on */
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07004893 dhdsdio_clkctl(bus, CLK_AVAIL, false);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004894
4895 /* Zero cbuf_index */
Greg Kroah-Hartmance0f1b82010-10-08 11:44:45 -07004896 addr = bus->console_addr + offsetof(hndrte_cons_t, cbuf_idx);
Stanislav Fomichev628f10b2011-02-20 21:43:32 +03004897 val = cpu_to_le32(0);
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07004898 rv = dhdsdio_membytes(bus, true, addr, (u8 *)&val, sizeof(val));
Jason Cooper9b890322010-09-30 15:15:39 -04004899 if (rv < 0)
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004900 goto done;
4901
4902 /* Write message into cbuf */
Greg Kroah-Hartmance0f1b82010-10-08 11:44:45 -07004903 addr = bus->console_addr + offsetof(hndrte_cons_t, cbuf);
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07004904 rv = dhdsdio_membytes(bus, true, addr, (u8 *)msg, msglen);
Jason Cooper9b890322010-09-30 15:15:39 -04004905 if (rv < 0)
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004906 goto done;
4907
4908 /* Write length into vcons_in */
Greg Kroah-Hartmance0f1b82010-10-08 11:44:45 -07004909 addr = bus->console_addr + offsetof(hndrte_cons_t, vcons_in);
Stanislav Fomichev628f10b2011-02-20 21:43:32 +03004910 val = cpu_to_le32(msglen);
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07004911 rv = dhdsdio_membytes(bus, true, addr, (u8 *)&val, sizeof(val));
Jason Cooper9b890322010-09-30 15:15:39 -04004912 if (rv < 0)
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004913 goto done;
4914
4915 /* Bump dongle by sending an empty event pkt.
4916 * sdpcm_sendup (RX) checks for virtual console input.
4917 */
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02004918 pkt = bcm_pkt_buf_get_skb(4 + SDPCM_RESERVE);
Jason Cooper9b890322010-09-30 15:15:39 -04004919 if ((pkt != NULL) && bus->clkstate == CLK_AVAIL)
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07004920 dhdsdio_txpkt(bus, pkt, SDPCM_EVENT_CHANNEL, true);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004921
4922done:
4923 if ((bus->idletime == DHD_IDLE_IMMEDIATE) && !bus->dpc_sched) {
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07004924 bus->activity = false;
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07004925 dhdsdio_clkctl(bus, CLK_NONE, true);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004926 }
4927
4928 dhd_os_sdunlock(bus->dhd);
4929
4930 return rv;
4931}
4932#endif /* DHD_DEBUG */
4933
4934#ifdef DHD_DEBUG
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07004935static void dhd_dump_cis(uint fn, u8 *cis)
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004936{
4937 uint byte, tag, tdata;
4938 DHD_INFO(("Function %d CIS:\n", fn));
4939
4940 for (tdata = byte = 0; byte < SBSDIO_CIS_SIZE_LIMIT; byte++) {
4941 if ((byte % 16) == 0)
4942 DHD_INFO((" "));
4943 DHD_INFO(("%02x ", cis[byte]));
4944 if ((byte % 16) == 15)
4945 DHD_INFO(("\n"));
4946 if (!tdata--) {
4947 tag = cis[byte];
4948 if (tag == 0xff)
4949 break;
4950 else if (!tag)
4951 tdata = 0;
4952 else if ((byte + 1) < SBSDIO_CIS_SIZE_LIMIT)
4953 tdata = cis[byte + 1] + 1;
4954 else
4955 DHD_INFO(("]"));
4956 }
4957 }
4958 if ((byte % 16) != 15)
4959 DHD_INFO(("\n"));
4960}
4961#endif /* DHD_DEBUG */
4962
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -07004963static bool dhdsdio_chipmatch(u16 chipid)
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004964{
4965 if (chipid == BCM4325_CHIP_ID)
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07004966 return true;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004967 if (chipid == BCM4329_CHIP_ID)
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07004968 return true;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004969 if (chipid == BCM4319_CHIP_ID)
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07004970 return true;
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07004971 return false;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004972}
4973
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -07004974static void *dhdsdio_probe(u16 venid, u16 devid, u16 bus_no,
4975 u16 slot, u16 func, uint bustype, void *regsva,
Arend van Spriel3c9d4c32011-03-02 21:18:48 +01004976 void *sdh)
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004977{
4978 int ret;
4979 dhd_bus_t *bus;
4980
4981 /* Init global variables at run-time, not as part of the declaration.
4982 * This is required to support init/de-init of the driver.
4983 * Initialization
4984 * of globals as part of the declaration results in non-deterministic
4985 * behavior since the value of the globals may be different on the
4986 * first time that the driver is initialized vs subsequent
4987 * initializations.
4988 */
4989 dhd_txbound = DHD_TXBOUND;
4990 dhd_rxbound = DHD_RXBOUND;
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07004991 dhd_alignctl = true;
4992 sd1idle = true;
4993 dhd_readahead = true;
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07004994 retrydata = false;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004995 dhd_dongle_memsize = 0;
4996 dhd_txminmax = DHD_TXMINMAX;
4997
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07004998 forcealign = true;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07004999
5000 dhd_common_init();
5001
5002 DHD_TRACE(("%s: Enter\n", __func__));
5003 DHD_INFO(("%s: venid 0x%04x devid 0x%04x\n", __func__, venid, devid));
5004
5005 /* We make assumptions about address window mappings */
Greg Kroah-Hartmanf024c482010-10-21 10:50:21 -07005006 ASSERT((unsigned long)regsva == SI_ENUM_BASE);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005007
5008 /* BCMSDH passes venid and devid based on CIS parsing -- but
5009 * low-power start
5010 * means early parse could fail, so here we should get either an ID
5011 * we recognize OR (-1) indicating we must request power first.
5012 */
5013 /* Check the Vendor ID */
5014 switch (venid) {
5015 case 0x0000:
Stanislav Fomichevbe1c09f2011-03-28 01:31:36 +04005016 case PCI_VENDOR_ID_BROADCOM:
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005017 break;
5018 default:
5019 DHD_ERROR(("%s: unknown vendor: 0x%04x\n", __func__, venid));
5020 return NULL;
5021 }
5022
5023 /* Check the Device ID and make sure it's one that we support */
5024 switch (devid) {
5025 case BCM4325_D11DUAL_ID: /* 4325 802.11a/g id */
5026 case BCM4325_D11G_ID: /* 4325 802.11g 2.4Ghz band id */
5027 case BCM4325_D11A_ID: /* 4325 802.11a 5Ghz band id */
5028 DHD_INFO(("%s: found 4325 Dongle\n", __func__));
5029 break;
5030 case BCM4329_D11NDUAL_ID: /* 4329 802.11n dualband device */
5031 case BCM4329_D11N2G_ID: /* 4329 802.11n 2.4G device */
5032 case BCM4329_D11N5G_ID: /* 4329 802.11n 5G device */
5033 case 0x4329:
5034 DHD_INFO(("%s: found 4329 Dongle\n", __func__));
5035 break;
5036 case BCM4319_D11N_ID: /* 4319 802.11n id */
5037 case BCM4319_D11N2G_ID: /* 4319 802.11n2g id */
5038 case BCM4319_D11N5G_ID: /* 4319 802.11n5g id */
5039 DHD_INFO(("%s: found 4319 Dongle\n", __func__));
5040 break;
5041 case 0:
5042 DHD_INFO(("%s: allow device id 0, will check chip internals\n",
5043 __func__));
5044 break;
5045
5046 default:
5047 DHD_ERROR(("%s: skipping 0x%04x/0x%04x, not a dongle\n",
5048 __func__, venid, devid));
5049 return NULL;
5050 }
5051
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005052 /* Allocate private bus interface state */
mike.rapoport@gmail.com5fcc1fc2010-10-13 00:09:10 +02005053 bus = kzalloc(sizeof(dhd_bus_t), GFP_ATOMIC);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005054 if (!bus) {
mike.rapoport@gmail.com5fcc1fc2010-10-13 00:09:10 +02005055 DHD_ERROR(("%s: kmalloc of dhd_bus_t failed\n", __func__));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005056 goto fail;
5057 }
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005058 bus->sdh = sdh;
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -07005059 bus->cl_devid = (u16) devid;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005060 bus->bus = DHD_BUS;
5061 bus->tx_seq = SDPCM_SEQUENCE_WRAP - 1;
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07005062 bus->usebufpool = false; /* Use bufpool if allocated,
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005063 else use locally malloced rxbuf */
5064
5065 /* attempt to attach to the dongle */
Arend van Spriel8da4a3a2011-03-02 21:18:42 +01005066 if (!(dhdsdio_probe_attach(bus, sdh, regsva, devid))) {
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005067 DHD_ERROR(("%s: dhdsdio_probe_attach failed\n", __func__));
5068 goto fail;
5069 }
5070
5071 /* Attach to the dhd/OS/network interface */
Arend van Spriel3c9d4c32011-03-02 21:18:48 +01005072 bus->dhd = dhd_attach(bus, SDPCM_RESERVE);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005073 if (!bus->dhd) {
5074 DHD_ERROR(("%s: dhd_attach failed\n", __func__));
5075 goto fail;
5076 }
5077
5078 /* Allocate buffers */
Arend van Spriel8da4a3a2011-03-02 21:18:42 +01005079 if (!(dhdsdio_probe_malloc(bus, sdh))) {
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005080 DHD_ERROR(("%s: dhdsdio_probe_malloc failed\n", __func__));
5081 goto fail;
5082 }
5083
Arend van Spriel8da4a3a2011-03-02 21:18:42 +01005084 if (!(dhdsdio_probe_init(bus, sdh))) {
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005085 DHD_ERROR(("%s: dhdsdio_probe_init failed\n", __func__));
5086 goto fail;
5087 }
5088
5089 /* Register interrupt callback, but mask it (not operational yet). */
5090 DHD_INTR(("%s: disable SDIO interrupts (not interested yet)\n",
5091 __func__));
5092 bcmsdh_intr_disable(sdh);
5093 ret = bcmsdh_intr_reg(sdh, dhdsdio_isr, bus);
5094 if (ret != 0) {
5095 DHD_ERROR(("%s: FAILED: bcmsdh_intr_reg returned %d\n",
5096 __func__, ret));
5097 goto fail;
5098 }
5099 DHD_INTR(("%s: registered SDIO interrupt function ok\n", __func__));
5100
5101 DHD_INFO(("%s: completed!!\n", __func__));
5102
5103 /* if firmware path present try to download and bring up bus */
Jason Cooper9b890322010-09-30 15:15:39 -04005104 ret = dhd_bus_start(bus->dhd);
5105 if (ret != 0) {
Roland Vossene10d82d2011-05-03 11:35:19 +02005106 if (ret == -ENOLINK) {
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005107 DHD_ERROR(("%s: dongle is not responding\n", __func__));
5108 goto fail;
5109 }
5110 }
5111 /* Ok, have the per-port tell the stack we're open for business */
5112 if (dhd_net_attach(bus->dhd, 0) != 0) {
5113 DHD_ERROR(("%s: Net attach failed!!\n", __func__));
5114 goto fail;
5115 }
5116
5117 return bus;
5118
5119fail:
Arend van Spriel3c9d4c32011-03-02 21:18:48 +01005120 dhdsdio_release(bus);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005121 return NULL;
5122}
5123
5124static bool
Arend van Spriel8da4a3a2011-03-02 21:18:42 +01005125dhdsdio_probe_attach(struct dhd_bus *bus, void *sdh, void *regsva, u16 devid)
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005126{
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07005127 u8 clkctl = 0;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005128 int err = 0;
5129
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07005130 bus->alp_only = true;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005131
5132 /* Return the window to backplane enumeration space for core access */
5133 if (dhdsdio_set_siaddr_window(bus, SI_ENUM_BASE))
5134 DHD_ERROR(("%s: FAILED to return to SI_ENUM_BASE\n", __func__));
5135
5136#ifdef DHD_DEBUG
Arend van Spriel0bef7742011-02-10 12:03:44 +01005137 printk(KERN_DEBUG "F1 signature read @0x18000000=0x%4x\n",
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005138 bcmsdh_reg_read(bus->sdh, SI_ENUM_BASE, 4));
5139
5140#endif /* DHD_DEBUG */
5141
Franky Linc05df632011-04-25 19:34:07 -07005142 /*
5143 * Force PLL off until dhdsdio_chip_attach()
5144 * programs PLL control regs
5145 */
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005146
5147 bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR,
5148 DHD_INIT_CLKCTL1, &err);
5149 if (!err)
5150 clkctl =
5151 bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR,
5152 &err);
5153
5154 if (err || ((clkctl & ~SBSDIO_AVBITS) != DHD_INIT_CLKCTL1)) {
5155 DHD_ERROR(("dhdsdio_probe: ChipClkCSR access: err %d wrote "
5156 "0x%02x read 0x%02x\n",
5157 err, DHD_INIT_CLKCTL1, clkctl));
5158 goto fail;
5159 }
5160#ifdef DHD_DEBUG
5161 if (DHD_INFO_ON()) {
5162 uint fn, numfn;
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07005163 u8 *cis[SDIOD_MAX_IOFUNCS];
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005164 int err = 0;
5165
5166 numfn = bcmsdh_query_iofnum(sdh);
5167 ASSERT(numfn <= SDIOD_MAX_IOFUNCS);
5168
5169 /* Make sure ALP is available before trying to read CIS */
5170 SPINWAIT(((clkctl = bcmsdh_cfg_read(sdh, SDIO_FUNC_1,
5171 SBSDIO_FUNC1_CHIPCLKCSR,
5172 NULL)),
5173 !SBSDIO_ALPAV(clkctl)), PMU_MAX_TRANSITION_DLY);
5174
5175 /* Now request ALP be put on the bus */
5176 bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR,
5177 DHD_INIT_CLKCTL2, &err);
mike.rapoport@gmail.com73831412010-10-13 00:09:07 +02005178 udelay(65);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005179
5180 for (fn = 0; fn <= numfn; fn++) {
Alexander Beregalov12d0eb42011-03-09 03:53:35 +03005181 cis[fn] = kzalloc(SBSDIO_CIS_SIZE_LIMIT, GFP_ATOMIC);
Jason Cooper9b890322010-09-30 15:15:39 -04005182 if (!cis[fn]) {
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005183 DHD_INFO(("dhdsdio_probe: fn %d cis malloc "
5184 "failed\n", fn));
5185 break;
5186 }
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005187
Jason Cooper9b890322010-09-30 15:15:39 -04005188 err = bcmsdh_cis_read(sdh, fn, cis[fn],
5189 SBSDIO_CIS_SIZE_LIMIT);
5190 if (err) {
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005191 DHD_INFO(("dhdsdio_probe: fn %d cis read "
5192 "err %d\n", fn, err));
mike.rapoport@gmail.com182acb32010-10-13 00:09:12 +02005193 kfree(cis[fn]);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005194 break;
5195 }
5196 dhd_dump_cis(fn, cis[fn]);
5197 }
5198
5199 while (fn-- > 0) {
5200 ASSERT(cis[fn]);
mike.rapoport@gmail.com182acb32010-10-13 00:09:12 +02005201 kfree(cis[fn]);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005202 }
5203
5204 if (err) {
5205 DHD_ERROR(("dhdsdio_probe: error read/parsing CIS\n"));
5206 goto fail;
5207 }
5208 }
5209#endif /* DHD_DEBUG */
5210
Franky Lincb63e4c2011-04-25 15:45:08 -07005211 if (dhdsdio_chip_attach(bus, regsva)) {
5212 DHD_ERROR(("%s: dhdsdio_chip_attach failed!\n", __func__));
5213 goto fail;
5214 }
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005215
Franky Linc05df632011-04-25 19:34:07 -07005216 bcmsdh_chipinfo(sdh, bus->ci->chip, bus->ci->chiprev);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005217
Franky Linc05df632011-04-25 19:34:07 -07005218 if (!dhdsdio_chipmatch((u16) bus->ci->chip)) {
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005219 DHD_ERROR(("%s: unsupported chip: 0x%04x\n",
Franky Linc05df632011-04-25 19:34:07 -07005220 __func__, bus->ci->chip));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005221 goto fail;
5222 }
5223
Franky Lin5d0d7a92011-04-25 19:34:05 -07005224 dhdsdio_sdiod_drive_strength_init(bus, dhd_sdiod_drive_strength);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005225
5226 /* Get info on the ARM and SOCRAM cores... */
5227 if (!DHD_NOPMU(bus)) {
Franky Linc05df632011-04-25 19:34:07 -07005228 bus->armrev = SBCOREREV(bcmsdh_reg_read(bus->sdh,
5229 CORE_SB(bus->ci->armcorebase, sbidhigh), 4));
5230 bus->orig_ramsize = bus->ci->ramsize;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005231 if (!(bus->orig_ramsize)) {
5232 DHD_ERROR(("%s: failed to find SOCRAM memory!\n",
5233 __func__));
5234 goto fail;
5235 }
5236 bus->ramsize = bus->orig_ramsize;
5237 if (dhd_dongle_memsize)
5238 dhd_dongle_setmemsize(bus, dhd_dongle_memsize);
5239
5240 DHD_ERROR(("DHD: dongle ram size is set to %d(orig %d)\n",
5241 bus->ramsize, bus->orig_ramsize));
5242 }
5243
Franky Linc05df632011-04-25 19:34:07 -07005244 bus->regs = (void *)bus->ci->buscorebase;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005245
5246 /* Set core control so an SDIO reset does a backplane reset */
Arend van Sprielff31c542011-03-01 10:56:54 +01005247 OR_REG(&bus->regs->corecontrol, CC_BPRESEN);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005248
Henry Ptasinskib33f0e22011-05-10 22:25:29 +02005249 bcm_pktq_init(&bus->txq, (PRIOMASK + 1), TXQLEN);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005250
5251 /* Locate an appropriately-aligned portion of hdrbuf */
Greg Kroah-Hartmanf024c482010-10-21 10:50:21 -07005252 bus->rxhdr = (u8 *) roundup((unsigned long)&bus->hdrbuf[0], DHD_SDALIGN);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005253
5254 /* Set the poll and/or interrupt flags */
5255 bus->intr = (bool) dhd_intr;
Jason Cooper9b890322010-09-30 15:15:39 -04005256 bus->poll = (bool) dhd_poll;
5257 if (bus->poll)
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005258 bus->pollrate = 1;
5259
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07005260 return true;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005261
5262fail:
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07005263 return false;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005264}
5265
Arend van Spriel8da4a3a2011-03-02 21:18:42 +01005266static bool dhdsdio_probe_malloc(dhd_bus_t *bus, void *sdh)
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005267{
5268 DHD_TRACE(("%s: Enter\n", __func__));
5269
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005270 if (bus->dhd->maxctl) {
5271 bus->rxblen =
Greg Kroah-Hartmane18d5312010-10-08 11:59:06 -07005272 roundup((bus->dhd->maxctl + SDPCM_HDRLEN),
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005273 ALIGNMENT) + DHD_SDALIGN;
mike.rapoport@gmail.com5fcc1fc2010-10-13 00:09:10 +02005274 bus->rxbuf = kmalloc(bus->rxblen, GFP_ATOMIC);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005275 if (!(bus->rxbuf)) {
mike.rapoport@gmail.com5fcc1fc2010-10-13 00:09:10 +02005276 DHD_ERROR(("%s: kmalloc of %d-byte rxbuf failed\n",
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005277 __func__, bus->rxblen));
5278 goto fail;
5279 }
5280 }
5281
5282 /* Allocate buffer to receive glomed packet */
mike.rapoport@gmail.com5fcc1fc2010-10-13 00:09:10 +02005283 bus->databuf = kmalloc(MAX_DATA_BUF, GFP_ATOMIC);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005284 if (!(bus->databuf)) {
mike.rapoport@gmail.com5fcc1fc2010-10-13 00:09:10 +02005285 DHD_ERROR(("%s: kmalloc of %d-byte databuf failed\n",
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005286 __func__, MAX_DATA_BUF));
5287 /* release rxbuf which was already located as above */
5288 if (!bus->rxblen)
mike.rapoport@gmail.com182acb32010-10-13 00:09:12 +02005289 kfree(bus->rxbuf);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005290 goto fail;
5291 }
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005292
5293 /* Align the buffer */
Greg Kroah-Hartmanf024c482010-10-21 10:50:21 -07005294 if ((unsigned long)bus->databuf % DHD_SDALIGN)
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005295 bus->dataptr =
5296 bus->databuf + (DHD_SDALIGN -
Greg Kroah-Hartmanf024c482010-10-21 10:50:21 -07005297 ((unsigned long)bus->databuf % DHD_SDALIGN));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005298 else
5299 bus->dataptr = bus->databuf;
5300
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07005301 return true;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005302
5303fail:
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07005304 return false;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005305}
5306
Arend van Spriel8da4a3a2011-03-02 21:18:42 +01005307static bool dhdsdio_probe_init(dhd_bus_t *bus, void *sdh)
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005308{
Greg Kroah-Hartman3e264162010-10-08 11:11:13 -07005309 s32 fnum;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005310
5311 DHD_TRACE(("%s: Enter\n", __func__));
5312
5313#ifdef SDTEST
5314 dhdsdio_pktgen_init(bus);
5315#endif /* SDTEST */
5316
5317 /* Disable F2 to clear any intermediate frame state on the dongle */
5318 bcmsdh_cfg_write(sdh, SDIO_FUNC_0, SDIOD_CCCR_IOEN, SDIO_FUNC_ENABLE_1,
5319 NULL);
5320
5321 bus->dhd->busstate = DHD_BUS_DOWN;
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07005322 bus->sleeping = false;
5323 bus->rxflow = false;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005324 bus->prev_rxlim_hit = 0;
5325
5326 /* Done with backplane-dependent accesses, can drop clock... */
5327 bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, 0, NULL);
5328
5329 /* ...and initialize clock/power states */
5330 bus->clkstate = CLK_SDONLY;
Greg Kroah-Hartman3e264162010-10-08 11:11:13 -07005331 bus->idletime = (s32) dhd_idletime;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005332 bus->idleclock = DHD_IDLE_ACTIVE;
5333
5334 /* Query the SD clock speed */
5335 if (bcmsdh_iovar_op(sdh, "sd_divisor", NULL, 0,
Greg Kroah-Hartman3e264162010-10-08 11:11:13 -07005336 &bus->sd_divisor, sizeof(s32),
Roland Vossena1c5ad82011-04-11 15:16:24 +02005337 false) != 0) {
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005338 DHD_ERROR(("%s: fail on %s get\n", __func__, "sd_divisor"));
5339 bus->sd_divisor = -1;
5340 } else {
5341 DHD_INFO(("%s: Initial value for %s is %d\n",
5342 __func__, "sd_divisor", bus->sd_divisor));
5343 }
5344
5345 /* Query the SD bus mode */
5346 if (bcmsdh_iovar_op(sdh, "sd_mode", NULL, 0,
Roland Vossena1c5ad82011-04-11 15:16:24 +02005347 &bus->sd_mode, sizeof(s32), false) != 0) {
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005348 DHD_ERROR(("%s: fail on %s get\n", __func__, "sd_mode"));
5349 bus->sd_mode = -1;
5350 } else {
5351 DHD_INFO(("%s: Initial value for %s is %d\n",
5352 __func__, "sd_mode", bus->sd_mode));
5353 }
5354
5355 /* Query the F2 block size, set roundup accordingly */
5356 fnum = 2;
Greg Kroah-Hartman3e264162010-10-08 11:11:13 -07005357 if (bcmsdh_iovar_op(sdh, "sd_blocksize", &fnum, sizeof(s32),
Roland Vossena1c5ad82011-04-11 15:16:24 +02005358 &bus->blocksize, sizeof(s32), false) != 0) {
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005359 bus->blocksize = 0;
5360 DHD_ERROR(("%s: fail on %s get\n", __func__, "sd_blocksize"));
5361 } else {
5362 DHD_INFO(("%s: Initial value for %s is %d\n",
5363 __func__, "sd_blocksize", bus->blocksize));
5364 }
Greg Kroah-Hartman7068c2f2010-10-08 11:34:59 -07005365 bus->roundup = min(max_roundup, bus->blocksize);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005366
5367 /* Query if bus module supports packet chaining,
5368 default to use if supported */
5369 if (bcmsdh_iovar_op(sdh, "sd_rxchain", NULL, 0,
Greg Kroah-Hartman3e264162010-10-08 11:11:13 -07005370 &bus->sd_rxchain, sizeof(s32),
Roland Vossena1c5ad82011-04-11 15:16:24 +02005371 false) != 0) {
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07005372 bus->sd_rxchain = false;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005373 } else {
5374 DHD_INFO(("%s: bus module (through bcmsdh API) %s chaining\n",
5375 __func__,
5376 (bus->sd_rxchain ? "supports" : "does not support")));
5377 }
5378 bus->use_rxchain = (bool) bus->sd_rxchain;
5379
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07005380 return true;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005381}
5382
5383bool
Arend van Spriel8da4a3a2011-03-02 21:18:42 +01005384dhd_bus_download_firmware(struct dhd_bus *bus, char *fw_path, char *nv_path)
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005385{
5386 bool ret;
5387 bus->fw_path = fw_path;
5388 bus->nv_path = nv_path;
5389
Arend van Spriel8da4a3a2011-03-02 21:18:42 +01005390 ret = dhdsdio_download_firmware(bus, bus->sdh);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005391
5392 return ret;
5393}
5394
5395static bool
Arend van Spriel8da4a3a2011-03-02 21:18:42 +01005396dhdsdio_download_firmware(struct dhd_bus *bus, void *sdh)
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005397{
5398 bool ret;
5399
5400 /* Download the firmware */
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07005401 dhdsdio_clkctl(bus, CLK_AVAIL, false);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005402
5403 ret = _dhdsdio_download_firmware(bus) == 0;
5404
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07005405 dhdsdio_clkctl(bus, CLK_SDONLY, false);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005406
5407 return ret;
5408}
5409
5410/* Detach and free everything */
Arend van Spriel3c9d4c32011-03-02 21:18:48 +01005411static void dhdsdio_release(dhd_bus_t *bus)
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005412{
5413 DHD_TRACE(("%s: Enter\n", __func__));
5414
5415 if (bus) {
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005416 /* De-register interrupt handler */
5417 bcmsdh_intr_disable(bus->sdh);
5418 bcmsdh_intr_dereg(bus->sdh);
5419
5420 if (bus->dhd) {
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005421 dhd_detach(bus->dhd);
Franky Lincee3cf42011-04-25 19:34:06 -07005422 dhdsdio_release_dongle(bus);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005423 bus->dhd = NULL;
5424 }
5425
Arend van Spriel8da4a3a2011-03-02 21:18:42 +01005426 dhdsdio_release_malloc(bus);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005427
mike.rapoport@gmail.com182acb32010-10-13 00:09:12 +02005428 kfree(bus);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005429 }
5430
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005431 DHD_TRACE(("%s: Disconnected\n", __func__));
5432}
5433
Arend van Spriel8da4a3a2011-03-02 21:18:42 +01005434static void dhdsdio_release_malloc(dhd_bus_t *bus)
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005435{
5436 DHD_TRACE(("%s: Enter\n", __func__));
5437
5438 if (bus->dhd && bus->dhd->dongle_reset)
5439 return;
5440
5441 if (bus->rxbuf) {
mike.rapoport@gmail.com182acb32010-10-13 00:09:12 +02005442 kfree(bus->rxbuf);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005443 bus->rxctl = bus->rxbuf = NULL;
5444 bus->rxlen = 0;
5445 }
5446
Ilia Mirkin46d994b2011-03-13 00:28:56 -05005447 kfree(bus->databuf);
5448 bus->databuf = NULL;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005449}
5450
Arend van Spriel8da4a3a2011-03-02 21:18:42 +01005451static void dhdsdio_release_dongle(dhd_bus_t *bus)
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005452{
5453 DHD_TRACE(("%s: Enter\n", __func__));
5454
5455 if (bus->dhd && bus->dhd->dongle_reset)
5456 return;
5457
Franky Linc05df632011-04-25 19:34:07 -07005458 if (bus->ci) {
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07005459 dhdsdio_clkctl(bus, CLK_AVAIL, false);
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07005460 dhdsdio_clkctl(bus, CLK_NONE, false);
Franky Lincee3cf42011-04-25 19:34:06 -07005461 dhdsdio_chip_detach(bus);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005462 if (bus->vars && bus->varsz)
mike.rapoport@gmail.com182acb32010-10-13 00:09:12 +02005463 kfree(bus->vars);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005464 bus->vars = NULL;
5465 }
5466
5467 DHD_TRACE(("%s: Disconnected\n", __func__));
5468}
5469
5470static void dhdsdio_disconnect(void *ptr)
5471{
5472 dhd_bus_t *bus = (dhd_bus_t *)ptr;
5473
5474 DHD_TRACE(("%s: Enter\n", __func__));
5475
5476 if (bus) {
5477 ASSERT(bus->dhd);
Arend van Spriel3c9d4c32011-03-02 21:18:48 +01005478 dhdsdio_release(bus);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005479 }
5480
5481 DHD_TRACE(("%s: Disconnected\n", __func__));
5482}
5483
5484/* Register/Unregister functions are called by the main DHD entry
5485 * point (e.g. module insertion) to link with the bus driver, in
5486 * order to look for or await the device.
5487 */
5488
5489static bcmsdh_driver_t dhd_sdio = {
5490 dhdsdio_probe,
5491 dhdsdio_disconnect
5492};
5493
5494int dhd_bus_register(void)
5495{
5496 DHD_TRACE(("%s: Enter\n", __func__));
5497
5498 return bcmsdh_register(&dhd_sdio);
5499}
5500
5501void dhd_bus_unregister(void)
5502{
5503 DHD_TRACE(("%s: Enter\n", __func__));
5504
5505 bcmsdh_unregister();
5506}
5507
5508#ifdef BCMEMBEDIMAGE
5509static int dhdsdio_download_code_array(struct dhd_bus *bus)
5510{
5511 int bcmerror = -1;
5512 int offset = 0;
5513
5514 DHD_INFO(("%s: download embedded firmware...\n", __func__));
5515
5516 /* Download image */
5517 while ((offset + MEMBLOCK) < sizeof(dlarray)) {
5518 bcmerror =
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07005519 dhdsdio_membytes(bus, true, offset, dlarray + offset,
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005520 MEMBLOCK);
5521 if (bcmerror) {
5522 DHD_ERROR(("%s: error %d on writing %d membytes at "
5523 "0x%08x\n",
5524 __func__, bcmerror, MEMBLOCK, offset));
5525 goto err;
5526 }
5527
5528 offset += MEMBLOCK;
5529 }
5530
5531 if (offset < sizeof(dlarray)) {
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07005532 bcmerror = dhdsdio_membytes(bus, true, offset,
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005533 dlarray + offset,
5534 sizeof(dlarray) - offset);
5535 if (bcmerror) {
5536 DHD_ERROR(("%s: error %d on writing %d membytes at "
5537 "0x%08x\n", __func__, bcmerror,
5538 sizeof(dlarray) - offset, offset));
5539 goto err;
5540 }
5541 }
5542#ifdef DHD_DEBUG
5543 /* Upload and compare the downloaded code */
5544 {
5545 unsigned char *ularray;
5546
mike.rapoport@gmail.com5fcc1fc2010-10-13 00:09:10 +02005547 ularray = kmalloc(bus->ramsize, GFP_ATOMIC);
Alexander Beregalov570edd32011-03-13 21:58:47 +03005548 if (!ularray) {
Roland Vossene10d82d2011-05-03 11:35:19 +02005549 bcmerror = -ENOMEM;
Alexander Beregalov570edd32011-03-13 21:58:47 +03005550 goto err;
5551 }
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005552 /* Upload image to verify downloaded contents. */
5553 offset = 0;
5554 memset(ularray, 0xaa, bus->ramsize);
5555 while ((offset + MEMBLOCK) < sizeof(dlarray)) {
5556 bcmerror =
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07005557 dhdsdio_membytes(bus, false, offset,
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005558 ularray + offset, MEMBLOCK);
5559 if (bcmerror) {
5560 DHD_ERROR(("%s: error %d on reading %d membytes"
5561 " at 0x%08x\n",
5562 __func__, bcmerror, MEMBLOCK, offset));
Alexander Beregalov570edd32011-03-13 21:58:47 +03005563 goto free;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005564 }
5565
5566 offset += MEMBLOCK;
5567 }
5568
5569 if (offset < sizeof(dlarray)) {
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07005570 bcmerror = dhdsdio_membytes(bus, false, offset,
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005571 ularray + offset,
5572 sizeof(dlarray) - offset);
5573 if (bcmerror) {
5574 DHD_ERROR(("%s: error %d on reading %d membytes at 0x%08x\n",
5575 __func__, bcmerror,
5576 sizeof(dlarray) - offset, offset));
Alexander Beregalov570edd32011-03-13 21:58:47 +03005577 goto free;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005578 }
5579 }
5580
5581 if (memcmp(dlarray, ularray, sizeof(dlarray))) {
5582 DHD_ERROR(("%s: Downloaded image is corrupted.\n",
5583 __func__));
5584 ASSERT(0);
Alexander Beregalov570edd32011-03-13 21:58:47 +03005585 goto free;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005586 } else
5587 DHD_ERROR(("%s: Download/Upload/Compare succeeded.\n",
5588 __func__));
Alexander Beregalov570edd32011-03-13 21:58:47 +03005589free:
mike.rapoport@gmail.com182acb32010-10-13 00:09:12 +02005590 kfree(ularray);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005591 }
5592#endif /* DHD_DEBUG */
5593
5594err:
5595 return bcmerror;
5596}
5597#endif /* BCMEMBEDIMAGE */
5598
5599static int dhdsdio_download_code_file(struct dhd_bus *bus, char *fw_path)
5600{
5601 int bcmerror = -1;
5602 int offset = 0;
5603 uint len;
5604 void *image = NULL;
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07005605 u8 *memblock = NULL, *memptr;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005606
5607 DHD_INFO(("%s: download firmware %s\n", __func__, fw_path));
5608
5609 image = dhd_os_open_image(fw_path);
5610 if (image == NULL)
5611 goto err;
5612
mike.rapoport@gmail.com5fcc1fc2010-10-13 00:09:10 +02005613 memptr = memblock = kmalloc(MEMBLOCK + DHD_SDALIGN, GFP_ATOMIC);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005614 if (memblock == NULL) {
5615 DHD_ERROR(("%s: Failed to allocate memory %d bytes\n",
5616 __func__, MEMBLOCK));
5617 goto err;
5618 }
Greg Kroah-Hartmanf024c482010-10-21 10:50:21 -07005619 if ((u32)(unsigned long)memblock % DHD_SDALIGN)
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005620 memptr +=
Greg Kroah-Hartmanf024c482010-10-21 10:50:21 -07005621 (DHD_SDALIGN - ((u32)(unsigned long)memblock % DHD_SDALIGN));
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005622
5623 /* Download image */
5624 while ((len =
5625 dhd_os_get_image_block((char *)memptr, MEMBLOCK, image))) {
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07005626 bcmerror = dhdsdio_membytes(bus, true, offset, memptr, len);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005627 if (bcmerror) {
5628 DHD_ERROR(("%s: error %d on writing %d membytes at "
5629 "0x%08x\n", __func__, bcmerror, MEMBLOCK, offset));
5630 goto err;
5631 }
5632
5633 offset += MEMBLOCK;
5634 }
5635
5636err:
Ilia Mirkin46d994b2011-03-13 00:28:56 -05005637 kfree(memblock);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005638
5639 if (image)
5640 dhd_os_close_image(image);
5641
5642 return bcmerror;
5643}
5644
5645/*
5646 * ProcessVars:Takes a buffer of "<var>=<value>\n" lines read from a file
5647 * and ending in a NUL.
5648 * Removes carriage returns, empty lines, comment lines, and converts
5649 * newlines to NULs.
5650 * Shortens buffer as needed and pads with NULs. End of buffer is marked
5651 * by two NULs.
5652*/
5653
5654static uint process_nvram_vars(char *varbuf, uint len)
5655{
5656 char *dp;
5657 bool findNewline;
5658 int column;
5659 uint buf_len, n;
5660
5661 dp = varbuf;
5662
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07005663 findNewline = false;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005664 column = 0;
5665
5666 for (n = 0; n < len; n++) {
5667 if (varbuf[n] == 0)
5668 break;
5669 if (varbuf[n] == '\r')
5670 continue;
5671 if (findNewline && varbuf[n] != '\n')
5672 continue;
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07005673 findNewline = false;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005674 if (varbuf[n] == '#') {
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07005675 findNewline = true;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005676 continue;
5677 }
5678 if (varbuf[n] == '\n') {
5679 if (column == 0)
5680 continue;
5681 *dp++ = 0;
5682 column = 0;
5683 continue;
5684 }
5685 *dp++ = varbuf[n];
5686 column++;
5687 }
5688 buf_len = dp - varbuf;
5689
5690 while (dp < varbuf + n)
5691 *dp++ = 0;
5692
5693 return buf_len;
5694}
5695
5696/*
5697 EXAMPLE: nvram_array
5698 nvram_arry format:
5699 name=value
5700 Use carriage return at the end of each assignment,
5701 and an empty string with
5702 carriage return at the end of array.
5703
5704 For example:
5705 unsigned char nvram_array[] = {"name1=value1\n",
5706 "name2=value2\n", "\n"};
5707 Hex values start with 0x, and mac addr format: xx:xx:xx:xx:xx:xx.
5708
5709 Search "EXAMPLE: nvram_array" to see how the array is activated.
5710*/
5711
5712void dhd_bus_set_nvram_params(struct dhd_bus *bus, const char *nvram_params)
5713{
5714 bus->nvram_params = nvram_params;
5715}
5716
5717static int dhdsdio_download_nvram(struct dhd_bus *bus)
5718{
5719 int bcmerror = -1;
5720 uint len;
5721 void *image = NULL;
5722 char *memblock = NULL;
5723 char *bufp;
5724 char *nv_path;
5725 bool nvram_file_exists;
5726
5727 nv_path = bus->nv_path;
5728
5729 nvram_file_exists = ((nv_path != NULL) && (nv_path[0] != '\0'));
5730 if (!nvram_file_exists && (bus->nvram_params == NULL))
5731 return 0;
5732
5733 if (nvram_file_exists) {
5734 image = dhd_os_open_image(nv_path);
5735 if (image == NULL)
5736 goto err;
5737 }
5738
mike.rapoport@gmail.com5fcc1fc2010-10-13 00:09:10 +02005739 memblock = kmalloc(MEMBLOCK, GFP_ATOMIC);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005740 if (memblock == NULL) {
5741 DHD_ERROR(("%s: Failed to allocate memory %d bytes\n",
5742 __func__, MEMBLOCK));
5743 goto err;
5744 }
5745
5746 /* Download variables */
5747 if (nvram_file_exists) {
5748 len = dhd_os_get_image_block(memblock, MEMBLOCK, image);
5749 } else {
5750 len = strlen(bus->nvram_params);
5751 ASSERT(len <= MEMBLOCK);
5752 if (len > MEMBLOCK)
5753 len = MEMBLOCK;
5754 memcpy(memblock, bus->nvram_params, len);
5755 }
5756
5757 if (len > 0 && len < MEMBLOCK) {
5758 bufp = (char *)memblock;
5759 bufp[len] = 0;
5760 len = process_nvram_vars(bufp, len);
5761 bufp += len;
5762 *bufp++ = 0;
5763 if (len)
5764 bcmerror = dhdsdio_downloadvars(bus, memblock, len + 1);
5765 if (bcmerror) {
5766 DHD_ERROR(("%s: error downloading vars: %d\n",
5767 __func__, bcmerror));
5768 }
5769 } else {
5770 DHD_ERROR(("%s: error reading nvram file: %d\n",
5771 __func__, len));
Roland Vossenb74ac122011-05-03 11:35:20 +02005772 bcmerror = -EIO;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005773 }
5774
5775err:
Ilia Mirkin46d994b2011-03-13 00:28:56 -05005776 kfree(memblock);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005777
5778 if (image)
5779 dhd_os_close_image(image);
5780
5781 return bcmerror;
5782}
5783
5784static int _dhdsdio_download_firmware(struct dhd_bus *bus)
5785{
5786 int bcmerror = -1;
5787
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07005788 bool embed = false; /* download embedded firmware */
5789 bool dlok = false; /* download firmware succeeded */
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005790
5791 /* Out immediately if no image to download */
5792 if ((bus->fw_path == NULL) || (bus->fw_path[0] == '\0')) {
5793#ifdef BCMEMBEDIMAGE
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07005794 embed = true;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005795#else
5796 return bcmerror;
5797#endif
5798 }
5799
5800 /* Keep arm in reset */
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07005801 if (dhdsdio_download_state(bus, true)) {
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005802 DHD_ERROR(("%s: error placing ARM core in reset\n", __func__));
5803 goto err;
5804 }
5805
5806 /* External image takes precedence if specified */
5807 if ((bus->fw_path != NULL) && (bus->fw_path[0] != '\0')) {
5808 if (dhdsdio_download_code_file(bus, bus->fw_path)) {
5809 DHD_ERROR(("%s: dongle image file download failed\n",
5810 __func__));
5811#ifdef BCMEMBEDIMAGE
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07005812 embed = true;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005813#else
5814 goto err;
5815#endif
5816 } else {
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07005817 embed = false;
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07005818 dlok = true;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005819 }
5820 }
5821#ifdef BCMEMBEDIMAGE
5822 if (embed) {
5823 if (dhdsdio_download_code_array(bus)) {
5824 DHD_ERROR(("%s: dongle image array download failed\n",
5825 __func__));
5826 goto err;
5827 } else {
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07005828 dlok = true;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005829 }
5830 }
5831#endif
5832 if (!dlok) {
5833 DHD_ERROR(("%s: dongle image download failed\n", __func__));
5834 goto err;
5835 }
5836
5837 /* EXAMPLE: nvram_array */
5838 /* If a valid nvram_arry is specified as above, it can be passed
5839 down to dongle */
5840 /* dhd_bus_set_nvram_params(bus, (char *)&nvram_array); */
5841
5842 /* External nvram takes precedence if specified */
5843 if (dhdsdio_download_nvram(bus)) {
5844 DHD_ERROR(("%s: dongle nvram file download failed\n",
5845 __func__));
5846 }
5847
5848 /* Take arm out of reset */
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07005849 if (dhdsdio_download_state(bus, false)) {
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005850 DHD_ERROR(("%s: error getting out of ARM core reset\n",
5851 __func__));
5852 goto err;
5853 }
5854
5855 bcmerror = 0;
5856
5857err:
5858 return bcmerror;
5859}
5860
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005861
5862static int
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -07005863dhd_bcmsdh_send_buf(dhd_bus_t *bus, u32 addr, uint fn, uint flags,
Arend van Sprielc26b1372010-11-23 14:06:23 +01005864 u8 *buf, uint nbytes, struct sk_buff *pkt,
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005865 bcmsdh_cmplt_fn_t complete, void *handle)
5866{
5867 return bcmsdh_send_buf
5868 (bus->sdh, addr, fn, flags, buf, nbytes, pkt, complete,
5869 handle);
5870}
5871
5872uint dhd_bus_chip(struct dhd_bus *bus)
5873{
Franky Linc05df632011-04-25 19:34:07 -07005874 ASSERT(bus->ci != NULL);
5875 return bus->ci->chip;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005876}
5877
5878void *dhd_bus_pub(struct dhd_bus *bus)
5879{
5880 return bus->dhd;
5881}
5882
5883void *dhd_bus_txq(struct dhd_bus *bus)
5884{
5885 return &bus->txq;
5886}
5887
5888uint dhd_bus_hdrlen(struct dhd_bus *bus)
5889{
5890 return SDPCM_HDRLEN;
5891}
5892
Greg Kroah-Hartman3fd79f72010-10-05 10:11:12 -07005893int dhd_bus_devreset(dhd_pub_t *dhdp, u8 flag)
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005894{
5895 int bcmerror = 0;
5896 dhd_bus_t *bus;
5897
5898 bus = dhdp->bus;
5899
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07005900 if (flag == true) {
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005901 if (!bus->dhd->dongle_reset) {
5902 /* Expect app to have torn down any
5903 connection before calling */
5904 /* Stop the bus, disable F2 */
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07005905 dhd_bus_stop(bus, false);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005906
5907 /* Clean tx/rx buffer pointers,
5908 detach from the dongle */
Arend van Spriel8da4a3a2011-03-02 21:18:42 +01005909 dhdsdio_release_dongle(bus);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005910
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07005911 bus->dhd->dongle_reset = true;
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07005912 bus->dhd->up = false;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005913
5914 DHD_TRACE(("%s: WLAN OFF DONE\n", __func__));
5915 /* App can now remove power from device */
5916 } else
Roland Vossenb74ac122011-05-03 11:35:20 +02005917 bcmerror = -EIO;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005918 } else {
5919 /* App must have restored power to device before calling */
5920
5921 DHD_TRACE(("\n\n%s: == WLAN ON ==\n", __func__));
5922
5923 if (bus->dhd->dongle_reset) {
5924 /* Turn on WLAN */
5925 /* Reset SD client */
5926 bcmsdh_reset(bus->sdh);
5927
5928 /* Attempt to re-attach & download */
Arend van Spriel8da4a3a2011-03-02 21:18:42 +01005929 if (dhdsdio_probe_attach(bus, bus->sdh,
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -07005930 (u32 *) SI_ENUM_BASE,
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005931 bus->cl_devid)) {
5932 /* Attempt to download binary to the dongle */
5933 if (dhdsdio_probe_init
Arend van Spriel8da4a3a2011-03-02 21:18:42 +01005934 (bus, bus->sdh)
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005935 && dhdsdio_download_firmware(bus,
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005936 bus->sdh)) {
5937
5938 /* Re-init bus, enable F2 transfer */
5939 dhd_bus_init((dhd_pub_t *) bus->dhd,
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07005940 false);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005941
5942#if defined(OOB_INTR_ONLY)
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07005943 dhd_enable_oob_intr(bus, true);
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005944#endif /* defined(OOB_INTR_ONLY) */
5945
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07005946 bus->dhd->dongle_reset = false;
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -07005947 bus->dhd->up = true;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005948
5949 DHD_TRACE(("%s: WLAN ON DONE\n",
5950 __func__));
5951 } else
Roland Vossenb74ac122011-05-03 11:35:20 +02005952 bcmerror = -EIO;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005953 } else
Roland Vossenb74ac122011-05-03 11:35:20 +02005954 bcmerror = -EIO;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005955 } else {
Roland Vossenb74ac122011-05-03 11:35:20 +02005956 bcmerror = -EISCONN;
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -07005957 DHD_ERROR(("%s: Set DEVRESET=false invoked when device "
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005958 "is on\n", __func__));
Roland Vossenb74ac122011-05-03 11:35:20 +02005959 bcmerror = -EIO;
Henry Ptasinskicf2b4482010-09-20 22:33:12 -07005960 }
5961 }
5962 return bcmerror;
5963}
Franky Lincb63e4c2011-04-25 15:45:08 -07005964
5965static int
5966dhdsdio_chip_recognition(bcmsdh_info_t *sdh, struct chip_info *ci, void *regs)
5967{
5968 u32 regdata;
5969
5970 /*
5971 * Get CC core rev
5972 * Chipid is assume to be at offset 0 from regs arg
5973 * For different chiptypes or old sdio hosts w/o chipcommon,
5974 * other ways of recognition should be added here.
5975 */
5976 ci->cccorebase = (u32)regs;
5977 regdata = bcmsdh_reg_read(sdh, CORE_CC_REG(ci->cccorebase, chipid), 4);
5978 ci->chip = regdata & CID_ID_MASK;
5979 ci->chiprev = (regdata & CID_REV_MASK) >> CID_REV_SHIFT;
5980
5981 DHD_INFO(("%s: chipid=0x%x chiprev=%d\n",
5982 __func__, ci->chip, ci->chiprev));
5983
5984 /* Address of cores for new chips should be added here */
5985 switch (ci->chip) {
5986 case BCM4329_CHIP_ID:
5987 ci->buscorebase = BCM4329_CORE_BUS_BASE;
5988 ci->ramcorebase = BCM4329_CORE_SOCRAM_BASE;
5989 ci->armcorebase = BCM4329_CORE_ARM_BASE;
Franky Linc05df632011-04-25 19:34:07 -07005990 ci->ramsize = BCM4329_RAMSIZE;
Franky Lincb63e4c2011-04-25 15:45:08 -07005991 break;
5992 default:
5993 DHD_ERROR(("%s: chipid 0x%x is not supported\n",
5994 __func__, ci->chip));
5995 return -ENODEV;
5996 }
5997
5998 regdata = bcmsdh_reg_read(sdh,
5999 CORE_SB(ci->cccorebase, sbidhigh), 4);
6000 ci->ccrev = SBCOREREV(regdata);
6001
6002 regdata = bcmsdh_reg_read(sdh,
6003 CORE_CC_REG(ci->cccorebase, pmucapabilities), 4);
6004 ci->pmurev = regdata & PCAP_REV_MASK;
6005
6006 regdata = bcmsdh_reg_read(sdh, CORE_SB(ci->buscorebase, sbidhigh), 4);
6007 ci->buscorerev = SBCOREREV(regdata);
6008 ci->buscoretype = (regdata & SBIDH_CC_MASK) >> SBIDH_CC_SHIFT;
6009
6010 DHD_INFO(("%s: ccrev=%d, pmurev=%d, buscore rev/type=%d/0x%x\n",
6011 __func__, ci->ccrev, ci->pmurev,
6012 ci->buscorerev, ci->buscoretype));
6013
6014 /* get chipcommon capabilites */
6015 ci->cccaps = bcmsdh_reg_read(sdh,
6016 CORE_CC_REG(ci->cccorebase, capabilities), 4);
6017
6018 return 0;
6019}
6020
6021static void
6022dhdsdio_chip_disablecore(bcmsdh_info_t *sdh, u32 corebase)
6023{
6024 u32 regdata;
6025
6026 regdata = bcmsdh_reg_read(sdh,
6027 CORE_SB(corebase, sbtmstatelow), 4);
6028 if (regdata & SBTML_RESET)
6029 return;
6030
6031 regdata = bcmsdh_reg_read(sdh,
6032 CORE_SB(corebase, sbtmstatelow), 4);
6033 if ((regdata & (SICF_CLOCK_EN << SBTML_SICF_SHIFT)) != 0) {
6034 /*
6035 * set target reject and spin until busy is clear
6036 * (preserve core-specific bits)
6037 */
6038 regdata = bcmsdh_reg_read(sdh,
6039 CORE_SB(corebase, sbtmstatelow), 4);
6040 bcmsdh_reg_write(sdh, CORE_SB(corebase, sbtmstatelow), 4,
6041 regdata | SBTML_REJ);
6042
6043 regdata = bcmsdh_reg_read(sdh,
6044 CORE_SB(corebase, sbtmstatelow), 4);
6045 udelay(1);
6046 SPINWAIT((bcmsdh_reg_read(sdh,
6047 CORE_SB(corebase, sbtmstatehigh), 4) &
6048 SBTMH_BUSY), 100000);
6049
6050 regdata = bcmsdh_reg_read(sdh,
6051 CORE_SB(corebase, sbtmstatehigh), 4);
6052 if (regdata & SBTMH_BUSY)
6053 DHD_ERROR(("%s: ARM core still busy\n", __func__));
6054
6055 regdata = bcmsdh_reg_read(sdh,
6056 CORE_SB(corebase, sbidlow), 4);
6057 if (regdata & SBIDL_INIT) {
6058 regdata = bcmsdh_reg_read(sdh,
6059 CORE_SB(corebase, sbimstate), 4) |
6060 SBIM_RJ;
6061 bcmsdh_reg_write(sdh,
6062 CORE_SB(corebase, sbimstate), 4,
6063 regdata);
6064 regdata = bcmsdh_reg_read(sdh,
6065 CORE_SB(corebase, sbimstate), 4);
6066 udelay(1);
6067 SPINWAIT((bcmsdh_reg_read(sdh,
6068 CORE_SB(corebase, sbimstate), 4) &
6069 SBIM_BY), 100000);
6070 }
6071
6072 /* set reset and reject while enabling the clocks */
6073 bcmsdh_reg_write(sdh,
6074 CORE_SB(corebase, sbtmstatelow), 4,
6075 (((SICF_FGC | SICF_CLOCK_EN) << SBTML_SICF_SHIFT) |
6076 SBTML_REJ | SBTML_RESET));
6077 regdata = bcmsdh_reg_read(sdh,
6078 CORE_SB(corebase, sbtmstatelow), 4);
6079 udelay(10);
6080
6081 /* clear the initiator reject bit */
6082 regdata = bcmsdh_reg_read(sdh,
6083 CORE_SB(corebase, sbidlow), 4);
6084 if (regdata & SBIDL_INIT) {
6085 regdata = bcmsdh_reg_read(sdh,
6086 CORE_SB(corebase, sbimstate), 4) &
6087 ~SBIM_RJ;
6088 bcmsdh_reg_write(sdh,
6089 CORE_SB(corebase, sbimstate), 4,
6090 regdata);
6091 }
6092 }
6093
6094 /* leave reset and reject asserted */
6095 bcmsdh_reg_write(sdh, CORE_SB(corebase, sbtmstatelow), 4,
6096 (SBTML_REJ | SBTML_RESET));
6097 udelay(1);
6098}
6099
6100static int
6101dhdsdio_chip_attach(struct dhd_bus *bus, void *regs)
6102{
6103 struct chip_info *ci;
6104 int err;
6105 u8 clkval, clkset;
6106
6107 DHD_TRACE(("%s: Enter\n", __func__));
6108
6109 /* alloc chip_info_t */
6110 ci = kmalloc(sizeof(struct chip_info), GFP_ATOMIC);
6111 if (NULL == ci) {
6112 DHD_ERROR(("%s: malloc failed!\n", __func__));
6113 return -ENOMEM;
6114 }
6115
6116 memset((unsigned char *)ci, 0, sizeof(struct chip_info));
6117
6118 /* bus/core/clk setup for register access */
6119 /* Try forcing SDIO core to do ALPAvail request only */
6120 clkset = SBSDIO_FORCE_HW_CLKREQ_OFF | SBSDIO_ALP_AVAIL_REQ;
6121 bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR,
6122 clkset, &err);
6123 if (err) {
6124 DHD_ERROR(("%s: error writing for HT off\n", __func__));
6125 goto fail;
6126 }
6127
6128 /* If register supported, wait for ALPAvail and then force ALP */
6129 /* This may take up to 15 milliseconds */
6130 clkval = bcmsdh_cfg_read(bus->sdh, SDIO_FUNC_1,
6131 SBSDIO_FUNC1_CHIPCLKCSR, NULL);
6132 if ((clkval & ~SBSDIO_AVBITS) == clkset) {
6133 SPINWAIT(((clkval =
6134 bcmsdh_cfg_read(bus->sdh, SDIO_FUNC_1,
6135 SBSDIO_FUNC1_CHIPCLKCSR,
6136 NULL)),
6137 !SBSDIO_ALPAV(clkval)),
6138 PMU_MAX_TRANSITION_DLY);
6139 if (!SBSDIO_ALPAV(clkval)) {
6140 DHD_ERROR(("%s: timeout on ALPAV wait, clkval 0x%02x\n",
6141 __func__, clkval));
6142 err = -EBUSY;
6143 goto fail;
6144 }
6145 clkset = SBSDIO_FORCE_HW_CLKREQ_OFF |
6146 SBSDIO_FORCE_ALP;
6147 bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1,
6148 SBSDIO_FUNC1_CHIPCLKCSR,
6149 clkset, &err);
6150 udelay(65);
6151 } else {
6152 DHD_ERROR(("%s: ChipClkCSR access: wrote 0x%02x read 0x%02x\n",
6153 __func__, clkset, clkval));
6154 err = -EACCES;
6155 goto fail;
6156 }
6157
6158 /* Also, disable the extra SDIO pull-ups */
6159 bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_SDIOPULLUP, 0,
6160 NULL);
6161
6162 err = dhdsdio_chip_recognition(bus->sdh, ci, regs);
6163 if (err)
6164 goto fail;
6165
6166 /*
6167 * Make sure any on-chip ARM is off (in case strapping is wrong),
6168 * or downloaded code was already running.
6169 */
6170 dhdsdio_chip_disablecore(bus->sdh, ci->armcorebase);
6171
6172 bcmsdh_reg_write(bus->sdh,
6173 CORE_CC_REG(ci->cccorebase, gpiopullup), 4, 0);
6174 bcmsdh_reg_write(bus->sdh,
6175 CORE_CC_REG(ci->cccorebase, gpiopulldown), 4, 0);
6176
6177 /* Disable F2 to clear any intermediate frame state on the dongle */
6178 bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_0, SDIOD_CCCR_IOEN,
6179 SDIO_FUNC_ENABLE_1, NULL);
6180
6181 /* WAR: cmd52 backplane read so core HW will drop ALPReq */
6182 clkval = bcmsdh_cfg_read(bus->sdh, SDIO_FUNC_1,
6183 0, NULL);
6184
6185 /* Done with backplane-dependent accesses, can drop clock... */
6186 bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, 0,
6187 NULL);
6188
6189 bus->ci = ci;
6190 return 0;
6191fail:
6192 bus->ci = NULL;
6193 kfree(ci);
6194 return err;
6195}
Franky Lineb5dc512011-04-25 19:34:04 -07006196
6197static void
6198dhdsdio_chip_resetcore(bcmsdh_info_t *sdh, u32 corebase)
6199{
6200 u32 regdata;
6201
6202 /*
6203 * Must do the disable sequence first to work for
6204 * arbitrary current core state.
6205 */
6206 dhdsdio_chip_disablecore(sdh, corebase);
6207
6208 /*
6209 * Now do the initialization sequence.
6210 * set reset while enabling the clock and
6211 * forcing them on throughout the core
6212 */
6213 bcmsdh_reg_write(sdh, CORE_SB(corebase, sbtmstatelow), 4,
6214 ((SICF_FGC | SICF_CLOCK_EN) << SBTML_SICF_SHIFT) |
6215 SBTML_RESET);
6216 udelay(1);
6217
6218 regdata = bcmsdh_reg_read(sdh, CORE_SB(corebase, sbtmstatehigh), 4);
6219 if (regdata & SBTMH_SERR)
6220 bcmsdh_reg_write(sdh, CORE_SB(corebase, sbtmstatehigh), 4, 0);
6221
6222 regdata = bcmsdh_reg_read(sdh, CORE_SB(corebase, sbimstate), 4);
6223 if (regdata & (SBIM_IBE | SBIM_TO))
6224 bcmsdh_reg_write(sdh, CORE_SB(corebase, sbimstate), 4,
6225 regdata & ~(SBIM_IBE | SBIM_TO));
6226
6227 /* clear reset and allow it to propagate throughout the core */
6228 bcmsdh_reg_write(sdh, CORE_SB(corebase, sbtmstatelow), 4,
6229 (SICF_FGC << SBTML_SICF_SHIFT) |
6230 (SICF_CLOCK_EN << SBTML_SICF_SHIFT));
6231 udelay(1);
6232
6233 /* leave clock enabled */
6234 bcmsdh_reg_write(sdh, CORE_SB(corebase, sbtmstatelow), 4,
6235 (SICF_CLOCK_EN << SBTML_SICF_SHIFT));
6236 udelay(1);
6237}
Franky Lin5d0d7a92011-04-25 19:34:05 -07006238
6239/* SDIO Pad drive strength to select value mappings */
6240struct sdiod_drive_str {
6241 u8 strength; /* Pad Drive Strength in mA */
6242 u8 sel; /* Chip-specific select value */
6243};
6244
6245/* SDIO Drive Strength to sel value table for PMU Rev 1 */
6246static const struct sdiod_drive_str sdiod_drive_strength_tab1[] = {
6247 {
6248 4, 0x2}, {
6249 2, 0x3}, {
6250 1, 0x0}, {
6251 0, 0x0}
6252 };
6253
6254/* SDIO Drive Strength to sel value table for PMU Rev 2, 3 */
6255static const struct sdiod_drive_str sdiod_drive_strength_tab2[] = {
6256 {
6257 12, 0x7}, {
6258 10, 0x6}, {
6259 8, 0x5}, {
6260 6, 0x4}, {
6261 4, 0x2}, {
6262 2, 0x1}, {
6263 0, 0x0}
6264 };
6265
6266/* SDIO Drive Strength to sel value table for PMU Rev 8 (1.8V) */
6267static const struct sdiod_drive_str sdiod_drive_strength_tab3[] = {
6268 {
6269 32, 0x7}, {
6270 26, 0x6}, {
6271 22, 0x5}, {
6272 16, 0x4}, {
6273 12, 0x3}, {
6274 8, 0x2}, {
6275 4, 0x1}, {
6276 0, 0x0}
6277 };
6278
6279#define SDIOD_DRVSTR_KEY(chip, pmu) (((chip) << 16) | (pmu))
6280
6281static void
6282dhdsdio_sdiod_drive_strength_init(struct dhd_bus *bus, u32 drivestrength) {
6283 struct sdiod_drive_str *str_tab = NULL;
6284 u32 str_mask = 0;
6285 u32 str_shift = 0;
Franky Lin5d0d7a92011-04-25 19:34:05 -07006286 char chn[8];
Franky Lin5d0d7a92011-04-25 19:34:05 -07006287
6288 if (!(bus->ci->cccaps & CC_CAP_PMU))
6289 return;
6290
6291 switch (SDIOD_DRVSTR_KEY(bus->ci->chip, bus->ci->pmurev)) {
6292 case SDIOD_DRVSTR_KEY(BCM4325_CHIP_ID, 1):
6293 str_tab = (struct sdiod_drive_str *)&sdiod_drive_strength_tab1;
6294 str_mask = 0x30000000;
6295 str_shift = 28;
6296 break;
6297 case SDIOD_DRVSTR_KEY(BCM4325_CHIP_ID, 2):
6298 case SDIOD_DRVSTR_KEY(BCM4325_CHIP_ID, 3):
6299 str_tab = (struct sdiod_drive_str *)&sdiod_drive_strength_tab2;
6300 str_mask = 0x00003800;
6301 str_shift = 11;
6302 break;
6303 case SDIOD_DRVSTR_KEY(BCM4336_CHIP_ID, 8):
6304 str_tab = (struct sdiod_drive_str *)&sdiod_drive_strength_tab3;
6305 str_mask = 0x00003800;
6306 str_shift = 11;
6307 break;
6308 default:
6309 DHD_ERROR(("No SDIO Drive strength init"
6310 "done for chip %s rev %d pmurev %d\n",
6311 bcm_chipname(bus->ci->chip, chn, 8),
6312 bus->ci->chiprev, bus->ci->pmurev));
6313 break;
6314 }
6315
6316 if (str_tab != NULL) {
6317 u32 drivestrength_sel = 0;
6318 u32 cc_data_temp;
6319 int i;
6320
6321 for (i = 0; str_tab[i].strength != 0; i++) {
6322 if (drivestrength >= str_tab[i].strength) {
6323 drivestrength_sel = str_tab[i].sel;
6324 break;
6325 }
6326 }
6327
6328 bcmsdh_reg_write(bus->sdh,
6329 CORE_CC_REG(bus->ci->cccorebase, chipcontrol_addr),
6330 4, 1);
6331 cc_data_temp = bcmsdh_reg_read(bus->sdh,
6332 CORE_CC_REG(bus->ci->cccorebase, chipcontrol_addr), 4);
6333 cc_data_temp &= ~str_mask;
6334 drivestrength_sel <<= str_shift;
6335 cc_data_temp |= drivestrength_sel;
6336 bcmsdh_reg_write(bus->sdh,
6337 CORE_CC_REG(bus->ci->cccorebase, chipcontrol_addr),
6338 4, cc_data_temp);
6339
6340 DHD_INFO(("SDIO: %dmA drive strength selected, set to 0x%08x\n",
6341 drivestrength, cc_data_temp));
6342 }
6343}
Franky Lincee3cf42011-04-25 19:34:06 -07006344
6345static void
6346dhdsdio_chip_detach(struct dhd_bus *bus)
6347{
6348 DHD_TRACE(("%s: Enter\n", __func__));
6349
6350 kfree(bus->ci);
6351 bus->ci = NULL;
6352}