^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * IDE ATAPI floppy driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 1996-1999 Gadi Oxman <gadio@netvision.net.il>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2000-2002 Paul Bristow <paul@paulbristow.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) 2005 Bartlomiej Zolnierkiewicz
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * This driver supports the following IDE floppy drives:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * LS-120/240 SuperDisk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Iomega Zip 100/250
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * Iomega PC Card Clik!/PocketZip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * For a historical changelog see
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * Documentation/ide/ChangeLog.ide-floppy.1996-2002
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/compat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/major.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/genhd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/cdrom.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/ide.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/hdreg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/bitops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/scatterlist.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <scsi/scsi_ioctl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <asm/byteorder.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include <asm/unaligned.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #include "ide-floppy.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * After each failed packet command we issue a request sense command and retry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * the packet command IDEFLOPPY_MAX_PC_RETRIES times.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define IDEFLOPPY_MAX_PC_RETRIES 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) /* format capacities descriptor codes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define CAPACITY_INVALID 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define CAPACITY_UNFORMATTED 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #define CAPACITY_CURRENT 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define CAPACITY_NO_CARTRIDGE 0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * The following delay solves a problem with ATAPI Zip 100 drive where BSY bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * was apparently being deasserted before the unit was ready to receive data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #define IDEFLOPPY_PC_DELAY (HZ/20) /* default delay for ZIP 100 (50ms) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) static int ide_floppy_callback(ide_drive_t *drive, int dsc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct ide_disk_obj *floppy = drive->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) struct ide_atapi_pc *pc = drive->pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct request *rq = pc->rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) int uptodate = pc->error ? 0 : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) ide_debug_log(IDE_DBG_FUNC, "enter");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) if (drive->failed_pc == pc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) drive->failed_pc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) if (pc->c[0] == GPCMD_READ_10 || pc->c[0] == GPCMD_WRITE_10 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) blk_rq_is_scsi(rq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) uptodate = 1; /* FIXME */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) else if (pc->c[0] == GPCMD_REQUEST_SENSE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) u8 *buf = bio_data(rq->bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) if (!pc->error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) floppy->sense_key = buf[2] & 0x0F;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) floppy->asc = buf[12];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) floppy->ascq = buf[13];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) floppy->progress_indication = buf[15] & 0x80 ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) (u16)get_unaligned((u16 *)&buf[16]) : 0x10000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if (drive->failed_pc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) ide_debug_log(IDE_DBG_PC, "pc = %x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) drive->failed_pc->c[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) ide_debug_log(IDE_DBG_SENSE, "sense key = %x, asc = %x,"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) "ascq = %x", floppy->sense_key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) floppy->asc, floppy->ascq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) printk(KERN_ERR PFX "Error in REQUEST SENSE itself - "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) "Aborting request!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) if (ata_misc_request(rq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) scsi_req(rq)->result = uptodate ? 0 : IDE_DRV_ERROR_GENERAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) return uptodate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static void ide_floppy_report_error(struct ide_disk_obj *floppy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) struct ide_atapi_pc *pc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) /* suppress error messages resulting from Medium not present */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (floppy->sense_key == 0x02 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) floppy->asc == 0x3a &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) floppy->ascq == 0x00)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) printk(KERN_ERR PFX "%s: I/O error, pc = %2x, key = %2x, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) "asc = %2x, ascq = %2x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) floppy->drive->name, pc->c[0], floppy->sense_key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) floppy->asc, floppy->ascq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) static ide_startstop_t ide_floppy_issue_pc(ide_drive_t *drive,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct ide_cmd *cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) struct ide_atapi_pc *pc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) struct ide_disk_obj *floppy = drive->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) if (drive->failed_pc == NULL &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) pc->c[0] != GPCMD_REQUEST_SENSE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) drive->failed_pc = pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) /* Set the current packet command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) drive->pc = pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) if (pc->retries > IDEFLOPPY_MAX_PC_RETRIES) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) unsigned int done = blk_rq_bytes(drive->hwif->rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) if (!(pc->flags & PC_FLAG_SUPPRESS_ERROR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) ide_floppy_report_error(floppy, pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) /* Giving up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) pc->error = IDE_DRV_ERROR_GENERAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) drive->failed_pc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) drive->pc_callback(drive, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) ide_complete_rq(drive, BLK_STS_IOERR, done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) return ide_stopped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) ide_debug_log(IDE_DBG_FUNC, "retry #%d", pc->retries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) pc->retries++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) return ide_issue_pc(drive, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) void ide_floppy_create_read_capacity_cmd(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] = GPCMD_READ_FORMAT_CAPACITIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) pc->c[7] = 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) pc->c[8] = 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) pc->req_xfer = 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) /* A mode sense command is used to "sense" floppy parameters. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) void ide_floppy_create_mode_sense_cmd(struct ide_atapi_pc *pc, u8 page_code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) u16 length = 8; /* sizeof(Mode Parameter Header) = 8 Bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) ide_init_pc(pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) pc->c[0] = GPCMD_MODE_SENSE_10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) pc->c[1] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) pc->c[2] = page_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) switch (page_code) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) case IDEFLOPPY_CAPABILITIES_PAGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) length += 12;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) case IDEFLOPPY_FLEXIBLE_DISK_PAGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) length += 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) printk(KERN_ERR PFX "unsupported page code in %s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) put_unaligned(cpu_to_be16(length), (u16 *) &pc->c[7]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) pc->req_xfer = length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) static void idefloppy_create_rw_cmd(ide_drive_t *drive,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) struct ide_atapi_pc *pc, struct request *rq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) unsigned long sector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) struct ide_disk_obj *floppy = drive->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) int block = sector / floppy->bs_factor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) int blocks = blk_rq_sectors(rq) / floppy->bs_factor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) int cmd = rq_data_dir(rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) ide_debug_log(IDE_DBG_FUNC, "block: %d, blocks: %d", block, blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) ide_init_pc(pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) pc->c[0] = cmd == READ ? GPCMD_READ_10 : GPCMD_WRITE_10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) put_unaligned(cpu_to_be16(blocks), (unsigned short *)&pc->c[7]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) memcpy(scsi_req(rq)->cmd, pc->c, 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) pc->rq = rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) if (cmd == WRITE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) pc->flags |= PC_FLAG_WRITING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) pc->flags |= PC_FLAG_DMA_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) static void idefloppy_blockpc_cmd(struct ide_disk_obj *floppy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) struct ide_atapi_pc *pc, struct request *rq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) ide_init_pc(pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) memcpy(pc->c, scsi_req(rq)->cmd, sizeof(pc->c));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) pc->rq = rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) if (blk_rq_bytes(rq)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) pc->flags |= PC_FLAG_DMA_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) if (rq_data_dir(rq) == WRITE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) pc->flags |= PC_FLAG_WRITING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) static ide_startstop_t ide_floppy_do_request(ide_drive_t *drive,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) struct request *rq, sector_t block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) struct ide_disk_obj *floppy = drive->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) struct ide_cmd cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) struct ide_atapi_pc *pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) ide_debug_log(IDE_DBG_FUNC, "enter, cmd: 0x%x\n", rq->cmd[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) if (drive->debug_mask & IDE_DBG_RQ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) blk_dump_rq_flags(rq, (rq->rq_disk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) ? rq->rq_disk->disk_name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) : "dev?"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) if (scsi_req(rq)->result >= ERROR_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) if (drive->failed_pc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) ide_floppy_report_error(floppy, drive->failed_pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) drive->failed_pc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) printk(KERN_ERR PFX "%s: I/O error\n", drive->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) if (ata_misc_request(rq)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) scsi_req(rq)->result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) ide_complete_rq(drive, BLK_STS_OK, blk_rq_bytes(rq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) return ide_stopped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) goto out_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) switch (req_op(rq)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) if (((long)blk_rq_pos(rq) % floppy->bs_factor) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) (blk_rq_sectors(rq) % floppy->bs_factor)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) printk(KERN_ERR PFX "%s: unsupported r/w rq size\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) drive->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) goto out_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) pc = &floppy->queued_pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) idefloppy_create_rw_cmd(drive, pc, rq, (unsigned long)block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) case REQ_OP_SCSI_IN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) case REQ_OP_SCSI_OUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) pc = &floppy->queued_pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) idefloppy_blockpc_cmd(floppy, pc, rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) case REQ_OP_DRV_IN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) case REQ_OP_DRV_OUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) switch (ide_req(rq)->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) case ATA_PRIV_MISC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) case ATA_PRIV_SENSE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) pc = (struct ide_atapi_pc *)ide_req(rq)->special;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) ide_prep_sense(drive, rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) memset(&cmd, 0, sizeof(cmd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) if (rq_data_dir(rq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) cmd.tf_flags |= IDE_TFLAG_WRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) cmd.rq = rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) if (!blk_rq_is_passthrough(rq) || blk_rq_bytes(rq)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) ide_init_sg_cmd(&cmd, blk_rq_bytes(rq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) ide_map_sg(drive, &cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) pc->rq = rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) return ide_floppy_issue_pc(drive, &cmd, pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) out_end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) drive->failed_pc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) if (blk_rq_is_passthrough(rq) && scsi_req(rq)->result == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) scsi_req(rq)->result = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) ide_complete_rq(drive, BLK_STS_IOERR, blk_rq_bytes(rq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) return ide_stopped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) * Look at the flexible disk page parameters. We ignore the CHS capacity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) * parameters and use the LBA parameters instead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) static int ide_floppy_get_flexible_disk_page(ide_drive_t *drive,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) struct ide_atapi_pc *pc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) struct ide_disk_obj *floppy = drive->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) struct gendisk *disk = floppy->disk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) u8 *page, buf[40];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) int capacity, lba_capacity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) u16 transfer_rate, sector_size, cyls, rpm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) u8 heads, sectors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) ide_floppy_create_mode_sense_cmd(pc, IDEFLOPPY_FLEXIBLE_DISK_PAGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) if (ide_queue_pc_tail(drive, disk, pc, buf, pc->req_xfer)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) printk(KERN_ERR PFX "Can't get flexible disk page params\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) if (buf[3] & 0x80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) drive->dev_flags |= IDE_DFLAG_WP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) drive->dev_flags &= ~IDE_DFLAG_WP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) set_disk_ro(disk, !!(drive->dev_flags & IDE_DFLAG_WP));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) page = &buf[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) transfer_rate = be16_to_cpup((__be16 *)&buf[8 + 2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) sector_size = be16_to_cpup((__be16 *)&buf[8 + 6]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) cyls = be16_to_cpup((__be16 *)&buf[8 + 8]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) rpm = be16_to_cpup((__be16 *)&buf[8 + 28]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) heads = buf[8 + 4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) sectors = buf[8 + 5];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) capacity = cyls * heads * sectors * sector_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) if (memcmp(page, &floppy->flexible_disk_page, 32))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) printk(KERN_INFO PFX "%s: %dkB, %d/%d/%d CHS, %d kBps, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) "%d sector size, %d rpm\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) drive->name, capacity / 1024, cyls, heads,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) sectors, transfer_rate / 8, sector_size, rpm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) memcpy(&floppy->flexible_disk_page, page, 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) drive->bios_cyl = cyls;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) drive->bios_head = heads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) drive->bios_sect = sectors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) lba_capacity = floppy->blocks * floppy->block_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) if (capacity < lba_capacity) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) printk(KERN_NOTICE PFX "%s: The disk reports a capacity of %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) "bytes, but the drive only handles %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) drive->name, lba_capacity, capacity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) floppy->blocks = floppy->block_size ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) capacity / floppy->block_size : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) drive->capacity64 = floppy->blocks * floppy->bs_factor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) * Determine if a media is present in the floppy drive, and if so, its LBA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) * capacity.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) static int ide_floppy_get_capacity(ide_drive_t *drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) struct ide_disk_obj *floppy = drive->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) struct gendisk *disk = floppy->disk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) struct ide_atapi_pc pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) u8 *cap_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) u8 pc_buf[256], header_len, desc_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) int i, rc = 1, blocks, length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) ide_debug_log(IDE_DBG_FUNC, "enter");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) drive->bios_cyl = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) drive->bios_head = drive->bios_sect = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) floppy->blocks = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) floppy->bs_factor = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) drive->capacity64 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) ide_floppy_create_read_capacity_cmd(&pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) if (ide_queue_pc_tail(drive, disk, &pc, pc_buf, pc.req_xfer)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) printk(KERN_ERR PFX "Can't get floppy parameters\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) header_len = pc_buf[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) cap_desc = &pc_buf[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) desc_cnt = header_len / 8; /* capacity descriptor of 8 bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) for (i = 0; i < desc_cnt; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) unsigned int desc_start = 4 + i*8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) blocks = be32_to_cpup((__be32 *)&pc_buf[desc_start]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) length = be16_to_cpup((__be16 *)&pc_buf[desc_start + 6]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) ide_debug_log(IDE_DBG_PROBE, "Descriptor %d: %dkB, %d blocks, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) "%d sector size",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) i, blocks * length / 1024,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) blocks, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) if (i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) * the code below is valid only for the 1st descriptor, ie i=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) switch (pc_buf[desc_start + 4] & 0x03) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) /* Clik! drive returns this instead of CAPACITY_CURRENT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) case CAPACITY_UNFORMATTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) * If it is not a clik drive, break out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) * (maintains previous driver behaviour)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) case CAPACITY_CURRENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) /* Normal Zip/LS-120 disks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) if (memcmp(cap_desc, &floppy->cap_desc, 8))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) printk(KERN_INFO PFX "%s: %dkB, %d blocks, %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) "sector size\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) drive->name, blocks * length / 1024,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) blocks, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) memcpy(&floppy->cap_desc, cap_desc, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) if (!length || length % 512) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) printk(KERN_NOTICE PFX "%s: %d bytes block size"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) " not supported\n", drive->name, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) floppy->blocks = blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) floppy->block_size = length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) floppy->bs_factor = length / 512;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) if (floppy->bs_factor != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) printk(KERN_NOTICE PFX "%s: Warning: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) "non 512 bytes block size not "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) "fully supported\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) drive->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) drive->capacity64 =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) floppy->blocks * floppy->bs_factor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) case CAPACITY_NO_CARTRIDGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) * This is a KERN_ERR so it appears on screen
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) * for the user to see
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) printk(KERN_ERR PFX "%s: No disk in drive\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) drive->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) case CAPACITY_INVALID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) printk(KERN_ERR PFX "%s: Invalid capacity for disk "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) "in drive\n", drive->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) ide_debug_log(IDE_DBG_PROBE, "Descriptor 0 Code: %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) pc_buf[desc_start + 4] & 0x03);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) /* Clik! disk does not support get_flexible_disk_page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) (void) ide_floppy_get_flexible_disk_page(drive, &pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) return rc;
^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) static void ide_floppy_setup(ide_drive_t *drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) struct ide_disk_obj *floppy = drive->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) u16 *id = drive->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) drive->pc_callback = ide_floppy_callback;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) * We used to check revisions here. At this point however I'm giving up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) * Just assume they are all broken, its easier.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) * The actual reason for the workarounds was likely a driver bug after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) * all rather than a firmware bug, and the workaround below used to hide
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) * it. It should be fixed as of version 1.9, but to be on the safe side
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) * we'll leave the limitation below for the 2.2.x tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) if (strstarts((char *)&id[ATA_ID_PROD], "IOMEGA ZIP 100 ATAPI")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) drive->atapi_flags |= IDE_AFLAG_ZIP_DRIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) /* This value will be visible in the /proc/ide/hdx/settings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) drive->pc_delay = IDEFLOPPY_PC_DELAY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) blk_queue_max_hw_sectors(drive->queue, 64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) * Guess what? The IOMEGA Clik! drive also needs the above fix. It makes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) * nasty clicking noises without it, so please don't remove this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) if (strstarts((char *)&id[ATA_ID_PROD], "IOMEGA Clik!")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) blk_queue_max_hw_sectors(drive->queue, 64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) drive->atapi_flags |= IDE_AFLAG_CLIK_DRIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) /* IOMEGA Clik! drives do not support lock/unlock commands */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) (void) ide_floppy_get_capacity(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) ide_proc_register_driver(drive, floppy->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) static void ide_floppy_flush(ide_drive_t *drive)
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) static int ide_floppy_init_media(ide_drive_t *drive, struct gendisk *disk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) if (ide_do_test_unit_ready(drive, disk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) ide_do_start_stop(drive, disk, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) ret = ide_floppy_get_capacity(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) set_capacity(disk, ide_gd_capacity(drive));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) const struct ide_disk_ops ide_atapi_disk_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) .check = ide_check_atapi_device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) .get_capacity = ide_floppy_get_capacity,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) .setup = ide_floppy_setup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) .flush = ide_floppy_flush,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) .init_media = ide_floppy_init_media,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) .set_doorlock = ide_set_media_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) .do_request = ide_floppy_do_request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) .ioctl = ide_floppy_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) .compat_ioctl = ide_floppy_compat_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) };