flash.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * NAND Flash Controller Device Driver
  3. * Copyright (c) 2009, Intel Corporation and its suppliers.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  17. *
  18. */
  19. #ifndef _FLASH_INTERFACE_
  20. #define _FLASH_INTERFACE_
  21. #include "ffsport.h"
  22. #include "spectraswconfig.h"
  23. #define MAX_BYTE_VALUE 0xFF
  24. #define MAX_WORD_VALUE 0xFFFF
  25. #define MAX_U32_VALUE 0xFFFFFFFF
  26. #define MAX_BLOCKNODE_VALUE 0xFFFFFF
  27. #define DISCARD_BLOCK 0x800000
  28. #define SPARE_BLOCK 0x400000
  29. #define BAD_BLOCK 0xC00000
  30. #define UNHIT_CACHE_ITEM 0xFFFF
  31. #define NAND_CACHE_INIT_ADDR 0xffffffffffffffffULL
  32. #define IN_PROGRESS_BLOCK_TABLE 0x00
  33. #define CURRENT_BLOCK_TABLE 0x01
  34. #define BTSIG_OFFSET (0)
  35. #define BTSIG_BYTES (5)
  36. #define BTSIG_DELTA (3)
  37. #define MAX_READ_COUNTER 0x2710
  38. #define FIRST_BT_ID (1)
  39. #define LAST_BT_ID (254)
  40. #define BTBLOCK_INVAL (u32)(0xFFFFFFFF)
  41. struct device_info_tag {
  42. u16 wDeviceMaker;
  43. u16 wDeviceID;
  44. u32 wDeviceType;
  45. u32 wSpectraStartBlock;
  46. u32 wSpectraEndBlock;
  47. u32 wTotalBlocks;
  48. u16 wPagesPerBlock;
  49. u16 wPageSize;
  50. u16 wPageDataSize;
  51. u16 wPageSpareSize;
  52. u16 wNumPageSpareFlag;
  53. u16 wECCBytesPerSector;
  54. u32 wBlockSize;
  55. u32 wBlockDataSize;
  56. u32 wDataBlockNum;
  57. u8 bPlaneNum;
  58. u16 wDeviceMainAreaSize;
  59. u16 wDeviceSpareAreaSize;
  60. u16 wDevicesConnected;
  61. u16 wDeviceWidth;
  62. u16 wHWRevision;
  63. u16 wHWFeatures;
  64. u16 wONFIDevFeatures;
  65. u16 wONFIOptCommands;
  66. u16 wONFITimingMode;
  67. u16 wONFIPgmCacheTimingMode;
  68. u16 MLCDevice;
  69. u16 wSpareSkipBytes;
  70. u8 nBitsInPageNumber;
  71. u8 nBitsInPageDataSize;
  72. u8 nBitsInBlockDataSize;
  73. };
  74. extern struct device_info_tag DeviceInfo;
  75. /* Cache item format */
  76. struct flash_cache_item_tag {
  77. u64 address;
  78. u16 use_cnt;
  79. u16 changed;
  80. u8 *buf;
  81. };
  82. struct flash_cache_tag {
  83. u32 cache_item_size; /* Size in bytes of each cache item */
  84. u16 pages_per_item; /* How many NAND pages in each cache item */
  85. u16 LRU; /* No. of the least recently used cache item */
  86. struct flash_cache_item_tag array[CACHE_ITEM_NUM];
  87. };
  88. /*
  89. *Data structure for each list node of the managment table
  90. * used for the Level 2 Cache. Each node maps one logical NAND block.
  91. */
  92. struct spectra_l2_cache_list {
  93. struct list_head list;
  94. u32 logical_blk_num; /* Logical block number */
  95. u32 pages_array[]; /* Page map array of this logical block.
  96. * Array index is the logical block number,
  97. * and for every item of this arry:
  98. * high 16 bit is index of the L2 cache block num,
  99. * low 16 bit is the phy page num
  100. * of the above L2 cache block.
  101. * This array will be kmalloc during run time.
  102. */
  103. };
  104. struct spectra_l2_cache_info {
  105. u32 blk_array[BLK_NUM_FOR_L2_CACHE];
  106. u16 cur_blk_idx; /* idx to the phy block number of current using */
  107. u16 cur_page_num; /* pages number of current using */
  108. struct spectra_l2_cache_list table; /* First node of the table */
  109. };
  110. #define RESTORE_CACHE_ON_CDMA_CHAIN_FAILURE 1
  111. #if RESTORE_CACHE_ON_CDMA_CHAIN_FAILURE
  112. struct flash_cache_mod_item_tag {
  113. u64 address;
  114. u8 changed;
  115. };
  116. struct flash_cache_delta_list_tag {
  117. u8 item; /* used cache item */
  118. struct flash_cache_mod_item_tag cache;
  119. };
  120. #endif
  121. extern struct flash_cache_tag Cache;
  122. extern u8 *buf_read_page_main_spare;
  123. extern u8 *buf_write_page_main_spare;
  124. extern u8 *buf_read_page_spare;
  125. extern u8 *buf_get_bad_block;
  126. extern u8 *cdma_desc_buf;
  127. extern u8 *memcp_desc_buf;
  128. /* struture used for IndentfyDevice function */
  129. struct spectra_indentfy_dev_tag {
  130. u32 NumBlocks;
  131. u16 PagesPerBlock;
  132. u16 PageDataSize;
  133. u16 wECCBytesPerSector;
  134. u32 wDataBlockNum;
  135. };
  136. int GLOB_FTL_Flash_Init(void);
  137. int GLOB_FTL_Flash_Release(void);
  138. /*void GLOB_FTL_Erase_Flash(void);*/
  139. int GLOB_FTL_Block_Erase(u64 block_addr);
  140. int GLOB_FTL_Is_BadBlock(u32 block_num);
  141. int GLOB_FTL_IdentifyDevice(struct spectra_indentfy_dev_tag *dev_data);
  142. int GLOB_FTL_Event_Status(int *);
  143. u16 glob_ftl_execute_cmds(void);
  144. /*int FTL_Read_Disturbance(ADDRESSTYPE dwBlockAddr);*/
  145. int FTL_Read_Disturbance(u32 dwBlockAddr);
  146. /*Flash r/w based on cache*/
  147. int GLOB_FTL_Page_Read(u8 *read_data, u64 page_addr);
  148. int GLOB_FTL_Page_Write(u8 *write_data, u64 page_addr);
  149. int GLOB_FTL_Wear_Leveling(void);
  150. int GLOB_FTL_Flash_Format(void);
  151. int GLOB_FTL_Init(void);
  152. int GLOB_FTL_Flush_Cache(void);
  153. int GLOB_FTL_Garbage_Collection(void);
  154. int GLOB_FTL_BT_Garbage_Collection(void);
  155. void GLOB_FTL_Cache_Release(void);
  156. u8 *get_blk_table_start_addr(void);
  157. u8 *get_wear_leveling_table_start_addr(void);
  158. unsigned long get_blk_table_len(void);
  159. unsigned long get_wear_leveling_table_len(void);
  160. #if DEBUG_BNDRY
  161. void debug_boundary_lineno_error(int chnl, int limit, int no, int lineno,
  162. char *filename);
  163. #define debug_boundary_error(chnl, limit, no) debug_boundary_lineno_error(chnl,\
  164. limit, no, __LINE__, __FILE__)
  165. #else
  166. #define debug_boundary_error(chnl, limit, no) ;
  167. #endif
  168. #endif /*_FLASH_INTERFACE_*/