qlcnic: Restructuring of qlc_83xx_fw_info structure.
authorPratik Pujar <pratik.pujar@qlogic.com>
Fri, 30 Aug 2013 17:51:22 +0000 (13:51 -0400)
committerDavid S. Miller <davem@davemloft.net>
Sun, 1 Sep 2013 02:34:44 +0000 (22:34 -0400)
o Removed unused and unnecessary members from qlc_83xx_fw_info
  structure.
o Made fw_info member of qlcnic_hardware_context as a pointer to
  qlc_83xx_fw_info structure.
o Added a member fw_file_name to qlc_83xx_fw_info structure which
  will hold the name of firmware image file name.

Signed-off-by: Pratik Pujar <pratik.pujar@qlogic.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/qlogic/qlcnic/qlcnic.h
drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.h
drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c

index 318663f..204d6e1 100644 (file)
@@ -463,7 +463,7 @@ struct qlcnic_hardware_context {
        struct qlcnic_fdt fdt;
        struct qlc_83xx_reset reset;
        struct qlc_83xx_idc idc;
-       struct qlc_83xx_fw_info fw_info;
+       struct qlc_83xx_fw_info *fw_info;
        struct qlcnic_intrpt_config *intr_tbl;
        struct qlcnic_sriov *sriov;
        u32 *reg_tbl;
index 6752d58..2a2ab6b 100644 (file)
@@ -274,11 +274,7 @@ struct qlcnic_macvlan_mbx {
 
 struct qlc_83xx_fw_info {
        const struct firmware   *fw;
-       u16     major_fw_version;
-       u8      minor_fw_version;
-       u8      sub_fw_version;
-       u8      fw_build_num;
-       u8      load_from_file;
+       char    fw_file_name[QLC_FW_FILE_NAME_LEN];
 };
 
 struct qlc_83xx_reset {
index b7eddfe..c24c2a4 100644 (file)
@@ -1267,31 +1267,33 @@ static int qlcnic_83xx_copy_bootloader(struct qlcnic_adapter *adapter)
 
 static int qlcnic_83xx_copy_fw_file(struct qlcnic_adapter *adapter)
 {
+       struct qlc_83xx_fw_info *fw_info = adapter->ahw->fw_info;
+       const struct firmware *fw = fw_info->fw;
        u32 dest, *p_cache;
-       u64 addr;
+       int i, ret = -EIO;
        u8 data[16];
        size_t size;
-       int i, ret = -EIO;
+       u64 addr;
 
        dest = QLCRDX(adapter->ahw, QLCNIC_FW_IMAGE_ADDR);
-       size = (adapter->ahw->fw_info.fw->size & ~0xF);
-       p_cache = (u32 *)adapter->ahw->fw_info.fw->data;
+       size = (fw->size & ~0xF);
+       p_cache = (u32 *)fw->data;
        addr = (u64)dest;
 
        ret = qlcnic_83xx_ms_mem_write128(adapter, addr,
                                          (u32 *)p_cache, size / 16);
        if (ret) {
                dev_err(&adapter->pdev->dev, "MS memory write failed\n");
-               release_firmware(adapter->ahw->fw_info.fw);
-               adapter->ahw->fw_info.fw = NULL;
+               release_firmware(fw);
+               fw_info->fw = NULL;
                return -EIO;
        }
 
        /* alignment check */
-       if (adapter->ahw->fw_info.fw->size & 0xF) {
+       if (fw->size & 0xF) {
                addr = dest + size;
-               for (i = 0; i < (adapter->ahw->fw_info.fw->size & 0xF); i++)
-                       data[i] = adapter->ahw->fw_info.fw->data[size + i];
+               for (i = 0; i < (fw->size & 0xF); i++)
+                       data[i] = fw->data[size + i];
                for (; i < 16; i++)
                        data[i] = 0;
                ret = qlcnic_83xx_ms_mem_write128(adapter, addr,
@@ -1299,13 +1301,13 @@ static int qlcnic_83xx_copy_fw_file(struct qlcnic_adapter *adapter)
                if (ret) {
                        dev_err(&adapter->pdev->dev,
                                "MS memory write failed\n");
-                       release_firmware(adapter->ahw->fw_info.fw);
-                       adapter->ahw->fw_info.fw = NULL;
+                       release_firmware(fw);
+                       fw_info->fw = NULL;
                        return -EIO;
                }
        }
-       release_firmware(adapter->ahw->fw_info.fw);
-       adapter->ahw->fw_info.fw = NULL;
+       release_firmware(fw);
+       fw_info->fw = NULL;
 
        return 0;
 }
@@ -1949,35 +1951,12 @@ static void qlcnic_83xx_init_hw(struct qlcnic_adapter *p_dev)
                dev_err(&p_dev->pdev->dev, "%s: failed\n", __func__);
 }
 
-static void qlcnic_83xx_get_fw_file_name(struct qlcnic_adapter *adapter,
-                                        char *file_name)
-{
-       struct pci_dev *pdev = adapter->pdev;
-
-       memset(file_name, 0, QLC_FW_FILE_NAME_LEN);
-
-       switch (pdev->device) {
-       case PCI_DEVICE_ID_QLOGIC_QLE834X:
-               strncpy(file_name, QLC_83XX_FW_FILE_NAME,
-                       QLC_FW_FILE_NAME_LEN);
-               break;
-       case PCI_DEVICE_ID_QLOGIC_QLE844X:
-               strncpy(file_name, QLC_84XX_FW_FILE_NAME,
-                       QLC_FW_FILE_NAME_LEN);
-               break;
-       default:
-               dev_err(&pdev->dev, "%s: Invalid device id\n",
-                       __func__);
-       }
-}
-
 static int qlcnic_83xx_load_fw_image_from_host(struct qlcnic_adapter *adapter)
 {
-       char fw_file_name[QLC_FW_FILE_NAME_LEN];
+       struct qlc_83xx_fw_info *fw_info = adapter->ahw->fw_info;
        int err = -EIO;
 
-       qlcnic_83xx_get_fw_file_name(adapter, fw_file_name);
-       if (request_firmware(&adapter->ahw->fw_info.fw, fw_file_name,
+       if (request_firmware(&fw_info->fw, fw_info->fw_file_name,
                             &(adapter->pdev->dev))) {
                dev_err(&adapter->pdev->dev,
                        "No file FW image, loading flash FW image.\n");
@@ -2173,6 +2152,39 @@ static void qlcnic_83xx_clear_function_resources(struct qlcnic_adapter *adapter)
        }
 }
 
+static int qlcnic_83xx_get_fw_info(struct qlcnic_adapter *adapter)
+{
+       struct qlcnic_hardware_context *ahw = adapter->ahw;
+       struct pci_dev *pdev = adapter->pdev;
+       struct qlc_83xx_fw_info *fw_info;
+       int err = 0;
+
+       ahw->fw_info = kzalloc(sizeof(*fw_info), GFP_KERNEL);
+       if (!ahw->fw_info) {
+               err = -ENOMEM;
+       } else {
+               fw_info = ahw->fw_info;
+               switch (pdev->device) {
+               case PCI_DEVICE_ID_QLOGIC_QLE834X:
+                       strncpy(fw_info->fw_file_name, QLC_83XX_FW_FILE_NAME,
+                               QLC_FW_FILE_NAME_LEN);
+                       break;
+               case PCI_DEVICE_ID_QLOGIC_QLE844X:
+                       strncpy(fw_info->fw_file_name, QLC_84XX_FW_FILE_NAME,
+                               QLC_FW_FILE_NAME_LEN);
+                       break;
+               default:
+                       dev_err(&pdev->dev, "%s: Invalid device id\n",
+                               __func__);
+                       err = -EINVAL;
+                       break;
+               }
+       }
+
+       return err;
+}
+
+
 int qlcnic_83xx_init(struct qlcnic_adapter *adapter, int pci_using_dac)
 {
        struct qlcnic_hardware_context *ahw = adapter->ahw;
@@ -2198,10 +2210,14 @@ int qlcnic_83xx_init(struct qlcnic_adapter *adapter, int pci_using_dac)
        if (!qlcnic_83xx_read_flash_descriptor_table(adapter))
                qlcnic_83xx_read_flash_mfg_id(adapter);
 
-       err = qlcnic_83xx_idc_init(adapter);
+       err = qlcnic_83xx_get_fw_info(adapter);
        if (err)
                goto detach_mbx;
 
+       err = qlcnic_83xx_idc_init(adapter);
+       if (err)
+               goto clear_fw_info;
+
        err = qlcnic_setup_intr(adapter, 0, 0);
        if (err) {
                dev_err(&adapter->pdev->dev, "Failed to setup interrupt\n");
@@ -2242,6 +2258,9 @@ disable_mbx_intr:
 disable_intr:
        qlcnic_teardown_intr(adapter);
 
+clear_fw_info:
+       kfree(ahw->fw_info);
+
 detach_mbx:
        qlcnic_83xx_detach_mailbox_work(adapter);
        qlcnic_83xx_free_mailbox(ahw->mailbox);
index b1046c3..2097d34 100644 (file)
@@ -2402,6 +2402,7 @@ static void qlcnic_remove(struct pci_dev *pdev)
                qlcnic_83xx_free_mbx_intr(adapter);
                qlcnic_83xx_detach_mailbox_work(adapter);
                qlcnic_83xx_free_mailbox(ahw->mailbox);
+               kfree(ahw->fw_info);
        }
 
        qlcnic_detach(adapter);