sm_ftl.h 2.2 KB

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