Skip to content

Commit

Permalink
kaweth: use request_firmware()
Browse files Browse the repository at this point in the history
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
  • Loading branch information
dwmw2 authored and David Woodhouse committed Jul 10, 2008
1 parent 0f805b8 commit 7968249
Show file tree
Hide file tree
Showing 8 changed files with 304 additions and 574 deletions.
43 changes: 26 additions & 17 deletions drivers/net/usb/kaweth.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -57,13 +57,12 @@
#include <linux/ethtool.h> #include <linux/ethtool.h>
#include <linux/dma-mapping.h> #include <linux/dma-mapping.h>
#include <linux/wait.h> #include <linux/wait.h>
#include <linux/firmware.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <asm/byteorder.h> #include <asm/byteorder.h>


#undef DEBUG #undef DEBUG


#include "kawethfw.h"

#define KAWETH_MTU 1514 #define KAWETH_MTU 1514
#define KAWETH_BUF_SIZE 1664 #define KAWETH_BUF_SIZE 1664
#define KAWETH_TX_TIMEOUT (5 * HZ) #define KAWETH_TX_TIMEOUT (5 * HZ)
Expand Down Expand Up @@ -108,6 +107,10 @@
MODULE_AUTHOR("Michael Zappe <zapman@interlan.net>, Stephane Alnet <stephane@u-picardie.fr>, Brad Hards <bhards@bigpond.net.au> and Oliver Neukum <oliver@neukum.org>"); MODULE_AUTHOR("Michael Zappe <zapman@interlan.net>, Stephane Alnet <stephane@u-picardie.fr>, Brad Hards <bhards@bigpond.net.au> and Oliver Neukum <oliver@neukum.org>");
MODULE_DESCRIPTION("KL5USB101 USB Ethernet driver"); MODULE_DESCRIPTION("KL5USB101 USB Ethernet driver");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
MODULE_FIRMWARE("kaweth/new_code.bin");
MODULE_FIRMWARE("kaweth/new_code_fix.bin");
MODULE_FIRMWARE("kaweth/trigger_code.bin");
MODULE_FIRMWARE("kaweth/trigger_code_fix.bin");


static const char driver_name[] = "kaweth"; static const char driver_name[] = "kaweth";


Expand Down Expand Up @@ -385,17 +388,28 @@ static int kaweth_set_receive_filter(struct kaweth_device *kaweth,
* kaweth_download_firmware * kaweth_download_firmware
****************************************************************/ ****************************************************************/
static int kaweth_download_firmware(struct kaweth_device *kaweth, static int kaweth_download_firmware(struct kaweth_device *kaweth,
__u8 *data, const char *fwname,
__u16 data_len,
__u8 interrupt, __u8 interrupt,
__u8 type) __u8 type)
{ {
if(data_len > KAWETH_FIRMWARE_BUF_SIZE) { const struct firmware *fw;
err("Firmware too big: %d", data_len); int data_len;
int ret;

ret = request_firmware(&fw, fwname, &kaweth->dev->dev);
if (ret) {
err("Firmware request failed\n");
return ret;
}

if (fw->size > KAWETH_FIRMWARE_BUF_SIZE) {
err("Firmware too big: %zu", fw->size);
return -ENOSPC; return -ENOSPC;
} }
data_len = fw->size;
memcpy(kaweth->firmware_buf, fw->data, fw->size);


memcpy(kaweth->firmware_buf, data, data_len); release_firmware(fw);


kaweth->firmware_buf[2] = (data_len & 0xFF) - 7; kaweth->firmware_buf[2] = (data_len & 0xFF) - 7;
kaweth->firmware_buf[3] = data_len >> 8; kaweth->firmware_buf[3] = data_len >> 8;
Expand All @@ -406,8 +420,7 @@ static int kaweth_download_firmware(struct kaweth_device *kaweth,
kaweth->firmware_buf[2]); kaweth->firmware_buf[2]);


dbg("Downloading firmware at %p to kaweth device at %p", dbg("Downloading firmware at %p to kaweth device at %p",
data, fw->data, kaweth);
kaweth);
dbg("Firmware length: %d", data_len); dbg("Firmware length: %d", data_len);


return kaweth_control(kaweth, return kaweth_control(kaweth,
Expand Down Expand Up @@ -1009,26 +1022,23 @@ static int kaweth_probe(
info("Downloading firmware..."); info("Downloading firmware...");
kaweth->firmware_buf = (__u8 *)__get_free_page(GFP_KERNEL); kaweth->firmware_buf = (__u8 *)__get_free_page(GFP_KERNEL);
if ((result = kaweth_download_firmware(kaweth, if ((result = kaweth_download_firmware(kaweth,
kaweth_new_code, "kaweth/new_code.bin",
len_kaweth_new_code,
100, 100,
2)) < 0) { 2)) < 0) {
err("Error downloading firmware (%d)", result); err("Error downloading firmware (%d)", result);
goto err_fw; goto err_fw;
} }


if ((result = kaweth_download_firmware(kaweth, if ((result = kaweth_download_firmware(kaweth,
kaweth_new_code_fix, "kaweth/new_code_fix.bin",
len_kaweth_new_code_fix,
100, 100,
3)) < 0) { 3)) < 0) {
err("Error downloading firmware fix (%d)", result); err("Error downloading firmware fix (%d)", result);
goto err_fw; goto err_fw;
} }


if ((result = kaweth_download_firmware(kaweth, if ((result = kaweth_download_firmware(kaweth,
kaweth_trigger_code, "kaweth/trigger_code.bin",
len_kaweth_trigger_code,
126, 126,
2)) < 0) { 2)) < 0) {
err("Error downloading trigger code (%d)", result); err("Error downloading trigger code (%d)", result);
Expand All @@ -1037,8 +1047,7 @@ static int kaweth_probe(
} }


if ((result = kaweth_download_firmware(kaweth, if ((result = kaweth_download_firmware(kaweth,
kaweth_trigger_code_fix, "kaweth/trigger_code_fix.bin",
len_kaweth_trigger_code_fix,
126, 126,
3)) < 0) { 3)) < 0) {
err("Error downloading trigger code fix (%d)", result); err("Error downloading trigger code fix (%d)", result);
Expand Down
Loading

0 comments on commit 7968249

Please sign in to comment.