Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / brcm80211 / brcmfmac / dhd_sdio.c
index a5354e731eaa0034bb449201ba9a54b902669fe0..4ff2d3c52ee60bb2227b4f1dfdd322e05219b135 100644 (file)
@@ -94,6 +94,7 @@ struct rte_console {
 
 #include "dhd_bus.h"
 #include "dhd_dbg.h"
+#include "tracepoint.h"
 
 #define TXQLEN         2048    /* bulk tx queue length */
 #define TXHI           (TXQLEN - 256)  /* turn on flow control above TXHI */
@@ -675,7 +676,7 @@ static int brcmf_sdbrcm_htclk(struct brcmf_sdio *bus, bool on, bool pendok)
        u8 clkctl, clkreq, devctl;
        unsigned long timeout;
 
-       brcmf_dbg(TRACE, "Enter\n");
+       brcmf_dbg(SDIO, "Enter\n");
 
        clkctl = 0;
 
@@ -713,7 +714,7 @@ static int brcmf_sdbrcm_htclk(struct brcmf_sdio *bus, bool on, bool pendok)
                        devctl |= SBSDIO_DEVCTL_CA_INT_ONLY;
                        brcmf_sdio_regwb(bus->sdiodev, SBSDIO_DEVICE_CTL,
                                         devctl, &err);
-                       brcmf_dbg(INFO, "CLKCTL: set PENDING\n");
+                       brcmf_dbg(SDIO, "CLKCTL: set PENDING\n");
                        bus->clkstate = CLK_PENDING;
 
                        return 0;
@@ -750,7 +751,7 @@ static int brcmf_sdbrcm_htclk(struct brcmf_sdio *bus, bool on, bool pendok)
 
                /* Mark clock available */
                bus->clkstate = CLK_AVAIL;
-               brcmf_dbg(INFO, "CLKCTL: turned ON\n");
+               brcmf_dbg(SDIO, "CLKCTL: turned ON\n");
 
 #if defined(DEBUG)
                if (!bus->alp_only) {
@@ -775,7 +776,7 @@ static int brcmf_sdbrcm_htclk(struct brcmf_sdio *bus, bool on, bool pendok)
                bus->clkstate = CLK_SDONLY;
                brcmf_sdio_regwb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR,
                                 clkreq, &err);
-               brcmf_dbg(INFO, "CLKCTL: turned OFF\n");
+               brcmf_dbg(SDIO, "CLKCTL: turned OFF\n");
                if (err) {
                        brcmf_err("Failed access turning clock off: %d\n",
                                  err);
@@ -788,7 +789,7 @@ static int brcmf_sdbrcm_htclk(struct brcmf_sdio *bus, bool on, bool pendok)
 /* Change idle/active SD state */
 static int brcmf_sdbrcm_sdclk(struct brcmf_sdio *bus, bool on)
 {
-       brcmf_dbg(TRACE, "Enter\n");
+       brcmf_dbg(SDIO, "Enter\n");
 
        if (on)
                bus->clkstate = CLK_SDONLY;
@@ -805,7 +806,7 @@ static int brcmf_sdbrcm_clkctl(struct brcmf_sdio *bus, uint target, bool pendok)
        uint oldstate = bus->clkstate;
 #endif                         /* DEBUG */
 
-       brcmf_dbg(TRACE, "Enter\n");
+       brcmf_dbg(SDIO, "Enter\n");
 
        /* Early exit if we're already there */
        if (bus->clkstate == target) {
@@ -849,7 +850,7 @@ static int brcmf_sdbrcm_clkctl(struct brcmf_sdio *bus, uint target, bool pendok)
                break;
        }
 #ifdef DEBUG
-       brcmf_dbg(INFO, "%d -> %d\n", oldstate, bus->clkstate);
+       brcmf_dbg(SDIO, "%d -> %d\n", oldstate, bus->clkstate);
 #endif                         /* DEBUG */
 
        return 0;
@@ -862,7 +863,7 @@ static u32 brcmf_sdbrcm_hostmail(struct brcmf_sdio *bus)
        u8 fcbits;
        int ret;
 
-       brcmf_dbg(TRACE, "Enter\n");
+       brcmf_dbg(SDIO, "Enter\n");
 
        /* Read mailbox data and ack that we did so */
        ret = r_sdreg32(bus, &hmb_data,
@@ -875,7 +876,7 @@ static u32 brcmf_sdbrcm_hostmail(struct brcmf_sdio *bus)
 
        /* Dongle recomposed rx frames, accept them again */
        if (hmb_data & HMB_DATA_NAKHANDLED) {
-               brcmf_dbg(INFO, "Dongle reports NAK handled, expect rtx of %d\n",
+               brcmf_dbg(SDIO, "Dongle reports NAK handled, expect rtx of %d\n",
                          bus->rx_seq);
                if (!bus->rxskip)
                        brcmf_err("unexpected NAKHANDLED!\n");
@@ -896,7 +897,7 @@ static u32 brcmf_sdbrcm_hostmail(struct brcmf_sdio *bus)
                                  "expecting %d\n",
                                  bus->sdpcm_ver, SDPCM_PROT_VERSION);
                else
-                       brcmf_dbg(INFO, "Dongle ready, protocol version %d\n",
+                       brcmf_dbg(SDIO, "Dongle ready, protocol version %d\n",
                                  bus->sdpcm_ver);
        }
 
@@ -970,7 +971,7 @@ static void brcmf_sdbrcm_rxfail(struct brcmf_sdio *bus, bool abort, bool rtx)
        if (!retries)
                brcmf_err("count never zeroed: last 0x%04x\n", lastrbc);
        else
-               brcmf_dbg(INFO, "flush took %d iterations\n", 0xffff - retries);
+               brcmf_dbg(SDIO, "flush took %d iterations\n", 0xffff - retries);
 
        if (rtx) {
                bus->sdcnt.rxrtx++;
@@ -1173,7 +1174,7 @@ static u8 brcmf_sdbrcm_rxglom(struct brcmf_sdio *bus, u8 rxseq)
        /* If packets, issue read(s) and send up packet chain */
        /* Return sequence numbers consumed? */
 
-       brcmf_dbg(TRACE, "start: glomd %p glom %p\n",
+       brcmf_dbg(SDIO, "start: glomd %p glom %p\n",
                  bus->glomd, skb_peek(&bus->glom));
 
        /* If there's a descriptor, generate the packet chain */
@@ -2117,7 +2118,7 @@ static void brcmf_sdbrcm_dpc(struct brcmf_sdio *bus)
                        bus->sdiodev->bus_if->state = BRCMF_BUS_DOWN;
                }
 
-               brcmf_dbg(INFO, "DPC: PENDING, devctl 0x%02x clkctl 0x%02x\n",
+               brcmf_dbg(SDIO, "DPC: PENDING, devctl 0x%02x clkctl 0x%02x\n",
                          devctl, clkctl);
 
                if (SBSDIO_HTAV(clkctl)) {
@@ -2387,7 +2388,7 @@ brcmf_sdbrcm_membytes(struct brcmf_sdio *bus, bool write, u32 address, u8 *data,
 
        /* Do the transfer(s) */
        while (size) {
-               brcmf_dbg(INFO, "%s %d bytes at offset 0x%08x in window 0x%08x\n",
+               brcmf_dbg(SDIO, "%s %d bytes at offset 0x%08x in window 0x%08x\n",
                          write ? "write" : "read", dsize,
                          sdaddr, address & SBSDIO_SBWINDOW_MASK);
                bcmerror = brcmf_sdcard_rwdata(bus->sdiodev, write,
@@ -2620,10 +2621,10 @@ brcmf_sdbrcm_bus_txctl(struct device *dev, unsigned char *msg, uint msglen)
                                                 msecs_to_jiffies(2000));
 
                if (!bus->ctrl_frame_stat) {
-                       brcmf_dbg(INFO, "ctrl_frame_stat == false\n");
+                       brcmf_dbg(SDIO, "ctrl_frame_stat == false\n");
                        ret = 0;
                } else {
-                       brcmf_dbg(INFO, "ctrl_frame_stat == true\n");
+                       brcmf_dbg(SDIO, "ctrl_frame_stat == true\n");
                        ret = -1;
                }
        }
@@ -2694,7 +2695,7 @@ static int brcmf_sdio_readshared(struct brcmf_sdio *bus,
 
        addr = le32_to_cpu(addr_le);
 
-       brcmf_dbg(INFO, "sdpcm_shared address 0x%08X\n", addr);
+       brcmf_dbg(SDIO, "sdpcm_shared address 0x%08X\n", addr);
 
        /*
         * Check if addr is valid.
@@ -2721,8 +2722,8 @@ static int brcmf_sdio_readshared(struct brcmf_sdio *bus,
        sh->console_addr = le32_to_cpu(sh_le.console_addr);
        sh->msgtrace_addr = le32_to_cpu(sh_le.msgtrace_addr);
 
-       if ((sh->flags & SDPCM_SHARED_VERSION_MASK) != SDPCM_SHARED_VERSION) {
-               brcmf_err("sdpcm_shared version mismatch: dhd %d dongle %d\n",
+       if ((sh->flags & SDPCM_SHARED_VERSION_MASK) > SDPCM_SHARED_VERSION) {
+               brcmf_err("sdpcm shared version unsupported: dhd %d dongle %d\n",
                          SDPCM_SHARED_VERSION,
                          sh->flags & SDPCM_SHARED_VERSION_MASK);
                return -EPROTO;
@@ -2804,21 +2805,18 @@ static int brcmf_sdio_trap_info(struct brcmf_sdio *bus, struct sdpcm_shared *sh,
        int error, res;
        char buf[350];
        struct brcmf_trap_info tr;
-       int nbytes;
        loff_t pos = 0;
 
-       if ((sh->flags & SDPCM_SHARED_TRAP) == 0)
+       if ((sh->flags & SDPCM_SHARED_TRAP) == 0) {
+               brcmf_dbg(INFO, "no trap in firmware\n");
                return 0;
+       }
 
        error = brcmf_sdbrcm_membytes(bus, false, sh->trap_addr, (u8 *)&tr,
                                      sizeof(struct brcmf_trap_info));
        if (error < 0)
                return error;
 
-       nbytes = brcmf_sdio_dump_console(bus, sh, data, count);
-       if (nbytes < 0)
-               return nbytes;
-
        res = scnprintf(buf, sizeof(buf),
                        "dongle trap info: type 0x%x @ epc 0x%08x\n"
                        "  cpsr 0x%08x spsr 0x%08x sp 0x%08x\n"
@@ -2834,12 +2832,7 @@ static int brcmf_sdio_trap_info(struct brcmf_sdio *bus, struct sdpcm_shared *sh,
                        le32_to_cpu(tr.r4), le32_to_cpu(tr.r5),
                        le32_to_cpu(tr.r6), le32_to_cpu(tr.r7));
 
-       error = simple_read_from_buffer(data+nbytes, count, &pos, buf, res);
-       if (error < 0)
-               return error;
-
-       nbytes += error;
-       return nbytes;
+       return simple_read_from_buffer(data, count, &pos, buf, res);
 }
 
 static int brcmf_sdio_assert_info(struct brcmf_sdio *bus,
@@ -2921,14 +2914,20 @@ static int brcmf_sdbrcm_died_dump(struct brcmf_sdio *bus, char __user *data,
        error = brcmf_sdio_assert_info(bus, &sh, data, count);
        if (error < 0)
                goto done;
-
        nbytes = error;
-       error = brcmf_sdio_trap_info(bus, &sh, data, count);
+
+       error = brcmf_sdio_trap_info(bus, &sh, data+nbytes, count);
+       if (error < 0)
+               goto done;
+       nbytes += error;
+
+       error = brcmf_sdio_dump_console(bus, &sh, data+nbytes, count);
        if (error < 0)
                goto done;
+       nbytes += error;
 
-       error += nbytes;
-       *ppos += error;
+       error = nbytes;
+       *ppos += nbytes;
 done:
        return error;
 }
@@ -3304,15 +3303,15 @@ static int _brcmf_sdbrcm_download_firmware(struct brcmf_sdio *bus)
                goto err;
        }
 
-       /* External image takes precedence if specified */
        if (brcmf_sdbrcm_download_code_file(bus)) {
                brcmf_err("dongle image file download failed\n");
                goto err;
        }
 
-       /* External nvram takes precedence if specified */
-       if (brcmf_sdbrcm_download_nvram(bus))
+       if (brcmf_sdbrcm_download_nvram(bus)) {
                brcmf_err("dongle nvram file download failed\n");
+               goto err;
+       }
 
        /* Take arm out of reset */
        if (brcmf_sdbrcm_download_state(bus, false)) {