Search Linux Wireless

[PATCH 2/2] orinoco: cache downloadable firmware image in memory for use during resume

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



orinoco: cache downloadable firmware image in memory for use during resume

If card is using downloadable firmware (like Agere 9.x), firmware has
to be reloaded during resume. It is not possible to use request_firmware
for that, because tasks are still frozen, so request_firmware will
just timeout and fail. So cache firmware image in memory for later
reuse in ->resume method.

Signed-off-by: Andrey Borzenkov <arvidjaar@xxxxxxx>

---

Unfortunately this is the only way to do it given current infrastructure.
I think that extra memory cost (~60kb) does not warrant anything more
sophisticated - even if this is possible. Also users not using dowloadable
firmware won't be penalized at all.

 drivers/net/wireless/orinoco.c |   42 ++++++++++++++++++++++++++++++----------
 drivers/net/wireless/orinoco.h |    4 ++++
 2 files changed, 35 insertions(+), 11 deletions(-)


diff --git a/drivers/net/wireless/orinoco.c b/drivers/net/wireless/orinoco.c
index 76c480b..204b2a6 100644
--- a/drivers/net/wireless/orinoco.c
+++ b/drivers/net/wireless/orinoco.c
@@ -487,15 +487,25 @@ orinoco_dl_firmware(struct orinoco_private *priv,
 	if (err)
 		goto free;
 
-	err = request_firmware(&fw_entry, firmware, priv->dev);
-	if (err) {
-		printk(KERN_ERR "%s: Cannot find firmware %s\n",
-		       dev->name, firmware);
-		err = -ENOENT;
-		goto free;
+	if (!priv->cached_fw_data) {
+		err = request_firmware(&fw_entry, firmware, priv->dev);
+		if (err) {
+			printk(KERN_ERR "%s: Cannot find firmware %s\n",
+			       dev->name, firmware);
+			err = -ENOENT;
+			goto free;
+		}
+		priv->cached_fw_size = fw_entry->size;
+		priv->cached_fw_data = kmemdup(fw_entry->data, fw_entry->size,
+						GFP_KERNEL);
+		release_firmware(fw_entry);
+		if (!priv->cached_fw_data) {
+			err = -ENOMEM;
+			goto abort;
+		}
 	}
 
-	hdr = (const struct orinoco_fw_header *) fw_entry->data;
+	hdr = (const struct orinoco_fw_header *) priv->cached_fw_data;
 
 	/* Enable aux port to allow programming */
 	err = hermesi_program_init(hw, le32_to_cpu(hdr->entry_point));
@@ -504,10 +514,10 @@ orinoco_dl_firmware(struct orinoco_private *priv,
 		goto abort;
 
 	/* Program data */
-	first_block = (fw_entry->data +
+	first_block = (priv->cached_fw_data +
 		       le16_to_cpu(hdr->headersize) +
 		       le32_to_cpu(hdr->block_offset));
-	end = fw_entry->data + fw_entry->size;
+	end = priv->cached_fw_data + priv->cached_fw_size;
 
 	err = hermes_program(hw, first_block, end);
 	printk(KERN_DEBUG "%s: Program returned %d\n", dev->name, err);
@@ -515,7 +525,7 @@ orinoco_dl_firmware(struct orinoco_private *priv,
 		goto abort;
 
 	/* Update production data */
-	first_block = (fw_entry->data +
+	first_block = (priv->cached_fw_data +
 		       le16_to_cpu(hdr->headersize) +
 		       le32_to_cpu(hdr->pdr_offset));
 
@@ -535,7 +545,13 @@ orinoco_dl_firmware(struct orinoco_private *priv,
 	       dev->name, hermes_present(hw));
 
 abort:
-	release_firmware(fw_entry);
+
+	/* If downloading failed, destroy cached copy */
+	if (err) {
+		priv->cached_fw_size = 0;
+		kfree(priv->cached_fw_data);
+		priv->cached_fw_data = NULL;
+	}
 
 free:
 	kfree(pda);
@@ -3534,6 +3550,9 @@ struct net_device
 	netif_carrier_off(dev);
 	priv->last_linkstatus = 0xffff;
 
+	priv->cached_fw_size = 0;
+	priv->cached_fw_data = NULL;
+
 	return dev;
 }
 
@@ -3545,6 +3564,7 @@ void free_orinocodev(struct net_device *dev)
 	 * when we call tasklet_kill it will run one final time,
 	 * emptying the list */
 	tasklet_kill(&priv->rx_tasklet);
+	kfree(priv->cached_fw_data);
 	priv->wpa_ie_len = 0;
 	kfree(priv->wpa_ie);
 	orinoco_mic_free(priv);
diff --git a/drivers/net/wireless/orinoco.h b/drivers/net/wireless/orinoco.h
index 981570b..403fff8 100644
--- a/drivers/net/wireless/orinoco.h
+++ b/drivers/net/wireless/orinoco.h
@@ -164,6 +164,10 @@ struct orinoco_private {
 	unsigned int wpa_enabled:1;
 	unsigned int tkip_cm_active:1;
 	unsigned int key_mgmt:3;
+
+	/* Cached firmware to use in ->resume */
+	u8 *cached_fw_data;
+	size_t cached_fw_size;
 };
 
 #ifdef ORINOCO_DEBUG

Attachment: signature.asc
Description: This is a digitally signed message part.


[Index of Archives]     [Linux Host AP]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Linux Kernel]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]
  Powered by Linux