1 /* SPDX-License-Identifier: GPL-2.0 */
5 #include <linux/percpu.h>
6 #include <linux/hashtable.h>
11 struct blk_mq_debugfs_attr
;
14 * Return values from elevator merger
17 ELEVATOR_NO_MERGE
= 0,
18 ELEVATOR_FRONT_MERGE
= 1,
19 ELEVATOR_BACK_MERGE
= 2,
20 ELEVATOR_DISCARD_MERGE
= 3,
23 struct blk_mq_alloc_data
;
26 struct elevator_mq_ops
{
27 int (*init_sched
)(struct request_queue
*, struct elevator_type
*);
28 void (*exit_sched
)(struct elevator_queue
*);
29 int (*init_hctx
)(struct blk_mq_hw_ctx
*, unsigned int);
30 void (*exit_hctx
)(struct blk_mq_hw_ctx
*, unsigned int);
31 void (*depth_updated
)(struct blk_mq_hw_ctx
*);
33 bool (*allow_merge
)(struct request_queue
*, struct request
*, struct bio
*);
34 bool (*bio_merge
)(struct request_queue
*, struct bio
*, unsigned int);
35 int (*request_merge
)(struct request_queue
*q
, struct request
**, struct bio
*);
36 void (*request_merged
)(struct request_queue
*, struct request
*, enum elv_merge
);
37 void (*requests_merged
)(struct request_queue
*, struct request
*, struct request
*);
38 void (*limit_depth
)(blk_opf_t
, struct blk_mq_alloc_data
*);
39 void (*prepare_request
)(struct request
*);
40 void (*finish_request
)(struct request
*);
41 void (*insert_requests
)(struct blk_mq_hw_ctx
*hctx
, struct list_head
*list
,
43 struct request
*(*dispatch_request
)(struct blk_mq_hw_ctx
*);
44 bool (*has_work
)(struct blk_mq_hw_ctx
*);
45 void (*completed_request
)(struct request
*, u64
);
46 void (*requeue_request
)(struct request
*);
47 struct request
*(*former_request
)(struct request_queue
*, struct request
*);
48 struct request
*(*next_request
)(struct request_queue
*, struct request
*);
49 void (*init_icq
)(struct io_cq
*);
50 void (*exit_icq
)(struct io_cq
*);
53 #define ELV_NAME_MAX (16)
56 struct attribute attr
;
57 ssize_t (*show
)(struct elevator_queue
*, char *);
58 ssize_t (*store
)(struct elevator_queue
*, const char *, size_t);
62 * identifies an elevator type, such as AS or deadline
66 /* managed by elevator core */
67 struct kmem_cache
*icq_cache
;
69 /* fields provided by elevator implementation */
70 struct elevator_mq_ops ops
;
72 size_t icq_size
; /* see iocontext.h */
73 size_t icq_align
; /* ditto */
74 struct elv_fs_entry
*elevator_attrs
;
75 const char *elevator_name
;
76 const char *elevator_alias
;
77 struct module
*elevator_owner
;
78 #ifdef CONFIG_BLK_DEBUG_FS
79 const struct blk_mq_debugfs_attr
*queue_debugfs_attrs
;
80 const struct blk_mq_debugfs_attr
*hctx_debugfs_attrs
;
83 /* managed by elevator core */
84 char icq_cache_name
[ELV_NAME_MAX
+ 6]; /* elvname + "_io_cq" */
85 struct list_head list
;
88 static inline bool elevator_tryget(struct elevator_type
*e
)
90 return try_module_get(e
->elevator_owner
);
93 static inline void __elevator_get(struct elevator_type
*e
)
95 __module_get(e
->elevator_owner
);
98 static inline void elevator_put(struct elevator_type
*e
)
100 module_put(e
->elevator_owner
);
103 #define ELV_HASH_BITS 6
105 void elv_rqhash_del(struct request_queue
*q
, struct request
*rq
);
106 void elv_rqhash_add(struct request_queue
*q
, struct request
*rq
);
107 void elv_rqhash_reposition(struct request_queue
*q
, struct request
*rq
);
108 struct request
*elv_rqhash_find(struct request_queue
*q
, sector_t offset
);
111 * each queue has an elevator_queue associated with it
113 struct elevator_queue
115 struct elevator_type
*type
;
118 struct mutex sysfs_lock
;
120 DECLARE_HASHTABLE(hash
, ELV_HASH_BITS
);
123 #define ELEVATOR_FLAG_REGISTERED 0
124 #define ELEVATOR_FLAG_DISABLE_WBT 1
127 * block elevator interface
129 extern enum elv_merge
elv_merge(struct request_queue
*, struct request
**,
131 extern void elv_merge_requests(struct request_queue
*, struct request
*,
133 extern void elv_merged_request(struct request_queue
*, struct request
*,
135 extern bool elv_attempt_insert_merge(struct request_queue
*, struct request
*,
137 extern struct request
*elv_former_request(struct request_queue
*, struct request
*);
138 extern struct request
*elv_latter_request(struct request_queue
*, struct request
*);
139 void elevator_init_mq(struct request_queue
*q
);
142 * io scheduler registration
144 extern int elv_register(struct elevator_type
*);
145 extern void elv_unregister(struct elevator_type
*);
148 * io scheduler sysfs switching
150 ssize_t
elv_iosched_show(struct gendisk
*disk
, char *page
);
151 void elv_iosched_load_module(struct gendisk
*disk
, const char *page
,
153 ssize_t
elv_iosched_store(struct gendisk
*disk
, const char *page
, size_t count
);
155 extern bool elv_bio_merge_ok(struct request
*, struct bio
*);
156 extern struct elevator_queue
*elevator_alloc(struct request_queue
*,
157 struct elevator_type
*);
162 extern struct request
*elv_rb_former_request(struct request_queue
*, struct request
*);
163 extern struct request
*elv_rb_latter_request(struct request_queue
*, struct request
*);
166 * rb support functions.
168 extern void elv_rb_add(struct rb_root
*, struct request
*);
169 extern void elv_rb_del(struct rb_root
*, struct request
*);
170 extern struct request
*elv_rb_find(struct rb_root
*, sector_t
);
173 * Insertion selection
175 #define ELEVATOR_INSERT_FRONT 1
176 #define ELEVATOR_INSERT_BACK 2
177 #define ELEVATOR_INSERT_SORT 3
178 #define ELEVATOR_INSERT_REQUEUE 4
179 #define ELEVATOR_INSERT_FLUSH 5
180 #define ELEVATOR_INSERT_SORT_MERGE 6
182 #define rb_entry_rq(node) rb_entry((node), struct request, rb_node)
184 #define rq_entry_fifo(ptr) list_entry((ptr), struct request, queuelist)
185 #define rq_fifo_clear(rq) list_del_init(&(rq)->queuelist)
187 #endif /* _ELEVATOR_H */