Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright © 2009 - Maxim Levitsky
0004  * SmartMedia/xD translation layer
0005  *
0006  * Based loosly on ssfdc.c which is
0007  *  © 2005 Eptar srl
0008  *  Author: Claudio Lanconelli <lanconelli.claudio@eptar.com>
0009  */
0010 
0011 #include <linux/mtd/blktrans.h>
0012 #include <linux/kfifo.h>
0013 #include <linux/sched.h>
0014 #include <linux/completion.h>
0015 #include <linux/mtd/mtd.h>
0016 
0017 
0018 
0019 struct ftl_zone {
0020     bool initialized;
0021     int16_t *lba_to_phys_table;     /* LBA to physical table */
0022     struct kfifo free_sectors;  /* queue of free sectors */
0023 };
0024 
0025 struct sm_ftl {
0026     struct mtd_blktrans_dev *trans;
0027 
0028     struct mutex mutex;     /* protects the structure */
0029     struct ftl_zone *zones;     /* FTL tables for each zone */
0030 
0031     /* Media information */
0032     int block_size;         /* block size in bytes */
0033     int zone_size;          /* zone size in blocks */
0034     int zone_count;         /* number of zones */
0035     int max_lba;            /* maximum lba in a zone */
0036     int smallpagenand;      /* 256 bytes/page nand */
0037     bool readonly;          /* is FS readonly */
0038     bool unstable;
0039     int cis_block;          /* CIS block location */
0040     int cis_boffset;        /* CIS offset in the block */
0041     int cis_page_offset;        /* CIS offset in the page */
0042     void *cis_buffer;       /* tmp buffer for cis reads */
0043 
0044     /* Cache */
0045     int cache_block;        /* block number of cached block */
0046     int cache_zone;         /* zone of cached block */
0047     unsigned char *cache_data;  /* cached block data */
0048     long unsigned int cache_data_invalid_bitmap;
0049     bool cache_clean;
0050     struct work_struct flush_work;
0051     struct timer_list timer;
0052 
0053     /* Geometry stuff */
0054     int heads;
0055     int sectors;
0056     int cylinders;
0057 
0058     struct attribute_group *disk_attributes;
0059 };
0060 
0061 struct chs_entry {
0062     unsigned long size;
0063     unsigned short cyl;
0064     unsigned char head;
0065     unsigned char sec;
0066 };
0067 
0068 
0069 #define SM_FTL_PARTN_BITS   3
0070 
0071 #define sm_printk(format, ...) \
0072     printk(KERN_WARNING "sm_ftl" ": " format "\n", ## __VA_ARGS__)
0073 
0074 #define dbg(format, ...) \
0075     if (debug) \
0076         printk(KERN_DEBUG "sm_ftl" ": " format "\n", ## __VA_ARGS__)
0077 
0078 #define dbg_verbose(format, ...) \
0079     if (debug > 1) \
0080         printk(KERN_DEBUG "sm_ftl" ": " format "\n", ## __VA_ARGS__)
0081 
0082 
0083 static int sm_erase_block(struct sm_ftl *ftl, int zone_num, uint16_t block,
0084                                 int put_free);
0085 static void sm_mark_block_bad(struct sm_ftl *ftl, int zone_num, int block);
0086 
0087 static int sm_recheck_media(struct sm_ftl *ftl);