sm_ftl.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright © 2009 - Maxim Levitsky
  3. * SmartMedia/xD translation layer
  4. *
  5. * Based loosly on ssfdc.c which is
  6. * © 2005 Eptar srl
  7. * Author: Claudio Lanconelli <lanconelli.claudio@eptar.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/mtd/blktrans.h>
  14. #include <linux/kfifo.h>
  15. #include <linux/sched.h>
  16. #include <linux/completion.h>
  17. #include <linux/mtd/mtd.h>
  18. struct ftl_zone {
  19. bool initialized;
  20. int16_t *lba_to_phys_table; /* LBA to physical table */
  21. struct kfifo free_sectors; /* queue of free sectors */
  22. };
  23. struct sm_ftl {
  24. struct mtd_blktrans_dev *trans;
  25. struct mutex mutex; /* protects the structure */
  26. struct ftl_zone *zones; /* FTL tables for each zone */
  27. /* Media information */
  28. int block_size; /* block size in bytes */
  29. int zone_size; /* zone size in blocks */
  30. int zone_count; /* number of zones */
  31. int max_lba; /* maximum lba in a zone */
  32. int smallpagenand; /* 256 bytes/page nand */
  33. bool readonly; /* is FS readonly */
  34. bool unstable;
  35. int cis_block; /* CIS block location */
  36. int cis_boffset; /* CIS offset in the block */
  37. int cis_page_offset; /* CIS offset in the page */
  38. void *cis_buffer; /* tmp buffer for cis reads */
  39. /* Cache */
  40. int cache_block; /* block number of cached block */
  41. int cache_zone; /* zone of cached block */
  42. unsigned char *cache_data; /* cached block data */
  43. long unsigned int cache_data_invalid_bitmap;
  44. bool cache_clean;
  45. struct work_struct flush_work;
  46. struct timer_list timer;
  47. /* Async erase stuff */
  48. struct completion erase_completion;
  49. /* Geometry stuff */
  50. int heads;
  51. int sectors;
  52. int cylinders;
  53. struct attribute_group *disk_attributes;
  54. };
  55. struct chs_entry {
  56. unsigned long size;
  57. unsigned short cyl;
  58. unsigned char head;
  59. unsigned char sec;
  60. };
  61. #define SM_FTL_PARTN_BITS 3
  62. #define sm_printk(format, ...) \
  63. printk(KERN_WARNING "sm_ftl" ": " format "\n", ## __VA_ARGS__)
  64. #define dbg(format, ...) \
  65. if (debug) \
  66. printk(KERN_DEBUG "sm_ftl" ": " format "\n", ## __VA_ARGS__)
  67. #define dbg_verbose(format, ...) \
  68. if (debug > 1) \
  69. printk(KERN_DEBUG "sm_ftl" ": " format "\n", ## __VA_ARGS__)
  70. static void sm_erase_callback(struct erase_info *self);
  71. static int sm_erase_block(struct sm_ftl *ftl, int zone_num, uint16_t block,
  72. int put_free);
  73. static void sm_mark_block_bad(struct sm_ftl *ftl, int zone_num, int block);
  74. static int sm_recheck_media(struct sm_ftl *ftl);