1 /* SPDX-License-Identifier: GPL-2.0 */
5 #include <linux/percpu.h>
6 #include <linux/hashtable.h>
10 struct blk_mq_debugfs_attr;
13 * Return values from elevator merger
16 ELEVATOR_NO_MERGE = 0,
17 ELEVATOR_FRONT_MERGE = 1,
18 ELEVATOR_BACK_MERGE = 2,
19 ELEVATOR_DISCARD_MERGE = 3,
22 struct blk_mq_alloc_data;
25 struct elevator_mq_ops {
26 int (*init_sched)(struct request_queue *, struct elevator_type *);
27 void (*exit_sched)(struct elevator_queue *);
28 int (*init_hctx)(struct blk_mq_hw_ctx *, unsigned int);
29 void (*exit_hctx)(struct blk_mq_hw_ctx *, unsigned int);
30 void (*depth_updated)(struct blk_mq_hw_ctx *);
32 bool (*allow_merge)(struct request_queue *, struct request *, struct bio *);
33 bool (*bio_merge)(struct request_queue *, struct bio *, unsigned int);
34 int (*request_merge)(struct request_queue *q, struct request **, struct bio *);
35 void (*request_merged)(struct request_queue *, struct request *, enum elv_merge);
36 void (*requests_merged)(struct request_queue *, struct request *, struct request *);
37 void (*limit_depth)(unsigned int, struct blk_mq_alloc_data *);
38 void (*prepare_request)(struct request *);
39 void (*finish_request)(struct request *);
40 void (*insert_requests)(struct blk_mq_hw_ctx *, struct list_head *, bool);
41 struct request *(*dispatch_request)(struct blk_mq_hw_ctx *);
42 bool (*has_work)(struct blk_mq_hw_ctx *);
43 void (*completed_request)(struct request *, u64);
44 void (*requeue_request)(struct request *);
45 struct request *(*former_request)(struct request_queue *, struct request *);
46 struct request *(*next_request)(struct request_queue *, struct request *);
47 void (*init_icq)(struct io_cq *);
48 void (*exit_icq)(struct io_cq *);
51 #define ELV_NAME_MAX (16)
54 struct attribute attr;
55 ssize_t (*show)(struct elevator_queue *, char *);
56 ssize_t (*store)(struct elevator_queue *, const char *, size_t);
60 * identifies an elevator type, such as AS or deadline
64 /* managed by elevator core */
65 struct kmem_cache *icq_cache;
67 /* fields provided by elevator implementation */
68 struct elevator_mq_ops ops;
70 size_t icq_size; /* see iocontext.h */
71 size_t icq_align; /* ditto */
72 struct elv_fs_entry *elevator_attrs;
73 const char *elevator_name;
74 const char *elevator_alias;
75 const unsigned int elevator_features;
76 struct module *elevator_owner;
77 #ifdef CONFIG_BLK_DEBUG_FS
78 const struct blk_mq_debugfs_attr *queue_debugfs_attrs;
79 const struct blk_mq_debugfs_attr *hctx_debugfs_attrs;
82 /* managed by elevator core */
83 char icq_cache_name[ELV_NAME_MAX + 6]; /* elvname + "_io_cq" */
84 struct list_head list;
87 #define ELV_HASH_BITS 6
89 void elv_rqhash_del(struct request_queue *q, struct request *rq);
90 void elv_rqhash_add(struct request_queue *q, struct request *rq);
91 void elv_rqhash_reposition(struct request_queue *q, struct request *rq);
92 struct request *elv_rqhash_find(struct request_queue *q, sector_t offset);
95 * each queue has an elevator_queue associated with it
99 struct elevator_type *type;
102 struct mutex sysfs_lock;
103 unsigned int registered:1;
104 DECLARE_HASHTABLE(hash, ELV_HASH_BITS);
108 * block elevator interface
110 extern enum elv_merge elv_merge(struct request_queue *, struct request **,
112 extern void elv_merge_requests(struct request_queue *, struct request *,
114 extern void elv_merged_request(struct request_queue *, struct request *,
116 extern bool elv_attempt_insert_merge(struct request_queue *, struct request *,
118 extern struct request *elv_former_request(struct request_queue *, struct request *);
119 extern struct request *elv_latter_request(struct request_queue *, struct request *);
120 void elevator_init_mq(struct request_queue *q);
123 * io scheduler registration
125 extern int elv_register(struct elevator_type *);
126 extern void elv_unregister(struct elevator_type *);
129 * io scheduler sysfs switching
131 extern ssize_t elv_iosched_show(struct request_queue *, char *);
132 extern ssize_t elv_iosched_store(struct request_queue *, const char *, size_t);
134 extern bool elv_bio_merge_ok(struct request *, struct bio *);
135 extern struct elevator_queue *elevator_alloc(struct request_queue *,
136 struct elevator_type *);
141 extern struct request *elv_rb_former_request(struct request_queue *, struct request *);
142 extern struct request *elv_rb_latter_request(struct request_queue *, struct request *);
145 * rb support functions.
147 extern void elv_rb_add(struct rb_root *, struct request *);
148 extern void elv_rb_del(struct rb_root *, struct request *);
149 extern struct request *elv_rb_find(struct rb_root *, sector_t);
152 * Insertion selection
154 #define ELEVATOR_INSERT_FRONT 1
155 #define ELEVATOR_INSERT_BACK 2
156 #define ELEVATOR_INSERT_SORT 3
157 #define ELEVATOR_INSERT_REQUEUE 4
158 #define ELEVATOR_INSERT_FLUSH 5
159 #define ELEVATOR_INSERT_SORT_MERGE 6
161 #define rb_entry_rq(node) rb_entry((node), struct request, rb_node)
163 #define rq_entry_fifo(ptr) list_entry((ptr), struct request, queuelist)
164 #define rq_fifo_clear(rq) list_del_init(&(rq)->queuelist)
166 #endif /* _ELEVATOR_H */