]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/ide/ide-cd.c
delkin_cb: use struct ide_port_info
[linux-2.6-omap-h63xx.git] / drivers / ide / ide-cd.c
index cc9e7f40d2ea3c670339be3b5bb7565a0904b933..68e7f19dc03662b405363ca23bf0081db73baa4a 100644 (file)
@@ -136,14 +136,12 @@ static int cdrom_log_sense(ide_drive_t *drive, struct request *rq,
        return log;
 }
 
-static
-void cdrom_analyze_sense_data(ide_drive_t *drive,
+static void cdrom_analyze_sense_data(ide_drive_t *drive,
                              struct request *failed_command,
                              struct request_sense *sense)
 {
        unsigned long sector;
        unsigned long bio_sectors;
-       unsigned long valid;
        struct cdrom_info *info = drive->driver_data;
 
        if (!cdrom_log_sense(drive, failed_command, sense))
@@ -174,21 +172,16 @@ void cdrom_analyze_sense_data(ide_drive_t *drive,
                                 (sense->information[2] <<  8) |
                                 (sense->information[3]);
 
-                       bio_sectors = bio_sectors(failed_command->bio);
-                       if (bio_sectors < 4)
-                               bio_sectors = 4;
                        if (drive->queue->hardsect_size == 2048)
                                /* device sector size is 2K */
                                sector <<= 2;
+
+                       bio_sectors = max(bio_sectors(failed_command->bio), 4U);
                        sector &= ~(bio_sectors - 1);
-                       valid = (sector - failed_command->sector) << 9;
 
-                       if (valid < 0)
-                               valid = 0;
                        if (sector < get_capacity(info->disk) &&
-                               drive->probed_capacity - sector < 4 * 75) {
+                           drive->probed_capacity - sector < 4 * 75)
                                set_capacity(info->disk, sector);
-                       }
                }
        }
 
@@ -219,7 +212,8 @@ static void cdrom_queue_request_sense(ide_drive_t *drive, void *sense,
 
        rq->data = sense;
        rq->cmd[0] = GPCMD_REQUEST_SENSE;
-       rq->cmd[4] = rq->data_len = 18;
+       rq->cmd[4] = 18;
+       rq->data_len = 18;
 
        rq->cmd_type = REQ_TYPE_SENSE;
 
@@ -279,11 +273,11 @@ static void cdrom_end_request(ide_drive_t *drive, int uptodate)
        ide_end_request(drive, uptodate, nsectors);
 }
 
-static void ide_dump_status_no_sense(ide_drive_t *drive, const char *msg, u8 stat)
+static void ide_dump_status_no_sense(ide_drive_t *drive, const char *msg, u8 st)
 {
-       if (stat & 0x80)
+       if (st & 0x80)
                return;
-       ide_dump_status(drive, msg, stat);
+       ide_dump_status(drive, msg, st);
 }
 
 /*
@@ -310,7 +304,8 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
        sense_key = err >> 4;
 
        if (rq == NULL) {
-               printk("%s: missing rq in cdrom_decode_status\n", drive->name);
+               printk(KERN_ERR "%s: missing rq in %s\n",
+                               drive->name, __func__);
                return 1;
        }
 
@@ -379,7 +374,7 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
                                cdrom_saw_media_change(drive);
 
                                /* fail the request */
-                               printk("%s: tray open\n", drive->name);
+                               printk(KERN_ERR "%s: tray open\n", drive->name);
                                do_end_request = 1;
                        } else {
                                struct cdrom_info *info = drive->driver_data;
@@ -390,7 +385,8 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
                                 * data from cache.
                                 */
                                if (!rq->errors)
-                                       info->write_timeout = jiffies + ATAPI_WAIT_WRITE_BUSY;
+                                       info->write_timeout = jiffies +
+                                                       ATAPI_WAIT_WRITE_BUSY;
                                rq->errors = 1;
                                if (time_after(jiffies, info->write_timeout))
                                        do_end_request = 1;
@@ -403,13 +399,14 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
                                         */
                                        spin_lock_irqsave(&ide_lock, flags);
                                        blk_plug_device(drive->queue);
-                                       spin_unlock_irqrestore(&ide_lock, flags);
+                                       spin_unlock_irqrestore(&ide_lock,
+                                                               flags);
                                        return 1;
                                }
                        }
                } else if (sense_key == UNIT_ATTENTION) {
                        /* media change */
-                       cdrom_saw_media_change (drive);
+                       cdrom_saw_media_change(drive);
 
                        /*
                         * Arrange to retry the request but be sure to give up
@@ -430,11 +427,14 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
                         * No point in re-trying a zillion times on a bad
                         * sector. If we got here the error is not correctable.
                         */
-                       ide_dump_status_no_sense(drive, "media error (bad sector)", stat);
+                       ide_dump_status_no_sense(drive,
+                                                "media error (bad sector)",
+                                                stat);
                        do_end_request = 1;
                } else if (sense_key == BLANK_CHECK) {
                        /* disk appears blank ?? */
-                       ide_dump_status_no_sense(drive, "media error (blank)", stat);
+                       ide_dump_status_no_sense(drive, "media error (blank)",
+                                                stat);
                        do_end_request = 1;
                } else if ((err & ~ABRT_ERR) != 0) {
                        /* go to the default handler for other errors */
@@ -504,7 +504,8 @@ static int cdrom_timer_expiry(ide_drive_t *drive)
                break;
        default:
                if (!(rq->cmd_flags & REQ_QUIET))
-                       printk(KERN_INFO "ide-cd: cmd 0x%x timed out\n", rq->cmd[0]);
+                       printk(KERN_INFO "ide-cd: cmd 0x%x timed out\n",
+                                        rq->cmd[0]);
                wait = 0;
                break;
        }
@@ -533,7 +534,7 @@ static ide_startstop_t cdrom_start_packet_command(ide_drive_t *drive,
 
        /* FIXME: for Virtual DMA we must check harder */
        if (info->dma)
-               info->dma = !hwif->dma_setup(drive);
+               info->dma = !hwif->dma_ops->dma_setup(drive);
 
        /* set up the controller registers */
        ide_pktcmd_tf_load(drive, IDE_TFLAG_OUT_NSECT | IDE_TFLAG_OUT_LBAL |
@@ -545,17 +546,11 @@ static ide_startstop_t cdrom_start_packet_command(ide_drive_t *drive,
                        drive->waiting_for_dma = 0;
 
                /* packet command */
-               ide_execute_command(drive, WIN_PACKETCMD, handler, ATAPI_WAIT_PC, cdrom_timer_expiry);
+               ide_execute_command(drive, WIN_PACKETCMD, handler,
+                                   ATAPI_WAIT_PC, cdrom_timer_expiry);
                return ide_started;
        } else {
-               unsigned long flags;
-
-               /* packet command */
-               spin_lock_irqsave(&ide_lock, flags);
-               hwif->OUTBSYNC(drive, WIN_PACKETCMD,
-                              hwif->io_ports[IDE_COMMAND_OFFSET]);
-               ndelay(400);
-               spin_unlock_irqrestore(&ide_lock, flags);
+               ide_execute_pkt_cmd(drive);
 
                return (*handler) (drive);
        }
@@ -606,11 +601,11 @@ static ide_startstop_t cdrom_transfer_packet_command(ide_drive_t *drive,
                cmd_len = ATAPI_MIN_CDB_BYTES;
 
        /* send the command to the device */
-       HWIF(drive)->atapi_output_bytes(drive, rq->cmd, cmd_len);
+       hwif->output_data(drive, NULL, rq->cmd, cmd_len);
 
        /* start the DMA if need be */
        if (info->dma)
-               hwif->dma_start(drive);
+               hwif->dma_ops->dma_start(drive);
 
        return ide_started;
 }
@@ -622,7 +617,7 @@ static void ide_cd_pad_transfer(ide_drive_t *drive, xfer_func_t *xf, int len)
 {
        while (len > 0) {
                int dum = 0;
-               xf(drive, &dum, sizeof(dum));
+               xf(drive, NULL, &dum, sizeof(dum));
                len -= sizeof(dum);
        }
 }
@@ -632,7 +627,7 @@ static void ide_cd_drain_data(ide_drive_t *drive, int nsects)
        while (nsects > 0) {
                static char dum[SECTOR_SIZE];
 
-               drive->hwif->atapi_input_bytes(drive, dum, sizeof(dum));
+               drive->hwif->input_data(drive, NULL, dum, sizeof(dum));
                nsects--;
        }
 }
@@ -659,7 +654,7 @@ static int ide_cd_check_ireason(ide_drive_t *drive, struct request *rq,
                printk(KERN_ERR "%s: %s: wrong transfer direction!\n",
                                drive->name, __func__);
 
-               xf = rw ? hwif->atapi_output_bytes : hwif->atapi_input_bytes;
+               xf = rw ? hwif->output_data : hwif->input_data;
                ide_cd_pad_transfer(drive, xf, len);
        } else  if (rw == 0 && ireason == 1) {
                /*
@@ -787,7 +782,7 @@ static ide_startstop_t cdrom_start_seek_continuation(ide_drive_t *drive)
 
        sector_div(frame, queue_hardsect_size(drive->queue) >> SECTOR_BITS);
 
-       memset(rq->cmd, 0, sizeof(rq->cmd));
+       memset(rq->cmd, 0, BLK_MAX_CDB);
        rq->cmd[0] = GPCMD_SEEK;
        put_unaligned(cpu_to_be32(frame), (unsigned int *) &rq->cmd[2]);
 
@@ -801,7 +796,8 @@ static ide_startstop_t cdrom_start_seek(ide_drive_t *drive, unsigned int block)
 
        info->dma = 0;
        info->start_seek = jiffies;
-       return cdrom_start_packet_command(drive, 0, cdrom_start_seek_continuation);
+       return cdrom_start_packet_command(drive, 0,
+                                         cdrom_start_seek_continuation);
 }
 
 /*
@@ -811,13 +807,15 @@ static ide_startstop_t cdrom_start_seek(ide_drive_t *drive, unsigned int block)
 static void restore_request(struct request *rq)
 {
        if (rq->buffer != bio_data(rq->bio)) {
-               sector_t n = (rq->buffer - (char *) bio_data(rq->bio)) / SECTOR_SIZE;
+               sector_t n =
+                       (rq->buffer - (char *)bio_data(rq->bio)) / SECTOR_SIZE;
 
                rq->buffer = bio_data(rq->bio);
                rq->nr_sectors += n;
                rq->sector -= n;
        }
-       rq->hard_cur_sectors = rq->current_nr_sectors = bio_cur_sectors(rq->bio);
+       rq->current_nr_sectors = bio_cur_sectors(rq->bio);
+       rq->hard_cur_sectors = rq->current_nr_sectors;
        rq->hard_nr_sectors = rq->nr_sectors;
        rq->hard_sector = rq->sector;
        rq->q->prep_rq_fn(rq->q, rq);
@@ -919,7 +917,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
        dma = info->dma;
        if (dma) {
                info->dma = 0;
-               dma_error = HWIF(drive)->ide_dma_end(drive);
+               dma_error = hwif->dma_ops->dma_end(drive);
                if (dma_error) {
                        printk(KERN_ERR "%s: DMA %s error\n", drive->name,
                                        write ? "write" : "read");
@@ -942,9 +940,9 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
        }
 
        /* ok we fall to pio :/ */
-       ireason = hwif->INB(hwif->io_ports[IDE_IREASON_OFFSET]) & 0x3;
-       lowcyl  = hwif->INB(hwif->io_ports[IDE_BCOUNTL_OFFSET]);
-       highcyl = hwif->INB(hwif->io_ports[IDE_BCOUNTH_OFFSET]);
+       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);
 
@@ -1009,10 +1007,10 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
 
        if (ireason == 0) {
                write = 1;
-               xferfunc = HWIF(drive)->atapi_output_bytes;
+               xferfunc = hwif->output_data;
        } else {
                write = 0;
-               xferfunc = HWIF(drive)->atapi_input_bytes;
+               xferfunc = hwif->input_data;
        }
 
        /* transfer data */
@@ -1051,7 +1049,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
                if (blen > thislen)
                        blen = thislen;
 
-               xferfunc(drive, ptr, blen);
+               xferfunc(drive, NULL, ptr, blen);
 
                thislen -= blen;
                len -= blen;
@@ -1182,7 +1180,8 @@ static ide_startstop_t cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
        /* sg request */
        if (rq->bio) {
                int mask = drive->queue->dma_alignment;
-               unsigned long addr = (unsigned long) page_address(bio_page(rq->bio));
+               unsigned long addr =
+                       (unsigned long)page_address(bio_page(rq->bio));
 
                info->dma = drive->using_dma;
 
@@ -1197,14 +1196,15 @@ static ide_startstop_t cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
        }
 
        /* start sending the command to the drive */
-       return cdrom_start_packet_command(drive, rq->data_len, cdrom_do_newpc_cont);
+       return cdrom_start_packet_command(drive, rq->data_len,
+                                         cdrom_do_newpc_cont);
 }
 
 /*
  * cdrom driver request routine.
  */
-static ide_startstop_t
-ide_do_rw_cdrom(ide_drive_t *drive, struct request *rq, sector_t block)
+static ide_startstop_t ide_do_rw_cdrom(ide_drive_t *drive, struct request *rq,
+                                       sector_t block)
 {
        ide_startstop_t action;
        struct cdrom_info *info = drive->driver_data;
@@ -1216,14 +1216,19 @@ ide_do_rw_cdrom(ide_drive_t *drive, struct request *rq, sector_t block)
 
                        if ((stat & SEEK_STAT) != SEEK_STAT) {
                                if (elapsed < IDECD_SEEK_TIMEOUT) {
-                                       ide_stall_queue(drive, IDECD_SEEK_TIMER);
+                                       ide_stall_queue(drive,
+                                                       IDECD_SEEK_TIMER);
                                        return ide_stopped;
                                }
-                               printk(KERN_ERR "%s: DSC timeout\n", drive->name);
+                               printk(KERN_ERR "%s: DSC timeout\n",
+                                               drive->name);
                        }
                        info->cd_flags &= ~IDE_CD_FLAG_SEEKING;
                }
-               if ((rq_data_dir(rq) == READ) && IDE_LARGE_SEEK(info->last_block, block, IDECD_SEEK_THRESHOLD) && drive->dsc_overlap)
+               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);
@@ -1254,8 +1259,7 @@ ide_do_rw_cdrom(ide_drive_t *drive, struct request *rq, sector_t block)
  * subsequent request sense command. The pointer can also be NULL, in which case
  * no sense information is returned.
  */
-static
-void msf_from_bcd(struct atapi_msf *msf)
+static void msf_from_bcd(struct atapi_msf *msf)
 {
        msf->minute = BCD2BIN(msf->minute);
        msf->second = BCD2BIN(msf->second);
@@ -1355,7 +1359,8 @@ int ide_cd_read_toc(ide_drive_t *drive, struct request_sense *sense)
                /* try to allocate space */
                toc = kmalloc(sizeof(struct atapi_toc), GFP_KERNEL);
                if (toc == NULL) {
-                       printk(KERN_ERR "%s: No cdrom TOC buffer!\n", drive->name);
+                       printk(KERN_ERR "%s: No cdrom TOC buffer!\n",
+                                       drive->name);
                        return -ENOMEM;
                }
                info->toc = toc;
@@ -1469,7 +1474,8 @@ int ide_cd_read_toc(ide_drive_t *drive, struct request_sense *sense)
 
                toc->last_session_lba = be32_to_cpu(ms_tmp.ent.addr.lba);
        } else {
-               ms_tmp.hdr.first_track = ms_tmp.hdr.last_track = CDROM_LEADOUT;
+               ms_tmp.hdr.last_track = CDROM_LEADOUT;
+               ms_tmp.hdr.first_track = ms_tmp.hdr.last_track;
                toc->last_session_lba = msf_to_lba(0, 2, 0); /* 0m 2s 0f */
        }
 
@@ -1583,8 +1589,7 @@ static int ide_cdrom_register(ide_drive_t *drive, int nslots)
        return register_cdrom(devinfo);
 }
 
-static
-int ide_cdrom_probe_capabilities(ide_drive_t *drive)
+static int ide_cdrom_probe_capabilities(ide_drive_t *drive)
 {
        struct cdrom_info *cd = drive->driver_data;
        struct cdrom_device_info *cdi = &cd->devinfo;
@@ -1598,7 +1603,8 @@ int ide_cdrom_probe_capabilities(ide_drive_t *drive)
 
        if (drive->media == ide_optical) {
                cdi->mask &= ~(CDC_MO_DRIVE | CDC_RAM);
-               printk(KERN_ERR "%s: ATAPI magneto-optical drive\n", drive->name);
+               printk(KERN_ERR "%s: ATAPI magneto-optical drive\n",
+                               drive->name);
                return nslots;
        }
 
@@ -1688,7 +1694,7 @@ static int ide_cdrom_prep_fs(struct request_queue *q, struct request *rq)
        long block = (long)rq->hard_sector / (hard_sect >> 9);
        unsigned long blocks = rq->hard_nr_sectors / (hard_sect >> 9);
 
-       memset(rq->cmd, 0, sizeof(rq->cmd));
+       memset(rq->cmd, 0, BLK_MAX_CDB);
 
        if (rq_data_dir(rq) == READ)
                rq->cmd[0] = GPCMD_READ_10;
@@ -1773,8 +1779,8 @@ static sector_t ide_cdrom_capacity(ide_drive_t *drive)
        return capacity * sectors_per_frame;
 }
 
-static int proc_idecd_read_capacity
-       (char *page, char **start, off_t off, int count, int *eof, void *data)
+static int proc_idecd_read_capacity(char *page, char **start, off_t off,
+                                       int count, int *eof, void *data)
 {
        ide_drive_t *drive = data;
        int len;
@@ -1854,8 +1860,7 @@ static unsigned int ide_cd_flags(struct hd_driveid *id)
        return 0;
 }
 
-static
-int ide_cdrom_setup(ide_drive_t *drive)
+static int ide_cdrom_setup(ide_drive_t *drive)
 {
        struct cdrom_info *cd = drive->driver_data;
        struct cdrom_device_info *cdi = &cd->devinfo;
@@ -1892,12 +1897,11 @@ int ide_cdrom_setup(ide_drive_t *drive)
        /* set correct block size */
        blk_queue_hardsect_size(drive->queue, CD_FRAMESIZE);
 
-       if (drive->autotune == IDE_TUNE_DEFAULT ||
-           drive->autotune == IDE_TUNE_AUTO)
-               drive->dsc_overlap = (drive->next != drive);
+       drive->dsc_overlap = (drive->next != drive);
 
        if (ide_cdrom_register(drive, nslots)) {
-               printk(KERN_ERR "%s: ide_cdrom_setup failed to register device with the cdrom driver.\n", drive->name);
+               printk(KERN_ERR "%s: %s failed to register device with the"
+                               " cdrom driver.\n", drive->name, __func__);
                cd->devinfo.handle = NULL;
                return 1;
        }
@@ -2094,17 +2098,20 @@ static int ide_cd_probe(ide_drive_t *drive)
        /* skip drives that we were told to ignore */
        if (ignore != NULL) {
                if (strstr(ignore, drive->name)) {
-                       printk(KERN_INFO "ide-cd: ignoring drive %s\n", drive->name);
+                       printk(KERN_INFO "ide-cd: ignoring drive %s\n",
+                                        drive->name);
                        goto failed;
                }
        }
        if (drive->scsi) {
-               printk(KERN_INFO "ide-cd: passing drive %s to ide-scsi emulation.\n", drive->name);
+               printk(KERN_INFO "ide-cd: passing drive %s to ide-scsi "
+                                "emulation.\n", drive->name);
                goto failed;
        }
        info = kzalloc(sizeof(struct cdrom_info), GFP_KERNEL);
        if (info == NULL) {
-               printk(KERN_ERR "%s: Can't allocate a cdrom structure\n", drive->name);
+               printk(KERN_ERR "%s: Can't allocate a cdrom structure\n",
+                               drive->name);
                goto failed;
        }