3 #define DWORD unsigned int
5 static INT
BcmDoChipSelect(struct bcm_mini_adapter
*Adapter
, UINT offset
);
6 static INT
BcmGetActiveDSD(struct bcm_mini_adapter
*Adapter
);
7 static INT
BcmGetActiveISO(struct bcm_mini_adapter
*Adapter
);
8 static UINT
BcmGetEEPROMSize(struct bcm_mini_adapter
*Adapter
);
9 static INT
BcmGetFlashCSInfo(struct bcm_mini_adapter
*Adapter
);
10 static UINT
BcmGetFlashSectorSize(struct bcm_mini_adapter
*Adapter
, UINT FlashSectorSizeSig
, UINT FlashSectorSize
);
12 static VOID
BcmValidateNvmType(struct bcm_mini_adapter
*Adapter
);
13 static INT
BcmGetNvmSize(struct bcm_mini_adapter
*Adapter
);
14 static UINT
BcmGetFlashSize(struct bcm_mini_adapter
*Adapter
);
15 static NVM_TYPE
BcmGetNvmType(struct bcm_mini_adapter
*Adapter
);
17 static INT
BcmGetSectionValEndOffset(struct bcm_mini_adapter
*Adapter
, FLASH2X_SECTION_VAL eFlash2xSectionVal
);
19 static B_UINT8
IsOffsetWritable(struct bcm_mini_adapter
*Adapter
, UINT uiOffset
);
20 static INT
IsSectionWritable(struct bcm_mini_adapter
*Adapter
, FLASH2X_SECTION_VAL Section
);
21 static INT
IsSectionExistInVendorInfo(struct bcm_mini_adapter
*Adapter
, FLASH2X_SECTION_VAL section
);
23 static INT
ReadDSDPriority(struct bcm_mini_adapter
*Adapter
, FLASH2X_SECTION_VAL dsd
);
24 static INT
ReadDSDSignature(struct bcm_mini_adapter
*Adapter
, FLASH2X_SECTION_VAL dsd
);
25 static INT
ReadISOPriority(struct bcm_mini_adapter
*Adapter
, FLASH2X_SECTION_VAL iso
);
26 static INT
ReadISOSignature(struct bcm_mini_adapter
*Adapter
, FLASH2X_SECTION_VAL iso
);
28 static INT
CorruptDSDSig(struct bcm_mini_adapter
*Adapter
, FLASH2X_SECTION_VAL eFlash2xSectionVal
);
29 static INT
CorruptISOSig(struct bcm_mini_adapter
*Adapter
, FLASH2X_SECTION_VAL eFlash2xSectionVal
);
30 static INT
SaveHeaderIfPresent(struct bcm_mini_adapter
*Adapter
, PUCHAR pBuff
, UINT uiSectAlignAddr
);
31 static INT
WriteToFlashWithoutSectorErase(struct bcm_mini_adapter
*Adapter
, PUINT pBuff
,
32 FLASH2X_SECTION_VAL eFlash2xSectionVal
,
33 UINT uiOffset
, UINT uiNumBytes
);
34 static FLASH2X_SECTION_VAL
getHighestPriDSD(struct bcm_mini_adapter
*Adapter
);
35 static FLASH2X_SECTION_VAL
getHighestPriISO(struct bcm_mini_adapter
*Adapter
);
37 static INT
BeceemFlashBulkRead(
38 struct bcm_mini_adapter
*Adapter
,
43 static INT
BeceemFlashBulkWrite(
44 struct bcm_mini_adapter
*Adapter
,
50 static INT
GetFlashBaseAddr(struct bcm_mini_adapter
*Adapter
);
52 static INT
ReadBeceemEEPROMBulk(struct bcm_mini_adapter
*Adapter
, UINT dwAddress
, UINT
*pdwData
, UINT dwNumData
);
54 // Procedure: ReadEEPROMStatusRegister
56 // Description: Reads the standard EEPROM Status Register.
59 // Adapter - ptr to Adapter object instance
63 //-----------------------------------------------------------------------------
65 static UCHAR
ReadEEPROMStatusRegister(struct bcm_mini_adapter
*Adapter
)
68 DWORD dwRetries
= MAX_EEPROM_RETRIES
* RETRIES_PER_DELAY
;
73 /* Read the EEPROM status register */
74 value
= EEPROM_READ_STATUS_REGISTER
;
75 wrmalt(Adapter
, EEPROM_CMDQ_SPI_REG
, &value
, sizeof(value
));
77 while (dwRetries
!= 0) {
80 rdmalt(Adapter
, EEPROM_SPI_Q_STATUS1_REG
, &uiStatus
, sizeof(uiStatus
));
81 if (Adapter
->device_removed
== TRUE
) {
82 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Modem has got removed hence exiting....");
86 /* Wait for Avail bit to be set. */
87 if ((uiStatus
& EEPROM_READ_DATA_AVAIL
) != 0) {
88 /* Clear the Avail/Full bits - which ever is set. */
89 value
= uiStatus
& (EEPROM_READ_DATA_AVAIL
| EEPROM_READ_DATA_FULL
);
90 wrmalt(Adapter
, EEPROM_SPI_Q_STATUS1_REG
, &value
, sizeof(value
));
93 rdmalt(Adapter
, EEPROM_READ_DATAQ_REG
, &value
, sizeof(value
));
94 uiData
= (UCHAR
)value
;
100 if (dwRetries
== 0) {
101 rdmalt(Adapter
, EEPROM_SPI_Q_STATUS1_REG
, &value
, sizeof(value
));
102 rdmalt(Adapter
, EEPROM_SPI_Q_STATUS_REG
, &value1
, sizeof(value1
));
103 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "0x3004 = %x 0x3008 = %x, retries = %d failed.\n", value
, value1
, MAX_EEPROM_RETRIES
* RETRIES_PER_DELAY
);
106 if (!(dwRetries
%RETRIES_PER_DELAY
))
111 } /* ReadEEPROMStatusRegister */
113 //-----------------------------------------------------------------------------
114 // Procedure: ReadBeceemEEPROMBulk
116 // Description: This routine reads 16Byte data from EEPROM
119 // Adapter - ptr to Adapter object instance
120 // dwAddress - EEPROM Offset to read the data from.
121 // pdwData - Pointer to double word where data needs to be stored in. // dwNumWords - Number of words. Valid values are 4 ONLY.
125 //-----------------------------------------------------------------------------
127 INT
ReadBeceemEEPROMBulk(struct bcm_mini_adapter
*Adapter
,
133 DWORD dwRetries
= MAX_EEPROM_RETRIES
* RETRIES_PER_DELAY
;
139 /* Flush the read and cmd queue. */
140 value
= (EEPROM_READ_QUEUE_FLUSH
| EEPROM_CMD_QUEUE_FLUSH
);
141 wrmalt(Adapter
, SPI_FLUSH_REG
, &value
, sizeof(value
));
143 wrmalt(Adapter
, SPI_FLUSH_REG
, &value
, sizeof(value
));
145 /* Clear the Avail/Full bits. */
146 value
= (EEPROM_READ_DATA_AVAIL
| EEPROM_READ_DATA_FULL
);
147 wrmalt(Adapter
, EEPROM_SPI_Q_STATUS1_REG
, &value
, sizeof(value
));
149 value
= dwAddress
| ((dwNumWords
== 4) ? EEPROM_16_BYTE_PAGE_READ
: EEPROM_4_BYTE_PAGE_READ
);
150 wrmalt(Adapter
, EEPROM_CMDQ_SPI_REG
, &value
, sizeof(value
));
152 while (dwRetries
!= 0) {
154 rdmalt(Adapter
, EEPROM_SPI_Q_STATUS1_REG
, &uiStatus
, sizeof(uiStatus
));
155 if (Adapter
->device_removed
== TRUE
) {
156 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Modem has got Removed.hence exiting from loop...");
160 /* If we are reading 16 bytes we want to be sure that the queue
161 * is full before we read. In the other cases we are ok if the
162 * queue has data available */
163 if (dwNumWords
== 4) {
164 if ((uiStatus
& EEPROM_READ_DATA_FULL
) != 0) {
165 /* Clear the Avail/Full bits - which ever is set. */
166 value
= (uiStatus
& (EEPROM_READ_DATA_AVAIL
| EEPROM_READ_DATA_FULL
));
167 wrmalt(Adapter
, EEPROM_SPI_Q_STATUS1_REG
, &value
, sizeof(value
));
170 } else if (dwNumWords
== 1) {
171 if ((uiStatus
& EEPROM_READ_DATA_AVAIL
) != 0) {
172 /* We just got Avail and we have to read 32bits so we
173 * need this sleep for Cardbus kind of devices. */
174 if (Adapter
->chip_id
== 0xBECE0210)
177 /* Clear the Avail/Full bits - which ever is set. */
178 value
= (uiStatus
& (EEPROM_READ_DATA_AVAIL
| EEPROM_READ_DATA_FULL
));
179 wrmalt(Adapter
, EEPROM_SPI_Q_STATUS1_REG
, &value
, sizeof(value
));
187 if (dwRetries
== 0) {
190 rdmalt(Adapter
, EEPROM_SPI_Q_STATUS1_REG
, &value
, sizeof(value
));
191 rdmalt(Adapter
, EEPROM_SPI_Q_STATUS_REG
, &value1
, sizeof(value1
));
192 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "dwNumWords %d 0x3004 = %x 0x3008 = %x retries = %d failed.\n",
193 dwNumWords
, value
, value1
, MAX_EEPROM_RETRIES
* RETRIES_PER_DELAY
);
194 return STATUS_FAILURE
;
197 if (!(dwRetries
%RETRIES_PER_DELAY
))
201 for (dwIndex
= 0; dwIndex
< dwNumWords
; dwIndex
++) {
202 /* We get only a byte at a time - from LSB to MSB. We shift it into an integer. */
203 pvalue
= (PUCHAR
)(pdwData
+ dwIndex
);
206 rdmalt(Adapter
, EEPROM_READ_DATAQ_REG
, &value
, sizeof(value
));
211 rdmalt(Adapter
, EEPROM_READ_DATAQ_REG
, &value
, sizeof(value
));
216 rdmalt(Adapter
, EEPROM_READ_DATAQ_REG
, &value
, sizeof(value
));
221 rdmalt(Adapter
, EEPROM_READ_DATAQ_REG
, &value
, sizeof(value
));
226 return STATUS_SUCCESS
;
227 } /* ReadBeceemEEPROMBulk() */
229 //-----------------------------------------------------------------------------
230 // Procedure: ReadBeceemEEPROM
232 // Description: This routine reads 4 data from EEPROM. It uses 1 or 2 page
233 // reads to do this operation.
236 // Adapter - ptr to Adapter object instance
237 // uiOffset - EEPROM Offset to read the data from.
238 // pBuffer - Pointer to word where data needs to be stored in.
242 //-----------------------------------------------------------------------------
244 INT
ReadBeceemEEPROM(struct bcm_mini_adapter
*Adapter
,
248 UINT uiData
[8] = {0};
249 UINT uiByteOffset
= 0;
250 UINT uiTempOffset
= 0;
252 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, " ====> ");
254 uiTempOffset
= uiOffset
- (uiOffset
% MAX_RW_SIZE
);
255 uiByteOffset
= uiOffset
- uiTempOffset
;
257 ReadBeceemEEPROMBulk(Adapter
, uiTempOffset
, (PUINT
)&uiData
[0], 4);
259 /* A word can overlap at most over 2 pages. In that case we read the
261 if (uiByteOffset
> 12)
262 ReadBeceemEEPROMBulk(Adapter
, uiTempOffset
+ MAX_RW_SIZE
, (PUINT
)&uiData
[4], 4);
264 memcpy((PUCHAR
)pBuffer
, (((PUCHAR
)&uiData
[0]) + uiByteOffset
), 4);
266 return STATUS_SUCCESS
;
267 } /* ReadBeceemEEPROM() */
269 INT
ReadMacAddressFromNVM(struct bcm_mini_adapter
*Adapter
)
272 unsigned char puMacAddr
[6];
274 Status
= BeceemNVMRead(Adapter
,
275 (PUINT
)&puMacAddr
[0],
276 INIT_PARAMS_1_MACADDRESS_ADDRESS
,
279 if (Status
== STATUS_SUCCESS
)
280 memcpy(Adapter
->dev
->dev_addr
, puMacAddr
, MAC_ADDRESS_SIZE
);
285 //-----------------------------------------------------------------------------
286 // Procedure: BeceemEEPROMBulkRead
288 // Description: Reads the EEPROM and returns the Data.
291 // Adapter - ptr to Adapter object instance
292 // pBuffer - Buffer to store the data read from EEPROM
293 // uiOffset - Offset of EEPROM from where data should be read
294 // uiNumBytes - Number of bytes to be read from the EEPROM.
297 // OSAL_STATUS_SUCCESS - if EEPROM read is successful.
298 // <FAILURE> - if failed.
299 //-----------------------------------------------------------------------------
301 INT
BeceemEEPROMBulkRead(struct bcm_mini_adapter
*Adapter
,
306 UINT uiData
[4] = {0};
307 // UINT uiAddress = 0;
308 UINT uiBytesRemaining
= uiNumBytes
;
310 UINT uiTempOffset
= 0;
311 UINT uiExtraBytes
= 0;
312 UINT uiFailureRetries
= 0;
313 PUCHAR pcBuff
= (PUCHAR
)pBuffer
;
315 if (uiOffset
% MAX_RW_SIZE
&& uiBytesRemaining
) {
316 uiTempOffset
= uiOffset
- (uiOffset
% MAX_RW_SIZE
);
317 uiExtraBytes
= uiOffset
- uiTempOffset
;
318 ReadBeceemEEPROMBulk(Adapter
, uiTempOffset
, (PUINT
)&uiData
[0], 4);
319 if (uiBytesRemaining
>= (MAX_RW_SIZE
- uiExtraBytes
)) {
320 memcpy(pBuffer
, (((PUCHAR
)&uiData
[0]) + uiExtraBytes
), MAX_RW_SIZE
- uiExtraBytes
);
321 uiBytesRemaining
-= (MAX_RW_SIZE
- uiExtraBytes
);
322 uiIndex
+= (MAX_RW_SIZE
- uiExtraBytes
);
323 uiOffset
+= (MAX_RW_SIZE
- uiExtraBytes
);
325 memcpy(pBuffer
, (((PUCHAR
)&uiData
[0]) + uiExtraBytes
), uiBytesRemaining
);
326 uiIndex
+= uiBytesRemaining
;
327 uiOffset
+= uiBytesRemaining
;
328 uiBytesRemaining
= 0;
332 while (uiBytesRemaining
&& uiFailureRetries
!= 128) {
333 if (Adapter
->device_removed
)
336 if (uiBytesRemaining
>= MAX_RW_SIZE
) {
337 /* For the requests more than or equal to 16 bytes, use bulk
338 * read function to make the access faster.
339 * We read 4 Dwords of data */
340 if (0 == ReadBeceemEEPROMBulk(Adapter
, uiOffset
, &uiData
[0], 4)) {
341 memcpy(pcBuff
+ uiIndex
, &uiData
[0], MAX_RW_SIZE
);
342 uiOffset
+= MAX_RW_SIZE
;
343 uiBytesRemaining
-= MAX_RW_SIZE
;
344 uiIndex
+= MAX_RW_SIZE
;
347 mdelay(3); //sleep for a while before retry...
349 } else if (uiBytesRemaining
>= 4) {
350 if (0 == ReadBeceemEEPROM(Adapter
, uiOffset
, &uiData
[0])) {
351 memcpy(pcBuff
+ uiIndex
, &uiData
[0], 4);
353 uiBytesRemaining
-= 4;
357 mdelay(3); //sleep for a while before retry...
360 // Handle the reads less than 4 bytes...
361 PUCHAR pCharBuff
= (PUCHAR
)pBuffer
;
362 pCharBuff
+= uiIndex
;
363 if (0 == ReadBeceemEEPROM(Adapter
, uiOffset
, &uiData
[0])) {
364 memcpy(pCharBuff
, &uiData
[0], uiBytesRemaining
); //copy only bytes requested.
365 uiBytesRemaining
= 0;
368 mdelay(3); //sleep for a while before retry...
376 //-----------------------------------------------------------------------------
377 // Procedure: BeceemFlashBulkRead
379 // Description: Reads the FLASH and returns the Data.
382 // Adapter - ptr to Adapter object instance
383 // pBuffer - Buffer to store the data read from FLASH
384 // uiOffset - Offset of FLASH from where data should be read
385 // uiNumBytes - Number of bytes to be read from the FLASH.
388 // OSAL_STATUS_SUCCESS - if FLASH read is successful.
389 // <FAILURE> - if failed.
390 //-----------------------------------------------------------------------------
392 static INT
BeceemFlashBulkRead(struct bcm_mini_adapter
*Adapter
,
398 UINT uiBytesToRead
= uiNumBytes
;
400 UINT uiPartOffset
= 0;
403 if (Adapter
->device_removed
) {
404 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Device Got Removed");
408 // Adding flash Base address
409 // uiOffset = uiOffset + GetFlashBaseAddr(Adapter);
410 #if defined(BCM_SHM_INTERFACE) && !defined(FLASH_DIRECT_ACCESS)
411 Status
= bcmflash_raw_read((uiOffset
/FLASH_PART_SIZE
), (uiOffset
% FLASH_PART_SIZE
), (unsigned char *)pBuffer
, uiNumBytes
);
415 Adapter
->SelectedChip
= RESET_CHIP_SELECT
;
417 if (uiOffset
% MAX_RW_SIZE
) {
418 BcmDoChipSelect(Adapter
, uiOffset
);
419 uiPartOffset
= (uiOffset
& (FLASH_PART_SIZE
- 1)) + GetFlashBaseAddr(Adapter
);
421 uiBytesToRead
= MAX_RW_SIZE
- (uiOffset
% MAX_RW_SIZE
);
422 uiBytesToRead
= MIN(uiNumBytes
, uiBytesToRead
);
424 bytes
= rdm(Adapter
, uiPartOffset
, (PCHAR
)pBuffer
+ uiIndex
, uiBytesToRead
);
427 Adapter
->SelectedChip
= RESET_CHIP_SELECT
;
431 uiIndex
+= uiBytesToRead
;
432 uiOffset
+= uiBytesToRead
;
433 uiNumBytes
-= uiBytesToRead
;
437 BcmDoChipSelect(Adapter
, uiOffset
);
438 uiPartOffset
= (uiOffset
& (FLASH_PART_SIZE
- 1)) + GetFlashBaseAddr(Adapter
);
440 uiBytesToRead
= MIN(uiNumBytes
, MAX_RW_SIZE
);
442 bytes
= rdm(Adapter
, uiPartOffset
, (PCHAR
)pBuffer
+ uiIndex
, uiBytesToRead
);
448 uiIndex
+= uiBytesToRead
;
449 uiOffset
+= uiBytesToRead
;
450 uiNumBytes
-= uiBytesToRead
;
452 Adapter
->SelectedChip
= RESET_CHIP_SELECT
;
456 //-----------------------------------------------------------------------------
457 // Procedure: BcmGetFlashSize
459 // Description: Finds the size of FLASH.
462 // Adapter - ptr to Adapter object instance
465 // UINT - size of the FLASH Storage.
467 //-----------------------------------------------------------------------------
469 static UINT
BcmGetFlashSize(struct bcm_mini_adapter
*Adapter
)
471 if (IsFlash2x(Adapter
))
472 return (Adapter
->psFlash2xCSInfo
->OffsetFromDSDStartForDSDHeader
+ sizeof(DSD_HEADER
));
477 //-----------------------------------------------------------------------------
478 // Procedure: BcmGetEEPROMSize
480 // Description: Finds the size of EEPROM.
483 // Adapter - ptr to Adapter object instance
486 // UINT - size of the EEPROM Storage.
488 //-----------------------------------------------------------------------------
490 static UINT
BcmGetEEPROMSize(struct bcm_mini_adapter
*Adapter
)
496 // if EEPROM is present and already Calibrated,it will have
497 // 'BECM' string at 0th offset.
498 // To find the EEPROM size read the possible boundaries of the
499 // EEPROM like 4K,8K etc..accessing the EEPROM beyond its size will
500 // result in wrap around. So when we get the End of the EEPROM we will
501 // get 'BECM' string which is indeed at offset 0.
503 BeceemEEPROMBulkRead(Adapter
, &uiData
, 0x0, 4);
504 if (uiData
== BECM
) {
505 for (uiIndex
= 2; uiIndex
<= 256; uiIndex
*= 2) {
506 BeceemEEPROMBulkRead(Adapter
, &uiData
, uiIndex
* 1024, 4);
508 return uiIndex
* 1024;
512 // EEPROM may not be present or not programmed
515 if (0 == BeceemEEPROMBulkWrite(Adapter
, (PUCHAR
)&uiData
, 0, 4, TRUE
)) {
517 for (uiIndex
= 2; uiIndex
<= 256; uiIndex
*= 2) {
518 BeceemEEPROMBulkRead(Adapter
, &uiData
, uiIndex
* 1024, 4);
519 if (uiData
== 0xBABEFACE)
520 return uiIndex
* 1024;
527 //-----------------------------------------------------------------------------
528 // Procedure: FlashSectorErase
530 // Description: Finds the sector size of the FLASH.
533 // Adapter - ptr to Adapter object instance
534 // addr - sector start address
535 // numOfSectors - number of sectors to be erased.
540 //-----------------------------------------------------------------------------
542 static INT
FlashSectorErase(struct bcm_mini_adapter
*Adapter
,
546 UINT iIndex
= 0, iRetries
= 0;
551 for (iIndex
= 0; iIndex
< numOfSectors
; iIndex
++) {
553 wrmalt(Adapter
, FLASH_SPI_CMDQ_REG
, &value
, sizeof(value
));
555 value
= (0xd8000000 | (addr
& 0xFFFFFF));
556 wrmalt(Adapter
, FLASH_SPI_CMDQ_REG
, &value
, sizeof(value
));
560 value
= (FLASH_CMD_STATUS_REG_READ
<< 24);
561 if (wrmalt(Adapter
, FLASH_SPI_CMDQ_REG
, &value
, sizeof(value
)) < 0) {
562 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Programing of FLASH_SPI_CMDQ_REG fails");
563 return STATUS_FAILURE
;
566 bytes
= rdmalt(Adapter
, FLASH_SPI_READQ_REG
, &uiStatus
, sizeof(uiStatus
));
569 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Reading status of FLASH_SPI_READQ_REG fails");
573 // After every try lets make the CPU free for 10 ms. generally time taken by the
574 // the sector erase cycle is 500 ms to 40000 msec. hence sleeping 10 ms
575 // won't hamper performance in any case.
577 } while ((uiStatus
& 0x1) && (iRetries
< 400));
579 if (uiStatus
& 0x1) {
580 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "iRetries crossing the limit of 80000\n");
581 return STATUS_FAILURE
;
584 addr
+= Adapter
->uiSectorSize
;
588 //-----------------------------------------------------------------------------
589 // Procedure: flashByteWrite
591 // Description: Performs Byte by Byte write to flash
594 // Adapter - ptr to Adapter object instance
595 // uiOffset - Offset of the flash where data needs to be written to.
596 // pData - Address of Data to be written.
600 //-----------------------------------------------------------------------------
602 static INT
flashByteWrite(struct bcm_mini_adapter
*Adapter
,
607 INT iRetries
= MAX_FLASH_RETRIES
* FLASH_PER_RETRIES_DELAY
; //3
609 ULONG ulData
= *(PUCHAR
)pData
;
612 // need not write 0xFF because write requires an erase and erase will
613 // make whole sector 0xFF.
617 return STATUS_SUCCESS
;
619 // DumpDebug(NVM_RW,("flashWrite ====>\n"));
620 value
= (FLASH_CMD_WRITE_ENABLE
<< 24);
621 if (wrmalt(Adapter
, FLASH_SPI_CMDQ_REG
, &value
, sizeof(value
)) < 0) {
622 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Write enable in FLASH_SPI_CMDQ_REG register fails");
623 return STATUS_FAILURE
;
626 if (wrm(Adapter
, FLASH_SPI_WRITEQ_REG
, (PCHAR
)&ulData
, 4) < 0) {
627 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "DATA Write on FLASH_SPI_WRITEQ_REG fails");
628 return STATUS_FAILURE
;
630 value
= (0x02000000 | (uiOffset
& 0xFFFFFF));
631 if (wrmalt(Adapter
, FLASH_SPI_CMDQ_REG
, &value
, sizeof(value
)) < 0) {
632 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Programming of FLASH_SPI_CMDQ_REG fails");
633 return STATUS_FAILURE
;
639 value
= (FLASH_CMD_STATUS_REG_READ
<< 24);
640 if (wrmalt(Adapter
, FLASH_SPI_CMDQ_REG
, &value
, sizeof(value
)) < 0) {
641 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Programing of FLASH_SPI_CMDQ_REG fails");
642 return STATUS_FAILURE
;
645 bytes
= rdmalt(Adapter
, FLASH_SPI_READQ_REG
, &uiStatus
, sizeof(uiStatus
));
648 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Reading status of FLASH_SPI_READQ_REG fails");
652 if (iRetries
&& ((iRetries
% FLASH_PER_RETRIES_DELAY
) == 0))
655 } while ((uiStatus
& 0x1) && (iRetries
> 0));
657 if (uiStatus
& 0x1) {
658 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Flash Write fails even after checking status for 200 times.");
659 return STATUS_FAILURE
;
662 return STATUS_SUCCESS
;
665 //-----------------------------------------------------------------------------
666 // Procedure: flashWrite
668 // Description: Performs write to flash
671 // Adapter - ptr to Adapter object instance
672 // uiOffset - Offset of the flash where data needs to be written to.
673 // pData - Address of Data to be written.
677 //-----------------------------------------------------------------------------
679 static INT
flashWrite(struct bcm_mini_adapter
*Adapter
,
685 //UINT uiReadBack = 0;
688 INT iRetries
= MAX_FLASH_RETRIES
* FLASH_PER_RETRIES_DELAY
; //3
690 UINT uiErasePattern
[4] = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF};
693 // need not write 0xFFFFFFFF because write requires an erase and erase will
694 // make whole sector 0xFFFFFFFF.
696 if (!memcmp(pData
, uiErasePattern
, MAX_RW_SIZE
))
699 value
= (FLASH_CMD_WRITE_ENABLE
<< 24);
701 if (wrmalt(Adapter
, FLASH_SPI_CMDQ_REG
, &value
, sizeof(value
)) < 0) {
702 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Write Enable of FLASH_SPI_CMDQ_REG fails");
703 return STATUS_FAILURE
;
706 if (wrm(Adapter
, uiOffset
, (PCHAR
)pData
, MAX_RW_SIZE
) < 0) {
707 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Data write fails...");
708 return STATUS_FAILURE
;
713 value
= (FLASH_CMD_STATUS_REG_READ
<< 24);
714 if (wrmalt(Adapter
, FLASH_SPI_CMDQ_REG
, &value
, sizeof(value
)) < 0) {
715 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Programing of FLASH_SPI_CMDQ_REG fails");
716 return STATUS_FAILURE
;
719 bytes
= rdmalt(Adapter
, FLASH_SPI_READQ_REG
, &uiStatus
, sizeof(uiStatus
));
722 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Reading status of FLASH_SPI_READQ_REG fails");
727 //this will ensure that in there will be no changes in the current path.
728 //currently one rdm/wrm takes 125 us.
729 //Hence 125 *2 * FLASH_PER_RETRIES_DELAY > 3 ms(worst case delay)
730 //Hence current implementation cycle will intoduce no delay in current path
731 if (iRetries
&& ((iRetries
% FLASH_PER_RETRIES_DELAY
) == 0))
733 } while ((uiStatus
& 0x1) && (iRetries
> 0));
735 if (uiStatus
& 0x1) {
736 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Flash Write fails even after checking status for 200 times.");
737 return STATUS_FAILURE
;
740 return STATUS_SUCCESS
;
743 //-----------------------------------------------------------------------------
744 // Procedure: flashByteWriteStatus
746 // Description: Performs byte by byte write to flash with write done status check
749 // Adapter - ptr to Adapter object instance
750 // uiOffset - Offset of the flash where data needs to be written to.
751 // pData - Address of the Data to be written.
755 //-----------------------------------------------------------------------------
756 static INT
flashByteWriteStatus(struct bcm_mini_adapter
*Adapter
,
761 INT iRetries
= MAX_FLASH_RETRIES
* FLASH_PER_RETRIES_DELAY
; //3
762 ULONG ulData
= *(PUCHAR
)pData
;
767 // need not write 0xFFFFFFFF because write requires an erase and erase will
768 // make whole sector 0xFFFFFFFF.
772 return STATUS_SUCCESS
;
774 // DumpDebug(NVM_RW,("flashWrite ====>\n"));
776 value
= (FLASH_CMD_WRITE_ENABLE
<< 24);
777 if (wrmalt(Adapter
, FLASH_SPI_CMDQ_REG
, &value
, sizeof(value
)) < 0) {
778 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Write enable in FLASH_SPI_CMDQ_REG register fails");
779 return STATUS_SUCCESS
;
781 if (wrm(Adapter
, FLASH_SPI_WRITEQ_REG
, (PCHAR
)&ulData
, 4) < 0) {
782 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "DATA Write on FLASH_SPI_WRITEQ_REG fails");
783 return STATUS_FAILURE
;
785 value
= (0x02000000 | (uiOffset
& 0xFFFFFF));
786 if (wrmalt(Adapter
, FLASH_SPI_CMDQ_REG
, &value
, sizeof(value
)) < 0) {
787 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Programming of FLASH_SPI_CMDQ_REG fails");
788 return STATUS_FAILURE
;
794 value
= (FLASH_CMD_STATUS_REG_READ
<< 24);
795 if (wrmalt(Adapter
, FLASH_SPI_CMDQ_REG
, &value
, sizeof(value
)) < 0) {
796 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Programing of FLASH_SPI_CMDQ_REG fails");
797 return STATUS_FAILURE
;
800 bytes
= rdmalt(Adapter
, FLASH_SPI_READQ_REG
, &uiStatus
, sizeof(uiStatus
));
803 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Reading status of FLASH_SPI_READQ_REG fails");
808 if (iRetries
&& ((iRetries
% FLASH_PER_RETRIES_DELAY
) == 0))
811 } while ((uiStatus
& 0x1) && (iRetries
> 0));
813 if (uiStatus
& 0x1) {
814 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Flash Write fails even after checking status for 200 times.");
815 return STATUS_FAILURE
;
818 return STATUS_SUCCESS
;
820 //-----------------------------------------------------------------------------
821 // Procedure: flashWriteStatus
823 // Description: Performs write to flash with write done status check
826 // Adapter - ptr to Adapter object instance
827 // uiOffset - Offset of the flash where data needs to be written to.
828 // pData - Address of the Data to be written.
832 //-----------------------------------------------------------------------------
834 static INT
flashWriteStatus(struct bcm_mini_adapter
*Adapter
,
839 INT iRetries
= MAX_FLASH_RETRIES
* FLASH_PER_RETRIES_DELAY
; //3
840 //UINT uiReadBack = 0;
842 UINT uiErasePattern
[4] = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF};
846 // need not write 0xFFFFFFFF because write requires an erase and erase will
847 // make whole sector 0xFFFFFFFF.
849 if (!memcmp(pData
, uiErasePattern
, MAX_RW_SIZE
))
852 value
= (FLASH_CMD_WRITE_ENABLE
<< 24);
853 if (wrmalt(Adapter
, FLASH_SPI_CMDQ_REG
, &value
, sizeof(value
)) < 0) {
854 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Write Enable of FLASH_SPI_CMDQ_REG fails");
855 return STATUS_FAILURE
;
858 if (wrm(Adapter
, uiOffset
, (PCHAR
)pData
, MAX_RW_SIZE
) < 0) {
859 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Data write fails...");
860 return STATUS_FAILURE
;
865 value
= (FLASH_CMD_STATUS_REG_READ
<< 24);
866 if (wrmalt(Adapter
, FLASH_SPI_CMDQ_REG
, &value
, sizeof(value
)) < 0) {
867 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Programing of FLASH_SPI_CMDQ_REG fails");
868 return STATUS_FAILURE
;
871 bytes
= rdmalt(Adapter
, FLASH_SPI_READQ_REG
, &uiStatus
, sizeof(uiStatus
));
874 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Reading status of FLASH_SPI_READQ_REG fails");
878 // this will ensure that in there will be no changes in the current path.
879 // currently one rdm/wrm takes 125 us.
880 // Hence 125 *2 * FLASH_PER_RETRIES_DELAY >3 ms(worst case delay)
881 // Hence current implementation cycle will intoduce no delay in current path
882 if (iRetries
&& ((iRetries
% FLASH_PER_RETRIES_DELAY
) == 0))
885 } while ((uiStatus
& 0x1) && (iRetries
> 0));
887 if (uiStatus
& 0x1) {
888 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Flash Write fails even after checking status for 200 times.");
889 return STATUS_FAILURE
;
892 return STATUS_SUCCESS
;
895 //-----------------------------------------------------------------------------
896 // Procedure: BcmRestoreBlockProtectStatus
898 // Description: Restores the original block protection status.
901 // Adapter - ptr to Adapter object instance
902 // ulWriteStatus -Original status
906 //-----------------------------------------------------------------------------
908 static VOID
BcmRestoreBlockProtectStatus(struct bcm_mini_adapter
*Adapter
, ULONG ulWriteStatus
)
911 value
= (FLASH_CMD_WRITE_ENABLE
<< 24);
912 wrmalt(Adapter
, FLASH_SPI_CMDQ_REG
, &value
, sizeof(value
));
915 value
= (FLASH_CMD_STATUS_REG_WRITE
<< 24) | (ulWriteStatus
<< 16);
916 wrmalt(Adapter
, FLASH_SPI_CMDQ_REG
, &value
, sizeof(value
));
920 //-----------------------------------------------------------------------------
921 // Procedure: BcmFlashUnProtectBlock
923 // Description: UnProtects appropriate blocks for writing.
926 // Adapter - ptr to Adapter object instance
927 // uiOffset - Offset of the flash where data needs to be written to. This should be Sector aligned.
929 // ULONG - Status value before UnProtect.
931 //-----------------------------------------------------------------------------
933 static ULONG
BcmFlashUnProtectBlock(struct bcm_mini_adapter
*Adapter
, UINT uiOffset
, UINT uiLength
)
936 ULONG ulWriteStatus
= 0;
939 uiOffset
= uiOffset
&0x000FFFFF;
941 // Implemented only for 1MB Flash parts.
943 if (FLASH_PART_SST25VF080B
== Adapter
->ulFlashID
) {
945 // Get Current BP status.
947 value
= (FLASH_CMD_STATUS_REG_READ
<< 24);
948 wrmalt(Adapter
, FLASH_SPI_CMDQ_REG
, &value
, sizeof(value
));
951 // Read status will be WWXXYYZZ. We have to take only WW.
953 rdmalt(Adapter
, FLASH_SPI_READQ_REG
, (PUINT
)&ulStatus
, sizeof(ulStatus
));
955 ulWriteStatus
= ulStatus
;
957 // Bits [5-2] give current block level protection status.
958 // Bit5: BP3 - DONT CARE
959 // BP2-BP0: 0 - NO PROTECTION, 1 - UPPER 1/16, 2 - UPPER 1/8, 3 - UPPER 1/4
960 // 4 - UPPER 1/2. 5 to 7 - ALL BLOCKS
964 if ((uiOffset
+uiLength
) <= 0x80000) {
966 // Offset comes in lower half of 1MB. Protect the upper half.
967 // Clear BP1 and BP0 and set BP2.
969 ulWriteStatus
|= (0x4<<2);
970 ulWriteStatus
&= ~(0x3<<2);
971 } else if ((uiOffset
+ uiLength
) <= 0xC0000) {
973 // Offset comes below Upper 1/4. Upper 1/4 can be protected.
974 // Clear BP2 and set BP1 and BP0.
976 ulWriteStatus
|= (0x3<<2);
977 ulWriteStatus
&= ~(0x1<<4);
978 } else if ((uiOffset
+ uiLength
) <= 0xE0000) {
980 // Offset comes below Upper 1/8. Upper 1/8 can be protected.
981 // Clear BP2 and BP0 and set BP1
983 ulWriteStatus
|= (0x1<<3);
984 ulWriteStatus
&= ~(0x5<<2);
985 } else if ((uiOffset
+ uiLength
) <= 0xF0000) {
987 // Offset comes below Upper 1/16. Only upper 1/16 can be protected.
988 // Set BP0 and Clear BP2,BP1.
990 ulWriteStatus
|= (0x1<<2);
991 ulWriteStatus
&= ~(0x3<<3);
995 // Clear BP2,BP1 and BP0.
997 ulWriteStatus
&= ~(0x7<<2);
1000 value
= (FLASH_CMD_WRITE_ENABLE
<< 24);
1001 wrmalt(Adapter
, FLASH_SPI_CMDQ_REG
, &value
, sizeof(value
));
1003 value
= (FLASH_CMD_STATUS_REG_WRITE
<< 24) | (ulWriteStatus
<< 16);
1004 wrmalt(Adapter
, FLASH_SPI_CMDQ_REG
, &value
, sizeof(value
));
1011 //-----------------------------------------------------------------------------
1012 // Procedure: BeceemFlashBulkWrite
1014 // Description: Performs write to the flash
1017 // Adapter - ptr to Adapter object instance
1018 // pBuffer - Data to be written.
1019 // uiOffset - Offset of the flash where data needs to be written to.
1020 // uiNumBytes - Number of bytes to be written.
1021 // bVerify - read verify flag.
1025 //-----------------------------------------------------------------------------
1027 static INT
BeceemFlashBulkWrite(struct bcm_mini_adapter
*Adapter
,
1033 PCHAR pTempBuff
= NULL
;
1034 PUCHAR pcBuffer
= (PUCHAR
)pBuffer
;
1036 UINT uiOffsetFromSectStart
= 0;
1037 UINT uiSectAlignAddr
= 0;
1038 UINT uiCurrSectOffsetAddr
= 0;
1039 UINT uiSectBoundary
= 0;
1040 UINT uiNumSectTobeRead
= 0;
1041 UCHAR ucReadBk
[16] = {0};
1043 INT Status
= STATUS_SUCCESS
;
1046 UINT uiPartOffset
= 0;
1048 #if defined(BCM_SHM_INTERFACE) && !defined(FLASH_DIRECT_ACCESS)
1049 Status
= bcmflash_raw_write((uiOffset
/ FLASH_PART_SIZE
), (uiOffset
% FLASH_PART_SIZE
), (unsigned char *)pBuffer
, uiNumBytes
);
1053 uiOffsetFromSectStart
= uiOffset
& ~(Adapter
->uiSectorSize
- 1);
1055 // Adding flash Base address
1056 // uiOffset = uiOffset + GetFlashBaseAddr(Adapter);
1058 uiSectAlignAddr
= uiOffset
& ~(Adapter
->uiSectorSize
- 1);
1059 uiCurrSectOffsetAddr
= uiOffset
& (Adapter
->uiSectorSize
- 1);
1060 uiSectBoundary
= uiSectAlignAddr
+ Adapter
->uiSectorSize
;
1062 pTempBuff
= kmalloc(Adapter
->uiSectorSize
, GFP_KERNEL
);
1063 if (NULL
== pTempBuff
)
1064 goto BeceemFlashBulkWrite_EXIT
;
1066 // check if the data to be written is overlapped across sectors
1068 if (uiOffset
+uiNumBytes
< uiSectBoundary
) {
1069 uiNumSectTobeRead
= 1;
1071 // Number of sectors = Last sector start address/First sector start address
1072 uiNumSectTobeRead
= (uiCurrSectOffsetAddr
+ uiNumBytes
) / Adapter
->uiSectorSize
;
1073 if ((uiCurrSectOffsetAddr
+ uiNumBytes
)%Adapter
->uiSectorSize
)
1074 uiNumSectTobeRead
++;
1076 // Check whether Requested sector is writable or not in case of flash2x write. But if write call is
1077 // for DSD calibration, allow it without checking of sector permission
1079 if (IsFlash2x(Adapter
) && (Adapter
->bAllDSDWriteAllow
== FALSE
)) {
1081 uiTemp
= uiNumSectTobeRead
;
1083 if (IsOffsetWritable(Adapter
, uiOffsetFromSectStart
+ index
* Adapter
->uiSectorSize
) == FALSE
) {
1084 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Sector Starting at offset <0X%X> is not writable",
1085 (uiOffsetFromSectStart
+ index
* Adapter
->uiSectorSize
));
1086 Status
= SECTOR_IS_NOT_WRITABLE
;
1087 goto BeceemFlashBulkWrite_EXIT
;
1089 uiTemp
= uiTemp
- 1;
1093 Adapter
->SelectedChip
= RESET_CHIP_SELECT
;
1094 while (uiNumSectTobeRead
) {
1095 // do_gettimeofday(&tv1);
1096 // BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "\nTime In start of write :%ld ms\n",(tv1.tv_sec *1000 + tv1.tv_usec /1000));
1097 uiPartOffset
= (uiSectAlignAddr
& (FLASH_PART_SIZE
- 1)) + GetFlashBaseAddr(Adapter
);
1099 BcmDoChipSelect(Adapter
, uiSectAlignAddr
);
1101 if (0 != BeceemFlashBulkRead(Adapter
,
1103 uiOffsetFromSectStart
,
1104 Adapter
->uiSectorSize
)) {
1106 goto BeceemFlashBulkWrite_EXIT
;
1109 // do_gettimeofday(&tr);
1110 // BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Total time taken by Read :%ld ms\n", (tr.tv_sec *1000 + tr.tv_usec/1000) - (tv1.tv_sec *1000 + tv1.tv_usec/1000));
1112 ulStatus
= BcmFlashUnProtectBlock(Adapter
, uiSectAlignAddr
, Adapter
->uiSectorSize
);
1114 if (uiNumSectTobeRead
> 1) {
1115 memcpy(&pTempBuff
[uiCurrSectOffsetAddr
], pcBuffer
, uiSectBoundary
- (uiSectAlignAddr
+ uiCurrSectOffsetAddr
));
1116 pcBuffer
+= ((uiSectBoundary
- (uiSectAlignAddr
+ uiCurrSectOffsetAddr
)));
1117 uiNumBytes
-= (uiSectBoundary
- (uiSectAlignAddr
+ uiCurrSectOffsetAddr
));
1119 memcpy(&pTempBuff
[uiCurrSectOffsetAddr
], pcBuffer
, uiNumBytes
);
1122 if (IsFlash2x(Adapter
))
1123 SaveHeaderIfPresent(Adapter
, (PUCHAR
)pTempBuff
, uiOffsetFromSectStart
);
1125 FlashSectorErase(Adapter
, uiPartOffset
, 1);
1126 // do_gettimeofday(&te);
1127 // BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Total time taken by Erase :%ld ms\n", (te.tv_sec *1000 + te.tv_usec/1000) - (tr.tv_sec *1000 + tr.tv_usec/1000));
1129 for (uiIndex
= 0; uiIndex
< Adapter
->uiSectorSize
; uiIndex
+= Adapter
->ulFlashWriteSize
) {
1130 if (Adapter
->device_removed
) {
1132 goto BeceemFlashBulkWrite_EXIT
;
1135 if (STATUS_SUCCESS
!= (*Adapter
->fpFlashWrite
)(Adapter
, uiPartOffset
+ uiIndex
, (&pTempBuff
[uiIndex
]))) {
1137 goto BeceemFlashBulkWrite_EXIT
;
1141 // do_gettimeofday(&tw);
1142 // BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Total time taken in Write to Flash :%ld ms\n", (tw.tv_sec *1000 + tw.tv_usec/1000) - (te.tv_sec *1000 + te.tv_usec/1000));
1143 for (uiIndex
= 0; uiIndex
< Adapter
->uiSectorSize
; uiIndex
+= MAX_RW_SIZE
) {
1144 if (STATUS_SUCCESS
== BeceemFlashBulkRead(Adapter
, (PUINT
)ucReadBk
, uiOffsetFromSectStart
+ uiIndex
, MAX_RW_SIZE
)) {
1145 if (Adapter
->ulFlashWriteSize
== 1) {
1146 UINT uiReadIndex
= 0;
1147 for (uiReadIndex
= 0; uiReadIndex
< 16; uiReadIndex
++) {
1148 if (ucReadBk
[uiReadIndex
] != pTempBuff
[uiIndex
+ uiReadIndex
]) {
1149 if (STATUS_SUCCESS
!= (*Adapter
->fpFlashWriteWithStatusCheck
)(Adapter
, uiPartOffset
+ uiIndex
+ uiReadIndex
, &pTempBuff
[uiIndex
+uiReadIndex
])) {
1150 Status
= STATUS_FAILURE
;
1151 goto BeceemFlashBulkWrite_EXIT
;
1156 if (memcmp(ucReadBk
, &pTempBuff
[uiIndex
], MAX_RW_SIZE
)) {
1157 if (STATUS_SUCCESS
!= (*Adapter
->fpFlashWriteWithStatusCheck
)(Adapter
, uiPartOffset
+ uiIndex
, &pTempBuff
[uiIndex
])) {
1158 Status
= STATUS_FAILURE
;
1159 goto BeceemFlashBulkWrite_EXIT
;
1165 // do_gettimeofday(&twv);
1166 // BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Total time taken in Write to Flash verification :%ld ms\n", (twv.tv_sec *1000 + twv.tv_usec/1000) - (tw.tv_sec *1000 + tw.tv_usec/1000));
1168 BcmRestoreBlockProtectStatus(Adapter
, ulStatus
);
1172 uiCurrSectOffsetAddr
= 0;
1173 uiSectAlignAddr
= uiSectBoundary
;
1174 uiSectBoundary
+= Adapter
->uiSectorSize
;
1175 uiOffsetFromSectStart
+= Adapter
->uiSectorSize
;
1176 uiNumSectTobeRead
--;
1178 // do_gettimeofday(&tv2);
1179 // BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Time after Write :%ld ms\n",(tv2.tv_sec *1000 + tv2.tv_usec/1000));
1180 // BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Total time taken by in Write is :%ld ms\n", (tv2.tv_sec *1000 + tv2.tv_usec/1000) - (tv1.tv_sec *1000 + tv1.tv_usec/1000));
1184 BeceemFlashBulkWrite_EXIT
:
1186 BcmRestoreBlockProtectStatus(Adapter
, ulStatus
);
1190 Adapter
->SelectedChip
= RESET_CHIP_SELECT
;
1194 //-----------------------------------------------------------------------------
1195 // Procedure: BeceemFlashBulkWriteStatus
1197 // Description: Writes to Flash. Checks the SPI status after each write.
1200 // Adapter - ptr to Adapter object instance
1201 // pBuffer - Data to be written.
1202 // uiOffset - Offset of the flash where data needs to be written to.
1203 // uiNumBytes - Number of bytes to be written.
1204 // bVerify - read verify flag.
1208 //-----------------------------------------------------------------------------
1210 static INT
BeceemFlashBulkWriteStatus(struct bcm_mini_adapter
*Adapter
,
1216 PCHAR pTempBuff
= NULL
;
1217 PUCHAR pcBuffer
= (PUCHAR
)pBuffer
;
1219 UINT uiOffsetFromSectStart
= 0;
1220 UINT uiSectAlignAddr
= 0;
1221 UINT uiCurrSectOffsetAddr
= 0;
1222 UINT uiSectBoundary
= 0;
1223 UINT uiNumSectTobeRead
= 0;
1224 UCHAR ucReadBk
[16] = {0};
1226 UINT Status
= STATUS_SUCCESS
;
1229 UINT uiPartOffset
= 0;
1231 uiOffsetFromSectStart
= uiOffset
& ~(Adapter
->uiSectorSize
- 1);
1233 // uiOffset += Adapter->ulFlashCalStart;
1234 // Adding flash Base address
1235 // uiOffset = uiOffset + GetFlashBaseAddr(Adapter);
1237 uiSectAlignAddr
= uiOffset
& ~(Adapter
->uiSectorSize
- 1);
1238 uiCurrSectOffsetAddr
= uiOffset
& (Adapter
->uiSectorSize
- 1);
1239 uiSectBoundary
= uiSectAlignAddr
+ Adapter
->uiSectorSize
;
1241 pTempBuff
= kmalloc(Adapter
->uiSectorSize
, GFP_KERNEL
);
1242 if (NULL
== pTempBuff
)
1243 goto BeceemFlashBulkWriteStatus_EXIT
;
1246 // check if the data to be written is overlapped across sectors
1248 if (uiOffset
+uiNumBytes
< uiSectBoundary
) {
1249 uiNumSectTobeRead
= 1;
1251 // Number of sectors = Last sector start address/First sector start address
1252 uiNumSectTobeRead
= (uiCurrSectOffsetAddr
+ uiNumBytes
) / Adapter
->uiSectorSize
;
1253 if ((uiCurrSectOffsetAddr
+ uiNumBytes
)%Adapter
->uiSectorSize
)
1254 uiNumSectTobeRead
++;
1257 if (IsFlash2x(Adapter
) && (Adapter
->bAllDSDWriteAllow
== FALSE
)) {
1259 uiTemp
= uiNumSectTobeRead
;
1261 if (IsOffsetWritable(Adapter
, uiOffsetFromSectStart
+ index
* Adapter
->uiSectorSize
) == FALSE
) {
1262 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Sector Starting at offset <0X%x> is not writable",
1263 (uiOffsetFromSectStart
+ index
* Adapter
->uiSectorSize
));
1264 Status
= SECTOR_IS_NOT_WRITABLE
;
1265 goto BeceemFlashBulkWriteStatus_EXIT
;
1267 uiTemp
= uiTemp
- 1;
1272 Adapter
->SelectedChip
= RESET_CHIP_SELECT
;
1273 while (uiNumSectTobeRead
) {
1274 uiPartOffset
= (uiSectAlignAddr
& (FLASH_PART_SIZE
- 1)) + GetFlashBaseAddr(Adapter
);
1276 BcmDoChipSelect(Adapter
, uiSectAlignAddr
);
1277 if (0 != BeceemFlashBulkRead(Adapter
,
1279 uiOffsetFromSectStart
,
1280 Adapter
->uiSectorSize
)) {
1282 goto BeceemFlashBulkWriteStatus_EXIT
;
1285 ulStatus
= BcmFlashUnProtectBlock(Adapter
, uiOffsetFromSectStart
, Adapter
->uiSectorSize
);
1287 if (uiNumSectTobeRead
> 1) {
1288 memcpy(&pTempBuff
[uiCurrSectOffsetAddr
], pcBuffer
, uiSectBoundary
- (uiSectAlignAddr
+ uiCurrSectOffsetAddr
));
1289 pcBuffer
+= ((uiSectBoundary
- (uiSectAlignAddr
+ uiCurrSectOffsetAddr
)));
1290 uiNumBytes
-= (uiSectBoundary
- (uiSectAlignAddr
+ uiCurrSectOffsetAddr
));
1292 memcpy(&pTempBuff
[uiCurrSectOffsetAddr
], pcBuffer
, uiNumBytes
);
1295 if (IsFlash2x(Adapter
))
1296 SaveHeaderIfPresent(Adapter
, (PUCHAR
)pTempBuff
, uiOffsetFromSectStart
);
1298 FlashSectorErase(Adapter
, uiPartOffset
, 1);
1300 for (uiIndex
= 0; uiIndex
< Adapter
->uiSectorSize
; uiIndex
+= Adapter
->ulFlashWriteSize
) {
1301 if (Adapter
->device_removed
) {
1303 goto BeceemFlashBulkWriteStatus_EXIT
;
1306 if (STATUS_SUCCESS
!= (*Adapter
->fpFlashWriteWithStatusCheck
)(Adapter
, uiPartOffset
+uiIndex
, &pTempBuff
[uiIndex
])) {
1308 goto BeceemFlashBulkWriteStatus_EXIT
;
1313 for (uiIndex
= 0; uiIndex
< Adapter
->uiSectorSize
; uiIndex
+= MAX_RW_SIZE
) {
1314 if (STATUS_SUCCESS
== BeceemFlashBulkRead(Adapter
, (PUINT
)ucReadBk
, uiOffsetFromSectStart
+ uiIndex
, MAX_RW_SIZE
)) {
1315 if (memcmp(ucReadBk
, &pTempBuff
[uiIndex
], MAX_RW_SIZE
)) {
1316 Status
= STATUS_FAILURE
;
1317 goto BeceemFlashBulkWriteStatus_EXIT
;
1324 BcmRestoreBlockProtectStatus(Adapter
, ulStatus
);
1328 uiCurrSectOffsetAddr
= 0;
1329 uiSectAlignAddr
= uiSectBoundary
;
1330 uiSectBoundary
+= Adapter
->uiSectorSize
;
1331 uiOffsetFromSectStart
+= Adapter
->uiSectorSize
;
1332 uiNumSectTobeRead
--;
1337 BeceemFlashBulkWriteStatus_EXIT
:
1339 BcmRestoreBlockProtectStatus(Adapter
, ulStatus
);
1342 Adapter
->SelectedChip
= RESET_CHIP_SELECT
;
1346 //-----------------------------------------------------------------------------
1347 // Procedure: PropagateCalParamsFromEEPROMToMemory
1349 // Description: Dumps the calibration section of EEPROM to DDR.
1352 // Adapter - ptr to Adapter object instance
1356 //-----------------------------------------------------------------------------
1358 INT
PropagateCalParamsFromEEPROMToMemory(struct bcm_mini_adapter
*Adapter
)
1360 PCHAR pBuff
= kmalloc(BUFFER_4K
, GFP_KERNEL
);
1361 UINT uiEepromSize
= 0;
1363 UINT uiBytesToCopy
= 0;
1364 UINT uiCalStartAddr
= EEPROM_CALPARAM_START
;
1365 UINT uiMemoryLoc
= EEPROM_CAL_DATA_INTERNAL_LOC
;
1372 if (0 != BeceemEEPROMBulkRead(Adapter
, &uiEepromSize
, EEPROM_SIZE_OFFSET
, 4)) {
1377 uiEepromSize
>>= 16;
1378 if (uiEepromSize
> 1024 * 1024) {
1383 uiBytesToCopy
= MIN(BUFFER_4K
, uiEepromSize
);
1385 while (uiBytesToCopy
) {
1386 if (0 != BeceemEEPROMBulkRead(Adapter
, (PUINT
)pBuff
, uiCalStartAddr
, uiBytesToCopy
)) {
1390 wrm(Adapter
, uiMemoryLoc
, (PCHAR
)(((PULONG
)pBuff
) + uiIndex
), uiBytesToCopy
);
1391 uiMemoryLoc
+= uiBytesToCopy
;
1392 uiEepromSize
-= uiBytesToCopy
;
1393 uiCalStartAddr
+= uiBytesToCopy
;
1394 uiIndex
+= uiBytesToCopy
/ 4;
1395 uiBytesToCopy
= MIN(BUFFER_4K
, uiEepromSize
);
1399 wrmalt(Adapter
, EEPROM_CAL_DATA_INTERNAL_LOC
- 4, &value
, sizeof(value
));
1401 wrmalt(Adapter
, EEPROM_CAL_DATA_INTERNAL_LOC
- 8, &value
, sizeof(value
));
1407 //-----------------------------------------------------------------------------
1408 // Procedure: PropagateCalParamsFromFlashToMemory
1410 // Description: Dumps the calibration section of EEPROM to DDR.
1413 // Adapter - ptr to Adapter object instance
1417 //-----------------------------------------------------------------------------
1419 INT
PropagateCalParamsFromFlashToMemory(struct bcm_mini_adapter
*Adapter
)
1422 UINT uiEepromSize
= 0;
1423 UINT uiBytesToCopy
= 0;
1425 UINT uiCalStartAddr
= EEPROM_CALPARAM_START
;
1426 UINT uiMemoryLoc
= EEPROM_CAL_DATA_INTERNAL_LOC
;
1431 // Write the signature first. This will ensure firmware does not access EEPROM.
1434 wrmalt(Adapter
, EEPROM_CAL_DATA_INTERNAL_LOC
- 4, &value
, sizeof(value
));
1436 wrmalt(Adapter
, EEPROM_CAL_DATA_INTERNAL_LOC
- 8, &value
, sizeof(value
));
1438 if (0 != BeceemNVMRead(Adapter
, &uiEepromSize
, EEPROM_SIZE_OFFSET
, 4))
1441 uiEepromSize
= ntohl(uiEepromSize
);
1442 uiEepromSize
>>= 16;
1445 // subtract the auto init section size
1447 uiEepromSize
-= EEPROM_CALPARAM_START
;
1449 if (uiEepromSize
> 1024 * 1024)
1452 pBuff
= kmalloc(uiEepromSize
, GFP_KERNEL
);
1456 if (0 != BeceemNVMRead(Adapter
, (PUINT
)pBuff
, uiCalStartAddr
, uiEepromSize
)) {
1463 uiBytesToCopy
= MIN(BUFFER_4K
, uiEepromSize
);
1465 while (uiBytesToCopy
) {
1466 Status
= wrm(Adapter
, uiMemoryLoc
, (PCHAR
)pPtr
, uiBytesToCopy
);
1468 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "wrm failed with status :%d", Status
);
1472 pPtr
+= uiBytesToCopy
;
1473 uiEepromSize
-= uiBytesToCopy
;
1474 uiMemoryLoc
+= uiBytesToCopy
;
1475 uiBytesToCopy
= MIN(BUFFER_4K
, uiEepromSize
);
1482 //-----------------------------------------------------------------------------
1483 // Procedure: BeceemEEPROMReadBackandVerify
1485 // Description: Read back the data written and verifies.
1488 // Adapter - ptr to Adapter object instance
1489 // pBuffer - Data to be written.
1490 // uiOffset - Offset of the flash where data needs to be written to.
1491 // uiNumBytes - Number of bytes to be written.
1495 //-----------------------------------------------------------------------------
1497 static INT
BeceemEEPROMReadBackandVerify(struct bcm_mini_adapter
*Adapter
,
1505 UINT auiData
[4] = {0};
1507 while (uiNumBytes
) {
1508 if (Adapter
->device_removed
)
1511 if (uiNumBytes
>= MAX_RW_SIZE
) {
1512 // for the requests more than or equal to MAX_RW_SIZE bytes, use bulk read function to make the access faster.
1513 BeceemEEPROMBulkRead(Adapter
, &auiData
[0], uiOffset
, MAX_RW_SIZE
);
1515 if (memcmp(&pBuffer
[uiIndex
], &auiData
[0], MAX_RW_SIZE
)) {
1517 BeceemEEPROMBulkWrite(Adapter
, (PUCHAR
)(pBuffer
+ uiIndex
), uiOffset
, MAX_RW_SIZE
, FALSE
);
1519 BeceemEEPROMBulkRead(Adapter
, &auiData
[0], uiOffset
, MAX_RW_SIZE
);
1521 if (memcmp(&pBuffer
[uiIndex
], &auiData
[0], MAX_RW_SIZE
))
1524 uiOffset
+= MAX_RW_SIZE
;
1525 uiNumBytes
-= MAX_RW_SIZE
;
1527 } else if (uiNumBytes
>= 4) {
1528 BeceemEEPROMBulkRead(Adapter
, &uiData
, uiOffset
, 4);
1529 if (uiData
!= pBuffer
[uiIndex
]) {
1531 BeceemEEPROMBulkWrite(Adapter
, (PUCHAR
)(pBuffer
+ uiIndex
), uiOffset
, 4, FALSE
);
1533 BeceemEEPROMBulkRead(Adapter
, &uiData
, uiOffset
, 4);
1534 if (uiData
!= pBuffer
[uiIndex
])
1541 // Handle the reads less than 4 bytes...
1543 memcpy(&uiData
, ((PUCHAR
)pBuffer
) + (uiIndex
* sizeof(UINT
)), uiNumBytes
);
1544 BeceemEEPROMBulkRead(Adapter
, &uiRdbk
, uiOffset
, 4);
1546 if (memcmp(&uiData
, &uiRdbk
, uiNumBytes
))
1556 static VOID
BcmSwapWord(UINT
*ptr1
)
1558 UINT tempval
= (UINT
)*ptr1
;
1559 char *ptr2
= (char *)&tempval
;
1560 char *ptr
= (char *)ptr1
;
1568 //-----------------------------------------------------------------------------
1569 // Procedure: BeceemEEPROMWritePage
1571 // Description: Performs page write (16bytes) to the EEPROM
1574 // Adapter - ptr to Adapter object instance
1575 // uiData - Data to be written.
1576 // uiOffset - Offset of the EEPROM where data needs to be written to.
1580 //-----------------------------------------------------------------------------
1582 static INT
BeceemEEPROMWritePage(struct bcm_mini_adapter
*Adapter
, UINT uiData
[], UINT uiOffset
)
1584 UINT uiRetries
= MAX_EEPROM_RETRIES
* RETRIES_PER_DELAY
;
1586 UCHAR uiEpromStatus
= 0;
1589 /* Flush the Write/Read/Cmd queues. */
1590 value
= (EEPROM_WRITE_QUEUE_FLUSH
| EEPROM_CMD_QUEUE_FLUSH
| EEPROM_READ_QUEUE_FLUSH
);
1591 wrmalt(Adapter
, SPI_FLUSH_REG
, &value
, sizeof(value
));
1593 wrmalt(Adapter
, SPI_FLUSH_REG
, &value
, sizeof(value
));
1595 /* Clear the Empty/Avail/Full bits. After this it has been confirmed
1596 * that the bit was cleared by reading back the register. See NOTE below.
1597 * We also clear the Read queues as we do a EEPROM status register read
1599 value
= (EEPROM_WRITE_QUEUE_EMPTY
| EEPROM_WRITE_QUEUE_AVAIL
| EEPROM_WRITE_QUEUE_FULL
| EEPROM_READ_DATA_AVAIL
| EEPROM_READ_DATA_FULL
);
1600 wrmalt(Adapter
, EEPROM_SPI_Q_STATUS1_REG
, &value
, sizeof(value
));
1603 value
= EEPROM_WRITE_ENABLE
;
1604 wrmalt(Adapter
, EEPROM_CMDQ_SPI_REG
, &value
, sizeof(value
));
1606 /* We can write back to back 8bits * 16 into the queue and as we have
1607 * checked for the queue to be empty we can write in a burst. */
1610 BcmSwapWord(&value
);
1611 wrm(Adapter
, EEPROM_WRITE_DATAQ_REG
, (PUCHAR
)&value
, 4);
1614 BcmSwapWord(&value
);
1615 wrm(Adapter
, EEPROM_WRITE_DATAQ_REG
, (PUCHAR
)&value
, 4);
1618 BcmSwapWord(&value
);
1619 wrm(Adapter
, EEPROM_WRITE_DATAQ_REG
, (PUCHAR
)&value
, 4);
1622 BcmSwapWord(&value
);
1623 wrm(Adapter
, EEPROM_WRITE_DATAQ_REG
, (PUCHAR
)&value
, 4);
1625 /* NOTE : After this write, on readback of EEPROM_SPI_Q_STATUS1_REG
1626 * shows that we see 7 for the EEPROM data write. Which means that
1627 * queue got full, also space is available as well as the queue is empty.
1628 * This may happen in sequence. */
1629 value
= EEPROM_16_BYTE_PAGE_WRITE
| uiOffset
;
1630 wrmalt(Adapter
, EEPROM_CMDQ_SPI_REG
, &value
, sizeof(value
));
1632 /* Ideally we should loop here without tries and eventually succeed.
1633 * What we are checking if the previous write has completed, and this
1634 * may take time. We should wait till the Empty bit is set. */
1636 rdmalt(Adapter
, EEPROM_SPI_Q_STATUS1_REG
, &uiStatus
, sizeof(uiStatus
));
1637 while ((uiStatus
& EEPROM_WRITE_QUEUE_EMPTY
) == 0) {
1639 if (uiRetries
== 0) {
1640 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "0x0f003004 = %x, %d retries failed.\n", uiStatus
, MAX_EEPROM_RETRIES
* RETRIES_PER_DELAY
);
1641 return STATUS_FAILURE
;
1644 if (!(uiRetries
%RETRIES_PER_DELAY
))
1648 rdmalt(Adapter
, EEPROM_SPI_Q_STATUS1_REG
, &uiStatus
, sizeof(uiStatus
));
1649 if (Adapter
->device_removed
== TRUE
) {
1650 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Modem got removed hence exiting from loop....");
1655 if (uiRetries
!= 0) {
1656 /* Clear the ones that are set - either, Empty/Full/Avail bits */
1657 value
= (uiStatus
& (EEPROM_WRITE_QUEUE_EMPTY
| EEPROM_WRITE_QUEUE_AVAIL
| EEPROM_WRITE_QUEUE_FULL
));
1658 wrmalt(Adapter
, EEPROM_SPI_Q_STATUS1_REG
, &value
, sizeof(value
));
1661 /* Here we should check if the EEPROM status register is correct before
1662 * proceeding. Bit 0 in the EEPROM Status register should be 0 before
1663 * we proceed further. A 1 at Bit 0 indicates that the EEPROM is busy
1664 * with the previous write. Note also that issuing this read finally
1665 * means the previous write to the EEPROM has completed. */
1666 uiRetries
= MAX_EEPROM_RETRIES
* RETRIES_PER_DELAY
;
1668 while (uiRetries
!= 0) {
1669 uiEpromStatus
= ReadEEPROMStatusRegister(Adapter
);
1670 if (Adapter
->device_removed
== TRUE
) {
1671 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Modem has got removed hence exiting from loop...");
1674 if ((EEPROM_STATUS_REG_WRITE_BUSY
& uiEpromStatus
) == 0) {
1675 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "EEPROM status register = %x tries = %d\n", uiEpromStatus
, (MAX_EEPROM_RETRIES
* RETRIES_PER_DELAY
- uiRetries
));
1676 return STATUS_SUCCESS
;
1679 if (uiRetries
== 0) {
1680 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "0x0f003004 = %x, for EEPROM status read %d retries failed.\n", uiEpromStatus
, MAX_EEPROM_RETRIES
* RETRIES_PER_DELAY
);
1681 return STATUS_FAILURE
;
1684 if (!(uiRetries
%RETRIES_PER_DELAY
))
1688 return STATUS_SUCCESS
;
1689 } /* BeceemEEPROMWritePage */
1691 //-----------------------------------------------------------------------------
1692 // Procedure: BeceemEEPROMBulkWrite
1694 // Description: Performs write to the EEPROM
1697 // Adapter - ptr to Adapter object instance
1698 // pBuffer - Data to be written.
1699 // uiOffset - Offset of the EEPROM where data needs to be written to.
1700 // uiNumBytes - Number of bytes to be written.
1701 // bVerify - read verify flag.
1705 //-----------------------------------------------------------------------------
1707 INT
BeceemEEPROMBulkWrite(struct bcm_mini_adapter
*Adapter
,
1713 UINT uiBytesToCopy
= uiNumBytes
;
1715 UINT uiData
[4] = {0};
1717 UINT uiTempOffset
= 0;
1718 UINT uiExtraBytes
= 0;
1719 // PUINT puiBuffer = (PUINT)pBuffer;
1722 if (uiOffset
% MAX_RW_SIZE
&& uiBytesToCopy
) {
1723 uiTempOffset
= uiOffset
- (uiOffset
% MAX_RW_SIZE
);
1724 uiExtraBytes
= uiOffset
- uiTempOffset
;
1726 BeceemEEPROMBulkRead(Adapter
, &uiData
[0], uiTempOffset
, MAX_RW_SIZE
);
1728 if (uiBytesToCopy
>= (16 - uiExtraBytes
)) {
1729 memcpy((((PUCHAR
)&uiData
[0]) + uiExtraBytes
), pBuffer
, MAX_RW_SIZE
- uiExtraBytes
);
1731 if (STATUS_FAILURE
== BeceemEEPROMWritePage(Adapter
, uiData
, uiTempOffset
))
1732 return STATUS_FAILURE
;
1734 uiBytesToCopy
-= (MAX_RW_SIZE
- uiExtraBytes
);
1735 uiIndex
+= (MAX_RW_SIZE
- uiExtraBytes
);
1736 uiOffset
+= (MAX_RW_SIZE
- uiExtraBytes
);
1738 memcpy((((PUCHAR
)&uiData
[0]) + uiExtraBytes
), pBuffer
, uiBytesToCopy
);
1740 if (STATUS_FAILURE
== BeceemEEPROMWritePage(Adapter
, uiData
, uiTempOffset
))
1741 return STATUS_FAILURE
;
1743 uiIndex
+= uiBytesToCopy
;
1744 uiOffset
+= uiBytesToCopy
;
1749 while (uiBytesToCopy
) {
1750 if (Adapter
->device_removed
)
1753 if (uiBytesToCopy
>= MAX_RW_SIZE
) {
1754 if (STATUS_FAILURE
== BeceemEEPROMWritePage(Adapter
, (PUINT
) &pBuffer
[uiIndex
], uiOffset
))
1755 return STATUS_FAILURE
;
1757 uiIndex
+= MAX_RW_SIZE
;
1758 uiOffset
+= MAX_RW_SIZE
;
1759 uiBytesToCopy
-= MAX_RW_SIZE
;
1762 // To program non 16byte aligned data, read 16byte and then update.
1764 BeceemEEPROMBulkRead(Adapter
, &uiData
[0], uiOffset
, 16);
1765 memcpy(&uiData
[0], pBuffer
+ uiIndex
, uiBytesToCopy
);
1767 if (STATUS_FAILURE
== BeceemEEPROMWritePage(Adapter
, uiData
, uiOffset
))
1768 return STATUS_FAILURE
;
1777 //-----------------------------------------------------------------------------
1778 // Procedure: BeceemNVMRead
1780 // Description: Reads n number of bytes from NVM.
1783 // Adapter - ptr to Adapter object instance
1784 // pBuffer - Buffer to store the data read from NVM
1785 // uiOffset - Offset of NVM from where data should be read
1786 // uiNumBytes - Number of bytes to be read from the NVM.
1789 // OSAL_STATUS_SUCCESS - if NVM read is successful.
1790 // <FAILURE> - if failed.
1791 //-----------------------------------------------------------------------------
1793 INT
BeceemNVMRead(struct bcm_mini_adapter
*Adapter
,
1800 #if !defined(BCM_SHM_INTERFACE) || defined(FLASH_DIRECT_ACCESS)
1801 UINT uiTemp
= 0, value
;
1804 if (Adapter
->eNVMType
== NVM_FLASH
) {
1805 if (Adapter
->bFlashRawRead
== FALSE
) {
1806 if (IsSectionExistInVendorInfo(Adapter
, Adapter
->eActiveDSD
))
1807 return vendorextnReadSection(Adapter
, (PUCHAR
)pBuffer
, Adapter
->eActiveDSD
, uiOffset
, uiNumBytes
);
1809 uiOffset
= uiOffset
+ Adapter
->ulFlashCalStart
;
1812 #if defined(BCM_SHM_INTERFACE) && !defined(FLASH_DIRECT_ACCESS)
1813 Status
= bcmflash_raw_read((uiOffset
/ FLASH_PART_SIZE
), (uiOffset
% FLASH_PART_SIZE
), (unsigned char *)pBuffer
, uiNumBytes
);
1815 rdmalt(Adapter
, 0x0f000C80, &uiTemp
, sizeof(uiTemp
));
1817 wrmalt(Adapter
, 0x0f000C80, &value
, sizeof(value
));
1818 Status
= BeceemFlashBulkRead(Adapter
,
1822 wrmalt(Adapter
, 0x0f000C80, &uiTemp
, sizeof(uiTemp
));
1824 } else if (Adapter
->eNVMType
== NVM_EEPROM
) {
1825 Status
= BeceemEEPROMBulkRead(Adapter
,
1836 //-----------------------------------------------------------------------------
1837 // Procedure: BeceemNVMWrite
1839 // Description: Writes n number of bytes to NVM.
1842 // Adapter - ptr to Adapter object instance
1843 // pBuffer - Buffer contains the data to be written.
1844 // uiOffset - Offset of NVM where data to be written to.
1845 // uiNumBytes - Number of bytes to be written..
1848 // OSAL_STATUS_SUCCESS - if NVM write is successful.
1849 // <FAILURE> - if failed.
1850 //-----------------------------------------------------------------------------
1852 INT
BeceemNVMWrite(struct bcm_mini_adapter
*Adapter
,
1860 UINT uiMemoryLoc
= EEPROM_CAL_DATA_INTERNAL_LOC
;
1863 #if !defined(BCM_SHM_INTERFACE) || defined(FLASH_DIRECT_ACCESS)
1867 UINT uiFlashOffset
= 0;
1869 if (Adapter
->eNVMType
== NVM_FLASH
) {
1870 if (IsSectionExistInVendorInfo(Adapter
, Adapter
->eActiveDSD
))
1871 Status
= vendorextnWriteSection(Adapter
, (PUCHAR
)pBuffer
, Adapter
->eActiveDSD
, uiOffset
, uiNumBytes
, bVerify
);
1873 uiFlashOffset
= uiOffset
+ Adapter
->ulFlashCalStart
;
1875 #if defined(BCM_SHM_INTERFACE) && !defined(FLASH_DIRECT_ACCESS)
1876 Status
= bcmflash_raw_write((uiFlashOffset
/ FLASH_PART_SIZE
), (uiFlashOffset
% FLASH_PART_SIZE
), (unsigned char *)pBuffer
, uiNumBytes
);
1878 rdmalt(Adapter
, 0x0f000C80, &uiTemp
, sizeof(uiTemp
));
1880 wrmalt(Adapter
, 0x0f000C80, &value
, sizeof(value
));
1882 if (Adapter
->bStatusWrite
== TRUE
)
1883 Status
= BeceemFlashBulkWriteStatus(Adapter
,
1890 Status
= BeceemFlashBulkWrite(Adapter
,
1898 if (uiOffset
>= EEPROM_CALPARAM_START
) {
1899 uiMemoryLoc
+= (uiOffset
- EEPROM_CALPARAM_START
);
1900 while (uiNumBytes
) {
1901 if (uiNumBytes
> BUFFER_4K
) {
1902 wrm(Adapter
, (uiMemoryLoc
+uiIndex
), (PCHAR
)(pBuffer
+ (uiIndex
/ 4)), BUFFER_4K
);
1903 uiNumBytes
-= BUFFER_4K
;
1904 uiIndex
+= BUFFER_4K
;
1906 wrm(Adapter
, uiMemoryLoc
+uiIndex
, (PCHAR
)(pBuffer
+ (uiIndex
/ 4)), uiNumBytes
);
1912 if ((uiOffset
+ uiNumBytes
) > EEPROM_CALPARAM_START
) {
1913 ULONG ulBytesTobeSkipped
= 0;
1914 PUCHAR pcBuffer
= (PUCHAR
)pBuffer
; // char pointer to take care of odd byte cases.
1915 uiNumBytes
-= (EEPROM_CALPARAM_START
- uiOffset
);
1916 ulBytesTobeSkipped
+= (EEPROM_CALPARAM_START
- uiOffset
);
1917 uiOffset
+= (EEPROM_CALPARAM_START
- uiOffset
);
1918 while (uiNumBytes
) {
1919 if (uiNumBytes
> BUFFER_4K
) {
1920 wrm(Adapter
, uiMemoryLoc
+ uiIndex
, (PCHAR
)&pcBuffer
[ulBytesTobeSkipped
+ uiIndex
], BUFFER_4K
);
1921 uiNumBytes
-= BUFFER_4K
;
1922 uiIndex
+= BUFFER_4K
;
1924 wrm(Adapter
, uiMemoryLoc
+ uiIndex
, (PCHAR
)&pcBuffer
[ulBytesTobeSkipped
+ uiIndex
], uiNumBytes
);
1931 // restore the values.
1932 wrmalt(Adapter
, 0x0f000C80, &uiTemp
, sizeof(uiTemp
));
1933 } else if (Adapter
->eNVMType
== NVM_EEPROM
) {
1934 Status
= BeceemEEPROMBulkWrite(Adapter
,
1940 Status
= BeceemEEPROMReadBackandVerify(Adapter
, (PUINT
)pBuffer
, uiOffset
, uiNumBytes
);
1947 //-----------------------------------------------------------------------------
1948 // Procedure: BcmUpdateSectorSize
1950 // Description: Updates the sector size to FLASH.
1953 // Adapter - ptr to Adapter object instance
1954 // uiSectorSize - sector size
1957 // OSAL_STATUS_SUCCESS - if NVM write is successful.
1958 // <FAILURE> - if failed.
1959 //-----------------------------------------------------------------------------
1961 INT
BcmUpdateSectorSize(struct bcm_mini_adapter
*Adapter
, UINT uiSectorSize
)
1964 FLASH_CS_INFO sFlashCsInfo
= {0};
1966 UINT uiSectorSig
= 0;
1967 UINT uiCurrentSectorSize
= 0;
1970 rdmalt(Adapter
, 0x0f000C80, &uiTemp
, sizeof(uiTemp
));
1972 wrmalt(Adapter
, 0x0f000C80, &value
, sizeof(value
));
1975 // Before updating the sector size in the reserved area, check if already present.
1977 BeceemFlashBulkRead(Adapter
, (PUINT
)&sFlashCsInfo
, Adapter
->ulFlashControlSectionStart
, sizeof(sFlashCsInfo
));
1978 uiSectorSig
= ntohl(sFlashCsInfo
.FlashSectorSizeSig
);
1979 uiCurrentSectorSize
= ntohl(sFlashCsInfo
.FlashSectorSize
);
1981 if (uiSectorSig
== FLASH_SECTOR_SIZE_SIG
) {
1982 if ((uiCurrentSectorSize
<= MAX_SECTOR_SIZE
) && (uiCurrentSectorSize
>= MIN_SECTOR_SIZE
)) {
1983 if (uiSectorSize
== uiCurrentSectorSize
) {
1984 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "Provided sector size is same as programmed in Flash");
1985 Status
= STATUS_SUCCESS
;
1991 if ((uiSectorSize
<= MAX_SECTOR_SIZE
) && (uiSectorSize
>= MIN_SECTOR_SIZE
)) {
1992 sFlashCsInfo
.FlashSectorSize
= htonl(uiSectorSize
);
1993 sFlashCsInfo
.FlashSectorSizeSig
= htonl(FLASH_SECTOR_SIZE_SIG
);
1995 Status
= BeceemFlashBulkWrite(Adapter
,
1996 (PUINT
)&sFlashCsInfo
,
1997 Adapter
->ulFlashControlSectionStart
,
1998 sizeof(sFlashCsInfo
),
2003 // restore the values.
2004 wrmalt(Adapter
, 0x0f000C80, &uiTemp
, sizeof(uiTemp
));
2009 //-----------------------------------------------------------------------------
2010 // Procedure: BcmGetFlashSectorSize
2012 // Description: Finds the sector size of the FLASH.
2015 // Adapter - ptr to Adapter object instance
2018 // UINT - sector size.
2020 //-----------------------------------------------------------------------------
2022 static UINT
BcmGetFlashSectorSize(struct bcm_mini_adapter
*Adapter
, UINT FlashSectorSizeSig
, UINT FlashSectorSize
)
2024 UINT uiSectorSize
= 0;
2025 UINT uiSectorSig
= 0;
2027 if (Adapter
->bSectorSizeOverride
&&
2028 (Adapter
->uiSectorSizeInCFG
<= MAX_SECTOR_SIZE
&&
2029 Adapter
->uiSectorSizeInCFG
>= MIN_SECTOR_SIZE
)) {
2030 Adapter
->uiSectorSize
= Adapter
->uiSectorSizeInCFG
;
2032 uiSectorSig
= FlashSectorSizeSig
;
2034 if (uiSectorSig
== FLASH_SECTOR_SIZE_SIG
) {
2035 uiSectorSize
= FlashSectorSize
;
2037 // If the sector size stored in the FLASH makes sense then use it.
2039 if (uiSectorSize
<= MAX_SECTOR_SIZE
&& uiSectorSize
>= MIN_SECTOR_SIZE
) {
2040 Adapter
->uiSectorSize
= uiSectorSize
;
2041 } else if (Adapter
->uiSectorSizeInCFG
<= MAX_SECTOR_SIZE
&&
2042 Adapter
->uiSectorSizeInCFG
>= MIN_SECTOR_SIZE
) {
2043 //No valid size in FLASH, check if Config file has it.
2044 Adapter
->uiSectorSize
= Adapter
->uiSectorSizeInCFG
;
2046 // Init to Default, if none of the above works.
2047 Adapter
->uiSectorSize
= DEFAULT_SECTOR_SIZE
;
2050 if (Adapter
->uiSectorSizeInCFG
<= MAX_SECTOR_SIZE
&&
2051 Adapter
->uiSectorSizeInCFG
>= MIN_SECTOR_SIZE
)
2052 Adapter
->uiSectorSize
= Adapter
->uiSectorSizeInCFG
;
2054 Adapter
->uiSectorSize
= DEFAULT_SECTOR_SIZE
;
2058 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "Sector size :%x\n", Adapter
->uiSectorSize
);
2060 return Adapter
->uiSectorSize
;
2063 //-----------------------------------------------------------------------------
2064 // Procedure: BcmInitEEPROMQueues
2066 // Description: Initialization of EEPROM queues.
2069 // Adapter - ptr to Adapter object instance
2072 // <OSAL_STATUS_CODE>
2073 //-----------------------------------------------------------------------------
2075 static INT
BcmInitEEPROMQueues(struct bcm_mini_adapter
*Adapter
)
2078 /* CHIP Bug : Clear the Avail bits on the Read queue. The default
2079 * value on this register is supposed to be 0x00001102.
2080 * But we get 0x00001122. */
2081 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "Fixing reset value on 0x0f003004 register\n");
2082 value
= EEPROM_READ_DATA_AVAIL
;
2083 wrmalt(Adapter
, EEPROM_SPI_Q_STATUS1_REG
, &value
, sizeof(value
));
2085 /* Flush the all the EEPROM queues. */
2086 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, " Flushing the queues\n");
2087 value
= EEPROM_ALL_QUEUE_FLUSH
;
2088 wrmalt(Adapter
, SPI_FLUSH_REG
, &value
, sizeof(value
));
2091 wrmalt(Adapter
, SPI_FLUSH_REG
, &value
, sizeof(value
));
2093 /* Read the EEPROM Status Register. Just to see, no real purpose. */
2094 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "EEPROM Status register value = %x\n", ReadEEPROMStatusRegister(Adapter
));
2096 return STATUS_SUCCESS
;
2097 } /* BcmInitEEPROMQueues() */
2099 //-----------------------------------------------------------------------------
2100 // Procedure: BcmInitNVM
2102 // Description: Initialization of NVM, EEPROM size,FLASH size, sector size etc.
2105 // Adapter - ptr to Adapter object instance
2108 // <OSAL_STATUS_CODE>
2109 //-----------------------------------------------------------------------------
2111 INT
BcmInitNVM(struct bcm_mini_adapter
*ps_adapter
)
2113 BcmValidateNvmType(ps_adapter
);
2114 BcmInitEEPROMQueues(ps_adapter
);
2116 if (ps_adapter
->eNVMType
== NVM_AUTODETECT
) {
2117 ps_adapter
->eNVMType
= BcmGetNvmType(ps_adapter
);
2118 if (ps_adapter
->eNVMType
== NVM_UNKNOWN
)
2119 BCM_DEBUG_PRINT(ps_adapter
, DBG_TYPE_PRINTK
, 0, 0, "NVM Type is unknown!!\n");
2120 } else if (ps_adapter
->eNVMType
== NVM_FLASH
) {
2121 BcmGetFlashCSInfo(ps_adapter
);
2124 BcmGetNvmSize(ps_adapter
);
2126 return STATUS_SUCCESS
;
2129 /***************************************************************************/
2130 /*BcmGetNvmSize : set the EEPROM or flash size in Adapter.
2133 * Adapter data structure
2137 /***************************************************************************/
2139 static INT
BcmGetNvmSize(struct bcm_mini_adapter
*Adapter
)
2141 if (Adapter
->eNVMType
== NVM_EEPROM
)
2142 Adapter
->uiNVMDSDSize
= BcmGetEEPROMSize(Adapter
);
2143 else if (Adapter
->eNVMType
== NVM_FLASH
)
2144 Adapter
->uiNVMDSDSize
= BcmGetFlashSize(Adapter
);
2149 //-----------------------------------------------------------------------------
2150 // Procedure: BcmValidateNvm
2152 // Description: Validates the NVM Type option selected against the device
2155 // Adapter - ptr to Adapter object instance
2159 //-----------------------------------------------------------------------------
2161 static VOID
BcmValidateNvmType(struct bcm_mini_adapter
*Adapter
)
2164 // if forcing the FLASH through CFG file, we should ensure device really has a FLASH.
2165 // Accessing the FLASH address without the FLASH being present can cause hang/freeze etc.
2166 // So if NVM_FLASH is selected for older chipsets, change it to AUTODETECT where EEPROM is 1st choice.
2169 if (Adapter
->eNVMType
== NVM_FLASH
&&
2170 Adapter
->chip_id
< 0xBECE3300)
2171 Adapter
->eNVMType
= NVM_AUTODETECT
;
2174 //-----------------------------------------------------------------------------
2175 // Procedure: BcmReadFlashRDID
2177 // Description: Reads ID from Serial Flash
2180 // Adapter - ptr to Adapter object instance
2184 //-----------------------------------------------------------------------------
2186 static ULONG
BcmReadFlashRDID(struct bcm_mini_adapter
*Adapter
)
2192 // Read ID Instruction.
2194 value
= (FLASH_CMD_READ_ID
<< 24);
2195 wrmalt(Adapter
, FLASH_SPI_CMDQ_REG
, &value
, sizeof(value
));
2201 // Read SPI READQ REG. The output will be WWXXYYZZ.
2202 // The ID is 3Bytes long and is WWXXYY. ZZ needs to be Ignored.
2204 rdmalt(Adapter
, FLASH_SPI_READQ_REG
, (PUINT
)&ulRDID
, sizeof(ulRDID
));
2206 return (ulRDID
>> 8);
2209 INT
BcmAllocFlashCSStructure(struct bcm_mini_adapter
*psAdapter
)
2211 if (psAdapter
== NULL
) {
2212 BCM_DEBUG_PRINT(psAdapter
, DBG_TYPE_PRINTK
, 0, 0, "Adapter structure point is NULL");
2215 psAdapter
->psFlashCSInfo
= (PFLASH_CS_INFO
)kzalloc(sizeof(FLASH_CS_INFO
), GFP_KERNEL
);
2216 if (psAdapter
->psFlashCSInfo
== NULL
) {
2217 BCM_DEBUG_PRINT(psAdapter
, DBG_TYPE_PRINTK
, 0, 0, "Can't Allocate memory for Flash 1.x");
2221 psAdapter
->psFlash2xCSInfo
= (PFLASH2X_CS_INFO
)kzalloc(sizeof(FLASH2X_CS_INFO
), GFP_KERNEL
);
2222 if (psAdapter
->psFlash2xCSInfo
== NULL
) {
2223 BCM_DEBUG_PRINT(psAdapter
, DBG_TYPE_PRINTK
, 0, 0, "Can't Allocate memory for Flash 2.x");
2224 kfree(psAdapter
->psFlashCSInfo
);
2228 psAdapter
->psFlash2xVendorInfo
= (PFLASH2X_VENDORSPECIFIC_INFO
)kzalloc(sizeof(FLASH2X_VENDORSPECIFIC_INFO
), GFP_KERNEL
);
2229 if (psAdapter
->psFlash2xVendorInfo
== NULL
) {
2230 BCM_DEBUG_PRINT(psAdapter
, DBG_TYPE_PRINTK
, 0, 0, "Can't Allocate Vendor Info Memory for Flash 2.x");
2231 kfree(psAdapter
->psFlashCSInfo
);
2232 kfree(psAdapter
->psFlash2xCSInfo
);
2236 return STATUS_SUCCESS
;
2239 INT
BcmDeAllocFlashCSStructure(struct bcm_mini_adapter
*psAdapter
)
2241 if (psAdapter
== NULL
) {
2242 BCM_DEBUG_PRINT(psAdapter
, DBG_TYPE_PRINTK
, 0, 0, "Adapter structure point is NULL");
2245 kfree(psAdapter
->psFlashCSInfo
);
2246 kfree(psAdapter
->psFlash2xCSInfo
);
2247 kfree(psAdapter
->psFlash2xVendorInfo
);
2248 return STATUS_SUCCESS
;
2251 static INT
BcmDumpFlash2XCSStructure(PFLASH2X_CS_INFO psFlash2xCSInfo
, struct bcm_mini_adapter
*Adapter
)
2255 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "**********************FLASH2X CS Structure *******************");
2256 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "Signature is :%x", (psFlash2xCSInfo
->MagicNumber
));
2257 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "Flash Major Version :%d", MAJOR_VERSION(psFlash2xCSInfo
->FlashLayoutVersion
));
2258 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "Flash Minor Version :%d", MINOR_VERSION(psFlash2xCSInfo
->FlashLayoutVersion
));
2259 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, " ISOImageMajorVersion:0x%x", (psFlash2xCSInfo
->ISOImageVersion
));
2260 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "SCSIFirmwareMajorVersion :0x%x", (psFlash2xCSInfo
->SCSIFirmwareVersion
));
2261 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "OffsetFromZeroForPart1ISOImage :0x%x", (psFlash2xCSInfo
->OffsetFromZeroForPart1ISOImage
));
2262 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "OffsetFromZeroForScsiFirmware :0x%x", (psFlash2xCSInfo
->OffsetFromZeroForScsiFirmware
));
2263 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "SizeOfScsiFirmware :0x%x", (psFlash2xCSInfo
->SizeOfScsiFirmware
));
2264 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "OffsetFromZeroForPart2ISOImage :0x%x", (psFlash2xCSInfo
->OffsetFromZeroForPart2ISOImage
));
2265 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "OffsetFromZeroForDSDStart :0x%x", (psFlash2xCSInfo
->OffsetFromZeroForDSDStart
));
2266 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "OffsetFromZeroForDSDEnd :0x%x", (psFlash2xCSInfo
->OffsetFromZeroForDSDEnd
));
2267 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "OffsetFromZeroForVSAStart :0x%x", (psFlash2xCSInfo
->OffsetFromZeroForVSAStart
));
2268 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "OffsetFromZeroForVSAEnd :0x%x", (psFlash2xCSInfo
->OffsetFromZeroForVSAEnd
));
2269 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "OffsetFromZeroForControlSectionStart :0x%x", (psFlash2xCSInfo
->OffsetFromZeroForControlSectionStart
));
2270 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "OffsetFromZeroForControlSectionData :0x%x", (psFlash2xCSInfo
->OffsetFromZeroForControlSectionData
));
2271 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "CDLessInactivityTimeout :0x%x", (psFlash2xCSInfo
->CDLessInactivityTimeout
));
2272 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "NewImageSignature :0x%x", (psFlash2xCSInfo
->NewImageSignature
));
2273 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "FlashSectorSizeSig :0x%x", (psFlash2xCSInfo
->FlashSectorSizeSig
));
2274 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "FlashSectorSize :0x%x", (psFlash2xCSInfo
->FlashSectorSize
));
2275 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "FlashWriteSupportSize :0x%x", (psFlash2xCSInfo
->FlashWriteSupportSize
));
2276 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "TotalFlashSize :0x%X", (psFlash2xCSInfo
->TotalFlashSize
));
2277 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "FlashBaseAddr :0x%x", (psFlash2xCSInfo
->FlashBaseAddr
));
2278 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "FlashPartMaxSize :0x%x", (psFlash2xCSInfo
->FlashPartMaxSize
));
2279 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "IsCDLessDeviceBootSig :0x%x", (psFlash2xCSInfo
->IsCDLessDeviceBootSig
));
2280 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "MassStorageTimeout :0x%x", (psFlash2xCSInfo
->MassStorageTimeout
));
2281 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "OffsetISOImage1Part1Start :0x%x", (psFlash2xCSInfo
->OffsetISOImage1Part1Start
));
2282 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "OffsetISOImage1Part1End :0x%x", (psFlash2xCSInfo
->OffsetISOImage1Part1End
));
2283 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "OffsetISOImage1Part2Start :0x%x", (psFlash2xCSInfo
->OffsetISOImage1Part2Start
));
2284 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "OffsetISOImage1Part2End :0x%x", (psFlash2xCSInfo
->OffsetISOImage1Part2End
));
2285 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "OffsetISOImage1Part3Start :0x%x", (psFlash2xCSInfo
->OffsetISOImage1Part3Start
));
2286 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "OffsetISOImage1Part3End :0x%x", (psFlash2xCSInfo
->OffsetISOImage1Part3End
));
2287 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "OffsetISOImage2Part1Start :0x%x", (psFlash2xCSInfo
->OffsetISOImage2Part1Start
));
2288 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "OffsetISOImage2Part1End :0x%x", (psFlash2xCSInfo
->OffsetISOImage2Part1End
));
2289 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "OffsetISOImage2Part2Start :0x%x", (psFlash2xCSInfo
->OffsetISOImage2Part2Start
));
2290 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "OffsetISOImage2Part2End :0x%x", (psFlash2xCSInfo
->OffsetISOImage2Part2End
));
2291 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "OffsetISOImage2Part3Start :0x%x", (psFlash2xCSInfo
->OffsetISOImage2Part3Start
));
2292 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "OffsetISOImage2Part3End :0x%x", (psFlash2xCSInfo
->OffsetISOImage2Part3End
));
2293 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "OffsetFromDSDStartForDSDHeader :0x%x", (psFlash2xCSInfo
->OffsetFromDSDStartForDSDHeader
));
2294 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "OffsetFromZeroForDSD1Start :0x%x", (psFlash2xCSInfo
->OffsetFromZeroForDSD1Start
));
2295 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "OffsetFromZeroForDSD1End :0x%x", (psFlash2xCSInfo
->OffsetFromZeroForDSD1End
));
2296 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "OffsetFromZeroForDSD2Start :0x%x", (psFlash2xCSInfo
->OffsetFromZeroForDSD2Start
));
2297 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "OffsetFromZeroForDSD2End :0x%x", (psFlash2xCSInfo
->OffsetFromZeroForDSD2End
));
2298 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "OffsetFromZeroForVSA1Start :0x%x", (psFlash2xCSInfo
->OffsetFromZeroForVSA1Start
));
2299 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "OffsetFromZeroForVSA1End :0x%x", (psFlash2xCSInfo
->OffsetFromZeroForVSA1End
));
2300 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "OffsetFromZeroForVSA2Start :0x%x", (psFlash2xCSInfo
->OffsetFromZeroForVSA2Start
));
2301 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "OffsetFromZeroForVSA2End :0x%x", (psFlash2xCSInfo
->OffsetFromZeroForVSA2End
));
2302 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "Sector Access Bit Map is Defined as :");
2304 for (Index
= 0; Index
< (FLASH2X_TOTAL_SIZE
/ (DEFAULT_SECTOR_SIZE
* 16)); Index
++)
2305 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "SectorAccessBitMap[%d] :0x%x", Index
,
2306 (psFlash2xCSInfo
->SectorAccessBitMap
[Index
]));
2308 return STATUS_SUCCESS
;
2311 static INT
ConvertEndianOf2XCSStructure(PFLASH2X_CS_INFO psFlash2xCSInfo
)
2315 psFlash2xCSInfo
->MagicNumber
= ntohl(psFlash2xCSInfo
->MagicNumber
);
2316 psFlash2xCSInfo
->FlashLayoutVersion
= ntohl(psFlash2xCSInfo
->FlashLayoutVersion
);
2317 //psFlash2xCSInfo->FlashLayoutMinorVersion = ntohs(psFlash2xCSInfo->FlashLayoutMinorVersion);
2318 psFlash2xCSInfo
->ISOImageVersion
= ntohl(psFlash2xCSInfo
->ISOImageVersion
);
2319 psFlash2xCSInfo
->SCSIFirmwareVersion
= ntohl(psFlash2xCSInfo
->SCSIFirmwareVersion
);
2320 psFlash2xCSInfo
->OffsetFromZeroForPart1ISOImage
= ntohl(psFlash2xCSInfo
->OffsetFromZeroForPart1ISOImage
);
2321 psFlash2xCSInfo
->OffsetFromZeroForScsiFirmware
= ntohl(psFlash2xCSInfo
->OffsetFromZeroForScsiFirmware
);
2322 psFlash2xCSInfo
->SizeOfScsiFirmware
= ntohl(psFlash2xCSInfo
->SizeOfScsiFirmware
);
2323 psFlash2xCSInfo
->OffsetFromZeroForPart2ISOImage
= ntohl(psFlash2xCSInfo
->OffsetFromZeroForPart2ISOImage
);
2324 psFlash2xCSInfo
->OffsetFromZeroForDSDStart
= ntohl(psFlash2xCSInfo
->OffsetFromZeroForDSDStart
);
2325 psFlash2xCSInfo
->OffsetFromZeroForDSDEnd
= ntohl(psFlash2xCSInfo
->OffsetFromZeroForDSDEnd
);
2326 psFlash2xCSInfo
->OffsetFromZeroForVSAStart
= ntohl(psFlash2xCSInfo
->OffsetFromZeroForVSAStart
);
2327 psFlash2xCSInfo
->OffsetFromZeroForVSAEnd
= ntohl(psFlash2xCSInfo
->OffsetFromZeroForVSAEnd
);
2328 psFlash2xCSInfo
->OffsetFromZeroForControlSectionStart
= ntohl(psFlash2xCSInfo
->OffsetFromZeroForControlSectionStart
);
2329 psFlash2xCSInfo
->OffsetFromZeroForControlSectionData
= ntohl(psFlash2xCSInfo
->OffsetFromZeroForControlSectionData
);
2330 psFlash2xCSInfo
->CDLessInactivityTimeout
= ntohl(psFlash2xCSInfo
->CDLessInactivityTimeout
);
2331 psFlash2xCSInfo
->NewImageSignature
= ntohl(psFlash2xCSInfo
->NewImageSignature
);
2332 psFlash2xCSInfo
->FlashSectorSizeSig
= ntohl(psFlash2xCSInfo
->FlashSectorSizeSig
);
2333 psFlash2xCSInfo
->FlashSectorSize
= ntohl(psFlash2xCSInfo
->FlashSectorSize
);
2334 psFlash2xCSInfo
->FlashWriteSupportSize
= ntohl(psFlash2xCSInfo
->FlashWriteSupportSize
);
2335 psFlash2xCSInfo
->TotalFlashSize
= ntohl(psFlash2xCSInfo
->TotalFlashSize
);
2336 psFlash2xCSInfo
->FlashBaseAddr
= ntohl(psFlash2xCSInfo
->FlashBaseAddr
);
2337 psFlash2xCSInfo
->FlashPartMaxSize
= ntohl(psFlash2xCSInfo
->FlashPartMaxSize
);
2338 psFlash2xCSInfo
->IsCDLessDeviceBootSig
= ntohl(psFlash2xCSInfo
->IsCDLessDeviceBootSig
);
2339 psFlash2xCSInfo
->MassStorageTimeout
= ntohl(psFlash2xCSInfo
->MassStorageTimeout
);
2340 psFlash2xCSInfo
->OffsetISOImage1Part1Start
= ntohl(psFlash2xCSInfo
->OffsetISOImage1Part1Start
);
2341 psFlash2xCSInfo
->OffsetISOImage1Part1End
= ntohl(psFlash2xCSInfo
->OffsetISOImage1Part1End
);
2342 psFlash2xCSInfo
->OffsetISOImage1Part2Start
= ntohl(psFlash2xCSInfo
->OffsetISOImage1Part2Start
);
2343 psFlash2xCSInfo
->OffsetISOImage1Part2End
= ntohl(psFlash2xCSInfo
->OffsetISOImage1Part2End
);
2344 psFlash2xCSInfo
->OffsetISOImage1Part3Start
= ntohl(psFlash2xCSInfo
->OffsetISOImage1Part3Start
);
2345 psFlash2xCSInfo
->OffsetISOImage1Part3End
= ntohl(psFlash2xCSInfo
->OffsetISOImage1Part3End
);
2346 psFlash2xCSInfo
->OffsetISOImage2Part1Start
= ntohl(psFlash2xCSInfo
->OffsetISOImage2Part1Start
);
2347 psFlash2xCSInfo
->OffsetISOImage2Part1End
= ntohl(psFlash2xCSInfo
->OffsetISOImage2Part1End
);
2348 psFlash2xCSInfo
->OffsetISOImage2Part2Start
= ntohl(psFlash2xCSInfo
->OffsetISOImage2Part2Start
);
2349 psFlash2xCSInfo
->OffsetISOImage2Part2End
= ntohl(psFlash2xCSInfo
->OffsetISOImage2Part2End
);
2350 psFlash2xCSInfo
->OffsetISOImage2Part3Start
= ntohl(psFlash2xCSInfo
->OffsetISOImage2Part3Start
);
2351 psFlash2xCSInfo
->OffsetISOImage2Part3End
= ntohl(psFlash2xCSInfo
->OffsetISOImage2Part3End
);
2352 psFlash2xCSInfo
->OffsetFromDSDStartForDSDHeader
= ntohl(psFlash2xCSInfo
->OffsetFromDSDStartForDSDHeader
);
2353 psFlash2xCSInfo
->OffsetFromZeroForDSD1Start
= ntohl(psFlash2xCSInfo
->OffsetFromZeroForDSD1Start
);
2354 psFlash2xCSInfo
->OffsetFromZeroForDSD1End
= ntohl(psFlash2xCSInfo
->OffsetFromZeroForDSD1End
);
2355 psFlash2xCSInfo
->OffsetFromZeroForDSD2Start
= ntohl(psFlash2xCSInfo
->OffsetFromZeroForDSD2Start
);
2356 psFlash2xCSInfo
->OffsetFromZeroForDSD2End
= ntohl(psFlash2xCSInfo
->OffsetFromZeroForDSD2End
);
2357 psFlash2xCSInfo
->OffsetFromZeroForVSA1Start
= ntohl(psFlash2xCSInfo
->OffsetFromZeroForVSA1Start
);
2358 psFlash2xCSInfo
->OffsetFromZeroForVSA1End
= ntohl(psFlash2xCSInfo
->OffsetFromZeroForVSA1End
);
2359 psFlash2xCSInfo
->OffsetFromZeroForVSA2Start
= ntohl(psFlash2xCSInfo
->OffsetFromZeroForVSA2Start
);
2360 psFlash2xCSInfo
->OffsetFromZeroForVSA2End
= ntohl(psFlash2xCSInfo
->OffsetFromZeroForVSA2End
);
2362 for (Index
= 0; Index
< (FLASH2X_TOTAL_SIZE
/ (DEFAULT_SECTOR_SIZE
* 16)); Index
++)
2363 psFlash2xCSInfo
->SectorAccessBitMap
[Index
] = ntohl(psFlash2xCSInfo
->SectorAccessBitMap
[Index
]);
2365 return STATUS_SUCCESS
;
2368 static INT
ConvertEndianOfCSStructure(PFLASH_CS_INFO psFlashCSInfo
)
2371 psFlashCSInfo
->MagicNumber
= ntohl(psFlashCSInfo
->MagicNumber
);
2372 psFlashCSInfo
->FlashLayoutVersion
= ntohl(psFlashCSInfo
->FlashLayoutVersion
);
2373 psFlashCSInfo
->ISOImageVersion
= ntohl(psFlashCSInfo
->ISOImageVersion
);
2374 //won't convert according to old assumption
2375 psFlashCSInfo
->SCSIFirmwareVersion
= (psFlashCSInfo
->SCSIFirmwareVersion
);
2376 psFlashCSInfo
->OffsetFromZeroForPart1ISOImage
= ntohl(psFlashCSInfo
->OffsetFromZeroForPart1ISOImage
);
2377 psFlashCSInfo
->OffsetFromZeroForScsiFirmware
= ntohl(psFlashCSInfo
->OffsetFromZeroForScsiFirmware
);
2378 psFlashCSInfo
->SizeOfScsiFirmware
= ntohl(psFlashCSInfo
->SizeOfScsiFirmware
);
2379 psFlashCSInfo
->OffsetFromZeroForPart2ISOImage
= ntohl(psFlashCSInfo
->OffsetFromZeroForPart2ISOImage
);
2380 psFlashCSInfo
->OffsetFromZeroForCalibrationStart
= ntohl(psFlashCSInfo
->OffsetFromZeroForCalibrationStart
);
2381 psFlashCSInfo
->OffsetFromZeroForCalibrationEnd
= ntohl(psFlashCSInfo
->OffsetFromZeroForCalibrationEnd
);
2382 psFlashCSInfo
->OffsetFromZeroForVSAStart
= ntohl(psFlashCSInfo
->OffsetFromZeroForVSAStart
);
2383 psFlashCSInfo
->OffsetFromZeroForVSAEnd
= ntohl(psFlashCSInfo
->OffsetFromZeroForVSAEnd
);
2384 psFlashCSInfo
->OffsetFromZeroForControlSectionStart
= ntohl(psFlashCSInfo
->OffsetFromZeroForControlSectionStart
);
2385 psFlashCSInfo
->OffsetFromZeroForControlSectionData
= ntohl(psFlashCSInfo
->OffsetFromZeroForControlSectionData
);
2386 psFlashCSInfo
->CDLessInactivityTimeout
= ntohl(psFlashCSInfo
->CDLessInactivityTimeout
);
2387 psFlashCSInfo
->NewImageSignature
= ntohl(psFlashCSInfo
->NewImageSignature
);
2388 psFlashCSInfo
->FlashSectorSizeSig
= ntohl(psFlashCSInfo
->FlashSectorSizeSig
);
2389 psFlashCSInfo
->FlashSectorSize
= ntohl(psFlashCSInfo
->FlashSectorSize
);
2390 psFlashCSInfo
->FlashWriteSupportSize
= ntohl(psFlashCSInfo
->FlashWriteSupportSize
);
2391 psFlashCSInfo
->TotalFlashSize
= ntohl(psFlashCSInfo
->TotalFlashSize
);
2392 psFlashCSInfo
->FlashBaseAddr
= ntohl(psFlashCSInfo
->FlashBaseAddr
);
2393 psFlashCSInfo
->FlashPartMaxSize
= ntohl(psFlashCSInfo
->FlashPartMaxSize
);
2394 psFlashCSInfo
->IsCDLessDeviceBootSig
= ntohl(psFlashCSInfo
->IsCDLessDeviceBootSig
);
2395 psFlashCSInfo
->MassStorageTimeout
= ntohl(psFlashCSInfo
->MassStorageTimeout
);
2397 return STATUS_SUCCESS
;
2400 static INT
IsSectionExistInVendorInfo(struct bcm_mini_adapter
*Adapter
, FLASH2X_SECTION_VAL section
)
2402 return (Adapter
->uiVendorExtnFlag
&&
2403 (Adapter
->psFlash2xVendorInfo
->VendorSection
[section
].AccessFlags
& FLASH2X_SECTION_PRESENT
) &&
2404 (Adapter
->psFlash2xVendorInfo
->VendorSection
[section
].OffsetFromZeroForSectionStart
!= UNINIT_PTR_IN_CS
));
2407 static VOID
UpdateVendorInfo(struct bcm_mini_adapter
*Adapter
)
2410 UINT uiSizeSection
= 0;
2412 Adapter
->uiVendorExtnFlag
= FALSE
;
2414 for (i
= 0; i
< TOTAL_SECTIONS
; i
++)
2415 Adapter
->psFlash2xVendorInfo
->VendorSection
[i
].OffsetFromZeroForSectionStart
= UNINIT_PTR_IN_CS
;
2417 if (STATUS_SUCCESS
!= vendorextnGetSectionInfo(Adapter
, Adapter
->psFlash2xVendorInfo
))
2421 while (i
< TOTAL_SECTIONS
) {
2422 if (!(Adapter
->psFlash2xVendorInfo
->VendorSection
[i
].AccessFlags
& FLASH2X_SECTION_PRESENT
)) {
2427 Adapter
->uiVendorExtnFlag
= TRUE
;
2428 uiSizeSection
= (Adapter
->psFlash2xVendorInfo
->VendorSection
[i
].OffsetFromZeroForSectionEnd
-
2429 Adapter
->psFlash2xVendorInfo
->VendorSection
[i
].OffsetFromZeroForSectionStart
);
2433 if ((uiSizeSection
>= (Adapter
->psFlash2xCSInfo
->OffsetFromDSDStartForDSDHeader
+ sizeof(DSD_HEADER
))) &&
2434 (UNINIT_PTR_IN_CS
!= Adapter
->psFlash2xVendorInfo
->VendorSection
[i
].OffsetFromZeroForSectionStart
))
2435 Adapter
->psFlash2xCSInfo
->OffsetFromZeroForDSDStart
= Adapter
->psFlash2xCSInfo
->OffsetFromZeroForDSDEnd
= VENDOR_PTR_IN_CS
;
2437 Adapter
->psFlash2xCSInfo
->OffsetFromZeroForDSDStart
= Adapter
->psFlash2xCSInfo
->OffsetFromZeroForDSDEnd
= UNINIT_PTR_IN_CS
;
2441 if ((uiSizeSection
>= (Adapter
->psFlash2xCSInfo
->OffsetFromDSDStartForDSDHeader
+ sizeof(DSD_HEADER
))) &&
2442 (UNINIT_PTR_IN_CS
!= Adapter
->psFlash2xVendorInfo
->VendorSection
[i
].OffsetFromZeroForSectionStart
))
2443 Adapter
->psFlash2xCSInfo
->OffsetFromZeroForDSD1Start
= Adapter
->psFlash2xCSInfo
->OffsetFromZeroForDSD1End
= VENDOR_PTR_IN_CS
;
2445 Adapter
->psFlash2xCSInfo
->OffsetFromZeroForDSD1Start
= Adapter
->psFlash2xCSInfo
->OffsetFromZeroForDSD1End
= UNINIT_PTR_IN_CS
;
2449 if ((uiSizeSection
>= (Adapter
->psFlash2xCSInfo
->OffsetFromDSDStartForDSDHeader
+ sizeof(DSD_HEADER
))) &&
2450 (UNINIT_PTR_IN_CS
!= Adapter
->psFlash2xVendorInfo
->VendorSection
[i
].OffsetFromZeroForSectionStart
))
2451 Adapter
->psFlash2xCSInfo
->OffsetFromZeroForDSD2Start
= Adapter
->psFlash2xCSInfo
->OffsetFromZeroForDSD2End
= VENDOR_PTR_IN_CS
;
2453 Adapter
->psFlash2xCSInfo
->OffsetFromZeroForDSD2Start
= Adapter
->psFlash2xCSInfo
->OffsetFromZeroForDSD2End
= UNINIT_PTR_IN_CS
;
2456 if (UNINIT_PTR_IN_CS
!= Adapter
->psFlash2xVendorInfo
->VendorSection
[i
].OffsetFromZeroForSectionStart
)
2457 Adapter
->psFlash2xCSInfo
->OffsetFromZeroForVSAStart
= Adapter
->psFlash2xCSInfo
->OffsetFromZeroForVSAEnd
= VENDOR_PTR_IN_CS
;
2459 Adapter
->psFlash2xCSInfo
->OffsetFromZeroForVSAStart
= Adapter
->psFlash2xCSInfo
->OffsetFromZeroForVSAEnd
= UNINIT_PTR_IN_CS
;
2463 if (UNINIT_PTR_IN_CS
!= Adapter
->psFlash2xVendorInfo
->VendorSection
[i
].OffsetFromZeroForSectionStart
)
2464 Adapter
->psFlash2xCSInfo
->OffsetFromZeroForVSA1Start
= Adapter
->psFlash2xCSInfo
->OffsetFromZeroForVSA1End
= VENDOR_PTR_IN_CS
;
2466 Adapter
->psFlash2xCSInfo
->OffsetFromZeroForVSA1Start
= Adapter
->psFlash2xCSInfo
->OffsetFromZeroForVSA1End
= UNINIT_PTR_IN_CS
;
2469 if (UNINIT_PTR_IN_CS
!= Adapter
->psFlash2xVendorInfo
->VendorSection
[i
].OffsetFromZeroForSectionStart
)
2470 Adapter
->psFlash2xCSInfo
->OffsetFromZeroForVSA2Start
= Adapter
->psFlash2xCSInfo
->OffsetFromZeroForVSA2End
= VENDOR_PTR_IN_CS
;
2472 Adapter
->psFlash2xCSInfo
->OffsetFromZeroForVSA2Start
= Adapter
->psFlash2xCSInfo
->OffsetFromZeroForVSA2End
= UNINIT_PTR_IN_CS
;
2482 //-----------------------------------------------------------------------------
2483 // Procedure: BcmGetFlashCSInfo
2485 // Description: Reads control structure and gets Cal section addresses.
2488 // Adapter - ptr to Adapter object instance
2492 //-----------------------------------------------------------------------------
2494 static INT
BcmGetFlashCSInfo(struct bcm_mini_adapter
*Adapter
)
2496 //FLASH_CS_INFO sFlashCsInfo = {0};
2498 #if !defined(BCM_SHM_INTERFACE) || defined(FLASH_DIRECT_ACCESS)
2502 UINT uiFlashLayoutMajorVersion
;
2503 Adapter
->uiFlashLayoutMinorVersion
= 0;
2504 Adapter
->uiFlashLayoutMajorVersion
= 0;
2505 Adapter
->ulFlashControlSectionStart
= FLASH_CS_INFO_START_ADDR
;
2507 Adapter
->uiFlashBaseAdd
= 0;
2508 Adapter
->ulFlashCalStart
= 0;
2509 memset(Adapter
->psFlashCSInfo
, 0 , sizeof(FLASH_CS_INFO
));
2510 memset(Adapter
->psFlash2xCSInfo
, 0 , sizeof(FLASH2X_CS_INFO
));
2512 if (!Adapter
->bDDRInitDone
) {
2513 value
= FLASH_CONTIGIOUS_START_ADDR_BEFORE_INIT
;
2514 wrmalt(Adapter
, 0xAF00A080, &value
, sizeof(value
));
2517 // Reading first 8 Bytes to get the Flash Layout
2518 // MagicNumber(4 bytes) +FlashLayoutMinorVersion(2 Bytes) +FlashLayoutMajorVersion(2 Bytes)
2519 BeceemFlashBulkRead(Adapter
, (PUINT
)Adapter
->psFlashCSInfo
, Adapter
->ulFlashControlSectionStart
, 8);
2521 Adapter
->psFlashCSInfo
->FlashLayoutVersion
= ntohl(Adapter
->psFlashCSInfo
->FlashLayoutVersion
);
2522 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "Flash Layout Version :%X", (Adapter
->psFlashCSInfo
->FlashLayoutVersion
));
2523 //BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Flash Layout Minor Version :%d\n", ntohs(sFlashCsInfo.FlashLayoutMinorVersion));
2524 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "Signature is :%x\n", ntohl(Adapter
->psFlashCSInfo
->MagicNumber
));
2526 if (FLASH_CONTROL_STRUCT_SIGNATURE
== ntohl(Adapter
->psFlashCSInfo
->MagicNumber
)) {
2527 uiFlashLayoutMajorVersion
= MAJOR_VERSION((Adapter
->psFlashCSInfo
->FlashLayoutVersion
));
2528 Adapter
->uiFlashLayoutMinorVersion
= MINOR_VERSION((Adapter
->psFlashCSInfo
->FlashLayoutVersion
));
2530 Adapter
->uiFlashLayoutMinorVersion
= 0;
2531 uiFlashLayoutMajorVersion
= 0;
2534 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "FLASH LAYOUT MAJOR VERSION :%X", uiFlashLayoutMajorVersion
);
2536 if (uiFlashLayoutMajorVersion
< FLASH_2X_MAJOR_NUMBER
) {
2537 BeceemFlashBulkRead(Adapter
, (PUINT
)Adapter
->psFlashCSInfo
, Adapter
->ulFlashControlSectionStart
, sizeof(FLASH_CS_INFO
));
2538 ConvertEndianOfCSStructure(Adapter
->psFlashCSInfo
);
2539 Adapter
->ulFlashCalStart
= (Adapter
->psFlashCSInfo
->OffsetFromZeroForCalibrationStart
);
2541 if (!((Adapter
->uiFlashLayoutMajorVersion
== 1) && (Adapter
->uiFlashLayoutMinorVersion
== 1)))
2542 Adapter
->ulFlashControlSectionStart
= Adapter
->psFlashCSInfo
->OffsetFromZeroForControlSectionStart
;
2544 if ((FLASH_CONTROL_STRUCT_SIGNATURE
== (Adapter
->psFlashCSInfo
->MagicNumber
)) &&
2545 (SCSI_FIRMWARE_MINOR_VERSION
<= MINOR_VERSION(Adapter
->psFlashCSInfo
->SCSIFirmwareVersion
)) &&
2546 (FLASH_SECTOR_SIZE_SIG
== (Adapter
->psFlashCSInfo
->FlashSectorSizeSig
)) &&
2547 (BYTE_WRITE_SUPPORT
== (Adapter
->psFlashCSInfo
->FlashWriteSupportSize
))) {
2548 Adapter
->ulFlashWriteSize
= (Adapter
->psFlashCSInfo
->FlashWriteSupportSize
);
2549 Adapter
->fpFlashWrite
= flashByteWrite
;
2550 Adapter
->fpFlashWriteWithStatusCheck
= flashByteWriteStatus
;
2552 Adapter
->ulFlashWriteSize
= MAX_RW_SIZE
;
2553 Adapter
->fpFlashWrite
= flashWrite
;
2554 Adapter
->fpFlashWriteWithStatusCheck
= flashWriteStatus
;
2557 BcmGetFlashSectorSize(Adapter
, (Adapter
->psFlashCSInfo
->FlashSectorSizeSig
),
2558 (Adapter
->psFlashCSInfo
->FlashSectorSize
));
2559 Adapter
->uiFlashBaseAdd
= Adapter
->psFlashCSInfo
->FlashBaseAddr
& 0xFCFFFFFF;
2561 if (BcmFlash2xBulkRead(Adapter
, (PUINT
)Adapter
->psFlash2xCSInfo
, NO_SECTION_VAL
,
2562 Adapter
->ulFlashControlSectionStart
, sizeof(FLASH2X_CS_INFO
))) {
2563 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Unable to read CS structure\n");
2564 return STATUS_FAILURE
;
2567 ConvertEndianOf2XCSStructure(Adapter
->psFlash2xCSInfo
);
2568 BcmDumpFlash2XCSStructure(Adapter
->psFlash2xCSInfo
, Adapter
);
2569 if ((FLASH_CONTROL_STRUCT_SIGNATURE
== Adapter
->psFlash2xCSInfo
->MagicNumber
) &&
2570 (SCSI_FIRMWARE_MINOR_VERSION
<= MINOR_VERSION(Adapter
->psFlash2xCSInfo
->SCSIFirmwareVersion
)) &&
2571 (FLASH_SECTOR_SIZE_SIG
== Adapter
->psFlash2xCSInfo
->FlashSectorSizeSig
) &&
2572 (BYTE_WRITE_SUPPORT
== Adapter
->psFlash2xCSInfo
->FlashWriteSupportSize
)) {
2573 Adapter
->ulFlashWriteSize
= Adapter
->psFlash2xCSInfo
->FlashWriteSupportSize
;
2574 Adapter
->fpFlashWrite
= flashByteWrite
;
2575 Adapter
->fpFlashWriteWithStatusCheck
= flashByteWriteStatus
;
2577 Adapter
->ulFlashWriteSize
= MAX_RW_SIZE
;
2578 Adapter
->fpFlashWrite
= flashWrite
;
2579 Adapter
->fpFlashWriteWithStatusCheck
= flashWriteStatus
;
2582 BcmGetFlashSectorSize(Adapter
, Adapter
->psFlash2xCSInfo
->FlashSectorSizeSig
,
2583 Adapter
->psFlash2xCSInfo
->FlashSectorSize
);
2585 UpdateVendorInfo(Adapter
);
2587 BcmGetActiveDSD(Adapter
);
2588 BcmGetActiveISO(Adapter
);
2589 Adapter
->uiFlashBaseAdd
= Adapter
->psFlash2xCSInfo
->FlashBaseAddr
& 0xFCFFFFFF;
2590 Adapter
->ulFlashControlSectionStart
= Adapter
->psFlash2xCSInfo
->OffsetFromZeroForControlSectionStart
;
2593 Concerns: what if CS sector size does not match with this sector size ???
2594 what is the indication of AccessBitMap in CS in flash 2.x ????
2596 Adapter
->ulFlashID
= BcmReadFlashRDID(Adapter
);
2597 Adapter
->uiFlashLayoutMajorVersion
= uiFlashLayoutMajorVersion
;
2599 return STATUS_SUCCESS
;
2602 //-----------------------------------------------------------------------------
2603 // Procedure: BcmGetNvmType
2605 // Description: Finds the type of NVM used.
2608 // Adapter - ptr to Adapter object instance
2613 //-----------------------------------------------------------------------------
2615 static NVM_TYPE
BcmGetNvmType(struct bcm_mini_adapter
*Adapter
)
2619 BeceemEEPROMBulkRead(Adapter
, &uiData
, 0x0, 4);
2624 // Read control struct and get cal addresses before accessing the flash
2626 BcmGetFlashCSInfo(Adapter
);
2628 BeceemFlashBulkRead(Adapter
, &uiData
, 0x0 + Adapter
->ulFlashCalStart
, 4);
2633 // even if there is no valid signature on EEPROM/FLASH find out if they really exist.
2634 // if exist select it.
2636 if (BcmGetEEPROMSize(Adapter
))
2644 * BcmGetSectionValStartOffset - this will calculate the section's starting offset if section val is given
2645 * @Adapter : Drivers Private Data structure
2646 * @eFlashSectionVal : Flash secion value defined in enum FLASH2X_SECTION_VAL
2649 * On success it return the start offset of the provided section val
2650 * On Failure -returns STATUS_FAILURE
2653 INT
BcmGetSectionValStartOffset(struct bcm_mini_adapter
*Adapter
, FLASH2X_SECTION_VAL eFlashSectionVal
)
2656 * Considering all the section for which end offset can be calculated or directly given
2657 * in CS Structure. if matching case does not exist, return STATUS_FAILURE indicating section
2658 * endoffset can't be calculated or given in CS Structure.
2661 INT SectStartOffset
= 0;
2663 SectStartOffset
= INVALID_OFFSET
;
2665 if (IsSectionExistInVendorInfo(Adapter
, eFlashSectionVal
))
2666 return Adapter
->psFlash2xVendorInfo
->VendorSection
[eFlashSectionVal
].OffsetFromZeroForSectionStart
;
2668 switch (eFlashSectionVal
) {
2670 if ((Adapter
->psFlash2xCSInfo
->OffsetISOImage1Part1Start
!= UNINIT_PTR_IN_CS
) &&
2671 (IsNonCDLessDevice(Adapter
) == FALSE
))
2672 SectStartOffset
= (Adapter
->psFlash2xCSInfo
->OffsetISOImage1Part1Start
);
2675 if ((Adapter
->psFlash2xCSInfo
->OffsetISOImage2Part1Start
!= UNINIT_PTR_IN_CS
) &&
2676 (IsNonCDLessDevice(Adapter
) == FALSE
))
2677 SectStartOffset
= (Adapter
->psFlash2xCSInfo
->OffsetISOImage2Part1Start
);
2680 if (Adapter
->psFlash2xCSInfo
->OffsetFromZeroForDSDStart
!= UNINIT_PTR_IN_CS
)
2681 SectStartOffset
= (Adapter
->psFlash2xCSInfo
->OffsetFromZeroForDSDStart
);
2684 if (Adapter
->psFlash2xCSInfo
->OffsetFromZeroForDSD1Start
!= UNINIT_PTR_IN_CS
)
2685 SectStartOffset
= (Adapter
->psFlash2xCSInfo
->OffsetFromZeroForDSD1Start
);
2688 if (Adapter
->psFlash2xCSInfo
->OffsetFromZeroForDSD2Start
!= UNINIT_PTR_IN_CS
)
2689 SectStartOffset
= (Adapter
->psFlash2xCSInfo
->OffsetFromZeroForDSD2Start
);
2692 if (Adapter
->psFlash2xCSInfo
->OffsetFromZeroForVSAStart
!= UNINIT_PTR_IN_CS
)
2693 SectStartOffset
= (Adapter
->psFlash2xCSInfo
->OffsetFromZeroForVSAStart
);
2696 if (Adapter
->psFlash2xCSInfo
->OffsetFromZeroForVSA1Start
!= UNINIT_PTR_IN_CS
)
2697 SectStartOffset
= (Adapter
->psFlash2xCSInfo
->OffsetFromZeroForVSA1Start
);
2700 if (Adapter
->psFlash2xCSInfo
->OffsetFromZeroForVSA2Start
!= UNINIT_PTR_IN_CS
)
2701 SectStartOffset
= (Adapter
->psFlash2xCSInfo
->OffsetFromZeroForVSA2Start
);
2704 if (Adapter
->psFlash2xCSInfo
->OffsetFromZeroForScsiFirmware
!= UNINIT_PTR_IN_CS
)
2705 SectStartOffset
= (Adapter
->psFlash2xCSInfo
->OffsetFromZeroForScsiFirmware
);
2707 case CONTROL_SECTION
:
2708 if (Adapter
->psFlash2xCSInfo
->OffsetFromZeroForControlSectionStart
!= UNINIT_PTR_IN_CS
)
2709 SectStartOffset
= (Adapter
->psFlash2xCSInfo
->OffsetFromZeroForControlSectionStart
);
2711 case ISO_IMAGE1_PART2
:
2712 if (Adapter
->psFlash2xCSInfo
->OffsetISOImage1Part2Start
!= UNINIT_PTR_IN_CS
)
2713 SectStartOffset
= (Adapter
->psFlash2xCSInfo
->OffsetISOImage1Part2Start
);
2715 case ISO_IMAGE1_PART3
:
2716 if (Adapter
->psFlash2xCSInfo
->OffsetISOImage1Part3Start
!= UNINIT_PTR_IN_CS
)
2717 SectStartOffset
= (Adapter
->psFlash2xCSInfo
->OffsetISOImage1Part3Start
);
2719 case ISO_IMAGE2_PART2
:
2720 if (Adapter
->psFlash2xCSInfo
->OffsetISOImage2Part2Start
!= UNINIT_PTR_IN_CS
)
2721 SectStartOffset
= (Adapter
->psFlash2xCSInfo
->OffsetISOImage2Part2Start
);
2723 case ISO_IMAGE2_PART3
:
2724 if (Adapter
->psFlash2xCSInfo
->OffsetISOImage2Part3Start
!= UNINIT_PTR_IN_CS
)
2725 SectStartOffset
= (Adapter
->psFlash2xCSInfo
->OffsetISOImage2Part3Start
);
2728 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Section Does not exist in Flash 2.x");
2729 SectStartOffset
= INVALID_OFFSET
;
2732 return SectStartOffset
;
2736 * BcmGetSectionValEndOffset - this will calculate the section's Ending offset if section val is given
2737 * @Adapter : Drivers Private Data structure
2738 * @eFlashSectionVal : Flash secion value defined in enum FLASH2X_SECTION_VAL
2741 * On success it return the end offset of the provided section val
2742 * On Failure -returns STATUS_FAILURE
2745 INT
BcmGetSectionValEndOffset(struct bcm_mini_adapter
*Adapter
, FLASH2X_SECTION_VAL eFlash2xSectionVal
)
2747 INT SectEndOffset
= 0;
2749 SectEndOffset
= INVALID_OFFSET
;
2750 if (IsSectionExistInVendorInfo(Adapter
, eFlash2xSectionVal
))
2751 return Adapter
->psFlash2xVendorInfo
->VendorSection
[eFlash2xSectionVal
].OffsetFromZeroForSectionEnd
;
2753 switch (eFlash2xSectionVal
) {
2755 if ((Adapter
->psFlash2xCSInfo
->OffsetISOImage1Part1End
!= UNINIT_PTR_IN_CS
) &&
2756 (IsNonCDLessDevice(Adapter
) == FALSE
))
2757 SectEndOffset
= (Adapter
->psFlash2xCSInfo
->OffsetISOImage1Part1End
);
2760 if ((Adapter
->psFlash2xCSInfo
->OffsetISOImage2Part1End
!= UNINIT_PTR_IN_CS
) &&
2761 (IsNonCDLessDevice(Adapter
) == FALSE
))
2762 SectEndOffset
= (Adapter
->psFlash2xCSInfo
->OffsetISOImage2Part1End
);
2765 if (Adapter
->psFlash2xCSInfo
->OffsetFromZeroForDSDEnd
!= UNINIT_PTR_IN_CS
)
2766 SectEndOffset
= (Adapter
->psFlash2xCSInfo
->OffsetFromZeroForDSDEnd
);
2769 if (Adapter
->psFlash2xCSInfo
->OffsetFromZeroForDSD1End
!= UNINIT_PTR_IN_CS
)
2770 SectEndOffset
= (Adapter
->psFlash2xCSInfo
->OffsetFromZeroForDSD1End
);
2773 if (Adapter
->psFlash2xCSInfo
->OffsetFromZeroForDSD2End
!= UNINIT_PTR_IN_CS
)
2774 SectEndOffset
= (Adapter
->psFlash2xCSInfo
->OffsetFromZeroForDSD2End
);
2777 if (Adapter
->psFlash2xCSInfo
->OffsetFromZeroForVSAEnd
!= UNINIT_PTR_IN_CS
)
2778 SectEndOffset
= (Adapter
->psFlash2xCSInfo
->OffsetFromZeroForVSAEnd
);
2781 if (Adapter
->psFlash2xCSInfo
->OffsetFromZeroForVSA1End
!= UNINIT_PTR_IN_CS
)
2782 SectEndOffset
= (Adapter
->psFlash2xCSInfo
->OffsetFromZeroForVSA1End
);
2785 if (Adapter
->psFlash2xCSInfo
->OffsetFromZeroForVSA2End
!= UNINIT_PTR_IN_CS
)
2786 SectEndOffset
= (Adapter
->psFlash2xCSInfo
->OffsetFromZeroForVSA2End
);
2789 if (Adapter
->psFlash2xCSInfo
->OffsetFromZeroForScsiFirmware
!= UNINIT_PTR_IN_CS
)
2790 SectEndOffset
= ((Adapter
->psFlash2xCSInfo
->OffsetFromZeroForScsiFirmware
) +
2791 (Adapter
->psFlash2xCSInfo
->SizeOfScsiFirmware
));
2793 case CONTROL_SECTION
:
2794 //Not Clear So Putting failure. confirm and fix it.
2795 SectEndOffset
= STATUS_FAILURE
;
2796 case ISO_IMAGE1_PART2
:
2797 if (Adapter
->psFlash2xCSInfo
->OffsetISOImage1Part2End
!= UNINIT_PTR_IN_CS
)
2798 SectEndOffset
= (Adapter
->psFlash2xCSInfo
->OffsetISOImage1Part2End
);
2800 case ISO_IMAGE1_PART3
:
2801 if (Adapter
->psFlash2xCSInfo
->OffsetISOImage1Part3End
!= UNINIT_PTR_IN_CS
)
2802 SectEndOffset
= (Adapter
->psFlash2xCSInfo
->OffsetISOImage1Part3End
);
2804 case ISO_IMAGE2_PART2
:
2805 if (Adapter
->psFlash2xCSInfo
->OffsetISOImage2Part2End
!= UNINIT_PTR_IN_CS
)
2806 SectEndOffset
= (Adapter
->psFlash2xCSInfo
->OffsetISOImage2Part2End
);
2808 case ISO_IMAGE2_PART3
:
2809 if (Adapter
->psFlash2xCSInfo
->OffsetISOImage2Part3End
!= UNINIT_PTR_IN_CS
)
2810 SectEndOffset
= (Adapter
->psFlash2xCSInfo
->OffsetISOImage2Part3End
);
2813 SectEndOffset
= INVALID_OFFSET
;
2816 return SectEndOffset
;
2820 * BcmFlash2xBulkRead:- Read API for Flash Map 2.x .
2821 * @Adapter :Driver Private Data Structure
2822 * @pBuffer : Buffer where data has to be put after reading
2823 * @eFlashSectionVal :Flash Section Val defined in FLASH2X_SECTION_VAL
2824 * @uiOffsetWithinSectionVal :- Offset with in provided section
2825 * @uiNumBytes : Number of Bytes for Read
2828 * return true on success and STATUS_FAILURE on fail.
2831 INT
BcmFlash2xBulkRead(struct bcm_mini_adapter
*Adapter
,
2833 FLASH2X_SECTION_VAL eFlash2xSectionVal
,
2834 UINT uiOffsetWithinSectionVal
,
2837 INT Status
= STATUS_SUCCESS
;
2838 INT SectionStartOffset
= 0;
2839 UINT uiAbsoluteOffset
= 0;
2840 UINT uiTemp
= 0, value
= 0;
2842 if (Adapter
== NULL
) {
2843 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Adapter structure is NULL");
2846 if (Adapter
->device_removed
) {
2847 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Device has been removed");
2851 //NO_SECTION_VAL means absolute offset is given.
2852 if (eFlash2xSectionVal
== NO_SECTION_VAL
)
2853 SectionStartOffset
= 0;
2855 SectionStartOffset
= BcmGetSectionValStartOffset(Adapter
, eFlash2xSectionVal
);
2857 if (SectionStartOffset
== STATUS_FAILURE
) {
2858 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "This Section<%d> does not exixt in Flash 2.x Map ", eFlash2xSectionVal
);
2862 if (IsSectionExistInVendorInfo(Adapter
, eFlash2xSectionVal
))
2863 return vendorextnReadSection(Adapter
, (PUCHAR
)pBuffer
, eFlash2xSectionVal
, uiOffsetWithinSectionVal
, uiNumBytes
);
2865 //calculating the absolute offset from FLASH;
2866 uiAbsoluteOffset
= uiOffsetWithinSectionVal
+ SectionStartOffset
;
2867 rdmalt(Adapter
, 0x0f000C80, &uiTemp
, sizeof(uiTemp
));
2869 wrmalt(Adapter
, 0x0f000C80, &value
, sizeof(value
));
2870 Status
= BeceemFlashBulkRead(Adapter
, pBuffer
, uiAbsoluteOffset
, uiNumBytes
);
2871 wrmalt(Adapter
, 0x0f000C80, &uiTemp
, sizeof(uiTemp
));
2873 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Flash Read Failed with Status :%d", Status
);
2881 * BcmFlash2xBulkWrite :-API for Writing on the Flash Map 2.x.
2882 * @Adapter :Driver Private Data Structure
2883 * @pBuffer : Buffer From where data has to taken for writing
2884 * @eFlashSectionVal :Flash Section Val defined in FLASH2X_SECTION_VAL
2885 * @uiOffsetWithinSectionVal :- Offset with in provided section
2886 * @uiNumBytes : Number of Bytes for Write
2889 * return true on success and STATUS_FAILURE on fail.
2893 INT
BcmFlash2xBulkWrite(struct bcm_mini_adapter
*Adapter
,
2895 FLASH2X_SECTION_VAL eFlash2xSectVal
,
2900 INT Status
= STATUS_SUCCESS
;
2901 UINT FlashSectValStartOffset
= 0;
2902 UINT uiTemp
= 0, value
= 0;
2904 if (Adapter
== NULL
) {
2905 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Adapter structure is NULL");
2909 if (Adapter
->device_removed
) {
2910 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Device has been removed");
2914 //NO_SECTION_VAL means absolute offset is given.
2915 if (eFlash2xSectVal
== NO_SECTION_VAL
)
2916 FlashSectValStartOffset
= 0;
2918 FlashSectValStartOffset
= BcmGetSectionValStartOffset(Adapter
, eFlash2xSectVal
);
2920 if (FlashSectValStartOffset
== STATUS_FAILURE
) {
2921 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "This Section<%d> does not exixt in Flash Map 2.x", eFlash2xSectVal
);
2925 if (IsSectionExistInVendorInfo(Adapter
, eFlash2xSectVal
))
2926 return vendorextnWriteSection(Adapter
, (PUCHAR
)pBuffer
, eFlash2xSectVal
, uiOffset
, uiNumBytes
, bVerify
);
2928 //calculating the absolute offset from FLASH;
2929 uiOffset
= uiOffset
+ FlashSectValStartOffset
;
2931 rdmalt(Adapter
, 0x0f000C80, &uiTemp
, sizeof(uiTemp
));
2933 wrmalt(Adapter
, 0x0f000C80, &value
, sizeof(value
));
2935 Status
= BeceemFlashBulkWrite(Adapter
, pBuffer
, uiOffset
, uiNumBytes
, bVerify
);
2937 wrmalt(Adapter
, 0x0f000C80, &uiTemp
, sizeof(uiTemp
));
2939 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Flash Write failed with Status :%d", Status
);
2947 * BcmGetActiveDSD : Set the Active DSD in Adapter Structure which has to be dumped in DDR
2948 * @Adapter :-Drivers private Data Structure
2951 * Return STATUS_SUCESS if get success in setting the right DSD else negaive error code
2955 static INT
BcmGetActiveDSD(struct bcm_mini_adapter
*Adapter
)
2957 FLASH2X_SECTION_VAL uiHighestPriDSD
= 0;
2959 uiHighestPriDSD
= getHighestPriDSD(Adapter
);
2960 Adapter
->eActiveDSD
= uiHighestPriDSD
;
2962 if (DSD0
== uiHighestPriDSD
)
2963 Adapter
->ulFlashCalStart
= Adapter
->psFlash2xCSInfo
->OffsetFromZeroForDSDStart
;
2964 if (DSD1
== uiHighestPriDSD
)
2965 Adapter
->ulFlashCalStart
= Adapter
->psFlash2xCSInfo
->OffsetFromZeroForDSD1Start
;
2966 if (DSD2
== uiHighestPriDSD
)
2967 Adapter
->ulFlashCalStart
= Adapter
->psFlash2xCSInfo
->OffsetFromZeroForDSD2Start
;
2968 if (Adapter
->eActiveDSD
)
2969 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "Active DSD :%d", Adapter
->eActiveDSD
);
2970 if (Adapter
->eActiveDSD
== 0) {
2971 //if No DSD gets Active, Make Active the DSD with WR permission
2972 if (IsSectionWritable(Adapter
, DSD2
)) {
2973 Adapter
->eActiveDSD
= DSD2
;
2974 Adapter
->ulFlashCalStart
= Adapter
->psFlash2xCSInfo
->OffsetFromZeroForDSD2Start
;
2975 } else if (IsSectionWritable(Adapter
, DSD1
)) {
2976 Adapter
->eActiveDSD
= DSD1
;
2977 Adapter
->ulFlashCalStart
= Adapter
->psFlash2xCSInfo
->OffsetFromZeroForDSD1Start
;
2978 } else if (IsSectionWritable(Adapter
, DSD0
)) {
2979 Adapter
->eActiveDSD
= DSD0
;
2980 Adapter
->ulFlashCalStart
= Adapter
->psFlash2xCSInfo
->OffsetFromZeroForDSDStart
;
2984 return STATUS_SUCCESS
;
2988 * BcmGetActiveISO :- Set the Active ISO in Adapter Data Structue
2989 * @Adapter : Driver private Data Structure
2992 * Sucsess:- STATUS_SUCESS
2993 * Failure- : negative erro code
2997 static INT
BcmGetActiveISO(struct bcm_mini_adapter
*Adapter
)
2999 INT HighestPriISO
= 0;
3001 HighestPriISO
= getHighestPriISO(Adapter
);
3003 Adapter
->eActiveISO
= HighestPriISO
;
3004 if (Adapter
->eActiveISO
== ISO_IMAGE2
)
3005 Adapter
->uiActiveISOOffset
= (Adapter
->psFlash2xCSInfo
->OffsetISOImage2Part1Start
);
3006 else if (Adapter
->eActiveISO
== ISO_IMAGE1
)
3007 Adapter
->uiActiveISOOffset
= (Adapter
->psFlash2xCSInfo
->OffsetISOImage1Part1Start
);
3009 if (Adapter
->eActiveISO
)
3010 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "Active ISO :%x", Adapter
->eActiveISO
);
3012 return STATUS_SUCCESS
;
3016 * IsOffsetWritable :- it will tell the access permission of the sector having passed offset
3017 * @Adapter : Drivers Private Data Structure
3018 * @uiOffset : Offset provided in the Flash
3021 * Success:-TRUE , offset is writable
3022 * Failure:-FALSE, offset is RO
3026 B_UINT8
IsOffsetWritable(struct bcm_mini_adapter
*Adapter
, UINT uiOffset
)
3028 UINT uiSectorNum
= 0;
3029 UINT uiWordOfSectorPermission
= 0;
3030 UINT uiBitofSectorePermission
= 0;
3031 B_UINT32 permissionBits
= 0;
3033 uiSectorNum
= uiOffset
/Adapter
->uiSectorSize
;
3035 // calculating the word having this Sector Access permission from SectorAccessBitMap Array
3036 uiWordOfSectorPermission
= Adapter
->psFlash2xCSInfo
->SectorAccessBitMap
[uiSectorNum
/ 16];
3038 // calculating the bit index inside the word for this sector
3039 uiBitofSectorePermission
= 2 * (15 - uiSectorNum
% 16);
3041 // Setting Access permission
3042 permissionBits
= uiWordOfSectorPermission
& (0x3 << uiBitofSectorePermission
);
3043 permissionBits
= (permissionBits
>> uiBitofSectorePermission
) & 0x3;
3044 if (permissionBits
== SECTOR_READWRITE_PERMISSION
)
3050 static INT
BcmDumpFlash2xSectionBitMap(PFLASH2X_BITMAP psFlash2xBitMap
)
3052 struct bcm_mini_adapter
*Adapter
= GET_BCM_ADAPTER(gblpnetdev
);
3054 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "***************Flash 2.x Section Bitmap***************");
3055 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "ISO_IMAGE1 :0X%x", psFlash2xBitMap
->ISO_IMAGE1
);
3056 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "ISO_IMAGE2 :0X%x", psFlash2xBitMap
->ISO_IMAGE2
);
3057 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "DSD0 :0X%x", psFlash2xBitMap
->DSD0
);
3058 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "DSD1 :0X%x", psFlash2xBitMap
->DSD1
);
3059 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "DSD2 :0X%x", psFlash2xBitMap
->DSD2
);
3060 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "VSA0 :0X%x", psFlash2xBitMap
->VSA0
);
3061 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "VSA1 :0X%x", psFlash2xBitMap
->VSA1
);
3062 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "VSA2 :0X%x", psFlash2xBitMap
->VSA2
);
3063 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "SCSI :0X%x", psFlash2xBitMap
->SCSI
);
3064 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "CONTROL_SECTION :0X%x", psFlash2xBitMap
->CONTROL_SECTION
);
3066 return STATUS_SUCCESS
;
3070 * BcmGetFlash2xSectionalBitMap :- It will provide the bit map of all the section present in Flash
3071 * 8bit has been assigned to every section.
3072 bit[0] :Section present or not
3073 bit[1] :section is valid or not
3074 bit[2] : Secton is read only or has write permission too.
3075 bit[3] : Active Section -
3076 bit[7...4] = Reserved .
3078 @Adapter:-Driver private Data Structure
3081 * Success:- STATUS_SUCESS
3082 * Failure:- negative error code
3085 INT
BcmGetFlash2xSectionalBitMap(struct bcm_mini_adapter
*Adapter
, PFLASH2X_BITMAP psFlash2xBitMap
)
3087 PFLASH2X_CS_INFO psFlash2xCSInfo
= Adapter
->psFlash2xCSInfo
;
3088 FLASH2X_SECTION_VAL uiHighestPriDSD
= 0;
3089 FLASH2X_SECTION_VAL uiHighestPriISO
= 0;
3090 BOOLEAN SetActiveDSDDone
= FALSE
;
3091 BOOLEAN SetActiveISODone
= FALSE
;
3093 // For 1.x map all the section except DSD0 will be shown as not present
3094 // This part will be used by calibration tool to detect the number of DSD present in Flash.
3095 if (IsFlash2x(Adapter
) == FALSE
) {
3096 psFlash2xBitMap
->ISO_IMAGE2
= 0;
3097 psFlash2xBitMap
->ISO_IMAGE1
= 0;
3098 psFlash2xBitMap
->DSD0
= FLASH2X_SECTION_VALID
| FLASH2X_SECTION_ACT
| FLASH2X_SECTION_PRESENT
; //0xF; //0000(Reseved)1(Active)0(RW)1(valid)1(present)
3099 psFlash2xBitMap
->DSD1
= 0;
3100 psFlash2xBitMap
->DSD2
= 0;
3101 psFlash2xBitMap
->VSA0
= 0;
3102 psFlash2xBitMap
->VSA1
= 0;
3103 psFlash2xBitMap
->VSA2
= 0;
3104 psFlash2xBitMap
->CONTROL_SECTION
= 0;
3105 psFlash2xBitMap
->SCSI
= 0;
3106 psFlash2xBitMap
->Reserved0
= 0;
3107 psFlash2xBitMap
->Reserved1
= 0;
3108 psFlash2xBitMap
->Reserved2
= 0;
3110 return STATUS_SUCCESS
;
3113 uiHighestPriDSD
= getHighestPriDSD(Adapter
);
3114 uiHighestPriISO
= getHighestPriISO(Adapter
);
3119 if ((psFlash2xCSInfo
->OffsetISOImage2Part1Start
) != UNINIT_PTR_IN_CS
) {
3120 //Setting the 0th Bit representing the Section is present or not.
3121 psFlash2xBitMap
->ISO_IMAGE2
= psFlash2xBitMap
->ISO_IMAGE2
| FLASH2X_SECTION_PRESENT
;
3123 if (ReadISOSignature(Adapter
, ISO_IMAGE2
) == ISO_IMAGE_MAGIC_NUMBER
)
3124 psFlash2xBitMap
->ISO_IMAGE2
|= FLASH2X_SECTION_VALID
;
3126 // Calculation for extrating the Access permission
3127 if (IsSectionWritable(Adapter
, ISO_IMAGE2
) == FALSE
)
3128 psFlash2xBitMap
->ISO_IMAGE2
|= FLASH2X_SECTION_RO
;
3130 if (SetActiveISODone
== FALSE
&& uiHighestPriISO
== ISO_IMAGE2
) {
3131 psFlash2xBitMap
->ISO_IMAGE2
|= FLASH2X_SECTION_ACT
;
3132 SetActiveISODone
= TRUE
;
3139 if ((psFlash2xCSInfo
->OffsetISOImage1Part1Start
) != UNINIT_PTR_IN_CS
) {
3140 // Setting the 0th Bit representing the Section is present or not.
3141 psFlash2xBitMap
->ISO_IMAGE1
= psFlash2xBitMap
->ISO_IMAGE1
| FLASH2X_SECTION_PRESENT
;
3143 if (ReadISOSignature(Adapter
, ISO_IMAGE1
) == ISO_IMAGE_MAGIC_NUMBER
)
3144 psFlash2xBitMap
->ISO_IMAGE1
|= FLASH2X_SECTION_VALID
;
3146 // Calculation for extrating the Access permission
3147 if (IsSectionWritable(Adapter
, ISO_IMAGE1
) == FALSE
)
3148 psFlash2xBitMap
->ISO_IMAGE1
|= FLASH2X_SECTION_RO
;
3150 if (SetActiveISODone
== FALSE
&& uiHighestPriISO
== ISO_IMAGE1
) {
3151 psFlash2xBitMap
->ISO_IMAGE1
|= FLASH2X_SECTION_ACT
;
3152 SetActiveISODone
= TRUE
;
3159 if ((psFlash2xCSInfo
->OffsetFromZeroForDSD2Start
) != UNINIT_PTR_IN_CS
) {
3160 //Setting the 0th Bit representing the Section is present or not.
3161 psFlash2xBitMap
->DSD2
= psFlash2xBitMap
->DSD2
| FLASH2X_SECTION_PRESENT
;
3163 if (ReadDSDSignature(Adapter
, DSD2
) == DSD_IMAGE_MAGIC_NUMBER
)
3164 psFlash2xBitMap
->DSD2
|= FLASH2X_SECTION_VALID
;
3166 // Calculation for extrating the Access permission
3167 if (IsSectionWritable(Adapter
, DSD2
) == FALSE
) {
3168 psFlash2xBitMap
->DSD2
|= FLASH2X_SECTION_RO
;
3170 //Means section is writable
3171 if ((SetActiveDSDDone
== FALSE
) && (uiHighestPriDSD
== DSD2
)) {
3172 psFlash2xBitMap
->DSD2
|= FLASH2X_SECTION_ACT
;
3173 SetActiveDSDDone
= TRUE
;
3181 if ((psFlash2xCSInfo
->OffsetFromZeroForDSD1Start
) != UNINIT_PTR_IN_CS
) {
3182 // Setting the 0th Bit representing the Section is present or not.
3183 psFlash2xBitMap
->DSD1
= psFlash2xBitMap
->DSD1
| FLASH2X_SECTION_PRESENT
;
3185 if (ReadDSDSignature(Adapter
, DSD1
) == DSD_IMAGE_MAGIC_NUMBER
)
3186 psFlash2xBitMap
->DSD1
|= FLASH2X_SECTION_VALID
;
3188 // Calculation for extrating the Access permission
3189 if (IsSectionWritable(Adapter
, DSD1
) == FALSE
) {
3190 psFlash2xBitMap
->DSD1
|= FLASH2X_SECTION_RO
;
3192 // Means section is writable
3193 if ((SetActiveDSDDone
== FALSE
) && (uiHighestPriDSD
== DSD1
)) {
3194 psFlash2xBitMap
->DSD1
|= FLASH2X_SECTION_ACT
;
3195 SetActiveDSDDone
= TRUE
;
3203 if ((psFlash2xCSInfo
->OffsetFromZeroForDSDStart
) != UNINIT_PTR_IN_CS
) {
3204 //Setting the 0th Bit representing the Section is present or not.
3205 psFlash2xBitMap
->DSD0
= psFlash2xBitMap
->DSD0
| FLASH2X_SECTION_PRESENT
;
3207 if (ReadDSDSignature(Adapter
, DSD0
) == DSD_IMAGE_MAGIC_NUMBER
)
3208 psFlash2xBitMap
->DSD0
|= FLASH2X_SECTION_VALID
;
3210 // Setting Access permission
3211 if (IsSectionWritable(Adapter
, DSD0
) == FALSE
) {
3212 psFlash2xBitMap
->DSD0
|= FLASH2X_SECTION_RO
;
3214 // Means section is writable
3215 if ((SetActiveDSDDone
== FALSE
) && (uiHighestPriDSD
== DSD0
)) {
3216 psFlash2xBitMap
->DSD0
|= FLASH2X_SECTION_ACT
;
3217 SetActiveDSDDone
= TRUE
;
3225 if ((psFlash2xCSInfo
->OffsetFromZeroForVSAStart
) != UNINIT_PTR_IN_CS
) {
3226 // Setting the 0th Bit representing the Section is present or not.
3227 psFlash2xBitMap
->VSA0
= psFlash2xBitMap
->VSA0
| FLASH2X_SECTION_PRESENT
;
3229 // Setting the Access Bit. Map is not defined hece setting it always valid
3230 psFlash2xBitMap
->VSA0
|= FLASH2X_SECTION_VALID
;
3232 // Calculation for extrating the Access permission
3233 if (IsSectionWritable(Adapter
, VSA0
) == FALSE
)
3234 psFlash2xBitMap
->VSA0
|= FLASH2X_SECTION_RO
;
3236 // By Default section is Active
3237 psFlash2xBitMap
->VSA0
|= FLASH2X_SECTION_ACT
;
3243 if ((psFlash2xCSInfo
->OffsetFromZeroForVSA1Start
) != UNINIT_PTR_IN_CS
) {
3244 // Setting the 0th Bit representing the Section is present or not.
3245 psFlash2xBitMap
->VSA1
= psFlash2xBitMap
->VSA1
| FLASH2X_SECTION_PRESENT
;
3247 // Setting the Access Bit. Map is not defined hece setting it always valid
3248 psFlash2xBitMap
->VSA1
|= FLASH2X_SECTION_VALID
;
3250 // Checking For Access permission
3251 if (IsSectionWritable(Adapter
, VSA1
) == FALSE
)
3252 psFlash2xBitMap
->VSA1
|= FLASH2X_SECTION_RO
;
3254 // By Default section is Active
3255 psFlash2xBitMap
->VSA1
|= FLASH2X_SECTION_ACT
;
3261 if ((psFlash2xCSInfo
->OffsetFromZeroForVSA2Start
) != UNINIT_PTR_IN_CS
) {
3262 // Setting the 0th Bit representing the Section is present or not.
3263 psFlash2xBitMap
->VSA2
= psFlash2xBitMap
->VSA2
| FLASH2X_SECTION_PRESENT
;
3265 // Setting the Access Bit. Map is not defined hece setting it always valid
3266 psFlash2xBitMap
->VSA2
|= FLASH2X_SECTION_VALID
;
3268 // Checking For Access permission
3269 if (IsSectionWritable(Adapter
, VSA2
) == FALSE
)
3270 psFlash2xBitMap
->VSA2
|= FLASH2X_SECTION_RO
;
3272 // By Default section is Active
3273 psFlash2xBitMap
->VSA2
|= FLASH2X_SECTION_ACT
;
3279 if ((psFlash2xCSInfo
->OffsetFromZeroForScsiFirmware
) != UNINIT_PTR_IN_CS
) {
3280 // Setting the 0th Bit representing the Section is present or not.
3281 psFlash2xBitMap
->SCSI
= psFlash2xBitMap
->SCSI
| FLASH2X_SECTION_PRESENT
;
3283 // Setting the Access Bit. Map is not defined hece setting it always valid
3284 psFlash2xBitMap
->SCSI
|= FLASH2X_SECTION_VALID
;
3286 // Checking For Access permission
3287 if (IsSectionWritable(Adapter
, SCSI
) == FALSE
)
3288 psFlash2xBitMap
->SCSI
|= FLASH2X_SECTION_RO
;
3290 // By Default section is Active
3291 psFlash2xBitMap
->SCSI
|= FLASH2X_SECTION_ACT
;
3297 if ((psFlash2xCSInfo
->OffsetFromZeroForControlSectionStart
) != UNINIT_PTR_IN_CS
) {
3298 // Setting the 0th Bit representing the Section is present or not.
3299 psFlash2xBitMap
->CONTROL_SECTION
= psFlash2xBitMap
->CONTROL_SECTION
| (FLASH2X_SECTION_PRESENT
);
3301 // Setting the Access Bit. Map is not defined hece setting it always valid
3302 psFlash2xBitMap
->CONTROL_SECTION
|= FLASH2X_SECTION_VALID
;
3304 // Checking For Access permission
3305 if (IsSectionWritable(Adapter
, CONTROL_SECTION
) == FALSE
)
3306 psFlash2xBitMap
->CONTROL_SECTION
|= FLASH2X_SECTION_RO
;
3308 // By Default section is Active
3309 psFlash2xBitMap
->CONTROL_SECTION
|= FLASH2X_SECTION_ACT
;
3313 // For Reserved Sections
3315 psFlash2xBitMap
->Reserved0
= 0;
3316 psFlash2xBitMap
->Reserved0
= 0;
3317 psFlash2xBitMap
->Reserved0
= 0;
3318 BcmDumpFlash2xSectionBitMap(psFlash2xBitMap
);
3320 return STATUS_SUCCESS
;
3324 BcmSetActiveSection :- Set Active section is used to make priority field highest over other
3325 section of same type.
3327 @Adapater :- Bcm Driver Private Data Structure
3328 @eFlash2xSectionVal :- Flash section val whose priority has to be made highest.
3330 Return Value:- Make the priorit highest else return erorr code
3334 INT
BcmSetActiveSection(struct bcm_mini_adapter
*Adapter
, FLASH2X_SECTION_VAL eFlash2xSectVal
)
3336 unsigned int SectImagePriority
= 0;
3337 INT Status
= STATUS_SUCCESS
;
3339 //DSD_HEADER sDSD = {0};
3340 //ISO_HEADER sISO = {0};
3341 INT HighestPriDSD
= 0 ;
3342 INT HighestPriISO
= 0;
3344 Status
= IsSectionWritable(Adapter
, eFlash2xSectVal
);
3345 if (Status
!= TRUE
) {
3346 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Provided Section <%d> is not writable", eFlash2xSectVal
);
3347 return STATUS_FAILURE
;
3350 Adapter
->bHeaderChangeAllowed
= TRUE
;
3351 switch (eFlash2xSectVal
) {
3354 if (ReadISOSignature(Adapter
, eFlash2xSectVal
) == ISO_IMAGE_MAGIC_NUMBER
) {
3355 HighestPriISO
= getHighestPriISO(Adapter
);
3357 if (HighestPriISO
== eFlash2xSectVal
) {
3358 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "Given ISO<%x> already has highest priority", eFlash2xSectVal
);
3359 Status
= STATUS_SUCCESS
;
3363 SectImagePriority
= ReadISOPriority(Adapter
, HighestPriISO
) + 1;
3365 if ((SectImagePriority
<= 0) && IsSectionWritable(Adapter
, HighestPriISO
)) {
3366 // This is a SPECIAL Case which will only happen if the current highest priority ISO has priority value = 0x7FFFFFFF.
3367 // We will write 1 to the current Highest priority ISO And then shall increase the priority of the requested ISO
3369 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "SectImagePriority wraparound happened, eFlash2xSectVal: 0x%x\n", eFlash2xSectVal
);
3370 SectImagePriority
= htonl(0x1);
3371 Status
= BcmFlash2xBulkWrite(Adapter
,
3374 0 + FIELD_OFFSET_IN_HEADER(PISO_HEADER
, ISOImagePriority
),
3378 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Priority has not been written properly");
3379 Status
= STATUS_FAILURE
;
3383 HighestPriISO
= getHighestPriISO(Adapter
);
3385 if (HighestPriISO
== eFlash2xSectVal
) {
3386 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "Given ISO<%x> already has highest priority", eFlash2xSectVal
);
3387 Status
= STATUS_SUCCESS
;
3391 SectImagePriority
= 2;
3394 SectImagePriority
= htonl(SectImagePriority
);
3396 Status
= BcmFlash2xBulkWrite(Adapter
,
3399 0 + FIELD_OFFSET_IN_HEADER(PISO_HEADER
, ISOImagePriority
),
3403 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Priority has not been written properly");
3407 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Signature is currupted. Hence can't increase the priority");
3408 Status
= STATUS_FAILURE
;
3415 if (ReadDSDSignature(Adapter
, eFlash2xSectVal
) == DSD_IMAGE_MAGIC_NUMBER
) {
3416 HighestPriDSD
= getHighestPriDSD(Adapter
);
3417 if ((HighestPriDSD
== eFlash2xSectVal
)) {
3418 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "Given DSD<%x> already has highest priority", eFlash2xSectVal
);
3419 Status
= STATUS_SUCCESS
;
3423 SectImagePriority
= ReadDSDPriority(Adapter
, HighestPriDSD
) + 1;
3424 if (SectImagePriority
<= 0) {
3425 // This is a SPECIAL Case which will only happen if the current highest priority DSD has priority value = 0x7FFFFFFF.
3426 // We will write 1 to the current Highest priority DSD And then shall increase the priority of the requested DSD
3428 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, NVM_RW
, DBG_LVL_ALL
, "SectImagePriority wraparound happened, eFlash2xSectVal: 0x%x\n", eFlash2xSectVal
);
3429 SectImagePriority
= htonl(0x1);
3431 Status
= BcmFlash2xBulkWrite(Adapter
,
3434 Adapter
->psFlash2xCSInfo
->OffsetFromDSDStartForDSDHeader
+ FIELD_OFFSET_IN_HEADER(PDSD_HEADER
, DSDImagePriority
),
3438 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Priority has not been written properly");
3442 HighestPriDSD
= getHighestPriDSD(Adapter
);
3444 if ((HighestPriDSD
== eFlash2xSectVal
)) {
3445 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "Made the DSD: %x highest by reducing priority of other\n", eFlash2xSectVal
);
3446 Status
= STATUS_SUCCESS
;
3450 SectImagePriority
= htonl(0x2);
3451 Status
= BcmFlash2xBulkWrite(Adapter
,
3454 Adapter
->psFlash2xCSInfo
->OffsetFromDSDStartForDSDHeader
+ FIELD_OFFSET_IN_HEADER(PDSD_HEADER
, DSDImagePriority
),
3458 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Priority has not been written properly");
3462 HighestPriDSD
= getHighestPriDSD(Adapter
);
3463 if ((HighestPriDSD
== eFlash2xSectVal
)) {
3464 Status
= STATUS_SUCCESS
;
3468 SectImagePriority
= 3;
3470 SectImagePriority
= htonl(SectImagePriority
);
3471 Status
= BcmFlash2xBulkWrite(Adapter
,
3474 Adapter
->psFlash2xCSInfo
->OffsetFromDSDStartForDSDHeader
+ FIELD_OFFSET_IN_HEADER(PDSD_HEADER
, DSDImagePriority
),
3478 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Priority has not been written properly");
3479 Status
= STATUS_FAILURE
;
3483 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Signature is currupted. Hence can't increase the priority");
3484 Status
= STATUS_FAILURE
;
3491 // Has to be decided
3494 Status
= STATUS_FAILURE
;
3498 Adapter
->bHeaderChangeAllowed
= FALSE
;
3503 BcmCopyISO - Used only for copying the ISO section
3504 @Adapater :- Bcm Driver Private Data Structure
3505 @sCopySectStrut :- Section copy structure
3507 Return value:- SUCCESS if copies successfully else negative error code
3511 INT
BcmCopyISO(struct bcm_mini_adapter
*Adapter
, FLASH2X_COPY_SECTION sCopySectStrut
)
3514 FLASH2X_SECTION_VAL eISOReadPart
= 0, eISOWritePart
= 0;
3515 UINT uiReadOffsetWithinPart
= 0, uiWriteOffsetWithinPart
= 0;
3516 UINT uiTotalDataToCopy
= 0;
3517 BOOLEAN IsThisHeaderSector
= FALSE
;
3520 UINT Status
= STATUS_SUCCESS
;
3521 UINT SigBuff
[MAX_RW_SIZE
];
3524 if (ReadISOSignature(Adapter
, sCopySectStrut
.SrcSection
) != ISO_IMAGE_MAGIC_NUMBER
) {
3525 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "error as Source ISO Section does not have valid signature");
3526 return STATUS_FAILURE
;
3529 Status
= BcmFlash2xBulkRead(Adapter
,
3531 sCopySectStrut
.SrcSection
,
3532 0 + FIELD_OFFSET_IN_HEADER(PISO_HEADER
, ISOImageSize
),
3535 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Read failed while copying ISO\n");
3539 ISOLength
= htonl(ISOLength
);
3540 if (ISOLength
% Adapter
->uiSectorSize
)
3541 ISOLength
= Adapter
->uiSectorSize
* (1 + ISOLength
/Adapter
->uiSectorSize
);
3543 sigOffset
= FIELD_OFFSET_IN_HEADER(PISO_HEADER
, ISOImageMagicNumber
);
3545 Buff
= kzalloc(Adapter
->uiSectorSize
, GFP_KERNEL
);
3548 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Memory allocation failed for section size");
3552 if (sCopySectStrut
.SrcSection
== ISO_IMAGE1
&& sCopySectStrut
.DstSection
== ISO_IMAGE2
) {
3553 eISOReadPart
= ISO_IMAGE1
;
3554 eISOWritePart
= ISO_IMAGE2
;
3555 uiReadOffsetWithinPart
= 0;
3556 uiWriteOffsetWithinPart
= 0;
3558 uiTotalDataToCopy
= (Adapter
->psFlash2xCSInfo
->OffsetISOImage1Part1End
) -
3559 (Adapter
->psFlash2xCSInfo
->OffsetISOImage1Part1Start
) +
3560 (Adapter
->psFlash2xCSInfo
->OffsetISOImage1Part2End
) -
3561 (Adapter
->psFlash2xCSInfo
->OffsetISOImage1Part2Start
) +
3562 (Adapter
->psFlash2xCSInfo
->OffsetISOImage1Part3End
) -
3563 (Adapter
->psFlash2xCSInfo
->OffsetISOImage1Part3Start
);
3565 if (uiTotalDataToCopy
< ISOLength
) {
3566 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "error as Source ISO Section does not have valid signature");
3567 Status
= STATUS_FAILURE
;
3571 uiTotalDataToCopy
= (Adapter
->psFlash2xCSInfo
->OffsetISOImage2Part1End
) -
3572 (Adapter
->psFlash2xCSInfo
->OffsetISOImage2Part1Start
) +
3573 (Adapter
->psFlash2xCSInfo
->OffsetISOImage2Part2End
) -
3574 (Adapter
->psFlash2xCSInfo
->OffsetISOImage2Part2Start
) +
3575 (Adapter
->psFlash2xCSInfo
->OffsetISOImage2Part3End
) -
3576 (Adapter
->psFlash2xCSInfo
->OffsetISOImage2Part3Start
);
3578 if (uiTotalDataToCopy
< ISOLength
) {
3579 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "error as Dest ISO Section does not have enough section size");
3580 Status
= STATUS_FAILURE
;
3584 uiTotalDataToCopy
= ISOLength
;
3586 CorruptISOSig(Adapter
, ISO_IMAGE2
);
3587 while (uiTotalDataToCopy
) {
3588 if (uiTotalDataToCopy
== Adapter
->uiSectorSize
) {
3589 // Setting for write of first sector. First sector is assumed to be written in last
3590 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "Writing the signature sector");
3591 eISOReadPart
= ISO_IMAGE1
;
3592 uiReadOffsetWithinPart
= 0;
3593 eISOWritePart
= ISO_IMAGE2
;
3594 uiWriteOffsetWithinPart
= 0;
3595 IsThisHeaderSector
= TRUE
;
3597 uiReadOffsetWithinPart
= uiReadOffsetWithinPart
+ Adapter
->uiSectorSize
;
3598 uiWriteOffsetWithinPart
= uiWriteOffsetWithinPart
+ Adapter
->uiSectorSize
;
3600 if ((eISOReadPart
== ISO_IMAGE1
) && (uiReadOffsetWithinPart
== (Adapter
->psFlash2xCSInfo
->OffsetISOImage1Part1End
- Adapter
->psFlash2xCSInfo
->OffsetISOImage1Part1Start
))) {
3601 eISOReadPart
= ISO_IMAGE1_PART2
;
3602 uiReadOffsetWithinPart
= 0;
3605 if ((eISOReadPart
== ISO_IMAGE1_PART2
) && (uiReadOffsetWithinPart
== (Adapter
->psFlash2xCSInfo
->OffsetISOImage1Part2End
- Adapter
->psFlash2xCSInfo
->OffsetISOImage1Part2Start
))) {
3606 eISOReadPart
= ISO_IMAGE1_PART3
;
3607 uiReadOffsetWithinPart
= 0;
3610 if ((eISOWritePart
== ISO_IMAGE2
) && (uiWriteOffsetWithinPart
== (Adapter
->psFlash2xCSInfo
->OffsetISOImage2Part1End
- Adapter
->psFlash2xCSInfo
->OffsetISOImage2Part1Start
))) {
3611 eISOWritePart
= ISO_IMAGE2_PART2
;
3612 uiWriteOffsetWithinPart
= 0;
3615 if ((eISOWritePart
== ISO_IMAGE2_PART2
) && (uiWriteOffsetWithinPart
== (Adapter
->psFlash2xCSInfo
->OffsetISOImage2Part2End
- Adapter
->psFlash2xCSInfo
->OffsetISOImage2Part2Start
))) {
3616 eISOWritePart
= ISO_IMAGE2_PART3
;
3617 uiWriteOffsetWithinPart
= 0;
3621 Status
= BcmFlash2xBulkRead(Adapter
,
3624 uiReadOffsetWithinPart
,
3625 Adapter
->uiSectorSize
);
3627 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Read failed while copying ISO: Part: %x, OffsetWithinPart: %x\n", eISOReadPart
, uiReadOffsetWithinPart
);
3631 if (IsThisHeaderSector
== TRUE
) {
3632 // If this is header sector write 0xFFFFFFFF at the sig time and in last write sig
3633 memcpy(SigBuff
, Buff
+ sigOffset
, MAX_RW_SIZE
);
3635 for (i
= 0; i
< MAX_RW_SIZE
; i
++)
3636 *(Buff
+ sigOffset
+ i
) = 0xFF;
3638 Adapter
->bHeaderChangeAllowed
= TRUE
;
3639 Status
= BcmFlash2xBulkWrite(Adapter
,
3642 uiWriteOffsetWithinPart
,
3643 Adapter
->uiSectorSize
,
3646 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Write failed while copying ISO: Part: %x, OffsetWithinPart: %x\n", eISOWritePart
, uiWriteOffsetWithinPart
);
3650 Adapter
->bHeaderChangeAllowed
= FALSE
;
3651 if (IsThisHeaderSector
== TRUE
) {
3652 WriteToFlashWithoutSectorErase(Adapter
,
3657 IsThisHeaderSector
= FALSE
;
3659 //subtracting the written Data
3660 uiTotalDataToCopy
= uiTotalDataToCopy
- Adapter
->uiSectorSize
;
3664 if (sCopySectStrut
.SrcSection
== ISO_IMAGE2
&& sCopySectStrut
.DstSection
== ISO_IMAGE1
) {
3665 eISOReadPart
= ISO_IMAGE2
;
3666 eISOWritePart
= ISO_IMAGE1
;
3667 uiReadOffsetWithinPart
= 0;
3668 uiWriteOffsetWithinPart
= 0;
3670 uiTotalDataToCopy
= (Adapter
->psFlash2xCSInfo
->OffsetISOImage2Part1End
) -
3671 (Adapter
->psFlash2xCSInfo
->OffsetISOImage2Part1Start
) +
3672 (Adapter
->psFlash2xCSInfo
->OffsetISOImage2Part2End
) -
3673 (Adapter
->psFlash2xCSInfo
->OffsetISOImage2Part2Start
) +
3674 (Adapter
->psFlash2xCSInfo
->OffsetISOImage2Part3End
) -
3675 (Adapter
->psFlash2xCSInfo
->OffsetISOImage2Part3Start
);
3677 if (uiTotalDataToCopy
< ISOLength
) {
3678 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "error as Source ISO Section does not have valid signature");
3679 Status
= STATUS_FAILURE
;
3683 uiTotalDataToCopy
= (Adapter
->psFlash2xCSInfo
->OffsetISOImage1Part1End
) -
3684 (Adapter
->psFlash2xCSInfo
->OffsetISOImage1Part1Start
) +
3685 (Adapter
->psFlash2xCSInfo
->OffsetISOImage1Part2End
) -
3686 (Adapter
->psFlash2xCSInfo
->OffsetISOImage1Part2Start
) +
3687 (Adapter
->psFlash2xCSInfo
->OffsetISOImage1Part3End
) -
3688 (Adapter
->psFlash2xCSInfo
->OffsetISOImage1Part3Start
);
3690 if (uiTotalDataToCopy
< ISOLength
) {
3691 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "error as Dest ISO Section does not have enough section size");
3692 Status
= STATUS_FAILURE
;
3696 uiTotalDataToCopy
= ISOLength
;
3698 CorruptISOSig(Adapter
, ISO_IMAGE1
);
3700 while (uiTotalDataToCopy
) {
3701 if (uiTotalDataToCopy
== Adapter
->uiSectorSize
) {
3702 //Setting for write of first sector. First sector is assumed to be written in last
3703 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "Writing the signature sector");
3704 eISOReadPart
= ISO_IMAGE2
;
3705 uiReadOffsetWithinPart
= 0;
3706 eISOWritePart
= ISO_IMAGE1
;
3707 uiWriteOffsetWithinPart
= 0;
3708 IsThisHeaderSector
= TRUE
;
3710 uiReadOffsetWithinPart
= uiReadOffsetWithinPart
+ Adapter
->uiSectorSize
;
3711 uiWriteOffsetWithinPart
= uiWriteOffsetWithinPart
+ Adapter
->uiSectorSize
;
3713 if ((eISOReadPart
== ISO_IMAGE2
) && (uiReadOffsetWithinPart
== (Adapter
->psFlash2xCSInfo
->OffsetISOImage2Part1End
- Adapter
->psFlash2xCSInfo
->OffsetISOImage2Part1Start
))) {
3714 eISOReadPart
= ISO_IMAGE2_PART2
;
3715 uiReadOffsetWithinPart
= 0;
3718 if ((eISOReadPart
== ISO_IMAGE2_PART2
) && (uiReadOffsetWithinPart
== (Adapter
->psFlash2xCSInfo
->OffsetISOImage2Part2End
- Adapter
->psFlash2xCSInfo
->OffsetISOImage2Part2Start
))) {
3719 eISOReadPart
= ISO_IMAGE2_PART3
;
3720 uiReadOffsetWithinPart
= 0;
3723 if ((eISOWritePart
== ISO_IMAGE1
) && (uiWriteOffsetWithinPart
== (Adapter
->psFlash2xCSInfo
->OffsetISOImage1Part1End
- Adapter
->psFlash2xCSInfo
->OffsetISOImage1Part1Start
))) {
3724 eISOWritePart
= ISO_IMAGE1_PART2
;
3725 uiWriteOffsetWithinPart
= 0;
3728 if ((eISOWritePart
== ISO_IMAGE1_PART2
) && (uiWriteOffsetWithinPart
== (Adapter
->psFlash2xCSInfo
->OffsetISOImage1Part2End
- Adapter
->psFlash2xCSInfo
->OffsetISOImage1Part2Start
))) {
3729 eISOWritePart
= ISO_IMAGE1_PART3
;
3730 uiWriteOffsetWithinPart
= 0;
3734 Status
= BcmFlash2xBulkRead(Adapter
,
3737 uiReadOffsetWithinPart
,
3738 Adapter
->uiSectorSize
);
3740 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Read failed while copying ISO: Part: %x, OffsetWithinPart: %x\n", eISOReadPart
, uiReadOffsetWithinPart
);
3744 if (IsThisHeaderSector
== TRUE
) {
3745 // If this is header sector write 0xFFFFFFFF at the sig time and in last write sig
3746 memcpy(SigBuff
, Buff
+ sigOffset
, MAX_RW_SIZE
);
3748 for (i
= 0; i
< MAX_RW_SIZE
; i
++)
3749 *(Buff
+ sigOffset
+ i
) = 0xFF;
3751 Adapter
->bHeaderChangeAllowed
= TRUE
;
3752 Status
= BcmFlash2xBulkWrite(Adapter
,
3755 uiWriteOffsetWithinPart
,
3756 Adapter
->uiSectorSize
,
3759 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Write failed while copying ISO: Part: %x, OffsetWithinPart: %x\n", eISOWritePart
, uiWriteOffsetWithinPart
);
3763 Adapter
->bHeaderChangeAllowed
= FALSE
;
3764 if (IsThisHeaderSector
== TRUE
) {
3765 WriteToFlashWithoutSectorErase(Adapter
,
3771 IsThisHeaderSector
= FALSE
;
3774 // subtracting the written Data
3775 uiTotalDataToCopy
= uiTotalDataToCopy
- Adapter
->uiSectorSize
;
3785 BcmFlash2xCorruptSig : this API is used to corrupt the written sig in Bcm Header present in flash section.
3786 It will corrupt the sig, if Section is writable, by making first bytes as zero.
3787 @Adapater :- Bcm Driver Private Data Structure
3788 @eFlash2xSectionVal :- Flash section val which has header
3791 Success :- If Section is present and writable, corrupt the sig and return STATUS_SUCCESS
3792 Failure :-Return negative error code
3797 INT
BcmFlash2xCorruptSig(struct bcm_mini_adapter
*Adapter
, FLASH2X_SECTION_VAL eFlash2xSectionVal
)
3799 INT Status
= STATUS_SUCCESS
;
3801 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Section Value :%x\n", eFlash2xSectionVal
);
3803 if ((eFlash2xSectionVal
== DSD0
) || (eFlash2xSectionVal
== DSD1
) || (eFlash2xSectionVal
== DSD2
)) {
3804 Status
= CorruptDSDSig(Adapter
, eFlash2xSectionVal
);
3805 } else if (eFlash2xSectionVal
== ISO_IMAGE1
|| eFlash2xSectionVal
== ISO_IMAGE2
) {
3806 Status
= CorruptISOSig(Adapter
, eFlash2xSectionVal
);
3808 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "Given Section <%d>does not have Header", eFlash2xSectionVal
);
3809 return STATUS_SUCCESS
;
3815 BcmFlash2xWriteSig :-this API is used to Write the sig if requested Section has
3816 header and Write Permission.
3817 @Adapater :- Bcm Driver Private Data Structure
3818 @eFlashSectionVal :- Flash section val which has header
3821 Success :- If Section is present and writable write the sig and return STATUS_SUCCESS
3822 Failure :-Return negative error code
3826 INT
BcmFlash2xWriteSig(struct bcm_mini_adapter
*Adapter
, FLASH2X_SECTION_VAL eFlashSectionVal
)
3828 UINT uiSignature
= 0;
3831 // DSD_HEADER dsdHeader = {0};
3832 if (Adapter
->bSigCorrupted
== FALSE
) {
3833 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "Signature is not corrupted by driver, hence not restoring\n");
3834 return STATUS_SUCCESS
;
3837 if (Adapter
->bAllDSDWriteAllow
== FALSE
) {
3838 if (IsSectionWritable(Adapter
, eFlashSectionVal
) == FALSE
) {
3839 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Section is not Writable...Hence can't Write signature");
3840 return SECTOR_IS_NOT_WRITABLE
;
3844 if ((eFlashSectionVal
== DSD0
) || (eFlashSectionVal
== DSD1
) || (eFlashSectionVal
== DSD2
)) {
3845 uiSignature
= htonl(DSD_IMAGE_MAGIC_NUMBER
);
3846 uiOffset
= Adapter
->psFlash2xCSInfo
->OffsetFromDSDStartForDSDHeader
;
3848 uiOffset
+= FIELD_OFFSET_IN_HEADER(PDSD_HEADER
, DSDImageMagicNumber
);
3850 if ((ReadDSDSignature(Adapter
, eFlashSectionVal
) & 0xFF000000) != CORRUPTED_PATTERN
) {
3851 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Corrupted Pattern is not there. Hence won't write sig");
3852 return STATUS_FAILURE
;
3854 } else if ((eFlashSectionVal
== ISO_IMAGE1
) || (eFlashSectionVal
== ISO_IMAGE2
)) {
3855 uiSignature
= htonl(ISO_IMAGE_MAGIC_NUMBER
);
3857 uiOffset
= FIELD_OFFSET_IN_HEADER(PISO_HEADER
, ISOImageMagicNumber
);
3858 if ((ReadISOSignature(Adapter
, eFlashSectionVal
) & 0xFF000000) != CORRUPTED_PATTERN
) {
3859 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Currupted Pattern is not there. Hence won't write sig");
3860 return STATUS_FAILURE
;
3863 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "GIVEN SECTION< %d > IS NOT VALID FOR SIG WRITE...", eFlashSectionVal
);
3864 return STATUS_FAILURE
;
3867 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "Restoring the signature");
3869 Adapter
->bHeaderChangeAllowed
= TRUE
;
3870 Adapter
->bSigCorrupted
= FALSE
;
3871 BcmFlash2xBulkWrite(Adapter
, &uiSignature
, eFlashSectionVal
, uiOffset
, SIGNATURE_SIZE
, TRUE
);
3872 Adapter
->bHeaderChangeAllowed
= FALSE
;
3874 return STATUS_SUCCESS
;
3878 validateFlash2xReadWrite :- This API is used to validate the user request for Read/Write.
3879 if requested Bytes goes beyond the Requested section, it reports error.
3880 @Adapater :- Bcm Driver Private Data Structure
3881 @psFlash2xReadWrite :-Flash2x Read/write structure pointer
3883 Return values:-Return TRUE is request is valid else FALSE.
3888 INT
validateFlash2xReadWrite(struct bcm_mini_adapter
*Adapter
, PFLASH2X_READWRITE psFlash2xReadWrite
)
3890 UINT uiNumOfBytes
= 0;
3891 UINT uiSectStartOffset
= 0;
3892 UINT uiSectEndOffset
= 0;
3894 uiNumOfBytes
= psFlash2xReadWrite
->numOfBytes
;
3896 if (IsSectionExistInFlash(Adapter
, psFlash2xReadWrite
->Section
) != TRUE
) {
3897 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Section<%x> does not exixt in Flash", psFlash2xReadWrite
->Section
);
3900 uiSectStartOffset
= BcmGetSectionValStartOffset(Adapter
, psFlash2xReadWrite
->Section
);
3901 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "Start offset :%x ,section :%d\n", uiSectStartOffset
, psFlash2xReadWrite
->Section
);
3902 if ((psFlash2xReadWrite
->Section
== ISO_IMAGE1
) || (psFlash2xReadWrite
->Section
== ISO_IMAGE2
)) {
3903 if (psFlash2xReadWrite
->Section
== ISO_IMAGE1
) {
3904 uiSectEndOffset
= BcmGetSectionValEndOffset(Adapter
, ISO_IMAGE1
) -
3905 BcmGetSectionValStartOffset(Adapter
, ISO_IMAGE1
) +
3906 BcmGetSectionValEndOffset(Adapter
, ISO_IMAGE1_PART2
) -
3907 BcmGetSectionValStartOffset(Adapter
, ISO_IMAGE1_PART2
) +
3908 BcmGetSectionValEndOffset(Adapter
, ISO_IMAGE1_PART3
) -
3909 BcmGetSectionValStartOffset(Adapter
, ISO_IMAGE1_PART3
);
3910 } else if (psFlash2xReadWrite
->Section
== ISO_IMAGE2
) {
3911 uiSectEndOffset
= BcmGetSectionValEndOffset(Adapter
, ISO_IMAGE2
) -
3912 BcmGetSectionValStartOffset(Adapter
, ISO_IMAGE2
) +
3913 BcmGetSectionValEndOffset(Adapter
, ISO_IMAGE2_PART2
) -
3914 BcmGetSectionValStartOffset(Adapter
, ISO_IMAGE2_PART2
) +
3915 BcmGetSectionValEndOffset(Adapter
, ISO_IMAGE2_PART3
) -
3916 BcmGetSectionValStartOffset(Adapter
, ISO_IMAGE2_PART3
);
3919 // since this uiSectEndoffset is the size of iso Image. hence for calculating the vitual endoffset
3920 // it should be added in startoffset. so that check done in last of this function can be valued.
3921 uiSectEndOffset
= uiSectStartOffset
+ uiSectEndOffset
;
3923 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "Total size of the ISO Image :%x", uiSectEndOffset
);
3925 uiSectEndOffset
= BcmGetSectionValEndOffset(Adapter
, psFlash2xReadWrite
->Section
);
3927 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "End offset :%x\n", uiSectEndOffset
);
3929 // Checking the boundary condition
3930 if ((uiSectStartOffset
+ psFlash2xReadWrite
->offset
+ uiNumOfBytes
) <= uiSectEndOffset
)
3933 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Invalid Request....");
3939 IsFlash2x :- check for Flash 2.x
3940 @Adapater :- Bcm Driver Private Data Structure
3943 return TRUE if flah2.x of hgher version else return false.
3946 INT
IsFlash2x(struct bcm_mini_adapter
*Adapter
)
3948 if (Adapter
->uiFlashLayoutMajorVersion
>= FLASH_2X_MAJOR_NUMBER
)
3955 GetFlashBaseAddr :- Calculate the Flash Base address
3956 @Adapater :- Bcm Driver Private Data Structure
3959 Success :- Base Address of the Flash
3962 static INT
GetFlashBaseAddr(struct bcm_mini_adapter
*Adapter
)
3964 UINT uiBaseAddr
= 0;
3966 if (Adapter
->bDDRInitDone
) {
3968 For All Valid Flash Versions... except 1.1, take the value from FlashBaseAddr
3969 In case of Raw Read... use the default value
3971 if (Adapter
->uiFlashLayoutMajorVersion
&& (Adapter
->bFlashRawRead
== FALSE
) &&
3972 !((Adapter
->uiFlashLayoutMajorVersion
== 1) && (Adapter
->uiFlashLayoutMinorVersion
== 1)))
3973 uiBaseAddr
= Adapter
->uiFlashBaseAdd
;
3975 uiBaseAddr
= FLASH_CONTIGIOUS_START_ADDR_AFTER_INIT
;
3978 For All Valid Flash Versions... except 1.1, take the value from FlashBaseAddr
3979 In case of Raw Read... use the default value
3981 if (Adapter
->uiFlashLayoutMajorVersion
&& (Adapter
->bFlashRawRead
== FALSE
) &&
3982 !((Adapter
->uiFlashLayoutMajorVersion
== 1) && (Adapter
->uiFlashLayoutMinorVersion
== 1)))
3983 uiBaseAddr
= Adapter
->uiFlashBaseAdd
| FLASH_CONTIGIOUS_START_ADDR_BEFORE_INIT
;
3985 uiBaseAddr
= FLASH_CONTIGIOUS_START_ADDR_BEFORE_INIT
;
3992 BcmCopySection :- This API is used to copy the One section in another. Both section should
3993 be contiuous and of same size. Hence this Will not be applicabe to copy ISO.
3995 @Adapater :- Bcm Driver Private Data Structure
3996 @SrcSection :- Source section From where data has to be copied
3997 @DstSection :- Destination section to which data has to be copied
3998 @offset :- Offset from/to where data has to be copied from one section to another.
3999 @numOfBytes :- number of byes that has to be copyed from one section to another at given offset.
4000 in case of numofBytes equal zero complete section will be copied.
4003 Success : Return STATUS_SUCCESS
4004 Faillure :- return negative error code
4008 INT
BcmCopySection(struct bcm_mini_adapter
*Adapter
,
4009 FLASH2X_SECTION_VAL SrcSection
,
4010 FLASH2X_SECTION_VAL DstSection
,
4015 UINT BytesToBeCopied
= 0;
4016 PUCHAR pBuff
= NULL
;
4017 INT Status
= STATUS_SUCCESS
;
4019 if (SrcSection
== DstSection
) {
4020 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Source and Destination should be different ...try again");
4024 if ((SrcSection
!= DSD0
) && (SrcSection
!= DSD1
) && (SrcSection
!= DSD2
)) {
4025 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Source should be DSD subsection");
4029 if ((DstSection
!= DSD0
) && (DstSection
!= DSD1
) && (DstSection
!= DSD2
)) {
4030 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Destination should be DSD subsection");
4034 // if offset zero means have to copy complete secton
4035 if (numOfBytes
== 0) {
4036 numOfBytes
= BcmGetSectionValEndOffset(Adapter
, SrcSection
)
4037 - BcmGetSectionValStartOffset(Adapter
, SrcSection
);
4039 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "Section Size :0x%x", numOfBytes
);
4042 if ((offset
+ numOfBytes
) > BcmGetSectionValEndOffset(Adapter
, SrcSection
)
4043 - BcmGetSectionValStartOffset(Adapter
, SrcSection
)) {
4044 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, " Input parameters going beyond the section offS: %x numB: %x of Source Section\n",
4045 offset
, numOfBytes
);
4049 if ((offset
+ numOfBytes
) > BcmGetSectionValEndOffset(Adapter
, DstSection
)
4050 - BcmGetSectionValStartOffset(Adapter
, DstSection
)) {
4051 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Input parameters going beyond the section offS: %x numB: %x of Destination Section\n",
4052 offset
, numOfBytes
);
4056 if (numOfBytes
> Adapter
->uiSectorSize
)
4057 BuffSize
= Adapter
->uiSectorSize
;
4059 BuffSize
= numOfBytes
;
4061 pBuff
= (PCHAR
)kzalloc(BuffSize
, GFP_KERNEL
);
4062 if (pBuff
== NULL
) {
4063 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Memory allocation failed.. ");
4067 BytesToBeCopied
= Adapter
->uiSectorSize
;
4068 if (offset
% Adapter
->uiSectorSize
)
4069 BytesToBeCopied
= Adapter
->uiSectorSize
- (offset
% Adapter
->uiSectorSize
);
4070 if (BytesToBeCopied
> numOfBytes
)
4071 BytesToBeCopied
= numOfBytes
;
4073 Adapter
->bHeaderChangeAllowed
= TRUE
;
4076 Status
= BcmFlash2xBulkRead(Adapter
, (PUINT
)pBuff
, SrcSection
, offset
, BytesToBeCopied
);
4078 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Read failed at offset :%d for NOB :%d", SrcSection
, BytesToBeCopied
);
4081 Status
= BcmFlash2xBulkWrite(Adapter
, (PUINT
)pBuff
, DstSection
, offset
, BytesToBeCopied
, FALSE
);
4083 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Write failed at offset :%d for NOB :%d", DstSection
, BytesToBeCopied
);
4086 offset
= offset
+ BytesToBeCopied
;
4087 numOfBytes
= numOfBytes
- BytesToBeCopied
;
4089 if (numOfBytes
> Adapter
->uiSectorSize
)
4090 BytesToBeCopied
= Adapter
->uiSectorSize
;
4092 BytesToBeCopied
= numOfBytes
;
4094 } while (numOfBytes
> 0);
4097 Adapter
->bHeaderChangeAllowed
= FALSE
;
4103 SaveHeaderIfPresent :- This API is use to Protect the Header in case of Header Sector write
4104 @Adapater :- Bcm Driver Private Data Structure
4105 @pBuff :- Data buffer that has to be written in sector having the header map.
4106 @uiOffset :- Flash offset that has to be written.
4109 Success :- On success return STATUS_SUCCESS
4110 Faillure :- Return negative error code
4114 INT
SaveHeaderIfPresent(struct bcm_mini_adapter
*Adapter
, PUCHAR pBuff
, UINT uiOffset
)
4116 UINT offsetToProtect
= 0, HeaderSizeToProtect
= 0;
4117 BOOLEAN bHasHeader
= FALSE
;
4118 PUCHAR pTempBuff
= NULL
;
4119 UINT uiSectAlignAddr
= 0;
4122 //making the offset sector aligned
4123 uiSectAlignAddr
= uiOffset
& ~(Adapter
->uiSectorSize
- 1);
4125 if ((uiSectAlignAddr
== BcmGetSectionValEndOffset(Adapter
, DSD2
) - Adapter
->uiSectorSize
) ||
4126 (uiSectAlignAddr
== BcmGetSectionValEndOffset(Adapter
, DSD1
) - Adapter
->uiSectorSize
) ||
4127 (uiSectAlignAddr
== BcmGetSectionValEndOffset(Adapter
, DSD0
) - Adapter
->uiSectorSize
)) {
4128 // offset from the sector boundary having the header map
4129 offsetToProtect
= Adapter
->psFlash2xCSInfo
->OffsetFromDSDStartForDSDHeader
% Adapter
->uiSectorSize
;
4130 HeaderSizeToProtect
= sizeof(DSD_HEADER
);
4134 if (uiSectAlignAddr
== BcmGetSectionValStartOffset(Adapter
, ISO_IMAGE1
) ||
4135 uiSectAlignAddr
== BcmGetSectionValStartOffset(Adapter
, ISO_IMAGE2
)) {
4136 offsetToProtect
= 0;
4137 HeaderSizeToProtect
= sizeof(ISO_HEADER
);
4140 // If Header is present overwrite passed buffer with this
4141 if (bHasHeader
&& (Adapter
->bHeaderChangeAllowed
== FALSE
)) {
4142 pTempBuff
= (PUCHAR
)kzalloc(HeaderSizeToProtect
, GFP_KERNEL
);
4143 if (pTempBuff
== NULL
) {
4144 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Memory allocation failed");
4148 BeceemFlashBulkRead(Adapter
, (PUINT
)pTempBuff
, (uiSectAlignAddr
+ offsetToProtect
), HeaderSizeToProtect
);
4149 BCM_DEBUG_PRINT_BUFFER(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, pTempBuff
, HeaderSizeToProtect
);
4150 //Replace Buffer content with Header
4151 memcpy(pBuff
+ offsetToProtect
, pTempBuff
, HeaderSizeToProtect
);
4155 if (bHasHeader
&& Adapter
->bSigCorrupted
) {
4156 sig
= *((PUINT
)(pBuff
+ offsetToProtect
+ FIELD_OFFSET_IN_HEADER(PDSD_HEADER
, DSDImageMagicNumber
)));
4158 if ((sig
& 0xFF000000) != CORRUPTED_PATTERN
) {
4159 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "Desired pattern is not at sig offset. Hence won't restore");
4160 Adapter
->bSigCorrupted
= FALSE
;
4161 return STATUS_SUCCESS
;
4163 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, " Corrupted sig is :%X", sig
);
4164 *((PUINT
)(pBuff
+ offsetToProtect
+ FIELD_OFFSET_IN_HEADER(PDSD_HEADER
, DSDImageMagicNumber
))) = htonl(DSD_IMAGE_MAGIC_NUMBER
);
4165 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "Restoring the signature in Header Write only");
4166 Adapter
->bSigCorrupted
= FALSE
;
4169 return STATUS_SUCCESS
;
4173 BcmDoChipSelect : This will selcet the appropriate chip for writing.
4174 @Adapater :- Bcm Driver Private Data Structure
4177 Select the Appropriate chip and retrn status Success
4179 static INT
BcmDoChipSelect(struct bcm_mini_adapter
*Adapter
, UINT offset
)
4181 UINT FlashConfig
= 0;
4183 UINT GPIOConfig
= 0;
4186 ChipNum
= offset
/ FLASH_PART_SIZE
;
4189 // Chip Select mapping to enable flash0.
4190 // To select flash 0, we have to OR with (0<<12).
4191 // ORing 0 will have no impact so not doing that part.
4192 // In future if Chip select value changes from 0 to non zero,
4193 // That needs be taken care with backward comaptibility. No worries for now.
4197 SelectedChip Variable is the selection that the host is 100% Sure the same as what the register will hold. This can be ONLY ensured
4198 if the Chip doesn't goes to low power mode while the flash operation is in progress (NVMRdmWrmLock is taken)
4199 Before every new Flash Write operation, we reset the variable. This is to ensure that after any wake-up from
4200 power down modes (Idle mode/shutdown mode), the values in the register will be different.
4203 if (Adapter
->SelectedChip
== ChipNum
)
4204 return STATUS_SUCCESS
;
4206 // BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Selected Chip :%x", ChipNum);
4207 Adapter
->SelectedChip
= ChipNum
;
4209 // bit[13..12] will select the appropriate chip
4210 rdmalt(Adapter
, FLASH_CONFIG_REG
, &FlashConfig
, 4);
4211 rdmalt(Adapter
, FLASH_GPIO_CONFIG_REG
, &GPIOConfig
, 4);
4219 GPIOConfig
|= (0x4 << CHIP_SELECT_BIT12
);
4223 GPIOConfig
|= (0x1 << CHIP_SELECT_BIT12
);
4227 GPIOConfig
|= (0x2 << CHIP_SELECT_BIT12
);
4231 /* In case the bits already written in the FLASH_CONFIG_REG is same as what the user desired,
4232 nothing to do... can return immediately.
4233 ASSUMPTION: FLASH_GPIO_CONFIG_REG will be in sync with FLASH_CONFIG_REG.
4234 Even if the chip goes to low power mode, it should wake with values in each register in sync with each other.
4235 These values are not written by host other than during CHIP_SELECT.
4237 if (PartNum
== ((FlashConfig
>> CHIP_SELECT_BIT12
) & 0x3))
4238 return STATUS_SUCCESS
;
4240 // clearing the bit[13..12]
4241 FlashConfig
&= 0xFFFFCFFF;
4242 FlashConfig
= (FlashConfig
| (PartNum
<<CHIP_SELECT_BIT12
)); // 00
4244 wrmalt(Adapter
, FLASH_GPIO_CONFIG_REG
, &GPIOConfig
, 4);
4247 wrmalt(Adapter
, FLASH_CONFIG_REG
, &FlashConfig
, 4);
4250 return STATUS_SUCCESS
;
4253 INT
ReadDSDSignature(struct bcm_mini_adapter
*Adapter
, FLASH2X_SECTION_VAL dsd
)
4256 //UINT sigoffsetInMap = 0;
4257 //DSD_HEADER dsdHeader = {0};
4260 //sigoffsetInMap =(PUCHAR)&(dsdHeader.DSDImageMagicNumber) -(PUCHAR)&dsdHeader;
4262 if (dsd
!= DSD0
&& dsd
!= DSD1
&& dsd
!= DSD2
) {
4263 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "passed section value is not for DSDs");
4264 return STATUS_FAILURE
;
4266 BcmFlash2xBulkRead(Adapter
,
4269 Adapter
->psFlash2xCSInfo
->OffsetFromDSDStartForDSDHeader
+ FIELD_OFFSET_IN_HEADER(PDSD_HEADER
, DSDImageMagicNumber
),
4272 uiDSDsig
= ntohl(uiDSDsig
);
4273 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "DSD SIG :%x", uiDSDsig
);
4278 INT
ReadDSDPriority(struct bcm_mini_adapter
*Adapter
, FLASH2X_SECTION_VAL dsd
)
4280 // UINT priOffsetInMap = 0 ;
4281 unsigned int uiDSDPri
= STATUS_FAILURE
;
4282 // DSD_HEADER dsdHeader = {0};
4283 // priOffsetInMap = (PUCHAR)&(dsdHeader.DSDImagePriority) -(PUCHAR)&dsdHeader;
4284 if (IsSectionWritable(Adapter
, dsd
)) {
4285 if (ReadDSDSignature(Adapter
, dsd
) == DSD_IMAGE_MAGIC_NUMBER
) {
4286 BcmFlash2xBulkRead(Adapter
,
4289 Adapter
->psFlash2xCSInfo
->OffsetFromDSDStartForDSDHeader
+ FIELD_OFFSET_IN_HEADER(PDSD_HEADER
, DSDImagePriority
),
4292 uiDSDPri
= ntohl(uiDSDPri
);
4293 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "DSD<%x> Priority :%x", dsd
, uiDSDPri
);
4300 FLASH2X_SECTION_VAL
getHighestPriDSD(struct bcm_mini_adapter
*Adapter
)
4302 INT DSDHighestPri
= STATUS_FAILURE
;
4304 FLASH2X_SECTION_VAL HighestPriDSD
= 0;
4306 if (IsSectionWritable(Adapter
, DSD2
)) {
4307 DSDHighestPri
= ReadDSDPriority(Adapter
, DSD2
);
4308 HighestPriDSD
= DSD2
;
4311 if (IsSectionWritable(Adapter
, DSD1
)) {
4312 DsdPri
= ReadDSDPriority(Adapter
, DSD1
);
4313 if (DSDHighestPri
< DsdPri
) {
4314 DSDHighestPri
= DsdPri
;
4315 HighestPriDSD
= DSD1
;
4319 if (IsSectionWritable(Adapter
, DSD0
)) {
4320 DsdPri
= ReadDSDPriority(Adapter
, DSD0
);
4321 if (DSDHighestPri
< DsdPri
) {
4322 DSDHighestPri
= DsdPri
;
4323 HighestPriDSD
= DSD0
;
4327 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "Highest DSD :%x , and its Pri :%x", HighestPriDSD
, DSDHighestPri
);
4329 return HighestPriDSD
;
4332 INT
ReadISOSignature(struct bcm_mini_adapter
*Adapter
, FLASH2X_SECTION_VAL iso
)
4335 //UINT sigoffsetInMap = 0;
4336 //ISO_HEADER ISOHeader = {0};
4337 //sigoffsetInMap =(PUCHAR)&(ISOHeader.ISOImageMagicNumber) -(PUCHAR)&ISOHeader;
4339 if (iso
!= ISO_IMAGE1
&& iso
!= ISO_IMAGE2
) {
4340 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "passed section value is not for ISOs");
4341 return STATUS_FAILURE
;
4343 BcmFlash2xBulkRead(Adapter
,
4346 0 + FIELD_OFFSET_IN_HEADER(PISO_HEADER
, ISOImageMagicNumber
),
4349 uiISOsig
= ntohl(uiISOsig
);
4350 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "ISO SIG :%x", uiISOsig
);
4355 INT
ReadISOPriority(struct bcm_mini_adapter
*Adapter
, FLASH2X_SECTION_VAL iso
)
4357 unsigned int ISOPri
= STATUS_FAILURE
;
4358 if (IsSectionWritable(Adapter
, iso
)) {
4359 if (ReadISOSignature(Adapter
, iso
) == ISO_IMAGE_MAGIC_NUMBER
) {
4360 BcmFlash2xBulkRead(Adapter
,
4363 0 + FIELD_OFFSET_IN_HEADER(PISO_HEADER
, ISOImagePriority
),
4366 ISOPri
= ntohl(ISOPri
);
4367 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "ISO<%x> Priority :%x", iso
, ISOPri
);
4374 FLASH2X_SECTION_VAL
getHighestPriISO(struct bcm_mini_adapter
*Adapter
)
4376 INT ISOHighestPri
= STATUS_FAILURE
;
4378 FLASH2X_SECTION_VAL HighestPriISO
= NO_SECTION_VAL
;
4380 if (IsSectionWritable(Adapter
, ISO_IMAGE2
)) {
4381 ISOHighestPri
= ReadISOPriority(Adapter
, ISO_IMAGE2
);
4382 HighestPriISO
= ISO_IMAGE2
;
4385 if (IsSectionWritable(Adapter
, ISO_IMAGE1
)) {
4386 ISOPri
= ReadISOPriority(Adapter
, ISO_IMAGE1
);
4387 if (ISOHighestPri
< ISOPri
) {
4388 ISOHighestPri
= ISOPri
;
4389 HighestPriISO
= ISO_IMAGE1
;
4393 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "Highest ISO :%x and its Pri :%x", HighestPriISO
, ISOHighestPri
);
4395 return HighestPriISO
;
4398 INT
WriteToFlashWithoutSectorErase(struct bcm_mini_adapter
*Adapter
,
4400 FLASH2X_SECTION_VAL eFlash2xSectionVal
,
4404 #if !defined(BCM_SHM_INTERFACE) || defined(FLASH_DIRECT_ACCESS)
4405 UINT uiTemp
= 0, value
= 0;
4407 UINT uiPartOffset
= 0;
4409 UINT uiStartOffset
= 0;
4410 // Adding section start address
4411 INT Status
= STATUS_SUCCESS
;
4412 PUCHAR pcBuff
= (PUCHAR
)pBuff
;
4414 if (uiNumBytes
% Adapter
->ulFlashWriteSize
) {
4415 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Writing without Sector Erase for non-FlashWriteSize number of bytes 0x%x\n", uiNumBytes
);
4416 return STATUS_FAILURE
;
4419 uiStartOffset
= BcmGetSectionValStartOffset(Adapter
, eFlash2xSectionVal
);
4421 if (IsSectionExistInVendorInfo(Adapter
, eFlash2xSectionVal
))
4422 return vendorextnWriteSectionWithoutErase(Adapter
, pcBuff
, eFlash2xSectionVal
, uiOffset
, uiNumBytes
);
4424 uiOffset
= uiOffset
+ uiStartOffset
;
4426 #if defined(BCM_SHM_INTERFACE) && !defined(FLASH_DIRECT_ACCESS)
4427 Status
= bcmflash_raw_writenoerase((uiOffset
/ FLASH_PART_SIZE
), (uiOffset
% FLASH_PART_SIZE
), pcBuff
, uiNumBytes
);
4429 rdmalt(Adapter
, 0x0f000C80, &uiTemp
, sizeof(uiTemp
));
4431 wrmalt(Adapter
, 0x0f000C80, &value
, sizeof(value
));
4433 Adapter
->SelectedChip
= RESET_CHIP_SELECT
;
4434 BcmDoChipSelect(Adapter
, uiOffset
);
4435 uiPartOffset
= (uiOffset
& (FLASH_PART_SIZE
- 1)) + GetFlashBaseAddr(Adapter
);
4437 for (i
= 0 ; i
< uiNumBytes
; i
+= Adapter
->ulFlashWriteSize
) {
4438 if (Adapter
->ulFlashWriteSize
== BYTE_WRITE_SUPPORT
)
4439 Status
= flashByteWrite(Adapter
, uiPartOffset
, pcBuff
);
4441 Status
= flashWrite(Adapter
, uiPartOffset
, pcBuff
);
4443 if (Status
!= STATUS_SUCCESS
)
4446 pcBuff
= pcBuff
+ Adapter
->ulFlashWriteSize
;
4447 uiPartOffset
= uiPartOffset
+ Adapter
->ulFlashWriteSize
;
4449 wrmalt(Adapter
, 0x0f000C80, &uiTemp
, sizeof(uiTemp
));
4450 Adapter
->SelectedChip
= RESET_CHIP_SELECT
;
4456 BOOLEAN
IsSectionExistInFlash(struct bcm_mini_adapter
*Adapter
, FLASH2X_SECTION_VAL section
)
4458 BOOLEAN SectionPresent
= FALSE
;
4462 if ((Adapter
->psFlash2xCSInfo
->OffsetISOImage1Part1Start
!= UNINIT_PTR_IN_CS
) &&
4463 (IsNonCDLessDevice(Adapter
) == FALSE
))
4464 SectionPresent
= TRUE
;
4467 if ((Adapter
->psFlash2xCSInfo
->OffsetISOImage2Part1Start
!= UNINIT_PTR_IN_CS
) &&
4468 (IsNonCDLessDevice(Adapter
) == FALSE
))
4469 SectionPresent
= TRUE
;
4472 if (Adapter
->psFlash2xCSInfo
->OffsetFromZeroForDSDStart
!= UNINIT_PTR_IN_CS
)
4473 SectionPresent
= TRUE
;
4476 if (Adapter
->psFlash2xCSInfo
->OffsetFromZeroForDSD1Start
!= UNINIT_PTR_IN_CS
)
4477 SectionPresent
= TRUE
;
4480 if (Adapter
->psFlash2xCSInfo
->OffsetFromZeroForDSD2Start
!= UNINIT_PTR_IN_CS
)
4481 SectionPresent
= TRUE
;
4484 if (Adapter
->psFlash2xCSInfo
->OffsetFromZeroForVSAStart
!= UNINIT_PTR_IN_CS
)
4485 SectionPresent
= TRUE
;
4488 if (Adapter
->psFlash2xCSInfo
->OffsetFromZeroForVSA1Start
!= UNINIT_PTR_IN_CS
)
4489 SectionPresent
= TRUE
;
4492 if (Adapter
->psFlash2xCSInfo
->OffsetFromZeroForVSA2Start
!= UNINIT_PTR_IN_CS
)
4493 SectionPresent
= TRUE
;
4496 if (Adapter
->psFlash2xCSInfo
->OffsetFromZeroForScsiFirmware
!= UNINIT_PTR_IN_CS
)
4497 SectionPresent
= TRUE
;
4499 case CONTROL_SECTION
:
4500 if (Adapter
->psFlash2xCSInfo
->OffsetFromZeroForControlSectionStart
!= UNINIT_PTR_IN_CS
)
4501 SectionPresent
= TRUE
;
4504 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Section Does not exist in Flash 2.x");
4505 SectionPresent
= FALSE
;
4508 return SectionPresent
;
4511 INT
IsSectionWritable(struct bcm_mini_adapter
*Adapter
, FLASH2X_SECTION_VAL Section
)
4513 INT offset
= STATUS_FAILURE
;
4516 if (IsSectionExistInFlash(Adapter
, Section
) == FALSE
) {
4517 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Section <%d> does not exixt", Section
);
4521 offset
= BcmGetSectionValStartOffset(Adapter
, Section
);
4522 if (offset
== INVALID_OFFSET
) {
4523 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Section<%d> does not exixt", Section
);
4527 if (IsSectionExistInVendorInfo(Adapter
, Section
))
4528 return !(Adapter
->psFlash2xVendorInfo
->VendorSection
[Section
].AccessFlags
& FLASH2X_SECTION_RO
);
4530 Status
= IsOffsetWritable(Adapter
, offset
);
4534 static INT
CorruptDSDSig(struct bcm_mini_adapter
*Adapter
, FLASH2X_SECTION_VAL eFlash2xSectionVal
)
4536 PUCHAR pBuff
= NULL
;
4539 UINT BlockStatus
= 0;
4540 UINT uiSectAlignAddr
= 0;
4542 Adapter
->bSigCorrupted
= FALSE
;
4543 if (Adapter
->bAllDSDWriteAllow
== FALSE
) {
4544 if (IsSectionWritable(Adapter
, eFlash2xSectionVal
) != TRUE
) {
4545 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Section is not Writable...Hence can't Corrupt signature");
4546 return SECTOR_IS_NOT_WRITABLE
;
4550 pBuff
= (PUCHAR
)kzalloc(MAX_RW_SIZE
, GFP_KERNEL
);
4551 if (pBuff
== NULL
) {
4552 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Can't allocate memorey");
4556 uiOffset
= Adapter
->psFlash2xCSInfo
->OffsetFromDSDStartForDSDHeader
+ sizeof(DSD_HEADER
);
4557 uiOffset
-= MAX_RW_SIZE
;
4559 BcmFlash2xBulkRead(Adapter
, (PUINT
)pBuff
, eFlash2xSectionVal
, uiOffset
, MAX_RW_SIZE
);
4561 sig
= *((PUINT
)(pBuff
+ 12));
4563 BCM_DEBUG_PRINT_BUFFER(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, pBuff
, MAX_RW_SIZE
);
4564 // Now corrupting the sig by corrupting 4th last Byte.
4567 if (sig
== DSD_IMAGE_MAGIC_NUMBER
) {
4568 Adapter
->bSigCorrupted
= TRUE
;
4569 if (Adapter
->ulFlashWriteSize
== BYTE_WRITE_SUPPORT
) {
4570 uiSectAlignAddr
= uiOffset
& ~(Adapter
->uiSectorSize
- 1);
4571 BlockStatus
= BcmFlashUnProtectBlock(Adapter
, uiSectAlignAddr
, Adapter
->uiSectorSize
);
4573 WriteToFlashWithoutSectorErase(Adapter
, (PUINT
)(pBuff
+ 12), eFlash2xSectionVal
,
4574 (uiOffset
+ 12), BYTE_WRITE_SUPPORT
);
4576 BcmRestoreBlockProtectStatus(Adapter
, BlockStatus
);
4580 WriteToFlashWithoutSectorErase(Adapter
, (PUINT
)pBuff
, eFlash2xSectionVal
,
4581 uiOffset
, MAX_RW_SIZE
);
4584 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "BCM Signature is not present in header");
4587 return STATUS_FAILURE
;
4591 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "Corrupted the signature");
4593 return STATUS_SUCCESS
;
4596 static INT
CorruptISOSig(struct bcm_mini_adapter
*Adapter
, FLASH2X_SECTION_VAL eFlash2xSectionVal
)
4598 PUCHAR pBuff
= NULL
;
4602 Adapter
->bSigCorrupted
= FALSE
;
4604 if (IsSectionWritable(Adapter
, eFlash2xSectionVal
) != TRUE
) {
4605 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Section is not Writable...Hence can't Corrupt signature");
4606 return SECTOR_IS_NOT_WRITABLE
;
4609 pBuff
= (PUCHAR
)kzalloc(MAX_RW_SIZE
, GFP_KERNEL
);
4610 if (pBuff
== NULL
) {
4611 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Can't allocate memorey");
4617 BcmFlash2xBulkRead(Adapter
, (PUINT
)pBuff
, eFlash2xSectionVal
, uiOffset
, MAX_RW_SIZE
);
4619 sig
= *((PUINT
)pBuff
);
4622 // corrupt signature
4625 if (sig
== ISO_IMAGE_MAGIC_NUMBER
) {
4626 Adapter
->bSigCorrupted
= TRUE
;
4627 WriteToFlashWithoutSectorErase(Adapter
, (PUINT
)pBuff
, eFlash2xSectionVal
,
4628 uiOffset
, Adapter
->ulFlashWriteSize
);
4630 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "BCM Signature is not present in header");
4633 return STATUS_FAILURE
;
4636 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, "Corrupted the signature");
4637 BCM_DEBUG_PRINT_BUFFER(Adapter
, DBG_TYPE_OTHERS
, NVM_RW
, DBG_LVL_ALL
, pBuff
, MAX_RW_SIZE
);
4640 return STATUS_SUCCESS
;
4643 BOOLEAN
IsNonCDLessDevice(struct bcm_mini_adapter
*Adapter
)
4645 if (Adapter
->psFlash2xCSInfo
->IsCDLessDeviceBootSig
== NON_CDLESS_DEVICE_BOOT_SIG
)