aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorDhananjay Phadke <dhananjay@netxen.com>2009-07-01 07:41:42 -0400
committerDavid S. Miller <davem@davemloft.net>2009-07-02 16:16:49 -0400
commit98e31bb00983a5b6d638a31e4ff77e5ca1ccf93e (patch)
tree2f9d2b944146694d02eae5dd05cb127f8a2f78c2 /drivers
parentc56bd0c39ce31e694b6f32223c15bdd582263a3f (diff)
netxen: fix the version code macro
Correct firmware encoding is 8 bit major, 8 bit minor and 16 bit subversion. Flash has sizes rightly set, but original driver submission messed it leaving 16 bit major and 8 bit subversion. Also fix a infinite loop when cut-thru file firmware is invalid. Signed-off-by: Dhananjay Phadke <dhananjay@netxen.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/net/netxen/netxen_nic.h13
-rw-r--r--drivers/net/netxen/netxen_nic_init.c25
2 files changed, 26 insertions, 12 deletions
diff --git a/drivers/net/netxen/netxen_nic.h b/drivers/net/netxen/netxen_nic.h
index 970cedeb5f37..26afcb5658d4 100644
--- a/drivers/net/netxen/netxen_nic.h
+++ b/drivers/net/netxen/netxen_nic.h
@@ -60,7 +60,18 @@
60#define _NETXEN_NIC_LINUX_SUBVERSION 30 60#define _NETXEN_NIC_LINUX_SUBVERSION 30
61#define NETXEN_NIC_LINUX_VERSIONID "4.0.30" 61#define NETXEN_NIC_LINUX_VERSIONID "4.0.30"
62 62
63#define NETXEN_VERSION_CODE(a, b, c) (((a) << 16) + ((b) << 8) + (c)) 63#define NETXEN_VERSION_CODE(a, b, c) (((a) << 24) + ((b) << 16) + (c))
64#define _major(v) (((v) >> 24) & 0xff)
65#define _minor(v) (((v) >> 16) & 0xff)
66#define _build(v) ((v) & 0xffff)
67
68/* version in image has weird encoding:
69 * 7:0 - major
70 * 15:8 - minor
71 * 31:16 - build (little endian)
72 */
73#define NETXEN_DECODE_VERSION(v) \
74 NETXEN_VERSION_CODE(((v) & 0xff), (((v) >> 8) & 0xff), ((v) >> 16))
64 75
65#define NETXEN_NUM_FLASH_SECTORS (64) 76#define NETXEN_NUM_FLASH_SECTORS (64)
66#define NETXEN_FLASH_SECTOR_SIZE (64 * 1024) 77#define NETXEN_FLASH_SECTOR_SIZE (64 * 1024)
diff --git a/drivers/net/netxen/netxen_nic_init.c b/drivers/net/netxen/netxen_nic_init.c
index 055bb61d6e77..7bdcbc67342f 100644
--- a/drivers/net/netxen/netxen_nic_init.c
+++ b/drivers/net/netxen/netxen_nic_init.c
@@ -756,7 +756,7 @@ static int
756netxen_validate_firmware(struct netxen_adapter *adapter, const char *fwname) 756netxen_validate_firmware(struct netxen_adapter *adapter, const char *fwname)
757{ 757{
758 __le32 val; 758 __le32 val;
759 u32 major, minor, build, ver, min_ver, bios; 759 u32 ver, min_ver, bios;
760 struct pci_dev *pdev = adapter->pdev; 760 struct pci_dev *pdev = adapter->pdev;
761 const struct firmware *fw = adapter->fw; 761 const struct firmware *fw = adapter->fw;
762 762
@@ -768,21 +768,18 @@ netxen_validate_firmware(struct netxen_adapter *adapter, const char *fwname)
768 return -EINVAL; 768 return -EINVAL;
769 769
770 val = cpu_to_le32(*(u32 *)&fw->data[NX_FW_VERSION_OFFSET]); 770 val = cpu_to_le32(*(u32 *)&fw->data[NX_FW_VERSION_OFFSET]);
771 major = (__force u32)val & 0xff;
772 minor = ((__force u32)val >> 8) & 0xff;
773 build = (__force u32)val >> 16;
774 771
775 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) 772 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
776 min_ver = NETXEN_VERSION_CODE(4, 0, 216); 773 min_ver = NETXEN_VERSION_CODE(4, 0, 216);
777 else 774 else
778 min_ver = NETXEN_VERSION_CODE(3, 4, 216); 775 min_ver = NETXEN_VERSION_CODE(3, 4, 216);
779 776
780 ver = NETXEN_VERSION_CODE(major, minor, build); 777 ver = NETXEN_DECODE_VERSION(val);
781 778
782 if ((major > _NETXEN_NIC_LINUX_MAJOR) || (ver < min_ver)) { 779 if ((_major(ver) > _NETXEN_NIC_LINUX_MAJOR) || (ver < min_ver)) {
783 dev_err(&pdev->dev, 780 dev_err(&pdev->dev,
784 "%s: firmware version %d.%d.%d unsupported\n", 781 "%s: firmware version %d.%d.%d unsupported\n",
785 fwname, major, minor, build); 782 fwname, _major(ver), _minor(ver), _build(ver));
786 return -EINVAL; 783 return -EINVAL;
787 } 784 }
788 785
@@ -798,11 +795,12 @@ netxen_validate_firmware(struct netxen_adapter *adapter, const char *fwname)
798 if (netxen_rom_fast_read(adapter, 795 if (netxen_rom_fast_read(adapter,
799 NX_FW_VERSION_OFFSET, (int *)&val)) 796 NX_FW_VERSION_OFFSET, (int *)&val))
800 return -EIO; 797 return -EIO;
801 major = (__force u32)val & 0xff; 798 val = NETXEN_DECODE_VERSION(val);
802 minor = ((__force u32)val >> 8) & 0xff; 799 if (val > ver) {
803 build = (__force u32)val >> 16; 800 dev_info(&pdev->dev, "%s: firmware is older than flash\n",
804 if (NETXEN_VERSION_CODE(major, minor, build) > ver) 801 fwname);
805 return -EINVAL; 802 return -EINVAL;
803 }
806 804
807 NXWR32(adapter, NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC); 805 NXWR32(adapter, NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC);
808 return 0; 806 return 0;
@@ -830,6 +828,8 @@ request_mn:
830 828
831 netxen_rom_fast_read(adapter, 829 netxen_rom_fast_read(adapter,
832 NX_FW_VERSION_OFFSET, (int *)&flashed_ver); 830 NX_FW_VERSION_OFFSET, (int *)&flashed_ver);
831 flashed_ver = NETXEN_DECODE_VERSION(flashed_ver);
832
833 if (flashed_ver >= NETXEN_VERSION_CODE(4, 0, 220)) { 833 if (flashed_ver >= NETXEN_VERSION_CODE(4, 0, 220)) {
834 capability = NXRD32(adapter, NX_PEG_TUNE_CAPABILITY); 834 capability = NXRD32(adapter, NX_PEG_TUNE_CAPABILITY);
835 if (capability & NX_PEG_TUNE_MN_PRESENT) { 835 if (capability & NX_PEG_TUNE_MN_PRESENT) {
@@ -838,6 +838,9 @@ request_mn:
838 } 838 }
839 } 839 }
840 840
841 adapter->fw = NULL;
842 goto done;
843
841request_fw: 844request_fw:
842 rc = request_firmware(&adapter->fw, fw_name[fw_type], &pdev->dev); 845 rc = request_firmware(&adapter->fw, fw_name[fw_type], &pdev->dev);
843 if (rc != 0) { 846 if (rc != 0) {