Skip to content

Commit fcaa406

Browse files
Jaswinder Singhdavem330
authored andcommitted
cassini: use request_firmware
Firmware blob looks like this... __le16 load_address unsigned char data[] [[email protected]: include vmalloc.h] Signed-off-by: Jaswinder Singh <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 5e68722 commit fcaa406

File tree

5 files changed

+207
-1523
lines changed

5 files changed

+207
-1523
lines changed

drivers/net/cassini.c

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
#include <linux/slab.h>
7575
#include <linux/delay.h>
7676
#include <linux/init.h>
77+
#include <linux/vmalloc.h>
7778
#include <linux/ioport.h>
7879
#include <linux/pci.h>
7980
#include <linux/mm.h>
@@ -91,6 +92,7 @@
9192
#include <linux/ip.h>
9293
#include <linux/tcp.h>
9394
#include <linux/mutex.h>
95+
#include <linux/firmware.h>
9496

9597
#include <net/checksum.h>
9698

@@ -197,6 +199,7 @@ static int link_mode;
197199
MODULE_AUTHOR("Adrian Sun ([email protected])");
198200
MODULE_DESCRIPTION("Sun Cassini(+) ethernet driver");
199201
MODULE_LICENSE("GPL");
202+
MODULE_FIRMWARE("sun/cassini.bin");
200203
module_param(cassini_debug, int, 0);
201204
MODULE_PARM_DESC(cassini_debug, "Cassini bitmapped debugging message enable value");
202205
module_param(link_mode, int, 0);
@@ -812,9 +815,44 @@ static int cas_reset_mii_phy(struct cas *cp)
812815
return (limit <= 0);
813816
}
814817

818+
static int cas_saturn_firmware_init(struct cas *cp)
819+
{
820+
const struct firmware *fw;
821+
const char fw_name[] = "sun/cassini.bin";
822+
int err;
823+
824+
if (PHY_NS_DP83065 != cp->phy_id)
825+
return 0;
826+
827+
err = request_firmware(&fw, fw_name, &cp->pdev->dev);
828+
if (err) {
829+
printk(KERN_ERR "cassini: Failed to load firmware \"%s\"\n",
830+
fw_name);
831+
return err;
832+
}
833+
if (fw->size < 2) {
834+
printk(KERN_ERR "cassini: bogus length %zu in \"%s\"\n",
835+
fw->size, fw_name);
836+
err = -EINVAL;
837+
goto out;
838+
}
839+
cp->fw_load_addr= fw->data[1] << 8 | fw->data[0];
840+
cp->fw_size = fw->size - 2;
841+
cp->fw_data = vmalloc(cp->fw_size);
842+
if (!cp->fw_data) {
843+
err = -ENOMEM;
844+
printk(KERN_ERR "cassini: \"%s\" Failed %d\n", fw_name, err);
845+
goto out;
846+
}
847+
memcpy(cp->fw_data, &fw->data[2], cp->fw_size);
848+
out:
849+
release_firmware(fw);
850+
return err;
851+
}
852+
815853
static void cas_saturn_firmware_load(struct cas *cp)
816854
{
817-
cas_saturn_patch_t *patch = cas_saturn_patch;
855+
int i;
818856

819857
cas_phy_powerdown(cp);
820858

@@ -833,11 +871,9 @@ static void cas_saturn_firmware_load(struct cas *cp)
833871

834872
/* download new firmware */
835873
cas_phy_write(cp, DP83065_MII_MEM, 0x1);
836-
cas_phy_write(cp, DP83065_MII_REGE, patch->addr);
837-
while (patch->addr) {
838-
cas_phy_write(cp, DP83065_MII_REGD, patch->val);
839-
patch++;
840-
}
874+
cas_phy_write(cp, DP83065_MII_REGE, cp->fw_load_addr);
875+
for (i = 0; i < cp->fw_size; i++)
876+
cas_phy_write(cp, DP83065_MII_REGD, cp->fw_data[i]);
841877

842878
/* enable firmware */
843879
cas_phy_write(cp, DP83065_MII_REGE, 0x8ff8);
@@ -5108,6 +5144,9 @@ static int __devinit cas_init_one(struct pci_dev *pdev,
51085144
cas_reset(cp, 0);
51095145
if (cas_check_invariants(cp))
51105146
goto err_out_iounmap;
5147+
if (cp->cas_flags & CAS_FLAG_SATURN)
5148+
if (cas_saturn_firmware_init(cp))
5149+
goto err_out_iounmap;
51115150

51125151
cp->init_block = (struct cas_init_block *)
51135152
pci_alloc_consistent(pdev, sizeof(struct cas_init_block),
@@ -5217,6 +5256,9 @@ static void __devexit cas_remove_one(struct pci_dev *pdev)
52175256
cp = netdev_priv(dev);
52185257
unregister_netdev(dev);
52195258

5259+
if (cp->fw_data)
5260+
vfree(cp->fw_data);
5261+
52205262
mutex_lock(&cp->pm_mutex);
52215263
flush_scheduled_work();
52225264
if (cp->hw_running)

0 commit comments

Comments
 (0)