Commit f06ebfee authored by Florian Schilhabel's avatar Florian Schilhabel Committed by Greg Kroah-Hartman

Staging: rtl8192su: refactored FirmwareDownload92S

added a new function: FirmwareRequest92S

This function(instead of FirmwareDownload92S) is now responsible for
requesting the firmware.

FirmwareDownload92S is now easier to read, smaller and follows kernel
coding style.

plus cosmetics.
Signed-off-by: default avatarFlorian Schilhabel <florian.c.schilhabel@googlemail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 8dbe821e
...@@ -338,46 +338,33 @@ void FirmwareHeaderPriveUpdate(struct net_device *dev, PRT_8192S_FIRMWARE_PRIV ...@@ -338,46 +338,33 @@ void FirmwareHeaderPriveUpdate(struct net_device *dev, PRT_8192S_FIRMWARE_PRIV
pFwPriv->rf_config = FirmwareHeaderMapRfType(dev); pFwPriv->rf_config = FirmwareHeaderMapRfType(dev);
} }
bool FirmwareRequest92S(struct net_device *dev, rt_firmware *pFirmware)
bool FirmwareDownload92S(struct net_device *dev)
{ {
struct r8192_priv *priv = ieee80211_priv(dev); struct r8192_priv *priv = ieee80211_priv(dev);
bool rtStatus = true; bool rtStatus = true;
const char *pFwImageFileName[1] = {"RTL8192SU/rtl8192sfw.bin"}; const char *pFwImageFileName[1] = {"RTL8192SU/rtl8192sfw.bin"};
u8 *pucMappedFile = NULL; u8 *pucMappedFile = NULL;
u32 ulFileLength, ulInitStep = 0; u32 ulInitStep = 0;
u8 FwHdrSize = RT_8192S_FIRMWARE_HDR_SIZE; u8 FwHdrSize = RT_8192S_FIRMWARE_HDR_SIZE;
rt_firmware *pFirmware = priv->pFirmware;
u8 FwStatus = FW_STATUS_INIT;
PRT_8192S_FIRMWARE_HDR pFwHdr = NULL; PRT_8192S_FIRMWARE_HDR pFwHdr = NULL;
PRT_8192S_FIRMWARE_PRIV pFwPriv = NULL; u32 file_length = 0;
int rc; int rc;
const struct firmware *fw_entry; const struct firmware *fw_entry;
u32 file_length = 0;
pFirmware->FWStatus = FW_STATUS_INIT;
RT_TRACE(COMP_FIRMWARE, " --->FirmwareDownload92S()\n"); rc = request_firmware(&fw_entry,
pFwImageFileName[ulInitStep],
&priv->udev->dev);
if (rc < 0)
goto RequestFirmware_Fail;
/* if (fw_entry->size > sizeof(pFirmware->szFwTmpBuffer)) {
* Load the firmware from RTL8192SU/rtl8192sfw.bin RT_TRACE(COMP_ERR, "%s(): image file too large"
*/ "for container buffer", __func__);
if(pFirmware->szFwTmpBufferLen == 0)
{
rc = request_firmware(&fw_entry, pFwImageFileName[ulInitStep],&priv->udev->dev);
if(rc < 0 ) {
RT_TRACE(COMP_ERR, "request firmware fail!\n");
goto DownloadFirmware_Fail;
}
if(fw_entry->size > sizeof(pFirmware->szFwTmpBuffer)) {
RT_TRACE(COMP_ERR, "img file size exceed the container buffer fail!\n");
release_firmware(fw_entry); release_firmware(fw_entry);
goto DownloadFirmware_Fail; goto RequestFirmware_Fail;
} }
memcpy(pFirmware->szFwTmpBuffer,fw_entry->data,fw_entry->size); memcpy(pFirmware->szFwTmpBuffer, fw_entry->data, fw_entry->size);
pFirmware->szFwTmpBufferLen = fw_entry->size; pFirmware->szFwTmpBufferLen = fw_entry->size;
release_firmware(fw_entry); release_firmware(fw_entry);
...@@ -387,39 +374,70 @@ bool FirmwareDownload92S(struct net_device *dev) ...@@ -387,39 +374,70 @@ bool FirmwareDownload92S(struct net_device *dev)
/* Retrieve FW header. */ /* Retrieve FW header. */
pFirmware->pFwHeader = (PRT_8192S_FIRMWARE_HDR) pucMappedFile; pFirmware->pFwHeader = (PRT_8192S_FIRMWARE_HDR) pucMappedFile;
pFwHdr = pFirmware->pFwHeader; pFwHdr = pFirmware->pFwHeader;
RT_TRACE(COMP_FIRMWARE,"signature:%x, version:%x, size:%x, imemsize:%x, sram size:%x\n", \
pFwHdr->Signature, pFwHdr->Version, pFwHdr->DMEMSize, \ RT_TRACE(COMP_FIRMWARE, "%s(): signature: %x, version: %x, "
pFwHdr->IMG_IMEM_SIZE, pFwHdr->IMG_SRAM_SIZE); "size: %x, imemsize: %x, sram size: %x",
pFirmware->FirmwareVersion = byte(pFwHdr->Version ,0); __func__, pFwHdr->Signature, pFwHdr->Version,
if ((pFwHdr->IMG_IMEM_SIZE==0) || (pFwHdr->IMG_IMEM_SIZE > sizeof(pFirmware->FwIMEM))) { pFwHdr->DMEMSize, pFwHdr->IMG_IMEM_SIZE,
RT_TRACE(COMP_ERR, "%s: memory for data image is less than IMEM required\n",\ pFwHdr->IMG_SRAM_SIZE);
__FUNCTION__);
goto DownloadFirmware_Fail; pFirmware->FirmwareVersion = byte(pFwHdr->Version , 0);
if ((pFwHdr->IMG_IMEM_SIZE == 0) ||
(pFwHdr->IMG_IMEM_SIZE > sizeof(pFirmware->FwIMEM))) {
RT_TRACE(COMP_ERR, "%s(): memory for data image is less than"
" IMEM requires", __func__);
goto RequestFirmware_Fail;
} else { } else {
pucMappedFile+=FwHdrSize; pucMappedFile += FwHdrSize;
/* Retrieve IMEM image. */ /* Retrieve IMEM image. */
memcpy(pFirmware->FwIMEM, pucMappedFile, pFwHdr->IMG_IMEM_SIZE); memcpy(pFirmware->FwIMEM, pucMappedFile, pFwHdr->IMG_IMEM_SIZE);
pFirmware->FwIMEMLen = pFwHdr->IMG_IMEM_SIZE; pFirmware->FwIMEMLen = pFwHdr->IMG_IMEM_SIZE;
} }
if (pFwHdr->IMG_SRAM_SIZE > sizeof(pFirmware->FwEMEM)) { if (pFwHdr->IMG_SRAM_SIZE > sizeof(pFirmware->FwEMEM)) {
RT_TRACE(COMP_ERR, "%s: memory for data image is less than EMEM required\n",\ RT_TRACE(COMP_ERR, "%s(): memory for data image is less than"
__FUNCTION__); " EMEM requires", __func__);
goto DownloadFirmware_Fail; goto RequestFirmware_Fail;
} else { } else {
pucMappedFile += pFirmware->FwIMEMLen; pucMappedFile += pFirmware->FwIMEMLen;
/* Retriecve EMEM image */ /* Retriecve EMEM image */
memcpy(pFirmware->FwEMEM, pucMappedFile, pFwHdr->IMG_SRAM_SIZE);//===>6 memcpy(pFirmware->FwEMEM, pucMappedFile, pFwHdr->IMG_SRAM_SIZE);
pFirmware->FwEMEMLen = pFwHdr->IMG_SRAM_SIZE; pFirmware->FwEMEMLen = pFwHdr->IMG_SRAM_SIZE;
} }
} return rtStatus;
RequestFirmware_Fail:
RT_TRACE(COMP_ERR, "%s(): failed with TCR-Status: %x\n",
__func__, read_nic_word(dev, TCR));
rtStatus = false;
return rtStatus;
}
bool FirmwareDownload92S(struct net_device *dev)
{
struct r8192_priv *priv = ieee80211_priv(dev);
bool rtStatus = true;
u8 *pucMappedFile = NULL;
u32 ulFileLength;
u8 FwHdrSize = RT_8192S_FIRMWARE_HDR_SIZE;
rt_firmware *pFirmware = priv->pFirmware;
u8 FwStatus = FW_STATUS_INIT;
PRT_8192S_FIRMWARE_HDR pFwHdr = NULL;
PRT_8192S_FIRMWARE_PRIV pFwPriv = NULL;
pFirmware->FWStatus = FW_STATUS_INIT;
/*
* Load the firmware from RTL8192SU/rtl8192sfw.bin if necessary
*/
if (pFirmware->szFwTmpBufferLen == 0) {
if (FirmwareRequest92S(dev, pFirmware) != true)
goto DownloadFirmware_Fail;
}
FwStatus = FirmwareGetNextStatus(pFirmware->FWStatus); FwStatus = FirmwareGetNextStatus(pFirmware->FWStatus);
while(FwStatus!= FW_STATUS_READY) while (FwStatus != FW_STATUS_READY) {
{ /* Image buffer redirection. */
// Image buffer redirection. switch (FwStatus) {
switch(FwStatus)
{
case FW_STATUS_LOAD_IMEM: case FW_STATUS_LOAD_IMEM:
pucMappedFile = pFirmware->FwIMEM; pucMappedFile = pFirmware->FwIMEM;
ulFileLength = pFirmware->FwIMEMLen; ulFileLength = pFirmware->FwIMEMLen;
...@@ -431,12 +449,15 @@ bool FirmwareDownload92S(struct net_device *dev) ...@@ -431,12 +449,15 @@ bool FirmwareDownload92S(struct net_device *dev)
break; break;
case FW_STATUS_LOAD_DMEM: case FW_STATUS_LOAD_DMEM:
/* <Roger_Notes> Partial update the content of header private. 2008.12.18 */ /* Partial update the content of private header */
pFwHdr = pFirmware->pFwHeader; pFwHdr = pFirmware->pFwHeader;
pFwPriv = (PRT_8192S_FIRMWARE_PRIV)&pFwHdr->FWPriv; pFwPriv = (PRT_8192S_FIRMWARE_PRIV)&pFwHdr->FWPriv;
FirmwareHeaderPriveUpdate(dev, pFwPriv); FirmwareHeaderPriveUpdate(dev, pFwPriv);
pucMappedFile = (u8*)(pFirmware->pFwHeader)+RT_8192S_FIRMWARE_HDR_EXCLUDE_PRI_SIZE; pucMappedFile = (u8 *)(pFirmware->pFwHeader) +
ulFileLength = FwHdrSize-RT_8192S_FIRMWARE_HDR_EXCLUDE_PRI_SIZE; RT_8192S_FIRMWARE_HDR_EXCLUDE_PRI_SIZE;
ulFileLength = FwHdrSize -
RT_8192S_FIRMWARE_HDR_EXCLUDE_PRI_SIZE;
break; break;
default: default:
...@@ -445,36 +466,31 @@ bool FirmwareDownload92S(struct net_device *dev) ...@@ -445,36 +466,31 @@ bool FirmwareDownload92S(struct net_device *dev)
break; break;
} }
//3// /* <2> Download image file */
//3// <2> Download image file
//3 // rtStatus = FirmwareDownloadCode(dev,
rtStatus = FirmwareDownloadCode(dev, pucMappedFile, ulFileLength); pucMappedFile,
ulFileLength);
if(rtStatus != true) if(rtStatus != true)
{
RT_TRACE(COMP_ERR, "FirmwareDownloadCode() fail ! \n" );
goto DownloadFirmware_Fail; goto DownloadFirmware_Fail;
}
//3// /* <3> Check whether load FW process is ready */
//3// <3> Check whether load FW process is ready
//3 //
rtStatus = FirmwareCheckReady(dev, FwStatus); rtStatus = FirmwareCheckReady(dev, FwStatus);
if(rtStatus != true) if(rtStatus != true)
{
RT_TRACE(COMP_ERR, "FirmwareDownloadCode() fail ! \n");
goto DownloadFirmware_Fail; goto DownloadFirmware_Fail;
}
FwStatus = FirmwareGetNextStatus(pFirmware->FWStatus); FwStatus = FirmwareGetNextStatus(pFirmware->FWStatus);
} }
RT_TRACE(COMP_FIRMWARE, "Firmware Download Success!!\n"); RT_TRACE(COMP_FIRMWARE, "%s(): Firmware Download Success", __func__);
return rtStatus; return rtStatus;
DownloadFirmware_Fail: DownloadFirmware_Fail:
RT_TRACE(COMP_ERR, "Firmware Download Fail!!%x\n",read_nic_word(dev, TCR)); RT_TRACE(COMP_ERR, "%s(): failed with TCR-Status: %x\n",
__func__, read_nic_word(dev, TCR));
rtStatus = false; rtStatus = false;
return rtStatus; return rtStatus;
} }
......
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