]> err.no Git - linux-2.6/blobdiff - drivers/ide/ide-cd.c
ide: add ide_read_bcount_and_ireason() helper
[linux-2.6] / drivers / ide / ide-cd.c
index d99847157186e9669efd3f56bfdb5eac54de7042..563a380d0e7a7c4e8585b5e1cc9ea6e1282705c7 100644 (file)
@@ -280,11 +280,12 @@ static void ide_dump_status_no_sense(ide_drive_t *drive, const char *msg, u8 st)
  */
 static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
 {
-       struct request *rq = HWGROUP(drive)->rq;
+       ide_hwif_t *hwif = drive->hwif;
+       struct request *rq = hwif->hwgroup->rq;
        int stat, err, sense_key;
 
        /* check for errors */
-       stat = ide_read_status(drive);
+       stat = hwif->read_status(hwif);
 
        if (stat_ret)
                *stat_ret = stat;
@@ -517,14 +518,9 @@ static ide_startstop_t cdrom_start_packet_command(ide_drive_t *drive,
                                                  int xferlen,
                                                  ide_handler_t *handler)
 {
-       ide_startstop_t startstop;
        struct cdrom_info *info = drive->driver_data;
        ide_hwif_t *hwif = drive->hwif;
 
-       /* wait for the controller to be idle */
-       if (ide_wait_stat(&startstop, drive, 0, BUSY_STAT, WAIT_READY))
-               return startstop;
-
        /* FIXME: for Virtual DMA we must check harder */
        if (info->dma)
                info->dma = !hwif->dma_ops->dma_setup(drive);
@@ -603,28 +599,6 @@ static ide_startstop_t cdrom_transfer_packet_command(ide_drive_t *drive,
        return ide_started;
 }
 
-/*
- * Block read functions.
- */
-static void ide_cd_pad_transfer(ide_drive_t *drive, xfer_func_t *xf, int len)
-{
-       while (len > 0) {
-               int dum = 0;
-               xf(drive, NULL, &dum, sizeof(dum));
-               len -= sizeof(dum);
-       }
-}
-
-static void ide_cd_drain_data(ide_drive_t *drive, int nsects)
-{
-       while (nsects > 0) {
-               static char dum[SECTOR_SIZE];
-
-               drive->hwif->input_data(drive, NULL, dum, sizeof(dum));
-               nsects--;
-       }
-}
-
 /*
  * Check the contents of the interrupt reason register from the cdrom
  * and attempt to recover if there are problems.  Returns  0 if everything's
@@ -633,6 +607,8 @@ static void ide_cd_drain_data(ide_drive_t *drive, int nsects)
 static int ide_cd_check_ireason(ide_drive_t *drive, struct request *rq,
                                int len, int ireason, int rw)
 {
+       ide_hwif_t *hwif = drive->hwif;
+
        /*
         * ireason == 0: the drive wants to receive data from us
         * ireason == 2: the drive is expecting to transfer data to us
@@ -640,21 +616,18 @@ static int ide_cd_check_ireason(ide_drive_t *drive, struct request *rq,
        if (ireason == (!rw << 1))
                return 0;
        else if (ireason == (rw << 1)) {
-               ide_hwif_t *hwif = drive->hwif;
-               xfer_func_t *xf;
 
                /* whoops... */
                printk(KERN_ERR "%s: %s: wrong transfer direction!\n",
                                drive->name, __func__);
 
-               xf = rw ? hwif->output_data : hwif->input_data;
-               ide_cd_pad_transfer(drive, xf, len);
+               ide_pad_transfer(drive, rw, len);
        } else  if (rw == 0 && ireason == 1) {
                /*
                 * Some drives (ASUS) seem to tell us that status info is
                 * available.  Just get it and ignore.
                 */
-               (void)ide_read_status(drive);
+               (void)hwif->read_status(hwif);
                return 0;
        } else {
                /* drive wants a command packet, or invalid ireason... */
@@ -696,16 +669,9 @@ static int ide_cd_check_transfer_size(ide_drive_t *drive, int len)
 
 static ide_startstop_t cdrom_newpc_intr(ide_drive_t *);
 
-/*
- * Routine to send a read/write packet command to the drive. This is usually
- * called directly from cdrom_start_{read,write}(). However, for drq_interrupt
- * devices, it is called from an interrupt when the drive is ready to accept
- * the command.
- */
-static ide_startstop_t cdrom_start_rw_cont(ide_drive_t *drive)
+static ide_startstop_t ide_cd_prepare_rw_request(ide_drive_t *drive,
+                                                struct request *rq)
 {
-       struct request *rq = HWGROUP(drive)->rq;
-
        if (rq_data_dir(rq) == READ) {
                unsigned short sectors_per_frame =
                        queue_hardsect_size(drive->queue) >> SECTOR_BITS;
@@ -742,6 +708,19 @@ static ide_startstop_t cdrom_start_rw_cont(ide_drive_t *drive)
        /* set up the command */
        rq->timeout = ATAPI_WAIT_PC;
 
+       return ide_started;
+}
+
+/*
+ * Routine to send a read/write packet command to the drive. This is usually
+ * called directly from cdrom_start_{read,write}(). However, for drq_interrupt
+ * devices, it is called from an interrupt when the drive is ready to accept
+ * the command.
+ */
+static ide_startstop_t cdrom_start_rw_cont(ide_drive_t *drive)
+{
+       struct request *rq = drive->hwif->hwgroup->rq;
+
        /* send the command to the drive and return */
        return cdrom_transfer_packet_command(drive, rq, cdrom_newpc_intr);
 }
@@ -768,9 +747,8 @@ static ide_startstop_t cdrom_seek_intr(ide_drive_t *drive)
        return ide_stopped;
 }
 
-static ide_startstop_t cdrom_start_seek_continuation(ide_drive_t *drive)
+static void ide_cd_prepare_seek_request(ide_drive_t *drive, struct request *rq)
 {
-       struct request *rq = HWGROUP(drive)->rq;
        sector_t frame = rq->sector;
 
        sector_div(frame, queue_hardsect_size(drive->queue) >> SECTOR_BITS);
@@ -780,17 +758,13 @@ static ide_startstop_t cdrom_start_seek_continuation(ide_drive_t *drive)
        put_unaligned(cpu_to_be32(frame), (unsigned int *) &rq->cmd[2]);
 
        rq->timeout = ATAPI_WAIT_PC;
-       return cdrom_transfer_packet_command(drive, rq, &cdrom_seek_intr);
 }
 
-static ide_startstop_t cdrom_start_seek(ide_drive_t *drive, unsigned int block)
+static ide_startstop_t cdrom_start_seek_continuation(ide_drive_t *drive)
 {
-       struct cdrom_info *info = drive->driver_data;
+       struct request *rq = drive->hwif->hwgroup->rq;
 
-       info->dma = 0;
-       info->start_seek = jiffies;
-       return cdrom_start_packet_command(drive, 0,
-                                         cdrom_start_seek_continuation);
+       return cdrom_transfer_packet_command(drive, rq, &cdrom_seek_intr);
 }
 
 /*
@@ -921,10 +895,11 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
        struct request *rq = HWGROUP(drive)->rq;
        xfer_func_t *xferfunc;
        ide_expiry_t *expiry = NULL;
-       int dma_error = 0, dma, stat, ireason, len, thislen, uptodate = 0;
+       int dma_error = 0, dma, stat, thislen, uptodate = 0;
        int write = (rq_data_dir(rq) == WRITE) ? 1 : 0;
        unsigned int timeout;
-       u8 lowcyl, highcyl;
+       u16 len;
+       u8 ireason;
 
        /* check for errors */
        dma = info->dma;
@@ -952,12 +927,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
                goto end_request;
        }
 
-       /* ok we fall to pio :/ */
-       ireason = hwif->INB(hwif->io_ports.nsect_addr) & 0x3;
-       lowcyl  = hwif->INB(hwif->io_ports.lbam_addr);
-       highcyl = hwif->INB(hwif->io_ports.lbah_addr);
-
-       len = lowcyl + (256 * highcyl);
+       ide_read_bcount_and_ireason(drive, &len, &ireason);
 
        thislen = blk_fs_request(rq) ? len : rq->data_len;
        if (thislen > len)
@@ -1011,7 +981,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
                                           - bio_cur_sectors(rq->bio),
                                           thislen >> 9);
                        if (nskip > 0) {
-                               ide_cd_drain_data(drive, nskip);
+                               ide_pad_transfer(drive, write, nskip << 9);
                                rq->current_nr_sectors -= nskip;
                                thislen -= (nskip << 9);
                        }
@@ -1048,7 +1018,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
                                 * If the buffers are full, pipe the rest into
                                 * oblivion.
                                 */
-                               ide_cd_drain_data(drive, thislen >> 9);
+                               ide_pad_transfer(drive, 0, thislen);
                        else {
                                printk(KERN_ERR "%s: confused, missing data\n",
                                                drive->name);
@@ -1096,7 +1066,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
 
        /* pad, if necessary */
        if (!blk_fs_request(rq) && len > 0)
-               ide_cd_pad_transfer(drive, xferfunc, len);
+               ide_pad_transfer(drive, write, len);
 
        if (blk_pc_request(rq)) {
                timeout = rq->timeout;
@@ -1165,21 +1135,17 @@ static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq)
        if (write)
                cd->devinfo.media_written = 1;
 
-       /* start sending the read/write request to the drive */
-       return cdrom_start_packet_command(drive, 32768, cdrom_start_rw_cont);
+       return ide_started;
 }
 
 static ide_startstop_t cdrom_do_newpc_cont(ide_drive_t *drive)
 {
        struct request *rq = HWGROUP(drive)->rq;
 
-       if (!rq->timeout)
-               rq->timeout = ATAPI_WAIT_PC;
-
        return cdrom_transfer_packet_command(drive, rq, cdrom_newpc_intr);
 }
 
-static ide_startstop_t cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
+static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
 {
        struct cdrom_info *info = drive->driver_data;
 
@@ -1191,10 +1157,16 @@ static ide_startstop_t cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
        info->dma = 0;
 
        /* sg request */
-       if (rq->bio) {
-               int mask = drive->queue->dma_alignment;
-               unsigned long addr =
-                       (unsigned long)page_address(bio_page(rq->bio));
+       if (rq->bio || ((rq->cmd_type == REQ_TYPE_ATA_PC) && rq->data_len)) {
+               struct request_queue *q = drive->queue;
+               unsigned int alignment;
+               unsigned long addr;
+               unsigned long stack_mask = ~(THREAD_SIZE - 1);
+
+               if (rq->bio)
+                       addr = (unsigned long)bio_data(rq->bio);
+               else
+                       addr = (unsigned long)rq->data;
 
                info->dma = drive->using_dma;
 
@@ -1204,28 +1176,31 @@ static ide_startstop_t cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
                 * NOTE! The "len" and "addr" checks should possibly have
                 * separate masks.
                 */
-               if ((rq->data_len & 15) || (addr & mask))
+               alignment = queue_dma_alignment(q) | q->dma_pad_mask;
+               if (addr & alignment || rq->data_len & alignment)
                        info->dma = 0;
-       }
 
-       /* start sending the command to the drive */
-       return cdrom_start_packet_command(drive, rq->data_len,
-                                         cdrom_do_newpc_cont);
+               if (!((addr & stack_mask) ^
+                     ((unsigned long)current->stack & stack_mask)))
+                       info->dma = 0;
+       }
 }
 
 /*
  * cdrom driver request routine.
  */
-static ide_startstop_t ide_do_rw_cdrom(ide_drive_t *drive, struct request *rq,
+static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq,
                                        sector_t block)
 {
-       ide_startstop_t action;
        struct cdrom_info *info = drive->driver_data;
+       ide_handler_t *fn;
+       int xferlen;
 
        if (blk_fs_request(rq)) {
                if (info->cd_flags & IDE_CD_FLAG_SEEKING) {
+                       ide_hwif_t *hwif = drive->hwif;
                        unsigned long elapsed = jiffies - info->start_seek;
-                       int stat = ide_read_status(drive);
+                       int stat = hwif->read_status(hwif);
 
                        if ((stat & SEEK_STAT) != SEEK_STAT) {
                                if (elapsed < IDECD_SEEK_TIMEOUT) {
@@ -1240,29 +1215,48 @@ static ide_startstop_t ide_do_rw_cdrom(ide_drive_t *drive, struct request *rq,
                }
                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
-                       action = cdrom_start_rw(drive, rq);
+                           IDECD_SEEK_THRESHOLD) &&
+                   drive->dsc_overlap) {
+                       xferlen = 0;
+                       fn = cdrom_start_seek_continuation;
+
+                       info->dma = 0;
+                       info->start_seek = jiffies;
+
+                       ide_cd_prepare_seek_request(drive, rq);
+               } else {
+                       xferlen = 32768;
+                       fn = cdrom_start_rw_cont;
+
+                       if (cdrom_start_rw(drive, rq) == ide_stopped)
+                               return ide_stopped;
+
+                       if (ide_cd_prepare_rw_request(drive, rq) == ide_stopped)
+                               return ide_stopped;
+               }
                info->last_block = block;
-               return action;
        } else if (blk_sense_request(rq) || blk_pc_request(rq) ||
                   rq->cmd_type == REQ_TYPE_ATA_PC) {
-               return cdrom_do_block_pc(drive, rq);
+               xferlen = rq->data_len;
+               fn = cdrom_do_newpc_cont;
+
+               if (!rq->timeout)
+                       rq->timeout = ATAPI_WAIT_PC;
+
+               cdrom_do_block_pc(drive, rq);
        } else if (blk_special_request(rq)) {
                /* right now this can only be a reset... */
                cdrom_end_request(drive, 1);
                return ide_stopped;
+       } else {
+               blk_dump_rq_flags(rq, "ide-cd bad flags");
+               cdrom_end_request(drive, 0);
+               return ide_stopped;
        }
 
-       blk_dump_rq_flags(rq, "ide-cd bad flags");
-       cdrom_end_request(drive, 0);
-       return ide_stopped;
+       return cdrom_start_packet_command(drive, xferlen, fn);
 }
 
-
-
 /*
  * Ioctl handling.
  *
@@ -1872,6 +1866,7 @@ static int ide_cdrom_setup(ide_drive_t *drive)
 
        blk_queue_prep_rq(drive->queue, ide_cdrom_prep_fn);
        blk_queue_dma_alignment(drive->queue, 31);
+       blk_queue_update_dma_pad(drive->queue, 15);
        drive->queue->unplug_delay = (1 * HZ) / 1000;
        if (!drive->queue->unplug_delay)
                drive->queue->unplug_delay = 1;
@@ -1954,10 +1949,9 @@ static ide_driver_t ide_cdrom_driver = {
        .version                = IDECD_VERSION,
        .media                  = ide_cdrom,
        .supports_dsc_overlap   = 1,
-       .do_request             = ide_do_rw_cdrom,
+       .do_request             = ide_cd_do_request,
        .end_request            = ide_end_request,
        .error                  = __ide_error,
-       .abort                  = __ide_abort,
 #ifdef CONFIG_IDE_PROC_FS
        .proc                   = idecd_proc,
 #endif