Commit da94a755 authored by Radu Voicilas's avatar Radu Voicilas Committed by Greg Kroah-Hartman

Staging: rtl8192e: Small code fixes for r819xE_firmware.c

Signed-off-by: default avatarRadu Voicilas <rvoicilas@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 4db3d5e4
/* /*
* Procedure: Init boot code/firmware code/data session * Procedure: Init boot code/firmware code/data session
* *
* Description: This routine will intialize firmware. If any error occurs * Description: This routine will intialize firmware. If any error occurs
* during the initialization process, the routine shall terminate * during the initialization process, the routine shall terminate
...@@ -7,19 +7,21 @@ ...@@ -7,19 +7,21 @@
* NdisOpenFile only from MiniportInitialize. * NdisOpenFile only from MiniportInitialize.
* *
* Arguments: The pointer of the adapter * Arguments: The pointer of the adapter
*
* Returns: * Returns:
* NDIS_STATUS_FAILURE - the following initialization process * NDIS_STATUS_FAILURE - the following initialization process
* should be terminated * should be terminated
* NDIS_STATUS_SUCCESS - if firmware initialization process * NDIS_STATUS_SUCCESS - if firmware initialization process
* success * success
*/ */
#include "r8192E.h" #include "r8192E.h"
#include "r8192E_hw.h" #include "r8192E_hw.h"
#include <linux/firmware.h> #include <linux/firmware.h>
/* It should be double word alignment */ /* It should be double word alignment */
#define GET_COMMAND_PACKET_FRAG_THRESHOLD(v) (4 * (v / 4) - 8) #define GET_COMMAND_PACKET_FRAG_THRESHOLD(v) (4 * (v / 4) - 8)
enum firmware_init_step { enum firmware_init_step {
FW_INIT_STEP0_BOOT = 0, FW_INIT_STEP0_BOOT = 0,
...@@ -47,17 +49,17 @@ void firmware_init_param(struct net_device *dev) ...@@ -47,17 +49,17 @@ void firmware_init_param(struct net_device *dev)
static bool fw_download_code(struct net_device *dev, u8 *code_virtual_address, static bool fw_download_code(struct net_device *dev, u8 *code_virtual_address,
u32 buffer_len) u32 buffer_len)
{ {
struct r8192_priv *priv = ieee80211_priv(dev); struct r8192_priv *priv = ieee80211_priv(dev);
bool rt_status = true; bool rt_status = true;
u16 frag_threshold; u16 frag_threshold;
u16 frag_length, frag_offset = 0; u16 frag_length, frag_offset = 0;
int i; int i;
rt_firmware *pfirmware = priv->pFirmware; rt_firmware *pfirmware = priv->pFirmware;
struct sk_buff *skb; struct sk_buff *skb;
unsigned char *seg_ptr; unsigned char *seg_ptr;
cb_desc *tcb_desc; cb_desc *tcb_desc;
u8 bLastIniPkt; u8 bLastIniPkt;
firmware_init_param(dev); firmware_init_param(dev);
...@@ -89,10 +91,17 @@ static bool fw_download_code(struct net_device *dev, u8 *code_virtual_address, ...@@ -89,10 +91,17 @@ static bool fw_download_code(struct net_device *dev, u8 *code_virtual_address,
* Transform from little endian to big endian and pending zero * Transform from little endian to big endian and pending zero
*/ */
for (i = 0; i < frag_length; i += 4) { for (i = 0; i < frag_length; i += 4) {
*seg_ptr++ = ((i+0) < frag_length) ? code_virtual_address[i+3] : 0; *seg_ptr++ = ((i+0) < frag_length) ? \
*seg_ptr++ = ((i+1) < frag_length) ? code_virtual_address[i+2] : 0; code_virtual_address[i+3] : 0;
*seg_ptr++ = ((i+2) < frag_length) ? code_virtual_address[i+1] : 0;
*seg_ptr++ = ((i+3) < frag_length) ? code_virtual_address[i+0] : 0; *seg_ptr++ = ((i+1) < frag_length) ? \
code_virtual_address[i+2] : 0;
*seg_ptr++ = ((i+2) < frag_length) ? \
code_virtual_address[i+1] : 0;
*seg_ptr++ = ((i+3) < frag_length) ? \
code_virtual_address[i+0] : 0;
} }
tcb_desc->txbuf_size = (u16)i; tcb_desc->txbuf_size = (u16)i;
skb_put(skb, i); skb_put(skb, i);
...@@ -204,16 +213,16 @@ static bool CPUcheck_firmware_ready(struct net_device *dev) ...@@ -204,16 +213,16 @@ static bool CPUcheck_firmware_ready(struct net_device *dev)
bool init_firmware(struct net_device *dev) bool init_firmware(struct net_device *dev)
{ {
struct r8192_priv *priv = ieee80211_priv(dev); struct r8192_priv *priv = ieee80211_priv(dev);
bool rt_status = TRUE; bool rt_status = true;
u32 file_length = 0; u32 file_length = 0;
u8 *mapped_file = NULL; u8 *mapped_file = NULL;
u32 init_step = 0; u32 init_step = 0;
enum opt_rst_type rst_opt = OPT_SYSTEM_RESET; enum opt_rst_type rst_opt = OPT_SYSTEM_RESET;
enum firmware_init_step starting_state = FW_INIT_STEP0_BOOT; enum firmware_init_step starting_state = FW_INIT_STEP0_BOOT;
rt_firmware *pfirmware = priv->pFirmware; rt_firmware *pfirmware = priv->pFirmware;
const struct firmware *fw_entry; const struct firmware *fw_entry;
const char *fw_name[3] = { "RTL8192E/boot.img", const char *fw_name[3] = { "RTL8192E/boot.img",
"RTL8192E/main.img", "RTL8192E/main.img",
"RTL8192E/data.img"}; "RTL8192E/data.img"};
...@@ -240,31 +249,37 @@ bool init_firmware(struct net_device *dev) ...@@ -240,31 +249,37 @@ bool init_firmware(struct net_device *dev)
* Download boot, main, and data image for System reset. * Download boot, main, and data image for System reset.
* Download data image for firmware reseta * Download data image for firmware reseta
*/ */
for (init_step = starting_state; init_step <= FW_INIT_STEP2_DATA; init_step++) { for (init_step = starting_state; init_step <= FW_INIT_STEP2_DATA; \
init_step++) {
/* /*
* Open Image file, and map file to contineous memory if open file success. * Open Image file, and map file to contineous memory if open file success.
* or read image file from array. Default load from IMG file * or read image file from array. Default load from IMG file
*/ */
if (rst_opt == OPT_SYSTEM_RESET) { if (rst_opt == OPT_SYSTEM_RESET) {
if (pfirmware->firmware_buf_size[init_step] == 0) { if (pfirmware->firmware_buf_size[init_step] == 0) {
rc = request_firmware(&fw_entry, fw_name[init_step], &priv->pdev->dev); rc = request_firmware(&fw_entry,
fw_name[init_step], &priv->pdev->dev);
if (rc < 0) { if (rc < 0) {
RT_TRACE(COMP_FIRMWARE, "request firmware fail!\n"); RT_TRACE(COMP_FIRMWARE, "request firmware fail!\n");
goto download_firmware_fail; goto download_firmware_fail;
} }
if (fw_entry->size > sizeof(pfirmware->firmware_buf[init_step])) { if (fw_entry->size > sizeof(pfirmware->firmware_buf[init_step])) {
RT_TRACE(COMP_FIRMWARE, "img file size exceed the container buffer fail!\n"); RT_TRACE(COMP_FIRMWARE, \
"img file size exceed the container buffer fail!\n");
goto download_firmware_fail; goto download_firmware_fail;
} }
if (init_step != FW_INIT_STEP1_MAIN) { if (init_step != FW_INIT_STEP1_MAIN) {
memcpy(pfirmware->firmware_buf[init_step], fw_entry->data, fw_entry->size); memcpy(pfirmware->firmware_buf[init_step],
fw_entry->data, fw_entry->size);
pfirmware->firmware_buf_size[init_step] = fw_entry->size; pfirmware->firmware_buf_size[init_step] = fw_entry->size;
} else { } else {
memset(pfirmware->firmware_buf[init_step], 0, 128); memset(pfirmware->firmware_buf[init_step], 0, 128);
memcpy(&pfirmware->firmware_buf[init_step][128], fw_entry->data, fw_entry->size); memcpy(&pfirmware->firmware_buf[init_step][128], fw_entry->data,
fw_entry->size);
pfirmware->firmware_buf_size[init_step] = fw_entry->size+128; pfirmware->firmware_buf_size[init_step] = fw_entry->size+128;
} }
...@@ -273,6 +288,7 @@ bool init_firmware(struct net_device *dev) ...@@ -273,6 +288,7 @@ bool init_firmware(struct net_device *dev)
} }
mapped_file = pfirmware->firmware_buf[init_step]; mapped_file = pfirmware->firmware_buf[init_step];
file_length = pfirmware->firmware_buf_size[init_step]; file_length = pfirmware->firmware_buf_size[init_step];
} else if (rst_opt == OPT_FIRMWARE_RESET) { } else if (rst_opt == OPT_FIRMWARE_RESET) {
/* we only need to download data.img here */ /* we only need to download data.img here */
mapped_file = pfirmware->firmware_buf[init_step]; mapped_file = pfirmware->firmware_buf[init_step];
...@@ -346,7 +362,6 @@ bool init_firmware(struct net_device *dev) ...@@ -346,7 +362,6 @@ bool init_firmware(struct net_device *dev)
download_firmware_fail: download_firmware_fail:
RT_TRACE(COMP_ERR, "ERR in %s()\n", __func__); RT_TRACE(COMP_ERR, "ERR in %s()\n", __func__);
rt_status = FALSE; rt_status = false;
return rt_status; return rt_status;
} }
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