1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __BLK_NULL_BLK_H
3 #define __BLK_NULL_BLK_H
6 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
8 #include <linux/blkdev.h>
9 #include <linux/slab.h>
10 #include <linux/blk-mq.h>
11 #include <linux/hrtimer.h>
12 #include <linux/configfs.h>
13 #include <linux/badblocks.h>
14 #include <linux/fault-inject.h>
21 struct nullb_queue *nq;
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;
32 struct nullb_cmd *cmds;
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;
44 unsigned int nr_zones;
45 unsigned int nr_zones_imp_open;
46 unsigned int nr_zones_exp_open;
47 unsigned int nr_zones_closed;
48 struct blk_zone *zones;
49 sector_t zone_size_sects;
51 unsigned long size; /* device size in MB */
52 unsigned long completion_nsec; /* time in ns to complete a request */
53 unsigned long cache_size; /* disk cache size in MB */
54 unsigned long zone_size; /* zone size in MB if device is zoned */
55 unsigned long zone_capacity; /* zone capacity in MB if device is zoned */
56 unsigned int zone_nr_conv; /* number of conventional zones */
57 unsigned int zone_max_open; /* max number of open zones */
58 unsigned int zone_max_active; /* max number of active zones */
59 unsigned int submit_queues; /* number of submission queues */
60 unsigned int home_node; /* home node for the device */
61 unsigned int queue_mode; /* block interface */
62 unsigned int blocksize; /* block size */
63 unsigned int irqmode; /* IRQ completion handler */
64 unsigned int hw_queue_depth; /* queue depth */
65 unsigned int index; /* index of the disk, only valid with a disk */
66 unsigned int mbps; /* Bandwidth throttle cap (in MB/s) */
67 bool blocking; /* blocking blk-mq device */
68 bool use_per_node_hctx; /* use per-node allocation for hardware context */
69 bool power; /* power on/off the device */
70 bool memory_backed; /* if data is stored in memory */
71 bool discard; /* if support discard */
72 bool zoned; /* if device is zoned */
76 struct nullb_device *dev;
77 struct list_head list;
79 struct request_queue *q;
81 struct blk_mq_tag_set *tag_set;
82 struct blk_mq_tag_set __tag_set;
83 unsigned int queue_depth;
84 atomic_long_t cur_bytes;
85 struct hrtimer bw_timer;
86 unsigned long cache_flush_pos;
89 struct nullb_queue *queues;
90 unsigned int nr_queues;
91 char disk_name[DISK_NAME_LEN];
94 blk_status_t null_process_cmd(struct nullb_cmd *cmd,
95 enum req_opf op, sector_t sector,
96 unsigned int nr_sectors);
98 #ifdef CONFIG_BLK_DEV_ZONED
99 int null_init_zoned_dev(struct nullb_device *dev, struct request_queue *q);
100 int null_register_zoned_dev(struct nullb *nullb);
101 void null_free_zoned_dev(struct nullb_device *dev);
102 int null_report_zones(struct gendisk *disk, sector_t sector,
103 unsigned int nr_zones, report_zones_cb cb, void *data);
104 blk_status_t null_process_zoned_cmd(struct nullb_cmd *cmd,
105 enum req_opf op, sector_t sector,
106 sector_t nr_sectors);
107 size_t null_zone_valid_read_len(struct nullb *nullb,
108 sector_t sector, unsigned int len);
110 static inline int null_init_zoned_dev(struct nullb_device *dev,
111 struct request_queue *q)
113 pr_err("CONFIG_BLK_DEV_ZONED not enabled\n");
116 static inline int null_register_zoned_dev(struct nullb *nullb)
120 static inline void null_free_zoned_dev(struct nullb_device *dev) {}
121 static inline blk_status_t null_process_zoned_cmd(struct nullb_cmd *cmd,
122 enum req_opf op, sector_t sector, sector_t nr_sectors)
124 return BLK_STS_NOTSUPP;
126 static inline size_t null_zone_valid_read_len(struct nullb *nullb,
132 #define null_report_zones NULL
133 #endif /* CONFIG_BLK_DEV_ZONED */
134 #endif /* __NULL_BLK_H */