Merge remote-tracking branch 'remotes/aosp/android-3.0' into develop-3.0
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / bcm4329 / dhd_sdio.c
index e9093e81062442820313da200485f209af1e71b6..5459661c6a9b15e24c030dd2a38be9517fc29a5a 100644 (file)
@@ -428,6 +428,7 @@ static void dhdsdio_sdtest_set(dhd_bus_t *bus, bool start);
 
 #ifdef DHD_DEBUG_TRAP
 static int dhdsdio_checkdied(dhd_bus_t *bus, uint8 *data, uint size);
+static int dhdsdio_mem_dump(dhd_bus_t *bus);
 #endif /* DHD_DEBUG_TRAP */
 static int dhdsdio_download_state(dhd_bus_t *bus, bool enter);
 
@@ -1845,6 +1846,11 @@ dhdsdio_checkdied(dhd_bus_t *bus, uint8 *data, uint size)
                DHD_ERROR(("%s: %s\n", __FUNCTION__, strbuf.origbuf));
        }
 
+       if (sdpcm_shared.flags & SDPCM_SHARED_TRAP) {
+                       /* Mem dump to a file on device */
+                       dhdsdio_mem_dump(bus);
+       }
+
 done:
        if (mbuffer)
                MFREE(bus->dhd->osh, mbuffer, msize);
@@ -1853,6 +1859,60 @@ done:
 
        return bcmerror;
 }
+
+static int
+dhdsdio_mem_dump(dhd_bus_t *bus)
+{
+       int ret = 0;
+       int size; /* Full mem size */
+       int start = 0; /* Start address */
+       int read_size = 0; /* Read size of each iteration */
+       uint8 *buf = NULL, *databuf = NULL;
+
+       /* Get full mem size */
+       size = bus->ramsize;
+       buf = MALLOC(bus->dhd->osh, size);
+       if (!buf) {
+               printf("%s: Out of memory (%d bytes)\n", __FUNCTION__, size);
+               return -1;
+       }
+
+       /* Read mem content */
+       printf("Dump dongle memory");
+       databuf = buf;
+       while (size)
+       {
+               read_size = MIN(MEMBLOCK, size);
+               if ((ret = dhdsdio_membytes(bus, FALSE, start, databuf, read_size)))
+               {
+                       printf("%s: Error membytes %d\n", __FUNCTION__, ret);
+                       if (buf) {
+                               MFREE(bus->dhd->osh, buf, size);
+                       }
+                       return -1;
+               }
+               printf(".");
+
+               /* Decrement size and increment start address */
+               size -= read_size;
+               start += read_size;
+               databuf += read_size;
+       }
+       printf("Done\n");
+
+#ifdef DHD_DEBUG
+       /* free buf before return !!! */
+       if (write_to_file(bus->dhd, buf, bus->ramsize))
+       {
+               printf("%s: Error writing to files\n", __FUNCTION__);
+               return -1;
+       }
+       /* buf free handled in write_to_file, not here */
+#else
+       MFREE(bus->dhd->osh, buf, size);
+#endif
+       return 0;
+}
 #endif /* DHD_DEBUG_TRAP */
 
 #ifdef DHD_DEBUG