diff options
author | Mateusz Kulikowski <mateusz.kulikowski@gmail.com> | 2015-10-19 23:00:26 +0300 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2015-10-25 05:23:13 +0300 |
commit | 09b1893831d23bac5d6a0a84ac578fdec7099b7d (patch) | |
tree | 465a435c5dc1e7aeeb50b5d399cdc2e9c06c598e /drivers/staging/rtl8192e | |
parent | 51dac5f09577e8300602e378d115075cf656a32c (diff) | |
download | linux-09b1893831d23bac5d6a0a84ac578fdec7099b7d.tar.xz |
staging: rtl8192e: Add _rtl92e_fw_prepare
Add function to request and prepare firmware image.
Signed-off-by: Mateusz Kulikowski <mateusz.kulikowski@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/staging/rtl8192e')
-rw-r--r-- | drivers/staging/rtl8192e/rtl8192e/r8192E_firmware.c | 71 |
1 files changed, 39 insertions, 32 deletions
diff --git a/drivers/staging/rtl8192e/rtl8192e/r8192E_firmware.c b/drivers/staging/rtl8192e/rtl8192e/r8192E_firmware.c index 2ac74843c130..b1ee65dfaf57 100644 --- a/drivers/staging/rtl8192e/rtl8192e/r8192E_firmware.c +++ b/drivers/staging/rtl8192e/rtl8192e/r8192E_firmware.c @@ -167,6 +167,36 @@ static bool _rtl92e_fw_check_ready(struct net_device *dev, return rt_status; } +static bool _rtl92e_fw_prepare(struct net_device *dev, struct rt_fw_blob *blob, + const char *name, u8 padding) +{ + const struct firmware *fw; + int rc, i; + bool ret = true; + + rc = request_firmware(&fw, name, &dev->dev); + if (rc < 0) + return false; + + if (round_up(fw->size, 4) > MAX_FW_SIZE - padding) { + netdev_err(dev, "Firmware image %s too big for the device.\n", + name); + ret = false; + goto out; + } + + if (padding) + memset(blob->data, 0, padding); + if (fw->size % 4) + memset(blob->data + padding + fw->size, 0, 4); + memcpy(blob->data + padding, fw->data, fw->size); + + blob->size = round_up(fw->size, 4) + padding; +out: + release_firmware(fw); + return ret; +} + bool rtl92e_init_fw(struct net_device *dev) { struct r8192_priv *priv = rtllib_priv(dev); @@ -202,39 +232,16 @@ bool rtl92e_init_fw(struct net_device *dev) RTL8192E_MAIN_IMG_FW, RTL8192E_DATA_IMG_FW }; - const struct firmware *fw_entry; - int rc; - - rc = request_firmware(&fw_entry, - fw_name[i], - &priv->pdev->dev); - if (rc < 0) { - RT_TRACE(COMP_FIRMWARE, - "request firmware fail!\n"); - goto download_firmware_fail; - } - if (fw_entry->size > MAX_FW_SIZE) { - RT_TRACE(COMP_FIRMWARE, - "img file size exceed the container struct buffer fail!\n"); - release_firmware(fw_entry); + int pad = 0; + + if (i == FW_INIT_STEP1_MAIN) + pad = 128; + + if (!_rtl92e_fw_prepare(dev, + &pfirmware->blobs[i], + fw_name[i], + pad)) goto download_firmware_fail; - } - - if (i != FW_INIT_STEP1_MAIN) { - memcpy(pfirmware->blobs[i].data, - fw_entry->data, fw_entry->size); - pfirmware->blobs[i].size = - fw_entry->size; - - } else { - memset(pfirmware->blobs[i].data, - 0, 128); - memcpy(&pfirmware->blobs[i].data[128], - fw_entry->data, fw_entry->size); - pfirmware->blobs[i].size = - fw_entry->size + 128; - } - release_firmware(fw_entry); } } |