Merge drm/drm-next into drm-intel-next-queued
[linux-2.6-microblaze.git] / drivers / block / null_blk.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __BLK_NULL_BLK_H
3 #define __BLK_NULL_BLK_H
4
5 #undef pr_fmt
6 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
7
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>
15
16 struct nullb_cmd {
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 zone_nr_conv; /* number of conventional zones */
53         unsigned int submit_queues; /* number of submission queues */
54         unsigned int home_node; /* home node for the device */
55         unsigned int queue_mode; /* block interface */
56         unsigned int blocksize; /* block size */
57         unsigned int irqmode; /* IRQ completion handler */
58         unsigned int hw_queue_depth; /* queue depth */
59         unsigned int index; /* index of the disk, only valid with a disk */
60         unsigned int mbps; /* Bandwidth throttle cap (in MB/s) */
61         bool blocking; /* blocking blk-mq device */
62         bool use_per_node_hctx; /* use per-node allocation for hardware context */
63         bool power; /* power on/off the device */
64         bool memory_backed; /* if data is stored in memory */
65         bool discard; /* if support discard */
66         bool zoned; /* if device is zoned */
67 };
68
69 struct nullb {
70         struct nullb_device *dev;
71         struct list_head list;
72         unsigned int index;
73         struct request_queue *q;
74         struct gendisk *disk;
75         struct blk_mq_tag_set *tag_set;
76         struct blk_mq_tag_set __tag_set;
77         unsigned int queue_depth;
78         atomic_long_t cur_bytes;
79         struct hrtimer bw_timer;
80         unsigned long cache_flush_pos;
81         spinlock_t lock;
82
83         struct nullb_queue *queues;
84         unsigned int nr_queues;
85         char disk_name[DISK_NAME_LEN];
86 };
87
88 blk_status_t null_process_cmd(struct nullb_cmd *cmd,
89                               enum req_opf op, sector_t sector,
90                               unsigned int nr_sectors);
91
92 #ifdef CONFIG_BLK_DEV_ZONED
93 int null_init_zoned_dev(struct nullb_device *dev, struct request_queue *q);
94 int null_register_zoned_dev(struct nullb *nullb);
95 void null_free_zoned_dev(struct nullb_device *dev);
96 int null_report_zones(struct gendisk *disk, sector_t sector,
97                       unsigned int nr_zones, report_zones_cb cb, void *data);
98 blk_status_t null_process_zoned_cmd(struct nullb_cmd *cmd,
99                                     enum req_opf op, sector_t sector,
100                                     sector_t nr_sectors);
101 size_t null_zone_valid_read_len(struct nullb *nullb,
102                                 sector_t sector, unsigned int len);
103 #else
104 static inline int null_init_zoned_dev(struct nullb_device *dev,
105                                       struct request_queue *q)
106 {
107         pr_err("CONFIG_BLK_DEV_ZONED not enabled\n");
108         return -EINVAL;
109 }
110 static inline int null_register_zoned_dev(struct nullb *nullb)
111 {
112         return -ENODEV;
113 }
114 static inline void null_free_zoned_dev(struct nullb_device *dev) {}
115 static inline blk_status_t null_process_zoned_cmd(struct nullb_cmd *cmd,
116                         enum req_opf op, sector_t sector, sector_t nr_sectors)
117 {
118         return BLK_STS_NOTSUPP;
119 }
120 static inline size_t null_zone_valid_read_len(struct nullb *nullb,
121                                               sector_t sector,
122                                               unsigned int len)
123 {
124         return len;
125 }
126 #define null_report_zones       NULL
127 #endif /* CONFIG_BLK_DEV_ZONED */
128 #endif /* __NULL_BLK_H */