8 #define KMSG_COMPONENT "scm_block"
9 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
13 #include <linux/module.h>
16 #include <linux/slab.h>
17 #include <linux/list.h>
25 static unsigned int nr_requests = 64;
34 static void __scm_free_rq(
struct scm_request *scmrq)
44 static void scm_free_rqs(
void)
58 static int __scm_alloc_rq(
void)
63 aobrq = kzalloc(
sizeof(*aobrq) +
sizeof(*scmrq),
GFP_KERNEL);
67 scmrq = (
void *) aobrq->
data;
80 INIT_LIST_HEAD(&scmrq->
list);
82 list_add(&scmrq->
list, &inactive_requests);
88 static int scm_alloc_rqs(
unsigned int nrqs)
92 while (nrqs-- && !ret)
93 ret = __scm_alloc_rq();
103 if (list_empty(&inactive_requests))
112 static void scm_request_done(
struct scm_request *scmrq)
117 list_add(&scmrq->
list, &inactive_requests);
118 spin_unlock_irqrestore(&
list_lock, flags);
126 static int scm_release(
struct gendisk *gendisk,
fmode_t mode)
132 static const struct block_device_operations scm_blk_devops = {
135 .release = scm_release,
138 static void scm_request_prepare(
struct scm_request *scmrq)
144 struct req_iterator iter;
148 scmrq->
aob->request.msb_count = 1;
156 rq_for_each_segment(bv, scmrq->
request, iter) {
164 static inline void scm_request_init(
struct scm_blk_dev *bdev,
171 memset(aob, 0,
sizeof(*aob));
183 static void scm_ensure_queue_restart(
struct scm_blk_dev *bdev)
198 scm_request_done(scmrq);
199 scm_ensure_queue_restart(bdev);
206 scm_request_done(scmrq);
218 if (req->cmd_type != REQ_TYPE_FS)
221 scmrq = scm_request_fetch();
224 scm_ensure_queue_restart(bdev);
227 scm_request_init(bdev, scmrq, req);
230 scm_request_done(scmrq);
238 scm_request_prepare(scmrq);
251 static void __scmrq_log_error(
struct scm_request *scmrq)
253 struct aob *aob = scmrq->
aob;
264 pr_err(
"An I/O operation to SCM failed with rc=%d\n",
275 __scmrq_log_error(scmrq);
277 spin_lock(&bdev->
lock);
279 spin_unlock(&bdev->
lock);
280 tasklet_hi_schedule(&bdev->
tasklet);
283 static void scm_blk_tasklet(
struct scm_blk_dev *bdev)
293 spin_unlock_irqrestore(&bdev->
lock, flags);
299 spin_unlock_irqrestore(&bdev->
rq_lock, flags);
316 spin_unlock_irqrestore(&bdev->
lock, flags);
325 unsigned int devindex, nr_max_blk;
329 if (devindex > 701) {
340 (
void (*)(
unsigned long)) scm_blk_tasklet,
341 (
unsigned long) bdev);
349 (
unsigned int) (
PAGE_SIZE /
sizeof(
struct aidaw)));
354 queue_flag_set_unlocked(QUEUE_FLAG_NONROT, rq);
361 rq->queuedata = scmdev;
362 bdev->gendisk->driverfs_dev = &scmdev->
dev;
363 bdev->gendisk->private_data = scmdev;
364 bdev->gendisk->fops = &scm_blk_devops;
365 bdev->gendisk->queue =
rq;
366 bdev->gendisk->major = scm_major;
369 len =
snprintf(bdev->gendisk->disk_name, DISK_NAME_LEN,
"scm");
371 len +=
snprintf(bdev->gendisk->disk_name + len,
372 DISK_NAME_LEN - len,
"%c",
373 'a' + (devindex / 26) - 1);
374 devindex = devindex % 26;
376 snprintf(bdev->gendisk->disk_name + len, DISK_NAME_LEN - len,
"%c",
380 set_capacity(bdev->gendisk, scmdev->
size >> 9);
399 static int __init scm_blk_init(
void)
411 if (scm_alloc_rqs(nr_requests))
438 static void __exit scm_blk_cleanup(
void)