2 * Copyright (c) 2010 Broadcom Corporation
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.
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.
17 #include <linux/types.h>
19 #include <linux/netdevice.h>
24 #include BCMEMBEDIMAGE
25 #endif /* BCMEMBEDIMAGE */
29 #include <bcmendian.h>
36 #include <hndrte_armtrap.h>
37 #include <hndrte_cons.h>
38 #endif /* DHD_DEBUG */
44 #include <sbsdpcmdev.h>
47 #include <proto/802.1d.h>
48 #include <proto/802.11.h>
50 #include <dngl_stats.h>
53 #include <dhd_proto.h>
57 #include <siutils_priv.h>
59 #ifndef DHDSDIO_MEM_DUMP_FNAME
60 #define DHDSDIO_MEM_DUMP_FNAME "mem_dump"
63 #define QLEN 256 /* bulk rx and tx queue lengths */
64 #define FCHI (QLEN - 10)
65 #define FCLOW (FCHI / 2)
68 #define TXRETRIES 2 /* # of retries for tx frames */
70 #if defined(CONFIG_MACH_SANDGATE2G)
71 #define DHD_RXBOUND 250 /* Default for max rx frames in
74 #define DHD_RXBOUND 50 /* Default for max rx frames in
76 #endif /* defined(CONFIG_MACH_SANDGATE2G) */
78 #define DHD_TXBOUND 20 /* Default for max tx frames in
81 #define DHD_TXMINMAX 1 /* Max tx frames if rx still pending */
83 #define MEMBLOCK 2048 /* Block size used for downloading
85 #define MAX_DATA_BUF (32 * 1024) /* Must be large enough to hold
86 biggest possible glom */
88 /* Packet alignment for most efficient SDIO (can change based on platform) */
90 #define DHD_SDALIGN 32
92 #if !ISPOWEROF2(DHD_SDALIGN)
93 #error DHD_SDALIGN is not a power of 2!
97 #define DHD_FIRSTREAD 32
99 #if !ISPOWEROF2(DHD_FIRSTREAD)
100 #error DHD_FIRSTREAD is not a power of 2!
103 /* Total length of frame header for dongle protocol */
104 #define SDPCM_HDRLEN (SDPCM_FRAMETAG_LEN + SDPCM_SWHEADER_LEN)
106 #define SDPCM_RESERVE (SDPCM_HDRLEN + SDPCM_TEST_HDRLEN + DHD_SDALIGN)
108 #define SDPCM_RESERVE (SDPCM_HDRLEN + DHD_SDALIGN)
111 /* Space for header read, limit for data packets */
113 #define MAX_HDR_READ 32
115 #if !ISPOWEROF2(MAX_HDR_READ)
116 #error MAX_HDR_READ is not a power of 2!
119 #define MAX_RX_DATASZ 2048
121 /* Maximum milliseconds to wait for F2 to come up */
122 #define DHD_WAIT_F2RDY 3000
124 /* Bump up limit on waiting for HT to account for first startup;
125 * if the image is doing a CRC calculation before programming the PMU
126 * for HT availability, it could take a couple hundred ms more, so
127 * max out at a 1 second (1000000us).
129 #if (PMU_MAX_TRANSITION_DLY <= 1000000)
130 #undef PMU_MAX_TRANSITION_DLY
131 #define PMU_MAX_TRANSITION_DLY 1000000
134 /* Value for ChipClockCSR during initial setup */
135 #define DHD_INIT_CLKCTL1 (SBSDIO_FORCE_HW_CLKREQ_OFF | \
136 SBSDIO_ALP_AVAIL_REQ)
137 #define DHD_INIT_CLKCTL2 (SBSDIO_FORCE_HW_CLKREQ_OFF | SBSDIO_FORCE_ALP)
139 /* Flags for SDH calls */
140 #define F2SYNC (SDIO_REQ_4BYTE | SDIO_REQ_FIXED)
142 /* Packet free applicable unconditionally for sdio and sdspi. Conditional if
143 * bufpool was present for gspi bus.
145 #define PKTFREE2() if ((bus->bus != SPI_BUS) || bus->usebufpool) \
146 pkt_buf_free_skb(bus->dhd->osh, pkt, false);
147 DHD_SPINWAIT_SLEEP_INIT(sdioh_spinwait_sleep
);
148 extern int dhdcdc_set_ioctl(dhd_pub_t
*dhd
, int ifidx
, uint cmd
, void *buf
,
152 /* Device console log buffer state */
153 typedef struct dhd_console
{
154 uint count
; /* Poll interval msec counter */
155 uint log_addr
; /* Log struct address (fixed) */
156 hndrte_log_t log
; /* Log struct (host copy) */
157 uint bufsize
; /* Size of log buffer */
158 u8
*buf
; /* Log buffer (host copy) */
159 uint last
; /* Last buffer read index */
161 #endif /* DHD_DEBUG */
163 /* Private data for SDIO bus interaction */
164 typedef struct dhd_bus
{
167 bcmsdh_info_t
*sdh
; /* Handle for BCMSDH calls */
168 si_t
*sih
; /* Handle for SI calls */
169 char *vars
; /* Variables (from CIS and/or other) */
170 uint varsz
; /* Size of variables buffer */
171 u32 sbaddr
; /* Current SB window pointer (-1, invalid) */
173 sdpcmd_regs_t
*regs
; /* Registers for SDIO core */
174 uint sdpcmrev
; /* SDIO core revision */
175 uint armrev
; /* CPU core revision */
176 uint ramrev
; /* SOCRAM core revision */
177 u32 ramsize
; /* Size of RAM in SOCRAM (bytes) */
178 u32 orig_ramsize
; /* Size of RAM in SOCRAM (bytes) */
180 u32 bus
; /* gSPI or SDIO bus */
181 u32 hostintmask
; /* Copy of Host Interrupt Mask */
182 u32 intstatus
; /* Intstatus bits (events) pending */
183 bool dpc_sched
; /* Indicates DPC schedule (intrpt rcvd) */
184 bool fcstate
; /* State of dongle flow-control */
186 u16 cl_devid
; /* cached devid for dhdsdio_probe_attach() */
187 char *fw_path
; /* module_param: path to firmware image */
188 char *nv_path
; /* module_param: path to nvram vars file */
189 const char *nvram_params
; /* user specified nvram params. */
191 uint blocksize
; /* Block size of SDIO transfers */
192 uint roundup
; /* Max roundup limit */
194 struct pktq txq
; /* Queue length used for flow-control */
195 u8 flowcontrol
; /* per prio flow control bitmask */
196 u8 tx_seq
; /* Transmit sequence number (next) */
197 u8 tx_max
; /* Maximum transmit sequence allowed */
199 u8 hdrbuf
[MAX_HDR_READ
+ DHD_SDALIGN
];
200 u8
*rxhdr
; /* Header of current rx frame (in hdrbuf) */
201 u16 nextlen
; /* Next Read Len from last header */
202 u8 rx_seq
; /* Receive sequence number (expected) */
203 bool rxskip
; /* Skip receive (awaiting NAK ACK) */
205 struct sk_buff
*glomd
; /* Packet containing glomming descriptor */
206 struct sk_buff
*glom
; /* Packet chain for glommed superframe */
207 uint glomerr
; /* Glom packet read errors */
209 u8
*rxbuf
; /* Buffer for receiving control packets */
210 uint rxblen
; /* Allocated length of rxbuf */
211 u8
*rxctl
; /* Aligned pointer into rxbuf */
212 u8
*databuf
; /* Buffer for receiving big glom packet */
213 u8
*dataptr
; /* Aligned pointer into databuf */
214 uint rxlen
; /* Length of valid data in buffer */
216 u8 sdpcm_ver
; /* Bus protocol reported by dongle */
218 bool intr
; /* Use interrupts */
219 bool poll
; /* Use polling */
220 bool ipend
; /* Device interrupt is pending */
221 bool intdis
; /* Interrupts disabled by isr */
222 uint intrcount
; /* Count of device interrupt callbacks */
223 uint lastintrs
; /* Count as of last watchdog timer */
224 uint spurious
; /* Count of spurious interrupts */
225 uint pollrate
; /* Ticks between device polls */
226 uint polltick
; /* Tick counter */
227 uint pollcnt
; /* Count of active polls */
230 dhd_console_t console
; /* Console output polling support */
231 uint console_addr
; /* Console address from shared struct */
232 #endif /* DHD_DEBUG */
234 uint regfails
; /* Count of R_REG/W_REG failures */
236 uint clkstate
; /* State of sd and backplane clock(s) */
237 bool activity
; /* Activity flag for clock down */
238 s32 idletime
; /* Control for activity timeout */
239 s32 idlecount
; /* Activity timeout counter */
240 s32 idleclock
; /* How to set bus driver when idle */
241 s32 sd_divisor
; /* Speed control to bus driver */
242 s32 sd_mode
; /* Mode control to bus driver */
243 s32 sd_rxchain
; /* If bcmsdh api accepts PKT chains */
244 bool use_rxchain
; /* If dhd should use PKT chains */
245 bool sleeping
; /* Is SDIO bus sleeping? */
246 bool rxflow_mode
; /* Rx flow control mode */
247 bool rxflow
; /* Is rx flow control on */
248 uint prev_rxlim_hit
; /* Is prev rx limit exceeded
249 (per dpc schedule) */
250 bool alp_only
; /* Don't use HT clock (ALP only) */
251 /* Field to decide if rx of control frames happen in rxbuf or lb-pool */
255 /* external loopback */
259 /* pktgen configuration */
260 uint pktgen_freq
; /* Ticks between bursts */
261 uint pktgen_count
; /* Packets to send each burst */
262 uint pktgen_print
; /* Bursts between count displays */
263 uint pktgen_total
; /* Stop after this many */
264 uint pktgen_minlen
; /* Minimum packet data len */
265 uint pktgen_maxlen
; /* Maximum packet data len */
266 uint pktgen_mode
; /* Configured mode: tx, rx, or echo */
267 uint pktgen_stop
; /* Number of tx failures causing stop */
269 /* active pktgen fields */
270 uint pktgen_tick
; /* Tick counter for bursts */
271 uint pktgen_ptick
; /* Burst counter for printing */
272 uint pktgen_sent
; /* Number of test packets generated */
273 uint pktgen_rcvd
; /* Number of test packets received */
274 uint pktgen_fail
; /* Number of failed send attempts */
275 u16 pktgen_len
; /* Length of next packet to send */
278 /* Some additional counters */
279 uint tx_sderrs
; /* Count of tx attempts with sd errors */
280 uint fcqueued
; /* Tx packets that got queued */
281 uint rxrtx
; /* Count of rtx requests (NAK to dongle) */
282 uint rx_toolong
; /* Receive frames too long to receive */
283 uint rxc_errors
; /* SDIO errors when reading control frames */
284 uint rx_hdrfail
; /* SDIO errors on header reads */
285 uint rx_badhdr
; /* Bad received headers (roosync?) */
286 uint rx_badseq
; /* Mismatched rx sequence number */
287 uint fc_rcvd
; /* Number of flow-control events received */
288 uint fc_xoff
; /* Number which turned on flow-control */
289 uint fc_xon
; /* Number which turned off flow-control */
290 uint rxglomfail
; /* Failed deglom attempts */
291 uint rxglomframes
; /* Number of glom frames (superframes) */
292 uint rxglompkts
; /* Number of packets from glom frames */
293 uint f2rxhdrs
; /* Number of header reads */
294 uint f2rxdata
; /* Number of frame data reads */
295 uint f2txdata
; /* Number of f2 frame writes */
296 uint f1regdata
; /* Number of f1 register accesses */
300 bool ctrl_frame_stat
;
306 #define CLK_PENDING 2 /* Not used yet */
309 #define DHD_NOPMU(dhd) (false)
312 static int qcount
[NUMPRIO
];
313 static int tx_packets
[NUMPRIO
];
314 #endif /* DHD_DEBUG */
316 /* Deferred transmit */
317 const uint dhd_deferred_tx
= 1;
319 extern uint dhd_watchdog_ms
;
320 extern void dhd_os_wd_timer(void *bus
, uint wdtick
);
327 /* override the RAM size if possible */
328 #define DONGLE_MIN_MEMSIZE (128 * 1024)
329 int dhd_dongle_memsize
;
331 static bool dhd_doflow
;
332 static bool dhd_alignctl
;
336 static bool retrydata
;
337 #define RETRYCHAN(chan) (((chan) == SDPCM_EVENT_CHANNEL) || retrydata)
339 static const uint watermark
= 8;
340 static const uint firstread
= DHD_FIRSTREAD
;
342 #define HDATLEN (firstread - (SDPCM_HDRLEN))
344 /* Retry count for register access failures */
345 static const uint retry_limit
= 2;
347 /* Force even SD lengths (some host controllers mess up on odd bytes) */
348 static bool forcealign
;
352 #if defined(OOB_INTR_ONLY) && defined(HW_OOB)
353 extern void bcmsdh_enable_hw_oob_intr(void *sdh
, bool enable
);
356 #if defined(OOB_INTR_ONLY) && defined(SDIO_ISR_THREAD)
357 #error OOB_INTR_ONLY is NOT working with SDIO_ISR_THREAD
358 #endif /* defined(OOB_INTR_ONLY) && defined(SDIO_ISR_THREAD) */
359 #define PKTALIGN(_osh, _p, _len, _align) \
362 datalign = (unsigned long)((_p)->data); \
363 datalign = roundup(datalign, (_align)) - datalign; \
364 ASSERT(datalign < (_align)); \
365 ASSERT((_p)->len >= ((_len) + datalign)); \
367 skb_pull((_p), datalign); \
368 __skb_trim((_p), (_len)); \
371 /* Limit on rounding up frames */
372 static const uint max_roundup
= 512;
374 /* Try doing readahead */
375 static bool dhd_readahead
;
377 /* To check if there's window offered */
378 #define DATAOK(bus) \
379 (((u8)(bus->tx_max - bus->tx_seq) != 0) && \
380 (((u8)(bus->tx_max - bus->tx_seq) & 0x80) == 0))
382 /* Macros to get register read/write status */
383 /* NOTE: these assume a local dhdsdio_bus_t *bus! */
384 #define R_SDREG(regvar, regaddr, retryvar) \
388 regvar = R_REG(bus->dhd->osh, regaddr); \
389 } while (bcmsdh_regfail(bus->sdh) && (++retryvar <= retry_limit)); \
391 bus->regfails += (retryvar-1); \
392 if (retryvar > retry_limit) { \
393 DHD_ERROR(("%s: FAILED" #regvar "READ, LINE %d\n", \
394 __func__, __LINE__)); \
400 #define W_SDREG(regval, regaddr, retryvar) \
404 W_REG(bus->dhd->osh, regaddr, regval); \
405 } while (bcmsdh_regfail(bus->sdh) && (++retryvar <= retry_limit)); \
407 bus->regfails += (retryvar-1); \
408 if (retryvar > retry_limit) \
409 DHD_ERROR(("%s: FAILED REGISTER WRITE, LINE %d\n", \
410 __func__, __LINE__)); \
414 #define DHD_BUS SDIO_BUS
416 #define PKT_AVAILABLE() (intstatus & I_HMB_FRAME_IND)
418 #define HOSTINTMASK (I_HMB_SW_MASK | I_CHIPACTIVE)
420 #define GSPI_PR55150_BAILOUT
423 static void dhdsdio_testrcv(dhd_bus_t
*bus
, void *pkt
, uint seq
);
424 static void dhdsdio_sdtest_set(dhd_bus_t
*bus
, bool start
);
428 static int dhdsdio_checkdied(dhd_bus_t
*bus
, u8
*data
, uint size
);
429 static int dhdsdio_mem_dump(dhd_bus_t
*bus
);
430 #endif /* DHD_DEBUG */
431 static int dhdsdio_download_state(dhd_bus_t
*bus
, bool enter
);
433 static void dhdsdio_release(dhd_bus_t
*bus
, struct osl_info
*osh
);
434 static void dhdsdio_release_malloc(dhd_bus_t
*bus
, struct osl_info
*osh
);
435 static void dhdsdio_disconnect(void *ptr
);
436 static bool dhdsdio_chipmatch(u16 chipid
);
437 static bool dhdsdio_probe_attach(dhd_bus_t
*bus
, struct osl_info
*osh
,
438 void *sdh
, void *regsva
, u16 devid
);
439 static bool dhdsdio_probe_malloc(dhd_bus_t
*bus
, struct osl_info
*osh
,
441 static bool dhdsdio_probe_init(dhd_bus_t
*bus
, struct osl_info
*osh
, void *sdh
);
442 static void dhdsdio_release_dongle(dhd_bus_t
*bus
, struct osl_info
* osh
);
444 static uint
process_nvram_vars(char *varbuf
, uint len
);
446 static void dhd_dongle_setmemsize(struct dhd_bus
*bus
, int mem_size
);
447 static int dhd_bcmsdh_recv_buf(dhd_bus_t
*bus
, u32 addr
, uint fn
,
448 uint flags
, u8
*buf
, uint nbytes
,
449 struct sk_buff
*pkt
, bcmsdh_cmplt_fn_t complete
,
451 static int dhd_bcmsdh_send_buf(dhd_bus_t
*bus
, u32 addr
, uint fn
,
452 uint flags
, u8
*buf
, uint nbytes
,
453 struct sk_buff
*pkt
, bcmsdh_cmplt_fn_t complete
,
456 static bool dhdsdio_download_firmware(struct dhd_bus
*bus
, struct osl_info
*osh
,
458 static int _dhdsdio_download_firmware(struct dhd_bus
*bus
);
460 static int dhdsdio_download_code_file(struct dhd_bus
*bus
, char *image_path
);
461 static int dhdsdio_download_nvram(struct dhd_bus
*bus
);
463 static int dhdsdio_download_code_array(struct dhd_bus
*bus
);
466 static void dhd_dongle_setmemsize(struct dhd_bus
*bus
, int mem_size
)
468 s32 min_size
= DONGLE_MIN_MEMSIZE
;
469 /* Restrict the memsize to user specified limit */
470 DHD_ERROR(("user: Restrict the dongle ram size to %d, min %d\n",
471 dhd_dongle_memsize
, min_size
));
472 if ((dhd_dongle_memsize
> min_size
) &&
473 (dhd_dongle_memsize
< (s32
) bus
->orig_ramsize
))
474 bus
->ramsize
= dhd_dongle_memsize
;
477 static int dhdsdio_set_siaddr_window(dhd_bus_t
*bus
, u32 address
)
480 bcmsdh_cfg_write(bus
->sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_SBADDRLOW
,
481 (address
>> 8) & SBSDIO_SBADDRLOW_MASK
, &err
);
483 bcmsdh_cfg_write(bus
->sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_SBADDRMID
,
484 (address
>> 16) & SBSDIO_SBADDRMID_MASK
, &err
);
486 bcmsdh_cfg_write(bus
->sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_SBADDRHIGH
,
487 (address
>> 24) & SBSDIO_SBADDRHIGH_MASK
,
492 /* Turn backplane clock on or off */
493 static int dhdsdio_htclk(dhd_bus_t
*bus
, bool on
, bool pendok
)
496 u8 clkctl
, clkreq
, devctl
;
499 DHD_TRACE(("%s: Enter\n", __func__
));
501 #if defined(OOB_INTR_ONLY)
508 /* Request HT Avail */
510 bus
->alp_only
? SBSDIO_ALP_AVAIL_REQ
: SBSDIO_HT_AVAIL_REQ
;
512 if ((bus
->sih
->chip
== BCM4329_CHIP_ID
)
513 && (bus
->sih
->chiprev
== 0))
514 clkreq
|= SBSDIO_FORCE_ALP
;
516 bcmsdh_cfg_write(sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_CHIPCLKCSR
,
519 DHD_ERROR(("%s: HT Avail request error: %d\n",
524 if (pendok
&& ((bus
->sih
->buscoretype
== PCMCIA_CORE_ID
)
525 && (bus
->sih
->buscorerev
== 9))) {
527 R_SDREG(dummy
, &bus
->regs
->clockctlstatus
, retries
);
530 /* Check current status */
532 bcmsdh_cfg_read(sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_CHIPCLKCSR
,
535 DHD_ERROR(("%s: HT Avail read error: %d\n",
540 /* Go to pending and await interrupt if appropriate */
541 if (!SBSDIO_CLKAV(clkctl
, bus
->alp_only
) && pendok
) {
542 /* Allow only clock-available interrupt */
544 bcmsdh_cfg_read(sdh
, SDIO_FUNC_1
, SBSDIO_DEVICE_CTL
,
547 DHD_ERROR(("%s: Devctl error setting CA: %d\n",
552 devctl
|= SBSDIO_DEVCTL_CA_INT_ONLY
;
553 bcmsdh_cfg_write(sdh
, SDIO_FUNC_1
, SBSDIO_DEVICE_CTL
,
555 DHD_INFO(("CLKCTL: set PENDING\n"));
556 bus
->clkstate
= CLK_PENDING
;
559 } else if (bus
->clkstate
== CLK_PENDING
) {
560 /* Cancel CA-only interrupt filter */
562 bcmsdh_cfg_read(sdh
, SDIO_FUNC_1
, SBSDIO_DEVICE_CTL
,
564 devctl
&= ~SBSDIO_DEVCTL_CA_INT_ONLY
;
565 bcmsdh_cfg_write(sdh
, SDIO_FUNC_1
, SBSDIO_DEVICE_CTL
,
569 /* Otherwise, wait here (polling) for HT Avail */
570 if (!SBSDIO_CLKAV(clkctl
, bus
->alp_only
)) {
571 SPINWAIT_SLEEP(sdioh_spinwait_sleep
,
573 bcmsdh_cfg_read(sdh
, SDIO_FUNC_1
,
574 SBSDIO_FUNC1_CHIPCLKCSR
,
576 !SBSDIO_CLKAV(clkctl
, bus
->alp_only
)),
577 PMU_MAX_TRANSITION_DLY
);
580 DHD_ERROR(("%s: HT Avail request error: %d\n",
584 if (!SBSDIO_CLKAV(clkctl
, bus
->alp_only
)) {
585 DHD_ERROR(("%s: HT Avail timeout (%d): clkctl 0x%02x\n",
586 __func__
, PMU_MAX_TRANSITION_DLY
, clkctl
));
590 /* Mark clock available */
591 bus
->clkstate
= CLK_AVAIL
;
592 DHD_INFO(("CLKCTL: turned ON\n"));
594 #if defined(DHD_DEBUG)
595 if (bus
->alp_only
== true) {
596 #if !defined(BCMLXSDMMC)
597 if (!SBSDIO_ALPONLY(clkctl
)) {
598 DHD_ERROR(("%s: HT Clock, when ALP Only\n",
601 #endif /* !defined(BCMLXSDMMC) */
603 if (SBSDIO_ALPONLY(clkctl
)) {
604 DHD_ERROR(("%s: HT Clock should be on.\n",
608 #endif /* defined (DHD_DEBUG) */
610 bus
->activity
= true;
614 if (bus
->clkstate
== CLK_PENDING
) {
615 /* Cancel CA-only interrupt filter */
617 bcmsdh_cfg_read(sdh
, SDIO_FUNC_1
, SBSDIO_DEVICE_CTL
,
619 devctl
&= ~SBSDIO_DEVCTL_CA_INT_ONLY
;
620 bcmsdh_cfg_write(sdh
, SDIO_FUNC_1
, SBSDIO_DEVICE_CTL
,
624 bus
->clkstate
= CLK_SDONLY
;
625 bcmsdh_cfg_write(sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_CHIPCLKCSR
,
627 DHD_INFO(("CLKCTL: turned OFF\n"));
629 DHD_ERROR(("%s: Failed access turning clock off: %d\n",
637 /* Change idle/active SD state */
638 static int dhdsdio_sdclk(dhd_bus_t
*bus
, bool on
)
643 DHD_TRACE(("%s: Enter\n", __func__
));
646 if (bus
->idleclock
== DHD_IDLE_STOP
) {
647 /* Turn on clock and restore mode */
649 err
= bcmsdh_iovar_op(bus
->sdh
, "sd_clock", NULL
, 0,
650 &iovalue
, sizeof(iovalue
), true);
652 DHD_ERROR(("%s: error enabling sd_clock: %d\n",
657 iovalue
= bus
->sd_mode
;
658 err
= bcmsdh_iovar_op(bus
->sdh
, "sd_mode", NULL
, 0,
659 &iovalue
, sizeof(iovalue
), true);
661 DHD_ERROR(("%s: error changing sd_mode: %d\n",
665 } else if (bus
->idleclock
!= DHD_IDLE_ACTIVE
) {
666 /* Restore clock speed */
667 iovalue
= bus
->sd_divisor
;
668 err
= bcmsdh_iovar_op(bus
->sdh
, "sd_divisor", NULL
, 0,
669 &iovalue
, sizeof(iovalue
), true);
671 DHD_ERROR(("%s: error restoring sd_divisor: %d\n",
676 bus
->clkstate
= CLK_SDONLY
;
678 /* Stop or slow the SD clock itself */
679 if ((bus
->sd_divisor
== -1) || (bus
->sd_mode
== -1)) {
680 DHD_TRACE(("%s: can't idle clock, divisor %d mode %d\n",
681 __func__
, bus
->sd_divisor
, bus
->sd_mode
));
684 if (bus
->idleclock
== DHD_IDLE_STOP
) {
686 /* Change to SD1 mode and turn off clock */
689 bcmsdh_iovar_op(bus
->sdh
, "sd_mode", NULL
,
691 sizeof(iovalue
), true);
693 DHD_ERROR(("%s: error changing sd_clock: %d\n",
700 err
= bcmsdh_iovar_op(bus
->sdh
, "sd_clock", NULL
, 0,
701 &iovalue
, sizeof(iovalue
), true);
703 DHD_ERROR(("%s: error disabling sd_clock: %d\n",
707 } else if (bus
->idleclock
!= DHD_IDLE_ACTIVE
) {
708 /* Set divisor to idle value */
709 iovalue
= bus
->idleclock
;
710 err
= bcmsdh_iovar_op(bus
->sdh
, "sd_divisor", NULL
, 0,
711 &iovalue
, sizeof(iovalue
), true);
713 DHD_ERROR(("%s: error changing sd_divisor: %d\n",
718 bus
->clkstate
= CLK_NONE
;
724 /* Transition SD and backplane clock readiness */
725 static int dhdsdio_clkctl(dhd_bus_t
*bus
, uint target
, bool pendok
)
728 uint oldstate
= bus
->clkstate
;
729 #endif /* DHD_DEBUG */
731 DHD_TRACE(("%s: Enter\n", __func__
));
733 /* Early exit if we're already there */
734 if (bus
->clkstate
== target
) {
735 if (target
== CLK_AVAIL
) {
736 dhd_os_wd_timer(bus
->dhd
, dhd_watchdog_ms
);
737 bus
->activity
= true;
744 /* Make sure SD clock is available */
745 if (bus
->clkstate
== CLK_NONE
)
746 dhdsdio_sdclk(bus
, true);
747 /* Now request HT Avail on the backplane */
748 dhdsdio_htclk(bus
, true, pendok
);
749 dhd_os_wd_timer(bus
->dhd
, dhd_watchdog_ms
);
750 bus
->activity
= true;
754 /* Remove HT request, or bring up SD clock */
755 if (bus
->clkstate
== CLK_NONE
)
756 dhdsdio_sdclk(bus
, true);
757 else if (bus
->clkstate
== CLK_AVAIL
)
758 dhdsdio_htclk(bus
, false, false);
760 DHD_ERROR(("dhdsdio_clkctl: request for %d -> %d\n",
761 bus
->clkstate
, target
));
762 dhd_os_wd_timer(bus
->dhd
, dhd_watchdog_ms
);
766 /* Make sure to remove HT request */
767 if (bus
->clkstate
== CLK_AVAIL
)
768 dhdsdio_htclk(bus
, false, false);
769 /* Now remove the SD clock */
770 dhdsdio_sdclk(bus
, false);
771 dhd_os_wd_timer(bus
->dhd
, 0);
775 DHD_INFO(("dhdsdio_clkctl: %d -> %d\n", oldstate
, bus
->clkstate
));
776 #endif /* DHD_DEBUG */
781 int dhdsdio_bussleep(dhd_bus_t
*bus
, bool sleep
)
783 bcmsdh_info_t
*sdh
= bus
->sdh
;
784 sdpcmd_regs_t
*regs
= bus
->regs
;
787 DHD_INFO(("dhdsdio_bussleep: request %s (currently %s)\n",
788 (sleep
? "SLEEP" : "WAKE"),
789 (bus
->sleeping
? "SLEEP" : "WAKE")));
791 /* Done if we're already in the requested state */
792 if (sleep
== bus
->sleeping
)
795 /* Going to sleep: set the alarm and turn off the lights... */
797 /* Don't sleep if something is pending */
798 if (bus
->dpc_sched
|| bus
->rxskip
|| pktq_len(&bus
->txq
))
801 /* Disable SDIO interrupts (no longer interested) */
802 bcmsdh_intr_disable(bus
->sdh
);
804 /* Make sure the controller has the bus up */
805 dhdsdio_clkctl(bus
, CLK_AVAIL
, false);
807 /* Tell device to start using OOB wakeup */
808 W_SDREG(SMB_USE_OOB
, ®s
->tosbmailbox
, retries
);
809 if (retries
> retry_limit
)
810 DHD_ERROR(("CANNOT SIGNAL CHIP, WILL NOT WAKE UP!!\n"));
812 /* Turn off our contribution to the HT clock request */
813 dhdsdio_clkctl(bus
, CLK_SDONLY
, false);
815 bcmsdh_cfg_write(sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_CHIPCLKCSR
,
816 SBSDIO_FORCE_HW_CLKREQ_OFF
, NULL
);
818 /* Isolate the bus */
819 if (bus
->sih
->chip
!= BCM4329_CHIP_ID
820 && bus
->sih
->chip
!= BCM4319_CHIP_ID
) {
821 bcmsdh_cfg_write(sdh
, SDIO_FUNC_1
, SBSDIO_DEVICE_CTL
,
822 SBSDIO_DEVCTL_PADS_ISO
, NULL
);
826 bus
->sleeping
= true;
829 /* Waking up: bus power up is ok, set local state */
831 bcmsdh_cfg_write(sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_CHIPCLKCSR
,
834 /* Force pad isolation off if possible
835 (in case power never toggled) */
836 if ((bus
->sih
->buscoretype
== PCMCIA_CORE_ID
)
837 && (bus
->sih
->buscorerev
>= 10))
838 bcmsdh_cfg_write(sdh
, SDIO_FUNC_1
, SBSDIO_DEVICE_CTL
, 0,
841 /* Make sure the controller has the bus up */
842 dhdsdio_clkctl(bus
, CLK_AVAIL
, false);
844 /* Send misc interrupt to indicate OOB not needed */
845 W_SDREG(0, ®s
->tosbmailboxdata
, retries
);
846 if (retries
<= retry_limit
)
847 W_SDREG(SMB_DEV_INT
, ®s
->tosbmailbox
, retries
);
849 if (retries
> retry_limit
)
850 DHD_ERROR(("CANNOT SIGNAL CHIP TO CLEAR OOB!!\n"));
852 /* Make sure we have SD bus access */
853 dhdsdio_clkctl(bus
, CLK_SDONLY
, false);
856 bus
->sleeping
= false;
858 /* Enable interrupts again */
859 if (bus
->intr
&& (bus
->dhd
->busstate
== DHD_BUS_DATA
)) {
861 bcmsdh_intr_enable(bus
->sdh
);
868 #if defined(OOB_INTR_ONLY)
869 void dhd_enable_oob_intr(struct dhd_bus
*bus
, bool enable
)
872 bcmsdh_enable_hw_oob_intr(bus
->sdh
, enable
);
874 sdpcmd_regs_t
*regs
= bus
->regs
;
877 dhdsdio_clkctl(bus
, CLK_AVAIL
, false);
878 if (enable
== true) {
880 /* Tell device to start using OOB wakeup */
881 W_SDREG(SMB_USE_OOB
, ®s
->tosbmailbox
, retries
);
882 if (retries
> retry_limit
)
883 DHD_ERROR(("CANNOT SIGNAL CHIP, WILL NOT WAKE UP!!\n"));
886 /* Send misc interrupt to indicate OOB not needed */
887 W_SDREG(0, ®s
->tosbmailboxdata
, retries
);
888 if (retries
<= retry_limit
)
889 W_SDREG(SMB_DEV_INT
, ®s
->tosbmailbox
, retries
);
892 /* Turn off our contribution to the HT clock request */
893 dhdsdio_clkctl(bus
, CLK_SDONLY
, false);
894 #endif /* !defined(HW_OOB) */
896 #endif /* defined(OOB_INTR_ONLY) */
898 #define BUS_WAKE(bus) \
900 if ((bus)->sleeping) \
901 dhdsdio_bussleep((bus), false); \
904 /* Writes a HW/SW header into the packet and sends it. */
905 /* Assumes: (a) header space already there, (b) caller holds lock */
906 static int dhdsdio_txpkt(dhd_bus_t
*bus
, struct sk_buff
*pkt
, uint chan
,
910 struct osl_info
*osh
;
919 DHD_TRACE(("%s: Enter\n", __func__
));
924 if (bus
->dhd
->dongle_reset
) {
929 frame
= (u8
*) (pkt
->data
);
931 /* Add alignment padding, allocate new packet if needed */
932 pad
= ((unsigned long)frame
% DHD_SDALIGN
);
934 if (skb_headroom(pkt
) < pad
) {
935 DHD_INFO(("%s: insufficient headroom %d for %d pad\n",
936 __func__
, skb_headroom(pkt
), pad
));
937 bus
->dhd
->tx_realloc
++;
938 new = pkt_buf_get_skb(osh
, (pkt
->len
+ DHD_SDALIGN
));
940 DHD_ERROR(("%s: couldn't allocate new %d-byte "
942 __func__
, pkt
->len
+ DHD_SDALIGN
));
947 PKTALIGN(osh
, new, pkt
->len
, DHD_SDALIGN
);
948 bcopy(pkt
->data
, new->data
, pkt
->len
);
950 pkt_buf_free_skb(osh
, pkt
, true);
951 /* free the pkt if canned one is not used */
954 frame
= (u8
*) (pkt
->data
);
955 ASSERT(((unsigned long)frame
% DHD_SDALIGN
) == 0);
959 frame
= (u8
*) (pkt
->data
);
961 ASSERT((pad
+ SDPCM_HDRLEN
) <= (int)(pkt
->len
));
962 memset(frame
, 0, pad
+ SDPCM_HDRLEN
);
965 ASSERT(pad
< DHD_SDALIGN
);
967 /* Hardware tag: 2 byte len followed by 2 byte ~len check (all LE) */
968 len
= (u16
) (pkt
->len
);
969 *(u16
*) frame
= htol16(len
);
970 *(((u16
*) frame
) + 1) = htol16(~len
);
972 /* Software tag: channel, sequence number, data offset */
974 ((chan
<< SDPCM_CHANNEL_SHIFT
) & SDPCM_CHANNEL_MASK
) | bus
->tx_seq
|
976 SDPCM_HDRLEN
) << SDPCM_DOFFSET_SHIFT
) & SDPCM_DOFFSET_MASK
);
977 htol32_ua_store(swheader
, frame
+ SDPCM_FRAMETAG_LEN
);
978 htol32_ua_store(0, frame
+ SDPCM_FRAMETAG_LEN
+ sizeof(swheader
));
981 tx_packets
[pkt
->priority
]++;
982 if (DHD_BYTES_ON() &&
983 (((DHD_CTL_ON() && (chan
== SDPCM_CONTROL_CHANNEL
)) ||
984 (DHD_DATA_ON() && (chan
!= SDPCM_CONTROL_CHANNEL
))))) {
985 prhex("Tx Frame", frame
, len
);
986 } else if (DHD_HDRS_ON()) {
987 prhex("TxHdr", frame
, min_t(u16
, len
, 16));
991 /* Raise len to next SDIO block to eliminate tail command */
992 if (bus
->roundup
&& bus
->blocksize
&& (len
> bus
->blocksize
)) {
993 u16 pad
= bus
->blocksize
- (len
% bus
->blocksize
);
994 if ((pad
<= bus
->roundup
) && (pad
< bus
->blocksize
))
996 if (pad
<= skb_tailroom(pkt
))
999 } else if (len
% DHD_SDALIGN
) {
1000 len
+= DHD_SDALIGN
- (len
% DHD_SDALIGN
);
1003 /* Some controllers have trouble with odd bytes -- round to even */
1004 if (forcealign
&& (len
& (ALIGNMENT
- 1))) {
1006 if (skb_tailroom(pkt
))
1008 len
= roundup(len
, ALIGNMENT
);
1011 DHD_ERROR(("%s: sending unrounded %d-byte packet\n",
1018 dhd_bcmsdh_send_buf(bus
, bcmsdh_cur_sbwad(sdh
), SDIO_FUNC_2
,
1019 F2SYNC
, frame
, len
, pkt
, NULL
, NULL
);
1021 ASSERT(ret
!= BCME_PENDING
);
1024 /* On failure, abort the command
1025 and terminate the frame */
1026 DHD_INFO(("%s: sdio error %d, abort command and "
1027 "terminate frame.\n", __func__
, ret
));
1030 bcmsdh_abort(sdh
, SDIO_FUNC_2
);
1031 bcmsdh_cfg_write(sdh
, SDIO_FUNC_1
,
1032 SBSDIO_FUNC1_FRAMECTRL
, SFC_WF_TERM
,
1036 for (i
= 0; i
< 3; i
++) {
1038 hi
= bcmsdh_cfg_read(sdh
, SDIO_FUNC_1
,
1039 SBSDIO_FUNC1_WFRAMEBCHI
,
1041 lo
= bcmsdh_cfg_read(sdh
, SDIO_FUNC_1
,
1042 SBSDIO_FUNC1_WFRAMEBCLO
,
1044 bus
->f1regdata
+= 2;
1045 if ((hi
== 0) && (lo
== 0))
1051 bus
->tx_seq
= (bus
->tx_seq
+ 1) % SDPCM_SEQUENCE_WRAP
;
1053 } while ((ret
< 0) && retrydata
&& retries
++ < TXRETRIES
);
1056 /* restore pkt buffer pointer before calling tx complete routine */
1057 skb_pull(pkt
, SDPCM_HDRLEN
+ pad
);
1058 dhd_os_sdunlock(bus
->dhd
);
1059 dhd_txcomplete(bus
->dhd
, pkt
, ret
!= 0);
1060 dhd_os_sdlock(bus
->dhd
);
1063 pkt_buf_free_skb(osh
, pkt
, true);
1068 int dhd_bus_txdata(struct dhd_bus
*bus
, struct sk_buff
*pkt
)
1070 int ret
= BCME_ERROR
;
1071 struct osl_info
*osh
;
1074 DHD_TRACE(("%s: Enter\n", __func__
));
1076 osh
= bus
->dhd
->osh
;
1080 /* Push the test header if doing loopback */
1081 if (bus
->ext_loop
) {
1083 skb_push(pkt
, SDPCM_TEST_HDRLEN
);
1085 *data
++ = SDPCM_TEST_ECHOREQ
;
1086 *data
++ = (u8
) bus
->loopid
++;
1087 *data
++ = (datalen
>> 0);
1088 *data
++ = (datalen
>> 8);
1089 datalen
+= SDPCM_TEST_HDRLEN
;
1093 /* Add space for the header */
1094 skb_push(pkt
, SDPCM_HDRLEN
);
1095 ASSERT(IS_ALIGNED((unsigned long)(pkt
->data
), 2));
1097 prec
= PRIO2PREC((pkt
->priority
& PRIOMASK
));
1099 /* Check for existing queue, current flow-control,
1100 pending event, or pending clock */
1101 if (dhd_deferred_tx
|| bus
->fcstate
|| pktq_len(&bus
->txq
)
1102 || bus
->dpc_sched
|| (!DATAOK(bus
))
1103 || (bus
->flowcontrol
& NBITVAL(prec
))
1104 || (bus
->clkstate
!= CLK_AVAIL
)) {
1105 DHD_TRACE(("%s: deferring pktq len %d\n", __func__
,
1106 pktq_len(&bus
->txq
)));
1109 /* Priority based enq */
1110 dhd_os_sdlock_txq(bus
->dhd
);
1111 if (dhd_prec_enq(bus
->dhd
, &bus
->txq
, pkt
, prec
) == false) {
1112 skb_pull(pkt
, SDPCM_HDRLEN
);
1113 dhd_txcomplete(bus
->dhd
, pkt
, false);
1114 pkt_buf_free_skb(osh
, pkt
, true);
1115 DHD_ERROR(("%s: out of bus->txq !!!\n", __func__
));
1116 ret
= BCME_NORESOURCE
;
1120 dhd_os_sdunlock_txq(bus
->dhd
);
1122 if ((pktq_len(&bus
->txq
) >= FCHI
) && dhd_doflow
)
1123 dhd_txflowcontrol(bus
->dhd
, 0, ON
);
1126 if (pktq_plen(&bus
->txq
, prec
) > qcount
[prec
])
1127 qcount
[prec
] = pktq_plen(&bus
->txq
, prec
);
1129 /* Schedule DPC if needed to send queued packet(s) */
1130 if (dhd_deferred_tx
&& !bus
->dpc_sched
) {
1131 bus
->dpc_sched
= true;
1132 dhd_sched_dpc(bus
->dhd
);
1135 /* Lock: we're about to use shared data/code (and SDIO) */
1136 dhd_os_sdlock(bus
->dhd
);
1138 /* Otherwise, send it now */
1140 /* Make sure back plane ht clk is on, no pending allowed */
1141 dhdsdio_clkctl(bus
, CLK_AVAIL
, true);
1144 DHD_TRACE(("%s: calling txpkt\n", __func__
));
1145 ret
= dhdsdio_txpkt(bus
, pkt
, SDPCM_DATA_CHANNEL
, true);
1147 ret
= dhdsdio_txpkt(bus
, pkt
,
1148 (bus
->ext_loop
? SDPCM_TEST_CHANNEL
:
1149 SDPCM_DATA_CHANNEL
), true);
1152 bus
->dhd
->tx_errors
++;
1154 bus
->dhd
->dstats
.tx_bytes
+= datalen
;
1156 if ((bus
->idletime
== DHD_IDLE_IMMEDIATE
) && !bus
->dpc_sched
) {
1157 bus
->activity
= false;
1158 dhdsdio_clkctl(bus
, CLK_NONE
, true);
1161 dhd_os_sdunlock(bus
->dhd
);
1167 static uint
dhdsdio_sendfromq(dhd_bus_t
*bus
, uint maxframes
)
1169 struct sk_buff
*pkt
;
1172 int ret
= 0, prec_out
;
1177 dhd_pub_t
*dhd
= bus
->dhd
;
1178 sdpcmd_regs_t
*regs
= bus
->regs
;
1180 DHD_TRACE(("%s: Enter\n", __func__
));
1182 tx_prec_map
= ~bus
->flowcontrol
;
1184 /* Send frames until the limit or some other event */
1185 for (cnt
= 0; (cnt
< maxframes
) && DATAOK(bus
); cnt
++) {
1186 dhd_os_sdlock_txq(bus
->dhd
);
1187 pkt
= pktq_mdeq(&bus
->txq
, tx_prec_map
, &prec_out
);
1189 dhd_os_sdunlock_txq(bus
->dhd
);
1192 dhd_os_sdunlock_txq(bus
->dhd
);
1193 datalen
= pkt
->len
- SDPCM_HDRLEN
;
1196 ret
= dhdsdio_txpkt(bus
, pkt
, SDPCM_DATA_CHANNEL
, true);
1198 ret
= dhdsdio_txpkt(bus
, pkt
,
1199 (bus
->ext_loop
? SDPCM_TEST_CHANNEL
:
1200 SDPCM_DATA_CHANNEL
), true);
1203 bus
->dhd
->tx_errors
++;
1205 bus
->dhd
->dstats
.tx_bytes
+= datalen
;
1207 /* In poll mode, need to check for other events */
1208 if (!bus
->intr
&& cnt
) {
1209 /* Check device status, signal pending interrupt */
1210 R_SDREG(intstatus
, ®s
->intstatus
, retries
);
1212 if (bcmsdh_regfail(bus
->sdh
))
1214 if (intstatus
& bus
->hostintmask
)
1219 /* Deflow-control stack if needed */
1220 if (dhd_doflow
&& dhd
->up
&& (dhd
->busstate
== DHD_BUS_DATA
) &&
1221 dhd
->txoff
&& (pktq_len(&bus
->txq
) < FCLOW
))
1222 dhd_txflowcontrol(dhd
, 0, OFF
);
1227 int dhd_bus_txctl(struct dhd_bus
*bus
, unsigned char *msg
, uint msglen
)
1233 bcmsdh_info_t
*sdh
= bus
->sdh
;
1238 DHD_TRACE(("%s: Enter\n", __func__
));
1240 if (bus
->dhd
->dongle_reset
)
1243 /* Back the pointer to make a room for bus header */
1244 frame
= msg
- SDPCM_HDRLEN
;
1245 len
= (msglen
+= SDPCM_HDRLEN
);
1247 /* Add alignment padding (optional for ctl frames) */
1249 doff
= ((unsigned long)frame
% DHD_SDALIGN
);
1254 memset(frame
, 0, doff
+ SDPCM_HDRLEN
);
1256 ASSERT(doff
< DHD_SDALIGN
);
1258 doff
+= SDPCM_HDRLEN
;
1260 /* Round send length to next SDIO block */
1261 if (bus
->roundup
&& bus
->blocksize
&& (len
> bus
->blocksize
)) {
1262 u16 pad
= bus
->blocksize
- (len
% bus
->blocksize
);
1263 if ((pad
<= bus
->roundup
) && (pad
< bus
->blocksize
))
1265 } else if (len
% DHD_SDALIGN
) {
1266 len
+= DHD_SDALIGN
- (len
% DHD_SDALIGN
);
1269 /* Satisfy length-alignment requirements */
1270 if (forcealign
&& (len
& (ALIGNMENT
- 1)))
1271 len
= roundup(len
, ALIGNMENT
);
1273 ASSERT(IS_ALIGNED((unsigned long)frame
, 2));
1275 /* Need to lock here to protect txseq and SDIO tx calls */
1276 dhd_os_sdlock(bus
->dhd
);
1280 /* Make sure backplane clock is on */
1281 dhdsdio_clkctl(bus
, CLK_AVAIL
, false);
1283 /* Hardware tag: 2 byte len followed by 2 byte ~len check (all LE) */
1284 *(u16
*) frame
= htol16((u16
) msglen
);
1285 *(((u16
*) frame
) + 1) = htol16(~msglen
);
1287 /* Software tag: channel, sequence number, data offset */
1289 ((SDPCM_CONTROL_CHANNEL
<< SDPCM_CHANNEL_SHIFT
) &
1291 | bus
->tx_seq
| ((doff
<< SDPCM_DOFFSET_SHIFT
) &
1292 SDPCM_DOFFSET_MASK
);
1293 htol32_ua_store(swheader
, frame
+ SDPCM_FRAMETAG_LEN
);
1294 htol32_ua_store(0, frame
+ SDPCM_FRAMETAG_LEN
+ sizeof(swheader
));
1297 DHD_INFO(("%s: No bus credit bus->tx_max %d, bus->tx_seq %d\n",
1298 __func__
, bus
->tx_max
, bus
->tx_seq
));
1299 bus
->ctrl_frame_stat
= true;
1301 bus
->ctrl_frame_buf
= frame
;
1302 bus
->ctrl_frame_len
= len
;
1304 dhd_wait_for_event(bus
->dhd
, &bus
->ctrl_frame_stat
);
1306 if (bus
->ctrl_frame_stat
== false) {
1307 DHD_INFO(("%s: ctrl_frame_stat == false\n", __func__
));
1310 DHD_INFO(("%s: ctrl_frame_stat == true\n", __func__
));
1317 if (DHD_BYTES_ON() && DHD_CTL_ON())
1318 prhex("Tx Frame", frame
, len
);
1319 else if (DHD_HDRS_ON())
1320 prhex("TxHdr", frame
, min_t(u16
, len
, 16));
1324 bus
->ctrl_frame_stat
= false;
1326 dhd_bcmsdh_send_buf(bus
, bcmsdh_cur_sbwad(sdh
),
1327 SDIO_FUNC_2
, F2SYNC
, frame
, len
,
1330 ASSERT(ret
!= BCME_PENDING
);
1333 /* On failure, abort the command and
1334 terminate the frame */
1335 DHD_INFO(("%s: sdio error %d, abort command and terminate frame.\n",
1339 bcmsdh_abort(sdh
, SDIO_FUNC_2
);
1341 bcmsdh_cfg_write(sdh
, SDIO_FUNC_1
,
1342 SBSDIO_FUNC1_FRAMECTRL
,
1346 for (i
= 0; i
< 3; i
++) {
1348 hi
= bcmsdh_cfg_read(sdh
, SDIO_FUNC_1
,
1349 SBSDIO_FUNC1_WFRAMEBCHI
,
1351 lo
= bcmsdh_cfg_read(sdh
, SDIO_FUNC_1
,
1352 SBSDIO_FUNC1_WFRAMEBCLO
,
1354 bus
->f1regdata
+= 2;
1355 if ((hi
== 0) && (lo
== 0))
1362 (bus
->tx_seq
+ 1) % SDPCM_SEQUENCE_WRAP
;
1364 } while ((ret
< 0) && retries
++ < TXRETRIES
);
1367 if ((bus
->idletime
== DHD_IDLE_IMMEDIATE
) && !bus
->dpc_sched
) {
1368 bus
->activity
= false;
1369 dhdsdio_clkctl(bus
, CLK_NONE
, true);
1372 dhd_os_sdunlock(bus
->dhd
);
1375 bus
->dhd
->tx_ctlerrs
++;
1377 bus
->dhd
->tx_ctlpkts
++;
1379 return ret
? -EIO
: 0;
1382 int dhd_bus_rxctl(struct dhd_bus
*bus
, unsigned char *msg
, uint msglen
)
1388 DHD_TRACE(("%s: Enter\n", __func__
));
1390 if (bus
->dhd
->dongle_reset
)
1393 /* Wait until control frame is available */
1394 timeleft
= dhd_os_ioctl_resp_wait(bus
->dhd
, &bus
->rxlen
, &pending
);
1396 dhd_os_sdlock(bus
->dhd
);
1398 bcopy(bus
->rxctl
, msg
, min(msglen
, rxlen
));
1400 dhd_os_sdunlock(bus
->dhd
);
1403 DHD_CTL(("%s: resumed on rxctl frame, got %d expected %d\n",
1404 __func__
, rxlen
, msglen
));
1405 } else if (timeleft
== 0) {
1406 DHD_ERROR(("%s: resumed on timeout\n", __func__
));
1408 dhd_os_sdlock(bus
->dhd
);
1409 dhdsdio_checkdied(bus
, NULL
, 0);
1410 dhd_os_sdunlock(bus
->dhd
);
1411 #endif /* DHD_DEBUG */
1412 } else if (pending
== true) {
1413 DHD_CTL(("%s: cancelled\n", __func__
));
1414 return -ERESTARTSYS
;
1416 DHD_CTL(("%s: resumed for unknown reason?\n", __func__
));
1418 dhd_os_sdlock(bus
->dhd
);
1419 dhdsdio_checkdied(bus
, NULL
, 0);
1420 dhd_os_sdunlock(bus
->dhd
);
1421 #endif /* DHD_DEBUG */
1425 bus
->dhd
->rx_ctlpkts
++;
1427 bus
->dhd
->rx_ctlerrs
++;
1429 return rxlen
? (int)rxlen
: -ETIMEDOUT
;
1468 const bcm_iovar_t dhdsdio_iovars
[] = {
1469 {"intr", IOV_INTR
, 0, IOVT_BOOL
, 0},
1470 {"sleep", IOV_SLEEP
, 0, IOVT_BOOL
, 0},
1471 {"pollrate", IOV_POLLRATE
, 0, IOVT_UINT32
, 0},
1472 {"idletime", IOV_IDLETIME
, 0, IOVT_INT32
, 0},
1473 {"idleclock", IOV_IDLECLOCK
, 0, IOVT_INT32
, 0},
1474 {"sd1idle", IOV_SD1IDLE
, 0, IOVT_BOOL
, 0},
1475 {"membytes", IOV_MEMBYTES
, 0, IOVT_BUFFER
, 2 * sizeof(int)},
1476 {"memsize", IOV_MEMSIZE
, 0, IOVT_UINT32
, 0},
1477 {"download", IOV_DOWNLOAD
, 0, IOVT_BOOL
, 0},
1478 {"vars", IOV_VARS
, 0, IOVT_BUFFER
, 0},
1479 {"sdiod_drive", IOV_SDIOD_DRIVE
, 0, IOVT_UINT32
, 0},
1480 {"readahead", IOV_READAHEAD
, 0, IOVT_BOOL
, 0},
1481 {"sdrxchain", IOV_SDRXCHAIN
, 0, IOVT_BOOL
, 0},
1482 {"alignctl", IOV_ALIGNCTL
, 0, IOVT_BOOL
, 0},
1483 {"sdalign", IOV_SDALIGN
, 0, IOVT_BOOL
, 0},
1484 {"devreset", IOV_DEVRESET
, 0, IOVT_BOOL
, 0},
1486 {"sdreg", IOV_SDREG
, 0, IOVT_BUFFER
, sizeof(sdreg_t
)}
1488 {"sbreg", IOV_SBREG
, 0, IOVT_BUFFER
, sizeof(sdreg_t
)}
1490 {"sd_cis", IOV_SDCIS
, 0, IOVT_BUFFER
, DHD_IOCTL_MAXLEN
}
1492 {"forcealign", IOV_FORCEEVEN
, 0, IOVT_BOOL
, 0}
1494 {"txbound", IOV_TXBOUND
, 0, IOVT_UINT32
, 0}
1496 {"rxbound", IOV_RXBOUND
, 0, IOVT_UINT32
, 0}
1498 {"txminmax", IOV_TXMINMAX
, 0, IOVT_UINT32
, 0}
1500 {"cpu", IOV_CPU
, 0, IOVT_BOOL
, 0}
1503 {"checkdied", IOV_CHECKDIED
, 0, IOVT_BUFFER
, 0}
1505 #endif /* DHD_DEBUG */
1506 #endif /* DHD_DEBUG */
1508 {"extloop", IOV_EXTLOOP
, 0, IOVT_BOOL
, 0}
1510 {"pktgen", IOV_PKTGEN
, 0, IOVT_BUFFER
, sizeof(dhd_pktgen_t
)}
1518 dhd_dump_pct(struct bcmstrbuf
*strbuf
, char *desc
, uint num
, uint div
)
1523 bcm_bprintf(strbuf
, "%s N/A", desc
);
1526 q2
= (100 * (num
- (q1
* div
))) / div
;
1527 bcm_bprintf(strbuf
, "%s %d.%02d", desc
, q1
, q2
);
1531 void dhd_bus_dump(dhd_pub_t
*dhdp
, struct bcmstrbuf
*strbuf
)
1533 dhd_bus_t
*bus
= dhdp
->bus
;
1535 bcm_bprintf(strbuf
, "Bus SDIO structure:\n");
1537 "hostintmask 0x%08x intstatus 0x%08x sdpcm_ver %d\n",
1538 bus
->hostintmask
, bus
->intstatus
, bus
->sdpcm_ver
);
1540 "fcstate %d qlen %d tx_seq %d, max %d, rxskip %d rxlen %d rx_seq %d\n",
1541 bus
->fcstate
, pktq_len(&bus
->txq
), bus
->tx_seq
, bus
->tx_max
,
1542 bus
->rxskip
, bus
->rxlen
, bus
->rx_seq
);
1543 bcm_bprintf(strbuf
, "intr %d intrcount %d lastintrs %d spurious %d\n",
1544 bus
->intr
, bus
->intrcount
, bus
->lastintrs
, bus
->spurious
);
1545 bcm_bprintf(strbuf
, "pollrate %d pollcnt %d regfails %d\n",
1546 bus
->pollrate
, bus
->pollcnt
, bus
->regfails
);
1548 bcm_bprintf(strbuf
, "\nAdditional counters:\n");
1550 "tx_sderrs %d fcqueued %d rxrtx %d rx_toolong %d rxc_errors %d\n",
1551 bus
->tx_sderrs
, bus
->fcqueued
, bus
->rxrtx
, bus
->rx_toolong
,
1553 bcm_bprintf(strbuf
, "rx_hdrfail %d badhdr %d badseq %d\n",
1554 bus
->rx_hdrfail
, bus
->rx_badhdr
, bus
->rx_badseq
);
1555 bcm_bprintf(strbuf
, "fc_rcvd %d, fc_xoff %d, fc_xon %d\n", bus
->fc_rcvd
,
1556 bus
->fc_xoff
, bus
->fc_xon
);
1557 bcm_bprintf(strbuf
, "rxglomfail %d, rxglomframes %d, rxglompkts %d\n",
1558 bus
->rxglomfail
, bus
->rxglomframes
, bus
->rxglompkts
);
1559 bcm_bprintf(strbuf
, "f2rx (hdrs/data) %d (%d/%d), f2tx %d f1regs %d\n",
1560 (bus
->f2rxhdrs
+ bus
->f2rxdata
), bus
->f2rxhdrs
,
1561 bus
->f2rxdata
, bus
->f2txdata
, bus
->f1regdata
);
1563 dhd_dump_pct(strbuf
, "\nRx: pkts/f2rd", bus
->dhd
->rx_packets
,
1564 (bus
->f2rxhdrs
+ bus
->f2rxdata
));
1565 dhd_dump_pct(strbuf
, ", pkts/f1sd", bus
->dhd
->rx_packets
,
1567 dhd_dump_pct(strbuf
, ", pkts/sd", bus
->dhd
->rx_packets
,
1568 (bus
->f2rxhdrs
+ bus
->f2rxdata
+ bus
->f1regdata
));
1569 dhd_dump_pct(strbuf
, ", pkts/int", bus
->dhd
->rx_packets
,
1571 bcm_bprintf(strbuf
, "\n");
1573 dhd_dump_pct(strbuf
, "Rx: glom pct", (100 * bus
->rxglompkts
),
1574 bus
->dhd
->rx_packets
);
1575 dhd_dump_pct(strbuf
, ", pkts/glom", bus
->rxglompkts
,
1577 bcm_bprintf(strbuf
, "\n");
1579 dhd_dump_pct(strbuf
, "Tx: pkts/f2wr", bus
->dhd
->tx_packets
,
1581 dhd_dump_pct(strbuf
, ", pkts/f1sd", bus
->dhd
->tx_packets
,
1583 dhd_dump_pct(strbuf
, ", pkts/sd", bus
->dhd
->tx_packets
,
1584 (bus
->f2txdata
+ bus
->f1regdata
));
1585 dhd_dump_pct(strbuf
, ", pkts/int", bus
->dhd
->tx_packets
,
1587 bcm_bprintf(strbuf
, "\n");
1589 dhd_dump_pct(strbuf
, "Total: pkts/f2rw",
1590 (bus
->dhd
->tx_packets
+ bus
->dhd
->rx_packets
),
1591 (bus
->f2txdata
+ bus
->f2rxhdrs
+ bus
->f2rxdata
));
1592 dhd_dump_pct(strbuf
, ", pkts/f1sd",
1593 (bus
->dhd
->tx_packets
+ bus
->dhd
->rx_packets
),
1595 dhd_dump_pct(strbuf
, ", pkts/sd",
1596 (bus
->dhd
->tx_packets
+ bus
->dhd
->rx_packets
),
1597 (bus
->f2txdata
+ bus
->f2rxhdrs
+ bus
->f2rxdata
+
1599 dhd_dump_pct(strbuf
, ", pkts/int",
1600 (bus
->dhd
->tx_packets
+ bus
->dhd
->rx_packets
),
1602 bcm_bprintf(strbuf
, "\n\n");
1606 if (bus
->pktgen_count
) {
1607 bcm_bprintf(strbuf
, "pktgen config and count:\n");
1609 "freq %d count %d print %d total %d min %d len %d\n",
1610 bus
->pktgen_freq
, bus
->pktgen_count
,
1611 bus
->pktgen_print
, bus
->pktgen_total
,
1612 bus
->pktgen_minlen
, bus
->pktgen_maxlen
);
1613 bcm_bprintf(strbuf
, "send attempts %d rcvd %d fail %d\n",
1614 bus
->pktgen_sent
, bus
->pktgen_rcvd
,
1619 bcm_bprintf(strbuf
, "dpc_sched %d host interrupt%spending\n",
1621 (bcmsdh_intr_pending(bus
->sdh
) ? " " : " not "));
1622 bcm_bprintf(strbuf
, "blocksize %d roundup %d\n", bus
->blocksize
,
1624 #endif /* DHD_DEBUG */
1626 "clkstate %d activity %d idletime %d idlecount %d sleeping %d\n",
1627 bus
->clkstate
, bus
->activity
, bus
->idletime
, bus
->idlecount
,
1631 void dhd_bus_clearcounts(dhd_pub_t
*dhdp
)
1633 dhd_bus_t
*bus
= (dhd_bus_t
*) dhdp
->bus
;
1635 bus
->intrcount
= bus
->lastintrs
= bus
->spurious
= bus
->regfails
= 0;
1636 bus
->rxrtx
= bus
->rx_toolong
= bus
->rxc_errors
= 0;
1637 bus
->rx_hdrfail
= bus
->rx_badhdr
= bus
->rx_badseq
= 0;
1638 bus
->tx_sderrs
= bus
->fc_rcvd
= bus
->fc_xoff
= bus
->fc_xon
= 0;
1639 bus
->rxglomfail
= bus
->rxglomframes
= bus
->rxglompkts
= 0;
1640 bus
->f2rxhdrs
= bus
->f2rxdata
= bus
->f2txdata
= bus
->f1regdata
= 0;
1644 static int dhdsdio_pktgen_get(dhd_bus_t
*bus
, u8
*arg
)
1646 dhd_pktgen_t pktgen
;
1648 pktgen
.version
= DHD_PKTGEN_VERSION
;
1649 pktgen
.freq
= bus
->pktgen_freq
;
1650 pktgen
.count
= bus
->pktgen_count
;
1651 pktgen
.print
= bus
->pktgen_print
;
1652 pktgen
.total
= bus
->pktgen_total
;
1653 pktgen
.minlen
= bus
->pktgen_minlen
;
1654 pktgen
.maxlen
= bus
->pktgen_maxlen
;
1655 pktgen
.numsent
= bus
->pktgen_sent
;
1656 pktgen
.numrcvd
= bus
->pktgen_rcvd
;
1657 pktgen
.numfail
= bus
->pktgen_fail
;
1658 pktgen
.mode
= bus
->pktgen_mode
;
1659 pktgen
.stop
= bus
->pktgen_stop
;
1661 bcopy(&pktgen
, arg
, sizeof(pktgen
));
1666 static int dhdsdio_pktgen_set(dhd_bus_t
*bus
, u8
*arg
)
1668 dhd_pktgen_t pktgen
;
1669 uint oldcnt
, oldmode
;
1671 bcopy(arg
, &pktgen
, sizeof(pktgen
));
1672 if (pktgen
.version
!= DHD_PKTGEN_VERSION
)
1675 oldcnt
= bus
->pktgen_count
;
1676 oldmode
= bus
->pktgen_mode
;
1678 bus
->pktgen_freq
= pktgen
.freq
;
1679 bus
->pktgen_count
= pktgen
.count
;
1680 bus
->pktgen_print
= pktgen
.print
;
1681 bus
->pktgen_total
= pktgen
.total
;
1682 bus
->pktgen_minlen
= pktgen
.minlen
;
1683 bus
->pktgen_maxlen
= pktgen
.maxlen
;
1684 bus
->pktgen_mode
= pktgen
.mode
;
1685 bus
->pktgen_stop
= pktgen
.stop
;
1687 bus
->pktgen_tick
= bus
->pktgen_ptick
= 0;
1688 bus
->pktgen_len
= max(bus
->pktgen_len
, bus
->pktgen_minlen
);
1689 bus
->pktgen_len
= min(bus
->pktgen_len
, bus
->pktgen_maxlen
);
1691 /* Clear counts for a new pktgen (mode change, or was stopped) */
1692 if (bus
->pktgen_count
&& (!oldcnt
|| oldmode
!= bus
->pktgen_mode
))
1693 bus
->pktgen_sent
= bus
->pktgen_rcvd
= bus
->pktgen_fail
= 0;
1700 dhdsdio_membytes(dhd_bus_t
*bus
, bool write
, u32 address
, u8
*data
,
1707 /* Determine initial transfer parameters */
1708 sdaddr
= address
& SBSDIO_SB_OFT_ADDR_MASK
;
1709 if ((sdaddr
+ size
) & SBSDIO_SBWINDOW_MASK
)
1710 dsize
= (SBSDIO_SB_OFT_ADDR_LIMIT
- sdaddr
);
1714 /* Set the backplane window to include the start address */
1715 bcmerror
= dhdsdio_set_siaddr_window(bus
, address
);
1717 DHD_ERROR(("%s: window change failed\n", __func__
));
1721 /* Do the transfer(s) */
1723 DHD_INFO(("%s: %s %d bytes at offset 0x%08x in window 0x%08x\n",
1724 __func__
, (write
? "write" : "read"), dsize
,
1725 sdaddr
, (address
& SBSDIO_SBWINDOW_MASK
)));
1727 bcmsdh_rwdata(bus
->sdh
, write
, sdaddr
, data
, dsize
);
1729 DHD_ERROR(("%s: membytes transfer failed\n", __func__
));
1733 /* Adjust for next transfer (if any) */
1738 bcmerror
= dhdsdio_set_siaddr_window(bus
, address
);
1740 DHD_ERROR(("%s: window change failed\n",
1745 dsize
= min_t(uint
, SBSDIO_SB_OFT_ADDR_LIMIT
, size
);
1750 /* Return the window to backplane enumeration space for core access */
1751 if (dhdsdio_set_siaddr_window(bus
, bcmsdh_cur_sbwad(bus
->sdh
))) {
1752 DHD_ERROR(("%s: FAILED to set window back to 0x%x\n",
1753 __func__
, bcmsdh_cur_sbwad(bus
->sdh
)));
1760 static int dhdsdio_readshared(dhd_bus_t
*bus
, sdpcm_shared_t
*sh
)
1765 /* Read last word in memory to determine address of
1766 sdpcm_shared structure */
1767 rv
= dhdsdio_membytes(bus
, false, bus
->ramsize
- 4, (u8
*)&addr
, 4);
1771 addr
= ltoh32(addr
);
1773 DHD_INFO(("sdpcm_shared address 0x%08X\n", addr
));
1776 * Check if addr is valid.
1777 * NVRAM length at the end of memory should have been overwritten.
1779 if (addr
== 0 || ((~addr
>> 16) & 0xffff) == (addr
& 0xffff)) {
1780 DHD_ERROR(("%s: address (0x%08x) of sdpcm_shared invalid\n",
1785 /* Read hndrte_shared structure */
1786 rv
= dhdsdio_membytes(bus
, false, addr
, (u8
*) sh
,
1787 sizeof(sdpcm_shared_t
));
1792 sh
->flags
= ltoh32(sh
->flags
);
1793 sh
->trap_addr
= ltoh32(sh
->trap_addr
);
1794 sh
->assert_exp_addr
= ltoh32(sh
->assert_exp_addr
);
1795 sh
->assert_file_addr
= ltoh32(sh
->assert_file_addr
);
1796 sh
->assert_line
= ltoh32(sh
->assert_line
);
1797 sh
->console_addr
= ltoh32(sh
->console_addr
);
1798 sh
->msgtrace_addr
= ltoh32(sh
->msgtrace_addr
);
1800 if ((sh
->flags
& SDPCM_SHARED_VERSION_MASK
) != SDPCM_SHARED_VERSION
) {
1801 DHD_ERROR(("%s: sdpcm_shared version %d in dhd "
1802 "is different than sdpcm_shared version %d in dongle\n",
1803 __func__
, SDPCM_SHARED_VERSION
,
1804 sh
->flags
& SDPCM_SHARED_VERSION_MASK
));
1811 static int dhdsdio_checkdied(dhd_bus_t
*bus
, u8
*data
, uint size
)
1815 char *mbuffer
= NULL
;
1816 uint maxstrlen
= 256;
1819 sdpcm_shared_t sdpcm_shared
;
1820 struct bcmstrbuf strbuf
;
1822 DHD_TRACE(("%s: Enter\n", __func__
));
1826 * Called after a rx ctrl timeout. "data" is NULL.
1827 * allocate memory to trace the trap or assert.
1830 mbuffer
= data
= kmalloc(msize
, GFP_ATOMIC
);
1831 if (mbuffer
== NULL
) {
1832 DHD_ERROR(("%s: kmalloc(%d) failed\n", __func__
,
1834 bcmerror
= BCME_NOMEM
;
1839 str
= kmalloc(maxstrlen
, GFP_ATOMIC
);
1841 DHD_ERROR(("%s: kmalloc(%d) failed\n", __func__
, maxstrlen
));
1842 bcmerror
= BCME_NOMEM
;
1846 bcmerror
= dhdsdio_readshared(bus
, &sdpcm_shared
);
1850 bcm_binit(&strbuf
, data
, size
);
1852 bcm_bprintf(&strbuf
,
1853 "msgtrace address : 0x%08X\nconsole address : 0x%08X\n",
1854 sdpcm_shared
.msgtrace_addr
, sdpcm_shared
.console_addr
);
1856 if ((sdpcm_shared
.flags
& SDPCM_SHARED_ASSERT_BUILT
) == 0) {
1857 /* NOTE: Misspelled assert is intentional - DO NOT FIX.
1858 * (Avoids conflict with real asserts for programmatic
1859 * parsing of output.)
1861 bcm_bprintf(&strbuf
, "Assrt not built in dongle\n");
1864 if ((sdpcm_shared
.flags
& (SDPCM_SHARED_ASSERT
| SDPCM_SHARED_TRAP
)) ==
1866 /* NOTE: Misspelled assert is intentional - DO NOT FIX.
1867 * (Avoids conflict with real asserts for programmatic
1868 * parsing of output.)
1870 bcm_bprintf(&strbuf
, "No trap%s in dongle",
1871 (sdpcm_shared
.flags
& SDPCM_SHARED_ASSERT_BUILT
)
1874 if (sdpcm_shared
.flags
& SDPCM_SHARED_ASSERT
) {
1875 /* Download assert */
1876 bcm_bprintf(&strbuf
, "Dongle assert");
1877 if (sdpcm_shared
.assert_exp_addr
!= 0) {
1879 bcmerror
= dhdsdio_membytes(bus
, false,
1880 sdpcm_shared
.assert_exp_addr
,
1881 (u8
*) str
, maxstrlen
);
1885 str
[maxstrlen
- 1] = '\0';
1886 bcm_bprintf(&strbuf
, " expr \"%s\"", str
);
1889 if (sdpcm_shared
.assert_file_addr
!= 0) {
1891 bcmerror
= dhdsdio_membytes(bus
, false,
1892 sdpcm_shared
.assert_file_addr
,
1893 (u8
*) str
, maxstrlen
);
1897 str
[maxstrlen
- 1] = '\0';
1898 bcm_bprintf(&strbuf
, " file \"%s\"", str
);
1901 bcm_bprintf(&strbuf
, " line %d ",
1902 sdpcm_shared
.assert_line
);
1905 if (sdpcm_shared
.flags
& SDPCM_SHARED_TRAP
) {
1906 bcmerror
= dhdsdio_membytes(bus
, false,
1907 sdpcm_shared
.trap_addr
, (u8
*)&tr
,
1912 bcm_bprintf(&strbuf
,
1913 "Dongle trap type 0x%x @ epc 0x%x, cpsr 0x%x, spsr 0x%x, sp 0x%x,"
1914 "lp 0x%x, rpc 0x%x Trap offset 0x%x, "
1915 "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",
1916 tr
.type
, tr
.epc
, tr
.cpsr
, tr
.spsr
, tr
.r13
,
1917 tr
.r14
, tr
.pc
, sdpcm_shared
.trap_addr
,
1918 tr
.r0
, tr
.r1
, tr
.r2
, tr
.r3
, tr
.r4
, tr
.r5
,
1923 if (sdpcm_shared
.flags
& (SDPCM_SHARED_ASSERT
| SDPCM_SHARED_TRAP
))
1924 DHD_ERROR(("%s: %s\n", __func__
, strbuf
.origbuf
));
1927 if (sdpcm_shared
.flags
& SDPCM_SHARED_TRAP
) {
1928 /* Mem dump to a file on device */
1929 dhdsdio_mem_dump(bus
);
1931 #endif /* DHD_DEBUG */
1942 static int dhdsdio_mem_dump(dhd_bus_t
*bus
)
1945 int size
; /* Full mem size */
1946 int start
= 0; /* Start address */
1947 int read_size
= 0; /* Read size of each iteration */
1948 u8
*buf
= NULL
, *databuf
= NULL
;
1950 /* Get full mem size */
1951 size
= bus
->ramsize
;
1952 buf
= kmalloc(size
, GFP_ATOMIC
);
1954 DHD_ERROR(("%s: Out of memory (%d bytes)\n", __func__
, size
));
1958 /* Read mem content */
1959 printk(KERN_DEBUG
"Dump dongle memory");
1962 read_size
= min(MEMBLOCK
, size
);
1963 ret
= dhdsdio_membytes(bus
, false, start
, databuf
, read_size
);
1965 DHD_ERROR(("%s: Error membytes %d\n", __func__
, ret
));
1972 /* Decrement size and increment start address */
1975 databuf
+= read_size
;
1977 printk(KERN_DEBUG
"Done\n");
1979 /* free buf before return !!! */
1980 if (write_to_file(bus
->dhd
, buf
, bus
->ramsize
)) {
1981 DHD_ERROR(("%s: Error writing to files\n", __func__
));
1985 /* buf free handled in write_to_file, not here */
1989 #define CONSOLE_LINE_MAX 192
1991 static int dhdsdio_readconsole(dhd_bus_t
*bus
)
1993 dhd_console_t
*c
= &bus
->console
;
1994 u8 line
[CONSOLE_LINE_MAX
], ch
;
1998 /* Don't do anything until FWREADY updates console address */
1999 if (bus
->console_addr
== 0)
2002 /* Read console log struct */
2003 addr
= bus
->console_addr
+ offsetof(hndrte_cons_t
, log
);
2004 rv
= dhdsdio_membytes(bus
, false, addr
, (u8
*)&c
->log
,
2009 /* Allocate console buffer (one time only) */
2010 if (c
->buf
== NULL
) {
2011 c
->bufsize
= ltoh32(c
->log
.buf_size
);
2012 c
->buf
= kmalloc(c
->bufsize
, GFP_ATOMIC
);
2017 idx
= ltoh32(c
->log
.idx
);
2019 /* Protect against corrupt value */
2020 if (idx
> c
->bufsize
)
2023 /* Skip reading the console buffer if the index pointer
2028 /* Read the console buffer */
2029 addr
= ltoh32(c
->log
.buf
);
2030 rv
= dhdsdio_membytes(bus
, false, addr
, c
->buf
, c
->bufsize
);
2034 while (c
->last
!= idx
) {
2035 for (n
= 0; n
< CONSOLE_LINE_MAX
- 2; n
++) {
2036 if (c
->last
== idx
) {
2037 /* This would output a partial line.
2039 * the buffer pointer and output this
2040 * line next time around.
2045 c
->last
= c
->bufsize
- n
;
2048 ch
= c
->buf
[c
->last
];
2049 c
->last
= (c
->last
+ 1) % c
->bufsize
;
2056 if (line
[n
- 1] == '\r')
2059 printk(KERN_DEBUG
"CONSOLE: %s\n", line
);
2066 #endif /* DHD_DEBUG */
2068 int dhdsdio_downloadvars(dhd_bus_t
*bus
, void *arg
, int len
)
2070 int bcmerror
= BCME_OK
;
2072 DHD_TRACE(("%s: Enter\n", __func__
));
2074 /* Basic sanity checks */
2076 bcmerror
= BCME_NOTDOWN
;
2080 bcmerror
= BCME_BUFTOOSHORT
;
2084 /* Free the old ones and replace with passed variables */
2088 bus
->vars
= kmalloc(len
, GFP_ATOMIC
);
2089 bus
->varsz
= bus
->vars
? len
: 0;
2090 if (bus
->vars
== NULL
) {
2091 bcmerror
= BCME_NOMEM
;
2095 /* Copy the passed variables, which should include the
2096 terminating double-null */
2097 bcopy(arg
, bus
->vars
, bus
->varsz
);
2103 dhdsdio_doiovar(dhd_bus_t
*bus
, const bcm_iovar_t
*vi
, u32 actionid
,
2104 const char *name
, void *params
, int plen
, void *arg
, int len
,
2111 DHD_TRACE(("%s: Enter, action %d name %s params %p plen %d arg %p "
2112 "len %d val_size %d\n",
2113 __func__
, actionid
, name
, params
, plen
, arg
, len
, val_size
));
2115 bcmerror
= bcm_iovar_lencheck(vi
, arg
, len
, IOV_ISSET(actionid
));
2119 if (plen
>= (int)sizeof(int_val
))
2120 bcopy(params
, &int_val
, sizeof(int_val
));
2122 bool_val
= (int_val
!= 0) ? true : false;
2124 /* Some ioctls use the bus */
2125 dhd_os_sdlock(bus
->dhd
);
2127 /* Check if dongle is in reset. If so, only allow DEVRESET iovars */
2128 if (bus
->dhd
->dongle_reset
&& !(actionid
== IOV_SVAL(IOV_DEVRESET
) ||
2129 actionid
== IOV_GVAL(IOV_DEVRESET
))) {
2130 bcmerror
= BCME_NOTREADY
;
2134 /* Handle sleep stuff before any clock mucking */
2135 if (vi
->varid
== IOV_SLEEP
) {
2136 if (IOV_ISSET(actionid
)) {
2137 bcmerror
= dhdsdio_bussleep(bus
, bool_val
);
2139 int_val
= (s32
) bus
->sleeping
;
2140 bcopy(&int_val
, arg
, val_size
);
2145 /* Request clock to allow SDIO accesses */
2146 if (!bus
->dhd
->dongle_reset
) {
2148 dhdsdio_clkctl(bus
, CLK_AVAIL
, false);
2152 case IOV_GVAL(IOV_INTR
):
2153 int_val
= (s32
) bus
->intr
;
2154 bcopy(&int_val
, arg
, val_size
);
2157 case IOV_SVAL(IOV_INTR
):
2158 bus
->intr
= bool_val
;
2159 bus
->intdis
= false;
2162 DHD_INTR(("%s: enable SDIO device interrupts\n",
2164 bcmsdh_intr_enable(bus
->sdh
);
2166 DHD_INTR(("%s: disable SDIO interrupts\n",
2168 bcmsdh_intr_disable(bus
->sdh
);
2173 case IOV_GVAL(IOV_POLLRATE
):
2174 int_val
= (s32
) bus
->pollrate
;
2175 bcopy(&int_val
, arg
, val_size
);
2178 case IOV_SVAL(IOV_POLLRATE
):
2179 bus
->pollrate
= (uint
) int_val
;
2180 bus
->poll
= (bus
->pollrate
!= 0);
2183 case IOV_GVAL(IOV_IDLETIME
):
2184 int_val
= bus
->idletime
;
2185 bcopy(&int_val
, arg
, val_size
);
2188 case IOV_SVAL(IOV_IDLETIME
):
2189 if ((int_val
< 0) && (int_val
!= DHD_IDLE_IMMEDIATE
))
2190 bcmerror
= BCME_BADARG
;
2192 bus
->idletime
= int_val
;
2195 case IOV_GVAL(IOV_IDLECLOCK
):
2196 int_val
= (s32
) bus
->idleclock
;
2197 bcopy(&int_val
, arg
, val_size
);
2200 case IOV_SVAL(IOV_IDLECLOCK
):
2201 bus
->idleclock
= int_val
;
2204 case IOV_GVAL(IOV_SD1IDLE
):
2205 int_val
= (s32
) sd1idle
;
2206 bcopy(&int_val
, arg
, val_size
);
2209 case IOV_SVAL(IOV_SD1IDLE
):
2213 case IOV_SVAL(IOV_MEMBYTES
):
2214 case IOV_GVAL(IOV_MEMBYTES
):
2220 bool set
= (actionid
== IOV_SVAL(IOV_MEMBYTES
));
2222 ASSERT(plen
>= 2 * sizeof(int));
2224 address
= (u32
) int_val
;
2225 bcopy((char *)params
+ sizeof(int_val
), &int_val
,
2227 size
= (uint
) int_val
;
2229 /* Do some validation */
2230 dsize
= set
? plen
- (2 * sizeof(int)) : len
;
2232 DHD_ERROR(("%s: error on %s membytes, addr "
2233 "0x%08x size %d dsize %d\n",
2234 __func__
, (set
? "set" : "get"),
2235 address
, size
, dsize
));
2236 bcmerror
= BCME_BADARG
;
2240 DHD_INFO(("%s: Request to %s %d bytes at address "
2242 __func__
, (set
? "write" : "read"), size
, address
));
2244 /* If we know about SOCRAM, check for a fit */
2245 if ((bus
->orig_ramsize
) &&
2246 ((address
> bus
->orig_ramsize
)
2247 || (address
+ size
> bus
->orig_ramsize
))) {
2248 DHD_ERROR(("%s: ramsize 0x%08x doesn't have %d "
2249 "bytes at 0x%08x\n",
2250 __func__
, bus
->orig_ramsize
, size
, address
));
2251 bcmerror
= BCME_BADARG
;
2255 /* Generate the actual data pointer */
2257 set
? (u8
*) params
+
2258 2 * sizeof(int) : (u8
*) arg
;
2260 /* Call to do the transfer */
2262 dhdsdio_membytes(bus
, set
, address
, data
, size
);
2267 case IOV_GVAL(IOV_MEMSIZE
):
2268 int_val
= (s32
) bus
->ramsize
;
2269 bcopy(&int_val
, arg
, val_size
);
2272 case IOV_GVAL(IOV_SDIOD_DRIVE
):
2273 int_val
= (s32
) dhd_sdiod_drive_strength
;
2274 bcopy(&int_val
, arg
, val_size
);
2277 case IOV_SVAL(IOV_SDIOD_DRIVE
):
2278 dhd_sdiod_drive_strength
= int_val
;
2279 si_sdiod_drive_strength_init(bus
->sih
, bus
->dhd
->osh
,
2280 dhd_sdiod_drive_strength
);
2283 case IOV_SVAL(IOV_DOWNLOAD
):
2284 bcmerror
= dhdsdio_download_state(bus
, bool_val
);
2287 case IOV_SVAL(IOV_VARS
):
2288 bcmerror
= dhdsdio_downloadvars(bus
, arg
, len
);
2291 case IOV_GVAL(IOV_READAHEAD
):
2292 int_val
= (s32
) dhd_readahead
;
2293 bcopy(&int_val
, arg
, val_size
);
2296 case IOV_SVAL(IOV_READAHEAD
):
2297 if (bool_val
&& !dhd_readahead
)
2299 dhd_readahead
= bool_val
;
2302 case IOV_GVAL(IOV_SDRXCHAIN
):
2303 int_val
= (s32
) bus
->use_rxchain
;
2304 bcopy(&int_val
, arg
, val_size
);
2307 case IOV_SVAL(IOV_SDRXCHAIN
):
2308 if (bool_val
&& !bus
->sd_rxchain
)
2309 bcmerror
= BCME_UNSUPPORTED
;
2311 bus
->use_rxchain
= bool_val
;
2313 case IOV_GVAL(IOV_ALIGNCTL
):
2314 int_val
= (s32
) dhd_alignctl
;
2315 bcopy(&int_val
, arg
, val_size
);
2318 case IOV_SVAL(IOV_ALIGNCTL
):
2319 dhd_alignctl
= bool_val
;
2322 case IOV_GVAL(IOV_SDALIGN
):
2323 int_val
= DHD_SDALIGN
;
2324 bcopy(&int_val
, arg
, val_size
);
2328 case IOV_GVAL(IOV_VARS
):
2329 if (bus
->varsz
< (uint
) len
)
2330 bcopy(bus
->vars
, arg
, bus
->varsz
);
2332 bcmerror
= BCME_BUFTOOSHORT
;
2334 #endif /* DHD_DEBUG */
2337 case IOV_GVAL(IOV_SDREG
):
2342 sd_ptr
= (sdreg_t
*) params
;
2344 addr
= (unsigned long)bus
->regs
+ sd_ptr
->offset
;
2345 size
= sd_ptr
->func
;
2346 int_val
= (s32
) bcmsdh_reg_read(bus
->sdh
, addr
, size
);
2347 if (bcmsdh_regfail(bus
->sdh
))
2348 bcmerror
= BCME_SDIO_ERROR
;
2349 bcopy(&int_val
, arg
, sizeof(s32
));
2353 case IOV_SVAL(IOV_SDREG
):
2358 sd_ptr
= (sdreg_t
*) params
;
2360 addr
= (unsigned long)bus
->regs
+ sd_ptr
->offset
;
2361 size
= sd_ptr
->func
;
2362 bcmsdh_reg_write(bus
->sdh
, addr
, size
, sd_ptr
->value
);
2363 if (bcmsdh_regfail(bus
->sdh
))
2364 bcmerror
= BCME_SDIO_ERROR
;
2368 /* Same as above, but offset is not backplane
2370 case IOV_GVAL(IOV_SBREG
):
2375 bcopy(params
, &sdreg
, sizeof(sdreg
));
2377 addr
= SI_ENUM_BASE
+ sdreg
.offset
;
2379 int_val
= (s32
) bcmsdh_reg_read(bus
->sdh
, addr
, size
);
2380 if (bcmsdh_regfail(bus
->sdh
))
2381 bcmerror
= BCME_SDIO_ERROR
;
2382 bcopy(&int_val
, arg
, sizeof(s32
));
2386 case IOV_SVAL(IOV_SBREG
):
2391 bcopy(params
, &sdreg
, sizeof(sdreg
));
2393 addr
= SI_ENUM_BASE
+ sdreg
.offset
;
2395 bcmsdh_reg_write(bus
->sdh
, addr
, size
, sdreg
.value
);
2396 if (bcmsdh_regfail(bus
->sdh
))
2397 bcmerror
= BCME_SDIO_ERROR
;
2401 case IOV_GVAL(IOV_SDCIS
):
2405 strcat(arg
, "\nFunc 0\n");
2406 bcmsdh_cis_read(bus
->sdh
, 0x10,
2407 (u8
*) arg
+ strlen(arg
),
2408 SBSDIO_CIS_SIZE_LIMIT
);
2409 strcat(arg
, "\nFunc 1\n");
2410 bcmsdh_cis_read(bus
->sdh
, 0x11,
2411 (u8
*) arg
+ strlen(arg
),
2412 SBSDIO_CIS_SIZE_LIMIT
);
2413 strcat(arg
, "\nFunc 2\n");
2414 bcmsdh_cis_read(bus
->sdh
, 0x12,
2415 (u8
*) arg
+ strlen(arg
),
2416 SBSDIO_CIS_SIZE_LIMIT
);
2420 case IOV_GVAL(IOV_FORCEEVEN
):
2421 int_val
= (s32
) forcealign
;
2422 bcopy(&int_val
, arg
, val_size
);
2425 case IOV_SVAL(IOV_FORCEEVEN
):
2426 forcealign
= bool_val
;
2429 case IOV_GVAL(IOV_TXBOUND
):
2430 int_val
= (s32
) dhd_txbound
;
2431 bcopy(&int_val
, arg
, val_size
);
2434 case IOV_SVAL(IOV_TXBOUND
):
2435 dhd_txbound
= (uint
) int_val
;
2438 case IOV_GVAL(IOV_RXBOUND
):
2439 int_val
= (s32
) dhd_rxbound
;
2440 bcopy(&int_val
, arg
, val_size
);
2443 case IOV_SVAL(IOV_RXBOUND
):
2444 dhd_rxbound
= (uint
) int_val
;
2447 case IOV_GVAL(IOV_TXMINMAX
):
2448 int_val
= (s32
) dhd_txminmax
;
2449 bcopy(&int_val
, arg
, val_size
);
2452 case IOV_SVAL(IOV_TXMINMAX
):
2453 dhd_txminmax
= (uint
) int_val
;
2455 #endif /* DHD_DEBUG */
2458 case IOV_GVAL(IOV_EXTLOOP
):
2459 int_val
= (s32
) bus
->ext_loop
;
2460 bcopy(&int_val
, arg
, val_size
);
2463 case IOV_SVAL(IOV_EXTLOOP
):
2464 bus
->ext_loop
= bool_val
;
2467 case IOV_GVAL(IOV_PKTGEN
):
2468 bcmerror
= dhdsdio_pktgen_get(bus
, arg
);
2471 case IOV_SVAL(IOV_PKTGEN
):
2472 bcmerror
= dhdsdio_pktgen_set(bus
, arg
);
2476 case IOV_SVAL(IOV_DEVRESET
):
2477 DHD_TRACE(("%s: Called set IOV_DEVRESET=%d dongle_reset=%d "
2479 __func__
, bool_val
, bus
->dhd
->dongle_reset
,
2480 bus
->dhd
->busstate
));
2482 ASSERT(bus
->dhd
->osh
);
2483 /* ASSERT(bus->cl_devid); */
2485 dhd_bus_devreset(bus
->dhd
, (u8
) bool_val
);
2489 case IOV_GVAL(IOV_DEVRESET
):
2490 DHD_TRACE(("%s: Called get IOV_DEVRESET\n", __func__
));
2492 /* Get its status */
2493 int_val
= (bool) bus
->dhd
->dongle_reset
;
2494 bcopy(&int_val
, arg
, val_size
);
2499 bcmerror
= BCME_UNSUPPORTED
;
2504 if ((bus
->idletime
== DHD_IDLE_IMMEDIATE
) && !bus
->dpc_sched
) {
2505 bus
->activity
= false;
2506 dhdsdio_clkctl(bus
, CLK_NONE
, true);
2509 dhd_os_sdunlock(bus
->dhd
);
2511 if (actionid
== IOV_SVAL(IOV_DEVRESET
) && bool_val
== false)
2512 dhd_preinit_ioctls((dhd_pub_t
*) bus
->dhd
);
2517 static int dhdsdio_write_vars(dhd_bus_t
*bus
)
2525 char *nvram_ularray
;
2526 #endif /* DHD_DEBUG */
2528 /* Even if there are no vars are to be written, we still
2529 need to set the ramsize. */
2530 varsize
= bus
->varsz
? roundup(bus
->varsz
, 4) : 0;
2531 varaddr
= (bus
->ramsize
- 4) - varsize
;
2534 vbuffer
= kmalloc(varsize
, GFP_ATOMIC
);
2538 memset(vbuffer
, 0, varsize
);
2539 bcopy(bus
->vars
, vbuffer
, bus
->varsz
);
2541 /* Write the vars list */
2543 dhdsdio_membytes(bus
, true, varaddr
, vbuffer
, varsize
);
2545 /* Verify NVRAM bytes */
2546 DHD_INFO(("Compare NVRAM dl & ul; varsize=%d\n", varsize
));
2547 nvram_ularray
= kmalloc(varsize
, GFP_ATOMIC
);
2551 /* Upload image to verify downloaded contents. */
2552 memset(nvram_ularray
, 0xaa, varsize
);
2554 /* Read the vars list to temp buffer for comparison */
2556 dhdsdio_membytes(bus
, false, varaddr
, nvram_ularray
,
2559 DHD_ERROR(("%s: error %d on reading %d nvram bytes at "
2560 "0x%08x\n", __func__
, bcmerror
, varsize
, varaddr
));
2562 /* Compare the org NVRAM with the one read from RAM */
2563 if (memcmp(vbuffer
, nvram_ularray
, varsize
)) {
2564 DHD_ERROR(("%s: Downloaded NVRAM image is corrupted.\n",
2567 DHD_ERROR(("%s: Download/Upload/Compare of NVRAM ok.\n",
2570 kfree(nvram_ularray
);
2571 #endif /* DHD_DEBUG */
2576 /* adjust to the user specified RAM */
2577 DHD_INFO(("Physical memory size: %d, usable memory size: %d\n",
2578 bus
->orig_ramsize
, bus
->ramsize
));
2579 DHD_INFO(("Vars are at %d, orig varsize is %d\n", varaddr
, varsize
));
2580 varsize
= ((bus
->orig_ramsize
- 4) - varaddr
);
2583 * Determine the length token:
2584 * Varsize, converted to words, in lower 16-bits, checksum
2590 varsizew
= varsize
/ 4;
2591 varsizew
= (~varsizew
<< 16) | (varsizew
& 0x0000FFFF);
2592 varsizew
= htol32(varsizew
);
2595 DHD_INFO(("New varsize is %d, length token=0x%08x\n", varsize
,
2598 /* Write the length token to the last word */
2599 bcmerror
= dhdsdio_membytes(bus
, true, (bus
->orig_ramsize
- 4),
2600 (u8
*)&varsizew
, 4);
2605 static int dhdsdio_download_state(dhd_bus_t
*bus
, bool enter
)
2610 /* To enter download state, disable ARM and reset SOCRAM.
2611 * To exit download state, simply reset ARM (default is RAM boot).
2615 bus
->alp_only
= true;
2617 if (!(si_setcore(bus
->sih
, ARM7S_CORE_ID
, 0)) &&
2618 !(si_setcore(bus
->sih
, ARMCM3_CORE_ID
, 0))) {
2619 DHD_ERROR(("%s: Failed to find ARM core!\n", __func__
));
2620 bcmerror
= BCME_ERROR
;
2624 si_core_disable(bus
->sih
, 0);
2625 if (bcmsdh_regfail(bus
->sdh
)) {
2626 bcmerror
= BCME_SDIO_ERROR
;
2630 if (!(si_setcore(bus
->sih
, SOCRAM_CORE_ID
, 0))) {
2631 DHD_ERROR(("%s: Failed to find SOCRAM core!\n",
2633 bcmerror
= BCME_ERROR
;
2637 si_core_reset(bus
->sih
, 0, 0);
2638 if (bcmsdh_regfail(bus
->sdh
)) {
2639 DHD_ERROR(("%s: Failure trying reset SOCRAM core?\n",
2641 bcmerror
= BCME_SDIO_ERROR
;
2645 /* Clear the top bit of memory */
2648 dhdsdio_membytes(bus
, true, bus
->ramsize
- 4,
2652 if (!(si_setcore(bus
->sih
, SOCRAM_CORE_ID
, 0))) {
2653 DHD_ERROR(("%s: Failed to find SOCRAM core!\n",
2655 bcmerror
= BCME_ERROR
;
2659 if (!si_iscoreup(bus
->sih
)) {
2660 DHD_ERROR(("%s: SOCRAM core is down after reset?\n",
2662 bcmerror
= BCME_ERROR
;
2666 bcmerror
= dhdsdio_write_vars(bus
);
2668 DHD_ERROR(("%s: no vars written to RAM\n", __func__
));
2672 if (!si_setcore(bus
->sih
, PCMCIA_CORE_ID
, 0) &&
2673 !si_setcore(bus
->sih
, SDIOD_CORE_ID
, 0)) {
2674 DHD_ERROR(("%s: Can't change back to SDIO core?\n",
2676 bcmerror
= BCME_ERROR
;
2679 W_SDREG(0xFFFFFFFF, &bus
->regs
->intstatus
, retries
);
2681 if (!(si_setcore(bus
->sih
, ARM7S_CORE_ID
, 0)) &&
2682 !(si_setcore(bus
->sih
, ARMCM3_CORE_ID
, 0))) {
2683 DHD_ERROR(("%s: Failed to find ARM core!\n", __func__
));
2684 bcmerror
= BCME_ERROR
;
2688 si_core_reset(bus
->sih
, 0, 0);
2689 if (bcmsdh_regfail(bus
->sdh
)) {
2690 DHD_ERROR(("%s: Failure trying to reset ARM core?\n",
2692 bcmerror
= BCME_SDIO_ERROR
;
2696 /* Allow HT Clock now that the ARM is running. */
2697 bus
->alp_only
= false;
2699 bus
->dhd
->busstate
= DHD_BUS_LOAD
;
2703 /* Always return to SDIOD core */
2704 if (!si_setcore(bus
->sih
, PCMCIA_CORE_ID
, 0))
2705 si_setcore(bus
->sih
, SDIOD_CORE_ID
, 0);
2711 dhd_bus_iovar_op(dhd_pub_t
*dhdp
, const char *name
,
2712 void *params
, int plen
, void *arg
, int len
, bool set
)
2714 dhd_bus_t
*bus
= dhdp
->bus
;
2715 const bcm_iovar_t
*vi
= NULL
;
2720 DHD_TRACE(("%s: Enter\n", __func__
));
2725 /* Get MUST have return space */
2726 ASSERT(set
|| (arg
&& len
));
2728 /* Set does NOT take qualifiers */
2729 ASSERT(!set
|| (!params
&& !plen
));
2731 /* Look up var locally; if not found pass to host driver */
2732 vi
= bcm_iovar_lookup(dhdsdio_iovars
, name
);
2734 dhd_os_sdlock(bus
->dhd
);
2738 /* Turn on clock in case SD command needs backplane */
2739 dhdsdio_clkctl(bus
, CLK_AVAIL
, false);
2742 bcmsdh_iovar_op(bus
->sdh
, name
, params
, plen
, arg
, len
,
2745 /* Check for bus configuration changes of interest */
2747 /* If it was divisor change, read the new one */
2748 if (set
&& strcmp(name
, "sd_divisor") == 0) {
2749 if (bcmsdh_iovar_op(bus
->sdh
, "sd_divisor", NULL
, 0,
2750 &bus
->sd_divisor
, sizeof(s32
),
2751 false) != BCME_OK
) {
2752 bus
->sd_divisor
= -1;
2753 DHD_ERROR(("%s: fail on %s get\n", __func__
,
2756 DHD_INFO(("%s: noted %s update, value now %d\n",
2757 __func__
, name
, bus
->sd_divisor
));
2760 /* If it was a mode change, read the new one */
2761 if (set
&& strcmp(name
, "sd_mode") == 0) {
2762 if (bcmsdh_iovar_op(bus
->sdh
, "sd_mode", NULL
, 0,
2763 &bus
->sd_mode
, sizeof(s32
),
2764 false) != BCME_OK
) {
2766 DHD_ERROR(("%s: fail on %s get\n", __func__
,
2769 DHD_INFO(("%s: noted %s update, value now %d\n",
2770 __func__
, name
, bus
->sd_mode
));
2773 /* Similar check for blocksize change */
2774 if (set
&& strcmp(name
, "sd_blocksize") == 0) {
2777 (bus
->sdh
, "sd_blocksize", &fnum
, sizeof(s32
),
2778 &bus
->blocksize
, sizeof(s32
),
2779 false) != BCME_OK
) {
2781 DHD_ERROR(("%s: fail on %s get\n", __func__
,
2784 DHD_INFO(("%s: noted %s update, value now %d\n",
2785 __func__
, "sd_blocksize",
2789 bus
->roundup
= min(max_roundup
, bus
->blocksize
);
2791 if ((bus
->idletime
== DHD_IDLE_IMMEDIATE
) && !bus
->dpc_sched
) {
2792 bus
->activity
= false;
2793 dhdsdio_clkctl(bus
, CLK_NONE
, true);
2796 dhd_os_sdunlock(bus
->dhd
);
2800 DHD_CTL(("%s: %s %s, len %d plen %d\n", __func__
,
2801 name
, (set
? "set" : "get"), len
, plen
));
2803 /* set up 'params' pointer in case this is a set command so that
2804 * the convenience int and bool code can be common to set and get
2806 if (params
== NULL
) {
2811 if (vi
->type
== IOVT_VOID
)
2813 else if (vi
->type
== IOVT_BUFFER
)
2816 /* all other types are integer sized */
2817 val_size
= sizeof(int);
2819 actionid
= set
? IOV_SVAL(vi
->varid
) : IOV_GVAL(vi
->varid
);
2821 dhdsdio_doiovar(bus
, vi
, actionid
, name
, params
, plen
, arg
, len
,
2828 void dhd_bus_stop(struct dhd_bus
*bus
, bool enforce_mutex
)
2830 struct osl_info
*osh
= bus
->dhd
->osh
;
2831 u32 local_hostintmask
;
2836 DHD_TRACE(("%s: Enter\n", __func__
));
2839 dhd_os_sdlock(bus
->dhd
);
2843 /* Enable clock for device interrupts */
2844 dhdsdio_clkctl(bus
, CLK_AVAIL
, false);
2846 /* Disable and clear interrupts at the chip level also */
2847 W_SDREG(0, &bus
->regs
->hostintmask
, retries
);
2848 local_hostintmask
= bus
->hostintmask
;
2849 bus
->hostintmask
= 0;
2851 /* Change our idea of bus state */
2852 bus
->dhd
->busstate
= DHD_BUS_DOWN
;
2854 /* Force clocks on backplane to be sure F2 interrupt propagates */
2856 bcmsdh_cfg_read(bus
->sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_CHIPCLKCSR
,
2859 bcmsdh_cfg_write(bus
->sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_CHIPCLKCSR
,
2860 (saveclk
| SBSDIO_FORCE_HT
), &err
);
2863 DHD_ERROR(("%s: Failed to force clock for F2: err %d\n",
2867 /* Turn off the bus (F2), free any pending packets */
2868 DHD_INTR(("%s: disable SDIO interrupts\n", __func__
));
2869 bcmsdh_intr_disable(bus
->sdh
);
2870 bcmsdh_cfg_write(bus
->sdh
, SDIO_FUNC_0
, SDIOD_CCCR_IOEN
,
2871 SDIO_FUNC_ENABLE_1
, NULL
);
2873 /* Clear any pending interrupts now that F2 is disabled */
2874 W_SDREG(local_hostintmask
, &bus
->regs
->intstatus
, retries
);
2876 /* Turn off the backplane clock (only) */
2877 dhdsdio_clkctl(bus
, CLK_SDONLY
, false);
2879 /* Clear the data packet queues */
2880 pktq_flush(osh
, &bus
->txq
, true);
2882 /* Clear any held glomming stuff */
2884 pkt_buf_free_skb(osh
, bus
->glomd
, false);
2887 pkt_buf_free_skb(osh
, bus
->glom
, false);
2889 bus
->glom
= bus
->glomd
= NULL
;
2891 /* Clear rx control and wake any waiters */
2893 dhd_os_ioctl_resp_wake(bus
->dhd
);
2895 /* Reset some F2 state stuff */
2896 bus
->rxskip
= false;
2897 bus
->tx_seq
= bus
->rx_seq
= 0;
2900 dhd_os_sdunlock(bus
->dhd
);
2903 int dhd_bus_init(dhd_pub_t
*dhdp
, bool enforce_mutex
)
2905 dhd_bus_t
*bus
= dhdp
->bus
;
2912 DHD_TRACE(("%s: Enter\n", __func__
));
2919 dhd_os_sdlock(bus
->dhd
);
2921 /* Make sure backplane clock is on, needed to generate F2 interrupt */
2922 dhdsdio_clkctl(bus
, CLK_AVAIL
, false);
2923 if (bus
->clkstate
!= CLK_AVAIL
)
2926 /* Force clocks on backplane to be sure F2 interrupt propagates */
2928 bcmsdh_cfg_read(bus
->sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_CHIPCLKCSR
,
2931 bcmsdh_cfg_write(bus
->sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_CHIPCLKCSR
,
2932 (saveclk
| SBSDIO_FORCE_HT
), &err
);
2935 DHD_ERROR(("%s: Failed to force clock for F2: err %d\n",
2940 /* Enable function 2 (frame transfers) */
2941 W_SDREG((SDPCM_PROT_VERSION
<< SMB_DATA_VERSION_SHIFT
),
2942 &bus
->regs
->tosbmailboxdata
, retries
);
2943 enable
= (SDIO_FUNC_ENABLE_1
| SDIO_FUNC_ENABLE_2
);
2945 bcmsdh_cfg_write(bus
->sdh
, SDIO_FUNC_0
, SDIOD_CCCR_IOEN
, enable
, NULL
);
2947 /* Give the dongle some time to do its thing and set IOR2 */
2948 dhd_timeout_start(&tmo
, DHD_WAIT_F2RDY
* 1000);
2951 while (ready
!= enable
&& !dhd_timeout_expired(&tmo
))
2953 bcmsdh_cfg_read(bus
->sdh
, SDIO_FUNC_0
, SDIOD_CCCR_IORDY
,
2956 DHD_INFO(("%s: enable 0x%02x, ready 0x%02x (waited %uus)\n",
2957 __func__
, enable
, ready
, tmo
.elapsed
));
2959 /* If F2 successfully enabled, set core and enable interrupts */
2960 if (ready
== enable
) {
2961 /* Make sure we're talking to the core. */
2962 bus
->regs
= si_setcore(bus
->sih
, PCMCIA_CORE_ID
, 0);
2964 bus
->regs
= si_setcore(bus
->sih
, SDIOD_CORE_ID
, 0);
2966 /* Set up the interrupt mask and enable interrupts */
2967 bus
->hostintmask
= HOSTINTMASK
;
2968 W_SDREG(bus
->hostintmask
, &bus
->regs
->hostintmask
, retries
);
2970 bcmsdh_cfg_write(bus
->sdh
, SDIO_FUNC_1
, SBSDIO_WATERMARK
,
2971 (u8
) watermark
, &err
);
2973 /* Set bus state according to enable result */
2974 dhdp
->busstate
= DHD_BUS_DATA
;
2976 /* bcmsdh_intr_unmask(bus->sdh); */
2978 bus
->intdis
= false;
2980 DHD_INTR(("%s: enable SDIO device interrupts\n",
2982 bcmsdh_intr_enable(bus
->sdh
);
2984 DHD_INTR(("%s: disable SDIO interrupts\n", __func__
));
2985 bcmsdh_intr_disable(bus
->sdh
);
2991 /* Disable F2 again */
2992 enable
= SDIO_FUNC_ENABLE_1
;
2993 bcmsdh_cfg_write(bus
->sdh
, SDIO_FUNC_0
, SDIOD_CCCR_IOEN
, enable
,
2997 /* Restore previous clock setting */
2998 bcmsdh_cfg_write(bus
->sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_CHIPCLKCSR
,
3001 /* If we didn't come up, turn off backplane clock */
3002 if (dhdp
->busstate
!= DHD_BUS_DATA
)
3003 dhdsdio_clkctl(bus
, CLK_NONE
, false);
3007 dhd_os_sdunlock(bus
->dhd
);
3012 static void dhdsdio_rxfail(dhd_bus_t
*bus
, bool abort
, bool rtx
)
3014 bcmsdh_info_t
*sdh
= bus
->sdh
;
3015 sdpcmd_regs_t
*regs
= bus
->regs
;
3021 DHD_ERROR(("%s: %sterminate frame%s\n", __func__
,
3022 (abort
? "abort command, " : ""),
3023 (rtx
? ", send NAK" : "")));
3026 bcmsdh_abort(sdh
, SDIO_FUNC_2
);
3028 bcmsdh_cfg_write(sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_FRAMECTRL
, SFC_RF_TERM
,
3032 /* Wait until the packet has been flushed (device/FIFO stable) */
3033 for (lastrbc
= retries
= 0xffff; retries
> 0; retries
--) {
3034 hi
= bcmsdh_cfg_read(sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_RFRAMEBCHI
,
3036 lo
= bcmsdh_cfg_read(sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_RFRAMEBCLO
,
3038 bus
->f1regdata
+= 2;
3040 if ((hi
== 0) && (lo
== 0))
3043 if ((hi
> (lastrbc
>> 8)) && (lo
> (lastrbc
& 0x00ff))) {
3044 DHD_ERROR(("%s: count growing: last 0x%04x now "
3046 __func__
, lastrbc
, ((hi
<< 8) + lo
)));
3048 lastrbc
= (hi
<< 8) + lo
;
3052 DHD_ERROR(("%s: count never zeroed: last 0x%04x\n",
3053 __func__
, lastrbc
));
3055 DHD_INFO(("%s: flush took %d iterations\n", __func__
,
3056 (0xffff - retries
)));
3061 W_SDREG(SMB_NAK
, ®s
->tosbmailbox
, retries
);
3063 if (retries
<= retry_limit
)
3067 /* Clear partial in any case */
3070 /* If we can't reach the device, signal failure */
3071 if (err
|| bcmsdh_regfail(sdh
))
3072 bus
->dhd
->busstate
= DHD_BUS_DOWN
;
3076 dhdsdio_read_control(dhd_bus_t
*bus
, u8
*hdr
, uint len
, uint doff
)
3078 bcmsdh_info_t
*sdh
= bus
->sdh
;
3083 DHD_TRACE(("%s: Enter\n", __func__
));
3085 /* Control data already received in aligned rxctl */
3086 if ((bus
->bus
== SPI_BUS
) && (!bus
->usebufpool
))
3090 /* Set rxctl for frame (w/optional alignment) */
3091 bus
->rxctl
= bus
->rxbuf
;
3093 bus
->rxctl
+= firstread
;
3094 pad
= ((unsigned long)bus
->rxctl
% DHD_SDALIGN
);
3096 bus
->rxctl
+= (DHD_SDALIGN
- pad
);
3097 bus
->rxctl
-= firstread
;
3099 ASSERT(bus
->rxctl
>= bus
->rxbuf
);
3101 /* Copy the already-read portion over */
3102 bcopy(hdr
, bus
->rxctl
, firstread
);
3103 if (len
<= firstread
)
3106 /* Copy the full data pkt in gSPI case and process ioctl. */
3107 if (bus
->bus
== SPI_BUS
) {
3108 bcopy(hdr
, bus
->rxctl
, len
);
3112 /* Raise rdlen to next SDIO block to avoid tail command */
3113 rdlen
= len
- firstread
;
3114 if (bus
->roundup
&& bus
->blocksize
&& (rdlen
> bus
->blocksize
)) {
3115 pad
= bus
->blocksize
- (rdlen
% bus
->blocksize
);
3116 if ((pad
<= bus
->roundup
) && (pad
< bus
->blocksize
) &&
3117 ((len
+ pad
) < bus
->dhd
->maxctl
))
3119 } else if (rdlen
% DHD_SDALIGN
) {
3120 rdlen
+= DHD_SDALIGN
- (rdlen
% DHD_SDALIGN
);
3123 /* Satisfy length-alignment requirements */
3124 if (forcealign
&& (rdlen
& (ALIGNMENT
- 1)))
3125 rdlen
= roundup(rdlen
, ALIGNMENT
);
3127 /* Drop if the read is too big or it exceeds our maximum */
3128 if ((rdlen
+ firstread
) > bus
->dhd
->maxctl
) {
3129 DHD_ERROR(("%s: %d-byte control read exceeds %d-byte buffer\n",
3130 __func__
, rdlen
, bus
->dhd
->maxctl
));
3131 bus
->dhd
->rx_errors
++;
3132 dhdsdio_rxfail(bus
, false, false);
3136 if ((len
- doff
) > bus
->dhd
->maxctl
) {
3137 DHD_ERROR(("%s: %d-byte ctl frame (%d-byte ctl data) exceeds "
3139 __func__
, len
, (len
- doff
), bus
->dhd
->maxctl
));
3140 bus
->dhd
->rx_errors
++;
3142 dhdsdio_rxfail(bus
, false, false);
3146 /* Read remainder of frame body into the rxctl buffer */
3148 dhd_bcmsdh_recv_buf(bus
, bcmsdh_cur_sbwad(sdh
), SDIO_FUNC_2
, F2SYNC
,
3149 (bus
->rxctl
+ firstread
), rdlen
, NULL
, NULL
,
3152 ASSERT(sdret
!= BCME_PENDING
);
3154 /* Control frame failures need retransmission */
3156 DHD_ERROR(("%s: read %d control bytes failed: %d\n",
3157 __func__
, rdlen
, sdret
));
3158 bus
->rxc_errors
++; /* dhd.rx_ctlerrs is higher level */
3159 dhdsdio_rxfail(bus
, true, true);
3166 if (DHD_BYTES_ON() && DHD_CTL_ON())
3167 prhex("RxCtrl", bus
->rxctl
, len
);
3170 /* Point to valid data and indicate its length */
3172 bus
->rxlen
= len
- doff
;
3175 /* Awake any waiters */
3176 dhd_os_ioctl_resp_wake(bus
->dhd
);
3179 static u8
dhdsdio_rxglom(dhd_bus_t
*bus
, u8 rxseq
)
3185 struct sk_buff
*pfirst
, *plast
, *pnext
, *save_pfirst
;
3186 struct osl_info
*osh
= bus
->dhd
->osh
;
3189 u8 chan
, seq
, doff
, sfdoff
;
3193 bool usechain
= bus
->use_rxchain
;
3195 /* If packets, issue read(s) and send up packet chain */
3196 /* Return sequence numbers consumed? */
3198 DHD_TRACE(("dhdsdio_rxglom: start: glomd %p glom %p\n", bus
->glomd
,
3201 /* If there's a descriptor, generate the packet chain */
3203 dhd_os_sdlock_rxq(bus
->dhd
);
3205 pfirst
= plast
= pnext
= NULL
;
3206 dlen
= (u16
) (bus
->glomd
->len
);
3207 dptr
= bus
->glomd
->data
;
3208 if (!dlen
|| (dlen
& 1)) {
3209 DHD_ERROR(("%s: bad glomd len(%d), ignore descriptor\n",
3214 for (totlen
= num
= 0; dlen
; num
++) {
3215 /* Get (and move past) next length */
3216 sublen
= ltoh16_ua(dptr
);
3217 dlen
-= sizeof(u16
);
3218 dptr
+= sizeof(u16
);
3219 if ((sublen
< SDPCM_HDRLEN
) ||
3220 ((num
== 0) && (sublen
< (2 * SDPCM_HDRLEN
)))) {
3221 DHD_ERROR(("%s: descriptor len %d bad: %d\n",
3222 __func__
, num
, sublen
));
3226 if (sublen
% DHD_SDALIGN
) {
3227 DHD_ERROR(("%s: sublen %d not multiple of %d\n",
3228 __func__
, sublen
, DHD_SDALIGN
));
3233 /* For last frame, adjust read len so total
3234 is a block multiple */
3237 (roundup(totlen
, bus
->blocksize
) - totlen
);
3238 totlen
= roundup(totlen
, bus
->blocksize
);
3241 /* Allocate/chain packet for next subframe */
3242 pnext
= pkt_buf_get_skb(osh
, sublen
+ DHD_SDALIGN
);
3243 if (pnext
== NULL
) {
3244 DHD_ERROR(("%s: pkt_buf_get_skb failed, num %d len %d\n",
3245 __func__
, num
, sublen
));
3248 ASSERT(!(pnext
->prev
));
3251 pfirst
= plast
= pnext
;
3254 plast
->next
= pnext
;
3258 /* Adhere to start alignment requirements */
3259 PKTALIGN(osh
, pnext
, sublen
, DHD_SDALIGN
);
3262 /* If all allocations succeeded, save packet chain
3265 DHD_GLOM(("%s: allocated %d-byte packet chain for %d "
3266 "subframes\n", __func__
, totlen
, num
));
3267 if (DHD_GLOM_ON() && bus
->nextlen
) {
3268 if (totlen
!= bus
->nextlen
) {
3269 DHD_GLOM(("%s: glomdesc mismatch: nextlen %d glomdesc %d " "rxseq %d\n",
3270 __func__
, bus
->nextlen
,
3275 pfirst
= pnext
= NULL
;
3278 pkt_buf_free_skb(osh
, pfirst
, false);
3283 /* Done with descriptor packet */
3284 pkt_buf_free_skb(osh
, bus
->glomd
, false);
3288 dhd_os_sdunlock_rxq(bus
->dhd
);
3291 /* Ok -- either we just generated a packet chain,
3292 or had one from before */
3294 if (DHD_GLOM_ON()) {
3295 DHD_GLOM(("%s: try superframe read, packet chain:\n",
3297 for (pnext
= bus
->glom
; pnext
; pnext
= pnext
->next
) {
3298 DHD_GLOM((" %p: %p len 0x%04x (%d)\n",
3299 pnext
, (u8
*) (pnext
->data
),
3300 pnext
->len
, pnext
->len
));
3305 dlen
= (u16
) pkttotlen(osh
, pfirst
);
3307 /* Do an SDIO read for the superframe. Configurable iovar to
3308 * read directly into the chained packet, or allocate a large
3309 * packet and and copy into the chain.
3312 errcode
= dhd_bcmsdh_recv_buf(bus
,
3314 (bus
->sdh
), SDIO_FUNC_2
,
3316 (u8
*) pfirst
->data
,
3317 dlen
, pfirst
, NULL
, NULL
);
3318 } else if (bus
->dataptr
) {
3319 errcode
= dhd_bcmsdh_recv_buf(bus
,
3321 (bus
->sdh
), SDIO_FUNC_2
,
3322 F2SYNC
, bus
->dataptr
,
3323 dlen
, NULL
, NULL
, NULL
);
3325 (u16
) pktfrombuf(osh
, pfirst
, 0, dlen
,
3327 if (sublen
!= dlen
) {
3328 DHD_ERROR(("%s: FAILED TO COPY, dlen %d sublen %d\n",
3329 __func__
, dlen
, sublen
));
3334 DHD_ERROR(("COULDN'T ALLOC %d-BYTE GLOM, FORCE FAILURE\n",
3339 ASSERT(errcode
!= BCME_PENDING
);
3341 /* On failure, kill the superframe, allow a couple retries */
3343 DHD_ERROR(("%s: glom read of %d bytes failed: %d\n",
3344 __func__
, dlen
, errcode
));
3345 bus
->dhd
->rx_errors
++;
3347 if (bus
->glomerr
++ < 3) {
3348 dhdsdio_rxfail(bus
, true, true);
3351 dhdsdio_rxfail(bus
, true, false);
3352 dhd_os_sdlock_rxq(bus
->dhd
);
3353 pkt_buf_free_skb(osh
, bus
->glom
, false);
3354 dhd_os_sdunlock_rxq(bus
->dhd
);
3361 if (DHD_GLOM_ON()) {
3362 prhex("SUPERFRAME", pfirst
->data
,
3363 min_t(int, pfirst
->len
, 48));
3367 /* Validate the superframe header */
3368 dptr
= (u8
*) (pfirst
->data
);
3369 sublen
= ltoh16_ua(dptr
);
3370 check
= ltoh16_ua(dptr
+ sizeof(u16
));
3372 chan
= SDPCM_PACKET_CHANNEL(&dptr
[SDPCM_FRAMETAG_LEN
]);
3373 seq
= SDPCM_PACKET_SEQUENCE(&dptr
[SDPCM_FRAMETAG_LEN
]);
3374 bus
->nextlen
= dptr
[SDPCM_FRAMETAG_LEN
+ SDPCM_NEXTLEN_OFFSET
];
3375 if ((bus
->nextlen
<< 4) > MAX_RX_DATASZ
) {
3376 DHD_INFO(("%s: nextlen too large (%d) seq %d\n",
3377 __func__
, bus
->nextlen
, seq
));
3380 doff
= SDPCM_DOFFSET_VALUE(&dptr
[SDPCM_FRAMETAG_LEN
]);
3381 txmax
= SDPCM_WINDOW_VALUE(&dptr
[SDPCM_FRAMETAG_LEN
]);
3384 if ((u16
)~(sublen
^ check
)) {
3385 DHD_ERROR(("%s (superframe): HW hdr error: len/check "
3386 "0x%04x/0x%04x\n", __func__
, sublen
, check
));
3388 } else if (roundup(sublen
, bus
->blocksize
) != dlen
) {
3389 DHD_ERROR(("%s (superframe): len 0x%04x, rounded "
3390 "0x%04x, expect 0x%04x\n",
3392 roundup(sublen
, bus
->blocksize
), dlen
));
3394 } else if (SDPCM_PACKET_CHANNEL(&dptr
[SDPCM_FRAMETAG_LEN
]) !=
3395 SDPCM_GLOM_CHANNEL
) {
3396 DHD_ERROR(("%s (superframe): bad channel %d\n",
3398 SDPCM_PACKET_CHANNEL(&dptr
3399 [SDPCM_FRAMETAG_LEN
])));
3401 } else if (SDPCM_GLOMDESC(&dptr
[SDPCM_FRAMETAG_LEN
])) {
3402 DHD_ERROR(("%s (superframe): got second descriptor?\n",
3405 } else if ((doff
< SDPCM_HDRLEN
) ||
3406 (doff
> (pfirst
->len
- SDPCM_HDRLEN
))) {
3407 DHD_ERROR(("%s (superframe): Bad data offset %d: HW %d "
3409 __func__
, doff
, sublen
,
3410 pfirst
->len
, SDPCM_HDRLEN
));
3414 /* Check sequence number of superframe SW header */
3416 DHD_INFO(("%s: (superframe) rx_seq %d, expected %d\n",
3417 __func__
, seq
, rxseq
));
3422 /* Check window for sanity */
3423 if ((u8
) (txmax
- bus
->tx_seq
) > 0x40) {
3424 DHD_ERROR(("%s: unlikely tx max %d with tx_seq %d\n",
3425 __func__
, txmax
, bus
->tx_seq
));
3426 txmax
= bus
->tx_seq
+ 2;
3428 bus
->tx_max
= txmax
;
3430 /* Remove superframe header, remember offset */
3431 skb_pull(pfirst
, doff
);
3434 /* Validate all the subframe headers */
3435 for (num
= 0, pnext
= pfirst
; pnext
&& !errcode
;
3436 num
++, pnext
= pnext
->next
) {
3437 dptr
= (u8
*) (pnext
->data
);
3438 dlen
= (u16
) (pnext
->len
);
3439 sublen
= ltoh16_ua(dptr
);
3440 check
= ltoh16_ua(dptr
+ sizeof(u16
));
3441 chan
= SDPCM_PACKET_CHANNEL(&dptr
[SDPCM_FRAMETAG_LEN
]);
3442 doff
= SDPCM_DOFFSET_VALUE(&dptr
[SDPCM_FRAMETAG_LEN
]);
3445 prhex("subframe", dptr
, 32);
3448 if ((u16
)~(sublen
^ check
)) {
3449 DHD_ERROR(("%s (subframe %d): HW hdr error: "
3450 "len/check 0x%04x/0x%04x\n",
3451 __func__
, num
, sublen
, check
));
3453 } else if ((sublen
> dlen
) || (sublen
< SDPCM_HDRLEN
)) {
3454 DHD_ERROR(("%s (subframe %d): length mismatch: "
3455 "len 0x%04x, expect 0x%04x\n",
3456 __func__
, num
, sublen
, dlen
));
3458 } else if ((chan
!= SDPCM_DATA_CHANNEL
) &&
3459 (chan
!= SDPCM_EVENT_CHANNEL
)) {
3460 DHD_ERROR(("%s (subframe %d): bad channel %d\n",
3461 __func__
, num
, chan
));
3463 } else if ((doff
< SDPCM_HDRLEN
) || (doff
> sublen
)) {
3464 DHD_ERROR(("%s (subframe %d): Bad data offset %d: HW %d min %d\n",
3465 __func__
, num
, doff
, sublen
,
3472 /* Terminate frame on error, request
3474 if (bus
->glomerr
++ < 3) {
3475 /* Restore superframe header space */
3476 skb_push(pfirst
, sfdoff
);
3477 dhdsdio_rxfail(bus
, true, true);
3480 dhdsdio_rxfail(bus
, true, false);
3481 dhd_os_sdlock_rxq(bus
->dhd
);
3482 pkt_buf_free_skb(osh
, bus
->glom
, false);
3483 dhd_os_sdunlock_rxq(bus
->dhd
);
3491 /* Basic SD framing looks ok - process each packet (header) */
3492 save_pfirst
= pfirst
;
3496 dhd_os_sdlock_rxq(bus
->dhd
);
3497 for (num
= 0; pfirst
; rxseq
++, pfirst
= pnext
) {
3498 pnext
= pfirst
->next
;
3499 pfirst
->next
= NULL
;
3501 dptr
= (u8
*) (pfirst
->data
);
3502 sublen
= ltoh16_ua(dptr
);
3503 chan
= SDPCM_PACKET_CHANNEL(&dptr
[SDPCM_FRAMETAG_LEN
]);
3504 seq
= SDPCM_PACKET_SEQUENCE(&dptr
[SDPCM_FRAMETAG_LEN
]);
3505 doff
= SDPCM_DOFFSET_VALUE(&dptr
[SDPCM_FRAMETAG_LEN
]);
3507 DHD_GLOM(("%s: Get subframe %d, %p(%p/%d), sublen %d "
3509 __func__
, num
, pfirst
, pfirst
->data
,
3510 pfirst
->len
, sublen
, chan
, seq
));
3512 ASSERT((chan
== SDPCM_DATA_CHANNEL
)
3513 || (chan
== SDPCM_EVENT_CHANNEL
));
3516 DHD_GLOM(("%s: rx_seq %d, expected %d\n",
3517 __func__
, seq
, rxseq
));
3522 if (DHD_BYTES_ON() && DHD_DATA_ON())
3523 prhex("Rx Subframe Data", dptr
, dlen
);
3526 __skb_trim(pfirst
, sublen
);
3527 skb_pull(pfirst
, doff
);
3529 if (pfirst
->len
== 0) {
3530 pkt_buf_free_skb(bus
->dhd
->osh
, pfirst
, false);
3532 plast
->next
= pnext
;
3534 ASSERT(save_pfirst
== pfirst
);
3535 save_pfirst
= pnext
;
3538 } else if (dhd_prot_hdrpull(bus
->dhd
, &ifidx
, pfirst
) !=
3540 DHD_ERROR(("%s: rx protocol error\n",
3542 bus
->dhd
->rx_errors
++;
3543 pkt_buf_free_skb(osh
, pfirst
, false);
3545 plast
->next
= pnext
;
3547 ASSERT(save_pfirst
== pfirst
);
3548 save_pfirst
= pnext
;
3553 /* this packet will go up, link back into
3554 chain and count it */
3555 pfirst
->next
= pnext
;
3560 if (DHD_GLOM_ON()) {
3561 DHD_GLOM(("%s subframe %d to stack, %p(%p/%d) "
3563 __func__
, num
, pfirst
, pfirst
->data
,
3564 pfirst
->len
, pfirst
->next
,
3566 prhex("", (u8
*) pfirst
->data
,
3567 min_t(int, pfirst
->len
, 32));
3569 #endif /* DHD_DEBUG */
3571 dhd_os_sdunlock_rxq(bus
->dhd
);
3573 dhd_os_sdunlock(bus
->dhd
);
3574 dhd_rx_frame(bus
->dhd
, ifidx
, save_pfirst
, num
);
3575 dhd_os_sdlock(bus
->dhd
);
3578 bus
->rxglomframes
++;
3579 bus
->rxglompkts
+= num
;
3584 /* Return true if there may be more frames to read */
3585 static uint
dhdsdio_readframes(dhd_bus_t
*bus
, uint maxframes
, bool *finished
)
3587 struct osl_info
*osh
= bus
->dhd
->osh
;
3588 bcmsdh_info_t
*sdh
= bus
->sdh
;
3590 u16 len
, check
; /* Extracted hardware header fields */
3591 u8 chan
, seq
, doff
; /* Extracted software header fields */
3592 u8 fcbits
; /* Extracted fcbits from software header */
3595 struct sk_buff
*pkt
; /* Packet for event or data frames */
3596 u16 pad
; /* Number of pad bytes to read */
3597 u16 rdlen
; /* Total number of bytes to read */
3598 u8 rxseq
; /* Next sequence number to expect */
3599 uint rxleft
= 0; /* Remaining number of frames allowed */
3600 int sdret
; /* Return code from bcmsdh calls */
3601 u8 txmax
; /* Maximum tx sequence offered */
3602 bool len_consistent
; /* Result of comparing readahead len and
3606 uint rxcount
= 0; /* Total frames read */
3608 #if defined(DHD_DEBUG) || defined(SDTEST)
3609 bool sdtest
= false; /* To limit message spew from test mode */
3612 DHD_TRACE(("%s: Enter\n", __func__
));
3617 /* Allow pktgen to override maxframes */
3618 if (bus
->pktgen_count
&& (bus
->pktgen_mode
== DHD_PKTGEN_RECV
)) {
3619 maxframes
= bus
->pktgen_count
;
3624 /* Not finished unless we encounter no more frames indication */
3627 for (rxseq
= bus
->rx_seq
, rxleft
= maxframes
;
3628 !bus
->rxskip
&& rxleft
&& bus
->dhd
->busstate
!= DHD_BUS_DOWN
;
3629 rxseq
++, rxleft
--) {
3631 /* Handle glomming separately */
3632 if (bus
->glom
|| bus
->glomd
) {
3634 DHD_GLOM(("%s: calling rxglom: glomd %p, glom %p\n",
3635 __func__
, bus
->glomd
, bus
->glom
));
3636 cnt
= dhdsdio_rxglom(bus
, rxseq
);
3637 DHD_GLOM(("%s: rxglom returned %d\n", __func__
, cnt
));
3639 rxleft
= (rxleft
> cnt
) ? (rxleft
- cnt
) : 1;
3643 /* Try doing single read if we can */
3644 if (dhd_readahead
&& bus
->nextlen
) {
3645 u16 nextlen
= bus
->nextlen
;
3648 if (bus
->bus
== SPI_BUS
) {
3649 rdlen
= len
= nextlen
;
3651 rdlen
= len
= nextlen
<< 4;
3653 /* Pad read to blocksize for efficiency */
3654 if (bus
->roundup
&& bus
->blocksize
3655 && (rdlen
> bus
->blocksize
)) {
3658 (rdlen
% bus
->blocksize
);
3659 if ((pad
<= bus
->roundup
)
3660 && (pad
< bus
->blocksize
)
3661 && ((rdlen
+ pad
+ firstread
) <
3664 } else if (rdlen
% DHD_SDALIGN
) {
3666 DHD_SDALIGN
- (rdlen
% DHD_SDALIGN
);
3670 /* We use bus->rxctl buffer in WinXP for initial
3671 * control pkt receives.
3672 * Later we use buffer-poll for data as well
3673 * as control packets.
3674 * This is required becuase dhd receives full
3675 * frame in gSPI unlike SDIO.
3676 * After the frame is received we have to
3677 * distinguish whether it is data
3678 * or non-data frame.
3680 /* Allocate a packet buffer */
3681 dhd_os_sdlock_rxq(bus
->dhd
);
3682 pkt
= pkt_buf_get_skb(osh
, rdlen
+ DHD_SDALIGN
);
3684 if (bus
->bus
== SPI_BUS
) {
3685 bus
->usebufpool
= false;
3686 bus
->rxctl
= bus
->rxbuf
;
3688 bus
->rxctl
+= firstread
;
3689 pad
= ((unsigned long)bus
->rxctl
%
3693 (DHD_SDALIGN
- pad
);
3694 bus
->rxctl
-= firstread
;
3696 ASSERT(bus
->rxctl
>= bus
->rxbuf
);
3698 /* Read the entire frame */
3699 sdret
= dhd_bcmsdh_recv_buf(bus
,
3708 ASSERT(sdret
!= BCME_PENDING
);
3710 /* Control frame failures need
3713 DHD_ERROR(("%s: read %d control bytes failed: %d\n",
3716 /* dhd.rx_ctlerrs is higher */
3718 dhd_os_sdunlock_rxq(bus
->dhd
);
3719 dhdsdio_rxfail(bus
, true,
3727 request rtx of events */
3728 DHD_ERROR(("%s (nextlen): pkt_buf_get_skb failed: len %d rdlen %d " "expected rxseq %d\n",
3729 __func__
, len
, rdlen
, rxseq
));
3730 /* Just go try again w/normal
3732 dhd_os_sdunlock_rxq(bus
->dhd
);
3736 if (bus
->bus
== SPI_BUS
)
3737 bus
->usebufpool
= true;
3739 ASSERT(!(pkt
->prev
));
3740 PKTALIGN(osh
, pkt
, rdlen
, DHD_SDALIGN
);
3741 rxbuf
= (u8
*) (pkt
->data
);
3742 /* Read the entire frame */
3744 dhd_bcmsdh_recv_buf(bus
,
3745 bcmsdh_cur_sbwad(sdh
),
3746 SDIO_FUNC_2
, F2SYNC
,
3747 rxbuf
, rdlen
, pkt
, NULL
,
3750 ASSERT(sdret
!= BCME_PENDING
);
3753 DHD_ERROR(("%s (nextlen): read %d bytes failed: %d\n",
3754 __func__
, rdlen
, sdret
));
3755 pkt_buf_free_skb(bus
->dhd
->osh
, pkt
, false);
3756 bus
->dhd
->rx_errors
++;
3757 dhd_os_sdunlock_rxq(bus
->dhd
);
3758 /* Force retry w/normal header read.
3759 * Don't attemp NAK for
3762 dhdsdio_rxfail(bus
, true,
3769 dhd_os_sdunlock_rxq(bus
->dhd
);
3771 /* Now check the header */
3772 bcopy(rxbuf
, bus
->rxhdr
, SDPCM_HDRLEN
);
3774 /* Extract hardware header fields */
3775 len
= ltoh16_ua(bus
->rxhdr
);
3776 check
= ltoh16_ua(bus
->rxhdr
+ sizeof(u16
));
3778 /* All zeros means readahead info was bad */
3779 if (!(len
| check
)) {
3780 DHD_INFO(("%s (nextlen): read zeros in HW "
3781 "header???\n", __func__
));
3782 dhd_os_sdlock_rxq(bus
->dhd
);
3784 dhd_os_sdunlock_rxq(bus
->dhd
);
3785 GSPI_PR55150_BAILOUT
;
3789 /* Validate check bytes */
3790 if ((u16
)~(len
^ check
)) {
3791 DHD_ERROR(("%s (nextlen): HW hdr error: nextlen/len/check" " 0x%04x/0x%04x/0x%04x\n",
3792 __func__
, nextlen
, len
, check
));
3793 dhd_os_sdlock_rxq(bus
->dhd
);
3795 dhd_os_sdunlock_rxq(bus
->dhd
);
3797 dhdsdio_rxfail(bus
, false, false);
3798 GSPI_PR55150_BAILOUT
;
3802 /* Validate frame length */
3803 if (len
< SDPCM_HDRLEN
) {
3804 DHD_ERROR(("%s (nextlen): HW hdr length "
3805 "invalid: %d\n", __func__
, len
));
3806 dhd_os_sdlock_rxq(bus
->dhd
);
3808 dhd_os_sdunlock_rxq(bus
->dhd
);
3809 GSPI_PR55150_BAILOUT
;
3813 /* Check for consistency withreadahead info */
3814 len_consistent
= (nextlen
!= (roundup(len
, 16) >> 4));
3815 if (len_consistent
) {
3816 /* Mismatch, force retry w/normal
3817 header (may be >4K) */
3818 DHD_ERROR(("%s (nextlen): mismatch, nextlen %d len %d rnd %d; " "expected rxseq %d\n",
3820 len
, roundup(len
, 16), rxseq
));
3821 dhd_os_sdlock_rxq(bus
->dhd
);
3823 dhd_os_sdunlock_rxq(bus
->dhd
);
3824 dhdsdio_rxfail(bus
, true,
3826 SPI_BUS
) ? false : true);
3827 GSPI_PR55150_BAILOUT
;
3831 /* Extract software header fields */
3833 SDPCM_PACKET_CHANNEL(&bus
->rxhdr
3834 [SDPCM_FRAMETAG_LEN
]);
3836 SDPCM_PACKET_SEQUENCE(&bus
->rxhdr
3837 [SDPCM_FRAMETAG_LEN
]);
3839 SDPCM_DOFFSET_VALUE(&bus
->rxhdr
3840 [SDPCM_FRAMETAG_LEN
]);
3842 SDPCM_WINDOW_VALUE(&bus
->rxhdr
[SDPCM_FRAMETAG_LEN
]);
3845 bus
->rxhdr
[SDPCM_FRAMETAG_LEN
+
3846 SDPCM_NEXTLEN_OFFSET
];
3847 if ((bus
->nextlen
<< 4) > MAX_RX_DATASZ
) {
3848 DHD_INFO(("%s (nextlen): got frame w/nextlen too large" " (%d), seq %d\n",
3849 __func__
, bus
->nextlen
, seq
));
3853 bus
->dhd
->rx_readahead_cnt
++;
3854 /* Handle Flow Control */
3856 SDPCM_FCMASK_VALUE(&bus
->rxhdr
[SDPCM_FRAMETAG_LEN
]);
3859 if (~bus
->flowcontrol
& fcbits
) {
3863 if (bus
->flowcontrol
& ~fcbits
) {
3870 bus
->flowcontrol
= fcbits
;
3873 /* Check and update sequence number */
3875 DHD_INFO(("%s (nextlen): rx_seq %d, expected "
3876 "%d\n", __func__
, seq
, rxseq
));
3881 /* Check window for sanity */
3882 if ((u8
) (txmax
- bus
->tx_seq
) > 0x40) {
3883 DHD_ERROR(("%s: got unlikely tx max %d with "
3885 __func__
, txmax
, bus
->tx_seq
));
3886 txmax
= bus
->tx_seq
+ 2;
3888 bus
->tx_max
= txmax
;
3891 if (DHD_BYTES_ON() && DHD_DATA_ON())
3892 prhex("Rx Data", rxbuf
, len
);
3893 else if (DHD_HDRS_ON())
3894 prhex("RxHdr", bus
->rxhdr
, SDPCM_HDRLEN
);
3897 if (chan
== SDPCM_CONTROL_CHANNEL
) {
3898 if (bus
->bus
== SPI_BUS
) {
3899 dhdsdio_read_control(bus
, rxbuf
, len
,
3901 if (bus
->usebufpool
) {
3902 dhd_os_sdlock_rxq(bus
->dhd
);
3903 pkt_buf_free_skb(bus
->dhd
->osh
, pkt
,
3905 dhd_os_sdunlock_rxq(bus
->dhd
);
3909 DHD_ERROR(("%s (nextlen): readahead on control" " packet %d?\n",
3911 /* Force retry w/normal header read */
3913 dhdsdio_rxfail(bus
, false, true);
3914 dhd_os_sdlock_rxq(bus
->dhd
);
3916 dhd_os_sdunlock_rxq(bus
->dhd
);
3921 if ((bus
->bus
== SPI_BUS
) && !bus
->usebufpool
) {
3922 DHD_ERROR(("Received %d bytes on %d channel. Running out of " "rx pktbuf's or not yet malloced.\n",
3927 /* Validate data offset */
3928 if ((doff
< SDPCM_HDRLEN
) || (doff
> len
)) {
3929 DHD_ERROR(("%s (nextlen): bad data offset %d: HW len %d min %d\n",
3930 __func__
, doff
, len
, SDPCM_HDRLEN
));
3931 dhd_os_sdlock_rxq(bus
->dhd
);
3933 dhd_os_sdunlock_rxq(bus
->dhd
);
3935 dhdsdio_rxfail(bus
, false, false);
3939 /* All done with this one -- now deliver the packet */
3942 /* gSPI frames should not be handled in fractions */
3943 if (bus
->bus
== SPI_BUS
)
3946 /* Read frame header (hardware and software) */
3948 dhd_bcmsdh_recv_buf(bus
, bcmsdh_cur_sbwad(sdh
), SDIO_FUNC_2
,
3949 F2SYNC
, bus
->rxhdr
, firstread
, NULL
,
3952 ASSERT(sdret
!= BCME_PENDING
);
3955 DHD_ERROR(("%s: RXHEADER FAILED: %d\n", __func__
,
3958 dhdsdio_rxfail(bus
, true, true);
3962 if (DHD_BYTES_ON() || DHD_HDRS_ON())
3963 prhex("RxHdr", bus
->rxhdr
, SDPCM_HDRLEN
);
3966 /* Extract hardware header fields */
3967 len
= ltoh16_ua(bus
->rxhdr
);
3968 check
= ltoh16_ua(bus
->rxhdr
+ sizeof(u16
));
3970 /* All zeros means no more frames */
3971 if (!(len
| check
)) {
3976 /* Validate check bytes */
3977 if ((u16
) ~(len
^ check
)) {
3978 DHD_ERROR(("%s: HW hdr err: len/check 0x%04x/0x%04x\n",
3979 __func__
, len
, check
));
3981 dhdsdio_rxfail(bus
, false, false);
3985 /* Validate frame length */
3986 if (len
< SDPCM_HDRLEN
) {
3987 DHD_ERROR(("%s: HW hdr length invalid: %d\n",
3992 /* Extract software header fields */
3993 chan
= SDPCM_PACKET_CHANNEL(&bus
->rxhdr
[SDPCM_FRAMETAG_LEN
]);
3994 seq
= SDPCM_PACKET_SEQUENCE(&bus
->rxhdr
[SDPCM_FRAMETAG_LEN
]);
3995 doff
= SDPCM_DOFFSET_VALUE(&bus
->rxhdr
[SDPCM_FRAMETAG_LEN
]);
3996 txmax
= SDPCM_WINDOW_VALUE(&bus
->rxhdr
[SDPCM_FRAMETAG_LEN
]);
3998 /* Validate data offset */
3999 if ((doff
< SDPCM_HDRLEN
) || (doff
> len
)) {
4000 DHD_ERROR(("%s: Bad data offset %d: HW len %d, min %d "
4002 __func__
, doff
, len
, SDPCM_HDRLEN
, seq
));
4005 dhdsdio_rxfail(bus
, false, false);
4009 /* Save the readahead length if there is one */
4011 bus
->rxhdr
[SDPCM_FRAMETAG_LEN
+ SDPCM_NEXTLEN_OFFSET
];
4012 if ((bus
->nextlen
<< 4) > MAX_RX_DATASZ
) {
4013 DHD_INFO(("%s (nextlen): got frame w/nextlen too large "
4015 __func__
, bus
->nextlen
, seq
));
4019 /* Handle Flow Control */
4020 fcbits
= SDPCM_FCMASK_VALUE(&bus
->rxhdr
[SDPCM_FRAMETAG_LEN
]);
4023 if (~bus
->flowcontrol
& fcbits
) {
4027 if (bus
->flowcontrol
& ~fcbits
) {
4034 bus
->flowcontrol
= fcbits
;
4037 /* Check and update sequence number */
4039 DHD_INFO(("%s: rx_seq %d, expected %d\n", __func__
,
4045 /* Check window for sanity */
4046 if ((u8
) (txmax
- bus
->tx_seq
) > 0x40) {
4047 DHD_ERROR(("%s: unlikely tx max %d with tx_seq %d\n",
4048 __func__
, txmax
, bus
->tx_seq
));
4049 txmax
= bus
->tx_seq
+ 2;
4051 bus
->tx_max
= txmax
;
4053 /* Call a separate function for control frames */
4054 if (chan
== SDPCM_CONTROL_CHANNEL
) {
4055 dhdsdio_read_control(bus
, bus
->rxhdr
, len
, doff
);
4059 ASSERT((chan
== SDPCM_DATA_CHANNEL
)
4060 || (chan
== SDPCM_EVENT_CHANNEL
)
4061 || (chan
== SDPCM_TEST_CHANNEL
)
4062 || (chan
== SDPCM_GLOM_CHANNEL
));
4064 /* Length to read */
4065 rdlen
= (len
> firstread
) ? (len
- firstread
) : 0;
4067 /* May pad read to blocksize for efficiency */
4068 if (bus
->roundup
&& bus
->blocksize
&&
4069 (rdlen
> bus
->blocksize
)) {
4070 pad
= bus
->blocksize
- (rdlen
% bus
->blocksize
);
4071 if ((pad
<= bus
->roundup
) && (pad
< bus
->blocksize
) &&
4072 ((rdlen
+ pad
+ firstread
) < MAX_RX_DATASZ
))
4074 } else if (rdlen
% DHD_SDALIGN
) {
4075 rdlen
+= DHD_SDALIGN
- (rdlen
% DHD_SDALIGN
);
4078 /* Satisfy length-alignment requirements */
4079 if (forcealign
&& (rdlen
& (ALIGNMENT
- 1)))
4080 rdlen
= roundup(rdlen
, ALIGNMENT
);
4082 if ((rdlen
+ firstread
) > MAX_RX_DATASZ
) {
4083 /* Too long -- skip this frame */
4084 DHD_ERROR(("%s: too long: len %d rdlen %d\n",
4085 __func__
, len
, rdlen
));
4086 bus
->dhd
->rx_errors
++;
4088 dhdsdio_rxfail(bus
, false, false);
4092 dhd_os_sdlock_rxq(bus
->dhd
);
4093 pkt
= pkt_buf_get_skb(osh
, (rdlen
+ firstread
+ DHD_SDALIGN
));
4095 /* Give up on data, request rtx of events */
4096 DHD_ERROR(("%s: pkt_buf_get_skb failed: rdlen %d chan %d\n",
4097 __func__
, rdlen
, chan
));
4098 bus
->dhd
->rx_dropped
++;
4099 dhd_os_sdunlock_rxq(bus
->dhd
);
4100 dhdsdio_rxfail(bus
, false, RETRYCHAN(chan
));
4103 dhd_os_sdunlock_rxq(bus
->dhd
);
4105 ASSERT(!(pkt
->prev
));
4107 /* Leave room for what we already read, and align remainder */
4108 ASSERT(firstread
< pkt
->len
);
4109 skb_pull(pkt
, firstread
);
4110 PKTALIGN(osh
, pkt
, rdlen
, DHD_SDALIGN
);
4112 /* Read the remaining frame data */
4114 dhd_bcmsdh_recv_buf(bus
, bcmsdh_cur_sbwad(sdh
), SDIO_FUNC_2
,
4115 F2SYNC
, ((u8
*) (pkt
->data
)), rdlen
,
4118 ASSERT(sdret
!= BCME_PENDING
);
4121 DHD_ERROR(("%s: read %d %s bytes failed: %d\n",
4124 SDPCM_EVENT_CHANNEL
) ? "event" : ((chan
==
4126 ? "data" : "test")),
4128 dhd_os_sdlock_rxq(bus
->dhd
);
4129 pkt_buf_free_skb(bus
->dhd
->osh
, pkt
, false);
4130 dhd_os_sdunlock_rxq(bus
->dhd
);
4131 bus
->dhd
->rx_errors
++;
4132 dhdsdio_rxfail(bus
, true, RETRYCHAN(chan
));
4136 /* Copy the already-read portion */
4137 skb_push(pkt
, firstread
);
4138 bcopy(bus
->rxhdr
, pkt
->data
, firstread
);
4141 if (DHD_BYTES_ON() && DHD_DATA_ON())
4142 prhex("Rx Data", pkt
->data
, len
);
4146 /* Save superframe descriptor and allocate packet frame */
4147 if (chan
== SDPCM_GLOM_CHANNEL
) {
4148 if (SDPCM_GLOMDESC(&bus
->rxhdr
[SDPCM_FRAMETAG_LEN
])) {
4149 DHD_GLOM(("%s: glom descriptor, %d bytes:\n",
4152 if (DHD_GLOM_ON()) {
4153 prhex("Glom Data", pkt
->data
, len
);
4156 __skb_trim(pkt
, len
);
4157 ASSERT(doff
== SDPCM_HDRLEN
);
4158 skb_pull(pkt
, SDPCM_HDRLEN
);
4161 DHD_ERROR(("%s: glom superframe w/o "
4162 "descriptor!\n", __func__
));
4163 dhdsdio_rxfail(bus
, false, false);
4168 /* Fill in packet len and prio, deliver upward */
4169 __skb_trim(pkt
, len
);
4170 skb_pull(pkt
, doff
);
4173 /* Test channel packets are processed separately */
4174 if (chan
== SDPCM_TEST_CHANNEL
) {
4175 dhdsdio_testrcv(bus
, pkt
, seq
);
4180 if (pkt
->len
== 0) {
4181 dhd_os_sdlock_rxq(bus
->dhd
);
4182 pkt_buf_free_skb(bus
->dhd
->osh
, pkt
, false);
4183 dhd_os_sdunlock_rxq(bus
->dhd
);
4185 } else if (dhd_prot_hdrpull(bus
->dhd
, &ifidx
, pkt
) != 0) {
4186 DHD_ERROR(("%s: rx protocol error\n", __func__
));
4187 dhd_os_sdlock_rxq(bus
->dhd
);
4188 pkt_buf_free_skb(bus
->dhd
->osh
, pkt
, false);
4189 dhd_os_sdunlock_rxq(bus
->dhd
);
4190 bus
->dhd
->rx_errors
++;
4194 /* Unlock during rx call */
4195 dhd_os_sdunlock(bus
->dhd
);
4196 dhd_rx_frame(bus
->dhd
, ifidx
, pkt
, 1);
4197 dhd_os_sdlock(bus
->dhd
);
4199 rxcount
= maxframes
- rxleft
;
4201 /* Message if we hit the limit */
4202 if (!rxleft
&& !sdtest
)
4203 DHD_DATA(("%s: hit rx limit of %d frames\n", __func__
,
4206 #endif /* DHD_DEBUG */
4207 DHD_DATA(("%s: processed %d frames\n", __func__
, rxcount
));
4208 /* Back off rxseq if awaiting rtx, update rx_seq */
4211 bus
->rx_seq
= rxseq
;
4216 static u32
dhdsdio_hostmail(dhd_bus_t
*bus
)
4218 sdpcmd_regs_t
*regs
= bus
->regs
;
4224 DHD_TRACE(("%s: Enter\n", __func__
));
4226 /* Read mailbox data and ack that we did so */
4227 R_SDREG(hmb_data
, ®s
->tohostmailboxdata
, retries
);
4228 if (retries
<= retry_limit
)
4229 W_SDREG(SMB_INT_ACK
, ®s
->tosbmailbox
, retries
);
4230 bus
->f1regdata
+= 2;
4232 /* Dongle recomposed rx frames, accept them again */
4233 if (hmb_data
& HMB_DATA_NAKHANDLED
) {
4234 DHD_INFO(("Dongle reports NAK handled, expect rtx of %d\n",
4237 DHD_ERROR(("%s: unexpected NAKHANDLED!\n", __func__
));
4239 bus
->rxskip
= false;
4240 intstatus
|= I_HMB_FRAME_IND
;
4244 * DEVREADY does not occur with gSPI.
4246 if (hmb_data
& (HMB_DATA_DEVREADY
| HMB_DATA_FWREADY
)) {
4248 (hmb_data
& HMB_DATA_VERSION_MASK
) >>
4249 HMB_DATA_VERSION_SHIFT
;
4250 if (bus
->sdpcm_ver
!= SDPCM_PROT_VERSION
)
4251 DHD_ERROR(("Version mismatch, dongle reports %d, "
4253 bus
->sdpcm_ver
, SDPCM_PROT_VERSION
));
4255 DHD_INFO(("Dongle ready, protocol version %d\n",
4260 * Flow Control has been moved into the RX headers and this out of band
4261 * method isn't used any more. Leae this here for possibly
4262 * remaining backward
4263 * compatible with older dongles
4265 if (hmb_data
& HMB_DATA_FC
) {
4267 (hmb_data
& HMB_DATA_FCDATA_MASK
) >> HMB_DATA_FCDATA_SHIFT
;
4269 if (fcbits
& ~bus
->flowcontrol
)
4271 if (bus
->flowcontrol
& ~fcbits
)
4275 bus
->flowcontrol
= fcbits
;
4278 /* Shouldn't be any others */
4279 if (hmb_data
& ~(HMB_DATA_DEVREADY
|
4280 HMB_DATA_NAKHANDLED
|
4283 HMB_DATA_FCDATA_MASK
| HMB_DATA_VERSION_MASK
)) {
4284 DHD_ERROR(("Unknown mailbox data content: 0x%02x\n", hmb_data
));
4290 bool dhdsdio_dpc(dhd_bus_t
*bus
)
4292 bcmsdh_info_t
*sdh
= bus
->sdh
;
4293 sdpcmd_regs_t
*regs
= bus
->regs
;
4294 u32 intstatus
, newstatus
= 0;
4296 uint rxlimit
= dhd_rxbound
; /* Rx frames to read before resched */
4297 uint txlimit
= dhd_txbound
; /* Tx frames to send before resched */
4298 uint framecnt
= 0; /* Temporary counter of tx/rx frames */
4299 bool rxdone
= true; /* Flag for no more read data */
4300 bool resched
= false; /* Flag indicating resched wanted */
4302 DHD_TRACE(("%s: Enter\n", __func__
));
4304 /* Start with leftover status bits */
4305 intstatus
= bus
->intstatus
;
4307 dhd_os_sdlock(bus
->dhd
);
4309 /* If waiting for HTAVAIL, check status */
4310 if (bus
->clkstate
== CLK_PENDING
) {
4312 u8 clkctl
, devctl
= 0;
4315 /* Check for inconsistent device control */
4317 bcmsdh_cfg_read(sdh
, SDIO_FUNC_1
, SBSDIO_DEVICE_CTL
, &err
);
4319 DHD_ERROR(("%s: error reading DEVCTL: %d\n",
4321 bus
->dhd
->busstate
= DHD_BUS_DOWN
;
4323 ASSERT(devctl
& SBSDIO_DEVCTL_CA_INT_ONLY
);
4325 #endif /* DHD_DEBUG */
4327 /* Read CSR, if clock on switch to AVAIL, else ignore */
4329 bcmsdh_cfg_read(sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_CHIPCLKCSR
,
4332 DHD_ERROR(("%s: error reading CSR: %d\n", __func__
,
4334 bus
->dhd
->busstate
= DHD_BUS_DOWN
;
4337 DHD_INFO(("DPC: PENDING, devctl 0x%02x clkctl 0x%02x\n", devctl
,
4340 if (SBSDIO_HTAV(clkctl
)) {
4342 bcmsdh_cfg_read(sdh
, SDIO_FUNC_1
, SBSDIO_DEVICE_CTL
,
4345 DHD_ERROR(("%s: error reading DEVCTL: %d\n",
4347 bus
->dhd
->busstate
= DHD_BUS_DOWN
;
4349 devctl
&= ~SBSDIO_DEVCTL_CA_INT_ONLY
;
4350 bcmsdh_cfg_write(sdh
, SDIO_FUNC_1
, SBSDIO_DEVICE_CTL
,
4353 DHD_ERROR(("%s: error writing DEVCTL: %d\n",
4355 bus
->dhd
->busstate
= DHD_BUS_DOWN
;
4357 bus
->clkstate
= CLK_AVAIL
;
4365 /* Make sure backplane clock is on */
4366 dhdsdio_clkctl(bus
, CLK_AVAIL
, true);
4367 if (bus
->clkstate
== CLK_PENDING
)
4370 /* Pending interrupt indicates new device status */
4373 R_SDREG(newstatus
, ®s
->intstatus
, retries
);
4375 if (bcmsdh_regfail(bus
->sdh
))
4377 newstatus
&= bus
->hostintmask
;
4378 bus
->fcstate
= !!(newstatus
& I_HMB_FC_STATE
);
4380 W_SDREG(newstatus
, ®s
->intstatus
, retries
);
4385 /* Merge new bits with previous */
4386 intstatus
|= newstatus
;
4389 /* Handle flow-control change: read new state in case our ack
4390 * crossed another change interrupt. If change still set, assume
4391 * FC ON for safety, let next loop through do the debounce.
4393 if (intstatus
& I_HMB_FC_CHANGE
) {
4394 intstatus
&= ~I_HMB_FC_CHANGE
;
4395 W_SDREG(I_HMB_FC_CHANGE
, ®s
->intstatus
, retries
);
4396 R_SDREG(newstatus
, ®s
->intstatus
, retries
);
4397 bus
->f1regdata
+= 2;
4399 !!(newstatus
& (I_HMB_FC_STATE
| I_HMB_FC_CHANGE
));
4400 intstatus
|= (newstatus
& bus
->hostintmask
);
4403 /* Handle host mailbox indication */
4404 if (intstatus
& I_HMB_HOST_INT
) {
4405 intstatus
&= ~I_HMB_HOST_INT
;
4406 intstatus
|= dhdsdio_hostmail(bus
);
4409 /* Generally don't ask for these, can get CRC errors... */
4410 if (intstatus
& I_WR_OOSYNC
) {
4411 DHD_ERROR(("Dongle reports WR_OOSYNC\n"));
4412 intstatus
&= ~I_WR_OOSYNC
;
4415 if (intstatus
& I_RD_OOSYNC
) {
4416 DHD_ERROR(("Dongle reports RD_OOSYNC\n"));
4417 intstatus
&= ~I_RD_OOSYNC
;
4420 if (intstatus
& I_SBINT
) {
4421 DHD_ERROR(("Dongle reports SBINT\n"));
4422 intstatus
&= ~I_SBINT
;
4425 /* Would be active due to wake-wlan in gSPI */
4426 if (intstatus
& I_CHIPACTIVE
) {
4427 DHD_INFO(("Dongle reports CHIPACTIVE\n"));
4428 intstatus
&= ~I_CHIPACTIVE
;
4431 /* Ignore frame indications if rxskip is set */
4433 intstatus
&= ~I_HMB_FRAME_IND
;
4435 /* On frame indication, read available frames */
4436 if (PKT_AVAILABLE()) {
4437 framecnt
= dhdsdio_readframes(bus
, rxlimit
, &rxdone
);
4438 if (rxdone
|| bus
->rxskip
)
4439 intstatus
&= ~I_HMB_FRAME_IND
;
4440 rxlimit
-= min(framecnt
, rxlimit
);
4443 /* Keep still-pending events for next scheduling */
4444 bus
->intstatus
= intstatus
;
4447 #if defined(OOB_INTR_ONLY)
4448 bcmsdh_oob_intr_set(1);
4449 #endif /* (OOB_INTR_ONLY) */
4450 /* Re-enable interrupts to detect new device events (mailbox, rx frame)
4451 * or clock availability. (Allows tx loop to check ipend if desired.)
4452 * (Unless register access seems hosed, as we may not be able to ACK...)
4454 if (bus
->intr
&& bus
->intdis
&& !bcmsdh_regfail(sdh
)) {
4455 DHD_INTR(("%s: enable SDIO interrupts, rxdone %d framecnt %d\n",
4456 __func__
, rxdone
, framecnt
));
4457 bus
->intdis
= false;
4458 bcmsdh_intr_enable(sdh
);
4461 if (DATAOK(bus
) && bus
->ctrl_frame_stat
&&
4462 (bus
->clkstate
== CLK_AVAIL
)) {
4466 dhd_bcmsdh_send_buf(bus
, bcmsdh_cur_sbwad(sdh
), SDIO_FUNC_2
,
4467 F2SYNC
, (u8
*) bus
->ctrl_frame_buf
,
4468 (u32
) bus
->ctrl_frame_len
, NULL
,
4470 ASSERT(ret
!= BCME_PENDING
);
4473 /* On failure, abort the command and
4474 terminate the frame */
4475 DHD_INFO(("%s: sdio error %d, abort command and "
4476 "terminate frame.\n", __func__
, ret
));
4479 bcmsdh_abort(sdh
, SDIO_FUNC_2
);
4481 bcmsdh_cfg_write(sdh
, SDIO_FUNC_1
,
4482 SBSDIO_FUNC1_FRAMECTRL
, SFC_WF_TERM
,
4486 for (i
= 0; i
< 3; i
++) {
4488 hi
= bcmsdh_cfg_read(sdh
, SDIO_FUNC_1
,
4489 SBSDIO_FUNC1_WFRAMEBCHI
,
4491 lo
= bcmsdh_cfg_read(sdh
, SDIO_FUNC_1
,
4492 SBSDIO_FUNC1_WFRAMEBCLO
,
4494 bus
->f1regdata
+= 2;
4495 if ((hi
== 0) && (lo
== 0))
4501 bus
->tx_seq
= (bus
->tx_seq
+ 1) % SDPCM_SEQUENCE_WRAP
;
4503 DHD_INFO(("Return_dpc value is : %d\n", ret
));
4504 bus
->ctrl_frame_stat
= false;
4505 dhd_wait_event_wakeup(bus
->dhd
);
4507 /* Send queued frames (limit 1 if rx may still be pending) */
4508 else if ((bus
->clkstate
== CLK_AVAIL
) && !bus
->fcstate
&&
4509 pktq_mlen(&bus
->txq
, ~bus
->flowcontrol
) && txlimit
4511 framecnt
= rxdone
? txlimit
: min(txlimit
, dhd_txminmax
);
4512 framecnt
= dhdsdio_sendfromq(bus
, framecnt
);
4513 txlimit
-= framecnt
;
4516 /* Resched if events or tx frames are pending,
4517 else await next interrupt */
4518 /* On failed register access, all bets are off:
4519 no resched or interrupts */
4520 if ((bus
->dhd
->busstate
== DHD_BUS_DOWN
) || bcmsdh_regfail(sdh
)) {
4521 DHD_ERROR(("%s: failed backplane access over SDIO, halting "
4522 "operation %d\n", __func__
, bcmsdh_regfail(sdh
)));
4523 bus
->dhd
->busstate
= DHD_BUS_DOWN
;
4525 } else if (bus
->clkstate
== CLK_PENDING
) {
4526 DHD_INFO(("%s: rescheduled due to CLK_PENDING awaiting "
4527 "I_CHIPACTIVE interrupt\n", __func__
));
4529 } else if (bus
->intstatus
|| bus
->ipend
||
4530 (!bus
->fcstate
&& pktq_mlen(&bus
->txq
, ~bus
->flowcontrol
) &&
4531 DATAOK(bus
)) || PKT_AVAILABLE()) {
4535 bus
->dpc_sched
= resched
;
4537 /* If we're done for now, turn off clock request. */
4538 if ((bus
->clkstate
!= CLK_PENDING
)
4539 && bus
->idletime
== DHD_IDLE_IMMEDIATE
) {
4540 bus
->activity
= false;
4541 dhdsdio_clkctl(bus
, CLK_NONE
, false);
4544 dhd_os_sdunlock(bus
->dhd
);
4549 bool dhd_bus_dpc(struct dhd_bus
*bus
)
4553 /* Call the DPC directly. */
4554 DHD_TRACE(("Calling dhdsdio_dpc() from %s\n", __func__
));
4555 resched
= dhdsdio_dpc(bus
);
4560 void dhdsdio_isr(void *arg
)
4562 dhd_bus_t
*bus
= (dhd_bus_t
*) arg
;
4565 DHD_TRACE(("%s: Enter\n", __func__
));
4568 DHD_ERROR(("%s : bus is null pointer , exit\n", __func__
));
4573 if (bus
->dhd
->busstate
== DHD_BUS_DOWN
) {
4574 DHD_ERROR(("%s : bus is down. we have nothing to do\n",
4578 /* Count the interrupt call */
4582 /* Shouldn't get this interrupt if we're sleeping? */
4583 if (bus
->sleeping
) {
4584 DHD_ERROR(("INTERRUPT WHILE SLEEPING??\n"));
4588 /* Disable additional interrupts (is this needed now)? */
4590 DHD_INTR(("%s: disable SDIO interrupts\n", __func__
));
4592 DHD_ERROR(("dhdsdio_isr() w/o interrupt configured!\n"));
4594 bcmsdh_intr_disable(sdh
);
4597 #if defined(SDIO_ISR_THREAD)
4598 DHD_TRACE(("Calling dhdsdio_dpc() from %s\n", __func__
));
4599 while (dhdsdio_dpc(bus
))
4602 bus
->dpc_sched
= true;
4603 dhd_sched_dpc(bus
->dhd
);
4609 static void dhdsdio_pktgen_init(dhd_bus_t
*bus
)
4611 /* Default to specified length, or full range */
4612 if (dhd_pktgen_len
) {
4613 bus
->pktgen_maxlen
= min(dhd_pktgen_len
, MAX_PKTGEN_LEN
);
4614 bus
->pktgen_minlen
= bus
->pktgen_maxlen
;
4616 bus
->pktgen_maxlen
= MAX_PKTGEN_LEN
;
4617 bus
->pktgen_minlen
= 0;
4619 bus
->pktgen_len
= (u16
) bus
->pktgen_minlen
;
4621 /* Default to per-watchdog burst with 10s print time */
4622 bus
->pktgen_freq
= 1;
4623 bus
->pktgen_print
= 10000 / dhd_watchdog_ms
;
4624 bus
->pktgen_count
= (dhd_pktgen
* dhd_watchdog_ms
+ 999) / 1000;
4626 /* Default to echo mode */
4627 bus
->pktgen_mode
= DHD_PKTGEN_ECHO
;
4628 bus
->pktgen_stop
= 1;
4631 static void dhdsdio_pktgen(dhd_bus_t
*bus
)
4633 struct sk_buff
*pkt
;
4637 struct osl_info
*osh
= bus
->dhd
->osh
;
4640 /* Display current count if appropriate */
4641 if (bus
->pktgen_print
&& (++bus
->pktgen_ptick
>= bus
->pktgen_print
)) {
4642 bus
->pktgen_ptick
= 0;
4643 printk(KERN_DEBUG
"%s: send attempts %d rcvd %d\n",
4644 __func__
, bus
->pktgen_sent
, bus
->pktgen_rcvd
);
4647 /* For recv mode, just make sure dongle has started sending */
4648 if (bus
->pktgen_mode
== DHD_PKTGEN_RECV
) {
4649 if (!bus
->pktgen_rcvd
)
4650 dhdsdio_sdtest_set(bus
, true);
4654 /* Otherwise, generate or request the specified number of packets */
4655 for (pktcount
= 0; pktcount
< bus
->pktgen_count
; pktcount
++) {
4656 /* Stop if total has been reached */
4657 if (bus
->pktgen_total
4658 && (bus
->pktgen_sent
>= bus
->pktgen_total
)) {
4659 bus
->pktgen_count
= 0;
4663 /* Allocate an appropriate-sized packet */
4664 len
= bus
->pktgen_len
;
4665 pkt
= pkt_buf_get_skb(osh
,
4666 (len
+ SDPCM_HDRLEN
+ SDPCM_TEST_HDRLEN
+ DHD_SDALIGN
),
4669 DHD_ERROR(("%s: pkt_buf_get_skb failed!\n", __func__
));
4672 PKTALIGN(osh
, pkt
, (len
+ SDPCM_HDRLEN
+ SDPCM_TEST_HDRLEN
),
4674 data
= (u8
*) (pkt
->data
) + SDPCM_HDRLEN
;
4676 /* Write test header cmd and extra based on mode */
4677 switch (bus
->pktgen_mode
) {
4678 case DHD_PKTGEN_ECHO
:
4679 *data
++ = SDPCM_TEST_ECHOREQ
;
4680 *data
++ = (u8
) bus
->pktgen_sent
;
4683 case DHD_PKTGEN_SEND
:
4684 *data
++ = SDPCM_TEST_DISCARD
;
4685 *data
++ = (u8
) bus
->pktgen_sent
;
4688 case DHD_PKTGEN_RXBURST
:
4689 *data
++ = SDPCM_TEST_BURST
;
4690 *data
++ = (u8
) bus
->pktgen_count
;
4694 DHD_ERROR(("Unrecognized pktgen mode %d\n",
4696 pkt_buf_free_skb(osh
, pkt
, true);
4697 bus
->pktgen_count
= 0;
4701 /* Write test header length field */
4702 *data
++ = (len
>> 0);
4703 *data
++ = (len
>> 8);
4705 /* Then fill in the remainder -- N/A for burst,
4707 for (fillbyte
= 0; fillbyte
< len
; fillbyte
++)
4709 SDPCM_TEST_FILL(fillbyte
, (u8
) bus
->pktgen_sent
);
4712 if (DHD_BYTES_ON() && DHD_DATA_ON()) {
4713 data
= (u8
*) (pkt
->data
) + SDPCM_HDRLEN
;
4714 prhex("dhdsdio_pktgen: Tx Data", data
,
4715 pkt
->len
- SDPCM_HDRLEN
);
4720 if (dhdsdio_txpkt(bus
, pkt
, SDPCM_TEST_CHANNEL
, true)) {
4722 if (bus
->pktgen_stop
4723 && bus
->pktgen_stop
== bus
->pktgen_fail
)
4724 bus
->pktgen_count
= 0;
4728 /* Bump length if not fixed, wrap at max */
4729 if (++bus
->pktgen_len
> bus
->pktgen_maxlen
)
4730 bus
->pktgen_len
= (u16
) bus
->pktgen_minlen
;
4732 /* Special case for burst mode: just send one request! */
4733 if (bus
->pktgen_mode
== DHD_PKTGEN_RXBURST
)
4738 static void dhdsdio_sdtest_set(dhd_bus_t
*bus
, bool start
)
4740 struct sk_buff
*pkt
;
4742 struct osl_info
*osh
= bus
->dhd
->osh
;
4744 /* Allocate the packet */
4745 pkt
= pkt_buf_get_skb(osh
, SDPCM_HDRLEN
+ SDPCM_TEST_HDRLEN
+ DHD_SDALIGN
,
4748 DHD_ERROR(("%s: pkt_buf_get_skb failed!\n", __func__
));
4751 PKTALIGN(osh
, pkt
, (SDPCM_HDRLEN
+ SDPCM_TEST_HDRLEN
), DHD_SDALIGN
);
4752 data
= (u8
*) (pkt
->data
) + SDPCM_HDRLEN
;
4754 /* Fill in the test header */
4755 *data
++ = SDPCM_TEST_SEND
;
4757 *data
++ = (bus
->pktgen_maxlen
>> 0);
4758 *data
++ = (bus
->pktgen_maxlen
>> 8);
4761 if (dhdsdio_txpkt(bus
, pkt
, SDPCM_TEST_CHANNEL
, true))
4765 static void dhdsdio_testrcv(dhd_bus_t
*bus
, struct sk_buff
*pkt
, uint seq
)
4767 struct osl_info
*osh
= bus
->dhd
->osh
;
4776 /* Check for min length */
4778 if (pktlen
< SDPCM_TEST_HDRLEN
) {
4779 DHD_ERROR(("dhdsdio_restrcv: toss runt frame, pktlen %d\n",
4781 pkt_buf_free_skb(osh
, pkt
, false);
4785 /* Extract header fields */
4790 len
+= *data
++ << 8;
4792 /* Check length for relevant commands */
4793 if (cmd
== SDPCM_TEST_DISCARD
|| cmd
== SDPCM_TEST_ECHOREQ
4794 || cmd
== SDPCM_TEST_ECHORSP
) {
4795 if (pktlen
!= len
+ SDPCM_TEST_HDRLEN
) {
4796 DHD_ERROR(("dhdsdio_testrcv: frame length mismatch, "
4797 "pktlen %d seq %d" " cmd %d extra %d len %d\n",
4798 pktlen
, seq
, cmd
, extra
, len
));
4799 pkt_buf_free_skb(osh
, pkt
, false);
4804 /* Process as per command */
4806 case SDPCM_TEST_ECHOREQ
:
4807 /* Rx->Tx turnaround ok (even on NDIS w/current
4809 *(u8
*) (pkt
->data
) = SDPCM_TEST_ECHORSP
;
4810 if (dhdsdio_txpkt(bus
, pkt
, SDPCM_TEST_CHANNEL
, true) == 0) {
4814 pkt_buf_free_skb(osh
, pkt
, false);
4819 case SDPCM_TEST_ECHORSP
:
4820 if (bus
->ext_loop
) {
4821 pkt_buf_free_skb(osh
, pkt
, false);
4826 for (offset
= 0; offset
< len
; offset
++, data
++) {
4827 if (*data
!= SDPCM_TEST_FILL(offset
, extra
)) {
4828 DHD_ERROR(("dhdsdio_testrcv: echo data mismatch: " "offset %d (len %d) expect 0x%02x rcvd 0x%02x\n",
4830 SDPCM_TEST_FILL(offset
, extra
), *data
));
4834 pkt_buf_free_skb(osh
, pkt
, false);
4838 case SDPCM_TEST_DISCARD
:
4839 pkt_buf_free_skb(osh
, pkt
, false);
4843 case SDPCM_TEST_BURST
:
4844 case SDPCM_TEST_SEND
:
4846 DHD_INFO(("dhdsdio_testrcv: unsupported or unknown command, "
4847 "pktlen %d seq %d" " cmd %d extra %d len %d\n",
4848 pktlen
, seq
, cmd
, extra
, len
));
4849 pkt_buf_free_skb(osh
, pkt
, false);
4853 /* For recv mode, stop at limie (and tell dongle to stop sending) */
4854 if (bus
->pktgen_mode
== DHD_PKTGEN_RECV
) {
4855 if (bus
->pktgen_total
4856 && (bus
->pktgen_rcvd
>= bus
->pktgen_total
)) {
4857 bus
->pktgen_count
= 0;
4858 dhdsdio_sdtest_set(bus
, false);
4864 extern bool dhd_bus_watchdog(dhd_pub_t
*dhdp
)
4868 DHD_TIMER(("%s: Enter\n", __func__
));
4872 if (bus
->dhd
->dongle_reset
)
4875 /* Ignore the timer if simulating bus down */
4879 dhd_os_sdlock(bus
->dhd
);
4881 /* Poll period: check device if appropriate. */
4882 if (bus
->poll
&& (++bus
->polltick
>= bus
->pollrate
)) {
4885 /* Reset poll tick */
4888 /* Check device if no interrupts */
4889 if (!bus
->intr
|| (bus
->intrcount
== bus
->lastintrs
)) {
4891 if (!bus
->dpc_sched
) {
4893 devpend
= bcmsdh_cfg_read(bus
->sdh
, SDIO_FUNC_0
,
4897 devpend
& (INTR_STATUS_FUNC1
|
4901 /* If there is something, make like the ISR and
4907 bcmsdh_intr_disable(bus
->sdh
);
4909 bus
->dpc_sched
= true;
4910 dhd_sched_dpc(bus
->dhd
);
4915 /* Update interrupt tracking */
4916 bus
->lastintrs
= bus
->intrcount
;
4919 /* Poll for console output periodically */
4920 if (dhdp
->busstate
== DHD_BUS_DATA
&& dhd_console_ms
!= 0) {
4921 bus
->console
.count
+= dhd_watchdog_ms
;
4922 if (bus
->console
.count
>= dhd_console_ms
) {
4923 bus
->console
.count
-= dhd_console_ms
;
4924 /* Make sure backplane clock is on */
4925 dhdsdio_clkctl(bus
, CLK_AVAIL
, false);
4926 if (dhdsdio_readconsole(bus
) < 0)
4927 dhd_console_ms
= 0; /* On error,
4931 #endif /* DHD_DEBUG */
4934 /* Generate packets if configured */
4935 if (bus
->pktgen_count
&& (++bus
->pktgen_tick
>= bus
->pktgen_freq
)) {
4936 /* Make sure backplane clock is on */
4937 dhdsdio_clkctl(bus
, CLK_AVAIL
, false);
4938 bus
->pktgen_tick
= 0;
4939 dhdsdio_pktgen(bus
);
4943 /* On idle timeout clear activity flag and/or turn off clock */
4944 if ((bus
->idletime
> 0) && (bus
->clkstate
== CLK_AVAIL
)) {
4945 if (++bus
->idlecount
>= bus
->idletime
) {
4947 if (bus
->activity
) {
4948 bus
->activity
= false;
4949 dhd_os_wd_timer(bus
->dhd
, dhd_watchdog_ms
);
4951 dhdsdio_clkctl(bus
, CLK_NONE
, false);
4956 dhd_os_sdunlock(bus
->dhd
);
4962 extern int dhd_bus_console_in(dhd_pub_t
*dhdp
, unsigned char *msg
, uint msglen
)
4964 dhd_bus_t
*bus
= dhdp
->bus
;
4967 struct sk_buff
*pkt
;
4969 /* Address could be zero if CONSOLE := 0 in dongle Makefile */
4970 if (bus
->console_addr
== 0)
4971 return BCME_UNSUPPORTED
;
4973 /* Exclusive bus access */
4974 dhd_os_sdlock(bus
->dhd
);
4976 /* Don't allow input if dongle is in reset */
4977 if (bus
->dhd
->dongle_reset
) {
4978 dhd_os_sdunlock(bus
->dhd
);
4979 return BCME_NOTREADY
;
4982 /* Request clock to allow SDIO accesses */
4984 /* No pend allowed since txpkt is called later, ht clk has to be on */
4985 dhdsdio_clkctl(bus
, CLK_AVAIL
, false);
4987 /* Zero cbuf_index */
4988 addr
= bus
->console_addr
+ offsetof(hndrte_cons_t
, cbuf_idx
);
4990 rv
= dhdsdio_membytes(bus
, true, addr
, (u8
*)&val
, sizeof(val
));
4994 /* Write message into cbuf */
4995 addr
= bus
->console_addr
+ offsetof(hndrte_cons_t
, cbuf
);
4996 rv
= dhdsdio_membytes(bus
, true, addr
, (u8
*)msg
, msglen
);
5000 /* Write length into vcons_in */
5001 addr
= bus
->console_addr
+ offsetof(hndrte_cons_t
, vcons_in
);
5002 val
= htol32(msglen
);
5003 rv
= dhdsdio_membytes(bus
, true, addr
, (u8
*)&val
, sizeof(val
));
5007 /* Bump dongle by sending an empty event pkt.
5008 * sdpcm_sendup (RX) checks for virtual console input.
5010 pkt
= pkt_buf_get_skb(bus
->dhd
->osh
, 4 + SDPCM_RESERVE
);
5011 if ((pkt
!= NULL
) && bus
->clkstate
== CLK_AVAIL
)
5012 dhdsdio_txpkt(bus
, pkt
, SDPCM_EVENT_CHANNEL
, true);
5015 if ((bus
->idletime
== DHD_IDLE_IMMEDIATE
) && !bus
->dpc_sched
) {
5016 bus
->activity
= false;
5017 dhdsdio_clkctl(bus
, CLK_NONE
, true);
5020 dhd_os_sdunlock(bus
->dhd
);
5024 #endif /* DHD_DEBUG */
5027 static void dhd_dump_cis(uint fn
, u8
*cis
)
5029 uint byte
, tag
, tdata
;
5030 DHD_INFO(("Function %d CIS:\n", fn
));
5032 for (tdata
= byte
= 0; byte
< SBSDIO_CIS_SIZE_LIMIT
; byte
++) {
5033 if ((byte
% 16) == 0)
5035 DHD_INFO(("%02x ", cis
[byte
]));
5036 if ((byte
% 16) == 15)
5044 else if ((byte
+ 1) < SBSDIO_CIS_SIZE_LIMIT
)
5045 tdata
= cis
[byte
+ 1] + 1;
5050 if ((byte
% 16) != 15)
5053 #endif /* DHD_DEBUG */
5055 static bool dhdsdio_chipmatch(u16 chipid
)
5057 if (chipid
== BCM4325_CHIP_ID
)
5059 if (chipid
== BCM4329_CHIP_ID
)
5061 if (chipid
== BCM4319_CHIP_ID
)
5066 static void *dhdsdio_probe(u16 venid
, u16 devid
, u16 bus_no
,
5067 u16 slot
, u16 func
, uint bustype
, void *regsva
,
5068 struct osl_info
*osh
, void *sdh
)
5073 /* Init global variables at run-time, not as part of the declaration.
5074 * This is required to support init/de-init of the driver.
5076 * of globals as part of the declaration results in non-deterministic
5077 * behavior since the value of the globals may be different on the
5078 * first time that the driver is initialized vs subsequent
5081 dhd_txbound
= DHD_TXBOUND
;
5082 dhd_rxbound
= DHD_RXBOUND
;
5083 dhd_alignctl
= true;
5085 dhd_readahead
= true;
5088 dhd_dongle_memsize
= 0;
5089 dhd_txminmax
= DHD_TXMINMAX
;
5095 DHD_TRACE(("%s: Enter\n", __func__
));
5096 DHD_INFO(("%s: venid 0x%04x devid 0x%04x\n", __func__
, venid
, devid
));
5098 /* We make assumptions about address window mappings */
5099 ASSERT((unsigned long)regsva
== SI_ENUM_BASE
);
5101 /* BCMSDH passes venid and devid based on CIS parsing -- but
5103 * means early parse could fail, so here we should get either an ID
5104 * we recognize OR (-1) indicating we must request power first.
5106 /* Check the Vendor ID */
5109 case VENDOR_BROADCOM
:
5112 DHD_ERROR(("%s: unknown vendor: 0x%04x\n", __func__
, venid
));
5116 /* Check the Device ID and make sure it's one that we support */
5118 case BCM4325_D11DUAL_ID
: /* 4325 802.11a/g id */
5119 case BCM4325_D11G_ID
: /* 4325 802.11g 2.4Ghz band id */
5120 case BCM4325_D11A_ID
: /* 4325 802.11a 5Ghz band id */
5121 DHD_INFO(("%s: found 4325 Dongle\n", __func__
));
5123 case BCM4329_D11NDUAL_ID
: /* 4329 802.11n dualband device */
5124 case BCM4329_D11N2G_ID
: /* 4329 802.11n 2.4G device */
5125 case BCM4329_D11N5G_ID
: /* 4329 802.11n 5G device */
5127 DHD_INFO(("%s: found 4329 Dongle\n", __func__
));
5129 case BCM4319_D11N_ID
: /* 4319 802.11n id */
5130 case BCM4319_D11N2G_ID
: /* 4319 802.11n2g id */
5131 case BCM4319_D11N5G_ID
: /* 4319 802.11n5g id */
5132 DHD_INFO(("%s: found 4319 Dongle\n", __func__
));
5135 DHD_INFO(("%s: allow device id 0, will check chip internals\n",
5140 DHD_ERROR(("%s: skipping 0x%04x/0x%04x, not a dongle\n",
5141 __func__
, venid
, devid
));
5146 /* Ask the OS interface part for an OSL handle */
5147 osh
= dhd_osl_attach(sdh
, DHD_BUS
);
5149 DHD_ERROR(("%s: osl_attach failed!\n", __func__
));
5154 /* Allocate private bus interface state */
5155 bus
= kzalloc(sizeof(dhd_bus_t
), GFP_ATOMIC
);
5157 DHD_ERROR(("%s: kmalloc of dhd_bus_t failed\n", __func__
));
5161 bus
->cl_devid
= (u16
) devid
;
5163 bus
->tx_seq
= SDPCM_SEQUENCE_WRAP
- 1;
5164 bus
->usebufpool
= false; /* Use bufpool if allocated,
5165 else use locally malloced rxbuf */
5167 /* attempt to attach to the dongle */
5168 if (!(dhdsdio_probe_attach(bus
, osh
, sdh
, regsva
, devid
))) {
5169 DHD_ERROR(("%s: dhdsdio_probe_attach failed\n", __func__
));
5173 /* Attach to the dhd/OS/network interface */
5174 bus
->dhd
= dhd_attach(osh
, bus
, SDPCM_RESERVE
);
5176 DHD_ERROR(("%s: dhd_attach failed\n", __func__
));
5180 /* Allocate buffers */
5181 if (!(dhdsdio_probe_malloc(bus
, osh
, sdh
))) {
5182 DHD_ERROR(("%s: dhdsdio_probe_malloc failed\n", __func__
));
5186 if (!(dhdsdio_probe_init(bus
, osh
, sdh
))) {
5187 DHD_ERROR(("%s: dhdsdio_probe_init failed\n", __func__
));
5191 /* Register interrupt callback, but mask it (not operational yet). */
5192 DHD_INTR(("%s: disable SDIO interrupts (not interested yet)\n",
5194 bcmsdh_intr_disable(sdh
);
5195 ret
= bcmsdh_intr_reg(sdh
, dhdsdio_isr
, bus
);
5197 DHD_ERROR(("%s: FAILED: bcmsdh_intr_reg returned %d\n",
5201 DHD_INTR(("%s: registered SDIO interrupt function ok\n", __func__
));
5203 DHD_INFO(("%s: completed!!\n", __func__
));
5205 /* if firmware path present try to download and bring up bus */
5206 ret
= dhd_bus_start(bus
->dhd
);
5208 if (ret
== BCME_NOTUP
) {
5209 DHD_ERROR(("%s: dongle is not responding\n", __func__
));
5213 /* Ok, have the per-port tell the stack we're open for business */
5214 if (dhd_net_attach(bus
->dhd
, 0) != 0) {
5215 DHD_ERROR(("%s: Net attach failed!!\n", __func__
));
5222 dhdsdio_release(bus
, osh
);
5227 dhdsdio_probe_attach(struct dhd_bus
*bus
, struct osl_info
*osh
, void *sdh
,
5228 void *regsva
, u16 devid
)
5233 bus
->alp_only
= true;
5235 /* Return the window to backplane enumeration space for core access */
5236 if (dhdsdio_set_siaddr_window(bus
, SI_ENUM_BASE
))
5237 DHD_ERROR(("%s: FAILED to return to SI_ENUM_BASE\n", __func__
));
5240 printk(KERN_DEBUG
"F1 signature read @0x18000000=0x%4x\n",
5241 bcmsdh_reg_read(bus
->sdh
, SI_ENUM_BASE
, 4));
5243 #endif /* DHD_DEBUG */
5245 /* Force PLL off until si_attach() programs PLL control regs */
5247 bcmsdh_cfg_write(sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_CHIPCLKCSR
,
5248 DHD_INIT_CLKCTL1
, &err
);
5251 bcmsdh_cfg_read(sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_CHIPCLKCSR
,
5254 if (err
|| ((clkctl
& ~SBSDIO_AVBITS
) != DHD_INIT_CLKCTL1
)) {
5255 DHD_ERROR(("dhdsdio_probe: ChipClkCSR access: err %d wrote "
5256 "0x%02x read 0x%02x\n",
5257 err
, DHD_INIT_CLKCTL1
, clkctl
));
5261 if (DHD_INFO_ON()) {
5263 u8
*cis
[SDIOD_MAX_IOFUNCS
];
5266 numfn
= bcmsdh_query_iofnum(sdh
);
5267 ASSERT(numfn
<= SDIOD_MAX_IOFUNCS
);
5269 /* Make sure ALP is available before trying to read CIS */
5270 SPINWAIT(((clkctl
= bcmsdh_cfg_read(sdh
, SDIO_FUNC_1
,
5271 SBSDIO_FUNC1_CHIPCLKCSR
,
5273 !SBSDIO_ALPAV(clkctl
)), PMU_MAX_TRANSITION_DLY
);
5275 /* Now request ALP be put on the bus */
5276 bcmsdh_cfg_write(sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_CHIPCLKCSR
,
5277 DHD_INIT_CLKCTL2
, &err
);
5280 for (fn
= 0; fn
<= numfn
; fn
++) {
5281 cis
[fn
] = kmalloc(SBSDIO_CIS_SIZE_LIMIT
, GFP_ATOMIC
);
5283 DHD_INFO(("dhdsdio_probe: fn %d cis malloc "
5287 memset(cis
[fn
], 0, SBSDIO_CIS_SIZE_LIMIT
);
5289 err
= bcmsdh_cis_read(sdh
, fn
, cis
[fn
],
5290 SBSDIO_CIS_SIZE_LIMIT
);
5292 DHD_INFO(("dhdsdio_probe: fn %d cis read "
5293 "err %d\n", fn
, err
));
5297 dhd_dump_cis(fn
, cis
[fn
]);
5306 DHD_ERROR(("dhdsdio_probe: error read/parsing CIS\n"));
5310 #endif /* DHD_DEBUG */
5312 /* si_attach() will provide an SI handle and scan the backplane */
5313 bus
->sih
= si_attach((uint
) devid
, osh
, regsva
, DHD_BUS
, sdh
,
5314 &bus
->vars
, &bus
->varsz
);
5316 DHD_ERROR(("%s: si_attach failed!\n", __func__
));
5320 bcmsdh_chipinfo(sdh
, bus
->sih
->chip
, bus
->sih
->chiprev
);
5322 if (!dhdsdio_chipmatch((u16
) bus
->sih
->chip
)) {
5323 DHD_ERROR(("%s: unsupported chip: 0x%04x\n",
5324 __func__
, bus
->sih
->chip
));
5328 si_sdiod_drive_strength_init(bus
->sih
, osh
, dhd_sdiod_drive_strength
);
5330 /* Get info on the ARM and SOCRAM cores... */
5331 if (!DHD_NOPMU(bus
)) {
5332 if ((si_setcore(bus
->sih
, ARM7S_CORE_ID
, 0)) ||
5333 (si_setcore(bus
->sih
, ARMCM3_CORE_ID
, 0))) {
5334 bus
->armrev
= si_corerev(bus
->sih
);
5336 DHD_ERROR(("%s: failed to find ARM core!\n", __func__
));
5339 bus
->orig_ramsize
= si_socram_size(bus
->sih
);
5340 if (!(bus
->orig_ramsize
)) {
5341 DHD_ERROR(("%s: failed to find SOCRAM memory!\n",
5345 bus
->ramsize
= bus
->orig_ramsize
;
5346 if (dhd_dongle_memsize
)
5347 dhd_dongle_setmemsize(bus
, dhd_dongle_memsize
);
5349 DHD_ERROR(("DHD: dongle ram size is set to %d(orig %d)\n",
5350 bus
->ramsize
, bus
->orig_ramsize
));
5353 /* ...but normally deal with the SDPCMDEV core */
5354 bus
->regs
= si_setcore(bus
->sih
, PCMCIA_CORE_ID
, 0);
5356 bus
->regs
= si_setcore(bus
->sih
, SDIOD_CORE_ID
, 0);
5358 DHD_ERROR(("%s: failed to find SDIODEV core!\n",
5363 bus
->sdpcmrev
= si_corerev(bus
->sih
);
5365 /* Set core control so an SDIO reset does a backplane reset */
5366 OR_REG(osh
, &bus
->regs
->corecontrol
, CC_BPRESEN
);
5368 pktq_init(&bus
->txq
, (PRIOMASK
+ 1), QLEN
);
5370 /* Locate an appropriately-aligned portion of hdrbuf */
5371 bus
->rxhdr
= (u8
*) roundup((unsigned long)&bus
->hdrbuf
[0], DHD_SDALIGN
);
5373 /* Set the poll and/or interrupt flags */
5374 bus
->intr
= (bool) dhd_intr
;
5375 bus
->poll
= (bool) dhd_poll
;
5385 static bool dhdsdio_probe_malloc(dhd_bus_t
*bus
, struct osl_info
*osh
,
5388 DHD_TRACE(("%s: Enter\n", __func__
));
5390 if (bus
->dhd
->maxctl
) {
5392 roundup((bus
->dhd
->maxctl
+ SDPCM_HDRLEN
),
5393 ALIGNMENT
) + DHD_SDALIGN
;
5394 bus
->rxbuf
= kmalloc(bus
->rxblen
, GFP_ATOMIC
);
5395 if (!(bus
->rxbuf
)) {
5396 DHD_ERROR(("%s: kmalloc of %d-byte rxbuf failed\n",
5397 __func__
, bus
->rxblen
));
5402 /* Allocate buffer to receive glomed packet */
5403 bus
->databuf
= kmalloc(MAX_DATA_BUF
, GFP_ATOMIC
);
5404 if (!(bus
->databuf
)) {
5405 DHD_ERROR(("%s: kmalloc of %d-byte databuf failed\n",
5406 __func__
, MAX_DATA_BUF
));
5407 /* release rxbuf which was already located as above */
5413 /* Align the buffer */
5414 if ((unsigned long)bus
->databuf
% DHD_SDALIGN
)
5416 bus
->databuf
+ (DHD_SDALIGN
-
5417 ((unsigned long)bus
->databuf
% DHD_SDALIGN
));
5419 bus
->dataptr
= bus
->databuf
;
5427 static bool dhdsdio_probe_init(dhd_bus_t
*bus
, struct osl_info
*osh
, void *sdh
)
5431 DHD_TRACE(("%s: Enter\n", __func__
));
5434 dhdsdio_pktgen_init(bus
);
5437 /* Disable F2 to clear any intermediate frame state on the dongle */
5438 bcmsdh_cfg_write(sdh
, SDIO_FUNC_0
, SDIOD_CCCR_IOEN
, SDIO_FUNC_ENABLE_1
,
5441 bus
->dhd
->busstate
= DHD_BUS_DOWN
;
5442 bus
->sleeping
= false;
5443 bus
->rxflow
= false;
5444 bus
->prev_rxlim_hit
= 0;
5446 /* Done with backplane-dependent accesses, can drop clock... */
5447 bcmsdh_cfg_write(sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_CHIPCLKCSR
, 0, NULL
);
5449 /* ...and initialize clock/power states */
5450 bus
->clkstate
= CLK_SDONLY
;
5451 bus
->idletime
= (s32
) dhd_idletime
;
5452 bus
->idleclock
= DHD_IDLE_ACTIVE
;
5454 /* Query the SD clock speed */
5455 if (bcmsdh_iovar_op(sdh
, "sd_divisor", NULL
, 0,
5456 &bus
->sd_divisor
, sizeof(s32
),
5457 false) != BCME_OK
) {
5458 DHD_ERROR(("%s: fail on %s get\n", __func__
, "sd_divisor"));
5459 bus
->sd_divisor
= -1;
5461 DHD_INFO(("%s: Initial value for %s is %d\n",
5462 __func__
, "sd_divisor", bus
->sd_divisor
));
5465 /* Query the SD bus mode */
5466 if (bcmsdh_iovar_op(sdh
, "sd_mode", NULL
, 0,
5467 &bus
->sd_mode
, sizeof(s32
), false) != BCME_OK
) {
5468 DHD_ERROR(("%s: fail on %s get\n", __func__
, "sd_mode"));
5471 DHD_INFO(("%s: Initial value for %s is %d\n",
5472 __func__
, "sd_mode", bus
->sd_mode
));
5475 /* Query the F2 block size, set roundup accordingly */
5477 if (bcmsdh_iovar_op(sdh
, "sd_blocksize", &fnum
, sizeof(s32
),
5478 &bus
->blocksize
, sizeof(s32
), false) != BCME_OK
) {
5480 DHD_ERROR(("%s: fail on %s get\n", __func__
, "sd_blocksize"));
5482 DHD_INFO(("%s: Initial value for %s is %d\n",
5483 __func__
, "sd_blocksize", bus
->blocksize
));
5485 bus
->roundup
= min(max_roundup
, bus
->blocksize
);
5487 /* Query if bus module supports packet chaining,
5488 default to use if supported */
5489 if (bcmsdh_iovar_op(sdh
, "sd_rxchain", NULL
, 0,
5490 &bus
->sd_rxchain
, sizeof(s32
),
5491 false) != BCME_OK
) {
5492 bus
->sd_rxchain
= false;
5494 DHD_INFO(("%s: bus module (through bcmsdh API) %s chaining\n",
5496 (bus
->sd_rxchain
? "supports" : "does not support")));
5498 bus
->use_rxchain
= (bool) bus
->sd_rxchain
;
5504 dhd_bus_download_firmware(struct dhd_bus
*bus
, struct osl_info
*osh
,
5505 char *fw_path
, char *nv_path
)
5508 bus
->fw_path
= fw_path
;
5509 bus
->nv_path
= nv_path
;
5511 ret
= dhdsdio_download_firmware(bus
, osh
, bus
->sdh
);
5517 dhdsdio_download_firmware(struct dhd_bus
*bus
, struct osl_info
*osh
, void *sdh
)
5521 /* Download the firmware */
5522 dhdsdio_clkctl(bus
, CLK_AVAIL
, false);
5524 ret
= _dhdsdio_download_firmware(bus
) == 0;
5526 dhdsdio_clkctl(bus
, CLK_SDONLY
, false);
5531 /* Detach and free everything */
5532 static void dhdsdio_release(dhd_bus_t
*bus
, struct osl_info
*osh
)
5534 DHD_TRACE(("%s: Enter\n", __func__
));
5539 /* De-register interrupt handler */
5540 bcmsdh_intr_disable(bus
->sdh
);
5541 bcmsdh_intr_dereg(bus
->sdh
);
5545 dhdsdio_release_dongle(bus
, osh
);
5547 dhd_detach(bus
->dhd
);
5551 dhdsdio_release_malloc(bus
, osh
);
5557 dhd_osl_detach(osh
);
5559 DHD_TRACE(("%s: Disconnected\n", __func__
));
5562 static void dhdsdio_release_malloc(dhd_bus_t
*bus
, struct osl_info
*osh
)
5564 DHD_TRACE(("%s: Enter\n", __func__
));
5566 if (bus
->dhd
&& bus
->dhd
->dongle_reset
)
5571 bus
->rxctl
= bus
->rxbuf
= NULL
;
5576 kfree(bus
->databuf
);
5577 bus
->databuf
= NULL
;
5581 static void dhdsdio_release_dongle(dhd_bus_t
*bus
, struct osl_info
*osh
)
5583 DHD_TRACE(("%s: Enter\n", __func__
));
5585 if (bus
->dhd
&& bus
->dhd
->dongle_reset
)
5589 dhdsdio_clkctl(bus
, CLK_AVAIL
, false);
5590 #if !defined(BCMLXSDMMC)
5591 si_watchdog(bus
->sih
, 4);
5592 #endif /* !defined(BCMLXSDMMC) */
5593 dhdsdio_clkctl(bus
, CLK_NONE
, false);
5594 si_detach(bus
->sih
);
5595 if (bus
->vars
&& bus
->varsz
)
5600 DHD_TRACE(("%s: Disconnected\n", __func__
));
5603 static void dhdsdio_disconnect(void *ptr
)
5605 dhd_bus_t
*bus
= (dhd_bus_t
*)ptr
;
5607 DHD_TRACE(("%s: Enter\n", __func__
));
5611 dhdsdio_release(bus
, bus
->dhd
->osh
);
5614 DHD_TRACE(("%s: Disconnected\n", __func__
));
5617 /* Register/Unregister functions are called by the main DHD entry
5618 * point (e.g. module insertion) to link with the bus driver, in
5619 * order to look for or await the device.
5622 static bcmsdh_driver_t dhd_sdio
= {
5627 int dhd_bus_register(void)
5629 DHD_TRACE(("%s: Enter\n", __func__
));
5631 return bcmsdh_register(&dhd_sdio
);
5634 void dhd_bus_unregister(void)
5636 DHD_TRACE(("%s: Enter\n", __func__
));
5638 bcmsdh_unregister();
5641 #ifdef BCMEMBEDIMAGE
5642 static int dhdsdio_download_code_array(struct dhd_bus
*bus
)
5647 DHD_INFO(("%s: download embedded firmware...\n", __func__
));
5649 /* Download image */
5650 while ((offset
+ MEMBLOCK
) < sizeof(dlarray
)) {
5652 dhdsdio_membytes(bus
, true, offset
, dlarray
+ offset
,
5655 DHD_ERROR(("%s: error %d on writing %d membytes at "
5657 __func__
, bcmerror
, MEMBLOCK
, offset
));
5664 if (offset
< sizeof(dlarray
)) {
5665 bcmerror
= dhdsdio_membytes(bus
, true, offset
,
5667 sizeof(dlarray
) - offset
);
5669 DHD_ERROR(("%s: error %d on writing %d membytes at "
5670 "0x%08x\n", __func__
, bcmerror
,
5671 sizeof(dlarray
) - offset
, offset
));
5676 /* Upload and compare the downloaded code */
5678 unsigned char *ularray
;
5680 ularray
= kmalloc(bus
->ramsize
, GFP_ATOMIC
);
5681 /* Upload image to verify downloaded contents. */
5683 memset(ularray
, 0xaa, bus
->ramsize
);
5684 while ((offset
+ MEMBLOCK
) < sizeof(dlarray
)) {
5686 dhdsdio_membytes(bus
, false, offset
,
5687 ularray
+ offset
, MEMBLOCK
);
5689 DHD_ERROR(("%s: error %d on reading %d membytes"
5691 __func__
, bcmerror
, MEMBLOCK
, offset
));
5698 if (offset
< sizeof(dlarray
)) {
5699 bcmerror
= dhdsdio_membytes(bus
, false, offset
,
5701 sizeof(dlarray
) - offset
);
5703 DHD_ERROR(("%s: error %d on reading %d membytes at 0x%08x\n",
5705 sizeof(dlarray
) - offset
, offset
));
5710 if (memcmp(dlarray
, ularray
, sizeof(dlarray
))) {
5711 DHD_ERROR(("%s: Downloaded image is corrupted.\n",
5716 DHD_ERROR(("%s: Download/Upload/Compare succeeded.\n",
5721 #endif /* DHD_DEBUG */
5726 #endif /* BCMEMBEDIMAGE */
5728 static int dhdsdio_download_code_file(struct dhd_bus
*bus
, char *fw_path
)
5734 u8
*memblock
= NULL
, *memptr
;
5736 DHD_INFO(("%s: download firmware %s\n", __func__
, fw_path
));
5738 image
= dhd_os_open_image(fw_path
);
5742 memptr
= memblock
= kmalloc(MEMBLOCK
+ DHD_SDALIGN
, GFP_ATOMIC
);
5743 if (memblock
== NULL
) {
5744 DHD_ERROR(("%s: Failed to allocate memory %d bytes\n",
5745 __func__
, MEMBLOCK
));
5748 if ((u32
)(unsigned long)memblock
% DHD_SDALIGN
)
5750 (DHD_SDALIGN
- ((u32
)(unsigned long)memblock
% DHD_SDALIGN
));
5752 /* Download image */
5754 dhd_os_get_image_block((char *)memptr
, MEMBLOCK
, image
))) {
5755 bcmerror
= dhdsdio_membytes(bus
, true, offset
, memptr
, len
);
5757 DHD_ERROR(("%s: error %d on writing %d membytes at "
5758 "0x%08x\n", __func__
, bcmerror
, MEMBLOCK
, offset
));
5770 dhd_os_close_image(image
);
5776 * ProcessVars:Takes a buffer of "<var>=<value>\n" lines read from a file
5777 * and ending in a NUL.
5778 * Removes carriage returns, empty lines, comment lines, and converts
5780 * Shortens buffer as needed and pads with NULs. End of buffer is marked
5784 static uint
process_nvram_vars(char *varbuf
, uint len
)
5793 findNewline
= false;
5796 for (n
= 0; n
< len
; n
++) {
5799 if (varbuf
[n
] == '\r')
5801 if (findNewline
&& varbuf
[n
] != '\n')
5803 findNewline
= false;
5804 if (varbuf
[n
] == '#') {
5808 if (varbuf
[n
] == '\n') {
5818 buf_len
= dp
- varbuf
;
5820 while (dp
< varbuf
+ n
)
5827 EXAMPLE: nvram_array
5830 Use carriage return at the end of each assignment,
5831 and an empty string with
5832 carriage return at the end of array.
5835 unsigned char nvram_array[] = {"name1=value1\n",
5836 "name2=value2\n", "\n"};
5837 Hex values start with 0x, and mac addr format: xx:xx:xx:xx:xx:xx.
5839 Search "EXAMPLE: nvram_array" to see how the array is activated.
5842 void dhd_bus_set_nvram_params(struct dhd_bus
*bus
, const char *nvram_params
)
5844 bus
->nvram_params
= nvram_params
;
5847 static int dhdsdio_download_nvram(struct dhd_bus
*bus
)
5852 char *memblock
= NULL
;
5855 bool nvram_file_exists
;
5857 nv_path
= bus
->nv_path
;
5859 nvram_file_exists
= ((nv_path
!= NULL
) && (nv_path
[0] != '\0'));
5860 if (!nvram_file_exists
&& (bus
->nvram_params
== NULL
))
5863 if (nvram_file_exists
) {
5864 image
= dhd_os_open_image(nv_path
);
5869 memblock
= kmalloc(MEMBLOCK
, GFP_ATOMIC
);
5870 if (memblock
== NULL
) {
5871 DHD_ERROR(("%s: Failed to allocate memory %d bytes\n",
5872 __func__
, MEMBLOCK
));
5876 /* Download variables */
5877 if (nvram_file_exists
) {
5878 len
= dhd_os_get_image_block(memblock
, MEMBLOCK
, image
);
5880 len
= strlen(bus
->nvram_params
);
5881 ASSERT(len
<= MEMBLOCK
);
5884 memcpy(memblock
, bus
->nvram_params
, len
);
5887 if (len
> 0 && len
< MEMBLOCK
) {
5888 bufp
= (char *)memblock
;
5890 len
= process_nvram_vars(bufp
, len
);
5894 bcmerror
= dhdsdio_downloadvars(bus
, memblock
, len
+ 1);
5896 DHD_ERROR(("%s: error downloading vars: %d\n",
5897 __func__
, bcmerror
));
5900 DHD_ERROR(("%s: error reading nvram file: %d\n",
5902 bcmerror
= BCME_SDIO_ERROR
;
5910 dhd_os_close_image(image
);
5915 static int _dhdsdio_download_firmware(struct dhd_bus
*bus
)
5919 bool embed
= false; /* download embedded firmware */
5920 bool dlok
= false; /* download firmware succeeded */
5922 /* Out immediately if no image to download */
5923 if ((bus
->fw_path
== NULL
) || (bus
->fw_path
[0] == '\0')) {
5924 #ifdef BCMEMBEDIMAGE
5931 /* Keep arm in reset */
5932 if (dhdsdio_download_state(bus
, true)) {
5933 DHD_ERROR(("%s: error placing ARM core in reset\n", __func__
));
5937 /* External image takes precedence if specified */
5938 if ((bus
->fw_path
!= NULL
) && (bus
->fw_path
[0] != '\0')) {
5939 if (dhdsdio_download_code_file(bus
, bus
->fw_path
)) {
5940 DHD_ERROR(("%s: dongle image file download failed\n",
5942 #ifdef BCMEMBEDIMAGE
5952 #ifdef BCMEMBEDIMAGE
5954 if (dhdsdio_download_code_array(bus
)) {
5955 DHD_ERROR(("%s: dongle image array download failed\n",
5964 DHD_ERROR(("%s: dongle image download failed\n", __func__
));
5968 /* EXAMPLE: nvram_array */
5969 /* If a valid nvram_arry is specified as above, it can be passed
5971 /* dhd_bus_set_nvram_params(bus, (char *)&nvram_array); */
5973 /* External nvram takes precedence if specified */
5974 if (dhdsdio_download_nvram(bus
)) {
5975 DHD_ERROR(("%s: dongle nvram file download failed\n",
5979 /* Take arm out of reset */
5980 if (dhdsdio_download_state(bus
, false)) {
5981 DHD_ERROR(("%s: error getting out of ARM core reset\n",
5993 dhd_bcmsdh_recv_buf(dhd_bus_t
*bus
, u32 addr
, uint fn
, uint flags
,
5994 u8
*buf
, uint nbytes
, struct sk_buff
*pkt
,
5995 bcmsdh_cmplt_fn_t complete
, void *handle
)
5999 /* 4329: GSPI check */
6001 bcmsdh_recv_buf(bus
->sdh
, addr
, fn
, flags
, buf
, nbytes
, pkt
,
6007 dhd_bcmsdh_send_buf(dhd_bus_t
*bus
, u32 addr
, uint fn
, uint flags
,
6008 u8
*buf
, uint nbytes
, struct sk_buff
*pkt
,
6009 bcmsdh_cmplt_fn_t complete
, void *handle
)
6011 return bcmsdh_send_buf
6012 (bus
->sdh
, addr
, fn
, flags
, buf
, nbytes
, pkt
, complete
,
6016 uint
dhd_bus_chip(struct dhd_bus
*bus
)
6018 ASSERT(bus
->sih
!= NULL
);
6019 return bus
->sih
->chip
;
6022 void *dhd_bus_pub(struct dhd_bus
*bus
)
6027 void *dhd_bus_txq(struct dhd_bus
*bus
)
6032 uint
dhd_bus_hdrlen(struct dhd_bus
*bus
)
6034 return SDPCM_HDRLEN
;
6037 int dhd_bus_devreset(dhd_pub_t
*dhdp
, u8 flag
)
6045 if (!bus
->dhd
->dongle_reset
) {
6046 /* Expect app to have torn down any
6047 connection before calling */
6048 /* Stop the bus, disable F2 */
6049 dhd_bus_stop(bus
, false);
6051 /* Clean tx/rx buffer pointers,
6052 detach from the dongle */
6053 dhdsdio_release_dongle(bus
, bus
->dhd
->osh
);
6055 bus
->dhd
->dongle_reset
= true;
6056 bus
->dhd
->up
= false;
6058 DHD_TRACE(("%s: WLAN OFF DONE\n", __func__
));
6059 /* App can now remove power from device */
6061 bcmerror
= BCME_SDIO_ERROR
;
6063 /* App must have restored power to device before calling */
6065 DHD_TRACE(("\n\n%s: == WLAN ON ==\n", __func__
));
6067 if (bus
->dhd
->dongle_reset
) {
6069 /* Reset SD client */
6070 bcmsdh_reset(bus
->sdh
);
6072 /* Attempt to re-attach & download */
6073 if (dhdsdio_probe_attach(bus
, bus
->dhd
->osh
, bus
->sdh
,
6074 (u32
*) SI_ENUM_BASE
,
6076 /* Attempt to download binary to the dongle */
6077 if (dhdsdio_probe_init
6078 (bus
, bus
->dhd
->osh
, bus
->sdh
)
6079 && dhdsdio_download_firmware(bus
,
6083 /* Re-init bus, enable F2 transfer */
6084 dhd_bus_init((dhd_pub_t
*) bus
->dhd
,
6087 #if defined(OOB_INTR_ONLY)
6088 dhd_enable_oob_intr(bus
, true);
6089 #endif /* defined(OOB_INTR_ONLY) */
6091 bus
->dhd
->dongle_reset
= false;
6092 bus
->dhd
->up
= true;
6094 DHD_TRACE(("%s: WLAN ON DONE\n",
6097 bcmerror
= BCME_SDIO_ERROR
;
6099 bcmerror
= BCME_SDIO_ERROR
;
6101 bcmerror
= BCME_NOTDOWN
;
6102 DHD_ERROR(("%s: Set DEVRESET=false invoked when device "
6103 "is on\n", __func__
));
6104 bcmerror
= BCME_SDIO_ERROR
;