diff options
Diffstat (limited to 'drivers/staging/bcm/nvm.c')
| -rw-r--r-- | drivers/staging/bcm/nvm.c | 270 |
1 files changed, 109 insertions, 161 deletions
diff --git a/drivers/staging/bcm/nvm.c b/drivers/staging/bcm/nvm.c index 91a5715964b..63be3be62eb 100644 --- a/drivers/staging/bcm/nvm.c +++ b/drivers/staging/bcm/nvm.c @@ -45,7 +45,7 @@ static int BeceemFlashBulkWrite( PUINT pBuffer, unsigned int uiOffset, unsigned int uiNumBytes, - BOOLEAN bVerify); + bool bVerify); static int GetFlashBaseAddr(struct bcm_mini_adapter *Adapter); @@ -103,7 +103,7 @@ static UCHAR ReadEEPROMStatusRegister(struct bcm_mini_adapter *Adapter) } if (!(dwRetries%RETRIES_PER_DELAY)) udelay(1000); - uiStatus = 0 ; + uiStatus = 0; } return uiData; } /* ReadEEPROMStatusRegister */ @@ -122,7 +122,7 @@ static UCHAR ReadEEPROMStatusRegister(struct bcm_mini_adapter *Adapter) * OSAL_STATUS_CODE: */ -int ReadBeceemEEPROMBulk(struct bcm_mini_adapter *Adapter, +static int ReadBeceemEEPROMBulk(struct bcm_mini_adapter *Adapter, DWORD dwAddress, DWORD *pdwData, DWORD dwNumWords) @@ -1034,7 +1034,7 @@ static int BeceemFlashBulkWrite(struct bcm_mini_adapter *Adapter, PUINT pBuffer, unsigned int uiOffset, unsigned int uiNumBytes, - BOOLEAN bVerify) + bool bVerify) { PCHAR pTempBuff = NULL; PUCHAR pcBuffer = (PUCHAR)pBuffer; @@ -1084,18 +1084,18 @@ static int BeceemFlashBulkWrite(struct bcm_mini_adapter *Adapter, * for DSD calibration, allow it without checking of sector permission */ - if (IsFlash2x(Adapter) && (Adapter->bAllDSDWriteAllow == FALSE)) { + if (IsFlash2x(Adapter) && (Adapter->bAllDSDWriteAllow == false)) { index = 0; uiTemp = uiNumSectTobeRead; while (uiTemp) { - if (IsOffsetWritable(Adapter, uiOffsetFromSectStart + index * Adapter->uiSectorSize) == FALSE) { + if (IsOffsetWritable(Adapter, uiOffsetFromSectStart + index * Adapter->uiSectorSize) == false) { BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Sector Starting at offset <0X%X> is not writable", (uiOffsetFromSectStart + index * Adapter->uiSectorSize)); Status = SECTOR_IS_NOT_WRITABLE; goto BeceemFlashBulkWrite_EXIT; } uiTemp = uiTemp - 1; - index = index + 1 ; + index = index + 1; } } Adapter->SelectedChip = RESET_CHIP_SELECT; @@ -1222,7 +1222,7 @@ static int BeceemFlashBulkWriteStatus(struct bcm_mini_adapter *Adapter, PUINT pBuffer, unsigned int uiOffset, unsigned int uiNumBytes, - BOOLEAN bVerify) + bool bVerify) { PCHAR pTempBuff = NULL; PUCHAR pcBuffer = (PUCHAR)pBuffer; @@ -1265,18 +1265,18 @@ static int BeceemFlashBulkWriteStatus(struct bcm_mini_adapter *Adapter, uiNumSectTobeRead++; } - if (IsFlash2x(Adapter) && (Adapter->bAllDSDWriteAllow == FALSE)) { + if (IsFlash2x(Adapter) && (Adapter->bAllDSDWriteAllow == false)) { index = 0; uiTemp = uiNumSectTobeRead; while (uiTemp) { - if (IsOffsetWritable(Adapter, uiOffsetFromSectStart + index * Adapter->uiSectorSize) == FALSE) { + if (IsOffsetWritable(Adapter, uiOffsetFromSectStart + index * Adapter->uiSectorSize) == false) { BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Sector Starting at offset <0X%x> is not writable", (uiOffsetFromSectStart + index * Adapter->uiSectorSize)); Status = SECTOR_IS_NOT_WRITABLE; goto BeceemFlashBulkWriteStatus_EXIT; } uiTemp = uiTemp - 1; - index = index + 1 ; + index = index + 1; } } @@ -1355,67 +1355,6 @@ BeceemFlashBulkWriteStatus_EXIT: } /* - * Procedure: PropagateCalParamsFromEEPROMToMemory - * - * Description: Dumps the calibration section of EEPROM to DDR. - * - * Arguments: - * Adapter - ptr to Adapter object instance - * Returns: - * OSAL_STATUS_CODE - * - */ - -int PropagateCalParamsFromEEPROMToMemory(struct bcm_mini_adapter *Adapter) -{ - PCHAR pBuff = kmalloc(BUFFER_4K, GFP_KERNEL); - unsigned int uiEepromSize = 0; - unsigned int uiIndex = 0; - unsigned int uiBytesToCopy = 0; - unsigned int uiCalStartAddr = EEPROM_CALPARAM_START; - unsigned int uiMemoryLoc = EEPROM_CAL_DATA_INTERNAL_LOC; - unsigned int value; - int Status = 0; - - if (!pBuff) - return -ENOMEM; - - if (0 != BeceemEEPROMBulkRead(Adapter, &uiEepromSize, EEPROM_SIZE_OFFSET, 4)) { - kfree(pBuff); - return -1; - } - - uiEepromSize >>= 16; - if (uiEepromSize > 1024 * 1024) { - kfree(pBuff); - return -1; - } - - uiBytesToCopy = MIN(BUFFER_4K, uiEepromSize); - - while (uiBytesToCopy) { - if (0 != BeceemEEPROMBulkRead(Adapter, (PUINT)pBuff, uiCalStartAddr, uiBytesToCopy)) { - Status = -1; - break; - } - wrm(Adapter, uiMemoryLoc, (PCHAR)(((PULONG)pBuff) + uiIndex), uiBytesToCopy); - uiMemoryLoc += uiBytesToCopy; - uiEepromSize -= uiBytesToCopy; - uiCalStartAddr += uiBytesToCopy; - uiIndex += uiBytesToCopy / 4; - uiBytesToCopy = MIN(BUFFER_4K, uiEepromSize); - - } - value = 0xbeadbead; - wrmalt(Adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 4, &value, sizeof(value)); - value = 0xbeadbead; - wrmalt(Adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 8, &value, sizeof(value)); - kfree(pBuff); - - return Status; -} - -/* * Procedure: PropagateCalParamsFromFlashToMemory * * Description: Dumps the calibration section of EEPROM to DDR. @@ -1525,7 +1464,7 @@ static int BeceemEEPROMReadBackandVerify(struct bcm_mini_adapter *Adapter, if (memcmp(&pBuffer[uiIndex], &auiData[0], MAX_RW_SIZE)) { /* re-write */ - BeceemEEPROMBulkWrite(Adapter, (PUCHAR)(pBuffer + uiIndex), uiOffset, MAX_RW_SIZE, FALSE); + BeceemEEPROMBulkWrite(Adapter, (PUCHAR)(pBuffer + uiIndex), uiOffset, MAX_RW_SIZE, false); mdelay(3); BeceemEEPROMBulkRead(Adapter, &auiData[0], uiOffset, MAX_RW_SIZE); @@ -1539,7 +1478,7 @@ static int BeceemEEPROMReadBackandVerify(struct bcm_mini_adapter *Adapter, BeceemEEPROMBulkRead(Adapter, &uiData, uiOffset, 4); if (uiData != pBuffer[uiIndex]) { /* re-write */ - BeceemEEPROMBulkWrite(Adapter, (PUCHAR)(pBuffer + uiIndex), uiOffset, 4, FALSE); + BeceemEEPROMBulkWrite(Adapter, (PUCHAR)(pBuffer + uiIndex), uiOffset, 4, false); mdelay(3); BeceemEEPROMBulkRead(Adapter, &uiData, uiOffset, 4); if (uiData != pBuffer[uiIndex]) @@ -1724,7 +1663,7 @@ int BeceemEEPROMBulkWrite(struct bcm_mini_adapter *Adapter, PUCHAR pBuffer, unsigned int uiOffset, unsigned int uiNumBytes, - BOOLEAN bVerify) + bool bVerify) { unsigned int uiBytesToCopy = uiNumBytes; /* unsigned int uiRdbk = 0; */ @@ -1819,7 +1758,7 @@ int BeceemNVMRead(struct bcm_mini_adapter *Adapter, #endif if (Adapter->eNVMType == NVM_FLASH) { - if (Adapter->bFlashRawRead == FALSE) { + if (Adapter->bFlashRawRead == false) { if (IsSectionExistInVendorInfo(Adapter, Adapter->eActiveDSD)) return vendorextnReadSection(Adapter, (PUCHAR)pBuffer, Adapter->eActiveDSD, uiOffset, uiNumBytes); @@ -1870,7 +1809,7 @@ int BeceemNVMWrite(struct bcm_mini_adapter *Adapter, PUINT pBuffer, unsigned int uiOffset, unsigned int uiNumBytes, - BOOLEAN bVerify) + bool bVerify) { int Status = 0; unsigned int uiTemp = 0; @@ -2425,7 +2364,7 @@ static VOID UpdateVendorInfo(struct bcm_mini_adapter *Adapter) B_UINT32 i = 0; unsigned int uiSizeSection = 0; - Adapter->uiVendorExtnFlag = FALSE; + Adapter->uiVendorExtnFlag = false; for (i = 0; i < TOTAL_SECTIONS; i++) Adapter->psFlash2xVendorInfo->VendorSection[i].OffsetFromZeroForSectionStart = UNINIT_PTR_IN_CS; @@ -2685,12 +2624,12 @@ int BcmGetSectionValStartOffset(struct bcm_mini_adapter *Adapter, enum bcm_flash switch (eFlashSectionVal) { case ISO_IMAGE1: if ((Adapter->psFlash2xCSInfo->OffsetISOImage1Part1Start != UNINIT_PTR_IN_CS) && - (IsNonCDLessDevice(Adapter) == FALSE)) + (IsNonCDLessDevice(Adapter) == false)) SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage1Part1Start); break; case ISO_IMAGE2: if ((Adapter->psFlash2xCSInfo->OffsetISOImage2Part1Start != UNINIT_PTR_IN_CS) && - (IsNonCDLessDevice(Adapter) == FALSE)) + (IsNonCDLessDevice(Adapter) == false)) SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage2Part1Start); break; case DSD0: @@ -2759,7 +2698,7 @@ int BcmGetSectionValStartOffset(struct bcm_mini_adapter *Adapter, enum bcm_flash * On Failure -returns STATUS_FAILURE */ -int BcmGetSectionValEndOffset(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_val eFlash2xSectionVal) +static int BcmGetSectionValEndOffset(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_val eFlash2xSectionVal) { int SectEndOffset = 0; @@ -2770,12 +2709,12 @@ int BcmGetSectionValEndOffset(struct bcm_mini_adapter *Adapter, enum bcm_flash2x switch (eFlash2xSectionVal) { case ISO_IMAGE1: if ((Adapter->psFlash2xCSInfo->OffsetISOImage1Part1End != UNINIT_PTR_IN_CS) && - (IsNonCDLessDevice(Adapter) == FALSE)) + (IsNonCDLessDevice(Adapter) == false)) SectEndOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage1Part1End); break; case ISO_IMAGE2: if ((Adapter->psFlash2xCSInfo->OffsetISOImage2Part1End != UNINIT_PTR_IN_CS) && - (IsNonCDLessDevice(Adapter) == FALSE)) + (IsNonCDLessDevice(Adapter) == false)) SectEndOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage2Part1End); break; case DSD0: @@ -2831,7 +2770,7 @@ int BcmGetSectionValEndOffset(struct bcm_mini_adapter *Adapter, enum bcm_flash2x SectEndOffset = INVALID_OFFSET; } - return SectEndOffset ; + return SectEndOffset; } /* @@ -2873,7 +2812,7 @@ int BcmFlash2xBulkRead(struct bcm_mini_adapter *Adapter, SectionStartOffset = BcmGetSectionValStartOffset(Adapter, eFlash2xSectionVal); if (SectionStartOffset == STATUS_FAILURE) { - BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "This Section<%d> does not exixt in Flash 2.x Map ", eFlash2xSectionVal); + BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "This Section<%d> does not exist in Flash 2.x Map ", eFlash2xSectionVal); return -EINVAL; } @@ -2936,7 +2875,7 @@ int BcmFlash2xBulkWrite(struct bcm_mini_adapter *Adapter, FlashSectValStartOffset = BcmGetSectionValStartOffset(Adapter, eFlash2xSectVal); if (FlashSectValStartOffset == STATUS_FAILURE) { - BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "This Section<%d> does not exixt in Flash Map 2.x", eFlash2xSectVal); + BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "This Section<%d> does not exist in Flash Map 2.x", eFlash2xSectVal); return -EINVAL; } @@ -3037,11 +2976,11 @@ static int BcmGetActiveISO(struct bcm_mini_adapter *Adapter) * * Return Value:- * Success:-TRUE , offset is writable - * Failure:-FALSE, offset is RO + * Failure:-false, offset is RO * */ -B_UINT8 IsOffsetWritable(struct bcm_mini_adapter *Adapter, unsigned int uiOffset) +static B_UINT8 IsOffsetWritable(struct bcm_mini_adapter *Adapter, unsigned int uiOffset) { unsigned int uiSectorNum = 0; unsigned int uiWordOfSectorPermission = 0; @@ -3062,7 +3001,7 @@ B_UINT8 IsOffsetWritable(struct bcm_mini_adapter *Adapter, unsigned int uiOffset if (permissionBits == SECTOR_READWRITE_PERMISSION) return TRUE; else - return FALSE; + return false; } static int BcmDumpFlash2xSectionBitMap(struct bcm_flash2x_bitmap *psFlash2xBitMap) @@ -3105,13 +3044,13 @@ int BcmGetFlash2xSectionalBitMap(struct bcm_mini_adapter *Adapter, struct bcm_fl struct bcm_flash2x_cs_info *psFlash2xCSInfo = Adapter->psFlash2xCSInfo; enum bcm_flash2x_section_val uiHighestPriDSD = 0; enum bcm_flash2x_section_val uiHighestPriISO = 0; - BOOLEAN SetActiveDSDDone = FALSE; - BOOLEAN SetActiveISODone = FALSE; + bool SetActiveDSDDone = false; + bool SetActiveISODone = false; /* For 1.x map all the section except DSD0 will be shown as not present * This part will be used by calibration tool to detect the number of DSD present in Flash. */ - if (IsFlash2x(Adapter) == FALSE) { + if (IsFlash2x(Adapter) == false) { psFlash2xBitMap->ISO_IMAGE2 = 0; psFlash2xBitMap->ISO_IMAGE1 = 0; psFlash2xBitMap->DSD0 = FLASH2X_SECTION_VALID | FLASH2X_SECTION_ACT | FLASH2X_SECTION_PRESENT; /* 0xF; 0000(Reseved)1(Active)0(RW)1(valid)1(present) */ @@ -3143,10 +3082,10 @@ int BcmGetFlash2xSectionalBitMap(struct bcm_mini_adapter *Adapter, struct bcm_fl psFlash2xBitMap->ISO_IMAGE2 |= FLASH2X_SECTION_VALID; /* Calculation for extrating the Access permission */ - if (IsSectionWritable(Adapter, ISO_IMAGE2) == FALSE) + if (IsSectionWritable(Adapter, ISO_IMAGE2) == false) psFlash2xBitMap->ISO_IMAGE2 |= FLASH2X_SECTION_RO; - if (SetActiveISODone == FALSE && uiHighestPriISO == ISO_IMAGE2) { + if (SetActiveISODone == false && uiHighestPriISO == ISO_IMAGE2) { psFlash2xBitMap->ISO_IMAGE2 |= FLASH2X_SECTION_ACT; SetActiveISODone = TRUE; } @@ -3163,10 +3102,10 @@ int BcmGetFlash2xSectionalBitMap(struct bcm_mini_adapter *Adapter, struct bcm_fl psFlash2xBitMap->ISO_IMAGE1 |= FLASH2X_SECTION_VALID; /* Calculation for extrating the Access permission */ - if (IsSectionWritable(Adapter, ISO_IMAGE1) == FALSE) + if (IsSectionWritable(Adapter, ISO_IMAGE1) == false) psFlash2xBitMap->ISO_IMAGE1 |= FLASH2X_SECTION_RO; - if (SetActiveISODone == FALSE && uiHighestPriISO == ISO_IMAGE1) { + if (SetActiveISODone == false && uiHighestPriISO == ISO_IMAGE1) { psFlash2xBitMap->ISO_IMAGE1 |= FLASH2X_SECTION_ACT; SetActiveISODone = TRUE; } @@ -3183,11 +3122,11 @@ int BcmGetFlash2xSectionalBitMap(struct bcm_mini_adapter *Adapter, struct bcm_fl psFlash2xBitMap->DSD2 |= FLASH2X_SECTION_VALID; /* Calculation for extrating the Access permission */ - if (IsSectionWritable(Adapter, DSD2) == FALSE) { + if (IsSectionWritable(Adapter, DSD2) == false) { psFlash2xBitMap->DSD2 |= FLASH2X_SECTION_RO; } else { /* Means section is writable */ - if ((SetActiveDSDDone == FALSE) && (uiHighestPriDSD == DSD2)) { + if ((SetActiveDSDDone == false) && (uiHighestPriDSD == DSD2)) { psFlash2xBitMap->DSD2 |= FLASH2X_SECTION_ACT; SetActiveDSDDone = TRUE; } @@ -3205,11 +3144,11 @@ int BcmGetFlash2xSectionalBitMap(struct bcm_mini_adapter *Adapter, struct bcm_fl psFlash2xBitMap->DSD1 |= FLASH2X_SECTION_VALID; /* Calculation for extrating the Access permission */ - if (IsSectionWritable(Adapter, DSD1) == FALSE) { + if (IsSectionWritable(Adapter, DSD1) == false) { psFlash2xBitMap->DSD1 |= FLASH2X_SECTION_RO; } else { /* Means section is writable */ - if ((SetActiveDSDDone == FALSE) && (uiHighestPriDSD == DSD1)) { + if ((SetActiveDSDDone == false) && (uiHighestPriDSD == DSD1)) { psFlash2xBitMap->DSD1 |= FLASH2X_SECTION_ACT; SetActiveDSDDone = TRUE; } @@ -3227,11 +3166,11 @@ int BcmGetFlash2xSectionalBitMap(struct bcm_mini_adapter *Adapter, struct bcm_fl psFlash2xBitMap->DSD0 |= FLASH2X_SECTION_VALID; /* Setting Access permission */ - if (IsSectionWritable(Adapter, DSD0) == FALSE) { + if (IsSectionWritable(Adapter, DSD0) == false) { psFlash2xBitMap->DSD0 |= FLASH2X_SECTION_RO; } else { /* Means section is writable */ - if ((SetActiveDSDDone == FALSE) && (uiHighestPriDSD == DSD0)) { + if ((SetActiveDSDDone == false) && (uiHighestPriDSD == DSD0)) { psFlash2xBitMap->DSD0 |= FLASH2X_SECTION_ACT; SetActiveDSDDone = TRUE; } @@ -3249,7 +3188,7 @@ int BcmGetFlash2xSectionalBitMap(struct bcm_mini_adapter *Adapter, struct bcm_fl psFlash2xBitMap->VSA0 |= FLASH2X_SECTION_VALID; /* Calculation for extrating the Access permission */ - if (IsSectionWritable(Adapter, VSA0) == FALSE) + if (IsSectionWritable(Adapter, VSA0) == false) psFlash2xBitMap->VSA0 |= FLASH2X_SECTION_RO; /* By Default section is Active */ @@ -3267,7 +3206,7 @@ int BcmGetFlash2xSectionalBitMap(struct bcm_mini_adapter *Adapter, struct bcm_fl psFlash2xBitMap->VSA1 |= FLASH2X_SECTION_VALID; /* Checking For Access permission */ - if (IsSectionWritable(Adapter, VSA1) == FALSE) + if (IsSectionWritable(Adapter, VSA1) == false) psFlash2xBitMap->VSA1 |= FLASH2X_SECTION_RO; /* By Default section is Active */ @@ -3285,7 +3224,7 @@ int BcmGetFlash2xSectionalBitMap(struct bcm_mini_adapter *Adapter, struct bcm_fl psFlash2xBitMap->VSA2 |= FLASH2X_SECTION_VALID; /* Checking For Access permission */ - if (IsSectionWritable(Adapter, VSA2) == FALSE) + if (IsSectionWritable(Adapter, VSA2) == false) psFlash2xBitMap->VSA2 |= FLASH2X_SECTION_RO; /* By Default section is Active */ @@ -3303,7 +3242,7 @@ int BcmGetFlash2xSectionalBitMap(struct bcm_mini_adapter *Adapter, struct bcm_fl psFlash2xBitMap->SCSI |= FLASH2X_SECTION_VALID; /* Checking For Access permission */ - if (IsSectionWritable(Adapter, SCSI) == FALSE) + if (IsSectionWritable(Adapter, SCSI) == false) psFlash2xBitMap->SCSI |= FLASH2X_SECTION_RO; /* By Default section is Active */ @@ -3321,7 +3260,7 @@ int BcmGetFlash2xSectionalBitMap(struct bcm_mini_adapter *Adapter, struct bcm_fl psFlash2xBitMap->CONTROL_SECTION |= FLASH2X_SECTION_VALID; /* Checking For Access permission */ - if (IsSectionWritable(Adapter, CONTROL_SECTION) == FALSE) + if (IsSectionWritable(Adapter, CONTROL_SECTION) == false) psFlash2xBitMap->CONTROL_SECTION |= FLASH2X_SECTION_RO; /* By Default section is Active */ @@ -3358,7 +3297,7 @@ int BcmSetActiveSection(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_secti /* struct bcm_dsd_header sDSD = {0}; * struct bcm_iso_header sISO = {0}; */ - int HighestPriDSD = 0 ; + int HighestPriDSD = 0; int HighestPriISO = 0; Status = IsSectionWritable(Adapter, eFlash2xSectVal); @@ -3435,7 +3374,7 @@ int BcmSetActiveSection(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_secti case DSD2: if (ReadDSDSignature(Adapter, eFlash2xSectVal) == DSD_IMAGE_MAGIC_NUMBER) { HighestPriDSD = getHighestPriDSD(Adapter); - if ((HighestPriDSD == eFlash2xSectVal)) { + if (HighestPriDSD == eFlash2xSectVal) { BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Given DSD<%x> already has highest priority", eFlash2xSectVal); Status = STATUS_SUCCESS; break; @@ -3463,7 +3402,7 @@ int BcmSetActiveSection(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_secti HighestPriDSD = getHighestPriDSD(Adapter); - if ((HighestPriDSD == eFlash2xSectVal)) { + if (HighestPriDSD == eFlash2xSectVal) { BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Made the DSD: %x highest by reducing priority of other\n", eFlash2xSectVal); Status = STATUS_SUCCESS; break; @@ -3482,7 +3421,7 @@ int BcmSetActiveSection(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_secti } HighestPriDSD = getHighestPriDSD(Adapter); - if ((HighestPriDSD == eFlash2xSectVal)) { + if (HighestPriDSD == eFlash2xSectVal) { Status = STATUS_SUCCESS; break; } @@ -3517,7 +3456,7 @@ int BcmSetActiveSection(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_secti break; } - Adapter->bHeaderChangeAllowed = FALSE; + Adapter->bHeaderChangeAllowed = false; return Status; } @@ -3536,7 +3475,7 @@ int BcmCopyISO(struct bcm_mini_adapter *Adapter, struct bcm_flash2x_copy_section enum bcm_flash2x_section_val eISOReadPart = 0, eISOWritePart = 0; unsigned int uiReadOffsetWithinPart = 0, uiWriteOffsetWithinPart = 0; unsigned int uiTotalDataToCopy = 0; - BOOLEAN IsThisHeaderSector = FALSE; + bool IsThisHeaderSector = false; unsigned int sigOffset = 0; unsigned int ISOLength = 0; unsigned int Status = STATUS_SUCCESS; @@ -3669,14 +3608,14 @@ int BcmCopyISO(struct bcm_mini_adapter *Adapter, struct bcm_flash2x_copy_section break; } - Adapter->bHeaderChangeAllowed = FALSE; + Adapter->bHeaderChangeAllowed = false; if (IsThisHeaderSector == TRUE) { WriteToFlashWithoutSectorErase(Adapter, SigBuff, eISOWritePart, sigOffset, MAX_RW_SIZE); - IsThisHeaderSector = FALSE; + IsThisHeaderSector = false; } /* subtracting the written Data */ uiTotalDataToCopy = uiTotalDataToCopy - Adapter->uiSectorSize; @@ -3782,7 +3721,7 @@ int BcmCopyISO(struct bcm_mini_adapter *Adapter, struct bcm_flash2x_copy_section break; } - Adapter->bHeaderChangeAllowed = FALSE; + Adapter->bHeaderChangeAllowed = false; if (IsThisHeaderSector == TRUE) { WriteToFlashWithoutSectorErase(Adapter, SigBuff, @@ -3790,7 +3729,7 @@ int BcmCopyISO(struct bcm_mini_adapter *Adapter, struct bcm_flash2x_copy_section sigOffset, MAX_RW_SIZE); - IsThisHeaderSector = FALSE; + IsThisHeaderSector = false; } /* subtracting the written Data */ @@ -3848,13 +3787,13 @@ int BcmFlash2xWriteSig(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_sectio unsigned int uiOffset = 0; /* struct bcm_dsd_header dsdHeader = {0}; */ - if (Adapter->bSigCorrupted == FALSE) { + if (Adapter->bSigCorrupted == false) { BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Signature is not corrupted by driver, hence not restoring\n"); return STATUS_SUCCESS; } - if (Adapter->bAllDSDWriteAllow == FALSE) { - if (IsSectionWritable(Adapter, eFlashSectionVal) == FALSE) { + if (Adapter->bAllDSDWriteAllow == false) { + if (IsSectionWritable(Adapter, eFlashSectionVal) == false) { BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Section is not Writable...Hence can't Write signature"); return SECTOR_IS_NOT_WRITABLE; } @@ -3886,9 +3825,9 @@ int BcmFlash2xWriteSig(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_sectio BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Restoring the signature"); Adapter->bHeaderChangeAllowed = TRUE; - Adapter->bSigCorrupted = FALSE; + Adapter->bSigCorrupted = false; BcmFlash2xBulkWrite(Adapter, &uiSignature, eFlashSectionVal, uiOffset, SIGNATURE_SIZE, TRUE); - Adapter->bHeaderChangeAllowed = FALSE; + Adapter->bHeaderChangeAllowed = false; return STATUS_SUCCESS; } @@ -3899,7 +3838,7 @@ int BcmFlash2xWriteSig(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_sectio * @Adapater :- Bcm Driver Private Data Structure * @psFlash2xReadWrite :-Flash2x Read/write structure pointer * - * Return values:-Return TRUE is request is valid else FALSE. + * Return values:-Return TRUE is request is valid else false. */ int validateFlash2xReadWrite(struct bcm_mini_adapter *Adapter, struct bcm_flash2x_readwrite *psFlash2xReadWrite) @@ -3911,8 +3850,8 @@ int validateFlash2xReadWrite(struct bcm_mini_adapter *Adapter, struct bcm_flash2 uiNumOfBytes = psFlash2xReadWrite->numOfBytes; if (IsSectionExistInFlash(Adapter, psFlash2xReadWrite->Section) != TRUE) { - BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Section<%x> does not exixt in Flash", psFlash2xReadWrite->Section); - return FALSE; + BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Section<%x> does not exist in Flash", psFlash2xReadWrite->Section); + return false; } uiSectStartOffset = BcmGetSectionValStartOffset(Adapter, psFlash2xReadWrite->Section); BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Start offset :%x ,section :%d\n", uiSectStartOffset, psFlash2xReadWrite->Section); @@ -3944,12 +3883,21 @@ int validateFlash2xReadWrite(struct bcm_mini_adapter *Adapter, struct bcm_flash2 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "End offset :%x\n", uiSectEndOffset); + /* psFlash2xReadWrite->offset and uiNumOfBytes are user controlled and can lead to integer overflows */ + if (psFlash2xReadWrite->offset > uiSectEndOffset) { + BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Invalid Request...."); + return false; + } + if (uiNumOfBytes > uiSectEndOffset) { + BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Invalid Request...."); + return false; + } /* Checking the boundary condition */ if ((uiSectStartOffset + psFlash2xReadWrite->offset + uiNumOfBytes) <= uiSectEndOffset) return TRUE; else { BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Invalid Request...."); - return FALSE; + return false; } } @@ -3966,7 +3914,7 @@ int IsFlash2x(struct bcm_mini_adapter *Adapter) if (Adapter->uiFlashLayoutMajorVersion >= FLASH_2X_MAJOR_NUMBER) return TRUE; else - return FALSE; + return false; } /* @@ -3986,7 +3934,7 @@ static int GetFlashBaseAddr(struct bcm_mini_adapter *Adapter) * For All Valid Flash Versions... except 1.1, take the value from FlashBaseAddr * In case of Raw Read... use the default value */ - if (Adapter->uiFlashLayoutMajorVersion && (Adapter->bFlashRawRead == FALSE) && + if (Adapter->uiFlashLayoutMajorVersion && (Adapter->bFlashRawRead == false) && !((Adapter->uiFlashLayoutMajorVersion == 1) && (Adapter->uiFlashLayoutMinorVersion == 1))) uiBaseAddr = Adapter->uiFlashBaseAdd; else @@ -3996,7 +3944,7 @@ static int GetFlashBaseAddr(struct bcm_mini_adapter *Adapter) * For All Valid Flash Versions... except 1.1, take the value from FlashBaseAddr * In case of Raw Read... use the default value */ - if (Adapter->uiFlashLayoutMajorVersion && (Adapter->bFlashRawRead == FALSE) && + if (Adapter->uiFlashLayoutMajorVersion && (Adapter->bFlashRawRead == false) && !((Adapter->uiFlashLayoutMajorVersion == 1) && (Adapter->uiFlashLayoutMinorVersion == 1))) uiBaseAddr = Adapter->uiFlashBaseAdd | FLASH_CONTIGIOUS_START_ADDR_BEFORE_INIT; else @@ -4094,7 +4042,7 @@ int BcmCopySection(struct bcm_mini_adapter *Adapter, BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Read failed at offset :%d for NOB :%d", SrcSection, BytesToBeCopied); break; } - Status = BcmFlash2xBulkWrite(Adapter, (PUINT)pBuff, DstSection, offset, BytesToBeCopied, FALSE); + Status = BcmFlash2xBulkWrite(Adapter, (PUINT)pBuff, DstSection, offset, BytesToBeCopied, false); if (Status) { BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Write failed at offset :%d for NOB :%d", DstSection, BytesToBeCopied); break; @@ -4110,7 +4058,7 @@ int BcmCopySection(struct bcm_mini_adapter *Adapter, } while (numOfBytes > 0); kfree(pBuff); - Adapter->bHeaderChangeAllowed = FALSE; + Adapter->bHeaderChangeAllowed = false; return Status; } @@ -4126,10 +4074,10 @@ int BcmCopySection(struct bcm_mini_adapter *Adapter, * Faillure :- Return negative error code */ -int SaveHeaderIfPresent(struct bcm_mini_adapter *Adapter, PUCHAR pBuff, unsigned int uiOffset) +static int SaveHeaderIfPresent(struct bcm_mini_adapter *Adapter, PUCHAR pBuff, unsigned int uiOffset) { unsigned int offsetToProtect = 0, HeaderSizeToProtect = 0; - BOOLEAN bHasHeader = FALSE; + bool bHasHeader = false; PUCHAR pTempBuff = NULL; unsigned int uiSectAlignAddr = 0; unsigned int sig = 0; @@ -4153,7 +4101,7 @@ int SaveHeaderIfPresent(struct bcm_mini_adapter *Adapter, PUCHAR pBuff, unsigned bHasHeader = TRUE; } /* If Header is present overwrite passed buffer with this */ - if (bHasHeader && (Adapter->bHeaderChangeAllowed == FALSE)) { + if (bHasHeader && (Adapter->bHeaderChangeAllowed == false)) { pTempBuff = kzalloc(HeaderSizeToProtect, GFP_KERNEL); if (!pTempBuff) { BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Memory allocation failed"); @@ -4172,13 +4120,13 @@ int SaveHeaderIfPresent(struct bcm_mini_adapter *Adapter, PUCHAR pBuff, unsigned sig = ntohl(sig); if ((sig & 0xFF000000) != CORRUPTED_PATTERN) { BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Desired pattern is not at sig offset. Hence won't restore"); - Adapter->bSigCorrupted = FALSE; + Adapter->bSigCorrupted = false; return STATUS_SUCCESS; } BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, " Corrupted sig is :%X", sig); *((PUINT)(pBuff + offsetToProtect + FIELD_OFFSET_IN_HEADER(struct bcm_dsd_header *, DSDImageMagicNumber))) = htonl(DSD_IMAGE_MAGIC_NUMBER); BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Restoring the signature in Header Write only"); - Adapter->bSigCorrupted = FALSE; + Adapter->bSigCorrupted = false; } return STATUS_SUCCESS; @@ -4265,7 +4213,7 @@ static int BcmDoChipSelect(struct bcm_mini_adapter *Adapter, unsigned int offset return STATUS_SUCCESS; } -int ReadDSDSignature(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_val dsd) +static int ReadDSDSignature(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_val dsd) { unsigned int uiDSDsig = 0; /* unsigned int sigoffsetInMap = 0; @@ -4290,7 +4238,7 @@ int ReadDSDSignature(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_ return uiDSDsig; } -int ReadDSDPriority(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_val dsd) +static int ReadDSDPriority(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_val dsd) { /* unsigned int priOffsetInMap = 0 ; */ unsigned int uiDSDPri = STATUS_FAILURE; @@ -4313,7 +4261,7 @@ int ReadDSDPriority(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_v return uiDSDPri; } -enum bcm_flash2x_section_val getHighestPriDSD(struct bcm_mini_adapter *Adapter) +static enum bcm_flash2x_section_val getHighestPriDSD(struct bcm_mini_adapter *Adapter) { int DSDHighestPri = STATUS_FAILURE; int DsdPri = 0; @@ -4345,7 +4293,7 @@ enum bcm_flash2x_section_val getHighestPriDSD(struct bcm_mini_adapter *Adapter) return HighestPriDSD; } -int ReadISOSignature(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_val iso) +static int ReadISOSignature(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_val iso) { unsigned int uiISOsig = 0; /* unsigned int sigoffsetInMap = 0; @@ -4368,7 +4316,7 @@ int ReadISOSignature(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_ return uiISOsig; } -int ReadISOPriority(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_val iso) +static int ReadISOPriority(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_val iso) { unsigned int ISOPri = STATUS_FAILURE; if (IsSectionWritable(Adapter, iso)) { @@ -4387,7 +4335,7 @@ int ReadISOPriority(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_v return ISOPri; } -enum bcm_flash2x_section_val getHighestPriISO(struct bcm_mini_adapter *Adapter) +static enum bcm_flash2x_section_val getHighestPriISO(struct bcm_mini_adapter *Adapter) { int ISOHighestPri = STATUS_FAILURE; int ISOPri = 0; @@ -4411,7 +4359,7 @@ enum bcm_flash2x_section_val getHighestPriISO(struct bcm_mini_adapter *Adapter) return HighestPriISO; } -int WriteToFlashWithoutSectorErase(struct bcm_mini_adapter *Adapter, +static int WriteToFlashWithoutSectorErase(struct bcm_mini_adapter *Adapter, PUINT pBuff, enum bcm_flash2x_section_val eFlash2xSectionVal, unsigned int uiOffset, @@ -4450,7 +4398,7 @@ int WriteToFlashWithoutSectorErase(struct bcm_mini_adapter *Adapter, BcmDoChipSelect(Adapter, uiOffset); uiPartOffset = (uiOffset & (FLASH_PART_SIZE - 1)) + GetFlashBaseAddr(Adapter); - for (i = 0 ; i < uiNumBytes; i += Adapter->ulFlashWriteSize) { + for (i = 0; i < uiNumBytes; i += Adapter->ulFlashWriteSize) { if (Adapter->ulFlashWriteSize == BYTE_WRITE_SUPPORT) Status = flashByteWrite(Adapter, uiPartOffset, pcBuff); else @@ -4469,19 +4417,19 @@ int WriteToFlashWithoutSectorErase(struct bcm_mini_adapter *Adapter, return Status; } -BOOLEAN IsSectionExistInFlash(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_val section) +bool IsSectionExistInFlash(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_val section) { - BOOLEAN SectionPresent = FALSE; + bool SectionPresent = false; switch (section) { case ISO_IMAGE1: if ((Adapter->psFlash2xCSInfo->OffsetISOImage1Part1Start != UNINIT_PTR_IN_CS) && - (IsNonCDLessDevice(Adapter) == FALSE)) + (IsNonCDLessDevice(Adapter) == false)) SectionPresent = TRUE; break; case ISO_IMAGE2: if ((Adapter->psFlash2xCSInfo->OffsetISOImage2Part1Start != UNINIT_PTR_IN_CS) && - (IsNonCDLessDevice(Adapter) == FALSE)) + (IsNonCDLessDevice(Adapter) == false)) SectionPresent = TRUE; break; case DSD0: @@ -4518,26 +4466,26 @@ BOOLEAN IsSectionExistInFlash(struct bcm_mini_adapter *Adapter, enum bcm_flash2x break; default: BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Section Does not exist in Flash 2.x"); - SectionPresent = FALSE; + SectionPresent = false; } return SectionPresent; } -int IsSectionWritable(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_val Section) +static int IsSectionWritable(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_val Section) { int offset = STATUS_FAILURE; - int Status = FALSE; + int Status = false; - if (IsSectionExistInFlash(Adapter, Section) == FALSE) { - BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Section <%d> does not exixt", Section); - return FALSE; + if (IsSectionExistInFlash(Adapter, Section) == false) { + BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Section <%d> does not exist", Section); + return false; } offset = BcmGetSectionValStartOffset(Adapter, Section); if (offset == INVALID_OFFSET) { - BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Section<%d> does not exixt", Section); - return FALSE; + BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Section<%d> does not exist", Section); + return false; } if (IsSectionExistInVendorInfo(Adapter, Section)) @@ -4555,8 +4503,8 @@ static int CorruptDSDSig(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_sect unsigned int BlockStatus = 0; unsigned int uiSectAlignAddr = 0; - Adapter->bSigCorrupted = FALSE; - if (Adapter->bAllDSDWriteAllow == FALSE) { + Adapter->bSigCorrupted = false; + if (Adapter->bAllDSDWriteAllow == false) { if (IsSectionWritable(Adapter, eFlash2xSectionVal) != TRUE) { BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Section is not Writable...Hence can't Corrupt signature"); return SECTOR_IS_NOT_WRITABLE; @@ -4615,7 +4563,7 @@ static int CorruptISOSig(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_sect unsigned int sig = 0; unsigned int uiOffset = 0; - Adapter->bSigCorrupted = FALSE; + Adapter->bSigCorrupted = false; if (IsSectionWritable(Adapter, eFlash2xSectionVal) != TRUE) { BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Section is not Writable...Hence can't Corrupt signature"); @@ -4656,10 +4604,10 @@ static int CorruptISOSig(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_sect return STATUS_SUCCESS; } -BOOLEAN IsNonCDLessDevice(struct bcm_mini_adapter *Adapter) +bool IsNonCDLessDevice(struct bcm_mini_adapter *Adapter) { if (Adapter->psFlash2xCSInfo->IsCDLessDeviceBootSig == NON_CDLESS_DEVICE_BOOT_SIG) return TRUE; else - return FALSE; + return false; } |
