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>
18 #include <linux/kernel.h>
19 #include <linux/kthread.h>
20 #include <linux/printk.h>
21 #include <linux/pci_ids.h>
22 #include <linux/netdevice.h>
23 #include <linux/sched.h>
24 #include <linux/mmc/sdio.h>
25 #include <linux/mmc/sdio_func.h>
26 #include <linux/semaphore.h>
27 #include <linux/firmware.h>
28 #include <asm/unaligned.h>
30 #include <brcmu_wifi.h>
31 #include <brcmu_utils.h>
32 #include <brcm_hw_ids.h>
34 #include "sdio_host.h"
37 /* register access macros */
40 #define R_REG(r, typ) \
41 brcmf_sdcard_reg_read(NULL, (r), sizeof(typ))
43 #define R_REG(r, typ) \
45 __typeof(*(r)) __osl_v; \
46 __asm__ __volatile__("sync"); \
47 __osl_v = brcmf_sdcard_reg_read(NULL, (r),\
49 __asm__ __volatile__("sync"); \
54 #define W_REG(r, v, typ) do { \
55 brcmf_sdcard_reg_write(NULL, (r), sizeof(typ), (v)); \
57 #else /* __BIG_ENDIAN */
58 #define R_REG(r, typ) \
59 brcmf_sdcard_reg_read(NULL, (r), sizeof(typ))
60 #define W_REG(r, v, typ) do { \
61 brcmf_sdcard_reg_write(NULL, (r), sizeof(typ), (v)); \
63 #endif /* __BIG_ENDIAN */
65 #define AND_REG(r, v, typ) W_REG((r), R_REG(r, typ) & (v), typ)
66 #define OR_REG(r, v, typ) W_REG((r), R_REG(r, typ) | (v), typ)
68 #define SET_REG(r, mask, val, typ) \
69 W_REG((r), ((R_REG(r) & ~(mask)) | (val)), typ)
73 /* ARM trap handling */
75 /* Trap types defined by ARM (see arminc.h) */
77 /* Trap locations in lo memory */
79 #define FIRST_TRAP TR_RST
80 #define LAST_TRAP (TR_FIQ * TRAP_STRIDE)
82 #if defined(__ARM_ARCH_4T__)
83 #define MAX_TRAP_TYPE (TR_FIQ + 1)
84 #elif defined(__ARM_ARCH_7M__)
85 #define MAX_TRAP_TYPE (TR_ISR + ARMCM3_NUMINTS)
86 #endif /* __ARM_ARCH_7M__ */
88 /* The trap structure is defined here as offsets for assembly */
94 #define TR_REG(n) (TR_REGS + (n) * 4)
95 #define TR_SP TR_REG(13)
96 #define TR_LR TR_REG(14)
97 #define TR_PC TR_REG(15)
99 #define TRAP_T_SIZE 80
124 #define CBUF_LEN (128)
126 #define LOG_BUF_LEN 1024
129 u32 buf
; /* Can't be pointer on (64-bit) hosts */
132 char *_buf_compat
; /* Redundant pointer for backward compat. */
137 * When there is no UART (e.g. Quickturn),
138 * the host should write a complete
139 * input line directly into cbuf and then write
140 * the length into vcons_in.
141 * This may also be used when there is a real UART
142 * (at risk of conflicting with
143 * the real UART). vcons_out is currently unused.
145 volatile uint vcons_in
;
146 volatile uint vcons_out
;
148 /* Output (logging) buffer
149 * Console output is written to a ring buffer log_buf at index log_idx.
150 * The host may read the output when it sees log_idx advance.
151 * Output will be lost if the output wraps around faster than the host
156 /* Console input line buffer
157 * Characters are read one at a time into cbuf
158 * until <CR> is received, then
159 * the buffer is processed as a command line.
160 * Also used for virtual UART.
167 #include <chipcommon.h>
171 #include "dngl_stats.h"
174 #include "dhd_proto.h"
178 #ifndef DHDSDIO_MEM_DUMP_FNAME
179 #define DHDSDIO_MEM_DUMP_FNAME "mem_dump"
182 #define TXQLEN 2048 /* bulk tx queue length */
183 #define TXHI (TXQLEN - 256) /* turn on flow control above TXHI */
184 #define TXLOW (TXHI - 256) /* turn off flow control below TXLOW */
187 #define TXRETRIES 2 /* # of retries for tx frames */
189 #if defined(CONFIG_MACH_SANDGATE2G)
190 #define DHD_RXBOUND 250 /* Default for max rx frames in
193 #define DHD_RXBOUND 50 /* Default for max rx frames in
195 #endif /* defined(CONFIG_MACH_SANDGATE2G) */
197 #define DHD_TXBOUND 20 /* Default for max tx frames in
200 #define DHD_TXMINMAX 1 /* Max tx frames if rx still pending */
202 #define MEMBLOCK 2048 /* Block size used for downloading
204 #define MAX_DATA_BUF (32 * 1024) /* Must be large enough to hold
205 biggest possible glom */
207 #ifndef BRCMF_FIRSTREAD
208 #define BRCMF_FIRSTREAD 32
210 #if !ISPOWEROF2(BRCMF_FIRSTREAD)
211 #error BRCMF_FIRSTREAD is not a power of 2!
214 /* Total length of frame header for dongle protocol */
215 #define SDPCM_HDRLEN (SDPCM_FRAMETAG_LEN + SDPCM_SWHEADER_LEN)
217 #define SDPCM_RESERVE (SDPCM_HDRLEN + SDPCM_TEST_HDRLEN + BRCMF_SDALIGN)
219 #define SDPCM_RESERVE (SDPCM_HDRLEN + BRCMF_SDALIGN)
223 * Software allocation of To SB Mailbox resources
226 /* tosbmailbox bits corresponding to intstatus bits */
227 #define SMB_NAK (1 << 0) /* Frame NAK */
228 #define SMB_INT_ACK (1 << 1) /* Host Interrupt ACK */
229 #define SMB_USE_OOB (1 << 2) /* Use OOB Wakeup */
230 #define SMB_DEV_INT (1 << 3) /* Miscellaneous Interrupt */
232 /* tosbmailboxdata */
233 #define SMB_DATA_VERSION_SHIFT 16 /* host protocol version */
236 * Software allocation of To Host Mailbox resources
240 #define I_HMB_FC_STATE I_HMB_SW0 /* Flow Control State */
241 #define I_HMB_FC_CHANGE I_HMB_SW1 /* Flow Control State Changed */
242 #define I_HMB_FRAME_IND I_HMB_SW2 /* Frame Indication */
243 #define I_HMB_HOST_INT I_HMB_SW3 /* Miscellaneous Interrupt */
245 /* tohostmailboxdata */
246 #define HMB_DATA_NAKHANDLED 1 /* retransmit NAK'd frame */
247 #define HMB_DATA_DEVREADY 2 /* talk to host after enable */
248 #define HMB_DATA_FC 4 /* per prio flowcontrol update flag */
249 #define HMB_DATA_FWREADY 8 /* fw ready for protocol activity */
251 #define HMB_DATA_FCDATA_MASK 0xff000000
252 #define HMB_DATA_FCDATA_SHIFT 24
254 #define HMB_DATA_VERSION_MASK 0x00ff0000
255 #define HMB_DATA_VERSION_SHIFT 16
258 * Software-defined protocol header
261 /* Current protocol version */
262 #define SDPCM_PROT_VERSION 4
264 /* SW frame header */
265 #define SDPCM_PACKET_SEQUENCE(p) (((u8 *)p)[0] & 0xff)
267 #define SDPCM_CHANNEL_MASK 0x00000f00
268 #define SDPCM_CHANNEL_SHIFT 8
269 #define SDPCM_PACKET_CHANNEL(p) (((u8 *)p)[1] & 0x0f)
271 #define SDPCM_NEXTLEN_OFFSET 2
273 /* Data Offset from SOF (HW Tag, SW Tag, Pad) */
274 #define SDPCM_DOFFSET_OFFSET 3 /* Data Offset */
275 #define SDPCM_DOFFSET_VALUE(p) (((u8 *)p)[SDPCM_DOFFSET_OFFSET] & 0xff)
276 #define SDPCM_DOFFSET_MASK 0xff000000
277 #define SDPCM_DOFFSET_SHIFT 24
278 #define SDPCM_FCMASK_OFFSET 4 /* Flow control */
279 #define SDPCM_FCMASK_VALUE(p) (((u8 *)p)[SDPCM_FCMASK_OFFSET] & 0xff)
280 #define SDPCM_WINDOW_OFFSET 5 /* Credit based fc */
281 #define SDPCM_WINDOW_VALUE(p) (((u8 *)p)[SDPCM_WINDOW_OFFSET] & 0xff)
283 #define SDPCM_SWHEADER_LEN 8 /* SW header is 64 bits */
285 /* logical channel numbers */
286 #define SDPCM_CONTROL_CHANNEL 0 /* Control channel Id */
287 #define SDPCM_EVENT_CHANNEL 1 /* Asyc Event Indication Channel Id */
288 #define SDPCM_DATA_CHANNEL 2 /* Data Xmit/Recv Channel Id */
289 #define SDPCM_GLOM_CHANNEL 3 /* For coalesced packets */
290 #define SDPCM_TEST_CHANNEL 15 /* Reserved for test/debug packets */
292 #define SDPCM_SEQUENCE_WRAP 256 /* wrap-around val for 8bit frame seq */
294 #define SDPCM_GLOMDESC(p) (((u8 *)p)[1] & 0x80)
296 /* For TEST_CHANNEL packets, define another 4-byte header */
297 #define SDPCM_TEST_HDRLEN 4 /*
298 * Generally: Cmd(1), Ext(1), Len(2);
299 * Semantics of Ext byte depend on
300 * command. Len is current or requested
301 * frame length, not including test
302 * header; sent little-endian.
304 #define SDPCM_TEST_DISCARD 0x01 /* Receiver discards. Ext:pattern id. */
305 #define SDPCM_TEST_ECHOREQ 0x02 /* Echo request. Ext:pattern id. */
306 #define SDPCM_TEST_ECHORSP 0x03 /* Echo response. Ext:pattern id. */
307 #define SDPCM_TEST_BURST 0x04 /*
308 * Receiver to send a burst.
309 * Ext is a frame count
311 #define SDPCM_TEST_SEND 0x05 /*
312 * Receiver sets send mode.
313 * Ext is boolean on/off
316 /* Handy macro for filling in datagen packets with a pattern */
317 #define SDPCM_TEST_FILL(byteno, id) ((u8)(id + byteno))
320 * Shared structure between dongle and the host.
321 * The structure contains pointers to trap or assert information.
323 #define SDPCM_SHARED_VERSION 0x0002
324 #define SDPCM_SHARED_VERSION_MASK 0x00FF
325 #define SDPCM_SHARED_ASSERT_BUILT 0x0100
326 #define SDPCM_SHARED_ASSERT 0x0200
327 #define SDPCM_SHARED_TRAP 0x0400
330 /* Space for header read, limit for data packets */
332 #define MAX_HDR_READ 32
334 #if !ISPOWEROF2(MAX_HDR_READ)
335 #error MAX_HDR_READ is not a power of 2!
338 #define MAX_RX_DATASZ 2048
340 /* Maximum milliseconds to wait for F2 to come up */
341 #define DHD_WAIT_F2RDY 3000
343 /* Bump up limit on waiting for HT to account for first startup;
344 * if the image is doing a CRC calculation before programming the PMU
345 * for HT availability, it could take a couple hundred ms more, so
346 * max out at a 1 second (1000000us).
348 #if (PMU_MAX_TRANSITION_DLY <= 1000000)
349 #undef PMU_MAX_TRANSITION_DLY
350 #define PMU_MAX_TRANSITION_DLY 1000000
353 /* Value for ChipClockCSR during initial setup */
354 #define DHD_INIT_CLKCTL1 (SBSDIO_FORCE_HW_CLKREQ_OFF | \
355 SBSDIO_ALP_AVAIL_REQ)
356 #define DHD_INIT_CLKCTL2 (SBSDIO_FORCE_HW_CLKREQ_OFF | SBSDIO_FORCE_ALP)
358 /* Flags for SDH calls */
359 #define F2SYNC (SDIO_REQ_4BYTE | SDIO_REQ_FIXED)
362 #define SBIM_IBE 0x20000 /* inbanderror */
363 #define SBIM_TO 0x40000 /* timeout */
364 #define SBIM_BY 0x01800000 /* busy (sonics >= 2.3) */
365 #define SBIM_RJ 0x02000000 /* reject (sonics >= 2.3) */
368 #define SBTML_RESET 0x0001 /* reset */
369 #define SBTML_REJ_MASK 0x0006 /* reject field */
370 #define SBTML_REJ 0x0002 /* reject */
371 #define SBTML_TMPREJ 0x0004 /* temporary reject, for error recovery */
373 #define SBTML_SICF_SHIFT 16 /* Shift to locate the SI control flags in sbtml */
376 #define SBTMH_SERR 0x0001 /* serror */
377 #define SBTMH_INT 0x0002 /* interrupt */
378 #define SBTMH_BUSY 0x0004 /* busy */
379 #define SBTMH_TO 0x0020 /* timeout (sonics >= 2.3) */
381 #define SBTMH_SISF_SHIFT 16 /* Shift to locate the SI status flags in sbtmh */
384 #define SBIDL_INIT 0x80 /* initiator */
387 #define SBIDH_RC_MASK 0x000f /* revision code */
388 #define SBIDH_RCE_MASK 0x7000 /* revision code extension field */
389 #define SBIDH_RCE_SHIFT 8
390 #define SBCOREREV(sbidh) \
391 ((((sbidh) & SBIDH_RCE_MASK) >> SBIDH_RCE_SHIFT) | ((sbidh) & SBIDH_RC_MASK))
392 #define SBIDH_CC_MASK 0x8ff0 /* core code */
393 #define SBIDH_CC_SHIFT 4
394 #define SBIDH_VC_MASK 0xffff0000 /* vendor code */
395 #define SBIDH_VC_SHIFT 16
398 * Conversion of 802.1D priority to precedence level
400 #define PRIO2PREC(prio) \
401 (((prio) == PRIO_8021D_NONE || (prio) == PRIO_8021D_BE) ? \
404 BRCMF_SPINWAIT_SLEEP_INIT(sdioh_spinwait_sleep
);
407 * Core reg address translation.
408 * Both macro's returns a 32 bits byte address on the backplane bus.
410 #define CORE_CC_REG(base, field) (base + offsetof(chipcregs_t, field))
411 #define CORE_BUS_REG(base, field) \
412 (base + offsetof(struct sdpcmd_regs, field))
413 #define CORE_SB(base, field) \
414 (base + SBCONFIGOFF + offsetof(struct sbconfig, field))
418 u32 corecontrol
; /* 0x00, rev8 */
419 u32 corestatus
; /* rev8 */
421 u32 biststatus
; /* rev8 */
424 u16 pcmciamesportaladdr
; /* 0x010, rev8 */
426 u16 pcmciamesportalmask
; /* rev8 */
428 u16 pcmciawrframebc
; /* rev8 */
430 u16 pcmciaunderflowtimer
; /* rev8 */
434 u32 intstatus
; /* 0x020, rev8 */
435 u32 hostintmask
; /* rev8 */
436 u32 intmask
; /* rev8 */
437 u32 sbintstatus
; /* rev8 */
438 u32 sbintmask
; /* rev8 */
439 u32 funcintmask
; /* rev4 */
441 u32 tosbmailbox
; /* 0x040, rev8 */
442 u32 tohostmailbox
; /* rev8 */
443 u32 tosbmailboxdata
; /* rev8 */
444 u32 tohostmailboxdata
; /* rev8 */
446 /* synchronized access to registers in SDIO clock domain */
447 u32 sdioaccess
; /* 0x050, rev8 */
450 /* PCMCIA frame control */
451 u8 pcmciaframectrl
; /* 0x060, rev8 */
453 u8 pcmciawatermark
; /* rev8 */
456 /* interrupt batching control */
457 u32 intrcvlazy
; /* 0x100, rev8 */
461 u32 cmd52rd
; /* 0x110, rev8 */
462 u32 cmd52wr
; /* rev8 */
463 u32 cmd53rd
; /* rev8 */
464 u32 cmd53wr
; /* rev8 */
465 u32 abort
; /* rev8 */
466 u32 datacrcerror
; /* rev8 */
467 u32 rdoutofsync
; /* rev8 */
468 u32 wroutofsync
; /* rev8 */
469 u32 writebusy
; /* rev8 */
470 u32 readwait
; /* rev8 */
471 u32 readterm
; /* rev8 */
472 u32 writeterm
; /* rev8 */
474 u32 clockctlstatus
; /* rev8 */
477 u32 PAD
[128]; /* DMA engines */
479 /* SDIO/PCMCIA CIS region */
480 char cis
[512]; /* 0x400-0x5ff, rev6 */
482 /* PCMCIA function control registers */
483 char pcmciafcr
[256]; /* 0x600-6ff, rev6 */
486 /* PCMCIA backplane access */
487 u16 backplanecsr
; /* 0x76E, rev6 */
488 u16 backplaneaddr0
; /* rev6 */
489 u16 backplaneaddr1
; /* rev6 */
490 u16 backplaneaddr2
; /* rev6 */
491 u16 backplaneaddr3
; /* rev6 */
492 u16 backplanedata0
; /* rev6 */
493 u16 backplanedata1
; /* rev6 */
494 u16 backplanedata2
; /* rev6 */
495 u16 backplanedata3
; /* rev6 */
498 /* sprom "size" & "blank" info */
499 u16 spromstatus
; /* 0x7BE, rev2 */
506 /* Device console log buffer state */
508 uint count
; /* Poll interval msec counter */
509 uint log_addr
; /* Log struct address (fixed) */
510 struct rte_log log
; /* Log struct (host copy) */
511 uint bufsize
; /* Size of log buffer */
512 u8
*buf
; /* Log buffer (host copy) */
513 uint last
; /* Last buffer read index */
517 struct sdpcm_shared
{
521 u32 assert_file_addr
;
523 u32 console_addr
; /* Address of struct rte_console */
529 /* misc chip info needed by some of the routines */
536 u32 buscorebase
; /* 32 bits backplane bus address */
545 /* Private data for SDIO bus interaction */
547 struct brcmf_pub
*drvr
;
549 struct brcmf_sdio_card
*card
; /* Handle for sdio card calls */
550 struct chip_info
*ci
; /* Chip info struct */
551 char *vars
; /* Variables (from CIS and/or other) */
552 uint varsz
; /* Size of variables buffer */
553 u32 sbaddr
; /* Current SB window pointer (-1, invalid) */
555 uint sdpcmrev
; /* SDIO core revision */
556 uint armrev
; /* CPU core revision */
557 uint ramrev
; /* SOCRAM core revision */
558 u32 ramsize
; /* Size of RAM in SOCRAM (bytes) */
559 u32 orig_ramsize
; /* Size of RAM in SOCRAM (bytes) */
561 u32 bus
; /* gSPI or SDIO bus */
562 u32 hostintmask
; /* Copy of Host Interrupt Mask */
563 u32 intstatus
; /* Intstatus bits (events) pending */
564 bool dpc_sched
; /* Indicates DPC schedule (intrpt rcvd) */
565 bool fcstate
; /* State of dongle flow-control */
567 u16 cl_devid
; /* cached devid for brcmf_sdio_probe_attach() */
569 uint blocksize
; /* Block size of SDIO transfers */
570 uint roundup
; /* Max roundup limit */
572 struct pktq txq
; /* Queue length used for flow-control */
573 u8 flowcontrol
; /* per prio flow control bitmask */
574 u8 tx_seq
; /* Transmit sequence number (next) */
575 u8 tx_max
; /* Maximum transmit sequence allowed */
577 u8 hdrbuf
[MAX_HDR_READ
+ BRCMF_SDALIGN
];
578 u8
*rxhdr
; /* Header of current rx frame (in hdrbuf) */
579 u16 nextlen
; /* Next Read Len from last header */
580 u8 rx_seq
; /* Receive sequence number (expected) */
581 bool rxskip
; /* Skip receive (awaiting NAK ACK) */
583 struct sk_buff
*glomd
; /* Packet containing glomming descriptor */
584 struct sk_buff
*glom
; /* Packet chain for glommed superframe */
585 uint glomerr
; /* Glom packet read errors */
587 u8
*rxbuf
; /* Buffer for receiving control packets */
588 uint rxblen
; /* Allocated length of rxbuf */
589 u8
*rxctl
; /* Aligned pointer into rxbuf */
590 u8
*databuf
; /* Buffer for receiving big glom packet */
591 u8
*dataptr
; /* Aligned pointer into databuf */
592 uint rxlen
; /* Length of valid data in buffer */
594 u8 sdpcm_ver
; /* Bus protocol reported by dongle */
596 bool intr
; /* Use interrupts */
597 bool poll
; /* Use polling */
598 bool ipend
; /* Device interrupt is pending */
599 bool intdis
; /* Interrupts disabled by isr */
600 uint intrcount
; /* Count of device interrupt callbacks */
601 uint lastintrs
; /* Count as of last watchdog timer */
602 uint spurious
; /* Count of spurious interrupts */
603 uint pollrate
; /* Ticks between device polls */
604 uint polltick
; /* Tick counter */
605 uint pollcnt
; /* Count of active polls */
608 struct dhd_console console
; /* Console output polling support */
609 uint console_addr
; /* Console address from shared struct */
612 uint regfails
; /* Count of R_REG/W_REG failures */
614 uint clkstate
; /* State of sd and backplane clock(s) */
615 bool activity
; /* Activity flag for clock down */
616 s32 idletime
; /* Control for activity timeout */
617 s32 idlecount
; /* Activity timeout counter */
618 s32 idleclock
; /* How to set bus driver when idle */
620 bool use_rxchain
; /* If dhd should use PKT chains */
621 bool sleeping
; /* Is SDIO bus sleeping? */
622 bool rxflow_mode
; /* Rx flow control mode */
623 bool rxflow
; /* Is rx flow control on */
624 uint prev_rxlim_hit
; /* Is prev rx limit exceeded
625 (per dpc schedule) */
626 bool alp_only
; /* Don't use HT clock (ALP only) */
627 /* Field to decide if rx of control frames happen in rxbuf or lb-pool */
631 /* external loopback */
635 /* pktgen configuration */
636 uint pktgen_freq
; /* Ticks between bursts */
637 uint pktgen_count
; /* Packets to send each burst */
638 uint pktgen_print
; /* Bursts between count displays */
639 uint pktgen_total
; /* Stop after this many */
640 uint pktgen_minlen
; /* Minimum packet data len */
641 uint pktgen_maxlen
; /* Maximum packet data len */
642 uint pktgen_mode
; /* Configured mode: tx, rx, or echo */
643 uint pktgen_stop
; /* Number of tx failures causing stop */
645 /* active pktgen fields */
646 uint pktgen_tick
; /* Tick counter for bursts */
647 uint pktgen_ptick
; /* Burst counter for printing */
648 uint pktgen_sent
; /* Number of test packets generated */
649 uint pktgen_rcvd
; /* Number of test packets received */
650 uint pktgen_fail
; /* Number of failed send attempts */
651 u16 pktgen_len
; /* Length of next packet to send */
654 /* Some additional counters */
655 uint tx_sderrs
; /* Count of tx attempts with sd errors */
656 uint fcqueued
; /* Tx packets that got queued */
657 uint rxrtx
; /* Count of rtx requests (NAK to dongle) */
658 uint rx_toolong
; /* Receive frames too long to receive */
659 uint rxc_errors
; /* SDIO errors when reading control frames */
660 uint rx_hdrfail
; /* SDIO errors on header reads */
661 uint rx_badhdr
; /* Bad received headers (roosync?) */
662 uint rx_badseq
; /* Mismatched rx sequence number */
663 uint fc_rcvd
; /* Number of flow-control events received */
664 uint fc_xoff
; /* Number which turned on flow-control */
665 uint fc_xon
; /* Number which turned off flow-control */
666 uint rxglomfail
; /* Failed deglom attempts */
667 uint rxglomframes
; /* Number of glom frames (superframes) */
668 uint rxglompkts
; /* Number of packets from glom frames */
669 uint f2rxhdrs
; /* Number of header reads */
670 uint f2rxdata
; /* Number of frame data reads */
671 uint f2txdata
; /* Number of f2 frame writes */
672 uint f1regdata
; /* Number of f1 register accesses */
676 bool ctrl_frame_stat
;
679 wait_queue_head_t ctrl_wait
;
681 struct timer_list timer
;
682 struct completion watchdog_wait
;
683 struct task_struct
*watchdog_tsk
;
686 struct tasklet_struct tasklet
;
687 struct task_struct
*dpc_tsk
;
688 struct completion dpc_wait
;
691 struct semaphore sdsem
;
695 const struct firmware
*firmware
;
702 u32 sbipsflag
; /* initiator port ocp slave flag */
704 u32 sbtpsflag
; /* target port ocp slave flag */
706 u32 sbtmerrloga
; /* (sonics >= 2.3) */
708 u32 sbtmerrlog
; /* (sonics >= 2.3) */
710 u32 sbadmatch3
; /* address match3 */
712 u32 sbadmatch2
; /* address match2 */
714 u32 sbadmatch1
; /* address match1 */
716 u32 sbimstate
; /* initiator agent state */
717 u32 sbintvec
; /* interrupt mask */
718 u32 sbtmstatelow
; /* target state */
719 u32 sbtmstatehigh
; /* target state */
720 u32 sbbwa0
; /* bandwidth allocation table0 */
722 u32 sbimconfiglow
; /* initiator configuration */
723 u32 sbimconfighigh
; /* initiator configuration */
724 u32 sbadmatch0
; /* address match0 */
726 u32 sbtmconfiglow
; /* target configuration */
727 u32 sbtmconfighigh
; /* target configuration */
728 u32 sbbconfig
; /* broadcast configuration */
730 u32 sbbstate
; /* broadcast state */
732 u32 sbactcnfg
; /* activate configuration */
734 u32 sbflagst
; /* current sbflags */
736 u32 sbidlow
; /* identification */
737 u32 sbidhigh
; /* identification */
743 #define CLK_PENDING 2 /* Not used yet */
746 #define DHD_NOPMU(dhd) (false)
749 static int qcount
[NUMPRIO
];
750 static int tx_packets
[NUMPRIO
];
753 /* Deferred transmit */
754 uint brcmf_deferred_tx
= 1;
755 module_param(brcmf_deferred_tx
, uint
, 0);
757 /* Watchdog thread priority, -1 to use kernel timer */
758 int brcmf_watchdog_prio
= 97;
759 module_param(brcmf_watchdog_prio
, int, 0);
761 /* Watchdog interval */
762 uint brcmf_watchdog_ms
= 10;
763 module_param(brcmf_watchdog_ms
, uint
, 0);
765 /* DPC thread priority, -1 to use tasklet */
766 int brcmf_dpc_prio
= 98;
767 module_param(brcmf_dpc_prio
, int, 0);
770 /* Console poll interval */
771 uint brcmf_console_ms
;
772 module_param(brcmf_console_ms
, uint
, 0);
773 #endif /* DHD_DEBUG */
780 /* override the RAM size if possible */
781 #define DONGLE_MIN_MEMSIZE (128 * 1024)
782 int brcmf_dongle_memsize
;
784 static bool brcmf_alignctl
;
788 static bool retrydata
;
789 #define RETRYCHAN(chan) (((chan) == SDPCM_EVENT_CHANNEL) || retrydata)
791 static const uint watermark
= 8;
792 static const uint firstread
= BRCMF_FIRSTREAD
;
794 #define HDATLEN (firstread - (SDPCM_HDRLEN))
796 /* Retry count for register access failures */
797 static const uint retry_limit
= 2;
799 /* Force even SD lengths (some host controllers mess up on odd bytes) */
800 static bool forcealign
;
804 #define PKTALIGN(_p, _len, _align) \
807 datalign = (unsigned long)((_p)->data); \
808 datalign = roundup(datalign, (_align)) - datalign; \
809 ASSERT(datalign < (_align)); \
810 ASSERT((_p)->len >= ((_len) + datalign)); \
812 skb_pull((_p), datalign); \
813 __skb_trim((_p), (_len)); \
816 /* Limit on rounding up frames */
817 static const uint max_roundup
= 512;
819 /* Try doing readahead */
820 static bool brcmf_readahead
;
822 /* To check if there's window offered */
823 #define DATAOK(bus) \
824 (((u8)(bus->tx_max - bus->tx_seq) != 0) && \
825 (((u8)(bus->tx_max - bus->tx_seq) & 0x80) == 0))
828 * Reads a register in the SDIO hardware block. This block occupies a series of
829 * adresses on the 32 bit backplane bus.
832 r_sdreg32(struct brcmf_bus
*bus
, u32
*regvar
, u32 reg_offset
, u32
*retryvar
)
836 *regvar
= R_REG(bus
->ci
->buscorebase
+ reg_offset
, u32
);
837 } while (brcmf_sdcard_regfail(bus
->card
) &&
838 (++(*retryvar
) <= retry_limit
));
840 bus
->regfails
+= (*retryvar
-1);
841 if (*retryvar
> retry_limit
) {
842 DHD_ERROR(("FAILED READ %Xh\n", reg_offset
));
849 w_sdreg32(struct brcmf_bus
*bus
, u32 regval
, u32 reg_offset
, u32
*retryvar
)
853 W_REG(bus
->ci
->buscorebase
+ reg_offset
, regval
, u32
);
854 } while (brcmf_sdcard_regfail(bus
->card
) &&
855 (++(*retryvar
) <= retry_limit
));
857 bus
->regfails
+= (*retryvar
-1);
858 if (*retryvar
> retry_limit
)
859 DHD_ERROR(("FAILED REGISTER WRITE %Xh\n", reg_offset
));
863 #define DHD_BUS SDIO_BUS
865 #define PKT_AVAILABLE() (intstatus & I_HMB_FRAME_IND)
867 #define HOSTINTMASK (I_HMB_SW_MASK | I_CHIPACTIVE)
870 static void brcmf_sdbrcm_checkdied(struct brcmf_bus
*bus
, void *pkt
, uint seq
);
871 static void brcmf_sdbrcm_sdtest_set(struct brcmf_bus
*bus
, bool start
);
875 static int brcmf_sdbrcm_bus_console_in(struct brcmf_pub
*drvr
,
876 unsigned char *msg
, uint msglen
);
877 static int brcmf_sdbrcm_checkdied(struct brcmf_bus
*bus
, u8
*data
, uint size
);
878 static int brcmf_sdbrcm_mem_dump(struct brcmf_bus
*bus
);
880 static int brcmf_sdbrcm_download_state(struct brcmf_bus
*bus
, bool enter
);
882 static void brcmf_sdbrcm_release(struct brcmf_bus
*bus
);
883 static void brcmf_sdbrcm_release_malloc(struct brcmf_bus
*bus
);
884 static void brcmf_sdbrcm_disconnect(void *ptr
);
885 static bool brcmf_sdbrcm_chipmatch(u16 chipid
);
886 static bool brcmf_sdbrcm_probe_attach(struct brcmf_bus
*bus
, void *card
,
887 u32 regsva
, u16 devid
);
888 static bool brcmf_sdbrcm_probe_malloc(struct brcmf_bus
*bus
, void *card
);
889 static bool brcmf_sdbrcm_probe_init(struct brcmf_bus
*bus
, void *card
);
890 static void brcmf_sdbrcm_release_dongle(struct brcmf_bus
*bus
);
892 static uint
brcmf_process_nvram_vars(char *varbuf
, uint len
);
894 static void brcmf_sdbrcm_setmemsize(struct brcmf_bus
*bus
, int mem_size
);
895 static int brcmf_sdbrcm_send_buf(struct brcmf_bus
*bus
, u32 addr
, uint fn
,
896 uint flags
, u8
*buf
, uint nbytes
,
898 void (*complete
)(void *handle
, int status
,
902 static bool brcmf_sdbrcm_download_firmware(struct brcmf_bus
*bus
, void *card
);
903 static int _brcmf_sdbrcm_download_firmware(struct brcmf_bus
*bus
);
905 static int brcmf_sdbrcm_download_code_file(struct brcmf_bus
*bus
);
906 static int brcmf_sdbrcm_download_nvram(struct brcmf_bus
*bus
);
909 brcmf_sdbrcm_chip_disablecore(struct brcmf_sdio_card
*card
, u32 corebase
);
911 static int brcmf_sdbrcm_chip_attach(struct brcmf_bus
*bus
, u32 regs
);
914 brcmf_sdbrcm_chip_resetcore(struct brcmf_sdio_card
*card
, u32 corebase
);
916 static void brcmf_sdbrcm_sdiod_drive_strength_init(struct brcmf_bus
*bus
,
918 static void brcmf_sdbrcm_chip_detach(struct brcmf_bus
*bus
);
919 static void brcmf_sdbrcm_wait_for_event(struct brcmf_bus
*bus
, bool *lockvar
);
920 static void brcmf_sdbrcm_wait_event_wakeup(struct brcmf_bus
*bus
);
921 static void brcmf_sdbrcm_watchdog(unsigned long data
);
922 static int brcmf_sdbrcm_watchdog_thread(void *data
);
923 static int brcmf_sdbrcm_dpc_thread(void *data
);
924 static void brcmf_sdbrcm_dpc_tasklet(unsigned long data
);
925 static void brcmf_sdbrcm_sched_dpc(struct brcmf_bus
*bus
);
926 static void brcmf_sdbrcm_sdlock(struct brcmf_bus
*bus
);
927 static void brcmf_sdbrcm_sdunlock(struct brcmf_bus
*bus
);
928 static int brcmf_sdbrcm_get_image(char *buf
, int len
, struct brcmf_bus
*bus
);
930 /* Packet free applicable unconditionally for sdio and sdspi.
931 * Conditional if bufpool was present for gspi bus.
933 static void brcmf_sdbrcm_pktfree2(struct brcmf_bus
*bus
, struct sk_buff
*pkt
)
935 if ((bus
->bus
!= SPI_BUS
) || bus
->usebufpool
)
936 brcmu_pkt_buf_free_skb(pkt
);
939 static void brcmf_sdbrcm_setmemsize(struct brcmf_bus
*bus
, int mem_size
)
941 s32 min_size
= DONGLE_MIN_MEMSIZE
;
942 /* Restrict the memsize to user specified limit */
943 DHD_ERROR(("user: Restrict the dongle ram size to %d, min %d\n",
944 brcmf_dongle_memsize
, min_size
));
945 if ((brcmf_dongle_memsize
> min_size
) &&
946 (brcmf_dongle_memsize
< (s32
) bus
->orig_ramsize
))
947 bus
->ramsize
= brcmf_dongle_memsize
;
950 static int brcmf_sdbrcm_set_siaddr_window(struct brcmf_bus
*bus
, u32 address
)
953 brcmf_sdcard_cfg_write(bus
->card
, SDIO_FUNC_1
, SBSDIO_FUNC1_SBADDRLOW
,
954 (address
>> 8) & SBSDIO_SBADDRLOW_MASK
, &err
);
956 brcmf_sdcard_cfg_write(bus
->card
, SDIO_FUNC_1
,
957 SBSDIO_FUNC1_SBADDRMID
,
958 (address
>> 16) & SBSDIO_SBADDRMID_MASK
, &err
);
960 brcmf_sdcard_cfg_write(bus
->card
, SDIO_FUNC_1
,
961 SBSDIO_FUNC1_SBADDRHIGH
,
962 (address
>> 24) & SBSDIO_SBADDRHIGH_MASK
,
967 /* Turn backplane clock on or off */
968 static int brcmf_sdbrcm_htclk(struct brcmf_bus
*bus
, bool on
, bool pendok
)
971 u8 clkctl
, clkreq
, devctl
;
972 struct brcmf_sdio_card
*card
;
974 DHD_TRACE(("%s: Enter\n", __func__
));
980 /* Request HT Avail */
982 bus
->alp_only
? SBSDIO_ALP_AVAIL_REQ
: SBSDIO_HT_AVAIL_REQ
;
984 if ((bus
->ci
->chip
== BCM4329_CHIP_ID
)
985 && (bus
->ci
->chiprev
== 0))
986 clkreq
|= SBSDIO_FORCE_ALP
;
988 brcmf_sdcard_cfg_write(card
, SDIO_FUNC_1
,
989 SBSDIO_FUNC1_CHIPCLKCSR
, clkreq
, &err
);
991 DHD_ERROR(("%s: HT Avail request error: %d\n",
996 if (pendok
&& ((bus
->ci
->buscoretype
== PCMCIA_CORE_ID
)
997 && (bus
->ci
->buscorerev
== 9))) {
999 r_sdreg32(bus
, &dummy
,
1000 offsetof(struct sdpcmd_regs
, clockctlstatus
),
1004 /* Check current status */
1005 clkctl
= brcmf_sdcard_cfg_read(card
, SDIO_FUNC_1
,
1006 SBSDIO_FUNC1_CHIPCLKCSR
, &err
);
1008 DHD_ERROR(("%s: HT Avail read error: %d\n",
1013 /* Go to pending and await interrupt if appropriate */
1014 if (!SBSDIO_CLKAV(clkctl
, bus
->alp_only
) && pendok
) {
1015 /* Allow only clock-available interrupt */
1016 devctl
= brcmf_sdcard_cfg_read(card
, SDIO_FUNC_1
,
1017 SBSDIO_DEVICE_CTL
, &err
);
1019 DHD_ERROR(("%s: Devctl error setting CA: %d\n",
1024 devctl
|= SBSDIO_DEVCTL_CA_INT_ONLY
;
1025 brcmf_sdcard_cfg_write(card
, SDIO_FUNC_1
,
1026 SBSDIO_DEVICE_CTL
, devctl
, &err
);
1027 DHD_INFO(("CLKCTL: set PENDING\n"));
1028 bus
->clkstate
= CLK_PENDING
;
1031 } else if (bus
->clkstate
== CLK_PENDING
) {
1032 /* Cancel CA-only interrupt filter */
1034 brcmf_sdcard_cfg_read(card
, SDIO_FUNC_1
,
1035 SBSDIO_DEVICE_CTL
, &err
);
1036 devctl
&= ~SBSDIO_DEVCTL_CA_INT_ONLY
;
1037 brcmf_sdcard_cfg_write(card
, SDIO_FUNC_1
,
1038 SBSDIO_DEVICE_CTL
, devctl
, &err
);
1041 /* Otherwise, wait here (polling) for HT Avail */
1042 if (!SBSDIO_CLKAV(clkctl
, bus
->alp_only
)) {
1043 BRCMF_SPINWAIT_SLEEP(sdioh_spinwait_sleep
,
1045 brcmf_sdcard_cfg_read(card
, SDIO_FUNC_1
,
1046 SBSDIO_FUNC1_CHIPCLKCSR
,
1048 !SBSDIO_CLKAV(clkctl
, bus
->alp_only
)),
1049 PMU_MAX_TRANSITION_DLY
);
1052 DHD_ERROR(("%s: HT Avail request error: %d\n",
1056 if (!SBSDIO_CLKAV(clkctl
, bus
->alp_only
)) {
1057 DHD_ERROR(("%s: HT Avail timeout (%d): clkctl 0x%02x\n",
1058 __func__
, PMU_MAX_TRANSITION_DLY
, clkctl
));
1062 /* Mark clock available */
1063 bus
->clkstate
= CLK_AVAIL
;
1064 DHD_INFO(("CLKCTL: turned ON\n"));
1067 if (bus
->alp_only
!= true) {
1068 if (SBSDIO_ALPONLY(clkctl
)) {
1069 DHD_ERROR(("%s: HT Clock should be on.\n",
1073 #endif /* defined (BCMDBG) */
1075 bus
->activity
= true;
1079 if (bus
->clkstate
== CLK_PENDING
) {
1080 /* Cancel CA-only interrupt filter */
1081 devctl
= brcmf_sdcard_cfg_read(card
, SDIO_FUNC_1
,
1082 SBSDIO_DEVICE_CTL
, &err
);
1083 devctl
&= ~SBSDIO_DEVCTL_CA_INT_ONLY
;
1084 brcmf_sdcard_cfg_write(card
, SDIO_FUNC_1
,
1085 SBSDIO_DEVICE_CTL
, devctl
, &err
);
1088 bus
->clkstate
= CLK_SDONLY
;
1089 brcmf_sdcard_cfg_write(card
, SDIO_FUNC_1
,
1090 SBSDIO_FUNC1_CHIPCLKCSR
, clkreq
, &err
);
1091 DHD_INFO(("CLKCTL: turned OFF\n"));
1093 DHD_ERROR(("%s: Failed access turning clock off: %d\n",
1101 /* Change idle/active SD state */
1102 static int brcmf_sdbrcm_sdclk(struct brcmf_bus
*bus
, bool on
)
1104 DHD_TRACE(("%s: Enter\n", __func__
));
1107 bus
->clkstate
= CLK_SDONLY
;
1109 bus
->clkstate
= CLK_NONE
;
1114 /* Transition SD and backplane clock readiness */
1115 static int brcmf_sdbrcm_clkctl(struct brcmf_bus
*bus
, uint target
, bool pendok
)
1118 uint oldstate
= bus
->clkstate
;
1121 DHD_TRACE(("%s: Enter\n", __func__
));
1123 /* Early exit if we're already there */
1124 if (bus
->clkstate
== target
) {
1125 if (target
== CLK_AVAIL
) {
1126 brcmf_sdbrcm_wd_timer(bus
, brcmf_watchdog_ms
);
1127 bus
->activity
= true;
1134 /* Make sure SD clock is available */
1135 if (bus
->clkstate
== CLK_NONE
)
1136 brcmf_sdbrcm_sdclk(bus
, true);
1137 /* Now request HT Avail on the backplane */
1138 brcmf_sdbrcm_htclk(bus
, true, pendok
);
1139 brcmf_sdbrcm_wd_timer(bus
, brcmf_watchdog_ms
);
1140 bus
->activity
= true;
1144 /* Remove HT request, or bring up SD clock */
1145 if (bus
->clkstate
== CLK_NONE
)
1146 brcmf_sdbrcm_sdclk(bus
, true);
1147 else if (bus
->clkstate
== CLK_AVAIL
)
1148 brcmf_sdbrcm_htclk(bus
, false, false);
1150 DHD_ERROR(("brcmf_sdbrcm_clkctl: request for %d -> %d"
1151 "\n", bus
->clkstate
, target
));
1152 brcmf_sdbrcm_wd_timer(bus
, brcmf_watchdog_ms
);
1156 /* Make sure to remove HT request */
1157 if (bus
->clkstate
== CLK_AVAIL
)
1158 brcmf_sdbrcm_htclk(bus
, false, false);
1159 /* Now remove the SD clock */
1160 brcmf_sdbrcm_sdclk(bus
, false);
1161 brcmf_sdbrcm_wd_timer(bus
, 0);
1165 DHD_INFO(("brcmf_sdbrcm_clkctl: %d -> %d\n", oldstate
, bus
->clkstate
));
1171 int brcmf_sdbrcm_bussleep(struct brcmf_bus
*bus
, bool sleep
)
1173 struct brcmf_sdio_card
*card
= bus
->card
;
1176 DHD_INFO(("brcmf_sdbrcm_bussleep: request %s (currently %s)\n",
1177 (sleep
? "SLEEP" : "WAKE"),
1178 (bus
->sleeping
? "SLEEP" : "WAKE")));
1180 /* Done if we're already in the requested state */
1181 if (sleep
== bus
->sleeping
)
1184 /* Going to sleep: set the alarm and turn off the lights... */
1186 /* Don't sleep if something is pending */
1187 if (bus
->dpc_sched
|| bus
->rxskip
|| pktq_len(&bus
->txq
))
1190 /* Disable SDIO interrupts (no longer interested) */
1191 brcmf_sdcard_intr_disable(bus
->card
);
1193 /* Make sure the controller has the bus up */
1194 brcmf_sdbrcm_clkctl(bus
, CLK_AVAIL
, false);
1196 /* Tell device to start using OOB wakeup */
1197 w_sdreg32(bus
, SMB_USE_OOB
,
1198 offsetof(struct sdpcmd_regs
, tosbmailbox
), &retries
);
1199 if (retries
> retry_limit
)
1200 DHD_ERROR(("CANNOT SIGNAL CHIP, WILL NOT WAKE UP!!\n"));
1202 /* Turn off our contribution to the HT clock request */
1203 brcmf_sdbrcm_clkctl(bus
, CLK_SDONLY
, false);
1205 brcmf_sdcard_cfg_write(card
, SDIO_FUNC_1
,
1206 SBSDIO_FUNC1_CHIPCLKCSR
,
1207 SBSDIO_FORCE_HW_CLKREQ_OFF
, NULL
);
1209 /* Isolate the bus */
1210 if (bus
->ci
->chip
!= BCM4329_CHIP_ID
1211 && bus
->ci
->chip
!= BCM4319_CHIP_ID
) {
1212 brcmf_sdcard_cfg_write(card
, SDIO_FUNC_1
,
1214 SBSDIO_DEVCTL_PADS_ISO
, NULL
);
1218 bus
->sleeping
= true;
1221 /* Waking up: bus power up is ok, set local state */
1223 brcmf_sdcard_cfg_write(card
, SDIO_FUNC_1
,
1224 SBSDIO_FUNC1_CHIPCLKCSR
, 0, NULL
);
1226 /* Force pad isolation off if possible
1227 (in case power never toggled) */
1228 if ((bus
->ci
->buscoretype
== PCMCIA_CORE_ID
)
1229 && (bus
->ci
->buscorerev
>= 10))
1230 brcmf_sdcard_cfg_write(card
, SDIO_FUNC_1
,
1231 SBSDIO_DEVICE_CTL
, 0, NULL
);
1233 /* Make sure the controller has the bus up */
1234 brcmf_sdbrcm_clkctl(bus
, CLK_AVAIL
, false);
1236 /* Send misc interrupt to indicate OOB not needed */
1237 w_sdreg32(bus
, 0, offsetof(struct sdpcmd_regs
, tosbmailboxdata
),
1239 if (retries
<= retry_limit
)
1240 w_sdreg32(bus
, SMB_DEV_INT
,
1241 offsetof(struct sdpcmd_regs
, tosbmailbox
),
1244 if (retries
> retry_limit
)
1245 DHD_ERROR(("CANNOT SIGNAL CHIP TO CLEAR OOB!!\n"));
1247 /* Make sure we have SD bus access */
1248 brcmf_sdbrcm_clkctl(bus
, CLK_SDONLY
, false);
1251 bus
->sleeping
= false;
1253 /* Enable interrupts again */
1254 if (bus
->intr
&& (bus
->drvr
->busstate
== DHD_BUS_DATA
)) {
1255 bus
->intdis
= false;
1256 brcmf_sdcard_intr_enable(bus
->card
);
1263 #define BUS_WAKE(bus) \
1265 if ((bus)->sleeping) \
1266 brcmf_sdbrcm_bussleep((bus), false); \
1269 /* Writes a HW/SW header into the packet and sends it. */
1270 /* Assumes: (a) header space already there, (b) caller holds lock */
1271 static int brcmf_sdbrcm_txpkt(struct brcmf_bus
*bus
, struct sk_buff
*pkt
, uint chan
,
1279 struct brcmf_sdio_card
*card
;
1280 struct sk_buff
*new;
1283 DHD_TRACE(("%s: Enter\n", __func__
));
1287 if (bus
->drvr
->dongle_reset
) {
1292 frame
= (u8
*) (pkt
->data
);
1294 /* Add alignment padding, allocate new packet if needed */
1295 pad
= ((unsigned long)frame
% BRCMF_SDALIGN
);
1297 if (skb_headroom(pkt
) < pad
) {
1298 DHD_INFO(("%s: insufficient headroom %d for %d pad\n",
1299 __func__
, skb_headroom(pkt
), pad
));
1300 bus
->drvr
->tx_realloc
++;
1301 new = brcmu_pkt_buf_get_skb(pkt
->len
+ BRCMF_SDALIGN
);
1303 DHD_ERROR(("%s: couldn't allocate new %d-byte "
1305 __func__
, pkt
->len
+ BRCMF_SDALIGN
));
1310 PKTALIGN(new, pkt
->len
, BRCMF_SDALIGN
);
1311 memcpy(new->data
, pkt
->data
, pkt
->len
);
1313 brcmu_pkt_buf_free_skb(pkt
);
1314 /* free the pkt if canned one is not used */
1317 frame
= (u8
*) (pkt
->data
);
1318 ASSERT(((unsigned long)frame
% BRCMF_SDALIGN
) == 0);
1322 frame
= (u8
*) (pkt
->data
);
1324 ASSERT((pad
+ SDPCM_HDRLEN
) <= (int)(pkt
->len
));
1325 memset(frame
, 0, pad
+ SDPCM_HDRLEN
);
1328 ASSERT(pad
< BRCMF_SDALIGN
);
1330 /* Hardware tag: 2 byte len followed by 2 byte ~len check (all LE) */
1331 len
= (u16
) (pkt
->len
);
1332 *(u16
*) frame
= cpu_to_le16(len
);
1333 *(((u16
*) frame
) + 1) = cpu_to_le16(~len
);
1335 /* Software tag: channel, sequence number, data offset */
1337 ((chan
<< SDPCM_CHANNEL_SHIFT
) & SDPCM_CHANNEL_MASK
) | bus
->tx_seq
|
1339 SDPCM_HDRLEN
) << SDPCM_DOFFSET_SHIFT
) & SDPCM_DOFFSET_MASK
);
1341 put_unaligned_le32(swheader
, frame
+ SDPCM_FRAMETAG_LEN
);
1342 put_unaligned_le32(0, frame
+ SDPCM_FRAMETAG_LEN
+ sizeof(swheader
));
1345 tx_packets
[pkt
->priority
]++;
1346 if (DHD_BYTES_ON() &&
1347 (((DHD_CTL_ON() && (chan
== SDPCM_CONTROL_CHANNEL
)) ||
1348 (DHD_DATA_ON() && (chan
!= SDPCM_CONTROL_CHANNEL
))))) {
1349 printk(KERN_DEBUG
"Tx Frame:\n");
1350 print_hex_dump_bytes("", DUMP_PREFIX_OFFSET
, frame
, len
);
1351 } else if (DHD_HDRS_ON()) {
1352 printk(KERN_DEBUG
"TxHdr:\n");
1353 print_hex_dump_bytes("", DUMP_PREFIX_OFFSET
,
1354 frame
, min_t(u16
, len
, 16));
1358 /* Raise len to next SDIO block to eliminate tail command */
1359 if (bus
->roundup
&& bus
->blocksize
&& (len
> bus
->blocksize
)) {
1360 u16 pad
= bus
->blocksize
- (len
% bus
->blocksize
);
1361 if ((pad
<= bus
->roundup
) && (pad
< bus
->blocksize
))
1363 } else if (len
% BRCMF_SDALIGN
) {
1364 len
+= BRCMF_SDALIGN
- (len
% BRCMF_SDALIGN
);
1367 /* Some controllers have trouble with odd bytes -- round to even */
1368 if (forcealign
&& (len
& (ALIGNMENT
- 1))) {
1369 len
= roundup(len
, ALIGNMENT
);
1373 ret
= brcmf_sdbrcm_send_buf(bus
, brcmf_sdcard_cur_sbwad(card
),
1374 SDIO_FUNC_2
, F2SYNC
, frame
, len
, pkt
, NULL
, NULL
);
1376 ASSERT(ret
!= -BCME_PENDING
);
1379 /* On failure, abort the command
1380 and terminate the frame */
1381 DHD_INFO(("%s: sdio error %d, abort command and "
1382 "terminate frame.\n", __func__
, ret
));
1385 brcmf_sdcard_abort(card
, SDIO_FUNC_2
);
1386 brcmf_sdcard_cfg_write(card
, SDIO_FUNC_1
,
1387 SBSDIO_FUNC1_FRAMECTRL
, SFC_WF_TERM
,
1391 for (i
= 0; i
< 3; i
++) {
1393 hi
= brcmf_sdcard_cfg_read(card
, SDIO_FUNC_1
,
1394 SBSDIO_FUNC1_WFRAMEBCHI
,
1396 lo
= brcmf_sdcard_cfg_read(card
, SDIO_FUNC_1
,
1397 SBSDIO_FUNC1_WFRAMEBCLO
,
1399 bus
->f1regdata
+= 2;
1400 if ((hi
== 0) && (lo
== 0))
1406 bus
->tx_seq
= (bus
->tx_seq
+ 1) % SDPCM_SEQUENCE_WRAP
;
1408 } while ((ret
< 0) && retrydata
&& retries
++ < TXRETRIES
);
1411 /* restore pkt buffer pointer before calling tx complete routine */
1412 skb_pull(pkt
, SDPCM_HDRLEN
+ pad
);
1413 brcmf_sdbrcm_sdunlock(bus
);
1414 brcmf_txcomplete(bus
->drvr
, pkt
, ret
!= 0);
1415 brcmf_sdbrcm_sdlock(bus
);
1418 brcmu_pkt_buf_free_skb(pkt
);
1423 int brcmf_sdbrcm_bus_txdata(struct brcmf_bus
*bus
, struct sk_buff
*pkt
)
1428 DHD_TRACE(("%s: Enter\n", __func__
));
1433 /* Push the test header if doing loopback */
1434 if (bus
->ext_loop
) {
1436 skb_push(pkt
, SDPCM_TEST_HDRLEN
);
1438 *data
++ = SDPCM_TEST_ECHOREQ
;
1439 *data
++ = (u8
) bus
->loopid
++;
1440 *data
++ = (datalen
>> 0);
1441 *data
++ = (datalen
>> 8);
1442 datalen
+= SDPCM_TEST_HDRLEN
;
1446 /* Add space for the header */
1447 skb_push(pkt
, SDPCM_HDRLEN
);
1448 ASSERT(IS_ALIGNED((unsigned long)(pkt
->data
), 2));
1450 prec
= PRIO2PREC((pkt
->priority
& PRIOMASK
));
1452 /* Check for existing queue, current flow-control,
1453 pending event, or pending clock */
1454 if (brcmf_deferred_tx
|| bus
->fcstate
|| pktq_len(&bus
->txq
)
1455 || bus
->dpc_sched
|| (!DATAOK(bus
))
1456 || (bus
->flowcontrol
& NBITVAL(prec
))
1457 || (bus
->clkstate
!= CLK_AVAIL
)) {
1458 DHD_TRACE(("%s: deferring pktq len %d\n", __func__
,
1459 pktq_len(&bus
->txq
)));
1462 /* Priority based enq */
1463 spin_lock_bh(&bus
->txqlock
);
1464 if (brcmf_c_prec_enq(bus
->drvr
, &bus
->txq
, pkt
, prec
) == false) {
1465 skb_pull(pkt
, SDPCM_HDRLEN
);
1466 brcmf_txcomplete(bus
->drvr
, pkt
, false);
1467 brcmu_pkt_buf_free_skb(pkt
);
1468 DHD_ERROR(("%s: out of bus->txq !!!\n", __func__
));
1473 spin_unlock_bh(&bus
->txqlock
);
1475 if (pktq_len(&bus
->txq
) >= TXHI
)
1476 brcmf_txflowcontrol(bus
->drvr
, 0, ON
);
1479 if (pktq_plen(&bus
->txq
, prec
) > qcount
[prec
])
1480 qcount
[prec
] = pktq_plen(&bus
->txq
, prec
);
1482 /* Schedule DPC if needed to send queued packet(s) */
1483 if (brcmf_deferred_tx
&& !bus
->dpc_sched
) {
1484 bus
->dpc_sched
= true;
1485 brcmf_sdbrcm_sched_dpc(bus
);
1488 /* Lock: we're about to use shared data/code (and SDIO) */
1489 brcmf_sdbrcm_sdlock(bus
);
1491 /* Otherwise, send it now */
1493 /* Make sure back plane ht clk is on, no pending allowed */
1494 brcmf_sdbrcm_clkctl(bus
, CLK_AVAIL
, true);
1497 DHD_TRACE(("%s: calling txpkt\n", __func__
));
1498 ret
= brcmf_sdbrcm_txpkt(bus
, pkt
, SDPCM_DATA_CHANNEL
, true);
1500 ret
= brcmf_sdbrcm_txpkt(bus
, pkt
,
1501 (bus
->ext_loop
? SDPCM_TEST_CHANNEL
:
1502 SDPCM_DATA_CHANNEL
), true);
1505 bus
->drvr
->tx_errors
++;
1507 bus
->drvr
->dstats
.tx_bytes
+= datalen
;
1509 if (bus
->idletime
== BRCMF_IDLE_IMMEDIATE
&&
1511 bus
->activity
= false;
1512 brcmf_sdbrcm_clkctl(bus
, CLK_NONE
, true);
1515 brcmf_sdbrcm_sdunlock(bus
);
1521 static uint
brcmf_sdbrcm_sendfromq(struct brcmf_bus
*bus
, uint maxframes
)
1523 struct sk_buff
*pkt
;
1526 int ret
= 0, prec_out
;
1531 struct brcmf_pub
*drvr
= bus
->drvr
;
1533 DHD_TRACE(("%s: Enter\n", __func__
));
1535 tx_prec_map
= ~bus
->flowcontrol
;
1537 /* Send frames until the limit or some other event */
1538 for (cnt
= 0; (cnt
< maxframes
) && DATAOK(bus
); cnt
++) {
1539 spin_lock_bh(&bus
->txqlock
);
1540 pkt
= brcmu_pktq_mdeq(&bus
->txq
, tx_prec_map
, &prec_out
);
1542 spin_unlock_bh(&bus
->txqlock
);
1545 spin_unlock_bh(&bus
->txqlock
);
1546 datalen
= pkt
->len
- SDPCM_HDRLEN
;
1549 ret
= brcmf_sdbrcm_txpkt(bus
, pkt
, SDPCM_DATA_CHANNEL
, true);
1551 ret
= brcmf_sdbrcm_txpkt(bus
, pkt
,
1552 (bus
->ext_loop
? SDPCM_TEST_CHANNEL
:
1553 SDPCM_DATA_CHANNEL
), true);
1556 bus
->drvr
->tx_errors
++;
1558 bus
->drvr
->dstats
.tx_bytes
+= datalen
;
1560 /* In poll mode, need to check for other events */
1561 if (!bus
->intr
&& cnt
) {
1562 /* Check device status, signal pending interrupt */
1563 r_sdreg32(bus
, &intstatus
,
1564 offsetof(struct sdpcmd_regs
, intstatus
),
1567 if (brcmf_sdcard_regfail(bus
->card
))
1569 if (intstatus
& bus
->hostintmask
)
1574 /* Deflow-control stack if needed */
1575 if (drvr
->up
&& (drvr
->busstate
== DHD_BUS_DATA
) &&
1576 drvr
->txoff
&& (pktq_len(&bus
->txq
) < TXLOW
))
1577 brcmf_txflowcontrol(drvr
, 0, OFF
);
1583 brcmf_sdbrcm_bus_txctl(struct brcmf_bus
*bus
, unsigned char *msg
, uint msglen
)
1589 struct brcmf_sdio_card
*card
= bus
->card
;
1594 DHD_TRACE(("%s: Enter\n", __func__
));
1596 if (bus
->drvr
->dongle_reset
)
1599 /* Back the pointer to make a room for bus header */
1600 frame
= msg
- SDPCM_HDRLEN
;
1601 len
= (msglen
+= SDPCM_HDRLEN
);
1603 /* Add alignment padding (optional for ctl frames) */
1604 if (brcmf_alignctl
) {
1605 doff
= ((unsigned long)frame
% BRCMF_SDALIGN
);
1610 memset(frame
, 0, doff
+ SDPCM_HDRLEN
);
1612 ASSERT(doff
< BRCMF_SDALIGN
);
1614 doff
+= SDPCM_HDRLEN
;
1616 /* Round send length to next SDIO block */
1617 if (bus
->roundup
&& bus
->blocksize
&& (len
> bus
->blocksize
)) {
1618 u16 pad
= bus
->blocksize
- (len
% bus
->blocksize
);
1619 if ((pad
<= bus
->roundup
) && (pad
< bus
->blocksize
))
1621 } else if (len
% BRCMF_SDALIGN
) {
1622 len
+= BRCMF_SDALIGN
- (len
% BRCMF_SDALIGN
);
1625 /* Satisfy length-alignment requirements */
1626 if (forcealign
&& (len
& (ALIGNMENT
- 1)))
1627 len
= roundup(len
, ALIGNMENT
);
1629 ASSERT(IS_ALIGNED((unsigned long)frame
, 2));
1631 /* Need to lock here to protect txseq and SDIO tx calls */
1632 brcmf_sdbrcm_sdlock(bus
);
1636 /* Make sure backplane clock is on */
1637 brcmf_sdbrcm_clkctl(bus
, CLK_AVAIL
, false);
1639 /* Hardware tag: 2 byte len followed by 2 byte ~len check (all LE) */
1640 *(u16
*) frame
= cpu_to_le16((u16
) msglen
);
1641 *(((u16
*) frame
) + 1) = cpu_to_le16(~msglen
);
1643 /* Software tag: channel, sequence number, data offset */
1645 ((SDPCM_CONTROL_CHANNEL
<< SDPCM_CHANNEL_SHIFT
) &
1647 | bus
->tx_seq
| ((doff
<< SDPCM_DOFFSET_SHIFT
) &
1648 SDPCM_DOFFSET_MASK
);
1649 put_unaligned_le32(swheader
, frame
+ SDPCM_FRAMETAG_LEN
);
1650 put_unaligned_le32(0, frame
+ SDPCM_FRAMETAG_LEN
+ sizeof(swheader
));
1653 DHD_INFO(("%s: No bus credit bus->tx_max %d, bus->tx_seq %d\n",
1654 __func__
, bus
->tx_max
, bus
->tx_seq
));
1655 bus
->ctrl_frame_stat
= true;
1657 bus
->ctrl_frame_buf
= frame
;
1658 bus
->ctrl_frame_len
= len
;
1660 brcmf_sdbrcm_wait_for_event(bus
, &bus
->ctrl_frame_stat
);
1662 if (bus
->ctrl_frame_stat
== false) {
1663 DHD_INFO(("%s: ctrl_frame_stat == false\n", __func__
));
1666 DHD_INFO(("%s: ctrl_frame_stat == true\n", __func__
));
1673 if (DHD_BYTES_ON() && DHD_CTL_ON()) {
1674 printk(KERN_DEBUG
"Tx Frame:\n");
1675 print_hex_dump_bytes("", DUMP_PREFIX_OFFSET
,
1677 } else if (DHD_HDRS_ON()) {
1678 printk(KERN_DEBUG
"TxHdr:\n");
1679 print_hex_dump_bytes("", DUMP_PREFIX_OFFSET
,
1680 frame
, min_t(u16
, len
, 16));
1685 bus
->ctrl_frame_stat
= false;
1686 ret
= brcmf_sdbrcm_send_buf(bus
,
1687 brcmf_sdcard_cur_sbwad(card
), SDIO_FUNC_2
,
1688 F2SYNC
, frame
, len
, NULL
, NULL
, NULL
);
1690 ASSERT(ret
!= -BCME_PENDING
);
1693 /* On failure, abort the command and
1694 terminate the frame */
1695 DHD_INFO(("%s: sdio error %d, abort command and terminate frame.\n",
1699 brcmf_sdcard_abort(card
, SDIO_FUNC_2
);
1701 brcmf_sdcard_cfg_write(card
, SDIO_FUNC_1
,
1702 SBSDIO_FUNC1_FRAMECTRL
,
1706 for (i
= 0; i
< 3; i
++) {
1708 hi
= brcmf_sdcard_cfg_read(card
,
1710 SBSDIO_FUNC1_WFRAMEBCHI
,
1712 lo
= brcmf_sdcard_cfg_read(card
,
1714 SBSDIO_FUNC1_WFRAMEBCLO
,
1716 bus
->f1regdata
+= 2;
1717 if ((hi
== 0) && (lo
== 0))
1724 (bus
->tx_seq
+ 1) % SDPCM_SEQUENCE_WRAP
;
1726 } while ((ret
< 0) && retries
++ < TXRETRIES
);
1729 if ((bus
->idletime
== BRCMF_IDLE_IMMEDIATE
) && !bus
->dpc_sched
) {
1730 bus
->activity
= false;
1731 brcmf_sdbrcm_clkctl(bus
, CLK_NONE
, true);
1734 brcmf_sdbrcm_sdunlock(bus
);
1737 bus
->drvr
->tx_ctlerrs
++;
1739 bus
->drvr
->tx_ctlpkts
++;
1741 return ret
? -EIO
: 0;
1744 int brcmf_sdbrcm_bus_rxctl(struct brcmf_bus
*bus
, unsigned char *msg
, uint msglen
)
1750 DHD_TRACE(("%s: Enter\n", __func__
));
1752 if (bus
->drvr
->dongle_reset
)
1755 /* Wait until control frame is available */
1756 timeleft
= brcmf_os_ioctl_resp_wait(bus
->drvr
, &bus
->rxlen
, &pending
);
1758 brcmf_sdbrcm_sdlock(bus
);
1760 memcpy(msg
, bus
->rxctl
, min(msglen
, rxlen
));
1762 brcmf_sdbrcm_sdunlock(bus
);
1765 DHD_CTL(("%s: resumed on rxctl frame, got %d expected %d\n",
1766 __func__
, rxlen
, msglen
));
1767 } else if (timeleft
== 0) {
1768 DHD_ERROR(("%s: resumed on timeout\n", __func__
));
1770 brcmf_sdbrcm_sdlock(bus
);
1771 brcmf_sdbrcm_checkdied(bus
, NULL
, 0);
1772 brcmf_sdbrcm_sdunlock(bus
);
1773 #endif /* DHD_DEBUG */
1774 } else if (pending
== true) {
1775 DHD_CTL(("%s: cancelled\n", __func__
));
1776 return -ERESTARTSYS
;
1778 DHD_CTL(("%s: resumed for unknown reason?\n", __func__
));
1780 brcmf_sdbrcm_sdlock(bus
);
1781 brcmf_sdbrcm_checkdied(bus
, NULL
, 0);
1782 brcmf_sdbrcm_sdunlock(bus
);
1783 #endif /* DHD_DEBUG */
1787 bus
->drvr
->rx_ctlpkts
++;
1789 bus
->drvr
->rx_ctlerrs
++;
1791 return rxlen
? (int)rxlen
: -ETIMEDOUT
;
1833 const struct brcmu_iovar dhdsdio_iovars
[] = {
1834 {"intr", IOV_INTR
, 0, IOVT_BOOL
, 0},
1835 {"sleep", IOV_SLEEP
, 0, IOVT_BOOL
, 0},
1836 {"pollrate", IOV_POLLRATE
, 0, IOVT_UINT32
, 0},
1837 {"idletime", IOV_IDLETIME
, 0, IOVT_INT32
, 0},
1838 {"idleclock", IOV_IDLECLOCK
, 0, IOVT_INT32
, 0},
1839 {"sd1idle", IOV_SD1IDLE
, 0, IOVT_BOOL
, 0},
1840 {"membytes", IOV_MEMBYTES
, 0, IOVT_BUFFER
, 2 * sizeof(int)},
1841 {"memsize", IOV_MEMSIZE
, 0, IOVT_UINT32
, 0},
1842 {"download", IOV_DOWNLOAD
, 0, IOVT_BOOL
, 0},
1843 {"vars", IOV_VARS
, 0, IOVT_BUFFER
, 0},
1844 {"sdiod_drive", IOV_SDIOD_DRIVE
, 0, IOVT_UINT32
, 0},
1845 {"readahead", IOV_READAHEAD
, 0, IOVT_BOOL
, 0},
1846 {"sdrxchain", IOV_SDRXCHAIN
, 0, IOVT_BOOL
, 0},
1847 {"alignctl", IOV_ALIGNCTL
, 0, IOVT_BOOL
, 0},
1848 {"sdalign", IOV_SDALIGN
, 0, IOVT_BOOL
, 0},
1849 {"devreset", IOV_DEVRESET
, 0, IOVT_BOOL
, 0},
1850 {"wdtick", IOV_WDTICK
, 0, IOVT_UINT32
, 0},
1852 {"cons", IOV_CONS
, 0, IOVT_BUFFER
, 0}
1854 {"dconpoll", IOV_DCONSOLE_POLL
, 0, IOVT_UINT32
, 0}
1856 {"sdreg", IOV_SDREG
, 0, IOVT_BUFFER
, sizeof(struct brcmf_sdreg
)}
1858 {"sbreg", IOV_SBREG
, 0, IOVT_BUFFER
, sizeof(struct brcmf_sdreg
)}
1860 {"sd_cis", IOV_SDCIS
, 0, IOVT_BUFFER
, BRCMF_IOCTL_MAXLEN
}
1862 {"forcealign", IOV_FORCEEVEN
, 0, IOVT_BOOL
, 0}
1864 {"txbound", IOV_TXBOUND
, 0, IOVT_UINT32
, 0}
1866 {"rxbound", IOV_RXBOUND
, 0, IOVT_UINT32
, 0}
1868 {"txminmax", IOV_TXMINMAX
, 0, IOVT_UINT32
, 0}
1870 {"cpu", IOV_CPU
, 0, IOVT_BOOL
, 0}
1872 {"checkdied", IOV_CHECKDIED
, 0, IOVT_BUFFER
, 0}
1876 {"extloop", IOV_EXTLOOP
, 0, IOVT_BOOL
, 0}
1878 {"pktgen", IOV_PKTGEN
, 0, IOVT_BUFFER
, sizeof(struct brcmf_pktgen
)}
1886 dhd_dump_pct(struct brcmu_strbuf
*strbuf
, char *desc
, uint num
, uint div
)
1891 brcmu_bprintf(strbuf
, "%s N/A", desc
);
1894 q2
= (100 * (num
- (q1
* div
))) / div
;
1895 brcmu_bprintf(strbuf
, "%s %d.%02d", desc
, q1
, q2
);
1899 void brcmf_sdbrcm_bus_dump(struct brcmf_pub
*drvr
, struct brcmu_strbuf
*strbuf
)
1901 struct brcmf_bus
*bus
= drvr
->bus
;
1903 brcmu_bprintf(strbuf
, "Bus SDIO structure:\n");
1904 brcmu_bprintf(strbuf
,
1905 "hostintmask 0x%08x intstatus 0x%08x sdpcm_ver %d\n",
1906 bus
->hostintmask
, bus
->intstatus
, bus
->sdpcm_ver
);
1907 brcmu_bprintf(strbuf
,
1908 "fcstate %d qlen %d tx_seq %d, max %d, rxskip %d rxlen %d rx_seq %d\n",
1909 bus
->fcstate
, pktq_len(&bus
->txq
), bus
->tx_seq
, bus
->tx_max
,
1910 bus
->rxskip
, bus
->rxlen
, bus
->rx_seq
);
1911 brcmu_bprintf(strbuf
, "intr %d intrcount %d lastintrs %d spurious %d\n",
1912 bus
->intr
, bus
->intrcount
, bus
->lastintrs
, bus
->spurious
);
1913 brcmu_bprintf(strbuf
, "pollrate %d pollcnt %d regfails %d\n",
1914 bus
->pollrate
, bus
->pollcnt
, bus
->regfails
);
1916 brcmu_bprintf(strbuf
, "\nAdditional counters:\n");
1917 brcmu_bprintf(strbuf
,
1918 "tx_sderrs %d fcqueued %d rxrtx %d rx_toolong %d rxc_errors %d\n",
1919 bus
->tx_sderrs
, bus
->fcqueued
, bus
->rxrtx
, bus
->rx_toolong
,
1921 brcmu_bprintf(strbuf
, "rx_hdrfail %d badhdr %d badseq %d\n",
1922 bus
->rx_hdrfail
, bus
->rx_badhdr
, bus
->rx_badseq
);
1923 brcmu_bprintf(strbuf
, "fc_rcvd %d, fc_xoff %d, fc_xon %d\n",
1924 bus
->fc_rcvd
, bus
->fc_xoff
, bus
->fc_xon
);
1925 brcmu_bprintf(strbuf
, "rxglomfail %d, rxglomframes %d, rxglompkts %d\n",
1926 bus
->rxglomfail
, bus
->rxglomframes
, bus
->rxglompkts
);
1927 brcmu_bprintf(strbuf
, "f2rx (hdrs/data) %d (%d/%d), f2tx %d f1regs"
1929 (bus
->f2rxhdrs
+ bus
->f2rxdata
), bus
->f2rxhdrs
,
1930 bus
->f2rxdata
, bus
->f2txdata
, bus
->f1regdata
);
1932 dhd_dump_pct(strbuf
, "\nRx: pkts/f2rd", bus
->drvr
->rx_packets
,
1933 (bus
->f2rxhdrs
+ bus
->f2rxdata
));
1934 dhd_dump_pct(strbuf
, ", pkts/f1sd", bus
->drvr
->rx_packets
,
1936 dhd_dump_pct(strbuf
, ", pkts/sd", bus
->drvr
->rx_packets
,
1937 (bus
->f2rxhdrs
+ bus
->f2rxdata
+ bus
->f1regdata
));
1938 dhd_dump_pct(strbuf
, ", pkts/int", bus
->drvr
->rx_packets
,
1940 brcmu_bprintf(strbuf
, "\n");
1942 dhd_dump_pct(strbuf
, "Rx: glom pct", (100 * bus
->rxglompkts
),
1943 bus
->drvr
->rx_packets
);
1944 dhd_dump_pct(strbuf
, ", pkts/glom", bus
->rxglompkts
,
1946 brcmu_bprintf(strbuf
, "\n");
1948 dhd_dump_pct(strbuf
, "Tx: pkts/f2wr", bus
->drvr
->tx_packets
,
1950 dhd_dump_pct(strbuf
, ", pkts/f1sd", bus
->drvr
->tx_packets
,
1952 dhd_dump_pct(strbuf
, ", pkts/sd", bus
->drvr
->tx_packets
,
1953 (bus
->f2txdata
+ bus
->f1regdata
));
1954 dhd_dump_pct(strbuf
, ", pkts/int", bus
->drvr
->tx_packets
,
1956 brcmu_bprintf(strbuf
, "\n");
1958 dhd_dump_pct(strbuf
, "Total: pkts/f2rw",
1959 (bus
->drvr
->tx_packets
+ bus
->drvr
->rx_packets
),
1960 (bus
->f2txdata
+ bus
->f2rxhdrs
+ bus
->f2rxdata
));
1961 dhd_dump_pct(strbuf
, ", pkts/f1sd",
1962 (bus
->drvr
->tx_packets
+ bus
->drvr
->rx_packets
),
1964 dhd_dump_pct(strbuf
, ", pkts/sd",
1965 (bus
->drvr
->tx_packets
+ bus
->drvr
->rx_packets
),
1966 (bus
->f2txdata
+ bus
->f2rxhdrs
+ bus
->f2rxdata
+
1968 dhd_dump_pct(strbuf
, ", pkts/int",
1969 (bus
->drvr
->tx_packets
+ bus
->drvr
->rx_packets
),
1971 brcmu_bprintf(strbuf
, "\n\n");
1975 if (bus
->pktgen_count
) {
1976 brcmu_bprintf(strbuf
, "pktgen config and count:\n");
1977 brcmu_bprintf(strbuf
,
1978 "freq %d count %d print %d total %d min %d len %d\n",
1979 bus
->pktgen_freq
, bus
->pktgen_count
,
1980 bus
->pktgen_print
, bus
->pktgen_total
,
1981 bus
->pktgen_minlen
, bus
->pktgen_maxlen
);
1982 brcmu_bprintf(strbuf
, "send attempts %d rcvd %d fail %d\n",
1983 bus
->pktgen_sent
, bus
->pktgen_rcvd
,
1988 brcmu_bprintf(strbuf
, "dpc_sched %d host interrupt%spending\n",
1989 bus
->dpc_sched
, " not ");
1990 brcmu_bprintf(strbuf
, "blocksize %d roundup %d\n", bus
->blocksize
,
1993 brcmu_bprintf(strbuf
,
1994 "clkstate %d activity %d idletime %d idlecount %d sleeping %d\n",
1995 bus
->clkstate
, bus
->activity
, bus
->idletime
, bus
->idlecount
,
1999 void brcmf_bus_clearcounts(struct brcmf_pub
*drvr
)
2001 struct brcmf_bus
*bus
= (struct brcmf_bus
*) drvr
->bus
;
2003 bus
->intrcount
= bus
->lastintrs
= bus
->spurious
= bus
->regfails
= 0;
2004 bus
->rxrtx
= bus
->rx_toolong
= bus
->rxc_errors
= 0;
2005 bus
->rx_hdrfail
= bus
->rx_badhdr
= bus
->rx_badseq
= 0;
2006 bus
->tx_sderrs
= bus
->fc_rcvd
= bus
->fc_xoff
= bus
->fc_xon
= 0;
2007 bus
->rxglomfail
= bus
->rxglomframes
= bus
->rxglompkts
= 0;
2008 bus
->f2rxhdrs
= bus
->f2rxdata
= bus
->f2txdata
= bus
->f1regdata
= 0;
2012 static int brcmf_sdbrcm_pktgen_get(struct brcmf_bus
*bus
, u8
*arg
)
2014 struct brcmf_pktgen pktgen
;
2016 pktgen
.version
= BRCMF_PKTGEN_VERSION
;
2017 pktgen
.freq
= bus
->pktgen_freq
;
2018 pktgen
.count
= bus
->pktgen_count
;
2019 pktgen
.print
= bus
->pktgen_print
;
2020 pktgen
.total
= bus
->pktgen_total
;
2021 pktgen
.minlen
= bus
->pktgen_minlen
;
2022 pktgen
.maxlen
= bus
->pktgen_maxlen
;
2023 pktgen
.numsent
= bus
->pktgen_sent
;
2024 pktgen
.numrcvd
= bus
->pktgen_rcvd
;
2025 pktgen
.numfail
= bus
->pktgen_fail
;
2026 pktgen
.mode
= bus
->pktgen_mode
;
2027 pktgen
.stop
= bus
->pktgen_stop
;
2029 memcpy(arg
, &pktgen
, sizeof(pktgen
));
2034 static int brcmf_sdbrcm_pktgen_set(struct brcmf_bus
*bus
, u8
*arg
)
2036 struct brcmf_pktgen pktgen
;
2037 uint oldcnt
, oldmode
;
2039 memcpy(&pktgen
, arg
, sizeof(pktgen
));
2040 if (pktgen
.version
!= BRCMF_PKTGEN_VERSION
)
2043 oldcnt
= bus
->pktgen_count
;
2044 oldmode
= bus
->pktgen_mode
;
2046 bus
->pktgen_freq
= pktgen
.freq
;
2047 bus
->pktgen_count
= pktgen
.count
;
2048 bus
->pktgen_print
= pktgen
.print
;
2049 bus
->pktgen_total
= pktgen
.total
;
2050 bus
->pktgen_minlen
= pktgen
.minlen
;
2051 bus
->pktgen_maxlen
= pktgen
.maxlen
;
2052 bus
->pktgen_mode
= pktgen
.mode
;
2053 bus
->pktgen_stop
= pktgen
.stop
;
2055 bus
->pktgen_tick
= bus
->pktgen_ptick
= 0;
2056 bus
->pktgen_len
= max(bus
->pktgen_len
, bus
->pktgen_minlen
);
2057 bus
->pktgen_len
= min(bus
->pktgen_len
, bus
->pktgen_maxlen
);
2059 /* Clear counts for a new pktgen (mode change, or was stopped) */
2060 if (bus
->pktgen_count
&& (!oldcnt
|| oldmode
!= bus
->pktgen_mode
))
2061 bus
->pktgen_sent
= bus
->pktgen_rcvd
= bus
->pktgen_fail
= 0;
2068 brcmf_sdbrcm_membytes(struct brcmf_bus
*bus
, bool write
, u32 address
, u8
*data
,
2075 /* Determine initial transfer parameters */
2076 sdaddr
= address
& SBSDIO_SB_OFT_ADDR_MASK
;
2077 if ((sdaddr
+ size
) & SBSDIO_SBWINDOW_MASK
)
2078 dsize
= (SBSDIO_SB_OFT_ADDR_LIMIT
- sdaddr
);
2082 /* Set the backplane window to include the start address */
2083 bcmerror
= brcmf_sdbrcm_set_siaddr_window(bus
, address
);
2085 DHD_ERROR(("%s: window change failed\n", __func__
));
2089 /* Do the transfer(s) */
2091 DHD_INFO(("%s: %s %d bytes at offset 0x%08x in window 0x%08x\n",
2092 __func__
, (write
? "write" : "read"), dsize
,
2093 sdaddr
, (address
& SBSDIO_SBWINDOW_MASK
)));
2095 brcmf_sdcard_rwdata(bus
->card
, write
, sdaddr
, data
, dsize
);
2097 DHD_ERROR(("%s: membytes transfer failed\n", __func__
));
2101 /* Adjust for next transfer (if any) */
2106 bcmerror
= brcmf_sdbrcm_set_siaddr_window(bus
, address
);
2108 DHD_ERROR(("%s: window change failed\n",
2113 dsize
= min_t(uint
, SBSDIO_SB_OFT_ADDR_LIMIT
, size
);
2118 /* Return the window to backplane enumeration space for core access */
2119 if (brcmf_sdbrcm_set_siaddr_window(bus
,
2120 brcmf_sdcard_cur_sbwad(bus
->card
))) {
2121 DHD_ERROR(("%s: FAILED to set window back to 0x%x\n",
2122 __func__
, brcmf_sdcard_cur_sbwad(bus
->card
)));
2129 static int brcmf_sdbrcm_readshared(struct brcmf_bus
*bus
, struct sdpcm_shared
*sh
)
2134 /* Read last word in memory to determine address of
2135 sdpcm_shared structure */
2136 rv
= brcmf_sdbrcm_membytes(bus
, false, bus
->ramsize
- 4, (u8
*)&addr
,
2141 addr
= le32_to_cpu(addr
);
2143 DHD_INFO(("sdpcm_shared address 0x%08X\n", addr
));
2146 * Check if addr is valid.
2147 * NVRAM length at the end of memory should have been overwritten.
2149 if (addr
== 0 || ((~addr
>> 16) & 0xffff) == (addr
& 0xffff)) {
2150 DHD_ERROR(("%s: address (0x%08x) of sdpcm_shared invalid\n",
2155 /* Read rte_shared structure */
2156 rv
= brcmf_sdbrcm_membytes(bus
, false, addr
, (u8
*) sh
,
2157 sizeof(struct sdpcm_shared
));
2162 sh
->flags
= le32_to_cpu(sh
->flags
);
2163 sh
->trap_addr
= le32_to_cpu(sh
->trap_addr
);
2164 sh
->assert_exp_addr
= le32_to_cpu(sh
->assert_exp_addr
);
2165 sh
->assert_file_addr
= le32_to_cpu(sh
->assert_file_addr
);
2166 sh
->assert_line
= le32_to_cpu(sh
->assert_line
);
2167 sh
->console_addr
= le32_to_cpu(sh
->console_addr
);
2168 sh
->msgtrace_addr
= le32_to_cpu(sh
->msgtrace_addr
);
2170 if ((sh
->flags
& SDPCM_SHARED_VERSION_MASK
) != SDPCM_SHARED_VERSION
) {
2171 DHD_ERROR(("%s: sdpcm_shared version %d in dhd "
2172 "is different than sdpcm_shared version %d in dongle\n",
2173 __func__
, SDPCM_SHARED_VERSION
,
2174 sh
->flags
& SDPCM_SHARED_VERSION_MASK
));
2181 static int brcmf_sdbrcm_checkdied(struct brcmf_bus
*bus
, u8
*data
, uint size
)
2185 char *mbuffer
= NULL
;
2186 uint maxstrlen
= 256;
2188 struct brcmf_trap tr
;
2189 struct sdpcm_shared sdpcm_shared
;
2190 struct brcmu_strbuf strbuf
;
2192 DHD_TRACE(("%s: Enter\n", __func__
));
2196 * Called after a rx ctrl timeout. "data" is NULL.
2197 * allocate memory to trace the trap or assert.
2200 mbuffer
= data
= kmalloc(msize
, GFP_ATOMIC
);
2201 if (mbuffer
== NULL
) {
2202 DHD_ERROR(("%s: kmalloc(%d) failed\n", __func__
,
2209 str
= kmalloc(maxstrlen
, GFP_ATOMIC
);
2211 DHD_ERROR(("%s: kmalloc(%d) failed\n", __func__
, maxstrlen
));
2216 bcmerror
= brcmf_sdbrcm_readshared(bus
, &sdpcm_shared
);
2220 brcmu_binit(&strbuf
, data
, size
);
2222 brcmu_bprintf(&strbuf
,
2223 "msgtrace address : 0x%08X\nconsole address : 0x%08X\n",
2224 sdpcm_shared
.msgtrace_addr
, sdpcm_shared
.console_addr
);
2226 if ((sdpcm_shared
.flags
& SDPCM_SHARED_ASSERT_BUILT
) == 0) {
2227 /* NOTE: Misspelled assert is intentional - DO NOT FIX.
2228 * (Avoids conflict with real asserts for programmatic
2229 * parsing of output.)
2231 brcmu_bprintf(&strbuf
, "Assrt not built in dongle\n");
2234 if ((sdpcm_shared
.flags
& (SDPCM_SHARED_ASSERT
| SDPCM_SHARED_TRAP
)) ==
2236 /* NOTE: Misspelled assert is intentional - DO NOT FIX.
2237 * (Avoids conflict with real asserts for programmatic
2238 * parsing of output.)
2240 brcmu_bprintf(&strbuf
, "No trap%s in dongle",
2241 (sdpcm_shared
.flags
& SDPCM_SHARED_ASSERT_BUILT
)
2244 if (sdpcm_shared
.flags
& SDPCM_SHARED_ASSERT
) {
2245 /* Download assert */
2246 brcmu_bprintf(&strbuf
, "Dongle assert");
2247 if (sdpcm_shared
.assert_exp_addr
!= 0) {
2249 bcmerror
= brcmf_sdbrcm_membytes(bus
, false,
2250 sdpcm_shared
.assert_exp_addr
,
2251 (u8
*) str
, maxstrlen
);
2255 str
[maxstrlen
- 1] = '\0';
2256 brcmu_bprintf(&strbuf
, " expr \"%s\"", str
);
2259 if (sdpcm_shared
.assert_file_addr
!= 0) {
2261 bcmerror
= brcmf_sdbrcm_membytes(bus
, false,
2262 sdpcm_shared
.assert_file_addr
,
2263 (u8
*) str
, maxstrlen
);
2267 str
[maxstrlen
- 1] = '\0';
2268 brcmu_bprintf(&strbuf
, " file \"%s\"", str
);
2271 brcmu_bprintf(&strbuf
, " line %d ",
2272 sdpcm_shared
.assert_line
);
2275 if (sdpcm_shared
.flags
& SDPCM_SHARED_TRAP
) {
2276 bcmerror
= brcmf_sdbrcm_membytes(bus
, false,
2277 sdpcm_shared
.trap_addr
, (u8
*)&tr
,
2278 sizeof(struct brcmf_trap
));
2282 brcmu_bprintf(&strbuf
,
2283 "Dongle trap type 0x%x @ epc 0x%x, cpsr 0x%x, spsr 0x%x, sp 0x%x,"
2284 "lp 0x%x, rpc 0x%x Trap offset 0x%x, "
2285 "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",
2286 tr
.type
, tr
.epc
, tr
.cpsr
, tr
.spsr
, tr
.r13
,
2287 tr
.r14
, tr
.pc
, sdpcm_shared
.trap_addr
,
2288 tr
.r0
, tr
.r1
, tr
.r2
, tr
.r3
, tr
.r4
, tr
.r5
,
2293 if (sdpcm_shared
.flags
& (SDPCM_SHARED_ASSERT
| SDPCM_SHARED_TRAP
))
2294 DHD_ERROR(("%s: %s\n", __func__
, strbuf
.origbuf
));
2297 if (sdpcm_shared
.flags
& SDPCM_SHARED_TRAP
) {
2298 /* Mem dump to a file on device */
2299 brcmf_sdbrcm_mem_dump(bus
);
2310 static int brcmf_sdbrcm_mem_dump(struct brcmf_bus
*bus
)
2313 int size
; /* Full mem size */
2314 int start
= 0; /* Start address */
2315 int read_size
= 0; /* Read size of each iteration */
2316 u8
*buf
= NULL
, *databuf
= NULL
;
2318 /* Get full mem size */
2319 size
= bus
->ramsize
;
2320 buf
= kmalloc(size
, GFP_ATOMIC
);
2322 DHD_ERROR(("%s: Out of memory (%d bytes)\n", __func__
, size
));
2326 /* Read mem content */
2327 printk(KERN_DEBUG
"Dump dongle memory");
2330 read_size
= min(MEMBLOCK
, size
);
2331 ret
= brcmf_sdbrcm_membytes(bus
, false, start
, databuf
,
2334 DHD_ERROR(("%s: Error membytes %d\n", __func__
, ret
));
2340 /* Decrement size and increment start address */
2343 databuf
+= read_size
;
2345 printk(KERN_DEBUG
"Done\n");
2347 /* free buf before return !!! */
2348 if (brcmf_write_to_file(bus
->drvr
, buf
, bus
->ramsize
)) {
2349 DHD_ERROR(("%s: Error writing to files\n", __func__
));
2353 /* buf free handled in brcmf_write_to_file, not here */
2357 #define CONSOLE_LINE_MAX 192
2359 static int brcmf_sdbrcm_readconsole(struct brcmf_bus
*bus
)
2361 struct dhd_console
*c
= &bus
->console
;
2362 u8 line
[CONSOLE_LINE_MAX
], ch
;
2366 /* Don't do anything until FWREADY updates console address */
2367 if (bus
->console_addr
== 0)
2370 /* Read console log struct */
2371 addr
= bus
->console_addr
+ offsetof(struct rte_console
, log
);
2372 rv
= brcmf_sdbrcm_membytes(bus
, false, addr
, (u8
*)&c
->log
,
2377 /* Allocate console buffer (one time only) */
2378 if (c
->buf
== NULL
) {
2379 c
->bufsize
= le32_to_cpu(c
->log
.buf_size
);
2380 c
->buf
= kmalloc(c
->bufsize
, GFP_ATOMIC
);
2385 idx
= le32_to_cpu(c
->log
.idx
);
2387 /* Protect against corrupt value */
2388 if (idx
> c
->bufsize
)
2391 /* Skip reading the console buffer if the index pointer
2396 /* Read the console buffer */
2397 addr
= le32_to_cpu(c
->log
.buf
);
2398 rv
= brcmf_sdbrcm_membytes(bus
, false, addr
, c
->buf
, c
->bufsize
);
2402 while (c
->last
!= idx
) {
2403 for (n
= 0; n
< CONSOLE_LINE_MAX
- 2; n
++) {
2404 if (c
->last
== idx
) {
2405 /* This would output a partial line.
2407 * the buffer pointer and output this
2408 * line next time around.
2413 c
->last
= c
->bufsize
- n
;
2416 ch
= c
->buf
[c
->last
];
2417 c
->last
= (c
->last
+ 1) % c
->bufsize
;
2424 if (line
[n
- 1] == '\r')
2427 printk(KERN_DEBUG
"CONSOLE: %s\n", line
);
2436 int brcmf_sdbrcm_downloadvars(struct brcmf_bus
*bus
, void *arg
, int len
)
2440 DHD_TRACE(("%s: Enter\n", __func__
));
2442 /* Basic sanity checks */
2443 if (bus
->drvr
->up
) {
2444 bcmerror
= -EISCONN
;
2448 bcmerror
= -EOVERFLOW
;
2452 /* Free the old ones and replace with passed variables */
2455 bus
->vars
= kmalloc(len
, GFP_ATOMIC
);
2456 bus
->varsz
= bus
->vars
? len
: 0;
2457 if (bus
->vars
== NULL
) {
2462 /* Copy the passed variables, which should include the
2463 terminating double-null */
2464 memcpy(bus
->vars
, arg
, bus
->varsz
);
2470 brcmf_sdbrcm_doiovar(struct brcmf_bus
*bus
, const struct brcmu_iovar
*vi
, u32 actionid
,
2471 const char *name
, void *params
, int plen
, void *arg
, int len
,
2478 DHD_TRACE(("%s: Enter, action %d name %s params %p plen %d arg %p "
2479 "len %d val_size %d\n",
2480 __func__
, actionid
, name
, params
, plen
, arg
, len
, val_size
));
2482 bcmerror
= brcmu_iovar_lencheck(vi
, arg
, len
, IOV_ISSET(actionid
));
2486 if (plen
>= (int)sizeof(int_val
))
2487 memcpy(&int_val
, params
, sizeof(int_val
));
2489 bool_val
= (int_val
!= 0) ? true : false;
2491 /* Some ioctls use the bus */
2492 brcmf_sdbrcm_sdlock(bus
);
2494 /* Check if dongle is in reset. If so, only allow DEVRESET iovars */
2495 if (bus
->drvr
->dongle_reset
&& !(actionid
== IOV_SVAL(IOV_DEVRESET
) ||
2496 actionid
== IOV_GVAL(IOV_DEVRESET
))) {
2501 /* Handle sleep stuff before any clock mucking */
2502 if (vi
->varid
== IOV_SLEEP
) {
2503 if (IOV_ISSET(actionid
)) {
2504 bcmerror
= brcmf_sdbrcm_bussleep(bus
, bool_val
);
2506 int_val
= (s32
) bus
->sleeping
;
2507 memcpy(arg
, &int_val
, val_size
);
2512 /* Request clock to allow SDIO accesses */
2513 if (!bus
->drvr
->dongle_reset
) {
2515 brcmf_sdbrcm_clkctl(bus
, CLK_AVAIL
, false);
2519 case IOV_GVAL(IOV_INTR
):
2520 int_val
= (s32
) bus
->intr
;
2521 memcpy(arg
, &int_val
, val_size
);
2524 case IOV_SVAL(IOV_INTR
):
2525 bus
->intr
= bool_val
;
2526 bus
->intdis
= false;
2527 if (bus
->drvr
->up
) {
2529 DHD_INTR(("%s: enable SDIO device interrupts\n",
2531 brcmf_sdcard_intr_enable(bus
->card
);
2533 DHD_INTR(("%s: disable SDIO interrupts\n",
2535 brcmf_sdcard_intr_disable(bus
->card
);
2540 case IOV_GVAL(IOV_POLLRATE
):
2541 int_val
= (s32
) bus
->pollrate
;
2542 memcpy(arg
, &int_val
, val_size
);
2545 case IOV_SVAL(IOV_POLLRATE
):
2546 bus
->pollrate
= (uint
) int_val
;
2547 bus
->poll
= (bus
->pollrate
!= 0);
2550 case IOV_GVAL(IOV_IDLETIME
):
2551 int_val
= bus
->idletime
;
2552 memcpy(arg
, &int_val
, val_size
);
2555 case IOV_SVAL(IOV_IDLETIME
):
2556 if ((int_val
< 0) && (int_val
!= BRCMF_IDLE_IMMEDIATE
))
2559 bus
->idletime
= int_val
;
2562 case IOV_GVAL(IOV_IDLECLOCK
):
2563 int_val
= (s32
) bus
->idleclock
;
2564 memcpy(arg
, &int_val
, val_size
);
2567 case IOV_SVAL(IOV_IDLECLOCK
):
2568 bus
->idleclock
= int_val
;
2571 case IOV_GVAL(IOV_SD1IDLE
):
2572 int_val
= (s32
) sd1idle
;
2573 memcpy(arg
, &int_val
, val_size
);
2576 case IOV_SVAL(IOV_SD1IDLE
):
2580 case IOV_SVAL(IOV_MEMBYTES
):
2581 case IOV_GVAL(IOV_MEMBYTES
):
2587 bool set
= (actionid
== IOV_SVAL(IOV_MEMBYTES
));
2589 ASSERT(plen
>= 2 * sizeof(int));
2591 address
= (u32
) int_val
;
2592 memcpy(&int_val
, (char *)params
+ sizeof(int_val
),
2594 size
= (uint
) int_val
;
2596 /* Do some validation */
2597 dsize
= set
? plen
- (2 * sizeof(int)) : len
;
2599 DHD_ERROR(("%s: error on %s membytes, addr "
2600 "0x%08x size %d dsize %d\n",
2601 __func__
, (set
? "set" : "get"),
2602 address
, size
, dsize
));
2607 DHD_INFO(("%s: Request to %s %d bytes at address "
2609 __func__
, (set
? "write" : "read"), size
, address
));
2611 /* If we know about SOCRAM, check for a fit */
2612 if ((bus
->orig_ramsize
) &&
2613 ((address
> bus
->orig_ramsize
)
2614 || (address
+ size
> bus
->orig_ramsize
))) {
2615 DHD_ERROR(("%s: ramsize 0x%08x doesn't have %d "
2616 "bytes at 0x%08x\n",
2617 __func__
, bus
->orig_ramsize
, size
, address
));
2622 /* Generate the actual data pointer */
2624 set
? (u8
*) params
+
2625 2 * sizeof(int) : (u8
*) arg
;
2627 /* Call to do the transfer */
2628 bcmerror
= brcmf_sdbrcm_membytes(bus
, set
, address
,
2634 case IOV_GVAL(IOV_MEMSIZE
):
2635 int_val
= (s32
) bus
->ramsize
;
2636 memcpy(arg
, &int_val
, val_size
);
2639 case IOV_GVAL(IOV_SDIOD_DRIVE
):
2640 int_val
= (s32
) brcmf_sdiod_drive_strength
;
2641 memcpy(arg
, &int_val
, val_size
);
2644 case IOV_SVAL(IOV_SDIOD_DRIVE
):
2645 brcmf_sdiod_drive_strength
= int_val
;
2646 brcmf_sdbrcm_sdiod_drive_strength_init(bus
,
2647 brcmf_sdiod_drive_strength
);
2650 case IOV_SVAL(IOV_DOWNLOAD
):
2651 bcmerror
= brcmf_sdbrcm_download_state(bus
, bool_val
);
2654 case IOV_SVAL(IOV_VARS
):
2655 bcmerror
= brcmf_sdbrcm_downloadvars(bus
, arg
, len
);
2658 case IOV_GVAL(IOV_READAHEAD
):
2659 int_val
= (s32
) brcmf_readahead
;
2660 memcpy(arg
, &int_val
, val_size
);
2663 case IOV_SVAL(IOV_READAHEAD
):
2664 if (bool_val
&& !brcmf_readahead
)
2666 brcmf_readahead
= bool_val
;
2669 case IOV_GVAL(IOV_SDRXCHAIN
):
2670 int_val
= (s32
) bus
->use_rxchain
;
2671 memcpy(arg
, &int_val
, val_size
);
2674 case IOV_SVAL(IOV_SDRXCHAIN
):
2675 if (bool_val
&& !bus
->sd_rxchain
)
2676 bcmerror
= -ENOTSUPP
;
2678 bus
->use_rxchain
= bool_val
;
2680 case IOV_GVAL(IOV_ALIGNCTL
):
2681 int_val
= (s32
) brcmf_alignctl
;
2682 memcpy(arg
, &int_val
, val_size
);
2685 case IOV_SVAL(IOV_ALIGNCTL
):
2686 brcmf_alignctl
= bool_val
;
2689 case IOV_GVAL(IOV_SDALIGN
):
2690 int_val
= BRCMF_SDALIGN
;
2691 memcpy(arg
, &int_val
, val_size
);
2695 case IOV_GVAL(IOV_VARS
):
2696 if (bus
->varsz
< (uint
) len
)
2697 memcpy(arg
, bus
->vars
, bus
->varsz
);
2699 bcmerror
= -EOVERFLOW
;
2704 case IOV_GVAL(IOV_DCONSOLE_POLL
):
2705 int_val
= (s32
) brcmf_console_ms
;
2706 memcpy(arg
, &int_val
, val_size
);
2709 case IOV_SVAL(IOV_DCONSOLE_POLL
):
2710 brcmf_console_ms
= (uint
) int_val
;
2713 case IOV_SVAL(IOV_CONS
):
2715 bcmerror
= brcmf_sdbrcm_bus_console_in(bus
->drvr
,
2719 case IOV_GVAL(IOV_SDREG
):
2721 struct brcmf_sdreg
*sd_ptr
;
2724 sd_ptr
= (struct brcmf_sdreg
*) params
;
2726 addr
= bus
->ci
->buscorebase
+ sd_ptr
->offset
;
2727 size
= sd_ptr
->func
;
2728 int_val
= (s32
) brcmf_sdcard_reg_read(bus
->card
, addr
,
2730 if (brcmf_sdcard_regfail(bus
->card
))
2732 memcpy(arg
, &int_val
, sizeof(s32
));
2736 case IOV_SVAL(IOV_SDREG
):
2738 struct brcmf_sdreg
*sd_ptr
;
2741 sd_ptr
= (struct brcmf_sdreg
*) params
;
2743 addr
= bus
->ci
->buscorebase
+ sd_ptr
->offset
;
2744 size
= sd_ptr
->func
;
2745 brcmf_sdcard_reg_write(bus
->card
, addr
, size
,
2747 if (brcmf_sdcard_regfail(bus
->card
))
2752 /* Same as above, but offset is not backplane
2754 case IOV_GVAL(IOV_SBREG
):
2756 struct brcmf_sdreg sdreg
;
2759 memcpy(&sdreg
, params
, sizeof(sdreg
));
2761 addr
= SI_ENUM_BASE
+ sdreg
.offset
;
2763 int_val
= (s32
) brcmf_sdcard_reg_read(bus
->card
, addr
,
2765 if (brcmf_sdcard_regfail(bus
->card
))
2767 memcpy(arg
, &int_val
, sizeof(s32
));
2771 case IOV_SVAL(IOV_SBREG
):
2773 struct brcmf_sdreg sdreg
;
2776 memcpy(&sdreg
, params
, sizeof(sdreg
));
2778 addr
= SI_ENUM_BASE
+ sdreg
.offset
;
2780 brcmf_sdcard_reg_write(bus
->card
, addr
, size
,
2782 if (brcmf_sdcard_regfail(bus
->card
))
2787 case IOV_GVAL(IOV_SDCIS
):
2791 strcat(arg
, "\nFunc 0\n");
2792 brcmf_sdcard_cis_read(bus
->card
, 0x10,
2793 (u8
*) arg
+ strlen(arg
),
2794 SBSDIO_CIS_SIZE_LIMIT
);
2795 strcat(arg
, "\nFunc 1\n");
2796 brcmf_sdcard_cis_read(bus
->card
, 0x11,
2797 (u8
*) arg
+ strlen(arg
),
2798 SBSDIO_CIS_SIZE_LIMIT
);
2799 strcat(arg
, "\nFunc 2\n");
2800 brcmf_sdcard_cis_read(bus
->card
, 0x12,
2801 (u8
*) arg
+ strlen(arg
),
2802 SBSDIO_CIS_SIZE_LIMIT
);
2806 case IOV_GVAL(IOV_FORCEEVEN
):
2807 int_val
= (s32
) forcealign
;
2808 memcpy(arg
, &int_val
, val_size
);
2811 case IOV_SVAL(IOV_FORCEEVEN
):
2812 forcealign
= bool_val
;
2815 case IOV_GVAL(IOV_TXBOUND
):
2816 int_val
= (s32
) brcmf_txbound
;
2817 memcpy(arg
, &int_val
, val_size
);
2820 case IOV_SVAL(IOV_TXBOUND
):
2821 brcmf_txbound
= (uint
) int_val
;
2824 case IOV_GVAL(IOV_RXBOUND
):
2825 int_val
= (s32
) brcmf_rxbound
;
2826 memcpy(arg
, &int_val
, val_size
);
2829 case IOV_SVAL(IOV_RXBOUND
):
2830 brcmf_rxbound
= (uint
) int_val
;
2833 case IOV_GVAL(IOV_TXMINMAX
):
2834 int_val
= (s32
) dhd_txminmax
;
2835 memcpy(arg
, &int_val
, val_size
);
2838 case IOV_SVAL(IOV_TXMINMAX
):
2839 dhd_txminmax
= (uint
) int_val
;
2844 case IOV_GVAL(IOV_EXTLOOP
):
2845 int_val
= (s32
) bus
->ext_loop
;
2846 memcpy(arg
, &int_val
, val_size
);
2849 case IOV_SVAL(IOV_EXTLOOP
):
2850 bus
->ext_loop
= bool_val
;
2853 case IOV_GVAL(IOV_PKTGEN
):
2854 bcmerror
= brcmf_sdbrcm_pktgen_get(bus
, arg
);
2857 case IOV_SVAL(IOV_PKTGEN
):
2858 bcmerror
= brcmf_sdbrcm_pktgen_set(bus
, arg
);
2862 case IOV_SVAL(IOV_DEVRESET
):
2863 DHD_TRACE(("%s: Called set IOV_DEVRESET=%d dongle_reset=%d "
2865 __func__
, bool_val
, bus
->drvr
->dongle_reset
,
2866 bus
->drvr
->busstate
));
2868 brcmf_bus_devreset(bus
->drvr
, (u8
) bool_val
);
2872 case IOV_GVAL(IOV_DEVRESET
):
2873 DHD_TRACE(("%s: Called get IOV_DEVRESET\n", __func__
));
2875 /* Get its status */
2876 int_val
= (bool) bus
->drvr
->dongle_reset
;
2877 memcpy(arg
, &int_val
, val_size
);
2881 case IOV_GVAL(IOV_WDTICK
):
2882 int_val
= (s32
) brcmf_watchdog_ms
;
2883 memcpy(arg
, &int_val
, val_size
);
2886 case IOV_SVAL(IOV_WDTICK
):
2887 if (!bus
->drvr
->up
) {
2888 bcmerror
= -ENOLINK
;
2891 brcmf_sdbrcm_wd_timer(bus
, (uint
) int_val
);
2895 bcmerror
= -ENOTSUPP
;
2900 if ((bus
->idletime
== BRCMF_IDLE_IMMEDIATE
) && !bus
->dpc_sched
) {
2901 bus
->activity
= false;
2902 brcmf_sdbrcm_clkctl(bus
, CLK_NONE
, true);
2905 brcmf_sdbrcm_sdunlock(bus
);
2907 if (actionid
== IOV_SVAL(IOV_DEVRESET
) && bool_val
== false)
2908 brcmf_c_preinit_ioctls(bus
->drvr
);
2913 static int brcmf_sdbrcm_write_vars(struct brcmf_bus
*bus
)
2921 char *nvram_ularray
;
2924 /* Even if there are no vars are to be written, we still
2925 need to set the ramsize. */
2926 varsize
= bus
->varsz
? roundup(bus
->varsz
, 4) : 0;
2927 varaddr
= (bus
->ramsize
- 4) - varsize
;
2930 vbuffer
= kzalloc(varsize
, GFP_ATOMIC
);
2934 memcpy(vbuffer
, bus
->vars
, bus
->varsz
);
2936 /* Write the vars list */
2938 brcmf_sdbrcm_membytes(bus
, true, varaddr
, vbuffer
, varsize
);
2940 /* Verify NVRAM bytes */
2941 DHD_INFO(("Compare NVRAM dl & ul; varsize=%d\n", varsize
));
2942 nvram_ularray
= kmalloc(varsize
, GFP_ATOMIC
);
2946 /* Upload image to verify downloaded contents. */
2947 memset(nvram_ularray
, 0xaa, varsize
);
2949 /* Read the vars list to temp buffer for comparison */
2951 brcmf_sdbrcm_membytes(bus
, false, varaddr
, nvram_ularray
,
2954 DHD_ERROR(("%s: error %d on reading %d nvram bytes at "
2955 "0x%08x\n", __func__
, bcmerror
, varsize
, varaddr
));
2957 /* Compare the org NVRAM with the one read from RAM */
2958 if (memcmp(vbuffer
, nvram_ularray
, varsize
)) {
2959 DHD_ERROR(("%s: Downloaded NVRAM image is corrupted.\n",
2962 DHD_ERROR(("%s: Download/Upload/Compare of NVRAM ok.\n",
2965 kfree(nvram_ularray
);
2971 /* adjust to the user specified RAM */
2972 DHD_INFO(("Physical memory size: %d, usable memory size: %d\n",
2973 bus
->orig_ramsize
, bus
->ramsize
));
2974 DHD_INFO(("Vars are at %d, orig varsize is %d\n", varaddr
, varsize
));
2975 varsize
= ((bus
->orig_ramsize
- 4) - varaddr
);
2978 * Determine the length token:
2979 * Varsize, converted to words, in lower 16-bits, checksum
2985 varsizew
= varsize
/ 4;
2986 varsizew
= (~varsizew
<< 16) | (varsizew
& 0x0000FFFF);
2987 varsizew
= cpu_to_le32(varsizew
);
2990 DHD_INFO(("New varsize is %d, length token=0x%08x\n", varsize
,
2993 /* Write the length token to the last word */
2994 bcmerror
= brcmf_sdbrcm_membytes(bus
, true, (bus
->orig_ramsize
- 4),
2995 (u8
*)&varsizew
, 4);
3000 static int brcmf_sdbrcm_download_state(struct brcmf_bus
*bus
, bool enter
)
3006 /* To enter download state, disable ARM and reset SOCRAM.
3007 * To exit download state, simply reset ARM (default is RAM boot).
3010 bus
->alp_only
= true;
3012 brcmf_sdbrcm_chip_disablecore(bus
->card
, bus
->ci
->armcorebase
);
3014 brcmf_sdbrcm_chip_resetcore(bus
->card
, bus
->ci
->ramcorebase
);
3016 /* Clear the top bit of memory */
3019 brcmf_sdbrcm_membytes(bus
, true, bus
->ramsize
- 4,
3023 regdata
= brcmf_sdcard_reg_read(bus
->card
,
3024 CORE_SB(bus
->ci
->ramcorebase
, sbtmstatelow
), 4);
3025 regdata
&= (SBTML_RESET
| SBTML_REJ_MASK
|
3026 (SICF_CLOCK_EN
<< SBTML_SICF_SHIFT
));
3027 if ((SICF_CLOCK_EN
<< SBTML_SICF_SHIFT
) != regdata
) {
3028 DHD_ERROR(("%s: SOCRAM core is down after reset?\n",
3034 bcmerror
= brcmf_sdbrcm_write_vars(bus
);
3036 DHD_ERROR(("%s: no vars written to RAM\n", __func__
));
3040 w_sdreg32(bus
, 0xFFFFFFFF,
3041 offsetof(struct sdpcmd_regs
, intstatus
), &retries
);
3043 brcmf_sdbrcm_chip_resetcore(bus
->card
, bus
->ci
->armcorebase
);
3045 /* Allow HT Clock now that the ARM is running. */
3046 bus
->alp_only
= false;
3048 bus
->drvr
->busstate
= DHD_BUS_LOAD
;
3055 brcmf_sdbrcm_bus_iovar_op(struct brcmf_pub
*drvr
, const char *name
,
3056 void *params
, int plen
, void *arg
, int len
, bool set
)
3058 struct brcmf_bus
*bus
= drvr
->bus
;
3059 const struct brcmu_iovar
*vi
= NULL
;
3064 DHD_TRACE(("%s: Enter\n", __func__
));
3069 /* Get MUST have return space */
3070 ASSERT(set
|| (arg
&& len
));
3072 /* Set does NOT take qualifiers */
3073 ASSERT(!set
|| (!params
&& !plen
));
3075 /* Look up var locally; if not found pass to host driver */
3076 vi
= brcmu_iovar_lookup(dhdsdio_iovars
, name
);
3078 brcmf_sdbrcm_sdlock(bus
);
3082 /* Turn on clock in case SD command needs backplane */
3083 brcmf_sdbrcm_clkctl(bus
, CLK_AVAIL
, false);
3085 bcmerror
= brcmf_sdcard_iovar_op(bus
->card
, name
, params
, plen
,
3088 /* Similar check for blocksize change */
3089 if (set
&& strcmp(name
, "sd_blocksize") == 0) {
3091 if (brcmf_sdcard_iovar_op
3092 (bus
->card
, "sd_blocksize", &fnum
, sizeof(s32
),
3093 &bus
->blocksize
, sizeof(s32
),
3096 DHD_ERROR(("%s: fail on %s get\n", __func__
,
3099 DHD_INFO(("%s: noted %s update, value now %d\n",
3100 __func__
, "sd_blocksize",
3104 bus
->roundup
= min(max_roundup
, bus
->blocksize
);
3106 if (bus
->idletime
== BRCMF_IDLE_IMMEDIATE
&&
3108 bus
->activity
= false;
3109 brcmf_sdbrcm_clkctl(bus
, CLK_NONE
, true);
3112 brcmf_sdbrcm_sdunlock(bus
);
3116 DHD_CTL(("%s: %s %s, len %d plen %d\n", __func__
,
3117 name
, (set
? "set" : "get"), len
, plen
));
3119 /* set up 'params' pointer in case this is a set command so that
3120 * the convenience int and bool code can be common to set and get
3122 if (params
== NULL
) {
3127 if (vi
->type
== IOVT_VOID
)
3129 else if (vi
->type
== IOVT_BUFFER
)
3132 /* all other types are integer sized */
3133 val_size
= sizeof(int);
3135 actionid
= set
? IOV_SVAL(vi
->varid
) : IOV_GVAL(vi
->varid
);
3136 bcmerror
= brcmf_sdbrcm_doiovar(bus
, vi
, actionid
, name
, params
, plen
,
3137 arg
, len
, val_size
);
3143 void brcmf_sdbrcm_bus_stop(struct brcmf_bus
*bus
, bool enforce_mutex
)
3145 u32 local_hostintmask
;
3150 DHD_TRACE(("%s: Enter\n", __func__
));
3153 brcmf_sdbrcm_sdlock(bus
);
3157 /* Enable clock for device interrupts */
3158 brcmf_sdbrcm_clkctl(bus
, CLK_AVAIL
, false);
3160 if (bus
->watchdog_tsk
) {
3161 send_sig(SIGTERM
, bus
->watchdog_tsk
, 1);
3162 kthread_stop(bus
->watchdog_tsk
);
3163 bus
->watchdog_tsk
= NULL
;
3167 send_sig(SIGTERM
, bus
->dpc_tsk
, 1);
3168 kthread_stop(bus
->dpc_tsk
);
3169 bus
->dpc_tsk
= NULL
;
3171 tasklet_kill(&bus
->tasklet
);
3173 /* Disable and clear interrupts at the chip level also */
3174 w_sdreg32(bus
, 0, offsetof(struct sdpcmd_regs
, hostintmask
), &retries
);
3175 local_hostintmask
= bus
->hostintmask
;
3176 bus
->hostintmask
= 0;
3178 /* Change our idea of bus state */
3179 bus
->drvr
->busstate
= DHD_BUS_DOWN
;
3181 /* Force clocks on backplane to be sure F2 interrupt propagates */
3182 saveclk
= brcmf_sdcard_cfg_read(bus
->card
, SDIO_FUNC_1
,
3183 SBSDIO_FUNC1_CHIPCLKCSR
, &err
);
3185 brcmf_sdcard_cfg_write(bus
->card
, SDIO_FUNC_1
,
3186 SBSDIO_FUNC1_CHIPCLKCSR
,
3187 (saveclk
| SBSDIO_FORCE_HT
), &err
);
3190 DHD_ERROR(("%s: Failed to force clock for F2: err %d\n",
3194 /* Turn off the bus (F2), free any pending packets */
3195 DHD_INTR(("%s: disable SDIO interrupts\n", __func__
));
3196 brcmf_sdcard_intr_disable(bus
->card
);
3197 brcmf_sdcard_cfg_write(bus
->card
, SDIO_FUNC_0
, SDIO_CCCR_IOEx
,
3198 SDIO_FUNC_ENABLE_1
, NULL
);
3200 /* Clear any pending interrupts now that F2 is disabled */
3201 w_sdreg32(bus
, local_hostintmask
,
3202 offsetof(struct sdpcmd_regs
, intstatus
), &retries
);
3204 /* Turn off the backplane clock (only) */
3205 brcmf_sdbrcm_clkctl(bus
, CLK_SDONLY
, false);
3207 /* Clear the data packet queues */
3208 brcmu_pktq_flush(&bus
->txq
, true, NULL
, NULL
);
3210 /* Clear any held glomming stuff */
3212 brcmu_pkt_buf_free_skb(bus
->glomd
);
3215 brcmu_pkt_buf_free_skb(bus
->glom
);
3217 bus
->glom
= bus
->glomd
= NULL
;
3219 /* Clear rx control and wake any waiters */
3221 brcmf_os_ioctl_resp_wake(bus
->drvr
);
3223 /* Reset some F2 state stuff */
3224 bus
->rxskip
= false;
3225 bus
->tx_seq
= bus
->rx_seq
= 0;
3228 brcmf_sdbrcm_sdunlock(bus
);
3231 int brcmf_sdbrcm_bus_init(struct brcmf_pub
*drvr
, bool enforce_mutex
)
3233 struct brcmf_bus
*bus
= drvr
->bus
;
3234 struct brcmf_timeout tmo
;
3240 DHD_TRACE(("%s: Enter\n", __func__
));
3242 /* try to download image and nvram to the dongle */
3243 if (drvr
->busstate
== DHD_BUS_DOWN
) {
3244 if (!(brcmf_sdbrcm_download_firmware(bus
, bus
->card
)))
3252 /* Start the watchdog timer */
3253 bus
->drvr
->tickcnt
= 0;
3254 brcmf_sdbrcm_wd_timer(bus
, brcmf_watchdog_ms
);
3257 brcmf_sdbrcm_sdlock(bus
);
3259 /* Make sure backplane clock is on, needed to generate F2 interrupt */
3260 brcmf_sdbrcm_clkctl(bus
, CLK_AVAIL
, false);
3261 if (bus
->clkstate
!= CLK_AVAIL
)
3264 /* Force clocks on backplane to be sure F2 interrupt propagates */
3266 brcmf_sdcard_cfg_read(bus
->card
, SDIO_FUNC_1
,
3267 SBSDIO_FUNC1_CHIPCLKCSR
, &err
);
3269 brcmf_sdcard_cfg_write(bus
->card
, SDIO_FUNC_1
,
3270 SBSDIO_FUNC1_CHIPCLKCSR
,
3271 (saveclk
| SBSDIO_FORCE_HT
), &err
);
3274 DHD_ERROR(("%s: Failed to force clock for F2: err %d\n",
3279 /* Enable function 2 (frame transfers) */
3280 w_sdreg32(bus
, SDPCM_PROT_VERSION
<< SMB_DATA_VERSION_SHIFT
,
3281 offsetof(struct sdpcmd_regs
, tosbmailboxdata
), &retries
);
3282 enable
= (SDIO_FUNC_ENABLE_1
| SDIO_FUNC_ENABLE_2
);
3284 brcmf_sdcard_cfg_write(bus
->card
, SDIO_FUNC_0
, SDIO_CCCR_IOEx
, enable
,
3287 /* Give the dongle some time to do its thing and set IOR2 */
3288 brcmf_timeout_start(&tmo
, DHD_WAIT_F2RDY
* 1000);
3291 while (ready
!= enable
&& !brcmf_timeout_expired(&tmo
))
3292 ready
= brcmf_sdcard_cfg_read(bus
->card
, SDIO_FUNC_0
,
3293 SDIO_CCCR_IORx
, NULL
);
3295 DHD_INFO(("%s: enable 0x%02x, ready 0x%02x (waited %uus)\n",
3296 __func__
, enable
, ready
, tmo
.elapsed
));
3298 /* If F2 successfully enabled, set core and enable interrupts */
3299 if (ready
== enable
) {
3300 /* Set up the interrupt mask and enable interrupts */
3301 bus
->hostintmask
= HOSTINTMASK
;
3302 w_sdreg32(bus
, bus
->hostintmask
,
3303 offsetof(struct sdpcmd_regs
, hostintmask
), &retries
);
3305 brcmf_sdcard_cfg_write(bus
->card
, SDIO_FUNC_1
, SBSDIO_WATERMARK
,
3306 (u8
) watermark
, &err
);
3308 /* Set bus state according to enable result */
3309 drvr
->busstate
= DHD_BUS_DATA
;
3311 bus
->intdis
= false;
3313 DHD_INTR(("%s: enable SDIO device interrupts\n",
3315 brcmf_sdcard_intr_enable(bus
->card
);
3317 DHD_INTR(("%s: disable SDIO interrupts\n", __func__
));
3318 brcmf_sdcard_intr_disable(bus
->card
);
3324 /* Disable F2 again */
3325 enable
= SDIO_FUNC_ENABLE_1
;
3326 brcmf_sdcard_cfg_write(bus
->card
, SDIO_FUNC_0
, SDIO_CCCR_IOEx
,
3330 /* Restore previous clock setting */
3331 brcmf_sdcard_cfg_write(bus
->card
, SDIO_FUNC_1
, SBSDIO_FUNC1_CHIPCLKCSR
,
3334 #if defined(OOB_INTR_ONLY)
3335 /* Host registration for OOB interrupt */
3336 if (brcmf_sdio_register_oob_intr(bus
->dhd
)) {
3337 brcmf_sdbrcm_wd_timer(bus
, 0);
3338 DHD_ERROR(("%s Host failed to resgister for OOB\n", __func__
));
3343 /* Enable oob at firmware */
3344 brcmf_sdbrcm_enable_oob_intr(bus
, true);
3345 #endif /* defined(OOB_INTR_ONLY) */
3347 /* If we didn't come up, turn off backplane clock */
3348 if (drvr
->busstate
!= DHD_BUS_DATA
)
3349 brcmf_sdbrcm_clkctl(bus
, CLK_NONE
, false);
3353 brcmf_sdbrcm_sdunlock(bus
);
3358 static void brcmf_sdbrcm_rxfail(struct brcmf_bus
*bus
, bool abort
, bool rtx
)
3360 struct brcmf_sdio_card
*card
= bus
->card
;
3366 DHD_ERROR(("%s: %sterminate frame%s\n", __func__
,
3367 (abort
? "abort command, " : ""),
3368 (rtx
? ", send NAK" : "")));
3371 brcmf_sdcard_abort(card
, SDIO_FUNC_2
);
3373 brcmf_sdcard_cfg_write(card
, SDIO_FUNC_1
, SBSDIO_FUNC1_FRAMECTRL
,
3377 /* Wait until the packet has been flushed (device/FIFO stable) */
3378 for (lastrbc
= retries
= 0xffff; retries
> 0; retries
--) {
3379 hi
= brcmf_sdcard_cfg_read(card
, SDIO_FUNC_1
,
3380 SBSDIO_FUNC1_RFRAMEBCHI
, NULL
);
3381 lo
= brcmf_sdcard_cfg_read(card
, SDIO_FUNC_1
,
3382 SBSDIO_FUNC1_RFRAMEBCLO
, NULL
);
3383 bus
->f1regdata
+= 2;
3385 if ((hi
== 0) && (lo
== 0))
3388 if ((hi
> (lastrbc
>> 8)) && (lo
> (lastrbc
& 0x00ff))) {
3389 DHD_ERROR(("%s: count growing: last 0x%04x now "
3391 __func__
, lastrbc
, ((hi
<< 8) + lo
)));
3393 lastrbc
= (hi
<< 8) + lo
;
3397 DHD_ERROR(("%s: count never zeroed: last 0x%04x\n",
3398 __func__
, lastrbc
));
3400 DHD_INFO(("%s: flush took %d iterations\n", __func__
,
3401 (0xffff - retries
)));
3406 w_sdreg32(bus
, SMB_NAK
,
3407 offsetof(struct sdpcmd_regs
, tosbmailbox
), &retries
);
3410 if (retries
<= retry_limit
)
3414 /* Clear partial in any case */
3417 /* If we can't reach the device, signal failure */
3418 if (err
|| brcmf_sdcard_regfail(card
))
3419 bus
->drvr
->busstate
= DHD_BUS_DOWN
;
3423 brcmf_sdbrcm_read_control(struct brcmf_bus
*bus
, u8
*hdr
, uint len
, uint doff
)
3425 struct brcmf_sdio_card
*card
= bus
->card
;
3430 DHD_TRACE(("%s: Enter\n", __func__
));
3432 /* Control data already received in aligned rxctl */
3433 if ((bus
->bus
== SPI_BUS
) && (!bus
->usebufpool
))
3437 /* Set rxctl for frame (w/optional alignment) */
3438 bus
->rxctl
= bus
->rxbuf
;
3439 if (brcmf_alignctl
) {
3440 bus
->rxctl
+= firstread
;
3441 pad
= ((unsigned long)bus
->rxctl
% BRCMF_SDALIGN
);
3443 bus
->rxctl
+= (BRCMF_SDALIGN
- pad
);
3444 bus
->rxctl
-= firstread
;
3446 ASSERT(bus
->rxctl
>= bus
->rxbuf
);
3448 /* Copy the already-read portion over */
3449 memcpy(bus
->rxctl
, hdr
, firstread
);
3450 if (len
<= firstread
)
3453 /* Copy the full data pkt in gSPI case and process ioctl. */
3454 if (bus
->bus
== SPI_BUS
) {
3455 memcpy(bus
->rxctl
, hdr
, len
);
3459 /* Raise rdlen to next SDIO block to avoid tail command */
3460 rdlen
= len
- firstread
;
3461 if (bus
->roundup
&& bus
->blocksize
&& (rdlen
> bus
->blocksize
)) {
3462 pad
= bus
->blocksize
- (rdlen
% bus
->blocksize
);
3463 if ((pad
<= bus
->roundup
) && (pad
< bus
->blocksize
) &&
3464 ((len
+ pad
) < bus
->drvr
->maxctl
))
3466 } else if (rdlen
% BRCMF_SDALIGN
) {
3467 rdlen
+= BRCMF_SDALIGN
- (rdlen
% BRCMF_SDALIGN
);
3470 /* Satisfy length-alignment requirements */
3471 if (forcealign
&& (rdlen
& (ALIGNMENT
- 1)))
3472 rdlen
= roundup(rdlen
, ALIGNMENT
);
3474 /* Drop if the read is too big or it exceeds our maximum */
3475 if ((rdlen
+ firstread
) > bus
->drvr
->maxctl
) {
3476 DHD_ERROR(("%s: %d-byte control read exceeds %d-byte buffer\n",
3477 __func__
, rdlen
, bus
->drvr
->maxctl
));
3478 bus
->drvr
->rx_errors
++;
3479 brcmf_sdbrcm_rxfail(bus
, false, false);
3483 if ((len
- doff
) > bus
->drvr
->maxctl
) {
3484 DHD_ERROR(("%s: %d-byte ctl frame (%d-byte ctl data) exceeds "
3486 __func__
, len
, (len
- doff
), bus
->drvr
->maxctl
));
3487 bus
->drvr
->rx_errors
++;
3489 brcmf_sdbrcm_rxfail(bus
, false, false);
3493 /* Read remainder of frame body into the rxctl buffer */
3494 sdret
= brcmf_sdcard_recv_buf(card
, brcmf_sdcard_cur_sbwad(card
),
3496 F2SYNC
, (bus
->rxctl
+ firstread
), rdlen
,
3499 ASSERT(sdret
!= -BCME_PENDING
);
3501 /* Control frame failures need retransmission */
3503 DHD_ERROR(("%s: read %d control bytes failed: %d\n",
3504 __func__
, rdlen
, sdret
));
3505 bus
->rxc_errors
++; /* dhd.rx_ctlerrs is higher level */
3506 brcmf_sdbrcm_rxfail(bus
, true, true);
3513 if (DHD_BYTES_ON() && DHD_CTL_ON()) {
3514 printk(KERN_DEBUG
"RxCtrl:\n");
3515 print_hex_dump_bytes("", DUMP_PREFIX_OFFSET
, bus
->rxctl
, len
);
3519 /* Point to valid data and indicate its length */
3521 bus
->rxlen
= len
- doff
;
3524 /* Awake any waiters */
3525 brcmf_os_ioctl_resp_wake(bus
->drvr
);
3528 static u8
brcmf_sdbrcm_rxglom(struct brcmf_bus
*bus
, u8 rxseq
)
3534 struct sk_buff
*pfirst
, *plast
, *pnext
, *save_pfirst
;
3537 u8 chan
, seq
, doff
, sfdoff
;
3541 bool usechain
= bus
->use_rxchain
;
3543 /* If packets, issue read(s) and send up packet chain */
3544 /* Return sequence numbers consumed? */
3546 DHD_TRACE(("brcmf_sdbrcm_rxglom: start: glomd %p glom %p\n", bus
->glomd
,
3549 /* If there's a descriptor, generate the packet chain */
3551 pfirst
= plast
= pnext
= NULL
;
3552 dlen
= (u16
) (bus
->glomd
->len
);
3553 dptr
= bus
->glomd
->data
;
3554 if (!dlen
|| (dlen
& 1)) {
3555 DHD_ERROR(("%s: bad glomd len(%d), ignore descriptor\n",
3560 for (totlen
= num
= 0; dlen
; num
++) {
3561 /* Get (and move past) next length */
3562 sublen
= get_unaligned_le16(dptr
);
3563 dlen
-= sizeof(u16
);
3564 dptr
+= sizeof(u16
);
3565 if ((sublen
< SDPCM_HDRLEN
) ||
3566 ((num
== 0) && (sublen
< (2 * SDPCM_HDRLEN
)))) {
3567 DHD_ERROR(("%s: descriptor len %d bad: %d\n",
3568 __func__
, num
, sublen
));
3572 if (sublen
% BRCMF_SDALIGN
) {
3573 DHD_ERROR(("%s: sublen %d not multiple of %d\n",
3574 __func__
, sublen
, BRCMF_SDALIGN
));
3579 /* For last frame, adjust read len so total
3580 is a block multiple */
3583 (roundup(totlen
, bus
->blocksize
) - totlen
);
3584 totlen
= roundup(totlen
, bus
->blocksize
);
3587 /* Allocate/chain packet for next subframe */
3588 pnext
= brcmu_pkt_buf_get_skb(sublen
+ BRCMF_SDALIGN
);
3589 if (pnext
== NULL
) {
3590 DHD_ERROR(("%s: bcm_pkt_buf_get_skb failed, "
3591 "num %d len %d\n", __func__
,
3595 ASSERT(!(pnext
->prev
));
3598 pfirst
= plast
= pnext
;
3601 plast
->next
= pnext
;
3605 /* Adhere to start alignment requirements */
3606 PKTALIGN(pnext
, sublen
, BRCMF_SDALIGN
);
3609 /* If all allocations succeeded, save packet chain
3612 DHD_GLOM(("%s: allocated %d-byte packet chain for %d "
3613 "subframes\n", __func__
, totlen
, num
));
3614 if (DHD_GLOM_ON() && bus
->nextlen
) {
3615 if (totlen
!= bus
->nextlen
) {
3616 DHD_GLOM(("%s: glomdesc mismatch: nextlen %d glomdesc %d " "rxseq %d\n",
3617 __func__
, bus
->nextlen
,
3622 pfirst
= pnext
= NULL
;
3625 brcmu_pkt_buf_free_skb(pfirst
);
3630 /* Done with descriptor packet */
3631 brcmu_pkt_buf_free_skb(bus
->glomd
);
3636 /* Ok -- either we just generated a packet chain,
3637 or had one from before */
3639 if (DHD_GLOM_ON()) {
3640 DHD_GLOM(("%s: try superframe read, packet chain:\n",
3642 for (pnext
= bus
->glom
; pnext
; pnext
= pnext
->next
) {
3643 DHD_GLOM((" %p: %p len 0x%04x (%d)\n",
3644 pnext
, (u8
*) (pnext
->data
),
3645 pnext
->len
, pnext
->len
));
3650 dlen
= (u16
) brcmu_pkttotlen(pfirst
);
3652 /* Do an SDIO read for the superframe. Configurable iovar to
3653 * read directly into the chained packet, or allocate a large
3654 * packet and and copy into the chain.
3657 errcode
= brcmf_sdcard_recv_buf(bus
->card
,
3658 brcmf_sdcard_cur_sbwad(bus
->card
),
3660 F2SYNC
, (u8
*) pfirst
->data
, dlen
,
3661 pfirst
, NULL
, NULL
);
3662 } else if (bus
->dataptr
) {
3663 errcode
= brcmf_sdcard_recv_buf(bus
->card
,
3664 brcmf_sdcard_cur_sbwad(bus
->card
),
3666 F2SYNC
, bus
->dataptr
, dlen
,
3668 sublen
= (u16
) brcmu_pktfrombuf(pfirst
, 0, dlen
,
3670 if (sublen
!= dlen
) {
3671 DHD_ERROR(("%s: FAILED TO COPY, dlen %d sublen %d\n",
3672 __func__
, dlen
, sublen
));
3677 DHD_ERROR(("COULDN'T ALLOC %d-BYTE GLOM, FORCE FAILURE\n",
3682 ASSERT(errcode
!= -BCME_PENDING
);
3684 /* On failure, kill the superframe, allow a couple retries */
3686 DHD_ERROR(("%s: glom read of %d bytes failed: %d\n",
3687 __func__
, dlen
, errcode
));
3688 bus
->drvr
->rx_errors
++;
3690 if (bus
->glomerr
++ < 3) {
3691 brcmf_sdbrcm_rxfail(bus
, true, true);
3694 brcmf_sdbrcm_rxfail(bus
, true, false);
3695 brcmu_pkt_buf_free_skb(bus
->glom
);
3702 if (DHD_GLOM_ON()) {
3703 printk(KERN_DEBUG
"SUPERFRAME:\n");
3704 print_hex_dump_bytes("", DUMP_PREFIX_OFFSET
,
3705 pfirst
->data
, min_t(int, pfirst
->len
, 48));
3709 /* Validate the superframe header */
3710 dptr
= (u8
*) (pfirst
->data
);
3711 sublen
= get_unaligned_le16(dptr
);
3712 check
= get_unaligned_le16(dptr
+ sizeof(u16
));
3714 chan
= SDPCM_PACKET_CHANNEL(&dptr
[SDPCM_FRAMETAG_LEN
]);
3715 seq
= SDPCM_PACKET_SEQUENCE(&dptr
[SDPCM_FRAMETAG_LEN
]);
3716 bus
->nextlen
= dptr
[SDPCM_FRAMETAG_LEN
+ SDPCM_NEXTLEN_OFFSET
];
3717 if ((bus
->nextlen
<< 4) > MAX_RX_DATASZ
) {
3718 DHD_INFO(("%s: nextlen too large (%d) seq %d\n",
3719 __func__
, bus
->nextlen
, seq
));
3722 doff
= SDPCM_DOFFSET_VALUE(&dptr
[SDPCM_FRAMETAG_LEN
]);
3723 txmax
= SDPCM_WINDOW_VALUE(&dptr
[SDPCM_FRAMETAG_LEN
]);
3726 if ((u16
)~(sublen
^ check
)) {
3727 DHD_ERROR(("%s (superframe): HW hdr error: len/check "
3728 "0x%04x/0x%04x\n", __func__
, sublen
, check
));
3730 } else if (roundup(sublen
, bus
->blocksize
) != dlen
) {
3731 DHD_ERROR(("%s (superframe): len 0x%04x, rounded "
3732 "0x%04x, expect 0x%04x\n",
3734 roundup(sublen
, bus
->blocksize
), dlen
));
3736 } else if (SDPCM_PACKET_CHANNEL(&dptr
[SDPCM_FRAMETAG_LEN
]) !=
3737 SDPCM_GLOM_CHANNEL
) {
3738 DHD_ERROR(("%s (superframe): bad channel %d\n",
3740 SDPCM_PACKET_CHANNEL(&dptr
3741 [SDPCM_FRAMETAG_LEN
])));
3743 } else if (SDPCM_GLOMDESC(&dptr
[SDPCM_FRAMETAG_LEN
])) {
3744 DHD_ERROR(("%s (superframe): got second descriptor?\n",
3747 } else if ((doff
< SDPCM_HDRLEN
) ||
3748 (doff
> (pfirst
->len
- SDPCM_HDRLEN
))) {
3749 DHD_ERROR(("%s (superframe): Bad data offset %d: HW %d "
3751 __func__
, doff
, sublen
,
3752 pfirst
->len
, SDPCM_HDRLEN
));
3756 /* Check sequence number of superframe SW header */
3758 DHD_INFO(("%s: (superframe) rx_seq %d, expected %d\n",
3759 __func__
, seq
, rxseq
));
3764 /* Check window for sanity */
3765 if ((u8
) (txmax
- bus
->tx_seq
) > 0x40) {
3766 DHD_ERROR(("%s: unlikely tx max %d with tx_seq %d\n",
3767 __func__
, txmax
, bus
->tx_seq
));
3768 txmax
= bus
->tx_seq
+ 2;
3770 bus
->tx_max
= txmax
;
3772 /* Remove superframe header, remember offset */
3773 skb_pull(pfirst
, doff
);
3776 /* Validate all the subframe headers */
3777 for (num
= 0, pnext
= pfirst
; pnext
&& !errcode
;
3778 num
++, pnext
= pnext
->next
) {
3779 dptr
= (u8
*) (pnext
->data
);
3780 dlen
= (u16
) (pnext
->len
);
3781 sublen
= get_unaligned_le16(dptr
);
3782 check
= get_unaligned_le16(dptr
+ sizeof(u16
));
3783 chan
= SDPCM_PACKET_CHANNEL(&dptr
[SDPCM_FRAMETAG_LEN
]);
3784 doff
= SDPCM_DOFFSET_VALUE(&dptr
[SDPCM_FRAMETAG_LEN
]);
3786 if (DHD_GLOM_ON()) {
3787 printk(KERN_DEBUG
"subframe:\n");
3788 print_hex_dump_bytes("", DUMP_PREFIX_OFFSET
,
3793 if ((u16
)~(sublen
^ check
)) {
3794 DHD_ERROR(("%s (subframe %d): HW hdr error: "
3795 "len/check 0x%04x/0x%04x\n",
3796 __func__
, num
, sublen
, check
));
3798 } else if ((sublen
> dlen
) || (sublen
< SDPCM_HDRLEN
)) {
3799 DHD_ERROR(("%s (subframe %d): length mismatch: "
3800 "len 0x%04x, expect 0x%04x\n",
3801 __func__
, num
, sublen
, dlen
));
3803 } else if ((chan
!= SDPCM_DATA_CHANNEL
) &&
3804 (chan
!= SDPCM_EVENT_CHANNEL
)) {
3805 DHD_ERROR(("%s (subframe %d): bad channel %d\n",
3806 __func__
, num
, chan
));
3808 } else if ((doff
< SDPCM_HDRLEN
) || (doff
> sublen
)) {
3809 DHD_ERROR(("%s (subframe %d): Bad data offset %d: HW %d min %d\n",
3810 __func__
, num
, doff
, sublen
,
3817 /* Terminate frame on error, request
3819 if (bus
->glomerr
++ < 3) {
3820 /* Restore superframe header space */
3821 skb_push(pfirst
, sfdoff
);
3822 brcmf_sdbrcm_rxfail(bus
, true, true);
3825 brcmf_sdbrcm_rxfail(bus
, true, false);
3826 brcmu_pkt_buf_free_skb(bus
->glom
);
3834 /* Basic SD framing looks ok - process each packet (header) */
3835 save_pfirst
= pfirst
;
3839 for (num
= 0; pfirst
; rxseq
++, pfirst
= pnext
) {
3840 pnext
= pfirst
->next
;
3841 pfirst
->next
= NULL
;
3843 dptr
= (u8
*) (pfirst
->data
);
3844 sublen
= get_unaligned_le16(dptr
);
3845 chan
= SDPCM_PACKET_CHANNEL(&dptr
[SDPCM_FRAMETAG_LEN
]);
3846 seq
= SDPCM_PACKET_SEQUENCE(&dptr
[SDPCM_FRAMETAG_LEN
]);
3847 doff
= SDPCM_DOFFSET_VALUE(&dptr
[SDPCM_FRAMETAG_LEN
]);
3849 DHD_GLOM(("%s: Get subframe %d, %p(%p/%d), sublen %d "
3851 __func__
, num
, pfirst
, pfirst
->data
,
3852 pfirst
->len
, sublen
, chan
, seq
));
3854 ASSERT((chan
== SDPCM_DATA_CHANNEL
)
3855 || (chan
== SDPCM_EVENT_CHANNEL
));
3858 DHD_GLOM(("%s: rx_seq %d, expected %d\n",
3859 __func__
, seq
, rxseq
));
3864 if (DHD_BYTES_ON() && DHD_DATA_ON()) {
3865 printk(KERN_DEBUG
"Rx Subframe Data:\n");
3866 print_hex_dump_bytes("", DUMP_PREFIX_OFFSET
,
3871 __skb_trim(pfirst
, sublen
);
3872 skb_pull(pfirst
, doff
);
3874 if (pfirst
->len
== 0) {
3875 brcmu_pkt_buf_free_skb(pfirst
);
3877 plast
->next
= pnext
;
3879 ASSERT(save_pfirst
== pfirst
);
3880 save_pfirst
= pnext
;
3883 } else if (brcmf_proto_hdrpull(bus
->drvr
, &ifidx
, pfirst
)
3885 DHD_ERROR(("%s: rx protocol error\n",
3887 bus
->drvr
->rx_errors
++;
3888 brcmu_pkt_buf_free_skb(pfirst
);
3890 plast
->next
= pnext
;
3892 ASSERT(save_pfirst
== pfirst
);
3893 save_pfirst
= pnext
;
3898 /* this packet will go up, link back into
3899 chain and count it */
3900 pfirst
->next
= pnext
;
3905 if (DHD_GLOM_ON()) {
3906 DHD_GLOM(("%s subframe %d to stack, %p(%p/%d) "
3908 __func__
, num
, pfirst
, pfirst
->data
,
3909 pfirst
->len
, pfirst
->next
,
3911 print_hex_dump_bytes("", DUMP_PREFIX_OFFSET
,
3913 min_t(int, pfirst
->len
, 32));
3918 brcmf_sdbrcm_sdunlock(bus
);
3919 brcmf_rx_frame(bus
->drvr
, ifidx
, save_pfirst
, num
);
3920 brcmf_sdbrcm_sdlock(bus
);
3923 bus
->rxglomframes
++;
3924 bus
->rxglompkts
+= num
;
3929 /* Return true if there may be more frames to read */
3931 brcmf_sdbrcm_readframes(struct brcmf_bus
*bus
, uint maxframes
, bool *finished
)
3933 struct brcmf_sdio_card
*card
= bus
->card
;
3935 u16 len
, check
; /* Extracted hardware header fields */
3936 u8 chan
, seq
, doff
; /* Extracted software header fields */
3937 u8 fcbits
; /* Extracted fcbits from software header */
3939 struct sk_buff
*pkt
; /* Packet for event or data frames */
3940 u16 pad
; /* Number of pad bytes to read */
3941 u16 rdlen
; /* Total number of bytes to read */
3942 u8 rxseq
; /* Next sequence number to expect */
3943 uint rxleft
= 0; /* Remaining number of frames allowed */
3944 int sdret
; /* Return code from calls */
3945 u8 txmax
; /* Maximum tx sequence offered */
3946 bool len_consistent
; /* Result of comparing readahead len and
3950 uint rxcount
= 0; /* Total frames read */
3952 #if defined(BCMDBG) || defined(SDTEST)
3953 bool sdtest
= false; /* To limit message spew from test mode */
3956 DHD_TRACE(("%s: Enter\n", __func__
));
3961 /* Allow pktgen to override maxframes */
3962 if (bus
->pktgen_count
&& (bus
->pktgen_mode
== BRCMF_PKTGEN_RECV
)) {
3963 maxframes
= bus
->pktgen_count
;
3968 /* Not finished unless we encounter no more frames indication */
3971 for (rxseq
= bus
->rx_seq
, rxleft
= maxframes
;
3972 !bus
->rxskip
&& rxleft
&& bus
->drvr
->busstate
!= DHD_BUS_DOWN
;
3973 rxseq
++, rxleft
--) {
3975 /* Handle glomming separately */
3976 if (bus
->glom
|| bus
->glomd
) {
3978 DHD_GLOM(("%s: calling rxglom: glomd %p, glom %p\n",
3979 __func__
, bus
->glomd
, bus
->glom
));
3980 cnt
= brcmf_sdbrcm_rxglom(bus
, rxseq
);
3981 DHD_GLOM(("%s: rxglom returned %d\n", __func__
, cnt
));
3983 rxleft
= (rxleft
> cnt
) ? (rxleft
- cnt
) : 1;
3987 /* Try doing single read if we can */
3988 if (brcmf_readahead
&& bus
->nextlen
) {
3989 u16 nextlen
= bus
->nextlen
;
3992 if (bus
->bus
== SPI_BUS
) {
3993 rdlen
= len
= nextlen
;
3995 rdlen
= len
= nextlen
<< 4;
3997 /* Pad read to blocksize for efficiency */
3998 if (bus
->roundup
&& bus
->blocksize
3999 && (rdlen
> bus
->blocksize
)) {
4002 (rdlen
% bus
->blocksize
);
4003 if ((pad
<= bus
->roundup
)
4004 && (pad
< bus
->blocksize
)
4005 && ((rdlen
+ pad
+ firstread
) <
4008 } else if (rdlen
% BRCMF_SDALIGN
) {
4010 BRCMF_SDALIGN
- (rdlen
% BRCMF_SDALIGN
);
4014 /* We use bus->rxctl buffer in WinXP for initial
4015 * control pkt receives.
4016 * Later we use buffer-poll for data as well
4017 * as control packets.
4018 * This is required because dhd receives full
4019 * frame in gSPI unlike SDIO.
4020 * After the frame is received we have to
4021 * distinguish whether it is data
4022 * or non-data frame.
4024 /* Allocate a packet buffer */
4025 pkt
= brcmu_pkt_buf_get_skb(rdlen
+ BRCMF_SDALIGN
);
4027 if (bus
->bus
== SPI_BUS
) {
4028 bus
->usebufpool
= false;
4029 bus
->rxctl
= bus
->rxbuf
;
4030 if (brcmf_alignctl
) {
4031 bus
->rxctl
+= firstread
;
4032 pad
= ((unsigned long)bus
->rxctl
%
4036 (BRCMF_SDALIGN
- pad
);
4037 bus
->rxctl
-= firstread
;
4039 ASSERT(bus
->rxctl
>= bus
->rxbuf
);
4041 /* Read the entire frame */
4042 sdret
= brcmf_sdcard_recv_buf(card
,
4043 brcmf_sdcard_cur_sbwad(card
),
4044 SDIO_FUNC_2
, F2SYNC
,
4048 ASSERT(sdret
!= -BCME_PENDING
);
4050 /* Control frame failures need
4053 DHD_ERROR(("%s: read %d control bytes failed: %d\n",
4056 /* dhd.rx_ctlerrs is higher */
4058 brcmf_sdbrcm_rxfail(bus
, true,
4066 request rtx of events */
4067 DHD_ERROR(("%s (nextlen): "
4068 "brcmu_pkt_buf_get_skb "
4070 " len %d rdlen %d expected"
4071 " rxseq %d\n", __func__
,
4072 len
, rdlen
, rxseq
));
4076 if (bus
->bus
== SPI_BUS
)
4077 bus
->usebufpool
= true;
4079 ASSERT(!(pkt
->prev
));
4080 PKTALIGN(pkt
, rdlen
, BRCMF_SDALIGN
);
4081 rxbuf
= (u8
*) (pkt
->data
);
4082 /* Read the entire frame */
4083 sdret
= brcmf_sdcard_recv_buf(card
,
4084 brcmf_sdcard_cur_sbwad(card
),
4085 SDIO_FUNC_2
, F2SYNC
,
4089 ASSERT(sdret
!= -BCME_PENDING
);
4092 DHD_ERROR(("%s (nextlen): read %d bytes failed: %d\n",
4093 __func__
, rdlen
, sdret
));
4094 brcmu_pkt_buf_free_skb(pkt
);
4095 bus
->drvr
->rx_errors
++;
4096 /* Force retry w/normal header read.
4097 * Don't attempt NAK for
4100 brcmf_sdbrcm_rxfail(bus
, true,
4108 /* Now check the header */
4109 memcpy(bus
->rxhdr
, rxbuf
, SDPCM_HDRLEN
);
4111 /* Extract hardware header fields */
4112 len
= get_unaligned_le16(bus
->rxhdr
);
4113 check
= get_unaligned_le16(bus
->rxhdr
+ sizeof(u16
));
4115 /* All zeros means readahead info was bad */
4116 if (!(len
| check
)) {
4117 DHD_INFO(("%s (nextlen): read zeros in HW "
4118 "header???\n", __func__
));
4119 brcmf_sdbrcm_pktfree2(bus
, pkt
);
4123 /* Validate check bytes */
4124 if ((u16
)~(len
^ check
)) {
4125 DHD_ERROR(("%s (nextlen): HW hdr error:"
4126 " nextlen/len/check"
4127 " 0x%04x/0x%04x/0x%04x\n",
4128 __func__
, nextlen
, len
, check
));
4130 brcmf_sdbrcm_rxfail(bus
, false, false);
4131 brcmf_sdbrcm_pktfree2(bus
, pkt
);
4135 /* Validate frame length */
4136 if (len
< SDPCM_HDRLEN
) {
4137 DHD_ERROR(("%s (nextlen): HW hdr length "
4138 "invalid: %d\n", __func__
, len
));
4139 brcmf_sdbrcm_pktfree2(bus
, pkt
);
4143 /* Check for consistency withreadahead info */
4144 len_consistent
= (nextlen
!= (roundup(len
, 16) >> 4));
4145 if (len_consistent
) {
4146 /* Mismatch, force retry w/normal
4147 header (may be >4K) */
4148 DHD_ERROR(("%s (nextlen): mismatch, "
4149 "nextlen %d len %d rnd %d; "
4150 "expected rxseq %d\n",
4152 len
, roundup(len
, 16), rxseq
));
4153 brcmf_sdbrcm_rxfail(bus
, true,
4154 bus
->bus
!= SPI_BUS
);
4155 brcmf_sdbrcm_pktfree2(bus
, pkt
);
4159 /* Extract software header fields */
4160 chan
= SDPCM_PACKET_CHANNEL(
4161 &bus
->rxhdr
[SDPCM_FRAMETAG_LEN
]);
4162 seq
= SDPCM_PACKET_SEQUENCE(
4163 &bus
->rxhdr
[SDPCM_FRAMETAG_LEN
]);
4164 doff
= SDPCM_DOFFSET_VALUE(
4165 &bus
->rxhdr
[SDPCM_FRAMETAG_LEN
]);
4166 txmax
= SDPCM_WINDOW_VALUE(
4167 &bus
->rxhdr
[SDPCM_FRAMETAG_LEN
]);
4170 bus
->rxhdr
[SDPCM_FRAMETAG_LEN
+
4171 SDPCM_NEXTLEN_OFFSET
];
4172 if ((bus
->nextlen
<< 4) > MAX_RX_DATASZ
) {
4173 DHD_INFO(("%s (nextlen): got frame w/nextlen too large" " (%d), seq %d\n",
4174 __func__
, bus
->nextlen
, seq
));
4178 bus
->drvr
->rx_readahead_cnt
++;
4180 /* Handle Flow Control */
4181 fcbits
= SDPCM_FCMASK_VALUE(
4182 &bus
->rxhdr
[SDPCM_FRAMETAG_LEN
]);
4184 if (bus
->flowcontrol
!= fcbits
) {
4185 if (~bus
->flowcontrol
& fcbits
)
4188 if (bus
->flowcontrol
& ~fcbits
)
4192 bus
->flowcontrol
= fcbits
;
4195 /* Check and update sequence number */
4197 DHD_INFO(("%s (nextlen): rx_seq %d, expected "
4198 "%d\n", __func__
, seq
, rxseq
));
4203 /* Check window for sanity */
4204 if ((u8
) (txmax
- bus
->tx_seq
) > 0x40) {
4205 DHD_ERROR(("%s: got unlikely tx max %d with "
4207 __func__
, txmax
, bus
->tx_seq
));
4208 txmax
= bus
->tx_seq
+ 2;
4210 bus
->tx_max
= txmax
;
4213 if (DHD_BYTES_ON() && DHD_DATA_ON()) {
4214 printk(KERN_DEBUG
"Rx Data:\n");
4215 print_hex_dump_bytes("", DUMP_PREFIX_OFFSET
,
4217 } else if (DHD_HDRS_ON()) {
4218 printk(KERN_DEBUG
"RxHdr:\n");
4219 print_hex_dump_bytes("", DUMP_PREFIX_OFFSET
,
4220 bus
->rxhdr
, SDPCM_HDRLEN
);
4224 if (chan
== SDPCM_CONTROL_CHANNEL
) {
4225 if (bus
->bus
== SPI_BUS
) {
4226 brcmf_sdbrcm_read_control(bus
, rxbuf
,
4229 DHD_ERROR(("%s (nextlen): readahead on control" " packet %d?\n",
4231 /* Force retry w/normal header read */
4233 brcmf_sdbrcm_rxfail(bus
, false, true);
4235 brcmf_sdbrcm_pktfree2(bus
, pkt
);
4239 if ((bus
->bus
== SPI_BUS
) && !bus
->usebufpool
) {
4240 DHD_ERROR(("Received %d bytes on %d channel. Running out of " "rx pktbuf's or not yet malloced.\n",
4245 /* Validate data offset */
4246 if ((doff
< SDPCM_HDRLEN
) || (doff
> len
)) {
4247 DHD_ERROR(("%s (nextlen): bad data offset %d: HW len %d min %d\n",
4248 __func__
, doff
, len
, SDPCM_HDRLEN
));
4249 brcmf_sdbrcm_rxfail(bus
, false, false);
4250 brcmf_sdbrcm_pktfree2(bus
, pkt
);
4254 /* All done with this one -- now deliver the packet */
4257 /* gSPI frames should not be handled in fractions */
4258 if (bus
->bus
== SPI_BUS
)
4261 /* Read frame header (hardware and software) */
4262 sdret
= brcmf_sdcard_recv_buf(card
,
4263 brcmf_sdcard_cur_sbwad(card
),
4264 SDIO_FUNC_2
, F2SYNC
, bus
->rxhdr
, firstread
,
4267 ASSERT(sdret
!= -BCME_PENDING
);
4270 DHD_ERROR(("%s: RXHEADER FAILED: %d\n", __func__
,
4273 brcmf_sdbrcm_rxfail(bus
, true, true);
4277 if (DHD_BYTES_ON() || DHD_HDRS_ON()) {
4278 printk(KERN_DEBUG
"RxHdr:\n");
4279 print_hex_dump_bytes("", DUMP_PREFIX_OFFSET
,
4280 bus
->rxhdr
, SDPCM_HDRLEN
);
4284 /* Extract hardware header fields */
4285 len
= get_unaligned_le16(bus
->rxhdr
);
4286 check
= get_unaligned_le16(bus
->rxhdr
+ sizeof(u16
));
4288 /* All zeros means no more frames */
4289 if (!(len
| check
)) {
4294 /* Validate check bytes */
4295 if ((u16
) ~(len
^ check
)) {
4296 DHD_ERROR(("%s: HW hdr err: len/check 0x%04x/0x%04x\n",
4297 __func__
, len
, check
));
4299 brcmf_sdbrcm_rxfail(bus
, false, false);
4303 /* Validate frame length */
4304 if (len
< SDPCM_HDRLEN
) {
4305 DHD_ERROR(("%s: HW hdr length invalid: %d\n",
4310 /* Extract software header fields */
4311 chan
= SDPCM_PACKET_CHANNEL(&bus
->rxhdr
[SDPCM_FRAMETAG_LEN
]);
4312 seq
= SDPCM_PACKET_SEQUENCE(&bus
->rxhdr
[SDPCM_FRAMETAG_LEN
]);
4313 doff
= SDPCM_DOFFSET_VALUE(&bus
->rxhdr
[SDPCM_FRAMETAG_LEN
]);
4314 txmax
= SDPCM_WINDOW_VALUE(&bus
->rxhdr
[SDPCM_FRAMETAG_LEN
]);
4316 /* Validate data offset */
4317 if ((doff
< SDPCM_HDRLEN
) || (doff
> len
)) {
4318 DHD_ERROR(("%s: Bad data offset %d: HW len %d, min %d "
4320 __func__
, doff
, len
, SDPCM_HDRLEN
, seq
));
4323 brcmf_sdbrcm_rxfail(bus
, false, false);
4327 /* Save the readahead length if there is one */
4329 bus
->rxhdr
[SDPCM_FRAMETAG_LEN
+ SDPCM_NEXTLEN_OFFSET
];
4330 if ((bus
->nextlen
<< 4) > MAX_RX_DATASZ
) {
4331 DHD_INFO(("%s (nextlen): got frame w/nextlen too large "
4333 __func__
, bus
->nextlen
, seq
));
4337 /* Handle Flow Control */
4338 fcbits
= SDPCM_FCMASK_VALUE(&bus
->rxhdr
[SDPCM_FRAMETAG_LEN
]);
4340 if (bus
->flowcontrol
!= fcbits
) {
4341 if (~bus
->flowcontrol
& fcbits
)
4344 if (bus
->flowcontrol
& ~fcbits
)
4348 bus
->flowcontrol
= fcbits
;
4351 /* Check and update sequence number */
4353 DHD_INFO(("%s: rx_seq %d, expected %d\n", __func__
,
4359 /* Check window for sanity */
4360 if ((u8
) (txmax
- bus
->tx_seq
) > 0x40) {
4361 DHD_ERROR(("%s: unlikely tx max %d with tx_seq %d\n",
4362 __func__
, txmax
, bus
->tx_seq
));
4363 txmax
= bus
->tx_seq
+ 2;
4365 bus
->tx_max
= txmax
;
4367 /* Call a separate function for control frames */
4368 if (chan
== SDPCM_CONTROL_CHANNEL
) {
4369 brcmf_sdbrcm_read_control(bus
, bus
->rxhdr
, len
, doff
);
4373 ASSERT((chan
== SDPCM_DATA_CHANNEL
)
4374 || (chan
== SDPCM_EVENT_CHANNEL
)
4375 || (chan
== SDPCM_TEST_CHANNEL
)
4376 || (chan
== SDPCM_GLOM_CHANNEL
));
4378 /* Length to read */
4379 rdlen
= (len
> firstread
) ? (len
- firstread
) : 0;
4381 /* May pad read to blocksize for efficiency */
4382 if (bus
->roundup
&& bus
->blocksize
&&
4383 (rdlen
> bus
->blocksize
)) {
4384 pad
= bus
->blocksize
- (rdlen
% bus
->blocksize
);
4385 if ((pad
<= bus
->roundup
) && (pad
< bus
->blocksize
) &&
4386 ((rdlen
+ pad
+ firstread
) < MAX_RX_DATASZ
))
4388 } else if (rdlen
% BRCMF_SDALIGN
) {
4389 rdlen
+= BRCMF_SDALIGN
- (rdlen
% BRCMF_SDALIGN
);
4392 /* Satisfy length-alignment requirements */
4393 if (forcealign
&& (rdlen
& (ALIGNMENT
- 1)))
4394 rdlen
= roundup(rdlen
, ALIGNMENT
);
4396 if ((rdlen
+ firstread
) > MAX_RX_DATASZ
) {
4397 /* Too long -- skip this frame */
4398 DHD_ERROR(("%s: too long: len %d rdlen %d\n",
4399 __func__
, len
, rdlen
));
4400 bus
->drvr
->rx_errors
++;
4402 brcmf_sdbrcm_rxfail(bus
, false, false);
4406 pkt
= brcmu_pkt_buf_get_skb(rdlen
+ firstread
+ BRCMF_SDALIGN
);
4408 /* Give up on data, request rtx of events */
4409 DHD_ERROR(("%s: brcmu_pkt_buf_get_skb failed: rdlen %d"
4410 " chan %d\n", __func__
, rdlen
, chan
));
4411 bus
->drvr
->rx_dropped
++;
4412 brcmf_sdbrcm_rxfail(bus
, false, RETRYCHAN(chan
));
4416 ASSERT(!(pkt
->prev
));
4418 /* Leave room for what we already read, and align remainder */
4419 ASSERT(firstread
< pkt
->len
);
4420 skb_pull(pkt
, firstread
);
4421 PKTALIGN(pkt
, rdlen
, BRCMF_SDALIGN
);
4423 /* Read the remaining frame data */
4424 sdret
= brcmf_sdcard_recv_buf(card
,
4425 brcmf_sdcard_cur_sbwad(card
),
4426 SDIO_FUNC_2
, F2SYNC
, ((u8
*) (pkt
->data
)),
4427 rdlen
, pkt
, NULL
, NULL
);
4429 ASSERT(sdret
!= -BCME_PENDING
);
4432 DHD_ERROR(("%s: read %d %s bytes failed: %d\n",
4435 SDPCM_EVENT_CHANNEL
) ? "event" : ((chan
==
4437 ? "data" : "test")),
4439 brcmu_pkt_buf_free_skb(pkt
);
4440 bus
->drvr
->rx_errors
++;
4441 brcmf_sdbrcm_rxfail(bus
, true, RETRYCHAN(chan
));
4445 /* Copy the already-read portion */
4446 skb_push(pkt
, firstread
);
4447 memcpy(pkt
->data
, bus
->rxhdr
, firstread
);
4450 if (DHD_BYTES_ON() && DHD_DATA_ON()) {
4451 printk(KERN_DEBUG
"Rx Data:\n");
4452 print_hex_dump_bytes("", DUMP_PREFIX_OFFSET
,
4458 /* Save superframe descriptor and allocate packet frame */
4459 if (chan
== SDPCM_GLOM_CHANNEL
) {
4460 if (SDPCM_GLOMDESC(&bus
->rxhdr
[SDPCM_FRAMETAG_LEN
])) {
4461 DHD_GLOM(("%s: glom descriptor, %d bytes:\n",
4464 if (DHD_GLOM_ON()) {
4465 printk(KERN_DEBUG
"Glom Data:\n");
4466 print_hex_dump_bytes("",
4471 __skb_trim(pkt
, len
);
4472 ASSERT(doff
== SDPCM_HDRLEN
);
4473 skb_pull(pkt
, SDPCM_HDRLEN
);
4476 DHD_ERROR(("%s: glom superframe w/o "
4477 "descriptor!\n", __func__
));
4478 brcmf_sdbrcm_rxfail(bus
, false, false);
4483 /* Fill in packet len and prio, deliver upward */
4484 __skb_trim(pkt
, len
);
4485 skb_pull(pkt
, doff
);
4488 /* Test channel packets are processed separately */
4489 if (chan
== SDPCM_TEST_CHANNEL
) {
4490 brcmf_sdbrcm_checkdied(bus
, pkt
, seq
);
4495 if (pkt
->len
== 0) {
4496 brcmu_pkt_buf_free_skb(pkt
);
4498 } else if (brcmf_proto_hdrpull(bus
->drvr
, &ifidx
, pkt
) != 0) {
4499 DHD_ERROR(("%s: rx protocol error\n", __func__
));
4500 brcmu_pkt_buf_free_skb(pkt
);
4501 bus
->drvr
->rx_errors
++;
4505 /* Unlock during rx call */
4506 brcmf_sdbrcm_sdunlock(bus
);
4507 brcmf_rx_frame(bus
->drvr
, ifidx
, pkt
, 1);
4508 brcmf_sdbrcm_sdlock(bus
);
4510 rxcount
= maxframes
- rxleft
;
4512 /* Message if we hit the limit */
4513 if (!rxleft
&& !sdtest
)
4514 DHD_DATA(("%s: hit rx limit of %d frames\n", __func__
,
4518 DHD_DATA(("%s: processed %d frames\n", __func__
, rxcount
));
4519 /* Back off rxseq if awaiting rtx, update rx_seq */
4522 bus
->rx_seq
= rxseq
;
4527 static u32
brcmf_sdbrcm_hostmail(struct brcmf_bus
*bus
)
4534 DHD_TRACE(("%s: Enter\n", __func__
));
4536 /* Read mailbox data and ack that we did so */
4537 r_sdreg32(bus
, &hmb_data
,
4538 offsetof(struct sdpcmd_regs
, tohostmailboxdata
), &retries
);
4540 if (retries
<= retry_limit
)
4541 w_sdreg32(bus
, SMB_INT_ACK
,
4542 offsetof(struct sdpcmd_regs
, tosbmailbox
), &retries
);
4543 bus
->f1regdata
+= 2;
4545 /* Dongle recomposed rx frames, accept them again */
4546 if (hmb_data
& HMB_DATA_NAKHANDLED
) {
4547 DHD_INFO(("Dongle reports NAK handled, expect rtx of %d\n",
4550 DHD_ERROR(("%s: unexpected NAKHANDLED!\n", __func__
));
4552 bus
->rxskip
= false;
4553 intstatus
|= I_HMB_FRAME_IND
;
4557 * DEVREADY does not occur with gSPI.
4559 if (hmb_data
& (HMB_DATA_DEVREADY
| HMB_DATA_FWREADY
)) {
4561 (hmb_data
& HMB_DATA_VERSION_MASK
) >>
4562 HMB_DATA_VERSION_SHIFT
;
4563 if (bus
->sdpcm_ver
!= SDPCM_PROT_VERSION
)
4564 DHD_ERROR(("Version mismatch, dongle reports %d, "
4566 bus
->sdpcm_ver
, SDPCM_PROT_VERSION
));
4568 DHD_INFO(("Dongle ready, protocol version %d\n",
4573 * Flow Control has been moved into the RX headers and this out of band
4574 * method isn't used any more.
4575 * remaining backward compatible with older dongles.
4577 if (hmb_data
& HMB_DATA_FC
) {
4578 fcbits
= (hmb_data
& HMB_DATA_FCDATA_MASK
) >>
4579 HMB_DATA_FCDATA_SHIFT
;
4581 if (fcbits
& ~bus
->flowcontrol
)
4584 if (bus
->flowcontrol
& ~fcbits
)
4588 bus
->flowcontrol
= fcbits
;
4591 /* Shouldn't be any others */
4592 if (hmb_data
& ~(HMB_DATA_DEVREADY
|
4593 HMB_DATA_NAKHANDLED
|
4596 HMB_DATA_FCDATA_MASK
| HMB_DATA_VERSION_MASK
)) {
4597 DHD_ERROR(("Unknown mailbox data content: 0x%02x\n", hmb_data
));
4603 static bool brcmf_sdbrcm_dpc(struct brcmf_bus
*bus
)
4605 struct brcmf_sdio_card
*card
= bus
->card
;
4606 u32 intstatus
, newstatus
= 0;
4608 uint rxlimit
= brcmf_rxbound
; /* Rx frames to read before resched */
4609 uint txlimit
= brcmf_txbound
; /* Tx frames to send before resched */
4610 uint framecnt
= 0; /* Temporary counter of tx/rx frames */
4611 bool rxdone
= true; /* Flag for no more read data */
4612 bool resched
= false; /* Flag indicating resched wanted */
4614 DHD_TRACE(("%s: Enter\n", __func__
));
4616 /* Start with leftover status bits */
4617 intstatus
= bus
->intstatus
;
4619 brcmf_sdbrcm_sdlock(bus
);
4621 /* If waiting for HTAVAIL, check status */
4622 if (bus
->clkstate
== CLK_PENDING
) {
4624 u8 clkctl
, devctl
= 0;
4627 /* Check for inconsistent device control */
4628 devctl
= brcmf_sdcard_cfg_read(card
, SDIO_FUNC_1
,
4629 SBSDIO_DEVICE_CTL
, &err
);
4631 DHD_ERROR(("%s: error reading DEVCTL: %d\n",
4633 bus
->drvr
->busstate
= DHD_BUS_DOWN
;
4635 ASSERT(devctl
& SBSDIO_DEVCTL_CA_INT_ONLY
);
4639 /* Read CSR, if clock on switch to AVAIL, else ignore */
4640 clkctl
= brcmf_sdcard_cfg_read(card
, SDIO_FUNC_1
,
4641 SBSDIO_FUNC1_CHIPCLKCSR
, &err
);
4643 DHD_ERROR(("%s: error reading CSR: %d\n", __func__
,
4645 bus
->drvr
->busstate
= DHD_BUS_DOWN
;
4648 DHD_INFO(("DPC: PENDING, devctl 0x%02x clkctl 0x%02x\n", devctl
,
4651 if (SBSDIO_HTAV(clkctl
)) {
4652 devctl
= brcmf_sdcard_cfg_read(card
, SDIO_FUNC_1
,
4653 SBSDIO_DEVICE_CTL
, &err
);
4655 DHD_ERROR(("%s: error reading DEVCTL: %d\n",
4657 bus
->drvr
->busstate
= DHD_BUS_DOWN
;
4659 devctl
&= ~SBSDIO_DEVCTL_CA_INT_ONLY
;
4660 brcmf_sdcard_cfg_write(card
, SDIO_FUNC_1
,
4661 SBSDIO_DEVICE_CTL
, devctl
, &err
);
4663 DHD_ERROR(("%s: error writing DEVCTL: %d\n",
4665 bus
->drvr
->busstate
= DHD_BUS_DOWN
;
4667 bus
->clkstate
= CLK_AVAIL
;
4675 /* Make sure backplane clock is on */
4676 brcmf_sdbrcm_clkctl(bus
, CLK_AVAIL
, true);
4677 if (bus
->clkstate
== CLK_PENDING
)
4680 /* Pending interrupt indicates new device status */
4683 r_sdreg32(bus
, &newstatus
,
4684 offsetof(struct sdpcmd_regs
, intstatus
), &retries
);
4686 if (brcmf_sdcard_regfail(bus
->card
))
4688 newstatus
&= bus
->hostintmask
;
4689 bus
->fcstate
= !!(newstatus
& I_HMB_FC_STATE
);
4691 w_sdreg32(bus
, newstatus
,
4692 offsetof(struct sdpcmd_regs
, intstatus
),
4698 /* Merge new bits with previous */
4699 intstatus
|= newstatus
;
4702 /* Handle flow-control change: read new state in case our ack
4703 * crossed another change interrupt. If change still set, assume
4704 * FC ON for safety, let next loop through do the debounce.
4706 if (intstatus
& I_HMB_FC_CHANGE
) {
4707 intstatus
&= ~I_HMB_FC_CHANGE
;
4708 w_sdreg32(bus
, I_HMB_FC_CHANGE
,
4709 offsetof(struct sdpcmd_regs
, intstatus
), &retries
);
4711 r_sdreg32(bus
, &newstatus
,
4712 offsetof(struct sdpcmd_regs
, intstatus
), &retries
);
4713 bus
->f1regdata
+= 2;
4715 !!(newstatus
& (I_HMB_FC_STATE
| I_HMB_FC_CHANGE
));
4716 intstatus
|= (newstatus
& bus
->hostintmask
);
4719 /* Handle host mailbox indication */
4720 if (intstatus
& I_HMB_HOST_INT
) {
4721 intstatus
&= ~I_HMB_HOST_INT
;
4722 intstatus
|= brcmf_sdbrcm_hostmail(bus
);
4725 /* Generally don't ask for these, can get CRC errors... */
4726 if (intstatus
& I_WR_OOSYNC
) {
4727 DHD_ERROR(("Dongle reports WR_OOSYNC\n"));
4728 intstatus
&= ~I_WR_OOSYNC
;
4731 if (intstatus
& I_RD_OOSYNC
) {
4732 DHD_ERROR(("Dongle reports RD_OOSYNC\n"));
4733 intstatus
&= ~I_RD_OOSYNC
;
4736 if (intstatus
& I_SBINT
) {
4737 DHD_ERROR(("Dongle reports SBINT\n"));
4738 intstatus
&= ~I_SBINT
;
4741 /* Would be active due to wake-wlan in gSPI */
4742 if (intstatus
& I_CHIPACTIVE
) {
4743 DHD_INFO(("Dongle reports CHIPACTIVE\n"));
4744 intstatus
&= ~I_CHIPACTIVE
;
4747 /* Ignore frame indications if rxskip is set */
4749 intstatus
&= ~I_HMB_FRAME_IND
;
4751 /* On frame indication, read available frames */
4752 if (PKT_AVAILABLE()) {
4753 framecnt
= brcmf_sdbrcm_readframes(bus
, rxlimit
, &rxdone
);
4754 if (rxdone
|| bus
->rxskip
)
4755 intstatus
&= ~I_HMB_FRAME_IND
;
4756 rxlimit
-= min(framecnt
, rxlimit
);
4759 /* Keep still-pending events for next scheduling */
4760 bus
->intstatus
= intstatus
;
4763 /* Re-enable interrupts to detect new device events (mailbox, rx frame)
4764 * or clock availability. (Allows tx loop to check ipend if desired.)
4765 * (Unless register access seems hosed, as we may not be able to ACK...)
4767 if (bus
->intr
&& bus
->intdis
&& !brcmf_sdcard_regfail(card
)) {
4768 DHD_INTR(("%s: enable SDIO interrupts, rxdone %d framecnt %d\n",
4769 __func__
, rxdone
, framecnt
));
4770 bus
->intdis
= false;
4771 brcmf_sdcard_intr_enable(card
);
4774 if (DATAOK(bus
) && bus
->ctrl_frame_stat
&&
4775 (bus
->clkstate
== CLK_AVAIL
)) {
4778 ret
= brcmf_sdbrcm_send_buf(bus
, brcmf_sdcard_cur_sbwad(card
),
4779 SDIO_FUNC_2
, F2SYNC
, (u8
*) bus
->ctrl_frame_buf
,
4780 (u32
) bus
->ctrl_frame_len
, NULL
, NULL
, NULL
);
4781 ASSERT(ret
!= -BCME_PENDING
);
4784 /* On failure, abort the command and
4785 terminate the frame */
4786 DHD_INFO(("%s: sdio error %d, abort command and "
4787 "terminate frame.\n", __func__
, ret
));
4790 brcmf_sdcard_abort(card
, SDIO_FUNC_2
);
4792 brcmf_sdcard_cfg_write(card
, SDIO_FUNC_1
,
4793 SBSDIO_FUNC1_FRAMECTRL
, SFC_WF_TERM
,
4797 for (i
= 0; i
< 3; i
++) {
4799 hi
= brcmf_sdcard_cfg_read(card
, SDIO_FUNC_1
,
4800 SBSDIO_FUNC1_WFRAMEBCHI
,
4802 lo
= brcmf_sdcard_cfg_read(card
, SDIO_FUNC_1
,
4803 SBSDIO_FUNC1_WFRAMEBCLO
,
4805 bus
->f1regdata
+= 2;
4806 if ((hi
== 0) && (lo
== 0))
4812 bus
->tx_seq
= (bus
->tx_seq
+ 1) % SDPCM_SEQUENCE_WRAP
;
4814 DHD_INFO(("Return_dpc value is : %d\n", ret
));
4815 bus
->ctrl_frame_stat
= false;
4816 brcmf_sdbrcm_wait_event_wakeup(bus
);
4818 /* Send queued frames (limit 1 if rx may still be pending) */
4819 else if ((bus
->clkstate
== CLK_AVAIL
) && !bus
->fcstate
&&
4820 brcmu_pktq_mlen(&bus
->txq
, ~bus
->flowcontrol
) && txlimit
4822 framecnt
= rxdone
? txlimit
: min(txlimit
, dhd_txminmax
);
4823 framecnt
= brcmf_sdbrcm_sendfromq(bus
, framecnt
);
4824 txlimit
-= framecnt
;
4827 /* Resched if events or tx frames are pending,
4828 else await next interrupt */
4829 /* On failed register access, all bets are off:
4830 no resched or interrupts */
4831 if ((bus
->drvr
->busstate
== DHD_BUS_DOWN
) ||
4832 brcmf_sdcard_regfail(card
)) {
4833 DHD_ERROR(("%s: failed backplane access over SDIO, halting "
4834 "operation %d\n", __func__
,
4835 brcmf_sdcard_regfail(card
)));
4836 bus
->drvr
->busstate
= DHD_BUS_DOWN
;
4838 } else if (bus
->clkstate
== CLK_PENDING
) {
4839 DHD_INFO(("%s: rescheduled due to CLK_PENDING awaiting "
4840 "I_CHIPACTIVE interrupt\n", __func__
));
4842 } else if (bus
->intstatus
|| bus
->ipend
||
4843 (!bus
->fcstate
&& brcmu_pktq_mlen(&bus
->txq
, ~bus
->flowcontrol
)
4844 && DATAOK(bus
)) || PKT_AVAILABLE()) {
4848 bus
->dpc_sched
= resched
;
4850 /* If we're done for now, turn off clock request. */
4851 if ((bus
->clkstate
!= CLK_PENDING
)
4852 && bus
->idletime
== BRCMF_IDLE_IMMEDIATE
) {
4853 bus
->activity
= false;
4854 brcmf_sdbrcm_clkctl(bus
, CLK_NONE
, false);
4857 brcmf_sdbrcm_sdunlock(bus
);
4862 void brcmf_sdbrcm_isr(void *arg
)
4864 struct brcmf_bus
*bus
= (struct brcmf_bus
*) arg
;
4865 struct brcmf_sdio_card
*card
;
4867 DHD_TRACE(("%s: Enter\n", __func__
));
4870 DHD_ERROR(("%s : bus is null pointer , exit\n", __func__
));
4875 if (bus
->drvr
->busstate
== DHD_BUS_DOWN
) {
4876 DHD_ERROR(("%s : bus is down. we have nothing to do\n",
4880 /* Count the interrupt call */
4884 /* Shouldn't get this interrupt if we're sleeping? */
4885 if (bus
->sleeping
) {
4886 DHD_ERROR(("INTERRUPT WHILE SLEEPING??\n"));
4890 /* Disable additional interrupts (is this needed now)? */
4892 DHD_INTR(("%s: disable SDIO interrupts\n", __func__
));
4894 DHD_ERROR(("brcmf_sdbrcm_isr() w/o interrupt configured!\n"));
4896 brcmf_sdcard_intr_disable(card
);
4899 #if defined(SDIO_ISR_THREAD)
4900 DHD_TRACE(("Calling brcmf_sdbrcm_dpc() from %s\n", __func__
));
4901 while (brcmf_sdbrcm_dpc(bus
))
4904 bus
->dpc_sched
= true;
4905 brcmf_sdbrcm_sched_dpc(bus
);
4911 static void brcmf_sdbrcm_pktgen_init(struct brcmf_bus
*bus
)
4913 /* Default to specified length, or full range */
4914 if (brcmf_pktgen_len
) {
4915 bus
->pktgen_maxlen
= min(brcmf_pktgen_len
,
4916 BRCMF_MAX_PKTGEN_LEN
);
4917 bus
->pktgen_minlen
= bus
->pktgen_maxlen
;
4919 bus
->pktgen_maxlen
= BRCMF_MAX_PKTGEN_LEN
;
4920 bus
->pktgen_minlen
= 0;
4922 bus
->pktgen_len
= (u16
) bus
->pktgen_minlen
;
4924 /* Default to per-watchdog burst with 10s print time */
4925 bus
->pktgen_freq
= 1;
4926 bus
->pktgen_print
= 10000 / brcmf_watchdog_ms
;
4927 bus
->pktgen_count
= (brcmf_pktgen
* brcmf_watchdog_ms
+ 999) / 1000;
4929 /* Default to echo mode */
4930 bus
->pktgen_mode
= BRCMF_PKTGEN_ECHO
;
4931 bus
->pktgen_stop
= 1;
4934 static void brcmf_sdbrcm_pktgen(struct brcmf_bus
*bus
)
4936 struct sk_buff
*pkt
;
4942 /* Display current count if appropriate */
4943 if (bus
->pktgen_print
&& (++bus
->pktgen_ptick
>= bus
->pktgen_print
)) {
4944 bus
->pktgen_ptick
= 0;
4945 printk(KERN_DEBUG
"%s: send attempts %d rcvd %d\n",
4946 __func__
, bus
->pktgen_sent
, bus
->pktgen_rcvd
);
4949 /* For recv mode, just make sure dongle has started sending */
4950 if (bus
->pktgen_mode
== BRCMF_PKTGEN_RECV
) {
4951 if (!bus
->pktgen_rcvd
)
4952 brcmf_sdbrcm_sdtest_set(bus
, true);
4956 /* Otherwise, generate or request the specified number of packets */
4957 for (pktcount
= 0; pktcount
< bus
->pktgen_count
; pktcount
++) {
4958 /* Stop if total has been reached */
4959 if (bus
->pktgen_total
4960 && (bus
->pktgen_sent
>= bus
->pktgen_total
)) {
4961 bus
->pktgen_count
= 0;
4965 /* Allocate an appropriate-sized packet */
4966 len
= bus
->pktgen_len
;
4967 pkt
= brcmu_pkt_buf_get_skb(
4968 len
+ SDPCM_HDRLEN
+ SDPCM_TEST_HDRLEN
+ BRCMF_SDALIGN
,
4971 DHD_ERROR(("%s: brcmu_pkt_buf_get_skb failed!\n",
4975 PKTALIGN(pkt
, (len
+ SDPCM_HDRLEN
+ SDPCM_TEST_HDRLEN
),
4977 data
= (u8
*) (pkt
->data
) + SDPCM_HDRLEN
;
4979 /* Write test header cmd and extra based on mode */
4980 switch (bus
->pktgen_mode
) {
4981 case BRCMF_PKTGEN_ECHO
:
4982 *data
++ = SDPCM_TEST_ECHOREQ
;
4983 *data
++ = (u8
) bus
->pktgen_sent
;
4986 case BRCMF_PKTGEN_SEND
:
4987 *data
++ = SDPCM_TEST_DISCARD
;
4988 *data
++ = (u8
) bus
->pktgen_sent
;
4991 case BRCMF_PKTGEN_RXBURST
:
4992 *data
++ = SDPCM_TEST_BURST
;
4993 *data
++ = (u8
) bus
->pktgen_count
;
4997 DHD_ERROR(("Unrecognized pktgen mode %d\n",
4999 brcmu_pkt_buf_free_skb(pkt
, true);
5000 bus
->pktgen_count
= 0;
5004 /* Write test header length field */
5005 *data
++ = (len
>> 0);
5006 *data
++ = (len
>> 8);
5008 /* Then fill in the remainder -- N/A for burst,
5010 for (fillbyte
= 0; fillbyte
< len
; fillbyte
++)
5012 SDPCM_TEST_FILL(fillbyte
, (u8
) bus
->pktgen_sent
);
5015 if (DHD_BYTES_ON() && DHD_DATA_ON()) {
5016 data
= (u8
*) (pkt
->data
) + SDPCM_HDRLEN
;
5017 printk(KERN_DEBUG
"brcmf_sdbrcm_pktgen: Tx Data:\n");
5018 print_hex_dump_bytes("", DUMP_PREFIX_OFFSET
, data
,
5019 pkt
->len
- SDPCM_HDRLEN
);
5024 if (brcmf_sdbrcm_txpkt(bus
, pkt
, SDPCM_TEST_CHANNEL
, true)) {
5026 if (bus
->pktgen_stop
5027 && bus
->pktgen_stop
== bus
->pktgen_fail
)
5028 bus
->pktgen_count
= 0;
5032 /* Bump length if not fixed, wrap at max */
5033 if (++bus
->pktgen_len
> bus
->pktgen_maxlen
)
5034 bus
->pktgen_len
= (u16
) bus
->pktgen_minlen
;
5036 /* Special case for burst mode: just send one request! */
5037 if (bus
->pktgen_mode
== BRCMF_PKTGEN_RXBURST
)
5042 static void brcmf_sdbrcm_sdtest_set(struct brcmf_bus
*bus
, bool start
)
5044 struct sk_buff
*pkt
;
5047 /* Allocate the packet */
5048 pkt
= brcmu_pkt_buf_get_skb(SDPCM_HDRLEN
+ SDPCM_TEST_HDRLEN
+
5049 BRCMF_SDALIGN
, true);
5051 DHD_ERROR(("%s: brcmu_pkt_buf_get_skb failed!\n", __func__
));
5054 PKTALIGN(pkt
, (SDPCM_HDRLEN
+ SDPCM_TEST_HDRLEN
), BRCMF_SDALIGN
);
5055 data
= (u8
*) (pkt
->data
) + SDPCM_HDRLEN
;
5057 /* Fill in the test header */
5058 *data
++ = SDPCM_TEST_SEND
;
5060 *data
++ = (bus
->pktgen_maxlen
>> 0);
5061 *data
++ = (bus
->pktgen_maxlen
>> 8);
5064 if (brcmf_sdbrcm_txpkt(bus
, pkt
, SDPCM_TEST_CHANNEL
, true))
5069 brcmf_sdbrcm_checkdied(struct brcmf_bus
*bus
, struct sk_buff
*pkt
, uint seq
)
5079 /* Check for min length */
5081 if (pktlen
< SDPCM_TEST_HDRLEN
) {
5082 DHD_ERROR(("brcmf_sdbrcm_checkdied: toss runt frame, pktlen "
5084 brcmu_pkt_buf_free_skb(pkt
, false);
5088 /* Extract header fields */
5093 len
+= *data
++ << 8;
5095 /* Check length for relevant commands */
5096 if (cmd
== SDPCM_TEST_DISCARD
|| cmd
== SDPCM_TEST_ECHOREQ
5097 || cmd
== SDPCM_TEST_ECHORSP
) {
5098 if (pktlen
!= len
+ SDPCM_TEST_HDRLEN
) {
5099 DHD_ERROR(("brcmf_sdbrcm_checkdied: frame length "
5100 "mismatch, pktlen %d seq %d" " cmd %d extra %d "
5102 pktlen
, seq
, cmd
, extra
, len
));
5103 brcmu_pkt_buf_free_skb(pkt
, false);
5108 /* Process as per command */
5110 case SDPCM_TEST_ECHOREQ
:
5111 /* Rx->Tx turnaround ok (even on NDIS w/current
5113 *(u8
*) (pkt
->data
) = SDPCM_TEST_ECHORSP
;
5114 if (brcmf_sdbrcm_txpkt(bus
, pkt
, SDPCM_TEST_CHANNEL
, true) == 0)
5118 brcmu_pkt_buf_free_skb(pkt
, false);
5123 case SDPCM_TEST_ECHORSP
:
5124 if (bus
->ext_loop
) {
5125 brcmu_pkt_buf_free_skb(pkt
, false);
5130 for (offset
= 0; offset
< len
; offset
++, data
++) {
5131 if (*data
!= SDPCM_TEST_FILL(offset
, extra
)) {
5132 DHD_ERROR(("brcmf_sdbrcm_checkdied: echo data "
5133 "mismatch: " "offset %d (len %d) "
5134 "expect 0x%02x rcvd 0x%02x\n",
5136 SDPCM_TEST_FILL(offset
, extra
),
5141 brcmu_pkt_buf_free_skb(pkt
, false);
5145 case SDPCM_TEST_DISCARD
:
5146 brcmu_pkt_buf_free_skb(pkt
, false);
5150 case SDPCM_TEST_BURST
:
5151 case SDPCM_TEST_SEND
:
5153 DHD_INFO(("brcmf_sdbrcm_checkdied: unsupported or unknown "
5154 "command, pktlen %d seq %d" " cmd %d extra %d len %d\n",
5155 pktlen
, seq
, cmd
, extra
, len
));
5156 brcmu_pkt_buf_free_skb(pkt
, false);
5160 /* For recv mode, stop at limie (and tell dongle to stop sending) */
5161 if (bus
->pktgen_mode
== BRCMF_PKTGEN_RECV
) {
5162 if (bus
->pktgen_total
5163 && (bus
->pktgen_rcvd
>= bus
->pktgen_total
)) {
5164 bus
->pktgen_count
= 0;
5165 brcmf_sdbrcm_sdtest_set(bus
, false);
5171 extern bool brcmf_sdbrcm_bus_watchdog(struct brcmf_pub
*drvr
)
5173 struct brcmf_bus
*bus
;
5175 DHD_TIMER(("%s: Enter\n", __func__
));
5179 if (bus
->drvr
->dongle_reset
)
5182 /* Ignore the timer if simulating bus down */
5186 brcmf_sdbrcm_sdlock(bus
);
5188 /* Poll period: check device if appropriate. */
5189 if (bus
->poll
&& (++bus
->polltick
>= bus
->pollrate
)) {
5192 /* Reset poll tick */
5195 /* Check device if no interrupts */
5196 if (!bus
->intr
|| (bus
->intrcount
== bus
->lastintrs
)) {
5198 if (!bus
->dpc_sched
) {
5200 devpend
= brcmf_sdcard_cfg_read(bus
->card
,
5201 SDIO_FUNC_0
, SDIO_CCCR_INTx
,
5204 devpend
& (INTR_STATUS_FUNC1
|
5208 /* If there is something, make like the ISR and
5214 brcmf_sdcard_intr_disable(bus
->card
);
5216 bus
->dpc_sched
= true;
5217 brcmf_sdbrcm_sched_dpc(bus
);
5222 /* Update interrupt tracking */
5223 bus
->lastintrs
= bus
->intrcount
;
5226 /* Poll for console output periodically */
5227 if (drvr
->busstate
== DHD_BUS_DATA
&& brcmf_console_ms
!= 0) {
5228 bus
->console
.count
+= brcmf_watchdog_ms
;
5229 if (bus
->console
.count
>= brcmf_console_ms
) {
5230 bus
->console
.count
-= brcmf_console_ms
;
5231 /* Make sure backplane clock is on */
5232 brcmf_sdbrcm_clkctl(bus
, CLK_AVAIL
, false);
5233 if (brcmf_sdbrcm_readconsole(bus
) < 0)
5234 brcmf_console_ms
= 0; /* On error,
5241 /* Generate packets if configured */
5242 if (bus
->pktgen_count
&& (++bus
->pktgen_tick
>= bus
->pktgen_freq
)) {
5243 /* Make sure backplane clock is on */
5244 brcmf_sdbrcm_clkctl(bus
, CLK_AVAIL
, false);
5245 bus
->pktgen_tick
= 0;
5246 brcmf_sdbrcm_pktgen(bus
);
5250 /* On idle timeout clear activity flag and/or turn off clock */
5251 if ((bus
->idletime
> 0) && (bus
->clkstate
== CLK_AVAIL
)) {
5252 if (++bus
->idlecount
>= bus
->idletime
) {
5254 if (bus
->activity
) {
5255 bus
->activity
= false;
5256 brcmf_sdbrcm_wd_timer(bus
, brcmf_watchdog_ms
);
5258 brcmf_sdbrcm_clkctl(bus
, CLK_NONE
, false);
5263 brcmf_sdbrcm_sdunlock(bus
);
5269 static int brcmf_sdbrcm_bus_console_in(struct brcmf_pub
*drvr
,
5270 unsigned char *msg
, uint msglen
)
5272 struct brcmf_bus
*bus
= drvr
->bus
;
5275 struct sk_buff
*pkt
;
5277 /* Address could be zero if CONSOLE := 0 in dongle Makefile */
5278 if (bus
->console_addr
== 0)
5281 /* Exclusive bus access */
5282 brcmf_sdbrcm_sdlock(bus
);
5284 /* Don't allow input if dongle is in reset */
5285 if (bus
->drvr
->dongle_reset
) {
5286 brcmf_sdbrcm_sdunlock(bus
);
5290 /* Request clock to allow SDIO accesses */
5292 /* No pend allowed since txpkt is called later, ht clk has to be on */
5293 brcmf_sdbrcm_clkctl(bus
, CLK_AVAIL
, false);
5295 /* Zero cbuf_index */
5296 addr
= bus
->console_addr
+ offsetof(struct rte_console
, cbuf_idx
);
5297 val
= cpu_to_le32(0);
5298 rv
= brcmf_sdbrcm_membytes(bus
, true, addr
, (u8
*)&val
, sizeof(val
));
5302 /* Write message into cbuf */
5303 addr
= bus
->console_addr
+ offsetof(struct rte_console
, cbuf
);
5304 rv
= brcmf_sdbrcm_membytes(bus
, true, addr
, (u8
*)msg
, msglen
);
5308 /* Write length into vcons_in */
5309 addr
= bus
->console_addr
+ offsetof(struct rte_console
, vcons_in
);
5310 val
= cpu_to_le32(msglen
);
5311 rv
= brcmf_sdbrcm_membytes(bus
, true, addr
, (u8
*)&val
, sizeof(val
));
5315 /* Bump dongle by sending an empty event pkt.
5316 * sdpcm_sendup (RX) checks for virtual console input.
5318 pkt
= brcmu_pkt_buf_get_skb(4 + SDPCM_RESERVE
);
5319 if ((pkt
!= NULL
) && bus
->clkstate
== CLK_AVAIL
)
5320 brcmf_sdbrcm_txpkt(bus
, pkt
, SDPCM_EVENT_CHANNEL
, true);
5323 if ((bus
->idletime
== BRCMF_IDLE_IMMEDIATE
) && !bus
->dpc_sched
) {
5324 bus
->activity
= false;
5325 brcmf_sdbrcm_clkctl(bus
, CLK_NONE
, true);
5328 brcmf_sdbrcm_sdunlock(bus
);
5334 static bool brcmf_sdbrcm_chipmatch(u16 chipid
)
5336 if (chipid
== BCM4325_CHIP_ID
)
5338 if (chipid
== BCM4329_CHIP_ID
)
5340 if (chipid
== BCM4319_CHIP_ID
)
5345 static void *brcmf_sdbrcm_probe(u16 venid
, u16 devid
, u16 bus_no
,
5346 u16 slot
, u16 func
, uint bustype
, u32 regsva
,
5350 struct brcmf_bus
*bus
;
5352 /* Init global variables at run-time, not as part of the declaration.
5353 * This is required to support init/de-init of the driver.
5355 * of globals as part of the declaration results in non-deterministic
5356 * behavior since the value of the globals may be different on the
5357 * first time that the driver is initialized vs subsequent
5360 brcmf_txbound
= DHD_TXBOUND
;
5361 brcmf_rxbound
= DHD_RXBOUND
;
5362 brcmf_alignctl
= true;
5364 brcmf_readahead
= true;
5366 brcmf_dongle_memsize
= 0;
5367 dhd_txminmax
= DHD_TXMINMAX
;
5373 DHD_TRACE(("%s: Enter\n", __func__
));
5374 DHD_INFO(("%s: venid 0x%04x devid 0x%04x\n", __func__
, venid
, devid
));
5376 /* We make assumptions about address window mappings */
5377 ASSERT(regsva
== SI_ENUM_BASE
);
5379 /* SDIO car passes venid and devid based on CIS parsing -- but
5381 * means early parse could fail, so here we should get either an ID
5382 * we recognize OR (-1) indicating we must request power first.
5384 /* Check the Vendor ID */
5387 case PCI_VENDOR_ID_BROADCOM
:
5390 DHD_ERROR(("%s: unknown vendor: 0x%04x\n", __func__
, venid
));
5394 /* Check the Device ID and make sure it's one that we support */
5396 case BCM4325_D11DUAL_ID
: /* 4325 802.11a/g id */
5397 case BCM4325_D11G_ID
: /* 4325 802.11g 2.4Ghz band id */
5398 case BCM4325_D11A_ID
: /* 4325 802.11a 5Ghz band id */
5399 DHD_INFO(("%s: found 4325 Dongle\n", __func__
));
5401 case BCM4329_D11NDUAL_ID
: /* 4329 802.11n dualband device */
5402 case BCM4329_D11N2G_ID
: /* 4329 802.11n 2.4G device */
5403 case BCM4329_D11N5G_ID
: /* 4329 802.11n 5G device */
5405 DHD_INFO(("%s: found 4329 Dongle\n", __func__
));
5407 case BCM4319_D11N_ID
: /* 4319 802.11n id */
5408 case BCM4319_D11N2G_ID
: /* 4319 802.11n2g id */
5409 case BCM4319_D11N5G_ID
: /* 4319 802.11n5g id */
5410 DHD_INFO(("%s: found 4319 Dongle\n", __func__
));
5413 DHD_INFO(("%s: allow device id 0, will check chip internals\n",
5418 DHD_ERROR(("%s: skipping 0x%04x/0x%04x, not a dongle\n",
5419 __func__
, venid
, devid
));
5423 /* Allocate private bus interface state */
5424 bus
= kzalloc(sizeof(struct brcmf_bus
), GFP_ATOMIC
);
5426 DHD_ERROR(("%s: kmalloc of struct dhd_bus failed\n", __func__
));
5430 bus
->cl_devid
= (u16
) devid
;
5432 bus
->tx_seq
= SDPCM_SEQUENCE_WRAP
- 1;
5433 bus
->usebufpool
= false; /* Use bufpool if allocated,
5434 else use locally malloced rxbuf */
5436 /* attempt to attach to the dongle */
5437 if (!(brcmf_sdbrcm_probe_attach(bus
, card
, regsva
, devid
))) {
5438 DHD_ERROR(("%s: brcmf_sdbrcm_probe_attach failed\n", __func__
));
5442 spin_lock_init(&bus
->txqlock
);
5443 init_waitqueue_head(&bus
->ctrl_wait
);
5445 /* Set up the watchdog timer */
5446 init_timer(&bus
->timer
);
5447 bus
->timer
.data
= (unsigned long)bus
;
5448 bus
->timer
.function
= brcmf_sdbrcm_watchdog
;
5450 /* Initialize thread based operation and lock */
5451 if ((brcmf_watchdog_prio
>= 0) && (brcmf_dpc_prio
>= 0)) {
5452 bus
->threads_only
= true;
5453 sema_init(&bus
->sdsem
, 1);
5455 bus
->threads_only
= false;
5456 spin_lock_init(&bus
->sdlock
);
5459 if (brcmf_dpc_prio
>= 0) {
5460 /* Initialize watchdog thread */
5461 init_completion(&bus
->watchdog_wait
);
5462 bus
->watchdog_tsk
= kthread_run(brcmf_sdbrcm_watchdog_thread
,
5463 bus
, "brcmf_watchdog");
5464 if (IS_ERR(bus
->watchdog_tsk
)) {
5466 "brcmf_watchdog thread failed to start\n");
5467 bus
->watchdog_tsk
= NULL
;
5470 bus
->watchdog_tsk
= NULL
;
5472 /* Set up the bottom half handler */
5473 if (brcmf_dpc_prio
>= 0) {
5474 /* Initialize DPC thread */
5475 init_completion(&bus
->dpc_wait
);
5476 bus
->dpc_tsk
= kthread_run(brcmf_sdbrcm_dpc_thread
,
5478 if (IS_ERR(bus
->dpc_tsk
)) {
5480 "dhd_dpc thread failed to start\n");
5481 bus
->dpc_tsk
= NULL
;
5484 tasklet_init(&bus
->tasklet
, brcmf_sdbrcm_dpc_tasklet
,
5485 (unsigned long)bus
);
5486 bus
->dpc_tsk
= NULL
;
5489 /* Attach to the dhd/OS/network interface */
5490 bus
->drvr
= brcmf_attach(bus
, SDPCM_RESERVE
);
5492 DHD_ERROR(("%s: dhd_attach failed\n", __func__
));
5496 /* Allocate buffers */
5497 if (!(brcmf_sdbrcm_probe_malloc(bus
, card
))) {
5498 DHD_ERROR(("%s: brcmf_sdbrcm_probe_malloc failed\n", __func__
));
5502 if (!(brcmf_sdbrcm_probe_init(bus
, card
))) {
5503 DHD_ERROR(("%s: brcmf_sdbrcm_probe_init failed\n", __func__
));
5507 /* Register interrupt callback, but mask it (not operational yet). */
5508 DHD_INTR(("%s: disable SDIO interrupts (not interested yet)\n",
5510 brcmf_sdcard_intr_disable(card
);
5511 ret
= brcmf_sdcard_intr_reg(card
, brcmf_sdbrcm_isr
, bus
);
5513 DHD_ERROR(("%s: FAILED: sdcard_intr_reg returned %d\n",
5517 DHD_INTR(("%s: registered SDIO interrupt function ok\n", __func__
));
5519 DHD_INFO(("%s: completed!!\n", __func__
));
5521 /* if firmware path present try to download and bring up bus */
5522 ret
= brcmf_bus_start(bus
->drvr
);
5524 if (ret
== -ENOLINK
) {
5525 DHD_ERROR(("%s: dongle is not responding\n", __func__
));
5529 /* Ok, have the per-port tell the stack we're open for business */
5530 if (brcmf_net_attach(bus
->drvr
, 0) != 0) {
5531 DHD_ERROR(("%s: Net attach failed!!\n", __func__
));
5538 brcmf_sdbrcm_release(bus
);
5543 brcmf_sdbrcm_probe_attach(struct brcmf_bus
*bus
, void *card
, u32 regsva
,
5549 bus
->alp_only
= true;
5551 /* Return the window to backplane enumeration space for core access */
5552 if (brcmf_sdbrcm_set_siaddr_window(bus
, SI_ENUM_BASE
))
5553 DHD_ERROR(("%s: FAILED to return to SI_ENUM_BASE\n", __func__
));
5556 printk(KERN_DEBUG
"F1 signature read @0x18000000=0x%4x\n",
5557 brcmf_sdcard_reg_read(bus
->card
, SI_ENUM_BASE
, 4));
5562 * Force PLL off until brcmf_sdbrcm_chip_attach()
5563 * programs PLL control regs
5566 brcmf_sdcard_cfg_write(card
, SDIO_FUNC_1
, SBSDIO_FUNC1_CHIPCLKCSR
,
5567 DHD_INIT_CLKCTL1
, &err
);
5570 brcmf_sdcard_cfg_read(card
, SDIO_FUNC_1
,
5571 SBSDIO_FUNC1_CHIPCLKCSR
, &err
);
5573 if (err
|| ((clkctl
& ~SBSDIO_AVBITS
) != DHD_INIT_CLKCTL1
)) {
5574 DHD_ERROR(("brcmf_sdbrcm_probe: ChipClkCSR access: err %d wrote"
5575 " 0x%02x read 0x%02x\n",
5576 err
, DHD_INIT_CLKCTL1
, clkctl
));
5580 if (brcmf_sdbrcm_chip_attach(bus
, regsva
)) {
5581 DHD_ERROR(("%s: brcmf_sdbrcm_chip_attach failed!\n", __func__
));
5585 if (!brcmf_sdbrcm_chipmatch((u16
) bus
->ci
->chip
)) {
5586 DHD_ERROR(("%s: unsupported chip: 0x%04x\n",
5587 __func__
, bus
->ci
->chip
));
5591 brcmf_sdbrcm_sdiod_drive_strength_init(bus
, brcmf_sdiod_drive_strength
);
5593 /* Get info on the ARM and SOCRAM cores... */
5594 if (!DHD_NOPMU(bus
)) {
5595 bus
->armrev
= SBCOREREV(brcmf_sdcard_reg_read(bus
->card
,
5596 CORE_SB(bus
->ci
->armcorebase
, sbidhigh
), 4));
5597 bus
->orig_ramsize
= bus
->ci
->ramsize
;
5598 if (!(bus
->orig_ramsize
)) {
5599 DHD_ERROR(("%s: failed to find SOCRAM memory!\n",
5603 bus
->ramsize
= bus
->orig_ramsize
;
5604 if (brcmf_dongle_memsize
)
5605 brcmf_sdbrcm_setmemsize(bus
, brcmf_dongle_memsize
);
5607 DHD_ERROR(("DHD: dongle ram size is set to %d(orig %d)\n",
5608 bus
->ramsize
, bus
->orig_ramsize
));
5611 /* Set core control so an SDIO reset does a backplane reset */
5612 OR_REG(bus
->ci
->buscorebase
+ offsetof(struct sdpcmd_regs
,
5616 brcmu_pktq_init(&bus
->txq
, (PRIOMASK
+ 1), TXQLEN
);
5618 /* Locate an appropriately-aligned portion of hdrbuf */
5619 bus
->rxhdr
= (u8
*) roundup((unsigned long)&bus
->hdrbuf
[0],
5622 /* Set the poll and/or interrupt flags */
5623 bus
->intr
= (bool) brcmf_intr
;
5624 bus
->poll
= (bool) brcmf_poll
;
5634 static bool brcmf_sdbrcm_probe_malloc(struct brcmf_bus
*bus
, void *card
)
5636 DHD_TRACE(("%s: Enter\n", __func__
));
5638 if (bus
->drvr
->maxctl
) {
5640 roundup((bus
->drvr
->maxctl
+ SDPCM_HDRLEN
),
5641 ALIGNMENT
) + BRCMF_SDALIGN
;
5642 bus
->rxbuf
= kmalloc(bus
->rxblen
, GFP_ATOMIC
);
5643 if (!(bus
->rxbuf
)) {
5644 DHD_ERROR(("%s: kmalloc of %d-byte rxbuf failed\n",
5645 __func__
, bus
->rxblen
));
5650 /* Allocate buffer to receive glomed packet */
5651 bus
->databuf
= kmalloc(MAX_DATA_BUF
, GFP_ATOMIC
);
5652 if (!(bus
->databuf
)) {
5653 DHD_ERROR(("%s: kmalloc of %d-byte databuf failed\n",
5654 __func__
, MAX_DATA_BUF
));
5655 /* release rxbuf which was already located as above */
5661 /* Align the buffer */
5662 if ((unsigned long)bus
->databuf
% BRCMF_SDALIGN
)
5663 bus
->dataptr
= bus
->databuf
+ (BRCMF_SDALIGN
-
5664 ((unsigned long)bus
->databuf
% BRCMF_SDALIGN
));
5666 bus
->dataptr
= bus
->databuf
;
5674 static bool brcmf_sdbrcm_probe_init(struct brcmf_bus
*bus
, void *card
)
5678 DHD_TRACE(("%s: Enter\n", __func__
));
5681 brcmf_sdbrcm_pktgen_init(bus
);
5684 /* Disable F2 to clear any intermediate frame state on the dongle */
5685 brcmf_sdcard_cfg_write(card
, SDIO_FUNC_0
, SDIO_CCCR_IOEx
,
5686 SDIO_FUNC_ENABLE_1
, NULL
);
5688 bus
->drvr
->busstate
= DHD_BUS_DOWN
;
5689 bus
->sleeping
= false;
5690 bus
->rxflow
= false;
5691 bus
->prev_rxlim_hit
= 0;
5693 /* Done with backplane-dependent accesses, can drop clock... */
5694 brcmf_sdcard_cfg_write(card
, SDIO_FUNC_1
, SBSDIO_FUNC1_CHIPCLKCSR
, 0,
5697 /* ...and initialize clock/power states */
5698 bus
->clkstate
= CLK_SDONLY
;
5699 bus
->idletime
= (s32
) brcmf_idletime
;
5700 bus
->idleclock
= BRCMF_IDLE_ACTIVE
;
5702 /* Query the F2 block size, set roundup accordingly */
5704 if (brcmf_sdcard_iovar_op(card
, "sd_blocksize", &fnum
, sizeof(s32
),
5705 &bus
->blocksize
, sizeof(s32
), false) != 0) {
5707 DHD_ERROR(("%s: fail on %s get\n", __func__
, "sd_blocksize"));
5709 DHD_INFO(("%s: Initial value for %s is %d\n",
5710 __func__
, "sd_blocksize", bus
->blocksize
));
5712 bus
->roundup
= min(max_roundup
, bus
->blocksize
);
5714 /* Query if bus module supports packet chaining,
5715 default to use if supported */
5716 if (brcmf_sdcard_iovar_op(card
, "sd_rxchain", NULL
, 0,
5717 &bus
->sd_rxchain
, sizeof(s32
),
5719 bus
->sd_rxchain
= false;
5721 DHD_INFO(("%s: bus module (through sdiocard API) %s chaining\n",
5723 (bus
->sd_rxchain
? "supports" : "does not support")));
5725 bus
->use_rxchain
= (bool) bus
->sd_rxchain
;
5731 brcmf_sdbrcm_download_firmware(struct brcmf_bus
*bus
, void *card
)
5735 /* Download the firmware */
5736 brcmf_sdbrcm_clkctl(bus
, CLK_AVAIL
, false);
5738 ret
= _brcmf_sdbrcm_download_firmware(bus
) == 0;
5740 brcmf_sdbrcm_clkctl(bus
, CLK_SDONLY
, false);
5745 /* Detach and free everything */
5746 static void brcmf_sdbrcm_release(struct brcmf_bus
*bus
)
5748 DHD_TRACE(("%s: Enter\n", __func__
));
5751 /* De-register interrupt handler */
5752 brcmf_sdcard_intr_disable(bus
->card
);
5753 brcmf_sdcard_intr_dereg(bus
->card
);
5756 brcmf_detach(bus
->drvr
);
5757 brcmf_sdbrcm_release_dongle(bus
);
5761 brcmf_sdbrcm_release_malloc(bus
);
5766 DHD_TRACE(("%s: Disconnected\n", __func__
));
5769 static void brcmf_sdbrcm_release_malloc(struct brcmf_bus
*bus
)
5771 DHD_TRACE(("%s: Enter\n", __func__
));
5773 if (bus
->drvr
&& bus
->drvr
->dongle_reset
)
5777 bus
->rxctl
= bus
->rxbuf
= NULL
;
5780 kfree(bus
->databuf
);
5781 bus
->databuf
= NULL
;
5784 static void brcmf_sdbrcm_release_dongle(struct brcmf_bus
*bus
)
5786 DHD_TRACE(("%s: Enter\n", __func__
));
5788 if (bus
->drvr
&& bus
->drvr
->dongle_reset
)
5792 brcmf_sdbrcm_clkctl(bus
, CLK_AVAIL
, false);
5793 brcmf_sdbrcm_clkctl(bus
, CLK_NONE
, false);
5794 brcmf_sdbrcm_chip_detach(bus
);
5795 if (bus
->vars
&& bus
->varsz
)
5800 DHD_TRACE(("%s: Disconnected\n", __func__
));
5803 static void brcmf_sdbrcm_disconnect(void *ptr
)
5805 struct brcmf_bus
*bus
= (struct brcmf_bus
*)ptr
;
5807 DHD_TRACE(("%s: Enter\n", __func__
));
5811 brcmf_sdbrcm_release(bus
);
5814 DHD_TRACE(("%s: Disconnected\n", __func__
));
5817 /* Register/Unregister functions are called by the main DHD entry
5818 * point (e.g. module insertion) to link with the bus driver, in
5819 * order to look for or await the device.
5822 static struct brcmf_sdioh_driver dhd_sdio
= {
5824 brcmf_sdbrcm_disconnect
5827 int brcmf_bus_register(void)
5829 DHD_TRACE(("%s: Enter\n", __func__
));
5831 /* Sanity check on the module parameters */
5833 /* Both watchdog and DPC as tasklets are ok */
5834 if ((brcmf_watchdog_prio
< 0) && (brcmf_dpc_prio
< 0))
5837 /* If both watchdog and DPC are threads, TX must be deferred */
5838 if ((brcmf_watchdog_prio
>= 0) && (brcmf_dpc_prio
>= 0)
5839 && brcmf_deferred_tx
)
5842 DHD_ERROR(("Invalid module parameters.\n"));
5846 return brcmf_sdio_register(&dhd_sdio
);
5849 void brcmf_bus_unregister(void)
5851 DHD_TRACE(("%s: Enter\n", __func__
));
5853 brcmf_sdio_unregister();
5856 static int brcmf_sdbrcm_download_code_file(struct brcmf_bus
*bus
)
5860 u8
*memblock
= NULL
, *memptr
;
5863 DHD_INFO(("%s: Enter\n", __func__
));
5865 bus
->fw_name
= BCM4329_FW_NAME
;
5866 ret
= request_firmware(&bus
->firmware
, bus
->fw_name
,
5867 &gInstance
->func
[2]->dev
);
5869 DHD_ERROR(("%s: Fail to request firmware %d\n", __func__
, ret
));
5874 memptr
= memblock
= kmalloc(MEMBLOCK
+ BRCMF_SDALIGN
, GFP_ATOMIC
);
5875 if (memblock
== NULL
) {
5876 DHD_ERROR(("%s: Failed to allocate memory %d bytes\n",
5877 __func__
, MEMBLOCK
));
5881 if ((u32
)(unsigned long)memblock
% BRCMF_SDALIGN
)
5882 memptr
+= (BRCMF_SDALIGN
-
5883 ((u32
)(unsigned long)memblock
% BRCMF_SDALIGN
));
5885 /* Download image */
5887 brcmf_sdbrcm_get_image((char *)memptr
, MEMBLOCK
, bus
))) {
5888 ret
= brcmf_sdbrcm_membytes(bus
, true, offset
, memptr
, len
);
5890 DHD_ERROR(("%s: error %d on writing %d membytes at "
5891 "0x%08x\n", __func__
, ret
, MEMBLOCK
, offset
));
5901 release_firmware(bus
->firmware
);
5908 * ProcessVars:Takes a buffer of "<var>=<value>\n" lines read from a file
5909 * and ending in a NUL.
5910 * Removes carriage returns, empty lines, comment lines, and converts
5912 * Shortens buffer as needed and pads with NULs. End of buffer is marked
5916 static uint
brcmf_process_nvram_vars(char *varbuf
, uint len
)
5925 findNewline
= false;
5928 for (n
= 0; n
< len
; n
++) {
5931 if (varbuf
[n
] == '\r')
5933 if (findNewline
&& varbuf
[n
] != '\n')
5935 findNewline
= false;
5936 if (varbuf
[n
] == '#') {
5940 if (varbuf
[n
] == '\n') {
5950 buf_len
= dp
- varbuf
;
5952 while (dp
< varbuf
+ n
)
5958 static int brcmf_sdbrcm_download_nvram(struct brcmf_bus
*bus
)
5961 char *memblock
= NULL
;
5965 bus
->nv_name
= BCM4329_NV_NAME
;
5966 ret
= request_firmware(&bus
->firmware
, bus
->nv_name
,
5967 &gInstance
->func
[2]->dev
);
5969 DHD_ERROR(("%s: Fail to request nvram %d\n", __func__
, ret
));
5974 memblock
= kmalloc(MEMBLOCK
, GFP_ATOMIC
);
5975 if (memblock
== NULL
) {
5976 DHD_ERROR(("%s: Failed to allocate memory %d bytes\n",
5977 __func__
, MEMBLOCK
));
5982 len
= brcmf_sdbrcm_get_image(memblock
, MEMBLOCK
, bus
);
5984 if (len
> 0 && len
< MEMBLOCK
) {
5985 bufp
= (char *)memblock
;
5987 len
= brcmf_process_nvram_vars(bufp
, len
);
5991 ret
= brcmf_sdbrcm_downloadvars(bus
, memblock
, len
+ 1);
5993 DHD_ERROR(("%s: error downloading vars: %d\n",
5996 DHD_ERROR(("%s: error reading nvram file: %d\n",
6004 release_firmware(bus
->firmware
);
6010 static int _brcmf_sdbrcm_download_firmware(struct brcmf_bus
*bus
)
6014 /* Keep arm in reset */
6015 if (brcmf_sdbrcm_download_state(bus
, true)) {
6016 DHD_ERROR(("%s: error placing ARM core in reset\n", __func__
));
6020 /* External image takes precedence if specified */
6021 if (brcmf_sdbrcm_download_code_file(bus
)) {
6022 DHD_ERROR(("%s: dongle image file download failed\n",
6027 /* EXAMPLE: nvram_array */
6028 /* If a valid nvram_arry is specified as above, it can be passed
6030 /* dhd_bus_set_nvram_params(bus, (char *)&nvram_array); */
6032 /* External nvram takes precedence if specified */
6033 if (brcmf_sdbrcm_download_nvram(bus
)) {
6034 DHD_ERROR(("%s: dongle nvram file download failed\n",
6038 /* Take arm out of reset */
6039 if (brcmf_sdbrcm_download_state(bus
, false)) {
6040 DHD_ERROR(("%s: error getting out of ARM core reset\n",
6053 brcmf_sdbrcm_send_buf(struct brcmf_bus
*bus
, u32 addr
, uint fn
, uint flags
,
6054 u8
*buf
, uint nbytes
, struct sk_buff
*pkt
,
6055 void (*complete
)(void *handle
, int status
,
6059 return brcmf_sdcard_send_buf
6060 (bus
->card
, addr
, fn
, flags
, buf
, nbytes
, pkt
, complete
,
6064 int brcmf_bus_devreset(struct brcmf_pub
*drvr
, u8 flag
)
6067 struct brcmf_bus
*bus
;
6072 brcmf_sdbrcm_wd_timer(bus
, 0);
6073 if (!bus
->drvr
->dongle_reset
) {
6074 /* Expect app to have torn down any
6075 connection before calling */
6076 /* Stop the bus, disable F2 */
6077 brcmf_sdbrcm_bus_stop(bus
, false);
6079 /* Clean tx/rx buffer pointers,
6080 detach from the dongle */
6081 brcmf_sdbrcm_release_dongle(bus
);
6083 bus
->drvr
->dongle_reset
= true;
6084 bus
->drvr
->up
= false;
6086 DHD_TRACE(("%s: WLAN OFF DONE\n", __func__
));
6087 /* App can now remove power from device */
6091 /* App must have restored power to device before calling */
6093 DHD_TRACE(("\n\n%s: == WLAN ON ==\n", __func__
));
6095 if (bus
->drvr
->dongle_reset
) {
6098 /* Attempt to re-attach & download */
6099 if (brcmf_sdbrcm_probe_attach(bus
, bus
->card
,
6102 /* Attempt to download binary to the dongle */
6103 if (brcmf_sdbrcm_probe_init(bus
, bus
->card
)) {
6104 /* Re-init bus, enable F2 transfer */
6105 brcmf_sdbrcm_bus_init(bus
->drvr
, false);
6107 bus
->drvr
->dongle_reset
= false;
6108 bus
->drvr
->up
= true;
6110 DHD_TRACE(("%s: WLAN ON DONE\n",
6117 bcmerror
= -EISCONN
;
6118 DHD_ERROR(("%s: Set DEVRESET=false invoked when device "
6119 "is on\n", __func__
));
6122 brcmf_sdbrcm_wd_timer(bus
, brcmf_watchdog_ms
);
6128 brcmf_sdbrcm_chip_recognition(struct brcmf_sdio_card
*card
,
6129 struct chip_info
*ci
, u32 regs
)
6135 * Chipid is assume to be at offset 0 from regs arg
6136 * For different chiptypes or old sdio hosts w/o chipcommon,
6137 * other ways of recognition should be added here.
6139 ci
->cccorebase
= regs
;
6140 regdata
= brcmf_sdcard_reg_read(card
,
6141 CORE_CC_REG(ci
->cccorebase
, chipid
), 4);
6142 ci
->chip
= regdata
& CID_ID_MASK
;
6143 ci
->chiprev
= (regdata
& CID_REV_MASK
) >> CID_REV_SHIFT
;
6145 DHD_INFO(("%s: chipid=0x%x chiprev=%d\n",
6146 __func__
, ci
->chip
, ci
->chiprev
));
6148 /* Address of cores for new chips should be added here */
6150 case BCM4329_CHIP_ID
:
6151 ci
->buscorebase
= BCM4329_CORE_BUS_BASE
;
6152 ci
->ramcorebase
= BCM4329_CORE_SOCRAM_BASE
;
6153 ci
->armcorebase
= BCM4329_CORE_ARM_BASE
;
6154 ci
->ramsize
= BCM4329_RAMSIZE
;
6157 DHD_ERROR(("%s: chipid 0x%x is not supported\n",
6158 __func__
, ci
->chip
));
6162 regdata
= brcmf_sdcard_reg_read(card
,
6163 CORE_SB(ci
->cccorebase
, sbidhigh
), 4);
6164 ci
->ccrev
= SBCOREREV(regdata
);
6166 regdata
= brcmf_sdcard_reg_read(card
,
6167 CORE_CC_REG(ci
->cccorebase
, pmucapabilities
), 4);
6168 ci
->pmurev
= regdata
& PCAP_REV_MASK
;
6170 regdata
= brcmf_sdcard_reg_read(card
,
6171 CORE_SB(ci
->buscorebase
, sbidhigh
), 4);
6172 ci
->buscorerev
= SBCOREREV(regdata
);
6173 ci
->buscoretype
= (regdata
& SBIDH_CC_MASK
) >> SBIDH_CC_SHIFT
;
6175 DHD_INFO(("%s: ccrev=%d, pmurev=%d, buscore rev/type=%d/0x%x\n",
6176 __func__
, ci
->ccrev
, ci
->pmurev
,
6177 ci
->buscorerev
, ci
->buscoretype
));
6179 /* get chipcommon capabilites */
6180 ci
->cccaps
= brcmf_sdcard_reg_read(card
,
6181 CORE_CC_REG(ci
->cccorebase
, capabilities
), 4);
6187 brcmf_sdbrcm_chip_disablecore(struct brcmf_sdio_card
*card
, u32 corebase
)
6191 regdata
= brcmf_sdcard_reg_read(card
,
6192 CORE_SB(corebase
, sbtmstatelow
), 4);
6193 if (regdata
& SBTML_RESET
)
6196 regdata
= brcmf_sdcard_reg_read(card
,
6197 CORE_SB(corebase
, sbtmstatelow
), 4);
6198 if ((regdata
& (SICF_CLOCK_EN
<< SBTML_SICF_SHIFT
)) != 0) {
6200 * set target reject and spin until busy is clear
6201 * (preserve core-specific bits)
6203 regdata
= brcmf_sdcard_reg_read(card
,
6204 CORE_SB(corebase
, sbtmstatelow
), 4);
6205 brcmf_sdcard_reg_write(card
, CORE_SB(corebase
, sbtmstatelow
), 4,
6206 regdata
| SBTML_REJ
);
6208 regdata
= brcmf_sdcard_reg_read(card
,
6209 CORE_SB(corebase
, sbtmstatelow
), 4);
6211 SPINWAIT((brcmf_sdcard_reg_read(card
,
6212 CORE_SB(corebase
, sbtmstatehigh
), 4) &
6213 SBTMH_BUSY
), 100000);
6215 regdata
= brcmf_sdcard_reg_read(card
,
6216 CORE_SB(corebase
, sbtmstatehigh
), 4);
6217 if (regdata
& SBTMH_BUSY
)
6218 DHD_ERROR(("%s: ARM core still busy\n", __func__
));
6220 regdata
= brcmf_sdcard_reg_read(card
,
6221 CORE_SB(corebase
, sbidlow
), 4);
6222 if (regdata
& SBIDL_INIT
) {
6223 regdata
= brcmf_sdcard_reg_read(card
,
6224 CORE_SB(corebase
, sbimstate
), 4) |
6226 brcmf_sdcard_reg_write(card
,
6227 CORE_SB(corebase
, sbimstate
), 4,
6229 regdata
= brcmf_sdcard_reg_read(card
,
6230 CORE_SB(corebase
, sbimstate
), 4);
6232 SPINWAIT((brcmf_sdcard_reg_read(card
,
6233 CORE_SB(corebase
, sbimstate
), 4) &
6237 /* set reset and reject while enabling the clocks */
6238 brcmf_sdcard_reg_write(card
,
6239 CORE_SB(corebase
, sbtmstatelow
), 4,
6240 (((SICF_FGC
| SICF_CLOCK_EN
) << SBTML_SICF_SHIFT
) |
6241 SBTML_REJ
| SBTML_RESET
));
6242 regdata
= brcmf_sdcard_reg_read(card
,
6243 CORE_SB(corebase
, sbtmstatelow
), 4);
6246 /* clear the initiator reject bit */
6247 regdata
= brcmf_sdcard_reg_read(card
,
6248 CORE_SB(corebase
, sbidlow
), 4);
6249 if (regdata
& SBIDL_INIT
) {
6250 regdata
= brcmf_sdcard_reg_read(card
,
6251 CORE_SB(corebase
, sbimstate
), 4) &
6253 brcmf_sdcard_reg_write(card
,
6254 CORE_SB(corebase
, sbimstate
), 4,
6259 /* leave reset and reject asserted */
6260 brcmf_sdcard_reg_write(card
, CORE_SB(corebase
, sbtmstatelow
), 4,
6261 (SBTML_REJ
| SBTML_RESET
));
6266 brcmf_sdbrcm_chip_attach(struct brcmf_bus
*bus
, u32 regs
)
6268 struct chip_info
*ci
;
6272 DHD_TRACE(("%s: Enter\n", __func__
));
6274 /* alloc chip_info_t */
6275 ci
= kmalloc(sizeof(struct chip_info
), GFP_ATOMIC
);
6277 DHD_ERROR(("%s: malloc failed!\n", __func__
));
6281 memset((unsigned char *)ci
, 0, sizeof(struct chip_info
));
6283 /* bus/core/clk setup for register access */
6284 /* Try forcing SDIO core to do ALPAvail request only */
6285 clkset
= SBSDIO_FORCE_HW_CLKREQ_OFF
| SBSDIO_ALP_AVAIL_REQ
;
6286 brcmf_sdcard_cfg_write(bus
->card
, SDIO_FUNC_1
, SBSDIO_FUNC1_CHIPCLKCSR
,
6289 DHD_ERROR(("%s: error writing for HT off\n", __func__
));
6293 /* If register supported, wait for ALPAvail and then force ALP */
6294 /* This may take up to 15 milliseconds */
6295 clkval
= brcmf_sdcard_cfg_read(bus
->card
, SDIO_FUNC_1
,
6296 SBSDIO_FUNC1_CHIPCLKCSR
, NULL
);
6297 if ((clkval
& ~SBSDIO_AVBITS
) == clkset
) {
6299 brcmf_sdcard_cfg_read(bus
->card
, SDIO_FUNC_1
,
6300 SBSDIO_FUNC1_CHIPCLKCSR
,
6302 !SBSDIO_ALPAV(clkval
)),
6303 PMU_MAX_TRANSITION_DLY
);
6304 if (!SBSDIO_ALPAV(clkval
)) {
6305 DHD_ERROR(("%s: timeout on ALPAV wait, clkval 0x%02x\n",
6310 clkset
= SBSDIO_FORCE_HW_CLKREQ_OFF
|
6312 brcmf_sdcard_cfg_write(bus
->card
, SDIO_FUNC_1
,
6313 SBSDIO_FUNC1_CHIPCLKCSR
,
6317 DHD_ERROR(("%s: ChipClkCSR access: wrote 0x%02x read 0x%02x\n",
6318 __func__
, clkset
, clkval
));
6323 /* Also, disable the extra SDIO pull-ups */
6324 brcmf_sdcard_cfg_write(bus
->card
, SDIO_FUNC_1
, SBSDIO_FUNC1_SDIOPULLUP
,
6327 err
= brcmf_sdbrcm_chip_recognition(bus
->card
, ci
, regs
);
6332 * Make sure any on-chip ARM is off (in case strapping is wrong),
6333 * or downloaded code was already running.
6335 brcmf_sdbrcm_chip_disablecore(bus
->card
, ci
->armcorebase
);
6337 brcmf_sdcard_reg_write(bus
->card
,
6338 CORE_CC_REG(ci
->cccorebase
, gpiopullup
), 4, 0);
6339 brcmf_sdcard_reg_write(bus
->card
,
6340 CORE_CC_REG(ci
->cccorebase
, gpiopulldown
), 4, 0);
6342 /* Disable F2 to clear any intermediate frame state on the dongle */
6343 brcmf_sdcard_cfg_write(bus
->card
, SDIO_FUNC_0
, SDIO_CCCR_IOEx
,
6344 SDIO_FUNC_ENABLE_1
, NULL
);
6346 /* WAR: cmd52 backplane read so core HW will drop ALPReq */
6347 clkval
= brcmf_sdcard_cfg_read(bus
->card
, SDIO_FUNC_1
,
6350 /* Done with backplane-dependent accesses, can drop clock... */
6351 brcmf_sdcard_cfg_write(bus
->card
, SDIO_FUNC_1
, SBSDIO_FUNC1_CHIPCLKCSR
,
6363 brcmf_sdbrcm_chip_resetcore(struct brcmf_sdio_card
*card
, u32 corebase
)
6368 * Must do the disable sequence first to work for
6369 * arbitrary current core state.
6371 brcmf_sdbrcm_chip_disablecore(card
, corebase
);
6374 * Now do the initialization sequence.
6375 * set reset while enabling the clock and
6376 * forcing them on throughout the core
6378 brcmf_sdcard_reg_write(card
, CORE_SB(corebase
, sbtmstatelow
), 4,
6379 ((SICF_FGC
| SICF_CLOCK_EN
) << SBTML_SICF_SHIFT
) |
6383 regdata
= brcmf_sdcard_reg_read(card
, CORE_SB(corebase
, sbtmstatehigh
),
6385 if (regdata
& SBTMH_SERR
)
6386 brcmf_sdcard_reg_write(card
, CORE_SB(corebase
, sbtmstatehigh
),
6389 regdata
= brcmf_sdcard_reg_read(card
, CORE_SB(corebase
, sbimstate
), 4);
6390 if (regdata
& (SBIM_IBE
| SBIM_TO
))
6391 brcmf_sdcard_reg_write(card
, CORE_SB(corebase
, sbimstate
), 4,
6392 regdata
& ~(SBIM_IBE
| SBIM_TO
));
6394 /* clear reset and allow it to propagate throughout the core */
6395 brcmf_sdcard_reg_write(card
, CORE_SB(corebase
, sbtmstatelow
), 4,
6396 (SICF_FGC
<< SBTML_SICF_SHIFT
) |
6397 (SICF_CLOCK_EN
<< SBTML_SICF_SHIFT
));
6400 /* leave clock enabled */
6401 brcmf_sdcard_reg_write(card
, CORE_SB(corebase
, sbtmstatelow
), 4,
6402 (SICF_CLOCK_EN
<< SBTML_SICF_SHIFT
));
6406 /* SDIO Pad drive strength to select value mappings */
6407 struct sdiod_drive_str
{
6408 u8 strength
; /* Pad Drive Strength in mA */
6409 u8 sel
; /* Chip-specific select value */
6412 /* SDIO Drive Strength to sel value table for PMU Rev 1 */
6413 static const struct sdiod_drive_str sdiod_drive_strength_tab1
[] = {
6421 /* SDIO Drive Strength to sel value table for PMU Rev 2, 3 */
6422 static const struct sdiod_drive_str sdiod_drive_strength_tab2
[] = {
6433 /* SDIO Drive Strength to sel value table for PMU Rev 8 (1.8V) */
6434 static const struct sdiod_drive_str sdiod_drive_strength_tab3
[] = {
6446 #define SDIOD_DRVSTR_KEY(chip, pmu) (((chip) << 16) | (pmu))
6449 brcmf_sdbrcm_sdiod_drive_strength_init(struct brcmf_bus
*bus
, u32 drivestrength
) {
6450 struct sdiod_drive_str
*str_tab
= NULL
;
6455 if (!(bus
->ci
->cccaps
& CC_CAP_PMU
))
6458 switch (SDIOD_DRVSTR_KEY(bus
->ci
->chip
, bus
->ci
->pmurev
)) {
6459 case SDIOD_DRVSTR_KEY(BCM4325_CHIP_ID
, 1):
6460 str_tab
= (struct sdiod_drive_str
*)&sdiod_drive_strength_tab1
;
6461 str_mask
= 0x30000000;
6464 case SDIOD_DRVSTR_KEY(BCM4325_CHIP_ID
, 2):
6465 case SDIOD_DRVSTR_KEY(BCM4325_CHIP_ID
, 3):
6466 str_tab
= (struct sdiod_drive_str
*)&sdiod_drive_strength_tab2
;
6467 str_mask
= 0x00003800;
6470 case SDIOD_DRVSTR_KEY(BCM4336_CHIP_ID
, 8):
6471 str_tab
= (struct sdiod_drive_str
*)&sdiod_drive_strength_tab3
;
6472 str_mask
= 0x00003800;
6476 DHD_ERROR(("No SDIO Drive strength init"
6477 "done for chip %s rev %d pmurev %d\n",
6478 brcmu_chipname(bus
->ci
->chip
, chn
, 8),
6479 bus
->ci
->chiprev
, bus
->ci
->pmurev
));
6483 if (str_tab
!= NULL
) {
6484 u32 drivestrength_sel
= 0;
6488 for (i
= 0; str_tab
[i
].strength
!= 0; i
++) {
6489 if (drivestrength
>= str_tab
[i
].strength
) {
6490 drivestrength_sel
= str_tab
[i
].sel
;
6495 brcmf_sdcard_reg_write(bus
->card
,
6496 CORE_CC_REG(bus
->ci
->cccorebase
, chipcontrol_addr
),
6498 cc_data_temp
= brcmf_sdcard_reg_read(bus
->card
,
6499 CORE_CC_REG(bus
->ci
->cccorebase
, chipcontrol_addr
), 4);
6500 cc_data_temp
&= ~str_mask
;
6501 drivestrength_sel
<<= str_shift
;
6502 cc_data_temp
|= drivestrength_sel
;
6503 brcmf_sdcard_reg_write(bus
->card
,
6504 CORE_CC_REG(bus
->ci
->cccorebase
, chipcontrol_addr
),
6507 DHD_INFO(("SDIO: %dmA drive strength selected, set to 0x%08x\n",
6508 drivestrength
, cc_data_temp
));
6513 brcmf_sdbrcm_chip_detach(struct brcmf_bus
*bus
)
6515 DHD_TRACE(("%s: Enter\n", __func__
));
6522 brcmf_sdbrcm_wait_for_event(struct brcmf_bus
*bus
, bool *lockvar
)
6524 brcmf_sdbrcm_sdunlock(bus
);
6525 wait_event_interruptible_timeout(bus
->ctrl_wait
,
6526 (*lockvar
== false), HZ
* 2);
6527 brcmf_sdbrcm_sdlock(bus
);
6532 brcmf_sdbrcm_wait_event_wakeup(struct brcmf_bus
*bus
)
6534 if (waitqueue_active(&bus
->ctrl_wait
))
6535 wake_up_interruptible(&bus
->ctrl_wait
);
6540 brcmf_sdbrcm_watchdog_thread(void *data
)
6542 struct brcmf_bus
*bus
= (struct brcmf_bus
*)data
;
6544 /* This thread doesn't need any user-level access,
6545 * so get rid of all our resources
6547 if (brcmf_watchdog_prio
> 0) {
6548 struct sched_param param
;
6549 param
.sched_priority
= (brcmf_watchdog_prio
< MAX_RT_PRIO
) ?
6550 brcmf_watchdog_prio
: (MAX_RT_PRIO
- 1);
6551 sched_setscheduler(current
, SCHED_FIFO
, ¶m
);
6554 allow_signal(SIGTERM
);
6555 /* Run until signal received */
6557 if (kthread_should_stop())
6559 if (!wait_for_completion_interruptible(&bus
->watchdog_wait
)) {
6560 if (bus
->drvr
->dongle_reset
== false)
6561 brcmf_sdbrcm_bus_watchdog(bus
->drvr
);
6562 /* Count the tick for reference */
6563 bus
->drvr
->tickcnt
++;
6571 brcmf_sdbrcm_watchdog(unsigned long data
)
6573 struct brcmf_bus
*bus
= (struct brcmf_bus
*)data
;
6575 if (brcmf_watchdog_prio
>= 0) {
6576 if (bus
->watchdog_tsk
)
6577 complete(&bus
->watchdog_wait
);
6581 brcmf_sdbrcm_bus_watchdog(bus
->drvr
);
6583 /* Count the tick for reference */
6584 bus
->drvr
->tickcnt
++;
6587 /* Reschedule the watchdog */
6588 if (bus
->wd_timer_valid
)
6589 mod_timer(&bus
->timer
, jiffies
+ brcmf_watchdog_ms
* HZ
/ 1000);
6593 brcmf_sdbrcm_wd_timer(struct brcmf_bus
*bus
, uint wdtick
)
6595 static uint save_ms
;
6597 /* don't start the wd until fw is loaded */
6598 if (bus
->drvr
->busstate
== DHD_BUS_DOWN
)
6601 /* Totally stop the timer */
6602 if (!wdtick
&& bus
->wd_timer_valid
== true) {
6603 del_timer_sync(&bus
->timer
);
6604 bus
->wd_timer_valid
= false;
6610 brcmf_watchdog_ms
= (uint
) wdtick
;
6612 if (save_ms
!= brcmf_watchdog_ms
) {
6613 if (bus
->wd_timer_valid
== true)
6614 /* Stop timer and restart at new value */
6615 del_timer_sync(&bus
->timer
);
6617 /* Create timer again when watchdog period is
6618 dynamically changed or in the first instance
6620 bus
->timer
.expires
=
6621 jiffies
+ brcmf_watchdog_ms
* HZ
/ 1000;
6622 add_timer(&bus
->timer
);
6625 /* Re arm the timer, at last watchdog period */
6626 mod_timer(&bus
->timer
,
6627 jiffies
+ brcmf_watchdog_ms
* HZ
/ 1000);
6630 bus
->wd_timer_valid
= true;
6635 static int brcmf_sdbrcm_dpc_thread(void *data
)
6637 struct brcmf_bus
*bus
= (struct brcmf_bus
*) data
;
6639 /* This thread doesn't need any user-level access,
6640 * so get rid of all our resources
6642 if (brcmf_dpc_prio
> 0) {
6643 struct sched_param param
;
6644 param
.sched_priority
= (brcmf_dpc_prio
< MAX_RT_PRIO
) ?
6645 brcmf_dpc_prio
: (MAX_RT_PRIO
- 1);
6646 sched_setscheduler(current
, SCHED_FIFO
, ¶m
);
6649 allow_signal(SIGTERM
);
6650 /* Run until signal received */
6652 if (kthread_should_stop())
6654 if (!wait_for_completion_interruptible(&bus
->dpc_wait
)) {
6655 /* Call bus dpc unless it indicated down
6656 (then clean stop) */
6657 if (bus
->drvr
->busstate
!= DHD_BUS_DOWN
) {
6658 if (brcmf_sdbrcm_dpc(bus
))
6659 complete(&bus
->dpc_wait
);
6661 brcmf_sdbrcm_bus_stop(bus
, true);
6669 static void brcmf_sdbrcm_dpc_tasklet(unsigned long data
)
6671 struct brcmf_bus
*bus
= (struct brcmf_bus
*) data
;
6673 /* Call bus dpc unless it indicated down (then clean stop) */
6674 if (bus
->drvr
->busstate
!= DHD_BUS_DOWN
) {
6675 if (brcmf_sdbrcm_dpc(bus
))
6676 tasklet_schedule(&bus
->tasklet
);
6678 brcmf_sdbrcm_bus_stop(bus
, true);
6681 static void brcmf_sdbrcm_sched_dpc(struct brcmf_bus
*bus
)
6684 complete(&bus
->dpc_wait
);
6688 tasklet_schedule(&bus
->tasklet
);
6691 static void brcmf_sdbrcm_sdlock(struct brcmf_bus
*bus
)
6693 if (bus
->threads_only
)
6696 spin_lock_bh(&bus
->sdlock
);
6699 static void brcmf_sdbrcm_sdunlock(struct brcmf_bus
*bus
)
6701 if (bus
->threads_only
)
6704 spin_unlock_bh(&bus
->sdlock
);
6707 static int brcmf_sdbrcm_get_image(char *buf
, int len
, struct brcmf_bus
*bus
)
6709 if (bus
->firmware
->size
< bus
->fw_ptr
+ len
)
6710 len
= bus
->firmware
->size
- bus
->fw_ptr
;
6712 memcpy(buf
, &bus
->firmware
->data
[bus
->fw_ptr
], len
);
6717 MODULE_FIRMWARE(BCM4329_FW_NAME
);
6718 MODULE_FIRMWARE(BCM4329_NV_NAME
);