^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * ATAPI support.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/cdrom.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/ide.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/scatterlist.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/gfp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <scsi/scsi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define DRV_NAME "ide-atapi"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define PFX DRV_NAME ": "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define debug_log(fmt, args...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) printk(KERN_INFO "ide: " fmt, ## args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define debug_log(fmt, args...) do {} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define ATAPI_MIN_CDB_BYTES 12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) static inline int dev_is_idecd(ide_drive_t *drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) return drive->media == ide_cdrom || drive->media == ide_optical;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * Check whether we can support a device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * based on the ATAPI IDENTIFY command results.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) int ide_check_atapi_device(ide_drive_t *drive, const char *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) u16 *id = drive->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) u8 gcw[2], protocol, device_type, removable, drq_type, packet_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) *((u16 *)&gcw) = id[ATA_ID_CONFIG];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) protocol = (gcw[1] & 0xC0) >> 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) device_type = gcw[1] & 0x1F;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) removable = (gcw[0] & 0x80) >> 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) drq_type = (gcw[0] & 0x60) >> 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) packet_size = gcw[0] & 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #ifdef CONFIG_PPC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) /* kludge for Apple PowerBook internal zip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) if (drive->media == ide_floppy && device_type == 5 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) !strstr((char *)&id[ATA_ID_PROD], "CD-ROM") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) strstr((char *)&id[ATA_ID_PROD], "ZIP"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) device_type = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) if (protocol != 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) printk(KERN_ERR "%s: %s: protocol (0x%02x) is not ATAPI\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) s, drive->name, protocol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) else if ((drive->media == ide_floppy && device_type != 0) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) (drive->media == ide_tape && device_type != 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) printk(KERN_ERR "%s: %s: invalid device type (0x%02x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) s, drive->name, device_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) else if (removable == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) printk(KERN_ERR "%s: %s: the removable flag is not set\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) s, drive->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) else if (drive->media == ide_floppy && drq_type == 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) printk(KERN_ERR "%s: %s: sorry, DRQ type (0x%02x) not "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) "supported\n", s, drive->name, drq_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) else if (packet_size != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) printk(KERN_ERR "%s: %s: packet size (0x%02x) is not 12 "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) "bytes\n", s, drive->name, packet_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) EXPORT_SYMBOL_GPL(ide_check_atapi_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) void ide_init_pc(struct ide_atapi_pc *pc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) memset(pc, 0, sizeof(*pc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) EXPORT_SYMBOL_GPL(ide_init_pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * Add a special packet command request to the tail of the request queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * and wait for it to be serviced.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) int ide_queue_pc_tail(ide_drive_t *drive, struct gendisk *disk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) struct ide_atapi_pc *pc, void *buf, unsigned int bufflen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) struct request *rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) rq = blk_get_request(drive->queue, REQ_OP_DRV_IN, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) ide_req(rq)->type = ATA_PRIV_MISC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) ide_req(rq)->special = pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) if (buf && bufflen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) error = blk_rq_map_kern(drive->queue, rq, buf, bufflen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) GFP_NOIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) goto put_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) memcpy(scsi_req(rq)->cmd, pc->c, 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) if (drive->media == ide_tape)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) scsi_req(rq)->cmd[13] = REQ_IDETAPE_PC1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) blk_execute_rq(drive->queue, disk, rq, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) error = scsi_req(rq)->result ? -EIO : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) put_req:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) blk_put_request(rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) EXPORT_SYMBOL_GPL(ide_queue_pc_tail);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) int ide_do_test_unit_ready(ide_drive_t *drive, struct gendisk *disk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) struct ide_atapi_pc pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) ide_init_pc(&pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) pc.c[0] = TEST_UNIT_READY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) return ide_queue_pc_tail(drive, disk, &pc, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) EXPORT_SYMBOL_GPL(ide_do_test_unit_ready);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) int ide_do_start_stop(ide_drive_t *drive, struct gendisk *disk, int start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) struct ide_atapi_pc pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) ide_init_pc(&pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) pc.c[0] = START_STOP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) pc.c[4] = start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) if (drive->media == ide_tape)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) pc.flags |= PC_FLAG_WAIT_FOR_DSC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) return ide_queue_pc_tail(drive, disk, &pc, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) EXPORT_SYMBOL_GPL(ide_do_start_stop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) int ide_set_media_lock(ide_drive_t *drive, struct gendisk *disk, int on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) struct ide_atapi_pc pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) if ((drive->dev_flags & IDE_DFLAG_DOORLOCKING) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) ide_init_pc(&pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) pc.c[0] = ALLOW_MEDIUM_REMOVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) pc.c[4] = on;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) return ide_queue_pc_tail(drive, disk, &pc, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) EXPORT_SYMBOL_GPL(ide_set_media_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) void ide_create_request_sense_cmd(ide_drive_t *drive, struct ide_atapi_pc *pc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) ide_init_pc(pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) pc->c[0] = REQUEST_SENSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) if (drive->media == ide_floppy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) pc->c[4] = 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) pc->req_xfer = 18;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) pc->c[4] = 20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) pc->req_xfer = 20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) EXPORT_SYMBOL_GPL(ide_create_request_sense_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) void ide_prep_sense(ide_drive_t *drive, struct request *rq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) struct request_sense *sense = &drive->sense_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) struct request *sense_rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) struct scsi_request *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) unsigned int cmd_len, sense_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) switch (drive->media) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) case ide_floppy:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) cmd_len = 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) sense_len = 18;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) case ide_tape:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) cmd_len = 20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) sense_len = 20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) cmd_len = 18;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) sense_len = 18;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) BUG_ON(sense_len > sizeof(*sense));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) if (ata_sense_request(rq) || drive->sense_rq_armed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) sense_rq = drive->sense_rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) if (!sense_rq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) sense_rq = blk_mq_alloc_request(drive->queue, REQ_OP_DRV_IN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) BLK_MQ_REQ_RESERVED | BLK_MQ_REQ_NOWAIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) drive->sense_rq = sense_rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) req = scsi_req(sense_rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) memset(sense, 0, sizeof(*sense));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) scsi_req_init(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) err = blk_rq_map_kern(drive->queue, sense_rq, sense, sense_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) GFP_NOIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) if (unlikely(err)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) if (printk_ratelimit())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) printk(KERN_WARNING PFX "%s: failed to map sense "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) "buffer\n", drive->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) blk_mq_free_request(sense_rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) drive->sense_rq = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) sense_rq->rq_disk = rq->rq_disk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) sense_rq->cmd_flags = REQ_OP_DRV_IN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) ide_req(sense_rq)->type = ATA_PRIV_SENSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) req->cmd[0] = GPCMD_REQUEST_SENSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) req->cmd[4] = cmd_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) if (drive->media == ide_tape)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) req->cmd[13] = REQ_IDETAPE_PC1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) drive->sense_rq_armed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) EXPORT_SYMBOL_GPL(ide_prep_sense);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) int ide_queue_sense_rq(ide_drive_t *drive, void *special)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) ide_hwif_t *hwif = drive->hwif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) struct request *sense_rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) spin_lock_irqsave(&hwif->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) /* deferred failure from ide_prep_sense() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) if (!drive->sense_rq_armed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) printk(KERN_WARNING PFX "%s: error queuing a sense request\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) drive->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) spin_unlock_irqrestore(&hwif->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) sense_rq = drive->sense_rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) ide_req(sense_rq)->special = special;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) drive->sense_rq_armed = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) drive->hwif->rq = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) ide_insert_request_head(drive, sense_rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) spin_unlock_irqrestore(&hwif->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) EXPORT_SYMBOL_GPL(ide_queue_sense_rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) * Called when an error was detected during the last packet command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) * We queue a request sense packet command at the head of the request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) * queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) void ide_retry_pc(ide_drive_t *drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) struct request *failed_rq = drive->hwif->rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) struct request *sense_rq = drive->sense_rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) struct ide_atapi_pc *pc = &drive->request_sense_pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) (void)ide_read_error(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) /* init pc from sense_rq */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) ide_init_pc(pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) memcpy(pc->c, scsi_req(sense_rq)->cmd, 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) if (drive->media == ide_tape)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) drive->atapi_flags |= IDE_AFLAG_IGNORE_DSC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) * Push back the failed request and put request sense on top
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) * of it. The failed command will be retried after sense data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) * is acquired.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) drive->hwif->rq = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) ide_requeue_and_plug(drive, failed_rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) if (ide_queue_sense_rq(drive, pc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) ide_complete_rq(drive, BLK_STS_IOERR, blk_rq_bytes(failed_rq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) EXPORT_SYMBOL_GPL(ide_retry_pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) int ide_cd_expiry(ide_drive_t *drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) struct request *rq = drive->hwif->rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) unsigned long wait = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) debug_log("%s: scsi_req(rq)->cmd[0]: 0x%x\n", __func__, scsi_req(rq)->cmd[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) * Some commands are *slow* and normally take a long time to complete.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) * Usually we can use the ATAPI "disconnect" to bypass this, but not all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) * commands/drives support that. Let ide_timer_expiry keep polling us
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) * for these.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) switch (scsi_req(rq)->cmd[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) case GPCMD_BLANK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) case GPCMD_FORMAT_UNIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) case GPCMD_RESERVE_RZONE_TRACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) case GPCMD_CLOSE_TRACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) case GPCMD_FLUSH_CACHE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) wait = ATAPI_WAIT_PC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) if (!(rq->rq_flags & RQF_QUIET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) printk(KERN_INFO PFX "cmd 0x%x timed out\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) scsi_req(rq)->cmd[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) wait = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) return wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) EXPORT_SYMBOL_GPL(ide_cd_expiry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) int ide_cd_get_xferlen(struct request *rq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) switch (req_op(rq)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) return 32768;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) case REQ_OP_SCSI_IN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) case REQ_OP_SCSI_OUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) return blk_rq_bytes(rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) case REQ_OP_DRV_IN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) case REQ_OP_DRV_OUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) switch (ide_req(rq)->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) case ATA_PRIV_PC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) case ATA_PRIV_SENSE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) return blk_rq_bytes(rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) EXPORT_SYMBOL_GPL(ide_cd_get_xferlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) void ide_read_bcount_and_ireason(ide_drive_t *drive, u16 *bcount, u8 *ireason)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) struct ide_taskfile tf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) drive->hwif->tp_ops->tf_read(drive, &tf, IDE_VALID_NSECT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) IDE_VALID_LBAM | IDE_VALID_LBAH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) *bcount = (tf.lbah << 8) | tf.lbam;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) *ireason = tf.nsect & 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) EXPORT_SYMBOL_GPL(ide_read_bcount_and_ireason);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) * Check the contents of the interrupt reason register and attempt to recover if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) * there are problems.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) * - 0 if everything's ok
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) * - 1 if the request has to be terminated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) int ide_check_ireason(ide_drive_t *drive, struct request *rq, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) int ireason, int rw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) ide_hwif_t *hwif = drive->hwif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) debug_log("ireason: 0x%x, rw: 0x%x\n", ireason, rw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) if (ireason == (!rw << 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) else if (ireason == (rw << 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) printk(KERN_ERR PFX "%s: %s: wrong transfer direction!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) drive->name, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) if (dev_is_idecd(drive))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) ide_pad_transfer(drive, rw, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) } else if (!rw && ireason == ATAPI_COD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) if (dev_is_idecd(drive)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) * Some drives (ASUS) seem to tell us that status info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) * is available. Just get it and ignore.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) (void)hwif->tp_ops->read_status(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) if (ireason & ATAPI_COD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) printk(KERN_ERR PFX "%s: CoD != 0 in %s\n", drive->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) /* drive wants a command packet, or invalid ireason... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) printk(KERN_ERR PFX "%s: %s: bad interrupt reason 0x%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) drive->name, __func__, ireason);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) if (dev_is_idecd(drive) && ata_pc_request(rq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) rq->rq_flags |= RQF_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) EXPORT_SYMBOL_GPL(ide_check_ireason);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) * This is the usual interrupt handler which will be called during a packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) * command. We will transfer some of the data (as requested by the drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) * and will re-point interrupt handler to us.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) struct ide_atapi_pc *pc = drive->pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) ide_hwif_t *hwif = drive->hwif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) struct ide_cmd *cmd = &hwif->cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) struct request *rq = hwif->rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) const struct ide_tp_ops *tp_ops = hwif->tp_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) unsigned int timeout, done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) u16 bcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) u8 stat, ireason, dsc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) u8 write = !!(pc->flags & PC_FLAG_WRITING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) debug_log("Enter %s - interrupt handler\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) timeout = (drive->media == ide_floppy) ? WAIT_FLOPPY_CMD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) : WAIT_TAPE_CMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) /* Clear the interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) stat = tp_ops->read_status(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) if (pc->flags & PC_FLAG_DMA_IN_PROGRESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) drive->waiting_for_dma = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) rc = hwif->dma_ops->dma_end(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) ide_dma_unmap_sg(drive, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) if (rc || (drive->media == ide_tape && (stat & ATA_ERR))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) if (drive->media == ide_floppy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) printk(KERN_ERR PFX "%s: DMA %s error\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) drive->name, rq_data_dir(pc->rq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) ? "write" : "read");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) pc->flags |= PC_FLAG_DMA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) scsi_req(rq)->resid_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) debug_log("%s: DMA finished\n", drive->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) /* No more interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) if ((stat & ATA_DRQ) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) int uptodate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) blk_status_t error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) debug_log("Packet command completed, %d bytes transferred\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) blk_rq_bytes(rq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) pc->flags &= ~PC_FLAG_DMA_IN_PROGRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) local_irq_enable_in_hardirq();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) if (drive->media == ide_tape &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) (stat & ATA_ERR) && scsi_req(rq)->cmd[0] == REQUEST_SENSE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) stat &= ~ATA_ERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) if ((stat & ATA_ERR) || (pc->flags & PC_FLAG_DMA_ERROR)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) /* Error detected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) debug_log("%s: I/O error\n", drive->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) if (drive->media != ide_tape)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) scsi_req(pc->rq)->result++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) if (scsi_req(rq)->cmd[0] == REQUEST_SENSE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) printk(KERN_ERR PFX "%s: I/O error in request "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) "sense command\n", drive->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) return ide_do_reset(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) debug_log("[cmd %x]: check condition\n", scsi_req(rq)->cmd[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) /* Retry operation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) ide_retry_pc(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) /* queued, but not started */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) return ide_stopped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) pc->error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) if ((pc->flags & PC_FLAG_WAIT_FOR_DSC) && (stat & ATA_DSC) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) dsc = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) * ->pc_callback() might change rq->data_len for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) * residual count, cache total length.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) done = blk_rq_bytes(rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) /* Command finished - Call the callback function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) uptodate = drive->pc_callback(drive, dsc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) if (uptodate == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) drive->failed_pc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) if (ata_misc_request(rq)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) scsi_req(rq)->result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) error = BLK_STS_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) if (blk_rq_is_passthrough(rq) && uptodate <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) if (scsi_req(rq)->result == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) scsi_req(rq)->result = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) error = uptodate ? BLK_STS_OK : BLK_STS_IOERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) ide_complete_rq(drive, error, blk_rq_bytes(rq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) return ide_stopped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) if (pc->flags & PC_FLAG_DMA_IN_PROGRESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) pc->flags &= ~PC_FLAG_DMA_IN_PROGRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) printk(KERN_ERR PFX "%s: The device wants to issue more "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) "interrupts in DMA mode\n", drive->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) ide_dma_off(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) return ide_do_reset(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) /* Get the number of bytes to transfer on this interrupt. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) ide_read_bcount_and_ireason(drive, &bcount, &ireason);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) if (ide_check_ireason(drive, rq, bcount, ireason, write))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) return ide_do_reset(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) done = min_t(unsigned int, bcount, cmd->nleft);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) ide_pio_bytes(drive, cmd, write, done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) /* Update transferred byte count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) scsi_req(rq)->resid_len -= done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) bcount -= done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) if (bcount)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) ide_pad_transfer(drive, write, bcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) debug_log("[cmd %x] transferred %d bytes, padded %d bytes, resid: %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) scsi_req(rq)->cmd[0], done, bcount, scsi_req(rq)->resid_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) /* And set the interrupt handler again */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) ide_set_handler(drive, ide_pc_intr, timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) return ide_started;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) static void ide_init_packet_cmd(struct ide_cmd *cmd, u8 valid_tf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) u16 bcount, u8 dma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) cmd->protocol = dma ? ATAPI_PROT_DMA : ATAPI_PROT_PIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) cmd->valid.out.tf = IDE_VALID_LBAH | IDE_VALID_LBAM |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) IDE_VALID_FEATURE | valid_tf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) cmd->tf.command = ATA_CMD_PACKET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) cmd->tf.feature = dma; /* Use PIO/DMA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) cmd->tf.lbam = bcount & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) cmd->tf.lbah = (bcount >> 8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) static u8 ide_read_ireason(ide_drive_t *drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) struct ide_taskfile tf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) drive->hwif->tp_ops->tf_read(drive, &tf, IDE_VALID_NSECT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) return tf.nsect & 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) static u8 ide_wait_ireason(ide_drive_t *drive, u8 ireason)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) int retries = 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) while (retries-- && ((ireason & ATAPI_COD) == 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) (ireason & ATAPI_IO))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) printk(KERN_ERR PFX "%s: (IO,CoD != (0,1) while issuing "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) "a packet command, retrying\n", drive->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) udelay(100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) ireason = ide_read_ireason(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) if (retries == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) printk(KERN_ERR PFX "%s: (IO,CoD != (0,1) while issuing"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) " a packet command, ignoring\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) drive->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) ireason |= ATAPI_COD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) ireason &= ~ATAPI_IO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) return ireason;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) static int ide_delayed_transfer_pc(ide_drive_t *drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) /* Send the actual packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) drive->hwif->tp_ops->output_data(drive, NULL, drive->pc->c, 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) /* Timeout for the packet command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) return WAIT_FLOPPY_CMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) static ide_startstop_t ide_transfer_pc(ide_drive_t *drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) struct ide_atapi_pc *pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) ide_hwif_t *hwif = drive->hwif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) struct request *rq = hwif->rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) ide_expiry_t *expiry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) unsigned int timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) int cmd_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) ide_startstop_t startstop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) u8 ireason;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) if (ide_wait_stat(&startstop, drive, ATA_DRQ, ATA_BUSY, WAIT_READY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) printk(KERN_ERR PFX "%s: Strange, packet command initiated yet "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) "DRQ isn't asserted\n", drive->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) return startstop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) if (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) if (drive->dma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) drive->waiting_for_dma = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) if (dev_is_idecd(drive)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) /* ATAPI commands get padded out to 12 bytes minimum */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) cmd_len = COMMAND_SIZE(scsi_req(rq)->cmd[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) if (cmd_len < ATAPI_MIN_CDB_BYTES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) cmd_len = ATAPI_MIN_CDB_BYTES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) timeout = rq->timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) expiry = ide_cd_expiry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) pc = drive->pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) cmd_len = ATAPI_MIN_CDB_BYTES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) * If necessary schedule the packet transfer to occur 'timeout'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) * milliseconds later in ide_delayed_transfer_pc() after the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) * device says it's ready for a packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) if (drive->atapi_flags & IDE_AFLAG_ZIP_DRIVE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) timeout = drive->pc_delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) expiry = &ide_delayed_transfer_pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) timeout = (drive->media == ide_floppy) ? WAIT_FLOPPY_CMD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) : WAIT_TAPE_CMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) expiry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) ireason = ide_read_ireason(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) if (drive->media == ide_tape)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) ireason = ide_wait_ireason(drive, ireason);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) if ((ireason & ATAPI_COD) == 0 || (ireason & ATAPI_IO)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) printk(KERN_ERR PFX "%s: (IO,CoD) != (0,1) while "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) "issuing a packet command\n", drive->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) return ide_do_reset(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) hwif->expiry = expiry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) /* Set the interrupt routine */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) ide_set_handler(drive,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) (dev_is_idecd(drive) ? drive->irq_handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) : ide_pc_intr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) /* Send the actual packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) if ((drive->atapi_flags & IDE_AFLAG_ZIP_DRIVE) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) hwif->tp_ops->output_data(drive, NULL, scsi_req(rq)->cmd, cmd_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) /* Begin DMA, if necessary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) if (dev_is_idecd(drive)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) if (drive->dma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) hwif->dma_ops->dma_start(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) if (pc->flags & PC_FLAG_DMA_OK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) pc->flags |= PC_FLAG_DMA_IN_PROGRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) hwif->dma_ops->dma_start(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) return ide_started;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) ide_startstop_t ide_issue_pc(ide_drive_t *drive, struct ide_cmd *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) struct ide_atapi_pc *pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) ide_hwif_t *hwif = drive->hwif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) ide_expiry_t *expiry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) struct request *rq = hwif->rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) unsigned int timeout, bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) u16 bcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) u8 valid_tf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) u8 drq_int = !!(drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) if (dev_is_idecd(drive)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) valid_tf = IDE_VALID_NSECT | IDE_VALID_LBAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) bcount = ide_cd_get_xferlen(rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) expiry = ide_cd_expiry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) timeout = ATAPI_WAIT_PC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) if (drive->dma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) drive->dma = !ide_dma_prepare(drive, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) pc = drive->pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) valid_tf = IDE_VALID_DEVICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) bytes = blk_rq_bytes(rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) bcount = ((drive->media == ide_tape) ? bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) : min_t(unsigned int,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) bytes, 63 * 1024));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) /* We haven't transferred any data yet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) scsi_req(rq)->resid_len = bcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) if (pc->flags & PC_FLAG_DMA_ERROR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) pc->flags &= ~PC_FLAG_DMA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) ide_dma_off(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) if (pc->flags & PC_FLAG_DMA_OK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) drive->dma = !ide_dma_prepare(drive, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) if (!drive->dma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) pc->flags &= ~PC_FLAG_DMA_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) timeout = (drive->media == ide_floppy) ? WAIT_FLOPPY_CMD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) : WAIT_TAPE_CMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) ide_init_packet_cmd(cmd, valid_tf, bcount, drive->dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) (void)do_rw_taskfile(drive, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) if (drq_int) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) if (drive->dma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) drive->waiting_for_dma = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) hwif->expiry = expiry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) ide_execute_command(drive, cmd, ide_transfer_pc, timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) return drq_int ? ide_started : ide_transfer_pc(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) EXPORT_SYMBOL_GPL(ide_issue_pc);