Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) #ifndef __BLK_NULL_BLK_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #define __BLK_NULL_BLK_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #undef pr_fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/blk-mq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/hrtimer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/configfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/badblocks.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/fault-inject.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) struct nullb_cmd {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 	struct request *rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 	struct bio *bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	unsigned int tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	blk_status_t error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	struct nullb_queue *nq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	struct hrtimer timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	bool fake_timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) struct nullb_queue {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	unsigned long *tag_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	wait_queue_head_t wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	unsigned int queue_depth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	struct nullb_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	unsigned int requeue_selection;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	struct nullb_cmd *cmds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) struct nullb_device {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	struct nullb *nullb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	struct config_item item;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	struct radix_tree_root data; /* data stored in the disk */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	struct radix_tree_root cache; /* disk cache data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	unsigned long flags; /* device flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	unsigned int curr_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	struct badblocks badblocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	unsigned int nr_zones;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	unsigned int nr_zones_imp_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	unsigned int nr_zones_exp_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	unsigned int nr_zones_closed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	struct blk_zone *zones;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	sector_t zone_size_sects;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	spinlock_t zone_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	unsigned long *zone_locks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	unsigned long size; /* device size in MB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	unsigned long completion_nsec; /* time in ns to complete a request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	unsigned long cache_size; /* disk cache size in MB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	unsigned long zone_size; /* zone size in MB if device is zoned */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	unsigned long zone_capacity; /* zone capacity in MB if device is zoned */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	unsigned int zone_nr_conv; /* number of conventional zones */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	unsigned int zone_max_open; /* max number of open zones */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	unsigned int zone_max_active; /* max number of active zones */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	unsigned int submit_queues; /* number of submission queues */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	unsigned int home_node; /* home node for the device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	unsigned int queue_mode; /* block interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	unsigned int blocksize; /* block size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	unsigned int irqmode; /* IRQ completion handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	unsigned int hw_queue_depth; /* queue depth */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	unsigned int index; /* index of the disk, only valid with a disk */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	unsigned int mbps; /* Bandwidth throttle cap (in MB/s) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	bool blocking; /* blocking blk-mq device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	bool use_per_node_hctx; /* use per-node allocation for hardware context */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	bool power; /* power on/off the device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	bool memory_backed; /* if data is stored in memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	bool discard; /* if support discard */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	bool zoned; /* if device is zoned */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) struct nullb {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	struct nullb_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	unsigned int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	struct request_queue *q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	struct gendisk *disk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	struct blk_mq_tag_set *tag_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	struct blk_mq_tag_set __tag_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	unsigned int queue_depth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	atomic_long_t cur_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	struct hrtimer bw_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	unsigned long cache_flush_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	spinlock_t lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	struct nullb_queue *queues;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	unsigned int nr_queues;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	char disk_name[DISK_NAME_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) blk_status_t null_process_cmd(struct nullb_cmd *cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 			      enum req_opf op, sector_t sector,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			      unsigned int nr_sectors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #ifdef CONFIG_BLK_DEV_ZONED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) int null_init_zoned_dev(struct nullb_device *dev, struct request_queue *q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) int null_register_zoned_dev(struct nullb *nullb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) void null_free_zoned_dev(struct nullb_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) int null_report_zones(struct gendisk *disk, sector_t sector,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		      unsigned int nr_zones, report_zones_cb cb, void *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) blk_status_t null_process_zoned_cmd(struct nullb_cmd *cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 				    enum req_opf op, sector_t sector,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 				    sector_t nr_sectors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) size_t null_zone_valid_read_len(struct nullb *nullb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 				sector_t sector, unsigned int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static inline int null_init_zoned_dev(struct nullb_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 				      struct request_queue *q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	pr_err("CONFIG_BLK_DEV_ZONED not enabled\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static inline int null_register_zoned_dev(struct nullb *nullb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static inline void null_free_zoned_dev(struct nullb_device *dev) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) static inline blk_status_t null_process_zoned_cmd(struct nullb_cmd *cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			enum req_opf op, sector_t sector, sector_t nr_sectors)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	return BLK_STS_NOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) static inline size_t null_zone_valid_read_len(struct nullb *nullb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 					      sector_t sector,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 					      unsigned int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) #define null_report_zones	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) #endif /* CONFIG_BLK_DEV_ZONED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) #endif /* __NULL_BLK_H */