dcssblk: remove the end of device check in dcssblk_submit_bio
[linux-2.6-block.git] / arch / m68k / emu / nfblock.c
CommitLineData
b2edd2fd
RZ
1/*
2 * ARAnyM block device driver
3 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file COPYING in the main directory of this archive
6 * for more details.
7 */
8
9#include <linux/module.h>
10#include <linux/moduleparam.h>
11#include <linux/init.h>
12
13#include <linux/kernel.h>
14#include <linux/errno.h>
15#include <linux/types.h>
16#include <linux/genhd.h>
17#include <linux/blkdev.h>
18#include <linux/hdreg.h>
19#include <linux/slab.h>
20
21#include <asm/natfeat.h>
22
23static long nfhd_id;
24
25enum {
26 /* emulation entry points */
27 NFHD_READ_WRITE = 10,
28 NFHD_GET_CAPACITY = 14,
29
30 /* skip ACSI devices */
31 NFHD_DEV_OFFSET = 8,
32};
33
34static inline s32 nfhd_read_write(u32 major, u32 minor, u32 rwflag, u32 recno,
35 u32 count, u32 buf)
36{
37 return nf_call(nfhd_id + NFHD_READ_WRITE, major, minor, rwflag, recno,
38 count, buf);
39}
40
41static inline s32 nfhd_get_capacity(u32 major, u32 minor, u32 *blocks,
42 u32 *blocksize)
43{
55490050
GU
44 return nf_call(nfhd_id + NFHD_GET_CAPACITY, major, minor,
45 virt_to_phys(blocks), virt_to_phys(blocksize));
b2edd2fd
RZ
46}
47
48static LIST_HEAD(nfhd_list);
49
50static int major_num;
51module_param(major_num, int, 0);
52
53struct nfhd_device {
54 struct list_head list;
55 int id;
56 u32 blocks, bsize;
57 int bshift;
58 struct request_queue *queue;
59 struct gendisk *disk;
60};
61
c62b37d9 62static blk_qc_t nfhd_submit_bio(struct bio *bio)
b2edd2fd 63{
6d41bb4d 64 struct nfhd_device *dev = bio->bi_disk->private_data;
7988613b
KO
65 struct bio_vec bvec;
66 struct bvec_iter iter;
67 int dir, len, shift;
4f024f37 68 sector_t sec = bio->bi_iter.bi_sector;
b2edd2fd
RZ
69
70 dir = bio_data_dir(bio);
71 shift = dev->bshift;
7988613b
KO
72 bio_for_each_segment(bvec, bio, iter) {
73 len = bvec.bv_len;
b2edd2fd
RZ
74 len >>= 9;
75 nfhd_read_write(dev->id, 0, dir, sec >> shift, len >> shift,
6e768461 76 page_to_phys(bvec.bv_page) + bvec.bv_offset);
b2edd2fd
RZ
77 sec += len;
78 }
4246a0b6 79 bio_endio(bio);
dece1635 80 return BLK_QC_T_NONE;
b2edd2fd
RZ
81}
82
83static int nfhd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
84{
85 struct nfhd_device *dev = bdev->bd_disk->private_data;
86
87 geo->cylinders = dev->blocks >> (6 - dev->bshift);
88 geo->heads = 4;
89 geo->sectors = 16;
90
91 return 0;
92}
93
94static const struct block_device_operations nfhd_ops = {
95 .owner = THIS_MODULE,
c62b37d9 96 .submit_bio = nfhd_submit_bio,
b2edd2fd
RZ
97 .getgeo = nfhd_getgeo,
98};
99
100static int __init nfhd_init_one(int id, u32 blocks, u32 bsize)
101{
102 struct nfhd_device *dev;
103 int dev_id = id - NFHD_DEV_OFFSET;
104
105 pr_info("nfhd%u: found device with %u blocks (%u bytes)\n", dev_id,
106 blocks, bsize);
107
108 if (bsize < 512 || (bsize & (bsize - 1))) {
109 pr_warn("nfhd%u: invalid block size\n", dev_id);
110 return -EINVAL;
111 }
112
113 dev = kmalloc(sizeof(struct nfhd_device), GFP_KERNEL);
114 if (!dev)
115 goto out;
116
117 dev->id = id;
118 dev->blocks = blocks;
119 dev->bsize = bsize;
120 dev->bshift = ffs(bsize) - 10;
121
c62b37d9 122 dev->queue = blk_alloc_queue(NUMA_NO_NODE);
b2edd2fd
RZ
123 if (dev->queue == NULL)
124 goto free_dev;
125
b2edd2fd
RZ
126 blk_queue_logical_block_size(dev->queue, bsize);
127
128 dev->disk = alloc_disk(16);
129 if (!dev->disk)
130 goto free_queue;
131
132 dev->disk->major = major_num;
133 dev->disk->first_minor = dev_id * 16;
134 dev->disk->fops = &nfhd_ops;
135 dev->disk->private_data = dev;
136 sprintf(dev->disk->disk_name, "nfhd%u", dev_id);
137 set_capacity(dev->disk, (sector_t)blocks * (bsize / 512));
138 dev->disk->queue = dev->queue;
139
140 add_disk(dev->disk);
141
142 list_add_tail(&dev->list, &nfhd_list);
143
144 return 0;
145
146free_queue:
147 blk_cleanup_queue(dev->queue);
148free_dev:
149 kfree(dev);
150out:
151 return -ENOMEM;
152}
153
154static int __init nfhd_init(void)
155{
156 u32 blocks, bsize;
30363d65 157 int ret;
b2edd2fd
RZ
158 int i;
159
160 nfhd_id = nf_get_id("XHDI");
161 if (!nfhd_id)
162 return -ENODEV;
163
30363d65
CX
164 ret = register_blkdev(major_num, "nfhd");
165 if (ret < 0) {
b2edd2fd 166 pr_warn("nfhd: unable to get major number\n");
30363d65 167 return ret;
b2edd2fd
RZ
168 }
169
30363d65
CX
170 if (!major_num)
171 major_num = ret;
172
b2edd2fd
RZ
173 for (i = NFHD_DEV_OFFSET; i < 24; i++) {
174 if (nfhd_get_capacity(i, 0, &blocks, &bsize))
175 continue;
176 nfhd_init_one(i, blocks, bsize);
177 }
178
179 return 0;
180}
181
182static void __exit nfhd_exit(void)
183{
184 struct nfhd_device *dev, *next;
185
186 list_for_each_entry_safe(dev, next, &nfhd_list, list) {
187 list_del(&dev->list);
188 del_gendisk(dev->disk);
189 put_disk(dev->disk);
190 blk_cleanup_queue(dev->queue);
191 kfree(dev);
192 }
193 unregister_blkdev(major_num, "nfhd");
194}
195
196module_init(nfhd_init);
197module_exit(nfhd_exit);
198
199MODULE_LICENSE("GPL");