^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) * Copyright (C) 1994-1998 Linus Torvalds & authors (see below)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 1998-2002 Linux ATA Development
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Andre Hedrick <andre@linux-ide.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2003 Red Hat
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) 2003-2005, 2007 Bartlomiej Zolnierkiewicz
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Mostly written by Mark Lord <mlord@pobox.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * and Gadi Oxman <gadio@netvision.net.il>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * and Andre Hedrick <andre@linux-ide.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * This is the IDE/ATA disk driver, as evolved from hd.c and ide.c.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/major.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/genhd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/leds.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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <asm/byteorder.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <asm/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <asm/div64.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include "ide-disk.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) static const u8 ide_rw_cmds[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) ATA_CMD_READ_MULTI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) ATA_CMD_WRITE_MULTI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) ATA_CMD_READ_MULTI_EXT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) ATA_CMD_WRITE_MULTI_EXT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) ATA_CMD_PIO_READ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) ATA_CMD_PIO_WRITE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) ATA_CMD_PIO_READ_EXT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) ATA_CMD_PIO_WRITE_EXT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) ATA_CMD_READ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) ATA_CMD_WRITE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) ATA_CMD_READ_EXT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) ATA_CMD_WRITE_EXT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static void ide_tf_set_cmd(ide_drive_t *drive, struct ide_cmd *cmd, u8 dma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) u8 index, lba48, write;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) lba48 = (cmd->tf_flags & IDE_TFLAG_LBA48) ? 2 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) write = (cmd->tf_flags & IDE_TFLAG_WRITE) ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) if (dma) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) cmd->protocol = ATA_PROT_DMA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) index = 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) cmd->protocol = ATA_PROT_PIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) if (drive->mult_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) cmd->tf_flags |= IDE_TFLAG_MULTI_PIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) index = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) cmd->tf.command = ide_rw_cmds[index + lba48 + write];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * __ide_do_rw_disk() issues READ and WRITE commands to a disk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * using LBA if supported, or CHS otherwise, to address sectors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) sector_t block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) ide_hwif_t *hwif = drive->hwif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) u16 nsectors = (u16)blk_rq_sectors(rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) u8 dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) struct ide_cmd cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) struct ide_taskfile *tf = &cmd.tf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) ide_startstop_t rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) if ((hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA) && lba48 && dma) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) if (block + blk_rq_sectors(rq) > 1ULL << 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) dma = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) lba48 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) memset(&cmd, 0, sizeof(cmd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) cmd.valid.out.tf = IDE_VALID_OUT_TF | IDE_VALID_DEVICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) cmd.valid.in.tf = IDE_VALID_IN_TF | IDE_VALID_DEVICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) if (drive->dev_flags & IDE_DFLAG_LBA) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if (lba48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) pr_debug("%s: LBA=0x%012llx\n", drive->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) (unsigned long long)block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) tf->nsect = nsectors & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) tf->lbal = (u8) block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) tf->lbam = (u8)(block >> 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) tf->lbah = (u8)(block >> 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) tf->device = ATA_LBA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) tf = &cmd.hob;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) tf->nsect = (nsectors >> 8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) tf->lbal = (u8)(block >> 24);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) if (sizeof(block) != 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) tf->lbam = (u8)((u64)block >> 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) tf->lbah = (u8)((u64)block >> 40);
^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) cmd.valid.out.hob = IDE_VALID_OUT_HOB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) cmd.valid.in.hob = IDE_VALID_IN_HOB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) cmd.tf_flags |= IDE_TFLAG_LBA48;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) tf->nsect = nsectors & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) tf->lbal = block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) tf->lbam = block >>= 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) tf->lbah = block >>= 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) tf->device = ((block >> 8) & 0xf) | ATA_LBA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) unsigned int sect, head, cyl, track;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) track = (int)block / drive->sect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) sect = (int)block % drive->sect + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) head = track % drive->head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) cyl = track / drive->head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) pr_debug("%s: CHS=%u/%u/%u\n", drive->name, cyl, head, sect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) tf->nsect = nsectors & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) tf->lbal = sect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) tf->lbam = cyl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) tf->lbah = cyl >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) tf->device = head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) cmd.tf_flags |= IDE_TFLAG_FS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) if (rq_data_dir(rq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) cmd.tf_flags |= IDE_TFLAG_WRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) ide_tf_set_cmd(drive, &cmd, dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) cmd.rq = rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) if (dma == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) ide_init_sg_cmd(&cmd, nsectors << 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) ide_map_sg(drive, &cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) rc = do_rw_taskfile(drive, &cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) if (rc == ide_stopped && dma) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) /* fallback to PIO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) cmd.tf_flags |= IDE_TFLAG_DMA_PIO_FALLBACK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) ide_tf_set_cmd(drive, &cmd, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) ide_init_sg_cmd(&cmd, nsectors << 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) rc = do_rw_taskfile(drive, &cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * 268435455 == 137439 MB or 28bit limit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) * 320173056 == 163929 MB or 48bit addressing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) * 1073741822 == 549756 MB or 48bit addressing fake drive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) static ide_startstop_t ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) sector_t block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) ide_hwif_t *hwif = drive->hwif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) BUG_ON(drive->dev_flags & IDE_DFLAG_BLOCKED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) BUG_ON(blk_rq_is_passthrough(rq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) ledtrig_disk_activity(rq_data_dir(rq) == WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) pr_debug("%s: %sing: block=%llu, sectors=%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) drive->name, rq_data_dir(rq) == READ ? "read" : "writ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) (unsigned long long)block, blk_rq_sectors(rq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) if (hwif->rw_disk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) hwif->rw_disk(drive, rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) return __ide_do_rw_disk(drive, rq, block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) * Queries for true maximum capacity of the drive.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) * Returns maximum LBA address (> 0) of the drive, 0 if failed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) static u64 idedisk_read_native_max_address(ide_drive_t *drive, int lba48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) struct ide_cmd cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) struct ide_taskfile *tf = &cmd.tf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) u64 addr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) memset(&cmd, 0, sizeof(cmd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) if (lba48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) tf->command = ATA_CMD_READ_NATIVE_MAX_EXT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) tf->command = ATA_CMD_READ_NATIVE_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) tf->device = ATA_LBA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) cmd.valid.out.tf = IDE_VALID_OUT_TF | IDE_VALID_DEVICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) cmd.valid.in.tf = IDE_VALID_IN_TF | IDE_VALID_DEVICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) if (lba48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) cmd.valid.out.hob = IDE_VALID_OUT_HOB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) cmd.valid.in.hob = IDE_VALID_IN_HOB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) cmd.tf_flags = IDE_TFLAG_LBA48;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) ide_no_data_taskfile(drive, &cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) /* if OK, compute maximum address value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) if (!(tf->status & ATA_ERR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) addr = ide_get_lba_addr(&cmd, lba48) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) return addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) * Sets maximum virtual LBA address of the drive.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) * Returns new maximum virtual LBA address (> 0) or 0 on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) static u64 idedisk_set_max_address(ide_drive_t *drive, u64 addr_req, int lba48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) struct ide_cmd cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) struct ide_taskfile *tf = &cmd.tf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) u64 addr_set = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) addr_req--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) memset(&cmd, 0, sizeof(cmd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) tf->lbal = (addr_req >> 0) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) tf->lbam = (addr_req >>= 8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) tf->lbah = (addr_req >>= 8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) if (lba48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) cmd.hob.lbal = (addr_req >>= 8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) cmd.hob.lbam = (addr_req >>= 8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) cmd.hob.lbah = (addr_req >>= 8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) tf->command = ATA_CMD_SET_MAX_EXT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) tf->device = (addr_req >>= 8) & 0x0f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) tf->command = ATA_CMD_SET_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) tf->device |= ATA_LBA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) cmd.valid.out.tf = IDE_VALID_OUT_TF | IDE_VALID_DEVICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) cmd.valid.in.tf = IDE_VALID_IN_TF | IDE_VALID_DEVICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) if (lba48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) cmd.valid.out.hob = IDE_VALID_OUT_HOB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) cmd.valid.in.hob = IDE_VALID_IN_HOB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) cmd.tf_flags = IDE_TFLAG_LBA48;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) ide_no_data_taskfile(drive, &cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) /* if OK, compute maximum address value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) if (!(tf->status & ATA_ERR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) addr_set = ide_get_lba_addr(&cmd, lba48) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) return addr_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) static unsigned long long sectors_to_MB(unsigned long long n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) n <<= 9; /* make it bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) do_div(n, 1000000); /* make it MB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) return n;
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) * Some disks report total number of sectors instead of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) * maximum sector address. We list them here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) static const struct drive_list_entry hpa_list[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) { "ST340823A", NULL },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) { "ST320413A", NULL },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) { "ST310211A", NULL },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) { NULL, NULL }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) static u64 ide_disk_hpa_get_native_capacity(ide_drive_t *drive, int lba48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) u64 capacity, set_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) capacity = drive->capacity64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) set_max = idedisk_read_native_max_address(drive, lba48);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) if (ide_in_drive_list(drive->id, hpa_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) * Since we are inclusive wrt to firmware revisions do this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) * extra check and apply the workaround only when needed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) if (set_max == capacity + 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) set_max--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) return set_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) static u64 ide_disk_hpa_set_capacity(ide_drive_t *drive, u64 set_max, int lba48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) set_max = idedisk_set_max_address(drive, set_max, lba48);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) if (set_max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) drive->capacity64 = set_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) return set_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) static void idedisk_check_hpa(ide_drive_t *drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) u64 capacity, set_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) int lba48 = ata_id_lba48_enabled(drive->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) capacity = drive->capacity64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) set_max = ide_disk_hpa_get_native_capacity(drive, lba48);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) if (set_max <= capacity)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) drive->probed_capacity = set_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) printk(KERN_INFO "%s: Host Protected Area detected.\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) "\tcurrent capacity is %llu sectors (%llu MB)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) "\tnative capacity is %llu sectors (%llu MB)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) drive->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) capacity, sectors_to_MB(capacity),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) set_max, sectors_to_MB(set_max));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) if ((drive->dev_flags & IDE_DFLAG_NOHPA) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) set_max = ide_disk_hpa_set_capacity(drive, set_max, lba48);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) if (set_max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) printk(KERN_INFO "%s: Host Protected Area disabled.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) drive->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) static int ide_disk_get_capacity(ide_drive_t *drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) u16 *id = drive->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) int lba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) if (ata_id_lba48_enabled(id)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) /* drive speaks 48-bit LBA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) lba = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) drive->capacity64 = ata_id_u64(id, ATA_ID_LBA_CAPACITY_2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) } else if (ata_id_has_lba(id) && ata_id_is_lba_capacity_ok(id)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) /* drive speaks 28-bit LBA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) lba = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) drive->capacity64 = ata_id_u32(id, ATA_ID_LBA_CAPACITY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) /* drive speaks boring old 28-bit CHS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) lba = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) drive->capacity64 = drive->cyl * drive->head * drive->sect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) drive->probed_capacity = drive->capacity64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) if (lba) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) drive->dev_flags |= IDE_DFLAG_LBA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) * If this device supports the Host Protected Area feature set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) * then we may need to change our opinion about its capacity.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) if (ata_id_hpa_enabled(id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) idedisk_check_hpa(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) /* limit drive capacity to 137GB if LBA48 cannot be used */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) if ((drive->dev_flags & IDE_DFLAG_LBA48) == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) drive->capacity64 > 1ULL << 28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) printk(KERN_WARNING "%s: cannot use LBA48 - full capacity "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) "%llu sectors (%llu MB)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) drive->name, (unsigned long long)drive->capacity64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) sectors_to_MB(drive->capacity64));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) drive->probed_capacity = drive->capacity64 = 1ULL << 28;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) if ((drive->hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) (drive->dev_flags & IDE_DFLAG_LBA48)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) if (drive->capacity64 > 1ULL << 28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) printk(KERN_INFO "%s: cannot use LBA48 DMA - PIO mode"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) " will be used for accessing sectors "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) "> %u\n", drive->name, 1 << 28);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) drive->dev_flags &= ~IDE_DFLAG_LBA48;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) static void ide_disk_unlock_native_capacity(ide_drive_t *drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) u16 *id = drive->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) int lba48 = ata_id_lba48_enabled(id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) if ((drive->dev_flags & IDE_DFLAG_LBA) == 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) ata_id_hpa_enabled(id) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) * according to the spec the SET MAX ADDRESS command shall be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) * immediately preceded by a READ NATIVE MAX ADDRESS command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) if (!ide_disk_hpa_get_native_capacity(drive, lba48))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) if (ide_disk_hpa_set_capacity(drive, drive->probed_capacity, lba48))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) drive->dev_flags |= IDE_DFLAG_NOHPA; /* disable HPA on resume */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) static bool idedisk_prep_rq(ide_drive_t *drive, struct request *rq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) struct ide_cmd *cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) if (req_op(rq) != REQ_OP_FLUSH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) if (ide_req(rq)->special) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) cmd = ide_req(rq)->special;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) memset(cmd, 0, sizeof(*cmd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) cmd = kzalloc(sizeof(*cmd), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) /* FIXME: map struct ide_taskfile on rq->cmd[] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) BUG_ON(cmd == NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) if (ata_id_flush_ext_enabled(drive->id) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) (drive->capacity64 >= (1UL << 28)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) cmd->tf.command = ATA_CMD_FLUSH_EXT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) cmd->tf.command = ATA_CMD_FLUSH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) cmd->valid.out.tf = IDE_VALID_OUT_TF | IDE_VALID_DEVICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) cmd->tf_flags = IDE_TFLAG_DYN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) cmd->protocol = ATA_PROT_NODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) rq->cmd_flags &= ~REQ_OP_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) rq->cmd_flags |= REQ_OP_DRV_OUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) ide_req(rq)->type = ATA_PRIV_TASKFILE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) ide_req(rq)->special = cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) cmd->rq = rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) ide_devset_get(multcount, mult_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) * This is tightly woven into the driver->do_special can not touch.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) * DON'T do it again until a total personality rewrite is committed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) static int set_multcount(ide_drive_t *drive, int arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) struct request *rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) if (arg < 0 || arg > (drive->id[ATA_ID_MAX_MULTSECT] & 0xff))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) if (drive->special_flags & IDE_SFLAG_SET_MULTMODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) rq = blk_get_request(drive->queue, REQ_OP_DRV_IN, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) ide_req(rq)->type = ATA_PRIV_TASKFILE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) drive->mult_req = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) drive->special_flags |= IDE_SFLAG_SET_MULTMODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) blk_execute_rq(drive->queue, NULL, rq, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) blk_put_request(rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) return (drive->mult_count == arg) ? 0 : -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) ide_devset_get_flag(nowerr, IDE_DFLAG_NOWERR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) static int set_nowerr(ide_drive_t *drive, int arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) if (arg < 0 || arg > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) if (arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) drive->dev_flags |= IDE_DFLAG_NOWERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) drive->dev_flags &= ~IDE_DFLAG_NOWERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) drive->bad_wstat = arg ? BAD_R_STAT : BAD_W_STAT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) static int ide_do_setfeature(ide_drive_t *drive, u8 feature, u8 nsect)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) struct ide_cmd cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) memset(&cmd, 0, sizeof(cmd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) cmd.tf.feature = feature;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) cmd.tf.nsect = nsect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) cmd.tf.command = ATA_CMD_SET_FEATURES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) cmd.valid.out.tf = IDE_VALID_OUT_TF | IDE_VALID_DEVICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) cmd.valid.in.tf = IDE_VALID_IN_TF | IDE_VALID_DEVICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) return ide_no_data_taskfile(drive, &cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) static void update_flush(ide_drive_t *drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) u16 *id = drive->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) bool wc = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) if (drive->dev_flags & IDE_DFLAG_WCACHE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) unsigned long long capacity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) int barrier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) * We must avoid issuing commands a drive does not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) * understand or we may crash it. We check flush cache
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) * is supported. We also check we have the LBA48 flush
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) * cache if the drive capacity is too large. By this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) * time we have trimmed the drive capacity if LBA48 is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) * not available so we don't need to recheck that.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) capacity = ide_gd_capacity(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) barrier = ata_id_flush_enabled(id) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) (drive->dev_flags & IDE_DFLAG_NOFLUSH) == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) ((drive->dev_flags & IDE_DFLAG_LBA48) == 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) capacity <= (1ULL << 28) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) ata_id_flush_ext_enabled(id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) printk(KERN_INFO "%s: cache flushes %ssupported\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) drive->name, barrier ? "" : "not ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) if (barrier) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) wc = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) drive->prep_rq = idedisk_prep_rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) blk_queue_write_cache(drive->queue, wc, false);
^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) ide_devset_get_flag(wcache, IDE_DFLAG_WCACHE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) static int set_wcache(ide_drive_t *drive, int arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) int err = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) if (arg < 0 || arg > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) if (ata_id_flush_enabled(drive->id)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) err = ide_do_setfeature(drive,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) arg ? SETFEATURES_WC_ON : SETFEATURES_WC_OFF, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) if (err == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) if (arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) drive->dev_flags |= IDE_DFLAG_WCACHE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) drive->dev_flags &= ~IDE_DFLAG_WCACHE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) update_flush(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) static int do_idedisk_flushcache(ide_drive_t *drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) struct ide_cmd cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) memset(&cmd, 0, sizeof(cmd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) if (ata_id_flush_ext_enabled(drive->id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) cmd.tf.command = ATA_CMD_FLUSH_EXT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) cmd.tf.command = ATA_CMD_FLUSH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) cmd.valid.out.tf = IDE_VALID_OUT_TF | IDE_VALID_DEVICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) cmd.valid.in.tf = IDE_VALID_IN_TF | IDE_VALID_DEVICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) return ide_no_data_taskfile(drive, &cmd);
^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) ide_devset_get(acoustic, acoustic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) static int set_acoustic(ide_drive_t *drive, int arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) if (arg < 0 || arg > 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) ide_do_setfeature(drive,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) arg ? SETFEATURES_AAM_ON : SETFEATURES_AAM_OFF, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) drive->acoustic = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) ide_devset_get_flag(addressing, IDE_DFLAG_LBA48);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) * drive->addressing:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) * 0: 28-bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) * 1: 48-bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) * 2: 48-bit capable doing 28-bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) static int set_addressing(ide_drive_t *drive, int arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) if (arg < 0 || arg > 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) if (arg && ((drive->hwif->host_flags & IDE_HFLAG_NO_LBA48) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) ata_id_lba48_enabled(drive->id) == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) if (arg == 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) arg = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) if (arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) drive->dev_flags |= IDE_DFLAG_LBA48;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) drive->dev_flags &= ~IDE_DFLAG_LBA48;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) ide_ext_devset_rw(acoustic, acoustic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) ide_ext_devset_rw(address, addressing);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) ide_ext_devset_rw(multcount, multcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) ide_ext_devset_rw(wcache, wcache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) ide_ext_devset_rw_sync(nowerr, nowerr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) static int ide_disk_check(ide_drive_t *drive, const char *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) static void ide_disk_setup(ide_drive_t *drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) struct ide_disk_obj *idkp = drive->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) struct request_queue *q = drive->queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) ide_hwif_t *hwif = drive->hwif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) u16 *id = drive->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) char *m = (char *)&id[ATA_ID_PROD];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) unsigned long long capacity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) ide_proc_register_driver(drive, idkp->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) if ((drive->dev_flags & IDE_DFLAG_ID_READ) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) if (drive->dev_flags & IDE_DFLAG_REMOVABLE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) * Removable disks (eg. SYQUEST); ignore 'WD' drives
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) if (m[0] != 'W' || m[1] != 'D')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) drive->dev_flags |= IDE_DFLAG_DOORLOCKING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) (void)set_addressing(drive, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) if (drive->dev_flags & IDE_DFLAG_LBA48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) int max_s = 2048;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) if (max_s > hwif->rqsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) max_s = hwif->rqsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) blk_queue_max_hw_sectors(q, max_s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) printk(KERN_INFO "%s: max request size: %dKiB\n", drive->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) queue_max_sectors(q) / 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) if (ata_id_is_ssd(id)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) blk_queue_flag_set(QUEUE_FLAG_NONROT, q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, q);
^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) /* calculate drive capacity, and select LBA if possible */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) ide_disk_get_capacity(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) * if possible, give fdisk access to more of the drive,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) * by correcting bios_cyls:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) capacity = ide_gd_capacity(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) if ((drive->dev_flags & IDE_DFLAG_FORCED_GEOM) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) if (ata_id_lba48_enabled(drive->id)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) /* compatibility */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) drive->bios_sect = 63;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) drive->bios_head = 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) if (drive->bios_sect && drive->bios_head) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) unsigned int cap0 = capacity; /* truncate to 32 bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) unsigned int cylsz, cyl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) if (cap0 != capacity)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) drive->bios_cyl = 65535;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) cylsz = drive->bios_sect * drive->bios_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) cyl = cap0 / cylsz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) if (cyl > 65535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) cyl = 65535;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) if (cyl > drive->bios_cyl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) drive->bios_cyl = cyl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) printk(KERN_INFO "%s: %llu sectors (%llu MB)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) drive->name, capacity, sectors_to_MB(capacity));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) /* Only print cache size when it was specified */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) if (id[ATA_ID_BUF_SIZE])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) printk(KERN_CONT " w/%dKiB Cache", id[ATA_ID_BUF_SIZE] / 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) printk(KERN_CONT ", CHS=%d/%d/%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) drive->bios_cyl, drive->bios_head, drive->bios_sect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) /* write cache enabled? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) if ((id[ATA_ID_CSFO] & 1) || ata_id_wcache_enabled(id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) drive->dev_flags |= IDE_DFLAG_WCACHE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) set_wcache(drive, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) if ((drive->dev_flags & IDE_DFLAG_LBA) == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) (drive->head == 0 || drive->head > 16))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) printk(KERN_ERR "%s: invalid geometry: %d physical heads?\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) drive->name, drive->head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) static void ide_disk_flush(ide_drive_t *drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) if (ata_id_flush_enabled(drive->id) == 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) (drive->dev_flags & IDE_DFLAG_WCACHE) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) if (do_idedisk_flushcache(drive))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) printk(KERN_INFO "%s: wcache flush failed!\n", drive->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) static int ide_disk_init_media(ide_drive_t *drive, struct gendisk *disk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) static int ide_disk_set_doorlock(ide_drive_t *drive, struct gendisk *disk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) int on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) struct ide_cmd cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) if ((drive->dev_flags & IDE_DFLAG_DOORLOCKING) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) memset(&cmd, 0, sizeof(cmd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) cmd.tf.command = on ? ATA_CMD_MEDIA_LOCK : ATA_CMD_MEDIA_UNLOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) cmd.valid.out.tf = IDE_VALID_OUT_TF | IDE_VALID_DEVICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) cmd.valid.in.tf = IDE_VALID_IN_TF | IDE_VALID_DEVICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) ret = ide_no_data_taskfile(drive, &cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) const struct ide_disk_ops ide_ata_disk_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) .check = ide_disk_check,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) .unlock_native_capacity = ide_disk_unlock_native_capacity,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) .get_capacity = ide_disk_get_capacity,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) .setup = ide_disk_setup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) .flush = ide_disk_flush,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) .init_media = ide_disk_init_media,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) .set_doorlock = ide_disk_set_doorlock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) .do_request = ide_do_rw_disk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) .ioctl = ide_disk_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) .compat_ioctl = ide_disk_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) };