Commit dbf28e21 authored by Johannes Berg's avatar Johannes Berg Committed by Wey-Yi Guy

iwlagn: combine firmware code/data

On new hardware, ucode images always come in
pairs: code and data. Therefore, combine the
variables into an appropriate struct and use
that when both code and data are needed.

Also, combine allocation and copying so that
we have less code in total.
Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
Signed-off-by: default avatarWey-Yi Guy <wey-yi.w.guy@intel.com>
parent ca7966c8
...@@ -161,17 +161,16 @@ static int iwlagn_load_section(struct iwl_priv *priv, const char *name, ...@@ -161,17 +161,16 @@ static int iwlagn_load_section(struct iwl_priv *priv, const char *name,
} }
static int iwlagn_load_given_ucode(struct iwl_priv *priv, static int iwlagn_load_given_ucode(struct iwl_priv *priv,
struct fw_desc *inst_image, struct fw_img *image)
struct fw_desc *data_image)
{ {
int ret = 0; int ret = 0;
ret = iwlagn_load_section(priv, "INST", inst_image, ret = iwlagn_load_section(priv, "INST", &image->code,
IWLAGN_RTC_INST_LOWER_BOUND); IWLAGN_RTC_INST_LOWER_BOUND);
if (ret) if (ret)
return ret; return ret;
return iwlagn_load_section(priv, "DATA", data_image, return iwlagn_load_section(priv, "DATA", &image->data,
IWLAGN_RTC_DATA_LOWER_BOUND); IWLAGN_RTC_DATA_LOWER_BOUND);
} }
...@@ -557,16 +556,16 @@ static void iwl_print_mismatch_inst(struct iwl_priv *priv, ...@@ -557,16 +556,16 @@ static void iwl_print_mismatch_inst(struct iwl_priv *priv,
* iwl_verify_ucode - determine which instruction image is in SRAM, * iwl_verify_ucode - determine which instruction image is in SRAM,
* and verify its contents * and verify its contents
*/ */
static int iwl_verify_ucode(struct iwl_priv *priv, struct fw_desc *fw_desc) static int iwl_verify_ucode(struct iwl_priv *priv, struct fw_img *img)
{ {
if (!iwlcore_verify_inst_sparse(priv, fw_desc)) { if (!iwlcore_verify_inst_sparse(priv, &img->code)) {
IWL_DEBUG_INFO(priv, "uCode is good in inst SRAM\n"); IWL_DEBUG_INFO(priv, "uCode is good in inst SRAM\n");
return 0; return 0;
} }
IWL_ERR(priv, "UCODE IMAGE IN INSTRUCTION SRAM NOT VALID!!\n"); IWL_ERR(priv, "UCODE IMAGE IN INSTRUCTION SRAM NOT VALID!!\n");
iwl_print_mismatch_inst(priv, fw_desc); iwl_print_mismatch_inst(priv, &img->code);
return -EIO; return -EIO;
} }
...@@ -602,8 +601,7 @@ static void iwlagn_alive_fn(struct iwl_priv *priv, ...@@ -602,8 +601,7 @@ static void iwlagn_alive_fn(struct iwl_priv *priv,
#define UCODE_CALIB_TIMEOUT (2*HZ) #define UCODE_CALIB_TIMEOUT (2*HZ)
int iwlagn_load_ucode_wait_alive(struct iwl_priv *priv, int iwlagn_load_ucode_wait_alive(struct iwl_priv *priv,
struct fw_desc *inst_image, struct fw_img *image,
struct fw_desc *data_image,
int subtype, int alternate_subtype) int subtype, int alternate_subtype)
{ {
struct iwl_notification_wait alive_wait; struct iwl_notification_wait alive_wait;
...@@ -621,7 +619,7 @@ int iwlagn_load_ucode_wait_alive(struct iwl_priv *priv, ...@@ -621,7 +619,7 @@ int iwlagn_load_ucode_wait_alive(struct iwl_priv *priv,
old_type = priv->ucode_type; old_type = priv->ucode_type;
priv->ucode_type = subtype; priv->ucode_type = subtype;
ret = iwlagn_load_given_ucode(priv, inst_image, data_image); ret = iwlagn_load_given_ucode(priv, image);
if (ret) { if (ret) {
priv->ucode_type = old_type; priv->ucode_type = old_type;
iwlagn_remove_notification(priv, &alive_wait); iwlagn_remove_notification(priv, &alive_wait);
...@@ -656,7 +654,7 @@ int iwlagn_load_ucode_wait_alive(struct iwl_priv *priv, ...@@ -656,7 +654,7 @@ int iwlagn_load_ucode_wait_alive(struct iwl_priv *priv,
return -EIO; return -EIO;
} }
ret = iwl_verify_ucode(priv, inst_image); ret = iwl_verify_ucode(priv, image);
if (ret) { if (ret) {
priv->ucode_type = old_type; priv->ucode_type = old_type;
return ret; return ret;
...@@ -684,7 +682,7 @@ int iwlagn_run_init_ucode(struct iwl_priv *priv) ...@@ -684,7 +682,7 @@ int iwlagn_run_init_ucode(struct iwl_priv *priv)
lockdep_assert_held(&priv->mutex); lockdep_assert_held(&priv->mutex);
/* No init ucode required? Curious, but maybe ok */ /* No init ucode required? Curious, but maybe ok */
if (!priv->ucode_init.len) if (!priv->ucode_init.code.len)
return 0; return 0;
if (priv->ucode_type != UCODE_SUBTYPE_NONE_LOADED) if (priv->ucode_type != UCODE_SUBTYPE_NONE_LOADED)
...@@ -696,7 +694,6 @@ int iwlagn_run_init_ucode(struct iwl_priv *priv) ...@@ -696,7 +694,6 @@ int iwlagn_run_init_ucode(struct iwl_priv *priv)
/* Will also start the device */ /* Will also start the device */
ret = iwlagn_load_ucode_wait_alive(priv, &priv->ucode_init, ret = iwlagn_load_ucode_wait_alive(priv, &priv->ucode_init,
&priv->ucode_init_data,
UCODE_SUBTYPE_INIT, -1); UCODE_SUBTYPE_INIT, -1);
if (ret) if (ret)
goto error; goto error;
......
...@@ -1173,12 +1173,42 @@ static struct attribute_group iwl_attribute_group = { ...@@ -1173,12 +1173,42 @@ static struct attribute_group iwl_attribute_group = {
* *
******************************************************************************/ ******************************************************************************/
static void iwl_free_fw_desc(struct pci_dev *pci_dev, struct fw_desc *desc)
{
if (desc->v_addr)
dma_free_coherent(&pci_dev->dev, desc->len,
desc->v_addr, desc->p_addr);
desc->v_addr = NULL;
desc->len = 0;
}
static void iwl_free_fw_img(struct pci_dev *pci_dev, struct fw_img *img)
{
iwl_free_fw_desc(pci_dev, &img->code);
iwl_free_fw_desc(pci_dev, &img->data);
}
static int iwl_alloc_fw_desc(struct pci_dev *pci_dev, struct fw_desc *desc,
const void *data, size_t len)
{
if (!len) {
desc->v_addr = NULL;
return -EINVAL;
}
desc->v_addr = dma_alloc_coherent(&pci_dev->dev, len,
&desc->p_addr, GFP_KERNEL);
if (!desc->v_addr)
return -ENOMEM;
desc->len = len;
memcpy(desc->v_addr, data, len);
return 0;
}
static void iwl_dealloc_ucode_pci(struct iwl_priv *priv) static void iwl_dealloc_ucode_pci(struct iwl_priv *priv)
{ {
iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code); iwl_free_fw_img(priv->pci_dev, &priv->ucode_rt);
iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data); iwl_free_fw_img(priv->pci_dev, &priv->ucode_init);
iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
} }
struct iwlagn_ucode_capabilities { struct iwlagn_ucode_capabilities {
...@@ -1647,24 +1677,20 @@ static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context) ...@@ -1647,24 +1677,20 @@ static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context)
/* Runtime instructions and 2 copies of data: /* Runtime instructions and 2 copies of data:
* 1) unmodified from disk * 1) unmodified from disk
* 2) backup cache for save/restore during power-downs */ * 2) backup cache for save/restore during power-downs */
priv->ucode_code.len = pieces.inst_size; if (iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_rt.code,
iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code); pieces.inst, pieces.inst_size))
goto err_pci_alloc;
priv->ucode_data.len = pieces.data_size; if (iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_rt.data,
iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data); pieces.data, pieces.data_size))
if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr)
goto err_pci_alloc; goto err_pci_alloc;
/* Initialization instructions and data */ /* Initialization instructions and data */
if (pieces.init_size && pieces.init_data_size) { if (pieces.init_size && pieces.init_data_size) {
priv->ucode_init.len = pieces.init_size; if (iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init.code,
iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init); pieces.init, pieces.init_size))
goto err_pci_alloc;
priv->ucode_init_data.len = pieces.init_data_size; if (iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init.data,
iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data); pieces.init_data, pieces.init_data_size))
if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
goto err_pci_alloc; goto err_pci_alloc;
} }
...@@ -1701,39 +1727,6 @@ static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context) ...@@ -1701,39 +1727,6 @@ static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context)
else else
priv->cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM; priv->cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
/* Copy images into buffers for card's bus-master reads ... */
/* Runtime instructions (first block of data in file) */
IWL_DEBUG_INFO(priv, "Copying (but not loading) uCode instr len %Zd\n",
pieces.inst_size);
memcpy(priv->ucode_code.v_addr, pieces.inst, pieces.inst_size);
IWL_DEBUG_INFO(priv, "uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
/*
* Runtime data
* NOTE: Copy into backup buffer will be done in iwl_up()
*/
IWL_DEBUG_INFO(priv, "Copying (but not loading) uCode data len %Zd\n",
pieces.data_size);
memcpy(priv->ucode_data.v_addr, pieces.data, pieces.data_size);
/* Initialization instructions */
if (pieces.init_size) {
IWL_DEBUG_INFO(priv, "Copying (but not loading) init instr len %Zd\n",
pieces.init_size);
memcpy(priv->ucode_init.v_addr, pieces.init, pieces.init_size);
}
/* Initialization data */
if (pieces.init_data_size) {
IWL_DEBUG_INFO(priv, "Copying (but not loading) init data len %Zd\n",
pieces.init_data_size);
memcpy(priv->ucode_init_data.v_addr, pieces.init_data,
pieces.init_data_size);
}
/* /*
* figure out the offset of chain noise reset and gain commands * figure out the offset of chain noise reset and gain commands
* base on the size of standard phy calibration commands table size * base on the size of standard phy calibration commands table size
...@@ -2450,8 +2443,7 @@ static int __iwl_up(struct iwl_priv *priv) ...@@ -2450,8 +2443,7 @@ static int __iwl_up(struct iwl_priv *priv)
} }
ret = iwlagn_load_ucode_wait_alive(priv, ret = iwlagn_load_ucode_wait_alive(priv,
&priv->ucode_code, &priv->ucode_rt,
&priv->ucode_data,
UCODE_SUBTYPE_REGULAR, UCODE_SUBTYPE_REGULAR,
UCODE_SUBTYPE_REGULAR_NEW); UCODE_SUBTYPE_REGULAR_NEW);
if (ret) { if (ret) {
......
...@@ -164,8 +164,7 @@ int iwlagn_send_bt_env(struct iwl_priv *priv, u8 action, u8 type); ...@@ -164,8 +164,7 @@ int iwlagn_send_bt_env(struct iwl_priv *priv, u8 action, u8 type);
void iwlagn_send_prio_tbl(struct iwl_priv *priv); void iwlagn_send_prio_tbl(struct iwl_priv *priv);
int iwlagn_run_init_ucode(struct iwl_priv *priv); int iwlagn_run_init_ucode(struct iwl_priv *priv);
int iwlagn_load_ucode_wait_alive(struct iwl_priv *priv, int iwlagn_load_ucode_wait_alive(struct iwl_priv *priv,
struct fw_desc *inst_image, struct fw_img *image,
struct fw_desc *data_image,
int subtype, int alternate_subtype); int subtype, int alternate_subtype);
/* lib */ /* lib */
......
...@@ -227,9 +227,9 @@ static ssize_t iwl_dbgfs_sram_read(struct file *file, ...@@ -227,9 +227,9 @@ static ssize_t iwl_dbgfs_sram_read(struct file *file,
if (!priv->dbgfs_sram_offset && !priv->dbgfs_sram_len) { if (!priv->dbgfs_sram_offset && !priv->dbgfs_sram_len) {
priv->dbgfs_sram_offset = 0x800000; priv->dbgfs_sram_offset = 0x800000;
if (priv->ucode_type == UCODE_SUBTYPE_INIT) if (priv->ucode_type == UCODE_SUBTYPE_INIT)
priv->dbgfs_sram_len = priv->ucode_init_data.len; priv->dbgfs_sram_len = priv->ucode_init.data.len;
else else
priv->dbgfs_sram_len = priv->ucode_data.len; priv->dbgfs_sram_len = priv->ucode_rt.data.len;
} }
len = priv->dbgfs_sram_len; len = priv->dbgfs_sram_len;
......
...@@ -479,6 +479,10 @@ struct fw_desc { ...@@ -479,6 +479,10 @@ struct fw_desc {
u32 len; /* bytes */ u32 len; /* bytes */
}; };
struct fw_img {
struct fw_desc code, data;
};
/* v1/v2 uCode file layout */ /* v1/v2 uCode file layout */
struct iwl_ucode_header { struct iwl_ucode_header {
__le32 ver; /* major/minor/API/serial */ __le32 ver; /* major/minor/API/serial */
...@@ -1266,10 +1270,9 @@ struct iwl_priv { ...@@ -1266,10 +1270,9 @@ struct iwl_priv {
int fw_index; /* firmware we're trying to load */ int fw_index; /* firmware we're trying to load */
u32 ucode_ver; /* version of ucode, copy of u32 ucode_ver; /* version of ucode, copy of
iwl_ucode.ver */ iwl_ucode.ver */
struct fw_desc ucode_code; /* runtime inst */ struct fw_img ucode_rt;
struct fw_desc ucode_data; /* runtime data original */ struct fw_img ucode_init;
struct fw_desc ucode_init; /* initialization inst */
struct fw_desc ucode_init_data; /* initialization data */
enum iwlagn_ucode_subtype ucode_type; enum iwlagn_ucode_subtype ucode_type;
u8 ucode_write_complete; /* the image write is complete */ u8 ucode_write_complete; /* the image write is complete */
char firmware_name[25]; char firmware_name[25];
......
...@@ -64,30 +64,6 @@ static inline int iwl_queue_dec_wrap(int index, int n_bd) ...@@ -64,30 +64,6 @@ static inline int iwl_queue_dec_wrap(int index, int n_bd)
return --index & (n_bd - 1); return --index & (n_bd - 1);
} }
/* TODO: Move fw_desc functions to iwl-pci.ko */
static inline void iwl_free_fw_desc(struct pci_dev *pci_dev,
struct fw_desc *desc)
{
if (desc->v_addr)
dma_free_coherent(&pci_dev->dev, desc->len,
desc->v_addr, desc->p_addr);
desc->v_addr = NULL;
desc->len = 0;
}
static inline int iwl_alloc_fw_desc(struct pci_dev *pci_dev,
struct fw_desc *desc)
{
if (!desc->len) {
desc->v_addr = NULL;
return -EINVAL;
}
desc->v_addr = dma_alloc_coherent(&pci_dev->dev, desc->len,
&desc->p_addr, GFP_KERNEL);
return (desc->v_addr != NULL) ? 0 : -ENOMEM;
}
/* /*
* we have 8 bits used like this: * we have 8 bits used like this:
* *
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment