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>
23 #include BCMEMBEDIMAGE
24 #endif /* BCMEMBEDIMAGE */
34 #include <hndrte_armtrap.h>
35 #include <hndrte_cons.h>
36 #endif /* DHD_DEBUG */
42 #include <sbsdpcmdev.h>
45 #include <proto/802.11.h>
47 #include <dngl_stats.h>
50 #include <dhd_proto.h>
54 #include <siutils_priv.h>
56 #ifndef DHDSDIO_MEM_DUMP_FNAME
57 #define DHDSDIO_MEM_DUMP_FNAME "mem_dump"
60 #define TXQLEN 2048 /* bulk tx queue length */
61 #define TXHI (TXQLEN - 256) /* turn on flow control above TXHI */
62 #define TXLOW (TXHI - 256) /* turn off flow control below TXLOW */
65 #define TXRETRIES 2 /* # of retries for tx frames */
67 #if defined(CONFIG_MACH_SANDGATE2G)
68 #define DHD_RXBOUND 250 /* Default for max rx frames in
71 #define DHD_RXBOUND 50 /* Default for max rx frames in
73 #endif /* defined(CONFIG_MACH_SANDGATE2G) */
75 #define DHD_TXBOUND 20 /* Default for max tx frames in
78 #define DHD_TXMINMAX 1 /* Max tx frames if rx still pending */
80 #define MEMBLOCK 2048 /* Block size used for downloading
82 #define MAX_DATA_BUF (32 * 1024) /* Must be large enough to hold
83 biggest possible glom */
85 /* Packet alignment for most efficient SDIO (can change based on platform) */
87 #define DHD_SDALIGN 32
89 #if !ISPOWEROF2(DHD_SDALIGN)
90 #error DHD_SDALIGN is not a power of 2!
94 #define DHD_FIRSTREAD 32
96 #if !ISPOWEROF2(DHD_FIRSTREAD)
97 #error DHD_FIRSTREAD is not a power of 2!
100 /* Total length of frame header for dongle protocol */
101 #define SDPCM_HDRLEN (SDPCM_FRAMETAG_LEN + SDPCM_SWHEADER_LEN)
103 #define SDPCM_RESERVE (SDPCM_HDRLEN + SDPCM_TEST_HDRLEN + DHD_SDALIGN)
105 #define SDPCM_RESERVE (SDPCM_HDRLEN + DHD_SDALIGN)
108 /* Space for header read, limit for data packets */
110 #define MAX_HDR_READ 32
112 #if !ISPOWEROF2(MAX_HDR_READ)
113 #error MAX_HDR_READ is not a power of 2!
116 #define MAX_RX_DATASZ 2048
118 /* Maximum milliseconds to wait for F2 to come up */
119 #define DHD_WAIT_F2RDY 3000
121 /* Bump up limit on waiting for HT to account for first startup;
122 * if the image is doing a CRC calculation before programming the PMU
123 * for HT availability, it could take a couple hundred ms more, so
124 * max out at a 1 second (1000000us).
126 #if (PMU_MAX_TRANSITION_DLY <= 1000000)
127 #undef PMU_MAX_TRANSITION_DLY
128 #define PMU_MAX_TRANSITION_DLY 1000000
131 /* Value for ChipClockCSR during initial setup */
132 #define DHD_INIT_CLKCTL1 (SBSDIO_FORCE_HW_CLKREQ_OFF | \
133 SBSDIO_ALP_AVAIL_REQ)
134 #define DHD_INIT_CLKCTL2 (SBSDIO_FORCE_HW_CLKREQ_OFF | SBSDIO_FORCE_ALP)
136 /* Flags for SDH calls */
137 #define F2SYNC (SDIO_REQ_4BYTE | SDIO_REQ_FIXED)
139 /* Packet free applicable unconditionally for sdio and sdspi. Conditional if
140 * bufpool was present for gspi bus.
142 #define PKTFREE2() if ((bus->bus != SPI_BUS) || bus->usebufpool) \
143 pkt_buf_free_skb(pkt);
146 * Conversion of 802.1D priority to precedence level
148 #define PRIO2PREC(prio) \
149 (((prio) == PRIO_8021D_NONE || (prio) == PRIO_8021D_BE) ? \
152 DHD_SPINWAIT_SLEEP_INIT(sdioh_spinwait_sleep
);
153 extern int dhdcdc_set_ioctl(dhd_pub_t
*dhd
, int ifidx
, uint cmd
, void *buf
,
157 /* Device console log buffer state */
158 typedef struct dhd_console
{
159 uint count
; /* Poll interval msec counter */
160 uint log_addr
; /* Log struct address (fixed) */
161 hndrte_log_t log
; /* Log struct (host copy) */
162 uint bufsize
; /* Size of log buffer */
163 u8
*buf
; /* Log buffer (host copy) */
164 uint last
; /* Last buffer read index */
166 #endif /* DHD_DEBUG */
168 /* Private data for SDIO bus interaction */
169 typedef struct dhd_bus
{
172 bcmsdh_info_t
*sdh
; /* Handle for BCMSDH calls */
173 si_t
*sih
; /* Handle for SI calls */
174 char *vars
; /* Variables (from CIS and/or other) */
175 uint varsz
; /* Size of variables buffer */
176 u32 sbaddr
; /* Current SB window pointer (-1, invalid) */
178 sdpcmd_regs_t
*regs
; /* Registers for SDIO core */
179 uint sdpcmrev
; /* SDIO core revision */
180 uint armrev
; /* CPU core revision */
181 uint ramrev
; /* SOCRAM core revision */
182 u32 ramsize
; /* Size of RAM in SOCRAM (bytes) */
183 u32 orig_ramsize
; /* Size of RAM in SOCRAM (bytes) */
185 u32 bus
; /* gSPI or SDIO bus */
186 u32 hostintmask
; /* Copy of Host Interrupt Mask */
187 u32 intstatus
; /* Intstatus bits (events) pending */
188 bool dpc_sched
; /* Indicates DPC schedule (intrpt rcvd) */
189 bool fcstate
; /* State of dongle flow-control */
191 u16 cl_devid
; /* cached devid for dhdsdio_probe_attach() */
192 char *fw_path
; /* module_param: path to firmware image */
193 char *nv_path
; /* module_param: path to nvram vars file */
194 const char *nvram_params
; /* user specified nvram params. */
196 uint blocksize
; /* Block size of SDIO transfers */
197 uint roundup
; /* Max roundup limit */
199 struct pktq txq
; /* Queue length used for flow-control */
200 u8 flowcontrol
; /* per prio flow control bitmask */
201 u8 tx_seq
; /* Transmit sequence number (next) */
202 u8 tx_max
; /* Maximum transmit sequence allowed */
204 u8 hdrbuf
[MAX_HDR_READ
+ DHD_SDALIGN
];
205 u8
*rxhdr
; /* Header of current rx frame (in hdrbuf) */
206 u16 nextlen
; /* Next Read Len from last header */
207 u8 rx_seq
; /* Receive sequence number (expected) */
208 bool rxskip
; /* Skip receive (awaiting NAK ACK) */
210 struct sk_buff
*glomd
; /* Packet containing glomming descriptor */
211 struct sk_buff
*glom
; /* Packet chain for glommed superframe */
212 uint glomerr
; /* Glom packet read errors */
214 u8
*rxbuf
; /* Buffer for receiving control packets */
215 uint rxblen
; /* Allocated length of rxbuf */
216 u8
*rxctl
; /* Aligned pointer into rxbuf */
217 u8
*databuf
; /* Buffer for receiving big glom packet */
218 u8
*dataptr
; /* Aligned pointer into databuf */
219 uint rxlen
; /* Length of valid data in buffer */
221 u8 sdpcm_ver
; /* Bus protocol reported by dongle */
223 bool intr
; /* Use interrupts */
224 bool poll
; /* Use polling */
225 bool ipend
; /* Device interrupt is pending */
226 bool intdis
; /* Interrupts disabled by isr */
227 uint intrcount
; /* Count of device interrupt callbacks */
228 uint lastintrs
; /* Count as of last watchdog timer */
229 uint spurious
; /* Count of spurious interrupts */
230 uint pollrate
; /* Ticks between device polls */
231 uint polltick
; /* Tick counter */
232 uint pollcnt
; /* Count of active polls */
235 dhd_console_t console
; /* Console output polling support */
236 uint console_addr
; /* Console address from shared struct */
237 #endif /* DHD_DEBUG */
239 uint regfails
; /* Count of R_REG/W_REG failures */
241 uint clkstate
; /* State of sd and backplane clock(s) */
242 bool activity
; /* Activity flag for clock down */
243 s32 idletime
; /* Control for activity timeout */
244 s32 idlecount
; /* Activity timeout counter */
245 s32 idleclock
; /* How to set bus driver when idle */
246 s32 sd_divisor
; /* Speed control to bus driver */
247 s32 sd_mode
; /* Mode control to bus driver */
248 s32 sd_rxchain
; /* If bcmsdh api accepts PKT chains */
249 bool use_rxchain
; /* If dhd should use PKT chains */
250 bool sleeping
; /* Is SDIO bus sleeping? */
251 bool rxflow_mode
; /* Rx flow control mode */
252 bool rxflow
; /* Is rx flow control on */
253 uint prev_rxlim_hit
; /* Is prev rx limit exceeded
254 (per dpc schedule) */
255 bool alp_only
; /* Don't use HT clock (ALP only) */
256 /* Field to decide if rx of control frames happen in rxbuf or lb-pool */
260 /* external loopback */
264 /* pktgen configuration */
265 uint pktgen_freq
; /* Ticks between bursts */
266 uint pktgen_count
; /* Packets to send each burst */
267 uint pktgen_print
; /* Bursts between count displays */
268 uint pktgen_total
; /* Stop after this many */
269 uint pktgen_minlen
; /* Minimum packet data len */
270 uint pktgen_maxlen
; /* Maximum packet data len */
271 uint pktgen_mode
; /* Configured mode: tx, rx, or echo */
272 uint pktgen_stop
; /* Number of tx failures causing stop */
274 /* active pktgen fields */
275 uint pktgen_tick
; /* Tick counter for bursts */
276 uint pktgen_ptick
; /* Burst counter for printing */
277 uint pktgen_sent
; /* Number of test packets generated */
278 uint pktgen_rcvd
; /* Number of test packets received */
279 uint pktgen_fail
; /* Number of failed send attempts */
280 u16 pktgen_len
; /* Length of next packet to send */
283 /* Some additional counters */
284 uint tx_sderrs
; /* Count of tx attempts with sd errors */
285 uint fcqueued
; /* Tx packets that got queued */
286 uint rxrtx
; /* Count of rtx requests (NAK to dongle) */
287 uint rx_toolong
; /* Receive frames too long to receive */
288 uint rxc_errors
; /* SDIO errors when reading control frames */
289 uint rx_hdrfail
; /* SDIO errors on header reads */
290 uint rx_badhdr
; /* Bad received headers (roosync?) */
291 uint rx_badseq
; /* Mismatched rx sequence number */
292 uint fc_rcvd
; /* Number of flow-control events received */
293 uint fc_xoff
; /* Number which turned on flow-control */
294 uint fc_xon
; /* Number which turned off flow-control */
295 uint rxglomfail
; /* Failed deglom attempts */
296 uint rxglomframes
; /* Number of glom frames (superframes) */
297 uint rxglompkts
; /* Number of packets from glom frames */
298 uint f2rxhdrs
; /* Number of header reads */
299 uint f2rxdata
; /* Number of frame data reads */
300 uint f2txdata
; /* Number of f2 frame writes */
301 uint f1regdata
; /* Number of f1 register accesses */
305 bool ctrl_frame_stat
;
311 #define CLK_PENDING 2 /* Not used yet */
314 #define DHD_NOPMU(dhd) (false)
317 static int qcount
[NUMPRIO
];
318 static int tx_packets
[NUMPRIO
];
319 #endif /* DHD_DEBUG */
321 /* Deferred transmit */
322 const uint dhd_deferred_tx
= 1;
324 extern uint dhd_watchdog_ms
;
325 extern void dhd_os_wd_timer(void *bus
, uint wdtick
);
332 /* override the RAM size if possible */
333 #define DONGLE_MIN_MEMSIZE (128 * 1024)
334 int dhd_dongle_memsize
;
336 static bool dhd_doflow
;
337 static bool dhd_alignctl
;
341 static bool retrydata
;
342 #define RETRYCHAN(chan) (((chan) == SDPCM_EVENT_CHANNEL) || retrydata)
344 static const uint watermark
= 8;
345 static const uint firstread
= DHD_FIRSTREAD
;
347 #define HDATLEN (firstread - (SDPCM_HDRLEN))
349 /* Retry count for register access failures */
350 static const uint retry_limit
= 2;
352 /* Force even SD lengths (some host controllers mess up on odd bytes) */
353 static bool forcealign
;
357 #if defined(OOB_INTR_ONLY) && defined(HW_OOB)
358 extern void bcmsdh_enable_hw_oob_intr(void *sdh
, bool enable
);
361 #if defined(OOB_INTR_ONLY) && defined(SDIO_ISR_THREAD)
362 #error OOB_INTR_ONLY is NOT working with SDIO_ISR_THREAD
363 #endif /* defined(OOB_INTR_ONLY) && defined(SDIO_ISR_THREAD) */
364 #define PKTALIGN(_p, _len, _align) \
367 datalign = (unsigned long)((_p)->data); \
368 datalign = roundup(datalign, (_align)) - datalign; \
369 ASSERT(datalign < (_align)); \
370 ASSERT((_p)->len >= ((_len) + datalign)); \
372 skb_pull((_p), datalign); \
373 __skb_trim((_p), (_len)); \
376 /* Limit on rounding up frames */
377 static const uint max_roundup
= 512;
379 /* Try doing readahead */
380 static bool dhd_readahead
;
382 /* To check if there's window offered */
383 #define DATAOK(bus) \
384 (((u8)(bus->tx_max - bus->tx_seq) != 0) && \
385 (((u8)(bus->tx_max - bus->tx_seq) & 0x80) == 0))
387 /* Macros to get register read/write status */
388 /* NOTE: these assume a local dhdsdio_bus_t *bus! */
389 #define R_SDREG(regvar, regaddr, retryvar) \
393 regvar = R_REG(regaddr); \
394 } while (bcmsdh_regfail(bus->sdh) && (++retryvar <= retry_limit)); \
396 bus->regfails += (retryvar-1); \
397 if (retryvar > retry_limit) { \
398 DHD_ERROR(("%s: FAILED" #regvar "READ, LINE %d\n", \
399 __func__, __LINE__)); \
405 #define W_SDREG(regval, regaddr, retryvar) \
409 W_REG(regaddr, regval); \
410 } while (bcmsdh_regfail(bus->sdh) && (++retryvar <= retry_limit)); \
412 bus->regfails += (retryvar-1); \
413 if (retryvar > retry_limit) \
414 DHD_ERROR(("%s: FAILED REGISTER WRITE, LINE %d\n", \
415 __func__, __LINE__)); \
419 #define DHD_BUS SDIO_BUS
421 #define PKT_AVAILABLE() (intstatus & I_HMB_FRAME_IND)
423 #define HOSTINTMASK (I_HMB_SW_MASK | I_CHIPACTIVE)
425 #define GSPI_PR55150_BAILOUT
428 static void dhdsdio_testrcv(dhd_bus_t
*bus
, void *pkt
, uint seq
);
429 static void dhdsdio_sdtest_set(dhd_bus_t
*bus
, bool start
);
433 static int dhdsdio_checkdied(dhd_bus_t
*bus
, u8
*data
, uint size
);
434 static int dhdsdio_mem_dump(dhd_bus_t
*bus
);
435 #endif /* DHD_DEBUG */
436 static int dhdsdio_download_state(dhd_bus_t
*bus
, bool enter
);
438 static void dhdsdio_release(dhd_bus_t
*bus
);
439 static void dhdsdio_release_malloc(dhd_bus_t
*bus
);
440 static void dhdsdio_disconnect(void *ptr
);
441 static bool dhdsdio_chipmatch(u16 chipid
);
442 static bool dhdsdio_probe_attach(dhd_bus_t
*bus
, void *sdh
,
443 void *regsva
, u16 devid
);
444 static bool dhdsdio_probe_malloc(dhd_bus_t
*bus
, void *sdh
);
445 static bool dhdsdio_probe_init(dhd_bus_t
*bus
, void *sdh
);
446 static void dhdsdio_release_dongle(dhd_bus_t
*bus
);
448 static uint
process_nvram_vars(char *varbuf
, uint len
);
450 static void dhd_dongle_setmemsize(struct dhd_bus
*bus
, int mem_size
);
451 static int dhd_bcmsdh_recv_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
,
455 static int dhd_bcmsdh_send_buf(dhd_bus_t
*bus
, u32 addr
, uint fn
,
456 uint flags
, u8
*buf
, uint nbytes
,
457 struct sk_buff
*pkt
, bcmsdh_cmplt_fn_t complete
,
460 static bool dhdsdio_download_firmware(struct dhd_bus
*bus
, void *sdh
);
461 static int _dhdsdio_download_firmware(struct dhd_bus
*bus
);
463 static int dhdsdio_download_code_file(struct dhd_bus
*bus
, char *image_path
);
464 static int dhdsdio_download_nvram(struct dhd_bus
*bus
);
466 static int dhdsdio_download_code_array(struct dhd_bus
*bus
);
469 static void dhd_dongle_setmemsize(struct dhd_bus
*bus
, int mem_size
)
471 s32 min_size
= DONGLE_MIN_MEMSIZE
;
472 /* Restrict the memsize to user specified limit */
473 DHD_ERROR(("user: Restrict the dongle ram size to %d, min %d\n",
474 dhd_dongle_memsize
, min_size
));
475 if ((dhd_dongle_memsize
> min_size
) &&
476 (dhd_dongle_memsize
< (s32
) bus
->orig_ramsize
))
477 bus
->ramsize
= dhd_dongle_memsize
;
480 static int dhdsdio_set_siaddr_window(dhd_bus_t
*bus
, u32 address
)
483 bcmsdh_cfg_write(bus
->sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_SBADDRLOW
,
484 (address
>> 8) & SBSDIO_SBADDRLOW_MASK
, &err
);
486 bcmsdh_cfg_write(bus
->sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_SBADDRMID
,
487 (address
>> 16) & SBSDIO_SBADDRMID_MASK
, &err
);
489 bcmsdh_cfg_write(bus
->sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_SBADDRHIGH
,
490 (address
>> 24) & SBSDIO_SBADDRHIGH_MASK
,
495 /* Turn backplane clock on or off */
496 static int dhdsdio_htclk(dhd_bus_t
*bus
, bool on
, bool pendok
)
499 u8 clkctl
, clkreq
, devctl
;
502 DHD_TRACE(("%s: Enter\n", __func__
));
504 #if defined(OOB_INTR_ONLY)
511 /* Request HT Avail */
513 bus
->alp_only
? SBSDIO_ALP_AVAIL_REQ
: SBSDIO_HT_AVAIL_REQ
;
515 if ((bus
->sih
->chip
== BCM4329_CHIP_ID
)
516 && (bus
->sih
->chiprev
== 0))
517 clkreq
|= SBSDIO_FORCE_ALP
;
519 bcmsdh_cfg_write(sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_CHIPCLKCSR
,
522 DHD_ERROR(("%s: HT Avail request error: %d\n",
527 if (pendok
&& ((bus
->sih
->buscoretype
== PCMCIA_CORE_ID
)
528 && (bus
->sih
->buscorerev
== 9))) {
530 R_SDREG(dummy
, &bus
->regs
->clockctlstatus
, retries
);
533 /* Check current status */
535 bcmsdh_cfg_read(sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_CHIPCLKCSR
,
538 DHD_ERROR(("%s: HT Avail read error: %d\n",
543 /* Go to pending and await interrupt if appropriate */
544 if (!SBSDIO_CLKAV(clkctl
, bus
->alp_only
) && pendok
) {
545 /* Allow only clock-available interrupt */
547 bcmsdh_cfg_read(sdh
, SDIO_FUNC_1
, SBSDIO_DEVICE_CTL
,
550 DHD_ERROR(("%s: Devctl error setting CA: %d\n",
555 devctl
|= SBSDIO_DEVCTL_CA_INT_ONLY
;
556 bcmsdh_cfg_write(sdh
, SDIO_FUNC_1
, SBSDIO_DEVICE_CTL
,
558 DHD_INFO(("CLKCTL: set PENDING\n"));
559 bus
->clkstate
= CLK_PENDING
;
562 } else if (bus
->clkstate
== CLK_PENDING
) {
563 /* Cancel CA-only interrupt filter */
565 bcmsdh_cfg_read(sdh
, SDIO_FUNC_1
, SBSDIO_DEVICE_CTL
,
567 devctl
&= ~SBSDIO_DEVCTL_CA_INT_ONLY
;
568 bcmsdh_cfg_write(sdh
, SDIO_FUNC_1
, SBSDIO_DEVICE_CTL
,
572 /* Otherwise, wait here (polling) for HT Avail */
573 if (!SBSDIO_CLKAV(clkctl
, bus
->alp_only
)) {
574 SPINWAIT_SLEEP(sdioh_spinwait_sleep
,
576 bcmsdh_cfg_read(sdh
, SDIO_FUNC_1
,
577 SBSDIO_FUNC1_CHIPCLKCSR
,
579 !SBSDIO_CLKAV(clkctl
, bus
->alp_only
)),
580 PMU_MAX_TRANSITION_DLY
);
583 DHD_ERROR(("%s: HT Avail request error: %d\n",
587 if (!SBSDIO_CLKAV(clkctl
, bus
->alp_only
)) {
588 DHD_ERROR(("%s: HT Avail timeout (%d): clkctl 0x%02x\n",
589 __func__
, PMU_MAX_TRANSITION_DLY
, clkctl
));
593 /* Mark clock available */
594 bus
->clkstate
= CLK_AVAIL
;
595 DHD_INFO(("CLKCTL: turned ON\n"));
597 #if defined(DHD_DEBUG)
598 if (bus
->alp_only
== true) {
599 #if !defined(BCMLXSDMMC)
600 if (!SBSDIO_ALPONLY(clkctl
)) {
601 DHD_ERROR(("%s: HT Clock, when ALP Only\n",
604 #endif /* !defined(BCMLXSDMMC) */
606 if (SBSDIO_ALPONLY(clkctl
)) {
607 DHD_ERROR(("%s: HT Clock should be on.\n",
611 #endif /* defined (DHD_DEBUG) */
613 bus
->activity
= true;
617 if (bus
->clkstate
== CLK_PENDING
) {
618 /* Cancel CA-only interrupt filter */
620 bcmsdh_cfg_read(sdh
, SDIO_FUNC_1
, SBSDIO_DEVICE_CTL
,
622 devctl
&= ~SBSDIO_DEVCTL_CA_INT_ONLY
;
623 bcmsdh_cfg_write(sdh
, SDIO_FUNC_1
, SBSDIO_DEVICE_CTL
,
627 bus
->clkstate
= CLK_SDONLY
;
628 bcmsdh_cfg_write(sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_CHIPCLKCSR
,
630 DHD_INFO(("CLKCTL: turned OFF\n"));
632 DHD_ERROR(("%s: Failed access turning clock off: %d\n",
640 /* Change idle/active SD state */
641 static int dhdsdio_sdclk(dhd_bus_t
*bus
, bool on
)
646 DHD_TRACE(("%s: Enter\n", __func__
));
649 if (bus
->idleclock
== DHD_IDLE_STOP
) {
650 /* Turn on clock and restore mode */
652 err
= bcmsdh_iovar_op(bus
->sdh
, "sd_clock", NULL
, 0,
653 &iovalue
, sizeof(iovalue
), true);
655 DHD_ERROR(("%s: error enabling sd_clock: %d\n",
660 iovalue
= bus
->sd_mode
;
661 err
= bcmsdh_iovar_op(bus
->sdh
, "sd_mode", NULL
, 0,
662 &iovalue
, sizeof(iovalue
), true);
664 DHD_ERROR(("%s: error changing sd_mode: %d\n",
668 } else if (bus
->idleclock
!= DHD_IDLE_ACTIVE
) {
669 /* Restore clock speed */
670 iovalue
= bus
->sd_divisor
;
671 err
= bcmsdh_iovar_op(bus
->sdh
, "sd_divisor", NULL
, 0,
672 &iovalue
, sizeof(iovalue
), true);
674 DHD_ERROR(("%s: error restoring sd_divisor: %d\n",
679 bus
->clkstate
= CLK_SDONLY
;
681 /* Stop or slow the SD clock itself */
682 if ((bus
->sd_divisor
== -1) || (bus
->sd_mode
== -1)) {
683 DHD_TRACE(("%s: can't idle clock, divisor %d mode %d\n",
684 __func__
, bus
->sd_divisor
, bus
->sd_mode
));
687 if (bus
->idleclock
== DHD_IDLE_STOP
) {
689 /* Change to SD1 mode and turn off clock */
692 bcmsdh_iovar_op(bus
->sdh
, "sd_mode", NULL
,
694 sizeof(iovalue
), true);
696 DHD_ERROR(("%s: error changing sd_clock: %d\n",
703 err
= bcmsdh_iovar_op(bus
->sdh
, "sd_clock", NULL
, 0,
704 &iovalue
, sizeof(iovalue
), true);
706 DHD_ERROR(("%s: error disabling sd_clock: %d\n",
710 } else if (bus
->idleclock
!= DHD_IDLE_ACTIVE
) {
711 /* Set divisor to idle value */
712 iovalue
= bus
->idleclock
;
713 err
= bcmsdh_iovar_op(bus
->sdh
, "sd_divisor", NULL
, 0,
714 &iovalue
, sizeof(iovalue
), true);
716 DHD_ERROR(("%s: error changing sd_divisor: %d\n",
721 bus
->clkstate
= CLK_NONE
;
727 /* Transition SD and backplane clock readiness */
728 static int dhdsdio_clkctl(dhd_bus_t
*bus
, uint target
, bool pendok
)
731 uint oldstate
= bus
->clkstate
;
732 #endif /* DHD_DEBUG */
734 DHD_TRACE(("%s: Enter\n", __func__
));
736 /* Early exit if we're already there */
737 if (bus
->clkstate
== target
) {
738 if (target
== CLK_AVAIL
) {
739 dhd_os_wd_timer(bus
->dhd
, dhd_watchdog_ms
);
740 bus
->activity
= true;
747 /* Make sure SD clock is available */
748 if (bus
->clkstate
== CLK_NONE
)
749 dhdsdio_sdclk(bus
, true);
750 /* Now request HT Avail on the backplane */
751 dhdsdio_htclk(bus
, true, pendok
);
752 dhd_os_wd_timer(bus
->dhd
, dhd_watchdog_ms
);
753 bus
->activity
= true;
757 /* Remove HT request, or bring up SD clock */
758 if (bus
->clkstate
== CLK_NONE
)
759 dhdsdio_sdclk(bus
, true);
760 else if (bus
->clkstate
== CLK_AVAIL
)
761 dhdsdio_htclk(bus
, false, false);
763 DHD_ERROR(("dhdsdio_clkctl: request for %d -> %d\n",
764 bus
->clkstate
, target
));
765 dhd_os_wd_timer(bus
->dhd
, dhd_watchdog_ms
);
769 /* Make sure to remove HT request */
770 if (bus
->clkstate
== CLK_AVAIL
)
771 dhdsdio_htclk(bus
, false, false);
772 /* Now remove the SD clock */
773 dhdsdio_sdclk(bus
, false);
774 dhd_os_wd_timer(bus
->dhd
, 0);
778 DHD_INFO(("dhdsdio_clkctl: %d -> %d\n", oldstate
, bus
->clkstate
));
779 #endif /* DHD_DEBUG */
784 int dhdsdio_bussleep(dhd_bus_t
*bus
, bool sleep
)
786 bcmsdh_info_t
*sdh
= bus
->sdh
;
787 sdpcmd_regs_t
*regs
= bus
->regs
;
790 DHD_INFO(("dhdsdio_bussleep: request %s (currently %s)\n",
791 (sleep
? "SLEEP" : "WAKE"),
792 (bus
->sleeping
? "SLEEP" : "WAKE")));
794 /* Done if we're already in the requested state */
795 if (sleep
== bus
->sleeping
)
798 /* Going to sleep: set the alarm and turn off the lights... */
800 /* Don't sleep if something is pending */
801 if (bus
->dpc_sched
|| bus
->rxskip
|| pktq_len(&bus
->txq
))
804 /* Disable SDIO interrupts (no longer interested) */
805 bcmsdh_intr_disable(bus
->sdh
);
807 /* Make sure the controller has the bus up */
808 dhdsdio_clkctl(bus
, CLK_AVAIL
, false);
810 /* Tell device to start using OOB wakeup */
811 W_SDREG(SMB_USE_OOB
, ®s
->tosbmailbox
, retries
);
812 if (retries
> retry_limit
)
813 DHD_ERROR(("CANNOT SIGNAL CHIP, WILL NOT WAKE UP!!\n"));
815 /* Turn off our contribution to the HT clock request */
816 dhdsdio_clkctl(bus
, CLK_SDONLY
, false);
818 bcmsdh_cfg_write(sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_CHIPCLKCSR
,
819 SBSDIO_FORCE_HW_CLKREQ_OFF
, NULL
);
821 /* Isolate the bus */
822 if (bus
->sih
->chip
!= BCM4329_CHIP_ID
823 && bus
->sih
->chip
!= BCM4319_CHIP_ID
) {
824 bcmsdh_cfg_write(sdh
, SDIO_FUNC_1
, SBSDIO_DEVICE_CTL
,
825 SBSDIO_DEVCTL_PADS_ISO
, NULL
);
829 bus
->sleeping
= true;
832 /* Waking up: bus power up is ok, set local state */
834 bcmsdh_cfg_write(sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_CHIPCLKCSR
,
837 /* Force pad isolation off if possible
838 (in case power never toggled) */
839 if ((bus
->sih
->buscoretype
== PCMCIA_CORE_ID
)
840 && (bus
->sih
->buscorerev
>= 10))
841 bcmsdh_cfg_write(sdh
, SDIO_FUNC_1
, SBSDIO_DEVICE_CTL
, 0,
844 /* Make sure the controller has the bus up */
845 dhdsdio_clkctl(bus
, CLK_AVAIL
, false);
847 /* Send misc interrupt to indicate OOB not needed */
848 W_SDREG(0, ®s
->tosbmailboxdata
, retries
);
849 if (retries
<= retry_limit
)
850 W_SDREG(SMB_DEV_INT
, ®s
->tosbmailbox
, retries
);
852 if (retries
> retry_limit
)
853 DHD_ERROR(("CANNOT SIGNAL CHIP TO CLEAR OOB!!\n"));
855 /* Make sure we have SD bus access */
856 dhdsdio_clkctl(bus
, CLK_SDONLY
, false);
859 bus
->sleeping
= false;
861 /* Enable interrupts again */
862 if (bus
->intr
&& (bus
->dhd
->busstate
== DHD_BUS_DATA
)) {
864 bcmsdh_intr_enable(bus
->sdh
);
871 #if defined(OOB_INTR_ONLY)
872 void dhd_enable_oob_intr(struct dhd_bus
*bus
, bool enable
)
875 bcmsdh_enable_hw_oob_intr(bus
->sdh
, enable
);
877 sdpcmd_regs_t
*regs
= bus
->regs
;
880 dhdsdio_clkctl(bus
, CLK_AVAIL
, false);
881 if (enable
== true) {
883 /* Tell device to start using OOB wakeup */
884 W_SDREG(SMB_USE_OOB
, ®s
->tosbmailbox
, retries
);
885 if (retries
> retry_limit
)
886 DHD_ERROR(("CANNOT SIGNAL CHIP, WILL NOT WAKE UP!!\n"));
889 /* Send misc interrupt to indicate OOB not needed */
890 W_SDREG(0, ®s
->tosbmailboxdata
, retries
);
891 if (retries
<= retry_limit
)
892 W_SDREG(SMB_DEV_INT
, ®s
->tosbmailbox
, retries
);
895 /* Turn off our contribution to the HT clock request */
896 dhdsdio_clkctl(bus
, CLK_SDONLY
, false);
897 #endif /* !defined(HW_OOB) */
899 #endif /* defined(OOB_INTR_ONLY) */
901 #define BUS_WAKE(bus) \
903 if ((bus)->sleeping) \
904 dhdsdio_bussleep((bus), false); \
907 /* Writes a HW/SW header into the packet and sends it. */
908 /* Assumes: (a) header space already there, (b) caller holds lock */
909 static int dhdsdio_txpkt(dhd_bus_t
*bus
, struct sk_buff
*pkt
, uint chan
,
921 DHD_TRACE(("%s: Enter\n", __func__
));
925 if (bus
->dhd
->dongle_reset
) {
930 frame
= (u8
*) (pkt
->data
);
932 /* Add alignment padding, allocate new packet if needed */
933 pad
= ((unsigned long)frame
% DHD_SDALIGN
);
935 if (skb_headroom(pkt
) < pad
) {
936 DHD_INFO(("%s: insufficient headroom %d for %d pad\n",
937 __func__
, skb_headroom(pkt
), pad
));
938 bus
->dhd
->tx_realloc
++;
939 new = pkt_buf_get_skb(pkt
->len
+ DHD_SDALIGN
);
941 DHD_ERROR(("%s: couldn't allocate new %d-byte "
943 __func__
, pkt
->len
+ DHD_SDALIGN
));
948 PKTALIGN(new, pkt
->len
, DHD_SDALIGN
);
949 memcpy(new->data
, pkt
->data
, pkt
->len
);
951 pkt_buf_free_skb(pkt
);
952 /* free the pkt if canned one is not used */
955 frame
= (u8
*) (pkt
->data
);
956 ASSERT(((unsigned long)frame
% DHD_SDALIGN
) == 0);
960 frame
= (u8
*) (pkt
->data
);
962 ASSERT((pad
+ SDPCM_HDRLEN
) <= (int)(pkt
->len
));
963 memset(frame
, 0, pad
+ SDPCM_HDRLEN
);
966 ASSERT(pad
< DHD_SDALIGN
);
968 /* Hardware tag: 2 byte len followed by 2 byte ~len check (all LE) */
969 len
= (u16
) (pkt
->len
);
970 *(u16
*) frame
= cpu_to_le16(len
);
971 *(((u16
*) frame
) + 1) = cpu_to_le16(~len
);
973 /* Software tag: channel, sequence number, data offset */
975 ((chan
<< SDPCM_CHANNEL_SHIFT
) & SDPCM_CHANNEL_MASK
) | bus
->tx_seq
|
977 SDPCM_HDRLEN
) << SDPCM_DOFFSET_SHIFT
) & SDPCM_DOFFSET_MASK
);
979 put_unaligned_le32(swheader
, frame
+ SDPCM_FRAMETAG_LEN
);
980 put_unaligned_le32(0, frame
+ SDPCM_FRAMETAG_LEN
+ sizeof(swheader
));
983 tx_packets
[pkt
->priority
]++;
984 if (DHD_BYTES_ON() &&
985 (((DHD_CTL_ON() && (chan
== SDPCM_CONTROL_CHANNEL
)) ||
986 (DHD_DATA_ON() && (chan
!= SDPCM_CONTROL_CHANNEL
))))) {
987 prhex("Tx Frame", frame
, len
);
988 } else if (DHD_HDRS_ON()) {
989 prhex("TxHdr", frame
, min_t(u16
, len
, 16));
993 /* Raise len to next SDIO block to eliminate tail command */
994 if (bus
->roundup
&& bus
->blocksize
&& (len
> bus
->blocksize
)) {
995 u16 pad
= bus
->blocksize
- (len
% bus
->blocksize
);
996 if ((pad
<= bus
->roundup
) && (pad
< bus
->blocksize
))
998 if (pad
<= skb_tailroom(pkt
))
1001 } else if (len
% DHD_SDALIGN
) {
1002 len
+= DHD_SDALIGN
- (len
% DHD_SDALIGN
);
1005 /* Some controllers have trouble with odd bytes -- round to even */
1006 if (forcealign
&& (len
& (ALIGNMENT
- 1))) {
1008 if (skb_tailroom(pkt
))
1010 len
= roundup(len
, ALIGNMENT
);
1013 DHD_ERROR(("%s: sending unrounded %d-byte packet\n",
1020 dhd_bcmsdh_send_buf(bus
, bcmsdh_cur_sbwad(sdh
), SDIO_FUNC_2
,
1021 F2SYNC
, frame
, len
, pkt
, NULL
, NULL
);
1023 ASSERT(ret
!= BCME_PENDING
);
1026 /* On failure, abort the command
1027 and terminate the frame */
1028 DHD_INFO(("%s: sdio error %d, abort command and "
1029 "terminate frame.\n", __func__
, ret
));
1032 bcmsdh_abort(sdh
, SDIO_FUNC_2
);
1033 bcmsdh_cfg_write(sdh
, SDIO_FUNC_1
,
1034 SBSDIO_FUNC1_FRAMECTRL
, SFC_WF_TERM
,
1038 for (i
= 0; i
< 3; i
++) {
1040 hi
= bcmsdh_cfg_read(sdh
, SDIO_FUNC_1
,
1041 SBSDIO_FUNC1_WFRAMEBCHI
,
1043 lo
= bcmsdh_cfg_read(sdh
, SDIO_FUNC_1
,
1044 SBSDIO_FUNC1_WFRAMEBCLO
,
1046 bus
->f1regdata
+= 2;
1047 if ((hi
== 0) && (lo
== 0))
1053 bus
->tx_seq
= (bus
->tx_seq
+ 1) % SDPCM_SEQUENCE_WRAP
;
1055 } while ((ret
< 0) && retrydata
&& retries
++ < TXRETRIES
);
1058 /* restore pkt buffer pointer before calling tx complete routine */
1059 skb_pull(pkt
, SDPCM_HDRLEN
+ pad
);
1060 dhd_os_sdunlock(bus
->dhd
);
1061 dhd_txcomplete(bus
->dhd
, pkt
, ret
!= 0);
1062 dhd_os_sdlock(bus
->dhd
);
1065 pkt_buf_free_skb(pkt
);
1070 int dhd_bus_txdata(struct dhd_bus
*bus
, struct sk_buff
*pkt
)
1072 int ret
= BCME_ERROR
;
1075 DHD_TRACE(("%s: Enter\n", __func__
));
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(pkt
);
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
) >= TXHI
) && 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
) < TXLOW
))
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
= cpu_to_le16((u16
) msglen
);
1285 *(((u16
*) frame
) + 1) = cpu_to_le16(~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 put_unaligned_le32(swheader
, frame
+ SDPCM_FRAMETAG_LEN
);
1294 put_unaligned_le32(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 memcpy(msg
, bus
->rxctl
, 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 memcpy(arg
, &pktgen
, sizeof(pktgen
));
1666 static int dhdsdio_pktgen_set(dhd_bus_t
*bus
, u8
*arg
)
1668 dhd_pktgen_t pktgen
;
1669 uint oldcnt
, oldmode
;
1671 memcpy(&pktgen
, arg
, 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
= le32_to_cpu(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
= le32_to_cpu(sh
->flags
);
1793 sh
->trap_addr
= le32_to_cpu(sh
->trap_addr
);
1794 sh
->assert_exp_addr
= le32_to_cpu(sh
->assert_exp_addr
);
1795 sh
->assert_file_addr
= le32_to_cpu(sh
->assert_file_addr
);
1796 sh
->assert_line
= le32_to_cpu(sh
->assert_line
);
1797 sh
->console_addr
= le32_to_cpu(sh
->console_addr
);
1798 sh
->msgtrace_addr
= le32_to_cpu(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
= le32_to_cpu(c
->log
.buf_size
);
2012 c
->buf
= kmalloc(c
->bufsize
, GFP_ATOMIC
);
2017 idx
= le32_to_cpu(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
= le32_to_cpu(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 memcpy(bus
->vars
, arg
, 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 memcpy(&int_val
, params
, 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 memcpy(arg
, &int_val
, 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 memcpy(arg
, &int_val
, 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 memcpy(arg
, &int_val
, 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 memcpy(arg
, &int_val
, 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 memcpy(arg
, &int_val
, 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 memcpy(arg
, &int_val
, 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 memcpy(&int_val
, (char *)params
+ sizeof(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 memcpy(arg
, &int_val
, val_size
);
2272 case IOV_GVAL(IOV_SDIOD_DRIVE
):
2273 int_val
= (s32
) dhd_sdiod_drive_strength
;
2274 memcpy(arg
, &int_val
, val_size
);
2277 case IOV_SVAL(IOV_SDIOD_DRIVE
):
2278 dhd_sdiod_drive_strength
= int_val
;
2279 si_sdiod_drive_strength_init(bus
->sih
,
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 memcpy(arg
, &int_val
, 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 memcpy(arg
, &int_val
, 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 memcpy(arg
, &int_val
, 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 memcpy(arg
, &int_val
, val_size
);
2328 case IOV_GVAL(IOV_VARS
):
2329 if (bus
->varsz
< (uint
) len
)
2330 memcpy(arg
, bus
->vars
, 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 memcpy(arg
, &int_val
, 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 memcpy(&sdreg
, params
, 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 memcpy(arg
, &int_val
, sizeof(s32
));
2386 case IOV_SVAL(IOV_SBREG
):
2391 memcpy(&sdreg
, params
, 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 memcpy(arg
, &int_val
, 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 memcpy(arg
, &int_val
, 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 memcpy(arg
, &int_val
, 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 memcpy(arg
, &int_val
, 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 memcpy(arg
, &int_val
, 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 dhd_bus_devreset(bus
->dhd
, (u8
) bool_val
);
2486 case IOV_GVAL(IOV_DEVRESET
):
2487 DHD_TRACE(("%s: Called get IOV_DEVRESET\n", __func__
));
2489 /* Get its status */
2490 int_val
= (bool) bus
->dhd
->dongle_reset
;
2491 memcpy(arg
, &int_val
, val_size
);
2496 bcmerror
= BCME_UNSUPPORTED
;
2501 if ((bus
->idletime
== DHD_IDLE_IMMEDIATE
) && !bus
->dpc_sched
) {
2502 bus
->activity
= false;
2503 dhdsdio_clkctl(bus
, CLK_NONE
, true);
2506 dhd_os_sdunlock(bus
->dhd
);
2508 if (actionid
== IOV_SVAL(IOV_DEVRESET
) && bool_val
== false)
2509 dhd_preinit_ioctls((dhd_pub_t
*) bus
->dhd
);
2514 static int dhdsdio_write_vars(dhd_bus_t
*bus
)
2522 char *nvram_ularray
;
2523 #endif /* DHD_DEBUG */
2525 /* Even if there are no vars are to be written, we still
2526 need to set the ramsize. */
2527 varsize
= bus
->varsz
? roundup(bus
->varsz
, 4) : 0;
2528 varaddr
= (bus
->ramsize
- 4) - varsize
;
2531 vbuffer
= kzalloc(varsize
, GFP_ATOMIC
);
2535 memcpy(vbuffer
, bus
->vars
, bus
->varsz
);
2537 /* Write the vars list */
2539 dhdsdio_membytes(bus
, true, varaddr
, vbuffer
, varsize
);
2541 /* Verify NVRAM bytes */
2542 DHD_INFO(("Compare NVRAM dl & ul; varsize=%d\n", varsize
));
2543 nvram_ularray
= kmalloc(varsize
, GFP_ATOMIC
);
2547 /* Upload image to verify downloaded contents. */
2548 memset(nvram_ularray
, 0xaa, varsize
);
2550 /* Read the vars list to temp buffer for comparison */
2552 dhdsdio_membytes(bus
, false, varaddr
, nvram_ularray
,
2555 DHD_ERROR(("%s: error %d on reading %d nvram bytes at "
2556 "0x%08x\n", __func__
, bcmerror
, varsize
, varaddr
));
2558 /* Compare the org NVRAM with the one read from RAM */
2559 if (memcmp(vbuffer
, nvram_ularray
, varsize
)) {
2560 DHD_ERROR(("%s: Downloaded NVRAM image is corrupted.\n",
2563 DHD_ERROR(("%s: Download/Upload/Compare of NVRAM ok.\n",
2566 kfree(nvram_ularray
);
2567 #endif /* DHD_DEBUG */
2572 /* adjust to the user specified RAM */
2573 DHD_INFO(("Physical memory size: %d, usable memory size: %d\n",
2574 bus
->orig_ramsize
, bus
->ramsize
));
2575 DHD_INFO(("Vars are at %d, orig varsize is %d\n", varaddr
, varsize
));
2576 varsize
= ((bus
->orig_ramsize
- 4) - varaddr
);
2579 * Determine the length token:
2580 * Varsize, converted to words, in lower 16-bits, checksum
2586 varsizew
= varsize
/ 4;
2587 varsizew
= (~varsizew
<< 16) | (varsizew
& 0x0000FFFF);
2588 varsizew
= cpu_to_le32(varsizew
);
2591 DHD_INFO(("New varsize is %d, length token=0x%08x\n", varsize
,
2594 /* Write the length token to the last word */
2595 bcmerror
= dhdsdio_membytes(bus
, true, (bus
->orig_ramsize
- 4),
2596 (u8
*)&varsizew
, 4);
2601 static int dhdsdio_download_state(dhd_bus_t
*bus
, bool enter
)
2606 /* To enter download state, disable ARM and reset SOCRAM.
2607 * To exit download state, simply reset ARM (default is RAM boot).
2611 bus
->alp_only
= true;
2613 if (!(si_setcore(bus
->sih
, ARM7S_CORE_ID
, 0)) &&
2614 !(si_setcore(bus
->sih
, ARMCM3_CORE_ID
, 0))) {
2615 DHD_ERROR(("%s: Failed to find ARM core!\n", __func__
));
2616 bcmerror
= BCME_ERROR
;
2620 si_core_disable(bus
->sih
, 0);
2621 if (bcmsdh_regfail(bus
->sdh
)) {
2622 bcmerror
= BCME_SDIO_ERROR
;
2626 if (!(si_setcore(bus
->sih
, SOCRAM_CORE_ID
, 0))) {
2627 DHD_ERROR(("%s: Failed to find SOCRAM core!\n",
2629 bcmerror
= BCME_ERROR
;
2633 si_core_reset(bus
->sih
, 0, 0);
2634 if (bcmsdh_regfail(bus
->sdh
)) {
2635 DHD_ERROR(("%s: Failure trying reset SOCRAM core?\n",
2637 bcmerror
= BCME_SDIO_ERROR
;
2641 /* Clear the top bit of memory */
2644 dhdsdio_membytes(bus
, true, bus
->ramsize
- 4,
2648 if (!(si_setcore(bus
->sih
, SOCRAM_CORE_ID
, 0))) {
2649 DHD_ERROR(("%s: Failed to find SOCRAM core!\n",
2651 bcmerror
= BCME_ERROR
;
2655 if (!si_iscoreup(bus
->sih
)) {
2656 DHD_ERROR(("%s: SOCRAM core is down after reset?\n",
2658 bcmerror
= BCME_ERROR
;
2662 bcmerror
= dhdsdio_write_vars(bus
);
2664 DHD_ERROR(("%s: no vars written to RAM\n", __func__
));
2668 if (!si_setcore(bus
->sih
, PCMCIA_CORE_ID
, 0) &&
2669 !si_setcore(bus
->sih
, SDIOD_CORE_ID
, 0)) {
2670 DHD_ERROR(("%s: Can't change back to SDIO core?\n",
2672 bcmerror
= BCME_ERROR
;
2675 W_SDREG(0xFFFFFFFF, &bus
->regs
->intstatus
, retries
);
2677 if (!(si_setcore(bus
->sih
, ARM7S_CORE_ID
, 0)) &&
2678 !(si_setcore(bus
->sih
, ARMCM3_CORE_ID
, 0))) {
2679 DHD_ERROR(("%s: Failed to find ARM core!\n", __func__
));
2680 bcmerror
= BCME_ERROR
;
2684 si_core_reset(bus
->sih
, 0, 0);
2685 if (bcmsdh_regfail(bus
->sdh
)) {
2686 DHD_ERROR(("%s: Failure trying to reset ARM core?\n",
2688 bcmerror
= BCME_SDIO_ERROR
;
2692 /* Allow HT Clock now that the ARM is running. */
2693 bus
->alp_only
= false;
2695 bus
->dhd
->busstate
= DHD_BUS_LOAD
;
2699 /* Always return to SDIOD core */
2700 if (!si_setcore(bus
->sih
, PCMCIA_CORE_ID
, 0))
2701 si_setcore(bus
->sih
, SDIOD_CORE_ID
, 0);
2707 dhd_bus_iovar_op(dhd_pub_t
*dhdp
, const char *name
,
2708 void *params
, int plen
, void *arg
, int len
, bool set
)
2710 dhd_bus_t
*bus
= dhdp
->bus
;
2711 const bcm_iovar_t
*vi
= NULL
;
2716 DHD_TRACE(("%s: Enter\n", __func__
));
2721 /* Get MUST have return space */
2722 ASSERT(set
|| (arg
&& len
));
2724 /* Set does NOT take qualifiers */
2725 ASSERT(!set
|| (!params
&& !plen
));
2727 /* Look up var locally; if not found pass to host driver */
2728 vi
= bcm_iovar_lookup(dhdsdio_iovars
, name
);
2730 dhd_os_sdlock(bus
->dhd
);
2734 /* Turn on clock in case SD command needs backplane */
2735 dhdsdio_clkctl(bus
, CLK_AVAIL
, false);
2738 bcmsdh_iovar_op(bus
->sdh
, name
, params
, plen
, arg
, len
,
2741 /* Check for bus configuration changes of interest */
2743 /* If it was divisor change, read the new one */
2744 if (set
&& strcmp(name
, "sd_divisor") == 0) {
2745 if (bcmsdh_iovar_op(bus
->sdh
, "sd_divisor", NULL
, 0,
2746 &bus
->sd_divisor
, sizeof(s32
),
2747 false) != BCME_OK
) {
2748 bus
->sd_divisor
= -1;
2749 DHD_ERROR(("%s: fail on %s get\n", __func__
,
2752 DHD_INFO(("%s: noted %s update, value now %d\n",
2753 __func__
, name
, bus
->sd_divisor
));
2756 /* If it was a mode change, read the new one */
2757 if (set
&& strcmp(name
, "sd_mode") == 0) {
2758 if (bcmsdh_iovar_op(bus
->sdh
, "sd_mode", NULL
, 0,
2759 &bus
->sd_mode
, sizeof(s32
),
2760 false) != BCME_OK
) {
2762 DHD_ERROR(("%s: fail on %s get\n", __func__
,
2765 DHD_INFO(("%s: noted %s update, value now %d\n",
2766 __func__
, name
, bus
->sd_mode
));
2769 /* Similar check for blocksize change */
2770 if (set
&& strcmp(name
, "sd_blocksize") == 0) {
2773 (bus
->sdh
, "sd_blocksize", &fnum
, sizeof(s32
),
2774 &bus
->blocksize
, sizeof(s32
),
2775 false) != BCME_OK
) {
2777 DHD_ERROR(("%s: fail on %s get\n", __func__
,
2780 DHD_INFO(("%s: noted %s update, value now %d\n",
2781 __func__
, "sd_blocksize",
2785 bus
->roundup
= min(max_roundup
, bus
->blocksize
);
2787 if ((bus
->idletime
== DHD_IDLE_IMMEDIATE
) && !bus
->dpc_sched
) {
2788 bus
->activity
= false;
2789 dhdsdio_clkctl(bus
, CLK_NONE
, true);
2792 dhd_os_sdunlock(bus
->dhd
);
2796 DHD_CTL(("%s: %s %s, len %d plen %d\n", __func__
,
2797 name
, (set
? "set" : "get"), len
, plen
));
2799 /* set up 'params' pointer in case this is a set command so that
2800 * the convenience int and bool code can be common to set and get
2802 if (params
== NULL
) {
2807 if (vi
->type
== IOVT_VOID
)
2809 else if (vi
->type
== IOVT_BUFFER
)
2812 /* all other types are integer sized */
2813 val_size
= sizeof(int);
2815 actionid
= set
? IOV_SVAL(vi
->varid
) : IOV_GVAL(vi
->varid
);
2817 dhdsdio_doiovar(bus
, vi
, actionid
, name
, params
, plen
, arg
, len
,
2824 void dhd_bus_stop(struct dhd_bus
*bus
, bool enforce_mutex
)
2826 u32 local_hostintmask
;
2831 DHD_TRACE(("%s: Enter\n", __func__
));
2834 dhd_os_sdlock(bus
->dhd
);
2838 /* Enable clock for device interrupts */
2839 dhdsdio_clkctl(bus
, CLK_AVAIL
, false);
2841 /* Disable and clear interrupts at the chip level also */
2842 W_SDREG(0, &bus
->regs
->hostintmask
, retries
);
2843 local_hostintmask
= bus
->hostintmask
;
2844 bus
->hostintmask
= 0;
2846 /* Change our idea of bus state */
2847 bus
->dhd
->busstate
= DHD_BUS_DOWN
;
2849 /* Force clocks on backplane to be sure F2 interrupt propagates */
2851 bcmsdh_cfg_read(bus
->sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_CHIPCLKCSR
,
2854 bcmsdh_cfg_write(bus
->sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_CHIPCLKCSR
,
2855 (saveclk
| SBSDIO_FORCE_HT
), &err
);
2858 DHD_ERROR(("%s: Failed to force clock for F2: err %d\n",
2862 /* Turn off the bus (F2), free any pending packets */
2863 DHD_INTR(("%s: disable SDIO interrupts\n", __func__
));
2864 bcmsdh_intr_disable(bus
->sdh
);
2865 bcmsdh_cfg_write(bus
->sdh
, SDIO_FUNC_0
, SDIOD_CCCR_IOEN
,
2866 SDIO_FUNC_ENABLE_1
, NULL
);
2868 /* Clear any pending interrupts now that F2 is disabled */
2869 W_SDREG(local_hostintmask
, &bus
->regs
->intstatus
, retries
);
2871 /* Turn off the backplane clock (only) */
2872 dhdsdio_clkctl(bus
, CLK_SDONLY
, false);
2874 /* Clear the data packet queues */
2875 pktq_flush(&bus
->txq
, true);
2877 /* Clear any held glomming stuff */
2879 pkt_buf_free_skb(bus
->glomd
);
2882 pkt_buf_free_skb(bus
->glom
);
2884 bus
->glom
= bus
->glomd
= NULL
;
2886 /* Clear rx control and wake any waiters */
2888 dhd_os_ioctl_resp_wake(bus
->dhd
);
2890 /* Reset some F2 state stuff */
2891 bus
->rxskip
= false;
2892 bus
->tx_seq
= bus
->rx_seq
= 0;
2895 dhd_os_sdunlock(bus
->dhd
);
2898 int dhd_bus_init(dhd_pub_t
*dhdp
, bool enforce_mutex
)
2900 dhd_bus_t
*bus
= dhdp
->bus
;
2907 DHD_TRACE(("%s: Enter\n", __func__
));
2914 dhd_os_sdlock(bus
->dhd
);
2916 /* Make sure backplane clock is on, needed to generate F2 interrupt */
2917 dhdsdio_clkctl(bus
, CLK_AVAIL
, false);
2918 if (bus
->clkstate
!= CLK_AVAIL
)
2921 /* Force clocks on backplane to be sure F2 interrupt propagates */
2923 bcmsdh_cfg_read(bus
->sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_CHIPCLKCSR
,
2926 bcmsdh_cfg_write(bus
->sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_CHIPCLKCSR
,
2927 (saveclk
| SBSDIO_FORCE_HT
), &err
);
2930 DHD_ERROR(("%s: Failed to force clock for F2: err %d\n",
2935 /* Enable function 2 (frame transfers) */
2936 W_SDREG((SDPCM_PROT_VERSION
<< SMB_DATA_VERSION_SHIFT
),
2937 &bus
->regs
->tosbmailboxdata
, retries
);
2938 enable
= (SDIO_FUNC_ENABLE_1
| SDIO_FUNC_ENABLE_2
);
2940 bcmsdh_cfg_write(bus
->sdh
, SDIO_FUNC_0
, SDIOD_CCCR_IOEN
, enable
, NULL
);
2942 /* Give the dongle some time to do its thing and set IOR2 */
2943 dhd_timeout_start(&tmo
, DHD_WAIT_F2RDY
* 1000);
2946 while (ready
!= enable
&& !dhd_timeout_expired(&tmo
))
2948 bcmsdh_cfg_read(bus
->sdh
, SDIO_FUNC_0
, SDIOD_CCCR_IORDY
,
2951 DHD_INFO(("%s: enable 0x%02x, ready 0x%02x (waited %uus)\n",
2952 __func__
, enable
, ready
, tmo
.elapsed
));
2954 /* If F2 successfully enabled, set core and enable interrupts */
2955 if (ready
== enable
) {
2956 /* Make sure we're talking to the core. */
2957 bus
->regs
= si_setcore(bus
->sih
, PCMCIA_CORE_ID
, 0);
2959 bus
->regs
= si_setcore(bus
->sih
, SDIOD_CORE_ID
, 0);
2961 /* Set up the interrupt mask and enable interrupts */
2962 bus
->hostintmask
= HOSTINTMASK
;
2963 W_SDREG(bus
->hostintmask
, &bus
->regs
->hostintmask
, retries
);
2965 bcmsdh_cfg_write(bus
->sdh
, SDIO_FUNC_1
, SBSDIO_WATERMARK
,
2966 (u8
) watermark
, &err
);
2968 /* Set bus state according to enable result */
2969 dhdp
->busstate
= DHD_BUS_DATA
;
2971 /* bcmsdh_intr_unmask(bus->sdh); */
2973 bus
->intdis
= false;
2975 DHD_INTR(("%s: enable SDIO device interrupts\n",
2977 bcmsdh_intr_enable(bus
->sdh
);
2979 DHD_INTR(("%s: disable SDIO interrupts\n", __func__
));
2980 bcmsdh_intr_disable(bus
->sdh
);
2986 /* Disable F2 again */
2987 enable
= SDIO_FUNC_ENABLE_1
;
2988 bcmsdh_cfg_write(bus
->sdh
, SDIO_FUNC_0
, SDIOD_CCCR_IOEN
, enable
,
2992 /* Restore previous clock setting */
2993 bcmsdh_cfg_write(bus
->sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_CHIPCLKCSR
,
2996 /* If we didn't come up, turn off backplane clock */
2997 if (dhdp
->busstate
!= DHD_BUS_DATA
)
2998 dhdsdio_clkctl(bus
, CLK_NONE
, false);
3002 dhd_os_sdunlock(bus
->dhd
);
3007 static void dhdsdio_rxfail(dhd_bus_t
*bus
, bool abort
, bool rtx
)
3009 bcmsdh_info_t
*sdh
= bus
->sdh
;
3010 sdpcmd_regs_t
*regs
= bus
->regs
;
3016 DHD_ERROR(("%s: %sterminate frame%s\n", __func__
,
3017 (abort
? "abort command, " : ""),
3018 (rtx
? ", send NAK" : "")));
3021 bcmsdh_abort(sdh
, SDIO_FUNC_2
);
3023 bcmsdh_cfg_write(sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_FRAMECTRL
, SFC_RF_TERM
,
3027 /* Wait until the packet has been flushed (device/FIFO stable) */
3028 for (lastrbc
= retries
= 0xffff; retries
> 0; retries
--) {
3029 hi
= bcmsdh_cfg_read(sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_RFRAMEBCHI
,
3031 lo
= bcmsdh_cfg_read(sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_RFRAMEBCLO
,
3033 bus
->f1regdata
+= 2;
3035 if ((hi
== 0) && (lo
== 0))
3038 if ((hi
> (lastrbc
>> 8)) && (lo
> (lastrbc
& 0x00ff))) {
3039 DHD_ERROR(("%s: count growing: last 0x%04x now "
3041 __func__
, lastrbc
, ((hi
<< 8) + lo
)));
3043 lastrbc
= (hi
<< 8) + lo
;
3047 DHD_ERROR(("%s: count never zeroed: last 0x%04x\n",
3048 __func__
, lastrbc
));
3050 DHD_INFO(("%s: flush took %d iterations\n", __func__
,
3051 (0xffff - retries
)));
3056 W_SDREG(SMB_NAK
, ®s
->tosbmailbox
, retries
);
3058 if (retries
<= retry_limit
)
3062 /* Clear partial in any case */
3065 /* If we can't reach the device, signal failure */
3066 if (err
|| bcmsdh_regfail(sdh
))
3067 bus
->dhd
->busstate
= DHD_BUS_DOWN
;
3071 dhdsdio_read_control(dhd_bus_t
*bus
, u8
*hdr
, uint len
, uint doff
)
3073 bcmsdh_info_t
*sdh
= bus
->sdh
;
3078 DHD_TRACE(("%s: Enter\n", __func__
));
3080 /* Control data already received in aligned rxctl */
3081 if ((bus
->bus
== SPI_BUS
) && (!bus
->usebufpool
))
3085 /* Set rxctl for frame (w/optional alignment) */
3086 bus
->rxctl
= bus
->rxbuf
;
3088 bus
->rxctl
+= firstread
;
3089 pad
= ((unsigned long)bus
->rxctl
% DHD_SDALIGN
);
3091 bus
->rxctl
+= (DHD_SDALIGN
- pad
);
3092 bus
->rxctl
-= firstread
;
3094 ASSERT(bus
->rxctl
>= bus
->rxbuf
);
3096 /* Copy the already-read portion over */
3097 memcpy(bus
->rxctl
, hdr
, firstread
);
3098 if (len
<= firstread
)
3101 /* Copy the full data pkt in gSPI case and process ioctl. */
3102 if (bus
->bus
== SPI_BUS
) {
3103 memcpy(bus
->rxctl
, hdr
, len
);
3107 /* Raise rdlen to next SDIO block to avoid tail command */
3108 rdlen
= len
- firstread
;
3109 if (bus
->roundup
&& bus
->blocksize
&& (rdlen
> bus
->blocksize
)) {
3110 pad
= bus
->blocksize
- (rdlen
% bus
->blocksize
);
3111 if ((pad
<= bus
->roundup
) && (pad
< bus
->blocksize
) &&
3112 ((len
+ pad
) < bus
->dhd
->maxctl
))
3114 } else if (rdlen
% DHD_SDALIGN
) {
3115 rdlen
+= DHD_SDALIGN
- (rdlen
% DHD_SDALIGN
);
3118 /* Satisfy length-alignment requirements */
3119 if (forcealign
&& (rdlen
& (ALIGNMENT
- 1)))
3120 rdlen
= roundup(rdlen
, ALIGNMENT
);
3122 /* Drop if the read is too big or it exceeds our maximum */
3123 if ((rdlen
+ firstread
) > bus
->dhd
->maxctl
) {
3124 DHD_ERROR(("%s: %d-byte control read exceeds %d-byte buffer\n",
3125 __func__
, rdlen
, bus
->dhd
->maxctl
));
3126 bus
->dhd
->rx_errors
++;
3127 dhdsdio_rxfail(bus
, false, false);
3131 if ((len
- doff
) > bus
->dhd
->maxctl
) {
3132 DHD_ERROR(("%s: %d-byte ctl frame (%d-byte ctl data) exceeds "
3134 __func__
, len
, (len
- doff
), bus
->dhd
->maxctl
));
3135 bus
->dhd
->rx_errors
++;
3137 dhdsdio_rxfail(bus
, false, false);
3141 /* Read remainder of frame body into the rxctl buffer */
3143 dhd_bcmsdh_recv_buf(bus
, bcmsdh_cur_sbwad(sdh
), SDIO_FUNC_2
, F2SYNC
,
3144 (bus
->rxctl
+ firstread
), rdlen
, NULL
, NULL
,
3147 ASSERT(sdret
!= BCME_PENDING
);
3149 /* Control frame failures need retransmission */
3151 DHD_ERROR(("%s: read %d control bytes failed: %d\n",
3152 __func__
, rdlen
, sdret
));
3153 bus
->rxc_errors
++; /* dhd.rx_ctlerrs is higher level */
3154 dhdsdio_rxfail(bus
, true, true);
3161 if (DHD_BYTES_ON() && DHD_CTL_ON())
3162 prhex("RxCtrl", bus
->rxctl
, len
);
3165 /* Point to valid data and indicate its length */
3167 bus
->rxlen
= len
- doff
;
3170 /* Awake any waiters */
3171 dhd_os_ioctl_resp_wake(bus
->dhd
);
3174 static u8
dhdsdio_rxglom(dhd_bus_t
*bus
, u8 rxseq
)
3180 struct sk_buff
*pfirst
, *plast
, *pnext
, *save_pfirst
;
3183 u8 chan
, seq
, doff
, sfdoff
;
3187 bool usechain
= bus
->use_rxchain
;
3189 /* If packets, issue read(s) and send up packet chain */
3190 /* Return sequence numbers consumed? */
3192 DHD_TRACE(("dhdsdio_rxglom: start: glomd %p glom %p\n", bus
->glomd
,
3195 /* If there's a descriptor, generate the packet chain */
3197 dhd_os_sdlock_rxq(bus
->dhd
);
3199 pfirst
= plast
= pnext
= NULL
;
3200 dlen
= (u16
) (bus
->glomd
->len
);
3201 dptr
= bus
->glomd
->data
;
3202 if (!dlen
|| (dlen
& 1)) {
3203 DHD_ERROR(("%s: bad glomd len(%d), ignore descriptor\n",
3208 for (totlen
= num
= 0; dlen
; num
++) {
3209 /* Get (and move past) next length */
3210 sublen
= get_unaligned_le16(dptr
);
3211 dlen
-= sizeof(u16
);
3212 dptr
+= sizeof(u16
);
3213 if ((sublen
< SDPCM_HDRLEN
) ||
3214 ((num
== 0) && (sublen
< (2 * SDPCM_HDRLEN
)))) {
3215 DHD_ERROR(("%s: descriptor len %d bad: %d\n",
3216 __func__
, num
, sublen
));
3220 if (sublen
% DHD_SDALIGN
) {
3221 DHD_ERROR(("%s: sublen %d not multiple of %d\n",
3222 __func__
, sublen
, DHD_SDALIGN
));
3227 /* For last frame, adjust read len so total
3228 is a block multiple */
3231 (roundup(totlen
, bus
->blocksize
) - totlen
);
3232 totlen
= roundup(totlen
, bus
->blocksize
);
3235 /* Allocate/chain packet for next subframe */
3236 pnext
= pkt_buf_get_skb(sublen
+ DHD_SDALIGN
);
3237 if (pnext
== NULL
) {
3238 DHD_ERROR(("%s: pkt_buf_get_skb failed, num %d len %d\n",
3239 __func__
, num
, sublen
));
3242 ASSERT(!(pnext
->prev
));
3245 pfirst
= plast
= pnext
;
3248 plast
->next
= pnext
;
3252 /* Adhere to start alignment requirements */
3253 PKTALIGN(pnext
, sublen
, DHD_SDALIGN
);
3256 /* If all allocations succeeded, save packet chain
3259 DHD_GLOM(("%s: allocated %d-byte packet chain for %d "
3260 "subframes\n", __func__
, totlen
, num
));
3261 if (DHD_GLOM_ON() && bus
->nextlen
) {
3262 if (totlen
!= bus
->nextlen
) {
3263 DHD_GLOM(("%s: glomdesc mismatch: nextlen %d glomdesc %d " "rxseq %d\n",
3264 __func__
, bus
->nextlen
,
3269 pfirst
= pnext
= NULL
;
3272 pkt_buf_free_skb(pfirst
);
3277 /* Done with descriptor packet */
3278 pkt_buf_free_skb(bus
->glomd
);
3282 dhd_os_sdunlock_rxq(bus
->dhd
);
3285 /* Ok -- either we just generated a packet chain,
3286 or had one from before */
3288 if (DHD_GLOM_ON()) {
3289 DHD_GLOM(("%s: try superframe read, packet chain:\n",
3291 for (pnext
= bus
->glom
; pnext
; pnext
= pnext
->next
) {
3292 DHD_GLOM((" %p: %p len 0x%04x (%d)\n",
3293 pnext
, (u8
*) (pnext
->data
),
3294 pnext
->len
, pnext
->len
));
3299 dlen
= (u16
) pkttotlen(pfirst
);
3301 /* Do an SDIO read for the superframe. Configurable iovar to
3302 * read directly into the chained packet, or allocate a large
3303 * packet and and copy into the chain.
3306 errcode
= dhd_bcmsdh_recv_buf(bus
,
3308 (bus
->sdh
), SDIO_FUNC_2
,
3310 (u8
*) pfirst
->data
,
3311 dlen
, pfirst
, NULL
, NULL
);
3312 } else if (bus
->dataptr
) {
3313 errcode
= dhd_bcmsdh_recv_buf(bus
,
3315 (bus
->sdh
), SDIO_FUNC_2
,
3316 F2SYNC
, bus
->dataptr
,
3317 dlen
, NULL
, NULL
, NULL
);
3319 (u16
) pktfrombuf(pfirst
, 0, dlen
,
3321 if (sublen
!= dlen
) {
3322 DHD_ERROR(("%s: FAILED TO COPY, dlen %d sublen %d\n",
3323 __func__
, dlen
, sublen
));
3328 DHD_ERROR(("COULDN'T ALLOC %d-BYTE GLOM, FORCE FAILURE\n",
3333 ASSERT(errcode
!= BCME_PENDING
);
3335 /* On failure, kill the superframe, allow a couple retries */
3337 DHD_ERROR(("%s: glom read of %d bytes failed: %d\n",
3338 __func__
, dlen
, errcode
));
3339 bus
->dhd
->rx_errors
++;
3341 if (bus
->glomerr
++ < 3) {
3342 dhdsdio_rxfail(bus
, true, true);
3345 dhdsdio_rxfail(bus
, true, false);
3346 dhd_os_sdlock_rxq(bus
->dhd
);
3347 pkt_buf_free_skb(bus
->glom
);
3348 dhd_os_sdunlock_rxq(bus
->dhd
);
3355 if (DHD_GLOM_ON()) {
3356 prhex("SUPERFRAME", pfirst
->data
,
3357 min_t(int, pfirst
->len
, 48));
3361 /* Validate the superframe header */
3362 dptr
= (u8
*) (pfirst
->data
);
3363 sublen
= get_unaligned_le16(dptr
);
3364 check
= get_unaligned_le16(dptr
+ sizeof(u16
));
3366 chan
= SDPCM_PACKET_CHANNEL(&dptr
[SDPCM_FRAMETAG_LEN
]);
3367 seq
= SDPCM_PACKET_SEQUENCE(&dptr
[SDPCM_FRAMETAG_LEN
]);
3368 bus
->nextlen
= dptr
[SDPCM_FRAMETAG_LEN
+ SDPCM_NEXTLEN_OFFSET
];
3369 if ((bus
->nextlen
<< 4) > MAX_RX_DATASZ
) {
3370 DHD_INFO(("%s: nextlen too large (%d) seq %d\n",
3371 __func__
, bus
->nextlen
, seq
));
3374 doff
= SDPCM_DOFFSET_VALUE(&dptr
[SDPCM_FRAMETAG_LEN
]);
3375 txmax
= SDPCM_WINDOW_VALUE(&dptr
[SDPCM_FRAMETAG_LEN
]);
3378 if ((u16
)~(sublen
^ check
)) {
3379 DHD_ERROR(("%s (superframe): HW hdr error: len/check "
3380 "0x%04x/0x%04x\n", __func__
, sublen
, check
));
3382 } else if (roundup(sublen
, bus
->blocksize
) != dlen
) {
3383 DHD_ERROR(("%s (superframe): len 0x%04x, rounded "
3384 "0x%04x, expect 0x%04x\n",
3386 roundup(sublen
, bus
->blocksize
), dlen
));
3388 } else if (SDPCM_PACKET_CHANNEL(&dptr
[SDPCM_FRAMETAG_LEN
]) !=
3389 SDPCM_GLOM_CHANNEL
) {
3390 DHD_ERROR(("%s (superframe): bad channel %d\n",
3392 SDPCM_PACKET_CHANNEL(&dptr
3393 [SDPCM_FRAMETAG_LEN
])));
3395 } else if (SDPCM_GLOMDESC(&dptr
[SDPCM_FRAMETAG_LEN
])) {
3396 DHD_ERROR(("%s (superframe): got second descriptor?\n",
3399 } else if ((doff
< SDPCM_HDRLEN
) ||
3400 (doff
> (pfirst
->len
- SDPCM_HDRLEN
))) {
3401 DHD_ERROR(("%s (superframe): Bad data offset %d: HW %d "
3403 __func__
, doff
, sublen
,
3404 pfirst
->len
, SDPCM_HDRLEN
));
3408 /* Check sequence number of superframe SW header */
3410 DHD_INFO(("%s: (superframe) rx_seq %d, expected %d\n",
3411 __func__
, seq
, rxseq
));
3416 /* Check window for sanity */
3417 if ((u8
) (txmax
- bus
->tx_seq
) > 0x40) {
3418 DHD_ERROR(("%s: unlikely tx max %d with tx_seq %d\n",
3419 __func__
, txmax
, bus
->tx_seq
));
3420 txmax
= bus
->tx_seq
+ 2;
3422 bus
->tx_max
= txmax
;
3424 /* Remove superframe header, remember offset */
3425 skb_pull(pfirst
, doff
);
3428 /* Validate all the subframe headers */
3429 for (num
= 0, pnext
= pfirst
; pnext
&& !errcode
;
3430 num
++, pnext
= pnext
->next
) {
3431 dptr
= (u8
*) (pnext
->data
);
3432 dlen
= (u16
) (pnext
->len
);
3433 sublen
= get_unaligned_le16(dptr
);
3434 check
= get_unaligned_le16(dptr
+ sizeof(u16
));
3435 chan
= SDPCM_PACKET_CHANNEL(&dptr
[SDPCM_FRAMETAG_LEN
]);
3436 doff
= SDPCM_DOFFSET_VALUE(&dptr
[SDPCM_FRAMETAG_LEN
]);
3439 prhex("subframe", dptr
, 32);
3442 if ((u16
)~(sublen
^ check
)) {
3443 DHD_ERROR(("%s (subframe %d): HW hdr error: "
3444 "len/check 0x%04x/0x%04x\n",
3445 __func__
, num
, sublen
, check
));
3447 } else if ((sublen
> dlen
) || (sublen
< SDPCM_HDRLEN
)) {
3448 DHD_ERROR(("%s (subframe %d): length mismatch: "
3449 "len 0x%04x, expect 0x%04x\n",
3450 __func__
, num
, sublen
, dlen
));
3452 } else if ((chan
!= SDPCM_DATA_CHANNEL
) &&
3453 (chan
!= SDPCM_EVENT_CHANNEL
)) {
3454 DHD_ERROR(("%s (subframe %d): bad channel %d\n",
3455 __func__
, num
, chan
));
3457 } else if ((doff
< SDPCM_HDRLEN
) || (doff
> sublen
)) {
3458 DHD_ERROR(("%s (subframe %d): Bad data offset %d: HW %d min %d\n",
3459 __func__
, num
, doff
, sublen
,
3466 /* Terminate frame on error, request
3468 if (bus
->glomerr
++ < 3) {
3469 /* Restore superframe header space */
3470 skb_push(pfirst
, sfdoff
);
3471 dhdsdio_rxfail(bus
, true, true);
3474 dhdsdio_rxfail(bus
, true, false);
3475 dhd_os_sdlock_rxq(bus
->dhd
);
3476 pkt_buf_free_skb(bus
->glom
);
3477 dhd_os_sdunlock_rxq(bus
->dhd
);
3485 /* Basic SD framing looks ok - process each packet (header) */
3486 save_pfirst
= pfirst
;
3490 dhd_os_sdlock_rxq(bus
->dhd
);
3491 for (num
= 0; pfirst
; rxseq
++, pfirst
= pnext
) {
3492 pnext
= pfirst
->next
;
3493 pfirst
->next
= NULL
;
3495 dptr
= (u8
*) (pfirst
->data
);
3496 sublen
= get_unaligned_le16(dptr
);
3497 chan
= SDPCM_PACKET_CHANNEL(&dptr
[SDPCM_FRAMETAG_LEN
]);
3498 seq
= SDPCM_PACKET_SEQUENCE(&dptr
[SDPCM_FRAMETAG_LEN
]);
3499 doff
= SDPCM_DOFFSET_VALUE(&dptr
[SDPCM_FRAMETAG_LEN
]);
3501 DHD_GLOM(("%s: Get subframe %d, %p(%p/%d), sublen %d "
3503 __func__
, num
, pfirst
, pfirst
->data
,
3504 pfirst
->len
, sublen
, chan
, seq
));
3506 ASSERT((chan
== SDPCM_DATA_CHANNEL
)
3507 || (chan
== SDPCM_EVENT_CHANNEL
));
3510 DHD_GLOM(("%s: rx_seq %d, expected %d\n",
3511 __func__
, seq
, rxseq
));
3516 if (DHD_BYTES_ON() && DHD_DATA_ON())
3517 prhex("Rx Subframe Data", dptr
, dlen
);
3520 __skb_trim(pfirst
, sublen
);
3521 skb_pull(pfirst
, doff
);
3523 if (pfirst
->len
== 0) {
3524 pkt_buf_free_skb(pfirst
);
3526 plast
->next
= pnext
;
3528 ASSERT(save_pfirst
== pfirst
);
3529 save_pfirst
= pnext
;
3532 } else if (dhd_prot_hdrpull(bus
->dhd
, &ifidx
, pfirst
) !=
3534 DHD_ERROR(("%s: rx protocol error\n",
3536 bus
->dhd
->rx_errors
++;
3537 pkt_buf_free_skb(pfirst
);
3539 plast
->next
= pnext
;
3541 ASSERT(save_pfirst
== pfirst
);
3542 save_pfirst
= pnext
;
3547 /* this packet will go up, link back into
3548 chain and count it */
3549 pfirst
->next
= pnext
;
3554 if (DHD_GLOM_ON()) {
3555 DHD_GLOM(("%s subframe %d to stack, %p(%p/%d) "
3557 __func__
, num
, pfirst
, pfirst
->data
,
3558 pfirst
->len
, pfirst
->next
,
3560 prhex("", (u8
*) pfirst
->data
,
3561 min_t(int, pfirst
->len
, 32));
3563 #endif /* DHD_DEBUG */
3565 dhd_os_sdunlock_rxq(bus
->dhd
);
3567 dhd_os_sdunlock(bus
->dhd
);
3568 dhd_rx_frame(bus
->dhd
, ifidx
, save_pfirst
, num
);
3569 dhd_os_sdlock(bus
->dhd
);
3572 bus
->rxglomframes
++;
3573 bus
->rxglompkts
+= num
;
3578 /* Return true if there may be more frames to read */
3579 static uint
dhdsdio_readframes(dhd_bus_t
*bus
, uint maxframes
, bool *finished
)
3581 bcmsdh_info_t
*sdh
= bus
->sdh
;
3583 u16 len
, check
; /* Extracted hardware header fields */
3584 u8 chan
, seq
, doff
; /* Extracted software header fields */
3585 u8 fcbits
; /* Extracted fcbits from software header */
3588 struct sk_buff
*pkt
; /* Packet for event or data frames */
3589 u16 pad
; /* Number of pad bytes to read */
3590 u16 rdlen
; /* Total number of bytes to read */
3591 u8 rxseq
; /* Next sequence number to expect */
3592 uint rxleft
= 0; /* Remaining number of frames allowed */
3593 int sdret
; /* Return code from bcmsdh calls */
3594 u8 txmax
; /* Maximum tx sequence offered */
3595 bool len_consistent
; /* Result of comparing readahead len and
3599 uint rxcount
= 0; /* Total frames read */
3601 #if defined(DHD_DEBUG) || defined(SDTEST)
3602 bool sdtest
= false; /* To limit message spew from test mode */
3605 DHD_TRACE(("%s: Enter\n", __func__
));
3610 /* Allow pktgen to override maxframes */
3611 if (bus
->pktgen_count
&& (bus
->pktgen_mode
== DHD_PKTGEN_RECV
)) {
3612 maxframes
= bus
->pktgen_count
;
3617 /* Not finished unless we encounter no more frames indication */
3620 for (rxseq
= bus
->rx_seq
, rxleft
= maxframes
;
3621 !bus
->rxskip
&& rxleft
&& bus
->dhd
->busstate
!= DHD_BUS_DOWN
;
3622 rxseq
++, rxleft
--) {
3624 /* Handle glomming separately */
3625 if (bus
->glom
|| bus
->glomd
) {
3627 DHD_GLOM(("%s: calling rxglom: glomd %p, glom %p\n",
3628 __func__
, bus
->glomd
, bus
->glom
));
3629 cnt
= dhdsdio_rxglom(bus
, rxseq
);
3630 DHD_GLOM(("%s: rxglom returned %d\n", __func__
, cnt
));
3632 rxleft
= (rxleft
> cnt
) ? (rxleft
- cnt
) : 1;
3636 /* Try doing single read if we can */
3637 if (dhd_readahead
&& bus
->nextlen
) {
3638 u16 nextlen
= bus
->nextlen
;
3641 if (bus
->bus
== SPI_BUS
) {
3642 rdlen
= len
= nextlen
;
3644 rdlen
= len
= nextlen
<< 4;
3646 /* Pad read to blocksize for efficiency */
3647 if (bus
->roundup
&& bus
->blocksize
3648 && (rdlen
> bus
->blocksize
)) {
3651 (rdlen
% bus
->blocksize
);
3652 if ((pad
<= bus
->roundup
)
3653 && (pad
< bus
->blocksize
)
3654 && ((rdlen
+ pad
+ firstread
) <
3657 } else if (rdlen
% DHD_SDALIGN
) {
3659 DHD_SDALIGN
- (rdlen
% DHD_SDALIGN
);
3663 /* We use bus->rxctl buffer in WinXP for initial
3664 * control pkt receives.
3665 * Later we use buffer-poll for data as well
3666 * as control packets.
3667 * This is required becuase dhd receives full
3668 * frame in gSPI unlike SDIO.
3669 * After the frame is received we have to
3670 * distinguish whether it is data
3671 * or non-data frame.
3673 /* Allocate a packet buffer */
3674 dhd_os_sdlock_rxq(bus
->dhd
);
3675 pkt
= pkt_buf_get_skb(rdlen
+ DHD_SDALIGN
);
3677 if (bus
->bus
== SPI_BUS
) {
3678 bus
->usebufpool
= false;
3679 bus
->rxctl
= bus
->rxbuf
;
3681 bus
->rxctl
+= firstread
;
3682 pad
= ((unsigned long)bus
->rxctl
%
3686 (DHD_SDALIGN
- pad
);
3687 bus
->rxctl
-= firstread
;
3689 ASSERT(bus
->rxctl
>= bus
->rxbuf
);
3691 /* Read the entire frame */
3692 sdret
= dhd_bcmsdh_recv_buf(bus
,
3701 ASSERT(sdret
!= BCME_PENDING
);
3703 /* Control frame failures need
3706 DHD_ERROR(("%s: read %d control bytes failed: %d\n",
3709 /* dhd.rx_ctlerrs is higher */
3711 dhd_os_sdunlock_rxq(bus
->dhd
);
3712 dhdsdio_rxfail(bus
, true,
3720 request rtx of events */
3721 DHD_ERROR(("%s (nextlen): pkt_buf_get_skb failed: len %d rdlen %d " "expected rxseq %d\n",
3722 __func__
, len
, rdlen
, rxseq
));
3723 /* Just go try again w/normal
3725 dhd_os_sdunlock_rxq(bus
->dhd
);
3729 if (bus
->bus
== SPI_BUS
)
3730 bus
->usebufpool
= true;
3732 ASSERT(!(pkt
->prev
));
3733 PKTALIGN(pkt
, rdlen
, DHD_SDALIGN
);
3734 rxbuf
= (u8
*) (pkt
->data
);
3735 /* Read the entire frame */
3737 dhd_bcmsdh_recv_buf(bus
,
3738 bcmsdh_cur_sbwad(sdh
),
3739 SDIO_FUNC_2
, F2SYNC
,
3740 rxbuf
, rdlen
, pkt
, NULL
,
3743 ASSERT(sdret
!= BCME_PENDING
);
3746 DHD_ERROR(("%s (nextlen): read %d bytes failed: %d\n",
3747 __func__
, rdlen
, sdret
));
3748 pkt_buf_free_skb(pkt
);
3749 bus
->dhd
->rx_errors
++;
3750 dhd_os_sdunlock_rxq(bus
->dhd
);
3751 /* Force retry w/normal header read.
3752 * Don't attemp NAK for
3755 dhdsdio_rxfail(bus
, true,
3762 dhd_os_sdunlock_rxq(bus
->dhd
);
3764 /* Now check the header */
3765 memcpy(bus
->rxhdr
, rxbuf
, SDPCM_HDRLEN
);
3767 /* Extract hardware header fields */
3768 len
= get_unaligned_le16(bus
->rxhdr
);
3769 check
= get_unaligned_le16(bus
->rxhdr
+ sizeof(u16
));
3771 /* All zeros means readahead info was bad */
3772 if (!(len
| check
)) {
3773 DHD_INFO(("%s (nextlen): read zeros in HW "
3774 "header???\n", __func__
));
3775 dhd_os_sdlock_rxq(bus
->dhd
);
3777 dhd_os_sdunlock_rxq(bus
->dhd
);
3778 GSPI_PR55150_BAILOUT
;
3782 /* Validate check bytes */
3783 if ((u16
)~(len
^ check
)) {
3784 DHD_ERROR(("%s (nextlen): HW hdr error: nextlen/len/check" " 0x%04x/0x%04x/0x%04x\n",
3785 __func__
, nextlen
, len
, check
));
3786 dhd_os_sdlock_rxq(bus
->dhd
);
3788 dhd_os_sdunlock_rxq(bus
->dhd
);
3790 dhdsdio_rxfail(bus
, false, false);
3791 GSPI_PR55150_BAILOUT
;
3795 /* Validate frame length */
3796 if (len
< SDPCM_HDRLEN
) {
3797 DHD_ERROR(("%s (nextlen): HW hdr length "
3798 "invalid: %d\n", __func__
, len
));
3799 dhd_os_sdlock_rxq(bus
->dhd
);
3801 dhd_os_sdunlock_rxq(bus
->dhd
);
3802 GSPI_PR55150_BAILOUT
;
3806 /* Check for consistency withreadahead info */
3807 len_consistent
= (nextlen
!= (roundup(len
, 16) >> 4));
3808 if (len_consistent
) {
3809 /* Mismatch, force retry w/normal
3810 header (may be >4K) */
3811 DHD_ERROR(("%s (nextlen): mismatch, nextlen %d len %d rnd %d; " "expected rxseq %d\n",
3813 len
, roundup(len
, 16), rxseq
));
3814 dhd_os_sdlock_rxq(bus
->dhd
);
3816 dhd_os_sdunlock_rxq(bus
->dhd
);
3817 dhdsdio_rxfail(bus
, true,
3819 SPI_BUS
) ? false : true);
3820 GSPI_PR55150_BAILOUT
;
3824 /* Extract software header fields */
3826 SDPCM_PACKET_CHANNEL(&bus
->rxhdr
3827 [SDPCM_FRAMETAG_LEN
]);
3829 SDPCM_PACKET_SEQUENCE(&bus
->rxhdr
3830 [SDPCM_FRAMETAG_LEN
]);
3832 SDPCM_DOFFSET_VALUE(&bus
->rxhdr
3833 [SDPCM_FRAMETAG_LEN
]);
3835 SDPCM_WINDOW_VALUE(&bus
->rxhdr
[SDPCM_FRAMETAG_LEN
]);
3838 bus
->rxhdr
[SDPCM_FRAMETAG_LEN
+
3839 SDPCM_NEXTLEN_OFFSET
];
3840 if ((bus
->nextlen
<< 4) > MAX_RX_DATASZ
) {
3841 DHD_INFO(("%s (nextlen): got frame w/nextlen too large" " (%d), seq %d\n",
3842 __func__
, bus
->nextlen
, seq
));
3846 bus
->dhd
->rx_readahead_cnt
++;
3847 /* Handle Flow Control */
3849 SDPCM_FCMASK_VALUE(&bus
->rxhdr
[SDPCM_FRAMETAG_LEN
]);
3852 if (~bus
->flowcontrol
& fcbits
) {
3856 if (bus
->flowcontrol
& ~fcbits
) {
3863 bus
->flowcontrol
= fcbits
;
3866 /* Check and update sequence number */
3868 DHD_INFO(("%s (nextlen): rx_seq %d, expected "
3869 "%d\n", __func__
, seq
, rxseq
));
3874 /* Check window for sanity */
3875 if ((u8
) (txmax
- bus
->tx_seq
) > 0x40) {
3876 DHD_ERROR(("%s: got unlikely tx max %d with "
3878 __func__
, txmax
, bus
->tx_seq
));
3879 txmax
= bus
->tx_seq
+ 2;
3881 bus
->tx_max
= txmax
;
3884 if (DHD_BYTES_ON() && DHD_DATA_ON())
3885 prhex("Rx Data", rxbuf
, len
);
3886 else if (DHD_HDRS_ON())
3887 prhex("RxHdr", bus
->rxhdr
, SDPCM_HDRLEN
);
3890 if (chan
== SDPCM_CONTROL_CHANNEL
) {
3891 if (bus
->bus
== SPI_BUS
) {
3892 dhdsdio_read_control(bus
, rxbuf
, len
,
3894 if (bus
->usebufpool
) {
3895 dhd_os_sdlock_rxq(bus
->dhd
);
3896 pkt_buf_free_skb(pkt
);
3897 dhd_os_sdunlock_rxq(bus
->dhd
);
3901 DHD_ERROR(("%s (nextlen): readahead on control" " packet %d?\n",
3903 /* Force retry w/normal header read */
3905 dhdsdio_rxfail(bus
, false, true);
3906 dhd_os_sdlock_rxq(bus
->dhd
);
3908 dhd_os_sdunlock_rxq(bus
->dhd
);
3913 if ((bus
->bus
== SPI_BUS
) && !bus
->usebufpool
) {
3914 DHD_ERROR(("Received %d bytes on %d channel. Running out of " "rx pktbuf's or not yet malloced.\n",
3919 /* Validate data offset */
3920 if ((doff
< SDPCM_HDRLEN
) || (doff
> len
)) {
3921 DHD_ERROR(("%s (nextlen): bad data offset %d: HW len %d min %d\n",
3922 __func__
, doff
, len
, SDPCM_HDRLEN
));
3923 dhd_os_sdlock_rxq(bus
->dhd
);
3925 dhd_os_sdunlock_rxq(bus
->dhd
);
3927 dhdsdio_rxfail(bus
, false, false);
3931 /* All done with this one -- now deliver the packet */
3934 /* gSPI frames should not be handled in fractions */
3935 if (bus
->bus
== SPI_BUS
)
3938 /* Read frame header (hardware and software) */
3940 dhd_bcmsdh_recv_buf(bus
, bcmsdh_cur_sbwad(sdh
), SDIO_FUNC_2
,
3941 F2SYNC
, bus
->rxhdr
, firstread
, NULL
,
3944 ASSERT(sdret
!= BCME_PENDING
);
3947 DHD_ERROR(("%s: RXHEADER FAILED: %d\n", __func__
,
3950 dhdsdio_rxfail(bus
, true, true);
3954 if (DHD_BYTES_ON() || DHD_HDRS_ON())
3955 prhex("RxHdr", bus
->rxhdr
, SDPCM_HDRLEN
);
3958 /* Extract hardware header fields */
3959 len
= get_unaligned_le16(bus
->rxhdr
);
3960 check
= get_unaligned_le16(bus
->rxhdr
+ sizeof(u16
));
3962 /* All zeros means no more frames */
3963 if (!(len
| check
)) {
3968 /* Validate check bytes */
3969 if ((u16
) ~(len
^ check
)) {
3970 DHD_ERROR(("%s: HW hdr err: len/check 0x%04x/0x%04x\n",
3971 __func__
, len
, check
));
3973 dhdsdio_rxfail(bus
, false, false);
3977 /* Validate frame length */
3978 if (len
< SDPCM_HDRLEN
) {
3979 DHD_ERROR(("%s: HW hdr length invalid: %d\n",
3984 /* Extract software header fields */
3985 chan
= SDPCM_PACKET_CHANNEL(&bus
->rxhdr
[SDPCM_FRAMETAG_LEN
]);
3986 seq
= SDPCM_PACKET_SEQUENCE(&bus
->rxhdr
[SDPCM_FRAMETAG_LEN
]);
3987 doff
= SDPCM_DOFFSET_VALUE(&bus
->rxhdr
[SDPCM_FRAMETAG_LEN
]);
3988 txmax
= SDPCM_WINDOW_VALUE(&bus
->rxhdr
[SDPCM_FRAMETAG_LEN
]);
3990 /* Validate data offset */
3991 if ((doff
< SDPCM_HDRLEN
) || (doff
> len
)) {
3992 DHD_ERROR(("%s: Bad data offset %d: HW len %d, min %d "
3994 __func__
, doff
, len
, SDPCM_HDRLEN
, seq
));
3997 dhdsdio_rxfail(bus
, false, false);
4001 /* Save the readahead length if there is one */
4003 bus
->rxhdr
[SDPCM_FRAMETAG_LEN
+ SDPCM_NEXTLEN_OFFSET
];
4004 if ((bus
->nextlen
<< 4) > MAX_RX_DATASZ
) {
4005 DHD_INFO(("%s (nextlen): got frame w/nextlen too large "
4007 __func__
, bus
->nextlen
, seq
));
4011 /* Handle Flow Control */
4012 fcbits
= SDPCM_FCMASK_VALUE(&bus
->rxhdr
[SDPCM_FRAMETAG_LEN
]);
4015 if (~bus
->flowcontrol
& fcbits
) {
4019 if (bus
->flowcontrol
& ~fcbits
) {
4026 bus
->flowcontrol
= fcbits
;
4029 /* Check and update sequence number */
4031 DHD_INFO(("%s: rx_seq %d, expected %d\n", __func__
,
4037 /* Check window for sanity */
4038 if ((u8
) (txmax
- bus
->tx_seq
) > 0x40) {
4039 DHD_ERROR(("%s: unlikely tx max %d with tx_seq %d\n",
4040 __func__
, txmax
, bus
->tx_seq
));
4041 txmax
= bus
->tx_seq
+ 2;
4043 bus
->tx_max
= txmax
;
4045 /* Call a separate function for control frames */
4046 if (chan
== SDPCM_CONTROL_CHANNEL
) {
4047 dhdsdio_read_control(bus
, bus
->rxhdr
, len
, doff
);
4051 ASSERT((chan
== SDPCM_DATA_CHANNEL
)
4052 || (chan
== SDPCM_EVENT_CHANNEL
)
4053 || (chan
== SDPCM_TEST_CHANNEL
)
4054 || (chan
== SDPCM_GLOM_CHANNEL
));
4056 /* Length to read */
4057 rdlen
= (len
> firstread
) ? (len
- firstread
) : 0;
4059 /* May pad read to blocksize for efficiency */
4060 if (bus
->roundup
&& bus
->blocksize
&&
4061 (rdlen
> bus
->blocksize
)) {
4062 pad
= bus
->blocksize
- (rdlen
% bus
->blocksize
);
4063 if ((pad
<= bus
->roundup
) && (pad
< bus
->blocksize
) &&
4064 ((rdlen
+ pad
+ firstread
) < MAX_RX_DATASZ
))
4066 } else if (rdlen
% DHD_SDALIGN
) {
4067 rdlen
+= DHD_SDALIGN
- (rdlen
% DHD_SDALIGN
);
4070 /* Satisfy length-alignment requirements */
4071 if (forcealign
&& (rdlen
& (ALIGNMENT
- 1)))
4072 rdlen
= roundup(rdlen
, ALIGNMENT
);
4074 if ((rdlen
+ firstread
) > MAX_RX_DATASZ
) {
4075 /* Too long -- skip this frame */
4076 DHD_ERROR(("%s: too long: len %d rdlen %d\n",
4077 __func__
, len
, rdlen
));
4078 bus
->dhd
->rx_errors
++;
4080 dhdsdio_rxfail(bus
, false, false);
4084 dhd_os_sdlock_rxq(bus
->dhd
);
4085 pkt
= pkt_buf_get_skb(rdlen
+ firstread
+ DHD_SDALIGN
);
4087 /* Give up on data, request rtx of events */
4088 DHD_ERROR(("%s: pkt_buf_get_skb failed: rdlen %d chan %d\n",
4089 __func__
, rdlen
, chan
));
4090 bus
->dhd
->rx_dropped
++;
4091 dhd_os_sdunlock_rxq(bus
->dhd
);
4092 dhdsdio_rxfail(bus
, false, RETRYCHAN(chan
));
4095 dhd_os_sdunlock_rxq(bus
->dhd
);
4097 ASSERT(!(pkt
->prev
));
4099 /* Leave room for what we already read, and align remainder */
4100 ASSERT(firstread
< pkt
->len
);
4101 skb_pull(pkt
, firstread
);
4102 PKTALIGN(pkt
, rdlen
, DHD_SDALIGN
);
4104 /* Read the remaining frame data */
4106 dhd_bcmsdh_recv_buf(bus
, bcmsdh_cur_sbwad(sdh
), SDIO_FUNC_2
,
4107 F2SYNC
, ((u8
*) (pkt
->data
)), rdlen
,
4110 ASSERT(sdret
!= BCME_PENDING
);
4113 DHD_ERROR(("%s: read %d %s bytes failed: %d\n",
4116 SDPCM_EVENT_CHANNEL
) ? "event" : ((chan
==
4118 ? "data" : "test")),
4120 dhd_os_sdlock_rxq(bus
->dhd
);
4121 pkt_buf_free_skb(pkt
);
4122 dhd_os_sdunlock_rxq(bus
->dhd
);
4123 bus
->dhd
->rx_errors
++;
4124 dhdsdio_rxfail(bus
, true, RETRYCHAN(chan
));
4128 /* Copy the already-read portion */
4129 skb_push(pkt
, firstread
);
4130 memcpy(pkt
->data
, bus
->rxhdr
, firstread
);
4133 if (DHD_BYTES_ON() && DHD_DATA_ON())
4134 prhex("Rx Data", pkt
->data
, len
);
4138 /* Save superframe descriptor and allocate packet frame */
4139 if (chan
== SDPCM_GLOM_CHANNEL
) {
4140 if (SDPCM_GLOMDESC(&bus
->rxhdr
[SDPCM_FRAMETAG_LEN
])) {
4141 DHD_GLOM(("%s: glom descriptor, %d bytes:\n",
4144 if (DHD_GLOM_ON()) {
4145 prhex("Glom Data", pkt
->data
, len
);
4148 __skb_trim(pkt
, len
);
4149 ASSERT(doff
== SDPCM_HDRLEN
);
4150 skb_pull(pkt
, SDPCM_HDRLEN
);
4153 DHD_ERROR(("%s: glom superframe w/o "
4154 "descriptor!\n", __func__
));
4155 dhdsdio_rxfail(bus
, false, false);
4160 /* Fill in packet len and prio, deliver upward */
4161 __skb_trim(pkt
, len
);
4162 skb_pull(pkt
, doff
);
4165 /* Test channel packets are processed separately */
4166 if (chan
== SDPCM_TEST_CHANNEL
) {
4167 dhdsdio_testrcv(bus
, pkt
, seq
);
4172 if (pkt
->len
== 0) {
4173 dhd_os_sdlock_rxq(bus
->dhd
);
4174 pkt_buf_free_skb(pkt
);
4175 dhd_os_sdunlock_rxq(bus
->dhd
);
4177 } else if (dhd_prot_hdrpull(bus
->dhd
, &ifidx
, pkt
) != 0) {
4178 DHD_ERROR(("%s: rx protocol error\n", __func__
));
4179 dhd_os_sdlock_rxq(bus
->dhd
);
4180 pkt_buf_free_skb(pkt
);
4181 dhd_os_sdunlock_rxq(bus
->dhd
);
4182 bus
->dhd
->rx_errors
++;
4186 /* Unlock during rx call */
4187 dhd_os_sdunlock(bus
->dhd
);
4188 dhd_rx_frame(bus
->dhd
, ifidx
, pkt
, 1);
4189 dhd_os_sdlock(bus
->dhd
);
4191 rxcount
= maxframes
- rxleft
;
4193 /* Message if we hit the limit */
4194 if (!rxleft
&& !sdtest
)
4195 DHD_DATA(("%s: hit rx limit of %d frames\n", __func__
,
4198 #endif /* DHD_DEBUG */
4199 DHD_DATA(("%s: processed %d frames\n", __func__
, rxcount
));
4200 /* Back off rxseq if awaiting rtx, update rx_seq */
4203 bus
->rx_seq
= rxseq
;
4208 static u32
dhdsdio_hostmail(dhd_bus_t
*bus
)
4210 sdpcmd_regs_t
*regs
= bus
->regs
;
4216 DHD_TRACE(("%s: Enter\n", __func__
));
4218 /* Read mailbox data and ack that we did so */
4219 R_SDREG(hmb_data
, ®s
->tohostmailboxdata
, retries
);
4220 if (retries
<= retry_limit
)
4221 W_SDREG(SMB_INT_ACK
, ®s
->tosbmailbox
, retries
);
4222 bus
->f1regdata
+= 2;
4224 /* Dongle recomposed rx frames, accept them again */
4225 if (hmb_data
& HMB_DATA_NAKHANDLED
) {
4226 DHD_INFO(("Dongle reports NAK handled, expect rtx of %d\n",
4229 DHD_ERROR(("%s: unexpected NAKHANDLED!\n", __func__
));
4231 bus
->rxskip
= false;
4232 intstatus
|= I_HMB_FRAME_IND
;
4236 * DEVREADY does not occur with gSPI.
4238 if (hmb_data
& (HMB_DATA_DEVREADY
| HMB_DATA_FWREADY
)) {
4240 (hmb_data
& HMB_DATA_VERSION_MASK
) >>
4241 HMB_DATA_VERSION_SHIFT
;
4242 if (bus
->sdpcm_ver
!= SDPCM_PROT_VERSION
)
4243 DHD_ERROR(("Version mismatch, dongle reports %d, "
4245 bus
->sdpcm_ver
, SDPCM_PROT_VERSION
));
4247 DHD_INFO(("Dongle ready, protocol version %d\n",
4252 * Flow Control has been moved into the RX headers and this out of band
4253 * method isn't used any more. Leae this here for possibly
4254 * remaining backward
4255 * compatible with older dongles
4257 if (hmb_data
& HMB_DATA_FC
) {
4259 (hmb_data
& HMB_DATA_FCDATA_MASK
) >> HMB_DATA_FCDATA_SHIFT
;
4261 if (fcbits
& ~bus
->flowcontrol
)
4263 if (bus
->flowcontrol
& ~fcbits
)
4267 bus
->flowcontrol
= fcbits
;
4270 /* Shouldn't be any others */
4271 if (hmb_data
& ~(HMB_DATA_DEVREADY
|
4272 HMB_DATA_NAKHANDLED
|
4275 HMB_DATA_FCDATA_MASK
| HMB_DATA_VERSION_MASK
)) {
4276 DHD_ERROR(("Unknown mailbox data content: 0x%02x\n", hmb_data
));
4282 bool dhdsdio_dpc(dhd_bus_t
*bus
)
4284 bcmsdh_info_t
*sdh
= bus
->sdh
;
4285 sdpcmd_regs_t
*regs
= bus
->regs
;
4286 u32 intstatus
, newstatus
= 0;
4288 uint rxlimit
= dhd_rxbound
; /* Rx frames to read before resched */
4289 uint txlimit
= dhd_txbound
; /* Tx frames to send before resched */
4290 uint framecnt
= 0; /* Temporary counter of tx/rx frames */
4291 bool rxdone
= true; /* Flag for no more read data */
4292 bool resched
= false; /* Flag indicating resched wanted */
4294 DHD_TRACE(("%s: Enter\n", __func__
));
4296 /* Start with leftover status bits */
4297 intstatus
= bus
->intstatus
;
4299 dhd_os_sdlock(bus
->dhd
);
4301 /* If waiting for HTAVAIL, check status */
4302 if (bus
->clkstate
== CLK_PENDING
) {
4304 u8 clkctl
, devctl
= 0;
4307 /* Check for inconsistent device control */
4309 bcmsdh_cfg_read(sdh
, SDIO_FUNC_1
, SBSDIO_DEVICE_CTL
, &err
);
4311 DHD_ERROR(("%s: error reading DEVCTL: %d\n",
4313 bus
->dhd
->busstate
= DHD_BUS_DOWN
;
4315 ASSERT(devctl
& SBSDIO_DEVCTL_CA_INT_ONLY
);
4317 #endif /* DHD_DEBUG */
4319 /* Read CSR, if clock on switch to AVAIL, else ignore */
4321 bcmsdh_cfg_read(sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_CHIPCLKCSR
,
4324 DHD_ERROR(("%s: error reading CSR: %d\n", __func__
,
4326 bus
->dhd
->busstate
= DHD_BUS_DOWN
;
4329 DHD_INFO(("DPC: PENDING, devctl 0x%02x clkctl 0x%02x\n", devctl
,
4332 if (SBSDIO_HTAV(clkctl
)) {
4334 bcmsdh_cfg_read(sdh
, SDIO_FUNC_1
, SBSDIO_DEVICE_CTL
,
4337 DHD_ERROR(("%s: error reading DEVCTL: %d\n",
4339 bus
->dhd
->busstate
= DHD_BUS_DOWN
;
4341 devctl
&= ~SBSDIO_DEVCTL_CA_INT_ONLY
;
4342 bcmsdh_cfg_write(sdh
, SDIO_FUNC_1
, SBSDIO_DEVICE_CTL
,
4345 DHD_ERROR(("%s: error writing DEVCTL: %d\n",
4347 bus
->dhd
->busstate
= DHD_BUS_DOWN
;
4349 bus
->clkstate
= CLK_AVAIL
;
4357 /* Make sure backplane clock is on */
4358 dhdsdio_clkctl(bus
, CLK_AVAIL
, true);
4359 if (bus
->clkstate
== CLK_PENDING
)
4362 /* Pending interrupt indicates new device status */
4365 R_SDREG(newstatus
, ®s
->intstatus
, retries
);
4367 if (bcmsdh_regfail(bus
->sdh
))
4369 newstatus
&= bus
->hostintmask
;
4370 bus
->fcstate
= !!(newstatus
& I_HMB_FC_STATE
);
4372 W_SDREG(newstatus
, ®s
->intstatus
, retries
);
4377 /* Merge new bits with previous */
4378 intstatus
|= newstatus
;
4381 /* Handle flow-control change: read new state in case our ack
4382 * crossed another change interrupt. If change still set, assume
4383 * FC ON for safety, let next loop through do the debounce.
4385 if (intstatus
& I_HMB_FC_CHANGE
) {
4386 intstatus
&= ~I_HMB_FC_CHANGE
;
4387 W_SDREG(I_HMB_FC_CHANGE
, ®s
->intstatus
, retries
);
4388 R_SDREG(newstatus
, ®s
->intstatus
, retries
);
4389 bus
->f1regdata
+= 2;
4391 !!(newstatus
& (I_HMB_FC_STATE
| I_HMB_FC_CHANGE
));
4392 intstatus
|= (newstatus
& bus
->hostintmask
);
4395 /* Handle host mailbox indication */
4396 if (intstatus
& I_HMB_HOST_INT
) {
4397 intstatus
&= ~I_HMB_HOST_INT
;
4398 intstatus
|= dhdsdio_hostmail(bus
);
4401 /* Generally don't ask for these, can get CRC errors... */
4402 if (intstatus
& I_WR_OOSYNC
) {
4403 DHD_ERROR(("Dongle reports WR_OOSYNC\n"));
4404 intstatus
&= ~I_WR_OOSYNC
;
4407 if (intstatus
& I_RD_OOSYNC
) {
4408 DHD_ERROR(("Dongle reports RD_OOSYNC\n"));
4409 intstatus
&= ~I_RD_OOSYNC
;
4412 if (intstatus
& I_SBINT
) {
4413 DHD_ERROR(("Dongle reports SBINT\n"));
4414 intstatus
&= ~I_SBINT
;
4417 /* Would be active due to wake-wlan in gSPI */
4418 if (intstatus
& I_CHIPACTIVE
) {
4419 DHD_INFO(("Dongle reports CHIPACTIVE\n"));
4420 intstatus
&= ~I_CHIPACTIVE
;
4423 /* Ignore frame indications if rxskip is set */
4425 intstatus
&= ~I_HMB_FRAME_IND
;
4427 /* On frame indication, read available frames */
4428 if (PKT_AVAILABLE()) {
4429 framecnt
= dhdsdio_readframes(bus
, rxlimit
, &rxdone
);
4430 if (rxdone
|| bus
->rxskip
)
4431 intstatus
&= ~I_HMB_FRAME_IND
;
4432 rxlimit
-= min(framecnt
, rxlimit
);
4435 /* Keep still-pending events for next scheduling */
4436 bus
->intstatus
= intstatus
;
4439 #if defined(OOB_INTR_ONLY)
4440 bcmsdh_oob_intr_set(1);
4441 #endif /* (OOB_INTR_ONLY) */
4442 /* Re-enable interrupts to detect new device events (mailbox, rx frame)
4443 * or clock availability. (Allows tx loop to check ipend if desired.)
4444 * (Unless register access seems hosed, as we may not be able to ACK...)
4446 if (bus
->intr
&& bus
->intdis
&& !bcmsdh_regfail(sdh
)) {
4447 DHD_INTR(("%s: enable SDIO interrupts, rxdone %d framecnt %d\n",
4448 __func__
, rxdone
, framecnt
));
4449 bus
->intdis
= false;
4450 bcmsdh_intr_enable(sdh
);
4453 if (DATAOK(bus
) && bus
->ctrl_frame_stat
&&
4454 (bus
->clkstate
== CLK_AVAIL
)) {
4458 dhd_bcmsdh_send_buf(bus
, bcmsdh_cur_sbwad(sdh
), SDIO_FUNC_2
,
4459 F2SYNC
, (u8
*) bus
->ctrl_frame_buf
,
4460 (u32
) bus
->ctrl_frame_len
, NULL
,
4462 ASSERT(ret
!= BCME_PENDING
);
4465 /* On failure, abort the command and
4466 terminate the frame */
4467 DHD_INFO(("%s: sdio error %d, abort command and "
4468 "terminate frame.\n", __func__
, ret
));
4471 bcmsdh_abort(sdh
, SDIO_FUNC_2
);
4473 bcmsdh_cfg_write(sdh
, SDIO_FUNC_1
,
4474 SBSDIO_FUNC1_FRAMECTRL
, SFC_WF_TERM
,
4478 for (i
= 0; i
< 3; i
++) {
4480 hi
= bcmsdh_cfg_read(sdh
, SDIO_FUNC_1
,
4481 SBSDIO_FUNC1_WFRAMEBCHI
,
4483 lo
= bcmsdh_cfg_read(sdh
, SDIO_FUNC_1
,
4484 SBSDIO_FUNC1_WFRAMEBCLO
,
4486 bus
->f1regdata
+= 2;
4487 if ((hi
== 0) && (lo
== 0))
4493 bus
->tx_seq
= (bus
->tx_seq
+ 1) % SDPCM_SEQUENCE_WRAP
;
4495 DHD_INFO(("Return_dpc value is : %d\n", ret
));
4496 bus
->ctrl_frame_stat
= false;
4497 dhd_wait_event_wakeup(bus
->dhd
);
4499 /* Send queued frames (limit 1 if rx may still be pending) */
4500 else if ((bus
->clkstate
== CLK_AVAIL
) && !bus
->fcstate
&&
4501 pktq_mlen(&bus
->txq
, ~bus
->flowcontrol
) && txlimit
4503 framecnt
= rxdone
? txlimit
: min(txlimit
, dhd_txminmax
);
4504 framecnt
= dhdsdio_sendfromq(bus
, framecnt
);
4505 txlimit
-= framecnt
;
4508 /* Resched if events or tx frames are pending,
4509 else await next interrupt */
4510 /* On failed register access, all bets are off:
4511 no resched or interrupts */
4512 if ((bus
->dhd
->busstate
== DHD_BUS_DOWN
) || bcmsdh_regfail(sdh
)) {
4513 DHD_ERROR(("%s: failed backplane access over SDIO, halting "
4514 "operation %d\n", __func__
, bcmsdh_regfail(sdh
)));
4515 bus
->dhd
->busstate
= DHD_BUS_DOWN
;
4517 } else if (bus
->clkstate
== CLK_PENDING
) {
4518 DHD_INFO(("%s: rescheduled due to CLK_PENDING awaiting "
4519 "I_CHIPACTIVE interrupt\n", __func__
));
4521 } else if (bus
->intstatus
|| bus
->ipend
||
4522 (!bus
->fcstate
&& pktq_mlen(&bus
->txq
, ~bus
->flowcontrol
) &&
4523 DATAOK(bus
)) || PKT_AVAILABLE()) {
4527 bus
->dpc_sched
= resched
;
4529 /* If we're done for now, turn off clock request. */
4530 if ((bus
->clkstate
!= CLK_PENDING
)
4531 && bus
->idletime
== DHD_IDLE_IMMEDIATE
) {
4532 bus
->activity
= false;
4533 dhdsdio_clkctl(bus
, CLK_NONE
, false);
4536 dhd_os_sdunlock(bus
->dhd
);
4541 bool dhd_bus_dpc(struct dhd_bus
*bus
)
4545 /* Call the DPC directly. */
4546 DHD_TRACE(("Calling dhdsdio_dpc() from %s\n", __func__
));
4547 resched
= dhdsdio_dpc(bus
);
4552 void dhdsdio_isr(void *arg
)
4554 dhd_bus_t
*bus
= (dhd_bus_t
*) arg
;
4557 DHD_TRACE(("%s: Enter\n", __func__
));
4560 DHD_ERROR(("%s : bus is null pointer , exit\n", __func__
));
4565 if (bus
->dhd
->busstate
== DHD_BUS_DOWN
) {
4566 DHD_ERROR(("%s : bus is down. we have nothing to do\n",
4570 /* Count the interrupt call */
4574 /* Shouldn't get this interrupt if we're sleeping? */
4575 if (bus
->sleeping
) {
4576 DHD_ERROR(("INTERRUPT WHILE SLEEPING??\n"));
4580 /* Disable additional interrupts (is this needed now)? */
4582 DHD_INTR(("%s: disable SDIO interrupts\n", __func__
));
4584 DHD_ERROR(("dhdsdio_isr() w/o interrupt configured!\n"));
4586 bcmsdh_intr_disable(sdh
);
4589 #if defined(SDIO_ISR_THREAD)
4590 DHD_TRACE(("Calling dhdsdio_dpc() from %s\n", __func__
));
4591 while (dhdsdio_dpc(bus
))
4594 bus
->dpc_sched
= true;
4595 dhd_sched_dpc(bus
->dhd
);
4601 static void dhdsdio_pktgen_init(dhd_bus_t
*bus
)
4603 /* Default to specified length, or full range */
4604 if (dhd_pktgen_len
) {
4605 bus
->pktgen_maxlen
= min(dhd_pktgen_len
, MAX_PKTGEN_LEN
);
4606 bus
->pktgen_minlen
= bus
->pktgen_maxlen
;
4608 bus
->pktgen_maxlen
= MAX_PKTGEN_LEN
;
4609 bus
->pktgen_minlen
= 0;
4611 bus
->pktgen_len
= (u16
) bus
->pktgen_minlen
;
4613 /* Default to per-watchdog burst with 10s print time */
4614 bus
->pktgen_freq
= 1;
4615 bus
->pktgen_print
= 10000 / dhd_watchdog_ms
;
4616 bus
->pktgen_count
= (dhd_pktgen
* dhd_watchdog_ms
+ 999) / 1000;
4618 /* Default to echo mode */
4619 bus
->pktgen_mode
= DHD_PKTGEN_ECHO
;
4620 bus
->pktgen_stop
= 1;
4623 static void dhdsdio_pktgen(dhd_bus_t
*bus
)
4625 struct sk_buff
*pkt
;
4631 /* Display current count if appropriate */
4632 if (bus
->pktgen_print
&& (++bus
->pktgen_ptick
>= bus
->pktgen_print
)) {
4633 bus
->pktgen_ptick
= 0;
4634 printk(KERN_DEBUG
"%s: send attempts %d rcvd %d\n",
4635 __func__
, bus
->pktgen_sent
, bus
->pktgen_rcvd
);
4638 /* For recv mode, just make sure dongle has started sending */
4639 if (bus
->pktgen_mode
== DHD_PKTGEN_RECV
) {
4640 if (!bus
->pktgen_rcvd
)
4641 dhdsdio_sdtest_set(bus
, true);
4645 /* Otherwise, generate or request the specified number of packets */
4646 for (pktcount
= 0; pktcount
< bus
->pktgen_count
; pktcount
++) {
4647 /* Stop if total has been reached */
4648 if (bus
->pktgen_total
4649 && (bus
->pktgen_sent
>= bus
->pktgen_total
)) {
4650 bus
->pktgen_count
= 0;
4654 /* Allocate an appropriate-sized packet */
4655 len
= bus
->pktgen_len
;
4656 pkt
= pkt_buf_get_skb(
4657 (len
+ SDPCM_HDRLEN
+ SDPCM_TEST_HDRLEN
+ DHD_SDALIGN
),
4660 DHD_ERROR(("%s: pkt_buf_get_skb failed!\n", __func__
));
4663 PKTALIGN(pkt
, (len
+ SDPCM_HDRLEN
+ SDPCM_TEST_HDRLEN
),
4665 data
= (u8
*) (pkt
->data
) + SDPCM_HDRLEN
;
4667 /* Write test header cmd and extra based on mode */
4668 switch (bus
->pktgen_mode
) {
4669 case DHD_PKTGEN_ECHO
:
4670 *data
++ = SDPCM_TEST_ECHOREQ
;
4671 *data
++ = (u8
) bus
->pktgen_sent
;
4674 case DHD_PKTGEN_SEND
:
4675 *data
++ = SDPCM_TEST_DISCARD
;
4676 *data
++ = (u8
) bus
->pktgen_sent
;
4679 case DHD_PKTGEN_RXBURST
:
4680 *data
++ = SDPCM_TEST_BURST
;
4681 *data
++ = (u8
) bus
->pktgen_count
;
4685 DHD_ERROR(("Unrecognized pktgen mode %d\n",
4687 pkt_buf_free_skb(pkt
, true);
4688 bus
->pktgen_count
= 0;
4692 /* Write test header length field */
4693 *data
++ = (len
>> 0);
4694 *data
++ = (len
>> 8);
4696 /* Then fill in the remainder -- N/A for burst,
4698 for (fillbyte
= 0; fillbyte
< len
; fillbyte
++)
4700 SDPCM_TEST_FILL(fillbyte
, (u8
) bus
->pktgen_sent
);
4703 if (DHD_BYTES_ON() && DHD_DATA_ON()) {
4704 data
= (u8
*) (pkt
->data
) + SDPCM_HDRLEN
;
4705 prhex("dhdsdio_pktgen: Tx Data", data
,
4706 pkt
->len
- SDPCM_HDRLEN
);
4711 if (dhdsdio_txpkt(bus
, pkt
, SDPCM_TEST_CHANNEL
, true)) {
4713 if (bus
->pktgen_stop
4714 && bus
->pktgen_stop
== bus
->pktgen_fail
)
4715 bus
->pktgen_count
= 0;
4719 /* Bump length if not fixed, wrap at max */
4720 if (++bus
->pktgen_len
> bus
->pktgen_maxlen
)
4721 bus
->pktgen_len
= (u16
) bus
->pktgen_minlen
;
4723 /* Special case for burst mode: just send one request! */
4724 if (bus
->pktgen_mode
== DHD_PKTGEN_RXBURST
)
4729 static void dhdsdio_sdtest_set(dhd_bus_t
*bus
, bool start
)
4731 struct sk_buff
*pkt
;
4734 /* Allocate the packet */
4735 pkt
= pkt_buf_get_skb(SDPCM_HDRLEN
+ SDPCM_TEST_HDRLEN
+ DHD_SDALIGN
,
4738 DHD_ERROR(("%s: pkt_buf_get_skb failed!\n", __func__
));
4741 PKTALIGN(pkt
, (SDPCM_HDRLEN
+ SDPCM_TEST_HDRLEN
), DHD_SDALIGN
);
4742 data
= (u8
*) (pkt
->data
) + SDPCM_HDRLEN
;
4744 /* Fill in the test header */
4745 *data
++ = SDPCM_TEST_SEND
;
4747 *data
++ = (bus
->pktgen_maxlen
>> 0);
4748 *data
++ = (bus
->pktgen_maxlen
>> 8);
4751 if (dhdsdio_txpkt(bus
, pkt
, SDPCM_TEST_CHANNEL
, true))
4755 static void dhdsdio_testrcv(dhd_bus_t
*bus
, struct sk_buff
*pkt
, uint seq
)
4765 /* Check for min length */
4767 if (pktlen
< SDPCM_TEST_HDRLEN
) {
4768 DHD_ERROR(("dhdsdio_restrcv: toss runt frame, pktlen %d\n",
4770 pkt_buf_free_skb(pkt
, false);
4774 /* Extract header fields */
4779 len
+= *data
++ << 8;
4781 /* Check length for relevant commands */
4782 if (cmd
== SDPCM_TEST_DISCARD
|| cmd
== SDPCM_TEST_ECHOREQ
4783 || cmd
== SDPCM_TEST_ECHORSP
) {
4784 if (pktlen
!= len
+ SDPCM_TEST_HDRLEN
) {
4785 DHD_ERROR(("dhdsdio_testrcv: frame length mismatch, "
4786 "pktlen %d seq %d" " cmd %d extra %d len %d\n",
4787 pktlen
, seq
, cmd
, extra
, len
));
4788 pkt_buf_free_skb(pkt
, false);
4793 /* Process as per command */
4795 case SDPCM_TEST_ECHOREQ
:
4796 /* Rx->Tx turnaround ok (even on NDIS w/current
4798 *(u8
*) (pkt
->data
) = SDPCM_TEST_ECHORSP
;
4799 if (dhdsdio_txpkt(bus
, pkt
, SDPCM_TEST_CHANNEL
, true) == 0) {
4803 pkt_buf_free_skb(pkt
, false);
4808 case SDPCM_TEST_ECHORSP
:
4809 if (bus
->ext_loop
) {
4810 pkt_buf_free_skb(pkt
, false);
4815 for (offset
= 0; offset
< len
; offset
++, data
++) {
4816 if (*data
!= SDPCM_TEST_FILL(offset
, extra
)) {
4817 DHD_ERROR(("dhdsdio_testrcv: echo data mismatch: " "offset %d (len %d) expect 0x%02x rcvd 0x%02x\n",
4819 SDPCM_TEST_FILL(offset
, extra
), *data
));
4823 pkt_buf_free_skb(pkt
, false);
4827 case SDPCM_TEST_DISCARD
:
4828 pkt_buf_free_skb(pkt
, false);
4832 case SDPCM_TEST_BURST
:
4833 case SDPCM_TEST_SEND
:
4835 DHD_INFO(("dhdsdio_testrcv: unsupported or unknown command, "
4836 "pktlen %d seq %d" " cmd %d extra %d len %d\n",
4837 pktlen
, seq
, cmd
, extra
, len
));
4838 pkt_buf_free_skb(pkt
, false);
4842 /* For recv mode, stop at limie (and tell dongle to stop sending) */
4843 if (bus
->pktgen_mode
== DHD_PKTGEN_RECV
) {
4844 if (bus
->pktgen_total
4845 && (bus
->pktgen_rcvd
>= bus
->pktgen_total
)) {
4846 bus
->pktgen_count
= 0;
4847 dhdsdio_sdtest_set(bus
, false);
4853 extern bool dhd_bus_watchdog(dhd_pub_t
*dhdp
)
4857 DHD_TIMER(("%s: Enter\n", __func__
));
4861 if (bus
->dhd
->dongle_reset
)
4864 /* Ignore the timer if simulating bus down */
4868 dhd_os_sdlock(bus
->dhd
);
4870 /* Poll period: check device if appropriate. */
4871 if (bus
->poll
&& (++bus
->polltick
>= bus
->pollrate
)) {
4874 /* Reset poll tick */
4877 /* Check device if no interrupts */
4878 if (!bus
->intr
|| (bus
->intrcount
== bus
->lastintrs
)) {
4880 if (!bus
->dpc_sched
) {
4882 devpend
= bcmsdh_cfg_read(bus
->sdh
, SDIO_FUNC_0
,
4886 devpend
& (INTR_STATUS_FUNC1
|
4890 /* If there is something, make like the ISR and
4896 bcmsdh_intr_disable(bus
->sdh
);
4898 bus
->dpc_sched
= true;
4899 dhd_sched_dpc(bus
->dhd
);
4904 /* Update interrupt tracking */
4905 bus
->lastintrs
= bus
->intrcount
;
4908 /* Poll for console output periodically */
4909 if (dhdp
->busstate
== DHD_BUS_DATA
&& dhd_console_ms
!= 0) {
4910 bus
->console
.count
+= dhd_watchdog_ms
;
4911 if (bus
->console
.count
>= dhd_console_ms
) {
4912 bus
->console
.count
-= dhd_console_ms
;
4913 /* Make sure backplane clock is on */
4914 dhdsdio_clkctl(bus
, CLK_AVAIL
, false);
4915 if (dhdsdio_readconsole(bus
) < 0)
4916 dhd_console_ms
= 0; /* On error,
4920 #endif /* DHD_DEBUG */
4923 /* Generate packets if configured */
4924 if (bus
->pktgen_count
&& (++bus
->pktgen_tick
>= bus
->pktgen_freq
)) {
4925 /* Make sure backplane clock is on */
4926 dhdsdio_clkctl(bus
, CLK_AVAIL
, false);
4927 bus
->pktgen_tick
= 0;
4928 dhdsdio_pktgen(bus
);
4932 /* On idle timeout clear activity flag and/or turn off clock */
4933 if ((bus
->idletime
> 0) && (bus
->clkstate
== CLK_AVAIL
)) {
4934 if (++bus
->idlecount
>= bus
->idletime
) {
4936 if (bus
->activity
) {
4937 bus
->activity
= false;
4938 dhd_os_wd_timer(bus
->dhd
, dhd_watchdog_ms
);
4940 dhdsdio_clkctl(bus
, CLK_NONE
, false);
4945 dhd_os_sdunlock(bus
->dhd
);
4951 extern int dhd_bus_console_in(dhd_pub_t
*dhdp
, unsigned char *msg
, uint msglen
)
4953 dhd_bus_t
*bus
= dhdp
->bus
;
4956 struct sk_buff
*pkt
;
4958 /* Address could be zero if CONSOLE := 0 in dongle Makefile */
4959 if (bus
->console_addr
== 0)
4960 return BCME_UNSUPPORTED
;
4962 /* Exclusive bus access */
4963 dhd_os_sdlock(bus
->dhd
);
4965 /* Don't allow input if dongle is in reset */
4966 if (bus
->dhd
->dongle_reset
) {
4967 dhd_os_sdunlock(bus
->dhd
);
4968 return BCME_NOTREADY
;
4971 /* Request clock to allow SDIO accesses */
4973 /* No pend allowed since txpkt is called later, ht clk has to be on */
4974 dhdsdio_clkctl(bus
, CLK_AVAIL
, false);
4976 /* Zero cbuf_index */
4977 addr
= bus
->console_addr
+ offsetof(hndrte_cons_t
, cbuf_idx
);
4978 val
= cpu_to_le32(0);
4979 rv
= dhdsdio_membytes(bus
, true, addr
, (u8
*)&val
, sizeof(val
));
4983 /* Write message into cbuf */
4984 addr
= bus
->console_addr
+ offsetof(hndrte_cons_t
, cbuf
);
4985 rv
= dhdsdio_membytes(bus
, true, addr
, (u8
*)msg
, msglen
);
4989 /* Write length into vcons_in */
4990 addr
= bus
->console_addr
+ offsetof(hndrte_cons_t
, vcons_in
);
4991 val
= cpu_to_le32(msglen
);
4992 rv
= dhdsdio_membytes(bus
, true, addr
, (u8
*)&val
, sizeof(val
));
4996 /* Bump dongle by sending an empty event pkt.
4997 * sdpcm_sendup (RX) checks for virtual console input.
4999 pkt
= pkt_buf_get_skb(4 + SDPCM_RESERVE
);
5000 if ((pkt
!= NULL
) && bus
->clkstate
== CLK_AVAIL
)
5001 dhdsdio_txpkt(bus
, pkt
, SDPCM_EVENT_CHANNEL
, true);
5004 if ((bus
->idletime
== DHD_IDLE_IMMEDIATE
) && !bus
->dpc_sched
) {
5005 bus
->activity
= false;
5006 dhdsdio_clkctl(bus
, CLK_NONE
, true);
5009 dhd_os_sdunlock(bus
->dhd
);
5013 #endif /* DHD_DEBUG */
5016 static void dhd_dump_cis(uint fn
, u8
*cis
)
5018 uint byte
, tag
, tdata
;
5019 DHD_INFO(("Function %d CIS:\n", fn
));
5021 for (tdata
= byte
= 0; byte
< SBSDIO_CIS_SIZE_LIMIT
; byte
++) {
5022 if ((byte
% 16) == 0)
5024 DHD_INFO(("%02x ", cis
[byte
]));
5025 if ((byte
% 16) == 15)
5033 else if ((byte
+ 1) < SBSDIO_CIS_SIZE_LIMIT
)
5034 tdata
= cis
[byte
+ 1] + 1;
5039 if ((byte
% 16) != 15)
5042 #endif /* DHD_DEBUG */
5044 static bool dhdsdio_chipmatch(u16 chipid
)
5046 if (chipid
== BCM4325_CHIP_ID
)
5048 if (chipid
== BCM4329_CHIP_ID
)
5050 if (chipid
== BCM4319_CHIP_ID
)
5055 static void *dhdsdio_probe(u16 venid
, u16 devid
, u16 bus_no
,
5056 u16 slot
, u16 func
, uint bustype
, void *regsva
,
5062 /* Init global variables at run-time, not as part of the declaration.
5063 * This is required to support init/de-init of the driver.
5065 * of globals as part of the declaration results in non-deterministic
5066 * behavior since the value of the globals may be different on the
5067 * first time that the driver is initialized vs subsequent
5070 dhd_txbound
= DHD_TXBOUND
;
5071 dhd_rxbound
= DHD_RXBOUND
;
5072 dhd_alignctl
= true;
5074 dhd_readahead
= true;
5077 dhd_dongle_memsize
= 0;
5078 dhd_txminmax
= DHD_TXMINMAX
;
5084 DHD_TRACE(("%s: Enter\n", __func__
));
5085 DHD_INFO(("%s: venid 0x%04x devid 0x%04x\n", __func__
, venid
, devid
));
5087 /* We make assumptions about address window mappings */
5088 ASSERT((unsigned long)regsva
== SI_ENUM_BASE
);
5090 /* BCMSDH passes venid and devid based on CIS parsing -- but
5092 * means early parse could fail, so here we should get either an ID
5093 * we recognize OR (-1) indicating we must request power first.
5095 /* Check the Vendor ID */
5098 case VENDOR_BROADCOM
:
5101 DHD_ERROR(("%s: unknown vendor: 0x%04x\n", __func__
, venid
));
5105 /* Check the Device ID and make sure it's one that we support */
5107 case BCM4325_D11DUAL_ID
: /* 4325 802.11a/g id */
5108 case BCM4325_D11G_ID
: /* 4325 802.11g 2.4Ghz band id */
5109 case BCM4325_D11A_ID
: /* 4325 802.11a 5Ghz band id */
5110 DHD_INFO(("%s: found 4325 Dongle\n", __func__
));
5112 case BCM4329_D11NDUAL_ID
: /* 4329 802.11n dualband device */
5113 case BCM4329_D11N2G_ID
: /* 4329 802.11n 2.4G device */
5114 case BCM4329_D11N5G_ID
: /* 4329 802.11n 5G device */
5116 DHD_INFO(("%s: found 4329 Dongle\n", __func__
));
5118 case BCM4319_D11N_ID
: /* 4319 802.11n id */
5119 case BCM4319_D11N2G_ID
: /* 4319 802.11n2g id */
5120 case BCM4319_D11N5G_ID
: /* 4319 802.11n5g id */
5121 DHD_INFO(("%s: found 4319 Dongle\n", __func__
));
5124 DHD_INFO(("%s: allow device id 0, will check chip internals\n",
5129 DHD_ERROR(("%s: skipping 0x%04x/0x%04x, not a dongle\n",
5130 __func__
, venid
, devid
));
5134 /* Allocate private bus interface state */
5135 bus
= kzalloc(sizeof(dhd_bus_t
), GFP_ATOMIC
);
5137 DHD_ERROR(("%s: kmalloc of dhd_bus_t failed\n", __func__
));
5141 bus
->cl_devid
= (u16
) devid
;
5143 bus
->tx_seq
= SDPCM_SEQUENCE_WRAP
- 1;
5144 bus
->usebufpool
= false; /* Use bufpool if allocated,
5145 else use locally malloced rxbuf */
5147 /* attempt to attach to the dongle */
5148 if (!(dhdsdio_probe_attach(bus
, sdh
, regsva
, devid
))) {
5149 DHD_ERROR(("%s: dhdsdio_probe_attach failed\n", __func__
));
5153 /* Attach to the dhd/OS/network interface */
5154 bus
->dhd
= dhd_attach(bus
, SDPCM_RESERVE
);
5156 DHD_ERROR(("%s: dhd_attach failed\n", __func__
));
5160 /* Allocate buffers */
5161 if (!(dhdsdio_probe_malloc(bus
, sdh
))) {
5162 DHD_ERROR(("%s: dhdsdio_probe_malloc failed\n", __func__
));
5166 if (!(dhdsdio_probe_init(bus
, sdh
))) {
5167 DHD_ERROR(("%s: dhdsdio_probe_init failed\n", __func__
));
5171 /* Register interrupt callback, but mask it (not operational yet). */
5172 DHD_INTR(("%s: disable SDIO interrupts (not interested yet)\n",
5174 bcmsdh_intr_disable(sdh
);
5175 ret
= bcmsdh_intr_reg(sdh
, dhdsdio_isr
, bus
);
5177 DHD_ERROR(("%s: FAILED: bcmsdh_intr_reg returned %d\n",
5181 DHD_INTR(("%s: registered SDIO interrupt function ok\n", __func__
));
5183 DHD_INFO(("%s: completed!!\n", __func__
));
5185 /* if firmware path present try to download and bring up bus */
5186 ret
= dhd_bus_start(bus
->dhd
);
5188 if (ret
== BCME_NOTUP
) {
5189 DHD_ERROR(("%s: dongle is not responding\n", __func__
));
5193 /* Ok, have the per-port tell the stack we're open for business */
5194 if (dhd_net_attach(bus
->dhd
, 0) != 0) {
5195 DHD_ERROR(("%s: Net attach failed!!\n", __func__
));
5202 dhdsdio_release(bus
);
5207 dhdsdio_probe_attach(struct dhd_bus
*bus
, void *sdh
, void *regsva
, u16 devid
)
5212 bus
->alp_only
= true;
5214 /* Return the window to backplane enumeration space for core access */
5215 if (dhdsdio_set_siaddr_window(bus
, SI_ENUM_BASE
))
5216 DHD_ERROR(("%s: FAILED to return to SI_ENUM_BASE\n", __func__
));
5219 printk(KERN_DEBUG
"F1 signature read @0x18000000=0x%4x\n",
5220 bcmsdh_reg_read(bus
->sdh
, SI_ENUM_BASE
, 4));
5222 #endif /* DHD_DEBUG */
5224 /* Force PLL off until si_attach() programs PLL control regs */
5226 bcmsdh_cfg_write(sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_CHIPCLKCSR
,
5227 DHD_INIT_CLKCTL1
, &err
);
5230 bcmsdh_cfg_read(sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_CHIPCLKCSR
,
5233 if (err
|| ((clkctl
& ~SBSDIO_AVBITS
) != DHD_INIT_CLKCTL1
)) {
5234 DHD_ERROR(("dhdsdio_probe: ChipClkCSR access: err %d wrote "
5235 "0x%02x read 0x%02x\n",
5236 err
, DHD_INIT_CLKCTL1
, clkctl
));
5240 if (DHD_INFO_ON()) {
5242 u8
*cis
[SDIOD_MAX_IOFUNCS
];
5245 numfn
= bcmsdh_query_iofnum(sdh
);
5246 ASSERT(numfn
<= SDIOD_MAX_IOFUNCS
);
5248 /* Make sure ALP is available before trying to read CIS */
5249 SPINWAIT(((clkctl
= bcmsdh_cfg_read(sdh
, SDIO_FUNC_1
,
5250 SBSDIO_FUNC1_CHIPCLKCSR
,
5252 !SBSDIO_ALPAV(clkctl
)), PMU_MAX_TRANSITION_DLY
);
5254 /* Now request ALP be put on the bus */
5255 bcmsdh_cfg_write(sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_CHIPCLKCSR
,
5256 DHD_INIT_CLKCTL2
, &err
);
5259 for (fn
= 0; fn
<= numfn
; fn
++) {
5260 cis
[fn
] = kzalloc(SBSDIO_CIS_SIZE_LIMIT
, GFP_ATOMIC
);
5262 DHD_INFO(("dhdsdio_probe: fn %d cis malloc "
5267 err
= bcmsdh_cis_read(sdh
, fn
, cis
[fn
],
5268 SBSDIO_CIS_SIZE_LIMIT
);
5270 DHD_INFO(("dhdsdio_probe: fn %d cis read "
5271 "err %d\n", fn
, err
));
5275 dhd_dump_cis(fn
, cis
[fn
]);
5284 DHD_ERROR(("dhdsdio_probe: error read/parsing CIS\n"));
5288 #endif /* DHD_DEBUG */
5290 /* si_attach() will provide an SI handle and scan the backplane */
5291 bus
->sih
= si_attach((uint
) devid
, regsva
, DHD_BUS
, sdh
,
5292 &bus
->vars
, &bus
->varsz
);
5294 DHD_ERROR(("%s: si_attach failed!\n", __func__
));
5298 bcmsdh_chipinfo(sdh
, bus
->sih
->chip
, bus
->sih
->chiprev
);
5300 if (!dhdsdio_chipmatch((u16
) bus
->sih
->chip
)) {
5301 DHD_ERROR(("%s: unsupported chip: 0x%04x\n",
5302 __func__
, bus
->sih
->chip
));
5306 si_sdiod_drive_strength_init(bus
->sih
, dhd_sdiod_drive_strength
);
5308 /* Get info on the ARM and SOCRAM cores... */
5309 if (!DHD_NOPMU(bus
)) {
5310 if ((si_setcore(bus
->sih
, ARM7S_CORE_ID
, 0)) ||
5311 (si_setcore(bus
->sih
, ARMCM3_CORE_ID
, 0))) {
5312 bus
->armrev
= si_corerev(bus
->sih
);
5314 DHD_ERROR(("%s: failed to find ARM core!\n", __func__
));
5317 bus
->orig_ramsize
= si_socram_size(bus
->sih
);
5318 if (!(bus
->orig_ramsize
)) {
5319 DHD_ERROR(("%s: failed to find SOCRAM memory!\n",
5323 bus
->ramsize
= bus
->orig_ramsize
;
5324 if (dhd_dongle_memsize
)
5325 dhd_dongle_setmemsize(bus
, dhd_dongle_memsize
);
5327 DHD_ERROR(("DHD: dongle ram size is set to %d(orig %d)\n",
5328 bus
->ramsize
, bus
->orig_ramsize
));
5331 /* ...but normally deal with the SDPCMDEV core */
5332 bus
->regs
= si_setcore(bus
->sih
, PCMCIA_CORE_ID
, 0);
5334 bus
->regs
= si_setcore(bus
->sih
, SDIOD_CORE_ID
, 0);
5336 DHD_ERROR(("%s: failed to find SDIODEV core!\n",
5341 bus
->sdpcmrev
= si_corerev(bus
->sih
);
5343 /* Set core control so an SDIO reset does a backplane reset */
5344 OR_REG(&bus
->regs
->corecontrol
, CC_BPRESEN
);
5346 pktq_init(&bus
->txq
, (PRIOMASK
+ 1), TXQLEN
);
5348 /* Locate an appropriately-aligned portion of hdrbuf */
5349 bus
->rxhdr
= (u8
*) roundup((unsigned long)&bus
->hdrbuf
[0], DHD_SDALIGN
);
5351 /* Set the poll and/or interrupt flags */
5352 bus
->intr
= (bool) dhd_intr
;
5353 bus
->poll
= (bool) dhd_poll
;
5363 static bool dhdsdio_probe_malloc(dhd_bus_t
*bus
, void *sdh
)
5365 DHD_TRACE(("%s: Enter\n", __func__
));
5367 if (bus
->dhd
->maxctl
) {
5369 roundup((bus
->dhd
->maxctl
+ SDPCM_HDRLEN
),
5370 ALIGNMENT
) + DHD_SDALIGN
;
5371 bus
->rxbuf
= kmalloc(bus
->rxblen
, GFP_ATOMIC
);
5372 if (!(bus
->rxbuf
)) {
5373 DHD_ERROR(("%s: kmalloc of %d-byte rxbuf failed\n",
5374 __func__
, bus
->rxblen
));
5379 /* Allocate buffer to receive glomed packet */
5380 bus
->databuf
= kmalloc(MAX_DATA_BUF
, GFP_ATOMIC
);
5381 if (!(bus
->databuf
)) {
5382 DHD_ERROR(("%s: kmalloc of %d-byte databuf failed\n",
5383 __func__
, MAX_DATA_BUF
));
5384 /* release rxbuf which was already located as above */
5390 /* Align the buffer */
5391 if ((unsigned long)bus
->databuf
% DHD_SDALIGN
)
5393 bus
->databuf
+ (DHD_SDALIGN
-
5394 ((unsigned long)bus
->databuf
% DHD_SDALIGN
));
5396 bus
->dataptr
= bus
->databuf
;
5404 static bool dhdsdio_probe_init(dhd_bus_t
*bus
, void *sdh
)
5408 DHD_TRACE(("%s: Enter\n", __func__
));
5411 dhdsdio_pktgen_init(bus
);
5414 /* Disable F2 to clear any intermediate frame state on the dongle */
5415 bcmsdh_cfg_write(sdh
, SDIO_FUNC_0
, SDIOD_CCCR_IOEN
, SDIO_FUNC_ENABLE_1
,
5418 bus
->dhd
->busstate
= DHD_BUS_DOWN
;
5419 bus
->sleeping
= false;
5420 bus
->rxflow
= false;
5421 bus
->prev_rxlim_hit
= 0;
5423 /* Done with backplane-dependent accesses, can drop clock... */
5424 bcmsdh_cfg_write(sdh
, SDIO_FUNC_1
, SBSDIO_FUNC1_CHIPCLKCSR
, 0, NULL
);
5426 /* ...and initialize clock/power states */
5427 bus
->clkstate
= CLK_SDONLY
;
5428 bus
->idletime
= (s32
) dhd_idletime
;
5429 bus
->idleclock
= DHD_IDLE_ACTIVE
;
5431 /* Query the SD clock speed */
5432 if (bcmsdh_iovar_op(sdh
, "sd_divisor", NULL
, 0,
5433 &bus
->sd_divisor
, sizeof(s32
),
5434 false) != BCME_OK
) {
5435 DHD_ERROR(("%s: fail on %s get\n", __func__
, "sd_divisor"));
5436 bus
->sd_divisor
= -1;
5438 DHD_INFO(("%s: Initial value for %s is %d\n",
5439 __func__
, "sd_divisor", bus
->sd_divisor
));
5442 /* Query the SD bus mode */
5443 if (bcmsdh_iovar_op(sdh
, "sd_mode", NULL
, 0,
5444 &bus
->sd_mode
, sizeof(s32
), false) != BCME_OK
) {
5445 DHD_ERROR(("%s: fail on %s get\n", __func__
, "sd_mode"));
5448 DHD_INFO(("%s: Initial value for %s is %d\n",
5449 __func__
, "sd_mode", bus
->sd_mode
));
5452 /* Query the F2 block size, set roundup accordingly */
5454 if (bcmsdh_iovar_op(sdh
, "sd_blocksize", &fnum
, sizeof(s32
),
5455 &bus
->blocksize
, sizeof(s32
), false) != BCME_OK
) {
5457 DHD_ERROR(("%s: fail on %s get\n", __func__
, "sd_blocksize"));
5459 DHD_INFO(("%s: Initial value for %s is %d\n",
5460 __func__
, "sd_blocksize", bus
->blocksize
));
5462 bus
->roundup
= min(max_roundup
, bus
->blocksize
);
5464 /* Query if bus module supports packet chaining,
5465 default to use if supported */
5466 if (bcmsdh_iovar_op(sdh
, "sd_rxchain", NULL
, 0,
5467 &bus
->sd_rxchain
, sizeof(s32
),
5468 false) != BCME_OK
) {
5469 bus
->sd_rxchain
= false;
5471 DHD_INFO(("%s: bus module (through bcmsdh API) %s chaining\n",
5473 (bus
->sd_rxchain
? "supports" : "does not support")));
5475 bus
->use_rxchain
= (bool) bus
->sd_rxchain
;
5481 dhd_bus_download_firmware(struct dhd_bus
*bus
, char *fw_path
, char *nv_path
)
5484 bus
->fw_path
= fw_path
;
5485 bus
->nv_path
= nv_path
;
5487 ret
= dhdsdio_download_firmware(bus
, bus
->sdh
);
5493 dhdsdio_download_firmware(struct dhd_bus
*bus
, void *sdh
)
5497 /* Download the firmware */
5498 dhdsdio_clkctl(bus
, CLK_AVAIL
, false);
5500 ret
= _dhdsdio_download_firmware(bus
) == 0;
5502 dhdsdio_clkctl(bus
, CLK_SDONLY
, false);
5507 /* Detach and free everything */
5508 static void dhdsdio_release(dhd_bus_t
*bus
)
5510 DHD_TRACE(("%s: Enter\n", __func__
));
5513 /* De-register interrupt handler */
5514 bcmsdh_intr_disable(bus
->sdh
);
5515 bcmsdh_intr_dereg(bus
->sdh
);
5519 dhdsdio_release_dongle(bus
);
5521 dhd_detach(bus
->dhd
);
5525 dhdsdio_release_malloc(bus
);
5530 DHD_TRACE(("%s: Disconnected\n", __func__
));
5533 static void dhdsdio_release_malloc(dhd_bus_t
*bus
)
5535 DHD_TRACE(("%s: Enter\n", __func__
));
5537 if (bus
->dhd
&& bus
->dhd
->dongle_reset
)
5542 bus
->rxctl
= bus
->rxbuf
= NULL
;
5547 kfree(bus
->databuf
);
5548 bus
->databuf
= NULL
;
5552 static void dhdsdio_release_dongle(dhd_bus_t
*bus
)
5554 DHD_TRACE(("%s: Enter\n", __func__
));
5556 if (bus
->dhd
&& bus
->dhd
->dongle_reset
)
5560 dhdsdio_clkctl(bus
, CLK_AVAIL
, false);
5561 #if !defined(BCMLXSDMMC)
5562 si_watchdog(bus
->sih
, 4);
5563 #endif /* !defined(BCMLXSDMMC) */
5564 dhdsdio_clkctl(bus
, CLK_NONE
, false);
5565 si_detach(bus
->sih
);
5566 if (bus
->vars
&& bus
->varsz
)
5571 DHD_TRACE(("%s: Disconnected\n", __func__
));
5574 static void dhdsdio_disconnect(void *ptr
)
5576 dhd_bus_t
*bus
= (dhd_bus_t
*)ptr
;
5578 DHD_TRACE(("%s: Enter\n", __func__
));
5582 dhdsdio_release(bus
);
5585 DHD_TRACE(("%s: Disconnected\n", __func__
));
5588 /* Register/Unregister functions are called by the main DHD entry
5589 * point (e.g. module insertion) to link with the bus driver, in
5590 * order to look for or await the device.
5593 static bcmsdh_driver_t dhd_sdio
= {
5598 int dhd_bus_register(void)
5600 DHD_TRACE(("%s: Enter\n", __func__
));
5602 return bcmsdh_register(&dhd_sdio
);
5605 void dhd_bus_unregister(void)
5607 DHD_TRACE(("%s: Enter\n", __func__
));
5609 bcmsdh_unregister();
5612 #ifdef BCMEMBEDIMAGE
5613 static int dhdsdio_download_code_array(struct dhd_bus
*bus
)
5618 DHD_INFO(("%s: download embedded firmware...\n", __func__
));
5620 /* Download image */
5621 while ((offset
+ MEMBLOCK
) < sizeof(dlarray
)) {
5623 dhdsdio_membytes(bus
, true, offset
, dlarray
+ offset
,
5626 DHD_ERROR(("%s: error %d on writing %d membytes at "
5628 __func__
, bcmerror
, MEMBLOCK
, offset
));
5635 if (offset
< sizeof(dlarray
)) {
5636 bcmerror
= dhdsdio_membytes(bus
, true, offset
,
5638 sizeof(dlarray
) - offset
);
5640 DHD_ERROR(("%s: error %d on writing %d membytes at "
5641 "0x%08x\n", __func__
, bcmerror
,
5642 sizeof(dlarray
) - offset
, offset
));
5647 /* Upload and compare the downloaded code */
5649 unsigned char *ularray
;
5651 ularray
= kmalloc(bus
->ramsize
, GFP_ATOMIC
);
5652 /* Upload image to verify downloaded contents. */
5654 memset(ularray
, 0xaa, bus
->ramsize
);
5655 while ((offset
+ MEMBLOCK
) < sizeof(dlarray
)) {
5657 dhdsdio_membytes(bus
, false, offset
,
5658 ularray
+ offset
, MEMBLOCK
);
5660 DHD_ERROR(("%s: error %d on reading %d membytes"
5662 __func__
, bcmerror
, MEMBLOCK
, offset
));
5669 if (offset
< sizeof(dlarray
)) {
5670 bcmerror
= dhdsdio_membytes(bus
, false, offset
,
5672 sizeof(dlarray
) - offset
);
5674 DHD_ERROR(("%s: error %d on reading %d membytes at 0x%08x\n",
5676 sizeof(dlarray
) - offset
, offset
));
5681 if (memcmp(dlarray
, ularray
, sizeof(dlarray
))) {
5682 DHD_ERROR(("%s: Downloaded image is corrupted.\n",
5687 DHD_ERROR(("%s: Download/Upload/Compare succeeded.\n",
5692 #endif /* DHD_DEBUG */
5697 #endif /* BCMEMBEDIMAGE */
5699 static int dhdsdio_download_code_file(struct dhd_bus
*bus
, char *fw_path
)
5705 u8
*memblock
= NULL
, *memptr
;
5707 DHD_INFO(("%s: download firmware %s\n", __func__
, fw_path
));
5709 image
= dhd_os_open_image(fw_path
);
5713 memptr
= memblock
= kmalloc(MEMBLOCK
+ DHD_SDALIGN
, GFP_ATOMIC
);
5714 if (memblock
== NULL
) {
5715 DHD_ERROR(("%s: Failed to allocate memory %d bytes\n",
5716 __func__
, MEMBLOCK
));
5719 if ((u32
)(unsigned long)memblock
% DHD_SDALIGN
)
5721 (DHD_SDALIGN
- ((u32
)(unsigned long)memblock
% DHD_SDALIGN
));
5723 /* Download image */
5725 dhd_os_get_image_block((char *)memptr
, MEMBLOCK
, image
))) {
5726 bcmerror
= dhdsdio_membytes(bus
, true, offset
, memptr
, len
);
5728 DHD_ERROR(("%s: error %d on writing %d membytes at "
5729 "0x%08x\n", __func__
, bcmerror
, MEMBLOCK
, offset
));
5741 dhd_os_close_image(image
);
5747 * ProcessVars:Takes a buffer of "<var>=<value>\n" lines read from a file
5748 * and ending in a NUL.
5749 * Removes carriage returns, empty lines, comment lines, and converts
5751 * Shortens buffer as needed and pads with NULs. End of buffer is marked
5755 static uint
process_nvram_vars(char *varbuf
, uint len
)
5764 findNewline
= false;
5767 for (n
= 0; n
< len
; n
++) {
5770 if (varbuf
[n
] == '\r')
5772 if (findNewline
&& varbuf
[n
] != '\n')
5774 findNewline
= false;
5775 if (varbuf
[n
] == '#') {
5779 if (varbuf
[n
] == '\n') {
5789 buf_len
= dp
- varbuf
;
5791 while (dp
< varbuf
+ n
)
5798 EXAMPLE: nvram_array
5801 Use carriage return at the end of each assignment,
5802 and an empty string with
5803 carriage return at the end of array.
5806 unsigned char nvram_array[] = {"name1=value1\n",
5807 "name2=value2\n", "\n"};
5808 Hex values start with 0x, and mac addr format: xx:xx:xx:xx:xx:xx.
5810 Search "EXAMPLE: nvram_array" to see how the array is activated.
5813 void dhd_bus_set_nvram_params(struct dhd_bus
*bus
, const char *nvram_params
)
5815 bus
->nvram_params
= nvram_params
;
5818 static int dhdsdio_download_nvram(struct dhd_bus
*bus
)
5823 char *memblock
= NULL
;
5826 bool nvram_file_exists
;
5828 nv_path
= bus
->nv_path
;
5830 nvram_file_exists
= ((nv_path
!= NULL
) && (nv_path
[0] != '\0'));
5831 if (!nvram_file_exists
&& (bus
->nvram_params
== NULL
))
5834 if (nvram_file_exists
) {
5835 image
= dhd_os_open_image(nv_path
);
5840 memblock
= kmalloc(MEMBLOCK
, GFP_ATOMIC
);
5841 if (memblock
== NULL
) {
5842 DHD_ERROR(("%s: Failed to allocate memory %d bytes\n",
5843 __func__
, MEMBLOCK
));
5847 /* Download variables */
5848 if (nvram_file_exists
) {
5849 len
= dhd_os_get_image_block(memblock
, MEMBLOCK
, image
);
5851 len
= strlen(bus
->nvram_params
);
5852 ASSERT(len
<= MEMBLOCK
);
5855 memcpy(memblock
, bus
->nvram_params
, len
);
5858 if (len
> 0 && len
< MEMBLOCK
) {
5859 bufp
= (char *)memblock
;
5861 len
= process_nvram_vars(bufp
, len
);
5865 bcmerror
= dhdsdio_downloadvars(bus
, memblock
, len
+ 1);
5867 DHD_ERROR(("%s: error downloading vars: %d\n",
5868 __func__
, bcmerror
));
5871 DHD_ERROR(("%s: error reading nvram file: %d\n",
5873 bcmerror
= BCME_SDIO_ERROR
;
5881 dhd_os_close_image(image
);
5886 static int _dhdsdio_download_firmware(struct dhd_bus
*bus
)
5890 bool embed
= false; /* download embedded firmware */
5891 bool dlok
= false; /* download firmware succeeded */
5893 /* Out immediately if no image to download */
5894 if ((bus
->fw_path
== NULL
) || (bus
->fw_path
[0] == '\0')) {
5895 #ifdef BCMEMBEDIMAGE
5902 /* Keep arm in reset */
5903 if (dhdsdio_download_state(bus
, true)) {
5904 DHD_ERROR(("%s: error placing ARM core in reset\n", __func__
));
5908 /* External image takes precedence if specified */
5909 if ((bus
->fw_path
!= NULL
) && (bus
->fw_path
[0] != '\0')) {
5910 if (dhdsdio_download_code_file(bus
, bus
->fw_path
)) {
5911 DHD_ERROR(("%s: dongle image file download failed\n",
5913 #ifdef BCMEMBEDIMAGE
5923 #ifdef BCMEMBEDIMAGE
5925 if (dhdsdio_download_code_array(bus
)) {
5926 DHD_ERROR(("%s: dongle image array download failed\n",
5935 DHD_ERROR(("%s: dongle image download failed\n", __func__
));
5939 /* EXAMPLE: nvram_array */
5940 /* If a valid nvram_arry is specified as above, it can be passed
5942 /* dhd_bus_set_nvram_params(bus, (char *)&nvram_array); */
5944 /* External nvram takes precedence if specified */
5945 if (dhdsdio_download_nvram(bus
)) {
5946 DHD_ERROR(("%s: dongle nvram file download failed\n",
5950 /* Take arm out of reset */
5951 if (dhdsdio_download_state(bus
, false)) {
5952 DHD_ERROR(("%s: error getting out of ARM core reset\n",
5964 dhd_bcmsdh_recv_buf(dhd_bus_t
*bus
, u32 addr
, uint fn
, uint flags
,
5965 u8
*buf
, uint nbytes
, struct sk_buff
*pkt
,
5966 bcmsdh_cmplt_fn_t complete
, void *handle
)
5970 /* 4329: GSPI check */
5972 bcmsdh_recv_buf(bus
->sdh
, addr
, fn
, flags
, buf
, nbytes
, pkt
,
5978 dhd_bcmsdh_send_buf(dhd_bus_t
*bus
, u32 addr
, uint fn
, uint flags
,
5979 u8
*buf
, uint nbytes
, struct sk_buff
*pkt
,
5980 bcmsdh_cmplt_fn_t complete
, void *handle
)
5982 return bcmsdh_send_buf
5983 (bus
->sdh
, addr
, fn
, flags
, buf
, nbytes
, pkt
, complete
,
5987 uint
dhd_bus_chip(struct dhd_bus
*bus
)
5989 ASSERT(bus
->sih
!= NULL
);
5990 return bus
->sih
->chip
;
5993 void *dhd_bus_pub(struct dhd_bus
*bus
)
5998 void *dhd_bus_txq(struct dhd_bus
*bus
)
6003 uint
dhd_bus_hdrlen(struct dhd_bus
*bus
)
6005 return SDPCM_HDRLEN
;
6008 int dhd_bus_devreset(dhd_pub_t
*dhdp
, u8 flag
)
6016 if (!bus
->dhd
->dongle_reset
) {
6017 /* Expect app to have torn down any
6018 connection before calling */
6019 /* Stop the bus, disable F2 */
6020 dhd_bus_stop(bus
, false);
6022 /* Clean tx/rx buffer pointers,
6023 detach from the dongle */
6024 dhdsdio_release_dongle(bus
);
6026 bus
->dhd
->dongle_reset
= true;
6027 bus
->dhd
->up
= false;
6029 DHD_TRACE(("%s: WLAN OFF DONE\n", __func__
));
6030 /* App can now remove power from device */
6032 bcmerror
= BCME_SDIO_ERROR
;
6034 /* App must have restored power to device before calling */
6036 DHD_TRACE(("\n\n%s: == WLAN ON ==\n", __func__
));
6038 if (bus
->dhd
->dongle_reset
) {
6040 /* Reset SD client */
6041 bcmsdh_reset(bus
->sdh
);
6043 /* Attempt to re-attach & download */
6044 if (dhdsdio_probe_attach(bus
, bus
->sdh
,
6045 (u32
*) SI_ENUM_BASE
,
6047 /* Attempt to download binary to the dongle */
6048 if (dhdsdio_probe_init
6050 && dhdsdio_download_firmware(bus
,
6053 /* Re-init bus, enable F2 transfer */
6054 dhd_bus_init((dhd_pub_t
*) bus
->dhd
,
6057 #if defined(OOB_INTR_ONLY)
6058 dhd_enable_oob_intr(bus
, true);
6059 #endif /* defined(OOB_INTR_ONLY) */
6061 bus
->dhd
->dongle_reset
= false;
6062 bus
->dhd
->up
= true;
6064 DHD_TRACE(("%s: WLAN ON DONE\n",
6067 bcmerror
= BCME_SDIO_ERROR
;
6069 bcmerror
= BCME_SDIO_ERROR
;
6071 bcmerror
= BCME_NOTDOWN
;
6072 DHD_ERROR(("%s: Set DEVRESET=false invoked when device "
6073 "is on\n", __func__
));
6074 bcmerror
= BCME_SDIO_ERROR
;