b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 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 <lanconelli.claudio@eptar.com> |
| 9 | */ |
| 10 | |
| 11 | #include <linux/mtd/blktrans.h> |
| 12 | #include <linux/kfifo.h> |
| 13 | #include <linux/sched.h> |
| 14 | #include <linux/completion.h> |
| 15 | #include <linux/mtd/mtd.h> |
| 16 | |
| 17 | |
| 18 | |
| 19 | struct ftl_zone { |
| 20 | bool initialized; |
| 21 | int16_t *lba_to_phys_table; /* LBA to physical table */ |
| 22 | struct kfifo free_sectors; /* queue of free sectors */ |
| 23 | }; |
| 24 | |
| 25 | struct sm_ftl { |
| 26 | struct mtd_blktrans_dev *trans; |
| 27 | |
| 28 | struct mutex mutex; /* protects the structure */ |
| 29 | struct ftl_zone *zones; /* FTL tables for each zone */ |
| 30 | |
| 31 | /* Media information */ |
| 32 | int block_size; /* block size in bytes */ |
| 33 | int zone_size; /* zone size in blocks */ |
| 34 | int zone_count; /* number of zones */ |
| 35 | int max_lba; /* maximum lba in a zone */ |
| 36 | int smallpagenand; /* 256 bytes/page nand */ |
| 37 | bool readonly; /* is FS readonly */ |
| 38 | bool unstable; |
| 39 | int cis_block; /* CIS block location */ |
| 40 | int cis_boffset; /* CIS offset in the block */ |
| 41 | int cis_page_offset; /* CIS offset in the page */ |
| 42 | void *cis_buffer; /* tmp buffer for cis reads */ |
| 43 | |
| 44 | /* Cache */ |
| 45 | int cache_block; /* block number of cached block */ |
| 46 | int cache_zone; /* zone of cached block */ |
| 47 | unsigned char *cache_data; /* cached block data */ |
| 48 | long unsigned int cache_data_invalid_bitmap; |
| 49 | bool cache_clean; |
| 50 | struct work_struct flush_work; |
| 51 | struct timer_list timer; |
| 52 | |
| 53 | /* Geometry stuff */ |
| 54 | int heads; |
| 55 | int sectors; |
| 56 | int cylinders; |
| 57 | |
| 58 | struct attribute_group *disk_attributes; |
| 59 | }; |
| 60 | |
| 61 | struct chs_entry { |
| 62 | unsigned long size; |
| 63 | unsigned short cyl; |
| 64 | unsigned char head; |
| 65 | unsigned char sec; |
| 66 | }; |
| 67 | |
| 68 | |
| 69 | #define SM_FTL_PARTN_BITS 3 |
| 70 | |
| 71 | #define sm_printk(format, ...) \ |
| 72 | printk(KERN_WARNING "sm_ftl" ": " format "\n", ## __VA_ARGS__) |
| 73 | |
| 74 | #define dbg(format, ...) \ |
| 75 | if (debug) \ |
| 76 | printk(KERN_DEBUG "sm_ftl" ": " format "\n", ## __VA_ARGS__) |
| 77 | |
| 78 | #define dbg_verbose(format, ...) \ |
| 79 | if (debug > 1) \ |
| 80 | printk(KERN_DEBUG "sm_ftl" ": " format "\n", ## __VA_ARGS__) |
| 81 | |
| 82 | |
| 83 | static int sm_erase_block(struct sm_ftl *ftl, int zone_num, uint16_t block, |
| 84 | int put_free); |
| 85 | static void sm_mark_block_bad(struct sm_ftl *ftl, int zone_num, int block); |
| 86 | |
| 87 | static int sm_recheck_media(struct sm_ftl *ftl); |