Skip to content

Commit

Permalink
iwlwifi: Support for uCode without init and bsm section
Browse files Browse the repository at this point in the history
This patch enables loading fw w/o init and bsm section. It also provides
general cleanup of the rutine.

Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Signed-off-by: Gregory Greenman <gregory.greenman@intel.com>
Signed-off-by: Zhu Yi <yi.zhu@intel.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
  • Loading branch information
Tomas Winkler authored and David S. Miller committed Jan 28, 2008
1 parent 5a6012e commit 90e759d
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 130 deletions.
120 changes: 56 additions & 64 deletions drivers/net/wireless/iwlwifi/iwl3945-base.c
Original file line number Diff line number Diff line change
Expand Up @@ -5767,6 +5767,12 @@ static void iwl3945_nic_start(struct iwl3945_priv *priv)
iwl3945_write32(priv, CSR_RESET, 0);
}

static int iwl3945_alloc_fw_desc(struct pci_dev *pci_dev, struct fw_desc *desc)
{
desc->v_addr = pci_alloc_consistent(pci_dev, desc->len, &desc->p_addr);
return (desc->v_addr != NULL) ? 0 : -ENOMEM;
}

/**
* iwl3945_read_ucode - Read uCode images from disk file.
*
Expand All @@ -5775,7 +5781,7 @@ static void iwl3945_nic_start(struct iwl3945_priv *priv)
static int iwl3945_read_ucode(struct iwl3945_priv *priv)
{
struct iwl3945_ucode *ucode;
int rc = 0;
int ret = 0;
const struct firmware *ucode_raw;
/* firmware file name contains uCode/driver compatibility version */
const char *name = "iwlwifi-3945" IWL3945_UCODE_API ".ucode";
Expand All @@ -5785,9 +5791,10 @@ static int iwl3945_read_ucode(struct iwl3945_priv *priv)

/* Ask kernel firmware_class module to get the boot firmware off disk.
* request_firmware() is synchronous, file is in memory on return. */
rc = request_firmware(&ucode_raw, name, &priv->pci_dev->dev);
if (rc < 0) {
IWL_ERROR("%s firmware file req failed: Reason %d\n", name, rc);
ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev);
if (ret < 0) {
IWL_ERROR("%s firmware file req failed: Reason %d\n",
name, ret);
goto error;
}

Expand All @@ -5797,7 +5804,7 @@ static int iwl3945_read_ucode(struct iwl3945_priv *priv)
/* Make sure that we got at least our header! */
if (ucode_raw->size < sizeof(*ucode)) {
IWL_ERROR("File size way too small!\n");
rc = -EINVAL;
ret = -EINVAL;
goto err_release;
}

Expand Down Expand Up @@ -5825,43 +5832,40 @@ static int iwl3945_read_ucode(struct iwl3945_priv *priv)

IWL_DEBUG_INFO("uCode file size %d too small\n",
(int)ucode_raw->size);
rc = -EINVAL;
ret = -EINVAL;
goto err_release;
}

/* Verify that uCode images will fit in card's SRAM */
if (inst_size > IWL_MAX_INST_SIZE) {
IWL_DEBUG_INFO("uCode instr len %d too large to fit in card\n",
(int)inst_size);
rc = -EINVAL;
IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
inst_size);
ret = -EINVAL;
goto err_release;
}

if (data_size > IWL_MAX_DATA_SIZE) {
IWL_DEBUG_INFO("uCode data len %d too large to fit in card\n",
(int)data_size);
rc = -EINVAL;
IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
data_size);
ret = -EINVAL;
goto err_release;
}
if (init_size > IWL_MAX_INST_SIZE) {
IWL_DEBUG_INFO
("uCode init instr len %d too large to fit in card\n",
(int)init_size);
rc = -EINVAL;
IWL_DEBUG_INFO("uCode init instr len %d too large to fit in\n",
init_size);
ret = -EINVAL;
goto err_release;
}
if (init_data_size > IWL_MAX_DATA_SIZE) {
IWL_DEBUG_INFO
("uCode init data len %d too large to fit in card\n",
(int)init_data_size);
rc = -EINVAL;
IWL_DEBUG_INFO("uCode init data len %d too large to fit in\n",
init_data_size);
ret = -EINVAL;
goto err_release;
}
if (boot_size > IWL_MAX_BSM_SIZE) {
IWL_DEBUG_INFO
("uCode boot instr len %d too large to fit in bsm\n",
(int)boot_size);
rc = -EINVAL;
IWL_DEBUG_INFO("uCode boot instr len %d too large to fit in\n",
boot_size);
ret = -EINVAL;
goto err_release;
}

Expand All @@ -5871,56 +5875,45 @@ static int iwl3945_read_ucode(struct iwl3945_priv *priv)
* 1) unmodified from disk
* 2) backup cache for save/restore during power-downs */
priv->ucode_code.len = inst_size;
priv->ucode_code.v_addr =
pci_alloc_consistent(priv->pci_dev,
priv->ucode_code.len,
&(priv->ucode_code.p_addr));
iwl3945_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);

priv->ucode_data.len = data_size;
priv->ucode_data.v_addr =
pci_alloc_consistent(priv->pci_dev,
priv->ucode_data.len,
&(priv->ucode_data.p_addr));
iwl3945_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);

priv->ucode_data_backup.len = data_size;
priv->ucode_data_backup.v_addr =
pci_alloc_consistent(priv->pci_dev,
priv->ucode_data_backup.len,
&(priv->ucode_data_backup.p_addr));
iwl3945_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);

if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
!priv->ucode_data_backup.v_addr)
goto err_pci_alloc;

/* Initialization instructions and data */
priv->ucode_init.len = init_size;
priv->ucode_init.v_addr =
pci_alloc_consistent(priv->pci_dev,
priv->ucode_init.len,
&(priv->ucode_init.p_addr));

priv->ucode_init_data.len = init_data_size;
priv->ucode_init_data.v_addr =
pci_alloc_consistent(priv->pci_dev,
priv->ucode_init_data.len,
&(priv->ucode_init_data.p_addr));
if (init_size && init_data_size) {
priv->ucode_init.len = init_size;
iwl3945_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);

priv->ucode_init_data.len = init_data_size;
iwl3945_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);

if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
goto err_pci_alloc;
}

/* Bootstrap (instructions only, no data) */
priv->ucode_boot.len = boot_size;
priv->ucode_boot.v_addr =
pci_alloc_consistent(priv->pci_dev,
priv->ucode_boot.len,
&(priv->ucode_boot.p_addr));
if (boot_size) {
priv->ucode_boot.len = boot_size;
iwl3945_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);

if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr ||
!priv->ucode_boot.v_addr || !priv->ucode_data_backup.v_addr)
goto err_pci_alloc;
if (!priv->ucode_boot.v_addr)
goto err_pci_alloc;
}

/* Copy images into buffers for card's bus-master reads ... */

/* Runtime instructions (first block of data in file) */
src = &ucode->data[0];
len = priv->ucode_code.len;
IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %d\n",
(int)len);
IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len);
memcpy(priv->ucode_code.v_addr, src, len);
IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
Expand All @@ -5929,17 +5922,16 @@ static int iwl3945_read_ucode(struct iwl3945_priv *priv)
* NOTE: Copy into backup buffer will be done in iwl3945_up() */
src = &ucode->data[inst_size];
len = priv->ucode_data.len;
IWL_DEBUG_INFO("Copying (but not loading) uCode data len %d\n",
(int)len);
IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len);
memcpy(priv->ucode_data.v_addr, src, len);
memcpy(priv->ucode_data_backup.v_addr, src, len);

/* Initialization instructions (3rd block) */
if (init_size) {
src = &ucode->data[inst_size + data_size];
len = priv->ucode_init.len;
IWL_DEBUG_INFO("Copying (but not loading) init instr len %d\n",
(int)len);
IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
len);
memcpy(priv->ucode_init.v_addr, src, len);
}

Expand All @@ -5965,14 +5957,14 @@ static int iwl3945_read_ucode(struct iwl3945_priv *priv)

err_pci_alloc:
IWL_ERROR("failed to allocate pci memory\n");
rc = -ENOMEM;
ret = -ENOMEM;
iwl3945_dealloc_ucode_pci(priv);

err_release:
release_firmware(ucode_raw);

error:
return rc;
return ret;
}


Expand Down
Loading

0 comments on commit 90e759d

Please sign in to comment.