| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> | 
| Stephen Rothwell | 8962cad | 2008-05-23 11:41:46 +1000 | [diff] [blame] | 9 |  *           Stephen Rothwell | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |  | 
 | 34 | #include <linux/major.h> | 
 | 35 | #include <linux/blkdev.h> | 
 | 36 | #include <linux/cdrom.h> | 
 | 37 | #include <linux/errno.h> | 
 | 38 | #include <linux/init.h> | 
 | 39 | #include <linux/dma-mapping.h> | 
 | 40 | #include <linux/module.h> | 
 | 41 | #include <linux/completion.h> | 
 | 42 | #include <linux/proc_fs.h> | 
 | 43 | #include <linux/seq_file.h> | 
| Jens Axboe | 3d1266c | 2007-10-24 13:21:21 +0200 | [diff] [blame] | 44 | #include <linux/scatterlist.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #include <asm/vio.h> | 
| Kelly Daly | 1ec65d7 | 2005-11-02 13:46:07 +1100 | [diff] [blame] | 47 | #include <asm/iseries/hv_types.h> | 
| Kelly Daly | e45423e | 2005-11-02 12:08:31 +1100 | [diff] [blame] | 48 | #include <asm/iseries/hv_lp_event.h> | 
| Kelly Daly | b420677 | 2005-11-02 15:13:57 +1100 | [diff] [blame] | 49 | #include <asm/iseries/vio.h> | 
| Stephen Rothwell | 31c72ad | 2006-12-15 15:44:04 +1100 | [diff] [blame] | 50 | #include <asm/firmware.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 |  | 
 | 52 | #define VIOCD_DEVICE			"iseries/vcd" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 |  | 
 | 54 | #define VIOCD_VERS "1.06" | 
 | 55 |  | 
 | 56 | #define VIOCD_KERN_WARNING		KERN_WARNING "viocd: " | 
 | 57 | #define VIOCD_KERN_INFO			KERN_INFO "viocd: " | 
 | 58 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | struct disk_info { | 
 | 111 | 	struct gendisk			*viocd_disk; | 
 | 112 | 	struct cdrom_device_info	viocd_info; | 
 | 113 | 	struct device			*dev; | 
| Stephen Rothwell | b833b48 | 2007-10-11 14:57:26 +1000 | [diff] [blame] | 114 | 	const char			*rsrcname; | 
 | 115 | 	const char			*type; | 
 | 116 | 	const char			*model; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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", | 
| Stephen Rothwell | b833b48 | 2007-10-11 14:57:26 +1000 | [diff] [blame] | 134 | 				i, viocd_diskinfo[i].rsrcname, | 
 | 135 | 				viocd_diskinfo[i].type, | 
 | 136 | 				viocd_diskinfo[i].model); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |  | 
| Arjan van de Ven | 2b8693c | 2007-02-12 00:55:32 -0800 | [diff] [blame] | 146 | static const struct file_operations proc_viocd_operations = { | 
| Denis V. Lunev | c7705f3 | 2008-04-29 01:02:35 -0700 | [diff] [blame] | 147 | 	.owner		= THIS_MODULE, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | 	.open		= proc_viocd_open, | 
 | 149 | 	.read		= seq_read, | 
 | 150 | 	.llseek		= seq_lseek, | 
 | 151 | 	.release	= single_release, | 
 | 152 | }; | 
 | 153 |  | 
| Al Viro | 4e379ae | 2008-03-02 10:25:44 -0500 | [diff] [blame] | 154 | static int viocd_blk_open(struct block_device *bdev, fmode_t mode) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | { | 
| Al Viro | 4e379ae | 2008-03-02 10:25:44 -0500 | [diff] [blame] | 156 | 	struct disk_info *di = bdev->bd_disk->private_data; | 
 | 157 | 	return cdrom_open(&di->viocd_info, bdev, mode); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | } | 
 | 159 |  | 
| Al Viro | 4e379ae | 2008-03-02 10:25:44 -0500 | [diff] [blame] | 160 | static int viocd_blk_release(struct gendisk *disk, fmode_t mode) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | { | 
| Al Viro | 4e379ae | 2008-03-02 10:25:44 -0500 | [diff] [blame] | 162 | 	struct disk_info *di = disk->private_data; | 
 | 163 | 	cdrom_release(&di->viocd_info, mode); | 
| Al Viro | bbc1cc9 | 2007-10-07 17:54:28 -0400 | [diff] [blame] | 164 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | } | 
 | 166 |  | 
| Al Viro | 4e379ae | 2008-03-02 10:25:44 -0500 | [diff] [blame] | 167 | static int viocd_blk_ioctl(struct block_device *bdev, fmode_t mode, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | 		unsigned cmd, unsigned long arg) | 
 | 169 | { | 
| Al Viro | 4e379ae | 2008-03-02 10:25:44 -0500 | [diff] [blame] | 170 | 	struct disk_info *di = bdev->bd_disk->private_data; | 
 | 171 | 	return cdrom_ioctl(&di->viocd_info, bdev, mode, cmd, arg); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | } | 
 | 173 |  | 
 | 174 | static int viocd_blk_media_changed(struct gendisk *disk) | 
 | 175 | { | 
 | 176 | 	struct disk_info *di = disk->private_data; | 
 | 177 | 	return cdrom_media_changed(&di->viocd_info); | 
 | 178 | } | 
 | 179 |  | 
| Alexey Dobriyan | 83d5cde | 2009-09-21 17:01:13 -0700 | [diff] [blame] | 180 | static const struct block_device_operations viocd_fops = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | 	.owner =		THIS_MODULE, | 
| Al Viro | 4e379ae | 2008-03-02 10:25:44 -0500 | [diff] [blame] | 182 | 	.open =			viocd_blk_open, | 
 | 183 | 	.release =		viocd_blk_release, | 
 | 184 | 	.locked_ioctl =		viocd_blk_ioctl, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | 	.media_changed =	viocd_blk_media_changed, | 
 | 186 | }; | 
 | 187 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | static int viocd_open(struct cdrom_device_info *cdi, int purpose) | 
 | 189 | { | 
 | 190 |         struct disk_info *diskinfo = cdi->handle; | 
 | 191 | 	int device_no = DEVICE_NR(diskinfo); | 
 | 192 | 	HvLpEvent_Rc hvrc; | 
 | 193 | 	struct viocd_waitevent we; | 
 | 194 |  | 
 | 195 | 	init_completion(&we.com); | 
 | 196 | 	hvrc = HvCallEvent_signalLpEventFast(viopath_hostLp, | 
 | 197 | 			HvLpEvent_Type_VirtualIo, | 
 | 198 | 			viomajorsubtype_cdio | viocdopen, | 
 | 199 | 			HvLpEvent_AckInd_DoAck, HvLpEvent_AckType_ImmediateAck, | 
 | 200 | 			viopath_sourceinst(viopath_hostLp), | 
 | 201 | 			viopath_targetinst(viopath_hostLp), | 
 | 202 | 			(u64)&we, VIOVERSION << 16, ((u64)device_no << 48), | 
 | 203 | 			0, 0, 0); | 
 | 204 | 	if (hvrc != 0) { | 
 | 205 | 		printk(VIOCD_KERN_WARNING | 
 | 206 | 				"bad rc on HvCallEvent_signalLpEventFast %d\n", | 
 | 207 | 				(int)hvrc); | 
 | 208 | 		return -EIO; | 
 | 209 | 	} | 
 | 210 |  | 
 | 211 | 	wait_for_completion(&we.com); | 
 | 212 |  | 
 | 213 | 	if (we.rc) { | 
 | 214 | 		const struct vio_error_entry *err = | 
 | 215 | 			vio_lookup_rc(viocd_err_table, we.sub_result); | 
 | 216 | 		printk(VIOCD_KERN_WARNING "bad rc %d:0x%04X on open: %s\n", | 
 | 217 | 				we.rc, we.sub_result, err->msg); | 
 | 218 | 		return -err->errno; | 
 | 219 | 	} | 
 | 220 |  | 
 | 221 | 	return 0; | 
 | 222 | } | 
 | 223 |  | 
 | 224 | static void viocd_release(struct cdrom_device_info *cdi) | 
 | 225 | { | 
 | 226 | 	int device_no = DEVICE_NR((struct disk_info *)cdi->handle); | 
 | 227 | 	HvLpEvent_Rc hvrc; | 
 | 228 |  | 
 | 229 | 	hvrc = HvCallEvent_signalLpEventFast(viopath_hostLp, | 
 | 230 | 			HvLpEvent_Type_VirtualIo, | 
 | 231 | 			viomajorsubtype_cdio | viocdclose, | 
 | 232 | 			HvLpEvent_AckInd_NoAck, HvLpEvent_AckType_ImmediateAck, | 
 | 233 | 			viopath_sourceinst(viopath_hostLp), | 
 | 234 | 			viopath_targetinst(viopath_hostLp), 0, | 
 | 235 | 			VIOVERSION << 16, ((u64)device_no << 48), 0, 0, 0); | 
 | 236 | 	if (hvrc != 0) | 
 | 237 | 		printk(VIOCD_KERN_WARNING | 
 | 238 | 				"bad rc on HvCallEvent_signalLpEventFast %d\n", | 
 | 239 | 				(int)hvrc); | 
 | 240 | } | 
 | 241 |  | 
 | 242 | /* Send a read or write request to OS/400 */ | 
 | 243 | static int send_request(struct request *req) | 
 | 244 | { | 
 | 245 | 	HvLpEvent_Rc hvrc; | 
 | 246 | 	struct disk_info *diskinfo = req->rq_disk->private_data; | 
 | 247 | 	u64 len; | 
 | 248 | 	dma_addr_t dmaaddr; | 
 | 249 | 	int direction; | 
 | 250 | 	u16 cmd; | 
 | 251 | 	struct scatterlist sg; | 
 | 252 |  | 
 | 253 | 	BUG_ON(req->nr_phys_segments > 1); | 
 | 254 |  | 
 | 255 | 	if (rq_data_dir(req) == READ) { | 
 | 256 | 		direction = DMA_FROM_DEVICE; | 
 | 257 | 		cmd = viomajorsubtype_cdio | viocdread; | 
 | 258 | 	} else { | 
 | 259 | 		direction = DMA_TO_DEVICE; | 
 | 260 | 		cmd = viomajorsubtype_cdio | viocdwrite; | 
 | 261 | 	} | 
 | 262 |  | 
| Jens Axboe | 3d1266c | 2007-10-24 13:21:21 +0200 | [diff] [blame] | 263 | 	sg_init_table(&sg, 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 |         if (blk_rq_map_sg(req->q, req, &sg) == 0) { | 
 | 265 | 		printk(VIOCD_KERN_WARNING | 
 | 266 | 				"error setting up scatter/gather list\n"); | 
 | 267 | 		return -1; | 
 | 268 | 	} | 
 | 269 |  | 
 | 270 | 	if (dma_map_sg(diskinfo->dev, &sg, 1, direction) == 0) { | 
 | 271 | 		printk(VIOCD_KERN_WARNING "error allocating sg tce\n"); | 
 | 272 | 		return -1; | 
 | 273 | 	} | 
 | 274 | 	dmaaddr = sg_dma_address(&sg); | 
 | 275 | 	len = sg_dma_len(&sg); | 
 | 276 |  | 
 | 277 | 	hvrc = HvCallEvent_signalLpEventFast(viopath_hostLp, | 
 | 278 | 			HvLpEvent_Type_VirtualIo, cmd, | 
 | 279 | 			HvLpEvent_AckInd_DoAck, | 
 | 280 | 			HvLpEvent_AckType_ImmediateAck, | 
 | 281 | 			viopath_sourceinst(viopath_hostLp), | 
 | 282 | 			viopath_targetinst(viopath_hostLp), | 
 | 283 | 			(u64)req, VIOVERSION << 16, | 
 | 284 | 			((u64)DEVICE_NR(diskinfo) << 48) | dmaaddr, | 
| Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 285 | 			(u64)blk_rq_pos(req) * 512, len, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | 	if (hvrc != HvLpEvent_Rc_Good) { | 
 | 287 | 		printk(VIOCD_KERN_WARNING "hv error on op %d\n", (int)hvrc); | 
 | 288 | 		return -1; | 
 | 289 | 	} | 
 | 290 |  | 
 | 291 | 	return 0; | 
 | 292 | } | 
 | 293 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | static int rwreq; | 
 | 295 |  | 
| Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 296 | static void do_viocd_request(struct request_queue *q) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | { | 
 | 298 | 	struct request *req; | 
 | 299 |  | 
| Tejun Heo | 9934c8c | 2009-05-08 11:54:16 +0900 | [diff] [blame] | 300 | 	while ((rwreq == 0) && ((req = blk_fetch_request(q)) != NULL)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | 		if (!blk_fs_request(req)) | 
| Tejun Heo | 40cbbb7 | 2009-04-23 11:05:19 +0900 | [diff] [blame] | 302 | 			__blk_end_request_all(req, -EIO); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | 		else if (send_request(req) < 0) { | 
 | 304 | 			printk(VIOCD_KERN_WARNING | 
 | 305 | 					"unable to send message to OS/400!"); | 
| Tejun Heo | 40cbbb7 | 2009-04-23 11:05:19 +0900 | [diff] [blame] | 306 | 			__blk_end_request_all(req, -EIO); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | 		} else | 
 | 308 | 			rwreq++; | 
 | 309 | 	} | 
 | 310 | } | 
 | 311 |  | 
 | 312 | static int viocd_media_changed(struct cdrom_device_info *cdi, int disc_nr) | 
 | 313 | { | 
 | 314 | 	struct viocd_waitevent we; | 
 | 315 | 	HvLpEvent_Rc hvrc; | 
 | 316 | 	int device_no = DEVICE_NR((struct disk_info *)cdi->handle); | 
 | 317 |  | 
 | 318 | 	init_completion(&we.com); | 
 | 319 |  | 
 | 320 | 	/* Send the open event to OS/400 */ | 
 | 321 | 	hvrc = HvCallEvent_signalLpEventFast(viopath_hostLp, | 
 | 322 | 			HvLpEvent_Type_VirtualIo, | 
 | 323 | 			viomajorsubtype_cdio | viocdcheck, | 
 | 324 | 			HvLpEvent_AckInd_DoAck, HvLpEvent_AckType_ImmediateAck, | 
 | 325 | 			viopath_sourceinst(viopath_hostLp), | 
 | 326 | 			viopath_targetinst(viopath_hostLp), | 
 | 327 | 			(u64)&we, VIOVERSION << 16, ((u64)device_no << 48), | 
 | 328 | 			0, 0, 0); | 
 | 329 | 	if (hvrc != 0) { | 
 | 330 | 		printk(VIOCD_KERN_WARNING "bad rc on HvCallEvent_signalLpEventFast %d\n", | 
 | 331 | 				(int)hvrc); | 
 | 332 | 		return -EIO; | 
 | 333 | 	} | 
 | 334 |  | 
 | 335 | 	wait_for_completion(&we.com); | 
 | 336 |  | 
 | 337 | 	/* Check the return code.  If bad, assume no change */ | 
 | 338 | 	if (we.rc) { | 
 | 339 | 		const struct vio_error_entry *err = | 
 | 340 | 			vio_lookup_rc(viocd_err_table, we.sub_result); | 
 | 341 | 		printk(VIOCD_KERN_WARNING | 
 | 342 | 				"bad rc %d:0x%04X on check_change: %s; Assuming no change\n", | 
 | 343 | 				we.rc, we.sub_result, err->msg); | 
 | 344 | 		return 0; | 
 | 345 | 	} | 
 | 346 |  | 
 | 347 | 	return we.changed; | 
 | 348 | } | 
 | 349 |  | 
 | 350 | static int viocd_lock_door(struct cdrom_device_info *cdi, int locking) | 
 | 351 | { | 
 | 352 | 	HvLpEvent_Rc hvrc; | 
 | 353 | 	u64 device_no = DEVICE_NR((struct disk_info *)cdi->handle); | 
 | 354 | 	/* NOTE: flags is 1 or 0 so it won't overwrite the device_no */ | 
 | 355 | 	u64 flags = !!locking; | 
 | 356 | 	struct viocd_waitevent we; | 
 | 357 |  | 
 | 358 | 	init_completion(&we.com); | 
 | 359 |  | 
 | 360 | 	/* Send the lockdoor event to OS/400 */ | 
 | 361 | 	hvrc = HvCallEvent_signalLpEventFast(viopath_hostLp, | 
 | 362 | 			HvLpEvent_Type_VirtualIo, | 
 | 363 | 			viomajorsubtype_cdio | viocdlockdoor, | 
 | 364 | 			HvLpEvent_AckInd_DoAck, HvLpEvent_AckType_ImmediateAck, | 
 | 365 | 			viopath_sourceinst(viopath_hostLp), | 
 | 366 | 			viopath_targetinst(viopath_hostLp), | 
 | 367 | 			(u64)&we, VIOVERSION << 16, | 
 | 368 | 			(device_no << 48) | (flags << 32), 0, 0, 0); | 
 | 369 | 	if (hvrc != 0) { | 
 | 370 | 		printk(VIOCD_KERN_WARNING "bad rc on HvCallEvent_signalLpEventFast %d\n", | 
 | 371 | 				(int)hvrc); | 
 | 372 | 		return -EIO; | 
 | 373 | 	} | 
 | 374 |  | 
 | 375 | 	wait_for_completion(&we.com); | 
 | 376 |  | 
 | 377 | 	if (we.rc != 0) | 
 | 378 | 		return -EIO; | 
 | 379 | 	return 0; | 
 | 380 | } | 
 | 381 |  | 
 | 382 | static int viocd_packet(struct cdrom_device_info *cdi, | 
 | 383 | 		struct packet_command *cgc) | 
 | 384 | { | 
 | 385 | 	unsigned int buflen = cgc->buflen; | 
 | 386 | 	int ret = -EIO; | 
 | 387 |  | 
 | 388 | 	switch (cgc->cmd[0]) { | 
 | 389 | 	case GPCMD_READ_DISC_INFO: | 
 | 390 | 		{ | 
 | 391 | 			disc_information *di = (disc_information *)cgc->buffer; | 
 | 392 |  | 
 | 393 | 			if (buflen >= 2) { | 
 | 394 | 				di->disc_information_length = cpu_to_be16(1); | 
 | 395 | 				ret = 0; | 
 | 396 | 			} | 
 | 397 | 			if (buflen >= 3) | 
 | 398 | 				di->erasable = | 
 | 399 | 					(cdi->ops->capability & ~cdi->mask | 
 | 400 | 					 & (CDC_DVD_RAM | CDC_RAM)) != 0; | 
 | 401 | 		} | 
 | 402 | 		break; | 
| Stephen Rothwell | 9db2925 | 2005-05-27 12:52:58 -0700 | [diff] [blame] | 403 | 	case GPCMD_GET_CONFIGURATION: | 
 | 404 | 		if (cgc->cmd[3] == CDF_RWRT) { | 
 | 405 | 			struct rwrt_feature_desc *rfd = (struct rwrt_feature_desc *)(cgc->buffer + sizeof(struct feature_header)); | 
 | 406 |  | 
 | 407 | 			if ((buflen >= | 
 | 408 | 			     (sizeof(struct feature_header) + sizeof(*rfd))) && | 
 | 409 | 			    (cdi->ops->capability & ~cdi->mask | 
 | 410 | 			     & (CDC_DVD_RAM | CDC_RAM))) { | 
 | 411 | 				rfd->feature_code = cpu_to_be16(CDF_RWRT); | 
 | 412 | 				rfd->curr = 1; | 
 | 413 | 				ret = 0; | 
 | 414 | 			} | 
 | 415 | 		} | 
 | 416 | 		break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | 	default: | 
 | 418 | 		if (cgc->sense) { | 
 | 419 | 			/* indicate Unknown code */ | 
 | 420 | 			cgc->sense->sense_key = 0x05; | 
 | 421 | 			cgc->sense->asc = 0x20; | 
 | 422 | 			cgc->sense->ascq = 0x00; | 
 | 423 | 		} | 
 | 424 | 		break; | 
 | 425 | 	} | 
 | 426 |  | 
 | 427 | 	cgc->stat = ret; | 
 | 428 | 	return ret; | 
 | 429 | } | 
 | 430 |  | 
 | 431 | static void restart_all_queues(int first_index) | 
 | 432 | { | 
 | 433 | 	int i; | 
 | 434 |  | 
 | 435 | 	for (i = first_index + 1; i < viocd_numdev; i++) | 
 | 436 | 		if (viocd_diskinfo[i].viocd_disk) | 
 | 437 | 			blk_run_queue(viocd_diskinfo[i].viocd_disk->queue); | 
 | 438 | 	for (i = 0; i <= first_index; i++) | 
 | 439 | 		if (viocd_diskinfo[i].viocd_disk) | 
 | 440 | 			blk_run_queue(viocd_diskinfo[i].viocd_disk->queue); | 
 | 441 | } | 
 | 442 |  | 
 | 443 | /* This routine handles incoming CD LP events */ | 
 | 444 | static void vio_handle_cd_event(struct HvLpEvent *event) | 
 | 445 | { | 
 | 446 | 	struct viocdlpevent *bevent; | 
 | 447 | 	struct viocd_waitevent *pwe; | 
 | 448 | 	struct disk_info *di; | 
 | 449 | 	unsigned long flags; | 
 | 450 | 	struct request *req; | 
 | 451 |  | 
 | 452 |  | 
 | 453 | 	if (event == NULL) | 
 | 454 | 		/* Notification that a partition went away! */ | 
 | 455 | 		return; | 
 | 456 | 	/* First, we should NEVER get an int here...only acks */ | 
| Stephen Rothwell | 677f8c0 | 2006-01-12 13:47:43 +1100 | [diff] [blame] | 457 | 	if (hvlpevent_is_int(event)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | 		printk(VIOCD_KERN_WARNING | 
 | 459 | 				"Yikes! got an int in viocd event handler!\n"); | 
| Stephen Rothwell | 677f8c0 | 2006-01-12 13:47:43 +1100 | [diff] [blame] | 460 | 		if (hvlpevent_need_ack(event)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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]; | 
| Martin K. Petersen | e1defc4 | 2009-05-22 17:17:49 -0400 | [diff] [blame] | 472 | 			blk_queue_logical_block_size(di->viocd_disk->queue, | 
 | 473 | 						     bevent->block_size); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | 			set_capacity(di->viocd_disk, | 
 | 475 | 					bevent->media_size * | 
 | 476 | 					bevent->block_size / 512); | 
 | 477 | 		} | 
 | 478 | 		/* FALLTHROUGH !! */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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); | 
 | 513 | 			printk(VIOCD_KERN_WARNING "request %p failed " | 
 | 514 | 					"with rc %d:0x%04X: %s\n", | 
 | 515 | 					req, event->xRc, | 
 | 516 | 					bevent->sub_result, err->msg); | 
| Tejun Heo | 40cbbb7 | 2009-04-23 11:05:19 +0900 | [diff] [blame] | 517 | 			__blk_end_request_all(req, -EIO); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | 		} else | 
| Tejun Heo | 40cbbb7 | 2009-04-23 11:05:19 +0900 | [diff] [blame] | 519 | 			__blk_end_request_all(req, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 |  | 
 | 521 | 		/* restart handling of incoming requests */ | 
 | 522 | 		spin_unlock_irqrestore(&viocd_reqlock, flags); | 
 | 523 | 		restart_all_queues(bevent->disk); | 
 | 524 | 		break; | 
 | 525 |  | 
 | 526 | 	default: | 
 | 527 | 		printk(VIOCD_KERN_WARNING | 
 | 528 | 				"message with invalid subtype %0x04X!\n", | 
 | 529 | 				event->xSubtype & VIOMINOR_SUBTYPE_MASK); | 
| Stephen Rothwell | 677f8c0 | 2006-01-12 13:47:43 +1100 | [diff] [blame] | 530 | 		if (hvlpevent_need_ack(event)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | 			event->xRc = HvLpEvent_Rc_InvalidSubtype; | 
 | 532 | 			HvCallEvent_ackLpEvent(event); | 
 | 533 | 		} | 
 | 534 | 	} | 
 | 535 | } | 
 | 536 |  | 
| Borislav Petkov | 3e636f7 | 2008-08-18 21:40:03 +0200 | [diff] [blame] | 537 | static int viocd_audio_ioctl(struct cdrom_device_info *cdi, unsigned int cmd, | 
 | 538 | 			     void *arg) | 
 | 539 | { | 
 | 540 | 	return -EINVAL; | 
 | 541 | } | 
 | 542 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | static struct cdrom_device_ops viocd_dops = { | 
 | 544 | 	.open = viocd_open, | 
 | 545 | 	.release = viocd_release, | 
 | 546 | 	.media_changed = viocd_media_changed, | 
 | 547 | 	.lock_door = viocd_lock_door, | 
 | 548 | 	.generic_packet = viocd_packet, | 
| Borislav Petkov | 3e636f7 | 2008-08-18 21:40:03 +0200 | [diff] [blame] | 549 | 	.audio_ioctl = viocd_audio_ioctl, | 
| Christoph Hellwig | 6a2900b | 2006-03-23 03:00:15 -0800 | [diff] [blame] | 550 | 	.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 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | }; | 
 | 552 |  | 
| Stephen Rothwell | c721192 | 2008-02-05 14:17:31 +1100 | [diff] [blame] | 553 | static int find_capability(const char *type) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | { | 
 | 555 | 	struct capability_entry *entry; | 
 | 556 |  | 
 | 557 | 	for(entry = capability_table; entry->type; ++entry) | 
 | 558 | 		if(!strncmp(entry->type, type, 4)) | 
 | 559 | 			break; | 
 | 560 | 	return entry->capability; | 
 | 561 | } | 
 | 562 |  | 
 | 563 | static int viocd_probe(struct vio_dev *vdev, const struct vio_device_id *id) | 
 | 564 | { | 
 | 565 | 	struct gendisk *gendisk; | 
 | 566 | 	int deviceno; | 
 | 567 | 	struct disk_info *d; | 
 | 568 | 	struct cdrom_device_info *c; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | 	struct request_queue *q; | 
| Stephen Rothwell | b833b48 | 2007-10-11 14:57:26 +1000 | [diff] [blame] | 570 | 	struct device_node *node = vdev->dev.archdata.of_node; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 |  | 
 | 572 | 	deviceno = vdev->unit_address; | 
| Roel Kluin | d3375ea | 2009-05-20 08:42:06 +0200 | [diff] [blame] | 573 | 	if (deviceno >= VIOCD_MAX_CD) | 
| Stephen Rothwell | b833b48 | 2007-10-11 14:57:26 +1000 | [diff] [blame] | 574 | 		return -ENODEV; | 
 | 575 | 	if (!node) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | 		return -ENODEV; | 
 | 577 |  | 
| Stephen Rothwell | b833b48 | 2007-10-11 14:57:26 +1000 | [diff] [blame] | 578 | 	if (deviceno >= viocd_numdev) | 
 | 579 | 		viocd_numdev = deviceno + 1; | 
 | 580 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | 	d = &viocd_diskinfo[deviceno]; | 
| Stephen Rothwell | b833b48 | 2007-10-11 14:57:26 +1000 | [diff] [blame] | 582 | 	d->rsrcname = of_get_property(node, "linux,vio_rsrcname", NULL); | 
 | 583 | 	d->type = of_get_property(node, "linux,vio_type", NULL); | 
 | 584 | 	d->model = of_get_property(node, "linux,vio_model", NULL); | 
 | 585 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | 	c = &d->viocd_info; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 |  | 
 | 588 | 	c->ops = &viocd_dops; | 
 | 589 | 	c->speed = 4; | 
 | 590 | 	c->capacity = 1; | 
 | 591 | 	c->handle = d; | 
| Stephen Rothwell | b833b48 | 2007-10-11 14:57:26 +1000 | [diff] [blame] | 592 | 	c->mask = ~find_capability(d->type); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | 	sprintf(c->name, VIOCD_DEVICE "%c", 'a' + deviceno); | 
 | 594 |  | 
 | 595 | 	if (register_cdrom(c) != 0) { | 
 | 596 | 		printk(VIOCD_KERN_WARNING "Cannot register viocd CD-ROM %s!\n", | 
 | 597 | 				c->name); | 
 | 598 | 		goto out; | 
 | 599 | 	} | 
 | 600 | 	printk(VIOCD_KERN_INFO "cd %s is iSeries resource %10.10s " | 
 | 601 | 			"type %4.4s, model %3.3s\n", | 
| Stephen Rothwell | b833b48 | 2007-10-11 14:57:26 +1000 | [diff] [blame] | 602 | 			c->name, d->rsrcname, d->type, d->model); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | 	q = blk_init_queue(do_viocd_request, &viocd_reqlock); | 
 | 604 | 	if (q == NULL) { | 
 | 605 | 		printk(VIOCD_KERN_WARNING "Cannot allocate queue for %s!\n", | 
 | 606 | 				c->name); | 
 | 607 | 		goto out_unregister_cdrom; | 
 | 608 | 	} | 
 | 609 | 	gendisk = alloc_disk(1); | 
 | 610 | 	if (gendisk == NULL) { | 
 | 611 | 		printk(VIOCD_KERN_WARNING "Cannot create gendisk for %s!\n", | 
 | 612 | 				c->name); | 
 | 613 | 		goto out_cleanup_queue; | 
 | 614 | 	} | 
 | 615 | 	gendisk->major = VIOCD_MAJOR; | 
 | 616 | 	gendisk->first_minor = deviceno; | 
 | 617 | 	strncpy(gendisk->disk_name, c->name, | 
 | 618 | 			sizeof(gendisk->disk_name)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | 	blk_queue_max_hw_segments(q, 1); | 
 | 620 | 	blk_queue_max_phys_segments(q, 1); | 
 | 621 | 	blk_queue_max_sectors(q, 4096 / 512); | 
 | 622 | 	gendisk->queue = q; | 
 | 623 | 	gendisk->fops = &viocd_fops; | 
 | 624 | 	gendisk->flags = GENHD_FL_CD|GENHD_FL_REMOVABLE; | 
 | 625 | 	set_capacity(gendisk, 0); | 
 | 626 | 	gendisk->private_data = d; | 
 | 627 | 	d->viocd_disk = gendisk; | 
 | 628 | 	d->dev = &vdev->dev; | 
 | 629 | 	gendisk->driverfs_dev = d->dev; | 
 | 630 | 	add_disk(gendisk); | 
 | 631 | 	return 0; | 
 | 632 |  | 
 | 633 | out_cleanup_queue: | 
 | 634 | 	blk_cleanup_queue(q); | 
 | 635 | out_unregister_cdrom: | 
 | 636 | 	unregister_cdrom(c); | 
 | 637 | out: | 
 | 638 | 	return -ENODEV; | 
 | 639 | } | 
 | 640 |  | 
 | 641 | static int viocd_remove(struct vio_dev *vdev) | 
 | 642 | { | 
 | 643 | 	struct disk_info *d = &viocd_diskinfo[vdev->unit_address]; | 
 | 644 |  | 
| Akinobu Mita | 0a0c411 | 2008-03-26 12:09:02 +0100 | [diff] [blame] | 645 | 	unregister_cdrom(&d->viocd_info); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | 	del_gendisk(d->viocd_disk); | 
 | 647 | 	blk_cleanup_queue(d->viocd_disk->queue); | 
 | 648 | 	put_disk(d->viocd_disk); | 
 | 649 | 	return 0; | 
 | 650 | } | 
 | 651 |  | 
 | 652 | /** | 
 | 653 |  * viocd_device_table: Used by vio.c to match devices that we | 
 | 654 |  * support. | 
 | 655 |  */ | 
 | 656 | static struct vio_device_id viocd_device_table[] __devinitdata = { | 
| Stephen Rothwell | de0fe3b | 2006-05-15 13:44:01 +1000 | [diff] [blame] | 657 | 	{ "block", "IBM,iSeries-viocd" }, | 
| Stephen Rothwell | fb120da | 2005-08-17 16:42:59 +1000 | [diff] [blame] | 658 | 	{ "", "" } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | MODULE_DEVICE_TABLE(vio, viocd_device_table); | 
| Stephen Rothwell | 915124d | 2005-10-24 15:12:22 +1000 | [diff] [blame] | 661 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | static struct vio_driver viocd_driver = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | 	.id_table = viocd_device_table, | 
 | 664 | 	.probe = viocd_probe, | 
| Stephen Rothwell | 6fdf539 | 2005-10-24 14:53:21 +1000 | [diff] [blame] | 665 | 	.remove = viocd_remove, | 
 | 666 | 	.driver = { | 
 | 667 | 		.name = "viocd", | 
| Stephen Rothwell | 915124d | 2005-10-24 15:12:22 +1000 | [diff] [blame] | 668 | 		.owner = THIS_MODULE, | 
| Stephen Rothwell | 6fdf539 | 2005-10-24 14:53:21 +1000 | [diff] [blame] | 669 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | }; | 
 | 671 |  | 
 | 672 | static int __init viocd_init(void) | 
 | 673 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | 	int ret = 0; | 
 | 675 |  | 
| Stephen Rothwell | 31c72ad | 2006-12-15 15:44:04 +1100 | [diff] [blame] | 676 | 	if (!firmware_has_feature(FW_FEATURE_ISERIES)) | 
 | 677 | 		return -ENODEV; | 
 | 678 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | 	if (viopath_hostLp == HvLpIndexInvalid) { | 
 | 680 | 		vio_set_hostlp(); | 
 | 681 | 		/* If we don't have a host, bail out */ | 
 | 682 | 		if (viopath_hostLp == HvLpIndexInvalid) | 
 | 683 | 			return -ENODEV; | 
 | 684 | 	} | 
 | 685 |  | 
 | 686 | 	printk(VIOCD_KERN_INFO "vers " VIOCD_VERS ", hosting partition %d\n", | 
 | 687 | 			viopath_hostLp); | 
 | 688 |  | 
 | 689 | 	if (register_blkdev(VIOCD_MAJOR, VIOCD_DEVICE) != 0) { | 
 | 690 | 		printk(VIOCD_KERN_WARNING "Unable to get major %d for %s\n", | 
 | 691 | 				VIOCD_MAJOR, VIOCD_DEVICE); | 
 | 692 | 		return -EIO; | 
 | 693 | 	} | 
 | 694 |  | 
 | 695 | 	ret = viopath_open(viopath_hostLp, viomajorsubtype_cdio, | 
 | 696 | 			MAX_CD_REQ + 2); | 
 | 697 | 	if (ret) { | 
 | 698 | 		printk(VIOCD_KERN_WARNING | 
 | 699 | 				"error opening path to host partition %d\n", | 
 | 700 | 				viopath_hostLp); | 
 | 701 | 		goto out_unregister; | 
 | 702 | 	} | 
 | 703 |  | 
 | 704 | 	/* Initialize our request handler */ | 
 | 705 | 	vio_setHandler(viomajorsubtype_cdio, vio_handle_cd_event); | 
 | 706 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | 	spin_lock_init(&viocd_reqlock); | 
 | 708 |  | 
 | 709 | 	ret = vio_register_driver(&viocd_driver); | 
 | 710 | 	if (ret) | 
 | 711 | 		goto out_free_info; | 
 | 712 |  | 
| Denis V. Lunev | c7705f3 | 2008-04-29 01:02:35 -0700 | [diff] [blame] | 713 | 	proc_create("iSeries/viocd", S_IFREG|S_IRUGO, NULL, | 
 | 714 | 		    &proc_viocd_operations); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | 	return 0; | 
 | 716 |  | 
 | 717 | out_free_info: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | 	vio_clearHandler(viomajorsubtype_cdio); | 
 | 719 | 	viopath_close(viopath_hostLp, viomajorsubtype_cdio, MAX_CD_REQ + 2); | 
 | 720 | out_unregister: | 
 | 721 | 	unregister_blkdev(VIOCD_MAJOR, VIOCD_DEVICE); | 
 | 722 | 	return ret; | 
 | 723 | } | 
 | 724 |  | 
 | 725 | static void __exit viocd_exit(void) | 
 | 726 | { | 
 | 727 | 	remove_proc_entry("iSeries/viocd", NULL); | 
 | 728 | 	vio_unregister_driver(&viocd_driver); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | 	viopath_close(viopath_hostLp, viomajorsubtype_cdio, MAX_CD_REQ + 2); | 
 | 730 | 	vio_clearHandler(viomajorsubtype_cdio); | 
 | 731 | 	unregister_blkdev(VIOCD_MAJOR, VIOCD_DEVICE); | 
 | 732 | } | 
 | 733 |  | 
 | 734 | module_init(viocd_init); | 
 | 735 | module_exit(viocd_exit); | 
 | 736 | MODULE_LICENSE("GPL"); |