]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* -*- linux-c -*- |
2 | * drivers/cdrom/viocd.c | |
3 | * | |
4 | * iSeries Virtual CD Rom | |
5 | * | |
6 | * Authors: Dave Boutcher <boutcher@us.ibm.com> | |
7 | * Ryan Arnold <ryanarn@us.ibm.com> | |
8 | * Colin Devilbiss <devilbis@us.ibm.com> | |
8962cadb | 9 | * Stephen Rothwell |
1da177e4 LT |
10 | * |
11 | * (C) Copyright 2000-2004 IBM Corporation | |
12 | * | |
13 | * This program is free software; you can redistribute it and/or | |
14 | * modify it under the terms of the GNU General Public License as | |
15 | * published by the Free Software Foundation; either version 2 of the | |
16 | * License, or (at your option) anyu later version. | |
17 | * | |
18 | * This program is distributed in the hope that it will be useful, but | |
19 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
21 | * General Public License for more details. | |
22 | * | |
23 | * You should have received a copy of the GNU General Public License | |
24 | * along with this program; if not, write to the Free Software Foundation, | |
25 | * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
26 | * | |
27 | * This routine provides access to CD ROM drives owned and managed by an | |
28 | * OS/400 partition running on the same box as this Linux partition. | |
29 | * | |
30 | * All operations are performed by sending messages back and forth to | |
31 | * the OS/400 partition. | |
32 | */ | |
33 | ||
e597cd09 JP |
34 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
35 | ||
1da177e4 LT |
36 | #include <linux/major.h> |
37 | #include <linux/blkdev.h> | |
38 | #include <linux/cdrom.h> | |
39 | #include <linux/errno.h> | |
40 | #include <linux/init.h> | |
41 | #include <linux/dma-mapping.h> | |
42 | #include <linux/module.h> | |
43 | #include <linux/completion.h> | |
44 | #include <linux/proc_fs.h> | |
8a6cfeb6 | 45 | #include <linux/smp_lock.h> |
1da177e4 | 46 | #include <linux/seq_file.h> |
3d1266c7 | 47 | #include <linux/scatterlist.h> |
1da177e4 | 48 | |
1da177e4 | 49 | #include <asm/vio.h> |
1ec65d76 | 50 | #include <asm/iseries/hv_types.h> |
e45423ea | 51 | #include <asm/iseries/hv_lp_event.h> |
b4206778 | 52 | #include <asm/iseries/vio.h> |
31c72ad0 | 53 | #include <asm/firmware.h> |
1da177e4 LT |
54 | |
55 | #define VIOCD_DEVICE "iseries/vcd" | |
1da177e4 LT |
56 | |
57 | #define VIOCD_VERS "1.06" | |
58 | ||
1da177e4 LT |
59 | /* |
60 | * Should probably make this a module parameter....sigh | |
61 | */ | |
62 | #define VIOCD_MAX_CD HVMAXARCHITECTEDVIRTUALCDROMS | |
63 | ||
64 | static const struct vio_error_entry viocd_err_table[] = { | |
65 | {0x0201, EINVAL, "Invalid Range"}, | |
66 | {0x0202, EINVAL, "Invalid Token"}, | |
67 | {0x0203, EIO, "DMA Error"}, | |
68 | {0x0204, EIO, "Use Error"}, | |
69 | {0x0205, EIO, "Release Error"}, | |
70 | {0x0206, EINVAL, "Invalid CD"}, | |
71 | {0x020C, EROFS, "Read Only Device"}, | |
72 | {0x020D, ENOMEDIUM, "Changed or Missing Volume (or Varied Off?)"}, | |
73 | {0x020E, EIO, "Optical System Error (Varied Off?)"}, | |
74 | {0x02FF, EIO, "Internal Error"}, | |
75 | {0x3010, EIO, "Changed Volume"}, | |
76 | {0xC100, EIO, "Optical System Error"}, | |
77 | {0x0000, 0, NULL}, | |
78 | }; | |
79 | ||
80 | /* | |
81 | * This is the structure we use to exchange info between driver and interrupt | |
82 | * handler | |
83 | */ | |
84 | struct viocd_waitevent { | |
85 | struct completion com; | |
86 | int rc; | |
87 | u16 sub_result; | |
88 | int changed; | |
89 | }; | |
90 | ||
91 | /* this is a lookup table for the true capabilities of a device */ | |
92 | struct capability_entry { | |
93 | char *type; | |
94 | int capability; | |
95 | }; | |
96 | ||
97 | static struct capability_entry capability_table[] __initdata = { | |
98 | { "6330", CDC_LOCK | CDC_DVD_RAM | CDC_RAM }, | |
99 | { "6331", CDC_LOCK | CDC_DVD_RAM | CDC_RAM }, | |
100 | { "6333", CDC_LOCK | CDC_DVD_RAM | CDC_RAM }, | |
101 | { "632A", CDC_LOCK | CDC_DVD_RAM | CDC_RAM }, | |
102 | { "6321", CDC_LOCK }, | |
103 | { "632B", 0 }, | |
104 | { NULL , CDC_LOCK }, | |
105 | }; | |
106 | ||
107 | /* These are our internal structures for keeping track of devices */ | |
108 | static int viocd_numdev; | |
109 | ||
1da177e4 LT |
110 | struct disk_info { |
111 | struct gendisk *viocd_disk; | |
112 | struct cdrom_device_info viocd_info; | |
113 | struct device *dev; | |
b833b481 SR |
114 | const char *rsrcname; |
115 | const char *type; | |
116 | const char *model; | |
1da177e4 LT |
117 | }; |
118 | static struct disk_info viocd_diskinfo[VIOCD_MAX_CD]; | |
119 | ||
120 | #define DEVICE_NR(di) ((di) - &viocd_diskinfo[0]) | |
121 | ||
122 | static spinlock_t viocd_reqlock; | |
123 | ||
124 | #define MAX_CD_REQ 1 | |
125 | ||
126 | /* procfs support */ | |
127 | static int proc_viocd_show(struct seq_file *m, void *v) | |
128 | { | |
129 | int i; | |
130 | ||
131 | for (i = 0; i < viocd_numdev; i++) { | |
132 | seq_printf(m, "viocd device %d is iSeries resource %10.10s" | |
133 | "type %4.4s, model %3.3s\n", | |
b833b481 SR |
134 | i, viocd_diskinfo[i].rsrcname, |
135 | viocd_diskinfo[i].type, | |
136 | viocd_diskinfo[i].model); | |
1da177e4 LT |
137 | } |
138 | return 0; | |
139 | } | |
140 | ||
141 | static int proc_viocd_open(struct inode *inode, struct file *file) | |
142 | { | |
143 | return single_open(file, proc_viocd_show, NULL); | |
144 | } | |
145 | ||
2b8693c0 | 146 | static const struct file_operations proc_viocd_operations = { |
c7705f34 | 147 | .owner = THIS_MODULE, |
1da177e4 LT |
148 | .open = proc_viocd_open, |
149 | .read = seq_read, | |
150 | .llseek = seq_lseek, | |
151 | .release = single_release, | |
152 | }; | |
153 | ||
4e379ae6 | 154 | static int viocd_blk_open(struct block_device *bdev, fmode_t mode) |
1da177e4 | 155 | { |
4e379ae6 AV |
156 | struct disk_info *di = bdev->bd_disk->private_data; |
157 | return cdrom_open(&di->viocd_info, bdev, mode); | |
1da177e4 LT |
158 | } |
159 | ||
4e379ae6 | 160 | static int viocd_blk_release(struct gendisk *disk, fmode_t mode) |
1da177e4 | 161 | { |
4e379ae6 AV |
162 | struct disk_info *di = disk->private_data; |
163 | cdrom_release(&di->viocd_info, mode); | |
bbc1cc97 | 164 | return 0; |
1da177e4 LT |
165 | } |
166 | ||
4e379ae6 | 167 | static int viocd_blk_ioctl(struct block_device *bdev, fmode_t mode, |
1da177e4 LT |
168 | unsigned cmd, unsigned long arg) |
169 | { | |
4e379ae6 | 170 | struct disk_info *di = bdev->bd_disk->private_data; |
8a6cfeb6 AB |
171 | int ret; |
172 | ||
173 | lock_kernel(); | |
174 | ret = cdrom_ioctl(&di->viocd_info, bdev, mode, cmd, arg); | |
175 | unlock_kernel(); | |
176 | ||
177 | return ret; | |
1da177e4 LT |
178 | } |
179 | ||
180 | static int viocd_blk_media_changed(struct gendisk *disk) | |
181 | { | |
182 | struct disk_info *di = disk->private_data; | |
183 | return cdrom_media_changed(&di->viocd_info); | |
184 | } | |
185 | ||
83d5cde4 | 186 | static const struct block_device_operations viocd_fops = { |
1da177e4 | 187 | .owner = THIS_MODULE, |
4e379ae6 AV |
188 | .open = viocd_blk_open, |
189 | .release = viocd_blk_release, | |
8a6cfeb6 | 190 | .ioctl = viocd_blk_ioctl, |
1da177e4 LT |
191 | .media_changed = viocd_blk_media_changed, |
192 | }; | |
193 | ||
1da177e4 LT |
194 | static int viocd_open(struct cdrom_device_info *cdi, int purpose) |
195 | { | |
196 | struct disk_info *diskinfo = cdi->handle; | |
197 | int device_no = DEVICE_NR(diskinfo); | |
198 | HvLpEvent_Rc hvrc; | |
199 | struct viocd_waitevent we; | |
200 | ||
201 | init_completion(&we.com); | |
202 | hvrc = HvCallEvent_signalLpEventFast(viopath_hostLp, | |
203 | HvLpEvent_Type_VirtualIo, | |
204 | viomajorsubtype_cdio | viocdopen, | |
205 | HvLpEvent_AckInd_DoAck, HvLpEvent_AckType_ImmediateAck, | |
206 | viopath_sourceinst(viopath_hostLp), | |
207 | viopath_targetinst(viopath_hostLp), | |
208 | (u64)&we, VIOVERSION << 16, ((u64)device_no << 48), | |
209 | 0, 0, 0); | |
210 | if (hvrc != 0) { | |
e597cd09 JP |
211 | pr_warning("bad rc on HvCallEvent_signalLpEventFast %d\n", |
212 | (int)hvrc); | |
1da177e4 LT |
213 | return -EIO; |
214 | } | |
215 | ||
216 | wait_for_completion(&we.com); | |
217 | ||
218 | if (we.rc) { | |
219 | const struct vio_error_entry *err = | |
220 | vio_lookup_rc(viocd_err_table, we.sub_result); | |
e597cd09 JP |
221 | pr_warning("bad rc %d:0x%04X on open: %s\n", |
222 | we.rc, we.sub_result, err->msg); | |
1da177e4 LT |
223 | return -err->errno; |
224 | } | |
225 | ||
226 | return 0; | |
227 | } | |
228 | ||
229 | static void viocd_release(struct cdrom_device_info *cdi) | |
230 | { | |
231 | int device_no = DEVICE_NR((struct disk_info *)cdi->handle); | |
232 | HvLpEvent_Rc hvrc; | |
233 | ||
234 | hvrc = HvCallEvent_signalLpEventFast(viopath_hostLp, | |
235 | HvLpEvent_Type_VirtualIo, | |
236 | viomajorsubtype_cdio | viocdclose, | |
237 | HvLpEvent_AckInd_NoAck, HvLpEvent_AckType_ImmediateAck, | |
238 | viopath_sourceinst(viopath_hostLp), | |
239 | viopath_targetinst(viopath_hostLp), 0, | |
240 | VIOVERSION << 16, ((u64)device_no << 48), 0, 0, 0); | |
241 | if (hvrc != 0) | |
e597cd09 JP |
242 | pr_warning("bad rc on HvCallEvent_signalLpEventFast %d\n", |
243 | (int)hvrc); | |
1da177e4 LT |
244 | } |
245 | ||
246 | /* Send a read or write request to OS/400 */ | |
247 | static int send_request(struct request *req) | |
248 | { | |
249 | HvLpEvent_Rc hvrc; | |
250 | struct disk_info *diskinfo = req->rq_disk->private_data; | |
251 | u64 len; | |
252 | dma_addr_t dmaaddr; | |
253 | int direction; | |
254 | u16 cmd; | |
255 | struct scatterlist sg; | |
256 | ||
257 | BUG_ON(req->nr_phys_segments > 1); | |
258 | ||
259 | if (rq_data_dir(req) == READ) { | |
260 | direction = DMA_FROM_DEVICE; | |
261 | cmd = viomajorsubtype_cdio | viocdread; | |
262 | } else { | |
263 | direction = DMA_TO_DEVICE; | |
264 | cmd = viomajorsubtype_cdio | viocdwrite; | |
265 | } | |
266 | ||
3d1266c7 | 267 | sg_init_table(&sg, 1); |
1da177e4 | 268 | if (blk_rq_map_sg(req->q, req, &sg) == 0) { |
e597cd09 | 269 | pr_warning("error setting up scatter/gather list\n"); |
1da177e4 LT |
270 | return -1; |
271 | } | |
272 | ||
273 | if (dma_map_sg(diskinfo->dev, &sg, 1, direction) == 0) { | |
e597cd09 | 274 | pr_warning("error allocating sg tce\n"); |
1da177e4 LT |
275 | return -1; |
276 | } | |
277 | dmaaddr = sg_dma_address(&sg); | |
278 | len = sg_dma_len(&sg); | |
279 | ||
280 | hvrc = HvCallEvent_signalLpEventFast(viopath_hostLp, | |
281 | HvLpEvent_Type_VirtualIo, cmd, | |
282 | HvLpEvent_AckInd_DoAck, | |
283 | HvLpEvent_AckType_ImmediateAck, | |
284 | viopath_sourceinst(viopath_hostLp), | |
285 | viopath_targetinst(viopath_hostLp), | |
286 | (u64)req, VIOVERSION << 16, | |
287 | ((u64)DEVICE_NR(diskinfo) << 48) | dmaaddr, | |
83096ebf | 288 | (u64)blk_rq_pos(req) * 512, len, 0); |
1da177e4 | 289 | if (hvrc != HvLpEvent_Rc_Good) { |
e597cd09 | 290 | pr_warning("hv error on op %d\n", (int)hvrc); |
1da177e4 LT |
291 | return -1; |
292 | } | |
293 | ||
294 | return 0; | |
295 | } | |
296 | ||
1da177e4 LT |
297 | static int rwreq; |
298 | ||
165125e1 | 299 | static void do_viocd_request(struct request_queue *q) |
1da177e4 LT |
300 | { |
301 | struct request *req; | |
302 | ||
9934c8c0 | 303 | while ((rwreq == 0) && ((req = blk_fetch_request(q)) != NULL)) { |
33659ebb | 304 | if (req->cmd_type != REQ_TYPE_FS) |
40cbbb78 | 305 | __blk_end_request_all(req, -EIO); |
1da177e4 | 306 | else if (send_request(req) < 0) { |
e597cd09 | 307 | pr_warning("unable to send message to OS/400!\n"); |
40cbbb78 | 308 | __blk_end_request_all(req, -EIO); |
1da177e4 LT |
309 | } else |
310 | rwreq++; | |
311 | } | |
312 | } | |
313 | ||
314 | static int viocd_media_changed(struct cdrom_device_info *cdi, int disc_nr) | |
315 | { | |
316 | struct viocd_waitevent we; | |
317 | HvLpEvent_Rc hvrc; | |
318 | int device_no = DEVICE_NR((struct disk_info *)cdi->handle); | |
319 | ||
320 | init_completion(&we.com); | |
321 | ||
322 | /* Send the open event to OS/400 */ | |
323 | hvrc = HvCallEvent_signalLpEventFast(viopath_hostLp, | |
324 | HvLpEvent_Type_VirtualIo, | |
325 | viomajorsubtype_cdio | viocdcheck, | |
326 | HvLpEvent_AckInd_DoAck, HvLpEvent_AckType_ImmediateAck, | |
327 | viopath_sourceinst(viopath_hostLp), | |
328 | viopath_targetinst(viopath_hostLp), | |
329 | (u64)&we, VIOVERSION << 16, ((u64)device_no << 48), | |
330 | 0, 0, 0); | |
331 | if (hvrc != 0) { | |
e597cd09 JP |
332 | pr_warning("bad rc on HvCallEvent_signalLpEventFast %d\n", |
333 | (int)hvrc); | |
1da177e4 LT |
334 | return -EIO; |
335 | } | |
336 | ||
337 | wait_for_completion(&we.com); | |
338 | ||
339 | /* Check the return code. If bad, assume no change */ | |
340 | if (we.rc) { | |
341 | const struct vio_error_entry *err = | |
342 | vio_lookup_rc(viocd_err_table, we.sub_result); | |
e597cd09 JP |
343 | pr_warning("bad rc %d:0x%04X on check_change: %s; Assuming no change\n", |
344 | we.rc, we.sub_result, err->msg); | |
1da177e4 LT |
345 | return 0; |
346 | } | |
347 | ||
348 | return we.changed; | |
349 | } | |
350 | ||
351 | static int viocd_lock_door(struct cdrom_device_info *cdi, int locking) | |
352 | { | |
353 | HvLpEvent_Rc hvrc; | |
354 | u64 device_no = DEVICE_NR((struct disk_info *)cdi->handle); | |
355 | /* NOTE: flags is 1 or 0 so it won't overwrite the device_no */ | |
356 | u64 flags = !!locking; | |
357 | struct viocd_waitevent we; | |
358 | ||
359 | init_completion(&we.com); | |
360 | ||
361 | /* Send the lockdoor event to OS/400 */ | |
362 | hvrc = HvCallEvent_signalLpEventFast(viopath_hostLp, | |
363 | HvLpEvent_Type_VirtualIo, | |
364 | viomajorsubtype_cdio | viocdlockdoor, | |
365 | HvLpEvent_AckInd_DoAck, HvLpEvent_AckType_ImmediateAck, | |
366 | viopath_sourceinst(viopath_hostLp), | |
367 | viopath_targetinst(viopath_hostLp), | |
368 | (u64)&we, VIOVERSION << 16, | |
369 | (device_no << 48) | (flags << 32), 0, 0, 0); | |
370 | if (hvrc != 0) { | |
e597cd09 JP |
371 | pr_warning("bad rc on HvCallEvent_signalLpEventFast %d\n", |
372 | (int)hvrc); | |
1da177e4 LT |
373 | return -EIO; |
374 | } | |
375 | ||
376 | wait_for_completion(&we.com); | |
377 | ||
378 | if (we.rc != 0) | |
379 | return -EIO; | |
380 | return 0; | |
381 | } | |
382 | ||
383 | static int viocd_packet(struct cdrom_device_info *cdi, | |
384 | struct packet_command *cgc) | |
385 | { | |
386 | unsigned int buflen = cgc->buflen; | |
387 | int ret = -EIO; | |
388 | ||
389 | switch (cgc->cmd[0]) { | |
390 | case GPCMD_READ_DISC_INFO: | |
391 | { | |
392 | disc_information *di = (disc_information *)cgc->buffer; | |
393 | ||
394 | if (buflen >= 2) { | |
395 | di->disc_information_length = cpu_to_be16(1); | |
396 | ret = 0; | |
397 | } | |
398 | if (buflen >= 3) | |
399 | di->erasable = | |
400 | (cdi->ops->capability & ~cdi->mask | |
401 | & (CDC_DVD_RAM | CDC_RAM)) != 0; | |
402 | } | |
403 | break; | |
9db29258 SR |
404 | case GPCMD_GET_CONFIGURATION: |
405 | if (cgc->cmd[3] == CDF_RWRT) { | |
406 | struct rwrt_feature_desc *rfd = (struct rwrt_feature_desc *)(cgc->buffer + sizeof(struct feature_header)); | |
407 | ||
408 | if ((buflen >= | |
409 | (sizeof(struct feature_header) + sizeof(*rfd))) && | |
410 | (cdi->ops->capability & ~cdi->mask | |
411 | & (CDC_DVD_RAM | CDC_RAM))) { | |
412 | rfd->feature_code = cpu_to_be16(CDF_RWRT); | |
413 | rfd->curr = 1; | |
414 | ret = 0; | |
415 | } | |
416 | } | |
417 | break; | |
1da177e4 LT |
418 | default: |
419 | if (cgc->sense) { | |
420 | /* indicate Unknown code */ | |
421 | cgc->sense->sense_key = 0x05; | |
422 | cgc->sense->asc = 0x20; | |
423 | cgc->sense->ascq = 0x00; | |
424 | } | |
425 | break; | |
426 | } | |
427 | ||
428 | cgc->stat = ret; | |
429 | return ret; | |
430 | } | |
431 | ||
432 | static void restart_all_queues(int first_index) | |
433 | { | |
434 | int i; | |
435 | ||
436 | for (i = first_index + 1; i < viocd_numdev; i++) | |
437 | if (viocd_diskinfo[i].viocd_disk) | |
438 | blk_run_queue(viocd_diskinfo[i].viocd_disk->queue); | |
439 | for (i = 0; i <= first_index; i++) | |
440 | if (viocd_diskinfo[i].viocd_disk) | |
441 | blk_run_queue(viocd_diskinfo[i].viocd_disk->queue); | |
442 | } | |
443 | ||
444 | /* This routine handles incoming CD LP events */ | |
445 | static void vio_handle_cd_event(struct HvLpEvent *event) | |
446 | { | |
447 | struct viocdlpevent *bevent; | |
448 | struct viocd_waitevent *pwe; | |
449 | struct disk_info *di; | |
450 | unsigned long flags; | |
451 | struct request *req; | |
452 | ||
453 | ||
454 | if (event == NULL) | |
455 | /* Notification that a partition went away! */ | |
456 | return; | |
457 | /* First, we should NEVER get an int here...only acks */ | |
677f8c0d | 458 | if (hvlpevent_is_int(event)) { |
e597cd09 | 459 | pr_warning("Yikes! got an int in viocd event handler!\n"); |
677f8c0d | 460 | if (hvlpevent_need_ack(event)) { |
1da177e4 LT |
461 | event->xRc = HvLpEvent_Rc_InvalidSubtype; |
462 | HvCallEvent_ackLpEvent(event); | |
463 | } | |
464 | } | |
465 | ||
466 | bevent = (struct viocdlpevent *)event; | |
467 | ||
468 | switch (event->xSubtype & VIOMINOR_SUBTYPE_MASK) { | |
469 | case viocdopen: | |
470 | if (event->xRc == 0) { | |
471 | di = &viocd_diskinfo[bevent->disk]; | |
e1defc4f MP |
472 | blk_queue_logical_block_size(di->viocd_disk->queue, |
473 | bevent->block_size); | |
1da177e4 LT |
474 | set_capacity(di->viocd_disk, |
475 | bevent->media_size * | |
476 | bevent->block_size / 512); | |
477 | } | |
478 | /* FALLTHROUGH !! */ | |
1da177e4 LT |
479 | case viocdlockdoor: |
480 | pwe = (struct viocd_waitevent *)event->xCorrelationToken; | |
481 | return_complete: | |
482 | pwe->rc = event->xRc; | |
483 | pwe->sub_result = bevent->sub_result; | |
484 | complete(&pwe->com); | |
485 | break; | |
486 | ||
487 | case viocdcheck: | |
488 | pwe = (struct viocd_waitevent *)event->xCorrelationToken; | |
489 | pwe->changed = bevent->flags; | |
490 | goto return_complete; | |
491 | ||
492 | case viocdclose: | |
493 | break; | |
494 | ||
495 | case viocdwrite: | |
496 | case viocdread: | |
497 | /* | |
498 | * Since this is running in interrupt mode, we need to | |
499 | * make sure we're not stepping on any global I/O operations | |
500 | */ | |
501 | di = &viocd_diskinfo[bevent->disk]; | |
502 | spin_lock_irqsave(&viocd_reqlock, flags); | |
503 | dma_unmap_single(di->dev, bevent->token, bevent->len, | |
504 | ((event->xSubtype & VIOMINOR_SUBTYPE_MASK) == viocdread) | |
505 | ? DMA_FROM_DEVICE : DMA_TO_DEVICE); | |
506 | req = (struct request *)bevent->event.xCorrelationToken; | |
507 | rwreq--; | |
508 | ||
509 | if (event->xRc != HvLpEvent_Rc_Good) { | |
510 | const struct vio_error_entry *err = | |
511 | vio_lookup_rc(viocd_err_table, | |
512 | bevent->sub_result); | |
e597cd09 JP |
513 | pr_warning("request %p failed with rc %d:0x%04X: %s\n", |
514 | req, event->xRc, | |
515 | bevent->sub_result, err->msg); | |
40cbbb78 | 516 | __blk_end_request_all(req, -EIO); |
1da177e4 | 517 | } else |
40cbbb78 | 518 | __blk_end_request_all(req, 0); |
1da177e4 LT |
519 | |
520 | /* restart handling of incoming requests */ | |
521 | spin_unlock_irqrestore(&viocd_reqlock, flags); | |
522 | restart_all_queues(bevent->disk); | |
523 | break; | |
524 | ||
525 | default: | |
e597cd09 JP |
526 | pr_warning("message with invalid subtype %0x04X!\n", |
527 | event->xSubtype & VIOMINOR_SUBTYPE_MASK); | |
677f8c0d | 528 | if (hvlpevent_need_ack(event)) { |
1da177e4 LT |
529 | event->xRc = HvLpEvent_Rc_InvalidSubtype; |
530 | HvCallEvent_ackLpEvent(event); | |
531 | } | |
532 | } | |
533 | } | |
534 | ||
3e636f78 BP |
535 | static int viocd_audio_ioctl(struct cdrom_device_info *cdi, unsigned int cmd, |
536 | void *arg) | |
537 | { | |
538 | return -EINVAL; | |
539 | } | |
540 | ||
1da177e4 LT |
541 | static struct cdrom_device_ops viocd_dops = { |
542 | .open = viocd_open, | |
543 | .release = viocd_release, | |
544 | .media_changed = viocd_media_changed, | |
545 | .lock_door = viocd_lock_door, | |
546 | .generic_packet = viocd_packet, | |
3e636f78 | 547 | .audio_ioctl = viocd_audio_ioctl, |
6a2900b6 | 548 | .capability = CDC_CLOSE_TRAY | CDC_OPEN_TRAY | CDC_LOCK | CDC_SELECT_SPEED | CDC_SELECT_DISC | CDC_MULTI_SESSION | CDC_MCN | CDC_MEDIA_CHANGED | CDC_PLAY_AUDIO | CDC_RESET | CDC_DRIVE_STATUS | CDC_GENERIC_PACKET | CDC_CD_R | CDC_CD_RW | CDC_DVD | CDC_DVD_R | CDC_DVD_RAM | CDC_RAM |
1da177e4 LT |
549 | }; |
550 | ||
c7211927 | 551 | static int find_capability(const char *type) |
1da177e4 LT |
552 | { |
553 | struct capability_entry *entry; | |
554 | ||
555 | for(entry = capability_table; entry->type; ++entry) | |
556 | if(!strncmp(entry->type, type, 4)) | |
557 | break; | |
558 | return entry->capability; | |
559 | } | |
560 | ||
561 | static int viocd_probe(struct vio_dev *vdev, const struct vio_device_id *id) | |
562 | { | |
563 | struct gendisk *gendisk; | |
564 | int deviceno; | |
565 | struct disk_info *d; | |
566 | struct cdrom_device_info *c; | |
1da177e4 | 567 | struct request_queue *q; |
61c7a080 | 568 | struct device_node *node = vdev->dev.of_node; |
1da177e4 LT |
569 | |
570 | deviceno = vdev->unit_address; | |
d3375ea7 | 571 | if (deviceno >= VIOCD_MAX_CD) |
1da177e4 | 572 | return -ENODEV; |
b833b481 SR |
573 | if (!node) |
574 | return -ENODEV; | |
575 | ||
576 | if (deviceno >= viocd_numdev) | |
577 | viocd_numdev = deviceno + 1; | |
1da177e4 LT |
578 | |
579 | d = &viocd_diskinfo[deviceno]; | |
b833b481 SR |
580 | d->rsrcname = of_get_property(node, "linux,vio_rsrcname", NULL); |
581 | d->type = of_get_property(node, "linux,vio_type", NULL); | |
582 | d->model = of_get_property(node, "linux,vio_model", NULL); | |
583 | ||
1da177e4 | 584 | c = &d->viocd_info; |
1da177e4 LT |
585 | |
586 | c->ops = &viocd_dops; | |
587 | c->speed = 4; | |
588 | c->capacity = 1; | |
589 | c->handle = d; | |
b833b481 | 590 | c->mask = ~find_capability(d->type); |
1da177e4 LT |
591 | sprintf(c->name, VIOCD_DEVICE "%c", 'a' + deviceno); |
592 | ||
593 | if (register_cdrom(c) != 0) { | |
e597cd09 | 594 | pr_warning("Cannot register viocd CD-ROM %s!\n", c->name); |
1da177e4 LT |
595 | goto out; |
596 | } | |
e597cd09 JP |
597 | pr_info("cd %s is iSeries resource %10.10s type %4.4s, model %3.3s\n", |
598 | c->name, d->rsrcname, d->type, d->model); | |
1da177e4 LT |
599 | q = blk_init_queue(do_viocd_request, &viocd_reqlock); |
600 | if (q == NULL) { | |
e597cd09 | 601 | pr_warning("Cannot allocate queue for %s!\n", c->name); |
1da177e4 LT |
602 | goto out_unregister_cdrom; |
603 | } | |
604 | gendisk = alloc_disk(1); | |
605 | if (gendisk == NULL) { | |
e597cd09 | 606 | pr_warning("Cannot create gendisk for %s!\n", c->name); |
1da177e4 LT |
607 | goto out_cleanup_queue; |
608 | } | |
609 | gendisk->major = VIOCD_MAJOR; | |
610 | gendisk->first_minor = deviceno; | |
611 | strncpy(gendisk->disk_name, c->name, | |
612 | sizeof(gendisk->disk_name)); | |
8a78362c | 613 | blk_queue_max_segments(q, 1); |
086fa5ff | 614 | blk_queue_max_hw_sectors(q, 4096 / 512); |
1da177e4 LT |
615 | gendisk->queue = q; |
616 | gendisk->fops = &viocd_fops; | |
617 | gendisk->flags = GENHD_FL_CD|GENHD_FL_REMOVABLE; | |
618 | set_capacity(gendisk, 0); | |
619 | gendisk->private_data = d; | |
620 | d->viocd_disk = gendisk; | |
621 | d->dev = &vdev->dev; | |
622 | gendisk->driverfs_dev = d->dev; | |
623 | add_disk(gendisk); | |
624 | return 0; | |
625 | ||
626 | out_cleanup_queue: | |
627 | blk_cleanup_queue(q); | |
628 | out_unregister_cdrom: | |
629 | unregister_cdrom(c); | |
630 | out: | |
631 | return -ENODEV; | |
632 | } | |
633 | ||
634 | static int viocd_remove(struct vio_dev *vdev) | |
635 | { | |
636 | struct disk_info *d = &viocd_diskinfo[vdev->unit_address]; | |
637 | ||
0a0c4114 | 638 | unregister_cdrom(&d->viocd_info); |
1da177e4 LT |
639 | del_gendisk(d->viocd_disk); |
640 | blk_cleanup_queue(d->viocd_disk->queue); | |
641 | put_disk(d->viocd_disk); | |
642 | return 0; | |
643 | } | |
644 | ||
645 | /** | |
646 | * viocd_device_table: Used by vio.c to match devices that we | |
647 | * support. | |
648 | */ | |
649 | static struct vio_device_id viocd_device_table[] __devinitdata = { | |
de0fe3b8 | 650 | { "block", "IBM,iSeries-viocd" }, |
fb120da6 | 651 | { "", "" } |
1da177e4 | 652 | }; |
1da177e4 | 653 | MODULE_DEVICE_TABLE(vio, viocd_device_table); |
915124d8 | 654 | |
1da177e4 | 655 | static struct vio_driver viocd_driver = { |
1da177e4 LT |
656 | .id_table = viocd_device_table, |
657 | .probe = viocd_probe, | |
6fdf5392 SR |
658 | .remove = viocd_remove, |
659 | .driver = { | |
660 | .name = "viocd", | |
915124d8 | 661 | .owner = THIS_MODULE, |
6fdf5392 | 662 | } |
1da177e4 LT |
663 | }; |
664 | ||
665 | static int __init viocd_init(void) | |
666 | { | |
1da177e4 LT |
667 | int ret = 0; |
668 | ||
31c72ad0 SR |
669 | if (!firmware_has_feature(FW_FEATURE_ISERIES)) |
670 | return -ENODEV; | |
671 | ||
1da177e4 LT |
672 | if (viopath_hostLp == HvLpIndexInvalid) { |
673 | vio_set_hostlp(); | |
674 | /* If we don't have a host, bail out */ | |
675 | if (viopath_hostLp == HvLpIndexInvalid) | |
676 | return -ENODEV; | |
677 | } | |
678 | ||
e597cd09 | 679 | pr_info("vers " VIOCD_VERS ", hosting partition %d\n", viopath_hostLp); |
1da177e4 LT |
680 | |
681 | if (register_blkdev(VIOCD_MAJOR, VIOCD_DEVICE) != 0) { | |
e597cd09 JP |
682 | pr_warning("Unable to get major %d for %s\n", |
683 | VIOCD_MAJOR, VIOCD_DEVICE); | |
1da177e4 LT |
684 | return -EIO; |
685 | } | |
686 | ||
687 | ret = viopath_open(viopath_hostLp, viomajorsubtype_cdio, | |
688 | MAX_CD_REQ + 2); | |
689 | if (ret) { | |
e597cd09 JP |
690 | pr_warning("error opening path to host partition %d\n", |
691 | viopath_hostLp); | |
1da177e4 LT |
692 | goto out_unregister; |
693 | } | |
694 | ||
695 | /* Initialize our request handler */ | |
696 | vio_setHandler(viomajorsubtype_cdio, vio_handle_cd_event); | |
697 | ||
1da177e4 LT |
698 | spin_lock_init(&viocd_reqlock); |
699 | ||
700 | ret = vio_register_driver(&viocd_driver); | |
701 | if (ret) | |
702 | goto out_free_info; | |
703 | ||
c7705f34 DL |
704 | proc_create("iSeries/viocd", S_IFREG|S_IRUGO, NULL, |
705 | &proc_viocd_operations); | |
1da177e4 LT |
706 | return 0; |
707 | ||
708 | out_free_info: | |
1da177e4 LT |
709 | vio_clearHandler(viomajorsubtype_cdio); |
710 | viopath_close(viopath_hostLp, viomajorsubtype_cdio, MAX_CD_REQ + 2); | |
711 | out_unregister: | |
712 | unregister_blkdev(VIOCD_MAJOR, VIOCD_DEVICE); | |
713 | return ret; | |
714 | } | |
715 | ||
716 | static void __exit viocd_exit(void) | |
717 | { | |
718 | remove_proc_entry("iSeries/viocd", NULL); | |
719 | vio_unregister_driver(&viocd_driver); | |
1da177e4 LT |
720 | viopath_close(viopath_hostLp, viomajorsubtype_cdio, MAX_CD_REQ + 2); |
721 | vio_clearHandler(viomajorsubtype_cdio); | |
722 | unregister_blkdev(VIOCD_MAJOR, VIOCD_DEVICE); | |
723 | } | |
724 | ||
725 | module_init(viocd_init); | |
726 | module_exit(viocd_exit); | |
727 | MODULE_LICENSE("GPL"); |