ms_block.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /*
  2. * ms_block.h - Sony MemoryStick (legacy) storage support
  3. * Copyright (C) 2013 Maxim Levitsky <maximlevitsky@gmail.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * Minor portions of the driver are copied from mspro_block.c which is
  10. * Copyright (C) 2007 Alex Dubov <oakad@yahoo.com>
  11. *
  12. * Also ms structures were copied from old broken driver by same author
  13. * These probably come from MS spec
  14. *
  15. */
  16. #ifndef MS_BLOCK_NEW_H
  17. #define MS_BLOCK_NEW_H
  18. #define MS_BLOCK_MAX_SEGS 32
  19. #define MS_BLOCK_MAX_PAGES ((2 << 16) - 1)
  20. #define MS_BLOCK_MAX_BOOT_ADDR 0x000c
  21. #define MS_BLOCK_BOOT_ID 0x0001
  22. #define MS_BLOCK_INVALID 0xffff
  23. #define MS_MAX_ZONES 16
  24. #define MS_BLOCKS_IN_ZONE 512
  25. #define MS_BLOCK_MAP_LINE_SZ 16
  26. #define MS_BLOCK_PART_SHIFT 3
  27. #define MEMSTICK_UNCORR_ERROR (MEMSTICK_STATUS1_UCFG | \
  28. MEMSTICK_STATUS1_UCEX | MEMSTICK_STATUS1_UCDT)
  29. #define MEMSTICK_CORR_ERROR (MEMSTICK_STATUS1_FGER | MEMSTICK_STATUS1_EXER | \
  30. MEMSTICK_STATUS1_DTER)
  31. #define MEMSTICK_INT_ERROR (MEMSTICK_INT_CMDNAK | MEMSTICK_INT_ERR)
  32. #define MEMSTICK_OVERWRITE_FLAG_NORMAL \
  33. (MEMSTICK_OVERWRITE_PGST1 | \
  34. MEMSTICK_OVERWRITE_PGST0 | \
  35. MEMSTICK_OVERWRITE_BKST)
  36. #define MEMSTICK_OV_PG_NORMAL \
  37. (MEMSTICK_OVERWRITE_PGST1 | MEMSTICK_OVERWRITE_PGST0)
  38. #define MEMSTICK_MANAGEMENT_FLAG_NORMAL \
  39. (MEMSTICK_MANAGEMENT_SYSFLG | \
  40. MEMSTICK_MANAGEMENT_SCMS1 | \
  41. MEMSTICK_MANAGEMENT_SCMS0) \
  42. struct ms_boot_header {
  43. unsigned short block_id;
  44. unsigned short format_reserved;
  45. unsigned char reserved0[184];
  46. unsigned char data_entry;
  47. unsigned char reserved1[179];
  48. } __packed;
  49. struct ms_system_item {
  50. unsigned int start_addr;
  51. unsigned int data_size;
  52. unsigned char data_type_id;
  53. unsigned char reserved[3];
  54. } __packed;
  55. struct ms_system_entry {
  56. struct ms_system_item disabled_block;
  57. struct ms_system_item cis_idi;
  58. unsigned char reserved[24];
  59. } __packed;
  60. struct ms_boot_attr_info {
  61. unsigned char memorystick_class;
  62. unsigned char format_unique_value1;
  63. unsigned short block_size;
  64. unsigned short number_of_blocks;
  65. unsigned short number_of_effective_blocks;
  66. unsigned short page_size;
  67. unsigned char extra_data_size;
  68. unsigned char format_unique_value2;
  69. unsigned char assembly_time[8];
  70. unsigned char format_unique_value3;
  71. unsigned char serial_number[3];
  72. unsigned char assembly_manufacturer_code;
  73. unsigned char assembly_model_code[3];
  74. unsigned short memory_manufacturer_code;
  75. unsigned short memory_device_code;
  76. unsigned short implemented_capacity;
  77. unsigned char format_unique_value4[2];
  78. unsigned char vcc;
  79. unsigned char vpp;
  80. unsigned short controller_number;
  81. unsigned short controller_function;
  82. unsigned char reserved0[9];
  83. unsigned char transfer_supporting;
  84. unsigned short format_unique_value5;
  85. unsigned char format_type;
  86. unsigned char memorystick_application;
  87. unsigned char device_type;
  88. unsigned char reserved1[22];
  89. unsigned char format_uniqure_value6[2];
  90. unsigned char reserved2[15];
  91. } __packed;
  92. struct ms_cis_idi {
  93. unsigned short general_config;
  94. unsigned short logical_cylinders;
  95. unsigned short reserved0;
  96. unsigned short logical_heads;
  97. unsigned short track_size;
  98. unsigned short page_size;
  99. unsigned short pages_per_track;
  100. unsigned short msw;
  101. unsigned short lsw;
  102. unsigned short reserved1;
  103. unsigned char serial_number[20];
  104. unsigned short buffer_type;
  105. unsigned short buffer_size_increments;
  106. unsigned short long_command_ecc;
  107. unsigned char firmware_version[28];
  108. unsigned char model_name[18];
  109. unsigned short reserved2[5];
  110. unsigned short pio_mode_number;
  111. unsigned short dma_mode_number;
  112. unsigned short field_validity;
  113. unsigned short current_logical_cylinders;
  114. unsigned short current_logical_heads;
  115. unsigned short current_pages_per_track;
  116. unsigned int current_page_capacity;
  117. unsigned short mutiple_page_setting;
  118. unsigned int addressable_pages;
  119. unsigned short single_word_dma;
  120. unsigned short multi_word_dma;
  121. unsigned char reserved3[128];
  122. } __packed;
  123. struct ms_boot_page {
  124. struct ms_boot_header header;
  125. struct ms_system_entry entry;
  126. struct ms_boot_attr_info attr;
  127. } __packed;
  128. struct msb_data {
  129. unsigned int usage_count;
  130. struct memstick_dev *card;
  131. struct gendisk *disk;
  132. struct request_queue *queue;
  133. spinlock_t q_lock;
  134. struct hd_geometry geometry;
  135. struct attribute_group attr_group;
  136. struct request *req;
  137. int caps;
  138. int disk_id;
  139. /* IO */
  140. struct workqueue_struct *io_queue;
  141. bool io_queue_stopped;
  142. struct work_struct io_work;
  143. bool card_dead;
  144. /* Media properties */
  145. struct ms_boot_page *boot_page;
  146. u16 boot_block_locations[2];
  147. int boot_block_count;
  148. bool read_only;
  149. unsigned short page_size;
  150. int block_size;
  151. int pages_in_block;
  152. int zone_count;
  153. int block_count;
  154. int logical_block_count;
  155. /* FTL tables */
  156. unsigned long *used_blocks_bitmap;
  157. unsigned long *erased_blocks_bitmap;
  158. u16 *lba_to_pba_table;
  159. int free_block_count[MS_MAX_ZONES];
  160. bool ftl_initialized;
  161. /* Cache */
  162. unsigned char *cache;
  163. unsigned long valid_cache_bitmap;
  164. int cache_block_lba;
  165. bool need_flush_cache;
  166. struct timer_list cache_flush_timer;
  167. /* Preallocated buffers */
  168. unsigned char *block_buffer;
  169. struct scatterlist prealloc_sg[MS_BLOCK_MAX_SEGS+1];
  170. /* handler's local data */
  171. struct ms_register_addr reg_addr;
  172. bool addr_valid;
  173. u8 command_value;
  174. bool command_need_oob;
  175. struct scatterlist *current_sg;
  176. int current_sg_offset;
  177. struct ms_register regs;
  178. int current_page;
  179. int state;
  180. int exit_error;
  181. bool int_polling;
  182. unsigned long int_timeout;
  183. };
  184. enum msb_readpage_states {
  185. MSB_RP_SEND_BLOCK_ADDRESS = 0,
  186. MSB_RP_SEND_READ_COMMAND,
  187. MSB_RP_SEND_INT_REQ,
  188. MSB_RP_RECEIVE_INT_REQ_RESULT,
  189. MSB_RP_SEND_READ_STATUS_REG,
  190. MSB_RP_RECEIVE_STATUS_REG,
  191. MSB_RP_SEND_OOB_READ,
  192. MSB_RP_RECEIVE_OOB_READ,
  193. MSB_RP_SEND_READ_DATA,
  194. MSB_RP_RECEIVE_READ_DATA,
  195. };
  196. enum msb_write_block_states {
  197. MSB_WB_SEND_WRITE_PARAMS = 0,
  198. MSB_WB_SEND_WRITE_OOB,
  199. MSB_WB_SEND_WRITE_COMMAND,
  200. MSB_WB_SEND_INT_REQ,
  201. MSB_WB_RECEIVE_INT_REQ,
  202. MSB_WB_SEND_WRITE_DATA,
  203. MSB_WB_RECEIVE_WRITE_CONFIRMATION,
  204. };
  205. enum msb_send_command_states {
  206. MSB_SC_SEND_WRITE_PARAMS,
  207. MSB_SC_SEND_WRITE_OOB,
  208. MSB_SC_SEND_COMMAND,
  209. MSB_SC_SEND_INT_REQ,
  210. MSB_SC_RECEIVE_INT_REQ,
  211. };
  212. enum msb_reset_states {
  213. MSB_RS_SEND,
  214. MSB_RS_CONFIRM,
  215. };
  216. enum msb_par_switch_states {
  217. MSB_PS_SEND_SWITCH_COMMAND,
  218. MSB_PS_SWICH_HOST,
  219. MSB_PS_CONFIRM,
  220. };
  221. struct chs_entry {
  222. unsigned long size;
  223. unsigned char sec;
  224. unsigned short cyl;
  225. unsigned char head;
  226. };
  227. static int msb_reset(struct msb_data *msb, bool full);
  228. static int h_msb_default_bad(struct memstick_dev *card,
  229. struct memstick_request **mrq);
  230. #define __dbg(level, format, ...) \
  231. do { \
  232. if (debug >= level) \
  233. pr_err(format "\n", ## __VA_ARGS__); \
  234. } while (0)
  235. #define dbg(format, ...) __dbg(1, format, ## __VA_ARGS__)
  236. #define dbg_verbose(format, ...) __dbg(2, format, ## __VA_ARGS__)
  237. #endif