From: Pavel Roskin <proski@gnu.org>
To: linux-wireless@vger.kernel.org
Subject: [PATCH 08/35] Merge at76_download_external_fw() into at76_load_external_fw()
Date: Sat, 01 Sep 2007 00:35:00 -0400 [thread overview]
Message-ID: <20070901043500.2498.52295.stgit@dv.roinet.com> (raw)
In-Reply-To: <20070901043233.2498.95850.stgit@dv.roinet.com>
Simplify logic to ensure that the last block is empty. Unify
DFU_PACKETSIZE and EXT_FW_BLOCK_SIZE into FW_BLOCK_SIZE.
Signed-off-by: Pavel Roskin <proski@gnu.org>
---
drivers/net/wireless/at76_usb.c | 98 ++++++++++++++++-----------------------
1 files changed, 39 insertions(+), 59 deletions(-)
diff --git a/drivers/net/wireless/at76_usb.c b/drivers/net/wireless/at76_usb.c
index 8994b70..544b1ad 100644
--- a/drivers/net/wireless/at76_usb.c
+++ b/drivers/net/wireless/at76_usb.c
@@ -232,7 +232,7 @@ static const char *const mac_states[] = {
#define DFU_GETSTATE 5
#define DFU_ABORT 6
-#define DFU_PACKETSIZE 1024
+#define FW_BLOCK_SIZE 1024
struct dfu_status {
unsigned char status;
@@ -312,7 +312,7 @@ static int at76_usbdfu_download(struct usb_device *udev, u8 *dfu_buffer,
return -EINVAL;
}
- block = kmalloc(DFU_PACKETSIZE, GFP_KERNEL);
+ block = kmalloc(FW_BLOCK_SIZE, GFP_KERNEL);
if (!block)
return -ENOMEM;
@@ -353,7 +353,7 @@ static int at76_usbdfu_download(struct usb_device *udev, u8 *dfu_buffer,
case STATE_DFU_IDLE:
at76_dbg(DBG_DFU, "DFU IDLE");
- dfu_block_bytes = min(dfu_bytes_left, DFU_PACKETSIZE);
+ dfu_block_bytes = min(dfu_bytes_left, FW_BLOCK_SIZE);
dfu_bytes_left -= dfu_block_bytes;
memcpy(block, dfu_buffer + dfu_buffer_offset,
dfu_block_bytes);
@@ -725,54 +725,6 @@ static inline int at76_get_cmd_status(struct usb_device *udev, u8 cmd)
return stat_buf[5];
}
-#define EXT_FW_BLOCK_SIZE 1024
-static int at76_download_external_fw(struct usb_device *udev, u8 *buf, int size)
-{
- int i = 0;
- int ret;
- u8 *block;
-
- if (size < 0)
- return -EINVAL;
- if (size > 0 && !buf)
- return -EFAULT;
-
- block = kmalloc(EXT_FW_BLOCK_SIZE, GFP_KERNEL);
- if (!block)
- return -ENOMEM;
-
- at76_dbg(DBG_DEVSTART, "downloading external firmware");
-
- while (size > 0) {
- int bsize = size > EXT_FW_BLOCK_SIZE ? EXT_FW_BLOCK_SIZE : size;
-
- memcpy(block, buf, bsize);
- at76_dbg(DBG_DEVSTART,
- "ext fw, size left = %5d, bsize = %4d, i = %2d",
- size, bsize, i);
- ret = at76_load_ext_fw_block(udev, i, block, bsize);
- if (ret < 0) {
- err("loading %dth firmware block failed: %d", i, ret);
- goto exit;
- }
- buf += bsize;
- size -= bsize;
- i++;
- }
-
- /* for fw >= 0.100, the device needs
- an extra empty block: */
- ret = at76_load_ext_fw_block(udev, i, block, 0);
- if (ret < 0) {
- err("loading %dth firmware block failed: %d", ret, i);
- goto exit;
- }
-
-exit:
- kfree(block);
- return ret;
-}
-
static int at76_set_card_command(struct usb_device *udev, int cmd, void *buf,
int buf_size)
{
@@ -3609,6 +3561,14 @@ static int at76_load_external_fw(struct usb_device *udev, struct fwentry *fwe)
{
int ret;
int op_mode;
+ int blockno = 0;
+ int bsize;
+ u8 *block;
+ u8 *buf = fwe->extfw;
+ int size = fwe->extfw_size;
+
+ if (!buf || !size)
+ return -ENOENT;
op_mode = at76_get_op_mode(udev);
at76_dbg(DBG_DEVSTART, "opmode %d", op_mode);
@@ -3618,20 +3578,40 @@ static int at76_load_external_fw(struct usb_device *udev, struct fwentry *fwe)
return -EINVAL;
}
- if (!fwe->extfw || !fwe->extfw_size)
- return -ENOENT;
+ block = kmalloc(FW_BLOCK_SIZE, GFP_KERNEL);
+ if (!block)
+ return -ENOMEM;
- ret = at76_download_external_fw(udev, fwe->extfw, fwe->extfw_size);
- if (ret < 0) {
- err("Downloading external firmware failed: %d", ret);
- return ret;
- }
+ at76_dbg(DBG_DEVSTART, "downloading external firmware");
+
+ /* for fw >= 0.100, the device needs an extra empty block */
+ do {
+ bsize = min_t(int, size, FW_BLOCK_SIZE);
+ memcpy(block, buf, bsize);
+ at76_dbg(DBG_DEVSTART,
+ "ext fw, size left = %5d, bsize = %4d, blockno = %2d",
+ size, bsize, blockno);
+ ret = at76_load_ext_fw_block(udev, blockno, block, bsize);
+ if (ret != bsize) {
+ err("loading %dth firmware block failed: %d", blockno,
+ ret);
+ goto exit;
+ }
+ buf += bsize;
+ size -= bsize;
+ blockno++;
+ } while (bsize > 0);
if (fwe->board_type == BOARD_505A_2958) {
at76_dbg(DBG_DEVSTART, "200 ms delay for board type 7");
schedule_timeout_interruptible(HZ / 5 + 1);
}
- return 0;
+
+exit:
+ kfree(block);
+ if (ret < 0)
+ err("Downloading external firmware failed: %d", ret);
+ return ret;
}
/* Download internal firmware */
next prev parent reply other threads:[~2007-09-01 4:35 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-01 4:34 [PATCH 00/35] Update at76_usb to the start of mac80211 port Pavel Roskin
2007-09-01 4:34 ` [PATCH 01/35] Protect at76_get_op_mode() and at76_get_mib() against short reads Pavel Roskin
2007-09-01 4:34 ` [PATCH 02/35] Use existing macros to find bulk in and bulk out endpoints Pavel Roskin
2007-09-01 4:34 ` [PATCH 03/35] Rewrite at76_alloc_urbs() in a more linear fashion Pavel Roskin
2007-09-01 4:34 ` [PATCH 04/35] Avoid overuse of NULL Pavel Roskin
2007-09-01 4:34 ` [PATCH 05/35] Add myself to the author list Pavel Roskin
2007-09-01 4:34 ` [PATCH 06/35] Move (de)initialization functions closer to the end of file Pavel Roskin
2007-09-01 4:34 ` [PATCH 07/35] Don't use shift on numeric constants in usb_control_msg() arguments Pavel Roskin
2007-09-01 4:35 ` Pavel Roskin [this message]
2007-09-01 4:35 ` [PATCH 09/35] Simplify at76_usbdfu_download() Pavel Roskin
2007-09-01 4:35 ` [PATCH 10/35] Add minimal support to 505AMX Pavel Roskin
2007-09-01 4:35 ` [PATCH 11/35] Simplify logic in at76_get_reg_domain() Pavel Roskin
2007-09-01 4:35 ` [PATCH 12/35] Fix hex2str() and mac2str() to avoid buffer overlap Pavel Roskin
2007-09-01 4:35 ` [PATCH 13/35] Rename some long functions and fields Pavel Roskin
2007-09-01 4:35 ` [PATCH 14/35] Fix incorrect queue management in at76_tx_mgmt() Pavel Roskin
2007-09-01 4:35 ` [PATCH 15/35] Introduce at76_quiesce(), use it to stop network activity Pavel Roskin
2007-09-01 4:35 ` [PATCH 16/35] Don't disable and enable tasklets, it doesn't work as expected Pavel Roskin
2007-09-01 4:35 ` [PATCH 17/35] Start beacon timeout task when connected Pavel Roskin
2007-09-01 4:35 ` [PATCH 18/35] Only cancel correct timeouts for Auth and Assoc replies Pavel Roskin
2007-09-01 9:17 ` Johannes Berg
2007-09-01 10:54 ` Pavel Roskin
2007-09-01 11:04 ` Johannes Berg
2007-09-01 13:16 ` John W. Linville
2007-09-01 20:09 ` Pavel Roskin
2007-09-01 4:36 ` [PATCH 19/35] Improve output of the regdomain id Pavel Roskin
2007-09-01 4:36 ` [PATCH 20/35] Protect at76_iw_handler_set_scan() with mutex Pavel Roskin
2007-09-01 4:36 ` [PATCH 21/35] Eliminate vendor IDs Pavel Roskin
2007-09-01 4:36 ` [PATCH 22/35] Only retry resubmitting rx_urb once Pavel Roskin
2007-09-01 4:36 ` [PATCH 23/35] Simplify at76_get_mib_mdomain() Pavel Roskin
2007-09-01 4:36 ` [PATCH 24/35] Do implicit scanning only with current ESSID Pavel Roskin
2007-09-01 4:36 ` [PATCH 25/35] Don't dump mib_mdomain while scanning, it's done on device startup Pavel Roskin
2007-09-01 4:36 ` [PATCH 26/35] Improve dump of MAC_ADDR Pavel Roskin
2007-09-01 4:36 ` [PATCH 27/35] Remove unneeded braces, found by checkpatch.pl Pavel Roskin
2007-09-01 4:36 ` [PATCH 28/35] Convert dbg() to at76_dbg() or remove it Pavel Roskin
2007-09-01 4:37 ` [PATCH 29/35] Eliminate at76_dbg_dumpbuf() in favor of hex2str() Pavel Roskin
2007-09-01 4:37 ` [PATCH 30/35] Eliminate pr_debug() in favor of at76_dbg() Pavel Roskin
2007-09-01 4:37 ` [PATCH 31/35] Simplify logic in at76_is_hidden_ssid() Pavel Roskin
2007-09-01 4:37 ` [PATCH 32/35] Massive cleanup of dump functions Pavel Roskin
2007-09-01 4:37 ` [PATCH 33/35] Remove international roaming support Pavel Roskin
2007-09-01 4:37 ` [PATCH 34/35] Don't do additional MIB dumps if DEBUG is defined Pavel Roskin
2007-09-01 4:37 ` [PATCH 35/35] Replace scan_runs with scan_need_any Pavel Roskin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070901043500.2498.52295.stgit@dv.roinet.com \
--to=proski@gnu.org \
--cc=linux-wireless@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).