3 #define DWORD unsigned int
4 // Procedure: ReadEEPROMStatusRegister
6 // Description: Reads the standard EEPROM Status Register.
9 // Adapter - ptr to Adapter object instance
13 //-----------------------------------------------------------------------------
15 static UCHAR ReadEEPROMStatusRegister( PMINI_ADAPTER Adapter )
18 DWORD dwRetries = MAX_EEPROM_RETRIES*RETRIES_PER_DELAY;
23 /* Read the EEPROM status register */
24 value = EEPROM_READ_STATUS_REGISTER ;
25 wrmalt( Adapter, EEPROM_CMDQ_SPI_REG, &value, sizeof(value));
27 while ( dwRetries != 0 )
31 rdmalt( Adapter, EEPROM_SPI_Q_STATUS1_REG,&uiStatus, sizeof(uiStatus));
32 if(Adapter->device_removed == TRUE)
34 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Modem has got removed hence exiting....");
38 /* Wait for Avail bit to be set. */
39 if ( ( uiStatus & EEPROM_READ_DATA_AVAIL) != 0 )
41 /* Clear the Avail/Full bits - which ever is set. */
42 value = uiStatus & (EEPROM_READ_DATA_AVAIL | EEPROM_READ_DATA_FULL);
43 wrmalt( Adapter, EEPROM_SPI_Q_STATUS1_REG, &value, sizeof(value));
46 rdmalt(Adapter, EEPROM_READ_DATAQ_REG,&value, sizeof(value));
47 uiData = (UCHAR)value;
55 rdmalt(Adapter, EEPROM_SPI_Q_STATUS1_REG,&value, sizeof(value));
56 rdmalt(Adapter, EEPROM_SPI_Q_STATUS_REG,&value1, sizeof(value1));
57 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);
60 if( !(dwRetries%RETRIES_PER_DELAY) )
65 } /* ReadEEPROMStatusRegister */
67 //-----------------------------------------------------------------------------
68 // Procedure: ReadBeceemEEPROMBulk
70 // Description: This routine reads 16Byte data from EEPROM
73 // Adapter - ptr to Adapter object instance
74 // dwAddress - EEPROM Offset to read the data from.
75 // pdwData - Pointer to double word where data needs to be stored in. // dwNumWords - Number of words. Valid values are 4 ONLY.
79 //-----------------------------------------------------------------------------
81 INT ReadBeceemEEPROMBulk( PMINI_ADAPTER Adapter,
88 DWORD dwRetries = MAX_EEPROM_RETRIES*RETRIES_PER_DELAY;
94 /* Flush the read and cmd queue. */
95 value=( EEPROM_READ_QUEUE_FLUSH | EEPROM_CMD_QUEUE_FLUSH );
96 wrmalt( Adapter, SPI_FLUSH_REG, &value, sizeof(value) );
98 wrmalt( Adapter, SPI_FLUSH_REG, &value, sizeof(value));
100 /* Clear the Avail/Full bits. */
101 value=( EEPROM_READ_DATA_AVAIL | EEPROM_READ_DATA_FULL );
102 wrmalt( Adapter, EEPROM_SPI_Q_STATUS1_REG,&value, sizeof(value));
104 value= dwAddress | ( (dwNumWords == 4) ? EEPROM_16_BYTE_PAGE_READ : EEPROM_4_BYTE_PAGE_READ );
105 wrmalt( Adapter, EEPROM_CMDQ_SPI_REG, &value, sizeof(value));
107 while ( dwRetries != 0 )
111 rdmalt( Adapter, EEPROM_SPI_Q_STATUS1_REG, &uiStatus, sizeof(uiStatus));
112 if(Adapter->device_removed == TRUE)
114 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Modem has got Removed.hence exiting from loop...");
118 /* If we are reading 16 bytes we want to be sure that the queue
119 * is full before we read. In the other cases we are ok if the
120 * queue has data available */
121 if ( dwNumWords == 4 )
123 if ( ( uiStatus & EEPROM_READ_DATA_FULL ) != 0 )
125 /* Clear the Avail/Full bits - which ever is set. */
126 value = ( uiStatus & (EEPROM_READ_DATA_AVAIL | EEPROM_READ_DATA_FULL) ) ;
127 wrmalt( Adapter, EEPROM_SPI_Q_STATUS1_REG,&value, sizeof(value));
131 else if ( dwNumWords == 1 )
134 if ( ( uiStatus & EEPROM_READ_DATA_AVAIL ) != 0 )
136 /* We just got Avail and we have to read 32bits so we
137 * need this sleep for Cardbus kind of devices. */
138 if (Adapter->chip_id == 0xBECE0210 )
141 /* Clear the Avail/Full bits - which ever is set. */
142 value=( uiStatus & (EEPROM_READ_DATA_AVAIL | EEPROM_READ_DATA_FULL) );
143 wrmalt( Adapter, EEPROM_SPI_Q_STATUS1_REG,&value, sizeof(value));
155 rdmalt(Adapter, EEPROM_SPI_Q_STATUS1_REG,&value, sizeof(value));
156 rdmalt(Adapter, EEPROM_SPI_Q_STATUS_REG,&value1, sizeof(value1));
157 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "dwNumWords %d 0x3004 = %x 0x3008 = %x retries = %d failed.\n", dwNumWords, value, value1, MAX_EEPROM_RETRIES*RETRIES_PER_DELAY);
158 return STATUS_FAILURE;
160 if( !(dwRetries%RETRIES_PER_DELAY) )
164 for ( dwIndex = 0; dwIndex < dwNumWords ; dwIndex++ )
166 /* We get only a byte at a time - from LSB to MSB. We shift it into an integer. */
167 pvalue = (PUCHAR)(pdwData + dwIndex);
170 rdmalt(Adapter, EEPROM_READ_DATAQ_REG,&value, sizeof(value));
175 rdmalt(Adapter, EEPROM_READ_DATAQ_REG,&value, sizeof(value));
180 rdmalt(Adapter, EEPROM_READ_DATAQ_REG,&value, sizeof(value));
185 rdmalt(Adapter, EEPROM_READ_DATAQ_REG,&value, sizeof(value));
190 return STATUS_SUCCESS;
191 } /* ReadBeceemEEPROMBulk() */
193 //-----------------------------------------------------------------------------
194 // Procedure: ReadBeceemEEPROM
196 // Description: This routine reads 4 data from EEPROM. It uses 1 or 2 page
197 // reads to do this operation.
200 // Adapter - ptr to Adapter object instance
201 // uiOffset - EEPROM Offset to read the data from.
202 // pBuffer - Pointer to word where data needs to be stored in.
206 //-----------------------------------------------------------------------------
208 INT ReadBeceemEEPROM( PMINI_ADAPTER Adapter,
213 UINT uiData[8] = {0};
214 UINT uiByteOffset = 0;
215 UINT uiTempOffset = 0;
217 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL," ====> ");
219 uiTempOffset = uiOffset - (uiOffset % MAX_RW_SIZE);
220 uiByteOffset = uiOffset - uiTempOffset;
222 ReadBeceemEEPROMBulk(Adapter, uiTempOffset, (PUINT)&uiData[0], 4);
224 /* A word can overlap at most over 2 pages. In that case we read the
226 if ( uiByteOffset > 12 )
228 ReadBeceemEEPROMBulk(Adapter, uiTempOffset + MAX_RW_SIZE, (PUINT)&uiData[4], 4);
231 OsalMemMove( (PUCHAR) pBuffer, ( ((PUCHAR)&uiData[0]) + uiByteOffset ), 4);
233 return STATUS_SUCCESS;
234 } /* ReadBeceemEEPROM() */
238 //-----------------------------------------------------------------------------
239 // Procedure: IsEEPROMWriteDone
241 // Description: Reads the SPI status to see the status of previous write.
244 // Adapter - ptr to Adapter object instance
247 // BOOLEAN - TRUE - write went through
248 // - FALSE - Write Failed.
249 //-----------------------------------------------------------------------------
251 BOOLEAN IsEEPROMWriteDone(PMINI_ADAPTER Adapter)
257 //sleep for 1.2ms ..worst case EEPROM write can take up to 1.2ms.
261 rdmalt(Adapter, EEPROM_SPI_Q_STATUS1_REG, &value, sizeof(value));
263 while(((value >> 14) & 1) == 1)
265 // EEPROM_SPI_Q_STATUS1_REG will be cleared only if write back to that.
267 wrmalt(Adapter, EEPROM_SPI_Q_STATUS1_REG,&value, sizeof(value));
275 rdmalt(Adapter, EEPROM_SPI_Q_STATUS1_REG, &value, sizeof(value));
283 //-----------------------------------------------------------------------------
284 // Procedure: ReadBeceemEEPROMBulk
286 // Description: This routine reads 16Byte data from EEPROM
289 // Adapter - ptr to Adapter object instance
290 // dwAddress - EEPROM Offset to read the data from.
291 // pdwData - Pointer to double word where data needs to be stored in.
295 //-----------------------------------------------------------------------------
297 INT ReadBeceemEEPROMBulk(PMINI_ADAPTER Adapter,DWORD dwAddress, DWORD *pdwData)
299 DWORD dwRetries = 16;
305 rdmalt (Adapter, 0x0f003008, &value, sizeof(value));
307 //read 0x0f003020 untill bit 1 of 0x0f003008 is set.
308 while(((value >> 1) & 1) == 0)
311 rdmalt (Adapter, 0x0f003020, &tmpVal, sizeof(tmpVal));
318 rdmalt (Adapter, 0x0f003008, &value, sizeof(value));
321 value = dwAddress | 0xfb000000;
322 wrmalt (Adapter, 0x0f003018, &value, sizeof(value));
326 for(dwIndex = 0;dwIndex < 4 ; dwIndex++)
329 rdmalt (Adapter, 0x0f003020, &value, sizeof(value));
330 pdwData[dwIndex] = value;
333 rdmalt (Adapter, 0x0f003020, &value, sizeof(value));
334 pdwData[dwIndex] |= (value << 8);
337 rdmalt (Adapter, 0x0f003020, &value, sizeof(value));
338 pdwData[dwIndex] |= (value << 16);
341 rdmalt (Adapter, 0x0f003020, &value, sizeof(value));
342 pdwData[dwIndex] |= (value << 24);
348 //-----------------------------------------------------------------------------
349 // Procedure: ReadBeceemEEPROM
351 // Description: This routine reads 4Byte data from EEPROM
354 // Adapter - ptr to Adapter object instance
355 // dwAddress - EEPROM Offset to read the data from.
356 // pdwData - Pointer to double word where data needs to be stored in.
360 //-----------------------------------------------------------------------------
362 INT ReadBeceemEEPROM(PMINI_ADAPTER Adapter,DWORD dwAddress, DWORD *pdwData)
365 DWORD dwReadValue = 0;
366 DWORD dwRetries = 16, dwCompleteWord = 0;
369 rdmalt(Adapter, 0x0f003008, &value, sizeof(value));
370 while (((value >> 1) & 1) == 0) {
371 rdmalt(Adapter, 0x0f003020, &tmpVal, sizeof(tmpVal));
373 if (dwRetries == 0) {
376 rdmalt(Adapter, 0x0f003008, &value, sizeof(value));
380 //wrm (0x0f003018, 0xNbXXXXXX) // N is the number of bytes u want to read (0 means 1, f means 16, b is the opcode for page read)
381 // Follow it up by N executions of rdm(0x0f003020) to read the rxed bytes from rx queue.
382 dwAddress |= 0x3b000000;
383 wrmalt(Adapter, 0x0f003018,&dwAddress,4);
385 rdmalt(Adapter, 0x0f003020,&dwReadValue,4);
386 dwCompleteWord=dwReadValue;
387 rdmalt(Adapter, 0x0f003020,&dwReadValue,4);
388 dwCompleteWord|=(dwReadValue<<8);
389 rdmalt(Adapter, 0x0f003020,&dwReadValue,4);
390 dwCompleteWord|=(dwReadValue<<16);
391 rdmalt(Adapter, 0x0f003020,&dwReadValue,4);
392 dwCompleteWord|=(dwReadValue<<24);
394 *pdwData = dwCompleteWord;
400 INT ReadMacAddressFromNVM(PMINI_ADAPTER Adapter)
403 unsigned char puMacAddr[6] = {0};
407 Status = BeceemNVMRead(Adapter,
408 (PUINT)&puMacAddr[0],
409 INIT_PARAMS_1_MACADDRESS_ADDRESS,
412 if(Status != STATUS_SUCCESS)
414 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Error in Reading the mac Addres with status :%d", Status);
418 memcpy(Adapter->dev->dev_addr, puMacAddr, MAC_ADDRESS_SIZE);
419 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Modem MAC Addr :");
420 BCM_DEBUG_PRINT_BUFFER(Adapter,DBG_TYPE_PRINTK, 0, DBG_LVL_ALL,&Adapter->dev->dev_addr[0],MAC_ADDRESS_SIZE);
421 for(i=0;i<MAC_ADDRESS_SIZE;i++)
424 if(Adapter->dev->dev_addr[i] == 0x00)
426 if(Adapter->dev->dev_addr[i] == 0xFF)
430 //BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "\n");
431 if(AllZeroMac == MAC_ADDRESS_SIZE)
432 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Warning :: MAC Address has all 00's");
433 if(AllFFMac == MAC_ADDRESS_SIZE)
434 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Warning :: MAC Address has all FF's");
440 //-----------------------------------------------------------------------------
441 // Procedure: BeceemEEPROMBulkRead
443 // Description: Reads the EEPROM and returns the Data.
446 // Adapter - ptr to Adapter object instance
447 // pBuffer - Buffer to store the data read from EEPROM
448 // uiOffset - Offset of EEPROM from where data should be read
449 // uiNumBytes - Number of bytes to be read from the EEPROM.
452 // OSAL_STATUS_SUCCESS - if EEPROM read is successfull.
453 // <FAILURE> - if failed.
454 //-----------------------------------------------------------------------------
456 INT BeceemEEPROMBulkRead(
457 PMINI_ADAPTER Adapter,
462 UINT uiData[4] = {0};
463 //UINT uiAddress = 0;
464 UINT uiBytesRemaining = uiNumBytes;
466 UINT uiTempOffset = 0;
467 UINT uiExtraBytes = 0;
468 UINT uiFailureRetries = 0;
469 PUCHAR pcBuff = (PUCHAR)pBuffer;
472 if(uiOffset%MAX_RW_SIZE&& uiBytesRemaining)
474 uiTempOffset = uiOffset - (uiOffset%MAX_RW_SIZE);
475 uiExtraBytes = uiOffset-uiTempOffset;
476 ReadBeceemEEPROMBulk(Adapter,uiTempOffset,(PUINT)&uiData[0],4);
477 if(uiBytesRemaining >= (MAX_RW_SIZE - uiExtraBytes))
479 OsalMemMove(pBuffer,(((PUCHAR)&uiData[0])+uiExtraBytes),MAX_RW_SIZE - uiExtraBytes);
481 uiBytesRemaining -= (MAX_RW_SIZE - uiExtraBytes);
482 uiIndex += (MAX_RW_SIZE - uiExtraBytes);
483 uiOffset += (MAX_RW_SIZE - uiExtraBytes);
487 OsalMemMove(pBuffer,(((PUCHAR)&uiData[0])+uiExtraBytes),uiBytesRemaining);
488 uiIndex += uiBytesRemaining;
489 uiOffset += uiBytesRemaining;
490 uiBytesRemaining = 0;
497 while(uiBytesRemaining && uiFailureRetries != 128)
499 if(Adapter->device_removed )
504 if(uiBytesRemaining >= MAX_RW_SIZE)
506 /* For the requests more than or equal to 16 bytes, use bulk
507 * read function to make the access faster.
508 * We read 4 Dwords of data */
509 if(0 == ReadBeceemEEPROMBulk(Adapter,uiOffset,&uiData[0],4))
511 OsalMemMove(pcBuff+uiIndex,&uiData[0],MAX_RW_SIZE);
512 uiOffset += MAX_RW_SIZE;
513 uiBytesRemaining -= MAX_RW_SIZE;
514 uiIndex += MAX_RW_SIZE;
519 mdelay(3);//sleep for a while before retry...
522 else if(uiBytesRemaining >= 4)
524 if(0 == ReadBeceemEEPROM(Adapter,uiOffset,&uiData[0]))
526 OsalMemMove(pcBuff+uiIndex,&uiData[0],4);
528 uiBytesRemaining -= 4;
534 mdelay(3);//sleep for a while before retry...
538 { // Handle the reads less than 4 bytes...
539 PUCHAR pCharBuff = (PUCHAR)pBuffer;
540 pCharBuff += uiIndex;
541 if(0 == ReadBeceemEEPROM(Adapter,uiOffset,&uiData[0]))
543 OsalMemMove(pCharBuff,&uiData[0],uiBytesRemaining);//copy only bytes requested.
544 uiBytesRemaining = 0;
549 mdelay(3);//sleep for a while before retry...
558 //-----------------------------------------------------------------------------
559 // Procedure: BeceemFlashBulkRead
561 // Description: Reads the FLASH and returns the Data.
564 // Adapter - ptr to Adapter object instance
565 // pBuffer - Buffer to store the data read from FLASH
566 // uiOffset - Offset of FLASH from where data should be read
567 // uiNumBytes - Number of bytes to be read from the FLASH.
570 // OSAL_STATUS_SUCCESS - if FLASH read is successfull.
571 // <FAILURE> - if failed.
572 //-----------------------------------------------------------------------------
574 INT BeceemFlashBulkRead(
575 PMINI_ADAPTER Adapter,
581 UINT uiBytesToRead = uiNumBytes;
583 UINT uiPartOffset = 0;
585 if(Adapter->device_removed )
587 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Device Got Removed ");
591 //Adding flash Base address
592 // uiOffset = uiOffset + GetFlashBaseAddr(Adapter);
593 #if defined(BCM_SHM_INTERFACE) && !defined(FLASH_DIRECT_ACCESS)
594 Status = bcmflash_raw_read((uiOffset/FLASH_PART_SIZE),(uiOffset % FLASH_PART_SIZE),( unsigned char *)pBuffer,uiNumBytes);
598 Adapter->SelectedChip = RESET_CHIP_SELECT;
600 if(uiOffset % MAX_RW_SIZE)
602 BcmDoChipSelect(Adapter,uiOffset);
603 uiPartOffset = (uiOffset & (FLASH_PART_SIZE - 1)) + GetFlashBaseAddr(Adapter);
605 uiBytesToRead = MAX_RW_SIZE - (uiOffset%MAX_RW_SIZE);
606 uiBytesToRead = MIN(uiNumBytes,uiBytesToRead);
608 if(rdm(Adapter,uiPartOffset, (PCHAR)pBuffer+uiIndex,uiBytesToRead))
611 Adapter->SelectedChip = RESET_CHIP_SELECT;
615 uiIndex += uiBytesToRead;
616 uiOffset += uiBytesToRead;
617 uiNumBytes -= uiBytesToRead;
622 BcmDoChipSelect(Adapter,uiOffset);
623 uiPartOffset = (uiOffset & (FLASH_PART_SIZE - 1)) + GetFlashBaseAddr(Adapter);
625 uiBytesToRead = MIN(uiNumBytes,MAX_RW_SIZE);
627 if(rdm(Adapter,uiPartOffset, (PCHAR)pBuffer+uiIndex,uiBytesToRead))
634 uiIndex += uiBytesToRead;
635 uiOffset += uiBytesToRead;
636 uiNumBytes -= uiBytesToRead;
639 Adapter->SelectedChip = RESET_CHIP_SELECT;
643 //-----------------------------------------------------------------------------
644 // Procedure: BcmGetFlashSize
646 // Description: Finds the size of FLASH.
649 // Adapter - ptr to Adapter object instance
652 // UINT - size of the FLASH Storage.
654 //-----------------------------------------------------------------------------
656 UINT BcmGetFlashSize(PMINI_ADAPTER Adapter)
659 if(Adapter->bDDRInitDone)
661 return rdm(Adapter,FLASH_CONTIGIOUS_START_ADDR_AFTER_INIT|FLASH_SIZE_ADDR);
664 return rdm(Adapter,FLASH_CONTIGIOUS_START_ADDR_BEFORE_INIT|FLASH_SIZE_ADDR);
666 if(IsFlash2x(Adapter))
667 return (Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + sizeof(DSD_HEADER));
674 //-----------------------------------------------------------------------------
675 // Procedure: BcmGetEEPROMSize
677 // Description: Finds the size of EEPROM.
680 // Adapter - ptr to Adapter object instance
683 // UINT - size of the EEPROM Storage.
685 //-----------------------------------------------------------------------------
687 UINT BcmGetEEPROMSize(PMINI_ADAPTER Adapter)
693 // if EEPROM is present and already Calibrated,it will have
694 // 'BECM' string at 0th offset.
695 // To find the EEPROM size read the possible boundaries of the
696 // EEPROM like 4K,8K etc..accessing the EEPROM beyond its size will
697 // result in wrap around. So when we get the End of the EEPROM we will
698 // get 'BECM' string which is indeed at offset 0.
700 BeceemEEPROMBulkRead(Adapter,&uiData,0x0,4);
703 for(uiIndex = 2;uiIndex <=256; uiIndex*=2)
705 BeceemEEPROMBulkRead(Adapter,&uiData,uiIndex*1024,4);
715 // EEPROM may not be present or not programmed
719 if(0 == BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&uiData,0,4,TRUE))
722 for(uiIndex = 2;uiIndex <=256; uiIndex*=2)
724 BeceemEEPROMBulkRead(Adapter,&uiData,uiIndex*1024,4);
725 if(uiData == 0xBABEFACE)
737 /***********************************************************************************/
739 // WriteBeceemEEPROM: Writes 4 byte data to EEPROM offset.
741 // uiEEPROMOffset - Offset to be written to.
742 // uiData - Data to be written.
744 /***********************************************************************************/
746 INT WriteBeceemEEPROM(PMINI_ADAPTER Adapter,UINT uiEEPROMOffset, UINT uiData)
750 ULONG ulRetryCount = 3;
753 if(uiEEPROMOffset > EEPROM_END)
759 uiData = htonl(uiData);
760 while(ulRetryCount--)
763 wrmalt(Adapter, 0x0F003018,&value, sizeof(value));//flush the EEPROM FIFO.
764 wrmalt(Adapter, 0x0F00301C,&uiData, sizeof(uiData));
765 value = 0x3A000000 | uiEEPROMOffset;
766 wrmalt(Adapter, 0x0F003018,&value, sizeof(value));
768 //read back and verify.
769 Status = ReadBeceemEEPROM(Adapter,uiEEPROMOffset,(UINT *)&ulRdBk);
778 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "WriteBeceemEEPROM: Readback does not match\n");
783 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "WriteBeceemEEPROM: Readback failed\n");
791 //-----------------------------------------------------------------------------
792 // Procedure: FlashSectorErase
794 // Description: Finds the sector size of the FLASH.
797 // Adapter - ptr to Adapter object instance
798 // addr - sector start address
799 // numOfSectors - number of sectors to be erased.
804 //-----------------------------------------------------------------------------
807 static INT FlashSectorErase(PMINI_ADAPTER Adapter,
811 UINT iIndex = 0, iRetries = 0;
815 for(iIndex=0;iIndex<numOfSectors;iIndex++)
818 wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value));
820 value = (0xd8000000 | (addr & 0xFFFFFF));
821 wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value));
826 value = (FLASH_CMD_STATUS_REG_READ << 24);
827 if(wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value)) < 0)
829 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Programing of FLASH_SPI_CMDQ_REG fails");
830 return STATUS_FAILURE;
833 if(rdmalt(Adapter, FLASH_SPI_READQ_REG, &uiStatus, sizeof(uiStatus)) < 0 )
835 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Reading status of FLASH_SPI_READQ_REG fails");
836 return STATUS_FAILURE;
839 //After every try lets make the CPU free for 10 ms. generally time taken by the
840 //the sector erase cycle is 500 ms to 40000 msec. hence sleeping 10 ms
841 //won't hamper performance in any case.
843 }while((uiStatus & 0x1) && (iRetries < 400));
847 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"iRetries crossing the limit of 80000\n");
848 return STATUS_FAILURE;
851 addr += Adapter->uiSectorSize;
855 //-----------------------------------------------------------------------------
856 // Procedure: flashByteWrite
858 // Description: Performs Byte by Byte write to flash
861 // Adapter - ptr to Adapter object instance
862 // uiOffset - Offset of the flash where data needs to be written to.
863 // pData - Address of Data to be written.
867 //-----------------------------------------------------------------------------
869 static INT flashByteWrite(
870 PMINI_ADAPTER Adapter,
876 INT iRetries = MAX_FLASH_RETRIES * FLASH_PER_RETRIES_DELAY; //3
879 ULONG ulData = *(PUCHAR)pData;
882 // need not write 0xFF because write requires an erase and erase will
883 // make whole sector 0xFF.
888 return STATUS_SUCCESS;
891 // DumpDebug(NVM_RW,("flashWrite ====>\n"));
892 value = (FLASH_CMD_WRITE_ENABLE << 24);
893 if(wrmalt(Adapter, FLASH_SPI_CMDQ_REG,&value, sizeof(value)) < 0)
895 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Write enable in FLASH_SPI_CMDQ_REG register fails");
896 return STATUS_FAILURE;
898 if(wrm(Adapter,FLASH_SPI_WRITEQ_REG, (PCHAR)&ulData, 4) < 0 )
900 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"DATA Write on FLASH_SPI_WRITEQ_REG fails");
901 return STATUS_FAILURE;
903 value = (0x02000000 | (uiOffset & 0xFFFFFF));
904 if(wrmalt(Adapter, FLASH_SPI_CMDQ_REG,&value, sizeof(value)) < 0 )
906 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Programming of FLASH_SPI_CMDQ_REG fails");
907 return STATUS_FAILURE;
914 value = (FLASH_CMD_STATUS_REG_READ << 24);
915 if(wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value)) < 0)
917 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Programing of FLASH_SPI_CMDQ_REG fails");
918 return STATUS_FAILURE;
921 if(rdmalt(Adapter, FLASH_SPI_READQ_REG, &uiStatus, sizeof(uiStatus)) < 0)
923 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Reading status of FLASH_SPI_READQ_REG fails");
924 return STATUS_FAILURE;
927 if( iRetries && ((iRetries % FLASH_PER_RETRIES_DELAY) == 0))
930 }while((uiStatus & 0x1) && (iRetries >0) );
934 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash Write fails even after checking status for 200 times.");
935 return STATUS_FAILURE ;
938 return STATUS_SUCCESS;
943 //-----------------------------------------------------------------------------
944 // Procedure: flashWrite
946 // Description: Performs write to flash
949 // Adapter - ptr to Adapter object instance
950 // uiOffset - Offset of the flash where data needs to be written to.
951 // pData - Address of Data to be written.
955 //-----------------------------------------------------------------------------
957 static INT flashWrite(
958 PMINI_ADAPTER Adapter,
965 //UINT uiReadBack = 0;
968 INT iRetries = MAX_FLASH_RETRIES * FLASH_PER_RETRIES_DELAY; //3
971 UINT uiErasePattern[4] = {0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF};
973 // need not write 0xFFFFFFFF because write requires an erase and erase will
974 // make whole sector 0xFFFFFFFF.
976 if (!OsalMemCompare(pData, uiErasePattern, MAX_RW_SIZE))
981 value = (FLASH_CMD_WRITE_ENABLE << 24);
983 if(wrmalt(Adapter, FLASH_SPI_CMDQ_REG,&value, sizeof(value)) < 0 )
985 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Write Enable of FLASH_SPI_CMDQ_REG fails");
986 return STATUS_FAILURE;
988 if(wrm(Adapter, uiOffset, (PCHAR)pData, MAX_RW_SIZE) < 0)
990 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Data write fails...");
991 return STATUS_FAILURE;
997 value = (FLASH_CMD_STATUS_REG_READ << 24);
998 if(wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value)) < 0)
1000 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Programing of FLASH_SPI_CMDQ_REG fails");
1001 return STATUS_FAILURE;
1004 if(rdmalt(Adapter, FLASH_SPI_READQ_REG, &uiStatus, sizeof(uiStatus)) < 0 )
1006 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Reading status of FLASH_SPI_READQ_REG fails");
1007 return STATUS_FAILURE;
1011 //this will ensure that in there will be no changes in the current path.
1012 //currently one rdm/wrm takes 125 us.
1013 //Hence 125 *2 * FLASH_PER_RETRIES_DELAY > 3 ms(worst case delay)
1014 //Hence current implementation cycle will intoduce no delay in current path
1015 if(iRetries && ((iRetries % FLASH_PER_RETRIES_DELAY) == 0))
1017 }while((uiStatus & 0x1) && (iRetries > 0));
1021 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash Write fails even after checking status for 200 times.");
1022 return STATUS_FAILURE ;
1025 return STATUS_SUCCESS;
1028 //-----------------------------------------------------------------------------
1029 // Procedure: flashByteWriteStatus
1031 // Description: Performs byte by byte write to flash with write done status check
1034 // Adapter - ptr to Adapter object instance
1035 // uiOffset - Offset of the flash where data needs to be written to.
1036 // pData - Address of the Data to be written.
1040 //-----------------------------------------------------------------------------
1041 static INT flashByteWriteStatus(
1042 PMINI_ADAPTER Adapter,
1047 INT iRetries = MAX_FLASH_RETRIES * FLASH_PER_RETRIES_DELAY; //3
1048 ULONG ulData = *(PUCHAR)pData;
1052 // need not write 0xFFFFFFFF because write requires an erase and erase will
1053 // make whole sector 0xFFFFFFFF.
1058 return STATUS_SUCCESS;
1061 // DumpDebug(NVM_RW,("flashWrite ====>\n"));
1063 value = (FLASH_CMD_WRITE_ENABLE << 24);
1064 if(wrmalt(Adapter, FLASH_SPI_CMDQ_REG,&value, sizeof(value)) < 0)
1066 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Write enable in FLASH_SPI_CMDQ_REG register fails");
1067 return STATUS_SUCCESS;
1069 if(wrm(Adapter,FLASH_SPI_WRITEQ_REG, (PCHAR)&ulData, 4) < 0)
1071 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"DATA Write on FLASH_SPI_WRITEQ_REG fails");
1072 return STATUS_FAILURE;
1074 value = (0x02000000 | (uiOffset & 0xFFFFFF));
1075 if(wrmalt(Adapter, FLASH_SPI_CMDQ_REG,&value, sizeof(value)) < 0)
1077 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Programming of FLASH_SPI_CMDQ_REG fails");
1078 return STATUS_FAILURE;
1085 value = (FLASH_CMD_STATUS_REG_READ << 24);
1086 if(wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value)) < 0)
1088 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Programing of FLASH_SPI_CMDQ_REG fails");
1089 return STATUS_FAILURE;
1092 if(rdmalt(Adapter, FLASH_SPI_READQ_REG, &uiStatus, sizeof(uiStatus)) < 0)
1094 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Reading status of FLASH_SPI_READQ_REG fails");
1095 return STATUS_FAILURE;
1099 if( iRetries && ((iRetries % FLASH_PER_RETRIES_DELAY) == 0))
1101 }while((uiStatus & 0x1) && (iRetries > 0));
1105 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash Write fails even after checking status for 200 times.");
1106 return STATUS_FAILURE ;
1109 return STATUS_SUCCESS;
1112 //-----------------------------------------------------------------------------
1113 // Procedure: flashWriteStatus
1115 // Description: Performs write to flash with write done status check
1118 // Adapter - ptr to Adapter object instance
1119 // uiOffset - Offset of the flash where data needs to be written to.
1120 // pData - Address of the Data to be written.
1124 //-----------------------------------------------------------------------------
1126 static INT flashWriteStatus(
1127 PMINI_ADAPTER Adapter,
1132 INT iRetries = MAX_FLASH_RETRIES * FLASH_PER_RETRIES_DELAY; //3
1133 //UINT uiReadBack = 0;
1135 UINT uiErasePattern[4] = {0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF};
1138 // need not write 0xFFFFFFFF because write requires an erase and erase will
1139 // make whole sector 0xFFFFFFFF.
1141 if (!OsalMemCompare(pData,uiErasePattern,MAX_RW_SIZE))
1146 value = (FLASH_CMD_WRITE_ENABLE << 24);
1147 if(wrmalt(Adapter, FLASH_SPI_CMDQ_REG,&value, sizeof(value)) < 0)
1149 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Write Enable of FLASH_SPI_CMDQ_REG fails");
1150 return STATUS_FAILURE;
1152 if(wrm(Adapter, uiOffset, (PCHAR)pData, MAX_RW_SIZE) < 0)
1154 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Data write fails...");
1155 return STATUS_FAILURE;
1161 value = (FLASH_CMD_STATUS_REG_READ << 24);
1162 if(wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value)) < 0)
1164 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Programing of FLASH_SPI_CMDQ_REG fails");
1165 return STATUS_FAILURE;
1168 if(rdmalt(Adapter, FLASH_SPI_READQ_REG, &uiStatus, sizeof(uiStatus)) < 0)
1170 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Reading status of FLASH_SPI_READQ_REG fails");
1171 return STATUS_FAILURE;
1174 //this will ensure that in there will be no changes in the current path.
1175 //currently one rdm/wrm takes 125 us.
1176 //Hence 125 *2 * FLASH_PER_RETRIES_DELAY >3 ms(worst case delay)
1177 //Hence current implementation cycle will intoduce no delay in current path
1178 if(iRetries && ((iRetries % FLASH_PER_RETRIES_DELAY) == 0))
1180 }while((uiStatus & 0x1) && (iRetries >0));
1184 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash Write fails even after checking status for 200 times.");
1185 return STATUS_FAILURE ;
1188 return STATUS_SUCCESS;
1191 //-----------------------------------------------------------------------------
1192 // Procedure: BcmRestoreBlockProtectStatus
1194 // Description: Restores the original block protection status.
1197 // Adapter - ptr to Adapter object instance
1198 // ulWriteStatus -Original status
1202 //-----------------------------------------------------------------------------
1204 static VOID BcmRestoreBlockProtectStatus(PMINI_ADAPTER Adapter,ULONG ulWriteStatus)
1207 value = (FLASH_CMD_WRITE_ENABLE<< 24);
1208 wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value));
1211 value = (FLASH_CMD_STATUS_REG_WRITE<<24)|(ulWriteStatus << 16);
1212 wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value));
1215 //-----------------------------------------------------------------------------
1216 // Procedure: BcmFlashUnProtectBlock
1218 // Description: UnProtects appropriate blocks for writing.
1221 // Adapter - ptr to Adapter object instance
1222 // uiOffset - Offset of the flash where data needs to be written to. This should be Sector aligned.
1224 // ULONG - Status value before UnProtect.
1226 //-----------------------------------------------------------------------------
1227 static ULONG BcmFlashUnProtectBlock(PMINI_ADAPTER Adapter,UINT uiOffset, UINT uiLength)
1230 ULONG ulWriteStatus = 0;
1232 uiOffset = uiOffset&0x000FFFFF;
1235 // Implemented only for 1MB Flash parts.
1237 if(FLASH_PART_SST25VF080B == Adapter->ulFlashID)
1240 // Get Current BP status.
1242 value = (FLASH_CMD_STATUS_REG_READ << 24);
1243 wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value));
1246 // Read status will be WWXXYYZZ. We have to take only WW.
1248 rdmalt(Adapter, FLASH_SPI_READQ_REG, (PUINT)&ulStatus, sizeof(ulStatus));
1250 ulWriteStatus = ulStatus;
1253 // Bits [5-2] give current block level protection status.
1254 // Bit5: BP3 - DONT CARE
1255 // BP2-BP0: 0 - NO PROTECTION, 1 - UPPER 1/16, 2 - UPPER 1/8, 3 - UPPER 1/4
1256 // 4 - UPPER 1/2. 5 to 7 - ALL BLOCKS
1261 if((uiOffset+uiLength) <= 0x80000)
1264 // Offset comes in lower half of 1MB. Protect the upper half.
1265 // Clear BP1 and BP0 and set BP2.
1267 ulWriteStatus |= (0x4<<2);
1268 ulWriteStatus &= ~(0x3<<2);
1270 else if((uiOffset+uiLength) <= 0xC0000)
1273 // Offset comes below Upper 1/4. Upper 1/4 can be protected.
1274 // Clear BP2 and set BP1 and BP0.
1276 ulWriteStatus |= (0x3<<2);
1277 ulWriteStatus &= ~(0x1<<4);
1279 else if((uiOffset+uiLength) <= 0xE0000)
1282 // Offset comes below Upper 1/8. Upper 1/8 can be protected.
1283 // Clear BP2 and BP0 and set BP1
1285 ulWriteStatus |= (0x1<<3);
1286 ulWriteStatus &= ~(0x5<<2);
1289 else if((uiOffset+uiLength) <= 0xF0000)
1292 // Offset comes below Upper 1/16. Only upper 1/16 can be protected.
1293 // Set BP0 and Clear BP2,BP1.
1295 ulWriteStatus |= (0x1<<2);
1296 ulWriteStatus &= ~(0x3<<3);
1302 // Clear BP2,BP1 and BP0.
1304 ulWriteStatus &= ~(0x7<<2);
1307 value = (FLASH_CMD_WRITE_ENABLE<< 24);
1308 wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value));
1310 value = (FLASH_CMD_STATUS_REG_WRITE<<24)|(ulWriteStatus << 16);
1311 wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value));
1319 //-----------------------------------------------------------------------------
1320 // Procedure: BeceemFlashBulkWrite
1322 // Description: Performs write to the flash
1325 // Adapter - ptr to Adapter object instance
1326 // pBuffer - Data to be written.
1327 // uiOffset - Offset of the flash where data needs to be written to.
1328 // uiNumBytes - Number of bytes to be written.
1329 // bVerify - read verify flag.
1333 //-----------------------------------------------------------------------------
1335 INT BeceemFlashBulkWrite(
1336 PMINI_ADAPTER Adapter,
1342 PCHAR pTempBuff = NULL;
1343 PUCHAR pcBuffer = (PUCHAR)pBuffer;
1345 UINT uiOffsetFromSectStart = 0;
1346 UINT uiSectAlignAddr = 0;
1347 UINT uiCurrSectOffsetAddr = 0;
1348 UINT uiSectBoundary = 0;
1349 UINT uiNumSectTobeRead = 0;
1350 UCHAR ucReadBk[16] = {0};
1352 INT Status = STATUS_SUCCESS;
1355 UINT uiPartOffset = 0;
1357 struct timeval tv1 = {0};
1358 struct timeval tv2 = {0};
1360 struct timeval tr = {0};
1361 struct timeval te = {0};
1362 struct timeval tw = {0};
1363 struct timeval twv = {0};
1366 #if defined(BCM_SHM_INTERFACE) && !defined(FLASH_DIRECT_ACCESS)
1367 Status = bcmflash_raw_write((uiOffset/FLASH_PART_SIZE),(uiOffset % FLASH_PART_SIZE),( unsigned char *)pBuffer,uiNumBytes);
1371 uiOffsetFromSectStart = uiOffset & ~(Adapter->uiSectorSize - 1);
1373 //Adding flash Base address
1374 // uiOffset = uiOffset + GetFlashBaseAddr(Adapter);
1376 uiSectAlignAddr = uiOffset & ~(Adapter->uiSectorSize - 1);
1377 uiCurrSectOffsetAddr = uiOffset & (Adapter->uiSectorSize - 1);
1378 uiSectBoundary = uiSectAlignAddr + Adapter->uiSectorSize;
1380 //pTempBuff = OsalMemAlloc(MAX_SECTOR_SIZE,'!MVN');
1381 pTempBuff = OsalMemAlloc(Adapter->uiSectorSize ,"!MVN");
1382 if(NULL == pTempBuff)
1384 goto BeceemFlashBulkWrite_EXIT;
1387 // check if the data to be written is overlapped accross sectors
1389 if(uiOffset+uiNumBytes < uiSectBoundary)
1391 uiNumSectTobeRead = 1;
1395 // Number of sectors = Last sector start address/First sector start address
1396 uiNumSectTobeRead = (uiCurrSectOffsetAddr+uiNumBytes)/Adapter->uiSectorSize;
1397 if((uiCurrSectOffsetAddr+uiNumBytes)%Adapter->uiSectorSize)
1399 uiNumSectTobeRead++;
1403 //Check whether Requested sector is writable or not in case of flash2x write. But if write call is
1404 // for DSD calibration, allow it without checking of sector permission
1406 if(IsFlash2x(Adapter) && (Adapter->bAllDSDWriteAllow == FALSE))
1409 uiTemp = uiNumSectTobeRead ;
1412 if(IsOffsetWritable(Adapter, uiOffsetFromSectStart + index * Adapter->uiSectorSize ) == FALSE)
1414 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Sector Starting at offset <0X%X> is not writable",
1415 (uiOffsetFromSectStart + index * Adapter->uiSectorSize));
1416 Status = SECTOR_IS_NOT_WRITABLE;
1417 goto BeceemFlashBulkWrite_EXIT;
1419 uiTemp = uiTemp - 1;
1424 Adapter->SelectedChip = RESET_CHIP_SELECT;
1425 while(uiNumSectTobeRead)
1427 //do_gettimeofday(&tv1);
1428 //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));
1429 uiPartOffset = (uiSectAlignAddr & (FLASH_PART_SIZE - 1)) + GetFlashBaseAddr(Adapter);
1431 BcmDoChipSelect(Adapter,uiSectAlignAddr);
1433 if(0 != BeceemFlashBulkRead(Adapter,
1435 uiOffsetFromSectStart,
1436 Adapter->uiSectorSize))
1439 goto BeceemFlashBulkWrite_EXIT;
1442 //do_gettimeofday(&tr);
1443 //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));
1445 ulStatus = BcmFlashUnProtectBlock(Adapter,uiSectAlignAddr,Adapter->uiSectorSize);
1448 if(uiNumSectTobeRead > 1)
1451 OsalMemMove(&pTempBuff[uiCurrSectOffsetAddr],pcBuffer,uiSectBoundary-(uiSectAlignAddr+uiCurrSectOffsetAddr));
1452 pcBuffer += ((uiSectBoundary-(uiSectAlignAddr+uiCurrSectOffsetAddr)));
1453 uiNumBytes -= (uiSectBoundary-(uiSectAlignAddr+uiCurrSectOffsetAddr));
1457 OsalMemMove(&pTempBuff[uiCurrSectOffsetAddr],pcBuffer,uiNumBytes);
1460 if(IsFlash2x(Adapter))
1462 SaveHeaderIfPresent(Adapter,(PUCHAR)pTempBuff,uiOffsetFromSectStart);
1465 FlashSectorErase(Adapter,uiPartOffset,1);
1466 //do_gettimeofday(&te);
1467 //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));
1469 for(uiIndex = 0; uiIndex < Adapter->uiSectorSize; uiIndex +=Adapter->ulFlashWriteSize)
1471 if(Adapter->device_removed)
1474 goto BeceemFlashBulkWrite_EXIT;
1476 if(STATUS_SUCCESS != (*Adapter->fpFlashWrite)(Adapter,uiPartOffset+uiIndex,(&pTempBuff[uiIndex])))
1479 goto BeceemFlashBulkWrite_EXIT;
1483 //do_gettimeofday(&tw);
1484 //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));
1485 for(uiIndex = 0;uiIndex < Adapter->uiSectorSize;uiIndex += MAX_RW_SIZE)
1487 if(STATUS_SUCCESS == BeceemFlashBulkRead(Adapter,(PUINT)ucReadBk,uiOffsetFromSectStart+uiIndex,MAX_RW_SIZE))
1489 if(Adapter->ulFlashWriteSize == 1)
1491 UINT uiReadIndex = 0;
1492 for(uiReadIndex = 0; uiReadIndex < 16; uiReadIndex++)
1494 if(ucReadBk[uiReadIndex] != pTempBuff[uiIndex+uiReadIndex])
1496 if(STATUS_SUCCESS != (*Adapter->fpFlashWriteWithStatusCheck)(Adapter,uiPartOffset+uiIndex+uiReadIndex,&pTempBuff[uiIndex+uiReadIndex]))
1498 Status = STATUS_FAILURE;
1499 goto BeceemFlashBulkWrite_EXIT;
1506 if(OsalMemCompare(ucReadBk,&pTempBuff[uiIndex],MAX_RW_SIZE))
1508 if(STATUS_SUCCESS != (*Adapter->fpFlashWriteWithStatusCheck)(Adapter,uiPartOffset+uiIndex,&pTempBuff[uiIndex]))
1510 Status = STATUS_FAILURE;
1511 goto BeceemFlashBulkWrite_EXIT;
1517 //do_gettimeofday(&twv);
1518 //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));
1523 BcmRestoreBlockProtectStatus(Adapter,ulStatus);
1527 uiCurrSectOffsetAddr = 0;
1528 uiSectAlignAddr = uiSectBoundary;
1529 uiSectBoundary += Adapter->uiSectorSize;
1530 uiOffsetFromSectStart += Adapter->uiSectorSize;
1531 uiNumSectTobeRead--;
1533 //do_gettimeofday(&tv2);
1534 //BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Time after Write :%ld ms\n",(tv2.tv_sec *1000 + tv2.tv_usec/1000));
1535 //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));
1539 BeceemFlashBulkWrite_EXIT:
1542 BcmRestoreBlockProtectStatus(Adapter,ulStatus);
1546 OsalMemFree(pTempBuff,Adapter->uiSectorSize);
1549 Adapter->SelectedChip = RESET_CHIP_SELECT;
1554 //-----------------------------------------------------------------------------
1555 // Procedure: BeceemFlashBulkWriteStatus
1557 // Description: Writes to Flash. Checks the SPI status after each write.
1560 // Adapter - ptr to Adapter object instance
1561 // pBuffer - Data to be written.
1562 // uiOffset - Offset of the flash where data needs to be written to.
1563 // uiNumBytes - Number of bytes to be written.
1564 // bVerify - read verify flag.
1568 //-----------------------------------------------------------------------------
1570 static INT BeceemFlashBulkWriteStatus(
1571 PMINI_ADAPTER Adapter,
1577 PCHAR pTempBuff = NULL;
1578 PUCHAR pcBuffer = (PUCHAR)pBuffer;
1580 UINT uiOffsetFromSectStart = 0;
1581 UINT uiSectAlignAddr = 0;
1582 UINT uiCurrSectOffsetAddr = 0;
1583 UINT uiSectBoundary = 0;
1584 UINT uiNumSectTobeRead = 0;
1585 UCHAR ucReadBk[16] = {0};
1587 UINT Status = STATUS_SUCCESS;
1590 UINT uiPartOffset = 0;
1592 uiOffsetFromSectStart = uiOffset & ~(Adapter->uiSectorSize - 1);
1594 //uiOffset += Adapter->ulFlashCalStart;
1595 //Adding flash Base address
1596 // uiOffset = uiOffset + GetFlashBaseAddr(Adapter);
1598 uiSectAlignAddr = uiOffset & ~(Adapter->uiSectorSize - 1);
1599 uiCurrSectOffsetAddr = uiOffset & (Adapter->uiSectorSize - 1);
1600 uiSectBoundary = uiSectAlignAddr + Adapter->uiSectorSize;
1604 // pTempBuff = OsalMemAlloc(MAX_SECTOR_SIZE,'!MVN');
1605 pTempBuff = OsalMemAlloc(Adapter->uiSectorSize,"!MVN");
1606 if(NULL == pTempBuff)
1608 goto BeceemFlashBulkWriteStatus_EXIT;
1611 // check if the data to be written is overlapped accross sectors
1613 if(uiOffset+uiNumBytes < uiSectBoundary)
1615 uiNumSectTobeRead = 1;
1619 // Number of sectors = Last sector start address/First sector start address
1620 uiNumSectTobeRead = (uiCurrSectOffsetAddr+uiNumBytes)/Adapter->uiSectorSize;
1621 if((uiCurrSectOffsetAddr+uiNumBytes)%Adapter->uiSectorSize)
1623 uiNumSectTobeRead++;
1627 if(IsFlash2x(Adapter) && (Adapter->bAllDSDWriteAllow == FALSE))
1630 uiTemp = uiNumSectTobeRead ;
1633 if(IsOffsetWritable(Adapter,uiOffsetFromSectStart + index * Adapter->uiSectorSize ) == FALSE)
1635 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Sector Starting at offset <0X%x> is not writable",
1636 (uiOffsetFromSectStart + index * Adapter->uiSectorSize));
1637 Status = SECTOR_IS_NOT_WRITABLE;
1638 goto BeceemFlashBulkWriteStatus_EXIT;
1640 uiTemp = uiTemp - 1;
1645 Adapter->SelectedChip = RESET_CHIP_SELECT;
1646 while(uiNumSectTobeRead)
1648 uiPartOffset = (uiSectAlignAddr & (FLASH_PART_SIZE - 1)) + GetFlashBaseAddr(Adapter);
1650 BcmDoChipSelect(Adapter,uiSectAlignAddr);
1651 if(0 != BeceemFlashBulkRead(Adapter,
1653 uiOffsetFromSectStart,
1654 Adapter->uiSectorSize))
1657 goto BeceemFlashBulkWriteStatus_EXIT;
1660 ulStatus = BcmFlashUnProtectBlock(Adapter,uiOffsetFromSectStart,Adapter->uiSectorSize);
1662 if(uiNumSectTobeRead > 1)
1665 OsalMemMove(&pTempBuff[uiCurrSectOffsetAddr],pcBuffer,uiSectBoundary-(uiSectAlignAddr+uiCurrSectOffsetAddr));
1666 pcBuffer += ((uiSectBoundary-(uiSectAlignAddr+uiCurrSectOffsetAddr)));
1667 uiNumBytes -= (uiSectBoundary-(uiSectAlignAddr+uiCurrSectOffsetAddr));
1671 OsalMemMove(&pTempBuff[uiCurrSectOffsetAddr],pcBuffer,uiNumBytes);
1674 if(IsFlash2x(Adapter))
1676 SaveHeaderIfPresent(Adapter,(PUCHAR)pTempBuff,uiOffsetFromSectStart);
1679 FlashSectorErase(Adapter,uiPartOffset,1);
1681 for(uiIndex = 0; uiIndex < Adapter->uiSectorSize; uiIndex +=Adapter->ulFlashWriteSize)
1684 if(Adapter->device_removed)
1687 goto BeceemFlashBulkWriteStatus_EXIT;
1690 if(STATUS_SUCCESS != (*Adapter->fpFlashWriteWithStatusCheck)(Adapter,uiPartOffset+uiIndex,&pTempBuff[uiIndex]))
1693 goto BeceemFlashBulkWriteStatus_EXIT;
1699 for(uiIndex = 0;uiIndex < Adapter->uiSectorSize;uiIndex += MAX_RW_SIZE)
1702 if(0 == BeceemFlashBulkRead(Adapter,uiReadBk,uiOffsetFromSectStart+uiIndex + Adapter->ulFlashCalStart ,MAX_RW_SIZE))
1704 for(uiReadIndex = 0;uiReadIndex < 4; uiReadIndex++)
1706 if(*((PUINT)&pTempBuff[uiIndex+uiReadIndex*4]) != uiReadBk[uiReadIndex])
1709 goto BeceemFlashBulkWriteStatus_EXIT;
1717 if(STATUS_SUCCESS == BeceemFlashBulkRead(Adapter,(PUINT)ucReadBk,uiOffsetFromSectStart+uiIndex,MAX_RW_SIZE))
1719 if(OsalMemCompare(ucReadBk,&pTempBuff[uiIndex],MAX_RW_SIZE))
1721 Status = STATUS_FAILURE;
1722 goto BeceemFlashBulkWriteStatus_EXIT;
1732 BcmRestoreBlockProtectStatus(Adapter,ulStatus);
1736 uiCurrSectOffsetAddr = 0;
1737 uiSectAlignAddr = uiSectBoundary;
1738 uiSectBoundary += Adapter->uiSectorSize;
1739 uiOffsetFromSectStart += Adapter->uiSectorSize;
1740 uiNumSectTobeRead--;
1745 BeceemFlashBulkWriteStatus_EXIT:
1748 BcmRestoreBlockProtectStatus(Adapter,ulStatus);
1752 OsalMemFree(pTempBuff,Adapter->uiSectorSize);
1754 Adapter->SelectedChip = RESET_CHIP_SELECT;
1759 //-----------------------------------------------------------------------------
1760 // Procedure: PropagateCalParamsFromEEPROMToMemory
1762 // Description: Dumps the calibration section of EEPROM to DDR.
1765 // Adapter - ptr to Adapter object instance
1769 //-----------------------------------------------------------------------------
1772 INT PropagateCalParamsFromEEPROMToMemory(PMINI_ADAPTER Adapter)
1774 PCHAR pBuff = OsalMemAlloc(BUFFER_4K,"3MVN");
1775 UINT uiEepromSize = 0;
1777 UINT uiBytesToCopy = 0;
1778 UINT uiCalStartAddr = EEPROM_CALPARAM_START;
1779 UINT uiMemoryLoc = EEPROM_CAL_DATA_INTERNAL_LOC;
1787 if(0 != BeceemEEPROMBulkRead(Adapter,&uiEepromSize,EEPROM_SIZE_OFFSET,4))
1790 OsalMemFree(pBuff,BUFFER_4K);
1794 uiEepromSize >>= 16;
1795 if(uiEepromSize > 1024*1024)
1797 OsalMemFree(pBuff,BUFFER_4K);
1802 uiBytesToCopy = MIN(BUFFER_4K,uiEepromSize);
1804 while(uiBytesToCopy)
1806 if(0 != BeceemEEPROMBulkRead(Adapter,(PUINT)pBuff,uiCalStartAddr,uiBytesToCopy))
1811 wrm(Adapter,uiMemoryLoc,(PCHAR)(((PULONG)pBuff)+uiIndex),uiBytesToCopy);
1812 uiMemoryLoc += uiBytesToCopy;
1813 uiEepromSize -= uiBytesToCopy;
1814 uiCalStartAddr += uiBytesToCopy;
1815 uiIndex += uiBytesToCopy/4;
1816 uiBytesToCopy = MIN(BUFFER_4K,uiEepromSize);
1820 wrmalt(Adapter, EEPROM_CAL_DATA_INTERNAL_LOC-4,&value, sizeof(value));
1822 wrmalt(Adapter, EEPROM_CAL_DATA_INTERNAL_LOC-8,&value, sizeof(value));
1823 OsalMemFree(pBuff,MAX_RW_SIZE);
1829 //-----------------------------------------------------------------------------
1830 // Procedure: PropagateCalParamsFromFlashToMemory
1832 // Description: Dumps the calibration section of EEPROM to DDR.
1835 // Adapter - ptr to Adapter object instance
1839 //-----------------------------------------------------------------------------
1841 INT PropagateCalParamsFromFlashToMemory(PMINI_ADAPTER Adapter)
1844 UINT uiEepromSize = 0;
1845 UINT uiBytesToCopy = 0;
1847 UINT uiCalStartAddr = EEPROM_CALPARAM_START;
1848 UINT uiMemoryLoc = EEPROM_CAL_DATA_INTERNAL_LOC;
1852 // Write the signature first. This will ensure firmware does not access EEPROM.
1855 wrmalt(Adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 4, &value, sizeof(value));
1857 wrmalt(Adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 8, &value, sizeof(value));
1859 if(0 != BeceemNVMRead(Adapter,&uiEepromSize,EEPROM_SIZE_OFFSET, 4))
1863 uiEepromSize = ntohl(uiEepromSize);
1864 uiEepromSize >>= 16;
1867 // subtract the auto init section size
1869 uiEepromSize -= EEPROM_CALPARAM_START;
1871 if(uiEepromSize > 1024*1024)
1876 pBuff = OsalMemAlloc(uiEepromSize, 0);
1878 if ( pBuff == NULL )
1883 if(0 != BeceemNVMRead(Adapter,(PUINT)pBuff,uiCalStartAddr, uiEepromSize))
1885 OsalMemFree(pBuff, 0);
1891 uiBytesToCopy = MIN(BUFFER_4K,uiEepromSize);
1893 while(uiBytesToCopy)
1895 Status = wrm(Adapter,uiMemoryLoc,(PCHAR)pPtr,uiBytesToCopy);
1898 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"wrm failed with status :%d",Status);
1902 pPtr += uiBytesToCopy;
1903 uiEepromSize -= uiBytesToCopy;
1904 uiMemoryLoc += uiBytesToCopy;
1905 uiBytesToCopy = MIN(BUFFER_4K,uiEepromSize);
1908 OsalMemFree(pBuff, 0);
1913 //-----------------------------------------------------------------------------
1914 // Procedure: BeceemEEPROMReadBackandVerify
1916 // Description: Read back the data written and verifies.
1919 // Adapter - ptr to Adapter object instance
1920 // pBuffer - Data to be written.
1921 // uiOffset - Offset of the flash where data needs to be written to.
1922 // uiNumBytes - Number of bytes to be written.
1926 //-----------------------------------------------------------------------------
1928 static INT BeceemEEPROMReadBackandVerify(
1929 PMINI_ADAPTER Adapter,
1937 UINT auiData[4] = {0};
1941 if(Adapter->device_removed )
1946 if(uiNumBytes >= MAX_RW_SIZE)
1947 {// for the requests more than or equal to MAX_RW_SIZE bytes, use bulk read function to make the access faster.
1948 BeceemEEPROMBulkRead(Adapter,&auiData[0],uiOffset,MAX_RW_SIZE);
1950 if(OsalMemCompare(&pBuffer[uiIndex],&auiData[0],MAX_RW_SIZE))
1953 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)(pBuffer+uiIndex),uiOffset,MAX_RW_SIZE,FALSE);
1955 BeceemEEPROMBulkRead(Adapter,&auiData[0],uiOffset,MAX_RW_SIZE);
1957 if(OsalMemCompare(&pBuffer[uiIndex],&auiData[0],MAX_RW_SIZE))
1962 uiOffset += MAX_RW_SIZE;
1963 uiNumBytes -= MAX_RW_SIZE;
1967 else if(uiNumBytes >= 4)
1969 BeceemEEPROMBulkRead(Adapter,&uiData,uiOffset,4);
1970 if(uiData != pBuffer[uiIndex])
1973 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)(pBuffer+uiIndex),uiOffset,4,FALSE);
1975 BeceemEEPROMBulkRead(Adapter,&uiData,uiOffset,4);
1976 if(uiData != pBuffer[uiIndex])
1987 { // Handle the reads less than 4 bytes...
1989 OsalMemMove(&uiData,((PUCHAR)pBuffer)+(uiIndex*sizeof(UINT)),uiNumBytes);
1990 BeceemEEPROMBulkRead(Adapter,&uiRdbk,uiOffset,4);
1992 if(memcmp(&uiData, &uiRdbk, uiNumBytes))
2003 static VOID BcmSwapWord(UINT *ptr1) {
2005 UINT tempval = (UINT)*ptr1;
2006 char *ptr2 = (char *)&tempval;
2007 char *ptr = (char *)ptr1;
2015 //-----------------------------------------------------------------------------
2016 // Procedure: BeceemEEPROMWritePage
2018 // Description: Performs page write (16bytes) to the EEPROM
2021 // Adapter - ptr to Adapter object instance
2022 // uiData - Data to be written.
2023 // uiOffset - Offset of the EEPROM where data needs to be written to.
2027 //-----------------------------------------------------------------------------
2028 static INT BeceemEEPROMWritePage( PMINI_ADAPTER Adapter, UINT uiData[], UINT uiOffset )
2030 UINT uiRetries = MAX_EEPROM_RETRIES*RETRIES_PER_DELAY;
2032 UCHAR uiEpromStatus = 0;
2035 /* Flush the Write/Read/Cmd queues. */
2036 value = ( EEPROM_WRITE_QUEUE_FLUSH | EEPROM_CMD_QUEUE_FLUSH | EEPROM_READ_QUEUE_FLUSH );
2037 wrmalt( Adapter, SPI_FLUSH_REG, &value, sizeof(value));
2039 wrmalt( Adapter, SPI_FLUSH_REG, &value, sizeof(value) );
2041 /* Clear the Empty/Avail/Full bits. After this it has been confirmed
2042 * that the bit was cleared by reading back the register. See NOTE below.
2043 * We also clear the Read queues as we do a EEPROM status register read
2045 value = ( EEPROM_WRITE_QUEUE_EMPTY | EEPROM_WRITE_QUEUE_AVAIL | EEPROM_WRITE_QUEUE_FULL | EEPROM_READ_DATA_AVAIL | EEPROM_READ_DATA_FULL ) ;
2046 wrmalt( Adapter, EEPROM_SPI_Q_STATUS1_REG,&value, sizeof(value));
2049 value = EEPROM_WRITE_ENABLE ;
2050 wrmalt( Adapter, EEPROM_CMDQ_SPI_REG,&value, sizeof(value) );
2052 /* We can write back to back 8bits * 16 into the queue and as we have
2053 * checked for the queue to be empty we can write in a burst. */
2056 BcmSwapWord(&value);
2057 wrm( Adapter, EEPROM_WRITE_DATAQ_REG, (PUCHAR)&value, 4);
2060 BcmSwapWord(&value);
2061 wrm( Adapter, EEPROM_WRITE_DATAQ_REG, (PUCHAR)&value, 4);
2064 BcmSwapWord(&value);
2065 wrm( Adapter, EEPROM_WRITE_DATAQ_REG, (PUCHAR)&value, 4);
2068 BcmSwapWord(&value);
2069 wrm( Adapter, EEPROM_WRITE_DATAQ_REG, (PUCHAR)&value, 4);
2071 /* NOTE : After this write, on readback of EEPROM_SPI_Q_STATUS1_REG
2072 * shows that we see 7 for the EEPROM data write. Which means that
2073 * queue got full, also space is available as well as the queue is empty.
2074 * This may happen in sequence. */
2075 value = EEPROM_16_BYTE_PAGE_WRITE | uiOffset ;
2076 wrmalt( Adapter, EEPROM_CMDQ_SPI_REG, &value, sizeof(value) );
2078 /* Ideally we should loop here without tries and eventually succeed.
2079 * What we are checking if the previous write has completed, and this
2080 * may take time. We should wait till the Empty bit is set. */
2082 rdmalt( Adapter, EEPROM_SPI_Q_STATUS1_REG,&uiStatus, sizeof(uiStatus)) ;
2083 while ( ( uiStatus & EEPROM_WRITE_QUEUE_EMPTY ) == 0 )
2086 if ( uiRetries == 0 )
2088 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "0x0f003004 = %x, %d retries failed.\n", uiStatus, MAX_EEPROM_RETRIES *RETRIES_PER_DELAY);
2089 return STATUS_FAILURE ;
2092 if( !(uiRetries%RETRIES_PER_DELAY) )
2096 rdmalt( Adapter, EEPROM_SPI_Q_STATUS1_REG,&uiStatus, sizeof(uiStatus)) ;
2097 if(Adapter->device_removed == TRUE)
2099 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Modem got removed hence exiting from loop....");
2105 if ( uiRetries != 0 )
2107 /* Clear the ones that are set - either, Empty/Full/Avail bits */
2108 value = ( uiStatus & ( EEPROM_WRITE_QUEUE_EMPTY | EEPROM_WRITE_QUEUE_AVAIL | EEPROM_WRITE_QUEUE_FULL ) );
2109 wrmalt( Adapter, EEPROM_SPI_Q_STATUS1_REG, &value, sizeof(value));
2112 /* Here we should check if the EEPROM status register is correct before
2113 * proceeding. Bit 0 in the EEPROM Status register should be 0 before
2114 * we proceed further. A 1 at Bit 0 indicates that the EEPROM is busy
2115 * with the previous write. Note also that issuing this read finally
2116 * means the previous write to the EEPROM has completed. */
2117 uiRetries = MAX_EEPROM_RETRIES*RETRIES_PER_DELAY;
2119 while ( uiRetries != 0 )
2121 uiEpromStatus = ReadEEPROMStatusRegister( Adapter) ;
2122 if(Adapter->device_removed == TRUE)
2124 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Modem has got removed hence exiting from loop...");
2127 if ( ( EEPROM_STATUS_REG_WRITE_BUSY & uiEpromStatus ) == 0 )
2129 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "EEPROM status register = %x tries = %d\n", uiEpromStatus, (MAX_EEPROM_RETRIES * RETRIES_PER_DELAY- uiRetries) );
2130 return STATUS_SUCCESS ;
2133 if ( uiRetries == 0 )
2135 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);
2136 return STATUS_FAILURE ;
2139 if( !(uiRetries%RETRIES_PER_DELAY) )
2143 return STATUS_SUCCESS ;
2144 } /* BeceemEEPROMWritePage */
2147 //-----------------------------------------------------------------------------
2148 // Procedure: BeceemEEPROMBulkWrite
2150 // Description: Performs write to the EEPROM
2153 // Adapter - ptr to Adapter object instance
2154 // pBuffer - Data to be written.
2155 // uiOffset - Offset of the EEPROM where data needs to be written to.
2156 // uiNumBytes - Number of bytes to be written.
2157 // bVerify - read verify flag.
2161 //-----------------------------------------------------------------------------
2163 INT BeceemEEPROMBulkWrite(
2164 PMINI_ADAPTER Adapter,
2170 UINT uiBytesToCopy = uiNumBytes;
2172 UINT uiData[4] = {0};
2174 UINT uiTempOffset = 0;
2175 UINT uiExtraBytes = 0;
2176 //PUINT puiBuffer = (PUINT)pBuffer;
2179 if(uiOffset%MAX_RW_SIZE && uiBytesToCopy)
2181 uiTempOffset = uiOffset - (uiOffset%MAX_RW_SIZE);
2182 uiExtraBytes = uiOffset-uiTempOffset;
2185 BeceemEEPROMBulkRead(Adapter,&uiData[0],uiTempOffset,MAX_RW_SIZE);
2187 if(uiBytesToCopy >= (16 -uiExtraBytes))
2189 OsalMemMove((((PUCHAR)&uiData[0])+uiExtraBytes),pBuffer,MAX_RW_SIZE- uiExtraBytes);
2191 if ( STATUS_FAILURE == BeceemEEPROMWritePage( Adapter, uiData, uiTempOffset ) )
2192 return STATUS_FAILURE;
2194 uiBytesToCopy -= (MAX_RW_SIZE - uiExtraBytes);
2195 uiIndex += (MAX_RW_SIZE - uiExtraBytes);
2196 uiOffset += (MAX_RW_SIZE - uiExtraBytes);
2200 OsalMemMove((((PUCHAR)&uiData[0])+uiExtraBytes),pBuffer,uiBytesToCopy);
2202 if ( STATUS_FAILURE == BeceemEEPROMWritePage( Adapter, uiData, uiTempOffset ) )
2203 return STATUS_FAILURE;
2205 uiIndex += uiBytesToCopy;
2206 uiOffset += uiBytesToCopy;
2213 while(uiBytesToCopy)
2215 if(Adapter->device_removed)
2220 if(uiBytesToCopy >= MAX_RW_SIZE)
2223 if (STATUS_FAILURE == BeceemEEPROMWritePage( Adapter, (PUINT) &pBuffer[uiIndex], uiOffset ) )
2224 return STATUS_FAILURE;
2226 uiIndex += MAX_RW_SIZE;
2227 uiOffset += MAX_RW_SIZE;
2228 uiBytesToCopy -= MAX_RW_SIZE;
2233 // To program non 16byte aligned data, read 16byte and then update.
2235 BeceemEEPROMBulkRead(Adapter,&uiData[0],uiOffset,16);
2236 OsalMemMove(&uiData[0],pBuffer+uiIndex,uiBytesToCopy);
2239 if ( STATUS_FAILURE == BeceemEEPROMWritePage( Adapter, uiData, uiOffset ) )
2240 return STATUS_FAILURE;
2249 //-----------------------------------------------------------------------------
2250 // Procedure: BeceemNVMRead
2252 // Description: Reads n number of bytes from NVM.
2255 // Adapter - ptr to Adapter object instance
2256 // pBuffer - Buffer to store the data read from NVM
2257 // uiOffset - Offset of NVM from where data should be read
2258 // uiNumBytes - Number of bytes to be read from the NVM.
2261 // OSAL_STATUS_SUCCESS - if NVM read is successfull.
2262 // <FAILURE> - if failed.
2263 //-----------------------------------------------------------------------------
2266 PMINI_ADAPTER Adapter,
2272 #if !defined(BCM_SHM_INTERFACE) || defined(FLASH_DIRECT_ACCESS)
2273 UINT uiTemp = 0, value;
2276 if(Adapter->eNVMType == NVM_FLASH)
2278 if(Adapter->bFlashRawRead == FALSE)
2280 if (IsSectionExistInVendorInfo(Adapter,Adapter->eActiveDSD))
2281 return vendorextnReadSection(Adapter,(PUCHAR)pBuffer,Adapter->eActiveDSD,uiOffset,uiNumBytes);
2282 uiOffset = uiOffset+ Adapter->ulFlashCalStart ;
2284 #if defined(BCM_SHM_INTERFACE) && !defined(FLASH_DIRECT_ACCESS)
2285 Status = bcmflash_raw_read((uiOffset/FLASH_PART_SIZE),(uiOffset % FLASH_PART_SIZE),( unsigned char *)pBuffer,uiNumBytes);
2288 rdmalt(Adapter, 0x0f000C80, &uiTemp, sizeof(uiTemp));
2290 wrmalt(Adapter, 0x0f000C80,&value, sizeof(value));
2291 Status = BeceemFlashBulkRead(Adapter,
2295 wrmalt(Adapter, 0x0f000C80, &uiTemp, sizeof(uiTemp));
2298 else if(Adapter->eNVMType == NVM_EEPROM)
2300 Status = BeceemEEPROMBulkRead(Adapter,
2312 //-----------------------------------------------------------------------------
2313 // Procedure: BeceemNVMWrite
2315 // Description: Writes n number of bytes to NVM.
2318 // Adapter - ptr to Adapter object instance
2319 // pBuffer - Buffer contains the data to be written.
2320 // uiOffset - Offset of NVM where data to be written to.
2321 // uiNumBytes - Number of bytes to be written..
2324 // OSAL_STATUS_SUCCESS - if NVM write is successfull.
2325 // <FAILURE> - if failed.
2326 //-----------------------------------------------------------------------------
2329 PMINI_ADAPTER Adapter,
2337 UINT uiMemoryLoc = EEPROM_CAL_DATA_INTERNAL_LOC;
2339 #if !defined(BCM_SHM_INTERFACE) || defined(FLASH_DIRECT_ACCESS)
2342 UINT uiFlashOffset = 0;
2344 if(Adapter->eNVMType == NVM_FLASH)
2346 if (IsSectionExistInVendorInfo(Adapter,Adapter->eActiveDSD))
2347 Status = vendorextnWriteSection(Adapter,(PUCHAR)pBuffer,Adapter->eActiveDSD,uiOffset,uiNumBytes,bVerify);
2350 uiFlashOffset = uiOffset + Adapter->ulFlashCalStart;
2352 #if defined(BCM_SHM_INTERFACE) && !defined(FLASH_DIRECT_ACCESS)
2353 Status = bcmflash_raw_write((uiFlashOffset/FLASH_PART_SIZE), (uiFlashOffset % FLASH_PART_SIZE), (unsigned char *)pBuffer,uiNumBytes);
2355 rdmalt(Adapter, 0x0f000C80, &uiTemp, sizeof(uiTemp));
2357 wrmalt(Adapter, 0x0f000C80, &value, sizeof(value));
2359 if(Adapter->bStatusWrite == TRUE)
2361 Status = BeceemFlashBulkWriteStatus(Adapter,
2370 Status = BeceemFlashBulkWrite(Adapter,
2380 if(uiOffset >= EEPROM_CALPARAM_START)
2382 uiMemoryLoc += (uiOffset - EEPROM_CALPARAM_START);
2385 if(uiNumBytes > BUFFER_4K)
2387 wrm(Adapter,(uiMemoryLoc+uiIndex),(PCHAR)(pBuffer+(uiIndex/4)),BUFFER_4K);
2388 uiNumBytes -= BUFFER_4K;
2389 uiIndex += BUFFER_4K;
2393 wrm(Adapter,uiMemoryLoc+uiIndex,(PCHAR)(pBuffer+(uiIndex/4)),uiNumBytes);
2401 if((uiOffset+uiNumBytes) > EEPROM_CALPARAM_START)
2403 ULONG ulBytesTobeSkipped = 0;
2404 PUCHAR pcBuffer = (PUCHAR)pBuffer;// char pointer to take care of odd byte cases.
2405 uiNumBytes -= (EEPROM_CALPARAM_START - uiOffset);
2406 ulBytesTobeSkipped += (EEPROM_CALPARAM_START - uiOffset);
2407 uiOffset += (EEPROM_CALPARAM_START - uiOffset);
2410 if(uiNumBytes > BUFFER_4K)
2412 wrm(Adapter,uiMemoryLoc+uiIndex,(PCHAR )&pcBuffer[ulBytesTobeSkipped+uiIndex],BUFFER_4K);
2413 uiNumBytes -= BUFFER_4K;
2414 uiIndex += BUFFER_4K;
2418 wrm(Adapter,uiMemoryLoc+uiIndex,(PCHAR)&pcBuffer[ulBytesTobeSkipped+uiIndex],uiNumBytes);
2427 // restore the values.
2428 wrmalt(Adapter,0x0f000C80,&uiTemp, sizeof(uiTemp));
2430 else if(Adapter->eNVMType == NVM_EEPROM)
2432 Status = BeceemEEPROMBulkWrite(Adapter,
2439 Status = BeceemEEPROMReadBackandVerify(Adapter,(PUINT)pBuffer,uiOffset,uiNumBytes);
2449 //-----------------------------------------------------------------------------
2450 // Procedure: BcmUpdateSectorSize
2452 // Description: Updates the sector size to FLASH.
2455 // Adapter - ptr to Adapter object instance
2456 // uiSectorSize - sector size
2459 // OSAL_STATUS_SUCCESS - if NVM write is successfull.
2460 // <FAILURE> - if failed.
2461 //-----------------------------------------------------------------------------
2463 INT BcmUpdateSectorSize(PMINI_ADAPTER Adapter,UINT uiSectorSize)
2466 FLASH_CS_INFO sFlashCsInfo = {0};
2469 UINT uiSectorSig = 0;
2470 UINT uiCurrentSectorSize = 0;
2476 rdmalt(Adapter, 0x0f000C80, &uiTemp, sizeof(uiTemp));
2478 wrmalt(Adapter, 0x0f000C80,&value, sizeof(value));
2481 // Before updating the sector size in the reserved area, check if already present.
2483 BeceemFlashBulkRead(Adapter,(PUINT)&sFlashCsInfo,Adapter->ulFlashControlSectionStart,sizeof(sFlashCsInfo));
2484 uiSectorSig = ntohl(sFlashCsInfo.FlashSectorSizeSig);
2485 uiCurrentSectorSize = ntohl(sFlashCsInfo.FlashSectorSize);
2487 if(uiSectorSig == FLASH_SECTOR_SIZE_SIG)
2490 if((uiCurrentSectorSize <= MAX_SECTOR_SIZE) && (uiCurrentSectorSize >= MIN_SECTOR_SIZE))
2492 if(uiSectorSize == uiCurrentSectorSize)
2494 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Provided sector size is same as programmed in Flash");
2495 Status = STATUS_SUCCESS;
2501 if((uiSectorSize <= MAX_SECTOR_SIZE) && (uiSectorSize >= MIN_SECTOR_SIZE))
2504 sFlashCsInfo.FlashSectorSize = htonl(uiSectorSize);
2505 sFlashCsInfo.FlashSectorSizeSig = htonl(FLASH_SECTOR_SIZE_SIG);
2507 Status = BeceemFlashBulkWrite(Adapter,
2508 (PUINT)&sFlashCsInfo,
2509 Adapter->ulFlashControlSectionStart,
2510 sizeof(sFlashCsInfo),
2517 // restore the values.
2518 wrmalt(Adapter, 0x0f000C80,&uiTemp, sizeof(uiTemp));
2525 //-----------------------------------------------------------------------------
2526 // Procedure: BcmGetFlashSectorSize
2528 // Description: Finds the sector size of the FLASH.
2531 // Adapter - ptr to Adapter object instance
2534 // UINT - sector size.
2536 //-----------------------------------------------------------------------------
2538 UINT BcmGetFlashSectorSize(PMINI_ADAPTER Adapter, UINT FlashSectorSizeSig, UINT FlashSectorSize)
2540 UINT uiSectorSize = 0;
2541 UINT uiSectorSig = 0;
2543 if(Adapter->bSectorSizeOverride &&
2544 (Adapter->uiSectorSizeInCFG <= MAX_SECTOR_SIZE &&
2545 Adapter->uiSectorSizeInCFG >= MIN_SECTOR_SIZE))
2547 Adapter->uiSectorSize = Adapter->uiSectorSizeInCFG;
2552 uiSectorSig = FlashSectorSizeSig;
2554 if(uiSectorSig == FLASH_SECTOR_SIZE_SIG)
2556 uiSectorSize = FlashSectorSize;
2558 // If the sector size stored in the FLASH makes sense then use it.
2560 if(uiSectorSize <= MAX_SECTOR_SIZE && uiSectorSize >= MIN_SECTOR_SIZE)
2562 Adapter->uiSectorSize = uiSectorSize;
2564 //No valid size in FLASH, check if Config file has it.
2565 else if(Adapter->uiSectorSizeInCFG <= MAX_SECTOR_SIZE &&
2566 Adapter->uiSectorSizeInCFG >= MIN_SECTOR_SIZE)
2568 Adapter->uiSectorSize = Adapter->uiSectorSizeInCFG;
2570 // Init to Default, if none of the above works.
2573 Adapter->uiSectorSize = DEFAULT_SECTOR_SIZE;
2579 if(Adapter->uiSectorSizeInCFG <= MAX_SECTOR_SIZE &&
2580 Adapter->uiSectorSizeInCFG >= MIN_SECTOR_SIZE)
2582 Adapter->uiSectorSize = Adapter->uiSectorSizeInCFG;
2586 Adapter->uiSectorSize = DEFAULT_SECTOR_SIZE;
2591 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Sector size :%x \n", Adapter->uiSectorSize);
2592 return Adapter->uiSectorSize;
2595 //-----------------------------------------------------------------------------
2596 // Procedure: BcmInitEEPROMQueues
2598 // Description: Initialization of EEPROM queues.
2601 // Adapter - ptr to Adapter object instance
2604 // <OSAL_STATUS_CODE>
2605 //-----------------------------------------------------------------------------
2607 static INT BcmInitEEPROMQueues(PMINI_ADAPTER Adapter)
2610 /* CHIP Bug : Clear the Avail bits on the Read queue. The default
2611 * value on this register is supposed to be 0x00001102.
2612 * But we get 0x00001122. */
2613 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Fixing reset value on 0x0f003004 register\n" );
2614 value = EEPROM_READ_DATA_AVAIL;
2615 wrmalt( Adapter, EEPROM_SPI_Q_STATUS1_REG, &value, sizeof(value));
2617 /* Flush the all the EEPROM queues. */
2618 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, " Flushing the queues\n");
2619 value =EEPROM_ALL_QUEUE_FLUSH ;
2620 wrmalt( Adapter, SPI_FLUSH_REG, &value, sizeof(value));
2623 wrmalt( Adapter, SPI_FLUSH_REG, &value, sizeof(value) );
2625 /* Read the EEPROM Status Register. Just to see, no real purpose. */
2626 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "EEPROM Status register value = %x\n", ReadEEPROMStatusRegister(Adapter) );
2628 return STATUS_SUCCESS;
2629 } /* BcmInitEEPROMQueues() */
2631 //-----------------------------------------------------------------------------
2632 // Procedure: BcmInitNVM
2634 // Description: Initialization of NVM, EEPROM size,FLASH size, sector size etc.
2637 // Adapter - ptr to Adapter object instance
2640 // <OSAL_STATUS_CODE>
2641 //-----------------------------------------------------------------------------
2643 INT BcmInitNVM(PMINI_ADAPTER ps_adapter)
2645 #ifdef BCM_SHM_INTERFACE
2646 #ifdef FLASH_DIRECT_ACCESS
2647 unsigned int data,data1,data2 = 1;
2648 wrm(ps_adapter, PAD_SELECT_REGISTER, &data2, 4);
2649 data1 = rdm(ps_adapter,SYS_CFG,&data,4);
2650 data1 = rdm(ps_adapter,SYS_CFG,&data,4);
2651 data2 = (data | 0x80 | 0x8000);
2652 wrm(ps_adapter,SYS_CFG, &data2,4); // over-write as Flash boot mode
2654 ps_adapter->eNVMType = NVM_FLASH;
2656 BcmValidateNvmType(ps_adapter);
2657 BcmInitEEPROMQueues(ps_adapter);
2660 if(ps_adapter->eNVMType == NVM_AUTODETECT)
2662 ps_adapter->eNVMType = BcmGetNvmType(ps_adapter);
2663 if(ps_adapter->eNVMType == NVM_UNKNOWN)
2665 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_PRINTK, 0, 0, "NVM Type is unknown!!\n");
2668 else if(ps_adapter->eNVMType == NVM_FLASH)
2670 BcmGetFlashCSInfo(ps_adapter);
2673 BcmGetNvmSize(ps_adapter);
2675 return STATUS_SUCCESS;
2677 /***************************************************************************/
2678 /*BcmGetNvmSize : set the EEPROM or flash size in Adapter.
2681 * Adapter data structure
2685 /***************************************************************************/
2687 INT BcmGetNvmSize(PMINI_ADAPTER Adapter)
2689 if(Adapter->eNVMType == NVM_EEPROM)
2691 Adapter->uiNVMDSDSize = BcmGetEEPROMSize(Adapter);
2693 else if(Adapter->eNVMType == NVM_FLASH)
2695 Adapter->uiNVMDSDSize = BcmGetFlashSize(Adapter);
2700 //-----------------------------------------------------------------------------
2701 // Procedure: BcmValidateNvm
2703 // Description: Validates the NVM Type option selected against the device
2706 // Adapter - ptr to Adapter object instance
2710 //-----------------------------------------------------------------------------
2711 VOID BcmValidateNvmType(PMINI_ADAPTER Adapter)
2715 // if forcing the FLASH through CFG file, we should ensure device really has a FLASH.
2716 // Accessing the FLASH address without the FLASH being present can cause hang/freeze etc.
2717 // So if NVM_FLASH is selected for older chipsets, change it to AUTODETECT where EEPROM is 1st choice.
2720 if(Adapter->eNVMType == NVM_FLASH &&
2721 Adapter->chip_id < 0xBECE3300)
2723 Adapter->eNVMType = NVM_AUTODETECT;
2726 //-----------------------------------------------------------------------------
2727 // Procedure: BcmReadFlashRDID
2729 // Description: Reads ID from Serial Flash
2732 // Adapter - ptr to Adapter object instance
2736 //-----------------------------------------------------------------------------
2737 static ULONG BcmReadFlashRDID(PMINI_ADAPTER Adapter)
2742 // Read ID Instruction.
2744 value = (FLASH_CMD_READ_ID<<24);
2745 wrmalt(Adapter, FLASH_SPI_CMDQ_REG,&value, sizeof(value));
2750 // Read SPI READQ REG. The output will be WWXXYYZZ.
2751 // The ID is 3Bytes long and is WWXXYY. ZZ needs to be Ignored.
2753 rdmalt(Adapter, FLASH_SPI_READQ_REG,(PUINT)&ulRDID, sizeof(ulRDID));
2755 return (ulRDID >>8);
2760 INT BcmAllocFlashCSStructure(PMINI_ADAPTER psAdapter)
2762 if(psAdapter == NULL)
2764 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_PRINTK, 0, 0, "Adapter structure point is NULL");
2767 psAdapter->psFlashCSInfo = (PFLASH_CS_INFO)kzalloc(sizeof(FLASH_CS_INFO), GFP_KERNEL);
2768 if(psAdapter->psFlashCSInfo == NULL)
2770 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_PRINTK, 0, 0,"Can't Allocate memory for Flash 1.x");
2774 psAdapter->psFlash2xCSInfo = (PFLASH2X_CS_INFO)kzalloc(sizeof(FLASH2X_CS_INFO), GFP_KERNEL);
2775 if(psAdapter->psFlash2xCSInfo == NULL)
2777 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_PRINTK, 0, 0,"Can't Allocate memory for Flash 2.x");
2778 bcm_kfree(psAdapter->psFlashCSInfo);
2782 psAdapter->psFlash2xVendorInfo = (PFLASH2X_VENDORSPECIFIC_INFO)kzalloc(sizeof(FLASH2X_VENDORSPECIFIC_INFO), GFP_KERNEL);
2783 if(psAdapter->psFlash2xVendorInfo == NULL)
2785 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_PRINTK, 0, 0,"Can't Allocate Vendor Info Memory for Flash 2.x");
2786 bcm_kfree(psAdapter->psFlashCSInfo);
2787 bcm_kfree(psAdapter->psFlash2xCSInfo);
2791 return STATUS_SUCCESS;
2794 INT BcmDeAllocFlashCSStructure(PMINI_ADAPTER psAdapter)
2796 if(psAdapter == NULL)
2798 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_PRINTK, 0, 0," Adapter structure point is NULL");
2801 bcm_kfree(psAdapter->psFlashCSInfo);
2802 bcm_kfree(psAdapter->psFlash2xCSInfo);
2803 bcm_kfree(psAdapter->psFlash2xVendorInfo);
2804 return STATUS_SUCCESS ;
2807 static INT BcmDumpFlash2XCSStructure(PFLASH2X_CS_INFO psFlash2xCSInfo,PMINI_ADAPTER Adapter)
2810 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "**********************FLASH2X CS Structure *******************");
2811 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Signature is :%x", (psFlash2xCSInfo->MagicNumber));
2812 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Flash Major Version :%d", MAJOR_VERSION(psFlash2xCSInfo->FlashLayoutVersion));
2813 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Flash Minor Version :%d", MINOR_VERSION(psFlash2xCSInfo->FlashLayoutVersion));
2814 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, " ISOImageMajorVersion:0x%x", (psFlash2xCSInfo->ISOImageVersion));
2815 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "SCSIFirmwareMajorVersion :0x%x", (psFlash2xCSInfo->SCSIFirmwareVersion));
2816 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForPart1ISOImage :0x%x", (psFlash2xCSInfo->OffsetFromZeroForPart1ISOImage));
2817 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForScsiFirmware :0x%x", (psFlash2xCSInfo->OffsetFromZeroForScsiFirmware));
2818 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "SizeOfScsiFirmware :0x%x", (psFlash2xCSInfo->SizeOfScsiFirmware ));
2819 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForPart2ISOImage :0x%x", (psFlash2xCSInfo->OffsetFromZeroForPart2ISOImage));
2820 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForDSDStart :0x%x", (psFlash2xCSInfo->OffsetFromZeroForDSDStart));
2821 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForDSDEnd :0x%x", (psFlash2xCSInfo->OffsetFromZeroForDSDEnd));
2822 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForVSAStart :0x%x", (psFlash2xCSInfo->OffsetFromZeroForVSAStart));
2823 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForVSAEnd :0x%x", (psFlash2xCSInfo->OffsetFromZeroForVSAEnd));
2824 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForControlSectionStart :0x%x", (psFlash2xCSInfo->OffsetFromZeroForControlSectionStart));
2825 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForControlSectionData :0x%x", (psFlash2xCSInfo->OffsetFromZeroForControlSectionData));
2826 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "CDLessInactivityTimeout :0x%x", (psFlash2xCSInfo->CDLessInactivityTimeout));
2827 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "NewImageSignature :0x%x", (psFlash2xCSInfo->NewImageSignature));
2828 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "FlashSectorSizeSig :0x%x", (psFlash2xCSInfo->FlashSectorSizeSig));
2829 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "FlashSectorSize :0x%x", (psFlash2xCSInfo->FlashSectorSize));
2830 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "FlashWriteSupportSize :0x%x", (psFlash2xCSInfo->FlashWriteSupportSize));
2831 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "TotalFlashSize :0x%X", (psFlash2xCSInfo->TotalFlashSize));
2832 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "FlashBaseAddr :0x%x", (psFlash2xCSInfo->FlashBaseAddr));
2833 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "FlashPartMaxSize :0x%x", (psFlash2xCSInfo->FlashPartMaxSize));
2834 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "IsCDLessDeviceBootSig :0x%x", (psFlash2xCSInfo->IsCDLessDeviceBootSig));
2835 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "MassStorageTimeout :0x%x", (psFlash2xCSInfo->MassStorageTimeout));
2836 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetISOImage1Part1Start :0x%x", (psFlash2xCSInfo->OffsetISOImage1Part1Start));
2837 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetISOImage1Part1End :0x%x", (psFlash2xCSInfo->OffsetISOImage1Part1End));
2838 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetISOImage1Part2Start :0x%x", (psFlash2xCSInfo->OffsetISOImage1Part2Start));
2839 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetISOImage1Part2End :0x%x", (psFlash2xCSInfo->OffsetISOImage1Part2End));
2840 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetISOImage1Part3Start :0x%x", (psFlash2xCSInfo->OffsetISOImage1Part3Start));
2841 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetISOImage1Part3End :0x%x", (psFlash2xCSInfo->OffsetISOImage1Part3End));
2842 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetISOImage2Part1Start :0x%x", (psFlash2xCSInfo->OffsetISOImage2Part1Start));
2843 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetISOImage2Part1End :0x%x", (psFlash2xCSInfo->OffsetISOImage2Part1End));
2844 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetISOImage2Part2Start :0x%x", (psFlash2xCSInfo->OffsetISOImage2Part2Start));
2845 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetISOImage2Part2End :0x%x", (psFlash2xCSInfo->OffsetISOImage2Part2End));
2846 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetISOImage2Part3Start :0x%x", (psFlash2xCSInfo->OffsetISOImage2Part3Start));
2847 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetISOImage2Part3End :0x%x", (psFlash2xCSInfo->OffsetISOImage2Part3End));
2848 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromDSDStartForDSDHeader :0x%x", (psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader));
2849 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForDSD1Start :0x%x", (psFlash2xCSInfo->OffsetFromZeroForDSD1Start));
2850 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForDSD1End :0x%x", (psFlash2xCSInfo->OffsetFromZeroForDSD1End));
2851 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForDSD2Start :0x%x", (psFlash2xCSInfo->OffsetFromZeroForDSD2Start));
2852 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForDSD2End :0x%x", (psFlash2xCSInfo->OffsetFromZeroForDSD2End));
2853 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForVSA1Start :0x%x", (psFlash2xCSInfo->OffsetFromZeroForVSA1Start));
2854 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForVSA1End :0x%x", (psFlash2xCSInfo->OffsetFromZeroForVSA1End));
2855 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForVSA2Start :0x%x", (psFlash2xCSInfo->OffsetFromZeroForVSA2Start));
2856 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForVSA2End :0x%x", (psFlash2xCSInfo->OffsetFromZeroForVSA2End));
2857 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Sector Access Bit Map is Defined as :");
2858 for(Index =0; Index <(FLASH2X_TOTAL_SIZE/(DEFAULT_SECTOR_SIZE *16)); Index++)
2860 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "SectorAccessBitMap[%d] :0x%x", Index,
2861 (psFlash2xCSInfo->SectorAccessBitMap[Index]));
2864 return STATUS_SUCCESS;
2868 static INT ConvertEndianOf2XCSStructure(PFLASH2X_CS_INFO psFlash2xCSInfo)
2871 psFlash2xCSInfo->MagicNumber = ntohl(psFlash2xCSInfo->MagicNumber);
2872 psFlash2xCSInfo->FlashLayoutVersion= ntohl(psFlash2xCSInfo->FlashLayoutVersion);
2873 //psFlash2xCSInfo->FlashLayoutMinorVersion = ntohs(psFlash2xCSInfo->FlashLayoutMinorVersion);
2874 psFlash2xCSInfo->ISOImageVersion = ntohl(psFlash2xCSInfo->ISOImageVersion);
2875 psFlash2xCSInfo->SCSIFirmwareVersion =ntohl(psFlash2xCSInfo->SCSIFirmwareVersion);
2876 psFlash2xCSInfo->OffsetFromZeroForPart1ISOImage = ntohl(psFlash2xCSInfo->OffsetFromZeroForPart1ISOImage);
2877 psFlash2xCSInfo->OffsetFromZeroForScsiFirmware = ntohl(psFlash2xCSInfo->OffsetFromZeroForScsiFirmware);
2878 psFlash2xCSInfo->SizeOfScsiFirmware = ntohl(psFlash2xCSInfo->SizeOfScsiFirmware );
2879 psFlash2xCSInfo->OffsetFromZeroForPart2ISOImage = ntohl(psFlash2xCSInfo->OffsetFromZeroForPart2ISOImage);
2880 psFlash2xCSInfo->OffsetFromZeroForDSDStart = ntohl(psFlash2xCSInfo->OffsetFromZeroForDSDStart);
2881 psFlash2xCSInfo->OffsetFromZeroForDSDEnd = ntohl(psFlash2xCSInfo->OffsetFromZeroForDSDEnd);
2882 psFlash2xCSInfo->OffsetFromZeroForVSAStart = ntohl(psFlash2xCSInfo->OffsetFromZeroForVSAStart);
2883 psFlash2xCSInfo->OffsetFromZeroForVSAEnd = ntohl(psFlash2xCSInfo->OffsetFromZeroForVSAEnd);
2884 psFlash2xCSInfo->OffsetFromZeroForControlSectionStart = ntohl(psFlash2xCSInfo->OffsetFromZeroForControlSectionStart);
2885 psFlash2xCSInfo->OffsetFromZeroForControlSectionData = ntohl(psFlash2xCSInfo->OffsetFromZeroForControlSectionData);
2886 psFlash2xCSInfo->CDLessInactivityTimeout = ntohl(psFlash2xCSInfo->CDLessInactivityTimeout);
2887 psFlash2xCSInfo->NewImageSignature = ntohl(psFlash2xCSInfo->NewImageSignature);
2888 psFlash2xCSInfo->FlashSectorSizeSig = ntohl(psFlash2xCSInfo->FlashSectorSizeSig);
2889 psFlash2xCSInfo->FlashSectorSize = ntohl(psFlash2xCSInfo->FlashSectorSize);
2890 psFlash2xCSInfo->FlashWriteSupportSize = ntohl(psFlash2xCSInfo->FlashWriteSupportSize);
2891 psFlash2xCSInfo->TotalFlashSize = ntohl(psFlash2xCSInfo->TotalFlashSize);
2892 psFlash2xCSInfo->FlashBaseAddr = ntohl(psFlash2xCSInfo->FlashBaseAddr);
2893 psFlash2xCSInfo->FlashPartMaxSize = ntohl(psFlash2xCSInfo->FlashPartMaxSize);
2894 psFlash2xCSInfo->IsCDLessDeviceBootSig = ntohl(psFlash2xCSInfo->IsCDLessDeviceBootSig);
2895 psFlash2xCSInfo->MassStorageTimeout = ntohl(psFlash2xCSInfo->MassStorageTimeout);
2896 psFlash2xCSInfo->OffsetISOImage1Part1Start = ntohl(psFlash2xCSInfo->OffsetISOImage1Part1Start);
2897 psFlash2xCSInfo->OffsetISOImage1Part1End = ntohl(psFlash2xCSInfo->OffsetISOImage1Part1End);
2898 psFlash2xCSInfo->OffsetISOImage1Part2Start = ntohl(psFlash2xCSInfo->OffsetISOImage1Part2Start);
2899 psFlash2xCSInfo->OffsetISOImage1Part2End = ntohl(psFlash2xCSInfo->OffsetISOImage1Part2End);
2900 psFlash2xCSInfo->OffsetISOImage1Part3Start = ntohl(psFlash2xCSInfo->OffsetISOImage1Part3Start);
2901 psFlash2xCSInfo->OffsetISOImage1Part3End = ntohl(psFlash2xCSInfo->OffsetISOImage1Part3End);
2902 psFlash2xCSInfo->OffsetISOImage2Part1Start = ntohl(psFlash2xCSInfo->OffsetISOImage2Part1Start);
2903 psFlash2xCSInfo->OffsetISOImage2Part1End = ntohl(psFlash2xCSInfo->OffsetISOImage2Part1End);
2904 psFlash2xCSInfo->OffsetISOImage2Part2Start = ntohl(psFlash2xCSInfo->OffsetISOImage2Part2Start);
2905 psFlash2xCSInfo->OffsetISOImage2Part2End = ntohl(psFlash2xCSInfo->OffsetISOImage2Part2End);
2906 psFlash2xCSInfo->OffsetISOImage2Part3Start = ntohl(psFlash2xCSInfo->OffsetISOImage2Part3Start);
2907 psFlash2xCSInfo->OffsetISOImage2Part3End = ntohl(psFlash2xCSInfo->OffsetISOImage2Part3End);
2908 psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader = ntohl(psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader);
2909 psFlash2xCSInfo->OffsetFromZeroForDSD1Start = ntohl(psFlash2xCSInfo->OffsetFromZeroForDSD1Start);
2910 psFlash2xCSInfo->OffsetFromZeroForDSD1End = ntohl(psFlash2xCSInfo->OffsetFromZeroForDSD1End);
2911 psFlash2xCSInfo->OffsetFromZeroForDSD2Start = ntohl(psFlash2xCSInfo->OffsetFromZeroForDSD2Start);
2912 psFlash2xCSInfo->OffsetFromZeroForDSD2End = ntohl(psFlash2xCSInfo->OffsetFromZeroForDSD2End);
2913 psFlash2xCSInfo->OffsetFromZeroForVSA1Start = ntohl(psFlash2xCSInfo->OffsetFromZeroForVSA1Start);
2914 psFlash2xCSInfo->OffsetFromZeroForVSA1End = ntohl(psFlash2xCSInfo->OffsetFromZeroForVSA1End);
2915 psFlash2xCSInfo->OffsetFromZeroForVSA2Start = ntohl(psFlash2xCSInfo->OffsetFromZeroForVSA2Start);
2916 psFlash2xCSInfo->OffsetFromZeroForVSA2End = ntohl(psFlash2xCSInfo->OffsetFromZeroForVSA2End);
2917 for(Index =0; Index <(FLASH2X_TOTAL_SIZE/(DEFAULT_SECTOR_SIZE *16)); Index++)
2919 psFlash2xCSInfo->SectorAccessBitMap[Index] = ntohl(psFlash2xCSInfo->SectorAccessBitMap[Index]);
2921 return STATUS_SUCCESS;
2924 static INT ConvertEndianOfCSStructure(PFLASH_CS_INFO psFlashCSInfo)
2927 psFlashCSInfo->MagicNumber =ntohl(psFlashCSInfo->MagicNumber);
2928 psFlashCSInfo->FlashLayoutVersion =ntohl(psFlashCSInfo->FlashLayoutVersion);
2929 psFlashCSInfo->ISOImageVersion = ntohl(psFlashCSInfo->ISOImageVersion);
2930 //won't convert according to old assumption
2931 psFlashCSInfo->SCSIFirmwareVersion =(psFlashCSInfo->SCSIFirmwareVersion);
2933 psFlashCSInfo->OffsetFromZeroForPart1ISOImage = ntohl(psFlashCSInfo->OffsetFromZeroForPart1ISOImage);
2934 psFlashCSInfo->OffsetFromZeroForScsiFirmware = ntohl(psFlashCSInfo->OffsetFromZeroForScsiFirmware);
2935 psFlashCSInfo->SizeOfScsiFirmware = ntohl(psFlashCSInfo->SizeOfScsiFirmware );
2936 psFlashCSInfo->OffsetFromZeroForPart2ISOImage = ntohl(psFlashCSInfo->OffsetFromZeroForPart2ISOImage);
2937 psFlashCSInfo->OffsetFromZeroForCalibrationStart = ntohl(psFlashCSInfo->OffsetFromZeroForCalibrationStart);
2938 psFlashCSInfo->OffsetFromZeroForCalibrationEnd = ntohl(psFlashCSInfo->OffsetFromZeroForCalibrationEnd);
2939 psFlashCSInfo->OffsetFromZeroForVSAStart = ntohl(psFlashCSInfo->OffsetFromZeroForVSAStart);
2940 psFlashCSInfo->OffsetFromZeroForVSAEnd = ntohl(psFlashCSInfo->OffsetFromZeroForVSAEnd);
2941 psFlashCSInfo->OffsetFromZeroForControlSectionStart = ntohl(psFlashCSInfo->OffsetFromZeroForControlSectionStart);
2942 psFlashCSInfo->OffsetFromZeroForControlSectionData = ntohl(psFlashCSInfo->OffsetFromZeroForControlSectionData);
2943 psFlashCSInfo->CDLessInactivityTimeout = ntohl(psFlashCSInfo->CDLessInactivityTimeout);
2944 psFlashCSInfo->NewImageSignature = ntohl(psFlashCSInfo->NewImageSignature);
2945 psFlashCSInfo->FlashSectorSizeSig = ntohl(psFlashCSInfo->FlashSectorSizeSig);
2946 psFlashCSInfo->FlashSectorSize = ntohl(psFlashCSInfo->FlashSectorSize);
2947 psFlashCSInfo->FlashWriteSupportSize = ntohl(psFlashCSInfo->FlashWriteSupportSize);
2948 psFlashCSInfo->TotalFlashSize = ntohl(psFlashCSInfo->TotalFlashSize);
2949 psFlashCSInfo->FlashBaseAddr = ntohl(psFlashCSInfo->FlashBaseAddr);
2950 psFlashCSInfo->FlashPartMaxSize = ntohl(psFlashCSInfo->FlashPartMaxSize);
2951 psFlashCSInfo->IsCDLessDeviceBootSig = ntohl(psFlashCSInfo->IsCDLessDeviceBootSig);
2952 psFlashCSInfo->MassStorageTimeout = ntohl(psFlashCSInfo->MassStorageTimeout);
2954 return STATUS_SUCCESS;
2957 INT IsSectionExistInVendorInfo(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL section)
2959 return ( Adapter->uiVendorExtnFlag &&
2960 (Adapter->psFlash2xVendorInfo->VendorSection[section].AccessFlags & FLASH2X_SECTION_PRESENT) &&
2961 (Adapter->psFlash2xVendorInfo->VendorSection[section].OffsetFromZeroForSectionStart != UNINIT_PTR_IN_CS) );
2964 static VOID UpdateVendorInfo(PMINI_ADAPTER Adapter)
2967 UINT uiSizeSection = 0;
2969 Adapter->uiVendorExtnFlag = FALSE;
2971 for(i = 0;i < TOTAL_SECTIONS;i++)
2972 Adapter->psFlash2xVendorInfo->VendorSection[i].OffsetFromZeroForSectionStart = UNINIT_PTR_IN_CS;
2974 if(STATUS_SUCCESS != vendorextnGetSectionInfo(Adapter, Adapter->psFlash2xVendorInfo))
2978 while(i < TOTAL_SECTIONS)
2980 if(!(Adapter->psFlash2xVendorInfo->VendorSection[i].AccessFlags & FLASH2X_SECTION_PRESENT))
2986 Adapter->uiVendorExtnFlag = TRUE;
2987 uiSizeSection = (Adapter->psFlash2xVendorInfo->VendorSection[i].OffsetFromZeroForSectionEnd -
2988 Adapter->psFlash2xVendorInfo->VendorSection[i].OffsetFromZeroForSectionStart);
2993 if(( uiSizeSection >= (Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + sizeof(DSD_HEADER))) &&
2994 (UNINIT_PTR_IN_CS != Adapter->psFlash2xVendorInfo->VendorSection[i].OffsetFromZeroForSectionStart))
2995 Adapter->psFlash2xCSInfo->OffsetFromZeroForDSDStart = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSDEnd = VENDOR_PTR_IN_CS;
2997 Adapter->psFlash2xCSInfo->OffsetFromZeroForDSDStart = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSDEnd = UNINIT_PTR_IN_CS;
3001 if(( uiSizeSection >= (Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + sizeof(DSD_HEADER))) &&
3002 (UNINIT_PTR_IN_CS != Adapter->psFlash2xVendorInfo->VendorSection[i].OffsetFromZeroForSectionStart))
3003 Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD1Start = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD1End = VENDOR_PTR_IN_CS;
3005 Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD1Start = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD1End = UNINIT_PTR_IN_CS;
3009 if(( uiSizeSection >= (Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + sizeof(DSD_HEADER))) &&
3010 (UNINIT_PTR_IN_CS != Adapter->psFlash2xVendorInfo->VendorSection[i].OffsetFromZeroForSectionStart))
3011 Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD2Start = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD2End = VENDOR_PTR_IN_CS;
3013 Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD2Start = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD2End = UNINIT_PTR_IN_CS;
3016 if(UNINIT_PTR_IN_CS != Adapter->psFlash2xVendorInfo->VendorSection[i].OffsetFromZeroForSectionStart)
3017 Adapter->psFlash2xCSInfo->OffsetFromZeroForVSAStart = Adapter->psFlash2xCSInfo->OffsetFromZeroForVSAEnd = VENDOR_PTR_IN_CS;
3019 Adapter->psFlash2xCSInfo->OffsetFromZeroForVSAStart = Adapter->psFlash2xCSInfo->OffsetFromZeroForVSAEnd = UNINIT_PTR_IN_CS;
3023 if(UNINIT_PTR_IN_CS != Adapter->psFlash2xVendorInfo->VendorSection[i].OffsetFromZeroForSectionStart)
3024 Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA1Start = Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA1End = VENDOR_PTR_IN_CS;
3026 Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA1Start = Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA1End = UNINIT_PTR_IN_CS;
3029 if(UNINIT_PTR_IN_CS != Adapter->psFlash2xVendorInfo->VendorSection[i].OffsetFromZeroForSectionStart)
3030 Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA2Start = Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA2End = VENDOR_PTR_IN_CS;
3032 Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA2Start = Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA2End = UNINIT_PTR_IN_CS;
3043 //-----------------------------------------------------------------------------
3044 // Procedure: BcmGetFlashCSInfo
3046 // Description: Reads control structure and gets Cal section addresses.
3049 // Adapter - ptr to Adapter object instance
3053 //-----------------------------------------------------------------------------
3055 INT BcmGetFlashCSInfo(PMINI_ADAPTER Adapter)
3057 //FLASH_CS_INFO sFlashCsInfo = {0};
3059 #if !defined(BCM_SHM_INTERFACE) || defined(FLASH_DIRECT_ACCESS)
3062 UINT uiFlashLayoutMajorVersion;
3063 Adapter->uiFlashLayoutMinorVersion = 0;
3064 Adapter->uiFlashLayoutMajorVersion = 0;
3065 Adapter->ulFlashControlSectionStart = FLASH_CS_INFO_START_ADDR;
3068 Adapter->uiFlashBaseAdd = 0;
3069 Adapter->ulFlashCalStart = 0;
3070 memset(Adapter->psFlashCSInfo, 0 ,sizeof(FLASH_CS_INFO));
3071 memset(Adapter->psFlash2xCSInfo, 0 ,sizeof(FLASH2X_CS_INFO));
3073 #ifndef BCM_SHM_INTERFACE
3074 if(!Adapter->bDDRInitDone)
3077 value = FLASH_CONTIGIOUS_START_ADDR_BEFORE_INIT;
3078 wrmalt(Adapter, 0xAF00A080, &value, sizeof(value));
3084 // Reading first 8 Bytes to get the Flash Layout
3085 // MagicNumber(4 bytes) +FlashLayoutMinorVersion(2 Bytes) +FlashLayoutMajorVersion(2 Bytes)
3086 BeceemFlashBulkRead(Adapter,(PUINT)Adapter->psFlashCSInfo,Adapter->ulFlashControlSectionStart,8);
3088 Adapter->psFlashCSInfo->FlashLayoutVersion = ntohl(Adapter->psFlashCSInfo->FlashLayoutVersion);
3089 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Flash Layout Version :%X", (Adapter->psFlashCSInfo->FlashLayoutVersion));
3090 //BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Flash Layout Minor Version :%d\n", ntohs(sFlashCsInfo.FlashLayoutMinorVersion));
3091 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Signature is :%x\n", ntohl(Adapter->psFlashCSInfo->MagicNumber));
3093 if(FLASH_CONTROL_STRUCT_SIGNATURE == ntohl(Adapter->psFlashCSInfo->MagicNumber))
3095 uiFlashLayoutMajorVersion = MAJOR_VERSION((Adapter->psFlashCSInfo->FlashLayoutVersion));
3096 Adapter->uiFlashLayoutMinorVersion = MINOR_VERSION((Adapter->psFlashCSInfo->FlashLayoutVersion));
3100 Adapter->uiFlashLayoutMinorVersion = 0;
3101 uiFlashLayoutMajorVersion = 0;
3104 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"FLASH LAYOUT MAJOR VERSION :%X", uiFlashLayoutMajorVersion);
3106 if(uiFlashLayoutMajorVersion < FLASH_2X_MAJOR_NUMBER)
3108 BeceemFlashBulkRead(Adapter,(PUINT)Adapter->psFlashCSInfo,Adapter->ulFlashControlSectionStart,sizeof(FLASH_CS_INFO));
3109 ConvertEndianOfCSStructure(Adapter->psFlashCSInfo);
3110 Adapter->ulFlashCalStart = (Adapter->psFlashCSInfo->OffsetFromZeroForCalibrationStart);
3112 if(!((Adapter->uiFlashLayoutMajorVersion == 1) && (Adapter->uiFlashLayoutMinorVersion == 1)))
3114 Adapter->ulFlashControlSectionStart = Adapter->psFlashCSInfo->OffsetFromZeroForControlSectionStart;
3117 if((FLASH_CONTROL_STRUCT_SIGNATURE == (Adapter->psFlashCSInfo->MagicNumber)) &&
3118 (SCSI_FIRMWARE_MINOR_VERSION <= MINOR_VERSION(Adapter->psFlashCSInfo->SCSIFirmwareVersion)) &&
3119 (FLASH_SECTOR_SIZE_SIG == (Adapter->psFlashCSInfo->FlashSectorSizeSig)) &&
3120 (BYTE_WRITE_SUPPORT == (Adapter->psFlashCSInfo->FlashWriteSupportSize)))
3122 Adapter->ulFlashWriteSize = (Adapter->psFlashCSInfo->FlashWriteSupportSize);
3123 Adapter->fpFlashWrite = flashByteWrite;
3124 Adapter->fpFlashWriteWithStatusCheck = flashByteWriteStatus;
3128 Adapter->ulFlashWriteSize = MAX_RW_SIZE;
3129 Adapter->fpFlashWrite = flashWrite;
3130 Adapter->fpFlashWriteWithStatusCheck = flashWriteStatus;
3133 BcmGetFlashSectorSize(Adapter, (Adapter->psFlashCSInfo->FlashSectorSizeSig),
3134 (Adapter->psFlashCSInfo->FlashSectorSize));
3137 Adapter->uiFlashBaseAdd = Adapter->psFlashCSInfo->FlashBaseAddr & 0xFCFFFFFF;
3143 if(BcmFlash2xBulkRead(Adapter,(PUINT)Adapter->psFlash2xCSInfo,NO_SECTION_VAL,
3144 Adapter->ulFlashControlSectionStart,sizeof(FLASH2X_CS_INFO)))
3146 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Unable to read CS structure \n");
3147 return STATUS_FAILURE;
3149 ConvertEndianOf2XCSStructure(Adapter->psFlash2xCSInfo);
3150 #ifndef BCM_SHM_INTERFACE
3151 BcmDumpFlash2XCSStructure(Adapter->psFlash2xCSInfo,Adapter);
3153 if((FLASH_CONTROL_STRUCT_SIGNATURE == Adapter->psFlash2xCSInfo->MagicNumber) &&
3154 (SCSI_FIRMWARE_MINOR_VERSION <= MINOR_VERSION(Adapter->psFlash2xCSInfo->SCSIFirmwareVersion)) &&
3155 (FLASH_SECTOR_SIZE_SIG == Adapter->psFlash2xCSInfo->FlashSectorSizeSig) &&
3156 (BYTE_WRITE_SUPPORT == Adapter->psFlash2xCSInfo->FlashWriteSupportSize))
3158 Adapter->ulFlashWriteSize = Adapter->psFlash2xCSInfo->FlashWriteSupportSize;
3159 Adapter->fpFlashWrite = flashByteWrite;
3160 Adapter->fpFlashWriteWithStatusCheck = flashByteWriteStatus;
3164 Adapter->ulFlashWriteSize = MAX_RW_SIZE;
3165 Adapter->fpFlashWrite = flashWrite;
3166 Adapter->fpFlashWriteWithStatusCheck = flashWriteStatus;
3169 BcmGetFlashSectorSize(Adapter, Adapter->psFlash2xCSInfo->FlashSectorSizeSig,
3170 Adapter->psFlash2xCSInfo->FlashSectorSize);
3172 UpdateVendorInfo(Adapter);
3174 BcmGetActiveDSD(Adapter);
3175 BcmGetActiveISO(Adapter);
3176 Adapter->uiFlashBaseAdd = Adapter->psFlash2xCSInfo->FlashBaseAddr & 0xFCFFFFFF;
3177 Adapter->ulFlashControlSectionStart = Adapter->psFlash2xCSInfo->OffsetFromZeroForControlSectionStart;
3181 Concerns: what if CS sector size does not match with this sector size ???
3182 what is the indication of AccessBitMap in CS in flash 2.x ????
3184 #ifndef BCM_SHM_INTERFACE
3185 Adapter->ulFlashID = BcmReadFlashRDID(Adapter);
3188 Adapter->uiFlashLayoutMajorVersion = uiFlashLayoutMajorVersion;
3191 if(FLASH_PART_SST25VF080B == Adapter->ulFlashID)
3194 // 1MB flash has been selected. we have to use 64K as sector size no matter what is kept in FLASH_CS.
3196 Adapter->uiSectorSize = 0x10000;
3200 return STATUS_SUCCESS ;
3204 //-----------------------------------------------------------------------------
3205 // Procedure: BcmGetNvmType
3207 // Description: Finds the type of NVM used.
3210 // Adapter - ptr to Adapter object instance
3215 //-----------------------------------------------------------------------------
3217 NVM_TYPE BcmGetNvmType(PMINI_ADAPTER Adapter)
3221 BeceemEEPROMBulkRead(Adapter,&uiData,0x0,4);
3227 // Read control struct and get cal addresses before accessing the flash
3229 BcmGetFlashCSInfo(Adapter);
3231 BeceemFlashBulkRead(Adapter,&uiData,0x0 + Adapter->ulFlashCalStart,4);
3237 // even if there is no valid signature on EEPROM/FLASH find out if they really exist.
3238 // if exist select it.
3240 if(BcmGetEEPROMSize(Adapter))
3252 * BcmGetSectionValStartOffset - this will calculate the section's starting offset if section val is given
3253 * @Adapter : Drivers Private Data structure
3254 * @eFlashSectionVal : Flash secion value defined in enum FLASH2X_SECTION_VAL
3257 * On success it return the start offset of the provided section val
3258 * On Failure -returns STATUS_FAILURE
3261 INT BcmGetSectionValStartOffset(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL eFlashSectionVal)
3264 * Considering all the section for which end offset can be calculated or directly given
3265 * in CS Structure. if matching case does not exist, return STATUS_FAILURE indicating section
3266 * endoffset can't be calculated or given in CS Stucture.
3269 INT SectStartOffset = 0 ;
3271 SectStartOffset = INVALID_OFFSET ;
3273 if(IsSectionExistInVendorInfo(Adapter,eFlashSectionVal))
3275 return Adapter->psFlash2xVendorInfo->VendorSection[eFlashSectionVal].OffsetFromZeroForSectionStart;
3278 switch(eFlashSectionVal)
3281 if((Adapter->psFlash2xCSInfo->OffsetISOImage1Part1Start != UNINIT_PTR_IN_CS) &&
3282 (IsNonCDLessDevice(Adapter) == FALSE))
3283 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage1Part1Start);
3286 if((Adapter->psFlash2xCSInfo->OffsetISOImage2Part1Start != UNINIT_PTR_IN_CS) &&
3287 (IsNonCDLessDevice(Adapter) == FALSE))
3288 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage2Part1Start);
3291 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForDSDStart != UNINIT_PTR_IN_CS)
3292 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForDSDStart);
3295 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD1Start != UNINIT_PTR_IN_CS)
3296 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD1Start);
3299 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD2Start != UNINIT_PTR_IN_CS)
3300 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD2Start);
3303 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForVSAStart != UNINIT_PTR_IN_CS)
3304 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForVSAStart);
3307 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA1Start != UNINIT_PTR_IN_CS)
3308 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA1Start);
3311 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA2Start != UNINIT_PTR_IN_CS)
3312 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA2Start);
3315 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForScsiFirmware != UNINIT_PTR_IN_CS)
3316 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForScsiFirmware);
3318 case CONTROL_SECTION :
3319 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForControlSectionStart != UNINIT_PTR_IN_CS)
3320 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForControlSectionStart);
3322 case ISO_IMAGE1_PART2 :
3323 if(Adapter->psFlash2xCSInfo->OffsetISOImage1Part2Start != UNINIT_PTR_IN_CS)
3324 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage1Part2Start);
3326 case ISO_IMAGE1_PART3 :
3327 if(Adapter->psFlash2xCSInfo->OffsetISOImage1Part3Start != UNINIT_PTR_IN_CS)
3328 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage1Part3Start);
3330 case ISO_IMAGE2_PART2 :
3331 if(Adapter->psFlash2xCSInfo->OffsetISOImage2Part2Start != UNINIT_PTR_IN_CS)
3332 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage2Part2Start);
3334 case ISO_IMAGE2_PART3 :
3335 if(Adapter->psFlash2xCSInfo->OffsetISOImage2Part3Start != UNINIT_PTR_IN_CS)
3336 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage2Part3Start);
3339 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Section Does not exist in Flash 2.x");
3340 SectStartOffset = INVALID_OFFSET;
3342 return SectStartOffset;
3346 * BcmGetSectionValEndOffset - this will calculate the section's Ending offset if section val is given
3347 * @Adapter : Drivers Private Data structure
3348 * @eFlashSectionVal : Flash secion value defined in enum FLASH2X_SECTION_VAL
3351 * On success it return the end offset of the provided section val
3352 * On Failure -returns STATUS_FAILURE
3355 INT BcmGetSectionValEndOffset(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL eFlash2xSectionVal)
3357 INT SectEndOffset = 0 ;
3358 SectEndOffset = INVALID_OFFSET;
3360 if(IsSectionExistInVendorInfo(Adapter,eFlash2xSectionVal))
3362 return Adapter->psFlash2xVendorInfo->VendorSection[eFlash2xSectionVal].OffsetFromZeroForSectionEnd;
3365 switch(eFlash2xSectionVal)
3368 if((Adapter->psFlash2xCSInfo->OffsetISOImage1Part1End!= UNINIT_PTR_IN_CS) &&
3369 (IsNonCDLessDevice(Adapter) == FALSE))
3370 SectEndOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage1Part1End);
3373 if((Adapter->psFlash2xCSInfo->OffsetISOImage2Part1End!= UNINIT_PTR_IN_CS) &&
3374 (IsNonCDLessDevice(Adapter) == FALSE))
3375 SectEndOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage2Part1End);
3378 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForDSDEnd != UNINIT_PTR_IN_CS)
3379 SectEndOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForDSDEnd);
3382 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD1End != UNINIT_PTR_IN_CS)
3383 SectEndOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD1End);
3386 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD2End != UNINIT_PTR_IN_CS)
3387 SectEndOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD2End);
3390 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForVSAEnd != UNINIT_PTR_IN_CS)
3391 SectEndOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForVSAEnd);
3394 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA1End != UNINIT_PTR_IN_CS)
3395 SectEndOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA1End);
3398 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA2End != UNINIT_PTR_IN_CS)
3399 SectEndOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA2End);
3402 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForScsiFirmware != UNINIT_PTR_IN_CS)
3403 SectEndOffset = ((Adapter->psFlash2xCSInfo->OffsetFromZeroForScsiFirmware) +
3404 (Adapter->psFlash2xCSInfo->SizeOfScsiFirmware));
3406 case CONTROL_SECTION :
3407 //Not Clear So Putting failure. confirm and fix it.
3408 SectEndOffset = STATUS_FAILURE;
3409 case ISO_IMAGE1_PART2 :
3410 if(Adapter->psFlash2xCSInfo->OffsetISOImage1Part2End!= UNINIT_PTR_IN_CS)
3411 SectEndOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage1Part2End);
3413 case ISO_IMAGE1_PART3 :
3414 if(Adapter->psFlash2xCSInfo->OffsetISOImage1Part3End!= UNINIT_PTR_IN_CS)
3415 SectEndOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage1Part3End);
3417 case ISO_IMAGE2_PART2 :
3418 if(Adapter->psFlash2xCSInfo->OffsetISOImage2Part2End != UNINIT_PTR_IN_CS)
3419 SectEndOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage2Part2End);
3421 case ISO_IMAGE2_PART3 :
3422 if(Adapter->psFlash2xCSInfo->OffsetISOImage2Part3End!= UNINIT_PTR_IN_CS)
3423 SectEndOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage2Part3End);
3427 SectEndOffset = INVALID_OFFSET;
3429 return SectEndOffset ;
3433 * BcmFlash2xBulkRead:- Read API for Flash Map 2.x .
3434 * @Adapter :Driver Private Data Structure
3435 * @pBuffer : Buffer where data has to be put after reading
3436 * @eFlashSectionVal :Flash Section Val defined in FLASH2X_SECTION_VAL
3437 * @uiOffsetWithinSectionVal :- Offset with in provided section
3438 * @uiNumBytes : Number of Bytes for Read
3441 * return true on sucess and STATUS_FAILURE on fail.
3444 INT BcmFlash2xBulkRead(
3445 PMINI_ADAPTER Adapter,
3447 FLASH2X_SECTION_VAL eFlash2xSectionVal,
3448 UINT uiOffsetWithinSectionVal,
3452 INT Status = STATUS_SUCCESS;
3453 INT SectionStartOffset = 0;
3454 UINT uiAbsoluteOffset = 0 ;
3455 UINT uiTemp =0, value =0 ;
3458 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Adapter structure is NULL");
3461 if(Adapter->device_removed )
3463 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Device has been removed");
3467 //NO_SECTION_VAL means absolute offset is given.
3468 if(eFlash2xSectionVal == NO_SECTION_VAL)
3469 SectionStartOffset = 0;
3471 SectionStartOffset = BcmGetSectionValStartOffset(Adapter,eFlash2xSectionVal);
3473 if(SectionStartOffset == STATUS_FAILURE )
3475 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"This Section<%d> does not exixt in Flash 2.x Map ",eFlash2xSectionVal);
3479 if(IsSectionExistInVendorInfo(Adapter,eFlash2xSectionVal))
3480 return vendorextnReadSection(Adapter,(PUCHAR)pBuffer, eFlash2xSectionVal, uiOffsetWithinSectionVal, uiNumBytes);
3482 //calculating the absolute offset from FLASH;
3483 uiAbsoluteOffset = uiOffsetWithinSectionVal + SectionStartOffset;
3484 rdmalt(Adapter, 0x0f000C80, &uiTemp, sizeof(uiTemp));
3486 wrmalt(Adapter, 0x0f000C80,&value, sizeof(value));
3488 Status= BeceemFlashBulkRead(Adapter, pBuffer,uiAbsoluteOffset,uiNumBytes) ;
3490 wrmalt(Adapter, 0x0f000C80, &uiTemp, sizeof(uiTemp));
3493 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Flash Read Failed with Status :%d", Status);
3501 * BcmFlash2xBulkWrite :-API for Writing on the Flash Map 2.x.
3502 * @Adapter :Driver Private Data Structure
3503 * @pBuffer : Buffer From where data has to taken for writing
3504 * @eFlashSectionVal :Flash Section Val defined in FLASH2X_SECTION_VAL
3505 * @uiOffsetWithinSectionVal :- Offset with in provided section
3506 * @uiNumBytes : Number of Bytes for Write
3509 * return true on sucess and STATUS_FAILURE on fail.
3513 INT BcmFlash2xBulkWrite(
3514 PMINI_ADAPTER Adapter,
3516 FLASH2X_SECTION_VAL eFlash2xSectVal,
3522 INT Status = STATUS_SUCCESS;
3523 UINT FlashSectValStartOffset = 0;
3524 UINT uiTemp = 0, value = 0;
3527 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Adapter structure is NULL");
3530 if(Adapter->device_removed )
3532 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Device has been removed");
3536 //NO_SECTION_VAL means absolute offset is given.
3537 if(eFlash2xSectVal == NO_SECTION_VAL)
3538 FlashSectValStartOffset = 0;
3540 FlashSectValStartOffset = BcmGetSectionValStartOffset(Adapter,eFlash2xSectVal);
3542 if(FlashSectValStartOffset == STATUS_FAILURE )
3544 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"This Section<%d> does not exixt in Flash Map 2.x",eFlash2xSectVal);
3548 if(IsSectionExistInVendorInfo(Adapter,eFlash2xSectVal))
3549 return vendorextnWriteSection(Adapter, (PUCHAR)pBuffer, eFlash2xSectVal, uiOffset, uiNumBytes, bVerify);
3551 //calculating the absolute offset from FLASH;
3552 uiOffset = uiOffset + FlashSectValStartOffset;
3554 rdmalt(Adapter, 0x0f000C80, &uiTemp, sizeof(uiTemp));
3556 wrmalt(Adapter, 0x0f000C80,&value, sizeof(value));
3558 Status = BeceemFlashBulkWrite(Adapter, pBuffer,uiOffset,uiNumBytes,bVerify);
3560 wrmalt(Adapter, 0x0f000C80, &uiTemp, sizeof(uiTemp));
3563 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Flash Write failed with Status :%d", Status);
3572 * ReadDSDHeader : Read the DSD map for the DSD Section val provided in Argument.
3573 * @Adapter : Beceem Private Data Structure
3574 * @psDSDHeader :Pointer of the buffer where header has to be read
3575 * @dsd :value of the Dyanmic DSD like DSD0 of DSD1 or DSD2
3578 * if suceeds return STATUS_SUCCESS or negative error code.
3580 INT ReadDSDHeader(PMINI_ADAPTER Adapter, PDSD_HEADER psDSDHeader, FLASH2X_SECTION_VAL dsd)
3582 INT Status = STATUS_SUCCESS;
3584 Status =BcmFlash2xBulkRead(Adapter,
3587 Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader,
3588 sizeof(DSD_HEADER));
3589 if(Status == STATUS_SUCCESS)
3591 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "DSDImageMagicNumber :0X%x", ntohl(psDSDHeader->DSDImageMagicNumber));
3592 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "DSDImageSize :0X%x ",ntohl(psDSDHeader->DSDImageSize));
3593 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "DSDImageCRC :0X%x",ntohl(psDSDHeader->DSDImageCRC));
3594 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "DSDImagePriority :0X%x",ntohl(psDSDHeader->DSDImagePriority));
3598 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"DSD Header read is failed with status :%d", Status);
3605 * BcmGetActiveDSD : Set the Active DSD in Adapter Structure which has to be dumped in DDR
3606 * @Adapter :-Drivers private Data Structure
3609 * Return STATUS_SUCESS if get sucess in setting the right DSD else negaive error code
3612 INT BcmGetActiveDSD(PMINI_ADAPTER Adapter)
3614 FLASH2X_SECTION_VAL uiHighestPriDSD = 0 ;
3616 uiHighestPriDSD = getHighestPriDSD(Adapter);
3617 Adapter->eActiveDSD = uiHighestPriDSD;
3619 if(DSD0 == uiHighestPriDSD)
3620 Adapter->ulFlashCalStart = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSDStart;
3621 if(DSD1 == uiHighestPriDSD)
3622 Adapter->ulFlashCalStart = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD1Start;
3623 if(DSD2 == uiHighestPriDSD)
3624 Adapter->ulFlashCalStart = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD2Start;
3625 if(Adapter->eActiveDSD)
3626 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Active DSD :%d", Adapter->eActiveDSD);
3627 if(Adapter->eActiveDSD == 0)
3629 //if No DSD gets Active, Make Active the DSD with WR permission
3630 if(IsSectionWritable(Adapter,DSD2))
3632 Adapter->eActiveDSD = DSD2;
3633 Adapter->ulFlashCalStart = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD2Start;
3635 else if(IsSectionWritable(Adapter,DSD1))
3637 Adapter->eActiveDSD = DSD1;
3638 Adapter->ulFlashCalStart = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD1Start;
3640 else if(IsSectionWritable(Adapter,DSD0))
3642 Adapter->eActiveDSD = DSD0;
3643 Adapter->ulFlashCalStart = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSDStart;
3647 return STATUS_SUCCESS;
3651 * ReadISOUnReservedBytes : Read the ISO map for the ISO Section val provided in Argument.
3652 * @Adapter : Driver Private Data Structure
3653 * @psISOHeader :Pointer of the location where header has to be read
3654 * @IsoImage :value of the Dyanmic ISO like ISO_IMAGE1 of ISO_IMAGE2
3657 * if suceeds return STATUS_SUCCESS or negative error code.
3660 INT ReadISOHeader(PMINI_ADAPTER Adapter, PISO_HEADER psISOHeader, FLASH2X_SECTION_VAL IsoImage)
3662 INT Status = STATUS_SUCCESS;
3664 Status = BcmFlash2xBulkRead(Adapter,
3668 sizeof(ISO_HEADER));
3670 if(Status == STATUS_SUCCESS)
3672 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "ISOImageMagicNumber :0X%x", ntohl(psISOHeader->ISOImageMagicNumber));
3673 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "ISOImageSize :0X%x ",ntohl(psISOHeader->ISOImageSize));
3674 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "ISOImageCRC :0X%x",ntohl(psISOHeader->ISOImageCRC));
3675 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "ISOImagePriority :0X%x",ntohl(psISOHeader->ISOImagePriority));
3679 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "ISO Header Read failed");
3685 * BcmGetActiveISO :- Set the Active ISO in Adapter Data Structue
3686 * @Adapter : Driver private Data Structure
3689 * Sucsess:- STATUS_SUCESS
3690 * Failure- : negative erro code
3694 INT BcmGetActiveISO(PMINI_ADAPTER Adapter)
3697 INT HighestPriISO = 0 ;
3698 HighestPriISO = getHighestPriISO(Adapter);
3700 Adapter->eActiveISO = HighestPriISO ;
3701 if(Adapter->eActiveISO == ISO_IMAGE2)
3702 Adapter->uiActiveISOOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage2Part1Start);
3703 else if(Adapter->eActiveISO == ISO_IMAGE1)
3704 Adapter->uiActiveISOOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage1Part1Start);
3706 if(Adapter->eActiveISO)
3707 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Active ISO :%x", Adapter->eActiveISO);
3709 return STATUS_SUCCESS;
3713 * IsOffsetWritable :- it will tell the access permission of the sector having passed offset
3714 * @Adapter : Drivers Private Data Structure
3715 * @uiOffset : Offset provided in the Flash
3718 * Sucess:-TRUE , offset is writable
3719 * Failure:-FALSE, offset is RO
3722 B_UINT8 IsOffsetWritable(PMINI_ADAPTER Adapter, UINT uiOffset)
3724 UINT uiSectorNum = 0;
3725 UINT uiWordOfSectorPermission =0;
3726 UINT uiBitofSectorePermission = 0;
3727 B_UINT32 permissionBits = 0;
3728 uiSectorNum = uiOffset/Adapter->uiSectorSize;
3730 //calculating the word having this Sector Access permission from SectorAccessBitMap Array
3731 uiWordOfSectorPermission = Adapter->psFlash2xCSInfo->SectorAccessBitMap[uiSectorNum /16];
3733 //calculating the bit index inside the word for this sector
3734 uiBitofSectorePermission = 2*(15 - uiSectorNum %16);
3736 //Setting Access permission
3737 permissionBits = uiWordOfSectorPermission & (0x3 << uiBitofSectorePermission) ;
3738 permissionBits = (permissionBits >> uiBitofSectorePermission) & 0x3;
3739 if(permissionBits == SECTOR_READWRITE_PERMISSION)
3745 static INT BcmDumpFlash2xSectionBitMap(PFLASH2X_BITMAP psFlash2xBitMap)
3747 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(gblpnetdev);
3748 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "***************Flash 2.x Section Bitmap***************");
3749 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"ISO_IMAGE1 :0X%x", psFlash2xBitMap->ISO_IMAGE1);
3750 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"ISO_IMAGE2 :0X%x", psFlash2xBitMap->ISO_IMAGE2);
3751 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"DSD0 :0X%x", psFlash2xBitMap->DSD0);
3752 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"DSD1 :0X%x", psFlash2xBitMap->DSD1);
3753 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"DSD2 :0X%x", psFlash2xBitMap->DSD2);
3754 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"VSA0 :0X%x", psFlash2xBitMap->VSA0);
3755 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"VSA1 :0X%x", psFlash2xBitMap->VSA1);
3756 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"VSA2 :0X%x", psFlash2xBitMap->VSA2);
3757 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"SCSI :0X%x", psFlash2xBitMap->SCSI);
3758 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"CONTROL_SECTION :0X%x", psFlash2xBitMap->CONTROL_SECTION);
3760 return STATUS_SUCCESS;
3764 * BcmGetFlash2xSectionalBitMap :- It will provide the bit map of all the section present in Flash
3765 * 8bit has been assigned to every section.
3766 bit[0] :Section present or not
3767 bit[1] :section is valid or not
3768 bit[2] : Secton is read only or has write permission too.
3769 bit[3] : Active Section -
3770 bit[7...4] = Reserved .
3772 @Adapter:-Driver private Data Structure
3775 * Sucess:- STATUS_SUCESS
3776 * Failure:- negative error code
3779 INT BcmGetFlash2xSectionalBitMap(PMINI_ADAPTER Adapter, PFLASH2X_BITMAP psFlash2xBitMap)
3783 PFLASH2X_CS_INFO psFlash2xCSInfo = Adapter->psFlash2xCSInfo;
3784 FLASH2X_SECTION_VAL uiHighestPriDSD = 0 ;
3785 FLASH2X_SECTION_VAL uiHighestPriISO= 0 ;
3786 BOOLEAN SetActiveDSDDone = FALSE ;
3787 BOOLEAN SetActiveISODone = FALSE ;
3789 //For 1.x map all the section except DSD0 will be shown as not present
3790 //This part will be used by calibration tool to detect the number of DSD present in Flash.
3791 if(IsFlash2x(Adapter) == FALSE)
3793 psFlash2xBitMap->ISO_IMAGE2 = 0;
3794 psFlash2xBitMap->ISO_IMAGE1 = 0;
3795 psFlash2xBitMap->DSD0 = FLASH2X_SECTION_VALID | FLASH2X_SECTION_ACT | FLASH2X_SECTION_PRESENT; //0xF; //0000(Reseved)1(Active)0(RW)1(valid)1(present)
3796 psFlash2xBitMap->DSD1 = 0 ;
3797 psFlash2xBitMap->DSD2 = 0 ;
3798 psFlash2xBitMap->VSA0 = 0 ;
3799 psFlash2xBitMap->VSA1 = 0 ;
3800 psFlash2xBitMap->VSA2 = 0 ;
3801 psFlash2xBitMap->CONTROL_SECTION = 0 ;
3802 psFlash2xBitMap->SCSI= 0 ;
3803 psFlash2xBitMap->Reserved0 = 0 ;
3804 psFlash2xBitMap->Reserved1 = 0 ;
3805 psFlash2xBitMap->Reserved2 = 0 ;
3806 return STATUS_SUCCESS ;
3810 uiHighestPriDSD = getHighestPriDSD(Adapter);
3811 uiHighestPriISO = getHighestPriISO(Adapter);
3816 if((psFlash2xCSInfo->OffsetISOImage2Part1Start) != UNINIT_PTR_IN_CS)
3818 //Setting the 0th Bit representing the Section is present or not.
3819 psFlash2xBitMap->ISO_IMAGE2= psFlash2xBitMap->ISO_IMAGE2 | FLASH2X_SECTION_PRESENT;
3822 if(ReadISOSignature(Adapter,ISO_IMAGE2)== ISO_IMAGE_MAGIC_NUMBER)
3823 psFlash2xBitMap->ISO_IMAGE2 |= FLASH2X_SECTION_VALID;
3826 //Calculation for extrating the Access permission
3827 if(IsSectionWritable(Adapter, ISO_IMAGE2) == FALSE)
3828 psFlash2xBitMap->ISO_IMAGE2 |= FLASH2X_SECTION_RO;
3830 if(SetActiveISODone == FALSE && uiHighestPriISO == ISO_IMAGE2)
3832 psFlash2xBitMap->ISO_IMAGE2 |= FLASH2X_SECTION_ACT ;
3833 SetActiveISODone = TRUE;
3841 if((psFlash2xCSInfo->OffsetISOImage1Part1Start) != UNINIT_PTR_IN_CS)
3843 //Setting the 0th Bit representing the Section is present or not.
3844 psFlash2xBitMap->ISO_IMAGE1 = psFlash2xBitMap->ISO_IMAGE1 | FLASH2X_SECTION_PRESENT;
3846 if(ReadISOSignature(Adapter,ISO_IMAGE1) == ISO_IMAGE_MAGIC_NUMBER)
3847 psFlash2xBitMap->ISO_IMAGE1 |= FLASH2X_SECTION_VALID;
3849 // Calculation for extrating the Access permission
3850 if(IsSectionWritable(Adapter, ISO_IMAGE1) == FALSE)
3851 psFlash2xBitMap->ISO_IMAGE1 |= FLASH2X_SECTION_RO;
3853 if(SetActiveISODone == FALSE && uiHighestPriISO == ISO_IMAGE1)
3855 psFlash2xBitMap->ISO_IMAGE1 |= FLASH2X_SECTION_ACT ;
3856 SetActiveISODone = TRUE;
3865 if((psFlash2xCSInfo->OffsetFromZeroForDSD2Start) != UNINIT_PTR_IN_CS)
3867 //Setting the 0th Bit representing the Section is present or not.
3868 psFlash2xBitMap->DSD2= psFlash2xBitMap->DSD2 | FLASH2X_SECTION_PRESENT;
3870 if(ReadDSDSignature(Adapter,DSD2)== DSD_IMAGE_MAGIC_NUMBER)
3871 psFlash2xBitMap->DSD2 |= FLASH2X_SECTION_VALID;
3873 //Calculation for extrating the Access permission
3874 if(IsSectionWritable(Adapter, DSD2) == FALSE)
3876 psFlash2xBitMap->DSD2 |= FLASH2X_SECTION_RO;
3881 //Means section is writable
3882 if((SetActiveDSDDone == FALSE) && (uiHighestPriDSD == DSD2))
3884 psFlash2xBitMap->DSD2 |= FLASH2X_SECTION_ACT ;
3885 SetActiveDSDDone =TRUE ;
3893 if((psFlash2xCSInfo->OffsetFromZeroForDSD1Start) != UNINIT_PTR_IN_CS)
3895 //Setting the 0th Bit representing the Section is present or not.
3896 psFlash2xBitMap->DSD1= psFlash2xBitMap->DSD1 | FLASH2X_SECTION_PRESENT;
3899 if(ReadDSDSignature(Adapter,DSD1)== DSD_IMAGE_MAGIC_NUMBER)
3900 psFlash2xBitMap->DSD1 |= FLASH2X_SECTION_VALID;
3902 //Calculation for extrating the Access permission
3903 if(IsSectionWritable(Adapter, DSD1) == FALSE)
3905 psFlash2xBitMap->DSD1 |= FLASH2X_SECTION_RO;
3909 //Means section is writable
3910 if((SetActiveDSDDone == FALSE) && (uiHighestPriDSD == DSD1))
3912 psFlash2xBitMap->DSD1 |= FLASH2X_SECTION_ACT ;
3913 SetActiveDSDDone =TRUE ;
3922 if((psFlash2xCSInfo->OffsetFromZeroForDSDStart) != UNINIT_PTR_IN_CS)
3924 //Setting the 0th Bit representing the Section is present or not.
3925 psFlash2xBitMap->DSD0 = psFlash2xBitMap->DSD0 | FLASH2X_SECTION_PRESENT;
3927 if(ReadDSDSignature(Adapter,DSD0) == DSD_IMAGE_MAGIC_NUMBER)
3928 psFlash2xBitMap->DSD0 |= FLASH2X_SECTION_VALID;
3930 //Setting Access permission
3931 if(IsSectionWritable(Adapter, DSD0) == FALSE)
3933 psFlash2xBitMap->DSD0 |= FLASH2X_SECTION_RO;
3937 //Means section is writable
3938 if((SetActiveDSDDone == FALSE) &&(uiHighestPriDSD == DSD0))
3940 psFlash2xBitMap->DSD0 |= FLASH2X_SECTION_ACT ;
3941 SetActiveDSDDone =TRUE ;
3949 if((psFlash2xCSInfo->OffsetFromZeroForVSAStart) != UNINIT_PTR_IN_CS)
3951 //Setting the 0th Bit representing the Section is present or not.
3952 psFlash2xBitMap->VSA0= psFlash2xBitMap->VSA0 | FLASH2X_SECTION_PRESENT;
3954 //Setting the Access Bit. Map is not defined hece setting it always valid
3955 psFlash2xBitMap->VSA0 |= FLASH2X_SECTION_VALID;
3957 //Calculation for extrating the Access permission
3958 if(IsSectionWritable(Adapter, VSA0) == FALSE)
3959 psFlash2xBitMap->VSA0 |= FLASH2X_SECTION_RO;
3961 //By Default section is Active
3962 psFlash2xBitMap->VSA0 |= FLASH2X_SECTION_ACT ;
3971 if((psFlash2xCSInfo->OffsetFromZeroForVSA1Start) != UNINIT_PTR_IN_CS)
3973 //Setting the 0th Bit representing the Section is present or not.
3974 psFlash2xBitMap->VSA1= psFlash2xBitMap->VSA1 | FLASH2X_SECTION_PRESENT;
3976 //Setting the Access Bit. Map is not defined hece setting it always valid
3977 psFlash2xBitMap->VSA1|= FLASH2X_SECTION_VALID;
3979 //Checking For Access permission
3980 if(IsSectionWritable(Adapter, VSA1) == FALSE)
3981 psFlash2xBitMap->VSA1 |= FLASH2X_SECTION_RO;
3983 //By Default section is Active
3984 psFlash2xBitMap->VSA1 |= FLASH2X_SECTION_ACT ;
3993 if((psFlash2xCSInfo->OffsetFromZeroForVSA2Start) != UNINIT_PTR_IN_CS)
3995 //Setting the 0th Bit representing the Section is present or not.
3996 psFlash2xBitMap->VSA2= psFlash2xBitMap->VSA2 | FLASH2X_SECTION_PRESENT;
3999 //Setting the Access Bit. Map is not defined hece setting it always valid
4000 psFlash2xBitMap->VSA2 |= FLASH2X_SECTION_VALID;
4002 //Checking For Access permission
4003 if(IsSectionWritable(Adapter, VSA2) == FALSE)
4004 psFlash2xBitMap->VSA2 |= FLASH2X_SECTION_RO;
4006 //By Default section is Active
4007 psFlash2xBitMap->VSA2 |= FLASH2X_SECTION_ACT ;
4013 if((psFlash2xCSInfo->OffsetFromZeroForScsiFirmware) != UNINIT_PTR_IN_CS)
4015 //Setting the 0th Bit representing the Section is present or not.
4016 psFlash2xBitMap->SCSI= psFlash2xBitMap->SCSI | FLASH2X_SECTION_PRESENT;
4019 //Setting the Access Bit. Map is not defined hece setting it always valid
4020 psFlash2xBitMap->SCSI|= FLASH2X_SECTION_VALID;
4022 //Checking For Access permission
4023 if(IsSectionWritable(Adapter, SCSI) == FALSE)
4024 psFlash2xBitMap->SCSI |= FLASH2X_SECTION_RO;
4026 //By Default section is Active
4027 psFlash2xBitMap->SCSI |= FLASH2X_SECTION_ACT ;
4035 if((psFlash2xCSInfo->OffsetFromZeroForControlSectionStart) != UNINIT_PTR_IN_CS)
4037 //Setting the 0th Bit representing the Section is present or not.
4038 psFlash2xBitMap->CONTROL_SECTION = psFlash2xBitMap->CONTROL_SECTION | (FLASH2X_SECTION_PRESENT);
4041 //Setting the Access Bit. Map is not defined hece setting it always valid
4042 psFlash2xBitMap->CONTROL_SECTION |= FLASH2X_SECTION_VALID;
4044 //Checking For Access permission
4045 if(IsSectionWritable(Adapter, CONTROL_SECTION) == FALSE)
4046 psFlash2xBitMap->CONTROL_SECTION |= FLASH2X_SECTION_RO;
4048 //By Default section is Active
4049 psFlash2xBitMap->CONTROL_SECTION |= FLASH2X_SECTION_ACT ;
4054 // For Reserved Sections
4056 psFlash2xBitMap->Reserved0 = 0;
4057 psFlash2xBitMap->Reserved0 = 0;
4058 psFlash2xBitMap->Reserved0 = 0;
4060 BcmDumpFlash2xSectionBitMap(psFlash2xBitMap);
4062 return STATUS_SUCCESS ;
4066 BcmSetActiveSection :- Set Active section is used to make priority field highest over other
4067 section of same type.
4069 @Adapater :- Bcm Driver Private Data Structure
4070 @eFlash2xSectionVal :- Flash section val whose priority has to be made highest.
4072 Return Value:- Make the priorit highest else return erorr code
4075 INT BcmSetActiveSection(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL eFlash2xSectVal)
4077 unsigned int SectImagePriority = 0;
4078 INT Status =STATUS_SUCCESS;
4080 //DSD_HEADER sDSD = {0};
4081 //ISO_HEADER sISO = {0};
4082 INT HighestPriDSD = 0 ;
4083 INT HighestPriISO = 0;
4087 Status = IsSectionWritable(Adapter,eFlash2xSectVal) ;
4090 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Provided Section <%d> is not writable",eFlash2xSectVal);
4091 return STATUS_FAILURE;
4094 Adapter->bHeaderChangeAllowed = TRUE ;
4095 switch(eFlash2xSectVal)
4099 if(ReadISOSignature(Adapter,eFlash2xSectVal)== ISO_IMAGE_MAGIC_NUMBER )
4101 HighestPriISO = getHighestPriISO(Adapter);
4103 if(HighestPriISO == eFlash2xSectVal )
4105 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Given ISO<%x> already has highest priority",eFlash2xSectVal );
4106 Status = STATUS_SUCCESS ;
4110 SectImagePriority = ReadISOPriority(Adapter, HighestPriISO) + 1;
4112 if((SectImagePriority <= 0) && IsSectionWritable(Adapter,HighestPriISO))
4114 // This is a SPECIAL Case which will only happen if the current highest priority ISO has priority value = 0x7FFFFFFF.
4115 // We will write 1 to the current Highest priority ISO And then shall increase the priority of the requested ISO
4117 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "SectImagePriority wraparound happend, eFlash2xSectVal: 0x%x\n",eFlash2xSectVal);
4118 SectImagePriority = htonl(0x1);
4119 Status = BcmFlash2xBulkWrite(Adapter,
4122 0 + FIELD_OFFSET_IN_HEADER(PISO_HEADER, ISOImagePriority),
4128 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Priority has not been written properly");
4129 Status = STATUS_FAILURE;
4133 HighestPriISO = getHighestPriISO(Adapter);
4135 if(HighestPriISO == eFlash2xSectVal )
4137 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Given ISO<%x> already has highest priority",eFlash2xSectVal );
4138 Status = STATUS_SUCCESS ;
4142 SectImagePriority = 2;
4146 SectImagePriority = htonl(SectImagePriority);
4148 Status = BcmFlash2xBulkWrite(Adapter,
4151 0 + FIELD_OFFSET_IN_HEADER(PISO_HEADER, ISOImagePriority),
4156 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Priority has not been written properly");
4162 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Signature is currupted. Hence can't increase the priority");
4163 Status = STATUS_FAILURE ;
4170 if(ReadDSDSignature(Adapter,eFlash2xSectVal)== DSD_IMAGE_MAGIC_NUMBER)
4172 HighestPriDSD = getHighestPriDSD(Adapter);
4174 if((HighestPriDSD == eFlash2xSectVal))
4176 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Given DSD<%x> already has highest priority", eFlash2xSectVal);
4177 Status = STATUS_SUCCESS ;
4181 SectImagePriority = ReadDSDPriority(Adapter, HighestPriDSD) + 1 ;
4182 if(SectImagePriority <= 0)
4184 // This is a SPECIAL Case which will only happen if the current highest priority DSD has priority value = 0x7FFFFFFF.
4185 // We will write 1 to the current Highest priority DSD And then shall increase the priority of the requested DSD
4187 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, NVM_RW, DBG_LVL_ALL, "SectImagePriority wraparound happend, eFlash2xSectVal: 0x%x\n",eFlash2xSectVal);
4188 SectImagePriority = htonl(0x1);
4190 Status = BcmFlash2xBulkWrite(Adapter,
4193 Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + FIELD_OFFSET_IN_HEADER(PDSD_HEADER, DSDImagePriority),
4199 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Priority has not been written properly");
4203 HighestPriDSD = getHighestPriDSD(Adapter);
4205 if((HighestPriDSD == eFlash2xSectVal))
4207 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Made the DSD: %x highest by reducing priority of other\n", eFlash2xSectVal);
4208 Status = STATUS_SUCCESS ;
4212 SectImagePriority = htonl(0x2);
4213 Status = BcmFlash2xBulkWrite(Adapter,
4216 Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + FIELD_OFFSET_IN_HEADER(PDSD_HEADER, DSDImagePriority),
4222 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Priority has not been written properly");
4226 HighestPriDSD = getHighestPriDSD(Adapter);
4228 if((HighestPriDSD == eFlash2xSectVal))
4230 Status = STATUS_SUCCESS ;
4233 SectImagePriority = 3 ;
4236 SectImagePriority = htonl(SectImagePriority);
4237 Status = BcmFlash2xBulkWrite(Adapter,
4240 Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + FIELD_OFFSET_IN_HEADER(PDSD_HEADER, DSDImagePriority),
4245 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Priority has not been written properly");
4246 Status = STATUS_FAILURE ;
4252 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Signature is currupted. Hence can't increase the priority");
4253 Status = STATUS_FAILURE ;
4263 Status = STATUS_FAILURE ;
4268 Adapter->bHeaderChangeAllowed = FALSE ;
4274 BcmCopyISO - Used only for copying the ISO section
4275 @Adapater :- Bcm Driver Private Data Structure
4276 @sCopySectStrut :- Section copy structure
4278 Return value:- SUCCESS if copies successfully else negative error code
4281 INT BcmCopyISO(PMINI_ADAPTER Adapter, FLASH2X_COPY_SECTION sCopySectStrut)
4285 FLASH2X_SECTION_VAL eISOReadPart = 0,eISOWritePart = 0;
4286 UINT uiReadOffsetWithinPart = 0, uiWriteOffsetWithinPart = 0;
4287 UINT uiTotalDataToCopy = 0;
4288 BOOLEAN IsThisHeaderSector = FALSE ;
4291 UINT Status = STATUS_SUCCESS;
4292 UINT SigBuff[MAX_RW_SIZE];
4295 if(ReadISOSignature(Adapter,sCopySectStrut.SrcSection) != ISO_IMAGE_MAGIC_NUMBER)
4297 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "error as Source ISO Section does not have valid signature");
4298 return STATUS_FAILURE;
4301 Status = BcmFlash2xBulkRead(Adapter,
4303 sCopySectStrut.SrcSection,
4304 0 + FIELD_OFFSET_IN_HEADER(PISO_HEADER,ISOImageSize),
4309 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Read failed while copying ISO\n");
4313 ISOLength = htonl(ISOLength);
4315 if(ISOLength % Adapter->uiSectorSize)
4317 ISOLength = Adapter->uiSectorSize*(1 + ISOLength/Adapter->uiSectorSize);
4320 sigOffset = FIELD_OFFSET_IN_HEADER(PISO_HEADER, ISOImageMagicNumber);
4322 Buff = kzalloc(Adapter->uiSectorSize, GFP_KERNEL);
4326 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Memory allocation failed for section size");
4330 if(sCopySectStrut.SrcSection ==ISO_IMAGE1 && sCopySectStrut.DstSection ==ISO_IMAGE2)
4332 eISOReadPart = ISO_IMAGE1 ;
4333 eISOWritePart = ISO_IMAGE2 ;
4334 uiReadOffsetWithinPart = 0;
4335 uiWriteOffsetWithinPart = 0 ;
4337 uiTotalDataToCopy =(Adapter->psFlash2xCSInfo->OffsetISOImage1Part1End) -
4338 (Adapter->psFlash2xCSInfo->OffsetISOImage1Part1Start)+
4339 (Adapter->psFlash2xCSInfo->OffsetISOImage1Part2End) -
4340 (Adapter->psFlash2xCSInfo->OffsetISOImage1Part2Start)+
4341 (Adapter->psFlash2xCSInfo->OffsetISOImage1Part3End) -
4342 (Adapter->psFlash2xCSInfo->OffsetISOImage1Part3Start);
4344 if(uiTotalDataToCopy < ISOLength)
4346 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"error as Source ISO Section does not have valid signature");
4347 return STATUS_FAILURE;
4350 uiTotalDataToCopy =(Adapter->psFlash2xCSInfo->OffsetISOImage2Part1End) -
4351 (Adapter->psFlash2xCSInfo->OffsetISOImage2Part1Start)+
4352 (Adapter->psFlash2xCSInfo->OffsetISOImage2Part2End) -
4353 (Adapter->psFlash2xCSInfo->OffsetISOImage2Part2Start)+
4354 (Adapter->psFlash2xCSInfo->OffsetISOImage2Part3End) -
4355 (Adapter->psFlash2xCSInfo->OffsetISOImage2Part3Start);
4357 if(uiTotalDataToCopy < ISOLength)
4359 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"error as Dest ISO Section does not have enough section size");
4360 return STATUS_FAILURE;
4363 uiTotalDataToCopy = ISOLength;
4365 CorruptISOSig(Adapter,ISO_IMAGE2);
4367 while(uiTotalDataToCopy)
4369 if(uiTotalDataToCopy == Adapter->uiSectorSize)
4371 //Setting for write of first sector. First sector is assumed to be written in last
4372 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Writing the signature sector");
4373 eISOReadPart = ISO_IMAGE1 ;
4374 uiReadOffsetWithinPart = 0;
4375 eISOWritePart = ISO_IMAGE2;
4376 uiWriteOffsetWithinPart = 0 ;
4377 IsThisHeaderSector = TRUE ;
4382 uiReadOffsetWithinPart = uiReadOffsetWithinPart + Adapter->uiSectorSize ;
4383 uiWriteOffsetWithinPart = uiWriteOffsetWithinPart + Adapter->uiSectorSize ;
4385 if((eISOReadPart == ISO_IMAGE1) && (uiReadOffsetWithinPart == (Adapter->psFlash2xCSInfo->OffsetISOImage1Part1End - Adapter->psFlash2xCSInfo->OffsetISOImage1Part1Start) ))
4387 eISOReadPart = ISO_IMAGE1_PART2 ;
4388 uiReadOffsetWithinPart = 0;
4390 if((eISOReadPart == ISO_IMAGE1_PART2) && (uiReadOffsetWithinPart == (Adapter->psFlash2xCSInfo->OffsetISOImage1Part2End - Adapter->psFlash2xCSInfo->OffsetISOImage1Part2Start)))
4392 eISOReadPart = ISO_IMAGE1_PART3 ;
4393 uiReadOffsetWithinPart = 0;
4395 if((eISOWritePart == ISO_IMAGE2) && (uiWriteOffsetWithinPart == (Adapter->psFlash2xCSInfo->OffsetISOImage2Part1End - Adapter->psFlash2xCSInfo->OffsetISOImage2Part1Start)))
4397 eISOWritePart = ISO_IMAGE2_PART2 ;
4398 uiWriteOffsetWithinPart = 0;
4400 if((eISOWritePart == ISO_IMAGE2_PART2) && (uiWriteOffsetWithinPart == (Adapter->psFlash2xCSInfo->OffsetISOImage2Part2End - Adapter->psFlash2xCSInfo->OffsetISOImage2Part2Start)))
4402 eISOWritePart = ISO_IMAGE2_PART3 ;
4403 uiWriteOffsetWithinPart = 0;
4407 Status = BcmFlash2xBulkRead(Adapter,
4410 uiReadOffsetWithinPart,
4411 Adapter->uiSectorSize
4416 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Read failed while copying ISO: Part: %x, OffsetWithinPart: %x\n", eISOReadPart, uiReadOffsetWithinPart);
4420 if(IsThisHeaderSector == TRUE)
4422 //If this is header sector write 0xFFFFFFFF at the sig time and in last write sig
4423 memcpy(SigBuff, Buff + sigOffset, MAX_RW_SIZE);
4425 for(i = 0; i < MAX_RW_SIZE;i++)
4426 *(Buff + sigOffset + i) = 0xFF;
4428 Adapter->bHeaderChangeAllowed = TRUE ;
4430 Status = BcmFlash2xBulkWrite(Adapter,
4433 uiWriteOffsetWithinPart,
4434 Adapter->uiSectorSize,
4438 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Write failed while copying ISO: Part: %x, OffsetWithinPart: %x\n", eISOWritePart, uiWriteOffsetWithinPart);
4442 Adapter->bHeaderChangeAllowed = FALSE;
4444 if(IsThisHeaderSector == TRUE)
4446 WriteToFlashWithoutSectorErase(Adapter,
4451 IsThisHeaderSector = FALSE ;
4453 //substracting the written Data
4454 uiTotalDataToCopy = uiTotalDataToCopy - Adapter->uiSectorSize ;
4460 if(sCopySectStrut.SrcSection ==ISO_IMAGE2 && sCopySectStrut.DstSection ==ISO_IMAGE1)
4462 eISOReadPart = ISO_IMAGE2 ;
4463 eISOWritePart = ISO_IMAGE1 ;
4464 uiReadOffsetWithinPart = 0;
4465 uiWriteOffsetWithinPart = 0 ;
4467 uiTotalDataToCopy =(Adapter->psFlash2xCSInfo->OffsetISOImage2Part1End) -
4468 (Adapter->psFlash2xCSInfo->OffsetISOImage2Part1Start)+
4469 (Adapter->psFlash2xCSInfo->OffsetISOImage2Part2End) -
4470 (Adapter->psFlash2xCSInfo->OffsetISOImage2Part2Start)+
4471 (Adapter->psFlash2xCSInfo->OffsetISOImage2Part3End) -
4472 (Adapter->psFlash2xCSInfo->OffsetISOImage2Part3Start);
4474 if(uiTotalDataToCopy < ISOLength)
4476 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"error as Source ISO Section does not have valid signature");
4477 return STATUS_FAILURE;
4480 uiTotalDataToCopy =(Adapter->psFlash2xCSInfo->OffsetISOImage1Part1End) -
4481 (Adapter->psFlash2xCSInfo->OffsetISOImage1Part1Start)+
4482 (Adapter->psFlash2xCSInfo->OffsetISOImage1Part2End) -
4483 (Adapter->psFlash2xCSInfo->OffsetISOImage1Part2Start)+
4484 (Adapter->psFlash2xCSInfo->OffsetISOImage1Part3End) -
4485 (Adapter->psFlash2xCSInfo->OffsetISOImage1Part3Start);
4487 if(uiTotalDataToCopy < ISOLength)
4489 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"error as Dest ISO Section does not have enough section size");
4490 return STATUS_FAILURE;
4493 uiTotalDataToCopy = ISOLength;
4495 CorruptISOSig(Adapter,ISO_IMAGE1);
4497 while(uiTotalDataToCopy)
4499 if(uiTotalDataToCopy == Adapter->uiSectorSize)
4501 //Setting for write of first sector. First sector is assumed to be written in last
4502 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Writing the signature sector");
4503 eISOReadPart = ISO_IMAGE2 ;
4504 uiReadOffsetWithinPart = 0;
4505 eISOWritePart = ISO_IMAGE1;
4506 uiWriteOffsetWithinPart = 0 ;
4507 IsThisHeaderSector = TRUE;
4512 uiReadOffsetWithinPart = uiReadOffsetWithinPart + Adapter->uiSectorSize ;
4513 uiWriteOffsetWithinPart = uiWriteOffsetWithinPart + Adapter->uiSectorSize ;
4515 if((eISOReadPart == ISO_IMAGE2) && (uiReadOffsetWithinPart == (Adapter->psFlash2xCSInfo->OffsetISOImage2Part1End - Adapter->psFlash2xCSInfo->OffsetISOImage2Part1Start) ))
4517 eISOReadPart = ISO_IMAGE2_PART2 ;
4518 uiReadOffsetWithinPart = 0;
4520 if((eISOReadPart == ISO_IMAGE2_PART2) && (uiReadOffsetWithinPart == (Adapter->psFlash2xCSInfo->OffsetISOImage2Part2End - Adapter->psFlash2xCSInfo->OffsetISOImage2Part2Start)))
4522 eISOReadPart = ISO_IMAGE2_PART3 ;
4523 uiReadOffsetWithinPart = 0;
4525 if((eISOWritePart == ISO_IMAGE1) && (uiWriteOffsetWithinPart == (Adapter->psFlash2xCSInfo->OffsetISOImage1Part1End - Adapter->psFlash2xCSInfo->OffsetISOImage1Part1Start)))
4527 eISOWritePart = ISO_IMAGE1_PART2 ;
4528 uiWriteOffsetWithinPart = 0;
4530 if((eISOWritePart == ISO_IMAGE1_PART2) && (uiWriteOffsetWithinPart == (Adapter->psFlash2xCSInfo->OffsetISOImage1Part2End - Adapter->psFlash2xCSInfo->OffsetISOImage1Part2Start)))
4532 eISOWritePart = ISO_IMAGE1_PART3 ;
4533 uiWriteOffsetWithinPart = 0;
4537 Status = BcmFlash2xBulkRead(Adapter,
4540 uiReadOffsetWithinPart,
4541 Adapter->uiSectorSize
4545 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Read failed while copying ISO: Part: %x, OffsetWithinPart: %x\n", eISOReadPart, uiReadOffsetWithinPart);
4549 if(IsThisHeaderSector == TRUE)
4551 //If this is header sector write 0xFFFFFFFF at the sig time and in last write sig
4552 memcpy(SigBuff, Buff + sigOffset, MAX_RW_SIZE);
4554 for(i = 0; i < MAX_RW_SIZE;i++)
4555 *(Buff + sigOffset + i) = 0xFF;
4558 Adapter->bHeaderChangeAllowed = TRUE ;
4559 Status = BcmFlash2xBulkWrite(Adapter,
4562 uiWriteOffsetWithinPart,
4563 Adapter->uiSectorSize,
4568 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Write failed while copying ISO: Part: %x, OffsetWithinPart: %x\n", eISOWritePart, uiWriteOffsetWithinPart);
4572 Adapter->bHeaderChangeAllowed = FALSE ;
4574 if(IsThisHeaderSector == TRUE)
4576 WriteToFlashWithoutSectorErase(Adapter,
4581 IsThisHeaderSector = FALSE ;
4584 //substracting the written Data
4585 uiTotalDataToCopy = uiTotalDataToCopy - Adapter->uiSectorSize ;
4596 BcmFlash2xCorruptSig : this API is used to corrupt the written sig in Bcm Header present in flash section.
4597 It will corrupt the sig, if Section is writable, by making first bytes as zero.
4598 @Adapater :- Bcm Driver Private Data Structure
4599 @eFlash2xSectionVal :- Flash section val which has header
4602 Sucess :- If Section is present and writable, corrupt the sig and return STATUS_SUCCESS
4603 Failure :-Return negative error code
4607 INT BcmFlash2xCorruptSig(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL eFlash2xSectionVal)
4610 INT Status = STATUS_SUCCESS ;
4611 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Section Value :%x \n", eFlash2xSectionVal);
4613 if((eFlash2xSectionVal == DSD0) || (eFlash2xSectionVal == DSD1) || (eFlash2xSectionVal == DSD2))
4615 Status = CorruptDSDSig(Adapter, eFlash2xSectionVal);
4617 else if(eFlash2xSectionVal == ISO_IMAGE1 || eFlash2xSectionVal == ISO_IMAGE2)
4619 Status = CorruptISOSig(Adapter, eFlash2xSectionVal);
4623 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Given Section <%d>does not have Header",eFlash2xSectionVal);
4624 return STATUS_SUCCESS;
4629 BcmFlash2xWriteSig :-this API is used to Write the sig if requested Section has
4630 header and Write Permission.
4631 @Adapater :- Bcm Driver Private Data Structure
4632 @eFlashSectionVal :- Flash section val which has header
4635 Sucess :- If Section is present and writable write the sig and return STATUS_SUCCESS
4636 Failure :-Return negative error code
4639 INT BcmFlash2xWriteSig(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL eFlashSectionVal)
4642 UINT uiSignature = 0 ;
4644 //DSD_HEADER dsdHeader = {0};
4646 if(Adapter->bSigCorrupted == FALSE)
4648 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Signature is not corrupted by driver, hence not restoring\n");
4649 return STATUS_SUCCESS;
4651 if(Adapter->bAllDSDWriteAllow == FALSE)
4653 if(IsSectionWritable(Adapter,eFlashSectionVal) == FALSE)
4655 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Section is not Writable...Hence can't Write signature");
4656 return SECTOR_IS_NOT_WRITABLE;
4659 if((eFlashSectionVal == DSD0) ||(eFlashSectionVal == DSD1) || (eFlashSectionVal == DSD2))
4661 uiSignature = htonl(DSD_IMAGE_MAGIC_NUMBER) ;
4662 uiOffset = Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader ;
4664 uiOffset += FIELD_OFFSET_IN_HEADER(PDSD_HEADER,DSDImageMagicNumber);
4666 if((ReadDSDSignature(Adapter,eFlashSectionVal) & 0xFF000000) != CORRUPTED_PATTERN)
4668 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Corrupted Pattern is not there. Hence won't write sig");
4669 return STATUS_FAILURE;
4673 else if((eFlashSectionVal == ISO_IMAGE1) || (eFlashSectionVal == ISO_IMAGE2))
4675 uiSignature = htonl(ISO_IMAGE_MAGIC_NUMBER);
4677 uiOffset = FIELD_OFFSET_IN_HEADER(PISO_HEADER,ISOImageMagicNumber);
4678 if((ReadISOSignature(Adapter,eFlashSectionVal) & 0xFF000000) != CORRUPTED_PATTERN)
4680 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Currupted Pattern is not there. Hence won't write sig");
4681 return STATUS_FAILURE;
4686 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"GIVEN SECTION< %d > IS NOT VALID FOR SIG WRITE...", eFlashSectionVal);
4687 return STATUS_FAILURE;
4690 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Restoring the signature");
4693 Adapter->bHeaderChangeAllowed = TRUE;
4694 Adapter->bSigCorrupted = FALSE;
4695 BcmFlash2xBulkWrite(Adapter, &uiSignature,eFlashSectionVal,uiOffset,SIGNATURE_SIZE,TRUE);
4696 Adapter->bHeaderChangeAllowed = FALSE;
4700 return STATUS_SUCCESS;
4703 validateFlash2xReadWrite :- This API is used to validate the user request for Read/Write.
4704 if requested Bytes goes beyond the Requested section, it reports error.
4705 @Adapater :- Bcm Driver Private Data Structure
4706 @psFlash2xReadWrite :-Flash2x Read/write structure pointer
4708 Return values:-Return TRUE is request is valid else FALSE.
4712 INT validateFlash2xReadWrite(PMINI_ADAPTER Adapter, PFLASH2X_READWRITE psFlash2xReadWrite)
4714 UINT uiNumOfBytes = 0 ;
4715 UINT uiSectStartOffset = 0 ;
4716 UINT uiSectEndOffset = 0;
4717 uiNumOfBytes = psFlash2xReadWrite->numOfBytes;
4719 if(IsSectionExistInFlash(Adapter,psFlash2xReadWrite->Section) != TRUE)
4721 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Section<%x> does not exixt in Flash",psFlash2xReadWrite->Section);
4724 uiSectStartOffset = BcmGetSectionValStartOffset(Adapter,psFlash2xReadWrite->Section);
4725 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Start offset :%x ,section :%d\n",uiSectStartOffset,psFlash2xReadWrite->Section);
4726 if((psFlash2xReadWrite->Section == ISO_IMAGE1) ||(psFlash2xReadWrite->Section == ISO_IMAGE2))
4728 if(psFlash2xReadWrite->Section == ISO_IMAGE1)
4730 uiSectEndOffset = BcmGetSectionValEndOffset(Adapter,ISO_IMAGE1) -
4731 BcmGetSectionValStartOffset(Adapter,ISO_IMAGE1)+
4732 BcmGetSectionValEndOffset(Adapter,ISO_IMAGE1_PART2) -
4733 BcmGetSectionValStartOffset(Adapter,ISO_IMAGE1_PART2)+
4734 BcmGetSectionValEndOffset(Adapter,ISO_IMAGE1_PART3) -
4735 BcmGetSectionValStartOffset(Adapter,ISO_IMAGE1_PART3);
4737 else if(psFlash2xReadWrite->Section == ISO_IMAGE2)
4739 uiSectEndOffset = BcmGetSectionValEndOffset(Adapter,ISO_IMAGE2) -
4740 BcmGetSectionValStartOffset(Adapter,ISO_IMAGE2)+
4741 BcmGetSectionValEndOffset(Adapter,ISO_IMAGE2_PART2) -
4742 BcmGetSectionValStartOffset(Adapter,ISO_IMAGE2_PART2)+
4743 BcmGetSectionValEndOffset(Adapter,ISO_IMAGE2_PART3) -
4744 BcmGetSectionValStartOffset(Adapter,ISO_IMAGE2_PART3);
4748 //since this uiSectEndoffset is the size of iso Image. hence for calculating the vitual endoffset
4749 //it should be added in startoffset. so that check done in last of this function can be valued.
4750 uiSectEndOffset = uiSectStartOffset + uiSectEndOffset ;
4752 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Total size of the ISO Image :%x",uiSectEndOffset);
4755 uiSectEndOffset = BcmGetSectionValEndOffset(Adapter,psFlash2xReadWrite->Section);
4756 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "End offset :%x \n",uiSectEndOffset);
4758 //Checking the boundary condition
4759 if((uiSectStartOffset + psFlash2xReadWrite->offset + uiNumOfBytes) <= uiSectEndOffset)
4763 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Invalid Request....");
4770 IsFlash2x :- check for Flash 2.x
4771 @Adapater :- Bcm Driver Private Data Structure
4774 return TRUE if flah2.x of hgher version else return false.
4777 INT IsFlash2x(PMINI_ADAPTER Adapter)
4779 if(Adapter->uiFlashLayoutMajorVersion >= FLASH_2X_MAJOR_NUMBER)
4785 GetFlashBaseAddr :- Calculate the Flash Base address
4786 @Adapater :- Bcm Driver Private Data Structure
4789 Success :- Base Address of the Flash
4792 INT GetFlashBaseAddr(PMINI_ADAPTER Adapter)
4795 UINT uiBaseAddr = 0;
4797 if(Adapter->bDDRInitDone)
4800 For All Valid Flash Versions... except 1.1, take the value from FlashBaseAddr
4801 In case of Raw Read... use the default value
4803 if(Adapter->uiFlashLayoutMajorVersion && (Adapter->bFlashRawRead == FALSE) &&
4804 !((Adapter->uiFlashLayoutMajorVersion == 1) && (Adapter->uiFlashLayoutMinorVersion == 1))
4806 uiBaseAddr = Adapter->uiFlashBaseAdd ;
4808 uiBaseAddr = FLASH_CONTIGIOUS_START_ADDR_AFTER_INIT;
4813 For All Valid Flash Versions... except 1.1, take the value from FlashBaseAddr
4814 In case of Raw Read... use the default value
4816 if(Adapter->uiFlashLayoutMajorVersion && (Adapter->bFlashRawRead == FALSE) &&
4817 !((Adapter->uiFlashLayoutMajorVersion == 1) && (Adapter->uiFlashLayoutMinorVersion == 1))
4819 uiBaseAddr = Adapter->uiFlashBaseAdd | FLASH_CONTIGIOUS_START_ADDR_BEFORE_INIT;
4821 uiBaseAddr = FLASH_CONTIGIOUS_START_ADDR_BEFORE_INIT;
4827 BcmCopySection :- This API is used to copy the One section in another. Both section should
4828 be contiuous and of same size. Hence this Will not be applicabe to copy ISO.
4830 @Adapater :- Bcm Driver Private Data Structure
4831 @SrcSection :- Source section From where data has to be copied
4832 @DstSection :- Destination section to which data has to be copied
4833 @offset :- Offset from/to where data has to be copied from one section to another.
4834 @numOfBytes :- number of byes that has to be copyed from one section to another at given offset.
4835 in case of numofBytes equal zero complete section will be copied.
4838 Sucess : Return STATUS_SUCCESS
4839 Faillure :- return negative error code
4843 INT BcmCopySection(PMINI_ADAPTER Adapter,
4844 FLASH2X_SECTION_VAL SrcSection,
4845 FLASH2X_SECTION_VAL DstSection,
4850 UINT BytesToBeCopied = 0;
4851 PUCHAR pBuff = NULL ;
4852 INT Status = STATUS_SUCCESS ;
4853 if(SrcSection == DstSection)
4855 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Source and Destination should be different ...try again");
4858 if((SrcSection != DSD0) && (SrcSection != DSD1) && (SrcSection != DSD2))
4860 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Source should be DSD subsection");
4863 if((DstSection != DSD0) && (DstSection != DSD1) && (DstSection != DSD2))
4865 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Destination should be DSD subsection");
4872 if((SrcSection == VSA0) || (SrcSection == VSA1) || (SrcSection == VSA2))
4874 if((DstSection != VSA0) && (DstSection != VSA1) && (DstSection != VSA2))
4876 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Source and Destion secton is not of same type");
4883 //if offset zero means have to copy complete secton
4887 numOfBytes = BcmGetSectionValEndOffset(Adapter,SrcSection)
4888 - BcmGetSectionValStartOffset(Adapter,SrcSection);
4890 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL," Section Size :0x%x",numOfBytes);
4893 if((offset + numOfBytes) > BcmGetSectionValEndOffset(Adapter,SrcSection)
4894 - BcmGetSectionValStartOffset(Adapter,SrcSection))
4896 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0," Input parameters going beyond the section offS: %x numB: %x of Source Section\n",
4897 offset, numOfBytes);
4901 if((offset + numOfBytes) > BcmGetSectionValEndOffset(Adapter,DstSection)
4902 - BcmGetSectionValStartOffset(Adapter,DstSection))
4904 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0," Input parameters going beyond the section offS: %x numB: %x of Destination Section\n",
4905 offset, numOfBytes);
4910 if(numOfBytes > Adapter->uiSectorSize )
4911 BuffSize = Adapter->uiSectorSize;
4913 BuffSize = numOfBytes ;
4915 pBuff = (PCHAR)kzalloc(BuffSize, GFP_KERNEL);
4918 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Memory allocation failed.. ");
4923 BytesToBeCopied = Adapter->uiSectorSize ;
4924 if(offset % Adapter->uiSectorSize)
4925 BytesToBeCopied = Adapter->uiSectorSize - (offset % Adapter->uiSectorSize);
4926 if(BytesToBeCopied > numOfBytes)
4927 BytesToBeCopied = numOfBytes ;
4931 Adapter->bHeaderChangeAllowed = TRUE;
4935 Status = BcmFlash2xBulkRead(Adapter, (PUINT)pBuff, SrcSection , offset,BytesToBeCopied);
4938 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Read failed at offset :%d for NOB :%d", SrcSection,BytesToBeCopied);
4941 Status = BcmFlash2xBulkWrite(Adapter,(PUINT)pBuff,DstSection,offset,BytesToBeCopied,FALSE);
4944 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Write failed at offset :%d for NOB :%d", DstSection,BytesToBeCopied);
4947 offset = offset + BytesToBeCopied;
4948 numOfBytes = numOfBytes - BytesToBeCopied ;
4951 if(numOfBytes > Adapter->uiSectorSize )
4952 BytesToBeCopied = Adapter->uiSectorSize;
4954 BytesToBeCopied = numOfBytes;
4956 }while(numOfBytes > 0) ;
4958 Adapter->bHeaderChangeAllowed = FALSE ;
4963 SaveHeaderIfPresent :- This API is use to Protect the Header in case of Header Sector write
4964 @Adapater :- Bcm Driver Private Data Structure
4965 @pBuff :- Data buffer that has to be written in sector having the header map.
4966 @uiOffset :- Flash offset that has to be written.
4969 Sucess :- On sucess return STATUS_SUCCESS
4970 Faillure :- Return negative error code
4974 INT SaveHeaderIfPresent(PMINI_ADAPTER Adapter, PUCHAR pBuff, UINT uiOffset)
4976 UINT offsetToProtect = 0,HeaderSizeToProtect =0;
4977 BOOLEAN bHasHeader = FALSE ;
4978 PUCHAR pTempBuff =NULL;
4979 UINT uiSectAlignAddr = 0;
4983 //if Chenges in Header is allowed, Return back
4984 if(Adapter->bHeaderChangeAllowed == TRUE)
4986 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Header Change is allowed");
4987 return STATUS_SUCCESS ;
4990 //making the offset sector alligned
4991 uiSectAlignAddr = uiOffset & ~(Adapter->uiSectorSize - 1);
4994 if((uiSectAlignAddr == BcmGetSectionValEndOffset(Adapter,DSD2)- Adapter->uiSectorSize)||
4995 (uiSectAlignAddr == BcmGetSectionValEndOffset(Adapter,DSD1)- Adapter->uiSectorSize)||
4996 (uiSectAlignAddr == BcmGetSectionValEndOffset(Adapter,DSD0)- Adapter->uiSectorSize))
4999 //offset from the sector boundry having the header map
5000 offsetToProtect = Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader % Adapter->uiSectorSize;
5001 HeaderSizeToProtect = sizeof(DSD_HEADER);
5005 if(uiSectAlignAddr == BcmGetSectionValStartOffset(Adapter,ISO_IMAGE1) ||
5006 uiSectAlignAddr == BcmGetSectionValStartOffset(Adapter,ISO_IMAGE2))
5008 offsetToProtect = 0;
5009 HeaderSizeToProtect = sizeof(ISO_HEADER);
5012 //If Header is present overwrite passed buffer with this
5013 if(bHasHeader && (Adapter->bHeaderChangeAllowed == FALSE))
5015 pTempBuff = (PUCHAR)kzalloc(HeaderSizeToProtect, GFP_KERNEL);
5016 if(pTempBuff == NULL)
5018 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Memory allocation failed ");
5022 BeceemFlashBulkRead(Adapter,(PUINT)pTempBuff,(uiSectAlignAddr + offsetToProtect),HeaderSizeToProtect);
5023 BCM_DEBUG_PRINT_BUFFER(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,pTempBuff ,HeaderSizeToProtect);
5024 //Replace Buffer content with Header
5025 memcpy(pBuff +offsetToProtect,pTempBuff,HeaderSizeToProtect);
5027 bcm_kfree(pTempBuff);
5029 if(bHasHeader && Adapter->bSigCorrupted)
5031 sig = *((PUINT)(pBuff + offsetToProtect + FIELD_OFFSET_IN_HEADER(PDSD_HEADER,DSDImageMagicNumber)));
5033 if((sig & 0xFF000000) != CORRUPTED_PATTERN)
5035 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Desired pattern is not at sig offset. Hence won't restore");
5036 Adapter->bSigCorrupted = FALSE;
5037 return STATUS_SUCCESS;
5039 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL," Corrupted sig is :%X", sig);
5040 *((PUINT)(pBuff + offsetToProtect + FIELD_OFFSET_IN_HEADER(PDSD_HEADER,DSDImageMagicNumber)))= htonl(DSD_IMAGE_MAGIC_NUMBER);
5041 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Restoring the signature in Header Write only");
5042 Adapter->bSigCorrupted = FALSE;
5045 return STATUS_SUCCESS ;
5047 INT BcmMakeFlashCSActive(PMINI_ADAPTER Adapter, UINT offset)
5049 UINT GPIOConfig = 0 ;
5052 if(Adapter->bFlashRawRead == FALSE)
5054 //Applicable for Flash2.x
5055 if(IsFlash2x(Adapter) == FALSE)
5056 return STATUS_SUCCESS;
5059 if(offset/FLASH_PART_SIZE)
5061 //bit[14..12] -> will select make Active CS1, CS2 or CS3
5062 // Select CS1, CS2 and CS3 (CS0 is dedicated pin)
5063 rdmalt(Adapter,FLASH_GPIO_CONFIG_REG, &GPIOConfig, 4);
5064 GPIOConfig |= (7 << 12);
5065 wrmalt(Adapter,FLASH_GPIO_CONFIG_REG, &GPIOConfig, 4);
5068 return STATUS_SUCCESS ;
5071 BcmDoChipSelect : This will selcet the appropriate chip for writing.
5072 @Adapater :- Bcm Driver Private Data Structure
5075 Select the Appropriate chip and retrn status Sucess
5077 INT BcmDoChipSelect(PMINI_ADAPTER Adapter, UINT offset)
5079 UINT FlashConfig = 0;
5081 UINT GPIOConfig = 0;
5084 ChipNum = offset / FLASH_PART_SIZE ;
5087 // Chip Select mapping to enable flash0.
5088 // To select flash 0, we have to OR with (0<<12).
5089 // ORing 0 will have no impact so not doing that part.
5090 // In future if Chip select value changes from 0 to non zero,
5091 // That needs be taken care with backward comaptibility. No worries for now.
5095 SelectedChip Variable is the selection that the host is 100% Sure the same as what the register will hold. This can be ONLY ensured
5096 if the Chip doesn't goes to low power mode while the flash operation is in progress (NVMRdmWrmLock is taken)
5097 Before every new Flash Write operation, we reset the variable. This is to ensure that after any wake-up from
5098 power down modes (Idle mode/shutdown mode), the values in the register will be different.
5101 if(Adapter->SelectedChip == ChipNum)
5102 return STATUS_SUCCESS;
5104 //BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Selected Chip :%x", ChipNum);
5105 Adapter->SelectedChip = ChipNum ;
5107 //bit[13..12] will select the appropriate chip
5108 rdmalt(Adapter,FLASH_CONFIG_REG, &FlashConfig, 4);
5109 rdmalt(Adapter,FLASH_GPIO_CONFIG_REG, &GPIOConfig, 4);
5119 GPIOConfig |= (0x4 << CHIP_SELECT_BIT12);
5123 GPIOConfig |= (0x1 << CHIP_SELECT_BIT12);
5127 GPIOConfig |= (0x2 << CHIP_SELECT_BIT12);
5131 /* In case the bits already written in the FLASH_CONFIG_REG is same as what the user desired,
5132 nothing to do... can return immediately.
5133 ASSUMPTION: FLASH_GPIO_CONFIG_REG will be in sync with FLASH_CONFIG_REG.
5134 Even if the chip goes to low power mode, it should wake with values in each register in sync with each other.
5135 These values are not written by host other than during CHIP_SELECT.
5137 if(PartNum == ((FlashConfig >> CHIP_SELECT_BIT12) & 0x3))
5138 return STATUS_SUCCESS;
5140 //clearing the bit[13..12]
5141 FlashConfig &= 0xFFFFCFFF;
5142 FlashConfig = (FlashConfig | (PartNum<<CHIP_SELECT_BIT12)); //00
5144 wrmalt(Adapter,FLASH_GPIO_CONFIG_REG, &GPIOConfig, 4);
5147 wrmalt(Adapter,FLASH_CONFIG_REG, &FlashConfig, 4);
5150 return STATUS_SUCCESS;
5153 INT ReadDSDSignature(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL dsd)
5156 //UINT sigoffsetInMap = 0;
5157 //DSD_HEADER dsdHeader = {0};
5160 //sigoffsetInMap =(PUCHAR)&(dsdHeader.DSDImageMagicNumber) -(PUCHAR)&dsdHeader;
5162 if(dsd != DSD0 && dsd != DSD1 && dsd != DSD2)
5164 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"passed section value is not for DSDs");
5165 return STATUS_FAILURE;
5167 BcmFlash2xBulkRead(Adapter,
5170 Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + FIELD_OFFSET_IN_HEADER(PDSD_HEADER,DSDImageMagicNumber),
5173 uiDSDsig = ntohl(uiDSDsig);
5174 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"DSD SIG :%x", uiDSDsig);
5178 INT ReadDSDPriority(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL dsd)
5180 //UINT priOffsetInMap = 0 ;
5181 unsigned int uiDSDPri = STATUS_FAILURE;
5182 //DSD_HEADER dsdHeader = {0};
5183 //priOffsetInMap = (PUCHAR)&(dsdHeader.DSDImagePriority) -(PUCHAR)&dsdHeader;
5184 if(IsSectionWritable(Adapter,dsd))
5186 if(ReadDSDSignature(Adapter,dsd)== DSD_IMAGE_MAGIC_NUMBER)
5188 BcmFlash2xBulkRead(Adapter,
5191 Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader +FIELD_OFFSET_IN_HEADER(PDSD_HEADER, DSDImagePriority),
5194 uiDSDPri = ntohl(uiDSDPri);
5195 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"DSD<%x> Priority :%x", dsd, uiDSDPri);
5201 FLASH2X_SECTION_VAL getHighestPriDSD(PMINI_ADAPTER Adapter)
5203 INT DSDHighestPri = STATUS_FAILURE;
5205 FLASH2X_SECTION_VAL HighestPriDSD = 0 ;
5207 if(IsSectionWritable(Adapter,DSD2))
5209 DSDHighestPri = ReadDSDPriority(Adapter,DSD2);
5210 HighestPriDSD = DSD2 ;
5212 if(IsSectionWritable(Adapter,DSD1))
5214 DsdPri = ReadDSDPriority(Adapter,DSD1);
5215 if(DSDHighestPri < DsdPri)
5217 DSDHighestPri = DsdPri ;
5218 HighestPriDSD = DSD1;
5221 if(IsSectionWritable(Adapter,DSD0))
5223 DsdPri = ReadDSDPriority(Adapter,DSD0);
5224 if(DSDHighestPri < DsdPri)
5226 DSDHighestPri = DsdPri ;
5227 HighestPriDSD = DSD0;
5231 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Highest DSD :%x , and its Pri :%x", HighestPriDSD, DSDHighestPri);
5232 return HighestPriDSD ;
5235 INT ReadISOSignature(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL iso)
5238 //UINT sigoffsetInMap = 0;
5239 //ISO_HEADER ISOHeader = {0};
5242 //sigoffsetInMap =(PUCHAR)&(ISOHeader.ISOImageMagicNumber) -(PUCHAR)&ISOHeader;
5244 if(iso != ISO_IMAGE1 && iso != ISO_IMAGE2)
5246 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"passed section value is not for ISOs");
5247 return STATUS_FAILURE;
5249 BcmFlash2xBulkRead(Adapter,
5252 0 + FIELD_OFFSET_IN_HEADER(PISO_HEADER,ISOImageMagicNumber),
5255 uiISOsig = ntohl(uiISOsig);
5256 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"ISO SIG :%x", uiISOsig);
5260 INT ReadISOPriority(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL iso)
5263 unsigned int ISOPri = STATUS_FAILURE;
5264 if(IsSectionWritable(Adapter,iso))
5266 if(ReadISOSignature(Adapter,iso)== ISO_IMAGE_MAGIC_NUMBER)
5268 BcmFlash2xBulkRead(Adapter,
5271 0 + FIELD_OFFSET_IN_HEADER(PISO_HEADER, ISOImagePriority),
5274 ISOPri = ntohl(ISOPri);
5275 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"ISO<%x> Priority :%x", iso, ISOPri);
5281 FLASH2X_SECTION_VAL getHighestPriISO(PMINI_ADAPTER Adapter)
5283 INT ISOHighestPri = STATUS_FAILURE;
5285 FLASH2X_SECTION_VAL HighestPriISO = NO_SECTION_VAL ;
5287 if(IsSectionWritable(Adapter,ISO_IMAGE2))
5289 ISOHighestPri = ReadISOPriority(Adapter,ISO_IMAGE2);
5290 HighestPriISO = ISO_IMAGE2 ;
5292 if(IsSectionWritable(Adapter,ISO_IMAGE1))
5294 ISOPri = ReadISOPriority(Adapter,ISO_IMAGE1);
5295 if(ISOHighestPri < ISOPri)
5297 ISOHighestPri = ISOPri ;
5298 HighestPriISO = ISO_IMAGE1;
5302 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Highest ISO :%x and its Pri :%x",HighestPriISO,ISOHighestPri);
5303 return HighestPriISO ;
5305 INT WriteToFlashWithoutSectorErase(PMINI_ADAPTER Adapter,
5307 FLASH2X_SECTION_VAL eFlash2xSectionVal,
5312 #if !defined(BCM_SHM_INTERFACE) || defined(FLASH_DIRECT_ACCESS)
5313 UINT uiTemp = 0, value = 0 ;
5315 UINT uiPartOffset = 0;
5317 UINT uiStartOffset = 0;
5318 //Adding section start address
5319 INT Status = STATUS_SUCCESS;
5320 PUCHAR pcBuff = (PUCHAR)pBuff;
5322 if(uiNumBytes % Adapter->ulFlashWriteSize)
5324 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Writing without Sector Erase for non-FlashWriteSize number of bytes 0x%x\n", uiNumBytes);
5325 return STATUS_FAILURE;
5328 uiStartOffset = BcmGetSectionValStartOffset(Adapter,eFlash2xSectionVal);
5330 if(IsSectionExistInVendorInfo(Adapter,eFlash2xSectionVal))
5332 return vendorextnWriteSectionWithoutErase(Adapter, pcBuff, eFlash2xSectionVal, uiOffset, uiNumBytes);
5335 uiOffset = uiOffset + uiStartOffset;
5337 #if defined(BCM_SHM_INTERFACE) && !defined(FLASH_DIRECT_ACCESS)
5338 Status = bcmflash_raw_writenoerase((uiOffset/FLASH_PART_SIZE),(uiOffset % FLASH_PART_SIZE), pcBuff,uiNumBytes);
5340 rdmalt(Adapter, 0x0f000C80, &uiTemp, sizeof(uiTemp));
5342 wrmalt(Adapter, 0x0f000C80,&value, sizeof(value));
5344 Adapter->SelectedChip = RESET_CHIP_SELECT;
5345 BcmDoChipSelect(Adapter,uiOffset);
5346 uiPartOffset = (uiOffset & (FLASH_PART_SIZE - 1)) + GetFlashBaseAddr(Adapter);
5348 for(i = 0 ; i< uiNumBytes; i += Adapter->ulFlashWriteSize)
5350 if(Adapter->ulFlashWriteSize == BYTE_WRITE_SUPPORT)
5351 Status = flashByteWrite(Adapter,uiPartOffset, pcBuff);
5353 Status = flashWrite(Adapter,uiPartOffset, pcBuff);
5355 if(Status != STATUS_SUCCESS)
5358 pcBuff = pcBuff + Adapter->ulFlashWriteSize;
5359 uiPartOffset = uiPartOffset + Adapter->ulFlashWriteSize;
5361 wrmalt(Adapter, 0x0f000C80, &uiTemp, sizeof(uiTemp));
5362 Adapter->SelectedChip = RESET_CHIP_SELECT;
5369 UINT getNumOfSubSectionWithWRPermisson(PMINI_ADAPTER Adapter, SECTION_TYPE secType)
5372 UINT numOfWRSubSec = 0;
5376 if(IsSectionWritable(Adapter,ISO_IMAGE1))
5377 numOfWRSubSec = numOfWRSubSec + 1;
5378 if(IsSectionWritable(Adapter,ISO_IMAGE2))
5379 numOfWRSubSec = numOfWRSubSec + 1;
5383 if(IsSectionWritable(Adapter,DSD2))
5384 numOfWRSubSec = numOfWRSubSec + 1;
5385 if(IsSectionWritable(Adapter,DSD1))
5386 numOfWRSubSec = numOfWRSubSec + 1;
5387 if(IsSectionWritable(Adapter,DSD0))
5388 numOfWRSubSec = numOfWRSubSec + 1;
5392 //for VSA Add code Here
5394 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Invalid secton<%d> is passed", secType);\
5398 return numOfWRSubSec;
5401 BOOLEAN IsSectionExistInFlash(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL section)
5404 BOOLEAN SectionPresent = FALSE ;
5410 if((Adapter->psFlash2xCSInfo->OffsetISOImage1Part1Start != UNINIT_PTR_IN_CS) &&
5411 (IsNonCDLessDevice(Adapter) == FALSE))
5412 SectionPresent = TRUE ;
5415 if((Adapter->psFlash2xCSInfo->OffsetISOImage2Part1Start != UNINIT_PTR_IN_CS) &&
5416 (IsNonCDLessDevice(Adapter) == FALSE))
5417 SectionPresent = TRUE ;
5420 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForDSDStart != UNINIT_PTR_IN_CS)
5421 SectionPresent = TRUE ;
5424 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD1Start != UNINIT_PTR_IN_CS)
5425 SectionPresent = TRUE ;
5428 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD2Start != UNINIT_PTR_IN_CS)
5429 SectionPresent = TRUE ;
5432 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForVSAStart != UNINIT_PTR_IN_CS)
5433 SectionPresent = TRUE ;
5436 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA1Start != UNINIT_PTR_IN_CS)
5437 SectionPresent = TRUE ;
5440 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA2Start != UNINIT_PTR_IN_CS)
5441 SectionPresent = TRUE ;
5444 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForScsiFirmware != UNINIT_PTR_IN_CS)
5445 SectionPresent = TRUE ;
5447 case CONTROL_SECTION :
5448 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForControlSectionStart != UNINIT_PTR_IN_CS)
5449 SectionPresent = TRUE ;
5452 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Section Does not exist in Flash 2.x");
5453 SectionPresent = FALSE;
5455 return SectionPresent ;
5457 INT IsSectionWritable(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL Section)
5459 INT offset = STATUS_FAILURE;
5461 if(IsSectionExistInFlash(Adapter,Section) == FALSE)
5463 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Section <%d> does not exixt", Section);
5466 offset = BcmGetSectionValStartOffset(Adapter,Section);
5467 if(offset == INVALID_OFFSET)
5469 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Section<%d> does not exixt", Section);
5473 if(IsSectionExistInVendorInfo(Adapter,Section))
5475 return !(Adapter->psFlash2xVendorInfo->VendorSection[Section].AccessFlags & FLASH2X_SECTION_RO);
5478 Status = IsOffsetWritable(Adapter,offset);
5482 INT CorruptDSDSig(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL eFlash2xSectionVal)
5485 PUCHAR pBuff = NULL;
5488 UINT BlockStatus = 0;
5489 UINT uiSectAlignAddr = 0;
5491 Adapter->bSigCorrupted = FALSE;
5493 if(Adapter->bAllDSDWriteAllow == FALSE)
5495 if(IsSectionWritable(Adapter,eFlash2xSectionVal) != TRUE)
5497 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Section is not Writable...Hence cant Corrupt signature");
5498 return SECTOR_IS_NOT_WRITABLE;
5502 pBuff = (PUCHAR)kzalloc(MAX_RW_SIZE, GFP_KERNEL);
5505 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Can't allocate memorey");
5509 uiOffset = Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + sizeof(DSD_HEADER);
5510 uiOffset -= MAX_RW_SIZE ;
5512 BcmFlash2xBulkRead(Adapter, (PUINT)pBuff,eFlash2xSectionVal,uiOffset,MAX_RW_SIZE);
5515 sig = *((PUINT)(pBuff +12));
5517 BCM_DEBUG_PRINT_BUFFER(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,pBuff,MAX_RW_SIZE);
5518 //Now corrupting the sig by corrupting 4th last Byte.
5521 if(sig == DSD_IMAGE_MAGIC_NUMBER)
5523 Adapter->bSigCorrupted = TRUE;
5524 if(Adapter->ulFlashWriteSize == BYTE_WRITE_SUPPORT)
5526 uiSectAlignAddr = uiOffset & ~(Adapter->uiSectorSize -1);
5527 BlockStatus = BcmFlashUnProtectBlock(Adapter,uiSectAlignAddr,Adapter->uiSectorSize);
5529 WriteToFlashWithoutSectorErase(Adapter,(PUINT)(pBuff + 12),eFlash2xSectionVal,
5530 (uiOffset + 12),BYTE_WRITE_SUPPORT);
5533 BcmRestoreBlockProtectStatus(Adapter,BlockStatus);
5539 WriteToFlashWithoutSectorErase(Adapter,(PUINT)pBuff,eFlash2xSectionVal,
5540 uiOffset ,MAX_RW_SIZE);
5545 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"BCM Signature is not present in header");
5547 return STATUS_FAILURE;
5551 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Corrupted the signature");
5552 return STATUS_SUCCESS ;
5555 INT CorruptISOSig(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL eFlash2xSectionVal)
5558 PUCHAR pBuff = NULL;
5562 Adapter->bSigCorrupted = FALSE;
5564 if(IsSectionWritable(Adapter,eFlash2xSectionVal) != TRUE)
5566 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Section is not Writable...Hence cant Corrupt signature");
5567 return SECTOR_IS_NOT_WRITABLE;
5570 pBuff = (PUCHAR)kzalloc(MAX_RW_SIZE, GFP_KERNEL);
5573 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Can't allocate memorey");
5579 BcmFlash2xBulkRead(Adapter, (PUINT)pBuff,eFlash2xSectionVal,uiOffset, MAX_RW_SIZE);
5581 sig = *((PUINT)pBuff);
5587 if(sig == ISO_IMAGE_MAGIC_NUMBER)
5589 Adapter->bSigCorrupted = TRUE;
5590 WriteToFlashWithoutSectorErase(Adapter,(PUINT)pBuff,eFlash2xSectionVal,
5591 uiOffset ,Adapter->ulFlashWriteSize);
5595 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"BCM Signature is not present in header");
5597 return STATUS_FAILURE;
5600 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Corrupted the signature");
5601 BCM_DEBUG_PRINT_BUFFER(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,pBuff,MAX_RW_SIZE);
5604 return STATUS_SUCCESS ;
5607 BOOLEAN IsNonCDLessDevice(PMINI_ADAPTER Adapter)
5609 if(Adapter->psFlash2xCSInfo->IsCDLessDeviceBootSig == NON_CDLESS_DEVICE_BOOT_SIG)