ia64/xen-unstable

changeset 377:cb3567d804d2

bitkeeper revision 1.178.1.1 (3e9ed9f8LHaadjxKzRBXgrVFHvdPPQ)

better cdrom support
author smh22@boulderdash.cl.cam.ac.uk
date Thu Apr 17 16:44:40 2003 +0000 (2003-04-17)
parents cece37ee4eab
children c04764a383ee
files BitKeeper/etc/ignore xen/drivers/ide/ide-cd.c xen/drivers/ide/ide-disk.c xen/drivers/ide/ide-xeno.c xen/drivers/ide/ide.c xen/drivers/scsi/scsi.c xen/drivers/scsi/sd.c xen/include/hypervisor-ifs/block.h xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/block/xl_ide.c
line diff
     1.1 --- a/BitKeeper/etc/ignore	Wed Apr 16 22:41:46 2003 +0000
     1.2 +++ b/BitKeeper/etc/ignore	Thu Apr 17 16:44:40 2003 +0000
     1.3 @@ -153,3 +153,22 @@ xen/net/eth.o
     1.4  xen/net/network.o
     1.5  xen/net/skbuff.o
     1.6  xen/tools/elf-reloc
     1.7 +tools/balloon/balloon
     1.8 +xen/common/dom_mem_ops.o
     1.9 +xen/common/string.o
    1.10 +xen/drivers/block/xen_segment.o
    1.11 +xen/drivers/cdrom/cdrom.o
    1.12 +xen/drivers/cdrom/driver.o
    1.13 +xen/drivers/ide/ide-cd.o
    1.14 +xen/drivers/scsi/aic7xxx/aic7770.o
    1.15 +xen/drivers/scsi/aic7xxx/aic7770_osm.o
    1.16 +xen/drivers/scsi/aic7xxx/aic7xxx.o
    1.17 +xen/drivers/scsi/aic7xxx/aic7xxx_93cx6.o
    1.18 +xen/drivers/scsi/aic7xxx/aic7xxx_core.o
    1.19 +xen/drivers/scsi/aic7xxx/aic7xxx_osm.o
    1.20 +xen/drivers/scsi/aic7xxx/aic7xxx_osm_pci.o
    1.21 +xen/drivers/scsi/aic7xxx/aic7xxx_pci.o
    1.22 +xen/drivers/scsi/aic7xxx/aic7xxx_proc.o
    1.23 +xen/drivers/scsi/megaraid.o
    1.24 +xen/image.s
    1.25 +xen/include/hypervisor-ifs/hypervisor-ifs
     2.1 --- a/xen/drivers/ide/ide-cd.c	Wed Apr 16 22:41:46 2003 +0000
     2.2 +++ b/xen/drivers/ide/ide-cd.c	Thu Apr 17 16:44:40 2003 +0000
     2.3 @@ -325,47 +325,47 @@
     2.4     buffers. */
     2.5  static void cdrom_saw_media_change (ide_drive_t *drive)
     2.6  {
     2.7 -	struct cdrom_info *info = drive->driver_data;
     2.8 +    struct cdrom_info *info = drive->driver_data;
     2.9  	
    2.10 -	CDROM_STATE_FLAGS (drive)->media_changed = 1;
    2.11 -	CDROM_STATE_FLAGS (drive)->toc_valid = 0;
    2.12 -	info->nsectors_buffered = 0;
    2.13 +    CDROM_STATE_FLAGS (drive)->media_changed = 1;
    2.14 +    CDROM_STATE_FLAGS (drive)->toc_valid = 0;
    2.15 +    info->nsectors_buffered = 0;
    2.16  }
    2.17  
    2.18  static int cdrom_log_sense(ide_drive_t *drive, struct packet_command *pc,
    2.19  			   struct request_sense *sense)
    2.20  {
    2.21 -	int log = 0;
    2.22 -
    2.23 -	if (sense == NULL || pc == NULL || pc->quiet)
    2.24 -		return 0;
    2.25 -
    2.26 -	switch (sense->sense_key) {
    2.27 -		case NO_SENSE: case RECOVERED_ERROR:
    2.28 -			break;
    2.29 -		case NOT_READY:
    2.30 -			/*
    2.31 -			 * don't care about tray state messages for
    2.32 -			 * e.g. capacity commands or in-progress or
    2.33 -			 * becoming ready
    2.34 -			 */
    2.35 -			if (sense->asc == 0x3a || sense->asc == 0x04)
    2.36 -				break;
    2.37 -			log = 1;
    2.38 -			break;
    2.39 -		case UNIT_ATTENTION:
    2.40 -			/*
    2.41 -			 * Make good and sure we've seen this potential media
    2.42 -			 * change. Some drives (i.e. Creative) fail to present
    2.43 -			 * the correct sense key in the error register.
    2.44 -			 */
    2.45 -			cdrom_saw_media_change(drive);
    2.46 -			break;
    2.47 -		default:
    2.48 -			log = 1;
    2.49 -			break;
    2.50 -	}
    2.51 -	return log;
    2.52 +    int log = 0;
    2.53 +
    2.54 +    if (sense == NULL || pc == NULL || pc->quiet)
    2.55 +	return 0;
    2.56 +
    2.57 +    switch (sense->sense_key) {
    2.58 +    case NO_SENSE: case RECOVERED_ERROR:
    2.59 +	break;
    2.60 +    case NOT_READY:
    2.61 +	/*
    2.62 +	 * don't care about tray state messages for
    2.63 +	 * e.g. capacity commands or in-progress or
    2.64 +	 * becoming ready
    2.65 +	 */
    2.66 +	if (sense->asc == 0x3a || sense->asc == 0x04)
    2.67 +	    break;
    2.68 +	log = 1;
    2.69 +	break;
    2.70 +    case UNIT_ATTENTION:
    2.71 +	/*
    2.72 +	 * Make good and sure we've seen this potential media
    2.73 +	 * change. Some drives (i.e. Creative) fail to present
    2.74 +	 * the correct sense key in the error register.
    2.75 +	 */
    2.76 +	cdrom_saw_media_change(drive);
    2.77 +	break;
    2.78 +    default:
    2.79 +	log = 1;
    2.80 +	break;
    2.81 +    }
    2.82 +    return log;
    2.83  }
    2.84  
    2.85  static
    2.86 @@ -374,141 +374,141 @@ void cdrom_analyze_sense_data(ide_drive_
    2.87  			      struct request_sense *sense)
    2.88  {
    2.89  
    2.90 -	if (!cdrom_log_sense(drive, failed_command, sense))
    2.91 -		return;
    2.92 -
    2.93 -	/*
    2.94 -	 * If a read toc is executed for a CD-R or CD-RW medium where
    2.95 -	 * the first toc has not been recorded yet, it will fail with
    2.96 -	 * 05/24/00 (which is a confusing error)
    2.97 -	 */
    2.98 -	if (failed_command && failed_command->c[0] == GPCMD_READ_TOC_PMA_ATIP)
    2.99 -		if (sense->sense_key == 0x05 && sense->asc == 0x24)
   2.100 -			return;
   2.101 +    if (!cdrom_log_sense(drive, failed_command, sense))
   2.102 +	return;
   2.103 +
   2.104 +    /*
   2.105 +     * If a read toc is executed for a CD-R or CD-RW medium where
   2.106 +     * the first toc has not been recorded yet, it will fail with
   2.107 +     * 05/24/00 (which is a confusing error)
   2.108 +     */
   2.109 +    if (failed_command && failed_command->c[0] == GPCMD_READ_TOC_PMA_ATIP)
   2.110 +	if (sense->sense_key == 0x05 && sense->asc == 0x24)
   2.111 +	    return;
   2.112  
   2.113  #if VERBOSE_IDE_CD_ERRORS
   2.114 -	{
   2.115 -		int i;
   2.116 -		const char *s;
   2.117 -		char buf[80];
   2.118 -
   2.119 -		printk ("ATAPI device %s:\n", drive->name);
   2.120 -		if (sense->error_code==0x70)
   2.121 -			printk("  Error: ");
   2.122 -		else if (sense->error_code==0x71)
   2.123 -			printk("  Deferred Error: ");
   2.124 -		else if (sense->error_code == 0x7f)
   2.125 -			printk("  Vendor-specific Error: ");
   2.126 -		else
   2.127 -			printk("  Unknown Error Type: ");
   2.128 -
   2.129 -		if (sense->sense_key < ARY_LEN(sense_key_texts))
   2.130 -			s = sense_key_texts[sense->sense_key];
   2.131 -		else
   2.132 -			s = "bad sense key!";
   2.133 -
   2.134 -		printk("%s -- (Sense key=0x%02x)\n", s, sense->sense_key);
   2.135 -
   2.136 -		if (sense->asc == 0x40) {
   2.137 -			sprintf(buf, "Diagnostic failure on component 0x%02x",
   2.138 -				 sense->ascq);
   2.139 -			s = buf;
   2.140 -		} else {
   2.141 -			int lo = 0, mid, hi = ARY_LEN(sense_data_texts);
   2.142 -			unsigned long key = (sense->sense_key << 16);
   2.143 -			key |= (sense->asc << 8);
   2.144 -			if (!(sense->ascq >= 0x80 && sense->ascq <= 0xdd))
   2.145 -				key |= sense->ascq;
   2.146 -			s = NULL;
   2.147 -
   2.148 -			while (hi > lo) {
   2.149 -				mid = (lo + hi) / 2;
   2.150 -				if (sense_data_texts[mid].asc_ascq == key ||
   2.151 -				    sense_data_texts[mid].asc_ascq == (0xff0000|key)) {
   2.152 -					s = sense_data_texts[mid].text;
   2.153 -					break;
   2.154 -				}
   2.155 -				else if (sense_data_texts[mid].asc_ascq > key)
   2.156 -					hi = mid;
   2.157 -				else
   2.158 -					lo = mid+1;
   2.159 -			}
   2.160 -		}
   2.161 -
   2.162 -		if (s == NULL) {
   2.163 -			if (sense->asc > 0x80)
   2.164 -				s = "(vendor-specific error)";
   2.165 -			else
   2.166 -				s = "(reserved error code)";
   2.167 +    {
   2.168 +	int i;
   2.169 +	const char *s;
   2.170 +	char buf[80];
   2.171 +
   2.172 +	printk ("ATAPI device %s:\n", drive->name);
   2.173 +	if (sense->error_code==0x70)
   2.174 +	    printk("  Error: ");
   2.175 +	else if (sense->error_code==0x71)
   2.176 +	    printk("  Deferred Error: ");
   2.177 +	else if (sense->error_code == 0x7f)
   2.178 +	    printk("  Vendor-specific Error: ");
   2.179 +	else
   2.180 +	    printk("  Unknown Error Type: ");
   2.181 +
   2.182 +	if (sense->sense_key < ARY_LEN(sense_key_texts))
   2.183 +	    s = sense_key_texts[sense->sense_key];
   2.184 +	else
   2.185 +	    s = "bad sense key!";
   2.186 +
   2.187 +	printk("%s -- (Sense key=0x%02x)\n", s, sense->sense_key);
   2.188 +
   2.189 +	if (sense->asc == 0x40) {
   2.190 +	    sprintf(buf, "Diagnostic failure on component 0x%02x",
   2.191 +		    sense->ascq);
   2.192 +	    s = buf;
   2.193 +	} else {
   2.194 +	    int lo = 0, mid, hi = ARY_LEN(sense_data_texts);
   2.195 +	    unsigned long key = (sense->sense_key << 16);
   2.196 +	    key |= (sense->asc << 8);
   2.197 +	    if (!(sense->ascq >= 0x80 && sense->ascq <= 0xdd))
   2.198 +		key |= sense->ascq;
   2.199 +	    s = NULL;
   2.200 +
   2.201 +	    while (hi > lo) {
   2.202 +		mid = (lo + hi) / 2;
   2.203 +		if (sense_data_texts[mid].asc_ascq == key ||
   2.204 +		    sense_data_texts[mid].asc_ascq == (0xff0000|key)) {
   2.205 +		    s = sense_data_texts[mid].text;
   2.206 +		    break;
   2.207  		}
   2.208 -
   2.209 -		printk("  %s -- (asc=0x%02x, ascq=0x%02x)\n",
   2.210 -			s, sense->asc, sense->ascq);
   2.211 -
   2.212 -		if (failed_command != NULL) {
   2.213 -
   2.214 -			int lo=0, mid, hi= ARY_LEN (packet_command_texts);
   2.215 -			s = NULL;
   2.216 -
   2.217 -			while (hi > lo) {
   2.218 -				mid = (lo + hi) / 2;
   2.219 -				if (packet_command_texts[mid].packet_command ==
   2.220 -				    failed_command->c[0]) {
   2.221 -					s = packet_command_texts[mid].text;
   2.222 -					break;
   2.223 -				}
   2.224 -				if (packet_command_texts[mid].packet_command >
   2.225 -				    failed_command->c[0])
   2.226 -					hi = mid;
   2.227 -				else
   2.228 -					lo = mid+1;
   2.229 -			}
   2.230 -
   2.231 -			printk ("  The failed \"%s\" packet command was: \n  \"", s);
   2.232 -			for (i=0; i<sizeof (failed_command->c); i++)
   2.233 -				printk ("%02x ", failed_command->c[i]);
   2.234 -			printk ("\"\n");
   2.235 +		else if (sense_data_texts[mid].asc_ascq > key)
   2.236 +		    hi = mid;
   2.237 +		else
   2.238 +		    lo = mid+1;
   2.239 +	    }
   2.240 +	}
   2.241 +
   2.242 +	if (s == NULL) {
   2.243 +	    if (sense->asc > 0x80)
   2.244 +		s = "(vendor-specific error)";
   2.245 +	    else
   2.246 +		s = "(reserved error code)";
   2.247 +	}
   2.248 +
   2.249 +	printk("  %s -- (asc=0x%02x, ascq=0x%02x)\n",
   2.250 +	       s, sense->asc, sense->ascq);
   2.251 +
   2.252 +	if (failed_command != NULL) {
   2.253 +
   2.254 +	    int lo=0, mid, hi= ARY_LEN (packet_command_texts);
   2.255 +	    s = NULL;
   2.256 +
   2.257 +	    while (hi > lo) {
   2.258 +		mid = (lo + hi) / 2;
   2.259 +		if (packet_command_texts[mid].packet_command ==
   2.260 +		    failed_command->c[0]) {
   2.261 +		    s = packet_command_texts[mid].text;
   2.262 +		    break;
   2.263  		}
   2.264 -
   2.265 -		/* The SKSV bit specifies validity of the sense_key_specific
   2.266 -		 * in the next two commands. It is bit 7 of the first byte.
   2.267 -		 * In the case of NOT_READY, if SKSV is set the drive can
   2.268 -		 * give us nice ETA readings.
   2.269 -		 */
   2.270 -		if (sense->sense_key == NOT_READY && (sense->sks[0] & 0x80)) {
   2.271 -			int progress = (sense->sks[1] << 8 | sense->sks[2]) * 100;
   2.272 -			printk("  Command is %02d%% complete\n", progress / 0xffff);
   2.273 -
   2.274 -		}
   2.275 -
   2.276 -		if (sense->sense_key == ILLEGAL_REQUEST &&
   2.277 -		    (sense->sks[0] & 0x80) != 0) {
   2.278 -			printk("  Error in %s byte %d",
   2.279 -				(sense->sks[0] & 0x40) != 0 ?
   2.280 -				"command packet" : "command data",
   2.281 -				(sense->sks[1] << 8) + sense->sks[2]);
   2.282 -
   2.283 -			if ((sense->sks[0] & 0x40) != 0)
   2.284 -				printk (" bit %d", sense->sks[0] & 0x07);
   2.285 -
   2.286 -			printk ("\n");
   2.287 -		}
   2.288 +		if (packet_command_texts[mid].packet_command >
   2.289 +		    failed_command->c[0])
   2.290 +		    hi = mid;
   2.291 +		else
   2.292 +		    lo = mid+1;
   2.293 +	    }
   2.294 +
   2.295 +	    printk ("  The failed \"%s\" packet command was: \n  \"", s);
   2.296 +	    for (i=0; i<sizeof (failed_command->c); i++)
   2.297 +		printk ("%02x ", failed_command->c[i]);
   2.298 +	    printk ("\"\n");
   2.299  	}
   2.300  
   2.301 +	/* The SKSV bit specifies validity of the sense_key_specific
   2.302 +	 * in the next two commands. It is bit 7 of the first byte.
   2.303 +	 * In the case of NOT_READY, if SKSV is set the drive can
   2.304 +	 * give us nice ETA readings.
   2.305 +	 */
   2.306 +	if (sense->sense_key == NOT_READY && (sense->sks[0] & 0x80)) {
   2.307 +	    int progress = (sense->sks[1] << 8 | sense->sks[2]) * 100;
   2.308 +	    printk("  Command is %02d%% complete\n", progress / 0xffff);
   2.309 +
   2.310 +	}
   2.311 +
   2.312 +	if (sense->sense_key == ILLEGAL_REQUEST &&
   2.313 +	    (sense->sks[0] & 0x80) != 0) {
   2.314 +	    printk("  Error in %s byte %d",
   2.315 +		   (sense->sks[0] & 0x40) != 0 ?
   2.316 +		   "command packet" : "command data",
   2.317 +		   (sense->sks[1] << 8) + sense->sks[2]);
   2.318 +
   2.319 +	    if ((sense->sks[0] & 0x40) != 0)
   2.320 +		printk (" bit %d", sense->sks[0] & 0x07);
   2.321 +
   2.322 +	    printk ("\n");
   2.323 +	}
   2.324 +    }
   2.325 +
   2.326  #else /* not VERBOSE_IDE_CD_ERRORS */
   2.327  
   2.328 -	/* Suppress printing unit attention and `in progress of becoming ready'
   2.329 -	   errors when we're not being verbose. */
   2.330 -
   2.331 -	if (sense->sense_key == UNIT_ATTENTION ||
   2.332 -	    (sense->sense_key == NOT_READY && (sense->asc == 4 ||
   2.333 -						sense->asc == 0x3a)))
   2.334 -		return;
   2.335 -
   2.336 -	printk("%s: error code: 0x%02x  sense_key: 0x%02x  asc: 0x%02x  ascq: 0x%02x\n",
   2.337 -		drive->name,
   2.338 -		sense->error_code, sense->sense_key,
   2.339 -		sense->asc, sense->ascq);
   2.340 +    /* Suppress printing unit attention and `in progress of becoming ready'
   2.341 +       errors when we're not being verbose. */
   2.342 +
   2.343 +    if (sense->sense_key == UNIT_ATTENTION ||
   2.344 +	(sense->sense_key == NOT_READY && (sense->asc == 4 ||
   2.345 +					   sense->asc == 0x3a)))
   2.346 +	return;
   2.347 +
   2.348 +    printk("%s: error code: 0x%02x  sense_key: 0x%02x  asc: 0x%02x  ascq: 0x%02x\n",
   2.349 +	   drive->name,
   2.350 +	   sense->error_code, sense->sense_key,
   2.351 +	   sense->asc, sense->ascq);
   2.352  #endif /* not VERBOSE_IDE_CD_ERRORS */
   2.353  }
   2.354  
   2.355 @@ -517,44 +517,45 @@ static void cdrom_queue_request_sense(id
   2.356  				      struct request_sense *sense,
   2.357  				      struct packet_command *failed_command)
   2.358  {
   2.359 -	struct cdrom_info *info		= drive->driver_data;
   2.360 -	struct packet_command *pc	= &info->request_sense_pc;
   2.361 -	struct request *rq;
   2.362 -
   2.363 -	if (sense == NULL)
   2.364 -		sense = &info->sense_data;
   2.365 -
   2.366 -	memset(pc, 0, sizeof(struct packet_command));
   2.367 -	pc->c[0] = GPCMD_REQUEST_SENSE;
   2.368 -	pc->c[4] = pc->buflen = 18;
   2.369 -	pc->buffer = (char *) sense;
   2.370 -	pc->sense = (struct request_sense *) failed_command;
   2.371 -
   2.372 -	/* stuff the sense request in front of our current request */
   2.373 -	rq = &info->request_sense_request;
   2.374 -	ide_init_drive_cmd(rq);
   2.375 -	rq->cmd = REQUEST_SENSE_COMMAND;
   2.376 -	rq->buffer = (char *) pc;
   2.377 -	rq->waiting = wait;
   2.378 -	(void) ide_do_drive_cmd(drive, rq, ide_preempt);
   2.379 +    struct cdrom_info *info		= drive->driver_data;
   2.380 +    struct packet_command *pc	= &info->request_sense_pc;
   2.381 +    struct request *rq;
   2.382 +
   2.383 +    if (sense == NULL)
   2.384 +	sense = &info->sense_data;
   2.385 +
   2.386 +    memset(pc, 0, sizeof(struct packet_command));
   2.387 +    pc->c[0] = GPCMD_REQUEST_SENSE;
   2.388 +    pc->c[4] = pc->buflen = 18;
   2.389 +    pc->buffer = (char *) sense;
   2.390 +    pc->sense = (struct request_sense *) failed_command;
   2.391 +
   2.392 +    /* stuff the sense request in front of our current request */
   2.393 +    rq = &info->request_sense_request;
   2.394 +    ide_init_drive_cmd(rq);
   2.395 +    rq->cmd = REQUEST_SENSE_COMMAND;
   2.396 +    rq->buffer = (char *) pc;
   2.397 +    rq->waiting = wait;
   2.398 +
   2.399 +    (void) ide_do_drive_cmd(drive, rq, ide_preempt);
   2.400  }
   2.401  
   2.402  
   2.403  static void cdrom_end_request (int uptodate, ide_drive_t *drive)
   2.404  {
   2.405 -	struct request *rq = HWGROUP(drive)->rq;
   2.406 -
   2.407 -	if (rq->cmd == REQUEST_SENSE_COMMAND && uptodate) {
   2.408 -		struct packet_command *pc = (struct packet_command *) rq->buffer;
   2.409 -		cdrom_analyze_sense_data(drive,
   2.410 -			(struct packet_command *) pc->sense,
   2.411 -			(struct request_sense *) (pc->buffer - pc->c[4]));
   2.412 -	}
   2.413 -	if (rq->cmd == READ || rq->cmd == WRITE)
   2.414 -		if (!rq->current_nr_sectors)
   2.415 -			uptodate = 1;
   2.416 -
   2.417 -	ide_end_request (uptodate, HWGROUP(drive));
   2.418 +    struct request *rq = HWGROUP(drive)->rq;
   2.419 +
   2.420 +    if (rq->cmd == REQUEST_SENSE_COMMAND && uptodate) {
   2.421 +	struct packet_command *pc = (struct packet_command *) rq->buffer;
   2.422 +	cdrom_analyze_sense_data(drive,
   2.423 +				 (struct packet_command *) pc->sense,
   2.424 +				 (struct request_sense *) (pc->buffer - pc->c[4]));
   2.425 +    }
   2.426 +    if (rq->cmd == READ || rq->cmd == WRITE)
   2.427 +	if (!rq->current_nr_sectors)
   2.428 +	    uptodate = 1;
   2.429 +
   2.430 +    ide_end_request (uptodate, HWGROUP(drive));
   2.431  }
   2.432  
   2.433  
   2.434 @@ -563,146 +564,146 @@ static void cdrom_end_request (int uptod
   2.435  static int cdrom_decode_status (ide_startstop_t *startstop, ide_drive_t *drive,
   2.436  				int good_stat, int *stat_ret)
   2.437  {
   2.438 -	struct request *rq = HWGROUP(drive)->rq;
   2.439 -	int stat, err, sense_key;
   2.440 -	struct packet_command *pc;
   2.441 +    struct request *rq = HWGROUP(drive)->rq;
   2.442 +    int stat, err, sense_key;
   2.443 +    struct packet_command *pc;
   2.444  	
   2.445 -	/* Check for errors. */
   2.446 -	stat = GET_STAT();
   2.447 -	*stat_ret = stat;
   2.448 -
   2.449 -	if (OK_STAT (stat, good_stat, BAD_R_STAT))
   2.450 -		return 0;
   2.451 -
   2.452 -	/* Get the IDE error register. */
   2.453 -	err = GET_ERR();
   2.454 -	sense_key = err >> 4;
   2.455 -
   2.456 -	if (rq == NULL) {
   2.457 -		printk("%s: missing rq in cdrom_decode_status\n", drive->name);
   2.458 -		*startstop = ide_stopped;
   2.459 -		return 1;
   2.460 -	}
   2.461 -
   2.462 -	if (rq->cmd == REQUEST_SENSE_COMMAND) {
   2.463 -		/* We got an error trying to get sense info
   2.464 -		   from the drive (probably while trying
   2.465 -		   to recover from a former error).  Just give up. */
   2.466 -
   2.467 -		pc = (struct packet_command *) rq->buffer;
   2.468 -		pc->stat = 1;
   2.469 -		cdrom_end_request (1, drive);
   2.470 -		*startstop = ide_error (drive, "request sense failure", stat);
   2.471 -		return 1;
   2.472 -
   2.473 -	} else if (rq->cmd == PACKET_COMMAND) {
   2.474 -		/* All other functions, except for READ. */
   2.475 -		struct completion *wait = NULL;
   2.476 -		pc = (struct packet_command *) rq->buffer;
   2.477 -
   2.478 -		/* Check for tray open. */
   2.479 -		if (sense_key == NOT_READY) {
   2.480 -			cdrom_saw_media_change (drive);
   2.481 -		} else if (sense_key == UNIT_ATTENTION) {
   2.482 -			/* Check for media change. */
   2.483 -			cdrom_saw_media_change (drive);
   2.484 -			/*printk("%s: media changed\n",drive->name);*/
   2.485 -			return 0;
   2.486 -		} else if (!pc->quiet) {
   2.487 -			/* Otherwise, print an error. */
   2.488 -			ide_dump_status(drive, "packet command error", stat);
   2.489 -		}
   2.490 -		
   2.491 -		/* Set the error flag and complete the request.
   2.492 -		   Then, if we have a CHECK CONDITION status,
   2.493 -		   queue a request sense command.  We must be careful,
   2.494 -		   though: we don't want the thread in
   2.495 -		   cdrom_queue_packet_command to wake up until
   2.496 -		   the request sense has completed.  We do this
   2.497 -		   by transferring the semaphore from the packet
   2.498 -		   command request to the request sense request. */
   2.499 -
   2.500 -		if ((stat & ERR_STAT) != 0) {
   2.501 -			// XXX SMH: if we get here we should retry ... hmmm
   2.502 -			printk("ide-cd: error (stat = 0x%x): will retry\n", stat); 
   2.503 -			wait = rq->waiting;
   2.504 -			rq->waiting = NULL;
   2.505 -		}
   2.506 -
   2.507 -		pc->stat = 1;
   2.508 -		cdrom_end_request (1, drive);
   2.509 -
   2.510 -		if ((stat & ERR_STAT) != 0)
   2.511 -			cdrom_queue_request_sense(drive, wait, pc->sense, pc);
   2.512 -	} else {
   2.513 -		/* Handle errors from READ and WRITE requests. */
   2.514 -
   2.515 -		if (sense_key == NOT_READY) {
   2.516 -			/* Tray open. */
   2.517 -			cdrom_saw_media_change (drive);
   2.518 -
   2.519 -			/* Fail the request. */
   2.520 -			printk ("%s: tray open\n", drive->name);
   2.521 -			cdrom_end_request (0, drive);
   2.522 -		} else if (sense_key == UNIT_ATTENTION) {
   2.523 -			/* Media change. */
   2.524 -			cdrom_saw_media_change (drive);
   2.525 -
   2.526 -			/* Arrange to retry the request.
   2.527 -			   But be sure to give up if we've retried
   2.528 -			   too many times. */
   2.529 -			if (++rq->errors > ERROR_MAX)
   2.530 -				cdrom_end_request (0, drive);
   2.531 -		} else if (sense_key == ILLEGAL_REQUEST ||
   2.532 -			   sense_key == DATA_PROTECT) {
   2.533 -			/* No point in retrying after an illegal
   2.534 -			   request or data protect error.*/
   2.535 -			ide_dump_status (drive, "command error", stat);
   2.536 -			cdrom_end_request (0, drive);
   2.537 -		} else if ((err & ~ABRT_ERR) != 0) {
   2.538 -			/* Go to the default handler
   2.539 -			   for other errors. */
   2.540 -			*startstop = ide_error (drive, "cdrom_decode_status", stat);
   2.541 -			return 1;
   2.542 -		} else if ((++rq->errors > ERROR_MAX)) {
   2.543 -			/* We've racked up too many retries.  Abort. */
   2.544 -			cdrom_end_request (0, drive);
   2.545 -		}
   2.546 -
   2.547 -		/* If we got a CHECK_CONDITION status,
   2.548 -		   queue a request sense command. */
   2.549 -		if ((stat & ERR_STAT) != 0)
   2.550 -			cdrom_queue_request_sense(drive, NULL, NULL, NULL);
   2.551 -	}
   2.552 -
   2.553 -	/* Retry, or handle the next request. */
   2.554 +    /* Check for errors. */
   2.555 +    stat = GET_STAT();
   2.556 +    *stat_ret = stat;
   2.557 +
   2.558 +    if (OK_STAT (stat, good_stat, BAD_R_STAT))
   2.559 +	return 0;
   2.560 +
   2.561 +    /* Get the IDE error register. */
   2.562 +    err = GET_ERR();
   2.563 +    sense_key = err >> 4;
   2.564 +
   2.565 +    if (rq == NULL) {
   2.566 +	printk("%s: missing rq in cdrom_decode_status\n", drive->name);
   2.567  	*startstop = ide_stopped;
   2.568  	return 1;
   2.569 +    }
   2.570 +
   2.571 +    if (rq->cmd == REQUEST_SENSE_COMMAND) {
   2.572 +	/* We got an error trying to get sense info
   2.573 +	   from the drive (probably while trying
   2.574 +	   to recover from a former error).  Just give up. */
   2.575 +
   2.576 +	pc = (struct packet_command *) rq->buffer;
   2.577 +	pc->stat = 1;
   2.578 +	cdrom_end_request (1, drive);
   2.579 +	*startstop = ide_error (drive, "request sense failure", stat);
   2.580 +	return 1;
   2.581 +
   2.582 +    } else if (rq->cmd == PACKET_COMMAND) {
   2.583 +	/* All other functions, except for READ. */
   2.584 +	struct completion *wait = NULL;
   2.585 +	pc = (struct packet_command *) rq->buffer;
   2.586 +
   2.587 +	/* Check for tray open. */
   2.588 +	if (sense_key == NOT_READY) {
   2.589 +	    cdrom_saw_media_change (drive);
   2.590 +	} else if (sense_key == UNIT_ATTENTION) {
   2.591 +	    /* Check for media change. */
   2.592 +	    cdrom_saw_media_change (drive);
   2.593 +	    /*printk("%s: media changed\n",drive->name);*/
   2.594 +	    return 0;
   2.595 +	} else if (!pc->quiet) {
   2.596 +	    /* Otherwise, print an error. */
   2.597 +	    ide_dump_status(drive, "packet command error", stat);
   2.598 +	}
   2.599 +		
   2.600 +	/* Set the error flag and complete the request.
   2.601 +	   Then, if we have a CHECK CONDITION status,
   2.602 +	   queue a request sense command.  We must be careful,
   2.603 +	   though: we don't want the thread in
   2.604 +	   cdrom_queue_packet_command to wake up until
   2.605 +	   the request sense has completed.  We do this
   2.606 +	   by transferring the semaphore from the packet
   2.607 +	   command request to the request sense request. */
   2.608 +
   2.609 +	if ((stat & ERR_STAT) != 0) {
   2.610 +	    // XXX SMH: if we get here we should retry ... hmmm
   2.611 +//	    printk("ide-cd: error (stat = 0x%x): will retry\n", stat); 
   2.612 +	    wait = rq->waiting;
   2.613 +	    rq->waiting = NULL;
   2.614 +	}
   2.615 +
   2.616 +	pc->stat = 1;
   2.617 +	cdrom_end_request (1, drive);
   2.618 +
   2.619 +	if ((stat & ERR_STAT) != 0)
   2.620 +	    cdrom_queue_request_sense(drive, wait, pc->sense, pc);
   2.621 +    } else {
   2.622 +	/* Handle errors from READ and WRITE requests. */
   2.623 +
   2.624 +	if (sense_key == NOT_READY) {
   2.625 +	    /* Tray open. */
   2.626 +	    cdrom_saw_media_change (drive);
   2.627 +
   2.628 +	    /* Fail the request. */
   2.629 +	    printk ("%s: tray open\n", drive->name);
   2.630 +	    cdrom_end_request (0, drive);
   2.631 +	} else if (sense_key == UNIT_ATTENTION) {
   2.632 +	    /* Media change. */
   2.633 +	    cdrom_saw_media_change (drive);
   2.634 +
   2.635 +	    /* Arrange to retry the request.
   2.636 +	       But be sure to give up if we've retried
   2.637 +	       too many times. */
   2.638 +	    if (++rq->errors > ERROR_MAX)
   2.639 +		cdrom_end_request (0, drive);
   2.640 +	} else if (sense_key == ILLEGAL_REQUEST ||
   2.641 +		   sense_key == DATA_PROTECT) {
   2.642 +	    /* No point in retrying after an illegal
   2.643 +	       request or data protect error.*/
   2.644 +	    ide_dump_status (drive, "command error", stat);
   2.645 +	    cdrom_end_request (0, drive);
   2.646 +	} else if ((err & ~ABRT_ERR) != 0) {
   2.647 +	    /* Go to the default handler
   2.648 +	       for other errors. */
   2.649 +	    *startstop = ide_error (drive, "cdrom_decode_status", stat);
   2.650 +	    return 1;
   2.651 +	} else if ((++rq->errors > ERROR_MAX)) {
   2.652 +	    /* We've racked up too many retries.  Abort. */
   2.653 +	    cdrom_end_request (0, drive);
   2.654 +	}
   2.655 +
   2.656 +	/* If we got a CHECK_CONDITION status,
   2.657 +	   queue a request sense command. */
   2.658 +	if ((stat & ERR_STAT) != 0)
   2.659 +	    cdrom_queue_request_sense(drive, NULL, NULL, NULL);
   2.660 +    }
   2.661 +
   2.662 +    /* Retry, or handle the next request. */
   2.663 +    *startstop = ide_stopped;
   2.664 +    return 1;
   2.665  }
   2.666  
   2.667  static int cdrom_timer_expiry(ide_drive_t *drive)
   2.668  {
   2.669 -	struct request *rq = HWGROUP(drive)->rq;
   2.670 -	struct packet_command *pc = (struct packet_command *) rq->buffer;
   2.671 -	unsigned long wait = 0;
   2.672 -
   2.673 -	/*
   2.674 -	 * Some commands are *slow* and normally take a long time to
   2.675 -	 * complete. Usually we can use the ATAPI "disconnect" to bypass
   2.676 -	 * this, but not all commands/drives support that. Let
   2.677 -	 * ide_timer_expiry keep polling us for these.
   2.678 -	 */
   2.679 -	switch (pc->c[0]) {
   2.680 -		case GPCMD_BLANK:
   2.681 -		case GPCMD_FORMAT_UNIT:
   2.682 -		case GPCMD_RESERVE_RZONE_TRACK:
   2.683 -			wait = WAIT_CMD;
   2.684 -			break;
   2.685 -		default:
   2.686 -			wait = 0;
   2.687 -			break;
   2.688 -	}
   2.689 -	return wait;
   2.690 +    struct request *rq = HWGROUP(drive)->rq;
   2.691 +    struct packet_command *pc = (struct packet_command *) rq->buffer;
   2.692 +    unsigned long wait = 0;
   2.693 +
   2.694 +    /*
   2.695 +     * Some commands are *slow* and normally take a long time to
   2.696 +     * complete. Usually we can use the ATAPI "disconnect" to bypass
   2.697 +     * this, but not all commands/drives support that. Let
   2.698 +     * ide_timer_expiry keep polling us for these.
   2.699 +     */
   2.700 +    switch (pc->c[0]) {
   2.701 +    case GPCMD_BLANK:
   2.702 +    case GPCMD_FORMAT_UNIT:
   2.703 +    case GPCMD_RESERVE_RZONE_TRACK:
   2.704 +	wait = WAIT_CMD;
   2.705 +	break;
   2.706 +    default:
   2.707 +	wait = 0;
   2.708 +	break;
   2.709 +    }
   2.710 +    return wait;
   2.711  }
   2.712  
   2.713  /* Set up the device registers for transferring a packet command on DEV,
   2.714 @@ -716,44 +717,44 @@ static ide_startstop_t cdrom_start_packe
   2.715  						  int xferlen,
   2.716  						  ide_handler_t *handler)
   2.717  {
   2.718 -	ide_startstop_t startstop;
   2.719 -	struct cdrom_info *info = drive->driver_data;
   2.720 -
   2.721 -	/* Wait for the controller to be idle. */
   2.722 -	if (ide_wait_stat(&startstop, drive, 0, BUSY_STAT, WAIT_READY))
   2.723 -		return startstop;
   2.724 -
   2.725 -	if (info->dma) {
   2.726 -		if (info->cmd == READ) {
   2.727 -			info->dma = !HWIF(drive)->dmaproc(ide_dma_read, drive);
   2.728 -		} else if (info->cmd == WRITE) {
   2.729 -			info->dma = !HWIF(drive)->dmaproc(ide_dma_write, drive);
   2.730 -		} else {
   2.731 -			printk("ide-cd: DMA set, but not allowed\n");
   2.732 -		}
   2.733 +    ide_startstop_t startstop;
   2.734 +    struct cdrom_info *info = drive->driver_data;
   2.735 +
   2.736 +    /* Wait for the controller to be idle. */
   2.737 +    if (ide_wait_stat(&startstop, drive, 0, BUSY_STAT, WAIT_READY))
   2.738 +	return startstop;
   2.739 +
   2.740 +    if (info->dma) {
   2.741 +	if (info->cmd == READ) {
   2.742 +	    info->dma = !HWIF(drive)->dmaproc(ide_dma_read, drive);
   2.743 +	} else if (info->cmd == WRITE) {
   2.744 +	    info->dma = !HWIF(drive)->dmaproc(ide_dma_write, drive);
   2.745 +	} else {
   2.746 +	    printk("ide-cd: DMA set, but not allowed\n");
   2.747  	}
   2.748 -
   2.749 -	/* Set up the controller registers. */
   2.750 -	OUT_BYTE (info->dma, IDE_FEATURE_REG);
   2.751 -	OUT_BYTE (0, IDE_NSECTOR_REG);
   2.752 -	OUT_BYTE (0, IDE_SECTOR_REG);
   2.753 -
   2.754 -	OUT_BYTE (xferlen & 0xff, IDE_LCYL_REG);
   2.755 -	OUT_BYTE (xferlen >> 8  , IDE_HCYL_REG);
   2.756 -	if (IDE_CONTROL_REG)
   2.757 -		OUT_BYTE (drive->ctl, IDE_CONTROL_REG);
   2.758 +    }
   2.759 +
   2.760 +    /* Set up the controller registers. */
   2.761 +    OUT_BYTE (info->dma, IDE_FEATURE_REG);
   2.762 +    OUT_BYTE (0, IDE_NSECTOR_REG);
   2.763 +    OUT_BYTE (0, IDE_SECTOR_REG);
   2.764 +
   2.765 +    OUT_BYTE (xferlen & 0xff, IDE_LCYL_REG);
   2.766 +    OUT_BYTE (xferlen >> 8  , IDE_HCYL_REG);
   2.767 +    if (IDE_CONTROL_REG)
   2.768 +	OUT_BYTE (drive->ctl, IDE_CONTROL_REG);
   2.769   
   2.770 -	if (info->dma)
   2.771 -		(void) (HWIF(drive)->dmaproc(ide_dma_begin, drive));
   2.772 -
   2.773 -	if (CDROM_CONFIG_FLAGS (drive)->drq_interrupt) {
   2.774 -		ide_set_handler (drive, handler, WAIT_CMD, cdrom_timer_expiry);
   2.775 -		OUT_BYTE (WIN_PACKETCMD, IDE_COMMAND_REG); /* packet command */
   2.776 -		return ide_started;
   2.777 -	} else {
   2.778 -		OUT_BYTE (WIN_PACKETCMD, IDE_COMMAND_REG); /* packet command */
   2.779 -		return (*handler) (drive);
   2.780 -	}
   2.781 +    if (info->dma)
   2.782 +	(void) (HWIF(drive)->dmaproc(ide_dma_begin, drive));
   2.783 +
   2.784 +    if (CDROM_CONFIG_FLAGS (drive)->drq_interrupt) {
   2.785 +	ide_set_handler (drive, handler, WAIT_CMD, cdrom_timer_expiry);
   2.786 +	OUT_BYTE (WIN_PACKETCMD, IDE_COMMAND_REG); /* packet command */
   2.787 +	return ide_started;
   2.788 +    } else {
   2.789 +	OUT_BYTE (WIN_PACKETCMD, IDE_COMMAND_REG); /* packet command */
   2.790 +	return (*handler) (drive);
   2.791 +    }
   2.792  }
   2.793  
   2.794  /* Send a packet command to DRIVE described by CMD_BUF and CMD_LEN.
   2.795 @@ -766,34 +767,34 @@ static ide_startstop_t cdrom_start_packe
   2.796   * struct packet_command *pc; now packet_command_t *pc;
   2.797   */
   2.798  static ide_startstop_t cdrom_transfer_packet_command (ide_drive_t *drive,
   2.799 -					  struct packet_command *pc,
   2.800 -					  ide_handler_t *handler)
   2.801 +						      struct packet_command *pc,
   2.802 +						      ide_handler_t *handler)
   2.803  {
   2.804 -	unsigned char *cmd_buf	= pc->c;
   2.805 -	int cmd_len		= sizeof(pc->c);
   2.806 -	unsigned int timeout	= pc->timeout;
   2.807 -	ide_startstop_t startstop;
   2.808 -
   2.809 -	if (CDROM_CONFIG_FLAGS (drive)->drq_interrupt) {
   2.810 -		/* Here we should have been called after receiving an interrupt
   2.811 -		   from the device.  DRQ should how be set. */
   2.812 -		int stat_dum;
   2.813 -
   2.814 -		/* Check for errors. */
   2.815 -		if (cdrom_decode_status (&startstop, drive, DRQ_STAT, &stat_dum))
   2.816 -			return startstop;
   2.817 -	} else {
   2.818 -		/* Otherwise, we must wait for DRQ to get set. */
   2.819 -		if (ide_wait_stat (&startstop, drive, DRQ_STAT, BUSY_STAT, WAIT_READY))
   2.820 -			return startstop;
   2.821 -	}
   2.822 -
   2.823 -	/* Arm the interrupt handler. */
   2.824 -	ide_set_handler (drive, handler, timeout, cdrom_timer_expiry);
   2.825 -
   2.826 -	/* Send the command to the device. */
   2.827 -	atapi_output_bytes (drive, cmd_buf, cmd_len);
   2.828 -	return ide_started;
   2.829 +    unsigned char *cmd_buf	= pc->c;
   2.830 +    int cmd_len		= sizeof(pc->c);
   2.831 +    unsigned int timeout	= pc->timeout;
   2.832 +    ide_startstop_t startstop;
   2.833 +
   2.834 +    if (CDROM_CONFIG_FLAGS (drive)->drq_interrupt) {
   2.835 +	/* Here we should have been called after receiving an interrupt
   2.836 +	   from the device.  DRQ should how be set. */
   2.837 +	int stat_dum;
   2.838 +
   2.839 +	/* Check for errors. */
   2.840 +	if (cdrom_decode_status (&startstop, drive, DRQ_STAT, &stat_dum))
   2.841 +	    return startstop;
   2.842 +    } else {
   2.843 +	/* Otherwise, we must wait for DRQ to get set. */
   2.844 +	if (ide_wait_stat (&startstop, drive, DRQ_STAT, BUSY_STAT, WAIT_READY))
   2.845 +	    return startstop;
   2.846 +    }
   2.847 +
   2.848 +    /* Arm the interrupt handler. */
   2.849 +    ide_set_handler (drive, handler, timeout, cdrom_timer_expiry);
   2.850 +
   2.851 +    /* Send the command to the device. */
   2.852 +    atapi_output_bytes (drive, cmd_buf, cmd_len);
   2.853 +    return ide_started;
   2.854  }
   2.855  
   2.856  /****************************************************************************
   2.857 @@ -810,39 +811,39 @@ static ide_startstop_t cdrom_transfer_pa
   2.858  static void cdrom_buffer_sectors (ide_drive_t *drive, unsigned long sector,
   2.859                                    int sectors_to_transfer)
   2.860  {
   2.861 -	struct cdrom_info *info = drive->driver_data;
   2.862 -
   2.863 -	/* Number of sectors to read into the buffer. */
   2.864 -	int sectors_to_buffer = MIN (sectors_to_transfer,
   2.865 -				     (SECTOR_BUFFER_SIZE >> SECTOR_BITS) -
   2.866 -				       info->nsectors_buffered);
   2.867 -
   2.868 -	char *dest;
   2.869 -
   2.870 -	/* If we couldn't get a buffer, don't try to buffer anything... */
   2.871 -	if (info->buffer == NULL)
   2.872 -		sectors_to_buffer = 0;
   2.873 -
   2.874 -	/* If this is the first sector in the buffer, remember its number. */
   2.875 -	if (info->nsectors_buffered == 0)
   2.876 -		info->sector_buffered = sector;
   2.877 -
   2.878 -	/* Read the data into the buffer. */
   2.879 -	dest = info->buffer + info->nsectors_buffered * SECTOR_SIZE;
   2.880 -	while (sectors_to_buffer > 0) {
   2.881 -		atapi_input_bytes (drive, dest, SECTOR_SIZE);
   2.882 -		--sectors_to_buffer;
   2.883 -		--sectors_to_transfer;
   2.884 -		++info->nsectors_buffered;
   2.885 -		dest += SECTOR_SIZE;
   2.886 -	}
   2.887 -
   2.888 -	/* Throw away any remaining data. */
   2.889 -	while (sectors_to_transfer > 0) {
   2.890 -		char dum[SECTOR_SIZE];
   2.891 -		atapi_input_bytes (drive, dum, sizeof (dum));
   2.892 -		--sectors_to_transfer;
   2.893 -	}
   2.894 +    struct cdrom_info *info = drive->driver_data;
   2.895 +
   2.896 +    /* Number of sectors to read into the buffer. */
   2.897 +    int sectors_to_buffer = MIN (sectors_to_transfer,
   2.898 +				 (SECTOR_BUFFER_SIZE >> SECTOR_BITS) -
   2.899 +				 info->nsectors_buffered);
   2.900 +
   2.901 +    char *dest;
   2.902 +
   2.903 +    /* If we couldn't get a buffer, don't try to buffer anything... */
   2.904 +    if (info->buffer == NULL)
   2.905 +	sectors_to_buffer = 0;
   2.906 +
   2.907 +    /* If this is the first sector in the buffer, remember its number. */
   2.908 +    if (info->nsectors_buffered == 0)
   2.909 +	info->sector_buffered = sector;
   2.910 +
   2.911 +    /* Read the data into the buffer. */
   2.912 +    dest = info->buffer + info->nsectors_buffered * SECTOR_SIZE;
   2.913 +    while (sectors_to_buffer > 0) {
   2.914 +	atapi_input_bytes (drive, dest, SECTOR_SIZE);
   2.915 +	--sectors_to_buffer;
   2.916 +	--sectors_to_transfer;
   2.917 +	++info->nsectors_buffered;
   2.918 +	dest += SECTOR_SIZE;
   2.919 +    }
   2.920 +
   2.921 +    /* Throw away any remaining data. */
   2.922 +    while (sectors_to_transfer > 0) {
   2.923 +	char dum[SECTOR_SIZE];
   2.924 +	atapi_input_bytes (drive, dum, sizeof (dum));
   2.925 +	--sectors_to_transfer;
   2.926 +    }
   2.927  }
   2.928  
   2.929  /*
   2.930 @@ -853,36 +854,36 @@ static void cdrom_buffer_sectors (ide_dr
   2.931  static inline
   2.932  int cdrom_read_check_ireason (ide_drive_t *drive, int len, int ireason)
   2.933  {
   2.934 -	ireason &= 3;
   2.935 -	if (ireason == 2) return 0;
   2.936 -
   2.937 -	if (ireason == 0) {
   2.938 -		/* Whoops... The drive is expecting to receive data from us! */
   2.939 -		printk ("%s: cdrom_read_intr: "
   2.940 -			"Drive wants to transfer data the wrong way!\n",
   2.941 -			drive->name);
   2.942 -
   2.943 -		/* Throw some data at the drive so it doesn't hang
   2.944 -		   and quit this request. */
   2.945 -		while (len > 0) {
   2.946 -			int dum = 0;
   2.947 -			atapi_output_bytes (drive, &dum, sizeof (dum));
   2.948 -			len -= sizeof (dum);
   2.949 -		}
   2.950 -	} else  if (ireason == 1) {
   2.951 -		/* Some drives (ASUS) seem to tell us that status
   2.952 -		 * info is available. just get it and ignore.
   2.953 -		 */
   2.954 -		GET_STAT();
   2.955 -		return 0;
   2.956 -	} else {
   2.957 -		/* Drive wants a command packet, or invalid ireason... */
   2.958 -		printk ("%s: cdrom_read_intr: bad interrupt reason %d\n",
   2.959 -			drive->name, ireason);
   2.960 +    ireason &= 3;
   2.961 +    if (ireason == 2) return 0;
   2.962 +
   2.963 +    if (ireason == 0) {
   2.964 +	/* Whoops... The drive is expecting to receive data from us! */
   2.965 +	printk ("%s: cdrom_read_intr: "
   2.966 +		"Drive wants to transfer data the wrong way!\n",
   2.967 +		drive->name);
   2.968 +
   2.969 +	/* Throw some data at the drive so it doesn't hang
   2.970 +	   and quit this request. */
   2.971 +	while (len > 0) {
   2.972 +	    int dum = 0;
   2.973 +	    atapi_output_bytes (drive, &dum, sizeof (dum));
   2.974 +	    len -= sizeof (dum);
   2.975  	}
   2.976 -
   2.977 -	cdrom_end_request (0, drive);
   2.978 -	return -1;
   2.979 +    } else  if (ireason == 1) {
   2.980 +	/* Some drives (ASUS) seem to tell us that status
   2.981 +	 * info is available. just get it and ignore.
   2.982 +	 */
   2.983 +	GET_STAT();
   2.984 +	return 0;
   2.985 +    } else {
   2.986 +	/* Drive wants a command packet, or invalid ireason... */
   2.987 +	printk ("%s: cdrom_read_intr: bad interrupt reason %d\n",
   2.988 +		drive->name, ireason);
   2.989 +    }
   2.990 +
   2.991 +    cdrom_end_request (0, drive);
   2.992 +    return -1;
   2.993  }
   2.994  
   2.995  /*
   2.996 @@ -890,129 +891,129 @@ int cdrom_read_check_ireason (ide_drive_
   2.997   */
   2.998  static ide_startstop_t cdrom_read_intr (ide_drive_t *drive)
   2.999  {
  2.1000 -	int stat;
  2.1001 -	int ireason, len, sectors_to_transfer, nskip;
  2.1002 -	struct cdrom_info *info = drive->driver_data;
  2.1003 -	int i, dma = info->dma, dma_error = 0;
  2.1004 -	ide_startstop_t startstop;
  2.1005 -
  2.1006 -	struct request *rq = HWGROUP(drive)->rq;
  2.1007 -
  2.1008 -	/* Check for errors. */
  2.1009 -	if (dma) {
  2.1010 -		info->dma = 0;
  2.1011 -		if ((dma_error = HWIF(drive)->dmaproc(ide_dma_end, drive)))
  2.1012 -			HWIF(drive)->dmaproc(ide_dma_off, drive);
  2.1013 -	}
  2.1014 -
  2.1015 -	if (cdrom_decode_status (&startstop, drive, 0, &stat))
  2.1016 -		return startstop;
  2.1017 +    int stat;
  2.1018 +    int ireason, len, sectors_to_transfer, nskip;
  2.1019 +    struct cdrom_info *info = drive->driver_data;
  2.1020 +    int i, dma = info->dma, dma_error = 0;
  2.1021 +    ide_startstop_t startstop;
  2.1022 +
  2.1023 +    struct request *rq = HWGROUP(drive)->rq;
  2.1024 +
  2.1025 +    /* Check for errors. */
  2.1026 +    if (dma) {
  2.1027 +	info->dma = 0;
  2.1028 +	if ((dma_error = HWIF(drive)->dmaproc(ide_dma_end, drive)))
  2.1029 +	    HWIF(drive)->dmaproc(ide_dma_off, drive);
  2.1030 +    }
  2.1031 +
  2.1032 +    if (cdrom_decode_status (&startstop, drive, 0, &stat))
  2.1033 +	return startstop;
  2.1034   
  2.1035 -	if (dma) {
  2.1036 -		if (!dma_error) {
  2.1037 -			for (i = rq->nr_sectors; i > 0;) {
  2.1038 -				i -= rq->current_nr_sectors;
  2.1039 -				ide_end_request(1, HWGROUP(drive));
  2.1040 -			}
  2.1041 -			return ide_stopped;
  2.1042 -		} else
  2.1043 -			return ide_error (drive, "dma error", stat);
  2.1044 -	}
  2.1045 -
  2.1046 -	/* Read the interrupt reason and the transfer length. */
  2.1047 -	ireason = IN_BYTE (IDE_NSECTOR_REG);
  2.1048 -	len = IN_BYTE (IDE_LCYL_REG) + 256 * IN_BYTE (IDE_HCYL_REG);
  2.1049 -
  2.1050 -	/* If DRQ is clear, the command has completed. */
  2.1051 -	if ((stat & DRQ_STAT) == 0) {
  2.1052 -		/* If we're not done filling the current buffer, complain.
  2.1053 -		   Otherwise, complete the command normally. */
  2.1054 -		if (rq->current_nr_sectors > 0) {
  2.1055 -			printk ("%s: cdrom_read_intr: data underrun (%ld blocks)\n",
  2.1056 -				drive->name, rq->current_nr_sectors);
  2.1057 -			cdrom_end_request (0, drive);
  2.1058 -		} else
  2.1059 -			cdrom_end_request (1, drive);
  2.1060 -		return ide_stopped;
  2.1061 +    if (dma) {
  2.1062 +	if (!dma_error) {
  2.1063 +	    for (i = rq->nr_sectors; i > 0;) {
  2.1064 +		i -= rq->current_nr_sectors;
  2.1065 +		ide_end_request(1, HWGROUP(drive));
  2.1066 +	    }
  2.1067 +	    return ide_stopped;
  2.1068 +	} else
  2.1069 +	    return ide_error (drive, "dma error", stat);
  2.1070 +    }
  2.1071 +
  2.1072 +    /* Read the interrupt reason and the transfer length. */
  2.1073 +    ireason = IN_BYTE (IDE_NSECTOR_REG);
  2.1074 +    len = IN_BYTE (IDE_LCYL_REG) + 256 * IN_BYTE (IDE_HCYL_REG);
  2.1075 +
  2.1076 +    /* If DRQ is clear, the command has completed. */
  2.1077 +    if ((stat & DRQ_STAT) == 0) {
  2.1078 +	/* If we're not done filling the current buffer, complain.
  2.1079 +	   Otherwise, complete the command normally. */
  2.1080 +	if (rq->current_nr_sectors > 0) {
  2.1081 +	    printk ("%s: cdrom_read_intr: data underrun (%ld blocks)\n",
  2.1082 +		    drive->name, rq->current_nr_sectors);
  2.1083 +	    cdrom_end_request (0, drive);
  2.1084 +	} else
  2.1085 +	    cdrom_end_request (1, drive);
  2.1086 +	return ide_stopped;
  2.1087 +    }
  2.1088 +
  2.1089 +    /* Check that the drive is expecting to do the same thing we are. */
  2.1090 +    if (cdrom_read_check_ireason (drive, len, ireason))
  2.1091 +	return ide_stopped;
  2.1092 +
  2.1093 +    /* Assume that the drive will always provide data in multiples
  2.1094 +       of at least SECTOR_SIZE, as it gets hairy to keep track
  2.1095 +       of the transfers otherwise. */
  2.1096 +    if ((len % SECTOR_SIZE) != 0) {
  2.1097 +	printk ("%s: cdrom_read_intr: Bad transfer size %d\n",
  2.1098 +		drive->name, len);
  2.1099 +	if (CDROM_CONFIG_FLAGS (drive)->limit_nframes)
  2.1100 +	    printk ("  This drive is not supported by this version of the driver\n");
  2.1101 +	else {
  2.1102 +	    printk ("  Trying to limit transfer sizes\n");
  2.1103 +	    CDROM_CONFIG_FLAGS (drive)->limit_nframes = 1;
  2.1104  	}
  2.1105 -
  2.1106 -	/* Check that the drive is expecting to do the same thing we are. */
  2.1107 -	if (cdrom_read_check_ireason (drive, len, ireason))
  2.1108 -		return ide_stopped;
  2.1109 -
  2.1110 -	/* Assume that the drive will always provide data in multiples
  2.1111 -	   of at least SECTOR_SIZE, as it gets hairy to keep track
  2.1112 -	   of the transfers otherwise. */
  2.1113 -	if ((len % SECTOR_SIZE) != 0) {
  2.1114 -		printk ("%s: cdrom_read_intr: Bad transfer size %d\n",
  2.1115 -			drive->name, len);
  2.1116 -		if (CDROM_CONFIG_FLAGS (drive)->limit_nframes)
  2.1117 -			printk ("  This drive is not supported by this version of the driver\n");
  2.1118 -		else {
  2.1119 -			printk ("  Trying to limit transfer sizes\n");
  2.1120 -			CDROM_CONFIG_FLAGS (drive)->limit_nframes = 1;
  2.1121 -		}
  2.1122 -		cdrom_end_request (0, drive);
  2.1123 -		return ide_stopped;
  2.1124 -	}
  2.1125 -
  2.1126 -	/* The number of sectors we need to read from the drive. */
  2.1127 -	sectors_to_transfer = len / SECTOR_SIZE;
  2.1128 -
  2.1129 -	/* First, figure out if we need to bit-bucket
  2.1130 -	   any of the leading sectors. */
  2.1131 -	nskip = MIN ((int)(rq->current_nr_sectors - (rq->bh->b_size >> SECTOR_BITS)),
  2.1132 -		     sectors_to_transfer);
  2.1133 -
  2.1134 -	while (nskip > 0) {
  2.1135 -		/* We need to throw away a sector. */
  2.1136 -		char dum[SECTOR_SIZE];
  2.1137 -		atapi_input_bytes (drive, dum, sizeof (dum));
  2.1138 -
  2.1139 +	cdrom_end_request (0, drive);
  2.1140 +	return ide_stopped;
  2.1141 +    }
  2.1142 +
  2.1143 +    /* The number of sectors we need to read from the drive. */
  2.1144 +    sectors_to_transfer = len / SECTOR_SIZE;
  2.1145 +
  2.1146 +    /* First, figure out if we need to bit-bucket
  2.1147 +       any of the leading sectors. */
  2.1148 +    nskip = MIN ((int)(rq->current_nr_sectors - (rq->bh->b_size >> SECTOR_BITS)),
  2.1149 +		 sectors_to_transfer);
  2.1150 +
  2.1151 +    while (nskip > 0) {
  2.1152 +	/* We need to throw away a sector. */
  2.1153 +	char dum[SECTOR_SIZE];
  2.1154 +	atapi_input_bytes (drive, dum, sizeof (dum));
  2.1155 +
  2.1156 +	--rq->current_nr_sectors;
  2.1157 +	--nskip;
  2.1158 +	--sectors_to_transfer;
  2.1159 +    }
  2.1160 +
  2.1161 +    /* Now loop while we still have data to read from the drive. */
  2.1162 +    while (sectors_to_transfer > 0) {
  2.1163 +	int this_transfer;
  2.1164 +
  2.1165 +	/* If we've filled the present buffer but there's another
  2.1166 +	   chained buffer after it, move on. */
  2.1167 +	if (rq->current_nr_sectors == 0 && rq->nr_sectors)
  2.1168 +	    cdrom_end_request (1, drive);
  2.1169 +
  2.1170 +	/* If the buffers are full, cache the rest of the data in our
  2.1171 +	   internal buffer. */
  2.1172 +	if (rq->current_nr_sectors == 0) {
  2.1173 +	    cdrom_buffer_sectors(drive, rq->sector, sectors_to_transfer);
  2.1174 +	    sectors_to_transfer = 0;
  2.1175 +	} else {
  2.1176 +	    /* Transfer data to the buffers.
  2.1177 +	       Figure out how many sectors we can transfer
  2.1178 +	       to the current buffer. */
  2.1179 +	    this_transfer = MIN (sectors_to_transfer,
  2.1180 +				 rq->current_nr_sectors);
  2.1181 +
  2.1182 +	    /* Read this_transfer sectors
  2.1183 +	       into the current buffer. */
  2.1184 +	    while (this_transfer > 0) {
  2.1185 +		atapi_input_bytes(drive, rq->buffer, SECTOR_SIZE);
  2.1186 +		rq->buffer += SECTOR_SIZE;
  2.1187 +		--rq->nr_sectors;
  2.1188  		--rq->current_nr_sectors;
  2.1189 -		--nskip;
  2.1190 +		++rq->sector;
  2.1191 +		--this_transfer;
  2.1192  		--sectors_to_transfer;
  2.1193 +	    }
  2.1194  	}
  2.1195 -
  2.1196 -	/* Now loop while we still have data to read from the drive. */
  2.1197 -	while (sectors_to_transfer > 0) {
  2.1198 -		int this_transfer;
  2.1199 -
  2.1200 -		/* If we've filled the present buffer but there's another
  2.1201 -		   chained buffer after it, move on. */
  2.1202 -		if (rq->current_nr_sectors == 0 && rq->nr_sectors)
  2.1203 -			cdrom_end_request (1, drive);
  2.1204 -
  2.1205 -		/* If the buffers are full, cache the rest of the data in our
  2.1206 -		   internal buffer. */
  2.1207 -		if (rq->current_nr_sectors == 0) {
  2.1208 -			cdrom_buffer_sectors(drive, rq->sector, sectors_to_transfer);
  2.1209 -			sectors_to_transfer = 0;
  2.1210 -		} else {
  2.1211 -			/* Transfer data to the buffers.
  2.1212 -			   Figure out how many sectors we can transfer
  2.1213 -			   to the current buffer. */
  2.1214 -			this_transfer = MIN (sectors_to_transfer,
  2.1215 -					     rq->current_nr_sectors);
  2.1216 -
  2.1217 -			/* Read this_transfer sectors
  2.1218 -			   into the current buffer. */
  2.1219 -			while (this_transfer > 0) {
  2.1220 -				atapi_input_bytes(drive, rq->buffer, SECTOR_SIZE);
  2.1221 -				rq->buffer += SECTOR_SIZE;
  2.1222 -				--rq->nr_sectors;
  2.1223 -				--rq->current_nr_sectors;
  2.1224 -				++rq->sector;
  2.1225 -				--this_transfer;
  2.1226 -				--sectors_to_transfer;
  2.1227 -			}
  2.1228 -		}
  2.1229 -	}
  2.1230 -
  2.1231 -	/* Done moving data!
  2.1232 -	   Wait for another interrupt. */
  2.1233 -	ide_set_handler(drive, &cdrom_read_intr, WAIT_CMD, NULL);
  2.1234 -	return ide_started;
  2.1235 +    }
  2.1236 +
  2.1237 +    /* Done moving data!
  2.1238 +       Wait for another interrupt. */
  2.1239 +    ide_set_handler(drive, &cdrom_read_intr, WAIT_CMD, NULL);
  2.1240 +    return ide_started;
  2.1241  }
  2.1242  
  2.1243  /*
  2.1244 @@ -1021,54 +1022,54 @@ static ide_startstop_t cdrom_read_intr (
  2.1245   */
  2.1246  static int cdrom_read_from_buffer (ide_drive_t *drive)
  2.1247  {
  2.1248 -	struct cdrom_info *info = drive->driver_data;
  2.1249 -	struct request *rq = HWGROUP(drive)->rq;
  2.1250 -
  2.1251 -	/* Can't do anything if there's no buffer. */
  2.1252 -	if (info->buffer == NULL) return 0;
  2.1253 -
  2.1254 -	/* Loop while this request needs data and the next block is present
  2.1255 -	   in our cache. */
  2.1256 -	while (rq->nr_sectors > 0 &&
  2.1257 -	       rq->sector >= info->sector_buffered &&
  2.1258 -	       rq->sector < info->sector_buffered + info->nsectors_buffered) {
  2.1259 -		if (rq->current_nr_sectors == 0)
  2.1260 -			cdrom_end_request (1, drive);
  2.1261 -
  2.1262 -		memcpy (rq->buffer,
  2.1263 -			info->buffer +
  2.1264 -			(rq->sector - info->sector_buffered) * SECTOR_SIZE,
  2.1265 -			SECTOR_SIZE);
  2.1266 -		rq->buffer += SECTOR_SIZE;
  2.1267 -		--rq->current_nr_sectors;
  2.1268 -		--rq->nr_sectors;
  2.1269 -		++rq->sector;
  2.1270 -	}
  2.1271 -
  2.1272 -	/* If we've satisfied the current request,
  2.1273 -	   terminate it successfully. */
  2.1274 -	if (rq->nr_sectors == 0) {
  2.1275 -		cdrom_end_request (1, drive);
  2.1276 -		return -1;
  2.1277 -	}
  2.1278 -
  2.1279 -	/* Move on to the next buffer if needed. */
  2.1280 +    struct cdrom_info *info = drive->driver_data;
  2.1281 +    struct request *rq = HWGROUP(drive)->rq;
  2.1282 +
  2.1283 +    /* Can't do anything if there's no buffer. */
  2.1284 +    if (info->buffer == NULL) return 0;
  2.1285 +
  2.1286 +    /* Loop while this request needs data and the next block is present
  2.1287 +       in our cache. */
  2.1288 +    while (rq->nr_sectors > 0 &&
  2.1289 +	   rq->sector >= info->sector_buffered &&
  2.1290 +	   rq->sector < info->sector_buffered + info->nsectors_buffered) {
  2.1291  	if (rq->current_nr_sectors == 0)
  2.1292 -		cdrom_end_request (1, drive);
  2.1293 -
  2.1294 -	/* If this condition does not hold, then the kluge i use to
  2.1295 -	   represent the number of sectors to skip at the start of a transfer
  2.1296 -	   will fail.  I think that this will never happen, but let's be
  2.1297 -	   paranoid and check. */
  2.1298 -	if (rq->current_nr_sectors < (rq->bh->b_size >> SECTOR_BITS) &&
  2.1299 -	    (rq->sector % SECTORS_PER_FRAME) != 0) {
  2.1300 -		printk ("%s: cdrom_read_from_buffer: buffer botch (%ld)\n",
  2.1301 -			drive->name, rq->sector);
  2.1302 -		cdrom_end_request (0, drive);
  2.1303 -		return -1;
  2.1304 -	}
  2.1305 -
  2.1306 -	return 0;
  2.1307 +	    cdrom_end_request (1, drive);
  2.1308 +
  2.1309 +	memcpy (rq->buffer,
  2.1310 +		info->buffer +
  2.1311 +		(rq->sector - info->sector_buffered) * SECTOR_SIZE,
  2.1312 +		SECTOR_SIZE);
  2.1313 +	rq->buffer += SECTOR_SIZE;
  2.1314 +	--rq->current_nr_sectors;
  2.1315 +	--rq->nr_sectors;
  2.1316 +	++rq->sector;
  2.1317 +    }
  2.1318 +
  2.1319 +    /* If we've satisfied the current request,
  2.1320 +       terminate it successfully. */
  2.1321 +    if (rq->nr_sectors == 0) {
  2.1322 +	cdrom_end_request (1, drive);
  2.1323 +	return -1;
  2.1324 +    }
  2.1325 +
  2.1326 +    /* Move on to the next buffer if needed. */
  2.1327 +    if (rq->current_nr_sectors == 0)
  2.1328 +	cdrom_end_request (1, drive);
  2.1329 +
  2.1330 +    /* If this condition does not hold, then the kluge i use to
  2.1331 +       represent the number of sectors to skip at the start of a transfer
  2.1332 +       will fail.  I think that this will never happen, but let's be
  2.1333 +       paranoid and check. */
  2.1334 +    if (rq->current_nr_sectors < (rq->bh->b_size >> SECTOR_BITS) &&
  2.1335 +	(rq->sector % SECTORS_PER_FRAME) != 0) {
  2.1336 +	printk ("%s: cdrom_read_from_buffer: buffer botch (%ld)\n",
  2.1337 +		drive->name, rq->sector);
  2.1338 +	cdrom_end_request (0, drive);
  2.1339 +	return -1;
  2.1340 +    }
  2.1341 +
  2.1342 +    return 0;
  2.1343  }
  2.1344  
  2.1345  /*
  2.1346 @@ -1079,58 +1080,58 @@ static int cdrom_read_from_buffer (ide_d
  2.1347   */
  2.1348  static ide_startstop_t cdrom_start_read_continuation (ide_drive_t *drive)
  2.1349  {
  2.1350 -	struct packet_command pc;
  2.1351 -	struct request *rq = HWGROUP(drive)->rq;
  2.1352 -	int nsect, sector, nframes, frame, nskip;
  2.1353 -
  2.1354 -	/* Number of sectors to transfer. */
  2.1355 -	nsect = rq->nr_sectors;
  2.1356 -
  2.1357 -	/* Starting sector. */
  2.1358 -	sector = rq->sector;
  2.1359 -
  2.1360 -	/* If the requested sector doesn't start on a cdrom block boundary,
  2.1361 -	   we must adjust the start of the transfer so that it does,
  2.1362 -	   and remember to skip the first few sectors.
  2.1363 -	   If the CURRENT_NR_SECTORS field is larger than the size
  2.1364 -	   of the buffer, it will mean that we're to skip a number
  2.1365 -	   of sectors equal to the amount by which CURRENT_NR_SECTORS
  2.1366 -	   is larger than the buffer size. */
  2.1367 -	nskip = (sector % SECTORS_PER_FRAME);
  2.1368 -	if (nskip > 0) {
  2.1369 -		/* Sanity check... */
  2.1370 -		if (rq->current_nr_sectors != (rq->bh->b_size >> SECTOR_BITS) &&
  2.1371 -			(rq->sector % CD_FRAMESIZE != 0)) {
  2.1372 -			printk ("%s: cdrom_start_read_continuation: buffer botch (%lu)\n",
  2.1373 -				drive->name, rq->current_nr_sectors);
  2.1374 -			cdrom_end_request (0, drive);
  2.1375 -			return ide_stopped;
  2.1376 -		}
  2.1377 -		sector -= nskip;
  2.1378 -		nsect += nskip;
  2.1379 -		rq->current_nr_sectors += nskip;
  2.1380 +    struct packet_command pc;
  2.1381 +    struct request *rq = HWGROUP(drive)->rq;
  2.1382 +    int nsect, sector, nframes, frame, nskip;
  2.1383 +
  2.1384 +    /* Number of sectors to transfer. */
  2.1385 +    nsect = rq->nr_sectors;
  2.1386 +
  2.1387 +    /* Starting sector. */
  2.1388 +    sector = rq->sector;
  2.1389 +
  2.1390 +    /* If the requested sector doesn't start on a cdrom block boundary,
  2.1391 +       we must adjust the start of the transfer so that it does,
  2.1392 +       and remember to skip the first few sectors.
  2.1393 +       If the CURRENT_NR_SECTORS field is larger than the size
  2.1394 +       of the buffer, it will mean that we're to skip a number
  2.1395 +       of sectors equal to the amount by which CURRENT_NR_SECTORS
  2.1396 +       is larger than the buffer size. */
  2.1397 +    nskip = (sector % SECTORS_PER_FRAME);
  2.1398 +    if (nskip > 0) {
  2.1399 +	/* Sanity check... */
  2.1400 +	if (rq->current_nr_sectors != (rq->bh->b_size >> SECTOR_BITS) &&
  2.1401 +	    (rq->sector % CD_FRAMESIZE != 0)) {
  2.1402 +	    printk ("%s: cdrom_start_read_continuation: buffer botch (%lu)\n",
  2.1403 +		    drive->name, rq->current_nr_sectors);
  2.1404 +	    cdrom_end_request (0, drive);
  2.1405 +	    return ide_stopped;
  2.1406  	}
  2.1407 -
  2.1408 -	/* Convert from sectors to cdrom blocks, rounding up the transfer
  2.1409 -	   length if needed. */
  2.1410 -	nframes = (nsect + SECTORS_PER_FRAME-1) / SECTORS_PER_FRAME;
  2.1411 -	frame = sector / SECTORS_PER_FRAME;
  2.1412 -
  2.1413 -	/* Largest number of frames was can transfer at once is 64k-1. For
  2.1414 -	   some drives we need to limit this even more. */
  2.1415 -	nframes = MIN (nframes, (CDROM_CONFIG_FLAGS (drive)->limit_nframes) ?
  2.1416 -		(65534 / CD_FRAMESIZE) : 65535);
  2.1417 -
  2.1418 -	/* Set up the command */
  2.1419 -	memset (&pc.c, 0, sizeof (pc.c));
  2.1420 -	pc.c[0] = GPCMD_READ_10;
  2.1421 -	pc.c[7] = (nframes >> 8);
  2.1422 -	pc.c[8] = (nframes & 0xff);
  2.1423 -	put_unaligned(cpu_to_be32(frame), (unsigned int *) &pc.c[2]);
  2.1424 -	pc.timeout = WAIT_CMD;
  2.1425 -
  2.1426 -	/* Send the command to the drive and return. */
  2.1427 -	return cdrom_transfer_packet_command(drive, &pc, &cdrom_read_intr);
  2.1428 +	sector -= nskip;
  2.1429 +	nsect += nskip;
  2.1430 +	rq->current_nr_sectors += nskip;
  2.1431 +    }
  2.1432 +
  2.1433 +    /* Convert from sectors to cdrom blocks, rounding up the transfer
  2.1434 +       length if needed. */
  2.1435 +    nframes = (nsect + SECTORS_PER_FRAME-1) / SECTORS_PER_FRAME;
  2.1436 +    frame = sector / SECTORS_PER_FRAME;
  2.1437 +
  2.1438 +    /* Largest number of frames was can transfer at once is 64k-1. For
  2.1439 +       some drives we need to limit this even more. */
  2.1440 +    nframes = MIN (nframes, (CDROM_CONFIG_FLAGS (drive)->limit_nframes) ?
  2.1441 +		   (65534 / CD_FRAMESIZE) : 65535);
  2.1442 +
  2.1443 +    /* Set up the command */
  2.1444 +    memset (&pc.c, 0, sizeof (pc.c));
  2.1445 +    pc.c[0] = GPCMD_READ_10;
  2.1446 +    pc.c[7] = (nframes >> 8);
  2.1447 +    pc.c[8] = (nframes & 0xff);
  2.1448 +    put_unaligned(cpu_to_be32(frame), (unsigned int *) &pc.c[2]);
  2.1449 +    pc.timeout = WAIT_CMD;
  2.1450 +
  2.1451 +    /* Send the command to the drive and return. */
  2.1452 +    return cdrom_transfer_packet_command(drive, &pc, &cdrom_read_intr);
  2.1453  }
  2.1454  
  2.1455  
  2.1456 @@ -1140,78 +1141,78 @@ static ide_startstop_t cdrom_start_read_
  2.1457  
  2.1458  static ide_startstop_t cdrom_seek_intr (ide_drive_t *drive)
  2.1459  {
  2.1460 -	struct cdrom_info *info = drive->driver_data;
  2.1461 -	int stat;
  2.1462 -	static int retry = 10;
  2.1463 -	ide_startstop_t startstop;
  2.1464 -
  2.1465 -	if (cdrom_decode_status (&startstop, drive, 0, &stat))
  2.1466 -		return startstop;
  2.1467 -	CDROM_CONFIG_FLAGS(drive)->seeking = 1;
  2.1468 -
  2.1469 -	if (retry && jiffies - info->start_seek > IDECD_SEEK_TIMER) {
  2.1470 -		if (--retry == 0) {
  2.1471 -			/*
  2.1472 -			 * this condition is far too common, to bother
  2.1473 -			 * users about it
  2.1474 -			 */
  2.1475 +    struct cdrom_info *info = drive->driver_data;
  2.1476 +    int stat;
  2.1477 +    static int retry = 10;
  2.1478 +    ide_startstop_t startstop;
  2.1479 +
  2.1480 +    if (cdrom_decode_status (&startstop, drive, 0, &stat))
  2.1481 +	return startstop;
  2.1482 +    CDROM_CONFIG_FLAGS(drive)->seeking = 1;
  2.1483 +
  2.1484 +    if (retry && jiffies - info->start_seek > IDECD_SEEK_TIMER) {
  2.1485 +	if (--retry == 0) {
  2.1486 +	    /*
  2.1487 +	     * this condition is far too common, to bother
  2.1488 +	     * users about it
  2.1489 +	     */
  2.1490  #if 0
  2.1491 -			printk("%s: disabled DSC seek overlap\n", drive->name);
  2.1492 +	    printk("%s: disabled DSC seek overlap\n", drive->name);
  2.1493  #endif
  2.1494 -			drive->dsc_overlap = 0;
  2.1495 -		}
  2.1496 +	    drive->dsc_overlap = 0;
  2.1497  	}
  2.1498 -	return ide_stopped;
  2.1499 +    }
  2.1500 +    return ide_stopped;
  2.1501  }
  2.1502  
  2.1503  static ide_startstop_t cdrom_start_seek_continuation (ide_drive_t *drive)
  2.1504  {
  2.1505 -	struct packet_command pc;
  2.1506 -	struct request *rq = HWGROUP(drive)->rq;
  2.1507 -	int sector, frame, nskip;
  2.1508 -
  2.1509 -	sector = rq->sector;
  2.1510 -	nskip = (sector % SECTORS_PER_FRAME);
  2.1511 -	if (nskip > 0)
  2.1512 -		sector -= nskip;
  2.1513 -	frame = sector / SECTORS_PER_FRAME;
  2.1514 -
  2.1515 -	memset (&pc.c, 0, sizeof (pc.c));
  2.1516 -	pc.c[0] = GPCMD_SEEK;
  2.1517 -	put_unaligned(cpu_to_be32(frame), (unsigned int *) &pc.c[2]);
  2.1518 -
  2.1519 -	pc.timeout = WAIT_CMD;
  2.1520 -	return cdrom_transfer_packet_command(drive, &pc, &cdrom_seek_intr);
  2.1521 +    struct packet_command pc;
  2.1522 +    struct request *rq = HWGROUP(drive)->rq;
  2.1523 +    int sector, frame, nskip;
  2.1524 +
  2.1525 +    sector = rq->sector;
  2.1526 +    nskip = (sector % SECTORS_PER_FRAME);
  2.1527 +    if (nskip > 0)
  2.1528 +	sector -= nskip;
  2.1529 +    frame = sector / SECTORS_PER_FRAME;
  2.1530 +
  2.1531 +    memset (&pc.c, 0, sizeof (pc.c));
  2.1532 +    pc.c[0] = GPCMD_SEEK;
  2.1533 +    put_unaligned(cpu_to_be32(frame), (unsigned int *) &pc.c[2]);
  2.1534 +
  2.1535 +    pc.timeout = WAIT_CMD;
  2.1536 +    return cdrom_transfer_packet_command(drive, &pc, &cdrom_seek_intr);
  2.1537  }
  2.1538  
  2.1539  static ide_startstop_t cdrom_start_seek (ide_drive_t *drive, unsigned int block)
  2.1540  {
  2.1541 -	struct cdrom_info *info = drive->driver_data;
  2.1542 -
  2.1543 -	info->dma = 0;
  2.1544 -	info->cmd = 0;
  2.1545 -	info->start_seek = jiffies;
  2.1546 -	return cdrom_start_packet_command (drive, 0, cdrom_start_seek_continuation);
  2.1547 +    struct cdrom_info *info = drive->driver_data;
  2.1548 +
  2.1549 +    info->dma = 0;
  2.1550 +    info->cmd = 0;
  2.1551 +    info->start_seek = jiffies;
  2.1552 +    return cdrom_start_packet_command (drive, 0, cdrom_start_seek_continuation);
  2.1553  }
  2.1554  
  2.1555  static inline int cdrom_merge_requests(struct request *rq, struct request *nxt)
  2.1556  {
  2.1557 -	int ret = 1;
  2.1558 -
  2.1559 -	/*
  2.1560 -	 * partitions not really working, but better check anyway...
  2.1561 -	 */
  2.1562 -	if (rq->cmd == nxt->cmd && rq->rq_dev == nxt->rq_dev) {
  2.1563 -		rq->nr_sectors += nxt->nr_sectors;
  2.1564 -		rq->hard_nr_sectors += nxt->nr_sectors;
  2.1565 -		rq->bhtail->b_reqnext = nxt->bh;
  2.1566 -		rq->bhtail = nxt->bhtail;
  2.1567 -		list_del(&nxt->queue);
  2.1568 -		blkdev_release_request(nxt);
  2.1569 -		ret = 0;
  2.1570 -	}
  2.1571 -
  2.1572 -	return ret;
  2.1573 +    int ret = 1;
  2.1574 +
  2.1575 +    /*
  2.1576 +     * partitions not really working, but better check anyway...
  2.1577 +     */
  2.1578 +    if (rq->cmd == nxt->cmd && rq->rq_dev == nxt->rq_dev) {
  2.1579 +	rq->nr_sectors += nxt->nr_sectors;
  2.1580 +	rq->hard_nr_sectors += nxt->nr_sectors;
  2.1581 +	rq->bhtail->b_reqnext = nxt->bh;
  2.1582 +	rq->bhtail = nxt->bhtail;
  2.1583 +	list_del(&nxt->queue);
  2.1584 +	blkdev_release_request(nxt);
  2.1585 +	ret = 0;
  2.1586 +    }
  2.1587 +
  2.1588 +    return ret;
  2.1589  }
  2.1590  
  2.1591  /*
  2.1592 @@ -1219,43 +1220,43 @@ static inline int cdrom_merge_requests(s
  2.1593   */
  2.1594  static void cdrom_attempt_remerge(ide_drive_t *drive, struct request *rq)
  2.1595  {
  2.1596 -	struct list_head *entry;
  2.1597 -	struct request *nxt;
  2.1598 -	unsigned long flags;
  2.1599 -
  2.1600 -	spin_lock_irqsave(&io_request_lock, flags);
  2.1601 -
  2.1602 -	while (1) {
  2.1603 -		entry = rq->queue.next;
  2.1604 -		if (entry == &drive->queue.queue_head)
  2.1605 -			break;
  2.1606 -
  2.1607 -		nxt = blkdev_entry_to_request(entry);
  2.1608 -		if (rq->sector + rq->nr_sectors != nxt->sector)
  2.1609 -			break;
  2.1610 -		else if (rq->nr_sectors + nxt->nr_sectors > SECTORS_MAX)
  2.1611 -			break;
  2.1612 -
  2.1613 -		if (cdrom_merge_requests(rq, nxt))
  2.1614 -			break;
  2.1615 -	}
  2.1616 -
  2.1617 -	spin_unlock_irqrestore(&io_request_lock, flags);
  2.1618 +    struct list_head *entry;
  2.1619 +    struct request *nxt;
  2.1620 +    unsigned long flags;
  2.1621 +
  2.1622 +    spin_lock_irqsave(&io_request_lock, flags);
  2.1623 +
  2.1624 +    while (1) {
  2.1625 +	entry = rq->queue.next;
  2.1626 +	if (entry == &drive->queue.queue_head)
  2.1627 +	    break;
  2.1628 +
  2.1629 +	nxt = blkdev_entry_to_request(entry);
  2.1630 +	if (rq->sector + rq->nr_sectors != nxt->sector)
  2.1631 +	    break;
  2.1632 +	else if (rq->nr_sectors + nxt->nr_sectors > SECTORS_MAX)
  2.1633 +	    break;
  2.1634 +
  2.1635 +	if (cdrom_merge_requests(rq, nxt))
  2.1636 +	    break;
  2.1637 +    }
  2.1638 +
  2.1639 +    spin_unlock_irqrestore(&io_request_lock, flags);
  2.1640  }
  2.1641  
  2.1642  /* Fix up a possibly partially-processed request so that we can
  2.1643     start it over entirely, or even put it back on the request queue. */
  2.1644  static void restore_request (struct request *rq)
  2.1645  {
  2.1646 -	if (rq->buffer != rq->bh->b_data) {
  2.1647 -		int n = (rq->buffer - rq->bh->b_data) / SECTOR_SIZE;
  2.1648 -		rq->buffer = rq->bh->b_data;
  2.1649 -		rq->nr_sectors += n;
  2.1650 -		rq->sector -= n;
  2.1651 -	}
  2.1652 -	rq->current_nr_sectors = rq->bh->b_size >> SECTOR_BITS;
  2.1653 -	rq->hard_nr_sectors = rq->nr_sectors;
  2.1654 -	rq->hard_sector = rq->sector;
  2.1655 +    if (rq->buffer != rq->bh->b_data) {
  2.1656 +	int n = (rq->buffer - rq->bh->b_data) / SECTOR_SIZE;
  2.1657 +	rq->buffer = rq->bh->b_data;
  2.1658 +	rq->nr_sectors += n;
  2.1659 +	rq->sector -= n;
  2.1660 +    }
  2.1661 +    rq->current_nr_sectors = rq->bh->b_size >> SECTOR_BITS;
  2.1662 +    rq->hard_nr_sectors = rq->nr_sectors;
  2.1663 +    rq->hard_sector = rq->sector;
  2.1664  }
  2.1665  
  2.1666  /*
  2.1667 @@ -1263,41 +1264,41 @@ static void restore_request (struct requ
  2.1668   */
  2.1669  static ide_startstop_t cdrom_start_read (ide_drive_t *drive, unsigned int block)
  2.1670  {
  2.1671 -	struct cdrom_info *info = drive->driver_data;
  2.1672 -	struct request *rq = HWGROUP(drive)->rq;
  2.1673 -	int minor = MINOR (rq->rq_dev);
  2.1674 -
  2.1675 -	/* If the request is relative to a partition, fix it up to refer to the
  2.1676 -	   absolute address.  */
  2.1677 -	if (minor & PARTN_MASK) {
  2.1678 -		rq->sector = block;
  2.1679 -		minor &= ~PARTN_MASK;
  2.1680 -		rq->rq_dev = MKDEV(MAJOR(rq->rq_dev), minor);
  2.1681 -	}
  2.1682 -
  2.1683 -	/* We may be retrying this request after an error.  Fix up
  2.1684 -	   any weirdness which might be present in the request packet. */
  2.1685 -	restore_request(rq);
  2.1686 -
  2.1687 -	/* Satisfy whatever we can of this request from our cached sector. */
  2.1688 -	if (cdrom_read_from_buffer(drive))
  2.1689 -		return ide_stopped;
  2.1690 -
  2.1691 -	cdrom_attempt_remerge(drive, rq);
  2.1692 -
  2.1693 -	/* Clear the local sector buffer. */
  2.1694 -	info->nsectors_buffered = 0;
  2.1695 -
  2.1696 -	/* use dma, if possible. */
  2.1697 -	if (drive->using_dma && (rq->sector % SECTORS_PER_FRAME == 0) &&
  2.1698 -				(rq->nr_sectors % SECTORS_PER_FRAME == 0))
  2.1699 -		info->dma = 1;
  2.1700 -	else
  2.1701 -		info->dma = 0;
  2.1702 -
  2.1703 -	info->cmd = READ;
  2.1704 -	/* Start sending the read request to the drive. */
  2.1705 -	return cdrom_start_packet_command(drive, 32768, cdrom_start_read_continuation);
  2.1706 +    struct cdrom_info *info = drive->driver_data;
  2.1707 +    struct request *rq = HWGROUP(drive)->rq;
  2.1708 +    int minor = MINOR (rq->rq_dev);
  2.1709 +
  2.1710 +    /* If the request is relative to a partition, fix it up to refer to the
  2.1711 +       absolute address.  */
  2.1712 +    if (minor & PARTN_MASK) {
  2.1713 +	rq->sector = block;
  2.1714 +	minor &= ~PARTN_MASK;
  2.1715 +	rq->rq_dev = MKDEV(MAJOR(rq->rq_dev), minor);
  2.1716 +    }
  2.1717 +
  2.1718 +    /* We may be retrying this request after an error.  Fix up
  2.1719 +       any weirdness which might be present in the request packet. */
  2.1720 +    restore_request(rq);
  2.1721 +
  2.1722 +    /* Satisfy whatever we can of this request from our cached sector. */
  2.1723 +    if (cdrom_read_from_buffer(drive))
  2.1724 +	return ide_stopped;
  2.1725 +
  2.1726 +    cdrom_attempt_remerge(drive, rq);
  2.1727 +
  2.1728 +    /* Clear the local sector buffer. */
  2.1729 +    info->nsectors_buffered = 0;
  2.1730 +
  2.1731 +    /* use dma, if possible. */
  2.1732 +    if (drive->using_dma && (rq->sector % SECTORS_PER_FRAME == 0) &&
  2.1733 +	(rq->nr_sectors % SECTORS_PER_FRAME == 0))
  2.1734 +	info->dma = 1;
  2.1735 +    else
  2.1736 +	info->dma = 0;
  2.1737 +
  2.1738 +    info->cmd = READ;
  2.1739 +    /* Start sending the read request to the drive. */
  2.1740 +    return cdrom_start_packet_command(drive, 32768, cdrom_start_read_continuation);
  2.1741  }
  2.1742  
  2.1743  /****************************************************************************
  2.1744 @@ -1311,128 +1312,128 @@ static int cdrom_lockdoor(ide_drive_t *d
  2.1745  /* Interrupt routine for packet command completion. */
  2.1746  static ide_startstop_t cdrom_pc_intr (ide_drive_t *drive)
  2.1747  {
  2.1748 -	int ireason, len, stat, thislen;
  2.1749 -	struct request *rq = HWGROUP(drive)->rq;
  2.1750 -	struct packet_command *pc = (struct packet_command *)rq->buffer;
  2.1751 -	ide_startstop_t startstop;
  2.1752 -
  2.1753 -	/* Check for errors. */
  2.1754 -	if (cdrom_decode_status (&startstop, drive, 0, &stat))
  2.1755 -		return startstop;
  2.1756 -
  2.1757 -	/* Read the interrupt reason and the transfer length. */
  2.1758 -	ireason = IN_BYTE (IDE_NSECTOR_REG);
  2.1759 -	len = IN_BYTE (IDE_LCYL_REG) + 256 * IN_BYTE (IDE_HCYL_REG);
  2.1760 -
  2.1761 -	/* If DRQ is clear, the command has completed.
  2.1762 -	   Complain if we still have data left to transfer. */
  2.1763 -	if ((stat & DRQ_STAT) == 0) {
  2.1764 -		/* Some of the trailing request sense fields are optional, and
  2.1765 -		   some drives don't send them.  Sigh. */
  2.1766 -		if (pc->c[0] == GPCMD_REQUEST_SENSE &&
  2.1767 -		    pc->buflen > 0 &&
  2.1768 -		    pc->buflen <= 5) {
  2.1769 -			while (pc->buflen > 0) {
  2.1770 -				*pc->buffer++ = 0;
  2.1771 -				--pc->buflen;
  2.1772 -			}
  2.1773 -		}
  2.1774 -
  2.1775 -		if (pc->buflen == 0)
  2.1776 -			cdrom_end_request (1, drive);
  2.1777 -		else {
  2.1778 -			/* Comment this out, because this always happens 
  2.1779 -			   right after a reset occurs, and it is annoying to 
  2.1780 -			   always print expected stuff.  */
  2.1781 -			/*
  2.1782 -			printk ("%s: cdrom_pc_intr: data underrun %d\n",
  2.1783 -				drive->name, pc->buflen);
  2.1784 -			*/
  2.1785 -			pc->stat = 1;
  2.1786 -			cdrom_end_request (1, drive);
  2.1787 -		}
  2.1788 -		return ide_stopped;
  2.1789 +    int ireason, len, stat, thislen;
  2.1790 +    struct request *rq = HWGROUP(drive)->rq;
  2.1791 +    struct packet_command *pc = (struct packet_command *)rq->buffer;
  2.1792 +    ide_startstop_t startstop;
  2.1793 +
  2.1794 +    /* Check for errors. */
  2.1795 +    if (cdrom_decode_status (&startstop, drive, 0, &stat))
  2.1796 +	return startstop;
  2.1797 +
  2.1798 +    /* Read the interrupt reason and the transfer length. */
  2.1799 +    ireason = IN_BYTE (IDE_NSECTOR_REG);
  2.1800 +    len = IN_BYTE (IDE_LCYL_REG) + 256 * IN_BYTE (IDE_HCYL_REG);
  2.1801 +
  2.1802 +    /* If DRQ is clear, the command has completed.
  2.1803 +       Complain if we still have data left to transfer. */
  2.1804 +    if ((stat & DRQ_STAT) == 0) {
  2.1805 +	/* Some of the trailing request sense fields are optional, and
  2.1806 +	   some drives don't send them.  Sigh. */
  2.1807 +	if (pc->c[0] == GPCMD_REQUEST_SENSE &&
  2.1808 +	    pc->buflen > 0 &&
  2.1809 +	    pc->buflen <= 5) {
  2.1810 +	    while (pc->buflen > 0) {
  2.1811 +		*pc->buffer++ = 0;
  2.1812 +		--pc->buflen;
  2.1813 +	    }
  2.1814 +	}
  2.1815 +
  2.1816 +	if (pc->buflen == 0)
  2.1817 +	    cdrom_end_request (1, drive);
  2.1818 +	else {
  2.1819 +	    /* Comment this out, because this always happens 
  2.1820 +	       right after a reset occurs, and it is annoying to 
  2.1821 +	       always print expected stuff.  */
  2.1822 +	    /*
  2.1823 +	      printk ("%s: cdrom_pc_intr: data underrun %d\n",
  2.1824 +	      drive->name, pc->buflen);
  2.1825 +	    */
  2.1826 +	    pc->stat = 1;
  2.1827 +	    cdrom_end_request (1, drive);
  2.1828  	}
  2.1829 -
  2.1830 -	/* Figure out how much data to transfer. */
  2.1831 -	thislen = pc->buflen;
  2.1832 -	if (thislen > len) thislen = len;
  2.1833 -
  2.1834 -	/* The drive wants to be written to. */
  2.1835 -	if ((ireason & 3) == 0) {
  2.1836 -		/* Transfer the data. */
  2.1837 -		atapi_output_bytes (drive, pc->buffer, thislen);
  2.1838 -
  2.1839 -		/* If we haven't moved enough data to satisfy the drive,
  2.1840 -		   add some padding. */
  2.1841 -		while (len > thislen) {
  2.1842 -			int dum = 0;
  2.1843 -			atapi_output_bytes (drive, &dum, sizeof (dum));
  2.1844 -			len -= sizeof (dum);
  2.1845 -		}
  2.1846 -
  2.1847 -		/* Keep count of how much data we've moved. */
  2.1848 -		pc->buffer += thislen;
  2.1849 -		pc->buflen -= thislen;
  2.1850 +	return ide_stopped;
  2.1851 +    }
  2.1852 +
  2.1853 +    /* Figure out how much data to transfer. */
  2.1854 +    thislen = pc->buflen;
  2.1855 +    if (thislen > len) thislen = len;
  2.1856 +
  2.1857 +    /* The drive wants to be written to. */
  2.1858 +    if ((ireason & 3) == 0) {
  2.1859 +	/* Transfer the data. */
  2.1860 +	atapi_output_bytes (drive, pc->buffer, thislen);
  2.1861 +
  2.1862 +	/* If we haven't moved enough data to satisfy the drive,
  2.1863 +	   add some padding. */
  2.1864 +	while (len > thislen) {
  2.1865 +	    int dum = 0;
  2.1866 +	    atapi_output_bytes (drive, &dum, sizeof (dum));
  2.1867 +	    len -= sizeof (dum);
  2.1868  	}
  2.1869  
  2.1870 -	/* Same drill for reading. */
  2.1871 -	else if ((ireason & 3) == 2) {
  2.1872 -
  2.1873 -		/* Transfer the data. */
  2.1874 -		atapi_input_bytes (drive, pc->buffer, thislen);
  2.1875 -
  2.1876 -		/* If we haven't moved enough data to satisfy the drive,
  2.1877 -		   add some padding. */
  2.1878 -		while (len > thislen) {
  2.1879 -			int dum = 0;
  2.1880 -			atapi_input_bytes (drive, &dum, sizeof (dum));
  2.1881 -			len -= sizeof (dum);
  2.1882 -		}
  2.1883 -
  2.1884 -		/* Keep count of how much data we've moved. */
  2.1885 -		pc->buffer += thislen;
  2.1886 -		pc->buflen -= thislen;
  2.1887 -	} else {
  2.1888 -		printk ("%s: cdrom_pc_intr: The drive "
  2.1889 -			"appears confused (ireason = 0x%2x)\n",
  2.1890 -			drive->name, ireason);
  2.1891 -		pc->stat = 1;
  2.1892 +	/* Keep count of how much data we've moved. */
  2.1893 +	pc->buffer += thislen;
  2.1894 +	pc->buflen -= thislen;
  2.1895 +    }
  2.1896 +
  2.1897 +    /* Same drill for reading. */
  2.1898 +    else if ((ireason & 3) == 2) {
  2.1899 +
  2.1900 +	/* Transfer the data. */
  2.1901 +	atapi_input_bytes (drive, pc->buffer, thislen);
  2.1902 +
  2.1903 +	/* If we haven't moved enough data to satisfy the drive,
  2.1904 +	   add some padding. */
  2.1905 +	while (len > thislen) {
  2.1906 +	    int dum = 0;
  2.1907 +	    atapi_input_bytes (drive, &dum, sizeof (dum));
  2.1908 +	    len -= sizeof (dum);
  2.1909  	}
  2.1910  
  2.1911 -	/* Now we wait for another interrupt. */
  2.1912 -	ide_set_handler (drive, &cdrom_pc_intr, WAIT_CMD, cdrom_timer_expiry);
  2.1913 -	return ide_started;
  2.1914 +	/* Keep count of how much data we've moved. */
  2.1915 +	pc->buffer += thislen;
  2.1916 +	pc->buflen -= thislen;
  2.1917 +    } else {
  2.1918 +	printk ("%s: cdrom_pc_intr: The drive "
  2.1919 +		"appears confused (ireason = 0x%2x)\n",
  2.1920 +		drive->name, ireason);
  2.1921 +	pc->stat = 1;
  2.1922 +    }
  2.1923 +
  2.1924 +    /* Now we wait for another interrupt. */
  2.1925 +    ide_set_handler (drive, &cdrom_pc_intr, WAIT_CMD, cdrom_timer_expiry);
  2.1926 +    return ide_started;
  2.1927  }
  2.1928  
  2.1929  
  2.1930  static ide_startstop_t cdrom_do_pc_continuation (ide_drive_t *drive)
  2.1931  {
  2.1932 -	struct request *rq = HWGROUP(drive)->rq;
  2.1933 -	struct packet_command *pc = (struct packet_command *)rq->buffer;
  2.1934 -
  2.1935 -	if (!pc->timeout)
  2.1936 -		pc->timeout = WAIT_CMD;
  2.1937 -
  2.1938 -	/* Send the command to the drive and return. */
  2.1939 -	return cdrom_transfer_packet_command(drive, pc, &cdrom_pc_intr);
  2.1940 +    struct request *rq = HWGROUP(drive)->rq;
  2.1941 +    struct packet_command *pc = (struct packet_command *)rq->buffer;
  2.1942 +
  2.1943 +    if (!pc->timeout)
  2.1944 +	pc->timeout = WAIT_CMD;
  2.1945 +
  2.1946 +    /* Send the command to the drive and return. */
  2.1947 +    return cdrom_transfer_packet_command(drive, pc, &cdrom_pc_intr);
  2.1948  }
  2.1949  
  2.1950  
  2.1951  static ide_startstop_t cdrom_do_packet_command (ide_drive_t *drive)
  2.1952  {
  2.1953 -	int len;
  2.1954 -	struct request *rq = HWGROUP(drive)->rq;
  2.1955 -	struct packet_command *pc = (struct packet_command *)rq->buffer;
  2.1956 -	struct cdrom_info *info = drive->driver_data;
  2.1957 -
  2.1958 -	info->dma = 0;
  2.1959 -	info->cmd = 0;
  2.1960 -	pc->stat = 0;
  2.1961 -	len = pc->buflen;
  2.1962 -
  2.1963 -	/* Start sending the command to the drive. */
  2.1964 -	return cdrom_start_packet_command (drive, len, cdrom_do_pc_continuation);
  2.1965 +    int len;
  2.1966 +    struct request *rq = HWGROUP(drive)->rq;
  2.1967 +    struct packet_command *pc = (struct packet_command *)rq->buffer;
  2.1968 +    struct cdrom_info *info = drive->driver_data;
  2.1969 +
  2.1970 +    info->dma = 0;
  2.1971 +    info->cmd = 0;
  2.1972 +    pc->stat = 0;
  2.1973 +    len = pc->buflen;
  2.1974 +
  2.1975 +    /* Start sending the command to the drive. */
  2.1976 +    return cdrom_start_packet_command (drive, len, cdrom_do_pc_continuation);
  2.1977  }
  2.1978  
  2.1979  
  2.1980 @@ -1441,60 +1442,60 @@ static ide_startstop_t cdrom_do_packet_c
  2.1981  static
  2.1982  void cdrom_sleep (int time)
  2.1983  {
  2.1984 -	int sleep = time;
  2.1985 -
  2.1986 -	do {
  2.1987 -		set_current_state(TASK_INTERRUPTIBLE);
  2.1988 -		sleep = schedule_timeout(sleep);
  2.1989 -	} while (sleep);
  2.1990 +    int sleep = time;
  2.1991 +
  2.1992 +    do {
  2.1993 +	set_current_state(TASK_INTERRUPTIBLE);
  2.1994 +	sleep = schedule_timeout(sleep);
  2.1995 +    } while (sleep);
  2.1996  }
  2.1997  
  2.1998  static
  2.1999  int cdrom_queue_packet_command(ide_drive_t *drive, struct packet_command *pc)
  2.2000  {
  2.2001 -	struct request_sense sense;
  2.2002 -	struct request req;
  2.2003 -	int retries = 10;
  2.2004 -
  2.2005 -	if (pc->sense == NULL)
  2.2006 -		pc->sense = &sense;
  2.2007 -
  2.2008 -	/* Start of retry loop. */
  2.2009 -	do {
  2.2010 -		ide_init_drive_cmd (&req);
  2.2011 -		req.cmd = PACKET_COMMAND;
  2.2012 -		req.buffer = (char *)pc;
  2.2013 -		if (ide_do_drive_cmd (drive, &req, ide_wait)) {
  2.2014 -			printk("%s: do_drive_cmd returned stat=%02x,err=%02x\n",
  2.2015 -				drive->name, req.buffer[0], req.buffer[1]);
  2.2016 -			/* FIXME: we should probably abort/retry or something */
  2.2017 -		}
  2.2018 -		if (pc->stat != 0) {
  2.2019 -			/* The request failed.  Retry if it was due to a unit
  2.2020 -			   attention status
  2.2021 -			   (usually means media was changed). */
  2.2022 -			struct request_sense *reqbuf = pc->sense;
  2.2023 -
  2.2024 -			if (reqbuf->sense_key == UNIT_ATTENTION)
  2.2025 -				cdrom_saw_media_change (drive);
  2.2026 -			else if (reqbuf->sense_key == NOT_READY &&
  2.2027 -				 reqbuf->asc == 4 && reqbuf->ascq != 4) {
  2.2028 +    struct request_sense sense;
  2.2029 +    struct request req;
  2.2030 +    int retries = 10;
  2.2031 +
  2.2032 +    if (pc->sense == NULL)
  2.2033 +	pc->sense = &sense;
  2.2034 +
  2.2035 +    /* Start of retry loop. */
  2.2036 +    do {
  2.2037 +	ide_init_drive_cmd (&req);
  2.2038 +	req.cmd = PACKET_COMMAND;
  2.2039 +	req.buffer = (char *)pc;
  2.2040 +	if (ide_do_drive_cmd (drive, &req, ide_wait)) {
  2.2041 +	    printk("%s: do_drive_cmd returned stat=%02x,err=%02x\n",
  2.2042 +		   drive->name, req.buffer[0], req.buffer[1]);
  2.2043 +	    /* FIXME: we should probably abort/retry or something */
  2.2044 +	}
  2.2045 +	if (pc->stat != 0) {
  2.2046 +	    /* The request failed.  Retry if it was due to a unit
  2.2047 +	       attention status
  2.2048 +	       (usually means media was changed). */
  2.2049 +	    struct request_sense *reqbuf = pc->sense;
  2.2050 +
  2.2051 +	    if (reqbuf->sense_key == UNIT_ATTENTION)
  2.2052 +		cdrom_saw_media_change (drive);
  2.2053 +	    else if (reqbuf->sense_key == NOT_READY &&
  2.2054 +		     reqbuf->asc == 4 && reqbuf->ascq != 4) {
  2.2055  				/* The drive is in the process of loading
  2.2056  				   a disk.  Retry, but wait a little to give
  2.2057  				   the drive time to complete the load. */
  2.2058 -				cdrom_sleep(2 * HZ);
  2.2059 -			} else {
  2.2060 +		cdrom_sleep(2 * HZ);
  2.2061 +	    } else {
  2.2062  				/* Otherwise, don't retry. */
  2.2063 -				retries = 0;
  2.2064 -			}
  2.2065 -			--retries;
  2.2066 -		}
  2.2067 -
  2.2068 -		/* End of retry loop. */
  2.2069 -	} while (pc->stat != 0 && retries >= 0);
  2.2070 -
  2.2071 -	/* Return an error if the command failed. */
  2.2072 -	return pc->stat ? -EIO : 0;
  2.2073 +		retries = 0;
  2.2074 +	    }
  2.2075 +	    --retries;
  2.2076 +	}
  2.2077 +
  2.2078 +	/* End of retry loop. */
  2.2079 +    } while (pc->stat != 0 && retries >= 0);
  2.2080 +
  2.2081 +    /* Return an error if the command failed. */
  2.2082 +    return pc->stat ? -EIO : 0;
  2.2083  }
  2.2084  
  2.2085  /*
  2.2086 @@ -1502,191 +1503,191 @@ int cdrom_queue_packet_command(ide_drive
  2.2087   */
  2.2088  static inline int cdrom_write_check_ireason(ide_drive_t *drive, int len, int ireason)
  2.2089  {
  2.2090 -	/* Two notes about IDE interrupt reason here - 0 means that
  2.2091 -	 * the drive wants to receive data from us, 2 means that
  2.2092 -	 * the drive is expecting data from us.
  2.2093 +    /* Two notes about IDE interrupt reason here - 0 means that
  2.2094 +     * the drive wants to receive data from us, 2 means that
  2.2095 +     * the drive is expecting data from us.
  2.2096  	 */
  2.2097 -	ireason &= 3;
  2.2098 -
  2.2099 -	if (ireason == 2) {
  2.2100 -		/* Whoops... The drive wants to send data. */
  2.2101 -		printk("%s: cdrom_write_intr: wrong transfer direction!\n",
  2.2102 -			drive->name);
  2.2103 -
  2.2104 -		/* Throw some data at the drive so it doesn't hang
  2.2105 +    ireason &= 3;
  2.2106 +
  2.2107 +    if (ireason == 2) {
  2.2108 +	/* Whoops... The drive wants to send data. */
  2.2109 +	printk("%s: cdrom_write_intr: wrong transfer direction!\n",
  2.2110 +	       drive->name);
  2.2111 +
  2.2112 +	/* Throw some data at the drive so it doesn't hang
  2.2113  		   and quit this request. */
  2.2114 -		while (len > 0) {
  2.2115 -			int dum = 0;
  2.2116 -			atapi_output_bytes(drive, &dum, sizeof(dum));
  2.2117 -			len -= sizeof(dum);
  2.2118 -		}
  2.2119 -	} else {
  2.2120 -		/* Drive wants a command packet, or invalid ireason... */
  2.2121 -		printk("%s: cdrom_write_intr: bad interrupt reason %d\n",
  2.2122 -			drive->name, ireason);
  2.2123 +	while (len > 0) {
  2.2124 +	    int dum = 0;
  2.2125 +	    atapi_output_bytes(drive, &dum, sizeof(dum));
  2.2126 +	    len -= sizeof(dum);
  2.2127  	}
  2.2128 -
  2.2129 -	cdrom_end_request(0, drive);
  2.2130 -	return 1;
  2.2131 +    } else {
  2.2132 +	/* Drive wants a command packet, or invalid ireason... */
  2.2133 +	printk("%s: cdrom_write_intr: bad interrupt reason %d\n",
  2.2134 +	       drive->name, ireason);
  2.2135 +    }
  2.2136 +
  2.2137 +    cdrom_end_request(0, drive);
  2.2138 +    return 1;
  2.2139  }
  2.2140  
  2.2141  static ide_startstop_t cdrom_write_intr(ide_drive_t *drive)
  2.2142  {
  2.2143 -	int stat, ireason, len, sectors_to_transfer, uptodate;
  2.2144 -	struct cdrom_info *info = drive->driver_data;
  2.2145 -	int i, dma_error = 0, dma = info->dma;
  2.2146 -	ide_startstop_t startstop;
  2.2147 -
  2.2148 -	struct request *rq = HWGROUP(drive)->rq;
  2.2149 -
  2.2150 -	/* Check for errors. */
  2.2151 -	if (dma) {
  2.2152 -		info->dma = 0;
  2.2153 -		if ((dma_error = HWIF(drive)->dmaproc(ide_dma_end, drive))) {
  2.2154 -			printk("ide-cd: write dma error\n");
  2.2155 -			HWIF(drive)->dmaproc(ide_dma_off, drive);
  2.2156 -		}
  2.2157 +    int stat, ireason, len, sectors_to_transfer, uptodate;
  2.2158 +    struct cdrom_info *info = drive->driver_data;
  2.2159 +    int i, dma_error = 0, dma = info->dma;
  2.2160 +    ide_startstop_t startstop;
  2.2161 +
  2.2162 +    struct request *rq = HWGROUP(drive)->rq;
  2.2163 +
  2.2164 +    /* Check for errors. */
  2.2165 +    if (dma) {
  2.2166 +	info->dma = 0;
  2.2167 +	if ((dma_error = HWIF(drive)->dmaproc(ide_dma_end, drive))) {
  2.2168 +	    printk("ide-cd: write dma error\n");
  2.2169 +	    HWIF(drive)->dmaproc(ide_dma_off, drive);
  2.2170  	}
  2.2171 -
  2.2172 -	if (cdrom_decode_status(&startstop, drive, 0, &stat)) {
  2.2173 -		printk("ide-cd: write_intr decode_status bad\n");
  2.2174 -		return startstop;
  2.2175 +    }
  2.2176 +
  2.2177 +    if (cdrom_decode_status(&startstop, drive, 0, &stat)) {
  2.2178 +	printk("ide-cd: write_intr decode_status bad\n");
  2.2179 +	return startstop;
  2.2180 +    }
  2.2181 + 
  2.2182 +    /*
  2.2183 +     * using dma, transfer is complete now
  2.2184 +     */
  2.2185 +    if (dma) {
  2.2186 +	if (dma_error)
  2.2187 +	    return ide_error(drive, "dma error", stat);
  2.2188 +
  2.2189 +	rq = HWGROUP(drive)->rq;
  2.2190 +	for (i = rq->nr_sectors; i > 0;) {
  2.2191 +	    i -= rq->current_nr_sectors;
  2.2192 +	    ide_end_request(1, HWGROUP(drive));
  2.2193  	}
  2.2194 - 
  2.2195 -	/*
  2.2196 -	 * using dma, transfer is complete now
  2.2197 +	return ide_stopped;
  2.2198 +    }
  2.2199 +
  2.2200 +    /* Read the interrupt reason and the transfer length. */
  2.2201 +    ireason = IN_BYTE(IDE_NSECTOR_REG);
  2.2202 +    len = IN_BYTE(IDE_LCYL_REG) + 256 * IN_BYTE(IDE_HCYL_REG);
  2.2203 +
  2.2204 +    /* If DRQ is clear, the command has completed. */
  2.2205 +    if ((stat & DRQ_STAT) == 0) {
  2.2206 +	/* If we're not done writing, complain.
  2.2207 +	 * Otherwise, complete the command normally.
  2.2208  	 */
  2.2209 -	if (dma) {
  2.2210 -		if (dma_error)
  2.2211 -			return ide_error(drive, "dma error", stat);
  2.2212 -
  2.2213 -		rq = HWGROUP(drive)->rq;
  2.2214 -		for (i = rq->nr_sectors; i > 0;) {
  2.2215 -			i -= rq->current_nr_sectors;
  2.2216 -			ide_end_request(1, HWGROUP(drive));
  2.2217 -		}
  2.2218 -		return ide_stopped;
  2.2219 +	uptodate = 1;
  2.2220 +	if (rq->current_nr_sectors > 0) {
  2.2221 +	    printk("%s: write_intr: data underrun (%ld blocks)\n",
  2.2222 +		   drive->name, rq->current_nr_sectors);
  2.2223 +	    uptodate = 0;
  2.2224  	}
  2.2225 -
  2.2226 -	/* Read the interrupt reason and the transfer length. */
  2.2227 -	ireason = IN_BYTE(IDE_NSECTOR_REG);
  2.2228 -	len = IN_BYTE(IDE_LCYL_REG) + 256 * IN_BYTE(IDE_HCYL_REG);
  2.2229 -
  2.2230 -	/* If DRQ is clear, the command has completed. */
  2.2231 -	if ((stat & DRQ_STAT) == 0) {
  2.2232 -		/* If we're not done writing, complain.
  2.2233 -		 * Otherwise, complete the command normally.
  2.2234 -		 */
  2.2235 -		uptodate = 1;
  2.2236 -		if (rq->current_nr_sectors > 0) {
  2.2237 -			printk("%s: write_intr: data underrun (%ld blocks)\n",
  2.2238 -			drive->name, rq->current_nr_sectors);
  2.2239 -			uptodate = 0;
  2.2240 -		}
  2.2241 -		cdrom_end_request(uptodate, drive);
  2.2242 -		return ide_stopped;
  2.2243 +	cdrom_end_request(uptodate, drive);
  2.2244 +	return ide_stopped;
  2.2245 +    }
  2.2246 +
  2.2247 +    /* Check that the drive is expecting to do the same thing we are. */
  2.2248 +    if (ireason & 3)
  2.2249 +	if (cdrom_write_check_ireason(drive, len, ireason))
  2.2250 +	    return ide_stopped;
  2.2251 +
  2.2252 +    sectors_to_transfer = len / SECTOR_SIZE;
  2.2253 +
  2.2254 +    /*
  2.2255 +     * now loop and write out the data
  2.2256 +     */
  2.2257 +    while (sectors_to_transfer > 0) {
  2.2258 +	int this_transfer;
  2.2259 +
  2.2260 +	if (!rq->current_nr_sectors) {
  2.2261 +	    printk("ide-cd: write_intr: oops\n");
  2.2262 +	    break;
  2.2263  	}
  2.2264  
  2.2265 -	/* Check that the drive is expecting to do the same thing we are. */
  2.2266 -	if (ireason & 3)
  2.2267 -		if (cdrom_write_check_ireason(drive, len, ireason))
  2.2268 -			return ide_stopped;
  2.2269 -
  2.2270 -	sectors_to_transfer = len / SECTOR_SIZE;
  2.2271 -
  2.2272  	/*
  2.2273 -	 * now loop and write out the data
  2.2274 +	 * Figure out how many sectors we can transfer
  2.2275  	 */
  2.2276 -	while (sectors_to_transfer > 0) {
  2.2277 -		int this_transfer;
  2.2278 -
  2.2279 -		if (!rq->current_nr_sectors) {
  2.2280 -			printk("ide-cd: write_intr: oops\n");
  2.2281 -			break;
  2.2282 -		}
  2.2283 -
  2.2284 -		/*
  2.2285 -		 * Figure out how many sectors we can transfer
  2.2286 -		 */
  2.2287 -		this_transfer = MIN(sectors_to_transfer,rq->current_nr_sectors);
  2.2288 -
  2.2289 -		while (this_transfer > 0) {
  2.2290 -			atapi_output_bytes(drive, rq->buffer, SECTOR_SIZE);
  2.2291 -			rq->buffer += SECTOR_SIZE;
  2.2292 -			--rq->nr_sectors;
  2.2293 -			--rq->current_nr_sectors;
  2.2294 -			++rq->sector;
  2.2295 -			--this_transfer;
  2.2296 -			--sectors_to_transfer;
  2.2297 -		}
  2.2298 -
  2.2299 -		/*
  2.2300 -		 * current buffer complete, move on
  2.2301 -		 */
  2.2302 -		if (rq->current_nr_sectors == 0 && rq->nr_sectors)
  2.2303 -			cdrom_end_request (1, drive);
  2.2304 +	this_transfer = MIN(sectors_to_transfer,rq->current_nr_sectors);
  2.2305 +
  2.2306 +	while (this_transfer > 0) {
  2.2307 +	    atapi_output_bytes(drive, rq->buffer, SECTOR_SIZE);
  2.2308 +	    rq->buffer += SECTOR_SIZE;
  2.2309 +	    --rq->nr_sectors;
  2.2310 +	    --rq->current_nr_sectors;
  2.2311 +	    ++rq->sector;
  2.2312 +	    --this_transfer;
  2.2313 +	    --sectors_to_transfer;
  2.2314  	}
  2.2315  
  2.2316 -	/* re-arm handler */
  2.2317 -	ide_set_handler(drive, &cdrom_write_intr, 5 * WAIT_CMD, NULL);
  2.2318 -	return ide_started;
  2.2319 +	/*
  2.2320 +	 * current buffer complete, move on
  2.2321 +	 */
  2.2322 +	if (rq->current_nr_sectors == 0 && rq->nr_sectors)
  2.2323 +	    cdrom_end_request (1, drive);
  2.2324 +    }
  2.2325 +
  2.2326 +    /* re-arm handler */
  2.2327 +    ide_set_handler(drive, &cdrom_write_intr, 5 * WAIT_CMD, NULL);
  2.2328 +    return ide_started;
  2.2329  }
  2.2330  
  2.2331  static ide_startstop_t cdrom_start_write_cont(ide_drive_t *drive)
  2.2332  {
  2.2333 -	struct packet_command pc;	/* packet_command_t pc; */
  2.2334 -	struct request *rq = HWGROUP(drive)->rq;
  2.2335 -	unsigned nframes, frame;
  2.2336 -
  2.2337 -	nframes = rq->nr_sectors >> 2;
  2.2338 -	frame = rq->sector >> 2;
  2.2339 -
  2.2340 -	memset(&pc.c, 0, sizeof(pc.c));
  2.2341 -	/*
  2.2342 -	 * we might as well use WRITE_12, but none of the device I have
  2.2343 -	 * support the streaming feature anyway, so who cares.
  2.2344 -	 */
  2.2345 -	pc.c[0] = GPCMD_WRITE_10;
  2.2346 +    struct packet_command pc;	/* packet_command_t pc; */
  2.2347 +    struct request *rq = HWGROUP(drive)->rq;
  2.2348 +    unsigned nframes, frame;
  2.2349 +
  2.2350 +    nframes = rq->nr_sectors >> 2;
  2.2351 +    frame = rq->sector >> 2;
  2.2352 +
  2.2353 +    memset(&pc.c, 0, sizeof(pc.c));
  2.2354 +    /*
  2.2355 +     * we might as well use WRITE_12, but none of the device I have
  2.2356 +     * support the streaming feature anyway, so who cares.
  2.2357 +     */
  2.2358 +    pc.c[0] = GPCMD_WRITE_10;
  2.2359  #if 0	/* the immediate bit */
  2.2360 -	pc.c[1] = 1 << 3;
  2.2361 +    pc.c[1] = 1 << 3;
  2.2362  #endif
  2.2363 -	pc.c[7] = (nframes >> 8) & 0xff;
  2.2364 -	pc.c[8] = nframes & 0xff;
  2.2365 -	put_unaligned(cpu_to_be32(frame), (unsigned int *)&pc.c[2]);
  2.2366 -	pc.timeout = 2 * WAIT_CMD;
  2.2367 -
  2.2368 -	return cdrom_transfer_packet_command(drive, &pc, cdrom_write_intr);
  2.2369 +    pc.c[7] = (nframes >> 8) & 0xff;
  2.2370 +    pc.c[8] = nframes & 0xff;
  2.2371 +    put_unaligned(cpu_to_be32(frame), (unsigned int *)&pc.c[2]);
  2.2372 +    pc.timeout = 2 * WAIT_CMD;
  2.2373 +
  2.2374 +    return cdrom_transfer_packet_command(drive, &pc, cdrom_write_intr);
  2.2375  }
  2.2376  
  2.2377  static ide_startstop_t cdrom_start_write(ide_drive_t *drive, struct request *rq)
  2.2378  {
  2.2379 -	struct cdrom_info *info = drive->driver_data;
  2.2380 -
  2.2381 -	/*
  2.2382 -	 * writes *must* be 2kB frame aligned
  2.2383 -	 */
  2.2384 -	if ((rq->nr_sectors & 3) || (rq->sector & 3)) {
  2.2385 -		cdrom_end_request(0, drive);
  2.2386 -		return ide_stopped;
  2.2387 -	}
  2.2388 -
  2.2389 -	/*
  2.2390 -	 * for dvd-ram and such media, it's a really big deal to get
  2.2391 -	 * big writes all the time. so scour the queue and attempt to
  2.2392 -	 * remerge requests, often the plugging will not have had time
  2.2393 -	 * to do this properly
  2.2394 -	 */
  2.2395 -	cdrom_attempt_remerge(drive, rq);
  2.2396 -
  2.2397 -	info->nsectors_buffered = 0;
  2.2398 -
  2.2399 -        /* use dma, if possible. we don't need to check more, since we
  2.2400 -	 * know that the transfer is always (at least!) 2KB aligned */
  2.2401 -	info->dma = drive->using_dma ? 1 : 0;
  2.2402 -	info->cmd = WRITE;
  2.2403 -
  2.2404 -	/* Start sending the read request to the drive. */
  2.2405 -	return cdrom_start_packet_command(drive, 32768, cdrom_start_write_cont);
  2.2406 +    struct cdrom_info *info = drive->driver_data;
  2.2407 +
  2.2408 +    /*
  2.2409 +     * writes *must* be 2kB frame aligned
  2.2410 +     */
  2.2411 +    if ((rq->nr_sectors & 3) || (rq->sector & 3)) {
  2.2412 +	cdrom_end_request(0, drive);
  2.2413 +	return ide_stopped;
  2.2414 +    }
  2.2415 +
  2.2416 +    /*
  2.2417 +     * for dvd-ram and such media, it's a really big deal to get
  2.2418 +     * big writes all the time. so scour the queue and attempt to
  2.2419 +     * remerge requests, often the plugging will not have had time
  2.2420 +     * to do this properly
  2.2421 +     */
  2.2422 +    cdrom_attempt_remerge(drive, rq);
  2.2423 +
  2.2424 +    info->nsectors_buffered = 0;
  2.2425 +
  2.2426 +    /* use dma, if possible. we don't need to check more, since we
  2.2427 +     * know that the transfer is always (at least!) 2KB aligned */
  2.2428 +    info->dma = drive->using_dma ? 1 : 0;
  2.2429 +    info->cmd = WRITE;
  2.2430 +
  2.2431 +    /* Start sending the read request to the drive. */
  2.2432 +    return cdrom_start_packet_command(drive, 32768, cdrom_start_write_cont);
  2.2433  }
  2.2434  
  2.2435  /****************************************************************************
  2.2436 @@ -1695,53 +1696,53 @@ static ide_startstop_t cdrom_start_write
  2.2437  static ide_startstop_t
  2.2438  ide_do_rw_cdrom (ide_drive_t *drive, struct request *rq, unsigned long block)
  2.2439  {
  2.2440 -	ide_startstop_t action;
  2.2441 -	struct cdrom_info *info = drive->driver_data;
  2.2442 -
  2.2443 -	switch (rq->cmd) {
  2.2444 -		case WRITE:
  2.2445 -		case READ: {
  2.2446 -			if (CDROM_CONFIG_FLAGS(drive)->seeking) {
  2.2447 -				unsigned long elpased = jiffies - info->start_seek;
  2.2448 -				int stat = GET_STAT();
  2.2449 -
  2.2450 -				if ((stat & SEEK_STAT) != SEEK_STAT) {
  2.2451 -					if (elpased < IDECD_SEEK_TIMEOUT) {
  2.2452 -						ide_stall_queue(drive, IDECD_SEEK_TIMER);
  2.2453 -						return ide_stopped;
  2.2454 -					}
  2.2455 -					printk ("%s: DSC timeout\n", drive->name);
  2.2456 -				}
  2.2457 -				CDROM_CONFIG_FLAGS(drive)->seeking = 0;
  2.2458 -			}
  2.2459 -			if (IDE_LARGE_SEEK(info->last_block, block, IDECD_SEEK_THRESHOLD) && drive->dsc_overlap)
  2.2460 -				action = cdrom_start_seek (drive, block);
  2.2461 -			else {
  2.2462 -				if (rq->cmd == READ)
  2.2463 -					action = cdrom_start_read(drive, block);
  2.2464 -				else
  2.2465 -					action = cdrom_start_write(drive, rq);
  2.2466 -			}
  2.2467 -			info->last_block = block;
  2.2468 -			return action;
  2.2469 +    ide_startstop_t action;
  2.2470 +    struct cdrom_info *info = drive->driver_data;
  2.2471 +
  2.2472 +    switch (rq->cmd) {
  2.2473 +    case WRITE:
  2.2474 +    case READ: {
  2.2475 +	if (CDROM_CONFIG_FLAGS(drive)->seeking) {
  2.2476 +	    unsigned long elpased = jiffies - info->start_seek;
  2.2477 +	    int stat = GET_STAT();
  2.2478 +
  2.2479 +	    if ((stat & SEEK_STAT) != SEEK_STAT) {
  2.2480 +		if (elpased < IDECD_SEEK_TIMEOUT) {
  2.2481 +		    ide_stall_queue(drive, IDECD_SEEK_TIMER);
  2.2482 +		    return ide_stopped;
  2.2483  		}
  2.2484 -
  2.2485 -		case PACKET_COMMAND:
  2.2486 -		case REQUEST_SENSE_COMMAND: {
  2.2487 -			return cdrom_do_packet_command(drive);
  2.2488 -		}
  2.2489 -
  2.2490 -		case RESET_DRIVE_COMMAND: {
  2.2491 -			cdrom_end_request(1, drive);
  2.2492 -			return ide_do_reset(drive);
  2.2493 -		}
  2.2494 -
  2.2495 -		default: {
  2.2496 -			printk("ide-cd: bad cmd %d\n", rq->cmd);
  2.2497 -			cdrom_end_request(0, drive);
  2.2498 -			return ide_stopped;
  2.2499 -		}
  2.2500 +		printk ("%s: DSC timeout\n", drive->name);
  2.2501 +	    }
  2.2502 +	    CDROM_CONFIG_FLAGS(drive)->seeking = 0;
  2.2503 +	}
  2.2504 +	if (IDE_LARGE_SEEK(info->last_block, block, IDECD_SEEK_THRESHOLD) && drive->dsc_overlap)
  2.2505 +	    action = cdrom_start_seek (drive, block);
  2.2506 +	else {
  2.2507 +	    if (rq->cmd == READ)
  2.2508 +		action = cdrom_start_read(drive, block);
  2.2509 +	    else
  2.2510 +		action = cdrom_start_write(drive, rq);
  2.2511  	}
  2.2512 +	info->last_block = block;
  2.2513 +	return action;
  2.2514 +    }
  2.2515 +
  2.2516 +    case PACKET_COMMAND:
  2.2517 +    case REQUEST_SENSE_COMMAND: {
  2.2518 +	return cdrom_do_packet_command(drive);
  2.2519 +    }
  2.2520 +
  2.2521 +    case RESET_DRIVE_COMMAND: {
  2.2522 +	cdrom_end_request(1, drive);
  2.2523 +	return ide_do_reset(drive);
  2.2524 +    }
  2.2525 +
  2.2526 +    default: {
  2.2527 +	printk("ide-cd: bad cmd %d\n", rq->cmd);
  2.2528 +	cdrom_end_request(0, drive);
  2.2529 +	return ide_stopped;
  2.2530 +    }
  2.2531 +    }
  2.2532  }
  2.2533  
  2.2534  
  2.2535 @@ -1760,22 +1761,22 @@ ide_do_rw_cdrom (ide_drive_t *drive, str
  2.2536  static inline
  2.2537  int bin2bcd (int x)
  2.2538  {
  2.2539 -	return (x%10) | ((x/10) << 4);
  2.2540 +    return (x%10) | ((x/10) << 4);
  2.2541  }
  2.2542  
  2.2543  
  2.2544  static inline
  2.2545  int bcd2bin (int x)
  2.2546  {
  2.2547 -	return (x >> 4) * 10 + (x & 0x0f);
  2.2548 +    return (x >> 4) * 10 + (x & 0x0f);
  2.2549  }
  2.2550  
  2.2551  static
  2.2552  void msf_from_bcd (struct atapi_msf *msf)
  2.2553  {
  2.2554 -	msf->minute = bcd2bin (msf->minute);
  2.2555 -	msf->second = bcd2bin (msf->second);
  2.2556 -	msf->frame  = bcd2bin (msf->frame);
  2.2557 +    msf->minute = bcd2bin (msf->minute);
  2.2558 +    msf->second = bcd2bin (msf->second);
  2.2559 +    msf->frame  = bcd2bin (msf->frame);
  2.2560  }
  2.2561  
  2.2562  #endif /* not STANDARD_ATAPI */
  2.2563 @@ -1784,40 +1785,40 @@ void msf_from_bcd (struct atapi_msf *msf
  2.2564  static inline
  2.2565  void lba_to_msf (int lba, byte *m, byte *s, byte *f)
  2.2566  {
  2.2567 -	lba += CD_MSF_OFFSET;
  2.2568 -	lba &= 0xffffff;  /* negative lbas use only 24 bits */
  2.2569 -	*m = lba / (CD_SECS * CD_FRAMES);
  2.2570 -	lba %= (CD_SECS * CD_FRAMES);
  2.2571 -	*s = lba / CD_FRAMES;
  2.2572 -	*f = lba % CD_FRAMES;
  2.2573 +    lba += CD_MSF_OFFSET;
  2.2574 +    lba &= 0xffffff;  /* negative lbas use only 24 bits */
  2.2575 +    *m = lba / (CD_SECS * CD_FRAMES);
  2.2576 +    lba %= (CD_SECS * CD_FRAMES);
  2.2577 +    *s = lba / CD_FRAMES;
  2.2578 +    *f = lba % CD_FRAMES;
  2.2579  }
  2.2580  
  2.2581  
  2.2582  static inline
  2.2583  int msf_to_lba (byte m, byte s, byte f)
  2.2584  {
  2.2585 -	return (((m * CD_SECS) + s) * CD_FRAMES + f) - CD_MSF_OFFSET;
  2.2586 +    return (((m * CD_SECS) + s) * CD_FRAMES + f) - CD_MSF_OFFSET;
  2.2587  }
  2.2588  
  2.2589  static int cdrom_check_status(ide_drive_t *drive, struct request_sense *sense)
  2.2590  {
  2.2591 -	struct packet_command pc;
  2.2592 -	struct cdrom_info *info = drive->driver_data;
  2.2593 -	struct cdrom_device_info *cdi = &info->devinfo;
  2.2594 -
  2.2595 -	memset(&pc, 0, sizeof(pc));
  2.2596 -	pc.sense = sense;
  2.2597 -
  2.2598 -	pc.c[0] = GPCMD_TEST_UNIT_READY;
  2.2599 +    struct packet_command pc;
  2.2600 +    struct cdrom_info *info = drive->driver_data;
  2.2601 +    struct cdrom_device_info *cdi = &info->devinfo;
  2.2602 +
  2.2603 +    memset(&pc, 0, sizeof(pc));
  2.2604 +    pc.sense = sense;
  2.2605 +
  2.2606 +    pc.c[0] = GPCMD_TEST_UNIT_READY;
  2.2607  
  2.2608  #if ! STANDARD_ATAPI
  2.2609 -        /* the Sanyo 3 CD changer uses byte 7 of TEST_UNIT_READY to 
  2.2610 -           switch CDs instead of supporting the LOAD_UNLOAD opcode   */
  2.2611 -
  2.2612 -        pc.c[7] = cdi->sanyo_slot % 3;
  2.2613 +    /* the Sanyo 3 CD changer uses byte 7 of TEST_UNIT_READY to 
  2.2614 +       switch CDs instead of supporting the LOAD_UNLOAD opcode   */
  2.2615 +
  2.2616 +    pc.c[7] = cdi->sanyo_slot % 3;
  2.2617  #endif /* not STANDARD_ATAPI */
  2.2618  
  2.2619 -	return cdrom_queue_packet_command(drive, &pc);
  2.2620 +    return cdrom_queue_packet_command(drive, &pc);
  2.2621  }
  2.2622  
  2.2623  
  2.2624 @@ -1825,43 +1826,43 @@ static int cdrom_check_status(ide_drive_
  2.2625  static int
  2.2626  cdrom_lockdoor(ide_drive_t *drive, int lockflag, struct request_sense *sense)
  2.2627  {
  2.2628 -	struct request_sense my_sense;
  2.2629 -	struct packet_command pc;
  2.2630 -	int stat;
  2.2631 -
  2.2632 -	if (sense == NULL)
  2.2633 -		sense = &my_sense;
  2.2634 -
  2.2635 -	/* If the drive cannot lock the door, just pretend. */
  2.2636 -	if (CDROM_CONFIG_FLAGS(drive)->no_doorlock) {
  2.2637 -		stat = 0;
  2.2638 -	} else {
  2.2639 -		memset(&pc, 0, sizeof(pc));
  2.2640 -		pc.sense = sense;
  2.2641 -		pc.c[0] = GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL;
  2.2642 -		pc.c[4] = lockflag ? 1 : 0;
  2.2643 -		stat = cdrom_queue_packet_command (drive, &pc);
  2.2644 -	}
  2.2645 -
  2.2646 -	/* If we got an illegal field error, the drive
  2.2647 -	   probably cannot lock the door. */
  2.2648 -	if (stat != 0 &&
  2.2649 -	    sense->sense_key == ILLEGAL_REQUEST &&
  2.2650 -	    (sense->asc == 0x24 || sense->asc == 0x20)) {
  2.2651 -		printk ("%s: door locking not supported\n",
  2.2652 -			drive->name);
  2.2653 -		CDROM_CONFIG_FLAGS (drive)->no_doorlock = 1;
  2.2654 -		stat = 0;
  2.2655 -	}
  2.2656 +    struct request_sense my_sense;
  2.2657 +    struct packet_command pc;
  2.2658 +    int stat;
  2.2659 +
  2.2660 +    if (sense == NULL)
  2.2661 +	sense = &my_sense;
  2.2662 +
  2.2663 +    /* If the drive cannot lock the door, just pretend. */
  2.2664 +    if (CDROM_CONFIG_FLAGS(drive)->no_doorlock) {
  2.2665 +	stat = 0;
  2.2666 +    } else {
  2.2667 +	memset(&pc, 0, sizeof(pc));
  2.2668 +	pc.sense = sense;
  2.2669 +	pc.c[0] = GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL;
  2.2670 +	pc.c[4] = lockflag ? 1 : 0;
  2.2671 +	stat = cdrom_queue_packet_command (drive, &pc);
  2.2672 +    }
  2.2673 +
  2.2674 +    /* If we got an illegal field error, the drive
  2.2675 +       probably cannot lock the door. */
  2.2676 +    if (stat != 0 &&
  2.2677 +	sense->sense_key == ILLEGAL_REQUEST &&
  2.2678 +	(sense->asc == 0x24 || sense->asc == 0x20)) {
  2.2679 +	printk ("%s: door locking not supported\n",
  2.2680 +		drive->name);
  2.2681 +	CDROM_CONFIG_FLAGS (drive)->no_doorlock = 1;
  2.2682 +	stat = 0;
  2.2683 +    }
  2.2684  	
  2.2685 -	/* no medium, that's alright. */
  2.2686 -	if (stat != 0 && sense->sense_key == NOT_READY && sense->asc == 0x3a)
  2.2687 -		stat = 0;
  2.2688 -
  2.2689 -	if (stat == 0)
  2.2690 -		CDROM_STATE_FLAGS (drive)->door_locked = lockflag;
  2.2691 -
  2.2692 -	return stat;
  2.2693 +    /* no medium, that's alright. */
  2.2694 +    if (stat != 0 && sense->sense_key == NOT_READY && sense->asc == 0x3a)
  2.2695 +	stat = 0;
  2.2696 +
  2.2697 +    if (stat == 0)
  2.2698 +	CDROM_STATE_FLAGS (drive)->door_locked = lockflag;
  2.2699 +
  2.2700 +    return stat;
  2.2701  }
  2.2702  
  2.2703  
  2.2704 @@ -1870,245 +1871,245 @@ cdrom_lockdoor(ide_drive_t *drive, int l
  2.2705  static int cdrom_eject(ide_drive_t *drive, int ejectflag,
  2.2706  		       struct request_sense *sense)
  2.2707  {
  2.2708 -	struct packet_command pc;
  2.2709 -
  2.2710 -	if (CDROM_CONFIG_FLAGS(drive)->no_eject && !ejectflag)
  2.2711 -		return -EDRIVE_CANT_DO_THIS;
  2.2712 +    struct packet_command pc;
  2.2713 +
  2.2714 +    if (CDROM_CONFIG_FLAGS(drive)->no_eject && !ejectflag)
  2.2715 +	return -EDRIVE_CANT_DO_THIS;
  2.2716  	
  2.2717 -	/* reload fails on some drives, if the tray is locked */
  2.2718 -	if (CDROM_STATE_FLAGS(drive)->door_locked && ejectflag)
  2.2719 -		return 0;
  2.2720 -
  2.2721 -	memset(&pc, 0, sizeof (pc));
  2.2722 -	pc.sense = sense;
  2.2723 -
  2.2724 -	pc.c[0] = GPCMD_START_STOP_UNIT;
  2.2725 -	pc.c[4] = 0x02 + (ejectflag != 0);
  2.2726 -	return cdrom_queue_packet_command (drive, &pc);
  2.2727 +    /* reload fails on some drives, if the tray is locked */
  2.2728 +    if (CDROM_STATE_FLAGS(drive)->door_locked && ejectflag)
  2.2729 +	return 0;
  2.2730 +
  2.2731 +    memset(&pc, 0, sizeof (pc));
  2.2732 +    pc.sense = sense;
  2.2733 +
  2.2734 +    pc.c[0] = GPCMD_START_STOP_UNIT;
  2.2735 +    pc.c[4] = 0x02 + (ejectflag != 0);
  2.2736 +    return cdrom_queue_packet_command (drive, &pc);
  2.2737  }
  2.2738  
  2.2739  static int cdrom_read_capacity(ide_drive_t *drive, unsigned long *capacity,
  2.2740  			       struct request_sense *sense)
  2.2741  {
  2.2742 -	struct {
  2.2743 -		__u32 lba;
  2.2744 -		__u32 blocklen;
  2.2745 -	} capbuf;
  2.2746 -
  2.2747 -	int stat;
  2.2748 -	struct packet_command pc;
  2.2749 -
  2.2750 -	memset(&pc, 0, sizeof(pc));
  2.2751 -	pc.sense = sense;
  2.2752 -
  2.2753 -	pc.c[0] = GPCMD_READ_CDVD_CAPACITY;
  2.2754 -	pc.buffer = (char *)&capbuf;
  2.2755 -	pc.buflen = sizeof(capbuf);
  2.2756 -
  2.2757 -	stat = cdrom_queue_packet_command(drive, &pc);
  2.2758 -	if (stat == 0)
  2.2759 -		*capacity = 1 + be32_to_cpu(capbuf.lba);
  2.2760 -
  2.2761 -	return stat;
  2.2762 +    struct {
  2.2763 +	__u32 lba;
  2.2764 +	__u32 blocklen;
  2.2765 +    } capbuf;
  2.2766 +
  2.2767 +    int stat;
  2.2768 +    struct packet_command pc;
  2.2769 +
  2.2770 +    memset(&pc, 0, sizeof(pc));
  2.2771 +    pc.sense = sense;
  2.2772 +
  2.2773 +    pc.c[0] = GPCMD_READ_CDVD_CAPACITY;
  2.2774 +    pc.buffer = (char *)&capbuf;
  2.2775 +    pc.buflen = sizeof(capbuf);
  2.2776 +
  2.2777 +    stat = cdrom_queue_packet_command(drive, &pc);
  2.2778 +    if (stat == 0)
  2.2779 +	*capacity = 1 + be32_to_cpu(capbuf.lba);
  2.2780 +
  2.2781 +    return stat;
  2.2782  }
  2.2783  
  2.2784  static int cdrom_read_tocentry(ide_drive_t *drive, int trackno, int msf_flag,
  2.2785 -				int format, char *buf, int buflen,
  2.2786 -				struct request_sense *sense)
  2.2787 +			       int format, char *buf, int buflen,
  2.2788 +			       struct request_sense *sense)
  2.2789  {
  2.2790 -	struct packet_command pc;
  2.2791 -
  2.2792 -	memset(&pc, 0, sizeof(pc));
  2.2793 -	pc.sense = sense;
  2.2794 -
  2.2795 -	pc.buffer =  buf;
  2.2796 -	pc.buflen = buflen;
  2.2797 -	pc.quiet = 1;
  2.2798 -	pc.c[0] = GPCMD_READ_TOC_PMA_ATIP;
  2.2799 -	pc.c[6] = trackno;
  2.2800 -	pc.c[7] = (buflen >> 8);
  2.2801 -	pc.c[8] = (buflen & 0xff);
  2.2802 -	pc.c[9] = (format << 6);
  2.2803 -
  2.2804 -	if (msf_flag)
  2.2805 -		pc.c[1] = 2;
  2.2806 -
  2.2807 -	return cdrom_queue_packet_command (drive, &pc);
  2.2808 +    struct packet_command pc;
  2.2809 +
  2.2810 +    memset(&pc, 0, sizeof(pc));
  2.2811 +    pc.sense = sense;
  2.2812 +
  2.2813 +    pc.buffer =  buf;
  2.2814 +    pc.buflen = buflen;
  2.2815 +    pc.quiet = 1;
  2.2816 +    pc.c[0] = GPCMD_READ_TOC_PMA_ATIP;
  2.2817 +    pc.c[6] = trackno;
  2.2818 +    pc.c[7] = (buflen >> 8);
  2.2819 +    pc.c[8] = (buflen & 0xff);
  2.2820 +    pc.c[9] = (format << 6);
  2.2821 +
  2.2822 +    if (msf_flag)
  2.2823 +	pc.c[1] = 2;
  2.2824 +
  2.2825 +    return cdrom_queue_packet_command (drive, &pc);
  2.2826  }
  2.2827  
  2.2828  
  2.2829  /* Try to read the entire TOC for the disk into our internal buffer. */
  2.2830  static int cdrom_read_toc(ide_drive_t *drive, struct request_sense *sense)
  2.2831  {
  2.2832 -	int minor, stat, ntracks, i;
  2.2833 -	kdev_t dev;
  2.2834 -	struct cdrom_info *info = drive->driver_data;
  2.2835 -	struct atapi_toc *toc = info->toc;
  2.2836 -	struct {
  2.2837 -		struct atapi_toc_header hdr;
  2.2838 -		struct atapi_toc_entry  ent;
  2.2839 -	} ms_tmp;
  2.2840 -
  2.2841 +    int minor, stat, ntracks, i;
  2.2842 +    kdev_t dev;
  2.2843 +    struct cdrom_info *info = drive->driver_data;
  2.2844 +    struct atapi_toc *toc = info->toc;
  2.2845 +    struct {
  2.2846 +	struct atapi_toc_header hdr;
  2.2847 +	struct atapi_toc_entry  ent;
  2.2848 +    } ms_tmp;
  2.2849 +
  2.2850 +    if (toc == NULL) {
  2.2851 +	/* Try to allocate space. */
  2.2852 +	toc = (struct atapi_toc *) kmalloc (sizeof (struct atapi_toc),
  2.2853 +					    GFP_KERNEL);
  2.2854 +	info->toc = toc;
  2.2855  	if (toc == NULL) {
  2.2856 -		/* Try to allocate space. */
  2.2857 -		toc = (struct atapi_toc *) kmalloc (sizeof (struct atapi_toc),
  2.2858 -						    GFP_KERNEL);
  2.2859 -		info->toc = toc;
  2.2860 -		if (toc == NULL) {
  2.2861 -			printk ("%s: No cdrom TOC buffer!\n", drive->name);
  2.2862 -			return -ENOMEM;
  2.2863 -		}
  2.2864 +	    printk ("%s: No cdrom TOC buffer!\n", drive->name);
  2.2865 +	    return -ENOMEM;
  2.2866  	}
  2.2867 -
  2.2868 -	/* Check to see if the existing data is still valid.
  2.2869 -	   If it is, just return. */
  2.2870 -	(void) cdrom_check_status(drive, sense);
  2.2871 -
  2.2872 -	if (CDROM_STATE_FLAGS(drive)->toc_valid)
  2.2873 -		return 0;
  2.2874 -
  2.2875 -	/* First read just the header, so we know how long the TOC is. */
  2.2876 -	stat = cdrom_read_tocentry(drive, 0, 1, 0, (char *) &toc->hdr,
  2.2877 -				    sizeof(struct atapi_toc_header), sense);
  2.2878 -	if (stat) return stat;
  2.2879 +    }
  2.2880 +
  2.2881 +    /* Check to see if the existing data is still valid.
  2.2882 +       If it is, just return. */
  2.2883 +    (void) cdrom_check_status(drive, sense);
  2.2884 +
  2.2885 +    if (CDROM_STATE_FLAGS(drive)->toc_valid)
  2.2886 +	return 0;
  2.2887 +
  2.2888 +    /* First read just the header, so we know how long the TOC is. */
  2.2889 +    stat = cdrom_read_tocentry(drive, 0, 1, 0, (char *) &toc->hdr,
  2.2890 +			       sizeof(struct atapi_toc_header), sense);
  2.2891 +    if (stat) return stat;
  2.2892  
  2.2893  #if ! STANDARD_ATAPI
  2.2894 -	if (CDROM_CONFIG_FLAGS (drive)->toctracks_as_bcd) {
  2.2895 -		toc->hdr.first_track = bcd2bin (toc->hdr.first_track);
  2.2896 -		toc->hdr.last_track  = bcd2bin (toc->hdr.last_track);
  2.2897 -	}
  2.2898 +    if (CDROM_CONFIG_FLAGS (drive)->toctracks_as_bcd) {
  2.2899 +	toc->hdr.first_track = bcd2bin (toc->hdr.first_track);
  2.2900 +	toc->hdr.last_track  = bcd2bin (toc->hdr.last_track);
  2.2901 +    }
  2.2902  #endif  /* not STANDARD_ATAPI */
  2.2903  
  2.2904 -	ntracks = toc->hdr.last_track - toc->hdr.first_track + 1;
  2.2905 -	if (ntracks <= 0)
  2.2906 -		return -EIO;
  2.2907 -	if (ntracks > MAX_TRACKS)
  2.2908 -		ntracks = MAX_TRACKS;
  2.2909 -
  2.2910 -	/* Now read the whole schmeer. */
  2.2911 -	stat = cdrom_read_tocentry(drive, toc->hdr.first_track, 1, 0,
  2.2912 -				  (char *)&toc->hdr,
  2.2913 +    ntracks = toc->hdr.last_track - toc->hdr.first_track + 1;
  2.2914 +    if (ntracks <= 0)
  2.2915 +	return -EIO;
  2.2916 +    if (ntracks > MAX_TRACKS)
  2.2917 +	ntracks = MAX_TRACKS;
  2.2918 +
  2.2919 +    /* Now read the whole schmeer. */
  2.2920 +    stat = cdrom_read_tocentry(drive, toc->hdr.first_track, 1, 0,
  2.2921 +			       (char *)&toc->hdr,
  2.2922 +			       sizeof(struct atapi_toc_header) +
  2.2923 +			       (ntracks + 1) *
  2.2924 +			       sizeof(struct atapi_toc_entry), sense);
  2.2925 +
  2.2926 +    if (stat && toc->hdr.first_track > 1) {
  2.2927 +	/* Cds with CDI tracks only don't have any TOC entries,
  2.2928 +	   despite of this the returned values are
  2.2929 +	   first_track == last_track = number of CDI tracks + 1,
  2.2930 +	   so that this case is indistinguishable from the same
  2.2931 +	   layout plus an additional audio track.
  2.2932 +	   If we get an error for the regular case, we assume
  2.2933 +	   a CDI without additional audio tracks. In this case
  2.2934 +	   the readable TOC is empty (CDI tracks are not included)
  2.2935 +	   and only holds the Leadout entry. Heiko Ei▀feldt */
  2.2936 +	ntracks = 0;
  2.2937 +	stat = cdrom_read_tocentry(drive, CDROM_LEADOUT, 1, 0,
  2.2938 +				   (char *)&toc->hdr,
  2.2939  				   sizeof(struct atapi_toc_header) +
  2.2940  				   (ntracks + 1) *
  2.2941 -				   sizeof(struct atapi_toc_entry), sense);
  2.2942 -
  2.2943 -	if (stat && toc->hdr.first_track > 1) {
  2.2944 -		/* Cds with CDI tracks only don't have any TOC entries,
  2.2945 -		   despite of this the returned values are
  2.2946 -		   first_track == last_track = number of CDI tracks + 1,
  2.2947 -		   so that this case is indistinguishable from the same
  2.2948 -		   layout plus an additional audio track.
  2.2949 -		   If we get an error for the regular case, we assume
  2.2950 -		   a CDI without additional audio tracks. In this case
  2.2951 -		   the readable TOC is empty (CDI tracks are not included)
  2.2952 -		   and only holds the Leadout entry. Heiko Ei▀feldt */
  2.2953 -		ntracks = 0;
  2.2954 -		stat = cdrom_read_tocentry(drive, CDROM_LEADOUT, 1, 0,
  2.2955 -					   (char *)&toc->hdr,
  2.2956 -					   sizeof(struct atapi_toc_header) +
  2.2957 -					   (ntracks + 1) *
  2.2958 -					   sizeof(struct atapi_toc_entry),
  2.2959 -					   sense);
  2.2960 -		if (stat) {
  2.2961 -			return stat;
  2.2962 -		}
  2.2963 +				   sizeof(struct atapi_toc_entry),
  2.2964 +				   sense);
  2.2965 +	if (stat) {
  2.2966 +	    return stat;
  2.2967 +	}
  2.2968  #if ! STANDARD_ATAPI
  2.2969 -		if (CDROM_CONFIG_FLAGS (drive)->toctracks_as_bcd) {
  2.2970 -			toc->hdr.first_track = bin2bcd(CDROM_LEADOUT);
  2.2971 -			toc->hdr.last_track = bin2bcd(CDROM_LEADOUT);
  2.2972 -		} else
  2.2973 +	if (CDROM_CONFIG_FLAGS (drive)->toctracks_as_bcd) {
  2.2974 +	    toc->hdr.first_track = bin2bcd(CDROM_LEADOUT);
  2.2975 +	    toc->hdr.last_track = bin2bcd(CDROM_LEADOUT);
  2.2976 +	} else
  2.2977  #endif  /* not STANDARD_ATAPI */
  2.2978 -		{
  2.2979 -			toc->hdr.first_track = CDROM_LEADOUT;
  2.2980 -			toc->hdr.last_track = CDROM_LEADOUT;
  2.2981 -		}
  2.2982 +	{
  2.2983 +	    toc->hdr.first_track = CDROM_LEADOUT;
  2.2984 +	    toc->hdr.last_track = CDROM_LEADOUT;
  2.2985  	}
  2.2986 -
  2.2987 -	if (stat)
  2.2988 -		return stat;
  2.2989 -
  2.2990 -	toc->hdr.toc_length = ntohs (toc->hdr.toc_length);
  2.2991 +    }
  2.2992 +
  2.2993 +    if (stat)
  2.2994 +	return stat;
  2.2995 +
  2.2996 +    toc->hdr.toc_length = ntohs (toc->hdr.toc_length);
  2.2997  
  2.2998  #if ! STANDARD_ATAPI
  2.2999 -	if (CDROM_CONFIG_FLAGS (drive)->toctracks_as_bcd) {
  2.3000 -		toc->hdr.first_track = bcd2bin (toc->hdr.first_track);
  2.3001 -		toc->hdr.last_track  = bcd2bin (toc->hdr.last_track);
  2.3002 +    if (CDROM_CONFIG_FLAGS (drive)->toctracks_as_bcd) {
  2.3003 +	toc->hdr.first_track = bcd2bin (toc->hdr.first_track);
  2.3004 +	toc->hdr.last_track  = bcd2bin (toc->hdr.last_track);
  2.3005 +    }
  2.3006 +#endif  /* not STANDARD_ATAPI */
  2.3007 +
  2.3008 +    for (i=0; i<=ntracks; i++) {
  2.3009 +#if ! STANDARD_ATAPI
  2.3010 +	if (CDROM_CONFIG_FLAGS (drive)->tocaddr_as_bcd) {
  2.3011 +	    if (CDROM_CONFIG_FLAGS (drive)->toctracks_as_bcd)
  2.3012 +		toc->ent[i].track = bcd2bin (toc->ent[i].track);
  2.3013 +	    msf_from_bcd (&toc->ent[i].addr.msf);
  2.3014  	}
  2.3015  #endif  /* not STANDARD_ATAPI */
  2.3016 -
  2.3017 -	for (i=0; i<=ntracks; i++) {
  2.3018 -#if ! STANDARD_ATAPI
  2.3019 -		if (CDROM_CONFIG_FLAGS (drive)->tocaddr_as_bcd) {
  2.3020 -			if (CDROM_CONFIG_FLAGS (drive)->toctracks_as_bcd)
  2.3021 -				toc->ent[i].track = bcd2bin (toc->ent[i].track);
  2.3022 -			msf_from_bcd (&toc->ent[i].addr.msf);
  2.3023 -		}
  2.3024 -#endif  /* not STANDARD_ATAPI */
  2.3025 -		toc->ent[i].addr.lba = msf_to_lba (toc->ent[i].addr.msf.minute,
  2.3026 -						   toc->ent[i].addr.msf.second,
  2.3027 -						   toc->ent[i].addr.msf.frame);
  2.3028 -	}
  2.3029 -
  2.3030 +	toc->ent[i].addr.lba = msf_to_lba (toc->ent[i].addr.msf.minute,
  2.3031 +					   toc->ent[i].addr.msf.second,
  2.3032 +					   toc->ent[i].addr.msf.frame);
  2.3033 +    }
  2.3034 +
  2.3035 +    /* Read the multisession information. */
  2.3036 +    if (toc->hdr.first_track != CDROM_LEADOUT) {
  2.3037  	/* Read the multisession information. */
  2.3038 -	if (toc->hdr.first_track != CDROM_LEADOUT) {
  2.3039 -		/* Read the multisession information. */
  2.3040 -		stat = cdrom_read_tocentry(drive, 0, 1, 1, (char *)&ms_tmp,
  2.3041 -					   sizeof(ms_tmp), sense);
  2.3042 -		if (stat) return stat;
  2.3043 -	} else {
  2.3044 -		ms_tmp.ent.addr.msf.minute = 0;
  2.3045 -		ms_tmp.ent.addr.msf.second = 2;
  2.3046 -		ms_tmp.ent.addr.msf.frame  = 0;
  2.3047 -		ms_tmp.hdr.first_track = ms_tmp.hdr.last_track = CDROM_LEADOUT;
  2.3048 -	}
  2.3049 +	stat = cdrom_read_tocentry(drive, 0, 1, 1, (char *)&ms_tmp,
  2.3050 +				   sizeof(ms_tmp), sense);
  2.3051 +	if (stat) return stat;
  2.3052 +    } else {
  2.3053 +	ms_tmp.ent.addr.msf.minute = 0;
  2.3054 +	ms_tmp.ent.addr.msf.second = 2;
  2.3055 +	ms_tmp.ent.addr.msf.frame  = 0;
  2.3056 +	ms_tmp.hdr.first_track = ms_tmp.hdr.last_track = CDROM_LEADOUT;
  2.3057 +    }
  2.3058  
  2.3059  #if ! STANDARD_ATAPI
  2.3060 -	if (CDROM_CONFIG_FLAGS (drive)->tocaddr_as_bcd)
  2.3061 -		msf_from_bcd (&ms_tmp.ent.addr.msf);
  2.3062 +    if (CDROM_CONFIG_FLAGS (drive)->tocaddr_as_bcd)
  2.3063 +	msf_from_bcd (&ms_tmp.ent.addr.msf);
  2.3064  #endif  /* not STANDARD_ATAPI */
  2.3065  
  2.3066 -	toc->last_session_lba = msf_to_lba (ms_tmp.ent.addr.msf.minute,
  2.3067 -					    ms_tmp.ent.addr.msf.second,
  2.3068 -					    ms_tmp.ent.addr.msf.frame);
  2.3069 -
  2.3070 -	toc->xa_flag = (ms_tmp.hdr.first_track != ms_tmp.hdr.last_track);
  2.3071 -
  2.3072 -	/* Now try to get the total cdrom capacity. */
  2.3073 -	minor = (drive->select.b.unit) << PARTN_BITS;
  2.3074 -	dev = MKDEV(HWIF(drive)->major, minor);
  2.3075 -	stat = cdrom_get_last_written(dev, &toc->capacity);
  2.3076 -	if (stat)
  2.3077 -		stat = cdrom_read_capacity(drive, &toc->capacity, sense);
  2.3078 -	if (stat)
  2.3079 -		toc->capacity = 0x1fffff;
  2.3080 -
  2.3081 -	HWIF(drive)->gd->sizes[drive->select.b.unit << PARTN_BITS] = (toc->capacity * SECTORS_PER_FRAME) >> (BLOCK_SIZE_BITS - 9);
  2.3082 -	drive->part[0].nr_sects = toc->capacity * SECTORS_PER_FRAME;
  2.3083 -
  2.3084 -	/* Remember that we've read this stuff. */
  2.3085 -	CDROM_STATE_FLAGS (drive)->toc_valid = 1;
  2.3086 -
  2.3087 -	return 0;
  2.3088 +    toc->last_session_lba = msf_to_lba (ms_tmp.ent.addr.msf.minute,
  2.3089 +					ms_tmp.ent.addr.msf.second,
  2.3090 +					ms_tmp.ent.addr.msf.frame);
  2.3091 +
  2.3092 +    toc->xa_flag = (ms_tmp.hdr.first_track != ms_tmp.hdr.last_track);
  2.3093 +
  2.3094 +    /* Now try to get the total cdrom capacity. */
  2.3095 +    minor = (drive->select.b.unit) << PARTN_BITS;
  2.3096 +    dev = MKDEV(HWIF(drive)->major, minor);
  2.3097 +    stat = cdrom_get_last_written(dev, &toc->capacity);
  2.3098 +    if (stat)
  2.3099 +	stat = cdrom_read_capacity(drive, &toc->capacity, sense);
  2.3100 +    if (stat)
  2.3101 +	toc->capacity = 0x1fffff;
  2.3102 +
  2.3103 +    HWIF(drive)->gd->sizes[drive->select.b.unit << PARTN_BITS] = (toc->capacity * SECTORS_PER_FRAME) >> (BLOCK_SIZE_BITS - 9);
  2.3104 +    drive->part[0].nr_sects = toc->capacity * SECTORS_PER_FRAME;
  2.3105 +
  2.3106 +    /* Remember that we've read this stuff. */
  2.3107 +    CDROM_STATE_FLAGS (drive)->toc_valid = 1;
  2.3108 +
  2.3109 +    return 0;
  2.3110  }
  2.3111  
  2.3112  
  2.3113  static int cdrom_read_subchannel(ide_drive_t *drive, int format, char *buf,
  2.3114  				 int buflen, struct request_sense *sense)
  2.3115  {
  2.3116 -	struct packet_command pc;
  2.3117 -
  2.3118 -	memset(&pc, 0, sizeof(pc));
  2.3119 -	pc.sense = sense;
  2.3120 -
  2.3121 -	pc.buffer = buf;
  2.3122 -	pc.buflen = buflen;
  2.3123 -	pc.c[0] = GPCMD_READ_SUBCHANNEL;
  2.3124 -	pc.c[1] = 2;     /* MSF addressing */
  2.3125 -	pc.c[2] = 0x40;  /* request subQ data */
  2.3126 -	pc.c[3] = format;
  2.3127 -	pc.c[7] = (buflen >> 8);
  2.3128 -	pc.c[8] = (buflen & 0xff);
  2.3129 -	return cdrom_queue_packet_command(drive, &pc);
  2.3130 +    struct packet_command pc;
  2.3131 +
  2.3132 +    memset(&pc, 0, sizeof(pc));
  2.3133 +    pc.sense = sense;
  2.3134 +
  2.3135 +    pc.buffer = buf;
  2.3136 +    pc.buflen = buflen;
  2.3137 +    pc.c[0] = GPCMD_READ_SUBCHANNEL;
  2.3138 +    pc.c[1] = 2;     /* MSF addressing */
  2.3139 +    pc.c[2] = 0x40;  /* request subQ data */
  2.3140 +    pc.c[3] = format;
  2.3141 +    pc.c[7] = (buflen >> 8);
  2.3142 +    pc.c[8] = (buflen & 0xff);
  2.3143 +    return cdrom_queue_packet_command(drive, &pc);
  2.3144  }
  2.3145  
  2.3146  /* ATAPI cdrom drives are free to select the speed you request or any slower
  2.3147 @@ -2116,140 +2117,140 @@ static int cdrom_read_subchannel(ide_dri
  2.3148  static int cdrom_select_speed(ide_drive_t *drive, int speed,
  2.3149  			      struct request_sense *sense)
  2.3150  {
  2.3151 -	struct packet_command pc;
  2.3152 -	memset(&pc, 0, sizeof(pc));
  2.3153 -	pc.sense = sense;
  2.3154 -
  2.3155 -	if (speed == 0)
  2.3156 -		speed = 0xffff; /* set to max */
  2.3157 -	else
  2.3158 -		speed *= 177;   /* Nx to kbytes/s */
  2.3159 -
  2.3160 -	pc.c[0] = GPCMD_SET_SPEED;
  2.3161 -	/* Read Drive speed in kbytes/second MSB */
  2.3162 -	pc.c[2] = (speed >> 8) & 0xff;	
  2.3163 -	/* Read Drive speed in kbytes/second LSB */
  2.3164 -	pc.c[3] = speed & 0xff;
  2.3165 -	if (CDROM_CONFIG_FLAGS(drive)->cd_r ||
  2.3166 -	    CDROM_CONFIG_FLAGS(drive)->cd_rw ||
  2.3167 -	    CDROM_CONFIG_FLAGS(drive)->dvd_r) {
  2.3168 -		/* Write Drive speed in kbytes/second MSB */
  2.3169 -		pc.c[4] = (speed >> 8) & 0xff;
  2.3170 -		/* Write Drive speed in kbytes/second LSB */
  2.3171 -		pc.c[5] = speed & 0xff;
  2.3172 -       }
  2.3173 -
  2.3174 -	return cdrom_queue_packet_command(drive, &pc);
  2.3175 +    struct packet_command pc;
  2.3176 +    memset(&pc, 0, sizeof(pc));
  2.3177 +    pc.sense = sense;
  2.3178 +
  2.3179 +    if (speed == 0)
  2.3180 +	speed = 0xffff; /* set to max */
  2.3181 +    else
  2.3182 +	speed *= 177;   /* Nx to kbytes/s */
  2.3183 +
  2.3184 +    pc.c[0] = GPCMD_SET_SPEED;
  2.3185 +    /* Read Drive speed in kbytes/second MSB */
  2.3186 +    pc.c[2] = (speed >> 8) & 0xff;	
  2.3187 +    /* Read Drive speed in kbytes/second LSB */
  2.3188 +    pc.c[3] = speed & 0xff;
  2.3189 +    if (CDROM_CONFIG_FLAGS(drive)->cd_r ||
  2.3190 +	CDROM_CONFIG_FLAGS(drive)->cd_rw ||
  2.3191 +	CDROM_CONFIG_FLAGS(drive)->dvd_r) {
  2.3192 +	/* Write Drive speed in kbytes/second MSB */
  2.3193 +	pc.c[4] = (speed >> 8) & 0xff;
  2.3194 +	/* Write Drive speed in kbytes/second LSB */
  2.3195 +	pc.c[5] = speed & 0xff;
  2.3196 +    }
  2.3197 +
  2.3198 +    return cdrom_queue_packet_command(drive, &pc);
  2.3199  }
  2.3200  
  2.3201  static int cdrom_play_audio(ide_drive_t *drive, int lba_start, int lba_end)
  2.3202  {
  2.3203 -	struct request_sense sense;
  2.3204 -	struct packet_command pc;
  2.3205 -
  2.3206 -	memset(&pc, 0, sizeof (pc));
  2.3207 -	pc.sense = &sense;
  2.3208 -
  2.3209 -	pc.c[0] = GPCMD_PLAY_AUDIO_MSF;
  2.3210 -	lba_to_msf(lba_start, &pc.c[3], &pc.c[4], &pc.c[5]);
  2.3211 -	lba_to_msf(lba_end-1, &pc.c[6], &pc.c[7], &pc.c[8]);
  2.3212 -
  2.3213 -	return cdrom_queue_packet_command(drive, &pc);
  2.3214 +    struct request_sense sense;
  2.3215 +    struct packet_command pc;
  2.3216 +
  2.3217 +    memset(&pc, 0, sizeof (pc));
  2.3218 +    pc.sense = &sense;
  2.3219 +
  2.3220 +    pc.c[0] = GPCMD_PLAY_AUDIO_MSF;
  2.3221 +    lba_to_msf(lba_start, &pc.c[3], &pc.c[4], &pc.c[5]);
  2.3222 +    lba_to_msf(lba_end-1, &pc.c[6], &pc.c[7], &pc.c[8]);
  2.3223 +
  2.3224 +    return cdrom_queue_packet_command(drive, &pc);
  2.3225  }
  2.3226  
  2.3227  static int cdrom_get_toc_entry(ide_drive_t *drive, int track,
  2.3228 -				struct atapi_toc_entry **ent)
  2.3229 +			       struct atapi_toc_entry **ent)
  2.3230  {
  2.3231 -	struct cdrom_info *info = drive->driver_data;
  2.3232 -	struct atapi_toc *toc = info->toc;
  2.3233 -	int ntracks;
  2.3234 -
  2.3235 -	/*
  2.3236 -	 * don't serve cached data, if the toc isn't valid
  2.3237 -	 */
  2.3238 -	if (!CDROM_STATE_FLAGS(drive)->toc_valid)
  2.3239 -		return -EINVAL;
  2.3240 -
  2.3241 -	/* Check validity of requested track number. */
  2.3242 -	ntracks = toc->hdr.last_track - toc->hdr.first_track + 1;
  2.3243 -	if (toc->hdr.first_track == CDROM_LEADOUT) ntracks = 0;
  2.3244 -	if (track == CDROM_LEADOUT)
  2.3245 -		*ent = &toc->ent[ntracks];
  2.3246 -	else if (track < toc->hdr.first_track ||
  2.3247 -		 track > toc->hdr.last_track)
  2.3248 -		return -EINVAL;
  2.3249 -	else
  2.3250 -		*ent = &toc->ent[track - toc->hdr.first_track];
  2.3251 -
  2.3252 -	return 0;
  2.3253 +    struct cdrom_info *info = drive->driver_data;
  2.3254 +    struct atapi_toc *toc = info->toc;
  2.3255 +    int ntracks;
  2.3256 +
  2.3257 +    /*
  2.3258 +     * don't serve cached data, if the toc isn't valid
  2.3259 +     */
  2.3260 +    if (!CDROM_STATE_FLAGS(drive)->toc_valid)
  2.3261 +	return -EINVAL;
  2.3262 +
  2.3263 +    /* Check validity of requested track number. */
  2.3264 +    ntracks = toc->hdr.last_track - toc->hdr.first_track + 1;
  2.3265 +    if (toc->hdr.first_track == CDROM_LEADOUT) ntracks = 0;
  2.3266 +    if (track == CDROM_LEADOUT)
  2.3267 +	*ent = &toc->ent[ntracks];
  2.3268 +    else if (track < toc->hdr.first_track ||
  2.3269 +	     track > toc->hdr.last_track)
  2.3270 +	return -EINVAL;
  2.3271 +    else
  2.3272 +	*ent = &toc->ent[track - toc->hdr.first_track];
  2.3273 +
  2.3274 +    return 0;
  2.3275  }
  2.3276  
  2.3277  /* the generic packet interface to cdrom.c */
  2.3278  static int ide_cdrom_packet(struct cdrom_device_info *cdi,
  2.3279  			    struct cdrom_generic_command *cgc)
  2.3280  {
  2.3281 -	struct packet_command pc;
  2.3282 -	ide_drive_t *drive = (ide_drive_t*) cdi->handle;
  2.3283 -
  2.3284 -	if (cgc->timeout <= 0)
  2.3285 -		cgc->timeout = WAIT_CMD;
  2.3286 -
  2.3287 -	/* here we queue the commands from the uniform CD-ROM
  2.3288 -	   layer. the packet must be complete, as we do not
  2.3289 -	   touch it at all. */
  2.3290 -	memset(&pc, 0, sizeof(pc));
  2.3291 -	memcpy(pc.c, cgc->cmd, CDROM_PACKET_SIZE);
  2.3292 -	pc.buffer = cgc->buffer;
  2.3293 -	pc.buflen = cgc->buflen;
  2.3294 -	pc.quiet = cgc->quiet;
  2.3295 -	pc.timeout = cgc->timeout;
  2.3296 -	pc.sense = cgc->sense;
  2.3297 -	return cgc->stat = cdrom_queue_packet_command(drive, &pc);
  2.3298 +    struct packet_command pc;
  2.3299 +    ide_drive_t *drive = (ide_drive_t*) cdi->handle;
  2.3300 +
  2.3301 +    if (cgc->timeout <= 0)
  2.3302 +	cgc->timeout = WAIT_CMD;
  2.3303 +
  2.3304 +    /* here we queue the commands from the uniform CD-ROM
  2.3305 +       layer. the packet must be complete, as we do not
  2.3306 +       touch it at all. */
  2.3307 +    memset(&pc, 0, sizeof(pc));
  2.3308 +    memcpy(pc.c, cgc->cmd, CDROM_PACKET_SIZE);
  2.3309 +    pc.buffer = cgc->buffer;
  2.3310 +    pc.buflen = cgc->buflen;
  2.3311 +    pc.quiet = cgc->quiet;
  2.3312 +    pc.timeout = cgc->timeout;
  2.3313 +    pc.sense = cgc->sense;
  2.3314 +    return cgc->stat = cdrom_queue_packet_command(drive, &pc);
  2.3315  }
  2.3316  
  2.3317  static
  2.3318  int ide_cdrom_dev_ioctl (struct cdrom_device_info *cdi,
  2.3319  			 unsigned int cmd, unsigned long arg)
  2.3320  {
  2.3321 -	struct cdrom_generic_command cgc;
  2.3322 -	char buffer[16];
  2.3323 -	int stat;
  2.3324 -
  2.3325 -	init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_UNKNOWN);
  2.3326 -
  2.3327 -	/* These will be moved into the Uniform layer shortly... */
  2.3328 -	switch (cmd) {
  2.3329 - 	case CDROMSETSPINDOWN: {
  2.3330 - 		char spindown;
  2.3331 +    struct cdrom_generic_command cgc;
  2.3332 +    char buffer[16];
  2.3333 +    int stat;
  2.3334 +
  2.3335 +    init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_UNKNOWN);
  2.3336 +
  2.3337 +    /* These will be moved into the Uniform layer shortly... */
  2.3338 +    switch (cmd) {
  2.3339 +    case CDROMSETSPINDOWN: {
  2.3340 +	char spindown;
  2.3341   
  2.3342 - 		if (copy_from_user(&spindown, (void *) arg, sizeof(char)))
  2.3343 -			return -EFAULT;
  2.3344 +	if (copy_from_user(&spindown, (void *) arg, sizeof(char)))
  2.3345 +	    return -EFAULT;
  2.3346   
  2.3347 -                if ((stat = cdrom_mode_sense(cdi, &cgc, GPMODE_CDROM_PAGE, 0)))
  2.3348 -			return stat;
  2.3349 -
  2.3350 - 		buffer[11] = (buffer[11] & 0xf0) | (spindown & 0x0f);
  2.3351 -
  2.3352 - 		return cdrom_mode_select(cdi, &cgc);
  2.3353 - 	} 
  2.3354 +	if ((stat = cdrom_mode_sense(cdi, &cgc, GPMODE_CDROM_PAGE, 0)))
  2.3355 +	    return stat;
  2.3356 +
  2.3357 +	buffer[11] = (buffer[11] & 0xf0) | (spindown & 0x0f);
  2.3358 +
  2.3359 +	return cdrom_mode_select(cdi, &cgc);
  2.3360 +    } 
  2.3361   
  2.3362 - 	case CDROMGETSPINDOWN: {
  2.3363 - 		char spindown;
  2.3364 +    case CDROMGETSPINDOWN: {
  2.3365 +	char spindown;
  2.3366   
  2.3367 -                if ((stat = cdrom_mode_sense(cdi, &cgc, GPMODE_CDROM_PAGE, 0)))
  2.3368 -			return stat;
  2.3369 +	if ((stat = cdrom_mode_sense(cdi, &cgc, GPMODE_CDROM_PAGE, 0)))
  2.3370 +	    return stat;
  2.3371   
  2.3372 - 		spindown = buffer[11] & 0x0f;
  2.3373 +	spindown = buffer[11] & 0x0f;
  2.3374   
  2.3375 -		if (copy_to_user((void *) arg, &spindown, sizeof (char)))
  2.3376 -			return -EFAULT;
  2.3377 +	if (copy_to_user((void *) arg, &spindown, sizeof (char)))
  2.3378 +	    return -EFAULT;
  2.3379   
  2.3380 - 		return 0;
  2.3381 - 	}
  2.3382 +	return 0;
  2.3383 +    }
  2.3384    
  2.3385 -	default:
  2.3386 -		return -EINVAL;
  2.3387 -	}
  2.3388 +    default:
  2.3389 +	return -EINVAL;
  2.3390 +    }
  2.3391  
  2.3392  }
  2.3393  
  2.3394 @@ -2258,209 +2259,209 @@ int ide_cdrom_audio_ioctl (struct cdrom_
  2.3395  			   unsigned int cmd, void *arg)
  2.3396  			   
  2.3397  {
  2.3398 -	ide_drive_t *drive = (ide_drive_t*) cdi->handle;
  2.3399 -	struct cdrom_info *info = drive->driver_data;
  2.3400 -	int stat;
  2.3401 -
  2.3402 -	switch (cmd) {
  2.3403 +    ide_drive_t *drive = (ide_drive_t*) cdi->handle;
  2.3404 +    struct cdrom_info *info = drive->driver_data;
  2.3405 +    int stat;
  2.3406 +
  2.3407 +    switch (cmd) {
  2.3408  	/*
  2.3409  	 * emulate PLAY_AUDIO_TI command with PLAY_AUDIO_10, since
  2.3410  	 * atapi doesn't support it
  2.3411  	 */
  2.3412 -	case CDROMPLAYTRKIND: {
  2.3413 -		unsigned long lba_start, lba_end;
  2.3414 -		struct cdrom_ti *ti = (struct cdrom_ti *)arg;
  2.3415 -		struct atapi_toc_entry *first_toc, *last_toc;
  2.3416 -
  2.3417 -		stat = cdrom_get_toc_entry(drive, ti->cdti_trk0, &first_toc);
  2.3418 -		if (stat)
  2.3419 -			return stat;
  2.3420 -
  2.3421 -		stat = cdrom_get_toc_entry(drive, ti->cdti_trk1, &last_toc);
  2.3422 -		if (stat)
  2.3423 -			return stat;
  2.3424 -
  2.3425 -		if (ti->cdti_trk1 != CDROM_LEADOUT)
  2.3426 -			++last_toc;
  2.3427 -		lba_start = first_toc->addr.lba;
  2.3428 -		lba_end   = last_toc->addr.lba;
  2.3429 -
  2.3430 -		if (lba_end <= lba_start)
  2.3431 -			return -EINVAL;
  2.3432 -
  2.3433 -		return cdrom_play_audio(drive, lba_start, lba_end);
  2.3434 -	}
  2.3435 -
  2.3436 -	case CDROMREADTOCHDR: {
  2.3437 -		struct cdrom_tochdr *tochdr = (struct cdrom_tochdr *) arg;
  2.3438 -		struct atapi_toc *toc;
  2.3439 -
  2.3440 -		/* Make sure our saved TOC is valid. */
  2.3441 -		stat = cdrom_read_toc(drive, NULL);
  2.3442 -		if (stat) return stat;
  2.3443 -
  2.3444 -		toc = info->toc;
  2.3445 -		tochdr->cdth_trk0 = toc->hdr.first_track;
  2.3446 -		tochdr->cdth_trk1 = toc->hdr.last_track;
  2.3447 -
  2.3448 -		return 0;
  2.3449 -	}
  2.3450 -
  2.3451 -	case CDROMREADTOCENTRY: {
  2.3452 -		struct cdrom_tocentry *tocentry = (struct cdrom_tocentry*) arg;
  2.3453 -		struct atapi_toc_entry *toce;
  2.3454 -
  2.3455 -		stat = cdrom_get_toc_entry (drive, tocentry->cdte_track, &toce);
  2.3456 -		if (stat) return stat;
  2.3457 -
  2.3458 -		tocentry->cdte_ctrl = toce->control;
  2.3459 -		tocentry->cdte_adr  = toce->adr;
  2.3460 -		if (tocentry->cdte_format == CDROM_MSF) {
  2.3461 -			lba_to_msf (toce->addr.lba,
  2.3462 -				   &tocentry->cdte_addr.msf.minute,
  2.3463 -				   &tocentry->cdte_addr.msf.second,
  2.3464 -				   &tocentry->cdte_addr.msf.frame);
  2.3465 -		} else
  2.3466 -			tocentry->cdte_addr.lba = toce->addr.lba;
  2.3467 -
  2.3468 -		return 0;
  2.3469 -	}
  2.3470 -
  2.3471 -	default:
  2.3472 -		return -EINVAL;
  2.3473 -	}
  2.3474 +    case CDROMPLAYTRKIND: {
  2.3475 +	unsigned long lba_start, lba_end;
  2.3476 +	struct cdrom_ti *ti = (struct cdrom_ti *)arg;
  2.3477 +	struct atapi_toc_entry *first_toc, *last_toc;
  2.3478 +
  2.3479 +	stat = cdrom_get_toc_entry(drive, ti->cdti_trk0, &first_toc);
  2.3480 +	if (stat)
  2.3481 +	    return stat;
  2.3482 +
  2.3483 +	stat = cdrom_get_toc_entry(drive, ti->cdti_trk1, &last_toc);
  2.3484 +	if (stat)
  2.3485 +	    return stat;
  2.3486 +
  2.3487 +	if (ti->cdti_trk1 != CDROM_LEADOUT)
  2.3488 +	    ++last_toc;
  2.3489 +	lba_start = first_toc->addr.lba;
  2.3490 +	lba_end   = last_toc->addr.lba;
  2.3491 +
  2.3492 +	if (lba_end <= lba_start)
  2.3493 +	    return -EINVAL;
  2.3494 +
  2.3495 +	return cdrom_play_audio(drive, lba_start, lba_end);
  2.3496 +    }
  2.3497 +
  2.3498 +    case CDROMREADTOCHDR: {
  2.3499 +	struct cdrom_tochdr *tochdr = (struct cdrom_tochdr *) arg;
  2.3500 +	struct atapi_toc *toc;
  2.3501 +
  2.3502 +	/* Make sure our saved TOC is valid. */
  2.3503 +	stat = cdrom_read_toc(drive, NULL);
  2.3504 +	if (stat) return stat;
  2.3505 +
  2.3506 +	toc = info->toc;
  2.3507 +	tochdr->cdth_trk0 = toc->hdr.first_track;
  2.3508 +	tochdr->cdth_trk1 = toc->hdr.last_track;
  2.3509 +
  2.3510 +	return 0;
  2.3511 +    }
  2.3512 +
  2.3513 +    case CDROMREADTOCENTRY: {
  2.3514 +	struct cdrom_tocentry *tocentry = (struct cdrom_tocentry*) arg;
  2.3515 +	struct atapi_toc_entry *toce;
  2.3516 +
  2.3517 +	stat = cdrom_get_toc_entry (drive, tocentry->cdte_track, &toce);
  2.3518 +	if (stat) return stat;
  2.3519 +
  2.3520 +	tocentry->cdte_ctrl = toce->control;
  2.3521 +	tocentry->cdte_adr  = toce->adr;
  2.3522 +	if (tocentry->cdte_format == CDROM_MSF) {
  2.3523 +	    lba_to_msf (toce->addr.lba,
  2.3524 +			&tocentry->cdte_addr.msf.minute,
  2.3525 +			&tocentry->cdte_addr.msf.second,
  2.3526 +			&tocentry->cdte_addr.msf.frame);
  2.3527 +	} else
  2.3528 +	    tocentry->cdte_addr.lba = toce->addr.lba;
  2.3529 +
  2.3530 +	return 0;
  2.3531 +    }
  2.3532 +
  2.3533 +    default:
  2.3534 +	return -EINVAL;
  2.3535 +    }
  2.3536  }
  2.3537  
  2.3538  static
  2.3539  int ide_cdrom_reset (struct cdrom_device_info *cdi)
  2.3540  {
  2.3541 -	ide_drive_t *drive = (ide_drive_t*) cdi->handle;
  2.3542 -	struct request_sense sense;
  2.3543 -	struct request req;
  2.3544 -	int ret;
  2.3545 -
  2.3546 -	ide_init_drive_cmd (&req);
  2.3547 -	req.cmd = RESET_DRIVE_COMMAND;
  2.3548 -	ret = ide_do_drive_cmd(drive, &req, ide_wait);
  2.3549 -
  2.3550 -	/*
  2.3551 -	 * A reset will unlock the door. If it was previously locked,
  2.3552 -	 * lock it again.
  2.3553 -	 */
  2.3554 -	if (CDROM_STATE_FLAGS(drive)->door_locked)
  2.3555 -		(void) cdrom_lockdoor(drive, 1, &sense);
  2.3556 -
  2.3557 -	return ret;
  2.3558 +    ide_drive_t *drive = (ide_drive_t*) cdi->handle;
  2.3559 +    struct request_sense sense;
  2.3560 +    struct request req;
  2.3561 +    int ret;
  2.3562 +
  2.3563 +    ide_init_drive_cmd (&req);
  2.3564 +    req.cmd = RESET_DRIVE_COMMAND;
  2.3565 +    ret = ide_do_drive_cmd(drive, &req, ide_wait);
  2.3566 +
  2.3567 +    /*
  2.3568 +     * A reset will unlock the door. If it was previously locked,
  2.3569 +     * lock it again.
  2.3570 +     */
  2.3571 +    if (CDROM_STATE_FLAGS(drive)->door_locked)
  2.3572 +	(void) cdrom_lockdoor(drive, 1, &sense);
  2.3573 +
  2.3574 +    return ret;
  2.3575  }
  2.3576  
  2.3577  
  2.3578  static
  2.3579  int ide_cdrom_tray_move (struct cdrom_device_info *cdi, int position)
  2.3580  {
  2.3581 -	ide_drive_t *drive = (ide_drive_t*) cdi->handle;
  2.3582 -	struct request_sense sense;
  2.3583 -
  2.3584 -	if (position) {
  2.3585 -		int stat = cdrom_lockdoor(drive, 0, &sense);
  2.3586 -		if (stat) return stat;
  2.3587 -	}
  2.3588 -
  2.3589 -	return cdrom_eject(drive, !position, &sense);
  2.3590 +    ide_drive_t *drive = (ide_drive_t*) cdi->handle;
  2.3591 +    struct request_sense sense;
  2.3592 +
  2.3593 +    if (position) {
  2.3594 +	int stat = cdrom_lockdoor(drive, 0, &sense);
  2.3595 +	if (stat) return stat;
  2.3596 +    }
  2.3597 +
  2.3598 +    return cdrom_eject(drive, !position, &sense);
  2.3599  }
  2.3600  
  2.3601  static
  2.3602  int ide_cdrom_lock_door (struct cdrom_device_info *cdi, int lock)
  2.3603  {
  2.3604 -	ide_drive_t *drive = (ide_drive_t*) cdi->handle;
  2.3605 -	return cdrom_lockdoor(drive, lock, NULL);
  2.3606 +    ide_drive_t *drive = (ide_drive_t*) cdi->handle;
  2.3607 +    return cdrom_lockdoor(drive, lock, NULL);
  2.3608  }
  2.3609  
  2.3610  static
  2.3611  int ide_cdrom_select_speed (struct cdrom_device_info *cdi, int speed)
  2.3612  {
  2.3613 -	ide_drive_t *drive = (ide_drive_t*) cdi->handle;
  2.3614 -	struct request_sense sense;
  2.3615 -	int stat;
  2.3616 -
  2.3617 -	if ((stat = cdrom_select_speed (drive, speed, &sense)) < 0)
  2.3618 -		return stat;
  2.3619 -
  2.3620 -        cdi->speed = CDROM_STATE_FLAGS (drive)->current_speed;
  2.3621 -        return 0;
  2.3622 +    ide_drive_t *drive = (ide_drive_t*) cdi->handle;
  2.3623 +    struct request_sense sense;
  2.3624 +    int stat;
  2.3625 +
  2.3626 +    if ((stat = cdrom_select_speed (drive, speed, &sense)) < 0)
  2.3627 +	return stat;
  2.3628 +
  2.3629 +    cdi->speed = CDROM_STATE_FLAGS (drive)->current_speed;
  2.3630 +    return 0;
  2.3631  }
  2.3632  
  2.3633  static
  2.3634  int ide_cdrom_drive_status (struct cdrom_device_info *cdi, int slot_nr)
  2.3635  {
  2.3636 -	ide_drive_t *drive = (ide_drive_t*) cdi->handle;
  2.3637 -
  2.3638 -	if (slot_nr == CDSL_CURRENT) {
  2.3639 -		struct request_sense sense;
  2.3640 -		int stat = cdrom_check_status(drive, &sense);
  2.3641 -		if (stat == 0 || sense.sense_key == UNIT_ATTENTION)
  2.3642 -			return CDS_DISC_OK;
  2.3643 -
  2.3644 -		if (sense.sense_key == NOT_READY && sense.asc == 0x04 &&
  2.3645 -		    sense.ascq == 0x04)
  2.3646 -			return CDS_DISC_OK;
  2.3647 -
  2.3648 -
  2.3649 -		/*
  2.3650 -		 * If not using Mt Fuji extended media tray reports,
  2.3651 -		 * just return TRAY_OPEN since ATAPI doesn't provide
  2.3652 -		 * any other way to detect this...
  2.3653 -		 */
  2.3654 -		if (sense.sense_key == NOT_READY) {
  2.3655 -			if (sense.asc == 0x3a && sense.ascq == 1)
  2.3656 -				return CDS_NO_DISC;
  2.3657 -			else
  2.3658 -				return CDS_TRAY_OPEN;
  2.3659 -		}
  2.3660 -
  2.3661 -		return CDS_DRIVE_NOT_READY;
  2.3662 +    ide_drive_t *drive = (ide_drive_t*) cdi->handle;
  2.3663 +
  2.3664 +    if (slot_nr == CDSL_CURRENT) {
  2.3665 +	struct request_sense sense;
  2.3666 +	int stat = cdrom_check_status(drive, &sense);
  2.3667 +	if (stat == 0 || sense.sense_key == UNIT_ATTENTION)
  2.3668 +	    return CDS_DISC_OK;
  2.3669 +
  2.3670 +	if (sense.sense_key == NOT_READY && sense.asc == 0x04 &&
  2.3671 +	    sense.ascq == 0x04)
  2.3672 +	    return CDS_DISC_OK;
  2.3673 +
  2.3674 +
  2.3675 +	/*
  2.3676 +	 * If not using Mt Fuji extended media tray reports,
  2.3677 +	 * just return TRAY_OPEN since ATAPI doesn't provide
  2.3678 +	 * any other way to detect this...
  2.3679 +	 */
  2.3680 +	if (sense.sense_key == NOT_READY) {
  2.3681 +	    if (sense.asc == 0x3a && sense.ascq == 1)
  2.3682 +		return CDS_NO_DISC;
  2.3683 +	    else
  2.3684 +		return CDS_TRAY_OPEN;
  2.3685  	}
  2.3686 -	return -EINVAL;
  2.3687 +
  2.3688 +	return CDS_DRIVE_NOT_READY;
  2.3689 +    }
  2.3690 +    return -EINVAL;
  2.3691  }
  2.3692  
  2.3693  static
  2.3694  int ide_cdrom_get_last_session (struct cdrom_device_info *cdi,
  2.3695  				struct cdrom_multisession *ms_info)
  2.3696  {
  2.3697 -	struct atapi_toc *toc;
  2.3698 -	ide_drive_t *drive = (ide_drive_t*) cdi->handle;
  2.3699 -	struct cdrom_info *info = drive->driver_data;
  2.3700 -	struct request_sense sense;
  2.3701 -	int ret;
  2.3702 -
  2.3703 -	if (!CDROM_STATE_FLAGS(drive)->toc_valid || info->toc == NULL)
  2.3704 -		if ((ret = cdrom_read_toc(drive, &sense)))
  2.3705 -			return ret;
  2.3706 -
  2.3707 -	toc = info->toc;
  2.3708 -	ms_info->addr.lba = toc->last_session_lba;
  2.3709 -	ms_info->xa_flag = toc->xa_flag;
  2.3710 -
  2.3711 -	return 0;
  2.3712 +    struct atapi_toc *toc;
  2.3713 +    ide_drive_t *drive = (ide_drive_t*) cdi->handle;
  2.3714 +    struct cdrom_info *info = drive->driver_data;
  2.3715 +    struct request_sense sense;
  2.3716 +    int ret;
  2.3717 +
  2.3718 +    if (!CDROM_STATE_FLAGS(drive)->toc_valid || info->toc == NULL)
  2.3719 +	if ((ret = cdrom_read_toc(drive, &sense)))
  2.3720 +	    return ret;
  2.3721 +
  2.3722 +    toc = info->toc;
  2.3723 +    ms_info->addr.lba = toc->last_session_lba;
  2.3724 +    ms_info->xa_flag = toc->xa_flag;
  2.3725 +
  2.3726 +    return 0;
  2.3727  }
  2.3728  
  2.3729  static
  2.3730  int ide_cdrom_get_mcn (struct cdrom_device_info *cdi,
  2.3731  		       struct cdrom_mcn *mcn_info)
  2.3732  {
  2.3733 -	int stat;
  2.3734 -	char mcnbuf[24];
  2.3735 -	ide_drive_t *drive = (ide_drive_t*) cdi->handle;
  2.3736 +    int stat;
  2.3737 +    char mcnbuf[24];
  2.3738 +    ide_drive_t *drive = (ide_drive_t*) cdi->handle;
  2.3739  
  2.3740  /* get MCN */
  2.3741 -	if ((stat = cdrom_read_subchannel(drive, 2, mcnbuf, sizeof (mcnbuf), NULL)))
  2.3742 -		return stat;
  2.3743 -
  2.3744 -	memcpy (mcn_info->medium_catalog_number, mcnbuf+9,
  2.3745 -		sizeof (mcn_info->medium_catalog_number)-1);
  2.3746 -	mcn_info->medium_catalog_number[sizeof (mcn_info->medium_catalog_number)-1]
  2.3747 -		= '\0';
  2.3748 -
  2.3749 -	return 0;
  2.3750 +    if ((stat = cdrom_read_subchannel(drive, 2, mcnbuf, sizeof (mcnbuf), NULL)))
  2.3751 +	return stat;
  2.3752 +
  2.3753 +    memcpy (mcn_info->medium_catalog_number, mcnbuf+9,
  2.3754 +	    sizeof (mcn_info->medium_catalog_number)-1);
  2.3755 +    mcn_info->medium_catalog_number[sizeof (mcn_info->medium_catalog_number)-1]
  2.3756 +	= '\0';
  2.3757 +
  2.3758 +    return 0;
  2.3759  }
  2.3760  
  2.3761  
  2.3762 @@ -2473,24 +2474,24 @@ static
  2.3763  int ide_cdrom_check_media_change_real (struct cdrom_device_info *cdi,
  2.3764  				       int slot_nr)
  2.3765  {
  2.3766 -	ide_drive_t *drive = (ide_drive_t*) cdi->handle;
  2.3767 -	int retval;
  2.3768 +    ide_drive_t *drive = (ide_drive_t*) cdi->handle;
  2.3769 +    int retval;
  2.3770  	
  2.3771 -	if (slot_nr == CDSL_CURRENT) {
  2.3772 -		(void) cdrom_check_status(drive, NULL);
  2.3773 -		retval = CDROM_STATE_FLAGS (drive)->media_changed;
  2.3774 -		CDROM_STATE_FLAGS (drive)->media_changed = 0;
  2.3775 -		return retval;
  2.3776 -	} else {
  2.3777 -		return -EINVAL;
  2.3778 -	}
  2.3779 +    if (slot_nr == CDSL_CURRENT) {
  2.3780 +	(void) cdrom_check_status(drive, NULL);
  2.3781 +	retval = CDROM_STATE_FLAGS (drive)->media_changed;
  2.3782 +	CDROM_STATE_FLAGS (drive)->media_changed = 0;
  2.3783 +	return retval;
  2.3784 +    } else {
  2.3785 +	return -EINVAL;
  2.3786 +    }
  2.3787  }
  2.3788  
  2.3789  
  2.3790  static
  2.3791  int ide_cdrom_open_real (struct cdrom_device_info *cdi, int purpose)
  2.3792  {
  2.3793 -	return 0;
  2.3794 +    return 0;
  2.3795  }
  2.3796  
  2.3797  
  2.3798 @@ -2509,360 +2510,360 @@ void ide_cdrom_release_real (struct cdro
  2.3799   * Device initialization.
  2.3800   */
  2.3801  static struct cdrom_device_ops ide_cdrom_dops = {
  2.3802 -	open:			ide_cdrom_open_real,
  2.3803 -	release:		ide_cdrom_release_real,
  2.3804 -	drive_status:		ide_cdrom_drive_status,
  2.3805 -	media_changed:		ide_cdrom_check_media_change_real,
  2.3806 -	tray_move:		ide_cdrom_tray_move,
  2.3807 -	lock_door:		ide_cdrom_lock_door,
  2.3808 -	select_speed:		ide_cdrom_select_speed,
  2.3809 -	get_last_session:	ide_cdrom_get_last_session,
  2.3810 -	get_mcn:		ide_cdrom_get_mcn,
  2.3811 -	reset:			ide_cdrom_reset,
  2.3812 -	audio_ioctl:		ide_cdrom_audio_ioctl,
  2.3813 -	dev_ioctl:		ide_cdrom_dev_ioctl,
  2.3814 -	capability:		CDC_CLOSE_TRAY | CDC_OPEN_TRAY | CDC_LOCK |
  2.3815 -				CDC_SELECT_SPEED | CDC_SELECT_DISC |
  2.3816 -				CDC_MULTI_SESSION | CDC_MCN |
  2.3817 -				CDC_MEDIA_CHANGED | CDC_PLAY_AUDIO | CDC_RESET |
  2.3818 -				CDC_IOCTLS | CDC_DRIVE_STATUS | CDC_CD_R |
  2.3819 -				CDC_CD_RW | CDC_DVD | CDC_DVD_R| CDC_DVD_RAM |
  2.3820 -				CDC_GENERIC_PACKET,
  2.3821 -	generic_packet:		ide_cdrom_packet,
  2.3822 +    open:			ide_cdrom_open_real,
  2.3823 +    release:		ide_cdrom_release_real,
  2.3824 +    drive_status:		ide_cdrom_drive_status,
  2.3825 +    media_changed:		ide_cdrom_check_media_change_real,
  2.3826 +    tray_move:		ide_cdrom_tray_move,
  2.3827 +    lock_door:		ide_cdrom_lock_door,
  2.3828 +    select_speed:		ide_cdrom_select_speed,
  2.3829 +    get_last_session:	ide_cdrom_get_last_session,
  2.3830 +    get_mcn:		ide_cdrom_get_mcn,
  2.3831 +    reset:			ide_cdrom_reset,
  2.3832 +    audio_ioctl:		ide_cdrom_audio_ioctl,
  2.3833 +    dev_ioctl:		ide_cdrom_dev_ioctl,
  2.3834 +    capability:		CDC_CLOSE_TRAY | CDC_OPEN_TRAY | CDC_LOCK |
  2.3835 +    CDC_SELECT_SPEED | CDC_SELECT_DISC |
  2.3836 +    CDC_MULTI_SESSION | CDC_MCN |
  2.3837 +    CDC_MEDIA_CHANGED | CDC_PLAY_AUDIO | CDC_RESET |
  2.3838 +    CDC_IOCTLS | CDC_DRIVE_STATUS | CDC_CD_R |
  2.3839 +    CDC_CD_RW | CDC_DVD | CDC_DVD_R| CDC_DVD_RAM |
  2.3840 +    CDC_GENERIC_PACKET,
  2.3841 +    generic_packet:		ide_cdrom_packet,
  2.3842  };
  2.3843  
  2.3844  static int ide_cdrom_register (ide_drive_t *drive, int nslots)
  2.3845  {
  2.3846 -	struct cdrom_info *info = drive->driver_data;
  2.3847 -	struct cdrom_device_info *devinfo = &info->devinfo;
  2.3848 -	int minor = (drive->select.b.unit) << PARTN_BITS;
  2.3849 -
  2.3850 -	devinfo->dev = MKDEV (HWIF(drive)->major, minor);
  2.3851 -	devinfo->ops = &ide_cdrom_dops;
  2.3852 -	devinfo->mask = 0;
  2.3853 -	*(int *)&devinfo->speed = CDROM_STATE_FLAGS (drive)->current_speed;
  2.3854 -	*(int *)&devinfo->capacity = nslots;
  2.3855 -	devinfo->handle = (void *) drive;
  2.3856 -	strcpy(devinfo->name, drive->name);
  2.3857 +    struct cdrom_info *info = drive->driver_data;
  2.3858 +    struct cdrom_device_info *devinfo = &info->devinfo;
  2.3859 +    int minor = (drive->select.b.unit) << PARTN_BITS;
  2.3860 +
  2.3861 +    devinfo->dev = MKDEV (HWIF(drive)->major, minor);
  2.3862 +    devinfo->ops = &ide_cdrom_dops;
  2.3863 +    devinfo->mask = 0;
  2.3864 +    *(int *)&devinfo->speed = CDROM_STATE_FLAGS (drive)->current_speed;
  2.3865 +    *(int *)&devinfo->capacity = nslots;
  2.3866 +    devinfo->handle = (void *) drive;
  2.3867 +    strcpy(devinfo->name, drive->name);
  2.3868  	
  2.3869 -	/* set capability mask to match the probe. */
  2.3870 -	if (!CDROM_CONFIG_FLAGS (drive)->cd_r)
  2.3871 -		devinfo->mask |= CDC_CD_R;
  2.3872 -	if (!CDROM_CONFIG_FLAGS (drive)->cd_rw)
  2.3873 -		devinfo->mask |= CDC_CD_RW;
  2.3874 -	if (!CDROM_CONFIG_FLAGS (drive)->dvd)
  2.3875 -		devinfo->mask |= CDC_DVD;
  2.3876 -	if (!CDROM_CONFIG_FLAGS (drive)->dvd_r)
  2.3877 -		devinfo->mask |= CDC_DVD_R;
  2.3878 -	if (!CDROM_CONFIG_FLAGS (drive)->dvd_ram)
  2.3879 -		devinfo->mask |= CDC_DVD_RAM;
  2.3880 -	if (!CDROM_CONFIG_FLAGS (drive)->is_changer)
  2.3881 -		devinfo->mask |= CDC_SELECT_DISC;
  2.3882 -	if (!CDROM_CONFIG_FLAGS (drive)->audio_play)
  2.3883 -		devinfo->mask |= CDC_PLAY_AUDIO;
  2.3884 -	if (!CDROM_CONFIG_FLAGS (drive)->close_tray)
  2.3885 -		devinfo->mask |= CDC_CLOSE_TRAY;
  2.3886 +    /* set capability mask to match the probe. */
  2.3887 +    if (!CDROM_CONFIG_FLAGS (drive)->cd_r)
  2.3888 +	devinfo->mask |= CDC_CD_R;
  2.3889 +    if (!CDROM_CONFIG_FLAGS (drive)->cd_rw)
  2.3890 +	devinfo->mask |= CDC_CD_RW;
  2.3891 +    if (!CDROM_CONFIG_FLAGS (drive)->dvd)
  2.3892 +	devinfo->mask |= CDC_DVD;
  2.3893 +    if (!CDROM_CONFIG_FLAGS (drive)->dvd_r)
  2.3894 +	devinfo->mask |= CDC_DVD_R;
  2.3895 +    if (!CDROM_CONFIG_FLAGS (drive)->dvd_ram)
  2.3896 +	devinfo->mask |= CDC_DVD_RAM;
  2.3897 +    if (!CDROM_CONFIG_FLAGS (drive)->is_changer)
  2.3898 +	devinfo->mask |= CDC_SELECT_DISC;
  2.3899 +    if (!CDROM_CONFIG_FLAGS (drive)->audio_play)
  2.3900 +	devinfo->mask |= CDC_PLAY_AUDIO;
  2.3901 +    if (!CDROM_CONFIG_FLAGS (drive)->close_tray)
  2.3902 +	devinfo->mask |= CDC_CLOSE_TRAY;
  2.3903  
  2.3904  #if 0
  2.3905 -	devinfo->de = devfs_register(drive->de, "cd", DEVFS_FL_DEFAULT,
  2.3906 -				     HWIF(drive)->major, minor,
  2.3907 -				     S_IFBLK | S_IRUGO | S_IWUGO,
  2.3908 -				     ide_fops, NULL);
  2.3909 +    devinfo->de = devfs_register(drive->de, "cd", DEVFS_FL_DEFAULT,
  2.3910 +				 HWIF(drive)->major, minor,
  2.3911 +				 S_IFBLK | S_IRUGO | S_IWUGO,
  2.3912 +				 ide_fops, NULL);
  2.3913  #endif
  2.3914  
  2.3915 -	return register_cdrom(devinfo);
  2.3916 +    return register_cdrom(devinfo);
  2.3917  }
  2.3918  
  2.3919  static
  2.3920  int ide_cdrom_get_capabilities(ide_drive_t *drive, struct atapi_capabilities_page *cap)
  2.3921  {
  2.3922 -	struct cdrom_info *info = drive->driver_data;
  2.3923 -	struct cdrom_device_info *cdi = &info->devinfo;
  2.3924 -	struct cdrom_generic_command cgc;
  2.3925 -	int stat, attempts = 3, size = sizeof(*cap);
  2.3926 -
  2.3927 -	/*
  2.3928 -	 * ACER50 (and others?) require the full spec length mode sense
  2.3929 -	 * page capabilities size, but older drives break.
  2.3930 -	 */
  2.3931 -	if (drive->id) {
  2.3932 -		if (!(!strcmp(drive->id->model, "ATAPI CD ROM DRIVE 50X MAX") ||
  2.3933 -		    !strcmp(drive->id->model, "WPI CDS-32X")))
  2.3934 -			size -= sizeof(cap->pad);
  2.3935 -	}
  2.3936 -
  2.3937 -	/* we have to cheat a little here. the packet will eventually
  2.3938 -	 * be queued with ide_cdrom_packet(), which extracts the
  2.3939 -	 * drive from cdi->handle. Since this device hasn't been
  2.3940 -	 * registered with the Uniform layer yet, it can't do this.
  2.3941 -	 * Same goes for cdi->ops.
  2.3942 -	 */
  2.3943 -	cdi->handle = (ide_drive_t *) drive;
  2.3944 -	cdi->ops = &ide_cdrom_dops;
  2.3945 -	init_cdrom_command(&cgc, cap, size, CGC_DATA_UNKNOWN);
  2.3946 -	do { /* we seem to get stat=0x01,err=0x00 the first time (??) */
  2.3947 -		stat = cdrom_mode_sense(cdi, &cgc, GPMODE_CAPABILITIES_PAGE, 0);
  2.3948 -		if (!stat)
  2.3949 -			break;
  2.3950 -	} while (--attempts);
  2.3951 -	return stat;
  2.3952 +    struct cdrom_info *info = drive->driver_data;
  2.3953 +    struct cdrom_device_info *cdi = &info->devinfo;
  2.3954 +    struct cdrom_generic_command cgc;
  2.3955 +    int stat, attempts = 3, size = sizeof(*cap);
  2.3956 +
  2.3957 +    /*
  2.3958 +     * ACER50 (and others?) require the full spec length mode sense
  2.3959 +     * page capabilities size, but older drives break.
  2.3960 +     */
  2.3961 +    if (drive->id) {
  2.3962 +	if (!(!strcmp(drive->id->model, "ATAPI CD ROM DRIVE 50X MAX") ||
  2.3963 +	      !strcmp(drive->id->model, "WPI CDS-32X")))
  2.3964 +	    size -= sizeof(cap->pad);
  2.3965 +    }
  2.3966 +
  2.3967 +    /* we have to cheat a little here. the packet will eventually
  2.3968 +     * be queued with ide_cdrom_packet(), which extracts the
  2.3969 +     * drive from cdi->handle. Since this device hasn't been
  2.3970 +     * registered with the Uniform layer yet, it can't do this.
  2.3971 +     * Same goes for cdi->ops.
  2.3972 +     */
  2.3973 +    cdi->handle = (ide_drive_t *) drive;
  2.3974 +    cdi->ops = &ide_cdrom_dops;
  2.3975 +    init_cdrom_command(&cgc, cap, size, CGC_DATA_UNKNOWN);
  2.3976 +    do { /* we seem to get stat=0x01,err=0x00 the first time (??) */
  2.3977 +	stat = cdrom_mode_sense(cdi, &cgc, GPMODE_CAPABILITIES_PAGE, 0);
  2.3978 +	if (!stat)
  2.3979 +	    break;
  2.3980 +    } while (--attempts);
  2.3981 +    return stat;
  2.3982  }
  2.3983  
  2.3984  static
  2.3985  int ide_cdrom_probe_capabilities (ide_drive_t *drive)
  2.3986  {
  2.3987 -	struct cdrom_info *info = drive->driver_data;
  2.3988 -	struct cdrom_device_info *cdi = &info->devinfo;
  2.3989 -	struct atapi_capabilities_page cap;
  2.3990 -	int nslots = 1;
  2.3991 -
  2.3992 -	if (CDROM_CONFIG_FLAGS (drive)->nec260) {
  2.3993 -		CDROM_CONFIG_FLAGS (drive)->no_eject = 0;                       
  2.3994 -		CDROM_CONFIG_FLAGS (drive)->audio_play = 1;       
  2.3995 -		return nslots;
  2.3996 -	}
  2.3997 -
  2.3998 -	if (ide_cdrom_get_capabilities(drive, &cap))
  2.3999 -		return 0;
  2.4000 -
  2.4001 -	if (cap.lock == 0)
  2.4002 -		CDROM_CONFIG_FLAGS (drive)->no_doorlock = 1;
  2.4003 -	if (cap.eject)
  2.4004 -		CDROM_CONFIG_FLAGS (drive)->no_eject = 0;
  2.4005 -	if (cap.cd_r_write)
  2.4006 -		CDROM_CONFIG_FLAGS (drive)->cd_r = 1;
  2.4007 -	if (cap.cd_rw_write)
  2.4008 -		CDROM_CONFIG_FLAGS (drive)->cd_rw = 1;
  2.4009 -	if (cap.test_write)
  2.4010 -		CDROM_CONFIG_FLAGS (drive)->test_write = 1;
  2.4011 -	if (cap.dvd_ram_read || cap.dvd_r_read || cap.dvd_rom)
  2.4012 -		CDROM_CONFIG_FLAGS (drive)->dvd = 1;
  2.4013 -	if (cap.dvd_ram_write)
  2.4014 -		CDROM_CONFIG_FLAGS (drive)->dvd_ram = 1;
  2.4015 -	if (cap.dvd_r_write)
  2.4016 -		CDROM_CONFIG_FLAGS (drive)->dvd_r = 1;
  2.4017 -	if (cap.audio_play)
  2.4018 -		CDROM_CONFIG_FLAGS (drive)->audio_play = 1;
  2.4019 -	if (cap.mechtype == mechtype_caddy || cap.mechtype == mechtype_popup)
  2.4020 -		CDROM_CONFIG_FLAGS (drive)->close_tray = 0;
  2.4021 +    struct cdrom_info *info = drive->driver_data;
  2.4022 +    struct cdrom_device_info *cdi = &info->devinfo;
  2.4023 +    struct atapi_capabilities_page cap;
  2.4024 +    int nslots = 1;
  2.4025 +
  2.4026 +    if (CDROM_CONFIG_FLAGS (drive)->nec260) {
  2.4027 +	CDROM_CONFIG_FLAGS (drive)->no_eject = 0;                       
  2.4028 +	CDROM_CONFIG_FLAGS (drive)->audio_play = 1;       
  2.4029 +	return nslots;
  2.4030 +    }
  2.4031 +
  2.4032 +    if (ide_cdrom_get_capabilities(drive, &cap))
  2.4033 +	return 0;
  2.4034 +
  2.4035 +    if (cap.lock == 0)
  2.4036 +	CDROM_CONFIG_FLAGS (drive)->no_doorlock = 1;
  2.4037 +    if (cap.eject)
  2.4038 +	CDROM_CONFIG_FLAGS (drive)->no_eject = 0;
  2.4039 +    if (cap.cd_r_write)
  2.4040 +	CDROM_CONFIG_FLAGS (drive)->cd_r = 1;
  2.4041 +    if (cap.cd_rw_write)
  2.4042 +	CDROM_CONFIG_FLAGS (drive)->cd_rw = 1;
  2.4043 +    if (cap.test_write)
  2.4044 +	CDROM_CONFIG_FLAGS (drive)->test_write = 1;
  2.4045 +    if (cap.dvd_ram_read || cap.dvd_r_read || cap.dvd_rom)
  2.4046 +	CDROM_CONFIG_FLAGS (drive)->dvd = 1;
  2.4047 +    if (cap.dvd_ram_write)
  2.4048 +	CDROM_CONFIG_FLAGS (drive)->dvd_ram = 1;
  2.4049 +    if (cap.dvd_r_write)
  2.4050 +	CDROM_CONFIG_FLAGS (drive)->dvd_r = 1;
  2.4051 +    if (cap.audio_play)
  2.4052 +	CDROM_CONFIG_FLAGS (drive)->audio_play = 1;
  2.4053 +    if (cap.mechtype == mechtype_caddy || cap.mechtype == mechtype_popup)
  2.4054 +	CDROM_CONFIG_FLAGS (drive)->close_tray = 0;
  2.4055  
  2.4056  #if ! STANDARD_ATAPI
  2.4057 -	if (cdi->sanyo_slot > 0) {
  2.4058 -		CDROM_CONFIG_FLAGS (drive)->is_changer = 1;
  2.4059 -		nslots = 3;
  2.4060 -	}
  2.4061 -
  2.4062 -	else
  2.4063 +    if (cdi->sanyo_slot > 0) {
  2.4064 +	CDROM_CONFIG_FLAGS (drive)->is_changer = 1;
  2.4065 +	nslots = 3;
  2.4066 +    }
  2.4067 +
  2.4068 +    else
  2.4069  #endif /* not STANDARD_ATAPI */
  2.4070  	if (cap.mechtype == mechtype_individual_changer ||
  2.4071  	    cap.mechtype == mechtype_cartridge_changer) {
  2.4072 -		if ((nslots = cdrom_number_of_slots(cdi)) > 1) {
  2.4073 -			CDROM_CONFIG_FLAGS (drive)->is_changer = 1;
  2.4074 -			CDROM_CONFIG_FLAGS (drive)->supp_disc_present = 1;
  2.4075 -		}
  2.4076 +	    if ((nslots = cdrom_number_of_slots(cdi)) > 1) {
  2.4077 +		CDROM_CONFIG_FLAGS (drive)->is_changer = 1;
  2.4078 +		CDROM_CONFIG_FLAGS (drive)->supp_disc_present = 1;
  2.4079 +	    }
  2.4080  	}
  2.4081  
  2.4082 -	/* The ACER/AOpen 24X cdrom has the speed fields byte-swapped */
  2.4083 -	if (drive->id && !drive->id->model[0] && !strncmp(drive->id->fw_rev, "241N", 4)) {
  2.4084 -		CDROM_STATE_FLAGS (drive)->current_speed  = 
  2.4085 -			(((unsigned int)cap.curspeed) + (176/2)) / 176;
  2.4086 -		CDROM_CONFIG_FLAGS (drive)->max_speed = 
  2.4087 -			(((unsigned int)cap.maxspeed) + (176/2)) / 176;
  2.4088 -	} else {
  2.4089 -		CDROM_STATE_FLAGS (drive)->current_speed  = 
  2.4090 -			(ntohs(cap.curspeed) + (176/2)) / 176;
  2.4091 -		CDROM_CONFIG_FLAGS (drive)->max_speed = 
  2.4092 -			(ntohs(cap.maxspeed) + (176/2)) / 176;
  2.4093 -	}
  2.4094 -
  2.4095 -	/* don't print speed if the drive reported 0.
  2.4096 -	 */
  2.4097 -	printk("%s: ATAPI", drive->name);
  2.4098 -	if (CDROM_CONFIG_FLAGS(drive)->max_speed)
  2.4099 -		printk(" %dX", CDROM_CONFIG_FLAGS(drive)->max_speed);
  2.4100 -	printk(" %s", CDROM_CONFIG_FLAGS(drive)->dvd ? "DVD-ROM" : "CD-ROM");
  2.4101 -
  2.4102 -	if (CDROM_CONFIG_FLAGS (drive)->dvd_r|CDROM_CONFIG_FLAGS (drive)->dvd_ram)
  2.4103 -        	printk (" DVD%s%s", 
  2.4104 +    /* The ACER/AOpen 24X cdrom has the speed fields byte-swapped */
  2.4105 +    if (drive->id && !drive->id->model[0] && !strncmp(drive->id->fw_rev, "241N", 4)) {
  2.4106 +	CDROM_STATE_FLAGS (drive)->current_speed  = 
  2.4107 +	    (((unsigned int)cap.curspeed) + (176/2)) / 176;
  2.4108 +	CDROM_CONFIG_FLAGS (drive)->max_speed = 
  2.4109 +	    (((unsigned int)cap.maxspeed) + (176/2)) / 176;
  2.4110 +    } else {
  2.4111 +	CDROM_STATE_FLAGS (drive)->current_speed  = 
  2.4112 +	    (ntohs(cap.curspeed) + (176/2)) / 176;
  2.4113 +	CDROM_CONFIG_FLAGS (drive)->max_speed = 
  2.4114 +	    (ntohs(cap.maxspeed) + (176/2)) / 176;
  2.4115 +    }
  2.4116 +
  2.4117 +    /* don't print speed if the drive reported 0.
  2.4118 +     */
  2.4119 +    printk("%s: ATAPI", drive->name);
  2.4120 +    if (CDROM_CONFIG_FLAGS(drive)->max_speed)
  2.4121 +	printk(" %dX", CDROM_CONFIG_FLAGS(drive)->max_speed);
  2.4122 +    printk(" %s", CDROM_CONFIG_FLAGS(drive)->dvd ? "DVD-ROM" : "CD-ROM");
  2.4123 +
  2.4124 +    if (CDROM_CONFIG_FLAGS (drive)->dvd_r|CDROM_CONFIG_FLAGS (drive)->dvd_ram)
  2.4125 +	printk (" DVD%s%s", 
  2.4126          	(CDROM_CONFIG_FLAGS (drive)->dvd_r)? "-R" : "", 
  2.4127          	(CDROM_CONFIG_FLAGS (drive)->dvd_ram)? "-RAM" : "");
  2.4128  
  2.4129 -        if (CDROM_CONFIG_FLAGS (drive)->cd_r|CDROM_CONFIG_FLAGS (drive)->cd_rw) 
  2.4130 -        	printk (" CD%s%s", 
  2.4131 +    if (CDROM_CONFIG_FLAGS (drive)->cd_r|CDROM_CONFIG_FLAGS (drive)->cd_rw) 
  2.4132 +	printk (" CD%s%s", 
  2.4133          	(CDROM_CONFIG_FLAGS (drive)->cd_r)? "-R" : "", 
  2.4134          	(CDROM_CONFIG_FLAGS (drive)->cd_rw)? "/RW" : "");
  2.4135  
  2.4136 -        if (CDROM_CONFIG_FLAGS (drive)->is_changer) 
  2.4137 -        	printk (" changer w/%d slots", nslots);
  2.4138 -        else 	
  2.4139 -        	printk (" drive");
  2.4140 -
  2.4141 -	printk (", %dkB Cache", be16_to_cpu(cap.buffer_size));
  2.4142 +    if (CDROM_CONFIG_FLAGS (drive)->is_changer) 
  2.4143 +	printk (" changer w/%d slots", nslots);
  2.4144 +    else 	
  2.4145 +	printk (" drive");
  2.4146 +
  2.4147 +    printk (", %dkB Cache", be16_to_cpu(cap.buffer_size));
  2.4148  
  2.4149  #ifdef CONFIG_BLK_DEV_IDEDMA
  2.4150 -	if (drive->using_dma)
  2.4151 -		(void) HWIF(drive)->dmaproc(ide_dma_verbose, drive);
  2.4152 +    if (drive->using_dma)
  2.4153 +	(void) HWIF(drive)->dmaproc(ide_dma_verbose, drive);
  2.4154  #endif /* CONFIG_BLK_DEV_IDEDMA */
  2.4155 -	printk("\n");
  2.4156 -
  2.4157 -	return nslots;
  2.4158 +    printk("\n");
  2.4159 +
  2.4160 +    return nslots;
  2.4161  }
  2.4162  
  2.4163  static void ide_cdrom_add_settings(ide_drive_t *drive)
  2.4164  {
  2.4165  #if 0 
  2.4166 -	int major = HWIF(drive)->major;
  2.4167 -	int minor = drive->select.b.unit << PARTN_BITS;
  2.4168 -
  2.4169 -	ide_add_setting(drive,	"breada_readahead",	SETTING_RW, BLKRAGET, BLKRASET, TYPE_INT, 0, 255, 1, 2, &read_ahead[major], NULL);
  2.4170 -	ide_add_setting(drive,	"file_readahead",	SETTING_RW, BLKFRAGET, BLKFRASET, TYPE_INTA, 0, INT_MAX, 1, 1024, &max_readahead[major][minor],	NULL);
  2.4171 -	ide_add_setting(drive,	"max_kb_per_request",	SETTING_RW, BLKSECTGET, BLKSECTSET, TYPE_INTA, 1, 255, 1, 2, &max_sectors[major][minor], NULL);
  2.4172 +    int major = HWIF(drive)->major;
  2.4173 +    int minor = drive->select.b.unit << PARTN_BITS;
  2.4174 +
  2.4175 +    ide_add_setting(drive,	"breada_readahead",	SETTING_RW, BLKRAGET, BLKRASET, TYPE_INT, 0, 255, 1, 2, &read_ahead[major], NULL);
  2.4176 +    ide_add_setting(drive,	"file_readahead",	SETTING_RW, BLKFRAGET, BLKFRASET, TYPE_INTA, 0, INT_MAX, 1, 1024, &max_readahead[major][minor],	NULL);
  2.4177 +    ide_add_setting(drive,	"max_kb_per_request",	SETTING_RW, BLKSECTGET, BLKSECTSET, TYPE_INTA, 1, 255, 1, 2, &max_sectors[major][minor], NULL);
  2.4178  #endif
  2.4179 -	ide_add_setting(drive,	"dsc_overlap",		SETTING_RW, -1, -1, TYPE_BYTE, 0, 1, 1,	1, &drive->dsc_overlap, NULL);
  2.4180 +    ide_add_setting(drive,	"dsc_overlap",		SETTING_RW, -1, -1, TYPE_BYTE, 0, 1, 1,	1, &drive->dsc_overlap, NULL);
  2.4181  }
  2.4182  
  2.4183  static
  2.4184  int ide_cdrom_setup (ide_drive_t *drive)
  2.4185  {
  2.4186 -	struct cdrom_info *info = drive->driver_data;
  2.4187 -	struct cdrom_device_info *cdi = &info->devinfo;
  2.4188 -	int minor = drive->select.b.unit << PARTN_BITS;
  2.4189 -	int nslots;
  2.4190 -
  2.4191 -	/*
  2.4192 -	 * default to read-only always and fix latter at the bottom
  2.4193 -	 */
  2.4194 -	set_device_ro(MKDEV(HWIF(drive)->major, minor), 1);
  2.4195 +    struct cdrom_info *info = drive->driver_data;
  2.4196 +    struct cdrom_device_info *cdi = &info->devinfo;
  2.4197 +    int minor = drive->select.b.unit << PARTN_BITS;
  2.4198 +    int nslots;
  2.4199 +
  2.4200 +    /*
  2.4201 +     * default to read-only always and fix latter at the bottom
  2.4202 +     */
  2.4203 +    set_device_ro(MKDEV(HWIF(drive)->major, minor), 1);
  2.4204  #if 0
  2.4205 -	set_blocksize(MKDEV(HWIF(drive)->major, minor), CD_FRAMESIZE);
  2.4206 +    set_blocksize(MKDEV(HWIF(drive)->major, minor), CD_FRAMESIZE);
  2.4207  #endif
  2.4208  
  2.4209 -	drive->special.all	= 0;
  2.4210 -	drive->ready_stat	= 0;
  2.4211 -
  2.4212 -	CDROM_STATE_FLAGS (drive)->media_changed = 1;
  2.4213 -	CDROM_STATE_FLAGS (drive)->toc_valid     = 0;
  2.4214 -	CDROM_STATE_FLAGS (drive)->door_locked   = 0;
  2.4215 +    drive->special.all	= 0;
  2.4216 +    drive->ready_stat	= 0;
  2.4217 +
  2.4218 +    CDROM_STATE_FLAGS (drive)->media_changed = 1;
  2.4219 +    CDROM_STATE_FLAGS (drive)->toc_valid     = 0;
  2.4220 +    CDROM_STATE_FLAGS (drive)->door_locked   = 0;
  2.4221  
  2.4222  #if NO_DOOR_LOCKING
  2.4223 -	CDROM_CONFIG_FLAGS (drive)->no_doorlock = 1;
  2.4224 +    CDROM_CONFIG_FLAGS (drive)->no_doorlock = 1;
  2.4225  #else
  2.4226 -	CDROM_CONFIG_FLAGS (drive)->no_doorlock = 0;
  2.4227 +    CDROM_CONFIG_FLAGS (drive)->no_doorlock = 0;
  2.4228  #endif
  2.4229  
  2.4230 -	if (drive->id != NULL)
  2.4231 -		CDROM_CONFIG_FLAGS (drive)->drq_interrupt =
  2.4232 -			((drive->id->config & 0x0060) == 0x20);
  2.4233 -	else
  2.4234 -		CDROM_CONFIG_FLAGS (drive)->drq_interrupt = 0;
  2.4235 -
  2.4236 -	CDROM_CONFIG_FLAGS (drive)->is_changer = 0;
  2.4237 -	CDROM_CONFIG_FLAGS (drive)->cd_r = 0;
  2.4238 -	CDROM_CONFIG_FLAGS (drive)->cd_rw = 0;
  2.4239 -	CDROM_CONFIG_FLAGS (drive)->test_write = 0;
  2.4240 -	CDROM_CONFIG_FLAGS (drive)->dvd = 0;
  2.4241 -	CDROM_CONFIG_FLAGS (drive)->dvd_r = 0;
  2.4242 -	CDROM_CONFIG_FLAGS (drive)->dvd_ram = 0;
  2.4243 -	CDROM_CONFIG_FLAGS (drive)->no_eject = 1;
  2.4244 -	CDROM_CONFIG_FLAGS (drive)->supp_disc_present = 0;
  2.4245 -	CDROM_CONFIG_FLAGS (drive)->audio_play = 0;
  2.4246 -	CDROM_CONFIG_FLAGS (drive)->close_tray = 1;
  2.4247 +    if (drive->id != NULL)
  2.4248 +	CDROM_CONFIG_FLAGS (drive)->drq_interrupt =
  2.4249 +	    ((drive->id->config & 0x0060) == 0x20);
  2.4250 +    else
  2.4251 +	CDROM_CONFIG_FLAGS (drive)->drq_interrupt = 0;
  2.4252 +
  2.4253 +    CDROM_CONFIG_FLAGS (drive)->is_changer = 0;
  2.4254 +    CDROM_CONFIG_FLAGS (drive)->cd_r = 0;
  2.4255 +    CDROM_CONFIG_FLAGS (drive)->cd_rw = 0;
  2.4256 +    CDROM_CONFIG_FLAGS (drive)->test_write = 0;
  2.4257 +    CDROM_CONFIG_FLAGS (drive)->dvd = 0;
  2.4258 +    CDROM_CONFIG_FLAGS (drive)->dvd_r = 0;
  2.4259 +    CDROM_CONFIG_FLAGS (drive)->dvd_ram = 0;
  2.4260 +    CDROM_CONFIG_FLAGS (drive)->no_eject = 1;
  2.4261 +    CDROM_CONFIG_FLAGS (drive)->supp_disc_present = 0;
  2.4262 +    CDROM_CONFIG_FLAGS (drive)->audio_play = 0;
  2.4263 +    CDROM_CONFIG_FLAGS (drive)->close_tray = 1;
  2.4264  	
  2.4265 -	/* limit transfer size per interrupt. */
  2.4266 -	CDROM_CONFIG_FLAGS (drive)->limit_nframes = 0;
  2.4267 -	if (drive->id != NULL) {
  2.4268 -		/* a testament to the nice quality of Samsung drives... */
  2.4269 -		if (!strcmp(drive->id->model, "SAMSUNG CD-ROM SCR-2430"))
  2.4270 -			CDROM_CONFIG_FLAGS (drive)->limit_nframes = 1;
  2.4271 -		else if (!strcmp(drive->id->model, "SAMSUNG CD-ROM SCR-2432"))
  2.4272 -			CDROM_CONFIG_FLAGS (drive)->limit_nframes = 1;
  2.4273 -		/* the 3231 model does not support the SET_CD_SPEED command */
  2.4274 -		else if (!strcmp(drive->id->model, "SAMSUNG CD-ROM SCR-3231"))
  2.4275 -			cdi->mask |= CDC_SELECT_SPEED;
  2.4276 -	}
  2.4277 +    /* limit transfer size per interrupt. */
  2.4278 +    CDROM_CONFIG_FLAGS (drive)->limit_nframes = 0;
  2.4279 +    if (drive->id != NULL) {
  2.4280 +	/* a testament to the nice quality of Samsung drives... */
  2.4281 +	if (!strcmp(drive->id->model, "SAMSUNG CD-ROM SCR-2430"))
  2.4282 +	    CDROM_CONFIG_FLAGS (drive)->limit_nframes = 1;
  2.4283 +	else if (!strcmp(drive->id->model, "SAMSUNG CD-ROM SCR-2432"))
  2.4284 +	    CDROM_CONFIG_FLAGS (drive)->limit_nframes = 1;
  2.4285 +	/* the 3231 model does not support the SET_CD_SPEED command */
  2.4286 +	else if (!strcmp(drive->id->model, "SAMSUNG CD-ROM SCR-3231"))
  2.4287 +	    cdi->mask |= CDC_SELECT_SPEED;
  2.4288 +    }
  2.4289  
  2.4290  #if ! STANDARD_ATAPI
  2.4291 -	/* by default Sanyo 3 CD changer support is turned off and
  2.4292 -           ATAPI Rev 2.2+ standard support for CD changers is used */
  2.4293 -	cdi->sanyo_slot = 0;
  2.4294 -
  2.4295 -	CDROM_CONFIG_FLAGS (drive)->nec260 = 0;
  2.4296 -	CDROM_CONFIG_FLAGS (drive)->toctracks_as_bcd = 0;
  2.4297 -	CDROM_CONFIG_FLAGS (drive)->tocaddr_as_bcd = 0;
  2.4298 -	CDROM_CONFIG_FLAGS (drive)->playmsf_as_bcd = 0;
  2.4299 -	CDROM_CONFIG_FLAGS (drive)->subchan_as_bcd = 0;
  2.4300 -
  2.4301 -	if (drive->id != NULL) {
  2.4302 -		if (strcmp (drive->id->model, "V003S0DS") == 0 &&
  2.4303 -		    drive->id->fw_rev[4] == '1' &&
  2.4304 -		    drive->id->fw_rev[6] <= '2') {
  2.4305 -			/* Vertos 300.
  2.4306 -			   Some versions of this drive like to talk BCD. */
  2.4307 -			CDROM_CONFIG_FLAGS (drive)->toctracks_as_bcd = 1;
  2.4308 -			CDROM_CONFIG_FLAGS (drive)->tocaddr_as_bcd = 1;
  2.4309 -			CDROM_CONFIG_FLAGS (drive)->playmsf_as_bcd = 1;
  2.4310 -			CDROM_CONFIG_FLAGS (drive)->subchan_as_bcd = 1;
  2.4311 -		}
  2.4312 -
  2.4313 -		else if (strcmp (drive->id->model, "V006E0DS") == 0 &&
  2.4314 -		    drive->id->fw_rev[4] == '1' &&
  2.4315 -		    drive->id->fw_rev[6] <= '2') {
  2.4316 -			/* Vertos 600 ESD. */
  2.4317 -			CDROM_CONFIG_FLAGS (drive)->toctracks_as_bcd = 1;
  2.4318 -		}
  2.4319 -
  2.4320 -		else if (strcmp (drive->id->model,
  2.4321 -				 "NEC CD-ROM DRIVE:260") == 0 &&
  2.4322 -			 strncmp (drive->id->fw_rev, "1.01", 4) == 0) { /* FIXME */
  2.4323 -			/* Old NEC260 (not R).
  2.4324 -			   This drive was released before the 1.2 version
  2.4325 -			   of the spec. */
  2.4326 -			CDROM_CONFIG_FLAGS (drive)->tocaddr_as_bcd = 1;
  2.4327 -			CDROM_CONFIG_FLAGS (drive)->playmsf_as_bcd = 1;
  2.4328 -			CDROM_CONFIG_FLAGS (drive)->subchan_as_bcd = 1;
  2.4329 -			CDROM_CONFIG_FLAGS (drive)->nec260         = 1;
  2.4330 -		}
  2.4331 -
  2.4332 -		else if (strcmp (drive->id->model, "WEARNES CDD-120") == 0 &&
  2.4333 -			 strncmp (drive->id->fw_rev, "A1.1", 4) == 0) { /* FIXME */
  2.4334 -			/* Wearnes */
  2.4335 -			CDROM_CONFIG_FLAGS (drive)->playmsf_as_bcd = 1;
  2.4336 -			CDROM_CONFIG_FLAGS (drive)->subchan_as_bcd = 1;
  2.4337 -		}
  2.4338 -
  2.4339 -                /* Sanyo 3 CD changer uses a non-standard command
  2.4340 -                    for CD changing */
  2.4341 -                 else if ((strcmp(drive->id->model, "CD-ROM CDR-C3 G") == 0) ||
  2.4342 -                         (strcmp(drive->id->model, "CD-ROM CDR-C3G") == 0) ||
  2.4343 -                         (strcmp(drive->id->model, "CD-ROM CDR_C36") == 0)) {
  2.4344 -                        /* uses CD in slot 0 when value is set to 3 */
  2.4345 -                        cdi->sanyo_slot = 3;
  2.4346 -                }
  2.4347 -
  2.4348 -
  2.4349 +    /* by default Sanyo 3 CD changer support is turned off and
  2.4350 +       ATAPI Rev 2.2+ standard support for CD changers is used */
  2.4351 +    cdi->sanyo_slot = 0;
  2.4352 +
  2.4353 +    CDROM_CONFIG_FLAGS (drive)->nec260 = 0;
  2.4354 +    CDROM_CONFIG_FLAGS (drive)->toctracks_as_bcd = 0;
  2.4355 +    CDROM_CONFIG_FLAGS (drive)->tocaddr_as_bcd = 0;
  2.4356 +    CDROM_CONFIG_FLAGS (drive)->playmsf_as_bcd = 0;
  2.4357 +    CDROM_CONFIG_FLAGS (drive)->subchan_as_bcd = 0;
  2.4358 +
  2.4359 +    if (drive->id != NULL) {
  2.4360 +	if (strcmp (drive->id->model, "V003S0DS") == 0 &&
  2.4361 +	    drive->id->fw_rev[4] == '1' &&
  2.4362 +	    drive->id->fw_rev[6] <= '2') {
  2.4363 +	    /* Vertos 300.
  2.4364 +	       Some versions of this drive like to talk BCD. */
  2.4365 +	    CDROM_CONFIG_FLAGS (drive)->toctracks_as_bcd = 1;
  2.4366 +	    CDROM_CONFIG_FLAGS (drive)->tocaddr_as_bcd = 1;
  2.4367 +	    CDROM_CONFIG_FLAGS (drive)->playmsf_as_bcd = 1;
  2.4368 +	    CDROM_CONFIG_FLAGS (drive)->subchan_as_bcd = 1;
  2.4369 +	}
  2.4370 +
  2.4371 +	else if (strcmp (drive->id->model, "V006E0DS") == 0 &&
  2.4372 +		 drive->id->fw_rev[4] == '1' &&
  2.4373 +		 drive->id->fw_rev[6] <= '2') {
  2.4374 +	    /* Vertos 600 ESD. */
  2.4375 +	    CDROM_CONFIG_FLAGS (drive)->toctracks_as_bcd = 1;
  2.4376 +	}
  2.4377 +
  2.4378 +	else if (strcmp (drive->id->model,
  2.4379 +			 "NEC CD-ROM DRIVE:260") == 0 &&
  2.4380 +		 strncmp (drive->id->fw_rev, "1.01", 4) == 0) { /* FIXME */
  2.4381 +	    /* Old NEC260 (not R).
  2.4382 +	       This drive was released before the 1.2 version
  2.4383 +	       of the spec. */
  2.4384 +	    CDROM_CONFIG_FLAGS (drive)->tocaddr_as_bcd = 1;
  2.4385 +	    CDROM_CONFIG_FLAGS (drive)->playmsf_as_bcd = 1;
  2.4386 +	    CDROM_CONFIG_FLAGS (drive)->subchan_as_bcd = 1;
  2.4387 +	    CDROM_CONFIG_FLAGS (drive)->nec260         = 1;
  2.4388  	}
  2.4389 +
  2.4390 +	else if (strcmp (drive->id->model, "WEARNES CDD-120") == 0 &&
  2.4391 +		 strncmp (drive->id->fw_rev, "A1.1", 4) == 0) { /* FIXME */
  2.4392 +	    /* Wearnes */
  2.4393 +	    CDROM_CONFIG_FLAGS (drive)->playmsf_as_bcd = 1;
  2.4394 +	    CDROM_CONFIG_FLAGS (drive)->subchan_as_bcd = 1;
  2.4395 +	}
  2.4396 +
  2.4397 +	/* Sanyo 3 CD changer uses a non-standard command
  2.4398 +	   for CD changing */
  2.4399 +	else if ((strcmp(drive->id->model, "CD-ROM CDR-C3 G") == 0) ||
  2.4400 +		 (strcmp(drive->id->model, "CD-ROM CDR-C3G") == 0) ||
  2.4401 +		 (strcmp(drive->id->model, "CD-ROM CDR_C36") == 0)) {
  2.4402 +	    /* uses CD in slot 0 when value is set to 3 */
  2.4403 +	    cdi->sanyo_slot = 3;
  2.4404 +	}
  2.4405 +
  2.4406 +
  2.4407 +    }
  2.4408  #endif /* not STANDARD_ATAPI */
  2.4409  
  2.4410 -	info->toc		= NULL;
  2.4411 -	info->buffer		= NULL;
  2.4412 -	info->sector_buffered	= 0;
  2.4413 -	info->nsectors_buffered	= 0;
  2.4414 -	info->changer_info      = NULL;
  2.4415 -	info->last_block	= 0;
  2.4416 -	info->start_seek	= 0;
  2.4417 -
  2.4418 -	nslots = ide_cdrom_probe_capabilities (drive);
  2.4419 -
  2.4420 -	if (CDROM_CONFIG_FLAGS(drive)->dvd_ram)
  2.4421 -		set_device_ro(MKDEV(HWIF(drive)->major, minor), 0);
  2.4422 -
  2.4423 -	if (ide_cdrom_register (drive, nslots)) {
  2.4424 -		printk ("%s: ide_cdrom_setup failed to register device with the cdrom driver.\n", drive->name);
  2.4425 -		info->devinfo.handle = NULL;
  2.4426 -		return 1;
  2.4427 -	}
  2.4428 -	ide_cdrom_add_settings(drive);
  2.4429 -	return 0;
  2.4430 +    info->toc		= NULL;
  2.4431 +    info->buffer		= NULL;
  2.4432 +    info->sector_buffered	= 0;
  2.4433 +    info->nsectors_buffered	= 0;
  2.4434 +    info->changer_info      = NULL;
  2.4435 +    info->last_block	= 0;
  2.4436 +    info->start_seek	= 0;
  2.4437 +
  2.4438 +    nslots = ide_cdrom_probe_capabilities (drive);
  2.4439 +
  2.4440 +    if (CDROM_CONFIG_FLAGS(drive)->dvd_ram)
  2.4441 +	set_device_ro(MKDEV(HWIF(drive)->major, minor), 0);
  2.4442 +
  2.4443 +    if (ide_cdrom_register (drive, nslots)) {
  2.4444 +	printk ("%s: ide_cdrom_setup failed to register device with the cdrom driver.\n", drive->name);
  2.4445 +	info->devinfo.handle = NULL;
  2.4446 +	return 1;
  2.4447 +    }
  2.4448 +    ide_cdrom_add_settings(drive);
  2.4449 +    return 0;
  2.4450  }
  2.4451  
  2.4452  /* Forwarding functions to generic routines. */
  2.4453 @@ -2871,137 +2872,137 @@ int ide_cdrom_ioctl (ide_drive_t *drive,
  2.4454  		     struct inode *inode, struct file *file,
  2.4455  		     unsigned int cmd, unsigned long arg)
  2.4456  {
  2.4457 -	return cdrom_ioctl (inode, file, cmd, arg);
  2.4458 +    return cdrom_ioctl (inode, file, cmd, arg);
  2.4459  }
  2.4460  
  2.4461  static
  2.4462  int ide_cdrom_open (struct inode *ip, struct file *fp, ide_drive_t *drive)
  2.4463  {
  2.4464 -	struct cdrom_info *info = drive->driver_data;
  2.4465 -	int rc = -ENOMEM;
  2.4466 -
  2.4467 -	MOD_INC_USE_COUNT;
  2.4468 -	if (info->buffer == NULL)
  2.4469 -		info->buffer = (char *) kmalloc(SECTOR_BUFFER_SIZE, GFP_KERNEL);
  2.4470 -        if ((info->buffer == NULL) || (rc = cdrom_open(ip, fp))) {
  2.4471 -		drive->usage--;
  2.4472 -		MOD_DEC_USE_COUNT;
  2.4473 -	}
  2.4474 -	return rc;
  2.4475 +    struct cdrom_info *info = drive->driver_data;
  2.4476 +    int rc = -ENOMEM;
  2.4477 +
  2.4478 +    MOD_INC_USE_COUNT;
  2.4479 +    if (info->buffer == NULL)
  2.4480 +	info->buffer = (char *) kmalloc(SECTOR_BUFFER_SIZE, GFP_KERNEL);
  2.4481 +    if ((info->buffer == NULL) || (rc = cdrom_open(ip, fp))) {
  2.4482 +	drive->usage--;
  2.4483 +	MOD_DEC_USE_COUNT;
  2.4484 +    }
  2.4485 +    return rc;
  2.4486  }
  2.4487  
  2.4488  static
  2.4489  void ide_cdrom_release (struct inode *inode, struct file *file,
  2.4490  			ide_drive_t *drive)
  2.4491  {
  2.4492 -	cdrom_release (inode, file);
  2.4493 -	MOD_DEC_USE_COUNT;
  2.4494 +    cdrom_release (inode, file);
  2.4495 +    MOD_DEC_USE_COUNT;
  2.4496  }
  2.4497  
  2.4498  static
  2.4499  int ide_cdrom_check_media_change (ide_drive_t *drive)
  2.4500  {
  2.4501 -	return cdrom_media_changed(MKDEV (HWIF (drive)->major,
  2.4502 -			(drive->select.b.unit) << PARTN_BITS));
  2.4503 +    return cdrom_media_changed(MKDEV (HWIF (drive)->major,
  2.4504 +				      (drive->select.b.unit) << PARTN_BITS));
  2.4505  }
  2.4506  
  2.4507  static
  2.4508  void ide_cdrom_revalidate (ide_drive_t *drive)
  2.4509  {
  2.4510 -	struct cdrom_info *info = drive->driver_data;
  2.4511 -	struct atapi_toc *toc;
  2.4512 -	int minor = drive->select.b.unit << PARTN_BITS;
  2.4513 -	struct request_sense sense;
  2.4514 -
  2.4515 -	cdrom_read_toc(drive, &sense);
  2.4516 -
  2.4517 -	if (!CDROM_STATE_FLAGS(drive)->toc_valid)
  2.4518 -		return;
  2.4519 -
  2.4520 -	toc = info->toc;
  2.4521 -
  2.4522 -	/* for general /dev/cdrom like mounting, one big disc */
  2.4523 -	drive->part[0].nr_sects = toc->capacity * SECTORS_PER_FRAME;
  2.4524 -	HWIF(drive)->gd->sizes[minor] = toc->capacity * BLOCKS_PER_FRAME;
  2.4525 -
  2.4526 -	/*
  2.4527 -	 * reset block size, ide_revalidate_disk incorrectly sets it to
  2.4528 -	 * 1024 even for CDROM's
  2.4529 -	 */
  2.4530 -	blk_size[HWIF(drive)->major] = HWIF(drive)->gd->sizes;
  2.4531 +    struct cdrom_info *info = drive->driver_data;
  2.4532 +    struct atapi_toc *toc;
  2.4533 +    int minor = drive->select.b.unit << PARTN_BITS;
  2.4534 +    struct request_sense sense;
  2.4535 +
  2.4536 +    cdrom_read_toc(drive, &sense);
  2.4537 +
  2.4538 +    if (!CDROM_STATE_FLAGS(drive)->toc_valid)
  2.4539 +	return;
  2.4540 +
  2.4541 +    toc = info->toc;
  2.4542 +
  2.4543 +    /* for general /dev/cdrom like mounting, one big disc */
  2.4544 +    drive->part[0].nr_sects = toc->capacity * SECTORS_PER_FRAME;
  2.4545 +    HWIF(drive)->gd->sizes[minor] = toc->capacity * BLOCKS_PER_FRAME;
  2.4546 +
  2.4547 +    /*
  2.4548 +     * reset block size, ide_revalidate_disk incorrectly sets it to
  2.4549 +     * 1024 even for CDROM's
  2.4550 +     */
  2.4551 +    blk_size[HWIF(drive)->major] = HWIF(drive)->gd->sizes;
  2.4552  #if 0
  2.4553 -	set_blocksize(MKDEV(HWIF(drive)->major, minor), CD_FRAMESIZE);
  2.4554 +    set_blocksize(MKDEV(HWIF(drive)->major, minor), CD_FRAMESIZE);
  2.4555  #endif
  2.4556  }
  2.4557  
  2.4558  static
  2.4559  unsigned long ide_cdrom_capacity (ide_drive_t *drive)
  2.4560  {
  2.4561 -	unsigned long capacity;
  2.4562 -
  2.4563 -	if (cdrom_read_capacity(drive, &capacity, NULL))
  2.4564 -		return 0;
  2.4565 -
  2.4566 -	return capacity * SECTORS_PER_FRAME;
  2.4567 +    unsigned long capacity;
  2.4568 +
  2.4569 +    if (cdrom_read_capacity(drive, &capacity, NULL))
  2.4570 +	return 0;
  2.4571 +
  2.4572 +    return capacity * SECTORS_PER_FRAME;
  2.4573  }
  2.4574  
  2.4575  static
  2.4576  int ide_cdrom_cleanup(ide_drive_t *drive)
  2.4577  {
  2.4578 -	struct cdrom_info *info = drive->driver_data;
  2.4579 -	struct cdrom_device_info *devinfo = &info->devinfo;
  2.4580 -
  2.4581 -	if (ide_unregister_subdriver (drive))
  2.4582 -		return 1;
  2.4583 -	if (info->buffer != NULL)
  2.4584 -		kfree(info->buffer);
  2.4585 -	if (info->toc != NULL)
  2.4586 -		kfree(info->toc);
  2.4587 -	if (info->changer_info != NULL)
  2.4588 -		kfree(info->changer_info);
  2.4589 -	if (devinfo->handle == drive && unregister_cdrom (devinfo))
  2.4590 -		printk ("%s: ide_cdrom_cleanup failed to unregister device from the cdrom driver.\n", drive->name);
  2.4591 -	kfree(info);
  2.4592 -	drive->driver_data = NULL;
  2.4593 -	return 0;
  2.4594 +    struct cdrom_info *info = drive->driver_data;
  2.4595 +    struct cdrom_device_info *devinfo = &info->devinfo;
  2.4596 +
  2.4597 +    if (ide_unregister_subdriver (drive))
  2.4598 +	return 1;
  2.4599 +    if (info->buffer != NULL)
  2.4600 +	kfree(info->buffer);
  2.4601 +    if (info->toc != NULL)
  2.4602 +	kfree(info->toc);
  2.4603 +    if (info->changer_info != NULL)
  2.4604 +	kfree(info->changer_info);
  2.4605 +    if (devinfo->handle == drive && unregister_cdrom (devinfo))
  2.4606 +	printk ("%s: ide_cdrom_cleanup failed to unregister device from the cdrom driver.\n", drive->name);
  2.4607 +    kfree(info);
  2.4608 +    drive->driver_data = NULL;
  2.4609 +    return 0;
  2.4610  }
  2.4611  
  2.4612  static
  2.4613  int ide_cdrom_reinit (ide_drive_t *drive)
  2.4614  {
  2.4615 -	return 0;
  2.4616 +    return 0;
  2.4617  }
  2.4618  
  2.4619  static ide_driver_t ide_cdrom_driver = {
  2.4620 -	name:			"ide-cdrom",
  2.4621 -	version:		IDECD_VERSION,
  2.4622 -	media:			ide_cdrom,
  2.4623 -	busy:			0,
  2.4624 -	supports_dma:		1,
  2.4625 -	supports_dsc_overlap:	1,
  2.4626 -	cleanup:		ide_cdrom_cleanup,
  2.4627 -	do_request:		ide_do_rw_cdrom,
  2.4628 -	end_request:		NULL,
  2.4629 -	ioctl:			ide_cdrom_ioctl,
  2.4630 -	open:			ide_cdrom_open,
  2.4631 -	release:		ide_cdrom_release,
  2.4632 -	media_change:		ide_cdrom_check_media_change,
  2.4633 -	revalidate:		ide_cdrom_revalidate,
  2.4634 -	pre_reset:		NULL,
  2.4635 -	capacity:		ide_cdrom_capacity,
  2.4636 -	special:		NULL,
  2.4637 +    name:			"ide-cdrom",
  2.4638 +    version:		IDECD_VERSION,
  2.4639 +    media:			ide_cdrom,
  2.4640 +    busy:			0,
  2.4641 +    supports_dma:		1,
  2.4642 +    supports_dsc_overlap:	1,
  2.4643 +    cleanup:		ide_cdrom_cleanup,
  2.4644 +    do_request:		ide_do_rw_cdrom,
  2.4645 +    end_request:		NULL,
  2.4646 +    ioctl:			ide_cdrom_ioctl,
  2.4647 +    open:			ide_cdrom_open,
  2.4648 +    release:		ide_cdrom_release,
  2.4649 +    media_change:		ide_cdrom_check_media_change,
  2.4650 +    revalidate:		ide_cdrom_revalidate,
  2.4651 +    pre_reset:		NULL,
  2.4652 +    capacity:		ide_cdrom_capacity,
  2.4653 +    special:		NULL,
  2.4654  #if 0
  2.4655 -	proc:			NULL,
  2.4656 -	driver_reinit:		ide_cdrom_reinit,
  2.4657 +    proc:			NULL,
  2.4658 +    driver_reinit:		ide_cdrom_reinit,
  2.4659  #endif
  2.4660  };
  2.4661  
  2.4662  int ide_cdrom_init(void);
  2.4663  static ide_module_t ide_cdrom_module = {
  2.4664 -	IDE_DRIVER_MODULE,
  2.4665 -	ide_cdrom_init,
  2.4666 -	&ide_cdrom_driver,
  2.4667 -	NULL
  2.4668 +    IDE_DRIVER_MODULE,
  2.4669 +    ide_cdrom_init,
  2.4670 +    &ide_cdrom_driver,
  2.4671 +    NULL
  2.4672  };
  2.4673  
  2.4674  /* options */
  2.4675 @@ -3012,61 +3013,61 @@ MODULE_DESCRIPTION("ATAPI CD-ROM Driver"
  2.4676  
  2.4677  static void __exit ide_cdrom_exit(void)
  2.4678  {
  2.4679 -	ide_drive_t *drive;
  2.4680 -	int failed = 0;
  2.4681 -
  2.4682 -	while ((drive = ide_scan_devices (ide_cdrom, ide_cdrom_driver.name, &ide_cdrom_driver, failed)) != NULL)
  2.4683 -		if (ide_cdrom_cleanup (drive)) {
  2.4684 -			printk ("%s: cleanup_module() called while still busy\n", drive->name);
  2.4685 -			failed++;
  2.4686 -		}
  2.4687 -	ide_unregister_module (&ide_cdrom_module);
  2.4688 +    ide_drive_t *drive;
  2.4689 +    int failed = 0;
  2.4690 +
  2.4691 +    while ((drive = ide_scan_devices (ide_cdrom, ide_cdrom_driver.name, &ide_cdrom_driver, failed)) != NULL)
  2.4692 +	if (ide_cdrom_cleanup (drive)) {
  2.4693 +	    printk ("%s: cleanup_module() called while still busy\n", drive->name);
  2.4694 +	    failed++;
  2.4695 +	}
  2.4696 +    ide_unregister_module (&ide_cdrom_module);
  2.4697  }
  2.4698   
  2.4699  int ide_cdrom_init(void)
  2.4700  {
  2.4701 -	ide_drive_t *drive;
  2.4702 -	struct cdrom_info *info;
  2.4703 -	int failed = 0;
  2.4704 -
  2.4705 -	MOD_INC_USE_COUNT;
  2.4706 -	while ((drive = ide_scan_devices (ide_cdrom, ide_cdrom_driver.name, NULL, failed++)) != NULL) {
  2.4707 -		/* skip drives that we were told to ignore */
  2.4708 -		if (ignore != NULL) {
  2.4709 -			if (strstr(ignore, drive->name)) {
  2.4710 -				printk("ide-cd: ignoring drive %s\n", drive->name);
  2.4711 -				continue;
  2.4712 -			}
  2.4713 -		}
  2.4714 -		if (drive->scsi) {
  2.4715 -			printk("ide-cd: passing drive %s to ide-scsi emulation.\n", drive->name);
  2.4716 -			continue;
  2.4717 -		}
  2.4718 -		info = (struct cdrom_info *) kmalloc (sizeof (struct cdrom_info), GFP_KERNEL);
  2.4719 -		if (info == NULL) {
  2.4720 -			printk ("%s: Can't allocate a cdrom structure\n", drive->name);
  2.4721 -			continue;
  2.4722 -		}
  2.4723 -		if (ide_register_subdriver (drive, &ide_cdrom_driver, IDE_SUBDRIVER_VERSION)) {
  2.4724 -			printk ("%s: Failed to register the driver with ide.c\n", drive->name);
  2.4725 -			kfree (info);
  2.4726 -			continue;
  2.4727 -		}
  2.4728 -		memset (info, 0, sizeof (struct cdrom_info));
  2.4729 -		drive->driver_data = info;
  2.4730 -		DRIVER(drive)->busy++;
  2.4731 -		if (ide_cdrom_setup (drive)) {
  2.4732 -			DRIVER(drive)->busy--;
  2.4733 -			if (ide_cdrom_cleanup (drive))
  2.4734 -				printk ("%s: ide_cdrom_cleanup failed in ide_cdrom_init\n", drive->name);
  2.4735 -			continue;
  2.4736 -		}
  2.4737 -		DRIVER(drive)->busy--;
  2.4738 -		failed--;
  2.4739 +    ide_drive_t *drive;
  2.4740 +    struct cdrom_info *info;
  2.4741 +    int failed = 0;
  2.4742 +
  2.4743 +    MOD_INC_USE_COUNT;
  2.4744 +    while ((drive = ide_scan_devices (ide_cdrom, ide_cdrom_driver.name, NULL, failed++)) != NULL) {
  2.4745 +	/* skip drives that we were told to ignore */
  2.4746 +	if (ignore != NULL) {
  2.4747 +	    if (strstr(ignore, drive->name)) {
  2.4748 +		printk("ide-cd: ignoring drive %s\n", drive->name);
  2.4749 +		continue;
  2.4750 +	    }
  2.4751 +	}
  2.4752 +	if (drive->scsi) {
  2.4753 +	    printk("ide-cd: passing drive %s to ide-scsi emulation.\n", drive->name);
  2.4754 +	    continue;
  2.4755  	}
  2.4756 -	ide_register_module(&ide_cdrom_module);
  2.4757 -	MOD_DEC_USE_COUNT;
  2.4758 -	return 0;
  2.4759 +	info = (struct cdrom_info *) kmalloc (sizeof (struct cdrom_info), GFP_KERNEL);
  2.4760 +	if (info == NULL) {
  2.4761 +	    printk ("%s: Can't allocate a cdrom structure\n", drive->name);
  2.4762 +	    continue;
  2.4763 +	}
  2.4764 +	if (ide_register_subdriver (drive, &ide_cdrom_driver, IDE_SUBDRIVER_VERSION)) {
  2.4765 +	    printk ("%s: Failed to register the driver with ide.c\n", drive->name);
  2.4766 +	    kfree (info);
  2.4767 +	    continue;
  2.4768 +	}
  2.4769 +	memset (info, 0, sizeof (struct cdrom_info));
  2.4770 +	drive->driver_data = info;
  2.4771 +	DRIVER(drive)->busy++;
  2.4772 +	if (ide_cdrom_setup (drive)) {
  2.4773 +	    DRIVER(drive)->busy--;
  2.4774 +	    if (ide_cdrom_cleanup (drive))
  2.4775 +		printk ("%s: ide_cdrom_cleanup failed in ide_cdrom_init\n", drive->name);
  2.4776 +	    continue;
  2.4777 +	}
  2.4778 +	DRIVER(drive)->busy--;
  2.4779 +	failed--;
  2.4780 +    }
  2.4781 +    ide_register_module(&ide_cdrom_module);
  2.4782 +    MOD_DEC_USE_COUNT;
  2.4783 +    return 0;
  2.4784  }
  2.4785  
  2.4786  module_init(ide_cdrom_init);
     3.1 --- a/xen/drivers/ide/ide-disk.c	Wed Apr 16 22:41:46 2003 +0000
     3.2 +++ b/xen/drivers/ide/ide-disk.c	Thu Apr 17 16:44:40 2003 +0000
     3.3 @@ -1322,10 +1322,6 @@ static void idedisk_setup (ide_drive_t *
     3.4  	struct hd_driveid *id = drive->id;
     3.5  	unsigned long capacity;
     3.6  
     3.7 -	printk (KERN_ALERT
     3.8 -		"ide-disk.c::idedisk_setup: chs %d %d %d\n",
     3.9 -		drive->cyl, drive->head, drive->sect);
    3.10 -	
    3.11  	idedisk_add_settings(drive);
    3.12  
    3.13  	if (id == NULL)
    3.14 @@ -1388,7 +1384,7 @@ static void idedisk_setup (ide_drive_t *
    3.15  	if ((capacity >= (drive->bios_cyl * drive->bios_sect * drive->bios_head)) &&
    3.16  	    (!drive->forced_geom) && drive->bios_sect && drive->bios_head)
    3.17  		drive->bios_cyl = (capacity / drive->bios_sect) / drive->bios_head;
    3.18 -	printk (KERN_INFO "[XEN] %s: %ld sectors", drive->name, capacity);
    3.19 +	printk (KERN_INFO "%s: %ld sectors", drive->name, capacity);
    3.20  
    3.21  	/* Give size in megabytes (MB), not mebibytes (MiB). */
    3.22  	/* We compute the exact rounded value, avoiding overflow. */
     4.1 --- a/xen/drivers/ide/ide-xeno.c	Wed Apr 16 22:41:46 2003 +0000
     4.2 +++ b/xen/drivers/ide/ide-xeno.c	Thu Apr 17 16:44:40 2003 +0000
     4.3 @@ -12,7 +12,8 @@ void ide_probe_devices(xen_disk_info_t* 
     4.4      int loop;
     4.5      unsigned int unit;
     4.6      xen_disk_info_t *xen_xdi = map_domain_mem(virt_to_phys(xdi));
     4.7 -    unsigned long capacity, device;
     4.8 +    unsigned long capacity; 
     4.9 +    unsigned short device, type; 
    4.10      ide_drive_t *drive;
    4.11      
    4.12      for ( loop = 0; loop < MAX_HWIFS; loop++ )
    4.13 @@ -23,17 +24,27 @@ void ide_probe_devices(xen_disk_info_t* 
    4.14          for ( unit = 0; unit < MAX_DRIVES; unit++ )
    4.15          {
    4.16              drive = &hwif->drives[unit];
    4.17 +
    4.18              if ( !drive->present ) continue;
    4.19              
    4.20 +	    /* 
    4.21 +	    ** NB: we use the ide 'media' field (ide_disk, ide_cdrom, etc) 
    4.22 +	    ** as our 'type' field (XD_TYPE_DISK, XD_TYPE_CDROM, etc). 
    4.23 +	    ** Hence must ensure these are kept in sync. 
    4.24 +	    */
    4.25 +	    type     = drive->media; 
    4.26              device   = MK_IDE_XENDEV((loop * MAX_DRIVES) + unit);
    4.27              capacity = current_capacity(drive);
    4.28  
    4.29 -            xen_xdi->disks[xen_xdi->count].device   = device;
    4.30 +            xen_xdi->disks[xen_xdi->count].device   = device; 
    4.31 +            xen_xdi->disks[xen_xdi->count].type     = type; 
    4.32              xen_xdi->disks[xen_xdi->count].capacity = capacity;
    4.33              xen_xdi->count++;
    4.34  
    4.35 -            printk("Disk %d: IDE-XENO capacity %ldkB (%ldMB)\n",
    4.36 -                   xen_xdi->count, capacity>>1, capacity>>11);
    4.37 +            printk("Device %d: IDE-XENO (%s) capacity %ldkB (%ldMB)\n",
    4.38 +                   xen_xdi->count, (type == XD_TYPE_DISK) ? "disk" : 
    4.39 +		   ((type == XD_TYPE_CDROM) ? "cdrom" : "unknown"), 
    4.40 +		   capacity>>1, capacity>>11);
    4.41          }
    4.42      }
    4.43  
     5.1 --- a/xen/drivers/ide/ide.c	Wed Apr 16 22:41:46 2003 +0000
     5.2 +++ b/xen/drivers/ide/ide.c	Thu Apr 17 16:44:40 2003 +0000
     5.3 @@ -2061,21 +2061,14 @@ int ide_do_drive_cmd (ide_drive_t *drive
     5.4      /* XXX SMH: spin waiting for response */
     5.5      if (action == ide_wait) { 
     5.6  
     5.7 -	/* if we get an error, ide-cd.c requeues (and kills our 'waitq') */
     5.8 -	if((rq->waiting != NULL) && *(int *)(rq->waiting)) {
     5.9 -	    do { 
    5.10 -		udelay(500); 
    5.11 -		usecs += 500; 
    5.12 -		if(usecs > 1000000) { 
    5.13 -		    printk("ide_do_drive_cmd [ide_wait]: giving "
    5.14 -			   "up after 1s\n"); 
    5.15 -		    *(int *)rq->waiting = 0; 
    5.16 -		}
    5.17 -	    } while((rq->waiting != NULL) && *(int *)(rq->waiting)); 
    5.18 +	while(wait) { 
    5.19 +	    udelay(500); 
    5.20 +	    usecs += 500; 
    5.21 +	    if(usecs > 1000000) { 
    5.22 +		printk("ide_do_drive_cmd [ide_wait]: still waiting\n"); 
    5.23 +		usecs = 0; 
    5.24 +	    }
    5.25  	}
    5.26 -
    5.27 -	if(rq->waiting == NULL)
    5.28 -	    return 1; 
    5.29      }
    5.30  
    5.31      return 0;
     6.1 --- a/xen/drivers/scsi/scsi.c	Wed Apr 16 22:41:46 2003 +0000
     6.2 +++ b/xen/drivers/scsi/scsi.c	Thu Apr 17 16:44:40 2003 +0000
     6.3 @@ -847,12 +847,12 @@ void scsi_wait_req (Scsi_Request * SRpnt
     6.4         we've waited on &wait -- hence we deallocate the command structure
     6.5         if it hasn't been done already. This is not the correct behaviour 
     6.6         in xen ... hmm .. how to fix? */
     6.7 -    while(*(int *)(SRpnt->sr_request.waiting)) {
     6.8 +    while(wait) { 
     6.9          udelay(500); 
    6.10          usecs += 500; 
    6.11          if(usecs > 1000000) {
    6.12 -            printk("scsi_wait_req: giving up after 1 seconds!\n"); 
    6.13 -            *(int *)(SRpnt->sr_request.waiting) = 0; 
    6.14 +            printk("scsi_wait_req: still waiting...!\n"); 
    6.15 +            usecs = 0; 
    6.16          } 
    6.17      }
    6.18  #endif
     7.1 --- a/xen/drivers/scsi/sd.c	Wed Apr 16 22:41:46 2003 +0000
     7.2 +++ b/xen/drivers/scsi/sd.c	Thu Apr 17 16:44:40 2003 +0000
     7.3 @@ -1329,11 +1329,13 @@ void scsi_probe_devices(xen_disk_info_t 
     7.4          device   = MK_SCSI_XENDEV(i);
     7.5          capacity = sd->capacity;
     7.6  
     7.7 +	/* XXX SMH: if make generic, need to properly determine 'type' */
     7.8          xen_xdi->disks[xen_xdi->count].device   = device;
     7.9 +	xen_xdi->disks[xen_xdi->count].type     = XD_TYPE_DISK; 
    7.10          xen_xdi->disks[xen_xdi->count].capacity = capacity; 
    7.11          xen_xdi->count++; 
    7.12                  
    7.13 -        printk("Disk %d: SCSI-XENO capacity %ldkB (%ldMB)\n",
    7.14 +        printk("Device %d: SCSI-XENO (disk) capacity %ldkB (%ldMB)\n",
    7.15                 xen_xdi->count, capacity>>1, capacity>>11);
    7.16      }
    7.17  
     8.1 --- a/xen/include/hypervisor-ifs/block.h	Wed Apr 16 22:41:46 2003 +0000
     8.2 +++ b/xen/include/hypervisor-ifs/block.h	Thu Apr 17 16:44:40 2003 +0000
     8.3 @@ -94,10 +94,18 @@ typedef struct blk_ring_st
     8.4  
     8.5  #define XEN_MAX_DISK_COUNT 100
     8.6  
     8.7 +/* XXX SMH: below types chosen to align with ide_xxx types in ide.h */
     8.8 +#define XD_TYPE_FLOPPY  0x00
     8.9 +#define XD_TYPE_TAPE    0x01
    8.10 +#define XD_TYPE_CDROM   0x05
    8.11 +#define XD_TYPE_OPTICAL 0x07
    8.12 +#define XD_TYPE_DISK    0x20 
    8.13 +
    8.14  typedef struct xen_disk
    8.15  {
    8.16 -    unsigned short device;
    8.17 -    unsigned long  capacity;
    8.18 +    unsigned short device;       /* device number (see top of file)    */
    8.19 +    unsigned short type;         /* device type, i.e. disk, cdrom, etc */
    8.20 +    unsigned long  capacity;     /* size in terms of #512 byte sectors */
    8.21  } xen_disk_t;
    8.22  
    8.23  typedef struct xen_disk_info
     9.1 --- a/xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/block/xl_ide.c	Wed Apr 16 22:41:46 2003 +0000
     9.2 +++ b/xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/block/xl_ide.c	Thu Apr 17 16:44:40 2003 +0000
     9.3 @@ -28,7 +28,6 @@ static struct block_device_operations xl
     9.4      revalidate:         xenolinux_block_revalidate,
     9.5  };
     9.6  
     9.7 -
     9.8  int xlide_hwsect(int minor) 
     9.9  {
    9.10      return xlide_hardsect_size[minor]; 
    9.11 @@ -38,7 +37,9 @@ int xlide_hwsect(int minor)
    9.12  int xlide_init(xen_disk_info_t *xdi) 
    9.13  {
    9.14      int i, result, units, minors, disk;
    9.15 +    unsigned short minor; 
    9.16      struct gendisk *gd;
    9.17 +    char buf[64]; 
    9.18  
    9.19      /* If we don't have any usable IDE devices we may as well bail now. */
    9.20      units = 0;
    9.21 @@ -107,18 +108,43 @@ int xlide_init(xen_disk_info_t *xdi)
    9.22      /* Now register each disk in turn. */
    9.23      for ( i = 0; i < xdi->count; i++ )
    9.24      {
    9.25 -        disk = xdi->disks[i].device & XENDEV_IDX_MASK;
    9.26 +        disk  = xdi->disks[i].device & XENDEV_IDX_MASK;
    9.27 +	minor = disk << XLIDE_PARTN_SHIFT; 
    9.28 +
    9.29  
    9.30          /* We can use the first 16 IDE devices. */
    9.31          if ( !IS_IDE_XENDEV(xdi->disks[i].device) || (disk >= 16) ) continue;
    9.32  
    9.33          ((xl_disk_t *)gd->real_devices)[disk].capacity =
    9.34              xdi->disks[i].capacity;
    9.35 -        register_disk(gd, 
    9.36 -                      MKDEV(XLIDE_MAJOR, disk<<XLIDE_PARTN_SHIFT), 
    9.37 -                      1<<XLIDE_PARTN_SHIFT, 
    9.38 -                      &xlide_block_fops, 
    9.39 -                      xdi->disks[i].capacity);
    9.40 +
    9.41 +
    9.42 +	switch (xdi->disks[i].type) { 
    9.43 +	case XD_TYPE_CDROM:
    9.44 +	    set_device_ro(MKDEV(XLIDE_MAJOR, minor), 1); 
    9.45 +	    // fall through
    9.46 +
    9.47 +	case XD_TYPE_FLOPPY: 
    9.48 +	case XD_TYPE_TAPE:
    9.49 +	    gd->flags[disk] = GENHD_FL_REMOVABLE; 
    9.50 +	    printk(KERN_ALERT "Skipping partition check on %s /dev/%s\n", 
    9.51 +		   xdi->disks[i].type == XD_TYPE_CDROM ? "cdrom" : 
    9.52 +		   (xdi->disks[i].type == XD_TYPE_TAPE ? "tape" : "floppy"), 
    9.53 +		   disk_name(gd, minor, buf)); 
    9.54 +	    break; 
    9.55 +
    9.56 +	case XD_TYPE_DISK: 
    9.57 +	    register_disk(gd, MKDEV(XLIDE_MAJOR, minor), 1<<XLIDE_PARTN_SHIFT, 
    9.58 +			  &xlide_block_fops, xdi->disks[i].capacity);
    9.59 +	    break; 
    9.60 +
    9.61 +	default: 
    9.62 +	    printk(KERN_ALERT "XenoLinux: unknown ide device type %d\n", 
    9.63 +		   xdi->disks[i].type); 
    9.64 +	    break; 
    9.65 +	}
    9.66 +
    9.67 +
    9.68      }
    9.69  
    9.70      printk(KERN_ALERT