Skip to content

Commit 4b6ece9

Browse files
3C359: use request_firmware
Signed-off-by: Jaswinder Singh Rajput <[email protected]>
1 parent a7a5eb9 commit 4b6ece9

File tree

6 files changed

+1651
-1596
lines changed

6 files changed

+1651
-1596
lines changed

drivers/net/tokenring/3c359.c

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
#include <linux/pci.h>
6363
#include <linux/spinlock.h>
6464
#include <linux/bitops.h>
65+
#include <linux/firmware.h>
6566

6667
#include <net/checksum.h>
6768

@@ -73,8 +74,10 @@
7374
static char version[] __devinitdata =
7475
"3c359.c v1.2.0 2/17/01 - Mike Phillips ([email protected])" ;
7576

77+
#define FW_NAME "3com/3C359.bin"
7678
MODULE_AUTHOR("Mike Phillips <[email protected]>") ;
7779
MODULE_DESCRIPTION("3Com 3C359 Velocity XL Token Ring Adapter Driver \n") ;
80+
MODULE_FIRMWARE(FW_NAME);
7881

7982
/* Module paramters */
8083

@@ -114,8 +117,6 @@ MODULE_PARM_DESC(message_level, "3c359: Level of reported messages") ;
114117
* will be stuck with 1555 lines of hex #'s in the code.
115118
*/
116119

117-
#include "3c359_microcode.h"
118-
119120
static struct pci_device_id xl_pci_tbl[] =
120121
{
121122
{PCI_VENDOR_ID_3COM,PCI_DEVICE_ID_3COM_3C359, PCI_ANY_ID, PCI_ANY_ID, },
@@ -364,19 +365,42 @@ static int __devinit xl_probe(struct pci_dev *pdev,
364365
return 0;
365366
}
366367

368+
static int xl_init_firmware(struct xl_private *xl_priv)
369+
{
370+
int err;
371+
372+
err = request_firmware(&xl_priv->fw, FW_NAME, &xl_priv->pdev->dev);
373+
if (err) {
374+
printk(KERN_ERR "Failed to load firmware \"%s\"\n", FW_NAME);
375+
return err;
376+
}
377+
378+
if (xl_priv->fw->size < 16) {
379+
printk(KERN_ERR "Bogus length %zu in \"%s\"\n",
380+
xl_priv->fw->size, FW_NAME);
381+
release_firmware(xl_priv->fw);
382+
err = -EINVAL;
383+
}
384+
385+
return err;
386+
}
367387

368388
static int __devinit xl_init(struct net_device *dev)
369389
{
370390
struct xl_private *xl_priv = netdev_priv(dev);
391+
int err;
371392

372393
printk(KERN_INFO "%s \n", version);
373394
printk(KERN_INFO "%s: I/O at %hx, MMIO at %p, using irq %d\n",
374395
xl_priv->xl_card_name, (unsigned int)dev->base_addr ,xl_priv->xl_mmio, dev->irq);
375396

376397
spin_lock_init(&xl_priv->xl_lock) ;
377398

378-
return xl_hw_reset(dev) ;
399+
err = xl_init_firmware(xl_priv);
400+
if (err == 0)
401+
err = xl_hw_reset(dev);
379402

403+
return err;
380404
}
381405

382406

@@ -386,7 +410,7 @@ static int __devinit xl_init(struct net_device *dev)
386410
*/
387411

388412
static int xl_hw_reset(struct net_device *dev)
389-
{
413+
{
390414
struct xl_private *xl_priv = netdev_priv(dev);
391415
u8 __iomem *xl_mmio = xl_priv->xl_mmio ;
392416
unsigned long t ;
@@ -396,6 +420,9 @@ static int xl_hw_reset(struct net_device *dev)
396420
u16 start ;
397421
int j ;
398422

423+
if (xl_priv->fw == NULL)
424+
return -EINVAL;
425+
399426
/*
400427
* Reset the card. If the card has got the microcode on board, we have
401428
* missed the initialization interrupt, so we must always do this.
@@ -458,25 +485,30 @@ static int xl_hw_reset(struct net_device *dev)
458485

459486
/*
460487
* Now to write the microcode into the shared ram
461-
* The microcode must finish at position 0xFFFF, so we must subtract
462-
* to get the start position for the code
488+
* The microcode must finish at position 0xFFFF,
489+
* so we must subtract to get the start position for the code
490+
*
491+
* Looks strange but ensures compiler only uses
492+
* 16 bit unsigned int
463493
*/
494+
start = (0xFFFF - (xl_priv->fw->size) + 1) ;
464495

465-
start = (0xFFFF - (mc_size) + 1 ) ; /* Looks strange but ensures compiler only uses 16 bit unsigned int for this */
466-
467496
printk(KERN_INFO "3C359: Uploading Microcode: ");
468-
469-
for (i = start, j = 0; j < mc_size; i++, j++) {
470-
writel(MEM_BYTE_WRITE | 0XD0000 | i, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
471-
writeb(microcode[j],xl_mmio + MMIO_MACDATA) ;
497+
498+
for (i = start, j = 0; j < xl_priv->fw->size; i++, j++) {
499+
writel(MEM_BYTE_WRITE | 0XD0000 | i,
500+
xl_mmio + MMIO_MAC_ACCESS_CMD);
501+
writeb(xl_priv->fw->data[j], xl_mmio + MMIO_MACDATA);
472502
if (j % 1024 == 0)
473503
printk(".");
474504
}
475505
printk("\n") ;
476506

477-
for (i=0;i < 16; i++) {
478-
writel( (MEM_BYTE_WRITE | 0xDFFF0) + i, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
479-
writeb(microcode[mc_size - 16 + i], xl_mmio + MMIO_MACDATA) ;
507+
for (i = 0; i < 16; i++) {
508+
writel((MEM_BYTE_WRITE | 0xDFFF0) + i,
509+
xl_mmio + MMIO_MAC_ACCESS_CMD);
510+
writeb(xl_priv->fw->data[xl_priv->fw->size - 16 + i],
511+
xl_mmio + MMIO_MACDATA);
480512
}
481513

482514
/*
@@ -1782,6 +1814,7 @@ static void __devexit xl_remove_one (struct pci_dev *pdev)
17821814
struct net_device *dev = pci_get_drvdata(pdev);
17831815
struct xl_private *xl_priv=netdev_priv(dev);
17841816

1817+
release_firmware(xl_priv->fw);
17851818
unregister_netdev(dev);
17861819
iounmap(xl_priv->xl_mmio) ;
17871820
pci_release_regions(pdev) ;

drivers/net/tokenring/3c359.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,5 +284,8 @@ struct xl_private {
284284
u8 xl_laa[6] ;
285285
u32 rx_ring_dma_addr ;
286286
u32 tx_ring_dma_addr ;
287+
288+
/* firmware section */
289+
const struct firmware *fw;
287290
};
288291

0 commit comments

Comments
 (0)