瀏覽代碼

brcmfmac: reduce allocations needed during nvram data download

The nvram data is preprocessed before being sent to the device
and just before sending an additional allocation was done that
assured word alignment of the data. This has moved to the
preprocessing step to reduce allocations and subsequent copying
of the nvram data.

Reviewed-by: Franky Lin <frankyl@broadcom.com>
Signed-off-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
Arend van Spriel 13 年之前
父節點
當前提交
6d4ef68086
共有 1 個文件被更改,包括 17 次插入31 次删除
  1. 17 31
      drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c

+ 17 - 31
drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c

@@ -3339,9 +3339,7 @@ brcmf_sdbrcm_bus_rxctl(struct device *dev, unsigned char *msg, uint msglen)
 static int brcmf_sdbrcm_write_vars(struct brcmf_sdio *bus)
 static int brcmf_sdbrcm_write_vars(struct brcmf_sdio *bus)
 {
 {
 	int bcmerror = 0;
 	int bcmerror = 0;
-	u32 varsize;
 	u32 varaddr;
 	u32 varaddr;
-	u8 *vbuffer;
 	u32 varsizew;
 	u32 varsizew;
 	__le32 varsizew_le;
 	__le32 varsizew_le;
 #ifdef DEBUG
 #ifdef DEBUG
@@ -3350,56 +3348,44 @@ static int brcmf_sdbrcm_write_vars(struct brcmf_sdio *bus)
 
 
 	/* Even if there are no vars are to be written, we still
 	/* Even if there are no vars are to be written, we still
 		 need to set the ramsize. */
 		 need to set the ramsize. */
-	varsize = bus->varsz ? roundup(bus->varsz, 4) : 0;
-	varaddr = (bus->ramsize - 4) - varsize;
+	varaddr = (bus->ramsize - 4) - bus->varsz;
 
 
 	if (bus->vars) {
 	if (bus->vars) {
-		vbuffer = kzalloc(varsize, GFP_ATOMIC);
-		if (!vbuffer)
-			return -ENOMEM;
-
-		memcpy(vbuffer, bus->vars, bus->varsz);
-
 		/* Write the vars list */
 		/* Write the vars list */
-		bcmerror =
-		    brcmf_sdbrcm_membytes(bus, true, varaddr, vbuffer, varsize);
+		bcmerror = brcmf_sdbrcm_membytes(bus, true, varaddr,
+						 bus->vars, bus->varsz);
 #ifdef DEBUG
 #ifdef DEBUG
 		/* Verify NVRAM bytes */
 		/* Verify NVRAM bytes */
-		brcmf_dbg(INFO, "Compare NVRAM dl & ul; varsize=%d\n", varsize);
-		nvram_ularray = kmalloc(varsize, GFP_ATOMIC);
-		if (!nvram_ularray) {
-			kfree(vbuffer);
+		brcmf_dbg(INFO, "Compare NVRAM dl & ul; varsize=%d\n",
+			  bus->varsz);
+		nvram_ularray = kmalloc(bus->varsz, GFP_ATOMIC);
+		if (!nvram_ularray)
 			return -ENOMEM;
 			return -ENOMEM;
-		}
 
 
 		/* Upload image to verify downloaded contents. */
 		/* Upload image to verify downloaded contents. */
-		memset(nvram_ularray, 0xaa, varsize);
+		memset(nvram_ularray, 0xaa, bus->varsz);
 
 
 		/* Read the vars list to temp buffer for comparison */
 		/* Read the vars list to temp buffer for comparison */
-		bcmerror =
-		    brcmf_sdbrcm_membytes(bus, false, varaddr, nvram_ularray,
-				     varsize);
+		bcmerror = brcmf_sdbrcm_membytes(bus, false, varaddr,
+						 nvram_ularray, bus->varsz);
 		if (bcmerror) {
 		if (bcmerror) {
 			brcmf_dbg(ERROR, "error %d on reading %d nvram bytes at 0x%08x\n",
 			brcmf_dbg(ERROR, "error %d on reading %d nvram bytes at 0x%08x\n",
-				  bcmerror, varsize, varaddr);
+				  bcmerror, bus->varsz, varaddr);
 		}
 		}
 		/* Compare the org NVRAM with the one read from RAM */
 		/* Compare the org NVRAM with the one read from RAM */
-		if (memcmp(vbuffer, nvram_ularray, varsize))
+		if (memcmp(bus->vars, nvram_ularray, bus->varsz))
 			brcmf_dbg(ERROR, "Downloaded NVRAM image is corrupted\n");
 			brcmf_dbg(ERROR, "Downloaded NVRAM image is corrupted\n");
 		else
 		else
 			brcmf_dbg(ERROR, "Download/Upload/Compare of NVRAM ok\n");
 			brcmf_dbg(ERROR, "Download/Upload/Compare of NVRAM ok\n");
 
 
 		kfree(nvram_ularray);
 		kfree(nvram_ularray);
 #endif				/* DEBUG */
 #endif				/* DEBUG */
-
-		kfree(vbuffer);
 	}
 	}
 
 
 	/* adjust to the user specified RAM */
 	/* adjust to the user specified RAM */
 	brcmf_dbg(INFO, "Physical memory size: %d\n", bus->ramsize);
 	brcmf_dbg(INFO, "Physical memory size: %d\n", bus->ramsize);
 	brcmf_dbg(INFO, "Vars are at %d, orig varsize is %d\n",
 	brcmf_dbg(INFO, "Vars are at %d, orig varsize is %d\n",
-		  varaddr, varsize);
-	varsize = ((bus->ramsize - 4) - varaddr);
+		  varaddr, bus->varsz);
 
 
 	/*
 	/*
 	 * Determine the length token:
 	 * Determine the length token:
@@ -3410,13 +3396,13 @@ static int brcmf_sdbrcm_write_vars(struct brcmf_sdio *bus)
 		varsizew = 0;
 		varsizew = 0;
 		varsizew_le = cpu_to_le32(0);
 		varsizew_le = cpu_to_le32(0);
 	} else {
 	} else {
-		varsizew = varsize / 4;
+		varsizew = bus->varsz / 4;
 		varsizew = (~varsizew << 16) | (varsizew & 0x0000FFFF);
 		varsizew = (~varsizew << 16) | (varsizew & 0x0000FFFF);
 		varsizew_le = cpu_to_le32(varsizew);
 		varsizew_le = cpu_to_le32(varsizew);
 	}
 	}
 
 
 	brcmf_dbg(INFO, "New varsize is %d, length token=0x%08x\n",
 	brcmf_dbg(INFO, "New varsize is %d, length token=0x%08x\n",
-		  varsize, varsizew);
+		  bus->varsz, varsizew);
 
 
 	/* Write the length token to the last word */
 	/* Write the length token to the last word */
 	bcmerror = brcmf_sdbrcm_membytes(bus, true, (bus->ramsize - 4),
 	bcmerror = brcmf_sdbrcm_membytes(bus, true, (bus->ramsize - 4),
@@ -3587,8 +3573,8 @@ static int brcmf_process_nvram_vars(struct brcmf_sdio *bus)
 		*dp++ = 0;
 		*dp++ = 0;
 
 
 	kfree(bus->vars);
 	kfree(bus->vars);
-
-	bus->varsz = buf_len + 1;
+	/* roundup needed for download to device */
+	bus->varsz = roundup(buf_len + 1, 4);
 	bus->vars = kmalloc(bus->varsz, GFP_KERNEL);
 	bus->vars = kmalloc(bus->varsz, GFP_KERNEL);
 	if (bus->vars == NULL) {
 	if (bus->vars == NULL) {
 		bus->varsz = 0;
 		bus->varsz = 0;