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>
17 struct list_head list
;
18 struct llist_node ll_list
;
19 struct __call_single_data csd
;
24 struct nullb_queue
*nq
;
29 unsigned long *tag_map
;
30 wait_queue_head_t wait
;
31 unsigned int queue_depth
;
32 struct nullb_device
*dev
;
33 unsigned int requeue_selection
;
35 struct nullb_cmd
*cmds
;
40 struct config_item item
;
41 struct radix_tree_root data
; /* data stored in the disk */
42 struct radix_tree_root cache
; /* disk cache data */
43 unsigned long flags
; /* device flags */
44 unsigned int curr_cache
;
45 struct badblocks badblocks
;
47 unsigned int nr_zones
;
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 int zone_nr_conv
; /* number of conventional zones */
56 unsigned int submit_queues
; /* number of submission queues */
57 unsigned int home_node
; /* home node for the device */
58 unsigned int queue_mode
; /* block interface */
59 unsigned int blocksize
; /* block size */
60 unsigned int irqmode
; /* IRQ completion handler */
61 unsigned int hw_queue_depth
; /* queue depth */
62 unsigned int index
; /* index of the disk, only valid with a disk */
63 unsigned int mbps
; /* Bandwidth throttle cap (in MB/s) */
64 bool blocking
; /* blocking blk-mq device */
65 bool use_per_node_hctx
; /* use per-node allocation for hardware context */
66 bool power
; /* power on/off the device */
67 bool memory_backed
; /* if data is stored in memory */
68 bool discard
; /* if support discard */
69 bool zoned
; /* if device is zoned */
73 struct nullb_device
*dev
;
74 struct list_head list
;
76 struct request_queue
*q
;
78 struct blk_mq_tag_set
*tag_set
;
79 struct blk_mq_tag_set __tag_set
;
80 unsigned int queue_depth
;
81 atomic_long_t cur_bytes
;
82 struct hrtimer bw_timer
;
83 unsigned long cache_flush_pos
;
86 struct nullb_queue
*queues
;
87 unsigned int nr_queues
;
88 char disk_name
[DISK_NAME_LEN
];
91 #ifdef CONFIG_BLK_DEV_ZONED
92 int null_zone_init(struct nullb_device
*dev
);
93 void null_zone_exit(struct nullb_device
*dev
);
94 int null_zone_report(struct gendisk
*disk
, sector_t sector
,
95 struct blk_zone
*zones
, unsigned int *nr_zones
);
96 blk_status_t
null_handle_zoned(struct nullb_cmd
*cmd
,
97 enum req_opf op
, sector_t sector
,
100 static inline int null_zone_init(struct nullb_device
*dev
)
102 pr_err("CONFIG_BLK_DEV_ZONED not enabled\n");
105 static inline void null_zone_exit(struct nullb_device
*dev
) {}
106 static inline int null_zone_report(struct gendisk
*disk
, sector_t sector
,
107 struct blk_zone
*zones
,
108 unsigned int *nr_zones
)
112 static inline blk_status_t
null_handle_zoned(struct nullb_cmd
*cmd
,
113 enum req_opf op
, sector_t sector
,
116 return BLK_STS_NOTSUPP
;
118 #endif /* CONFIG_BLK_DEV_ZONED */
119 #endif /* __NULL_BLK_H */