sm_ftl.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. /* Geometry stuff */
  48. int heads;
  49. int sectors;
  50. int cylinders;
  51. struct attribute_group *disk_attributes;
  52. };
  53. struct chs_entry {
  54. unsigned long size;
  55. unsigned short cyl;
  56. unsigned char head;
  57. unsigned char sec;
  58. };
  59. #define SM_FTL_PARTN_BITS 3
  60. #define sm_printk(format, ...) \
  61. printk(KERN_WARNING "sm_ftl" ": " format "\n", ## __VA_ARGS__)
  62. #define dbg(format, ...) \
  63. if (debug) \
  64. printk(KERN_DEBUG "sm_ftl" ": " format "\n", ## __VA_ARGS__)
  65. #define dbg_verbose(format, ...) \
  66. if (debug > 1) \
  67. printk(KERN_DEBUG "sm_ftl" ": " format "\n", ## __VA_ARGS__)
  68. static int sm_erase_block(struct sm_ftl *ftl, int zone_num, uint16_t block,
  69. int put_free);
  70. static void sm_mark_block_bad(struct sm_ftl *ftl, int zone_num, int block);
  71. static int sm_recheck_media(struct sm_ftl *ftl);