From 21ea1f0f011a5bbfbc3f5c134a4e537e5f5c1c50 Mon Sep 17 00:00:00 2001 From: Bartlomiej Zolnierkiewicz Date: Fri, 1 Feb 2008 23:09:27 +0100 Subject: [PATCH] ide-cd: merge cdrom_start_read() and cdrom_start_write() Add handling of read requests to cdrom_start_write(), rename it to cdrom_start_rw() and remove no longer needed cdrom_start_read(). There should be no functionality changes caused by this patch. Signed-off-by: Bartlomiej Zolnierkiewicz --- drivers/ide/ide-cd.c | 101 +++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 61 deletions(-) diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c index edcdc7432ddf..4b395e015e76 100644 --- a/drivers/ide/ide-cd.c +++ b/drivers/ide/ide-cd.c @@ -918,38 +918,6 @@ static void restore_request (struct request *rq) rq->q->prep_rq_fn(rq->q, rq); } -/* - * Start a read request from the CD-ROM. - */ -static ide_startstop_t cdrom_start_read (ide_drive_t *drive, unsigned int block) -{ - struct cdrom_info *info = drive->driver_data; - struct request *rq = HWGROUP(drive)->rq; - unsigned short sectors_per_frame; - - sectors_per_frame = queue_hardsect_size(drive->queue) >> SECTOR_BITS; - - /* We may be retrying this request after an error. Fix up - any weirdness which might be present in the request packet. */ - restore_request(rq); - - /* Satisfy whatever we can of this request from our cached sector. */ - if (cdrom_read_from_buffer(drive)) - return ide_stopped; - - /* Clear the local sector buffer. */ - info->nsectors_buffered = 0; - - /* use dma, if possible. */ - info->dma = drive->using_dma; - if ((rq->sector & (sectors_per_frame - 1)) || - (rq->nr_sectors & (sectors_per_frame - 1))) - info->dma = 0; - - /* Start sending the read request to the drive. */ - return cdrom_start_packet_command(drive, 32768, cdrom_start_rw_cont); -} - /**************************************************************************** * Execute all other packet commands. */ @@ -1383,38 +1351,53 @@ static ide_startstop_t cdrom_rw_intr(ide_drive_t *drive) return ide_started; } -static ide_startstop_t cdrom_start_write(ide_drive_t *drive, struct request *rq) +static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq) { - struct cdrom_info *info = drive->driver_data; - struct gendisk *g = info->disk; - unsigned short sectors_per_frame = queue_hardsect_size(drive->queue) >> SECTOR_BITS; + struct cdrom_info *cd = drive->driver_data; + int write = rq_data_dir(rq) == WRITE; + unsigned short sectors_per_frame = + queue_hardsect_size(drive->queue) >> SECTOR_BITS; - /* - * writes *must* be hardware frame aligned - */ - if ((rq->nr_sectors & (sectors_per_frame - 1)) || - (rq->sector & (sectors_per_frame - 1))) { - cdrom_end_request(drive, 0); - return ide_stopped; + if (write) { + /* + * disk has become write protected + */ + if (cd->disk->policy) { + cdrom_end_request(drive, 0); + return ide_stopped; + } + } else { + /* + * We may be retrying this request after an error. Fix up any + * weirdness which might be present in the request packet. + */ + restore_request(rq); + + /* Satisfy whatever we can of this request from our cache. */ + if (cdrom_read_from_buffer(drive)) + return ide_stopped; } /* - * disk has become write protected + * use DMA, if possible / writes *must* be hardware frame aligned */ - if (g->policy) { - cdrom_end_request(drive, 0); - return ide_stopped; - } - - info->nsectors_buffered = 0; + if ((rq->nr_sectors & (sectors_per_frame - 1)) || + (rq->sector & (sectors_per_frame - 1))) { + if (write) { + cdrom_end_request(drive, 0); + return ide_stopped; + } + cd->dma = 0; + } else + cd->dma = drive->using_dma; - /* use dma, if possible. we don't need to check more, since we - * know that the transfer is always (at least!) frame aligned */ - info->dma = drive->using_dma ? 1 : 0; + /* Clear the local sector buffer. */ + cd->nsectors_buffered = 0; - info->devinfo.media_written = 1; + if (write) + cd->devinfo.media_written = 1; - /* Start sending the write request to the drive. */ + /* Start sending the read/write request to the drive. */ return cdrom_start_packet_command(drive, 32768, cdrom_start_rw_cont); } @@ -1487,12 +1470,8 @@ ide_do_rw_cdrom (ide_drive_t *drive, struct request *rq, sector_t block) } if ((rq_data_dir(rq) == READ) && IDE_LARGE_SEEK(info->last_block, block, IDECD_SEEK_THRESHOLD) && drive->dsc_overlap) { action = cdrom_start_seek(drive, block); - } else { - if (rq_data_dir(rq) == READ) - action = cdrom_start_read(drive, block); - else - action = cdrom_start_write(drive, rq); - } + } else + action = cdrom_start_rw(drive, rq); info->last_block = block; return action; } else if (blk_sense_request(rq) || blk_pc_request(rq) || -- 2.30.2