| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | #ifndef __BLK_NULL_BLK_H |
| 3 | #define __BLK_NULL_BLK_H |
| 4 | |
| 5 | #include <linux/blkdev.h> |
| 6 | #include <linux/slab.h> |
| 7 | #include <linux/blk-mq.h> |
| 8 | #include <linux/hrtimer.h> |
| 9 | #include <linux/configfs.h> |
| 10 | #include <linux/badblocks.h> |
| 11 | #include <linux/fault-inject.h> |
| 12 | |
| 13 | struct nullb_cmd { |
| 14 | struct list_head list; |
| 15 | struct llist_node ll_list; |
| 16 | struct __call_single_data csd; |
| 17 | struct request *rq; |
| 18 | struct bio *bio; |
| 19 | unsigned int tag; |
| 20 | blk_status_t error; |
| 21 | struct nullb_queue *nq; |
| 22 | struct hrtimer timer; |
| 23 | }; |
| 24 | |
| 25 | struct nullb_queue { |
| 26 | unsigned long *tag_map; |
| 27 | wait_queue_head_t wait; |
| 28 | unsigned int queue_depth; |
| 29 | struct nullb_device *dev; |
| 30 | unsigned int requeue_selection; |
| 31 | |
| 32 | struct nullb_cmd *cmds; |
| 33 | }; |
| 34 | |
| 35 | struct nullb_device { |
| 36 | struct nullb *nullb; |
| 37 | struct config_item item; |
| 38 | struct radix_tree_root data; /* data stored in the disk */ |
| 39 | struct radix_tree_root cache; /* disk cache data */ |
| 40 | unsigned long flags; /* device flags */ |
| 41 | unsigned int curr_cache; |
| 42 | struct badblocks badblocks; |
| 43 | |
| 44 | unsigned int nr_zones; |
| 45 | struct blk_zone *zones; |
| 46 | sector_t zone_size_sects; |
| 47 | |
| 48 | unsigned long size; /* device size in MB */ |
| 49 | unsigned long completion_nsec; /* time in ns to complete a request */ |
| 50 | unsigned long cache_size; /* disk cache size in MB */ |
| 51 | unsigned long zone_size; /* zone size in MB if device is zoned */ |
| 52 | unsigned int submit_queues; /* number of submission queues */ |
| 53 | unsigned int home_node; /* home node for the device */ |
| 54 | unsigned int queue_mode; /* block interface */ |
| 55 | unsigned int blocksize; /* block size */ |
| 56 | unsigned int irqmode; /* IRQ completion handler */ |
| 57 | unsigned int hw_queue_depth; /* queue depth */ |
| 58 | unsigned int index; /* index of the disk, only valid with a disk */ |
| 59 | unsigned int mbps; /* Bandwidth throttle cap (in MB/s) */ |
| 60 | bool blocking; /* blocking blk-mq device */ |
| 61 | bool use_per_node_hctx; /* use per-node allocation for hardware context */ |
| 62 | bool power; /* power on/off the device */ |
| 63 | bool memory_backed; /* if data is stored in memory */ |
| 64 | bool discard; /* if support discard */ |
| 65 | bool zoned; /* if device is zoned */ |
| 66 | }; |
| 67 | |
| 68 | struct nullb { |
| 69 | struct nullb_device *dev; |
| 70 | struct list_head list; |
| 71 | unsigned int index; |
| 72 | struct request_queue *q; |
| 73 | struct gendisk *disk; |
| 74 | struct blk_mq_tag_set *tag_set; |
| 75 | struct blk_mq_tag_set __tag_set; |
| 76 | unsigned int queue_depth; |
| 77 | atomic_long_t cur_bytes; |
| 78 | struct hrtimer bw_timer; |
| 79 | unsigned long cache_flush_pos; |
| 80 | spinlock_t lock; |
| 81 | |
| 82 | struct nullb_queue *queues; |
| 83 | unsigned int nr_queues; |
| 84 | char disk_name[DISK_NAME_LEN]; |
| 85 | }; |
| 86 | |
| 87 | #ifdef CONFIG_BLK_DEV_ZONED |
| 88 | int null_zone_init(struct nullb_device *dev); |
| 89 | void null_zone_exit(struct nullb_device *dev); |
| 90 | blk_status_t null_zone_report(struct nullb *nullb, struct bio *bio); |
| 91 | void null_zone_write(struct nullb_cmd *cmd, sector_t sector, |
| 92 | unsigned int nr_sectors); |
| 93 | void null_zone_reset(struct nullb_cmd *cmd, sector_t sector); |
| 94 | #else |
| 95 | static inline int null_zone_init(struct nullb_device *dev) |
| 96 | { |
| 97 | return -EINVAL; |
| 98 | } |
| 99 | static inline void null_zone_exit(struct nullb_device *dev) {} |
| 100 | static inline blk_status_t null_zone_report(struct nullb *nullb, |
| 101 | struct bio *bio) |
| 102 | { |
| 103 | return BLK_STS_NOTSUPP; |
| 104 | } |
| 105 | static inline void null_zone_write(struct nullb_cmd *cmd, sector_t sector, |
| 106 | unsigned int nr_sectors) |
| 107 | { |
| 108 | } |
| 109 | static inline void null_zone_reset(struct nullb_cmd *cmd, sector_t sector) {} |
| 110 | #endif /* CONFIG_BLK_DEV_ZONED */ |
| 111 | #endif /* __NULL_BLK_H */ |