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 memcpy( (PUCHAR) pBuffer, ( ((PUCHAR)&uiData[0]) + uiByteOffset ), 4);
233 return STATUS_SUCCESS;
234 } /* ReadBeceemEEPROM() */
238 INT ReadMacAddressFromNVM(PMINI_ADAPTER Adapter)
241 unsigned char puMacAddr[6] = {0};
245 Status = BeceemNVMRead(Adapter,
246 (PUINT)&puMacAddr[0],
247 INIT_PARAMS_1_MACADDRESS_ADDRESS,
250 if(Status != STATUS_SUCCESS)
252 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Error in Reading the mac Addres with status :%d", Status);
256 memcpy(Adapter->dev->dev_addr, puMacAddr, MAC_ADDRESS_SIZE);
257 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Modem MAC Addr :");
258 BCM_DEBUG_PRINT_BUFFER(Adapter,DBG_TYPE_PRINTK, 0, DBG_LVL_ALL,&Adapter->dev->dev_addr[0],MAC_ADDRESS_SIZE);
259 for(i=0;i<MAC_ADDRESS_SIZE;i++)
262 if(Adapter->dev->dev_addr[i] == 0x00)
264 if(Adapter->dev->dev_addr[i] == 0xFF)
268 //BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "\n");
269 if(AllZeroMac == MAC_ADDRESS_SIZE)
270 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Warning :: MAC Address has all 00's");
271 if(AllFFMac == MAC_ADDRESS_SIZE)
272 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Warning :: MAC Address has all FF's");
278 //-----------------------------------------------------------------------------
279 // Procedure: BeceemEEPROMBulkRead
281 // Description: Reads the EEPROM and returns the Data.
284 // Adapter - ptr to Adapter object instance
285 // pBuffer - Buffer to store the data read from EEPROM
286 // uiOffset - Offset of EEPROM from where data should be read
287 // uiNumBytes - Number of bytes to be read from the EEPROM.
290 // OSAL_STATUS_SUCCESS - if EEPROM read is successfull.
291 // <FAILURE> - if failed.
292 //-----------------------------------------------------------------------------
294 INT BeceemEEPROMBulkRead(
295 PMINI_ADAPTER Adapter,
300 UINT uiData[4] = {0};
301 //UINT uiAddress = 0;
302 UINT uiBytesRemaining = uiNumBytes;
304 UINT uiTempOffset = 0;
305 UINT uiExtraBytes = 0;
306 UINT uiFailureRetries = 0;
307 PUCHAR pcBuff = (PUCHAR)pBuffer;
310 if(uiOffset%MAX_RW_SIZE&& uiBytesRemaining)
312 uiTempOffset = uiOffset - (uiOffset%MAX_RW_SIZE);
313 uiExtraBytes = uiOffset-uiTempOffset;
314 ReadBeceemEEPROMBulk(Adapter,uiTempOffset,(PUINT)&uiData[0],4);
315 if(uiBytesRemaining >= (MAX_RW_SIZE - uiExtraBytes))
317 memcpy(pBuffer,(((PUCHAR)&uiData[0])+uiExtraBytes),MAX_RW_SIZE - uiExtraBytes);
319 uiBytesRemaining -= (MAX_RW_SIZE - uiExtraBytes);
320 uiIndex += (MAX_RW_SIZE - uiExtraBytes);
321 uiOffset += (MAX_RW_SIZE - uiExtraBytes);
325 memcpy(pBuffer,(((PUCHAR)&uiData[0])+uiExtraBytes),uiBytesRemaining);
326 uiIndex += uiBytesRemaining;
327 uiOffset += uiBytesRemaining;
328 uiBytesRemaining = 0;
335 while(uiBytesRemaining && uiFailureRetries != 128)
337 if(Adapter->device_removed )
342 if(uiBytesRemaining >= MAX_RW_SIZE)
344 /* For the requests more than or equal to 16 bytes, use bulk
345 * read function to make the access faster.
346 * We read 4 Dwords of data */
347 if(0 == ReadBeceemEEPROMBulk(Adapter,uiOffset,&uiData[0],4))
349 memcpy(pcBuff+uiIndex,&uiData[0],MAX_RW_SIZE);
350 uiOffset += MAX_RW_SIZE;
351 uiBytesRemaining -= MAX_RW_SIZE;
352 uiIndex += MAX_RW_SIZE;
357 mdelay(3);//sleep for a while before retry...
360 else if(uiBytesRemaining >= 4)
362 if(0 == ReadBeceemEEPROM(Adapter,uiOffset,&uiData[0]))
364 memcpy(pcBuff+uiIndex,&uiData[0],4);
366 uiBytesRemaining -= 4;
372 mdelay(3);//sleep for a while before retry...
376 { // Handle the reads less than 4 bytes...
377 PUCHAR pCharBuff = (PUCHAR)pBuffer;
378 pCharBuff += uiIndex;
379 if(0 == ReadBeceemEEPROM(Adapter,uiOffset,&uiData[0]))
381 memcpy(pCharBuff,&uiData[0],uiBytesRemaining);//copy only bytes requested.
382 uiBytesRemaining = 0;
387 mdelay(3);//sleep for a while before retry...
396 //-----------------------------------------------------------------------------
397 // Procedure: BeceemFlashBulkRead
399 // Description: Reads the FLASH and returns the Data.
402 // Adapter - ptr to Adapter object instance
403 // pBuffer - Buffer to store the data read from FLASH
404 // uiOffset - Offset of FLASH from where data should be read
405 // uiNumBytes - Number of bytes to be read from the FLASH.
408 // OSAL_STATUS_SUCCESS - if FLASH read is successfull.
409 // <FAILURE> - if failed.
410 //-----------------------------------------------------------------------------
412 INT BeceemFlashBulkRead(
413 PMINI_ADAPTER Adapter,
419 UINT uiBytesToRead = uiNumBytes;
421 UINT uiPartOffset = 0;
423 if(Adapter->device_removed )
425 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Device Got Removed ");
429 //Adding flash Base address
430 // uiOffset = uiOffset + GetFlashBaseAddr(Adapter);
431 #if defined(BCM_SHM_INTERFACE) && !defined(FLASH_DIRECT_ACCESS)
432 Status = bcmflash_raw_read((uiOffset/FLASH_PART_SIZE),(uiOffset % FLASH_PART_SIZE),( unsigned char *)pBuffer,uiNumBytes);
436 Adapter->SelectedChip = RESET_CHIP_SELECT;
438 if(uiOffset % MAX_RW_SIZE)
440 BcmDoChipSelect(Adapter,uiOffset);
441 uiPartOffset = (uiOffset & (FLASH_PART_SIZE - 1)) + GetFlashBaseAddr(Adapter);
443 uiBytesToRead = MAX_RW_SIZE - (uiOffset%MAX_RW_SIZE);
444 uiBytesToRead = MIN(uiNumBytes,uiBytesToRead);
446 if(rdm(Adapter,uiPartOffset, (PCHAR)pBuffer+uiIndex,uiBytesToRead))
449 Adapter->SelectedChip = RESET_CHIP_SELECT;
453 uiIndex += uiBytesToRead;
454 uiOffset += uiBytesToRead;
455 uiNumBytes -= uiBytesToRead;
460 BcmDoChipSelect(Adapter,uiOffset);
461 uiPartOffset = (uiOffset & (FLASH_PART_SIZE - 1)) + GetFlashBaseAddr(Adapter);
463 uiBytesToRead = MIN(uiNumBytes,MAX_RW_SIZE);
465 if(rdm(Adapter,uiPartOffset, (PCHAR)pBuffer+uiIndex,uiBytesToRead))
472 uiIndex += uiBytesToRead;
473 uiOffset += uiBytesToRead;
474 uiNumBytes -= uiBytesToRead;
477 Adapter->SelectedChip = RESET_CHIP_SELECT;
481 //-----------------------------------------------------------------------------
482 // Procedure: BcmGetFlashSize
484 // Description: Finds the size of FLASH.
487 // Adapter - ptr to Adapter object instance
490 // UINT - size of the FLASH Storage.
492 //-----------------------------------------------------------------------------
494 UINT BcmGetFlashSize(PMINI_ADAPTER Adapter)
496 if(IsFlash2x(Adapter))
497 return (Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + sizeof(DSD_HEADER));
504 //-----------------------------------------------------------------------------
505 // Procedure: BcmGetEEPROMSize
507 // Description: Finds the size of EEPROM.
510 // Adapter - ptr to Adapter object instance
513 // UINT - size of the EEPROM Storage.
515 //-----------------------------------------------------------------------------
517 UINT BcmGetEEPROMSize(PMINI_ADAPTER Adapter)
523 // if EEPROM is present and already Calibrated,it will have
524 // 'BECM' string at 0th offset.
525 // To find the EEPROM size read the possible boundaries of the
526 // EEPROM like 4K,8K etc..accessing the EEPROM beyond its size will
527 // result in wrap around. So when we get the End of the EEPROM we will
528 // get 'BECM' string which is indeed at offset 0.
530 BeceemEEPROMBulkRead(Adapter,&uiData,0x0,4);
533 for(uiIndex = 2;uiIndex <=256; uiIndex*=2)
535 BeceemEEPROMBulkRead(Adapter,&uiData,uiIndex*1024,4);
545 // EEPROM may not be present or not programmed
549 if(0 == BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&uiData,0,4,TRUE))
552 for(uiIndex = 2;uiIndex <=256; uiIndex*=2)
554 BeceemEEPROMBulkRead(Adapter,&uiData,uiIndex*1024,4);
555 if(uiData == 0xBABEFACE)
567 //-----------------------------------------------------------------------------
568 // Procedure: FlashSectorErase
570 // Description: Finds the sector size of the FLASH.
573 // Adapter - ptr to Adapter object instance
574 // addr - sector start address
575 // numOfSectors - number of sectors to be erased.
580 //-----------------------------------------------------------------------------
583 static INT FlashSectorErase(PMINI_ADAPTER Adapter,
587 UINT iIndex = 0, iRetries = 0;
591 for(iIndex=0;iIndex<numOfSectors;iIndex++)
594 wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value));
596 value = (0xd8000000 | (addr & 0xFFFFFF));
597 wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value));
602 value = (FLASH_CMD_STATUS_REG_READ << 24);
603 if(wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value)) < 0)
605 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Programing of FLASH_SPI_CMDQ_REG fails");
606 return STATUS_FAILURE;
609 if(rdmalt(Adapter, FLASH_SPI_READQ_REG, &uiStatus, sizeof(uiStatus)) < 0 )
611 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Reading status of FLASH_SPI_READQ_REG fails");
612 return STATUS_FAILURE;
615 //After every try lets make the CPU free for 10 ms. generally time taken by the
616 //the sector erase cycle is 500 ms to 40000 msec. hence sleeping 10 ms
617 //won't hamper performance in any case.
619 }while((uiStatus & 0x1) && (iRetries < 400));
623 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"iRetries crossing the limit of 80000\n");
624 return STATUS_FAILURE;
627 addr += Adapter->uiSectorSize;
631 //-----------------------------------------------------------------------------
632 // Procedure: flashByteWrite
634 // Description: Performs Byte by Byte write to flash
637 // Adapter - ptr to Adapter object instance
638 // uiOffset - Offset of the flash where data needs to be written to.
639 // pData - Address of Data to be written.
643 //-----------------------------------------------------------------------------
645 static INT flashByteWrite(
646 PMINI_ADAPTER Adapter,
652 INT iRetries = MAX_FLASH_RETRIES * FLASH_PER_RETRIES_DELAY; //3
655 ULONG ulData = *(PUCHAR)pData;
658 // need not write 0xFF because write requires an erase and erase will
659 // make whole sector 0xFF.
664 return STATUS_SUCCESS;
667 // DumpDebug(NVM_RW,("flashWrite ====>\n"));
668 value = (FLASH_CMD_WRITE_ENABLE << 24);
669 if(wrmalt(Adapter, FLASH_SPI_CMDQ_REG,&value, sizeof(value)) < 0)
671 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Write enable in FLASH_SPI_CMDQ_REG register fails");
672 return STATUS_FAILURE;
674 if(wrm(Adapter,FLASH_SPI_WRITEQ_REG, (PCHAR)&ulData, 4) < 0 )
676 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"DATA Write on FLASH_SPI_WRITEQ_REG fails");
677 return STATUS_FAILURE;
679 value = (0x02000000 | (uiOffset & 0xFFFFFF));
680 if(wrmalt(Adapter, FLASH_SPI_CMDQ_REG,&value, sizeof(value)) < 0 )
682 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Programming of FLASH_SPI_CMDQ_REG fails");
683 return STATUS_FAILURE;
690 value = (FLASH_CMD_STATUS_REG_READ << 24);
691 if(wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value)) < 0)
693 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Programing of FLASH_SPI_CMDQ_REG fails");
694 return STATUS_FAILURE;
697 if(rdmalt(Adapter, FLASH_SPI_READQ_REG, &uiStatus, sizeof(uiStatus)) < 0)
699 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Reading status of FLASH_SPI_READQ_REG fails");
700 return STATUS_FAILURE;
703 if( iRetries && ((iRetries % FLASH_PER_RETRIES_DELAY) == 0))
706 }while((uiStatus & 0x1) && (iRetries >0) );
710 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash Write fails even after checking status for 200 times.");
711 return STATUS_FAILURE ;
714 return STATUS_SUCCESS;
719 //-----------------------------------------------------------------------------
720 // Procedure: flashWrite
722 // Description: Performs write to flash
725 // Adapter - ptr to Adapter object instance
726 // uiOffset - Offset of the flash where data needs to be written to.
727 // pData - Address of Data to be written.
731 //-----------------------------------------------------------------------------
733 static INT flashWrite(
734 PMINI_ADAPTER Adapter,
741 //UINT uiReadBack = 0;
744 INT iRetries = MAX_FLASH_RETRIES * FLASH_PER_RETRIES_DELAY; //3
747 UINT uiErasePattern[4] = {0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF};
749 // need not write 0xFFFFFFFF because write requires an erase and erase will
750 // make whole sector 0xFFFFFFFF.
752 if (!memcmp(pData, uiErasePattern, MAX_RW_SIZE))
757 value = (FLASH_CMD_WRITE_ENABLE << 24);
759 if(wrmalt(Adapter, FLASH_SPI_CMDQ_REG,&value, sizeof(value)) < 0 )
761 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Write Enable of FLASH_SPI_CMDQ_REG fails");
762 return STATUS_FAILURE;
764 if(wrm(Adapter, uiOffset, (PCHAR)pData, MAX_RW_SIZE) < 0)
766 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Data write fails...");
767 return STATUS_FAILURE;
773 value = (FLASH_CMD_STATUS_REG_READ << 24);
774 if(wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value)) < 0)
776 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Programing of FLASH_SPI_CMDQ_REG fails");
777 return STATUS_FAILURE;
780 if(rdmalt(Adapter, FLASH_SPI_READQ_REG, &uiStatus, sizeof(uiStatus)) < 0 )
782 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Reading status of FLASH_SPI_READQ_REG fails");
783 return STATUS_FAILURE;
787 //this will ensure that in there will be no changes in the current path.
788 //currently one rdm/wrm takes 125 us.
789 //Hence 125 *2 * FLASH_PER_RETRIES_DELAY > 3 ms(worst case delay)
790 //Hence current implementation cycle will intoduce no delay in current path
791 if(iRetries && ((iRetries % FLASH_PER_RETRIES_DELAY) == 0))
793 }while((uiStatus & 0x1) && (iRetries > 0));
797 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash Write fails even after checking status for 200 times.");
798 return STATUS_FAILURE ;
801 return STATUS_SUCCESS;
804 //-----------------------------------------------------------------------------
805 // Procedure: flashByteWriteStatus
807 // Description: Performs byte by byte write to flash with write done status check
810 // Adapter - ptr to Adapter object instance
811 // uiOffset - Offset of the flash where data needs to be written to.
812 // pData - Address of the Data to be written.
816 //-----------------------------------------------------------------------------
817 static INT flashByteWriteStatus(
818 PMINI_ADAPTER Adapter,
823 INT iRetries = MAX_FLASH_RETRIES * FLASH_PER_RETRIES_DELAY; //3
824 ULONG ulData = *(PUCHAR)pData;
828 // need not write 0xFFFFFFFF because write requires an erase and erase will
829 // make whole sector 0xFFFFFFFF.
834 return STATUS_SUCCESS;
837 // DumpDebug(NVM_RW,("flashWrite ====>\n"));
839 value = (FLASH_CMD_WRITE_ENABLE << 24);
840 if(wrmalt(Adapter, FLASH_SPI_CMDQ_REG,&value, sizeof(value)) < 0)
842 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Write enable in FLASH_SPI_CMDQ_REG register fails");
843 return STATUS_SUCCESS;
845 if(wrm(Adapter,FLASH_SPI_WRITEQ_REG, (PCHAR)&ulData, 4) < 0)
847 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"DATA Write on FLASH_SPI_WRITEQ_REG fails");
848 return STATUS_FAILURE;
850 value = (0x02000000 | (uiOffset & 0xFFFFFF));
851 if(wrmalt(Adapter, FLASH_SPI_CMDQ_REG,&value, sizeof(value)) < 0)
853 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Programming of FLASH_SPI_CMDQ_REG fails");
854 return STATUS_FAILURE;
861 value = (FLASH_CMD_STATUS_REG_READ << 24);
862 if(wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value)) < 0)
864 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Programing of FLASH_SPI_CMDQ_REG fails");
865 return STATUS_FAILURE;
868 if(rdmalt(Adapter, FLASH_SPI_READQ_REG, &uiStatus, sizeof(uiStatus)) < 0)
870 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Reading status of FLASH_SPI_READQ_REG fails");
871 return STATUS_FAILURE;
875 if( iRetries && ((iRetries % FLASH_PER_RETRIES_DELAY) == 0))
877 }while((uiStatus & 0x1) && (iRetries > 0));
881 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash Write fails even after checking status for 200 times.");
882 return STATUS_FAILURE ;
885 return STATUS_SUCCESS;
888 //-----------------------------------------------------------------------------
889 // Procedure: flashWriteStatus
891 // Description: Performs write to flash with write done status check
894 // Adapter - ptr to Adapter object instance
895 // uiOffset - Offset of the flash where data needs to be written to.
896 // pData - Address of the Data to be written.
900 //-----------------------------------------------------------------------------
902 static INT flashWriteStatus(
903 PMINI_ADAPTER Adapter,
908 INT iRetries = MAX_FLASH_RETRIES * FLASH_PER_RETRIES_DELAY; //3
909 //UINT uiReadBack = 0;
911 UINT uiErasePattern[4] = {0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF};
914 // need not write 0xFFFFFFFF because write requires an erase and erase will
915 // make whole sector 0xFFFFFFFF.
917 if (!memcmp(pData,uiErasePattern,MAX_RW_SIZE))
922 value = (FLASH_CMD_WRITE_ENABLE << 24);
923 if(wrmalt(Adapter, FLASH_SPI_CMDQ_REG,&value, sizeof(value)) < 0)
925 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Write Enable of FLASH_SPI_CMDQ_REG fails");
926 return STATUS_FAILURE;
928 if(wrm(Adapter, uiOffset, (PCHAR)pData, MAX_RW_SIZE) < 0)
930 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Data write fails...");
931 return STATUS_FAILURE;
937 value = (FLASH_CMD_STATUS_REG_READ << 24);
938 if(wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value)) < 0)
940 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Programing of FLASH_SPI_CMDQ_REG fails");
941 return STATUS_FAILURE;
944 if(rdmalt(Adapter, FLASH_SPI_READQ_REG, &uiStatus, sizeof(uiStatus)) < 0)
946 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Reading status of FLASH_SPI_READQ_REG fails");
947 return STATUS_FAILURE;
950 //this will ensure that in there will be no changes in the current path.
951 //currently one rdm/wrm takes 125 us.
952 //Hence 125 *2 * FLASH_PER_RETRIES_DELAY >3 ms(worst case delay)
953 //Hence current implementation cycle will intoduce no delay in current path
954 if(iRetries && ((iRetries % FLASH_PER_RETRIES_DELAY) == 0))
956 }while((uiStatus & 0x1) && (iRetries >0));
960 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash Write fails even after checking status for 200 times.");
961 return STATUS_FAILURE ;
964 return STATUS_SUCCESS;
967 //-----------------------------------------------------------------------------
968 // Procedure: BcmRestoreBlockProtectStatus
970 // Description: Restores the original block protection status.
973 // Adapter - ptr to Adapter object instance
974 // ulWriteStatus -Original status
978 //-----------------------------------------------------------------------------
980 static VOID BcmRestoreBlockProtectStatus(PMINI_ADAPTER Adapter,ULONG ulWriteStatus)
983 value = (FLASH_CMD_WRITE_ENABLE<< 24);
984 wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value));
987 value = (FLASH_CMD_STATUS_REG_WRITE<<24)|(ulWriteStatus << 16);
988 wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value));
991 //-----------------------------------------------------------------------------
992 // Procedure: BcmFlashUnProtectBlock
994 // Description: UnProtects appropriate blocks for writing.
997 // Adapter - ptr to Adapter object instance
998 // uiOffset - Offset of the flash where data needs to be written to. This should be Sector aligned.
1000 // ULONG - Status value before UnProtect.
1002 //-----------------------------------------------------------------------------
1003 static ULONG BcmFlashUnProtectBlock(PMINI_ADAPTER Adapter,UINT uiOffset, UINT uiLength)
1006 ULONG ulWriteStatus = 0;
1008 uiOffset = uiOffset&0x000FFFFF;
1011 // Implemented only for 1MB Flash parts.
1013 if(FLASH_PART_SST25VF080B == Adapter->ulFlashID)
1016 // Get Current BP status.
1018 value = (FLASH_CMD_STATUS_REG_READ << 24);
1019 wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value));
1022 // Read status will be WWXXYYZZ. We have to take only WW.
1024 rdmalt(Adapter, FLASH_SPI_READQ_REG, (PUINT)&ulStatus, sizeof(ulStatus));
1026 ulWriteStatus = ulStatus;
1029 // Bits [5-2] give current block level protection status.
1030 // Bit5: BP3 - DONT CARE
1031 // BP2-BP0: 0 - NO PROTECTION, 1 - UPPER 1/16, 2 - UPPER 1/8, 3 - UPPER 1/4
1032 // 4 - UPPER 1/2. 5 to 7 - ALL BLOCKS
1037 if((uiOffset+uiLength) <= 0x80000)
1040 // Offset comes in lower half of 1MB. Protect the upper half.
1041 // Clear BP1 and BP0 and set BP2.
1043 ulWriteStatus |= (0x4<<2);
1044 ulWriteStatus &= ~(0x3<<2);
1046 else if((uiOffset+uiLength) <= 0xC0000)
1049 // Offset comes below Upper 1/4. Upper 1/4 can be protected.
1050 // Clear BP2 and set BP1 and BP0.
1052 ulWriteStatus |= (0x3<<2);
1053 ulWriteStatus &= ~(0x1<<4);
1055 else if((uiOffset+uiLength) <= 0xE0000)
1058 // Offset comes below Upper 1/8. Upper 1/8 can be protected.
1059 // Clear BP2 and BP0 and set BP1
1061 ulWriteStatus |= (0x1<<3);
1062 ulWriteStatus &= ~(0x5<<2);
1065 else if((uiOffset+uiLength) <= 0xF0000)
1068 // Offset comes below Upper 1/16. Only upper 1/16 can be protected.
1069 // Set BP0 and Clear BP2,BP1.
1071 ulWriteStatus |= (0x1<<2);
1072 ulWriteStatus &= ~(0x3<<3);
1078 // Clear BP2,BP1 and BP0.
1080 ulWriteStatus &= ~(0x7<<2);
1083 value = (FLASH_CMD_WRITE_ENABLE<< 24);
1084 wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value));
1086 value = (FLASH_CMD_STATUS_REG_WRITE<<24)|(ulWriteStatus << 16);
1087 wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value));
1095 //-----------------------------------------------------------------------------
1096 // Procedure: BeceemFlashBulkWrite
1098 // Description: Performs write to the flash
1101 // Adapter - ptr to Adapter object instance
1102 // pBuffer - Data to be written.
1103 // uiOffset - Offset of the flash where data needs to be written to.
1104 // uiNumBytes - Number of bytes to be written.
1105 // bVerify - read verify flag.
1109 //-----------------------------------------------------------------------------
1111 INT BeceemFlashBulkWrite(
1112 PMINI_ADAPTER Adapter,
1118 PCHAR pTempBuff = NULL;
1119 PUCHAR pcBuffer = (PUCHAR)pBuffer;
1121 UINT uiOffsetFromSectStart = 0;
1122 UINT uiSectAlignAddr = 0;
1123 UINT uiCurrSectOffsetAddr = 0;
1124 UINT uiSectBoundary = 0;
1125 UINT uiNumSectTobeRead = 0;
1126 UCHAR ucReadBk[16] = {0};
1128 INT Status = STATUS_SUCCESS;
1131 UINT uiPartOffset = 0;
1133 #if defined(BCM_SHM_INTERFACE) && !defined(FLASH_DIRECT_ACCESS)
1134 Status = bcmflash_raw_write((uiOffset/FLASH_PART_SIZE),(uiOffset % FLASH_PART_SIZE),( unsigned char *)pBuffer,uiNumBytes);
1138 uiOffsetFromSectStart = uiOffset & ~(Adapter->uiSectorSize - 1);
1140 //Adding flash Base address
1141 // uiOffset = uiOffset + GetFlashBaseAddr(Adapter);
1143 uiSectAlignAddr = uiOffset & ~(Adapter->uiSectorSize - 1);
1144 uiCurrSectOffsetAddr = uiOffset & (Adapter->uiSectorSize - 1);
1145 uiSectBoundary = uiSectAlignAddr + Adapter->uiSectorSize;
1147 pTempBuff = kmalloc(Adapter->uiSectorSize, GFP_KERNEL);
1148 if(NULL == pTempBuff)
1149 goto BeceemFlashBulkWrite_EXIT;
1151 // check if the data to be written is overlapped accross sectors
1153 if(uiOffset+uiNumBytes < uiSectBoundary)
1155 uiNumSectTobeRead = 1;
1159 // Number of sectors = Last sector start address/First sector start address
1160 uiNumSectTobeRead = (uiCurrSectOffsetAddr+uiNumBytes)/Adapter->uiSectorSize;
1161 if((uiCurrSectOffsetAddr+uiNumBytes)%Adapter->uiSectorSize)
1163 uiNumSectTobeRead++;
1166 //Check whether Requested sector is writable or not in case of flash2x write. But if write call is
1167 // for DSD calibration, allow it without checking of sector permission
1169 if(IsFlash2x(Adapter) && (Adapter->bAllDSDWriteAllow == FALSE))
1172 uiTemp = uiNumSectTobeRead ;
1175 if(IsOffsetWritable(Adapter, uiOffsetFromSectStart + index * Adapter->uiSectorSize ) == FALSE)
1177 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Sector Starting at offset <0X%X> is not writable",
1178 (uiOffsetFromSectStart + index * Adapter->uiSectorSize));
1179 Status = SECTOR_IS_NOT_WRITABLE;
1180 goto BeceemFlashBulkWrite_EXIT;
1182 uiTemp = uiTemp - 1;
1186 Adapter->SelectedChip = RESET_CHIP_SELECT;
1187 while(uiNumSectTobeRead)
1189 //do_gettimeofday(&tv1);
1190 //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));
1191 uiPartOffset = (uiSectAlignAddr & (FLASH_PART_SIZE - 1)) + GetFlashBaseAddr(Adapter);
1193 BcmDoChipSelect(Adapter,uiSectAlignAddr);
1195 if(0 != BeceemFlashBulkRead(Adapter,
1197 uiOffsetFromSectStart,
1198 Adapter->uiSectorSize))
1201 goto BeceemFlashBulkWrite_EXIT;
1204 //do_gettimeofday(&tr);
1205 //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));
1207 ulStatus = BcmFlashUnProtectBlock(Adapter,uiSectAlignAddr,Adapter->uiSectorSize);
1210 if(uiNumSectTobeRead > 1)
1213 memcpy(&pTempBuff[uiCurrSectOffsetAddr],pcBuffer,uiSectBoundary-(uiSectAlignAddr+uiCurrSectOffsetAddr));
1214 pcBuffer += ((uiSectBoundary-(uiSectAlignAddr+uiCurrSectOffsetAddr)));
1215 uiNumBytes -= (uiSectBoundary-(uiSectAlignAddr+uiCurrSectOffsetAddr));
1219 memcpy(&pTempBuff[uiCurrSectOffsetAddr],pcBuffer,uiNumBytes);
1222 if(IsFlash2x(Adapter))
1224 SaveHeaderIfPresent(Adapter,(PUCHAR)pTempBuff,uiOffsetFromSectStart);
1227 FlashSectorErase(Adapter,uiPartOffset,1);
1228 //do_gettimeofday(&te);
1229 //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));
1231 for(uiIndex = 0; uiIndex < Adapter->uiSectorSize; uiIndex +=Adapter->ulFlashWriteSize)
1233 if(Adapter->device_removed)
1236 goto BeceemFlashBulkWrite_EXIT;
1238 if(STATUS_SUCCESS != (*Adapter->fpFlashWrite)(Adapter,uiPartOffset+uiIndex,(&pTempBuff[uiIndex])))
1241 goto BeceemFlashBulkWrite_EXIT;
1245 //do_gettimeofday(&tw);
1246 //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));
1247 for(uiIndex = 0;uiIndex < Adapter->uiSectorSize;uiIndex += MAX_RW_SIZE)
1249 if(STATUS_SUCCESS == BeceemFlashBulkRead(Adapter,(PUINT)ucReadBk,uiOffsetFromSectStart+uiIndex,MAX_RW_SIZE))
1251 if(Adapter->ulFlashWriteSize == 1)
1253 UINT uiReadIndex = 0;
1254 for(uiReadIndex = 0; uiReadIndex < 16; uiReadIndex++)
1256 if(ucReadBk[uiReadIndex] != pTempBuff[uiIndex+uiReadIndex])
1258 if(STATUS_SUCCESS != (*Adapter->fpFlashWriteWithStatusCheck)(Adapter,uiPartOffset+uiIndex+uiReadIndex,&pTempBuff[uiIndex+uiReadIndex]))
1260 Status = STATUS_FAILURE;
1261 goto BeceemFlashBulkWrite_EXIT;
1268 if(memcmp(ucReadBk,&pTempBuff[uiIndex],MAX_RW_SIZE))
1270 if(STATUS_SUCCESS != (*Adapter->fpFlashWriteWithStatusCheck)(Adapter,uiPartOffset+uiIndex,&pTempBuff[uiIndex]))
1272 Status = STATUS_FAILURE;
1273 goto BeceemFlashBulkWrite_EXIT;
1279 //do_gettimeofday(&twv);
1280 //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));
1285 BcmRestoreBlockProtectStatus(Adapter,ulStatus);
1289 uiCurrSectOffsetAddr = 0;
1290 uiSectAlignAddr = uiSectBoundary;
1291 uiSectBoundary += Adapter->uiSectorSize;
1292 uiOffsetFromSectStart += Adapter->uiSectorSize;
1293 uiNumSectTobeRead--;
1295 //do_gettimeofday(&tv2);
1296 //BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Time after Write :%ld ms\n",(tv2.tv_sec *1000 + tv2.tv_usec/1000));
1297 //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));
1301 BeceemFlashBulkWrite_EXIT:
1304 BcmRestoreBlockProtectStatus(Adapter,ulStatus);
1309 Adapter->SelectedChip = RESET_CHIP_SELECT;
1314 //-----------------------------------------------------------------------------
1315 // Procedure: BeceemFlashBulkWriteStatus
1317 // Description: Writes to Flash. Checks the SPI status after each write.
1320 // Adapter - ptr to Adapter object instance
1321 // pBuffer - Data to be written.
1322 // uiOffset - Offset of the flash where data needs to be written to.
1323 // uiNumBytes - Number of bytes to be written.
1324 // bVerify - read verify flag.
1328 //-----------------------------------------------------------------------------
1330 static INT BeceemFlashBulkWriteStatus(
1331 PMINI_ADAPTER Adapter,
1337 PCHAR pTempBuff = NULL;
1338 PUCHAR pcBuffer = (PUCHAR)pBuffer;
1340 UINT uiOffsetFromSectStart = 0;
1341 UINT uiSectAlignAddr = 0;
1342 UINT uiCurrSectOffsetAddr = 0;
1343 UINT uiSectBoundary = 0;
1344 UINT uiNumSectTobeRead = 0;
1345 UCHAR ucReadBk[16] = {0};
1347 UINT Status = STATUS_SUCCESS;
1350 UINT uiPartOffset = 0;
1352 uiOffsetFromSectStart = uiOffset & ~(Adapter->uiSectorSize - 1);
1354 //uiOffset += Adapter->ulFlashCalStart;
1355 //Adding flash Base address
1356 // uiOffset = uiOffset + GetFlashBaseAddr(Adapter);
1358 uiSectAlignAddr = uiOffset & ~(Adapter->uiSectorSize - 1);
1359 uiCurrSectOffsetAddr = uiOffset & (Adapter->uiSectorSize - 1);
1360 uiSectBoundary = uiSectAlignAddr + Adapter->uiSectorSize;
1362 pTempBuff = kmalloc(Adapter->uiSectorSize, GFP_KERNEL);
1363 if(NULL == pTempBuff)
1364 goto BeceemFlashBulkWriteStatus_EXIT;
1367 // check if the data to be written is overlapped accross sectors
1369 if(uiOffset+uiNumBytes < uiSectBoundary)
1371 uiNumSectTobeRead = 1;
1375 // Number of sectors = Last sector start address/First sector start address
1376 uiNumSectTobeRead = (uiCurrSectOffsetAddr+uiNumBytes)/Adapter->uiSectorSize;
1377 if((uiCurrSectOffsetAddr+uiNumBytes)%Adapter->uiSectorSize)
1379 uiNumSectTobeRead++;
1383 if(IsFlash2x(Adapter) && (Adapter->bAllDSDWriteAllow == FALSE))
1386 uiTemp = uiNumSectTobeRead ;
1389 if(IsOffsetWritable(Adapter,uiOffsetFromSectStart + index * Adapter->uiSectorSize ) == FALSE)
1391 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Sector Starting at offset <0X%x> is not writable",
1392 (uiOffsetFromSectStart + index * Adapter->uiSectorSize));
1393 Status = SECTOR_IS_NOT_WRITABLE;
1394 goto BeceemFlashBulkWriteStatus_EXIT;
1396 uiTemp = uiTemp - 1;
1401 Adapter->SelectedChip = RESET_CHIP_SELECT;
1402 while(uiNumSectTobeRead)
1404 uiPartOffset = (uiSectAlignAddr & (FLASH_PART_SIZE - 1)) + GetFlashBaseAddr(Adapter);
1406 BcmDoChipSelect(Adapter,uiSectAlignAddr);
1407 if(0 != BeceemFlashBulkRead(Adapter,
1409 uiOffsetFromSectStart,
1410 Adapter->uiSectorSize))
1413 goto BeceemFlashBulkWriteStatus_EXIT;
1416 ulStatus = BcmFlashUnProtectBlock(Adapter,uiOffsetFromSectStart,Adapter->uiSectorSize);
1418 if(uiNumSectTobeRead > 1)
1421 memcpy(&pTempBuff[uiCurrSectOffsetAddr],pcBuffer,uiSectBoundary-(uiSectAlignAddr+uiCurrSectOffsetAddr));
1422 pcBuffer += ((uiSectBoundary-(uiSectAlignAddr+uiCurrSectOffsetAddr)));
1423 uiNumBytes -= (uiSectBoundary-(uiSectAlignAddr+uiCurrSectOffsetAddr));
1427 memcpy(&pTempBuff[uiCurrSectOffsetAddr],pcBuffer,uiNumBytes);
1430 if(IsFlash2x(Adapter))
1432 SaveHeaderIfPresent(Adapter,(PUCHAR)pTempBuff,uiOffsetFromSectStart);
1435 FlashSectorErase(Adapter,uiPartOffset,1);
1437 for(uiIndex = 0; uiIndex < Adapter->uiSectorSize; uiIndex +=Adapter->ulFlashWriteSize)
1440 if(Adapter->device_removed)
1443 goto BeceemFlashBulkWriteStatus_EXIT;
1446 if(STATUS_SUCCESS != (*Adapter->fpFlashWriteWithStatusCheck)(Adapter,uiPartOffset+uiIndex,&pTempBuff[uiIndex]))
1449 goto BeceemFlashBulkWriteStatus_EXIT;
1455 for(uiIndex = 0;uiIndex < Adapter->uiSectorSize;uiIndex += MAX_RW_SIZE)
1458 if(STATUS_SUCCESS == BeceemFlashBulkRead(Adapter,(PUINT)ucReadBk,uiOffsetFromSectStart+uiIndex,MAX_RW_SIZE))
1460 if(memcmp(ucReadBk,&pTempBuff[uiIndex],MAX_RW_SIZE))
1462 Status = STATUS_FAILURE;
1463 goto BeceemFlashBulkWriteStatus_EXIT;
1473 BcmRestoreBlockProtectStatus(Adapter,ulStatus);
1477 uiCurrSectOffsetAddr = 0;
1478 uiSectAlignAddr = uiSectBoundary;
1479 uiSectBoundary += Adapter->uiSectorSize;
1480 uiOffsetFromSectStart += Adapter->uiSectorSize;
1481 uiNumSectTobeRead--;
1486 BeceemFlashBulkWriteStatus_EXIT:
1489 BcmRestoreBlockProtectStatus(Adapter,ulStatus);
1493 Adapter->SelectedChip = RESET_CHIP_SELECT;
1498 //-----------------------------------------------------------------------------
1499 // Procedure: PropagateCalParamsFromEEPROMToMemory
1501 // Description: Dumps the calibration section of EEPROM to DDR.
1504 // Adapter - ptr to Adapter object instance
1508 //-----------------------------------------------------------------------------
1511 INT PropagateCalParamsFromEEPROMToMemory(PMINI_ADAPTER Adapter)
1513 PCHAR pBuff = kmalloc(BUFFER_4K, GFP_KERNEL);
1514 UINT uiEepromSize = 0;
1516 UINT uiBytesToCopy = 0;
1517 UINT uiCalStartAddr = EEPROM_CALPARAM_START;
1518 UINT uiMemoryLoc = EEPROM_CAL_DATA_INTERNAL_LOC;
1526 if(0 != BeceemEEPROMBulkRead(Adapter,&uiEepromSize,EEPROM_SIZE_OFFSET,4))
1533 uiEepromSize >>= 16;
1534 if(uiEepromSize > 1024*1024)
1541 uiBytesToCopy = MIN(BUFFER_4K,uiEepromSize);
1543 while(uiBytesToCopy)
1545 if(0 != BeceemEEPROMBulkRead(Adapter,(PUINT)pBuff,uiCalStartAddr,uiBytesToCopy))
1550 wrm(Adapter,uiMemoryLoc,(PCHAR)(((PULONG)pBuff)+uiIndex),uiBytesToCopy);
1551 uiMemoryLoc += uiBytesToCopy;
1552 uiEepromSize -= uiBytesToCopy;
1553 uiCalStartAddr += uiBytesToCopy;
1554 uiIndex += uiBytesToCopy/4;
1555 uiBytesToCopy = MIN(BUFFER_4K,uiEepromSize);
1559 wrmalt(Adapter, EEPROM_CAL_DATA_INTERNAL_LOC-4,&value, sizeof(value));
1561 wrmalt(Adapter, EEPROM_CAL_DATA_INTERNAL_LOC-8,&value, sizeof(value));
1568 //-----------------------------------------------------------------------------
1569 // Procedure: PropagateCalParamsFromFlashToMemory
1571 // Description: Dumps the calibration section of EEPROM to DDR.
1574 // Adapter - ptr to Adapter object instance
1578 //-----------------------------------------------------------------------------
1580 INT PropagateCalParamsFromFlashToMemory(PMINI_ADAPTER Adapter)
1583 UINT uiEepromSize = 0;
1584 UINT uiBytesToCopy = 0;
1586 UINT uiCalStartAddr = EEPROM_CALPARAM_START;
1587 UINT uiMemoryLoc = EEPROM_CAL_DATA_INTERNAL_LOC;
1591 // Write the signature first. This will ensure firmware does not access EEPROM.
1594 wrmalt(Adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 4, &value, sizeof(value));
1596 wrmalt(Adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 8, &value, sizeof(value));
1598 if(0 != BeceemNVMRead(Adapter,&uiEepromSize,EEPROM_SIZE_OFFSET, 4))
1602 uiEepromSize = ntohl(uiEepromSize);
1603 uiEepromSize >>= 16;
1606 // subtract the auto init section size
1608 uiEepromSize -= EEPROM_CALPARAM_START;
1610 if(uiEepromSize > 1024*1024)
1615 pBuff = kmalloc(uiEepromSize, GFP_KERNEL);
1617 if ( pBuff == NULL )
1622 if(0 != BeceemNVMRead(Adapter,(PUINT)pBuff,uiCalStartAddr, uiEepromSize))
1630 uiBytesToCopy = MIN(BUFFER_4K,uiEepromSize);
1632 while(uiBytesToCopy)
1634 Status = wrm(Adapter,uiMemoryLoc,(PCHAR)pPtr,uiBytesToCopy);
1637 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"wrm failed with status :%d",Status);
1641 pPtr += uiBytesToCopy;
1642 uiEepromSize -= uiBytesToCopy;
1643 uiMemoryLoc += uiBytesToCopy;
1644 uiBytesToCopy = MIN(BUFFER_4K,uiEepromSize);
1652 //-----------------------------------------------------------------------------
1653 // Procedure: BeceemEEPROMReadBackandVerify
1655 // Description: Read back the data written and verifies.
1658 // Adapter - ptr to Adapter object instance
1659 // pBuffer - Data to be written.
1660 // uiOffset - Offset of the flash where data needs to be written to.
1661 // uiNumBytes - Number of bytes to be written.
1665 //-----------------------------------------------------------------------------
1667 static INT BeceemEEPROMReadBackandVerify(
1668 PMINI_ADAPTER Adapter,
1676 UINT auiData[4] = {0};
1680 if(Adapter->device_removed )
1685 if(uiNumBytes >= MAX_RW_SIZE)
1686 {// for the requests more than or equal to MAX_RW_SIZE bytes, use bulk read function to make the access faster.
1687 BeceemEEPROMBulkRead(Adapter,&auiData[0],uiOffset,MAX_RW_SIZE);
1689 if(memcmp(&pBuffer[uiIndex],&auiData[0],MAX_RW_SIZE))
1692 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)(pBuffer+uiIndex),uiOffset,MAX_RW_SIZE,FALSE);
1694 BeceemEEPROMBulkRead(Adapter,&auiData[0],uiOffset,MAX_RW_SIZE);
1696 if(memcmp(&pBuffer[uiIndex],&auiData[0],MAX_RW_SIZE))
1701 uiOffset += MAX_RW_SIZE;
1702 uiNumBytes -= MAX_RW_SIZE;
1706 else if(uiNumBytes >= 4)
1708 BeceemEEPROMBulkRead(Adapter,&uiData,uiOffset,4);
1709 if(uiData != pBuffer[uiIndex])
1712 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)(pBuffer+uiIndex),uiOffset,4,FALSE);
1714 BeceemEEPROMBulkRead(Adapter,&uiData,uiOffset,4);
1715 if(uiData != pBuffer[uiIndex])
1726 { // Handle the reads less than 4 bytes...
1728 memcpy(&uiData,((PUCHAR)pBuffer)+(uiIndex*sizeof(UINT)),uiNumBytes);
1729 BeceemEEPROMBulkRead(Adapter,&uiRdbk,uiOffset,4);
1731 if(memcmp(&uiData, &uiRdbk, uiNumBytes))
1742 static VOID BcmSwapWord(UINT *ptr1) {
1744 UINT tempval = (UINT)*ptr1;
1745 char *ptr2 = (char *)&tempval;
1746 char *ptr = (char *)ptr1;
1754 //-----------------------------------------------------------------------------
1755 // Procedure: BeceemEEPROMWritePage
1757 // Description: Performs page write (16bytes) to the EEPROM
1760 // Adapter - ptr to Adapter object instance
1761 // uiData - Data to be written.
1762 // uiOffset - Offset of the EEPROM where data needs to be written to.
1766 //-----------------------------------------------------------------------------
1767 static INT BeceemEEPROMWritePage( PMINI_ADAPTER Adapter, UINT uiData[], UINT uiOffset )
1769 UINT uiRetries = MAX_EEPROM_RETRIES*RETRIES_PER_DELAY;
1771 UCHAR uiEpromStatus = 0;
1774 /* Flush the Write/Read/Cmd queues. */
1775 value = ( EEPROM_WRITE_QUEUE_FLUSH | EEPROM_CMD_QUEUE_FLUSH | EEPROM_READ_QUEUE_FLUSH );
1776 wrmalt( Adapter, SPI_FLUSH_REG, &value, sizeof(value));
1778 wrmalt( Adapter, SPI_FLUSH_REG, &value, sizeof(value) );
1780 /* Clear the Empty/Avail/Full bits. After this it has been confirmed
1781 * that the bit was cleared by reading back the register. See NOTE below.
1782 * We also clear the Read queues as we do a EEPROM status register read
1784 value = ( EEPROM_WRITE_QUEUE_EMPTY | EEPROM_WRITE_QUEUE_AVAIL | EEPROM_WRITE_QUEUE_FULL | EEPROM_READ_DATA_AVAIL | EEPROM_READ_DATA_FULL ) ;
1785 wrmalt( Adapter, EEPROM_SPI_Q_STATUS1_REG,&value, sizeof(value));
1788 value = EEPROM_WRITE_ENABLE ;
1789 wrmalt( Adapter, EEPROM_CMDQ_SPI_REG,&value, sizeof(value) );
1791 /* We can write back to back 8bits * 16 into the queue and as we have
1792 * checked for the queue to be empty we can write in a burst. */
1795 BcmSwapWord(&value);
1796 wrm( Adapter, EEPROM_WRITE_DATAQ_REG, (PUCHAR)&value, 4);
1799 BcmSwapWord(&value);
1800 wrm( Adapter, EEPROM_WRITE_DATAQ_REG, (PUCHAR)&value, 4);
1803 BcmSwapWord(&value);
1804 wrm( Adapter, EEPROM_WRITE_DATAQ_REG, (PUCHAR)&value, 4);
1807 BcmSwapWord(&value);
1808 wrm( Adapter, EEPROM_WRITE_DATAQ_REG, (PUCHAR)&value, 4);
1810 /* NOTE : After this write, on readback of EEPROM_SPI_Q_STATUS1_REG
1811 * shows that we see 7 for the EEPROM data write. Which means that
1812 * queue got full, also space is available as well as the queue is empty.
1813 * This may happen in sequence. */
1814 value = EEPROM_16_BYTE_PAGE_WRITE | uiOffset ;
1815 wrmalt( Adapter, EEPROM_CMDQ_SPI_REG, &value, sizeof(value) );
1817 /* Ideally we should loop here without tries and eventually succeed.
1818 * What we are checking if the previous write has completed, and this
1819 * may take time. We should wait till the Empty bit is set. */
1821 rdmalt( Adapter, EEPROM_SPI_Q_STATUS1_REG,&uiStatus, sizeof(uiStatus)) ;
1822 while ( ( uiStatus & EEPROM_WRITE_QUEUE_EMPTY ) == 0 )
1825 if ( uiRetries == 0 )
1827 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "0x0f003004 = %x, %d retries failed.\n", uiStatus, MAX_EEPROM_RETRIES *RETRIES_PER_DELAY);
1828 return STATUS_FAILURE ;
1831 if( !(uiRetries%RETRIES_PER_DELAY) )
1835 rdmalt( Adapter, EEPROM_SPI_Q_STATUS1_REG,&uiStatus, sizeof(uiStatus)) ;
1836 if(Adapter->device_removed == TRUE)
1838 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Modem got removed hence exiting from loop....");
1844 if ( uiRetries != 0 )
1846 /* Clear the ones that are set - either, Empty/Full/Avail bits */
1847 value = ( uiStatus & ( EEPROM_WRITE_QUEUE_EMPTY | EEPROM_WRITE_QUEUE_AVAIL | EEPROM_WRITE_QUEUE_FULL ) );
1848 wrmalt( Adapter, EEPROM_SPI_Q_STATUS1_REG, &value, sizeof(value));
1851 /* Here we should check if the EEPROM status register is correct before
1852 * proceeding. Bit 0 in the EEPROM Status register should be 0 before
1853 * we proceed further. A 1 at Bit 0 indicates that the EEPROM is busy
1854 * with the previous write. Note also that issuing this read finally
1855 * means the previous write to the EEPROM has completed. */
1856 uiRetries = MAX_EEPROM_RETRIES*RETRIES_PER_DELAY;
1858 while ( uiRetries != 0 )
1860 uiEpromStatus = ReadEEPROMStatusRegister( Adapter) ;
1861 if(Adapter->device_removed == TRUE)
1863 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Modem has got removed hence exiting from loop...");
1866 if ( ( EEPROM_STATUS_REG_WRITE_BUSY & uiEpromStatus ) == 0 )
1868 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "EEPROM status register = %x tries = %d\n", uiEpromStatus, (MAX_EEPROM_RETRIES * RETRIES_PER_DELAY- uiRetries) );
1869 return STATUS_SUCCESS ;
1872 if ( uiRetries == 0 )
1874 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);
1875 return STATUS_FAILURE ;
1878 if( !(uiRetries%RETRIES_PER_DELAY) )
1882 return STATUS_SUCCESS ;
1883 } /* BeceemEEPROMWritePage */
1886 //-----------------------------------------------------------------------------
1887 // Procedure: BeceemEEPROMBulkWrite
1889 // Description: Performs write to the EEPROM
1892 // Adapter - ptr to Adapter object instance
1893 // pBuffer - Data to be written.
1894 // uiOffset - Offset of the EEPROM where data needs to be written to.
1895 // uiNumBytes - Number of bytes to be written.
1896 // bVerify - read verify flag.
1900 //-----------------------------------------------------------------------------
1902 INT BeceemEEPROMBulkWrite(
1903 PMINI_ADAPTER Adapter,
1909 UINT uiBytesToCopy = uiNumBytes;
1911 UINT uiData[4] = {0};
1913 UINT uiTempOffset = 0;
1914 UINT uiExtraBytes = 0;
1915 //PUINT puiBuffer = (PUINT)pBuffer;
1918 if(uiOffset%MAX_RW_SIZE && uiBytesToCopy)
1920 uiTempOffset = uiOffset - (uiOffset%MAX_RW_SIZE);
1921 uiExtraBytes = uiOffset-uiTempOffset;
1924 BeceemEEPROMBulkRead(Adapter,&uiData[0],uiTempOffset,MAX_RW_SIZE);
1926 if(uiBytesToCopy >= (16 -uiExtraBytes))
1928 memcpy((((PUCHAR)&uiData[0])+uiExtraBytes),pBuffer,MAX_RW_SIZE- uiExtraBytes);
1930 if ( STATUS_FAILURE == BeceemEEPROMWritePage( Adapter, uiData, uiTempOffset ) )
1931 return STATUS_FAILURE;
1933 uiBytesToCopy -= (MAX_RW_SIZE - uiExtraBytes);
1934 uiIndex += (MAX_RW_SIZE - uiExtraBytes);
1935 uiOffset += (MAX_RW_SIZE - uiExtraBytes);
1939 memcpy((((PUCHAR)&uiData[0])+uiExtraBytes),pBuffer,uiBytesToCopy);
1941 if ( STATUS_FAILURE == BeceemEEPROMWritePage( Adapter, uiData, uiTempOffset ) )
1942 return STATUS_FAILURE;
1944 uiIndex += uiBytesToCopy;
1945 uiOffset += uiBytesToCopy;
1952 while(uiBytesToCopy)
1954 if(Adapter->device_removed)
1959 if(uiBytesToCopy >= MAX_RW_SIZE)
1962 if (STATUS_FAILURE == BeceemEEPROMWritePage( Adapter, (PUINT) &pBuffer[uiIndex], uiOffset ) )
1963 return STATUS_FAILURE;
1965 uiIndex += MAX_RW_SIZE;
1966 uiOffset += MAX_RW_SIZE;
1967 uiBytesToCopy -= MAX_RW_SIZE;
1972 // To program non 16byte aligned data, read 16byte and then update.
1974 BeceemEEPROMBulkRead(Adapter,&uiData[0],uiOffset,16);
1975 memcpy(&uiData[0],pBuffer+uiIndex,uiBytesToCopy);
1978 if ( STATUS_FAILURE == BeceemEEPROMWritePage( Adapter, uiData, uiOffset ) )
1979 return STATUS_FAILURE;
1988 //-----------------------------------------------------------------------------
1989 // Procedure: BeceemNVMRead
1991 // Description: Reads n number of bytes from NVM.
1994 // Adapter - ptr to Adapter object instance
1995 // pBuffer - Buffer to store the data read from NVM
1996 // uiOffset - Offset of NVM from where data should be read
1997 // uiNumBytes - Number of bytes to be read from the NVM.
2000 // OSAL_STATUS_SUCCESS - if NVM read is successfull.
2001 // <FAILURE> - if failed.
2002 //-----------------------------------------------------------------------------
2005 PMINI_ADAPTER Adapter,
2011 #if !defined(BCM_SHM_INTERFACE) || defined(FLASH_DIRECT_ACCESS)
2012 UINT uiTemp = 0, value;
2015 if(Adapter->eNVMType == NVM_FLASH)
2017 if(Adapter->bFlashRawRead == FALSE)
2019 if (IsSectionExistInVendorInfo(Adapter,Adapter->eActiveDSD))
2020 return vendorextnReadSection(Adapter,(PUCHAR)pBuffer,Adapter->eActiveDSD,uiOffset,uiNumBytes);
2021 uiOffset = uiOffset+ Adapter->ulFlashCalStart ;
2023 #if defined(BCM_SHM_INTERFACE) && !defined(FLASH_DIRECT_ACCESS)
2024 Status = bcmflash_raw_read((uiOffset/FLASH_PART_SIZE),(uiOffset % FLASH_PART_SIZE),( unsigned char *)pBuffer,uiNumBytes);
2027 rdmalt(Adapter, 0x0f000C80, &uiTemp, sizeof(uiTemp));
2029 wrmalt(Adapter, 0x0f000C80,&value, sizeof(value));
2030 Status = BeceemFlashBulkRead(Adapter,
2034 wrmalt(Adapter, 0x0f000C80, &uiTemp, sizeof(uiTemp));
2037 else if(Adapter->eNVMType == NVM_EEPROM)
2039 Status = BeceemEEPROMBulkRead(Adapter,
2051 //-----------------------------------------------------------------------------
2052 // Procedure: BeceemNVMWrite
2054 // Description: Writes n number of bytes to NVM.
2057 // Adapter - ptr to Adapter object instance
2058 // pBuffer - Buffer contains the data to be written.
2059 // uiOffset - Offset of NVM where data to be written to.
2060 // uiNumBytes - Number of bytes to be written..
2063 // OSAL_STATUS_SUCCESS - if NVM write is successfull.
2064 // <FAILURE> - if failed.
2065 //-----------------------------------------------------------------------------
2068 PMINI_ADAPTER Adapter,
2076 UINT uiMemoryLoc = EEPROM_CAL_DATA_INTERNAL_LOC;
2078 #if !defined(BCM_SHM_INTERFACE) || defined(FLASH_DIRECT_ACCESS)
2081 UINT uiFlashOffset = 0;
2083 if(Adapter->eNVMType == NVM_FLASH)
2085 if (IsSectionExistInVendorInfo(Adapter,Adapter->eActiveDSD))
2086 Status = vendorextnWriteSection(Adapter,(PUCHAR)pBuffer,Adapter->eActiveDSD,uiOffset,uiNumBytes,bVerify);
2089 uiFlashOffset = uiOffset + Adapter->ulFlashCalStart;
2091 #if defined(BCM_SHM_INTERFACE) && !defined(FLASH_DIRECT_ACCESS)
2092 Status = bcmflash_raw_write((uiFlashOffset/FLASH_PART_SIZE), (uiFlashOffset % FLASH_PART_SIZE), (unsigned char *)pBuffer,uiNumBytes);
2094 rdmalt(Adapter, 0x0f000C80, &uiTemp, sizeof(uiTemp));
2096 wrmalt(Adapter, 0x0f000C80, &value, sizeof(value));
2098 if(Adapter->bStatusWrite == TRUE)
2100 Status = BeceemFlashBulkWriteStatus(Adapter,
2109 Status = BeceemFlashBulkWrite(Adapter,
2119 if(uiOffset >= EEPROM_CALPARAM_START)
2121 uiMemoryLoc += (uiOffset - EEPROM_CALPARAM_START);
2124 if(uiNumBytes > BUFFER_4K)
2126 wrm(Adapter,(uiMemoryLoc+uiIndex),(PCHAR)(pBuffer+(uiIndex/4)),BUFFER_4K);
2127 uiNumBytes -= BUFFER_4K;
2128 uiIndex += BUFFER_4K;
2132 wrm(Adapter,uiMemoryLoc+uiIndex,(PCHAR)(pBuffer+(uiIndex/4)),uiNumBytes);
2140 if((uiOffset+uiNumBytes) > EEPROM_CALPARAM_START)
2142 ULONG ulBytesTobeSkipped = 0;
2143 PUCHAR pcBuffer = (PUCHAR)pBuffer;// char pointer to take care of odd byte cases.
2144 uiNumBytes -= (EEPROM_CALPARAM_START - uiOffset);
2145 ulBytesTobeSkipped += (EEPROM_CALPARAM_START - uiOffset);
2146 uiOffset += (EEPROM_CALPARAM_START - uiOffset);
2149 if(uiNumBytes > BUFFER_4K)
2151 wrm(Adapter,uiMemoryLoc+uiIndex,(PCHAR )&pcBuffer[ulBytesTobeSkipped+uiIndex],BUFFER_4K);
2152 uiNumBytes -= BUFFER_4K;
2153 uiIndex += BUFFER_4K;
2157 wrm(Adapter,uiMemoryLoc+uiIndex,(PCHAR)&pcBuffer[ulBytesTobeSkipped+uiIndex],uiNumBytes);
2166 // restore the values.
2167 wrmalt(Adapter,0x0f000C80,&uiTemp, sizeof(uiTemp));
2169 else if(Adapter->eNVMType == NVM_EEPROM)
2171 Status = BeceemEEPROMBulkWrite(Adapter,
2178 Status = BeceemEEPROMReadBackandVerify(Adapter,(PUINT)pBuffer,uiOffset,uiNumBytes);
2188 //-----------------------------------------------------------------------------
2189 // Procedure: BcmUpdateSectorSize
2191 // Description: Updates the sector size to FLASH.
2194 // Adapter - ptr to Adapter object instance
2195 // uiSectorSize - sector size
2198 // OSAL_STATUS_SUCCESS - if NVM write is successfull.
2199 // <FAILURE> - if failed.
2200 //-----------------------------------------------------------------------------
2202 INT BcmUpdateSectorSize(PMINI_ADAPTER Adapter,UINT uiSectorSize)
2205 FLASH_CS_INFO sFlashCsInfo = {0};
2208 UINT uiSectorSig = 0;
2209 UINT uiCurrentSectorSize = 0;
2215 rdmalt(Adapter, 0x0f000C80, &uiTemp, sizeof(uiTemp));
2217 wrmalt(Adapter, 0x0f000C80,&value, sizeof(value));
2220 // Before updating the sector size in the reserved area, check if already present.
2222 BeceemFlashBulkRead(Adapter,(PUINT)&sFlashCsInfo,Adapter->ulFlashControlSectionStart,sizeof(sFlashCsInfo));
2223 uiSectorSig = ntohl(sFlashCsInfo.FlashSectorSizeSig);
2224 uiCurrentSectorSize = ntohl(sFlashCsInfo.FlashSectorSize);
2226 if(uiSectorSig == FLASH_SECTOR_SIZE_SIG)
2229 if((uiCurrentSectorSize <= MAX_SECTOR_SIZE) && (uiCurrentSectorSize >= MIN_SECTOR_SIZE))
2231 if(uiSectorSize == uiCurrentSectorSize)
2233 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Provided sector size is same as programmed in Flash");
2234 Status = STATUS_SUCCESS;
2240 if((uiSectorSize <= MAX_SECTOR_SIZE) && (uiSectorSize >= MIN_SECTOR_SIZE))
2243 sFlashCsInfo.FlashSectorSize = htonl(uiSectorSize);
2244 sFlashCsInfo.FlashSectorSizeSig = htonl(FLASH_SECTOR_SIZE_SIG);
2246 Status = BeceemFlashBulkWrite(Adapter,
2247 (PUINT)&sFlashCsInfo,
2248 Adapter->ulFlashControlSectionStart,
2249 sizeof(sFlashCsInfo),
2256 // restore the values.
2257 wrmalt(Adapter, 0x0f000C80,&uiTemp, sizeof(uiTemp));
2264 //-----------------------------------------------------------------------------
2265 // Procedure: BcmGetFlashSectorSize
2267 // Description: Finds the sector size of the FLASH.
2270 // Adapter - ptr to Adapter object instance
2273 // UINT - sector size.
2275 //-----------------------------------------------------------------------------
2277 UINT BcmGetFlashSectorSize(PMINI_ADAPTER Adapter, UINT FlashSectorSizeSig, UINT FlashSectorSize)
2279 UINT uiSectorSize = 0;
2280 UINT uiSectorSig = 0;
2282 if(Adapter->bSectorSizeOverride &&
2283 (Adapter->uiSectorSizeInCFG <= MAX_SECTOR_SIZE &&
2284 Adapter->uiSectorSizeInCFG >= MIN_SECTOR_SIZE))
2286 Adapter->uiSectorSize = Adapter->uiSectorSizeInCFG;
2291 uiSectorSig = FlashSectorSizeSig;
2293 if(uiSectorSig == FLASH_SECTOR_SIZE_SIG)
2295 uiSectorSize = FlashSectorSize;
2297 // If the sector size stored in the FLASH makes sense then use it.
2299 if(uiSectorSize <= MAX_SECTOR_SIZE && uiSectorSize >= MIN_SECTOR_SIZE)
2301 Adapter->uiSectorSize = uiSectorSize;
2303 //No valid size in FLASH, check if Config file has it.
2304 else if(Adapter->uiSectorSizeInCFG <= MAX_SECTOR_SIZE &&
2305 Adapter->uiSectorSizeInCFG >= MIN_SECTOR_SIZE)
2307 Adapter->uiSectorSize = Adapter->uiSectorSizeInCFG;
2309 // Init to Default, if none of the above works.
2312 Adapter->uiSectorSize = DEFAULT_SECTOR_SIZE;
2318 if(Adapter->uiSectorSizeInCFG <= MAX_SECTOR_SIZE &&
2319 Adapter->uiSectorSizeInCFG >= MIN_SECTOR_SIZE)
2321 Adapter->uiSectorSize = Adapter->uiSectorSizeInCFG;
2325 Adapter->uiSectorSize = DEFAULT_SECTOR_SIZE;
2330 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Sector size :%x \n", Adapter->uiSectorSize);
2331 return Adapter->uiSectorSize;
2334 //-----------------------------------------------------------------------------
2335 // Procedure: BcmInitEEPROMQueues
2337 // Description: Initialization of EEPROM queues.
2340 // Adapter - ptr to Adapter object instance
2343 // <OSAL_STATUS_CODE>
2344 //-----------------------------------------------------------------------------
2346 static INT BcmInitEEPROMQueues(PMINI_ADAPTER Adapter)
2349 /* CHIP Bug : Clear the Avail bits on the Read queue. The default
2350 * value on this register is supposed to be 0x00001102.
2351 * But we get 0x00001122. */
2352 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Fixing reset value on 0x0f003004 register\n" );
2353 value = EEPROM_READ_DATA_AVAIL;
2354 wrmalt( Adapter, EEPROM_SPI_Q_STATUS1_REG, &value, sizeof(value));
2356 /* Flush the all the EEPROM queues. */
2357 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, " Flushing the queues\n");
2358 value =EEPROM_ALL_QUEUE_FLUSH ;
2359 wrmalt( Adapter, SPI_FLUSH_REG, &value, sizeof(value));
2362 wrmalt( Adapter, SPI_FLUSH_REG, &value, sizeof(value) );
2364 /* Read the EEPROM Status Register. Just to see, no real purpose. */
2365 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "EEPROM Status register value = %x\n", ReadEEPROMStatusRegister(Adapter) );
2367 return STATUS_SUCCESS;
2368 } /* BcmInitEEPROMQueues() */
2370 //-----------------------------------------------------------------------------
2371 // Procedure: BcmInitNVM
2373 // Description: Initialization of NVM, EEPROM size,FLASH size, sector size etc.
2376 // Adapter - ptr to Adapter object instance
2379 // <OSAL_STATUS_CODE>
2380 //-----------------------------------------------------------------------------
2382 INT BcmInitNVM(PMINI_ADAPTER ps_adapter)
2384 BcmValidateNvmType(ps_adapter);
2385 BcmInitEEPROMQueues(ps_adapter);
2387 if(ps_adapter->eNVMType == NVM_AUTODETECT)
2389 ps_adapter->eNVMType = BcmGetNvmType(ps_adapter);
2390 if(ps_adapter->eNVMType == NVM_UNKNOWN)
2392 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_PRINTK, 0, 0, "NVM Type is unknown!!\n");
2395 else if(ps_adapter->eNVMType == NVM_FLASH)
2397 BcmGetFlashCSInfo(ps_adapter);
2400 BcmGetNvmSize(ps_adapter);
2402 return STATUS_SUCCESS;
2404 /***************************************************************************/
2405 /*BcmGetNvmSize : set the EEPROM or flash size in Adapter.
2408 * Adapter data structure
2412 /***************************************************************************/
2414 INT BcmGetNvmSize(PMINI_ADAPTER Adapter)
2416 if(Adapter->eNVMType == NVM_EEPROM)
2418 Adapter->uiNVMDSDSize = BcmGetEEPROMSize(Adapter);
2420 else if(Adapter->eNVMType == NVM_FLASH)
2422 Adapter->uiNVMDSDSize = BcmGetFlashSize(Adapter);
2427 //-----------------------------------------------------------------------------
2428 // Procedure: BcmValidateNvm
2430 // Description: Validates the NVM Type option selected against the device
2433 // Adapter - ptr to Adapter object instance
2437 //-----------------------------------------------------------------------------
2438 VOID BcmValidateNvmType(PMINI_ADAPTER Adapter)
2442 // if forcing the FLASH through CFG file, we should ensure device really has a FLASH.
2443 // Accessing the FLASH address without the FLASH being present can cause hang/freeze etc.
2444 // So if NVM_FLASH is selected for older chipsets, change it to AUTODETECT where EEPROM is 1st choice.
2447 if(Adapter->eNVMType == NVM_FLASH &&
2448 Adapter->chip_id < 0xBECE3300)
2450 Adapter->eNVMType = NVM_AUTODETECT;
2453 //-----------------------------------------------------------------------------
2454 // Procedure: BcmReadFlashRDID
2456 // Description: Reads ID from Serial Flash
2459 // Adapter - ptr to Adapter object instance
2463 //-----------------------------------------------------------------------------
2464 static ULONG BcmReadFlashRDID(PMINI_ADAPTER Adapter)
2469 // Read ID Instruction.
2471 value = (FLASH_CMD_READ_ID<<24);
2472 wrmalt(Adapter, FLASH_SPI_CMDQ_REG,&value, sizeof(value));
2477 // Read SPI READQ REG. The output will be WWXXYYZZ.
2478 // The ID is 3Bytes long and is WWXXYY. ZZ needs to be Ignored.
2480 rdmalt(Adapter, FLASH_SPI_READQ_REG,(PUINT)&ulRDID, sizeof(ulRDID));
2482 return (ulRDID >>8);
2487 INT BcmAllocFlashCSStructure(PMINI_ADAPTER psAdapter)
2489 if(psAdapter == NULL)
2491 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_PRINTK, 0, 0, "Adapter structure point is NULL");
2494 psAdapter->psFlashCSInfo = (PFLASH_CS_INFO)kzalloc(sizeof(FLASH_CS_INFO), GFP_KERNEL);
2495 if(psAdapter->psFlashCSInfo == NULL)
2497 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_PRINTK, 0, 0,"Can't Allocate memory for Flash 1.x");
2501 psAdapter->psFlash2xCSInfo = (PFLASH2X_CS_INFO)kzalloc(sizeof(FLASH2X_CS_INFO), GFP_KERNEL);
2502 if(psAdapter->psFlash2xCSInfo == NULL)
2504 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_PRINTK, 0, 0,"Can't Allocate memory for Flash 2.x");
2505 kfree(psAdapter->psFlashCSInfo);
2509 psAdapter->psFlash2xVendorInfo = (PFLASH2X_VENDORSPECIFIC_INFO)kzalloc(sizeof(FLASH2X_VENDORSPECIFIC_INFO), GFP_KERNEL);
2510 if(psAdapter->psFlash2xVendorInfo == NULL)
2512 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_PRINTK, 0, 0,"Can't Allocate Vendor Info Memory for Flash 2.x");
2513 kfree(psAdapter->psFlashCSInfo);
2514 kfree(psAdapter->psFlash2xCSInfo);
2518 return STATUS_SUCCESS;
2521 INT BcmDeAllocFlashCSStructure(PMINI_ADAPTER psAdapter)
2523 if(psAdapter == NULL)
2525 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_PRINTK, 0, 0," Adapter structure point is NULL");
2528 kfree(psAdapter->psFlashCSInfo);
2529 kfree(psAdapter->psFlash2xCSInfo);
2530 kfree(psAdapter->psFlash2xVendorInfo);
2531 return STATUS_SUCCESS ;
2534 static INT BcmDumpFlash2XCSStructure(PFLASH2X_CS_INFO psFlash2xCSInfo,PMINI_ADAPTER Adapter)
2537 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "**********************FLASH2X CS Structure *******************");
2538 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Signature is :%x", (psFlash2xCSInfo->MagicNumber));
2539 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Flash Major Version :%d", MAJOR_VERSION(psFlash2xCSInfo->FlashLayoutVersion));
2540 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Flash Minor Version :%d", MINOR_VERSION(psFlash2xCSInfo->FlashLayoutVersion));
2541 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, " ISOImageMajorVersion:0x%x", (psFlash2xCSInfo->ISOImageVersion));
2542 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "SCSIFirmwareMajorVersion :0x%x", (psFlash2xCSInfo->SCSIFirmwareVersion));
2543 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForPart1ISOImage :0x%x", (psFlash2xCSInfo->OffsetFromZeroForPart1ISOImage));
2544 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForScsiFirmware :0x%x", (psFlash2xCSInfo->OffsetFromZeroForScsiFirmware));
2545 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "SizeOfScsiFirmware :0x%x", (psFlash2xCSInfo->SizeOfScsiFirmware ));
2546 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForPart2ISOImage :0x%x", (psFlash2xCSInfo->OffsetFromZeroForPart2ISOImage));
2547 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForDSDStart :0x%x", (psFlash2xCSInfo->OffsetFromZeroForDSDStart));
2548 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForDSDEnd :0x%x", (psFlash2xCSInfo->OffsetFromZeroForDSDEnd));
2549 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForVSAStart :0x%x", (psFlash2xCSInfo->OffsetFromZeroForVSAStart));
2550 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForVSAEnd :0x%x", (psFlash2xCSInfo->OffsetFromZeroForVSAEnd));
2551 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForControlSectionStart :0x%x", (psFlash2xCSInfo->OffsetFromZeroForControlSectionStart));
2552 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForControlSectionData :0x%x", (psFlash2xCSInfo->OffsetFromZeroForControlSectionData));
2553 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "CDLessInactivityTimeout :0x%x", (psFlash2xCSInfo->CDLessInactivityTimeout));
2554 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "NewImageSignature :0x%x", (psFlash2xCSInfo->NewImageSignature));
2555 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "FlashSectorSizeSig :0x%x", (psFlash2xCSInfo->FlashSectorSizeSig));
2556 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "FlashSectorSize :0x%x", (psFlash2xCSInfo->FlashSectorSize));
2557 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "FlashWriteSupportSize :0x%x", (psFlash2xCSInfo->FlashWriteSupportSize));
2558 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "TotalFlashSize :0x%X", (psFlash2xCSInfo->TotalFlashSize));
2559 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "FlashBaseAddr :0x%x", (psFlash2xCSInfo->FlashBaseAddr));
2560 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "FlashPartMaxSize :0x%x", (psFlash2xCSInfo->FlashPartMaxSize));
2561 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "IsCDLessDeviceBootSig :0x%x", (psFlash2xCSInfo->IsCDLessDeviceBootSig));
2562 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "MassStorageTimeout :0x%x", (psFlash2xCSInfo->MassStorageTimeout));
2563 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetISOImage1Part1Start :0x%x", (psFlash2xCSInfo->OffsetISOImage1Part1Start));
2564 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetISOImage1Part1End :0x%x", (psFlash2xCSInfo->OffsetISOImage1Part1End));
2565 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetISOImage1Part2Start :0x%x", (psFlash2xCSInfo->OffsetISOImage1Part2Start));
2566 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetISOImage1Part2End :0x%x", (psFlash2xCSInfo->OffsetISOImage1Part2End));
2567 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetISOImage1Part3Start :0x%x", (psFlash2xCSInfo->OffsetISOImage1Part3Start));
2568 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetISOImage1Part3End :0x%x", (psFlash2xCSInfo->OffsetISOImage1Part3End));
2569 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetISOImage2Part1Start :0x%x", (psFlash2xCSInfo->OffsetISOImage2Part1Start));
2570 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetISOImage2Part1End :0x%x", (psFlash2xCSInfo->OffsetISOImage2Part1End));
2571 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetISOImage2Part2Start :0x%x", (psFlash2xCSInfo->OffsetISOImage2Part2Start));
2572 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetISOImage2Part2End :0x%x", (psFlash2xCSInfo->OffsetISOImage2Part2End));
2573 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetISOImage2Part3Start :0x%x", (psFlash2xCSInfo->OffsetISOImage2Part3Start));
2574 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetISOImage2Part3End :0x%x", (psFlash2xCSInfo->OffsetISOImage2Part3End));
2575 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromDSDStartForDSDHeader :0x%x", (psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader));
2576 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForDSD1Start :0x%x", (psFlash2xCSInfo->OffsetFromZeroForDSD1Start));
2577 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForDSD1End :0x%x", (psFlash2xCSInfo->OffsetFromZeroForDSD1End));
2578 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForDSD2Start :0x%x", (psFlash2xCSInfo->OffsetFromZeroForDSD2Start));
2579 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForDSD2End :0x%x", (psFlash2xCSInfo->OffsetFromZeroForDSD2End));
2580 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForVSA1Start :0x%x", (psFlash2xCSInfo->OffsetFromZeroForVSA1Start));
2581 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForVSA1End :0x%x", (psFlash2xCSInfo->OffsetFromZeroForVSA1End));
2582 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForVSA2Start :0x%x", (psFlash2xCSInfo->OffsetFromZeroForVSA2Start));
2583 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForVSA2End :0x%x", (psFlash2xCSInfo->OffsetFromZeroForVSA2End));
2584 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Sector Access Bit Map is Defined as :");
2585 for(Index =0; Index <(FLASH2X_TOTAL_SIZE/(DEFAULT_SECTOR_SIZE *16)); Index++)
2587 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "SectorAccessBitMap[%d] :0x%x", Index,
2588 (psFlash2xCSInfo->SectorAccessBitMap[Index]));
2591 return STATUS_SUCCESS;
2595 static INT ConvertEndianOf2XCSStructure(PFLASH2X_CS_INFO psFlash2xCSInfo)
2598 psFlash2xCSInfo->MagicNumber = ntohl(psFlash2xCSInfo->MagicNumber);
2599 psFlash2xCSInfo->FlashLayoutVersion= ntohl(psFlash2xCSInfo->FlashLayoutVersion);
2600 //psFlash2xCSInfo->FlashLayoutMinorVersion = ntohs(psFlash2xCSInfo->FlashLayoutMinorVersion);
2601 psFlash2xCSInfo->ISOImageVersion = ntohl(psFlash2xCSInfo->ISOImageVersion);
2602 psFlash2xCSInfo->SCSIFirmwareVersion =ntohl(psFlash2xCSInfo->SCSIFirmwareVersion);
2603 psFlash2xCSInfo->OffsetFromZeroForPart1ISOImage = ntohl(psFlash2xCSInfo->OffsetFromZeroForPart1ISOImage);
2604 psFlash2xCSInfo->OffsetFromZeroForScsiFirmware = ntohl(psFlash2xCSInfo->OffsetFromZeroForScsiFirmware);
2605 psFlash2xCSInfo->SizeOfScsiFirmware = ntohl(psFlash2xCSInfo->SizeOfScsiFirmware );
2606 psFlash2xCSInfo->OffsetFromZeroForPart2ISOImage = ntohl(psFlash2xCSInfo->OffsetFromZeroForPart2ISOImage);
2607 psFlash2xCSInfo->OffsetFromZeroForDSDStart = ntohl(psFlash2xCSInfo->OffsetFromZeroForDSDStart);
2608 psFlash2xCSInfo->OffsetFromZeroForDSDEnd = ntohl(psFlash2xCSInfo->OffsetFromZeroForDSDEnd);
2609 psFlash2xCSInfo->OffsetFromZeroForVSAStart = ntohl(psFlash2xCSInfo->OffsetFromZeroForVSAStart);
2610 psFlash2xCSInfo->OffsetFromZeroForVSAEnd = ntohl(psFlash2xCSInfo->OffsetFromZeroForVSAEnd);
2611 psFlash2xCSInfo->OffsetFromZeroForControlSectionStart = ntohl(psFlash2xCSInfo->OffsetFromZeroForControlSectionStart);
2612 psFlash2xCSInfo->OffsetFromZeroForControlSectionData = ntohl(psFlash2xCSInfo->OffsetFromZeroForControlSectionData);
2613 psFlash2xCSInfo->CDLessInactivityTimeout = ntohl(psFlash2xCSInfo->CDLessInactivityTimeout);
2614 psFlash2xCSInfo->NewImageSignature = ntohl(psFlash2xCSInfo->NewImageSignature);
2615 psFlash2xCSInfo->FlashSectorSizeSig = ntohl(psFlash2xCSInfo->FlashSectorSizeSig);
2616 psFlash2xCSInfo->FlashSectorSize = ntohl(psFlash2xCSInfo->FlashSectorSize);
2617 psFlash2xCSInfo->FlashWriteSupportSize = ntohl(psFlash2xCSInfo->FlashWriteSupportSize);
2618 psFlash2xCSInfo->TotalFlashSize = ntohl(psFlash2xCSInfo->TotalFlashSize);
2619 psFlash2xCSInfo->FlashBaseAddr = ntohl(psFlash2xCSInfo->FlashBaseAddr);
2620 psFlash2xCSInfo->FlashPartMaxSize = ntohl(psFlash2xCSInfo->FlashPartMaxSize);
2621 psFlash2xCSInfo->IsCDLessDeviceBootSig = ntohl(psFlash2xCSInfo->IsCDLessDeviceBootSig);
2622 psFlash2xCSInfo->MassStorageTimeout = ntohl(psFlash2xCSInfo->MassStorageTimeout);
2623 psFlash2xCSInfo->OffsetISOImage1Part1Start = ntohl(psFlash2xCSInfo->OffsetISOImage1Part1Start);
2624 psFlash2xCSInfo->OffsetISOImage1Part1End = ntohl(psFlash2xCSInfo->OffsetISOImage1Part1End);
2625 psFlash2xCSInfo->OffsetISOImage1Part2Start = ntohl(psFlash2xCSInfo->OffsetISOImage1Part2Start);
2626 psFlash2xCSInfo->OffsetISOImage1Part2End = ntohl(psFlash2xCSInfo->OffsetISOImage1Part2End);
2627 psFlash2xCSInfo->OffsetISOImage1Part3Start = ntohl(psFlash2xCSInfo->OffsetISOImage1Part3Start);
2628 psFlash2xCSInfo->OffsetISOImage1Part3End = ntohl(psFlash2xCSInfo->OffsetISOImage1Part3End);
2629 psFlash2xCSInfo->OffsetISOImage2Part1Start = ntohl(psFlash2xCSInfo->OffsetISOImage2Part1Start);
2630 psFlash2xCSInfo->OffsetISOImage2Part1End = ntohl(psFlash2xCSInfo->OffsetISOImage2Part1End);
2631 psFlash2xCSInfo->OffsetISOImage2Part2Start = ntohl(psFlash2xCSInfo->OffsetISOImage2Part2Start);
2632 psFlash2xCSInfo->OffsetISOImage2Part2End = ntohl(psFlash2xCSInfo->OffsetISOImage2Part2End);
2633 psFlash2xCSInfo->OffsetISOImage2Part3Start = ntohl(psFlash2xCSInfo->OffsetISOImage2Part3Start);
2634 psFlash2xCSInfo->OffsetISOImage2Part3End = ntohl(psFlash2xCSInfo->OffsetISOImage2Part3End);
2635 psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader = ntohl(psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader);
2636 psFlash2xCSInfo->OffsetFromZeroForDSD1Start = ntohl(psFlash2xCSInfo->OffsetFromZeroForDSD1Start);
2637 psFlash2xCSInfo->OffsetFromZeroForDSD1End = ntohl(psFlash2xCSInfo->OffsetFromZeroForDSD1End);
2638 psFlash2xCSInfo->OffsetFromZeroForDSD2Start = ntohl(psFlash2xCSInfo->OffsetFromZeroForDSD2Start);
2639 psFlash2xCSInfo->OffsetFromZeroForDSD2End = ntohl(psFlash2xCSInfo->OffsetFromZeroForDSD2End);
2640 psFlash2xCSInfo->OffsetFromZeroForVSA1Start = ntohl(psFlash2xCSInfo->OffsetFromZeroForVSA1Start);
2641 psFlash2xCSInfo->OffsetFromZeroForVSA1End = ntohl(psFlash2xCSInfo->OffsetFromZeroForVSA1End);
2642 psFlash2xCSInfo->OffsetFromZeroForVSA2Start = ntohl(psFlash2xCSInfo->OffsetFromZeroForVSA2Start);
2643 psFlash2xCSInfo->OffsetFromZeroForVSA2End = ntohl(psFlash2xCSInfo->OffsetFromZeroForVSA2End);
2644 for(Index =0; Index <(FLASH2X_TOTAL_SIZE/(DEFAULT_SECTOR_SIZE *16)); Index++)
2646 psFlash2xCSInfo->SectorAccessBitMap[Index] = ntohl(psFlash2xCSInfo->SectorAccessBitMap[Index]);
2648 return STATUS_SUCCESS;
2651 static INT ConvertEndianOfCSStructure(PFLASH_CS_INFO psFlashCSInfo)
2654 psFlashCSInfo->MagicNumber =ntohl(psFlashCSInfo->MagicNumber);
2655 psFlashCSInfo->FlashLayoutVersion =ntohl(psFlashCSInfo->FlashLayoutVersion);
2656 psFlashCSInfo->ISOImageVersion = ntohl(psFlashCSInfo->ISOImageVersion);
2657 //won't convert according to old assumption
2658 psFlashCSInfo->SCSIFirmwareVersion =(psFlashCSInfo->SCSIFirmwareVersion);
2660 psFlashCSInfo->OffsetFromZeroForPart1ISOImage = ntohl(psFlashCSInfo->OffsetFromZeroForPart1ISOImage);
2661 psFlashCSInfo->OffsetFromZeroForScsiFirmware = ntohl(psFlashCSInfo->OffsetFromZeroForScsiFirmware);
2662 psFlashCSInfo->SizeOfScsiFirmware = ntohl(psFlashCSInfo->SizeOfScsiFirmware );
2663 psFlashCSInfo->OffsetFromZeroForPart2ISOImage = ntohl(psFlashCSInfo->OffsetFromZeroForPart2ISOImage);
2664 psFlashCSInfo->OffsetFromZeroForCalibrationStart = ntohl(psFlashCSInfo->OffsetFromZeroForCalibrationStart);
2665 psFlashCSInfo->OffsetFromZeroForCalibrationEnd = ntohl(psFlashCSInfo->OffsetFromZeroForCalibrationEnd);
2666 psFlashCSInfo->OffsetFromZeroForVSAStart = ntohl(psFlashCSInfo->OffsetFromZeroForVSAStart);
2667 psFlashCSInfo->OffsetFromZeroForVSAEnd = ntohl(psFlashCSInfo->OffsetFromZeroForVSAEnd);
2668 psFlashCSInfo->OffsetFromZeroForControlSectionStart = ntohl(psFlashCSInfo->OffsetFromZeroForControlSectionStart);
2669 psFlashCSInfo->OffsetFromZeroForControlSectionData = ntohl(psFlashCSInfo->OffsetFromZeroForControlSectionData);
2670 psFlashCSInfo->CDLessInactivityTimeout = ntohl(psFlashCSInfo->CDLessInactivityTimeout);
2671 psFlashCSInfo->NewImageSignature = ntohl(psFlashCSInfo->NewImageSignature);
2672 psFlashCSInfo->FlashSectorSizeSig = ntohl(psFlashCSInfo->FlashSectorSizeSig);
2673 psFlashCSInfo->FlashSectorSize = ntohl(psFlashCSInfo->FlashSectorSize);
2674 psFlashCSInfo->FlashWriteSupportSize = ntohl(psFlashCSInfo->FlashWriteSupportSize);
2675 psFlashCSInfo->TotalFlashSize = ntohl(psFlashCSInfo->TotalFlashSize);
2676 psFlashCSInfo->FlashBaseAddr = ntohl(psFlashCSInfo->FlashBaseAddr);
2677 psFlashCSInfo->FlashPartMaxSize = ntohl(psFlashCSInfo->FlashPartMaxSize);
2678 psFlashCSInfo->IsCDLessDeviceBootSig = ntohl(psFlashCSInfo->IsCDLessDeviceBootSig);
2679 psFlashCSInfo->MassStorageTimeout = ntohl(psFlashCSInfo->MassStorageTimeout);
2681 return STATUS_SUCCESS;
2684 INT IsSectionExistInVendorInfo(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL section)
2686 return ( Adapter->uiVendorExtnFlag &&
2687 (Adapter->psFlash2xVendorInfo->VendorSection[section].AccessFlags & FLASH2X_SECTION_PRESENT) &&
2688 (Adapter->psFlash2xVendorInfo->VendorSection[section].OffsetFromZeroForSectionStart != UNINIT_PTR_IN_CS) );
2691 static VOID UpdateVendorInfo(PMINI_ADAPTER Adapter)
2694 UINT uiSizeSection = 0;
2696 Adapter->uiVendorExtnFlag = FALSE;
2698 for(i = 0;i < TOTAL_SECTIONS;i++)
2699 Adapter->psFlash2xVendorInfo->VendorSection[i].OffsetFromZeroForSectionStart = UNINIT_PTR_IN_CS;
2701 if(STATUS_SUCCESS != vendorextnGetSectionInfo(Adapter, Adapter->psFlash2xVendorInfo))
2705 while(i < TOTAL_SECTIONS)
2707 if(!(Adapter->psFlash2xVendorInfo->VendorSection[i].AccessFlags & FLASH2X_SECTION_PRESENT))
2713 Adapter->uiVendorExtnFlag = TRUE;
2714 uiSizeSection = (Adapter->psFlash2xVendorInfo->VendorSection[i].OffsetFromZeroForSectionEnd -
2715 Adapter->psFlash2xVendorInfo->VendorSection[i].OffsetFromZeroForSectionStart);
2720 if(( uiSizeSection >= (Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + sizeof(DSD_HEADER))) &&
2721 (UNINIT_PTR_IN_CS != Adapter->psFlash2xVendorInfo->VendorSection[i].OffsetFromZeroForSectionStart))
2722 Adapter->psFlash2xCSInfo->OffsetFromZeroForDSDStart = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSDEnd = VENDOR_PTR_IN_CS;
2724 Adapter->psFlash2xCSInfo->OffsetFromZeroForDSDStart = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSDEnd = UNINIT_PTR_IN_CS;
2728 if(( uiSizeSection >= (Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + sizeof(DSD_HEADER))) &&
2729 (UNINIT_PTR_IN_CS != Adapter->psFlash2xVendorInfo->VendorSection[i].OffsetFromZeroForSectionStart))
2730 Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD1Start = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD1End = VENDOR_PTR_IN_CS;
2732 Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD1Start = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD1End = UNINIT_PTR_IN_CS;
2736 if(( uiSizeSection >= (Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + sizeof(DSD_HEADER))) &&
2737 (UNINIT_PTR_IN_CS != Adapter->psFlash2xVendorInfo->VendorSection[i].OffsetFromZeroForSectionStart))
2738 Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD2Start = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD2End = VENDOR_PTR_IN_CS;
2740 Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD2Start = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD2End = UNINIT_PTR_IN_CS;
2743 if(UNINIT_PTR_IN_CS != Adapter->psFlash2xVendorInfo->VendorSection[i].OffsetFromZeroForSectionStart)
2744 Adapter->psFlash2xCSInfo->OffsetFromZeroForVSAStart = Adapter->psFlash2xCSInfo->OffsetFromZeroForVSAEnd = VENDOR_PTR_IN_CS;
2746 Adapter->psFlash2xCSInfo->OffsetFromZeroForVSAStart = Adapter->psFlash2xCSInfo->OffsetFromZeroForVSAEnd = UNINIT_PTR_IN_CS;
2750 if(UNINIT_PTR_IN_CS != Adapter->psFlash2xVendorInfo->VendorSection[i].OffsetFromZeroForSectionStart)
2751 Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA1Start = Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA1End = VENDOR_PTR_IN_CS;
2753 Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA1Start = Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA1End = UNINIT_PTR_IN_CS;
2756 if(UNINIT_PTR_IN_CS != Adapter->psFlash2xVendorInfo->VendorSection[i].OffsetFromZeroForSectionStart)
2757 Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA2Start = Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA2End = VENDOR_PTR_IN_CS;
2759 Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA2Start = Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA2End = UNINIT_PTR_IN_CS;
2770 //-----------------------------------------------------------------------------
2771 // Procedure: BcmGetFlashCSInfo
2773 // Description: Reads control structure and gets Cal section addresses.
2776 // Adapter - ptr to Adapter object instance
2780 //-----------------------------------------------------------------------------
2782 INT BcmGetFlashCSInfo(PMINI_ADAPTER Adapter)
2784 //FLASH_CS_INFO sFlashCsInfo = {0};
2786 #if !defined(BCM_SHM_INTERFACE) || defined(FLASH_DIRECT_ACCESS)
2789 UINT uiFlashLayoutMajorVersion;
2790 Adapter->uiFlashLayoutMinorVersion = 0;
2791 Adapter->uiFlashLayoutMajorVersion = 0;
2792 Adapter->ulFlashControlSectionStart = FLASH_CS_INFO_START_ADDR;
2795 Adapter->uiFlashBaseAdd = 0;
2796 Adapter->ulFlashCalStart = 0;
2797 memset(Adapter->psFlashCSInfo, 0 ,sizeof(FLASH_CS_INFO));
2798 memset(Adapter->psFlash2xCSInfo, 0 ,sizeof(FLASH2X_CS_INFO));
2800 if(!Adapter->bDDRInitDone)
2803 value = FLASH_CONTIGIOUS_START_ADDR_BEFORE_INIT;
2804 wrmalt(Adapter, 0xAF00A080, &value, sizeof(value));
2809 // Reading first 8 Bytes to get the Flash Layout
2810 // MagicNumber(4 bytes) +FlashLayoutMinorVersion(2 Bytes) +FlashLayoutMajorVersion(2 Bytes)
2811 BeceemFlashBulkRead(Adapter,(PUINT)Adapter->psFlashCSInfo,Adapter->ulFlashControlSectionStart,8);
2813 Adapter->psFlashCSInfo->FlashLayoutVersion = ntohl(Adapter->psFlashCSInfo->FlashLayoutVersion);
2814 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Flash Layout Version :%X", (Adapter->psFlashCSInfo->FlashLayoutVersion));
2815 //BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Flash Layout Minor Version :%d\n", ntohs(sFlashCsInfo.FlashLayoutMinorVersion));
2816 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Signature is :%x\n", ntohl(Adapter->psFlashCSInfo->MagicNumber));
2818 if(FLASH_CONTROL_STRUCT_SIGNATURE == ntohl(Adapter->psFlashCSInfo->MagicNumber))
2820 uiFlashLayoutMajorVersion = MAJOR_VERSION((Adapter->psFlashCSInfo->FlashLayoutVersion));
2821 Adapter->uiFlashLayoutMinorVersion = MINOR_VERSION((Adapter->psFlashCSInfo->FlashLayoutVersion));
2825 Adapter->uiFlashLayoutMinorVersion = 0;
2826 uiFlashLayoutMajorVersion = 0;
2829 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"FLASH LAYOUT MAJOR VERSION :%X", uiFlashLayoutMajorVersion);
2831 if(uiFlashLayoutMajorVersion < FLASH_2X_MAJOR_NUMBER)
2833 BeceemFlashBulkRead(Adapter,(PUINT)Adapter->psFlashCSInfo,Adapter->ulFlashControlSectionStart,sizeof(FLASH_CS_INFO));
2834 ConvertEndianOfCSStructure(Adapter->psFlashCSInfo);
2835 Adapter->ulFlashCalStart = (Adapter->psFlashCSInfo->OffsetFromZeroForCalibrationStart);
2837 if(!((Adapter->uiFlashLayoutMajorVersion == 1) && (Adapter->uiFlashLayoutMinorVersion == 1)))
2839 Adapter->ulFlashControlSectionStart = Adapter->psFlashCSInfo->OffsetFromZeroForControlSectionStart;
2842 if((FLASH_CONTROL_STRUCT_SIGNATURE == (Adapter->psFlashCSInfo->MagicNumber)) &&
2843 (SCSI_FIRMWARE_MINOR_VERSION <= MINOR_VERSION(Adapter->psFlashCSInfo->SCSIFirmwareVersion)) &&
2844 (FLASH_SECTOR_SIZE_SIG == (Adapter->psFlashCSInfo->FlashSectorSizeSig)) &&
2845 (BYTE_WRITE_SUPPORT == (Adapter->psFlashCSInfo->FlashWriteSupportSize)))
2847 Adapter->ulFlashWriteSize = (Adapter->psFlashCSInfo->FlashWriteSupportSize);
2848 Adapter->fpFlashWrite = flashByteWrite;
2849 Adapter->fpFlashWriteWithStatusCheck = flashByteWriteStatus;
2853 Adapter->ulFlashWriteSize = MAX_RW_SIZE;
2854 Adapter->fpFlashWrite = flashWrite;
2855 Adapter->fpFlashWriteWithStatusCheck = flashWriteStatus;
2858 BcmGetFlashSectorSize(Adapter, (Adapter->psFlashCSInfo->FlashSectorSizeSig),
2859 (Adapter->psFlashCSInfo->FlashSectorSize));
2862 Adapter->uiFlashBaseAdd = Adapter->psFlashCSInfo->FlashBaseAddr & 0xFCFFFFFF;
2868 if(BcmFlash2xBulkRead(Adapter,(PUINT)Adapter->psFlash2xCSInfo,NO_SECTION_VAL,
2869 Adapter->ulFlashControlSectionStart,sizeof(FLASH2X_CS_INFO)))
2871 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Unable to read CS structure \n");
2872 return STATUS_FAILURE;
2874 ConvertEndianOf2XCSStructure(Adapter->psFlash2xCSInfo);
2875 BcmDumpFlash2XCSStructure(Adapter->psFlash2xCSInfo,Adapter);
2876 if((FLASH_CONTROL_STRUCT_SIGNATURE == Adapter->psFlash2xCSInfo->MagicNumber) &&
2877 (SCSI_FIRMWARE_MINOR_VERSION <= MINOR_VERSION(Adapter->psFlash2xCSInfo->SCSIFirmwareVersion)) &&
2878 (FLASH_SECTOR_SIZE_SIG == Adapter->psFlash2xCSInfo->FlashSectorSizeSig) &&
2879 (BYTE_WRITE_SUPPORT == Adapter->psFlash2xCSInfo->FlashWriteSupportSize))
2881 Adapter->ulFlashWriteSize = Adapter->psFlash2xCSInfo->FlashWriteSupportSize;
2882 Adapter->fpFlashWrite = flashByteWrite;
2883 Adapter->fpFlashWriteWithStatusCheck = flashByteWriteStatus;
2887 Adapter->ulFlashWriteSize = MAX_RW_SIZE;
2888 Adapter->fpFlashWrite = flashWrite;
2889 Adapter->fpFlashWriteWithStatusCheck = flashWriteStatus;
2892 BcmGetFlashSectorSize(Adapter, Adapter->psFlash2xCSInfo->FlashSectorSizeSig,
2893 Adapter->psFlash2xCSInfo->FlashSectorSize);
2895 UpdateVendorInfo(Adapter);
2897 BcmGetActiveDSD(Adapter);
2898 BcmGetActiveISO(Adapter);
2899 Adapter->uiFlashBaseAdd = Adapter->psFlash2xCSInfo->FlashBaseAddr & 0xFCFFFFFF;
2900 Adapter->ulFlashControlSectionStart = Adapter->psFlash2xCSInfo->OffsetFromZeroForControlSectionStart;
2904 Concerns: what if CS sector size does not match with this sector size ???
2905 what is the indication of AccessBitMap in CS in flash 2.x ????
2907 Adapter->ulFlashID = BcmReadFlashRDID(Adapter);
2909 Adapter->uiFlashLayoutMajorVersion = uiFlashLayoutMajorVersion;
2912 return STATUS_SUCCESS ;
2916 //-----------------------------------------------------------------------------
2917 // Procedure: BcmGetNvmType
2919 // Description: Finds the type of NVM used.
2922 // Adapter - ptr to Adapter object instance
2927 //-----------------------------------------------------------------------------
2929 NVM_TYPE BcmGetNvmType(PMINI_ADAPTER Adapter)
2933 BeceemEEPROMBulkRead(Adapter,&uiData,0x0,4);
2939 // Read control struct and get cal addresses before accessing the flash
2941 BcmGetFlashCSInfo(Adapter);
2943 BeceemFlashBulkRead(Adapter,&uiData,0x0 + Adapter->ulFlashCalStart,4);
2949 // even if there is no valid signature on EEPROM/FLASH find out if they really exist.
2950 // if exist select it.
2952 if(BcmGetEEPROMSize(Adapter))
2964 * BcmGetSectionValStartOffset - this will calculate the section's starting offset if section val is given
2965 * @Adapter : Drivers Private Data structure
2966 * @eFlashSectionVal : Flash secion value defined in enum FLASH2X_SECTION_VAL
2969 * On success it return the start offset of the provided section val
2970 * On Failure -returns STATUS_FAILURE
2973 INT BcmGetSectionValStartOffset(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL eFlashSectionVal)
2976 * Considering all the section for which end offset can be calculated or directly given
2977 * in CS Structure. if matching case does not exist, return STATUS_FAILURE indicating section
2978 * endoffset can't be calculated or given in CS Stucture.
2981 INT SectStartOffset = 0 ;
2983 SectStartOffset = INVALID_OFFSET ;
2985 if(IsSectionExistInVendorInfo(Adapter,eFlashSectionVal))
2987 return Adapter->psFlash2xVendorInfo->VendorSection[eFlashSectionVal].OffsetFromZeroForSectionStart;
2990 switch(eFlashSectionVal)
2993 if((Adapter->psFlash2xCSInfo->OffsetISOImage1Part1Start != UNINIT_PTR_IN_CS) &&
2994 (IsNonCDLessDevice(Adapter) == FALSE))
2995 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage1Part1Start);
2998 if((Adapter->psFlash2xCSInfo->OffsetISOImage2Part1Start != UNINIT_PTR_IN_CS) &&
2999 (IsNonCDLessDevice(Adapter) == FALSE))
3000 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage2Part1Start);
3003 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForDSDStart != UNINIT_PTR_IN_CS)
3004 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForDSDStart);
3007 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD1Start != UNINIT_PTR_IN_CS)
3008 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD1Start);
3011 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD2Start != UNINIT_PTR_IN_CS)
3012 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD2Start);
3015 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForVSAStart != UNINIT_PTR_IN_CS)
3016 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForVSAStart);
3019 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA1Start != UNINIT_PTR_IN_CS)
3020 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA1Start);
3023 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA2Start != UNINIT_PTR_IN_CS)
3024 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA2Start);
3027 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForScsiFirmware != UNINIT_PTR_IN_CS)
3028 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForScsiFirmware);
3030 case CONTROL_SECTION :
3031 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForControlSectionStart != UNINIT_PTR_IN_CS)
3032 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForControlSectionStart);
3034 case ISO_IMAGE1_PART2 :
3035 if(Adapter->psFlash2xCSInfo->OffsetISOImage1Part2Start != UNINIT_PTR_IN_CS)
3036 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage1Part2Start);
3038 case ISO_IMAGE1_PART3 :
3039 if(Adapter->psFlash2xCSInfo->OffsetISOImage1Part3Start != UNINIT_PTR_IN_CS)
3040 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage1Part3Start);
3042 case ISO_IMAGE2_PART2 :
3043 if(Adapter->psFlash2xCSInfo->OffsetISOImage2Part2Start != UNINIT_PTR_IN_CS)
3044 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage2Part2Start);
3046 case ISO_IMAGE2_PART3 :
3047 if(Adapter->psFlash2xCSInfo->OffsetISOImage2Part3Start != UNINIT_PTR_IN_CS)
3048 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage2Part3Start);
3051 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Section Does not exist in Flash 2.x");
3052 SectStartOffset = INVALID_OFFSET;
3054 return SectStartOffset;
3058 * BcmGetSectionValEndOffset - this will calculate the section's Ending offset if section val is given
3059 * @Adapter : Drivers Private Data structure
3060 * @eFlashSectionVal : Flash secion value defined in enum FLASH2X_SECTION_VAL
3063 * On success it return the end offset of the provided section val
3064 * On Failure -returns STATUS_FAILURE
3067 INT BcmGetSectionValEndOffset(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL eFlash2xSectionVal)
3069 INT SectEndOffset = 0 ;
3070 SectEndOffset = INVALID_OFFSET;
3072 if(IsSectionExistInVendorInfo(Adapter,eFlash2xSectionVal))
3074 return Adapter->psFlash2xVendorInfo->VendorSection[eFlash2xSectionVal].OffsetFromZeroForSectionEnd;
3077 switch(eFlash2xSectionVal)
3080 if((Adapter->psFlash2xCSInfo->OffsetISOImage1Part1End!= UNINIT_PTR_IN_CS) &&
3081 (IsNonCDLessDevice(Adapter) == FALSE))
3082 SectEndOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage1Part1End);
3085 if((Adapter->psFlash2xCSInfo->OffsetISOImage2Part1End!= UNINIT_PTR_IN_CS) &&
3086 (IsNonCDLessDevice(Adapter) == FALSE))
3087 SectEndOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage2Part1End);
3090 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForDSDEnd != UNINIT_PTR_IN_CS)
3091 SectEndOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForDSDEnd);
3094 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD1End != UNINIT_PTR_IN_CS)
3095 SectEndOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD1End);
3098 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD2End != UNINIT_PTR_IN_CS)
3099 SectEndOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD2End);
3102 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForVSAEnd != UNINIT_PTR_IN_CS)
3103 SectEndOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForVSAEnd);
3106 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA1End != UNINIT_PTR_IN_CS)
3107 SectEndOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA1End);
3110 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA2End != UNINIT_PTR_IN_CS)
3111 SectEndOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA2End);
3114 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForScsiFirmware != UNINIT_PTR_IN_CS)
3115 SectEndOffset = ((Adapter->psFlash2xCSInfo->OffsetFromZeroForScsiFirmware) +
3116 (Adapter->psFlash2xCSInfo->SizeOfScsiFirmware));
3118 case CONTROL_SECTION :
3119 //Not Clear So Putting failure. confirm and fix it.
3120 SectEndOffset = STATUS_FAILURE;
3121 case ISO_IMAGE1_PART2 :
3122 if(Adapter->psFlash2xCSInfo->OffsetISOImage1Part2End!= UNINIT_PTR_IN_CS)
3123 SectEndOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage1Part2End);
3125 case ISO_IMAGE1_PART3 :
3126 if(Adapter->psFlash2xCSInfo->OffsetISOImage1Part3End!= UNINIT_PTR_IN_CS)
3127 SectEndOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage1Part3End);
3129 case ISO_IMAGE2_PART2 :
3130 if(Adapter->psFlash2xCSInfo->OffsetISOImage2Part2End != UNINIT_PTR_IN_CS)
3131 SectEndOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage2Part2End);
3133 case ISO_IMAGE2_PART3 :
3134 if(Adapter->psFlash2xCSInfo->OffsetISOImage2Part3End!= UNINIT_PTR_IN_CS)
3135 SectEndOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage2Part3End);
3139 SectEndOffset = INVALID_OFFSET;
3141 return SectEndOffset ;
3145 * BcmFlash2xBulkRead:- Read API for Flash Map 2.x .
3146 * @Adapter :Driver Private Data Structure
3147 * @pBuffer : Buffer where data has to be put after reading
3148 * @eFlashSectionVal :Flash Section Val defined in FLASH2X_SECTION_VAL
3149 * @uiOffsetWithinSectionVal :- Offset with in provided section
3150 * @uiNumBytes : Number of Bytes for Read
3153 * return true on sucess and STATUS_FAILURE on fail.
3156 INT BcmFlash2xBulkRead(
3157 PMINI_ADAPTER Adapter,
3159 FLASH2X_SECTION_VAL eFlash2xSectionVal,
3160 UINT uiOffsetWithinSectionVal,
3164 INT Status = STATUS_SUCCESS;
3165 INT SectionStartOffset = 0;
3166 UINT uiAbsoluteOffset = 0 ;
3167 UINT uiTemp =0, value =0 ;
3170 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Adapter structure is NULL");
3173 if(Adapter->device_removed )
3175 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Device has been removed");
3179 //NO_SECTION_VAL means absolute offset is given.
3180 if(eFlash2xSectionVal == NO_SECTION_VAL)
3181 SectionStartOffset = 0;
3183 SectionStartOffset = BcmGetSectionValStartOffset(Adapter,eFlash2xSectionVal);
3185 if(SectionStartOffset == STATUS_FAILURE )
3187 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"This Section<%d> does not exixt in Flash 2.x Map ",eFlash2xSectionVal);
3191 if(IsSectionExistInVendorInfo(Adapter,eFlash2xSectionVal))
3192 return vendorextnReadSection(Adapter,(PUCHAR)pBuffer, eFlash2xSectionVal, uiOffsetWithinSectionVal, uiNumBytes);
3194 //calculating the absolute offset from FLASH;
3195 uiAbsoluteOffset = uiOffsetWithinSectionVal + SectionStartOffset;
3196 rdmalt(Adapter, 0x0f000C80, &uiTemp, sizeof(uiTemp));
3198 wrmalt(Adapter, 0x0f000C80,&value, sizeof(value));
3200 Status= BeceemFlashBulkRead(Adapter, pBuffer,uiAbsoluteOffset,uiNumBytes) ;
3202 wrmalt(Adapter, 0x0f000C80, &uiTemp, sizeof(uiTemp));
3205 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Flash Read Failed with Status :%d", Status);
3213 * BcmFlash2xBulkWrite :-API for Writing on the Flash Map 2.x.
3214 * @Adapter :Driver Private Data Structure
3215 * @pBuffer : Buffer From where data has to taken for writing
3216 * @eFlashSectionVal :Flash Section Val defined in FLASH2X_SECTION_VAL
3217 * @uiOffsetWithinSectionVal :- Offset with in provided section
3218 * @uiNumBytes : Number of Bytes for Write
3221 * return true on sucess and STATUS_FAILURE on fail.
3225 INT BcmFlash2xBulkWrite(
3226 PMINI_ADAPTER Adapter,
3228 FLASH2X_SECTION_VAL eFlash2xSectVal,
3234 INT Status = STATUS_SUCCESS;
3235 UINT FlashSectValStartOffset = 0;
3236 UINT uiTemp = 0, value = 0;
3239 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Adapter structure is NULL");
3242 if(Adapter->device_removed )
3244 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Device has been removed");
3248 //NO_SECTION_VAL means absolute offset is given.
3249 if(eFlash2xSectVal == NO_SECTION_VAL)
3250 FlashSectValStartOffset = 0;
3252 FlashSectValStartOffset = BcmGetSectionValStartOffset(Adapter,eFlash2xSectVal);
3254 if(FlashSectValStartOffset == STATUS_FAILURE )
3256 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"This Section<%d> does not exixt in Flash Map 2.x",eFlash2xSectVal);
3260 if(IsSectionExistInVendorInfo(Adapter,eFlash2xSectVal))
3261 return vendorextnWriteSection(Adapter, (PUCHAR)pBuffer, eFlash2xSectVal, uiOffset, uiNumBytes, bVerify);
3263 //calculating the absolute offset from FLASH;
3264 uiOffset = uiOffset + FlashSectValStartOffset;
3266 rdmalt(Adapter, 0x0f000C80, &uiTemp, sizeof(uiTemp));
3268 wrmalt(Adapter, 0x0f000C80,&value, sizeof(value));
3270 Status = BeceemFlashBulkWrite(Adapter, pBuffer,uiOffset,uiNumBytes,bVerify);
3272 wrmalt(Adapter, 0x0f000C80, &uiTemp, sizeof(uiTemp));
3275 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Flash Write failed with Status :%d", Status);
3284 * ReadDSDHeader : Read the DSD map for the DSD Section val provided in Argument.
3285 * @Adapter : Beceem Private Data Structure
3286 * @psDSDHeader :Pointer of the buffer where header has to be read
3287 * @dsd :value of the Dyanmic DSD like DSD0 of DSD1 or DSD2
3290 * if suceeds return STATUS_SUCCESS or negative error code.
3292 INT ReadDSDHeader(PMINI_ADAPTER Adapter, PDSD_HEADER psDSDHeader, FLASH2X_SECTION_VAL dsd)
3294 INT Status = STATUS_SUCCESS;
3296 Status =BcmFlash2xBulkRead(Adapter,
3299 Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader,
3300 sizeof(DSD_HEADER));
3301 if(Status == STATUS_SUCCESS)
3303 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "DSDImageMagicNumber :0X%x", ntohl(psDSDHeader->DSDImageMagicNumber));
3304 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "DSDImageSize :0X%x ",ntohl(psDSDHeader->DSDImageSize));
3305 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "DSDImageCRC :0X%x",ntohl(psDSDHeader->DSDImageCRC));
3306 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "DSDImagePriority :0X%x",ntohl(psDSDHeader->DSDImagePriority));
3310 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"DSD Header read is failed with status :%d", Status);
3317 * BcmGetActiveDSD : Set the Active DSD in Adapter Structure which has to be dumped in DDR
3318 * @Adapter :-Drivers private Data Structure
3321 * Return STATUS_SUCESS if get sucess in setting the right DSD else negaive error code
3324 INT BcmGetActiveDSD(PMINI_ADAPTER Adapter)
3326 FLASH2X_SECTION_VAL uiHighestPriDSD = 0 ;
3328 uiHighestPriDSD = getHighestPriDSD(Adapter);
3329 Adapter->eActiveDSD = uiHighestPriDSD;
3331 if(DSD0 == uiHighestPriDSD)
3332 Adapter->ulFlashCalStart = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSDStart;
3333 if(DSD1 == uiHighestPriDSD)
3334 Adapter->ulFlashCalStart = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD1Start;
3335 if(DSD2 == uiHighestPriDSD)
3336 Adapter->ulFlashCalStart = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD2Start;
3337 if(Adapter->eActiveDSD)
3338 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Active DSD :%d", Adapter->eActiveDSD);
3339 if(Adapter->eActiveDSD == 0)
3341 //if No DSD gets Active, Make Active the DSD with WR permission
3342 if(IsSectionWritable(Adapter,DSD2))
3344 Adapter->eActiveDSD = DSD2;
3345 Adapter->ulFlashCalStart = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD2Start;
3347 else if(IsSectionWritable(Adapter,DSD1))
3349 Adapter->eActiveDSD = DSD1;
3350 Adapter->ulFlashCalStart = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD1Start;
3352 else if(IsSectionWritable(Adapter,DSD0))
3354 Adapter->eActiveDSD = DSD0;
3355 Adapter->ulFlashCalStart = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSDStart;
3359 return STATUS_SUCCESS;
3363 * ReadISOUnReservedBytes : Read the ISO map for the ISO Section val provided in Argument.
3364 * @Adapter : Driver Private Data Structure
3365 * @psISOHeader :Pointer of the location where header has to be read
3366 * @IsoImage :value of the Dyanmic ISO like ISO_IMAGE1 of ISO_IMAGE2
3369 * if suceeds return STATUS_SUCCESS or negative error code.
3372 INT ReadISOHeader(PMINI_ADAPTER Adapter, PISO_HEADER psISOHeader, FLASH2X_SECTION_VAL IsoImage)
3374 INT Status = STATUS_SUCCESS;
3376 Status = BcmFlash2xBulkRead(Adapter,
3380 sizeof(ISO_HEADER));
3382 if(Status == STATUS_SUCCESS)
3384 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "ISOImageMagicNumber :0X%x", ntohl(psISOHeader->ISOImageMagicNumber));
3385 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "ISOImageSize :0X%x ",ntohl(psISOHeader->ISOImageSize));
3386 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "ISOImageCRC :0X%x",ntohl(psISOHeader->ISOImageCRC));
3387 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "ISOImagePriority :0X%x",ntohl(psISOHeader->ISOImagePriority));
3391 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "ISO Header Read failed");
3397 * BcmGetActiveISO :- Set the Active ISO in Adapter Data Structue
3398 * @Adapter : Driver private Data Structure
3401 * Sucsess:- STATUS_SUCESS
3402 * Failure- : negative erro code
3406 INT BcmGetActiveISO(PMINI_ADAPTER Adapter)
3409 INT HighestPriISO = 0 ;
3410 HighestPriISO = getHighestPriISO(Adapter);
3412 Adapter->eActiveISO = HighestPriISO ;
3413 if(Adapter->eActiveISO == ISO_IMAGE2)
3414 Adapter->uiActiveISOOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage2Part1Start);
3415 else if(Adapter->eActiveISO == ISO_IMAGE1)
3416 Adapter->uiActiveISOOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage1Part1Start);
3418 if(Adapter->eActiveISO)
3419 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Active ISO :%x", Adapter->eActiveISO);
3421 return STATUS_SUCCESS;
3425 * IsOffsetWritable :- it will tell the access permission of the sector having passed offset
3426 * @Adapter : Drivers Private Data Structure
3427 * @uiOffset : Offset provided in the Flash
3430 * Sucess:-TRUE , offset is writable
3431 * Failure:-FALSE, offset is RO
3434 B_UINT8 IsOffsetWritable(PMINI_ADAPTER Adapter, UINT uiOffset)
3436 UINT uiSectorNum = 0;
3437 UINT uiWordOfSectorPermission =0;
3438 UINT uiBitofSectorePermission = 0;
3439 B_UINT32 permissionBits = 0;
3440 uiSectorNum = uiOffset/Adapter->uiSectorSize;
3442 //calculating the word having this Sector Access permission from SectorAccessBitMap Array
3443 uiWordOfSectorPermission = Adapter->psFlash2xCSInfo->SectorAccessBitMap[uiSectorNum /16];
3445 //calculating the bit index inside the word for this sector
3446 uiBitofSectorePermission = 2*(15 - uiSectorNum %16);
3448 //Setting Access permission
3449 permissionBits = uiWordOfSectorPermission & (0x3 << uiBitofSectorePermission) ;
3450 permissionBits = (permissionBits >> uiBitofSectorePermission) & 0x3;
3451 if(permissionBits == SECTOR_READWRITE_PERMISSION)
3457 static INT BcmDumpFlash2xSectionBitMap(PFLASH2X_BITMAP psFlash2xBitMap)
3459 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(gblpnetdev);
3460 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "***************Flash 2.x Section Bitmap***************");
3461 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"ISO_IMAGE1 :0X%x", psFlash2xBitMap->ISO_IMAGE1);
3462 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"ISO_IMAGE2 :0X%x", psFlash2xBitMap->ISO_IMAGE2);
3463 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"DSD0 :0X%x", psFlash2xBitMap->DSD0);
3464 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"DSD1 :0X%x", psFlash2xBitMap->DSD1);
3465 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"DSD2 :0X%x", psFlash2xBitMap->DSD2);
3466 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"VSA0 :0X%x", psFlash2xBitMap->VSA0);
3467 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"VSA1 :0X%x", psFlash2xBitMap->VSA1);
3468 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"VSA2 :0X%x", psFlash2xBitMap->VSA2);
3469 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"SCSI :0X%x", psFlash2xBitMap->SCSI);
3470 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"CONTROL_SECTION :0X%x", psFlash2xBitMap->CONTROL_SECTION);
3472 return STATUS_SUCCESS;
3476 * BcmGetFlash2xSectionalBitMap :- It will provide the bit map of all the section present in Flash
3477 * 8bit has been assigned to every section.
3478 bit[0] :Section present or not
3479 bit[1] :section is valid or not
3480 bit[2] : Secton is read only or has write permission too.
3481 bit[3] : Active Section -
3482 bit[7...4] = Reserved .
3484 @Adapter:-Driver private Data Structure
3487 * Sucess:- STATUS_SUCESS
3488 * Failure:- negative error code
3491 INT BcmGetFlash2xSectionalBitMap(PMINI_ADAPTER Adapter, PFLASH2X_BITMAP psFlash2xBitMap)
3495 PFLASH2X_CS_INFO psFlash2xCSInfo = Adapter->psFlash2xCSInfo;
3496 FLASH2X_SECTION_VAL uiHighestPriDSD = 0 ;
3497 FLASH2X_SECTION_VAL uiHighestPriISO= 0 ;
3498 BOOLEAN SetActiveDSDDone = FALSE ;
3499 BOOLEAN SetActiveISODone = FALSE ;
3501 //For 1.x map all the section except DSD0 will be shown as not present
3502 //This part will be used by calibration tool to detect the number of DSD present in Flash.
3503 if(IsFlash2x(Adapter) == FALSE)
3505 psFlash2xBitMap->ISO_IMAGE2 = 0;
3506 psFlash2xBitMap->ISO_IMAGE1 = 0;
3507 psFlash2xBitMap->DSD0 = FLASH2X_SECTION_VALID | FLASH2X_SECTION_ACT | FLASH2X_SECTION_PRESENT; //0xF; //0000(Reseved)1(Active)0(RW)1(valid)1(present)
3508 psFlash2xBitMap->DSD1 = 0 ;
3509 psFlash2xBitMap->DSD2 = 0 ;
3510 psFlash2xBitMap->VSA0 = 0 ;
3511 psFlash2xBitMap->VSA1 = 0 ;
3512 psFlash2xBitMap->VSA2 = 0 ;
3513 psFlash2xBitMap->CONTROL_SECTION = 0 ;
3514 psFlash2xBitMap->SCSI= 0 ;
3515 psFlash2xBitMap->Reserved0 = 0 ;
3516 psFlash2xBitMap->Reserved1 = 0 ;
3517 psFlash2xBitMap->Reserved2 = 0 ;
3518 return STATUS_SUCCESS ;
3522 uiHighestPriDSD = getHighestPriDSD(Adapter);
3523 uiHighestPriISO = getHighestPriISO(Adapter);
3528 if((psFlash2xCSInfo->OffsetISOImage2Part1Start) != UNINIT_PTR_IN_CS)
3530 //Setting the 0th Bit representing the Section is present or not.
3531 psFlash2xBitMap->ISO_IMAGE2= psFlash2xBitMap->ISO_IMAGE2 | FLASH2X_SECTION_PRESENT;
3534 if(ReadISOSignature(Adapter,ISO_IMAGE2)== ISO_IMAGE_MAGIC_NUMBER)
3535 psFlash2xBitMap->ISO_IMAGE2 |= FLASH2X_SECTION_VALID;
3538 //Calculation for extrating the Access permission
3539 if(IsSectionWritable(Adapter, ISO_IMAGE2) == FALSE)
3540 psFlash2xBitMap->ISO_IMAGE2 |= FLASH2X_SECTION_RO;
3542 if(SetActiveISODone == FALSE && uiHighestPriISO == ISO_IMAGE2)
3544 psFlash2xBitMap->ISO_IMAGE2 |= FLASH2X_SECTION_ACT ;
3545 SetActiveISODone = TRUE;
3553 if((psFlash2xCSInfo->OffsetISOImage1Part1Start) != UNINIT_PTR_IN_CS)
3555 //Setting the 0th Bit representing the Section is present or not.
3556 psFlash2xBitMap->ISO_IMAGE1 = psFlash2xBitMap->ISO_IMAGE1 | FLASH2X_SECTION_PRESENT;
3558 if(ReadISOSignature(Adapter,ISO_IMAGE1) == ISO_IMAGE_MAGIC_NUMBER)
3559 psFlash2xBitMap->ISO_IMAGE1 |= FLASH2X_SECTION_VALID;
3561 // Calculation for extrating the Access permission
3562 if(IsSectionWritable(Adapter, ISO_IMAGE1) == FALSE)
3563 psFlash2xBitMap->ISO_IMAGE1 |= FLASH2X_SECTION_RO;
3565 if(SetActiveISODone == FALSE && uiHighestPriISO == ISO_IMAGE1)
3567 psFlash2xBitMap->ISO_IMAGE1 |= FLASH2X_SECTION_ACT ;
3568 SetActiveISODone = TRUE;
3577 if((psFlash2xCSInfo->OffsetFromZeroForDSD2Start) != UNINIT_PTR_IN_CS)
3579 //Setting the 0th Bit representing the Section is present or not.
3580 psFlash2xBitMap->DSD2= psFlash2xBitMap->DSD2 | FLASH2X_SECTION_PRESENT;
3582 if(ReadDSDSignature(Adapter,DSD2)== DSD_IMAGE_MAGIC_NUMBER)
3583 psFlash2xBitMap->DSD2 |= FLASH2X_SECTION_VALID;
3585 //Calculation for extrating the Access permission
3586 if(IsSectionWritable(Adapter, DSD2) == FALSE)
3588 psFlash2xBitMap->DSD2 |= FLASH2X_SECTION_RO;
3593 //Means section is writable
3594 if((SetActiveDSDDone == FALSE) && (uiHighestPriDSD == DSD2))
3596 psFlash2xBitMap->DSD2 |= FLASH2X_SECTION_ACT ;
3597 SetActiveDSDDone =TRUE ;
3605 if((psFlash2xCSInfo->OffsetFromZeroForDSD1Start) != UNINIT_PTR_IN_CS)
3607 //Setting the 0th Bit representing the Section is present or not.
3608 psFlash2xBitMap->DSD1= psFlash2xBitMap->DSD1 | FLASH2X_SECTION_PRESENT;
3611 if(ReadDSDSignature(Adapter,DSD1)== DSD_IMAGE_MAGIC_NUMBER)
3612 psFlash2xBitMap->DSD1 |= FLASH2X_SECTION_VALID;
3614 //Calculation for extrating the Access permission
3615 if(IsSectionWritable(Adapter, DSD1) == FALSE)
3617 psFlash2xBitMap->DSD1 |= FLASH2X_SECTION_RO;
3621 //Means section is writable
3622 if((SetActiveDSDDone == FALSE) && (uiHighestPriDSD == DSD1))
3624 psFlash2xBitMap->DSD1 |= FLASH2X_SECTION_ACT ;
3625 SetActiveDSDDone =TRUE ;
3634 if((psFlash2xCSInfo->OffsetFromZeroForDSDStart) != UNINIT_PTR_IN_CS)
3636 //Setting the 0th Bit representing the Section is present or not.
3637 psFlash2xBitMap->DSD0 = psFlash2xBitMap->DSD0 | FLASH2X_SECTION_PRESENT;
3639 if(ReadDSDSignature(Adapter,DSD0) == DSD_IMAGE_MAGIC_NUMBER)
3640 psFlash2xBitMap->DSD0 |= FLASH2X_SECTION_VALID;
3642 //Setting Access permission
3643 if(IsSectionWritable(Adapter, DSD0) == FALSE)
3645 psFlash2xBitMap->DSD0 |= FLASH2X_SECTION_RO;
3649 //Means section is writable
3650 if((SetActiveDSDDone == FALSE) &&(uiHighestPriDSD == DSD0))
3652 psFlash2xBitMap->DSD0 |= FLASH2X_SECTION_ACT ;
3653 SetActiveDSDDone =TRUE ;
3661 if((psFlash2xCSInfo->OffsetFromZeroForVSAStart) != UNINIT_PTR_IN_CS)
3663 //Setting the 0th Bit representing the Section is present or not.
3664 psFlash2xBitMap->VSA0= psFlash2xBitMap->VSA0 | FLASH2X_SECTION_PRESENT;
3666 //Setting the Access Bit. Map is not defined hece setting it always valid
3667 psFlash2xBitMap->VSA0 |= FLASH2X_SECTION_VALID;
3669 //Calculation for extrating the Access permission
3670 if(IsSectionWritable(Adapter, VSA0) == FALSE)
3671 psFlash2xBitMap->VSA0 |= FLASH2X_SECTION_RO;
3673 //By Default section is Active
3674 psFlash2xBitMap->VSA0 |= FLASH2X_SECTION_ACT ;
3683 if((psFlash2xCSInfo->OffsetFromZeroForVSA1Start) != UNINIT_PTR_IN_CS)
3685 //Setting the 0th Bit representing the Section is present or not.
3686 psFlash2xBitMap->VSA1= psFlash2xBitMap->VSA1 | FLASH2X_SECTION_PRESENT;
3688 //Setting the Access Bit. Map is not defined hece setting it always valid
3689 psFlash2xBitMap->VSA1|= FLASH2X_SECTION_VALID;
3691 //Checking For Access permission
3692 if(IsSectionWritable(Adapter, VSA1) == FALSE)
3693 psFlash2xBitMap->VSA1 |= FLASH2X_SECTION_RO;
3695 //By Default section is Active
3696 psFlash2xBitMap->VSA1 |= FLASH2X_SECTION_ACT ;
3705 if((psFlash2xCSInfo->OffsetFromZeroForVSA2Start) != UNINIT_PTR_IN_CS)
3707 //Setting the 0th Bit representing the Section is present or not.
3708 psFlash2xBitMap->VSA2= psFlash2xBitMap->VSA2 | FLASH2X_SECTION_PRESENT;
3711 //Setting the Access Bit. Map is not defined hece setting it always valid
3712 psFlash2xBitMap->VSA2 |= FLASH2X_SECTION_VALID;
3714 //Checking For Access permission
3715 if(IsSectionWritable(Adapter, VSA2) == FALSE)
3716 psFlash2xBitMap->VSA2 |= FLASH2X_SECTION_RO;
3718 //By Default section is Active
3719 psFlash2xBitMap->VSA2 |= FLASH2X_SECTION_ACT ;
3725 if((psFlash2xCSInfo->OffsetFromZeroForScsiFirmware) != UNINIT_PTR_IN_CS)
3727 //Setting the 0th Bit representing the Section is present or not.
3728 psFlash2xBitMap->SCSI= psFlash2xBitMap->SCSI | FLASH2X_SECTION_PRESENT;
3731 //Setting the Access Bit. Map is not defined hece setting it always valid
3732 psFlash2xBitMap->SCSI|= FLASH2X_SECTION_VALID;
3734 //Checking For Access permission
3735 if(IsSectionWritable(Adapter, SCSI) == FALSE)
3736 psFlash2xBitMap->SCSI |= FLASH2X_SECTION_RO;
3738 //By Default section is Active
3739 psFlash2xBitMap->SCSI |= FLASH2X_SECTION_ACT ;
3747 if((psFlash2xCSInfo->OffsetFromZeroForControlSectionStart) != UNINIT_PTR_IN_CS)
3749 //Setting the 0th Bit representing the Section is present or not.
3750 psFlash2xBitMap->CONTROL_SECTION = psFlash2xBitMap->CONTROL_SECTION | (FLASH2X_SECTION_PRESENT);
3753 //Setting the Access Bit. Map is not defined hece setting it always valid
3754 psFlash2xBitMap->CONTROL_SECTION |= FLASH2X_SECTION_VALID;
3756 //Checking For Access permission
3757 if(IsSectionWritable(Adapter, CONTROL_SECTION) == FALSE)
3758 psFlash2xBitMap->CONTROL_SECTION |= FLASH2X_SECTION_RO;
3760 //By Default section is Active
3761 psFlash2xBitMap->CONTROL_SECTION |= FLASH2X_SECTION_ACT ;
3766 // For Reserved Sections
3768 psFlash2xBitMap->Reserved0 = 0;
3769 psFlash2xBitMap->Reserved0 = 0;
3770 psFlash2xBitMap->Reserved0 = 0;
3772 BcmDumpFlash2xSectionBitMap(psFlash2xBitMap);
3774 return STATUS_SUCCESS ;
3778 BcmSetActiveSection :- Set Active section is used to make priority field highest over other
3779 section of same type.
3781 @Adapater :- Bcm Driver Private Data Structure
3782 @eFlash2xSectionVal :- Flash section val whose priority has to be made highest.
3784 Return Value:- Make the priorit highest else return erorr code
3787 INT BcmSetActiveSection(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL eFlash2xSectVal)
3789 unsigned int SectImagePriority = 0;
3790 INT Status =STATUS_SUCCESS;
3792 //DSD_HEADER sDSD = {0};
3793 //ISO_HEADER sISO = {0};
3794 INT HighestPriDSD = 0 ;
3795 INT HighestPriISO = 0;
3799 Status = IsSectionWritable(Adapter,eFlash2xSectVal) ;
3802 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Provided Section <%d> is not writable",eFlash2xSectVal);
3803 return STATUS_FAILURE;
3806 Adapter->bHeaderChangeAllowed = TRUE ;
3807 switch(eFlash2xSectVal)
3811 if(ReadISOSignature(Adapter,eFlash2xSectVal)== ISO_IMAGE_MAGIC_NUMBER )
3813 HighestPriISO = getHighestPriISO(Adapter);
3815 if(HighestPriISO == eFlash2xSectVal )
3817 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Given ISO<%x> already has highest priority",eFlash2xSectVal );
3818 Status = STATUS_SUCCESS ;
3822 SectImagePriority = ReadISOPriority(Adapter, HighestPriISO) + 1;
3824 if((SectImagePriority <= 0) && IsSectionWritable(Adapter,HighestPriISO))
3826 // This is a SPECIAL Case which will only happen if the current highest priority ISO has priority value = 0x7FFFFFFF.
3827 // We will write 1 to the current Highest priority ISO And then shall increase the priority of the requested ISO
3829 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "SectImagePriority wraparound happend, eFlash2xSectVal: 0x%x\n",eFlash2xSectVal);
3830 SectImagePriority = htonl(0x1);
3831 Status = BcmFlash2xBulkWrite(Adapter,
3834 0 + FIELD_OFFSET_IN_HEADER(PISO_HEADER, ISOImagePriority),
3840 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Priority has not been written properly");
3841 Status = STATUS_FAILURE;
3845 HighestPriISO = getHighestPriISO(Adapter);
3847 if(HighestPriISO == eFlash2xSectVal )
3849 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Given ISO<%x> already has highest priority",eFlash2xSectVal );
3850 Status = STATUS_SUCCESS ;
3854 SectImagePriority = 2;
3858 SectImagePriority = htonl(SectImagePriority);
3860 Status = BcmFlash2xBulkWrite(Adapter,
3863 0 + FIELD_OFFSET_IN_HEADER(PISO_HEADER, ISOImagePriority),
3868 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Priority has not been written properly");
3874 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Signature is currupted. Hence can't increase the priority");
3875 Status = STATUS_FAILURE ;
3882 if(ReadDSDSignature(Adapter,eFlash2xSectVal)== DSD_IMAGE_MAGIC_NUMBER)
3884 HighestPriDSD = getHighestPriDSD(Adapter);
3886 if((HighestPriDSD == eFlash2xSectVal))
3888 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Given DSD<%x> already has highest priority", eFlash2xSectVal);
3889 Status = STATUS_SUCCESS ;
3893 SectImagePriority = ReadDSDPriority(Adapter, HighestPriDSD) + 1 ;
3894 if(SectImagePriority <= 0)
3896 // This is a SPECIAL Case which will only happen if the current highest priority DSD has priority value = 0x7FFFFFFF.
3897 // We will write 1 to the current Highest priority DSD And then shall increase the priority of the requested DSD
3899 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, NVM_RW, DBG_LVL_ALL, "SectImagePriority wraparound happend, eFlash2xSectVal: 0x%x\n",eFlash2xSectVal);
3900 SectImagePriority = htonl(0x1);
3902 Status = BcmFlash2xBulkWrite(Adapter,
3905 Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + FIELD_OFFSET_IN_HEADER(PDSD_HEADER, DSDImagePriority),
3911 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Priority has not been written properly");
3915 HighestPriDSD = getHighestPriDSD(Adapter);
3917 if((HighestPriDSD == eFlash2xSectVal))
3919 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Made the DSD: %x highest by reducing priority of other\n", eFlash2xSectVal);
3920 Status = STATUS_SUCCESS ;
3924 SectImagePriority = htonl(0x2);
3925 Status = BcmFlash2xBulkWrite(Adapter,
3928 Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + FIELD_OFFSET_IN_HEADER(PDSD_HEADER, DSDImagePriority),
3934 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Priority has not been written properly");
3938 HighestPriDSD = getHighestPriDSD(Adapter);
3940 if((HighestPriDSD == eFlash2xSectVal))
3942 Status = STATUS_SUCCESS ;
3945 SectImagePriority = 3 ;
3948 SectImagePriority = htonl(SectImagePriority);
3949 Status = BcmFlash2xBulkWrite(Adapter,
3952 Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + FIELD_OFFSET_IN_HEADER(PDSD_HEADER, DSDImagePriority),
3957 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Priority has not been written properly");
3958 Status = STATUS_FAILURE ;
3964 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Signature is currupted. Hence can't increase the priority");
3965 Status = STATUS_FAILURE ;
3975 Status = STATUS_FAILURE ;
3980 Adapter->bHeaderChangeAllowed = FALSE ;
3986 BcmCopyISO - Used only for copying the ISO section
3987 @Adapater :- Bcm Driver Private Data Structure
3988 @sCopySectStrut :- Section copy structure
3990 Return value:- SUCCESS if copies successfully else negative error code
3993 INT BcmCopyISO(PMINI_ADAPTER Adapter, FLASH2X_COPY_SECTION sCopySectStrut)
3997 FLASH2X_SECTION_VAL eISOReadPart = 0,eISOWritePart = 0;
3998 UINT uiReadOffsetWithinPart = 0, uiWriteOffsetWithinPart = 0;
3999 UINT uiTotalDataToCopy = 0;
4000 BOOLEAN IsThisHeaderSector = FALSE ;
4003 UINT Status = STATUS_SUCCESS;
4004 UINT SigBuff[MAX_RW_SIZE];
4007 if(ReadISOSignature(Adapter,sCopySectStrut.SrcSection) != ISO_IMAGE_MAGIC_NUMBER)
4009 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "error as Source ISO Section does not have valid signature");
4010 return STATUS_FAILURE;
4013 Status = BcmFlash2xBulkRead(Adapter,
4015 sCopySectStrut.SrcSection,
4016 0 + FIELD_OFFSET_IN_HEADER(PISO_HEADER,ISOImageSize),
4021 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Read failed while copying ISO\n");
4025 ISOLength = htonl(ISOLength);
4027 if(ISOLength % Adapter->uiSectorSize)
4029 ISOLength = Adapter->uiSectorSize*(1 + ISOLength/Adapter->uiSectorSize);
4032 sigOffset = FIELD_OFFSET_IN_HEADER(PISO_HEADER, ISOImageMagicNumber);
4034 Buff = kzalloc(Adapter->uiSectorSize, GFP_KERNEL);
4038 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Memory allocation failed for section size");
4042 if(sCopySectStrut.SrcSection ==ISO_IMAGE1 && sCopySectStrut.DstSection ==ISO_IMAGE2)
4044 eISOReadPart = ISO_IMAGE1 ;
4045 eISOWritePart = ISO_IMAGE2 ;
4046 uiReadOffsetWithinPart = 0;
4047 uiWriteOffsetWithinPart = 0 ;
4049 uiTotalDataToCopy =(Adapter->psFlash2xCSInfo->OffsetISOImage1Part1End) -
4050 (Adapter->psFlash2xCSInfo->OffsetISOImage1Part1Start)+
4051 (Adapter->psFlash2xCSInfo->OffsetISOImage1Part2End) -
4052 (Adapter->psFlash2xCSInfo->OffsetISOImage1Part2Start)+
4053 (Adapter->psFlash2xCSInfo->OffsetISOImage1Part3End) -
4054 (Adapter->psFlash2xCSInfo->OffsetISOImage1Part3Start);
4056 if(uiTotalDataToCopy < ISOLength)
4058 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"error as Source ISO Section does not have valid signature");
4059 return STATUS_FAILURE;
4062 uiTotalDataToCopy =(Adapter->psFlash2xCSInfo->OffsetISOImage2Part1End) -
4063 (Adapter->psFlash2xCSInfo->OffsetISOImage2Part1Start)+
4064 (Adapter->psFlash2xCSInfo->OffsetISOImage2Part2End) -
4065 (Adapter->psFlash2xCSInfo->OffsetISOImage2Part2Start)+
4066 (Adapter->psFlash2xCSInfo->OffsetISOImage2Part3End) -
4067 (Adapter->psFlash2xCSInfo->OffsetISOImage2Part3Start);
4069 if(uiTotalDataToCopy < ISOLength)
4071 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"error as Dest ISO Section does not have enough section size");
4072 return STATUS_FAILURE;
4075 uiTotalDataToCopy = ISOLength;
4077 CorruptISOSig(Adapter,ISO_IMAGE2);
4079 while(uiTotalDataToCopy)
4081 if(uiTotalDataToCopy == Adapter->uiSectorSize)
4083 //Setting for write of first sector. First sector is assumed to be written in last
4084 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Writing the signature sector");
4085 eISOReadPart = ISO_IMAGE1 ;
4086 uiReadOffsetWithinPart = 0;
4087 eISOWritePart = ISO_IMAGE2;
4088 uiWriteOffsetWithinPart = 0 ;
4089 IsThisHeaderSector = TRUE ;
4094 uiReadOffsetWithinPart = uiReadOffsetWithinPart + Adapter->uiSectorSize ;
4095 uiWriteOffsetWithinPart = uiWriteOffsetWithinPart + Adapter->uiSectorSize ;
4097 if((eISOReadPart == ISO_IMAGE1) && (uiReadOffsetWithinPart == (Adapter->psFlash2xCSInfo->OffsetISOImage1Part1End - Adapter->psFlash2xCSInfo->OffsetISOImage1Part1Start) ))
4099 eISOReadPart = ISO_IMAGE1_PART2 ;
4100 uiReadOffsetWithinPart = 0;
4102 if((eISOReadPart == ISO_IMAGE1_PART2) && (uiReadOffsetWithinPart == (Adapter->psFlash2xCSInfo->OffsetISOImage1Part2End - Adapter->psFlash2xCSInfo->OffsetISOImage1Part2Start)))
4104 eISOReadPart = ISO_IMAGE1_PART3 ;
4105 uiReadOffsetWithinPart = 0;
4107 if((eISOWritePart == ISO_IMAGE2) && (uiWriteOffsetWithinPart == (Adapter->psFlash2xCSInfo->OffsetISOImage2Part1End - Adapter->psFlash2xCSInfo->OffsetISOImage2Part1Start)))
4109 eISOWritePart = ISO_IMAGE2_PART2 ;
4110 uiWriteOffsetWithinPart = 0;
4112 if((eISOWritePart == ISO_IMAGE2_PART2) && (uiWriteOffsetWithinPart == (Adapter->psFlash2xCSInfo->OffsetISOImage2Part2End - Adapter->psFlash2xCSInfo->OffsetISOImage2Part2Start)))
4114 eISOWritePart = ISO_IMAGE2_PART3 ;
4115 uiWriteOffsetWithinPart = 0;
4119 Status = BcmFlash2xBulkRead(Adapter,
4122 uiReadOffsetWithinPart,
4123 Adapter->uiSectorSize
4128 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Read failed while copying ISO: Part: %x, OffsetWithinPart: %x\n", eISOReadPart, uiReadOffsetWithinPart);
4132 if(IsThisHeaderSector == TRUE)
4134 //If this is header sector write 0xFFFFFFFF at the sig time and in last write sig
4135 memcpy(SigBuff, Buff + sigOffset, MAX_RW_SIZE);
4137 for(i = 0; i < MAX_RW_SIZE;i++)
4138 *(Buff + sigOffset + i) = 0xFF;
4140 Adapter->bHeaderChangeAllowed = TRUE ;
4142 Status = BcmFlash2xBulkWrite(Adapter,
4145 uiWriteOffsetWithinPart,
4146 Adapter->uiSectorSize,
4150 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Write failed while copying ISO: Part: %x, OffsetWithinPart: %x\n", eISOWritePart, uiWriteOffsetWithinPart);
4154 Adapter->bHeaderChangeAllowed = FALSE;
4156 if(IsThisHeaderSector == TRUE)
4158 WriteToFlashWithoutSectorErase(Adapter,
4163 IsThisHeaderSector = FALSE ;
4165 //substracting the written Data
4166 uiTotalDataToCopy = uiTotalDataToCopy - Adapter->uiSectorSize ;
4172 if(sCopySectStrut.SrcSection ==ISO_IMAGE2 && sCopySectStrut.DstSection ==ISO_IMAGE1)
4174 eISOReadPart = ISO_IMAGE2 ;
4175 eISOWritePart = ISO_IMAGE1 ;
4176 uiReadOffsetWithinPart = 0;
4177 uiWriteOffsetWithinPart = 0 ;
4179 uiTotalDataToCopy =(Adapter->psFlash2xCSInfo->OffsetISOImage2Part1End) -
4180 (Adapter->psFlash2xCSInfo->OffsetISOImage2Part1Start)+
4181 (Adapter->psFlash2xCSInfo->OffsetISOImage2Part2End) -
4182 (Adapter->psFlash2xCSInfo->OffsetISOImage2Part2Start)+
4183 (Adapter->psFlash2xCSInfo->OffsetISOImage2Part3End) -
4184 (Adapter->psFlash2xCSInfo->OffsetISOImage2Part3Start);
4186 if(uiTotalDataToCopy < ISOLength)
4188 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"error as Source ISO Section does not have valid signature");
4189 return STATUS_FAILURE;
4192 uiTotalDataToCopy =(Adapter->psFlash2xCSInfo->OffsetISOImage1Part1End) -
4193 (Adapter->psFlash2xCSInfo->OffsetISOImage1Part1Start)+
4194 (Adapter->psFlash2xCSInfo->OffsetISOImage1Part2End) -
4195 (Adapter->psFlash2xCSInfo->OffsetISOImage1Part2Start)+
4196 (Adapter->psFlash2xCSInfo->OffsetISOImage1Part3End) -
4197 (Adapter->psFlash2xCSInfo->OffsetISOImage1Part3Start);
4199 if(uiTotalDataToCopy < ISOLength)
4201 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"error as Dest ISO Section does not have enough section size");
4202 return STATUS_FAILURE;
4205 uiTotalDataToCopy = ISOLength;
4207 CorruptISOSig(Adapter,ISO_IMAGE1);
4209 while(uiTotalDataToCopy)
4211 if(uiTotalDataToCopy == Adapter->uiSectorSize)
4213 //Setting for write of first sector. First sector is assumed to be written in last
4214 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Writing the signature sector");
4215 eISOReadPart = ISO_IMAGE2 ;
4216 uiReadOffsetWithinPart = 0;
4217 eISOWritePart = ISO_IMAGE1;
4218 uiWriteOffsetWithinPart = 0 ;
4219 IsThisHeaderSector = TRUE;
4224 uiReadOffsetWithinPart = uiReadOffsetWithinPart + Adapter->uiSectorSize ;
4225 uiWriteOffsetWithinPart = uiWriteOffsetWithinPart + Adapter->uiSectorSize ;
4227 if((eISOReadPart == ISO_IMAGE2) && (uiReadOffsetWithinPart == (Adapter->psFlash2xCSInfo->OffsetISOImage2Part1End - Adapter->psFlash2xCSInfo->OffsetISOImage2Part1Start) ))
4229 eISOReadPart = ISO_IMAGE2_PART2 ;
4230 uiReadOffsetWithinPart = 0;
4232 if((eISOReadPart == ISO_IMAGE2_PART2) && (uiReadOffsetWithinPart == (Adapter->psFlash2xCSInfo->OffsetISOImage2Part2End - Adapter->psFlash2xCSInfo->OffsetISOImage2Part2Start)))
4234 eISOReadPart = ISO_IMAGE2_PART3 ;
4235 uiReadOffsetWithinPart = 0;
4237 if((eISOWritePart == ISO_IMAGE1) && (uiWriteOffsetWithinPart == (Adapter->psFlash2xCSInfo->OffsetISOImage1Part1End - Adapter->psFlash2xCSInfo->OffsetISOImage1Part1Start)))
4239 eISOWritePart = ISO_IMAGE1_PART2 ;
4240 uiWriteOffsetWithinPart = 0;
4242 if((eISOWritePart == ISO_IMAGE1_PART2) && (uiWriteOffsetWithinPart == (Adapter->psFlash2xCSInfo->OffsetISOImage1Part2End - Adapter->psFlash2xCSInfo->OffsetISOImage1Part2Start)))
4244 eISOWritePart = ISO_IMAGE1_PART3 ;
4245 uiWriteOffsetWithinPart = 0;
4249 Status = BcmFlash2xBulkRead(Adapter,
4252 uiReadOffsetWithinPart,
4253 Adapter->uiSectorSize
4257 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Read failed while copying ISO: Part: %x, OffsetWithinPart: %x\n", eISOReadPart, uiReadOffsetWithinPart);
4261 if(IsThisHeaderSector == TRUE)
4263 //If this is header sector write 0xFFFFFFFF at the sig time and in last write sig
4264 memcpy(SigBuff, Buff + sigOffset, MAX_RW_SIZE);
4266 for(i = 0; i < MAX_RW_SIZE;i++)
4267 *(Buff + sigOffset + i) = 0xFF;
4270 Adapter->bHeaderChangeAllowed = TRUE ;
4271 Status = BcmFlash2xBulkWrite(Adapter,
4274 uiWriteOffsetWithinPart,
4275 Adapter->uiSectorSize,
4280 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Write failed while copying ISO: Part: %x, OffsetWithinPart: %x\n", eISOWritePart, uiWriteOffsetWithinPart);
4284 Adapter->bHeaderChangeAllowed = FALSE ;
4286 if(IsThisHeaderSector == TRUE)
4288 WriteToFlashWithoutSectorErase(Adapter,
4293 IsThisHeaderSector = FALSE ;
4296 //substracting the written Data
4297 uiTotalDataToCopy = uiTotalDataToCopy - Adapter->uiSectorSize ;
4308 BcmFlash2xCorruptSig : this API is used to corrupt the written sig in Bcm Header present in flash section.
4309 It will corrupt the sig, if Section is writable, by making first bytes as zero.
4310 @Adapater :- Bcm Driver Private Data Structure
4311 @eFlash2xSectionVal :- Flash section val which has header
4314 Sucess :- If Section is present and writable, corrupt the sig and return STATUS_SUCCESS
4315 Failure :-Return negative error code
4319 INT BcmFlash2xCorruptSig(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL eFlash2xSectionVal)
4322 INT Status = STATUS_SUCCESS ;
4323 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Section Value :%x \n", eFlash2xSectionVal);
4325 if((eFlash2xSectionVal == DSD0) || (eFlash2xSectionVal == DSD1) || (eFlash2xSectionVal == DSD2))
4327 Status = CorruptDSDSig(Adapter, eFlash2xSectionVal);
4329 else if(eFlash2xSectionVal == ISO_IMAGE1 || eFlash2xSectionVal == ISO_IMAGE2)
4331 Status = CorruptISOSig(Adapter, eFlash2xSectionVal);
4335 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Given Section <%d>does not have Header",eFlash2xSectionVal);
4336 return STATUS_SUCCESS;
4341 BcmFlash2xWriteSig :-this API is used to Write the sig if requested Section has
4342 header and Write Permission.
4343 @Adapater :- Bcm Driver Private Data Structure
4344 @eFlashSectionVal :- Flash section val which has header
4347 Sucess :- If Section is present and writable write the sig and return STATUS_SUCCESS
4348 Failure :-Return negative error code
4351 INT BcmFlash2xWriteSig(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL eFlashSectionVal)
4354 UINT uiSignature = 0 ;
4356 //DSD_HEADER dsdHeader = {0};
4358 if(Adapter->bSigCorrupted == FALSE)
4360 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Signature is not corrupted by driver, hence not restoring\n");
4361 return STATUS_SUCCESS;
4363 if(Adapter->bAllDSDWriteAllow == FALSE)
4365 if(IsSectionWritable(Adapter,eFlashSectionVal) == FALSE)
4367 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Section is not Writable...Hence can't Write signature");
4368 return SECTOR_IS_NOT_WRITABLE;
4371 if((eFlashSectionVal == DSD0) ||(eFlashSectionVal == DSD1) || (eFlashSectionVal == DSD2))
4373 uiSignature = htonl(DSD_IMAGE_MAGIC_NUMBER) ;
4374 uiOffset = Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader ;
4376 uiOffset += FIELD_OFFSET_IN_HEADER(PDSD_HEADER,DSDImageMagicNumber);
4378 if((ReadDSDSignature(Adapter,eFlashSectionVal) & 0xFF000000) != CORRUPTED_PATTERN)
4380 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Corrupted Pattern is not there. Hence won't write sig");
4381 return STATUS_FAILURE;
4385 else if((eFlashSectionVal == ISO_IMAGE1) || (eFlashSectionVal == ISO_IMAGE2))
4387 uiSignature = htonl(ISO_IMAGE_MAGIC_NUMBER);
4389 uiOffset = FIELD_OFFSET_IN_HEADER(PISO_HEADER,ISOImageMagicNumber);
4390 if((ReadISOSignature(Adapter,eFlashSectionVal) & 0xFF000000) != CORRUPTED_PATTERN)
4392 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Currupted Pattern is not there. Hence won't write sig");
4393 return STATUS_FAILURE;
4398 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"GIVEN SECTION< %d > IS NOT VALID FOR SIG WRITE...", eFlashSectionVal);
4399 return STATUS_FAILURE;
4402 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Restoring the signature");
4405 Adapter->bHeaderChangeAllowed = TRUE;
4406 Adapter->bSigCorrupted = FALSE;
4407 BcmFlash2xBulkWrite(Adapter, &uiSignature,eFlashSectionVal,uiOffset,SIGNATURE_SIZE,TRUE);
4408 Adapter->bHeaderChangeAllowed = FALSE;
4412 return STATUS_SUCCESS;
4415 validateFlash2xReadWrite :- This API is used to validate the user request for Read/Write.
4416 if requested Bytes goes beyond the Requested section, it reports error.
4417 @Adapater :- Bcm Driver Private Data Structure
4418 @psFlash2xReadWrite :-Flash2x Read/write structure pointer
4420 Return values:-Return TRUE is request is valid else FALSE.
4424 INT validateFlash2xReadWrite(PMINI_ADAPTER Adapter, PFLASH2X_READWRITE psFlash2xReadWrite)
4426 UINT uiNumOfBytes = 0 ;
4427 UINT uiSectStartOffset = 0 ;
4428 UINT uiSectEndOffset = 0;
4429 uiNumOfBytes = psFlash2xReadWrite->numOfBytes;
4431 if(IsSectionExistInFlash(Adapter,psFlash2xReadWrite->Section) != TRUE)
4433 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Section<%x> does not exixt in Flash",psFlash2xReadWrite->Section);
4436 uiSectStartOffset = BcmGetSectionValStartOffset(Adapter,psFlash2xReadWrite->Section);
4437 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Start offset :%x ,section :%d\n",uiSectStartOffset,psFlash2xReadWrite->Section);
4438 if((psFlash2xReadWrite->Section == ISO_IMAGE1) ||(psFlash2xReadWrite->Section == ISO_IMAGE2))
4440 if(psFlash2xReadWrite->Section == ISO_IMAGE1)
4442 uiSectEndOffset = BcmGetSectionValEndOffset(Adapter,ISO_IMAGE1) -
4443 BcmGetSectionValStartOffset(Adapter,ISO_IMAGE1)+
4444 BcmGetSectionValEndOffset(Adapter,ISO_IMAGE1_PART2) -
4445 BcmGetSectionValStartOffset(Adapter,ISO_IMAGE1_PART2)+
4446 BcmGetSectionValEndOffset(Adapter,ISO_IMAGE1_PART3) -
4447 BcmGetSectionValStartOffset(Adapter,ISO_IMAGE1_PART3);
4449 else if(psFlash2xReadWrite->Section == ISO_IMAGE2)
4451 uiSectEndOffset = BcmGetSectionValEndOffset(Adapter,ISO_IMAGE2) -
4452 BcmGetSectionValStartOffset(Adapter,ISO_IMAGE2)+
4453 BcmGetSectionValEndOffset(Adapter,ISO_IMAGE2_PART2) -
4454 BcmGetSectionValStartOffset(Adapter,ISO_IMAGE2_PART2)+
4455 BcmGetSectionValEndOffset(Adapter,ISO_IMAGE2_PART3) -
4456 BcmGetSectionValStartOffset(Adapter,ISO_IMAGE2_PART3);
4460 //since this uiSectEndoffset is the size of iso Image. hence for calculating the vitual endoffset
4461 //it should be added in startoffset. so that check done in last of this function can be valued.
4462 uiSectEndOffset = uiSectStartOffset + uiSectEndOffset ;
4464 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Total size of the ISO Image :%x",uiSectEndOffset);
4467 uiSectEndOffset = BcmGetSectionValEndOffset(Adapter,psFlash2xReadWrite->Section);
4468 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "End offset :%x \n",uiSectEndOffset);
4470 //Checking the boundary condition
4471 if((uiSectStartOffset + psFlash2xReadWrite->offset + uiNumOfBytes) <= uiSectEndOffset)
4475 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Invalid Request....");
4482 IsFlash2x :- check for Flash 2.x
4483 @Adapater :- Bcm Driver Private Data Structure
4486 return TRUE if flah2.x of hgher version else return false.
4489 INT IsFlash2x(PMINI_ADAPTER Adapter)
4491 if(Adapter->uiFlashLayoutMajorVersion >= FLASH_2X_MAJOR_NUMBER)
4497 GetFlashBaseAddr :- Calculate the Flash Base address
4498 @Adapater :- Bcm Driver Private Data Structure
4501 Success :- Base Address of the Flash
4504 INT GetFlashBaseAddr(PMINI_ADAPTER Adapter)
4507 UINT uiBaseAddr = 0;
4509 if(Adapter->bDDRInitDone)
4512 For All Valid Flash Versions... except 1.1, take the value from FlashBaseAddr
4513 In case of Raw Read... use the default value
4515 if(Adapter->uiFlashLayoutMajorVersion && (Adapter->bFlashRawRead == FALSE) &&
4516 !((Adapter->uiFlashLayoutMajorVersion == 1) && (Adapter->uiFlashLayoutMinorVersion == 1))
4518 uiBaseAddr = Adapter->uiFlashBaseAdd ;
4520 uiBaseAddr = FLASH_CONTIGIOUS_START_ADDR_AFTER_INIT;
4525 For All Valid Flash Versions... except 1.1, take the value from FlashBaseAddr
4526 In case of Raw Read... use the default value
4528 if(Adapter->uiFlashLayoutMajorVersion && (Adapter->bFlashRawRead == FALSE) &&
4529 !((Adapter->uiFlashLayoutMajorVersion == 1) && (Adapter->uiFlashLayoutMinorVersion == 1))
4531 uiBaseAddr = Adapter->uiFlashBaseAdd | FLASH_CONTIGIOUS_START_ADDR_BEFORE_INIT;
4533 uiBaseAddr = FLASH_CONTIGIOUS_START_ADDR_BEFORE_INIT;
4539 BcmCopySection :- This API is used to copy the One section in another. Both section should
4540 be contiuous and of same size. Hence this Will not be applicabe to copy ISO.
4542 @Adapater :- Bcm Driver Private Data Structure
4543 @SrcSection :- Source section From where data has to be copied
4544 @DstSection :- Destination section to which data has to be copied
4545 @offset :- Offset from/to where data has to be copied from one section to another.
4546 @numOfBytes :- number of byes that has to be copyed from one section to another at given offset.
4547 in case of numofBytes equal zero complete section will be copied.
4550 Sucess : Return STATUS_SUCCESS
4551 Faillure :- return negative error code
4555 INT BcmCopySection(PMINI_ADAPTER Adapter,
4556 FLASH2X_SECTION_VAL SrcSection,
4557 FLASH2X_SECTION_VAL DstSection,
4562 UINT BytesToBeCopied = 0;
4563 PUCHAR pBuff = NULL ;
4564 INT Status = STATUS_SUCCESS ;
4565 if(SrcSection == DstSection)
4567 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Source and Destination should be different ...try again");
4570 if((SrcSection != DSD0) && (SrcSection != DSD1) && (SrcSection != DSD2))
4572 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Source should be DSD subsection");
4575 if((DstSection != DSD0) && (DstSection != DSD1) && (DstSection != DSD2))
4577 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Destination should be DSD subsection");
4581 //if offset zero means have to copy complete secton
4585 numOfBytes = BcmGetSectionValEndOffset(Adapter,SrcSection)
4586 - BcmGetSectionValStartOffset(Adapter,SrcSection);
4588 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL," Section Size :0x%x",numOfBytes);
4591 if((offset + numOfBytes) > BcmGetSectionValEndOffset(Adapter,SrcSection)
4592 - BcmGetSectionValStartOffset(Adapter,SrcSection))
4594 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0," Input parameters going beyond the section offS: %x numB: %x of Source Section\n",
4595 offset, numOfBytes);
4599 if((offset + numOfBytes) > BcmGetSectionValEndOffset(Adapter,DstSection)
4600 - BcmGetSectionValStartOffset(Adapter,DstSection))
4602 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0," Input parameters going beyond the section offS: %x numB: %x of Destination Section\n",
4603 offset, numOfBytes);
4608 if(numOfBytes > Adapter->uiSectorSize )
4609 BuffSize = Adapter->uiSectorSize;
4611 BuffSize = numOfBytes ;
4613 pBuff = (PCHAR)kzalloc(BuffSize, GFP_KERNEL);
4616 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Memory allocation failed.. ");
4621 BytesToBeCopied = Adapter->uiSectorSize ;
4622 if(offset % Adapter->uiSectorSize)
4623 BytesToBeCopied = Adapter->uiSectorSize - (offset % Adapter->uiSectorSize);
4624 if(BytesToBeCopied > numOfBytes)
4625 BytesToBeCopied = numOfBytes ;
4629 Adapter->bHeaderChangeAllowed = TRUE;
4633 Status = BcmFlash2xBulkRead(Adapter, (PUINT)pBuff, SrcSection , offset,BytesToBeCopied);
4636 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Read failed at offset :%d for NOB :%d", SrcSection,BytesToBeCopied);
4639 Status = BcmFlash2xBulkWrite(Adapter,(PUINT)pBuff,DstSection,offset,BytesToBeCopied,FALSE);
4642 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Write failed at offset :%d for NOB :%d", DstSection,BytesToBeCopied);
4645 offset = offset + BytesToBeCopied;
4646 numOfBytes = numOfBytes - BytesToBeCopied ;
4649 if(numOfBytes > Adapter->uiSectorSize )
4650 BytesToBeCopied = Adapter->uiSectorSize;
4652 BytesToBeCopied = numOfBytes;
4654 }while(numOfBytes > 0) ;
4656 Adapter->bHeaderChangeAllowed = FALSE ;
4661 SaveHeaderIfPresent :- This API is use to Protect the Header in case of Header Sector write
4662 @Adapater :- Bcm Driver Private Data Structure
4663 @pBuff :- Data buffer that has to be written in sector having the header map.
4664 @uiOffset :- Flash offset that has to be written.
4667 Sucess :- On sucess return STATUS_SUCCESS
4668 Faillure :- Return negative error code
4672 INT SaveHeaderIfPresent(PMINI_ADAPTER Adapter, PUCHAR pBuff, UINT uiOffset)
4674 UINT offsetToProtect = 0,HeaderSizeToProtect =0;
4675 BOOLEAN bHasHeader = FALSE ;
4676 PUCHAR pTempBuff =NULL;
4677 UINT uiSectAlignAddr = 0;
4680 //making the offset sector alligned
4681 uiSectAlignAddr = uiOffset & ~(Adapter->uiSectorSize - 1);
4684 if((uiSectAlignAddr == BcmGetSectionValEndOffset(Adapter,DSD2)- Adapter->uiSectorSize)||
4685 (uiSectAlignAddr == BcmGetSectionValEndOffset(Adapter,DSD1)- Adapter->uiSectorSize)||
4686 (uiSectAlignAddr == BcmGetSectionValEndOffset(Adapter,DSD0)- Adapter->uiSectorSize))
4689 //offset from the sector boundry having the header map
4690 offsetToProtect = Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader % Adapter->uiSectorSize;
4691 HeaderSizeToProtect = sizeof(DSD_HEADER);
4695 if(uiSectAlignAddr == BcmGetSectionValStartOffset(Adapter,ISO_IMAGE1) ||
4696 uiSectAlignAddr == BcmGetSectionValStartOffset(Adapter,ISO_IMAGE2))
4698 offsetToProtect = 0;
4699 HeaderSizeToProtect = sizeof(ISO_HEADER);
4702 //If Header is present overwrite passed buffer with this
4703 if(bHasHeader && (Adapter->bHeaderChangeAllowed == FALSE))
4705 pTempBuff = (PUCHAR)kzalloc(HeaderSizeToProtect, GFP_KERNEL);
4706 if(pTempBuff == NULL)
4708 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Memory allocation failed ");
4712 BeceemFlashBulkRead(Adapter,(PUINT)pTempBuff,(uiSectAlignAddr + offsetToProtect),HeaderSizeToProtect);
4713 BCM_DEBUG_PRINT_BUFFER(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,pTempBuff ,HeaderSizeToProtect);
4714 //Replace Buffer content with Header
4715 memcpy(pBuff +offsetToProtect,pTempBuff,HeaderSizeToProtect);
4719 if(bHasHeader && Adapter->bSigCorrupted)
4721 sig = *((PUINT)(pBuff + offsetToProtect + FIELD_OFFSET_IN_HEADER(PDSD_HEADER,DSDImageMagicNumber)));
4723 if((sig & 0xFF000000) != CORRUPTED_PATTERN)
4725 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Desired pattern is not at sig offset. Hence won't restore");
4726 Adapter->bSigCorrupted = FALSE;
4727 return STATUS_SUCCESS;
4729 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL," Corrupted sig is :%X", sig);
4730 *((PUINT)(pBuff + offsetToProtect + FIELD_OFFSET_IN_HEADER(PDSD_HEADER,DSDImageMagicNumber)))= htonl(DSD_IMAGE_MAGIC_NUMBER);
4731 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Restoring the signature in Header Write only");
4732 Adapter->bSigCorrupted = FALSE;
4735 return STATUS_SUCCESS ;
4737 INT BcmMakeFlashCSActive(PMINI_ADAPTER Adapter, UINT offset)
4739 UINT GPIOConfig = 0 ;
4742 if(Adapter->bFlashRawRead == FALSE)
4744 //Applicable for Flash2.x
4745 if(IsFlash2x(Adapter) == FALSE)
4746 return STATUS_SUCCESS;
4749 if(offset/FLASH_PART_SIZE)
4751 //bit[14..12] -> will select make Active CS1, CS2 or CS3
4752 // Select CS1, CS2 and CS3 (CS0 is dedicated pin)
4753 rdmalt(Adapter,FLASH_GPIO_CONFIG_REG, &GPIOConfig, 4);
4754 GPIOConfig |= (7 << 12);
4755 wrmalt(Adapter,FLASH_GPIO_CONFIG_REG, &GPIOConfig, 4);
4758 return STATUS_SUCCESS ;
4761 BcmDoChipSelect : This will selcet the appropriate chip for writing.
4762 @Adapater :- Bcm Driver Private Data Structure
4765 Select the Appropriate chip and retrn status Sucess
4767 INT BcmDoChipSelect(PMINI_ADAPTER Adapter, UINT offset)
4769 UINT FlashConfig = 0;
4771 UINT GPIOConfig = 0;
4774 ChipNum = offset / FLASH_PART_SIZE ;
4777 // Chip Select mapping to enable flash0.
4778 // To select flash 0, we have to OR with (0<<12).
4779 // ORing 0 will have no impact so not doing that part.
4780 // In future if Chip select value changes from 0 to non zero,
4781 // That needs be taken care with backward comaptibility. No worries for now.
4785 SelectedChip Variable is the selection that the host is 100% Sure the same as what the register will hold. This can be ONLY ensured
4786 if the Chip doesn't goes to low power mode while the flash operation is in progress (NVMRdmWrmLock is taken)
4787 Before every new Flash Write operation, we reset the variable. This is to ensure that after any wake-up from
4788 power down modes (Idle mode/shutdown mode), the values in the register will be different.
4791 if(Adapter->SelectedChip == ChipNum)
4792 return STATUS_SUCCESS;
4794 //BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Selected Chip :%x", ChipNum);
4795 Adapter->SelectedChip = ChipNum ;
4797 //bit[13..12] will select the appropriate chip
4798 rdmalt(Adapter,FLASH_CONFIG_REG, &FlashConfig, 4);
4799 rdmalt(Adapter,FLASH_GPIO_CONFIG_REG, &GPIOConfig, 4);
4809 GPIOConfig |= (0x4 << CHIP_SELECT_BIT12);
4813 GPIOConfig |= (0x1 << CHIP_SELECT_BIT12);
4817 GPIOConfig |= (0x2 << CHIP_SELECT_BIT12);
4821 /* In case the bits already written in the FLASH_CONFIG_REG is same as what the user desired,
4822 nothing to do... can return immediately.
4823 ASSUMPTION: FLASH_GPIO_CONFIG_REG will be in sync with FLASH_CONFIG_REG.
4824 Even if the chip goes to low power mode, it should wake with values in each register in sync with each other.
4825 These values are not written by host other than during CHIP_SELECT.
4827 if(PartNum == ((FlashConfig >> CHIP_SELECT_BIT12) & 0x3))
4828 return STATUS_SUCCESS;
4830 //clearing the bit[13..12]
4831 FlashConfig &= 0xFFFFCFFF;
4832 FlashConfig = (FlashConfig | (PartNum<<CHIP_SELECT_BIT12)); //00
4834 wrmalt(Adapter,FLASH_GPIO_CONFIG_REG, &GPIOConfig, 4);
4837 wrmalt(Adapter,FLASH_CONFIG_REG, &FlashConfig, 4);
4840 return STATUS_SUCCESS;
4843 INT ReadDSDSignature(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL dsd)
4846 //UINT sigoffsetInMap = 0;
4847 //DSD_HEADER dsdHeader = {0};
4850 //sigoffsetInMap =(PUCHAR)&(dsdHeader.DSDImageMagicNumber) -(PUCHAR)&dsdHeader;
4852 if(dsd != DSD0 && dsd != DSD1 && dsd != DSD2)
4854 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"passed section value is not for DSDs");
4855 return STATUS_FAILURE;
4857 BcmFlash2xBulkRead(Adapter,
4860 Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + FIELD_OFFSET_IN_HEADER(PDSD_HEADER,DSDImageMagicNumber),
4863 uiDSDsig = ntohl(uiDSDsig);
4864 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"DSD SIG :%x", uiDSDsig);
4868 INT ReadDSDPriority(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL dsd)
4870 //UINT priOffsetInMap = 0 ;
4871 unsigned int uiDSDPri = STATUS_FAILURE;
4872 //DSD_HEADER dsdHeader = {0};
4873 //priOffsetInMap = (PUCHAR)&(dsdHeader.DSDImagePriority) -(PUCHAR)&dsdHeader;
4874 if(IsSectionWritable(Adapter,dsd))
4876 if(ReadDSDSignature(Adapter,dsd)== DSD_IMAGE_MAGIC_NUMBER)
4878 BcmFlash2xBulkRead(Adapter,
4881 Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader +FIELD_OFFSET_IN_HEADER(PDSD_HEADER, DSDImagePriority),
4884 uiDSDPri = ntohl(uiDSDPri);
4885 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"DSD<%x> Priority :%x", dsd, uiDSDPri);
4891 FLASH2X_SECTION_VAL getHighestPriDSD(PMINI_ADAPTER Adapter)
4893 INT DSDHighestPri = STATUS_FAILURE;
4895 FLASH2X_SECTION_VAL HighestPriDSD = 0 ;
4897 if(IsSectionWritable(Adapter,DSD2))
4899 DSDHighestPri = ReadDSDPriority(Adapter,DSD2);
4900 HighestPriDSD = DSD2 ;
4902 if(IsSectionWritable(Adapter,DSD1))
4904 DsdPri = ReadDSDPriority(Adapter,DSD1);
4905 if(DSDHighestPri < DsdPri)
4907 DSDHighestPri = DsdPri ;
4908 HighestPriDSD = DSD1;
4911 if(IsSectionWritable(Adapter,DSD0))
4913 DsdPri = ReadDSDPriority(Adapter,DSD0);
4914 if(DSDHighestPri < DsdPri)
4916 DSDHighestPri = DsdPri ;
4917 HighestPriDSD = DSD0;
4921 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Highest DSD :%x , and its Pri :%x", HighestPriDSD, DSDHighestPri);
4922 return HighestPriDSD ;
4925 INT ReadISOSignature(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL iso)
4928 //UINT sigoffsetInMap = 0;
4929 //ISO_HEADER ISOHeader = {0};
4932 //sigoffsetInMap =(PUCHAR)&(ISOHeader.ISOImageMagicNumber) -(PUCHAR)&ISOHeader;
4934 if(iso != ISO_IMAGE1 && iso != ISO_IMAGE2)
4936 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"passed section value is not for ISOs");
4937 return STATUS_FAILURE;
4939 BcmFlash2xBulkRead(Adapter,
4942 0 + FIELD_OFFSET_IN_HEADER(PISO_HEADER,ISOImageMagicNumber),
4945 uiISOsig = ntohl(uiISOsig);
4946 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"ISO SIG :%x", uiISOsig);
4950 INT ReadISOPriority(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL iso)
4953 unsigned int ISOPri = STATUS_FAILURE;
4954 if(IsSectionWritable(Adapter,iso))
4956 if(ReadISOSignature(Adapter,iso)== ISO_IMAGE_MAGIC_NUMBER)
4958 BcmFlash2xBulkRead(Adapter,
4961 0 + FIELD_OFFSET_IN_HEADER(PISO_HEADER, ISOImagePriority),
4964 ISOPri = ntohl(ISOPri);
4965 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"ISO<%x> Priority :%x", iso, ISOPri);
4971 FLASH2X_SECTION_VAL getHighestPriISO(PMINI_ADAPTER Adapter)
4973 INT ISOHighestPri = STATUS_FAILURE;
4975 FLASH2X_SECTION_VAL HighestPriISO = NO_SECTION_VAL ;
4977 if(IsSectionWritable(Adapter,ISO_IMAGE2))
4979 ISOHighestPri = ReadISOPriority(Adapter,ISO_IMAGE2);
4980 HighestPriISO = ISO_IMAGE2 ;
4982 if(IsSectionWritable(Adapter,ISO_IMAGE1))
4984 ISOPri = ReadISOPriority(Adapter,ISO_IMAGE1);
4985 if(ISOHighestPri < ISOPri)
4987 ISOHighestPri = ISOPri ;
4988 HighestPriISO = ISO_IMAGE1;
4992 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Highest ISO :%x and its Pri :%x",HighestPriISO,ISOHighestPri);
4993 return HighestPriISO ;
4995 INT WriteToFlashWithoutSectorErase(PMINI_ADAPTER Adapter,
4997 FLASH2X_SECTION_VAL eFlash2xSectionVal,
5002 #if !defined(BCM_SHM_INTERFACE) || defined(FLASH_DIRECT_ACCESS)
5003 UINT uiTemp = 0, value = 0 ;
5005 UINT uiPartOffset = 0;
5007 UINT uiStartOffset = 0;
5008 //Adding section start address
5009 INT Status = STATUS_SUCCESS;
5010 PUCHAR pcBuff = (PUCHAR)pBuff;
5012 if(uiNumBytes % Adapter->ulFlashWriteSize)
5014 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Writing without Sector Erase for non-FlashWriteSize number of bytes 0x%x\n", uiNumBytes);
5015 return STATUS_FAILURE;
5018 uiStartOffset = BcmGetSectionValStartOffset(Adapter,eFlash2xSectionVal);
5020 if(IsSectionExistInVendorInfo(Adapter,eFlash2xSectionVal))
5022 return vendorextnWriteSectionWithoutErase(Adapter, pcBuff, eFlash2xSectionVal, uiOffset, uiNumBytes);
5025 uiOffset = uiOffset + uiStartOffset;
5027 #if defined(BCM_SHM_INTERFACE) && !defined(FLASH_DIRECT_ACCESS)
5028 Status = bcmflash_raw_writenoerase((uiOffset/FLASH_PART_SIZE),(uiOffset % FLASH_PART_SIZE), pcBuff,uiNumBytes);
5030 rdmalt(Adapter, 0x0f000C80, &uiTemp, sizeof(uiTemp));
5032 wrmalt(Adapter, 0x0f000C80,&value, sizeof(value));
5034 Adapter->SelectedChip = RESET_CHIP_SELECT;
5035 BcmDoChipSelect(Adapter,uiOffset);
5036 uiPartOffset = (uiOffset & (FLASH_PART_SIZE - 1)) + GetFlashBaseAddr(Adapter);
5038 for(i = 0 ; i< uiNumBytes; i += Adapter->ulFlashWriteSize)
5040 if(Adapter->ulFlashWriteSize == BYTE_WRITE_SUPPORT)
5041 Status = flashByteWrite(Adapter,uiPartOffset, pcBuff);
5043 Status = flashWrite(Adapter,uiPartOffset, pcBuff);
5045 if(Status != STATUS_SUCCESS)
5048 pcBuff = pcBuff + Adapter->ulFlashWriteSize;
5049 uiPartOffset = uiPartOffset + Adapter->ulFlashWriteSize;
5051 wrmalt(Adapter, 0x0f000C80, &uiTemp, sizeof(uiTemp));
5052 Adapter->SelectedChip = RESET_CHIP_SELECT;
5058 BOOLEAN IsSectionExistInFlash(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL section)
5061 BOOLEAN SectionPresent = FALSE ;
5067 if((Adapter->psFlash2xCSInfo->OffsetISOImage1Part1Start != UNINIT_PTR_IN_CS) &&
5068 (IsNonCDLessDevice(Adapter) == FALSE))
5069 SectionPresent = TRUE ;
5072 if((Adapter->psFlash2xCSInfo->OffsetISOImage2Part1Start != UNINIT_PTR_IN_CS) &&
5073 (IsNonCDLessDevice(Adapter) == FALSE))
5074 SectionPresent = TRUE ;
5077 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForDSDStart != UNINIT_PTR_IN_CS)
5078 SectionPresent = TRUE ;
5081 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD1Start != UNINIT_PTR_IN_CS)
5082 SectionPresent = TRUE ;
5085 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD2Start != UNINIT_PTR_IN_CS)
5086 SectionPresent = TRUE ;
5089 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForVSAStart != UNINIT_PTR_IN_CS)
5090 SectionPresent = TRUE ;
5093 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA1Start != UNINIT_PTR_IN_CS)
5094 SectionPresent = TRUE ;
5097 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA2Start != UNINIT_PTR_IN_CS)
5098 SectionPresent = TRUE ;
5101 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForScsiFirmware != UNINIT_PTR_IN_CS)
5102 SectionPresent = TRUE ;
5104 case CONTROL_SECTION :
5105 if(Adapter->psFlash2xCSInfo->OffsetFromZeroForControlSectionStart != UNINIT_PTR_IN_CS)
5106 SectionPresent = TRUE ;
5109 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Section Does not exist in Flash 2.x");
5110 SectionPresent = FALSE;
5112 return SectionPresent ;
5114 INT IsSectionWritable(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL Section)
5116 INT offset = STATUS_FAILURE;
5118 if(IsSectionExistInFlash(Adapter,Section) == FALSE)
5120 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Section <%d> does not exixt", Section);
5123 offset = BcmGetSectionValStartOffset(Adapter,Section);
5124 if(offset == INVALID_OFFSET)
5126 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Section<%d> does not exixt", Section);
5130 if(IsSectionExistInVendorInfo(Adapter,Section))
5132 return !(Adapter->psFlash2xVendorInfo->VendorSection[Section].AccessFlags & FLASH2X_SECTION_RO);
5135 Status = IsOffsetWritable(Adapter,offset);
5139 INT CorruptDSDSig(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL eFlash2xSectionVal)
5142 PUCHAR pBuff = NULL;
5145 UINT BlockStatus = 0;
5146 UINT uiSectAlignAddr = 0;
5148 Adapter->bSigCorrupted = FALSE;
5150 if(Adapter->bAllDSDWriteAllow == FALSE)
5152 if(IsSectionWritable(Adapter,eFlash2xSectionVal) != TRUE)
5154 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Section is not Writable...Hence cant Corrupt signature");
5155 return SECTOR_IS_NOT_WRITABLE;
5159 pBuff = (PUCHAR)kzalloc(MAX_RW_SIZE, GFP_KERNEL);
5162 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Can't allocate memorey");
5166 uiOffset = Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + sizeof(DSD_HEADER);
5167 uiOffset -= MAX_RW_SIZE ;
5169 BcmFlash2xBulkRead(Adapter, (PUINT)pBuff,eFlash2xSectionVal,uiOffset,MAX_RW_SIZE);
5172 sig = *((PUINT)(pBuff +12));
5174 BCM_DEBUG_PRINT_BUFFER(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,pBuff,MAX_RW_SIZE);
5175 //Now corrupting the sig by corrupting 4th last Byte.
5178 if(sig == DSD_IMAGE_MAGIC_NUMBER)
5180 Adapter->bSigCorrupted = TRUE;
5181 if(Adapter->ulFlashWriteSize == BYTE_WRITE_SUPPORT)
5183 uiSectAlignAddr = uiOffset & ~(Adapter->uiSectorSize -1);
5184 BlockStatus = BcmFlashUnProtectBlock(Adapter,uiSectAlignAddr,Adapter->uiSectorSize);
5186 WriteToFlashWithoutSectorErase(Adapter,(PUINT)(pBuff + 12),eFlash2xSectionVal,
5187 (uiOffset + 12),BYTE_WRITE_SUPPORT);
5190 BcmRestoreBlockProtectStatus(Adapter,BlockStatus);
5196 WriteToFlashWithoutSectorErase(Adapter,(PUINT)pBuff,eFlash2xSectionVal,
5197 uiOffset ,MAX_RW_SIZE);
5202 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"BCM Signature is not present in header");
5204 return STATUS_FAILURE;
5208 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Corrupted the signature");
5209 return STATUS_SUCCESS ;
5212 INT CorruptISOSig(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL eFlash2xSectionVal)
5215 PUCHAR pBuff = NULL;
5219 Adapter->bSigCorrupted = FALSE;
5221 if(IsSectionWritable(Adapter,eFlash2xSectionVal) != TRUE)
5223 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Section is not Writable...Hence cant Corrupt signature");
5224 return SECTOR_IS_NOT_WRITABLE;
5227 pBuff = (PUCHAR)kzalloc(MAX_RW_SIZE, GFP_KERNEL);
5230 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Can't allocate memorey");
5236 BcmFlash2xBulkRead(Adapter, (PUINT)pBuff,eFlash2xSectionVal,uiOffset, MAX_RW_SIZE);
5238 sig = *((PUINT)pBuff);
5244 if(sig == ISO_IMAGE_MAGIC_NUMBER)
5246 Adapter->bSigCorrupted = TRUE;
5247 WriteToFlashWithoutSectorErase(Adapter,(PUINT)pBuff,eFlash2xSectionVal,
5248 uiOffset ,Adapter->ulFlashWriteSize);
5252 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"BCM Signature is not present in header");
5254 return STATUS_FAILURE;
5257 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Corrupted the signature");
5258 BCM_DEBUG_PRINT_BUFFER(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,pBuff,MAX_RW_SIZE);
5261 return STATUS_SUCCESS ;
5264 BOOLEAN IsNonCDLessDevice(PMINI_ADAPTER Adapter)
5266 if(Adapter->psFlash2xCSInfo->IsCDLessDeviceBootSig == NON_CDLESS_DEVICE_BOOT_SIG)